mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 12:53:34 +08:00
UXAssist v1.0.4
This commit is contained in:
@@ -15,6 +15,7 @@ public static class FactoryPatch
|
||||
public static ConfigEntry<bool> RemoveBuildRangeLimitEnabled;
|
||||
public static ConfigEntry<bool> LargerAreaForUpgradeAndDismantleEnabled;
|
||||
public static ConfigEntry<bool> LargerAreaForTerraformEnabled;
|
||||
public static ConfigEntry<bool> OffGridBuildingEnabled;
|
||||
|
||||
private static Harmony _factoryPatch;
|
||||
|
||||
@@ -26,12 +27,14 @@ public static class FactoryPatch
|
||||
RemoveBuildRangeLimitEnabled.SettingChanged += (_, _) => RemoveBuildRangeLimit.Enable(RemoveBuildRangeLimitEnabled.Value);
|
||||
LargerAreaForUpgradeAndDismantleEnabled.SettingChanged += (_, _) => LargerAreaForUpgradeAndDismantle.Enable(LargerAreaForUpgradeAndDismantleEnabled.Value);
|
||||
LargerAreaForTerraformEnabled.SettingChanged += (_, _) => LargerAreaForTerraform.Enable(LargerAreaForTerraformEnabled.Value);
|
||||
OffGridBuildingEnabled.SettingChanged += (_, _) => OffGridBuilding.Enable(OffGridBuildingEnabled.Value);
|
||||
UnlimitInteractive.Enable(UnlimitInteractiveEnabled.Value);
|
||||
RemoveSomeConditionBuild.Enable(RemoveSomeConditionEnabled.Value);
|
||||
NightLight.Enable(NightLightEnabled.Value);
|
||||
RemoveBuildRangeLimit.Enable(RemoveBuildRangeLimitEnabled.Value);
|
||||
LargerAreaForUpgradeAndDismantle.Enable(LargerAreaForUpgradeAndDismantleEnabled.Value);
|
||||
LargerAreaForTerraform.Enable(LargerAreaForTerraformEnabled.Value);
|
||||
OffGridBuilding.Enable(OffGridBuildingEnabled.Value);
|
||||
|
||||
_factoryPatch ??= Harmony.CreateAndPatchAll(typeof(FactoryPatch));
|
||||
}
|
||||
@@ -44,6 +47,7 @@ public static class FactoryPatch
|
||||
RemoveBuildRangeLimit.Enable(false);
|
||||
LargerAreaForUpgradeAndDismantle.Enable(false);
|
||||
LargerAreaForTerraform.Enable(false);
|
||||
OffGridBuilding.Enable(false);
|
||||
|
||||
_factoryPatch?.UnpatchSelf();
|
||||
_factoryPatch = null;
|
||||
@@ -519,4 +523,147 @@ public static class FactoryPatch
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
|
||||
public class OffGridBuilding
|
||||
{
|
||||
private static Harmony _patch;
|
||||
private const float SteppedRotationDegrees = 15f;
|
||||
|
||||
public static void Enable(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
_patch ??= Harmony.CreateAndPatchAll(typeof(OffGridBuilding));
|
||||
return;
|
||||
}
|
||||
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
private static void MatchIgnoreGridAndCheckIfRotatable(CodeMatcher matcher, out Label? ifBlockEntryLabel, out Label? elseBlockEntryLabel)
|
||||
{
|
||||
Label? thisIfBlockEntryLabel = null;
|
||||
Label? thisElseBlockEntryLabel = null;
|
||||
|
||||
matcher.MatchForward(
|
||||
false
|
||||
, new CodeMatch(ci => ci.Calls(AccessTools.PropertyGetter(typeof(VFInput), nameof(VFInput._ignoreGrid))))
|
||||
, new CodeMatch(ci => ci.Branches(out thisElseBlockEntryLabel))
|
||||
, new CodeMatch(ci => ci.IsLdarg())
|
||||
, new CodeMatch(OpCodes.Ldfld)
|
||||
, new CodeMatch(OpCodes.Ldfld)
|
||||
, new CodeMatch(ci => ci.LoadsConstant(EMinerType.Vein))
|
||||
, new CodeMatch(ci => ci.Branches(out thisIfBlockEntryLabel))
|
||||
, new CodeMatch(ci => ci.IsLdarg())
|
||||
, new CodeMatch(OpCodes.Ldfld)
|
||||
, new CodeMatch(OpCodes.Ldfld)
|
||||
, new CodeMatch(ci => ci.Branches(out _))
|
||||
);
|
||||
|
||||
ifBlockEntryLabel = thisIfBlockEntryLabel;
|
||||
elseBlockEntryLabel = thisElseBlockEntryLabel;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.UpdateRaycast))]
|
||||
[HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.DeterminePreviews))]
|
||||
public static IEnumerable<CodeInstruction> AllowOffGridConstruction(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
|
||||
MatchIgnoreGridAndCheckIfRotatable(matcher, out var entryLabel, out _);
|
||||
|
||||
if (matcher.IsInvalid)
|
||||
return instructions;
|
||||
|
||||
matcher.Advance(2);
|
||||
matcher.Insert(new CodeInstruction(OpCodes.Br, entryLabel.Value));
|
||||
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(BuildTool_Click), nameof(BuildTool_Click.DeterminePreviews))]
|
||||
public static IEnumerable<CodeInstruction> PreventDraggingWhenOffGrid(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
|
||||
Label? exitLabel = null;
|
||||
|
||||
matcher.MatchForward(
|
||||
false
|
||||
, new CodeMatch(ci => ci.Branches(out exitLabel))
|
||||
, new CodeMatch(OpCodes.Ldarg_0)
|
||||
, new CodeMatch(ci => ci.LoadsConstant(1))
|
||||
, new CodeMatch(ci => ci.StoresField(AccessTools.Field(typeof(BuildTool_Click), nameof(BuildTool_Click.isDragging))))
|
||||
);
|
||||
|
||||
if (matcher.IsInvalid)
|
||||
return instructions;
|
||||
|
||||
matcher.Advance(1);
|
||||
matcher.Insert(
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(VFInput), nameof(VFInput._ignoreGrid)))
|
||||
, new CodeInstruction(OpCodes.Brtrue, exitLabel)
|
||||
);
|
||||
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
public static IEnumerable<CodeInstruction> PatchToPerformSteppedRotate(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
|
||||
MatchIgnoreGridAndCheckIfRotatable(matcher, out var ifBlockEntryLabel, out var elseBlockEntryLabel);
|
||||
|
||||
if (matcher.IsInvalid)
|
||||
return instructions;
|
||||
|
||||
while (!matcher.Labels.Contains(elseBlockEntryLabel.Value))
|
||||
matcher.Advance(1);
|
||||
|
||||
Label? ifBlockExitLabel = null;
|
||||
|
||||
matcher.MatchBack(false, new CodeMatch(ci => ci.Branches(out ifBlockExitLabel)));
|
||||
|
||||
if (matcher.IsInvalid)
|
||||
return instructions;
|
||||
|
||||
while (!matcher.Labels.Contains(ifBlockEntryLabel.Value))
|
||||
matcher.Advance(-1);
|
||||
|
||||
var instructionToClone = matcher.Instruction.Clone();
|
||||
var overwriteWith = CodeInstruction.LoadField(typeof(VFInput), nameof(VFInput.control));
|
||||
|
||||
matcher.SetAndAdvance(overwriteWith.opcode, overwriteWith.operand);
|
||||
matcher.Insert(instructionToClone);
|
||||
matcher.CreateLabel(out var existingEntryLabel);
|
||||
matcher.InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Brfalse, existingEntryLabel)
|
||||
, new CodeInstruction(OpCodes.Ldarg_0)
|
||||
, CodeInstruction.Call(typeof(OffGridBuilding), nameof(OffGridBuilding.RotateStepped))
|
||||
, new CodeInstruction(OpCodes.Br, ifBlockExitLabel)
|
||||
);
|
||||
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
public static void RotateStepped(BuildTool_Click instance)
|
||||
{
|
||||
if (VFInput._rotate.onDown)
|
||||
{
|
||||
instance.yaw += SteppedRotationDegrees;
|
||||
instance.yaw = Mathf.Repeat(instance.yaw, 360f);
|
||||
instance.yaw = Mathf.Round(instance.yaw / SteppedRotationDegrees) * SteppedRotationDegrees;
|
||||
}
|
||||
|
||||
if (VFInput._counterRotate.onDown)
|
||||
{
|
||||
instance.yaw -= SteppedRotationDegrees;
|
||||
instance.yaw = Mathf.Repeat(instance.yaw, 360f);
|
||||
instance.yaw = Mathf.Round(instance.yaw / SteppedRotationDegrees) * SteppedRotationDegrees;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user