mirror of
https://github.com/soarqin/DSP_Mods_TO.git
synced 2025-12-14 18:43:29 +08:00
Added CruiseAssist and AutoPilot
This commit is contained in:
30
CruiseAssist/Patches/Patch_GameMain.cs
Normal file
30
CruiseAssist/Patches/Patch_GameMain.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using CruiseAssist.Commons;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CruiseAssist.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(GameMain))]
|
||||
internal class Patch_GameMain
|
||||
{
|
||||
[HarmonyPatch("Begin")]
|
||||
[HarmonyPostfix]
|
||||
public static void Begin_Postfix()
|
||||
{
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.GameMainBegin);
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.CheckConfig(ConfigManager.Step.GameMainBegin.ToString());
|
||||
});
|
||||
}
|
||||
|
||||
[HarmonyPatch("Pause")]
|
||||
[HarmonyPrefix]
|
||||
public static void Pause_Prefix()
|
||||
{
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.CheckConfig(ConfigManager.Step.State.ToString());
|
||||
});
|
||||
}
|
||||
}
|
||||
31
CruiseAssist/Patches/Patch_PlayerMoveDrift.cs
Normal file
31
CruiseAssist/Patches/Patch_PlayerMoveDrift.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CruiseAssist.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(PlayerMove_Drift))]
|
||||
internal class Patch_PlayerMoveDrift
|
||||
{
|
||||
[HarmonyPatch("GameTick")]
|
||||
[HarmonyPrefix]
|
||||
public static void GameTick_Prefix(PlayerMove_Drift __instance)
|
||||
{
|
||||
if (!CruiseAssistPlugin.Enable) return;
|
||||
if (!CruiseAssistPlugin.TargetSelected) return;
|
||||
if (__instance.controller.movementStateInFrame != EMovementState.Drift) return;
|
||||
if (VFInput._moveForward.pressing || VFInput._pullUp.pressing)
|
||||
{
|
||||
CruiseAssistPlugin.Interrupt = true;
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.CancelOperate();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.OperateDrift(__instance);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
31
CruiseAssist/Patches/Patch_PlayerMoveFly.cs
Normal file
31
CruiseAssist/Patches/Patch_PlayerMoveFly.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CruiseAssist.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(PlayerMove_Fly))]
|
||||
internal class Patch_PlayerMoveFly
|
||||
{
|
||||
[HarmonyPatch("GameTick")]
|
||||
[HarmonyPrefix]
|
||||
public static void GameTick_Prefix(PlayerMove_Fly __instance)
|
||||
{
|
||||
if (!CruiseAssistPlugin.Enable) return;
|
||||
if (!CruiseAssistPlugin.TargetSelected) return;
|
||||
if (__instance.controller.movementStateInFrame != EMovementState.Fly) return;
|
||||
if (VFInput._moveForward.pressing || VFInput._pullUp.pressing)
|
||||
{
|
||||
CruiseAssistPlugin.Interrupt = true;
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.CancelOperate();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.OperateFly(__instance);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
51
CruiseAssist/Patches/Patch_PlayerMoveSail.cs
Normal file
51
CruiseAssist/Patches/Patch_PlayerMoveSail.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CruiseAssist.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(PlayerMove_Sail))]
|
||||
internal class Patch_PlayerMoveSail
|
||||
{
|
||||
[HarmonyPatch("GameTick")]
|
||||
[HarmonyPrefix]
|
||||
public static void GameTick_Prefix(PlayerMove_Sail __instance)
|
||||
{
|
||||
if (!CruiseAssistPlugin.Enable) return;
|
||||
if (!CruiseAssistPlugin.TargetSelected) return;
|
||||
var player = __instance.player;
|
||||
if (!player.sailing) return;
|
||||
var controller = player.controller;
|
||||
if (controller.input0 != Vector4.zero || controller.input1 != Vector4.zero)
|
||||
{
|
||||
CruiseAssistPlugin.Interrupt = true;
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.CancelOperate();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CruiseAssistPlugin.TargetPlanet != null)
|
||||
{
|
||||
CruiseAssistPlugin.TargetUPos = CruiseAssistPlugin.TargetPlanet.uPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CruiseAssistPlugin.TargetStar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CruiseAssistPlugin.TargetUPos = CruiseAssistPlugin.TargetStar.uPosition;
|
||||
}
|
||||
var operate = false;
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
operate |= extension.OperateSail(__instance);
|
||||
});
|
||||
if (operate) return;
|
||||
var vec = CruiseAssistPlugin.TargetUPos - player.uPosition;
|
||||
var magnitude = controller.actionSail.visual_uvel.magnitude;
|
||||
player.uVelocity = Vector3.Slerp(player.uVelocity, vec.normalized * magnitude, 1.6f / Mathf.Max(10f, Vector3.Angle(vec, player.uVelocity)));
|
||||
}
|
||||
}
|
||||
}
|
||||
161
CruiseAssist/Patches/Patch_PlayerMoveWalk.cs
Normal file
161
CruiseAssist/Patches/Patch_PlayerMoveWalk.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using System.Linq;
|
||||
using CruiseAssist.Commons;
|
||||
using CruiseAssist.Enums;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CruiseAssist.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(PlayerMove_Walk))]
|
||||
internal class Patch_PlayerMoveWalk
|
||||
{
|
||||
[HarmonyPatch("GameTick")]
|
||||
[HarmonyPrefix]
|
||||
public static void GameTick_Prefix(PlayerMove_Walk __instance)
|
||||
{
|
||||
CruiseAssistPlugin.State = CruiseAssistState.Inactive;
|
||||
CruiseAssistPlugin.Interrupt = false;
|
||||
CruiseAssistPlugin.TargetStar = null;
|
||||
CruiseAssistPlugin.TargetPlanet = null;
|
||||
CruiseAssistPlugin.TargetUPos = VectorLF3.zero;
|
||||
CruiseAssistPlugin.TargetRange = 0.0;
|
||||
CruiseAssistPlugin.TargetSelected = false;
|
||||
if (GameMain.localPlanet != null)
|
||||
{
|
||||
if (CruiseAssistPlugin.History.Count == 0 || CruiseAssistPlugin.History.Last() != GameMain.localPlanet.id)
|
||||
{
|
||||
if (CruiseAssistPlugin.History.Count >= 128)
|
||||
{
|
||||
CruiseAssistPlugin.History.RemoveAt(0);
|
||||
}
|
||||
CruiseAssistPlugin.History.Add(GameMain.localPlanet.id);
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
||||
}
|
||||
}
|
||||
|
||||
if (!CruiseAssistPlugin.Enable)
|
||||
{
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.SetInactive();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var indicatorAstroId = GameMain.mainPlayer.navigation.indicatorAstroId;
|
||||
if (indicatorAstroId != 0 && CruiseAssistPlugin.SelectTargetAstroId != indicatorAstroId)
|
||||
{
|
||||
CruiseAssistPlugin.SelectTargetAstroId = indicatorAstroId;
|
||||
if (indicatorAstroId % 100 != 0)
|
||||
{
|
||||
CruiseAssistPlugin.SelectTargetPlanet = GameMain.galaxy.PlanetById(indicatorAstroId);
|
||||
CruiseAssistPlugin.SelectTargetStar = CruiseAssistPlugin.SelectTargetPlanet.star;
|
||||
}
|
||||
else
|
||||
{
|
||||
CruiseAssistPlugin.SelectTargetPlanet = null;
|
||||
CruiseAssistPlugin.SelectTargetStar = GameMain.galaxy.StarById(indicatorAstroId / 100);
|
||||
}
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.SetTargetAstroId(indicatorAstroId);
|
||||
});
|
||||
}
|
||||
|
||||
if (CruiseAssistPlugin.SelectTargetStar != null)
|
||||
{
|
||||
if (GameMain.localStar != null && CruiseAssistPlugin.SelectTargetStar.id == GameMain.localStar.id)
|
||||
{
|
||||
if (CruiseAssistPlugin.SelectTargetPlanet == null && GameMain.localPlanet != null)
|
||||
{
|
||||
CruiseAssistPlugin.SelectTargetStar = null;
|
||||
CruiseAssistPlugin.SelectTargetAstroId = 0;
|
||||
GameMain.mainPlayer.navigation.indicatorAstroId = 0;
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.SetInactive();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (CruiseAssistPlugin.SelectTargetPlanet != null)
|
||||
{
|
||||
if (GameMain.localPlanet != null && CruiseAssistPlugin.SelectTargetPlanet.id == GameMain.localPlanet.id)
|
||||
{
|
||||
CruiseAssistPlugin.SelectTargetStar = null;
|
||||
CruiseAssistPlugin.SelectTargetPlanet = null;
|
||||
CruiseAssistPlugin.SelectTargetAstroId = 0;
|
||||
GameMain.mainPlayer.navigation.indicatorAstroId = 0;
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.SetInactive();
|
||||
});
|
||||
return;
|
||||
}
|
||||
CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.SelectTargetPlanet;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CruiseAssistPlugin.ReticuleTargetPlanet != null)
|
||||
{
|
||||
CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.ReticuleTargetPlanet;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.SelectTargetStar;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CruiseAssistPlugin.ReticuleTargetPlanet != null)
|
||||
{
|
||||
CruiseAssistPlugin.TargetPlanet = CruiseAssistPlugin.ReticuleTargetPlanet;
|
||||
}
|
||||
else if (CruiseAssistPlugin.ReticuleTargetStar != null)
|
||||
{
|
||||
CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.ReticuleTargetStar;
|
||||
}
|
||||
}
|
||||
|
||||
if (CruiseAssistPlugin.TargetPlanet != null)
|
||||
{
|
||||
CruiseAssistPlugin.State = CruiseAssistState.ToPlanet;
|
||||
CruiseAssistPlugin.TargetStar = CruiseAssistPlugin.TargetPlanet.star;
|
||||
CruiseAssistPlugin.TargetRange = (CruiseAssistPlugin.TargetPlanet.uPosition - GameMain.mainPlayer.uPosition).magnitude - CruiseAssistPlugin.TargetPlanet.realRadius;
|
||||
CruiseAssistPlugin.TargetSelected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CruiseAssistPlugin.TargetStar == null)
|
||||
{
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.SetInactive();
|
||||
});
|
||||
return;
|
||||
}
|
||||
CruiseAssistPlugin.State = CruiseAssistState.ToStar;
|
||||
CruiseAssistPlugin.TargetRange = (CruiseAssistPlugin.TargetStar.uPosition - GameMain.mainPlayer.uPosition).magnitude - (CruiseAssistPlugin.TargetStar.viewRadius - 120f);
|
||||
CruiseAssistPlugin.TargetSelected = true;
|
||||
}
|
||||
var flag18 = __instance.controller.movementStateInFrame > EMovementState.Walk;
|
||||
if (flag18) return;
|
||||
if (VFInput._jump.pressing)
|
||||
{
|
||||
CruiseAssistPlugin.Interrupt = true;
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.CancelOperate();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.OperateWalk(__instance);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
71
CruiseAssist/Patches/Patch_UISailPanel.cs
Normal file
71
CruiseAssist/Patches/Patch_UISailPanel.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using CruiseAssist.Commons;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CruiseAssist.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(UISailPanel))]
|
||||
internal class Patch_UISailPanel
|
||||
{
|
||||
[HarmonyPatch("_OnUpdate")]
|
||||
[HarmonyTranspiler]
|
||||
public static IEnumerable<CodeInstruction> OnUpdate_Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var codeMatcher = new CodeMatcher(instructions);
|
||||
codeMatcher.MatchForward(true, new CodeMatch(OpCodes.Ldarg_0));
|
||||
codeMatcher.InsertAndAdvance(
|
||||
Transpilers.EmitDelegate<Action>(delegate
|
||||
{
|
||||
CruiseAssistPlugin.ReticuleTargetPlanet = null;
|
||||
CruiseAssistPlugin.ReticuleTargetStar = null;
|
||||
})
|
||||
);
|
||||
codeMatcher.MatchForward(true, new CodeMatch(OpCodes.Bge_Un), new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Stloc_S), new CodeMatch(OpCodes.Ldc_I4_1), new CodeMatch(OpCodes.Stloc_S), new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Stloc_S));
|
||||
codeMatcher.Advance(1).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldloc_0),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(StarData), "planets")),
|
||||
new CodeInstruction(OpCodes.Ldloc_S, 21),
|
||||
Transpilers.EmitDelegate(delegate(PlanetData[] planets, int planetIndex)
|
||||
{
|
||||
CruiseAssistPlugin.ReticuleTargetPlanet = planets[planetIndex];
|
||||
})
|
||||
);
|
||||
codeMatcher.MatchForward(true,
|
||||
new CodeMatch(OpCodes.Bge_Un),
|
||||
new CodeMatch(OpCodes.Ldloc_S),
|
||||
new CodeMatch(OpCodes.Stloc_S),
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(OpCodes.Stloc_S),
|
||||
new CodeMatch(OpCodes.Ldloc_S),
|
||||
new CodeMatch(OpCodes.Stloc_S));
|
||||
codeMatcher.Advance(1).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldloc_S, 20),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(GalaxyData), "stars")),
|
||||
new CodeInstruction(OpCodes.Ldloc_S, 24),
|
||||
Transpilers.EmitDelegate(delegate(StarData[] stars, int starIndex)
|
||||
{
|
||||
CruiseAssistPlugin.ReticuleTargetStar = stars[starIndex];
|
||||
})
|
||||
);
|
||||
return codeMatcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyPatch("_OnOpen")]
|
||||
[HarmonyPrefix]
|
||||
public static void OnOpen_Prefix()
|
||||
{
|
||||
if (CruiseAssistPlugin.Conf.AutoDisableLockCursorFlag)
|
||||
{
|
||||
UIRoot.instance.uiGame.disableLockCursor = true;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch("_OnClose")]
|
||||
[HarmonyPrefix]
|
||||
public static void OnClose_Prefix()
|
||||
{
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
||||
}
|
||||
}
|
||||
19
CruiseAssist/Patches/Patch_UIStarmap.cs
Normal file
19
CruiseAssist/Patches/Patch_UIStarmap.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using CruiseAssist.Commons;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CruiseAssist.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(UIStarmap))]
|
||||
internal class Patch_UIStarmap
|
||||
{
|
||||
[HarmonyPatch("_OnClose")]
|
||||
[HarmonyPrefix]
|
||||
public static void OnClose_Prefix()
|
||||
{
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.CheckConfig(ConfigManager.Step.State.ToString());
|
||||
});
|
||||
}
|
||||
}
|
||||
19
CruiseAssist/Patches/Patch_UITechTree.cs
Normal file
19
CruiseAssist/Patches/Patch_UITechTree.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using CruiseAssist.Commons;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace CruiseAssist.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(UITechTree))]
|
||||
internal class Patch_UITechTree
|
||||
{
|
||||
[HarmonyPatch("_OnOpen")]
|
||||
[HarmonyPrefix]
|
||||
public static void OnOpen_Prefix()
|
||||
{
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
||||
CruiseAssistPlugin.Extensions.ForEach(delegate(ICruiseAssistExtensionAPI extension)
|
||||
{
|
||||
extension.CheckConfig(ConfigManager.Step.State.ToString());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user