1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2026-02-04 19:42:17 +08:00

WIP for UXAssist new features

This commit is contained in:
2025-04-13 20:05:20 +08:00
parent cdd71006b8
commit 5674d601ec
7 changed files with 302 additions and 112 deletions

View File

@@ -34,6 +34,11 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
public static ConfigEntry<bool> TankFastFillInAndTakeOutEnabled;
public static ConfigEntry<int> TankFastFillInAndTakeOutMultiplier;
public static ConfigEntry<bool> CutConveyorBeltEnabled;
public static ConfigEntry<bool> TweakBuildingBufferEnabled;
public static ConfigEntry<int> ReceiverBufferCount;
public static ConfigEntry<int> AssemblerBufferTimeMultiplier;
public static ConfigEntry<int> AssemblerBufferMininumMultiplier;
private static PressKeyBind _doNotRenderEntitiesKey;
private static PressKeyBind _offgridfForPathsKey;
private static PressKeyBind _cutConveyorBeltKey;
@@ -43,30 +48,30 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
public static void Init()
{
_doNotRenderEntitiesKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
{
key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true),
conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND,
name = "ToggleDoNotRenderEntities",
canOverride = true
}
{
key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true),
conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND,
name = "ToggleDoNotRenderEntities",
canOverride = true
}
);
I18N.Add("KEYToggleDoNotRenderEntities", "Toggle Do Not Render Factory Entities", "切换不渲染工厂建筑实体");
_offgridfForPathsKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
{
key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true),
conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.UI | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND,
name = "OffgridForPaths",
canOverride = true
}
{
key = new CombineKey(0, 0, ECombineKeyAction.OnceClick, true),
conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.UI | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND,
name = "OffgridForPaths",
canOverride = true
}
);
I18N.Add("KEYOffgridForPaths", "Build belts offgrid", "脱离网格建造传送带");
_cutConveyorBeltKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
{
key = new CombineKey((int)KeyCode.X, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false),
conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND,
name = "CutConveyorBelt",
canOverride = true
}
{
key = new CombineKey((int)KeyCode.X, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false),
conflictGroup = KeyBindConflict.MOVEMENT | KeyBindConflict.FLYING | KeyBindConflict.SAILING | KeyBindConflict.BUILD_MODE_1 | KeyBindConflict.KEYBOARD_KEYBIND,
name = "CutConveyorBelt",
canOverride = true
}
);
I18N.Add("KEYCutConveyorBelt", "Cut conveyor belt", "切割传送带");
@@ -89,8 +94,12 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
DragBuildPowerPolesAlternatelyEnabled.SettingChanged += (_, _) => DragBuildPowerPoles.AlternatelyChanged();
BeltSignalsForBuyOutEnabled.SettingChanged += (_, _) => BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
TankFastFillInAndTakeOutEnabled.SettingChanged += (_, _) => TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value);
TankFastFillInAndTakeOutMultiplier.SettingChanged += (_, _) => { UpdateTankFastFillInAndTakeOutMultiplierRealValue(); };
TankFastFillInAndTakeOutMultiplier.SettingChanged += (_, _) => UpdateTankFastFillInAndTakeOutMultiplierRealValue();
CutConveyorBeltEnabled.SettingChanged += (_, _) => CutConveyorBelt.Enable(CutConveyorBeltEnabled.Value);
TweakBuildingBufferEnabled.SettingChanged += (_, _) => TweakBuildingBuffer.Enable(TweakBuildingBufferEnabled.Value);
AssemblerBufferTimeMultiplier.SettingChanged += (_, _) => TweakBuildingBuffer.RefreshAssemblerBufferMultipliers();
AssemblerBufferMininumMultiplier.SettingChanged += (_, _) => TweakBuildingBuffer.RefreshAssemblerBufferMultipliers();
ReceiverBufferCount.SettingChanged += (_, _) => TweakBuildingBuffer.RefreshReceiverBufferCount();
}
public static void Start()
@@ -110,6 +119,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
BeltSignalsForBuyOut.Enable(BeltSignalsForBuyOutEnabled.Value);
TankFastFillInAndTakeOut.Enable(TankFastFillInAndTakeOutEnabled.Value);
CutConveyorBelt.Enable(CutConveyorBeltEnabled.Value);
TweakBuildingBuffer.Enable(TweakBuildingBufferEnabled.Value);
Enable(true);
UpdateTankFastFillInAndTakeOutMultiplierRealValue();
@@ -119,6 +129,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
{
Enable(false);
TweakBuildingBuffer.Enable(false);
CutConveyorBelt.Enable(false);
TankFastFillInAndTakeOut.Enable(false);
BeltSignalsForBuyOut.Enable(false);
@@ -234,7 +245,7 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
_sail = null;
_nightlightInitialized = false;
}
private static void GameMain_End_Postfix()
{
if (_sunlight)
@@ -705,13 +716,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
return matcher.InstructionEnumeration();
}
private static bool CheckOffgridForPathsKeyPressed()
{
ref var bind = ref _offgridfForPathsKey.defaultBind;
ref var key = ref VFInput.override_keys[bind.id];
return key.IsNull() ? bind.key.GetKey() : key.GetKey();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(BuildTool_Path), nameof(BuildTool_Path.UpdateRaycast))]
public static IEnumerable<CodeInstruction> AllowOffGridConstructionForPath(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
@@ -736,7 +740,8 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
var jmp0 = generator.DefineLabel();
var jmp1 = generator.DefineLabel();
matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(OffGridBuilding), nameof(CheckOffgridForPathsKeyPressed))),
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(FactoryPatch), nameof(_offgridfForPathsKey))),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))),
new CodeInstruction(OpCodes.Brfalse, jmp0),
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldarg_0),
@@ -1963,12 +1968,10 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
private class CutConveyorBelt : PatchImpl<CutConveyorBelt>
{
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerController), nameof(PlayerController.GameTick))]
private static void PlayerController_GameTick_Postfix(PlayerController __instance)
{
if (DSPGame.IsMenuDemo) return;
if (!_cutConveyorBeltKey.keyValue) return;
var raycast = __instance.cmd.raycast;
if (raycast == null) return;
@@ -1979,4 +1982,83 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
Functions.FactoryFunctions.CutConveyorBelt(cargoTraffic, beltId);
}
}
}
private class TweakBuildingBuffer : PatchImpl<TweakBuildingBuffer>
{
public static void RefreshReceiverBufferCount()
{
if (!TweakBuildingBufferEnabled.Value) return;
/* re-patch to use new value */
var patch = Instance._patch;
patch.Unpatch(AccessTools.Method(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.GameTick_Gamma)), AccessTools.Method(typeof(TweakBuildingBuffer), nameof(PowerGeneratorComponent_GameTick_Gamma_Transpiler)));
patch.Patch(AccessTools.Method(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.GameTick_Gamma)), null, null, new HarmonyMethod(typeof(TweakBuildingBuffer), nameof(PowerGeneratorComponent_GameTick_Gamma_Transpiler)));
}
public static void RefreshAssemblerBufferMultipliers()
{
if (!TweakBuildingBufferEnabled.Value) return;
/* re-patch to use new value */
var patch = Instance._patch;
patch.Unpatch(AccessTools.Method(typeof(AssemblerComponent), nameof(AssemblerComponent.UpdateNeeds)), AccessTools.Method(typeof(TweakBuildingBuffer), nameof(AssemblerComponent_UpdateNeeds_Transpiler)));
patch.Patch(AccessTools.Method(typeof(AssemblerComponent), nameof(AssemblerComponent.UpdateNeeds)), null, null, new HarmonyMethod(typeof(TweakBuildingBuffer), nameof(AssemblerComponent_UpdateNeeds_Transpiler)));
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.GameTick_Gamma))]
private static IEnumerable<CodeInstruction> PowerGeneratorComponent_GameTick_Gamma_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
/*
* Patch:
* bool flag3 = keyFrame && useIon && (float)this.catalystPoint < 72000f;
* To:
* bool flag3 = keyFrame && useIon && this.catalystPoint < 3600 * ReceiverBufferCount.Value;
*/
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PowerGeneratorComponent), nameof(PowerGeneratorComponent.catalystPoint))),
new CodeMatch(OpCodes.Conv_R4),
new CodeMatch(OpCodes.Ldc_R4, 72000f),
new CodeMatch(OpCodes.Clt)
);
matcher.Advance(2).RemoveInstructions(2).Insert(new CodeInstruction(OpCodes.Ldc_I4, ReceiverBufferCount.Value * 3600));
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(AssemblerComponent), nameof(AssemblerComponent.UpdateNeeds))]
private static IEnumerable<CodeInstruction> AssemblerComponent_UpdateNeeds_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
/*
* Patch:
* int num2 = this.speedOverride * 180 / this.timeSpend + 1;
* if (num2 < 2)
* {
* num2 = 2;
* }
* To:
* int num2 = this.speedOverride * 60 * (AssemblerBufferTimeMultiplier.Value - 1) * 60 / this.timeSpend + 1;
* if (num2 < AssemblerBufferMininumMultiplier.Value)
* {
* num2 = AssemblerBufferMininumMultiplier.Value;
* }
*/
var matcher = new CodeMatcher(instructions, generator);
matcher.MatchForward(false,
new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(AssemblerComponent), nameof(AssemblerComponent.speedOverride))),
new CodeMatch(OpCodes.Ldc_I4, 180),
new CodeMatch(OpCodes.Mul)
);
matcher.Advance(2).Operand = (AssemblerBufferTimeMultiplier.Value - 1) * 60;
matcher.Advance(2).MatchForward(false,
new CodeMatch(OpCodes.Ldc_I4_2),
new CodeMatch(ci => ci.opcode == OpCodes.Bge_S || ci.opcode == OpCodes.Bge),
new CodeMatch(OpCodes.Ldc_I4_2)
);
matcher.Operand = AssemblerBufferMininumMultiplier.Value;
matcher.Advance(2).Operand = AssemblerBufferMininumMultiplier.Value;
return matcher.InstructionEnumeration();
}
}
}

View File

@@ -8,7 +8,7 @@ using UXAssist.Common;
namespace UXAssist.Patches;
public static class PlayerPatch
public class PlayerPatch: PatchImpl<PlayerPatch>
{
public static ConfigEntry<bool> EnhancedMechaForgeCountControlEnabled;
public static ConfigEntry<bool> HideTipsForSandsChangesEnabled;
@@ -17,7 +17,8 @@ public static class PlayerPatch
public static ConfigEntry<bool> AutoBoostEnabled;
public static ConfigEntry<double> DistanceToWarp;
private static PressKeyBind _autoDriveKey;
private static PressKeyBind _showAllAstrosNameKey;
public static void Init()
{
_autoDriveKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
@@ -27,8 +28,20 @@ public static class PlayerPatch
name = "ToggleAutoCruise",
canOverride = true
});
I18N.Add("KEYToggleAutoCruise", "Toggle auto-cruise", "切换自动巡航");
I18N.Add("AutoCruiseOn", "Auto-cruise enabled", "已启用自动巡航");
I18N.Add("AutoCruiseOff", "Auto-cruise disabled", "已禁用自动巡航");
_showAllAstrosNameKey = KeyBindings.RegisterKeyBinding(new BuiltinKey
{
key = new CombineKey(0, CombineKey.ALT_COMB, ECombineKeyAction.OnceClick, false),
conflictGroup = KeyBindConflict.UI | KeyBindConflict.KEYBOARD_KEYBIND,
name = "ShowAllAstrosName",
canOverride = true
}
);
I18N.Add("KEYShowAllAstrosName", "Keep pressing to show all astros' name", "按住显示所有星球名称");
EnhancedMechaForgeCountControlEnabled.SettingChanged += (_, _) => EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value);
HideTipsForSandsChangesEnabled.SettingChanged += (_, _) => HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value);
AutoNavigationEnabled.SettingChanged += (_, _) => AutoNavigation.Enable(AutoNavigationEnabled.Value);
@@ -39,6 +52,7 @@ public static class PlayerPatch
EnhancedMechaForgeCountControl.Enable(EnhancedMechaForgeCountControlEnabled.Value);
HideTipsForSandsChanges.Enable(HideTipsForSandsChangesEnabled.Value);
AutoNavigation.Enable(AutoNavigationEnabled.Value);
Enable(true);
}
public static void OnUpdate()
@@ -48,14 +62,35 @@ public static class PlayerPatch
AutoNavigation.ToggleAutoCruise();
}
}
public static void Uninit()
{
Enable(false);
EnhancedMechaForgeCountControl.Enable(false);
HideTipsForSandsChanges.Enable(false);
AutoNavigation.Enable(false);
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(UIStarmapStar), nameof(UIStarmapStar._OnLateUpdate))]
private static IEnumerable<CodeInstruction> UIStarmapStar__OnLateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
var matcher = new CodeMatcher(instructions, generator);
Label? br = null;
matcher.MatchForward(false,
new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(UIStarmapStar), nameof(UIStarmapStar.projectedCoord))),
new CodeMatch(ci => ci.IsLdloc()),
new CodeMatch(ci => ci.Branches(out br))
);
matcher.Advance(3);
matcher.InsertAndAdvance(
new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PlayerPatch), nameof(_showAllAstrosNameKey))),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(KeyBindings), nameof(KeyBindings.IsKeyPressing))),
new CodeInstruction(OpCodes.Brtrue, br.Value)
);
return matcher.InstructionEnumeration();
}
private class EnhancedMechaForgeCountControl: PatchImpl<EnhancedMechaForgeCountControl>
{
[HarmonyTranspiler]
@@ -319,7 +354,7 @@ public static class PlayerPatch
);
return matcher.InstructionEnumeration();
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(VFInput), nameof(VFInput._sailSpeedUp), MethodType.Getter)]
private static IEnumerable<CodeInstruction> VFInput_sailSpeedUp_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
@@ -335,7 +370,7 @@ public static class PlayerPatch
return matcher.InstructionEnumeration();
}
/* Disable Lock Cursor Mode on entering sail panel
/* Disable Lock Cursor Mode on entering sail panel
[HarmonyPrefix]
[HarmonyPatch(typeof(UISailPanel), nameof(UISailPanel._OnOpen))]
public static void OnOpen_Prefix()