Skip to content

Commit

Permalink
Some Palworld finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
thommcgrath committed Jan 31, 2024
1 parent a9ca057 commit ba69d52
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 180 deletions.
1 change: 0 additions & 1 deletion Project/Modules/Game Support/Ark/Project.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ Inherits Beacon.Project
Messages.Add("What happens when an Ark spins out of control?")

Var Rand As Random = System.Random
Rand.RandomizeSeed
Var Index As Integer = Rand.InRange(0, Messages.LastIndex)

Values.Add(New Ark.ConfigValue(Ark.ConfigFileGameUserSettings, "MessageOfTheDay", "Message=" + Messages(Index)))
Expand Down
1 change: 0 additions & 1 deletion Project/Modules/Game Support/ArkSA/Project.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ Inherits Beacon.Project
Messages.Add("What happens when an Ark spins out of control?")

Var Rand As Random = System.Random
Rand.RandomizeSeed
Var Index As Integer = Rand.InRange(0, Messages.LastIndex)

Values.Add(New ArkSA.ConfigValue(ArkSA.ConfigFileGameUserSettings, "MessageOfTheDay", "Message=" + Messages(Index)))
Expand Down
169 changes: 1 addition & 168 deletions Project/Modules/Game Support/Palworld/DeployIntegration.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,7 @@ Inherits Beacon.DeployIntegration
Var Settings As JSONItem = GameServer.Child("settings")
Settings.Compact = False
OldFiles.Value("Config.json") = Settings.ToString

NitradoChanges = Self.NitradoPrepareChanges(Organizer)
Var NewSettings As New JSONItem(Settings.ToString)
For Each Entry As DictionaryEntry In NitradoChanges
Try
Var Setting As Palworld.ConfigOption = Entry.Key
Var NewValue As String = Entry.Value

Var Changes() As Nitrado.SettingChange = Nitrado.HostingProvider.PrepareSettingChanges(GameServer, Setting, NewValue)
For Each Change As Nitrado.SettingChange In Changes
Try
Var Parent As JSONItem = NewSettings.Child(Change.Category)
Parent.Value(Change.Key) = Change.Value
Catch ChangeErr As RuntimeException
App.Log(ChangeErr, CurrentMethodName, "Updating config json")
End Try
Next
Catch EntryErr As RuntimeException
App.Log(EntryErr, CurrentMethodName, "Processing Nitrado changes")
End Try
Next
NewSettings.Compact = False
NewFiles.Value("Config.json") = NewSettings.ToString
NewFiles.Value("Config.json") = Settings.ToString
End Select

Self.RunBackup(OldFiles, NewFiles)
Expand All @@ -143,61 +121,10 @@ Inherits Beacon.DeployIntegration
Self.Finish()
Return
End If

// Make command line changes
Select Case Self.Provider
Case IsA Nitrado.HostingProvider
Self.Log("Updating other settings…")
If NitradoChanges Is Nil Then
Call Self.NitradoApplySettings(Organizer)
Else
Call Self.NitradoApplySettings(NitradoChanges)
End If
If Self.Finished Then
Return
End If
End Select
End Sub
#tag EndEvent


#tag Method, Flags = &h1
Protected Function NitradoApplySettings(Changes As Dictionary) As Boolean
If (Self.Provider IsA Nitrado.HostingProvider) = False Then
Return False
End If

// Deploy changes
For Each Entry As DictionaryEntry In Changes
Var Setting As Palworld.ConfigOption = Entry.Key
Var NewValue As String = Entry.Value

Try
Self.Provider.GameSetting(Project, Profile, Setting) = NewValue
Catch Err As RuntimeException
Self.SetError(Err)
Return False
End Try

// So we don't go nuts
Self.Thread.Sleep(100)
Next

Return True
End Function
#tag EndMethod

#tag Method, Flags = &h1
Protected Function NitradoApplySettings(Organizer As Palworld.ConfigOrganizer) As Boolean
If (Self.Provider IsA Nitrado.HostingProvider) = False Then
Return False
End If

Var Changes As Dictionary = Self.NitradoPrepareChanges(Organizer)
Return Self.NitradoApplySettings(Changes)
End Function
#tag EndMethod

#tag Method, Flags = &h1
Protected Sub NitradoCooldownWait()
// Since the process is about to upload, we need to find the log file and determine how long to wait
Expand Down Expand Up @@ -239,100 +166,6 @@ Inherits Beacon.DeployIntegration
End Sub
#tag EndMethod

#tag Method, Flags = &h1
Protected Function NitradoPrepareChanges(Organizer As Palworld.ConfigOrganizer) As Dictionary
Var Project As Palworld.Project = Self.Project
Var Profile As Palworld.ServerProfile = Self.Profile
Var Keys() As Palworld.ConfigOption = Organizer.DistinctKeys
Var NewValues As New Dictionary
Var Style As Palworld.ConfigOption.NitradoDeployStyles = Palworld.ConfigOption.NitradoDeployStyles.Expert

For Each ConfigOption As Palworld.ConfigOption In Keys
If ConfigOption.HasNitradoEquivalent = False Then
Continue
End If

Var SendToNitrado As Boolean = ConfigOption.NitradoDeployStyle = Palworld.ConfigOption.NitradoDeployStyles.Both Or ConfigOption.NitradoDeployStyle = Style
If SendToNitrado = False Then
Continue
End If

Var Values() As Palworld.ConfigValue = Organizer.FilteredValues(ConfigOption)

Select Case ConfigOption.NitradoFormat
Case Palworld.ConfigOption.NitradoFormats.Line
Var Lines() As String
For Each Value As Palworld.ConfigValue In Values
Lines.Add(Value.Command)
Next
NewValues.Value(ConfigOption) = Lines
Case Palworld.ConfigOption.NitradoFormats.Value
If Values.Count >= 1 Then
Var Value As String = Values(Values.LastIndex).Value

If ConfigOption.ValueType = Palworld.ConfigOption.ValueTypes.TypeBoolean Then
Value = Value.Lowercase

Var Reversed As NullableBoolean = NullableBoolean.FromVariant(ConfigOption.Constraint("nitrado.boolean.reversed"))
If (Reversed Is Nil) = False And Reversed.BooleanValue Then
Value = If(Value = "true", "false", "true")
End If
End If

NewValues.Value(ConfigOption) = Value
Else
// This doesn't make sense
Break
End If
End Select
Next

Var Changes As New Dictionary
For Each Entry As DictionaryEntry In NewValues
Var ConfigOption As Palworld.ConfigOption = Entry.Key
Var CurrentValue As Variant = Self.Provider.GameSetting(Project, Profile, ConfigOption)
Var FinishedValue As String
If Entry.Value.Type = Variant.TypeString Then
// Value comparison
If ConfigOption.ValuesEqual(Entry.Value, CurrentValue) Then
Continue
End If
FinishedValue = Entry.Value.StringValue
ElseIf Entry.Value.IsArray And Entry.Value.ArrayElementType = Variant.TypeString Then
// Line comparison, but if there is only one line, go back to value comparison
Var NewLines() As String = Entry.Value
FinishedValue = NewLines.Join(EndOfLine) // Prepare the finished value before sorting, even if we nay not use it

Var CurrentLines() As String = CurrentValue.StringValue.ReplaceLineEndings(EndOfLine.UNIX).Split(EndOfLine.UNIX)

If NewLines.Count = 1 And CurrentLines.Count = 1 And (ConfigOption.ValueType = Palworld.ConfigOption.ValueTypes.TypeNumeric Or ConfigOption.ValueType = Palworld.ConfigOption.ValueTypes.TypeBoolean Or ConfigOption.ValueType = Palworld.ConfigOption.ValueTypes.TypeBoolean) Then
Var NewValue As String = NewLines(0).Middle(NewLines(0).IndexOf("=") + 1)
CurrentValue = CurrentLines(0).Middle(CurrentLines(0).IndexOf("=") + 1)
If ConfigOption.ValuesEqual(NewValue, CurrentValue) Then
Continue
End If
FinishedValue = NewLines(0)
Else
NewLines.Sort
CurrentLines.Sort
Var NewHash As String = EncodeHex(Crypto.SHA1(NewLines.Join(EndOfLine.UNIX).Lowercase))
Var CurrentHash As String = EncodeHex(Crypto.SHA1(CurrentLines.Join(EndOfLine.UNIX).Lowercase))
If NewHash = CurrentHash Then
// No change
Continue
End If
End If
Else
Continue
End If

Changes.Value(ConfigOption) = FinishedValue
Next

Return Changes
End Function
#tag EndMethod

#tag Method, Flags = &h0
Function Profile() As Palworld.ServerProfile
Return Palworld.ServerProfile(Super.Profile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Inherits Beacon.DiscoverIntegration
Case IsA Nitrado.HostingProvider
Self.Log("Checking server status…")
Try
Profile.BasePath = Provider.GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeString, "/game_specific.path"))
Profile.BasePath = Nitrado.HostingProvider(Provider).GameSetting(Project, Profile, New Beacon.GenericGameSetting(Beacon.GenericGameSetting.TypeString, "/game_specific.path"))
Catch Err As RuntimeException
Self.SetError("Could not find server base path: " + Err.Message)
Return Nil
Expand Down
50 changes: 43 additions & 7 deletions Project/Modules/Game Support/Palworld/Project.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,51 @@ Inherits Beacon.Project

#tag Method, Flags = &h0
Function CreateTrollConfigOrganizer(Profile As Palworld.ServerProfile) As Palworld.ConfigOrganizer
Var Values As New Palworld.ConfigOrganizer
Var Values As New Dictionary
If (Profile Is Nil) = False Then
Values.Value("ServerName") = Profile.Name
Values.Value("ServerDescription") = Profile.ServerDescription
If (Profile.AdminPassword Is Nil) = False Then
Values.Value("AdminPassword") = Profile.AdminPassword.StringValue
End If
If (Profile.ServerPassword Is Nil) = False Then
Values.Value("ServerPassword") = Profile.ServerPassword.StringValue
End If
End If

Var Index As Integer = System.Random.InRange(0, 5)

#if DebugBuild
#Pragma Warning "Needs troll organizer"
#else
#Pragma Error "Needs troll organizer"
#endif
Select Case Index
Case 0
Values.Value("bEnableAimAssistPad") = False
Values.Value("bEnableAimAssistKeyboard") = False
Case 1
Values.Value("bEnableFriendlyFire") = True
Values.Value("bEnablePlayerToPlayerDamage") = True
Values.Value("PalDamageRateDefense") = 0.0001
Values.Value("PlayerDamageRateDefense") = 0.0001
Case 2
Values.Value("PalStaminaDecreaseRate") = 1000
Values.Value("PlayerStaminaDecreaseRate") = 1000
Case 3
Values.Value("WorkSpeedRate") = 0.0001
Case 4
Values.Value("ExpRate") = 0.0001
Case 5
Values.Value("PlayerAutoHpRegeneRateInSleep") = 0.0001
Values.Value("PlayerAutoHPRegeneRate") = 0.0001
Values.Value("PalAutoHpRegeneRateInSleep") = 0.0001
Values.Value("PalAutoHPRegeneRate") = 0.0001
Case 6
Values.Value("PalSpawnNumRate") = 0.01
End Select

Var Organizer As New Palworld.ConfigOrganizer
For Each Entry As DictionaryEntry In Values
Organizer.Add(Palworld.ConfigFileSettings, Palworld.HeaderPalworldSettings, "OptionSettings", Entry.Key.StringValue, Entry.Value, Palworld.ConfigOrganizer.OptionValueIsManaged)
Next

Return Values
Return Organizer
End Function
#tag EndMethod

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ End
// We'll create five entries to create a proper spread

Var Randomizer As Random = System.Random
Randomizer.RandomizeSeed
Radius = Radius / 2
Var OffsetRadius As Double = Radius / 2 // For 1/4 of the original

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ End
// We'll create five entries to create a proper spread

Var Randomizer As Random = System.Random
Randomizer.RandomizeSeed
Radius = Radius / 2
Var OffsetRadius As Double = Radius / 2 // For 1/4 of the original

Expand Down

0 comments on commit ba69d52

Please sign in to comment.