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

UXAssist: Work in progress

This commit is contained in:
2023-10-10 02:38:24 +08:00
parent 41f2103c11
commit 6caa183cfa
26 changed files with 1477 additions and 1800 deletions

View File

@@ -58,25 +58,6 @@ public class MechaDronesTweaksPlugin : BaseUnityPlugin
MechaDronesTweaks.EnergyMultiplier,
new ConfigDescription("Energy consumption multiplier for mecha drones",
new AcceptableValueRange<float>(0f, 1f))).Value;
MechaDronesTweaks.RemoveBuildRangeLimit = Config.Bind("MechaBuild", "RemoveBuildRangeLimit",
MechaDronesTweaks.RemoveBuildRangeLimit,
"Remove limit for build range and maximum count of drag building belts/buildings\nNote: this does not affect range limit for mecha drones' action")
.Value;
MechaDronesTweaks.LargerAreaForUpgradeAndDismantle = Config.Bind("MechaBuild",
"LargerAreaForUpgradeAndDismantle", MechaDronesTweaks.LargerAreaForUpgradeAndDismantle,
"Increase maximum area size for upgrade and dismantle to 31x31 (from 11x11)").Value;
MechaDronesTweaks.LargerAreaForTerraform = Config.Bind("MechaBuild", "LargerAreaForTerraform",
MechaDronesTweaks.LargerAreaForTerraform,
"Increase maximum area size for terraform to 30x30 (from 10x10)\nNote: this may impact game performance while using large area")
.Value;
MechaDronesTweaks.EnhancedMechaForgeCountControl = Config.Bind("", "EnhancedMechaForgeCountControl",
MechaDronesTweaks.EnhancedMechaForgeCountControl,
"Enhanced count control for hand-make, increases maximum of count to 1000, and you can hold Ctrl/Shift/Alt to change the count rapidly")
.Value;
MechaDronesTweaks.InventoryStackMultiplier = Config.Bind("Storage", "InventoryStackMultiplier",
MechaDronesTweaks.InventoryStackMultiplier,
"Stack count multiplier for inventory items, this also affects stack count for storage boxes")
.Value;
_harmony.PatchAll(typeof(MechaDronesTweaks));
}
@@ -90,11 +71,6 @@ public static class MechaDronesTweaks
public static float FixedSpeed = 300f;
public static float SpeedMultiplier = 4f;
public static float EnergyMultiplier = 0.1f;
public static bool RemoveBuildRangeLimit = true;
public static bool LargerAreaForUpgradeAndDismantle = true;
public static bool LargerAreaForTerraform = true;
public static bool EnhancedMechaForgeCountControl = true;
public static int InventoryStackMultiplier = 1;
[HarmonyTranspiler, HarmonyPatch(typeof(UITechTree), "RefreshDataValueText")]
private static IEnumerable<CodeInstruction> UITechTreeRefreshDataValueText_Transpiler(
@@ -279,396 +255,4 @@ public static class MechaDronesTweaks
}
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(BuildTool_Dismantle), nameof(BuildTool_Dismantle.DeterminePreviews))]
[HarmonyPatch(typeof(BuildTool_Upgrade), nameof(BuildTool_Upgrade.DeterminePreviews))]
private static IEnumerable<CodeInstruction> BuildTools_CursorSizePatch_Transpiler(
IEnumerable<CodeInstruction> instructions)
{
if (!LargerAreaForUpgradeAndDismantle)
{
foreach (var instr in instructions)
{
yield return instr;
}
}
else
{
foreach (var instr in instructions)
{
if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(11))
{
yield return new CodeInstruction(OpCodes.Ldc_I4_S, 31);
}
else
{
yield return instr;
}
}
}
}
[HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Reform), MethodType.Constructor)]
private static IEnumerable<CodeInstruction> BuildTool_Reform_Constructor_Transpiler(
IEnumerable<CodeInstruction> instructions)
{
if (!LargerAreaForTerraform)
{
foreach (var instr in instructions)
{
yield return instr;
}
}
else
{
foreach (var instr in instructions)
{
if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(100))
{
yield return new CodeInstruction(OpCodes.Ldc_I4, 900);
}
else
{
yield return instr;
}
}
}
}
[HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))]
private static IEnumerable<CodeInstruction> BuildTool_Reform_ReformAction_Transpiler(
IEnumerable<CodeInstruction> instructions)
{
if (!LargerAreaForTerraform)
{
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.Ldc_I4_S && instr.OperandIs(10) &&
(ilist[i - 1].opcode == OpCodes.Ldfld &&
ilist[i - 1].OperandIs(AccessTools.Field(typeof(BuildTool_Reform), "brushSize"))
||
ilist[i + 1].opcode == OpCodes.Stfld &&
ilist[i + 1].OperandIs(AccessTools.Field(typeof(BuildTool_Reform), "brushSize")))
)
{
yield return new CodeInstruction(OpCodes.Ldc_I4_S, 30);
}
else
{
yield return instr;
}
}
}
}
[HarmonyTranspiler, HarmonyPatch(typeof(ConnGizmoGraph), MethodType.Constructor)]
private static IEnumerable<CodeInstruction> ConnGizmoGraph_Constructor_Transpiler(
IEnumerable<CodeInstruction> instructions)
{
if (!RemoveBuildRangeLimit)
{
foreach (var instr in instructions)
{
yield return instr;
}
}
else
{
foreach (var instr in instructions)
{
if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(256))
{
yield return new CodeInstruction(OpCodes.Ldc_I4, 2048);
}
else
{
yield return instr;
}
}
}
}
[HarmonyTranspiler, HarmonyPatch(typeof(ConnGizmoGraph), nameof(ConnGizmoGraph.SetPointCount))]
private static IEnumerable<CodeInstruction> ConnGizmoGraph_SetPointCount_Transpiler(
IEnumerable<CodeInstruction> instructions)
{
if (!RemoveBuildRangeLimit)
{
foreach (var instr in instructions)
{
yield return instr;
}
}
else
{
foreach (var instr in instructions)
{
if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(256))
{
yield return new CodeInstruction(OpCodes.Ldc_I4, 2048);
}
else
{
yield return instr;
}
}
}
}
[HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path._OnInit))]
private static IEnumerable<CodeInstruction> BuildTool_Path__OnInit_Transpiler(
IEnumerable<CodeInstruction> instructions)
{
if (!RemoveBuildRangeLimit)
{
foreach (var instr in instructions)
{
yield return instr;
}
}
else
{
foreach (var instr in instructions)
{
if (instr.opcode == OpCodes.Ldc_I4 && instr.OperandIs(160))
{
instr.operand = 2048;
}
yield return instr;
}
}
}
[HarmonyTranspiler, HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click._OnInit))]
private static IEnumerable<CodeInstruction> BuildTool_Click__OnInit_Transpiler(
IEnumerable<CodeInstruction> instructions)
{
if (!RemoveBuildRangeLimit)
{
foreach (var instr in instructions)
{
yield return instr;
}
}
else
{
foreach (var instr in instructions)
{
if (instr.opcode == OpCodes.Ldc_I4_S && instr.OperandIs(15))
{
yield return new CodeInstruction(OpCodes.Ldc_I4, 512);
}
else
{
yield return instr;
}
}
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(BuildTool_Addon), nameof(BuildTool_Addon.CheckBuildConditions))]
[HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.CheckBuildConditions))]
[HarmonyPatch(typeof(BuildTool_Dismantle), nameof(BuildTool_Dismantle.DetermineMoreChainTargets))]
[HarmonyPatch(typeof(BuildTool_Dismantle), nameof(BuildTool_Dismantle.DeterminePreviews))]
[HarmonyPatch(typeof(BuildTool_Inserter), nameof(BuildTool_Inserter.CheckBuildConditions))]
[HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path.CheckBuildConditions))]
[HarmonyPatch(typeof(BuildTool_Reform), nameof(BuildTool_Reform.ReformAction))]
[HarmonyPatch(typeof(BuildTool_Upgrade), nameof(BuildTool_Upgrade.DetermineMoreChainTargets))]
[HarmonyPatch(typeof(BuildTool_Upgrade), nameof(BuildTool_Upgrade.DeterminePreviews))]
private static IEnumerable<CodeInstruction> BuildAreaLimitRemoval_Transpiler(
IEnumerable<CodeInstruction> instructions)
{
if (!RemoveBuildRangeLimit)
{
foreach (var instr in instructions)
{
yield return instr;
}
}
else
{
/* Patch (player.mecha.buildArea * player.mecha.buildArea) to 100000000 */
var ilist = instructions.ToList();
var count = ilist.Count - 8;
int i;
for (i = 0; i < count; i++)
{
var found = false;
while (true)
{
var instr = ilist[i + 1];
if (instr.opcode != OpCodes.Call ||
!instr.OperandIs(AccessTools.Method(typeof(BuildTool), "get_player")))
{
break;
}
instr = ilist[i + 2];
if (instr.opcode != OpCodes.Callvirt ||
!instr.OperandIs(AccessTools.Method(typeof(Player), "get_mecha")))
{
break;
}
instr = ilist[i + 3];
if (instr.opcode != OpCodes.Ldfld ||
!instr.OperandIs(AccessTools.Field(typeof(Mecha), "buildArea")))
{
break;
}
instr = ilist[i + 5];
if (instr.opcode != OpCodes.Call ||
!instr.OperandIs(AccessTools.Method(typeof(BuildTool), "get_player")))
{
break;
}
instr = ilist[i + 6];
if (instr.opcode != OpCodes.Callvirt ||
!instr.OperandIs(AccessTools.Method(typeof(Player), "get_mecha")))
{
break;
}
instr = ilist[i + 7];
if (instr.opcode != OpCodes.Ldfld ||
!instr.OperandIs(AccessTools.Field(typeof(Mecha), "buildArea")))
{
break;
}
instr = ilist[i + 8];
if (instr.opcode != OpCodes.Mul)
{
break;
}
found = true;
yield return new CodeInstruction(OpCodes.Ldc_R4, 100000000.0f);
break;
}
if (found)
{
i += 8;
}
else
{
yield return ilist[i];
}
}
for (; i < ilist.Count; i++)
{
yield return ilist[i];
}
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIReplicatorWindow), "OnOkButtonClick")]
private static IEnumerable<CodeInstruction> UIReplicatorWindow_OnOkButtonClick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
if (!EnhancedMechaForgeCountControl) return instructions;
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldc_I4_S, 10)
).Set(OpCodes.Ldc_I4, 1000);
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIReplicatorWindow), "OnPlusButtonClick")]
[HarmonyPatch(typeof(UIReplicatorWindow), "OnMinusButtonClick")]
private static IEnumerable<CodeInstruction> UIReplicatorWindow_OnPlusButtonClick_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
if (!EnhancedMechaForgeCountControl) return instructions;
var label1 = generator.DefineLabel();
var label2 = generator.DefineLabel();
var label3 = generator.DefineLabel();
var label4 = generator.DefineLabel();
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldloc_0),
new CodeMatch(OpCodes.Ldc_I4_1),
new CodeMatch(o => o.opcode == OpCodes.Add || o.opcode == OpCodes.Sub)
).Advance(1).RemoveInstruction().InsertAndAdvance(
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), "control")),
new CodeInstruction(OpCodes.Brfalse_S, label1),
new CodeInstruction(OpCodes.Ldc_I4_S, 10),
new CodeInstruction(OpCodes.Br_S, label4),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), "shift")).WithLabels(label1),
new CodeInstruction(OpCodes.Brfalse_S, label2),
new CodeInstruction(OpCodes.Ldc_I4_S, 100),
new CodeInstruction(OpCodes.Br_S, label4),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(VFInput), "alt")).WithLabels(label2),
new CodeInstruction(OpCodes.Brfalse_S, label3),
new CodeInstruction(OpCodes.Ldc_I4, 1000),
new CodeInstruction(OpCodes.Br_S, label4),
new CodeInstruction(OpCodes.Ldc_I4_1).WithLabels(label3)
).Labels.Add(label4);
return matcher.InstructionEnumeration();
}
[HarmonyPrefix, HarmonyPatch(typeof(StorageComponent), "LoadStatic")]
private static bool StorageComponent_LoadStatic_Prefix()
{
if (StorageComponent.staticLoaded) return false;
if (InventoryStackMultiplier <= 1) return true;
foreach (var proto in LDB.items.dataArray)
{
proto.StackSize *= InventoryStackMultiplier;
}
return true;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(Mecha), nameof(Mecha.SetForNewGame))]
private static IEnumerable<CodeInstruction> Mecha_SetForNewGame_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
if (InventoryStackMultiplier <= 1) return instructions;
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldc_I4, 1210),
new CodeMatch(OpCodes.Ldc_I4_S, 20)
).Advance(1).Set(OpCodes.Ldc_I4_S, 20 * InventoryStackMultiplier);
return matcher.InstructionEnumeration();
}
[HarmonyPostfix, HarmonyPatch(typeof(StorageComponent), "Import")]
private static void StorageComponent_Import_Postfix(StorageComponent __instance)
{
if (InventoryStackMultiplier <= 1) return;
var size = __instance.size;
if (size <= 0) return;
if (__instance.type == EStorageType.Filtered)
{
if (__instance.grids[0].itemId == 1210)
{
__instance.grids[0].stackSize = 20 * InventoryStackMultiplier;
}
return;
}
for (var i = 0; i < size; i++)
{
var itemId = __instance.grids[i].itemId;
if (itemId != 0)
{
__instance.grids[i].stackSize = StorageComponent.itemStackCount[itemId];
}
}
}
}

View File

@@ -6,7 +6,7 @@
<AssemblyName>MechaDronesTweaks</AssemblyName>
<BepInExPluginGuid>org.soardev.mechadronestweaks</BepInExPluginGuid>
<Description>DSP MOD - MechaDronesTweaks</Description>
<Version>1.1.1</Version>
<Version>1.1.2</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

View File

@@ -5,11 +5,14 @@
## Updates
* 1.1.2
+ `RemoveBuildRangeLimit`, `LargerAreaForUpgradeAndDismantle` and `LargerAreaForTerraform` are moved to [UXAssist](https://dsp.thunderstore.io/package/soarqin/UXAssist)
* 1.1.1
* Fixed crash in `LargeAreaForTerraform` functions.
+ Fixed crash in `LargeAreaForTerraform` functions.
* 1.1.0
* Added `RemoveBuildRangeLimit`, `LargerAreaForUpgradeAndDismantle` and `LargerAreaForTerraform` options (Check Usage for details).
+ Added `RemoveBuildRangeLimit`, `LargerAreaForUpgradeAndDismantle` and `LargerAreaForTerraform` options (Check Usage for details).
## Usage
* Inspired by [FastDrones](https://dsp.thunderstore.io/package/dkoppstein/FastDrones/), but patching IL codes, consuming less CPU to reduce lags on massive builds especially blueprints' put.
@@ -26,14 +29,19 @@
* `FixedSpeed` [Default Value: 300]: Fixed flying speed for mecha drones.
* `SpeedMultiplier` [Default Value: 4]: Speed multiplier for mecha drones.
* `EnergyMultiplier` [Default Value: 0.1]: Energy consumption multiplier for mecha drones.
* `[MechaBuild]`
* `RemoveBuildRangeLimit` [Default Value: true]: Remove limit for build range and maximum count of drag building belts/buildings.
* Note: this does not affect range limit for mecha drones' action
* `LargerAreaForUpgradeAndDismantle` [Default Value: true]: Increase maximum area size for upgrade and dismantle to 31x31 (from 11x11).
* `LargerAreaForTerraform` [Default Value: true]: Increase maximum area size for terraform to 30x30 (from 10x10).
* Note: this may impact game performance while using large area.
* Note: This MOD will disable `FastDrones` if the MOD is installed, to avoid conflict in functions.
## 更新日志
* 1.1.2
+ `RemoveBuildRangeLimit`, `LargerAreaForUpgradeAndDismantle``LargerAreaForTerraform` 移动到了 MOD [UXAssist](https://dsp.thunderstore.io/package/soarqin/UXAssist) 中
* 1.1.1
+ 修复了 `LargeAreaForTerraform` 功能可能导致崩溃的问题。
* 1.1.0
+ 添加了 `RemoveBuildRangeLimit`, `LargerAreaForUpgradeAndDismantle``LargerAreaForTerraform` 选项 (详情见使用说明)。
## 使用说明
* 功能参考 [FastDrones](https://dsp.thunderstore.io/package/dkoppstein/FastDrones/)但主要对IL代码进行Patch因此消耗更少的CPU尤其在大规模建造比如放置蓝图的时候可以大大减少卡顿。
* 不影响当前游戏存档:
@@ -49,10 +57,4 @@
* `FixedSpeed` [默认值: 300]: 固定速度。
* `SpeedMultiplier` [默认值: 4]: 速度倍数。
* `EnergyMultiplier` [默认值: 0.1]: 能量消耗倍数。
* `[MechaBuild]`
* `RemoveBuildRangeLimit` [默认值: true]: 解除摆放建筑距离和拖放建筑/传送带数量的限制。
* 注意: 并不会解除建设机行动的距离限制。
* `LargerAreaForUpgradeAndDismantle` [默认值: true]: 提升区域升级和拆除建筑的最大区域至31x31 (之前是11x11)。
* `LargerAreaForTerraform` [默认值: true]: 提升区域铺设地地基的最大区域至30x30 (之前是10x10)。
* 注意: 使用较大的区域可能对游戏实时性能有影响。
* 说明: 如果安装了`FastDrones`本MOD会将其禁用避免功能冲突。

View File

@@ -1,6 +1,6 @@
{
"name": "MechaDronesTweaks",
"version_number": "1.1.1",
"version_number": "1.1.2",
"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": [