1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 04:53:30 +08:00

CheatEnabler v2.3.6

This commit is contained in:
2023-11-07 16:52:03 +08:00
parent 269f98c995
commit 05485d76b5
3 changed files with 69 additions and 5 deletions

View File

@@ -124,6 +124,66 @@ public static class FactoryPatch
{
ArrivePlanet(factory);
}
GameMain.data?.warningSystem?.UpdateCriticalWarningText();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(WarningSystem), nameof(WarningSystem.hasCriticalWarning), MethodType.Getter)]
private static IEnumerable<CodeInstruction> WarningSystem_hasCriticalWarning_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
matcher.End().MatchBack(false,
new CodeMatch(OpCodes.Ret)
);
matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoConditionEnabled))),
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), nameof(ConfigEntry<bool>.Value))),
new CodeInstruction(OpCodes.Or)
);
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(WarningSystem), nameof(WarningSystem.UpdateCriticalWarningText))]
private static IEnumerable<CodeInstruction> WarningSystem_UpdateCriticalWarningText_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldstr),
new CodeMatch(OpCodes.Call, AccessTools.PropertySetter(typeof(WarningSystem), nameof(WarningSystem.criticalWarningTexts)))
);
matcher.Repeat(m =>
{
var label1 = generator.DefineLabel();
var label2 = generator.DefineLabel();
m.Advance(1).Labels.Add(label1);
m.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(NoConditionEnabled))),
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), nameof(ConfigEntry<bool>.Value))),
new CodeInstruction(OpCodes.Brfalse, label1),
new CodeInstruction(OpCodes.Ldstr, "Build without condition is enabled!"),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(StringTranslate), nameof(StringTranslate.Translate), new[] { typeof(string) })),
new CodeInstruction(OpCodes.Ldstr, "\r\n"),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(string), nameof(string.Concat), new[] { typeof(string), typeof(string) })),
new CodeInstruction(OpCodes.Call, AccessTools.PropertySetter(typeof(WarningSystem), nameof(WarningSystem.criticalWarningTexts)))
);
if (m.InstructionAt(2).opcode == OpCodes.Ret)
{
m.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(WarningSystem), nameof(WarningSystem.onCriticalWarningTextChanged))),
new CodeInstruction(OpCodes.Brfalse_S, label2),
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(WarningSystem), nameof(WarningSystem.onCriticalWarningTextChanged))),
new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Action), nameof(Action.Invoke)))
);
}
m.InsertAndAdvance(
new CodeInstruction(OpCodes.Br, label2)
).Advance(2).Labels.Add(label2);
});
return matcher.InstructionEnumeration();
}
private static class ImmediateBuild
@@ -262,6 +322,7 @@ public static class FactoryPatch
private static Harmony _noConditionPatch;
public static void Enable(bool on)
{
GameMain.data?.warningSystem?.UpdateCriticalWarningText();
if (on)
{
_noConditionPatch ??= Harmony.CreateAndPatchAll(typeof(NoConditionBuild));
@@ -270,7 +331,7 @@ public static class FactoryPatch
_noConditionPatch?.UnpatchSelf();
_noConditionPatch = null;
}
[HarmonyTranspiler, HarmonyPriority(Priority.Last)]
[HarmonyPatch(typeof(BuildTool_Addon), nameof(BuildTool_Addon.CheckBuildConditions))]
// [HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))]

View File

@@ -5,7 +5,9 @@
## Changlog
* 2.3.6
+ Fix a issue in `Finish build immediately` that some buildings are not finished immediately.
+ Support for UXAssist's new function within `Finish build immediately`.
+ Add a warning message when `Build without condition` is enabled.
+ Fix a issue in `Finish build immediately` that some buildings are not finished immediately.
* 2.3.5
+ Fix another crash in `Skip bullet period`.
* 2.3.4
@@ -111,6 +113,8 @@
## 更新日志
* 2.3.6
+ 在`建造秒完成`中支持UXAssist的新功能
+ 在启用`无条件建造`时添加警告信息
+ 修复了`建造秒完成`可能导致部分建筑无法立即完成的问题
* 2.3.5
+ 修复了`跳过子弹阶段`可能导致崩溃的问题

View File

@@ -29,6 +29,7 @@ public static class UIConfigWindow
I18N.Add("Finish build immediately", "Finish build immediately", "建造秒完成");
I18N.Add("Architect mode", "Architect mode", "建筑师模式");
I18N.Add("Build without condition", "Build without condition check", "无条件建造");
I18N.Add("Build without condition is enabled!", "!!Build without condition is enabled!!", "!!无条件建造已开启!!");
I18N.Add("No collision", "No collision", "无碰撞");
I18N.Add("Belt signal generator", "Belt signal generator", "传送带信号物品生成");
I18N.Add("Belt signal alt format", "Belt signal alt format", "传送带信号替换格式");
@@ -79,9 +80,7 @@ public static class UIConfigWindow
MyWindow.AddTipsButton(x, y, tab1, "Unlock Tech with Key-Modifiers", "Unlock Tech with Key-Modifiers Tips", "unlock-tech-tips");
x = 300f;
y = 10f;
_resignGameBtn = wnd.AddButton(x, y, tab1, "Assign game to current account", 16, "resign-game-btn", () => { GameMain.data.account = AccountData.me; });
var rect = (RectTransform)_resignGameBtn.transform;
rect.sizeDelta = new Vector2(200f, rect.sizeDelta.y);
_resignGameBtn = wnd.AddButton(x, y, 200f, tab1, "Assign game to current account", 16, "resign-game-btn", () => { GameMain.data.account = AccountData.me; });
var tab2 = wnd.AddTab(_windowTrans, "Factory");
x = 0f;