From 534d602953c168fb34342ff46b566978eabc0e39 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Fri, 16 Feb 2024 21:59:34 +0800 Subject: [PATCH] bug fixes, with TODO added --- CheatEnabler/PlanetPatch.cs | 4 ++-- HideTips/HideTips.cs | 10 ++++++--- MechaDronesTweaks/MechaDronesTweaks.cs | 1 - UXAssist/FactoryPatch.cs | 12 +++++----- UXAssist/PlanetFunctions.cs | 31 +++++++++++++++++++++++++- UXAssist/TODO.md | 4 ++++ 6 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 UXAssist/TODO.md diff --git a/CheatEnabler/PlanetPatch.cs b/CheatEnabler/PlanetPatch.cs index 6c10b8b..1019fb3 100644 --- a/CheatEnabler/PlanetPatch.cs +++ b/CheatEnabler/PlanetPatch.cs @@ -49,9 +49,9 @@ public static class PlanetPatch { var matcher = new CodeMatcher(instructions, generator); matcher.MatchForward(false, - new CodeMatch(instr => instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(22)) + new CodeMatch(instr => instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(23)) ).Advance(1).MatchForward(false, - new CodeMatch(instr => instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(22)) + new CodeMatch(instr => instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(23)) ); matcher.Repeat(codeMatcher => { diff --git a/HideTips/HideTips.cs b/HideTips/HideTips.cs index d069528..39fc84e 100644 --- a/HideTips/HideTips.cs +++ b/HideTips/HideTips.cs @@ -20,7 +20,7 @@ public class HideTips : BaseUnityPlugin private static bool _noResearchCompletionPopups = true; private static bool _noResearchCompletionTips; private static bool _skipPrologue = true; - private static bool _hideMenuDemo; +// private static bool _hideMenuDemo; private static Harmony _patch; @@ -34,13 +34,15 @@ public class HideTips : BaseUnityPlugin _noResearchCompletionPopups = Config.Bind("General", "NoResearchCompletionPopups", _noResearchCompletionPopups, "Disable Research Completion Popup Windows").Value; _noResearchCompletionTips = Config.Bind("General", "NoResearchCompletionTips", _noResearchCompletionTips, "Disable Research Completion Tips").Value; _skipPrologue = Config.Bind("General", "SkipPrologue", _skipPrologue, "Skip prologue for new game").Value; - _hideMenuDemo = Config.Bind("General", "HideMenuDemo", _hideMenuDemo, "Disable title screen demo scene loading").Value; +// _hideMenuDemo = Config.Bind("General", "HideMenuDemo", _hideMenuDemo, "Disable title screen demo scene loading").Value; if (!_cfgEnabled) return; Harmony.CreateAndPatchAll(typeof(HideTips)); + /* if (_hideMenuDemo) { _patch = Harmony.CreateAndPatchAll(typeof(HideMenuDemo)); } + */ } private void OnDestroy() @@ -141,6 +143,7 @@ public class HideTips : BaseUnityPlugin } } +/* [HarmonyPatch] class HideMenuDemo { @@ -208,4 +211,5 @@ class HideMenuDemo DSPGame.Game._running = true; return false; } -} \ No newline at end of file +} +*/ diff --git a/MechaDronesTweaks/MechaDronesTweaks.cs b/MechaDronesTweaks/MechaDronesTweaks.cs index b0a6c72..99b34c6 100644 --- a/MechaDronesTweaks/MechaDronesTweaks.cs +++ b/MechaDronesTweaks/MechaDronesTweaks.cs @@ -73,7 +73,6 @@ public static class MechaDronesTweaks public static float EnergyMultiplier = 0.1f; [HarmonyTranspiler] - [HarmonyPatch(typeof(ConstructionModuleComponent), nameof(ConstructionModuleComponent.SearchForNewTargets))] [HarmonyPatch(typeof(ConstructionSystem), nameof(ConstructionSystem.UpdateDrones))] [HarmonyPatch(typeof(UIMechaWindow), nameof(UIMechaWindow.UpdateProps))] [HarmonyPatch(typeof(UITechTree), nameof(UITechTree.RefreshDataValueText))] diff --git a/UXAssist/FactoryPatch.cs b/UXAssist/FactoryPatch.cs index 40a1ddc..e19f7c1 100644 --- a/UXAssist/FactoryPatch.cs +++ b/UXAssist/FactoryPatch.cs @@ -347,18 +347,18 @@ public static class FactoryPatch * ldloc.s V_88 (88) * ldloc.s V_120 (120) * brtrue.s 2054 (173A) ldc.i4.s 17 - * ldc.i4.s 18 + * ldc.i4.s EBuildCondition.JointCannotLift (19) * br.s 2055 (173C) stfld valuetype EBuildCondition BuildPreview::condition - * ldc.i4.s 17 + * ldc.i4.s EBuildCondition.EBuildCondition.JointCannotLift (19) (18) * stfld valuetype EBuildCondition BuildPreview::condition */ matcher.MatchForward(false, new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(instr => instr.opcode == OpCodes.Brtrue_S || instr.opcode == OpCodes.Brtrue), - new CodeMatch(instr => instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(18)), + new CodeMatch(instr => instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(19)), new CodeMatch(instr => instr.opcode == OpCodes.Br_S || instr.opcode == OpCodes.Br), - new CodeMatch(instr => instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(17)), + new CodeMatch(instr => instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(18)), new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(BuildPreview), nameof(BuildPreview.condition))) ); if (matcher.IsValid) @@ -375,12 +375,12 @@ public static class FactoryPatch /* search for: * ldloc.s V_88 (88) - * ldc.i4.s 15-19 + * ldc.i4.s EBuildCondition.TooSteep(16)-EBuildCondition.InputConflict(20) * stfld valuetype EBuildCondition BuildPreview::condition */ matcher.Start().MatchForward(false, new CodeMatch(instr => instr.opcode == OpCodes.Ldloc_S || instr.opcode == OpCodes.Ldloc), - new CodeMatch(instr => (instr.opcode == OpCodes.Ldc_I4_S || instr.opcode == OpCodes.Ldc_I4) && Convert.ToInt64(instr.operand) is >= 15 and <= 19), + new CodeMatch(instr => (instr.opcode == OpCodes.Ldc_I4_S || instr.opcode == OpCodes.Ldc_I4) && Convert.ToInt64(instr.operand) is >= 16 and <= 20), new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(BuildPreview), nameof(BuildPreview.condition))) ); if (matcher.IsValid) diff --git a/UXAssist/PlanetFunctions.cs b/UXAssist/PlanetFunctions.cs index 52d325f..03c9d40 100644 --- a/UXAssist/PlanetFunctions.cs +++ b/UXAssist/PlanetFunctions.cs @@ -55,7 +55,7 @@ public static class PlanetFunctions //planet.data.CalcVerts(); for (var id = factory.entityCursor - 1; id > 0; id--) { - var ed = factory.entityPool[id]; + ref var ed = ref factory.entityPool[id]; if (ed.id != id) continue; if (ed.colliderId != 0) { @@ -77,6 +77,21 @@ public static class PlanetFunctions planet.audio?.RemoveAudioData(ed.audioId); } + if (planet.factory.enemyPool != null) + { + for (var i = planet.factory.enemyCursor - 1; i > 0; i--) + { + ref var ptr13 = ref planet.factory.enemyPool[i]; + if (ptr13.id != i) continue; + var combatStatId = ptr13.combatStatId; + planet.factory.skillSystem.OnRemovingSkillTarget(combatStatId, planet.factory.skillSystem.combatStats.buffer[combatStatId].originAstroId, ETargetType.CombatStat); + planet.factory.skillSystem.combatStats.Remove(combatStatId); + planet.factory.KillEnemyFinally(player, i, ref CombatStat.empty); + } + planet.factory.enemySystem.Free(); + UIRoot.instance.uiGame.dfAssaultTip.ClearAllSpots(); + } + var stationPool = factory.transport?.stationPool; if (stationPool != null) { @@ -120,20 +135,34 @@ public static class PlanetFunctions if (warningPool[i].id == i && warningPool[i].factoryId == index) warningSystem.RemoveWarningData(warningPool[i].id); } + var isCombatMode = factory.gameData.gameDesc.isCombatMode; factory.entityCursor = 1; factory.entityRecycleCursor = 0; factory.entityCapacity = 0; factory.SetEntityCapacity(1024); + factory.craftCursor = 1; + factory.craftRecycleCursor = 0; + factory.craftCapacity = 0; + factory.SetCraftCapacity(128); factory.prebuildCursor = 1; factory.prebuildRecycleCursor = 0; factory.prebuildCapacity = 0; factory.SetPrebuildCapacity(256); + factory.enemyCursor = 1; + factory.enemyRecycleCursor = 0; + factory.enemyCapacity = 0; + factory.SetEnemyCapacity(isCombatMode ? 1024 : 32); factory.cargoContainer = new CargoContainer(); factory.cargoTraffic = new CargoTraffic(planet); factory.blockContainer = new MiniBlockContainer(); factory.factoryStorage = new FactoryStorage(planet); factory.powerSystem = new PowerSystem(planet); + factory.constructionSystem = new ConstructionSystem(planet); factory.factorySystem = new FactorySystem(planet); + factory.enemySystem = new EnemyDFGroundSystem(planet); + factory.combatGroundSystem = new CombatGroundSystem(planet); + factory.defenseSystem = new DefenseSystem(planet); + factory.planetATField = new PlanetATField(planet); factory.transport = new PlanetTransport(GameMain.data, planet); factory.transport.Init(); factory.digitalSystem = new DigitalSystem(planet); diff --git a/UXAssist/TODO.md b/UXAssist/TODO.md new file mode 100644 index 0000000..8360cb9 --- /dev/null +++ b/UXAssist/TODO.md @@ -0,0 +1,4 @@ +#### TODO +* Show coordinates of buildings, on both preview-mode and panel +* Better handling of consuming metadata +* More queued commands