using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Math;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("StellarAutoNavigation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StellarAutoNavigation")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace AutoStellerNavigate
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "AutoStellerNavigate";
public const string PLUGIN_NAME = "AutoStellerNavigate";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace AutoNavigate
{
public class AutoStellarNavigation
{
public enum NavigateType
{
Null,
Star,
Planet
}
public class Target
{
public static double s_FocusParam = 0.01;
private PlanetData m_PlanetData;
private StarData m_StarData;
public PlanetData TargetPlanet => m_PlanetData;
public StarData TargetStar => m_StarData;
public VectorLF3 Position
{
get
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
if (TargetPlanet != null)
{
return TargetPlanet.uPosition;
}
if (TargetStar != null)
{
return TargetStar.uPosition;
}
ModDebug.Error((object)"Get Target Position while no target!!!");
return new VectorLF3(0.0, 0.0, 0.0);
}
}
public bool IsLocalStarPlanet
{
get
{
if (GameMain.localStar != null && TargetPlanet != null && TargetPlanet.star == GameMain.localStar)
{
return true;
}
return false;
}
}
public bool IsVaild()
{
if (TargetStar == null)
{
return TargetPlanet != null;
}
return true;
}
public void Reset()
{
m_PlanetData = null;
m_StarData = null;
}
public void SetTarget(StarData star)
{
Reset();
m_StarData = star;
}
public void SetTarget(PlanetData planet)
{
Reset();
m_PlanetData = planet;
}
public static bool IsFocusing(VectorLF3 lineL, VectorLF3 lineR)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
return IsFocusingNormalized(((VectorLF3)(ref lineL)).normalized, ((VectorLF3)(ref lineR)).normalized);
}
public static bool IsFocusingNormalized(VectorLF3 dirL, VectorLF3 dirR)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
VectorLF3 val = dirL - dirR;
return ((VectorLF3)(ref val)).magnitude < s_FocusParam;
}
public double GetDistance(Player __instance)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
double result = 3.4028234663852886E+38;
VectorLF3 val;
if (TargetPlanet != null)
{
val = TargetPlanet.uPosition - __instance.uPosition;
result = ((VectorLF3)(ref val)).magnitude;
}
else if (TargetStar != null)
{
val = TargetStar.uPosition - __instance.uPosition;
result = ((VectorLF3)(ref val)).magnitude;
}
else
{
ModDebug.Error((object)"GetDistance while no target!!!");
}
return result;
}
public VectorLF3 GetDirection(Player __instance)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
VectorLF3 result = VectorLF3.zero;
VectorLF3 val;
if (TargetPlanet != null)
{
val = TargetPlanet.uPosition - __instance.uPosition;
result = ((VectorLF3)(ref val)).normalized;
}
else if (TargetStar != null)
{
val = TargetStar.uPosition - __instance.uPosition;
result = ((VectorLF3)(ref val)).normalized;
}
else
{
ModDebug.Error((object)"GetDirection while no target!!!");
}
return result;
}
}
public class NavigationConfig
{
public ConfigEntry<double> speedUpEnergylimit;
public ConfigEntry<double> wrapEnergylimit;
public double planetNearastDistance;
public int sparseStarPlanetCount;
public double sparseStarPlanetNearastDistance;
public double focusParam;
public double longNavUncoverRange;
public double shortNavUncoverRange;
public ConfigEntry<bool> enableLocalWrap;
public ConfigEntry<double> localWrapMinDistance;
}
public static class Warp
{
public static bool HasWarper(PlayerMove_Sail __instance)
{
return GetWarperCount(__instance) > 0;
}
public static int GetWarperCount(PlayerMove_Sail __instance)
{
return ((PlayerAction)__instance).player.mecha.warpStorage.GetItemCount(1210);
}
public static bool TryWrap(AutoStellarNavigation self, PlayerMove_Sail __instance)
{
if (HasWarpChance(self, __instance))
{
TryEnterWarp(__instance);
return true;
}
return false;
}
public static bool HasWarpChance(AutoStellarNavigation self, PlayerMove_Sail __instance)
{
if (((PlayerAction)__instance).player.mecha.thrusterLevel < 3)
{
return false;
}
if (__instance.mecha.coreEnergy < __instance.mecha.warpStartPowerPerSpeed * (double)__instance.mecha.maxWarpSpeed)
{
return false;
}
if (!HasWarper(__instance))
{
return false;
}
if (self.IsCurNavStar || LocalPlanetWarp())
{
return true;
}
return false;
bool LocalPlanetWarp()
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
if (GameMain.localPlanet != null && self.target.TargetPlanet.id == GameMain.localPlanet.id)
{
return false;
}
VectorLF3 val = ((PlayerAction)__instance).player.uPosition - self.target.TargetPlanet.uPosition;
if (((VectorLF3)(ref val)).magnitude < self.localWrapMinDistance)
{
return false;
}
return true;
}
}
public static bool TryEnterWarp(PlayerMove_Sail __instance, bool playSound = true)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
if (!((PlayerAction)__instance).player.warping && ((PlayerAction)__instance).player.mecha.UseWarper())
{
((PlayerAction)__instance).player.warpCommand = true;
if (playSound)
{
VFAudio.Create("warp-begin", ((PlayerAction)__instance).player.transform, Vector3.zero, true, 0, -1, -1L);
}
return true;
}
return false;
}
public static bool TryLeaveWarp(PlayerMove_Sail __instance, bool playSound = true)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
if (((PlayerAction)__instance).player.warping)
{
((PlayerAction)__instance).player.warpCommand = false;
if (playSound)
{
VFAudio.Create("warp-end", ((PlayerAction)__instance).player.transform, Vector3.zero, true, 0, -1, -1L);
}
return true;
}
return false;
}
}
public static class Sail
{
public static void SetDir(PlayerMove_Sail __instance, VectorLF3 dir)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
((PlayerAction)__instance).controller.fwdRayUDir = dir;
}
public static void TrySpeedUp(AutoStellarNavigation __this, PlayerMove_Sail __instance)
{
if (((PlayerAction)__instance).player.mecha.coreEnergy >= __this.speedUpEnergyLimit)
{
__this.sailSpeedUp = true;
}
}
}
public static class Fly
{
public static bool TrySwtichToSail(PlayerMove_Fly __instance)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Invalid comparison between Unknown and I4
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
if (__instance.mecha.thrusterLevel < 2)
{
return false;
}
if ((int)((PlayerAction)__instance).controller.cmd.type == 5)
{
((PlayerAction)__instance).controller.cmd.type = (ECommand)0;
}
((PlayerAction)__instance).controller.movementStateInFrame = (EMovementState)3;
((PlayerAction)__instance).controller.actionSail.ResetSailState();
GameCamera.instance.SyncForSailMode();
GameMain.gameScenario.NotifyOnSailModeEnter();
return true;
}
}
public static class Walk
{
public static bool TrySwitchToFly(PlayerMove_Walk __instance)
{
if (__instance.mecha.thrusterLevel < 1)
{
return false;
}
__instance.jumpCoolTime = 0.3f;
__instance.jumpedTime = 0f;
__instance.flyUpChance = 0f;
__instance.SwitchToFly();
return true;
}
}
private const int THRUSTER_LEVEL_FLY = 1;
private const int THRUSTER_LEVEL_SAIL = 2;
private const int THRUSTER_LEVEL_WARP = 3;
public Target target;
public Text modeText;
private Player player;
public bool isHistoryNav;
public bool sailSpeedUp;
private NavigationConfig config;
private bool useConfigFile = true;
private double speedUpEnergyLimit;
private double wrapEnergyLimit;
private double planetNearestDistance;
private int sparseStarPlanetCount;
private double sparseStarPlanetNearestDistance;
private double longNavUncoverRange;
private double shortNavUncoverRange;
private bool enableLocalWrap;
private double localWrapMinDistance;
public NavigateType CurNavigateType
{
get
{
if (IsCurNavStar)
{
return NavigateType.Star;
}
if (IsCurNavPlanet)
{
return NavigateType.Planet;
}
return NavigateType.Null;
}
}
public bool IsCurNavPlanet => target.TargetPlanet != null;
public bool IsCurNavStar => target.TargetStar != null;
public bool enable { get; private set; }
public bool Pause()
{
if (enable)
{
ModDebug.Log((object)"SafePause");
enable = false;
isHistoryNav = true;
return true;
}
return false;
}
public bool Resume()
{
if (isHistoryNav && !enable)
{
ModDebug.Log((object)"SafeResume");
enable = true;
isHistoryNav = false;
return true;
}
isHistoryNav = false;
return false;
}
public AutoStellarNavigation(NavigationConfig config)
{
this.config = config;
target = new Target();
Reset();
target.Reset();
}
public bool Navigate()
{
if (enable)
{
return enable;
}
if (CurNavigateType == NavigateType.Null)
{
Arrive();
enable = false;
}
else if (DetermineArrive())
{
Arrive();
enable = false;
}
else
{
enable = true;
}
return enable;
}
public bool ToggleNavigate()
{
if (!enable)
{
return Navigate();
}
return Arrive();
}
public void Reset()
{
isHistoryNav = false;
player = null;
enable = false;
sailSpeedUp = false;
if (useConfigFile)
{
speedUpEnergyLimit = ((config.speedUpEnergylimit.Value > 0.0) ? config.speedUpEnergylimit.Value : 0.0);
wrapEnergyLimit = ((config.wrapEnergylimit.Value > 0.0) ? config.wrapEnergylimit.Value : 0.0);
planetNearestDistance = 60000.0;
sparseStarPlanetCount = 2;
sparseStarPlanetNearestDistance = 200000.0;
Target.s_FocusParam = 0.02;
longNavUncoverRange = 1000.0;
shortNavUncoverRange = 100.0;
enableLocalWrap = config.enableLocalWrap.Value;
localWrapMinDistance = ((config.localWrapMinDistance.Value > 0.0) ? config.localWrapMinDistance.Value : 0.0);
}
else
{
speedUpEnergyLimit = 50000000.0;
wrapEnergyLimit = 1000000000.0;
planetNearestDistance = 60000.0;
sparseStarPlanetCount = 2;
sparseStarPlanetNearestDistance = 200000.0;
Target.s_FocusParam = 0.02;
longNavUncoverRange = 1000.0;
shortNavUncoverRange = 100.0;
enableLocalWrap = false;
localWrapMinDistance = 0.0;
}
}
public void HandlePlayerInput()
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
if (enable && (VFInput._moveForward.onDown || VFInput._moveBackward.onDown || VFInput._moveLeft.onDown || VFInput._moveRight.onDown))
{
Arrive();
}
}
public bool Arrive(string extraTip = null)
{
string text = ModTranslate.LocalText("Navigation Mode Ended");
if (extraTip != null)
{
text = text + "-" + extraTip;
}
Reset();
UIRealtimeTip.Popup(text, true, 0);
if ((Object)(object)modeText != (Object)null && ((UIBehaviour)modeText).IsActive())
{
((Component)modeText).gameObject.SetActive(false);
modeText.text = string.Empty;
}
return true;
}
public bool DetermineArrive()
{
if (IsCurNavPlanet && GameMain.localPlanet != null && GameMain.localPlanet.id == target.TargetPlanet.id)
{
return true;
}
if (IsCurNavStar && GameMain.localStar != null && GameMain.localStar.id == target.TargetStar.id)
{
return true;
}
return false;
}
public bool AdvisePointIfOcclusion(PlayerMove_Sail __instance, ref VectorLF3 advisePoint, double radiusOffest)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Expected O, but got Unknown
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_0260: Unknown result type (might be due to invalid IL or missing references)
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_0266: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Expected O, but got Unknown
//IL_0271: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0288: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
bool flag = false;
bool flag2 = false;
StarData localStar = GameMain.localStar;
VectorLF3 uPosition = ((PlayerAction)__instance).player.uPosition;
VectorLF3 val = VectorLF3.zero;
if (IsCurNavStar)
{
flag2 = true;
val = target.TargetStar.uPosition;
}
else
{
if (!IsCurNavPlanet)
{
ModDebug.Error((object)"AdvisePointIfOcclusion When No Navigate!!!");
return false;
}
flag = true;
val = target.TargetPlanet.uPosition;
}
bool flag3 = false;
Line3D val2 = new Line3D();
double num = 0.0;
Line3D val3 = new Line3D(uPosition, val);
Plane3D val4 = new Plane3D();
val4.normal = val3.dir;
if (localStar != null)
{
for (int i = 0; i < localStar.planetCount; i++)
{
PlanetData val5 = localStar.planets[i];
val4.ponit = val5.uPosition;
if (val4.IsParallel(val3) || (flag && val5.id == target.TargetPlanet.id))
{
continue;
}
VectorLF3 intersection = val4.GetIntersection(val3);
double num2 = (double)val5.realRadius + radiusOffest;
if (!(((VectorLF3)(ref intersection)).Distance(val5.uPosition) < num2) || !(((VectorLF3)(ref intersection)).Distance(uPosition) + ((VectorLF3)(ref intersection)).Distance(val) <= ((VectorLF3)(ref val)).Distance(uPosition) + 0.1))
{
continue;
}
flag3 = true;
if (num2 > num)
{
num = num2;
val2.src = val5.uPosition;
if (val5.uPosition != intersection)
{
val2.dst = intersection;
}
else
{
val2.dst = val4.GetAnyPoint();
}
}
}
StarData val6 = localStar;
val4.ponit = val6.uPosition;
if ((!flag2 || val6.id != target.TargetStar.id) && !val4.IsParallel(val3))
{
VectorLF3 intersection2 = val4.GetIntersection(val3);
double num3 = (double)val6.physicsRadius + radiusOffest;
if (((VectorLF3)(ref intersection2)).Distance(val6.uPosition) < num3)
{
flag3 = true;
if (num3 > num)
{
num = num3;
val2.src = val6.uPosition;
if (val6.uPosition != intersection2)
{
val2.dst = intersection2;
}
else
{
val2.dst = val4.GetAnyPoint();
}
}
}
}
}
if (flag3)
{
VectorLF3 val7 = val2.src + val2.dir * (num + 10.0);
Line3D val8 = new Line3D(val, val7);
val4.normal = val8.dir;
val4.ponit = uPosition;
advisePoint = val4.GetIntersection(val8);
}
return flag3;
}
private double NearestPlanetDistance(PlayerMove_Sail __instance)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
StarData localStar = GameMain.localStar;
VectorLF3 val = localStar.planets[0].uPosition - ((PlayerAction)__instance).player.uPosition;
double num = ((VectorLF3)(ref val)).magnitude;
if (localStar == null)
{
return -10.0;
}
for (int i = 0; i < localStar.planetCount; i++)
{
val = localStar.planets[i].uPosition - ((PlayerAction)__instance).player.uPosition;
double magnitude = ((VectorLF3)(ref val)).magnitude;
if (magnitude < num)
{
num = magnitude;
}
}
return num;
}
public bool IsCloseToNearStar(PlayerMove_Sail __instance)
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
if (GameMain.localStar == null)
{
return false;
}
bool result = false;
double num = NearestPlanetDistance(__instance);
if (num > 0.0)
{
if (GameMain.localStar.planetCount <= sparseStarPlanetCount && num < sparseStarPlanetNearestDistance)
{
return true;
}
if (num < planetNearestDistance)
{
result = true;
}
}
else
{
VectorLF3 val = GameMain.localStar.uPosition - ((PlayerAction)__instance).player.uPosition;
if (((VectorLF3)(ref val)).magnitude < planetNearestDistance)
{
result = true;
}
}
return result;
}
public void StarNavigation(PlayerMove_Sail __instance)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
ModDebug.Assert(IsCurNavStar);
player = ((PlayerAction)__instance).player;
if (!IsCurNavStar)
{
Arrive();
return;
}
PlanetData localPlanet = GameMain.localPlanet;
if (localPlanet != null)
{
VectorLF3 val = ((PlayerAction)__instance).player.uPosition - localPlanet.uPosition;
VectorLF3 normalized = ((VectorLF3)(ref val)).normalized;
Sail.SetDir(__instance, normalized);
}
else if (DetermineArrive() && IsCloseToNearStar(__instance))
{
Arrive();
Warp.TryLeaveWarp(__instance);
}
else
{
LongDistanceNavigate(__instance);
}
}
private bool NeedLocalLongDistanceNavigate(PlayerMove_Sail __instance)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
VectorLF3 val = target.TargetPlanet.uPosition - ((PlayerAction)__instance).player.uPosition;
double magnitude = ((VectorLF3)(ref val)).magnitude;
if (!enableLocalWrap || !(magnitude > localWrapMinDistance) || !(magnitude > (double)target.TargetPlanet.realRadius + longNavUncoverRange))
{
return !target.IsLocalStarPlanet;
}
return true;
}
public void PlanetNavigation(PlayerMove_Sail __instance)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
ModDebug.Assert(IsCurNavPlanet);
player = ((PlayerAction)__instance).player;
if (!IsCurNavPlanet)
{
Arrive();
}
else if (NeedLocalLongDistanceNavigate(__instance))
{
PlanetData localPlanet = GameMain.localPlanet;
if (localPlanet != null && target.TargetPlanet != null && localPlanet.id != target.TargetPlanet.id)
{
VectorLF3 val = ((PlayerAction)__instance).player.uPosition - localPlanet.uPosition;
VectorLF3 normalized = ((VectorLF3)(ref val)).normalized;
Sail.SetDir(__instance, normalized);
}
else
{
LongDistanceNavigate(__instance);
}
}
else
{
ShortDistanceNavigate(__instance);
}
}
private void ShortDistanceNavigate(PlayerMove_Sail __instance)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
VectorLF3 direction = target.GetDirection(((PlayerAction)__instance).player);
Sail.SetDir(__instance, direction);
VectorLF3 advisePoint = VectorLF3.zero;
if (AdvisePointIfOcclusion(__instance, ref advisePoint, shortNavUncoverRange))
{
VectorLF3 val = advisePoint - ((PlayerAction)__instance).player.uPosition;
direction = ((VectorLF3)(ref val)).normalized;
Sail.SetDir(__instance, direction);
Sail.TrySpeedUp(this, __instance);
}
else if (Target.IsFocusingNormalized(direction, ((VectorLF3)(ref ((PlayerAction)__instance).player.uVelocity)).normalized))
{
Sail.TrySpeedUp(this, __instance);
}
}
private void LongDistanceNavigate(PlayerMove_Sail __instance)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
VectorLF3 direction = target.GetDirection(((PlayerAction)__instance).player);
Sail.SetDir(__instance, direction);
VectorLF3 advisePoint = VectorLF3.zero;
if (AdvisePointIfOcclusion(__instance, ref advisePoint, longNavUncoverRange))
{
VectorLF3 val = advisePoint - ((PlayerAction)__instance).player.uPosition;
direction = ((VectorLF3)(ref val)).normalized;
Sail.SetDir(__instance, direction);
Sail.TrySpeedUp(this, __instance);
}
else if (Target.IsFocusingNormalized(direction, ((VectorLF3)(ref ((PlayerAction)__instance).player.uVelocity)).normalized) && !((PlayerAction)__instance).player.warping && (!(((PlayerAction)__instance).player.mecha.coreEnergy >= wrapEnergyLimit) || !Warp.TryWrap(this, __instance)))
{
if (IsCurNavPlanet && target.IsLocalStarPlanet)
{
Sail.TrySpeedUp(this, __instance);
}
else if (LongDistanceNavigateNeedSpeedUp())
{
Sail.TrySpeedUp(this, __instance);
}
}
bool LongDistanceNavigateNeedSpeedUp()
{
if (((PlayerAction)__instance).player.mecha.coreEnergy >= speedUpEnergyLimit)
{
if (((PlayerAction)__instance).player.mecha.thrusterLevel < 3)
{
return true;
}
Warp.HasWarper(__instance);
return true;
}
_ = ((PlayerAction)__instance).player.mecha.coreEnergy;
_ = wrapEnergyLimit;
return false;
}
}
}
[BepInPlugin("0x.plugins.dsp.StellarAutoNavigation", "StellarAutoNavigation", "1.08")]
public class AutoNavigate : BaseUnityPlugin
{
private class SafeMode
{
[HarmonyPatch(typeof(GameMain), "OnDestroy")]
public class SafeDestroy
{
private static void Prefix()
{
Reset();
}
}
[HarmonyPatch(typeof(GameMain), "Pause")]
public class SafePause
{
public static void Prefix()
{
s_NavigateInstance.Pause();
}
}
[HarmonyPatch(typeof(GameMain), "Resume")]
public class SafeResume
{
public static void Prefix()
{
s_NavigateInstance.Resume();
}
}
public static void Reset()
{
s_IsHistoryNavigated = false;
s_NavigateInstance.Reset();
s_NavigateInstance.target.Reset();
__this.player = null;
}
}
[HarmonyPatch(typeof(PlayerController), "Init")]
private class PlayerControllerInit
{
private static void Postfix(PlayerController __instance)
{
__this.player = __instance.player;
}
}
[HarmonyPatch(typeof(UIGeneralTips), "_OnUpdate")]
private class NavigateTips
{
private static Vector2 anchoredPosition = new Vector2(0f, 160f);
public static void Postfix(UIGeneralTips __instance)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (s_NavigateInstance.enable)
{
Text value = Traverse.Create((object)__instance).Field("modeText").GetValue<Text>();
((Component)value).gameObject.SetActive(true);
((Graphic)value).rectTransform.anchoredPosition = anchoredPosition;
if (s_NavigateInstance.IsCurNavPlanet)
{
value.text = ModTranslate.LocalText("Stellar Auto Navigation");
}
else if (s_NavigateInstance.IsCurNavStar)
{
value.text = ModTranslate.LocalText("Galaxy Auto Navigation");
}
s_NavigateInstance.modeText = value;
}
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private class SailSpeedUp
{
private static void Postfix(ref bool __result)
{
if (s_NavigateInstance.enable && s_NavigateInstance.sailSpeedUp)
{
__result = true;
}
}
}
[HarmonyPatch(typeof(PlayerMove_Sail), "GameTick")]
private class SailMode_AutoNavigate
{
private static VectorLF3 oTargetURot;
private static double? lastDist;
private static void Prefix(PlayerMove_Sail __instance)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
if (!s_NavigateInstance.enable || (!((PlayerAction)__instance).player.sailing && !((PlayerAction)__instance).player.warping))
{
return;
}
((PlayerAction)__instance).controller.input0.y += 1f;
oTargetURot = ((PlayerAction)__instance).controller.fwdRayUDir;
if (((PlayerAction)__instance).player.warping)
{
double distance = s_NavigateInstance.target.GetDistance(((PlayerAction)__instance).player);
if (lastDist.HasValue && lastDist < distance)
{
ModDebug.Trace((object)$"Dropping out of warp, passed target - ld:{lastDist} cd:{distance}");
AutoStellarNavigation.Warp.TryLeaveWarp(__instance, playSound: false);
}
lastDist = distance;
}
if (s_NavigateInstance.IsCurNavStar)
{
s_NavigateInstance.StarNavigation(__instance);
}
else if (s_NavigateInstance.IsCurNavPlanet)
{
s_NavigateInstance.PlanetNavigation(__instance);
}
}
private static void Postfix(PlayerMove_Sail __instance)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
s_NavigateInstance.sailSpeedUp = false;
if (s_NavigateInstance.enable && (GameMain.localPlanet != null || s_NavigateInstance.target.IsVaild()))
{
((PlayerAction)__instance).controller.fwdRayUDir = oTargetURot;
((Behaviour)__instance.sailPoser).enabled = true;
s_NavigateInstance.HandlePlayerInput();
}
}
}
[HarmonyPatch(typeof(PlayerMove_Fly), "GameTick")]
private class FlyMode_TrySwitchToSail
{
private static float sailMinAltitude = 49f;
private static void Prefix(PlayerMove_Fly __instance)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Invalid comparison between Unknown and I4
ModDebug.Trace((object)"Begin FlyMode_TrySwitchToSail.PreFix");
if (!s_NavigateInstance.enable)
{
ModDebug.Trace((object)"No navigation, exiting");
return;
}
if ((int)((PlayerAction)__instance).player.movementState != 2)
{
ModDebug.Trace((object)"Movement != fly");
return;
}
if (s_NavigateInstance.DetermineArrive())
{
ModDebug.Log((object)"FlyModeArrive");
s_NavigateInstance.Arrive();
}
else if (__instance.mecha.thrusterLevel < 2)
{
ModDebug.Trace((object)"Thruster level too low");
s_NavigateInstance.Arrive(ModTranslate.LocalText("Thruster Level Too Low"));
}
else if (((PlayerAction)__instance).player.mecha.coreEnergy < s_NavigateMinEnergy.Value)
{
ModDebug.Trace((object)"Mecha energy too low");
s_NavigateInstance.Arrive(ModTranslate.LocalText("Mecha Energy Too Low"));
}
else
{
ModDebug.Trace((object)"In else");
((PlayerAction)__instance).controller.input1.y += 1f;
if (__instance.currentAltitude > sailMinAltitude)
{
ModDebug.Trace((object)"Switch to sail");
AutoStellarNavigation.Fly.TrySwtichToSail(__instance);
}
}
ModDebug.Trace((object)"End FlyMode_TrySwitchToSail.PreFix");
}
}
[HarmonyPatch(typeof(PlayerMove_Walk), "UpdateJump")]
private class WalkMode_TrySwitchToFly
{
private static void Postfix(PlayerMove_Walk __instance, ref bool __result)
{
ModDebug.Trace((object)"Begin FlyMode_TrySwitchToSail.PostFix");
if (!s_NavigateInstance.enable)
{
ModDebug.Trace((object)"No navigation, exiting");
return;
}
if (!s_NavigateInstance.target.IsVaild())
{
ModDebug.Trace((object)"Navigation point invalid, exiting");
return;
}
if (s_NavigateInstance.DetermineArrive())
{
ModDebug.Log((object)"WalkModeArrive");
s_NavigateInstance.Arrive();
}
else if (__instance.mecha.thrusterLevel < 1)
{
ModDebug.Trace((object)"Thruster level too low");
s_NavigateInstance.Arrive(ModTranslate.LocalText("Thruster Level Too Low"));
}
else if (((PlayerAction)__instance).player.mecha.coreEnergy < s_NavigateMinEnergy.Value)
{
ModDebug.Trace((object)"Mecha energy too low");
s_NavigateInstance.Arrive(ModTranslate.LocalText("Mecha Energy Too Low"));
}
else
{
ModDebug.Trace((object)"Switching to fly mode");
AutoStellarNavigation.Walk.TrySwitchToFly(__instance);
__result = true;
}
ModDebug.Trace((object)"End FlyMode_TrySwitchToSail.PostFix");
}
}
[HarmonyPatch(typeof(UIStarmap), "OnCursorFunction3Click")]
private class OnSetIndicatorAstro
{
private static void Prefix(UIStarmap __instance)
{
if ((Object)(object)__instance.focusPlanet != (Object)null && __instance.focusPlanet.planet != null)
{
s_NavigateInstance.target.SetTarget(__instance.focusPlanet.planet);
}
else if ((Object)(object)__instance.focusStar != (Object)null && __instance.focusStar.star != null)
{
s_NavigateInstance.target.SetTarget(__instance.focusStar.star);
}
}
}
[HarmonyPatch(typeof(UIStarmap), "UpdateCursorView")]
private class UIStarmap_UpdateCursorView
{
private static void Postfix(UIStarmap __instance)
{
if (Input.GetKeyDown((KeyCode)306))
{
if ((Object)(object)__instance.mouseHoverStar != (Object)null && __instance.mouseHoverStar.star != null)
{
__instance.focusStar = __instance.mouseHoverStar;
__instance.focusPlanet = null;
__instance.OnCursorFunction3Click(0);
}
else if ((Object)(object)__instance.mouseHoverPlanet != (Object)null && __instance.mouseHoverPlanet.planet != null)
{
__instance.focusPlanet = __instance.mouseHoverPlanet;
__instance.focusStar = null;
__instance.OnCursorFunction3Click(0);
}
}
}
}
public const string __NAME__ = "StellarAutoNavigation";
public const string __GUID__ = "0x.plugins.dsp.StellarAutoNavigation";
public static AutoNavigate __this;
public static AutoStellarNavigation s_NavigateInstance;
public static bool s_IsHistoryNavigated;
public static ConfigEntry<double> s_NavigateMinEnergy;
private Player player;
private void Start()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
ModDebug.SetLogger(((BaseUnityPlugin)this).Logger);
__this = this;
s_NavigateInstance = new AutoStellarNavigation(GetNavigationConfig());
new Harmony("0x.plugins.dsp.StellarAutoNavigation").PatchAll();
}
private void Update()
{
if (player != null && (Input.GetKeyDown((KeyCode)256) || Input.GetKeyDown((KeyCode)107)))
{
s_NavigateInstance.ToggleNavigate();
}
}
private AutoStellarNavigation.NavigationConfig GetNavigationConfig()
{
AutoStellarNavigation.NavigationConfig navigationConfig = new AutoStellarNavigation.NavigationConfig();
s_NavigateMinEnergy = ((BaseUnityPlugin)this).Config.Bind<double>("AutoStellarNavigation", "minAutoNavEnergy", 50000000.0, "开启自动导航最低能量(最低50m)");
navigationConfig.speedUpEnergylimit = ((BaseUnityPlugin)this).Config.Bind<double>("AutoStellarNavigation", "SpeedUpEnergylimit", 50000000.0, "开启加速最低能量(默认50m)");
navigationConfig.wrapEnergylimit = ((BaseUnityPlugin)this).Config.Bind<double>("AutoStellarNavigation", "WrapEnergylimit", 800000000.0, "开启曲率最低能量(默认800m)");
navigationConfig.enableLocalWrap = ((BaseUnityPlugin)this).Config.Bind<bool>("AutoStellarNavigation", "EnableLocalWrap", true, "是否开启本地行星曲率飞行");
navigationConfig.localWrapMinDistance = ((BaseUnityPlugin)this).Config.Bind<double>("AutoStellarNavigation", "LocalWrapMinDistance", 100000.0, "本地行星曲率飞行最短距离");
if (s_NavigateMinEnergy.Value < 50000000.0)
{
s_NavigateMinEnergy.Value = 50000000.0;
}
return navigationConfig;
}
}
}