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

UXAssist: Drag build Power Towers fix

This commit is contained in:
2025-10-03 14:29:41 +08:00
parent 49226001be
commit ac9f4ee8a9
4 changed files with 33 additions and 14 deletions

View File

@@ -3,6 +3,10 @@
## Changlog ## Changlog
* 1.4.3
* `Build Tesla Tower and Wireless Power Tower alternately`:
* Fix wrong implementation for latest game patch.
* Cannot use Tesla Tower as start Power Tower now, due to new matrix build mechanism.
* 1.4.2 * 1.4.2
* Fixed a crash issue. * Fixed a crash issue.
* 1.4.1 * 1.4.1
@@ -340,6 +344,10 @@
## 更新日志 ## 更新日志
* 1.4.3
* `交替建造电力感应塔和无线输电塔`:
* 修复了在最新游戏补丁中的错误实现
* 由于新的矩阵建造机制,现在无法使用电力感应塔作为起始电塔
* 1.4.2 * 1.4.2
* 修复了一个崩溃问题 * 修复了一个崩溃问题
* 1.4.1 * 1.4.1

View File

@@ -1401,7 +1401,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
{ {
private static readonly List<bool> OldDragBuild = []; private static readonly List<bool> OldDragBuild = [];
private static readonly List<Vector2> OldDragBuildDist = []; private static readonly List<Vector2> OldDragBuildDist = [];
private static readonly int[] PowerPoleIds = [2201, 2202, 2212]; private static readonly int[] PowerPoleIds = [2202, 2212];
protected override void OnEnable() protected override void OnEnable()
{ {
@@ -1435,13 +1435,13 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
OldDragBuildDist.Clear(); OldDragBuildDist.Clear();
foreach (var id in PowerPoleIds) foreach (var id in PowerPoleIds)
{ {
var powerPole = LDB.items.Select(id); var prefabDesc = LDB.items.Select(id)?.prefabDesc;
if (powerPole?.prefabDesc == null) return; if (prefabDesc == null) return;
OldDragBuild.Add(powerPole.prefabDesc.dragBuild); OldDragBuild.Add(prefabDesc.dragBuild);
OldDragBuildDist.Add(powerPole.prefabDesc.dragBuildDist); OldDragBuildDist.Add(prefabDesc.dragBuildDist);
powerPole.prefabDesc.dragBuild = true; prefabDesc.dragBuild = true;
var distance = (id == 2201 && DragBuildPowerPolesAlternatelyEnabled.Value ? LDB.items.Select(2202) : powerPole).prefabDesc.powerConnectDistance - 0.72f; var distance = prefabDesc.powerConnectDistance - 0.72f;
powerPole.prefabDesc.dragBuildDist = new Vector2(distance, distance); prefabDesc.dragBuildDist = new Vector2(distance, distance);
} }
} }
@@ -1560,17 +1560,28 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BuildTool_Click), nameof(BuildTool_Click.handPrefabDesc))), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BuildTool_Click), nameof(BuildTool_Click.handPrefabDesc))),
new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(BuildPreview), nameof(BuildPreview.desc))) new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(BuildPreview), nameof(BuildPreview.desc)))
).Advance(2).InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 6)).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) => );
var pos = matcher.Pos;
matcher.MatchBack(false,
new CodeMatch(ci => ci.IsLdloc()),
new CodeMatch(ci => ci.IsLdloc()),
new CodeMatch(OpCodes.Mul),
new CodeMatch(ci => ci.IsLdloc()),
new CodeMatch(OpCodes.Add)
);
var operand = matcher.Operand;
matcher.Start().Advance(pos);
matcher.Advance(2).InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, operand)).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) =>
{ {
if (!DragBuildPowerPolesAlternatelyEnabled.Value || (i & 1) == 0) return click.handItem; if (!DragBuildPowerPolesAlternatelyEnabled.Value || (i & 1) == 0) return click.handItem;
var id = click.handItem.ID; var id = click.handItem.ID;
if (id != 2201 && id != 2202) return click.handItem; if (id != 2202) return click.handItem;
return LDB.items.Select(id ^ 3); return LDB.items.Select(id ^ 3);
})).Advance(3).InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 6)).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) => })).Advance(3).InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, operand)).SetInstructionAndAdvance(Transpilers.EmitDelegate((BuildTool_Click click, int i) =>
{ {
if (!DragBuildPowerPolesAlternatelyEnabled.Value || (i & 1) == 0) return click.handPrefabDesc; if (!DragBuildPowerPolesAlternatelyEnabled.Value || (i & 1) == 0) return click.handPrefabDesc;
var id = click.handItem.ID; var id = click.handItem.ID;
if (id != 2201 && id != 2202) return click.handPrefabDesc; if (id != 2202) return click.handPrefabDesc;
return LDB.items.Select(id ^ 3).prefabDesc; return LDB.items.Select(id ^ 3).prefabDesc;
})); }));
return matcher.InstructionEnumeration(); return matcher.InstructionEnumeration();

View File

@@ -4,7 +4,7 @@
<TargetFramework>net472</TargetFramework> <TargetFramework>net472</TargetFramework>
<BepInExPluginGuid>org.soardev.uxassist</BepInExPluginGuid> <BepInExPluginGuid>org.soardev.uxassist</BepInExPluginGuid>
<Description>DSP MOD - UXAssist</Description> <Description>DSP MOD - UXAssist</Description>
<Version>1.4.2</Version> <Version>1.4.3</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<PackageId>UXAssist</PackageId> <PackageId>UXAssist</PackageId>

View File

@@ -1,6 +1,6 @@
{ {
"name": "UXAssist", "name": "UXAssist",
"version_number": "1.4.2", "version_number": "1.4.3",
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UXAssist", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/UXAssist",
"description": "Some functions and patches for better user experience / 一些提升用户体验的功能和补丁", "description": "Some functions and patches for better user experience / 一些提升用户体验的功能和补丁",
"dependencies": [ "dependencies": [