diff --git a/MechaDronesTweaks/MechaDronesTweaks.cs b/MechaDronesTweaks/MechaDronesTweaks.cs index 19fd77d..ef2767d 100644 --- a/MechaDronesTweaks/MechaDronesTweaks.cs +++ b/MechaDronesTweaks/MechaDronesTweaks.cs @@ -5,6 +5,7 @@ using System.Reflection.Emit; using BepInEx; using BepInEx.Configuration; using HarmonyLib; +using UnityEngine; namespace MechaDronesTweaks; @@ -72,187 +73,123 @@ public static class MechaDronesTweaks public static float SpeedMultiplier = 4f; public static float EnergyMultiplier = 0.1f; - [HarmonyTranspiler, HarmonyPatch(typeof(UITechTree), "RefreshDataValueText")] + [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))] private static IEnumerable UITechTreeRefreshDataValueText_Transpiler( - IEnumerable instructions) + IEnumerable instructions, ILGenerator generator) { - foreach (var instr in instructions) + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GameHistoryData), nameof(GameHistoryData.constructionDroneSpeed))) + ); + if (UseFixedSpeed) { - if (instr.opcode == OpCodes.Callvirt && - instr.OperandIs(AccessTools.Method(typeof(Mecha), "get_droneSpeed"))) + matcher.Repeat(m => m.Advance(1).InsertAndAdvance( + new CodeInstruction(OpCodes.Pop), + new CodeInstruction(OpCodes.Ldc_R4, FixedSpeed) + )); + } + else + { + matcher.Repeat(m => m.Advance(1).InsertAndAdvance( + new CodeInstruction(OpCodes.Ldc_R4, SpeedMultiplier), + new CodeInstruction(OpCodes.Mul) + )); + } + return matcher.InstructionEnumeration(); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(ConstructionModuleComponent), nameof(ConstructionModuleComponent.EjectBaseDrone))] + [HarmonyPatch(typeof(ConstructionModuleComponent), nameof(ConstructionModuleComponent.EjectMechaDrone))] + private static IEnumerable MechaUpdateTargets_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + if (!SkipStage1) + return matcher.InstructionEnumeration(); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldc_I4_1), + new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(DroneComponent), nameof(DroneComponent.stage))) + ).Operand = 2; + return matcher.InstructionEnumeration(); + } + + [HarmonyTranspiler, HarmonyPatch(typeof(ConstructionSystem), nameof(ConstructionSystem.UpdateDrones))] + private static IEnumerable MechaUpdateDrones_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + if (EnergyMultiplier >= 1f) + return matcher.InstructionEnumeration(); + matcher.MatchForward(false, + new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(ModeConfig), nameof(ModeConfig.droneEnergyPerMeter))) + ).Advance(1).Insert( + new CodeInstruction(OpCodes.Ldc_R8, (double)EnergyMultiplier), + new CodeInstruction(OpCodes.Mul) + ); + return matcher.InstructionEnumeration(); + } + + [HarmonyTranspiler] + // ref CraftData craft, PlanetFactory factory, ref Vector3 ejectPos, float droneSpeed, float dt, ref double mechaEnergy, ref double mechaEnergyChange, double flyEnergyRate, double repairEnergyCost, out float energyRatio + [HarmonyPatch(typeof(DroneComponent), nameof(DroneComponent.InternalUpdate), new[] { typeof(CraftData), typeof(PlanetFactory), typeof(Vector3), typeof(float), typeof(float), typeof(double), typeof(double), typeof(double), typeof(double), typeof(float) }, new[] { ArgumentType.Ref, ArgumentType.Normal, ArgumentType.Ref, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Ref, ArgumentType.Ref, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Out })] + // ref CraftData craft, PlanetFactory factory, Vector3 ejectPos, float droneSpeed, float dt, ref long energy, double flyEnergyRate, double repairEnergyCost, out float energyRatio + [HarmonyPatch(typeof(DroneComponent), nameof(DroneComponent.InternalUpdate), new[] { typeof(CraftData), typeof(PlanetFactory), typeof(Vector3), typeof(float), typeof(float), typeof(long), typeof(double), typeof(double), typeof(float) }, new[] { ArgumentType.Ref, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Ref, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Out })] + private static IEnumerable MechaDroneUpdate_Transpiler(IEnumerable instructions, ILGenerator generator) + { + var matcher = new CodeMatcher(instructions, generator); + + if (RemoveSpeedLimitForStage1) + { + matcher.MatchForward(false, + new CodeMatch(instr => instr.opcode == OpCodes.Ldc_R4 && instr.OperandIs(1f)), + new CodeMatch(instr => instr.opcode == OpCodes.Ldc_R4 && instr.OperandIs(3f)) + ); + matcher.Advance(1).Operand = 10000f; + } + + if (!UseFixedSpeed && Math.Abs(SpeedMultiplier - 1.0f) < 0.01f) + return matcher.InstructionEnumeration(); + + matcher.Start().MatchForward(false, + new CodeMatch(OpCodes.Ldarg_0), + new CodeMatch(OpCodes.Ldc_R4), + new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(DroneComponent), nameof(DroneComponent.progress))) + ); + matcher.Repeat(m => + { + if (m.InstructionAt(1).OperandIs(0f)) + { + m.InstructionAt(3).labels = m.Labels; + m.RemoveInstructions(3); + } + else if (m.InstructionAt(1).OperandIs(1f)) + { + m.Advance(1).Operand = 0f; + m.Advance(2); + } + } + ); + matcher.Start().MatchForward(false, + new CodeMatch(instr => instr.opcode == OpCodes.Ldc_R4 && instr.OperandIs(0.5f)) + ); + matcher.Repeat(m => { if (UseFixedSpeed) { - yield return new CodeInstruction(OpCodes.Pop); - yield return new CodeInstruction(OpCodes.Ldc_R4, FixedSpeed); + if (FixedSpeed > 75f) + { + m.Operand = 0.5f * FixedSpeed / 75f; + } } else { - yield return instr; - yield return new CodeInstruction(OpCodes.Ldc_R4, SpeedMultiplier); - yield return new CodeInstruction(OpCodes.Mul); + m.Operand = 0.5f * SpeedMultiplier; } } - else - { - yield return instr; - } - } - } - - [HarmonyTranspiler, HarmonyPatch(typeof(MechaDroneLogic), "UpdateTargets")] - private static IEnumerable MechaUpdateTargets_Transpiler(IEnumerable instructions) - { - if (SkipStage1) - { - var ilist = instructions.ToList(); - for (var i = 0; i < ilist.Count; i++) - { - var instr = ilist[i]; - if (instr.opcode == OpCodes.Ldc_I4_1) - { - var instrNext = ilist[i + 1]; - if (instrNext.opcode == OpCodes.Stfld && - instrNext.OperandIs(AccessTools.Field(typeof(MechaDrone), "stage"))) - { - instr.opcode = OpCodes.Ldc_I4_2; - } - } - - yield return instr; - } - } - else - { - foreach (var instr in instructions) - { - yield return instr; - } - } - } - - [HarmonyTranspiler, HarmonyPatch(typeof(MechaDroneLogic), "UpdateDrones")] - private static IEnumerable MechaUpdateDrones_Transpiler(IEnumerable instructions) - { - if (EnergyMultiplier >= 1f) - { - foreach (var instr in instructions) - { - yield return instr; - } - } - else - { - foreach (var instr in instructions) - { - yield return instr; - if (instr.opcode != OpCodes.Ldfld || - !instr.OperandIs(AccessTools.Field(typeof(Mecha), "droneEnergyPerMeter"))) continue; - yield return new CodeInstruction(OpCodes.Ldc_R8, (double)EnergyMultiplier); - yield return new CodeInstruction(OpCodes.Mul); - } - } - } - - [HarmonyTranspiler, HarmonyPatch(typeof(MechaDrone), "Update")] - private static IEnumerable MechaDroneUpdate_Transpiler(IEnumerable instructions) - { - if (!UseFixedSpeed && Math.Abs(SpeedMultiplier - 1.0f) < 0.01f) - { - foreach (var instr in instructions) - { - yield return instr; - } - } - else - { - var ilist = instructions.ToList(); - for (var i = 0; i < ilist.Count; i++) - { - var instr = ilist[i]; - if (instr.opcode == OpCodes.Ldarg_0) - { - var instrNext = ilist[i + 1]; - if (instrNext.opcode == OpCodes.Ldfld && - instrNext.OperandIs(AccessTools.Field(typeof(MechaDrone), "speed"))) - { - if (UseFixedSpeed) - { - var newInstr = new CodeInstruction(instr) - { - opcode = OpCodes.Ldc_R4, - operand = FixedSpeed - }; - yield return newInstr; - } - else - { - yield return instr; - yield return instrNext; - yield return new CodeInstruction(OpCodes.Ldc_R4, SpeedMultiplier); - yield return new CodeInstruction(OpCodes.Mul); - } - - i++; - continue; - } - - if (instrNext.opcode == OpCodes.Ldc_R4) - { - if (instrNext.OperandIs(0f)) - { - var instrNext2 = ilist[i + 2]; - if (instrNext2.opcode == OpCodes.Stfld && - instrNext2.OperandIs(AccessTools.Field(typeof(MechaDrone), "progress"))) - { - ilist[i + 3].labels = instr.labels; - i += 2; - continue; - } - } - else if (instrNext.OperandIs(1f)) - { - var instrNext2 = ilist[i + 2]; - if (instrNext2.opcode == OpCodes.Stfld && - instrNext2.OperandIs(AccessTools.Field(typeof(MechaDrone), "progress"))) - { - instrNext.operand = 0f; - yield return instr; - yield return instrNext; - yield return instrNext2; - i += 2; - continue; - } - } - } - } - else if (instr.opcode == OpCodes.Ldc_R4) - { - if (instr.OperandIs(0.5f)) - { - if (UseFixedSpeed) - { - if (FixedSpeed > 75f) - { - instr.operand = 0.5f * FixedSpeed / 75f; - } - } - else - { - instr.operand = 0.5f * SpeedMultiplier; - } - } - else if (instr.OperandIs(3f)) - { - if (RemoveSpeedLimitForStage1) - { - instr.operand = 10000f; - } - } - } - - yield return instr; - } - } + ); + return matcher.InstructionEnumeration(); } } \ No newline at end of file diff --git a/MechaDronesTweaks/MechaDronesTweaks.csproj b/MechaDronesTweaks/MechaDronesTweaks.csproj index 51c8b35..0bf6f95 100644 --- a/MechaDronesTweaks/MechaDronesTweaks.csproj +++ b/MechaDronesTweaks/MechaDronesTweaks.csproj @@ -6,7 +6,7 @@ MechaDronesTweaks org.soardev.mechadronestweaks DSP MOD - MechaDronesTweaks - 1.1.2 + 1.1.3 true latest https://nuget.bepinex.dev/v3/index.json diff --git a/MechaDronesTweaks/README.md b/MechaDronesTweaks/README.md index 92fb115..63406f3 100644 --- a/MechaDronesTweaks/README.md +++ b/MechaDronesTweaks/README.md @@ -4,6 +4,9 @@ #### 机甲建设机调整(FastDrones MOD的后继者) ## Updates +* 1.1.3 + + Support for game version 0.10.28.20759+ + + Fixed a minor bug that `RemoveSpeedLimitForStage1` not working while `UseFixedSpeed` set to false and `SpeedMultiplier` set to 1 * 1.1.2 + `RemoveBuildRangeLimit`, `LargerAreaForUpgradeAndDismantle` and `LargerAreaForTerraform` are moved to [UXAssist](https://dsp.thunderstore.io/package/soarqin/UXAssist) @@ -32,6 +35,9 @@ * Note: This MOD will disable `FastDrones` if the MOD is installed, to avoid conflict in functions. ## 更新日志 +* 1.1.3 + + 支持游戏版本0.10.28.20759+ + + 修复了当`UseFixedSpeed`设置为false且`SpeedMultiplier`设置为1时`RemoveSpeedLimitForStage1`无效的问题 * 1.1.2 + `RemoveBuildRangeLimit`, `LargerAreaForUpgradeAndDismantle` 和 `LargerAreaForTerraform` 移动到了 MOD [UXAssist](https://dsp.thunderstore.io/package/soarqin/UXAssist) 中 diff --git a/MechaDronesTweaks/package/manifest.json b/MechaDronesTweaks/package/manifest.json index 535515b..009fda8 100644 --- a/MechaDronesTweaks/package/manifest.json +++ b/MechaDronesTweaks/package/manifest.json @@ -1,6 +1,6 @@ { "name": "MechaDronesTweaks", - "version_number": "1.1.2", + "version_number": "1.1.3", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/MechaDronesTweaks", "description": "Some tweaks for mecha drones and build functions(Successor to FastDrones MOD) / 机甲建设机和建设功能调整(FastDrones MOD的后继者)", "dependencies": [ diff --git a/UniverseGenTweaks/MoreSettings.cs b/UniverseGenTweaks/MoreSettings.cs index 06b4522..ce48a1f 100644 --- a/UniverseGenTweaks/MoreSettings.cs +++ b/UniverseGenTweaks/MoreSettings.cs @@ -243,7 +243,28 @@ public class MoreSettings var matcher = new CodeMatcher(instructions, generator); matcher.MatchForward(false, new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(25700)) - ).Repeat(m => m.SetAndAdvance(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(MoreSettings.MaxStarCount))).Insert( + ); + matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(MoreSettings.MaxStarCount))).Insert( + new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry), nameof(ConfigEntry.Value))), + new CodeInstruction(OpCodes.Ldc_I4_1), + new CodeInstruction(OpCodes.Add), + new CodeInstruction(OpCodes.Ldc_I4_S, 100), + new CodeInstruction(OpCodes.Mul) + )); + return matcher.InstructionEnumeration(); + } + + [HarmonyTranspiler] + [HarmonyPatch(typeof(SectorModel), nameof(SectorModel.CreateGalaxyAstroBuffer))] + [HarmonyPatch(typeof(SpaceColliderLogic), nameof(SpaceColliderLogic.UpdateCollidersPose))] + private static IEnumerable SectorModel_CreateGalaxyAstroBuffer_Transpiler(IEnumerable instructions, ILGenerator generator) + { + // 25600 -> (MaxStarCount.Value + 1) * 100 + var matcher = new CodeMatcher(instructions, generator); + matcher.MatchForward(false, + new CodeMatch(ci => ci.opcode == OpCodes.Ldc_I4 && ci.OperandIs(25600)) + ); + matcher.Repeat(m => m.SetAndAdvance(OpCodes.Ldsfld, AccessTools.Field(typeof(MoreSettings), nameof(MoreSettings.MaxStarCount))).Insert( new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry), nameof(ConfigEntry.Value))), new CodeInstruction(OpCodes.Ldc_I4_1), new CodeInstruction(OpCodes.Add), diff --git a/UniverseGenTweaks/README.md b/UniverseGenTweaks/README.md index 06b6b1d..c6105ce 100644 --- a/UniverseGenTweaks/README.md +++ b/UniverseGenTweaks/README.md @@ -4,6 +4,9 @@ #### 宇宙生成参数调节 ## Changelog +* 1.2.4 + + Fix a crash while setting star count greater than 256 (again) + + Fix bug that collider check is not enabled on stars with ID greater than 255 * 1.2.3 + Fix a crash while setting star count greater than 256 * 1.2.2 @@ -35,6 +38,9 @@ * High luminosity for birth star ## 更新日志 +* 1.2.4 + + 修复了设置星系数大于256时崩溃的问题(再次) + + 修复了ID大于255的星系没有启用碰撞体检测的问题 * 1.2.3 + 修复了设置星系数大于256时崩溃的问题 * 1.2.2 diff --git a/UniverseGenTweaks/UniverseGenTweaks.csproj b/UniverseGenTweaks/UniverseGenTweaks.csproj index 3dcba3f..65bfc16 100644 --- a/UniverseGenTweaks/UniverseGenTweaks.csproj +++ b/UniverseGenTweaks/UniverseGenTweaks.csproj @@ -6,7 +6,7 @@ UniverseGenTweaks org.soardev.universegentweaks DSP MOD - UniverseGenTweaks - 1.2.3 + 1.2.4 true latest https://nuget.bepinex.dev/v3/index.json diff --git a/UniverseGenTweaks/package/manifest.json b/UniverseGenTweaks/package/manifest.json index 726d5f6..f3be9ad 100644 --- a/UniverseGenTweaks/package/manifest.json +++ b/UniverseGenTweaks/package/manifest.json @@ -1,6 +1,6 @@ { "name": "UniverseGenTweaks", - "version_number": "1.2.3", + "version_number": "1.2.4", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UniverseGenTweaks", "description": "Universe Generation Tweaks / 宇宙生成参数调节", "dependencies": [