Skip to content

Commit

Permalink
Fixed (?) bug with race in singleplayer pregame menu
Browse files Browse the repository at this point in the history
  • Loading branch information
alphanin9 committed Jan 17, 2025
1 parent 272db00 commit 7ca5425
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scripting/DifficultyAdjustment/NGPlusModSettings.reds
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class UserSettings {
@runtimeProperty("ModSettings.description", "NewGamePlus_ClampPlayerLevelInTransfer_Desc")
public let clampPlayerLevel: Bool = true;
@runtimeProperty("ModSettings.mod", "NewGamePlus_MainMenuButton")
@runtimeProperty("ModSettings.displayName", "NewGamePlus_DisableSaveValidation_Name")
@runtimeProperty("ModSettings.description", "NewGamePlus_DisableSaveValidation_Desc")
public let disableValidationChecks: Bool = false;
@runtimeProperty("ModSettings.mod", "NewGamePlus_MainMenuButton")
@runtimeProperty("ModSettings.category", "NewGamePlus_Difficulty_Name")
@runtimeProperty("ModSettings.category.order", "1")
Expand Down Expand Up @@ -116,6 +121,7 @@ public class UserSettings {
}
}

// Note: should be done on native side by patching DynamicSpawnSystem fields directly!
public class DynamicSpawnSystemCustomizer extends ScriptableTweak {
protected cb func OnApply() {
let settings = UserSettings.Get();
Expand Down
11 changes: 11 additions & 0 deletions scripting/NGPlusButtonAdder.reds
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module NGPlus.ButtonAdder
@addField(SingleplayerMenuGameController)
public let m_hasNewGamePlus: Bool = false;

@addField(SingleplayerMenuGameController)
public let m_actionListMutex: RWLock;

@wrapMethod(SingleplayerMenuGameController)
protected cb func OnInitialize() -> Bool {
wrappedMethod();
Expand All @@ -28,6 +31,14 @@ protected cb func OnNewGamePlusSavesReady(hasSaves: Bool) -> Void {
}
}

@wrapMethod(SingleplayerMenuGameController)
protected func ShowActionsList() {
// To avoid troubles with callbacks triggering simultaneously or almost simultaneously, add locking
RWLock.Acquire(this.m_actionListMutex);
wrappedMethod();
RWLock.Release(this.m_actionListMutex);
}

@wrapMethod(gameuiMenuItemListGameController)
private func AddMenuItem(const label: script_ref<String>, spawnEvent: CName) -> Void {
wrappedMethod(label, spawnEvent);
Expand Down

0 comments on commit 7ca5425

Please sign in to comment.