style(loader): file-scoped namespace + silence Harmony003 false positive

This commit is contained in:
gamer147
2026-06-03 09:17:37 -04:00
parent 800e40344b
commit 620ae31582

View File

@@ -1,74 +1,74 @@
using Cute; using Cute;
using HarmonyLib; using HarmonyLib;
namespace SVSimLoader.Patches namespace SVSimLoader.Patches;
[HarmonyPatch]
public static class MultiInstancePatches
{ {
[HarmonyPatch] // (1) Defeat the machine-wide single-instance guard. createMutex is private, so target it
public static class MultiInstancePatches // by string name. Prefix returning false skips the original (Application.Quit never runs).
[HarmonyPatch(typeof(BootApp), "createMutex")]
[HarmonyPrefix]
public static bool SkipMutex()
{ {
// (1) Defeat the machine-wide single-instance guard. createMutex is private, so target it if (!SvSimConfig.SecondaryInstance) return true; // primary/normal: run original
// by string name. Prefix returning false skips the original (Application.Quit never runs). Plugin.Log.LogWarning("Multi-instance: skipping BootApp.createMutex single-instance guard.");
[HarmonyPatch(typeof(BootApp), "createMutex")] return false;
[HarmonyPrefix] }
public static bool SkipMutex()
{
if (!SvSimConfig.SecondaryInstance) return true; // primary/normal: run original
Plugin.Log.LogWarning("Multi-instance: skipping BootApp.createMutex single-instance guard.");
return false;
}
// (2) Redirect the three identity keys to the per-instance file store. Other keys fall // (2) Redirect the three identity keys to the per-instance file store. Other keys fall
// through to the original (return true). // through to the original (return true).
private static bool IsIdentityKey(string key) => private static bool IsIdentityKey(string key) =>
key == "UDID" || key == "VIEWER_ID" || key == "SHORT_UDID"; key == "UDID" || key == "VIEWER_ID" || key == "SHORT_UDID";
[HarmonyPatch(typeof(SavedataManager), nameof(SavedataManager.GetString))] [HarmonyPatch(typeof(SavedataManager), nameof(SavedataManager.GetString))]
[HarmonyPrefix] [HarmonyPrefix]
public static bool GetString(string key, string defaultValue, ref string __result) public static bool GetString(string key, string defaultValue, ref string __result)
{ {
if (!SvSimConfig.SecondaryInstance || !IsIdentityKey(key)) return true; if (!SvSimConfig.SecondaryInstance || !IsIdentityKey(key)) return true;
__result = InstanceIdentityStore.TryGet(key, out var v) ? v : defaultValue; __result = InstanceIdentityStore.TryGet(key, out var v) ? v : defaultValue;
return false; return false;
} }
[HarmonyPatch(typeof(SavedataManager), nameof(SavedataManager.SetString))] [HarmonyPatch(typeof(SavedataManager), nameof(SavedataManager.SetString))]
[HarmonyPrefix] [HarmonyPrefix]
public static bool SetString(string key, string value) public static bool SetString(string key, string value)
{ {
if (!SvSimConfig.SecondaryInstance || !IsIdentityKey(key)) return true; if (!SvSimConfig.SecondaryInstance || !IsIdentityKey(key)) return true;
InstanceIdentityStore.Set(key, value); InstanceIdentityStore.Set(key, value);
return false; return false;
} }
[HarmonyPatch(typeof(SavedataManager), nameof(SavedataManager.GetInt))] [HarmonyPatch(typeof(SavedataManager), nameof(SavedataManager.GetInt))]
[HarmonyPrefix] [HarmonyPrefix]
public static bool GetInt(string key, int defaultValue, ref int __result) public static bool GetInt(string key, int defaultValue, ref int __result)
{ {
if (!SvSimConfig.SecondaryInstance || !IsIdentityKey(key)) return true; if (!SvSimConfig.SecondaryInstance || !IsIdentityKey(key)) return true;
__result = InstanceIdentityStore.TryGet(key, out var v) && int.TryParse(v, out var i) ? i : defaultValue; __result = InstanceIdentityStore.TryGet(key, out var v) && int.TryParse(v, out var i) ? i : defaultValue;
return false; return false;
} }
[HarmonyPatch(typeof(SavedataManager), nameof(SavedataManager.SetInt))] [HarmonyPatch(typeof(SavedataManager), nameof(SavedataManager.SetInt))]
[HarmonyPrefix] [HarmonyPrefix]
public static bool SetInt(string key, int value) public static bool SetInt(string key, int value)
{ {
if (!SvSimConfig.SecondaryInstance || !IsIdentityKey(key)) return true; if (!SvSimConfig.SecondaryInstance || !IsIdentityKey(key)) return true;
InstanceIdentityStore.Set(key, value.ToString()); int v = value;
return false; InstanceIdentityStore.Set(key, v.ToString());
} return false;
}
// (3) Force a synthetic Steam identity. setSTEAMPlatformData runs in Certification.Start(); // (3) Force a synthetic Steam identity. setSTEAMPlatformData runs in Certification.Start();
// a postfix overwrites SteamID/SteamSessionTicket (private setters) via Traverse. // a postfix overwrites SteamID/SteamSessionTicket (private setters) via Traverse.
[HarmonyPatch(typeof(Certification), "setSTEAMPlatformData")] [HarmonyPatch(typeof(Certification), "setSTEAMPlatformData")]
[HarmonyPostfix] [HarmonyPostfix]
public static void ForceSteamIdentity() public static void ForceSteamIdentity()
{ {
if (!SvSimConfig.SecondaryInstance) return; if (!SvSimConfig.SecondaryInstance) return;
Traverse.Create(typeof(Certification)).Property("SteamID").SetValue(SvSimConfig.FakeSteamId); Traverse.Create(typeof(Certification)).Property("SteamID").SetValue(SvSimConfig.FakeSteamId);
Traverse.Create(typeof(Certification)).Property("SteamSessionTicket").SetValue(SvSimConfig.FakeTicket); Traverse.Create(typeof(Certification)).Property("SteamSessionTicket").SetValue(SvSimConfig.FakeTicket);
Plugin.Log.LogWarning( Plugin.Log.LogWarning(
$"Multi-instance: forced SteamID={SvSimConfig.FakeSteamId}, ticket={SvSimConfig.FakeTicket}."); $"Multi-instance: forced SteamID={SvSimConfig.FakeSteamId}, ticket={SvSimConfig.FakeTicket}.");
}
} }
} }