diff --git a/UXAssist/ModsCompat/AuxilaryfunctionWrapper.cs b/UXAssist/ModsCompat/AuxilaryfunctionWrapper.cs index ca70aac..dc8704c 100644 --- a/UXAssist/ModsCompat/AuxilaryfunctionWrapper.cs +++ b/UXAssist/ModsCompat/AuxilaryfunctionWrapper.cs @@ -10,7 +10,7 @@ public static class AuxilaryfunctionWrapper private const string AuxilaryfunctionGuid = "cn.blacksnipe.dsp.Auxilaryfunction"; public static ConfigEntry ShowStationInfo; - public static void Init(Harmony harmony) + public static void Start(Harmony harmony) { if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(AuxilaryfunctionGuid, out var pluginInfo)) return; var assembly = pluginInfo.Instance.GetType().Assembly; diff --git a/UXAssist/ModsCompat/BulletTimeWrapper.cs b/UXAssist/ModsCompat/BulletTimeWrapper.cs index 1e7378c..f93f1f1 100644 --- a/UXAssist/ModsCompat/BulletTimeWrapper.cs +++ b/UXAssist/ModsCompat/BulletTimeWrapper.cs @@ -10,45 +10,8 @@ public static class BulletTimeWrapper private const string BulletTimeGuid = "com.starfi5h.plugin.BulletTime"; public static bool HasBulletTime; - public static void Init(Harmony harmony) + public static void Start(Harmony _) { - HasBulletTime = BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(BulletTimeGuid, out var pluginInfo); - if (!HasBulletTime) return; - - I18N.Add("Increase game speed (max 10x)", "Increase game speed (max 10x)", "提升游戏速度(最高10倍)"); - I18N.Apply(); - - var assembly = pluginInfo.Instance.GetType().Assembly; - try - { - var classType = assembly.GetType("BulletTime.IngameUI"); - harmony.Patch(AccessTools.Method(classType, "Init"), - null, null, new HarmonyMethod(AccessTools.Method(typeof(BulletTimeWrapper), nameof(IngameUI_Init_Transpiler)))); - harmony.Patch(AccessTools.Method(classType, "OnSpeedButtonClick"), - null, null, new HarmonyMethod(AccessTools.Method(typeof(BulletTimeWrapper), nameof(IngameUI_OnSpeedButtonClick_Transpiler)))); - } - catch - { - UXAssist.Logger.LogWarning("Failed to patch BulletTime functions()"); - } + HasBulletTime = BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(BulletTimeGuid, out var _); } - - private static IEnumerable IngameUI_Init_Transpiler(IEnumerable instructions) - { - var matcher = new CodeMatcher(instructions); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldstr, "Increase game speed (max 4x)") - ).Set(OpCodes.Ldstr, "Increase game speed (max 10x)"); - return matcher.InstructionEnumeration(); - } - - private static IEnumerable IngameUI_OnSpeedButtonClick_Transpiler(IEnumerable instructions) - { - var matcher = new CodeMatcher(instructions); - matcher.MatchForward(false, - new CodeMatch(OpCodes.Ldc_R8, 240.0) - ).Set(OpCodes.Ldc_R8, 600.0); - return matcher.InstructionEnumeration(); - } - -} \ No newline at end of file +} diff --git a/UXAssist/Patches/TechPatch.cs b/UXAssist/Patches/TechPatch.cs index 56a2766..10cb0fc 100644 --- a/UXAssist/Patches/TechPatch.cs +++ b/UXAssist/Patches/TechPatch.cs @@ -381,12 +381,6 @@ public static class TechPatch void DoUnlockFuncInternal() { - UnlockTechRecursive(__instance.techProto, maxLevel); - history.VarifyTechQueue(); - if (history.currentTech != history.techQueue[0]) - { - history.currentTech = history.techQueue[0]; - } var mainPlayer = GameMain.mainPlayer; for (var i = 0; i < 6; i++) { @@ -398,6 +392,12 @@ public static class TechPatch mainPlayer.mecha.AddProductionStat(itemId, itemCount, mainPlayer.nearestFactory); mainPlayer.mecha.AddConsumptionStat(itemId, itemCount, mainPlayer.nearestFactory); } + UnlockTechRecursive(__instance.techProto, maxLevel); + history.VarifyTechQueue(); + if (history.currentTech != history.techQueue[0]) + { + history.currentTech = history.techQueue[0]; + } } } } diff --git a/UXAssist/UXAssist.cs b/UXAssist/UXAssist.cs index 0c656cd..dcdce29 100644 --- a/UXAssist/UXAssist.cs +++ b/UXAssist/UXAssist.cs @@ -30,7 +30,7 @@ public class UXAssist : BaseUnityPlugin, IModCanSave private static bool _initialized; private static PressKeyBind _toggleKey; private static ConfigFile _dummyConfig; - private Type[] _patches; + private Type[] _patches, _compats; #region IModCanSave private const ushort ModSaveVersion = 1; @@ -160,6 +160,8 @@ public class UXAssist : BaseUnityPlugin, IModCanSave _patches = Common.Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "UXAssist.Patches"); _patches?.Do(type => type.GetMethod("Init")?.Invoke(null, null)); + _compats = Common.Util.GetTypesInNamespace(Assembly.GetExecutingAssembly(), "UXAssist.ModsCompat"); + _compats?.Do(type => type.GetMethod("Init")?.Invoke(null, null)); I18N.Apply(); I18N.OnInitialized += RecreateConfigWindow; @@ -171,9 +173,9 @@ public class UXAssist : BaseUnityPlugin, IModCanSave UIPatch.Enable(true); _patches?.Do(type => type.GetMethod("Start")?.Invoke(null, null)); - var patch = UIPatch.GetHarmony(); - ModsCompat.AuxilaryfunctionWrapper.Init(patch); - ModsCompat.BulletTimeWrapper.Init(patch); + + object[] parameters = [UIPatch.GetHarmony()]; + _compats?.Do(type => type.GetMethod("Start")?.Invoke(null, parameters)); } private void OnDestroy()