Skip to content

Commit

Permalink
Do not disable the Mods button when quitting to the Main Menu from ga…
Browse files Browse the repository at this point in the history
…meplay in Stock Bug Fix, as Steam mods obviously have to be fully loaded by then.

Fix a very rare race condition in Fast Track.
  • Loading branch information
peterhaneve committed Sep 27, 2024
1 parent 4be5d20 commit 7837264
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
18 changes: 10 additions & 8 deletions FastTrack/GamePatches/SuitMarkerUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ public sealed class SuitMarkerUpdater : KMonoBehaviour, ISim1000ms, ISim200ms {
/// <param name="equipment">The assignables containing the suit to drop.</param>
private static void DropSuit(Assignables equipment) {
var assignable = equipment.GetAssignable(Db.Get().AssignableSlots.Suit);
var notification = new Notification(STRINGS.MISC.NOTIFICATIONS.SUIT_DROPPED.NAME,
NotificationType.BadMinor, (_, data) => STRINGS. MISC.NOTIFICATIONS.
SUIT_DROPPED.TOOLTIP);
assignable.Unassign();
if (assignable.TryGetComponent(out Notifier notifier))
notifier.Add(notification);
if (assignable != null) {
var notification = new Notification(STRINGS.MISC.NOTIFICATIONS.SUIT_DROPPED.NAME,
NotificationType.BadMinor, (_, data) => STRINGS. MISC.NOTIFICATIONS.
SUIT_DROPPED.TOOLTIP);
assignable.Unassign();
if (assignable.TryGetComponent(out Notifier notifier))
notifier.Add(notification);
}
}

/// <summary>
Expand Down Expand Up @@ -263,7 +265,7 @@ internal void UpdateSuitStatus() {

/// <summary>
/// Applied to SuitMarker.EquipSuitReactable to make the Run method more efficient and
/// use the SuitMarkerUpdater..
/// use the SuitMarkerUpdater.
/// </summary>
[HarmonyPatch(typeof(SuitMarker.EquipSuitReactable), nameof(SuitMarker.
EquipSuitReactable.Run))]
Expand Down Expand Up @@ -316,7 +318,7 @@ internal static bool Prefix() {

/// <summary>
/// Applied to SuitMarker.UnequipSuitReactable to make the Run method more efficient and
/// use the SuitMarkerUpdater..
/// use the SuitMarkerUpdater.
/// </summary>
[HarmonyPatch(typeof(SuitMarker.UnequipSuitReactable), nameof(SuitMarker.
UnequipSuitReactable.Run))]
Expand Down
2 changes: 1 addition & 1 deletion PLibCore/PatchManager/PLibMethodAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void Run(Harmony instance) {
Method.Invoke(null, new object[] { instance, requiredType });
} else
PUtil.LogWarning("Invalid signature for PLibMethod - must have (), " +
"(HarmonyInstance), or (HarmonyInstance, Type)");
"(Harmony), or (Harmony, Type)");
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions StockBugFix/QueuedModReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public sealed class QueuedModReporter : KMonoBehaviour {
private static readonly IDetouredField<MainMenu, KButton> RESUME_GAME = PDetours.
DetourFieldLazy<MainMenu, KButton>(nameof(MainMenu.Button_ResumeGame));

public static void Init() {
firstLoad = true;
}

/// <summary>
/// Only lock the button out on the first main menu load; loading and quitting a game
/// is so slow that it will certainly be loaded by then.
/// </summary>
private static volatile bool firstLoad;

/// <summary>
/// Is the mods button already enabled?
/// </summary>
Expand Down Expand Up @@ -74,8 +84,9 @@ private void FindModsButton(Transform buttonParent) {
protected override void OnSpawn() {
base.OnSpawn();
startupTime = 0.0f;
if (StockBugFixOptions.Instance.DelayModsMenu && TryGetComponent(out MainMenu mm))
{
if (firstLoad && StockBugFixOptions.Instance.DelayModsMenu && TryGetComponent(
out MainMenu mm)) {
firstLoad = false;
try {
Transform buttonParent;
KButton resumeButton;
Expand Down
2 changes: 1 addition & 1 deletion StockBugFix/StockBugFix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Stock Bug Fix</AssemblyTitle>
<FileVersion>4.3.0.0</FileVersion>
<FileVersion>4.4.0.0</FileVersion>
<RootNamespace>PeterHan.StockBugFix</RootNamespace>
<Description>Fixes bugs and annoyances in the stock game.</Description>
<AssemblyVersion>3.2.0.0</AssemblyVersion>
Expand Down
2 changes: 2 additions & 0 deletions StockBugFix/StockBugsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ internal static void AfterDbInit() {
FixRadiationSickness();
if (StockBugFixOptions.Instance.FixTraits)
TraitsExclusionPatches.FixTraits();
QueuedModReporter.Init();
}

/// <summary>
Expand Down Expand Up @@ -241,6 +242,7 @@ public override void OnLoad(Harmony instance) {
PUtil.InitLibrary();
var pm = new PPatchManager(instance);
pm.RegisterPatchClass(typeof(StockBugsPatches));
pm.RegisterPatchClass(typeof(DiseaseSourcesPatch));
pm.RegisterPatchClass(typeof(SweepFixPatches));
FixModUpdateRace(instance);
PRegistry.PutData("Bugs.TepidizerPulse", true);
Expand Down
21 changes: 14 additions & 7 deletions StockBugFix/StockQOLPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Collections.Generic;
using System.Reflection;
using PeterHan.PLib.Core;
using PeterHan.PLib.PatchManager;
using UnityEngine;

namespace PeterHan.StockBugFix {
Expand Down Expand Up @@ -210,21 +211,27 @@ internal static bool Prefix(FoodDiagnostic __instance,
/// Applied to multiple types to add a Disease Source icon to Buddy Buds, Bristle
/// Blossoms and Bammoths.
/// </summary>
[HarmonyPatch]
public static class PollenDiseaseSources_Patch {
internal static IEnumerable<MethodBase> TargetMethods() {
internal static class DiseaseSourcesPatch {
/// <summary>
/// Since referencing the Bammoth causes localization to break through transitive
/// string references, apply the patch manually after the Db is loaded.
/// </summary>
[PLibMethod(RunAt.AfterDbInit)]
internal static void ApplyPatch(Harmony harmony) {
const string METHOD_NAME = nameof(IEntityConfig.CreatePrefab);
var bammothType = PPatchTools.GetTypeSafe("IceBellyConfig");
yield return typeof(BulbPlantConfig).GetMethodSafe(METHOD_NAME, false);
yield return typeof(PrickleFlowerConfig).GetMethodSafe(METHOD_NAME, false);
var patchMethod = new HarmonyMethod(typeof(DiseaseSourcesPatch),
nameof(PollenGermsPostfix));
harmony.Patch(typeof(BulbPlantConfig), METHOD_NAME, postfix: patchMethod);
harmony.Patch(typeof(PrickleFlowerConfig), METHOD_NAME, postfix: patchMethod);
if (bammothType != null)
yield return bammothType.GetMethodSafe(METHOD_NAME, false);
harmony.Patch(bammothType, METHOD_NAME, postfix: patchMethod);
}

/// <summary>
/// Applied after CreatePrefab runs.
/// </summary>
internal static void Postfix(GameObject __result) {
internal static void PollenGermsPostfix(GameObject __result) {
__result.AddOrGet<DiseaseSourceVisualizer>().alwaysShowDisease = "PollenGerms";
}
}
Expand Down

0 comments on commit 7837264

Please sign in to comment.