mirror of
https://github.com/soarqin/DSP_Mods_TO.git
synced 2026-02-04 14:12:18 +08:00
Added CruiseAssist and AutoPilot
This commit is contained in:
33
AutoPilot/AutoPilot.csproj
Normal file
33
AutoPilot/AutoPilot.csproj
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<AssemblyName>AutoPilot</AssemblyName>
|
||||
<BepInExPluginGuid>tanu.AutoPilot</BepInExPluginGuid>
|
||||
<Description>DSP MOD - AutoPilot</Description>
|
||||
<Version>0.0.4</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<RestoreAdditionalProjectSources>https://nuget.bepinex.dev/v3/index.json</RestoreAdditionalProjectSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
||||
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-r.*" />
|
||||
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CruiseAssist\CruiseAssist.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip
zip -9 -j package/$(ProjectName)-$(Version).zip $(TargetPath) package/icon.png package/manifest.json README.md" />
|
||||
</Target>
|
||||
</Project>
|
||||
71
AutoPilot/AutoPilotConfigManager.cs
Normal file
71
AutoPilot/AutoPilotConfigManager.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using AutoPilot.Commons;
|
||||
using AutoPilot.UI;
|
||||
using BepInEx.Configuration;
|
||||
|
||||
namespace AutoPilot;
|
||||
|
||||
internal class AutoPilotConfigManager : ConfigManager
|
||||
{
|
||||
internal AutoPilotConfigManager(ConfigFile Config)
|
||||
: base(Config)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void CheckConfigImplements(Step step)
|
||||
{
|
||||
var ok = false;
|
||||
if (step == Step.Awake)
|
||||
{
|
||||
var configEntry = Bind("Base", "ModVersion", "0.0.4", "Don't change.");
|
||||
configEntry.Value = "0.0.4";
|
||||
ok = true;
|
||||
}
|
||||
|
||||
if (step is Step.Awake or Step.GameMainBegin)
|
||||
{
|
||||
AutoPilotDebugUI.Show = Bind("Debug", "DebugWindowShow", false).Value;
|
||||
AutoPilotPlugin.Conf.MinEnergyPer = Bind("Setting", "MinEnergyPer", 20).Value;
|
||||
AutoPilotPlugin.Conf.MaxSpeed = Bind("Setting", "MaxSpeed", 2000).Value;
|
||||
AutoPilotPlugin.Conf.WarpMinRangeAU = Bind("Setting", "WarpMinRangeAU", 2).Value;
|
||||
AutoPilotPlugin.Conf.SpeedToWarp = Bind("Setting", "WarpSpeed", 1200).Value;
|
||||
AutoPilotPlugin.Conf.LocalWarpFlag = Bind("Setting", "LocalWarp", false).Value;
|
||||
AutoPilotPlugin.Conf.AutoStartFlag = Bind("Setting", "AutoStart", true).Value;
|
||||
AutoPilotPlugin.Conf.MainWindowJoinFlag = Bind("Setting", "MainWindowJoin", true).Value;
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
AutoPilotMainUI.Rect[i].x = Bind("State", $"MainWindow{i}Left", 100).Value;
|
||||
AutoPilotMainUI.Rect[i].y = Bind("State", $"MainWindow{i}Top", 100).Value;
|
||||
AutoPilotConfigUI.Rect[i].x = Bind("State", $"ConfigWindow{i}Left", 100).Value;
|
||||
AutoPilotConfigUI.Rect[i].y = Bind("State", $"ConfigWindow{i}Top", 100).Value;
|
||||
}
|
||||
AutoPilotDebugUI.Rect.x = Bind("State", "DebugWindowLeft", 100).Value;
|
||||
AutoPilotDebugUI.Rect.y = Bind("State", "DebugWindowTop", 100).Value;
|
||||
}
|
||||
else if (step == Step.State)
|
||||
{
|
||||
LogManager.LogInfo("check state.");
|
||||
ok |= UpdateEntry("Setting", "MinEnergyPer", AutoPilotPlugin.Conf.MinEnergyPer);
|
||||
ok |= UpdateEntry("Setting", "MaxSpeed", AutoPilotPlugin.Conf.MaxSpeed);
|
||||
ok |= UpdateEntry("Setting", "WarpMinRangeAU", AutoPilotPlugin.Conf.WarpMinRangeAU);
|
||||
ok |= UpdateEntry("Setting", "WarpSpeed", AutoPilotPlugin.Conf.SpeedToWarp);
|
||||
ok |= UpdateEntry("Setting", "LocalWarp", AutoPilotPlugin.Conf.LocalWarpFlag);
|
||||
ok |= UpdateEntry("Setting", "AutoStart", AutoPilotPlugin.Conf.AutoStartFlag);
|
||||
ok |= UpdateEntry("Setting", "MainWindowJoin", AutoPilotPlugin.Conf.MainWindowJoinFlag);
|
||||
for (var j = 0; j < 2; j++)
|
||||
{
|
||||
ok |= UpdateEntry("State", $"MainWindow{j}Left", (int)AutoPilotMainUI.Rect[j].x);
|
||||
ok |= UpdateEntry("State", $"MainWindow{j}Top", (int)AutoPilotMainUI.Rect[j].y);
|
||||
ok |= UpdateEntry("State", $"ConfigWindow{j}Left", (int)AutoPilotConfigUI.Rect[j].x);
|
||||
ok |= UpdateEntry("State", $"ConfigWindow{j}Top", (int)AutoPilotConfigUI.Rect[j].y);
|
||||
}
|
||||
ok |= UpdateEntry("State", "DebugWindowLeft", (int)AutoPilotDebugUI.Rect.x);
|
||||
ok |= UpdateEntry("State", "DebugWindowTop", (int)AutoPilotDebugUI.Rect.y);
|
||||
AutoPilotMainUI.NextCheckGameTick = long.MaxValue;
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
236
AutoPilot/AutoPilotExtension.cs
Normal file
236
AutoPilot/AutoPilotExtension.cs
Normal file
@@ -0,0 +1,236 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using AutoPilot.Commons;
|
||||
using AutoPilot.Enums;
|
||||
using AutoPilot.UI;
|
||||
using CruiseAssist;
|
||||
using CruiseAssist.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AutoPilot;
|
||||
|
||||
internal class AutoPilotExtension : ICruiseAssistExtensionAPI
|
||||
{
|
||||
public void CheckConfig(string step)
|
||||
{
|
||||
EnumUtils.TryParse(step, out ConfigManager.Step step2);
|
||||
ConfigManager.CheckConfig(step2);
|
||||
}
|
||||
|
||||
public void SetTargetAstroId(int astroId)
|
||||
{
|
||||
AutoPilotPlugin.State = (AutoPilotPlugin.Conf.AutoStartFlag ? AutoPilotState.Active : AutoPilotState.Inactive);
|
||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
||||
}
|
||||
|
||||
public bool OperateWalk(PlayerMove_Walk __instance)
|
||||
{
|
||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var player = __instance.player;
|
||||
var mecha = player.mecha;
|
||||
AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
||||
AutoPilotPlugin.Speed = player.controller.actionSail.visual_uvel.magnitude;
|
||||
AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
|
||||
AutoPilotPlugin.LeavePlanet = true;
|
||||
AutoPilotPlugin.SpeedUp = false;
|
||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
||||
var ignoreGravityFlag = AutoPilotPlugin.Conf.IgnoreGravityFlag;
|
||||
if (ignoreGravityFlag)
|
||||
{
|
||||
player.controller.universalGravity = VectorLF3.zero;
|
||||
player.controller.localGravity = VectorLF3.zero;
|
||||
}
|
||||
__instance.controller.input0.z = 1f;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool OperateDrift(PlayerMove_Drift __instance)
|
||||
{
|
||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var player = __instance.player;
|
||||
var mecha = player.mecha;
|
||||
AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
||||
AutoPilotPlugin.Speed = player.controller.actionSail.visual_uvel.magnitude;
|
||||
AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
|
||||
AutoPilotPlugin.LeavePlanet = true;
|
||||
AutoPilotPlugin.SpeedUp = false;
|
||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
||||
var ignoreGravityFlag = AutoPilotPlugin.Conf.IgnoreGravityFlag;
|
||||
if (ignoreGravityFlag)
|
||||
{
|
||||
player.controller.universalGravity = VectorLF3.zero;
|
||||
player.controller.localGravity = VectorLF3.zero;
|
||||
}
|
||||
__instance.controller.input0.z = 1f;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool OperateFly(PlayerMove_Fly __instance)
|
||||
{
|
||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var player = __instance.player;
|
||||
var mecha = player.mecha;
|
||||
AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
||||
AutoPilotPlugin.Speed = player.controller.actionSail.visual_uvel.magnitude;
|
||||
AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
|
||||
AutoPilotPlugin.LeavePlanet = true;
|
||||
AutoPilotPlugin.SpeedUp = false;
|
||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
||||
var ignoreGravityFlag = AutoPilotPlugin.Conf.IgnoreGravityFlag;
|
||||
if (ignoreGravityFlag)
|
||||
{
|
||||
player.controller.universalGravity = VectorLF3.zero;
|
||||
player.controller.localGravity = VectorLF3.zero;
|
||||
}
|
||||
var controller = __instance.controller;
|
||||
controller.input0.y = controller.input0.y + 1f;
|
||||
var controller2 = __instance.controller;
|
||||
controller2.input1.y = controller2.input1.y + 1f;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool OperateSail(PlayerMove_Sail __instance)
|
||||
{
|
||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var player = __instance.player;
|
||||
var mecha = player.mecha;
|
||||
AutoPilotPlugin.EnergyPer = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
||||
AutoPilotPlugin.Speed = player.controller.actionSail.visual_uvel.magnitude;
|
||||
AutoPilotPlugin.WarperCount = mecha.warpStorage.GetItemCount(1210);
|
||||
AutoPilotPlugin.LeavePlanet = false;
|
||||
AutoPilotPlugin.SpeedUp = false;
|
||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
||||
if (player.warping)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AutoPilotPlugin.EnergyPer < AutoPilotPlugin.Conf.MinEnergyPer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AutoPilotPlugin.Conf.IgnoreGravityFlag)
|
||||
{
|
||||
player.controller.universalGravity = VectorLF3.zero;
|
||||
player.controller.localGravity = VectorLF3.zero;
|
||||
}
|
||||
|
||||
if (AutoPilotPlugin.Speed < AutoPilotPlugin.Conf.MaxSpeed)
|
||||
{
|
||||
AutoPilotPlugin.InputSailSpeedUp = true;
|
||||
AutoPilotPlugin.SpeedUp = true;
|
||||
}
|
||||
|
||||
if (GameMain.localPlanet == null)
|
||||
{
|
||||
if (!AutoPilotPlugin.Conf.LocalWarpFlag && GameMain.localStar != null && CruiseAssistPlugin.TargetStar.id == GameMain.localStar.id) return false;
|
||||
if (!(AutoPilotPlugin.Conf.WarpMinRangeAU * 40000.0 <= CruiseAssistPlugin.TargetRange) || !(AutoPilotPlugin.Conf.SpeedToWarp <= AutoPilotPlugin.Speed) ||
|
||||
1 > AutoPilotPlugin.WarperCount) return false;
|
||||
if (!(mecha.coreEnergy > mecha.warpStartPowerPerSpeed * mecha.maxWarpSpeed)) return false;
|
||||
if (!mecha.UseWarper()) return false;
|
||||
player.warpCommand = true;
|
||||
VFAudio.Create("warp-begin", player.transform, Vector3.zero, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
var vec = player.uPosition - GameMain.localPlanet.uPosition;
|
||||
if (120.0 < AutoPilotPlugin.Speed && Math.Max(GameMain.localPlanet.realRadius, 800f) < vec.magnitude - GameMain.localPlanet.realRadius)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
VectorLF3 result;
|
||||
if (Vector3.Angle(player.uPosition - GameMain.localPlanet.uPosition, CruiseAssistPlugin.TargetUPos - GameMain.localPlanet.uPosition) > 90f)
|
||||
{
|
||||
AutoPilotPlugin.LeavePlanet = true;
|
||||
result = vec;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = CruiseAssistPlugin.TargetUPos - player.uPosition;
|
||||
}
|
||||
var num = Vector3.Angle(result, player.uVelocity);
|
||||
var num2 = 1.6f / Mathf.Max(10f, num);
|
||||
var num3 = Math.Min(AutoPilotPlugin.Speed, 120.0);
|
||||
player.uVelocity = Vector3.Slerp(player.uVelocity, result.normalized * num3, num2);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetInactive()
|
||||
{
|
||||
AutoPilotPlugin.State = AutoPilotState.Inactive;
|
||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
||||
}
|
||||
|
||||
public void CancelOperate()
|
||||
{
|
||||
AutoPilotPlugin.State = AutoPilotState.Inactive;
|
||||
AutoPilotPlugin.InputSailSpeedUp = false;
|
||||
}
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
var uiGame = UIRoot.instance.uiGame;
|
||||
var num = CruiseAssistMainUI.Scale / 100f;
|
||||
AutoPilotMainUI.OnGUI();
|
||||
var flag = AutoPilotConfigUI.Show[CruiseAssistMainUI.WIdx];
|
||||
if (flag)
|
||||
{
|
||||
AutoPilotConfigUI.OnGUI();
|
||||
}
|
||||
var show = AutoPilotDebugUI.Show;
|
||||
if (show)
|
||||
{
|
||||
AutoPilotDebugUI.OnGUI();
|
||||
}
|
||||
var flag2 = ResetInput(AutoPilotMainUI.Rect[CruiseAssistMainUI.WIdx], num);
|
||||
var flag3 = !flag2 && AutoPilotConfigUI.Show[CruiseAssistMainUI.WIdx];
|
||||
if (flag3)
|
||||
{
|
||||
flag2 = ResetInput(AutoPilotConfigUI.Rect[CruiseAssistMainUI.WIdx], num);
|
||||
}
|
||||
var flag4 = !flag2 && AutoPilotDebugUI.Show;
|
||||
if (flag4)
|
||||
{
|
||||
flag2 = ResetInput(AutoPilotDebugUI.Rect, num);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ResetInput(Rect rect, float scale)
|
||||
{
|
||||
var num = rect.xMin * scale;
|
||||
var num2 = rect.xMax * scale;
|
||||
var num3 = rect.yMin * scale;
|
||||
var num4 = rect.yMax * scale;
|
||||
var x = Input.mousePosition.x;
|
||||
var num5 = Screen.height - Input.mousePosition.y;
|
||||
var flag = num <= x && x <= num2 && num3 <= num5 && num5 <= num4;
|
||||
if (flag)
|
||||
{
|
||||
int[] array = { 0, 1, 2 };
|
||||
var flag2 = array.Any(Input.GetMouseButton) || Input.mouseScrollDelta.y != 0f;
|
||||
if (flag2)
|
||||
{
|
||||
Input.ResetInputAxes();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
64
AutoPilot/AutoPilotPlugin.cs
Normal file
64
AutoPilot/AutoPilotPlugin.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using AutoPilot.Commons;
|
||||
using AutoPilot.Enums;
|
||||
using AutoPilot.Patches;
|
||||
using BepInEx;
|
||||
using CruiseAssist;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace AutoPilot;
|
||||
|
||||
[BepInDependency("tanu.CruiseAssist")]
|
||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||
public class AutoPilotPlugin : BaseUnityPlugin
|
||||
{
|
||||
public void Awake()
|
||||
{
|
||||
LogManager.Logger = Logger;
|
||||
new AutoPilotConfigManager(Config);
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.Awake);
|
||||
_harmony = new Harmony("tanu.AutoPilot.Patch");
|
||||
_harmony.PatchAll(typeof(Patch_VFInput));
|
||||
CruiseAssistPlugin.RegistExtension(new AutoPilotExtension());
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
CruiseAssistPlugin.UnregistExtension(typeof(AutoPilotExtension));
|
||||
_harmony.UnpatchSelf();
|
||||
}
|
||||
|
||||
public static double EnergyPer = 0.0;
|
||||
|
||||
public static double Speed = 0.0;
|
||||
|
||||
public static int WarperCount = 0;
|
||||
|
||||
public static bool LeavePlanet = false;
|
||||
|
||||
public static bool SpeedUp = false;
|
||||
|
||||
public static AutoPilotState State = AutoPilotState.Inactive;
|
||||
|
||||
public static bool InputSailSpeedUp = false;
|
||||
|
||||
private Harmony _harmony;
|
||||
|
||||
public static class Conf
|
||||
{
|
||||
public static int MinEnergyPer = 20;
|
||||
|
||||
public static int MaxSpeed = 2000;
|
||||
|
||||
public static int WarpMinRangeAU = 2;
|
||||
|
||||
public static int SpeedToWarp = 1200;
|
||||
|
||||
public static bool LocalWarpFlag = false;
|
||||
|
||||
public static bool AutoStartFlag = true;
|
||||
|
||||
public static bool IgnoreGravityFlag = true;
|
||||
|
||||
public static bool MainWindowJoinFlag = true;
|
||||
}
|
||||
}
|
||||
157
AutoPilot/Commons/ConfigManager.cs
Normal file
157
AutoPilot/Commons/ConfigManager.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace AutoPilot.Commons;
|
||||
|
||||
internal abstract class ConfigManager
|
||||
{
|
||||
public static ConfigFile Config { get; private set; }
|
||||
|
||||
protected ConfigManager(ConfigFile config)
|
||||
{
|
||||
_instance = this;
|
||||
Config = config;
|
||||
Config.SaveOnConfigSet = false;
|
||||
}
|
||||
|
||||
public static void CheckConfig(Step step)
|
||||
{
|
||||
_instance.CheckConfigImplements(step);
|
||||
}
|
||||
|
||||
protected abstract void CheckConfigImplements(Step step);
|
||||
|
||||
public static ConfigEntry<T> Bind<T>(ConfigDefinition configDefinition, T defaultValue, ConfigDescription configDescription = null)
|
||||
{
|
||||
return Config.Bind(configDefinition, defaultValue, configDescription);
|
||||
}
|
||||
|
||||
public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, ConfigDescription configDescription = null)
|
||||
{
|
||||
return Config.Bind(section, key, defaultValue, configDescription);
|
||||
}
|
||||
|
||||
public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description)
|
||||
{
|
||||
return Config.Bind(section, key, defaultValue, description);
|
||||
}
|
||||
|
||||
public static ConfigEntry<T> GetEntry<T>(ConfigDefinition configDefinition)
|
||||
{
|
||||
ConfigEntry<T> configEntry;
|
||||
try
|
||||
{
|
||||
configEntry = (ConfigEntry<T>)Config[configDefinition];
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
LogManager.LogError($"{ex.GetType()}: configDefinition={configDefinition}");
|
||||
throw;
|
||||
}
|
||||
return configEntry;
|
||||
}
|
||||
|
||||
public static ConfigEntry<T> GetEntry<T>(string section, string key)
|
||||
{
|
||||
return GetEntry<T>(new ConfigDefinition(section, key));
|
||||
}
|
||||
|
||||
public static T GetValue<T>(ConfigDefinition configDefinition)
|
||||
{
|
||||
return GetEntry<T>(configDefinition).Value;
|
||||
}
|
||||
|
||||
public static T GetValue<T>(string section, string key)
|
||||
{
|
||||
return GetEntry<T>(section, key).Value;
|
||||
}
|
||||
|
||||
public static bool ContainsKey(ConfigDefinition configDefinition)
|
||||
{
|
||||
return Config.ContainsKey(configDefinition);
|
||||
}
|
||||
|
||||
public static bool ContainsKey(string section, string key)
|
||||
{
|
||||
return Config.ContainsKey(new ConfigDefinition(section, key));
|
||||
}
|
||||
|
||||
public static bool UpdateEntry<T>(string section, string key, T value) where T : IComparable
|
||||
{
|
||||
var entry = GetEntry<T>(section, key);
|
||||
var value2 = entry.Value;
|
||||
var flag = value2.CompareTo(value) == 0;
|
||||
bool flag2;
|
||||
if (flag)
|
||||
{
|
||||
flag2 = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.Value = value;
|
||||
flag2 = true;
|
||||
}
|
||||
return flag2;
|
||||
}
|
||||
|
||||
public static bool RemoveEntry(ConfigDefinition key)
|
||||
{
|
||||
return Config.Remove(key);
|
||||
}
|
||||
|
||||
public static Dictionary<ConfigDefinition, string> GetOrphanedEntries()
|
||||
{
|
||||
var flag = _orphanedEntries == null;
|
||||
if (flag)
|
||||
{
|
||||
_orphanedEntries = Traverse.Create(Config).Property<Dictionary<ConfigDefinition, string>>("OrphanedEntries").Value;
|
||||
}
|
||||
return _orphanedEntries;
|
||||
}
|
||||
|
||||
public static void Migration<T>(string newSection, string newKey, T defaultValue, string oldSection, string oldKey)
|
||||
{
|
||||
GetOrphanedEntries();
|
||||
var configDefinition = new ConfigDefinition(oldSection, oldKey);
|
||||
var flag = _orphanedEntries.TryGetValue(configDefinition, out var text);
|
||||
if (!flag) return;
|
||||
Bind(newSection, newKey, defaultValue).SetSerializedValue(text);
|
||||
_orphanedEntries.Remove(configDefinition);
|
||||
LogManager.LogInfo(string.Concat("migration ", oldSection, ".", oldKey, "(", text, ") => ", newSection, ".", newKey));
|
||||
}
|
||||
|
||||
public static void Save(bool clearOrphanedEntries = false)
|
||||
{
|
||||
if (clearOrphanedEntries)
|
||||
{
|
||||
GetOrphanedEntries().Clear();
|
||||
}
|
||||
Config.Save();
|
||||
LogManager.LogInfo("save config.");
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
Config.Clear();
|
||||
}
|
||||
|
||||
public static void Reload()
|
||||
{
|
||||
Config.Reload();
|
||||
}
|
||||
|
||||
private static ConfigManager _instance;
|
||||
|
||||
private static Dictionary<ConfigDefinition, string> _orphanedEntries;
|
||||
|
||||
public enum Step
|
||||
{
|
||||
Awake,
|
||||
GameMainBegin,
|
||||
UniverseGenCreateGalaxy,
|
||||
State,
|
||||
ChangeSeed
|
||||
}
|
||||
}
|
||||
17
AutoPilot/Commons/EnumUtils.cs
Normal file
17
AutoPilot/Commons/EnumUtils.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace AutoPilot.Commons;
|
||||
|
||||
internal static class EnumUtils
|
||||
{
|
||||
public static bool TryParse<TEnum>(string value, out TEnum result) where TEnum : struct
|
||||
{
|
||||
if (value == null || !Enum.IsDefined(typeof(TEnum), value))
|
||||
{
|
||||
result = (TEnum)Enum.GetValues(typeof(TEnum)).GetValue(0);
|
||||
return false;
|
||||
}
|
||||
result = (TEnum)Enum.Parse(typeof(TEnum), value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
34
AutoPilot/Commons/LogManager.cs
Normal file
34
AutoPilot/Commons/LogManager.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Reflection;
|
||||
using BepInEx.Logging;
|
||||
|
||||
namespace AutoPilot.Commons;
|
||||
|
||||
internal static class LogManager
|
||||
{
|
||||
public static ManualLogSource Logger { private get; set; }
|
||||
|
||||
public static void LogInfo(object data)
|
||||
{
|
||||
Logger.LogInfo(data);
|
||||
}
|
||||
|
||||
public static void LogInfo(MethodBase method)
|
||||
{
|
||||
Logger.LogInfo(method.DeclaringType.Name + "." + method.Name);
|
||||
}
|
||||
|
||||
public static void LogInfo(MethodBase method, object data)
|
||||
{
|
||||
Logger.LogInfo(string.Concat(method.DeclaringType.Name, ".", method.Name, ": ", data?.ToString()));
|
||||
}
|
||||
|
||||
public static void LogError(object data)
|
||||
{
|
||||
Logger.LogError(data);
|
||||
}
|
||||
|
||||
public static void LogError(MethodBase method, object data)
|
||||
{
|
||||
Logger.LogError(string.Concat(method.DeclaringType.Name, ".", method.Name, ": ", data?.ToString()));
|
||||
}
|
||||
}
|
||||
7
AutoPilot/Enums/AutoPilotState.cs
Normal file
7
AutoPilot/Enums/AutoPilotState.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace AutoPilot.Enums;
|
||||
|
||||
public enum AutoPilotState
|
||||
{
|
||||
Active,
|
||||
Inactive
|
||||
}
|
||||
17
AutoPilot/Patches/Patch_VFInput.cs
Normal file
17
AutoPilot/Patches/Patch_VFInput.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using AutoPilot.Enums;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace AutoPilot.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(VFInput))]
|
||||
internal class Patch_VFInput
|
||||
{
|
||||
[HarmonyPatch("_sailSpeedUp", MethodType.Getter)]
|
||||
[HarmonyPostfix]
|
||||
public static void SailSpeedUp_Postfix(ref bool __result)
|
||||
{
|
||||
if (AutoPilotPlugin.State == AutoPilotState.Inactive) return;
|
||||
if (AutoPilotPlugin.InputSailSpeedUp)
|
||||
__result = true;
|
||||
}
|
||||
}
|
||||
176
AutoPilot/UI/AutoPilotConfigUI.cs
Normal file
176
AutoPilot/UI/AutoPilotConfigUI.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using CruiseAssist.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AutoPilot.UI;
|
||||
|
||||
internal static class AutoPilotConfigUI
|
||||
{
|
||||
public static void OnGUI()
|
||||
{
|
||||
_wIdx = CruiseAssistMainUI.WIdx;
|
||||
Rect[_wIdx] = GUILayout.Window(99031292, Rect[_wIdx], WindowFunction, "AutoPilot - Config", CruiseAssistMainUI.WindowStyle, Array.Empty<GUILayoutOption>());
|
||||
var scale = CruiseAssistMainUI.Scale / 100f;
|
||||
if (Screen.width / scale < Rect[_wIdx].xMax)
|
||||
{
|
||||
Rect[_wIdx].x = Screen.width / scale - Rect[_wIdx].width;
|
||||
}
|
||||
|
||||
if (Rect[_wIdx].x < 0f)
|
||||
{
|
||||
Rect[_wIdx].x = 0f;
|
||||
}
|
||||
|
||||
if (Screen.height / scale < Rect[_wIdx].yMax)
|
||||
{
|
||||
Rect[_wIdx].y = Screen.height / scale - Rect[_wIdx].height;
|
||||
}
|
||||
|
||||
if (Rect[_wIdx].y < 0f)
|
||||
{
|
||||
Rect[_wIdx].y = 0f;
|
||||
}
|
||||
|
||||
if (LastCheckWindowLeft[_wIdx] != float.MinValue)
|
||||
{
|
||||
if (Rect[_wIdx].x != LastCheckWindowLeft[_wIdx] || Rect[_wIdx].y != LastCheckWindowTop[_wIdx])
|
||||
{
|
||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||
}
|
||||
}
|
||||
LastCheckWindowLeft[_wIdx] = Rect[_wIdx].x;
|
||||
LastCheckWindowTop[_wIdx] = Rect[_wIdx].y;
|
||||
}
|
||||
|
||||
public static void WindowFunction(int windowId)
|
||||
{
|
||||
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
|
||||
var guistyle = new GUIStyle(GUI.skin.label)
|
||||
{
|
||||
fontSize = 12,
|
||||
fixedHeight = 20f,
|
||||
alignment = TextAnchor.MiddleLeft
|
||||
};
|
||||
var guistyle2 = new GUIStyle(CruiseAssistMainUI.BaseTextFieldStyle)
|
||||
{
|
||||
fontSize = 12,
|
||||
fixedWidth = 60f
|
||||
};
|
||||
guistyle.fixedHeight = 20f;
|
||||
guistyle2.alignment = TextAnchor.MiddleRight;
|
||||
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
|
||||
guistyle.fixedWidth = 240f;
|
||||
GUILayout.Label("Min Energy Percent (0-100 default:20)".Translate(), guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.FlexibleSpace();
|
||||
SetValue(ref TempMinEnergyPer, GUILayout.TextField(TempMinEnergyPer, guistyle2, Array.Empty<GUILayoutOption>()), 0, 100, ref AutoPilotPlugin.Conf.MinEnergyPer);
|
||||
guistyle.fixedWidth = 20f;
|
||||
GUILayout.Label("%", guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
|
||||
guistyle.fixedWidth = 240f;
|
||||
GUILayout.Label("Max Speed (0-2000 default:2000)".Translate(), guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.FlexibleSpace();
|
||||
SetValue(ref TempMaxSpeed, GUILayout.TextField(TempMaxSpeed, guistyle2, Array.Empty<GUILayoutOption>()), 0, 2000, ref AutoPilotPlugin.Conf.MaxSpeed);
|
||||
guistyle.fixedWidth = 20f;
|
||||
GUILayout.Label("m/s", guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
|
||||
guistyle.fixedWidth = 240f;
|
||||
GUILayout.Label("Warp Min Range (1-60 default:2)".Translate(), guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.FlexibleSpace();
|
||||
SetValue(ref TempWarpMinRangeAU, GUILayout.TextArea(TempWarpMinRangeAU, guistyle2, Array.Empty<GUILayoutOption>()), 1, 60, ref AutoPilotPlugin.Conf.WarpMinRangeAU);
|
||||
guistyle.fixedWidth = 20f;
|
||||
GUILayout.Label("AU", guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
|
||||
guistyle.fixedWidth = 240f;
|
||||
GUILayout.Label("Speed to warp (0-2000 default:1200)".Translate(), guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.FlexibleSpace();
|
||||
SetValue(ref TempSpeedToWarp, GUILayout.TextArea(TempSpeedToWarp, guistyle2, Array.Empty<GUILayoutOption>()), 0, 2000, ref AutoPilotPlugin.Conf.SpeedToWarp);
|
||||
guistyle.fixedWidth = 20f;
|
||||
GUILayout.Label("m/s", guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.EndHorizontal();
|
||||
var guistyle3 = new GUIStyle(CruiseAssistMainUI.BaseToggleStyle)
|
||||
{
|
||||
fixedHeight = 20f,
|
||||
fontSize = 12,
|
||||
alignment = TextAnchor.LowerLeft
|
||||
};
|
||||
GUI.changed = false;
|
||||
AutoPilotPlugin.Conf.LocalWarpFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.LocalWarpFlag, "Warp to planet in local system.".Translate(), guistyle3, Array.Empty<GUILayoutOption>());
|
||||
if (GUI.changed)
|
||||
{
|
||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||
}
|
||||
GUI.changed = false;
|
||||
AutoPilotPlugin.Conf.AutoStartFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.AutoStartFlag, "Start AutoPilot when set target planet.".Translate(), guistyle3, Array.Empty<GUILayoutOption>());
|
||||
if (GUI.changed)
|
||||
{
|
||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||
}
|
||||
GUI.changed = false;
|
||||
AutoPilotPlugin.Conf.MainWindowJoinFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.MainWindowJoinFlag, "Join AutoPilot window to CruiseAssist window.".Translate(), guistyle3, Array.Empty<GUILayoutOption>());
|
||||
if (GUI.changed)
|
||||
{
|
||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
if (GUI.Button(new Rect(Rect[_wIdx].width - 16f, 1f, 16f, 16f), "", CruiseAssistMainUI.CloseButtonStyle))
|
||||
{
|
||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||
Show[_wIdx] = false;
|
||||
}
|
||||
GUI.DragWindow();
|
||||
}
|
||||
|
||||
private static bool SetValue(ref string temp, string instr, int min, int max, ref int value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(instr))
|
||||
{
|
||||
temp = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!int.TryParse(instr, out var num)) return false;
|
||||
if (num < min)
|
||||
{
|
||||
num = min;
|
||||
}
|
||||
else if (max < num)
|
||||
{
|
||||
num = max;
|
||||
}
|
||||
value = num;
|
||||
temp = value.ToString();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static int _wIdx;
|
||||
|
||||
public const float WindowWidth = 400f;
|
||||
|
||||
public const float WindowHeight = 400f;
|
||||
|
||||
public static readonly bool[] Show = new bool[2];
|
||||
|
||||
public static readonly Rect[] Rect = {
|
||||
new Rect(0f, 0f, 400f, 400f),
|
||||
new Rect(0f, 0f, 400f, 400f)
|
||||
};
|
||||
|
||||
private static readonly float[] LastCheckWindowLeft = { float.MinValue, float.MinValue };
|
||||
|
||||
private static readonly float[] LastCheckWindowTop = { float.MinValue, float.MinValue };
|
||||
|
||||
public static string TempMinEnergyPer;
|
||||
|
||||
public static string TempMaxSpeed;
|
||||
|
||||
public static string TempWarpMinRangeAU;
|
||||
|
||||
public static string TempSpeedToWarp;
|
||||
}
|
||||
139
AutoPilot/UI/AutoPilotDebugUI.cs
Normal file
139
AutoPilot/UI/AutoPilotDebugUI.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using AutoPilot.Commons;
|
||||
using CruiseAssist;
|
||||
using CruiseAssist.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AutoPilot.UI;
|
||||
|
||||
internal class AutoPilotDebugUI
|
||||
{
|
||||
public static void OnGUI()
|
||||
{
|
||||
var guistyle = new GUIStyle(GUI.skin.window)
|
||||
{
|
||||
fontSize = 11
|
||||
};
|
||||
Rect = GUILayout.Window(99031293, Rect, WindowFunction, "AutoPilot - Debug", guistyle, Array.Empty<GUILayoutOption>());
|
||||
var num = CruiseAssistMainUI.Scale / 100f;
|
||||
var flag = Screen.width < Rect.xMax;
|
||||
if (flag)
|
||||
{
|
||||
Rect.x = Screen.width - Rect.width;
|
||||
}
|
||||
var flag2 = Rect.x < 0f;
|
||||
if (flag2)
|
||||
{
|
||||
Rect.x = 0f;
|
||||
}
|
||||
var flag3 = Screen.height < Rect.yMax;
|
||||
if (flag3)
|
||||
{
|
||||
Rect.y = Screen.height - Rect.height;
|
||||
}
|
||||
var flag4 = Rect.y < 0f;
|
||||
if (flag4)
|
||||
{
|
||||
Rect.y = 0f;
|
||||
}
|
||||
var flag5 = lastCheckWindowLeft != float.MinValue;
|
||||
if (flag5)
|
||||
{
|
||||
var flag6 = Rect.x != lastCheckWindowLeft || Rect.y != lastCheckWindowTop;
|
||||
if (flag6)
|
||||
{
|
||||
AutoPilotMainUI.NextCheckGameTick = GameMain.gameTick + 300L;
|
||||
}
|
||||
}
|
||||
lastCheckWindowLeft = Rect.x;
|
||||
lastCheckWindowTop = Rect.y;
|
||||
var flag7 = AutoPilotMainUI.NextCheckGameTick <= GameMain.gameTick;
|
||||
if (flag7)
|
||||
{
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WindowFunction(int windowId)
|
||||
{
|
||||
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
|
||||
var guistyle = new GUIStyle(GUI.skin.label)
|
||||
{
|
||||
fontSize = 12
|
||||
};
|
||||
scrollPos = GUILayout.BeginScrollView(scrollPos, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.Label($"GameMain.mainPlayer.uPosition={GameMain.mainPlayer.uPosition}", guistyle, Array.Empty<GUILayoutOption>());
|
||||
var flag = GameMain.localPlanet != null && CruiseAssistPlugin.TargetUPos != VectorLF3.zero;
|
||||
if (flag)
|
||||
{
|
||||
var mainPlayer = GameMain.mainPlayer;
|
||||
var targetUPos = CruiseAssistPlugin.TargetUPos;
|
||||
var magnitude = (targetUPos - mainPlayer.uPosition).magnitude;
|
||||
var magnitude2 = (targetUPos - GameMain.localPlanet.uPosition).magnitude;
|
||||
var vectorLF = mainPlayer.uPosition - GameMain.localPlanet.uPosition;
|
||||
var vectorLF2 = CruiseAssistPlugin.TargetUPos - GameMain.localPlanet.uPosition;
|
||||
GUILayout.Label("range1=" + RangeToString(magnitude), guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.Label("range2=" + RangeToString(magnitude2), guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.Label($"range1>range2={magnitude > magnitude2}", guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.Label($"angle={Vector3.Angle(vectorLF, vectorLF2)}", guistyle, Array.Empty<GUILayoutOption>());
|
||||
}
|
||||
var mecha = GameMain.mainPlayer.mecha;
|
||||
GUILayout.Label($"mecha.coreEnergy={mecha.coreEnergy}", guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.Label($"mecha.coreEnergyCap={mecha.coreEnergyCap}", guistyle, Array.Empty<GUILayoutOption>());
|
||||
var num = mecha.coreEnergy / mecha.coreEnergyCap * 100.0;
|
||||
GUILayout.Label($"energyPer={num}", guistyle, Array.Empty<GUILayoutOption>());
|
||||
var magnitude3 = GameMain.mainPlayer.controller.actionSail.visual_uvel.magnitude;
|
||||
GUILayout.Label("spped=" + RangeToString(magnitude3), guistyle, Array.Empty<GUILayoutOption>());
|
||||
var movementStateInFrame = GameMain.mainPlayer.controller.movementStateInFrame;
|
||||
GUILayout.Label($"movementStateInFrame={movementStateInFrame}", guistyle, Array.Empty<GUILayoutOption>());
|
||||
var guistyle2 = new GUIStyle(GUI.skin.toggle)
|
||||
{
|
||||
fixedHeight = 20f,
|
||||
fontSize = 12,
|
||||
alignment = TextAnchor.LowerLeft
|
||||
};
|
||||
GUI.changed = false;
|
||||
AutoPilotPlugin.Conf.IgnoreGravityFlag = GUILayout.Toggle(AutoPilotPlugin.Conf.IgnoreGravityFlag, "Ignore gravity.", guistyle2, Array.Empty<GUILayoutOption>());
|
||||
var changed = GUI.changed;
|
||||
if (changed)
|
||||
{
|
||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndVertical();
|
||||
GUI.DragWindow();
|
||||
}
|
||||
|
||||
public static string RangeToString(double range)
|
||||
{
|
||||
var flag = range < 10000.0;
|
||||
string text;
|
||||
if (flag)
|
||||
{
|
||||
text = ((int)(range + 0.5)) + "m ";
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag2 = range < 600000.0;
|
||||
if (flag2)
|
||||
{
|
||||
text = (range / 40000.0).ToString("0.00") + "AU";
|
||||
}
|
||||
else
|
||||
{
|
||||
text = (range / 2400000.0).ToString("0.00") + "Ly";
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public static bool Show = false;
|
||||
|
||||
public static Rect Rect = new Rect(0f, 0f, 400f, 400f);
|
||||
|
||||
private static float lastCheckWindowLeft = float.MinValue;
|
||||
|
||||
private static float lastCheckWindowTop = float.MinValue;
|
||||
|
||||
private static Vector2 scrollPos = Vector2.zero;
|
||||
}
|
||||
195
AutoPilot/UI/AutoPilotMainUI.cs
Normal file
195
AutoPilot/UI/AutoPilotMainUI.cs
Normal file
@@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using AutoPilot.Commons;
|
||||
using AutoPilot.Enums;
|
||||
using CruiseAssist;
|
||||
using CruiseAssist.Enums;
|
||||
using CruiseAssist.UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AutoPilot.UI;
|
||||
|
||||
internal class AutoPilotMainUI
|
||||
{
|
||||
public static void OnGUI()
|
||||
{
|
||||
wIdx = CruiseAssistMainUI.WIdx;
|
||||
var viewMode = CruiseAssistMainUI.ViewMode;
|
||||
var cruiseAssistMainUIViewMode = viewMode;
|
||||
if (cruiseAssistMainUIViewMode != CruiseAssistMainUIViewMode.Full)
|
||||
{
|
||||
if (cruiseAssistMainUIViewMode == CruiseAssistMainUIViewMode.Mini)
|
||||
{
|
||||
Rect[wIdx].width = CruiseAssistMainUI.Rect[wIdx].width;
|
||||
Rect[wIdx].height = 70f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Rect[wIdx].width = CruiseAssistMainUI.Rect[wIdx].width;
|
||||
Rect[wIdx].height = 150f;
|
||||
}
|
||||
var guistyle = new GUIStyle(CruiseAssistMainUI.WindowStyle)
|
||||
{
|
||||
fontSize = 11
|
||||
};
|
||||
Rect[wIdx] = GUILayout.Window(99031291, Rect[wIdx], WindowFunction, "AutoPilot", guistyle, Array.Empty<GUILayoutOption>());
|
||||
var num = CruiseAssistMainUI.Scale / 100f;
|
||||
var mainWindowJoinFlag = AutoPilotPlugin.Conf.MainWindowJoinFlag;
|
||||
if (mainWindowJoinFlag)
|
||||
{
|
||||
Rect[wIdx].x = CruiseAssistMainUI.Rect[CruiseAssistMainUI.WIdx].x;
|
||||
Rect[wIdx].y = CruiseAssistMainUI.Rect[CruiseAssistMainUI.WIdx].yMax;
|
||||
}
|
||||
var flag = Screen.width / num < Rect[wIdx].xMax;
|
||||
if (flag)
|
||||
{
|
||||
Rect[wIdx].x = Screen.width / num - Rect[wIdx].width;
|
||||
}
|
||||
var flag2 = Rect[wIdx].x < 0f;
|
||||
if (flag2)
|
||||
{
|
||||
Rect[wIdx].x = 0f;
|
||||
}
|
||||
var flag3 = Screen.height / num < Rect[wIdx].yMax;
|
||||
if (flag3)
|
||||
{
|
||||
Rect[wIdx].y = Screen.height / num - Rect[wIdx].height;
|
||||
}
|
||||
var flag4 = Rect[wIdx].y < 0f;
|
||||
if (flag4)
|
||||
{
|
||||
Rect[wIdx].y = 0f;
|
||||
}
|
||||
var flag5 = lastCheckWindowLeft[wIdx] != float.MinValue;
|
||||
if (flag5)
|
||||
{
|
||||
var flag6 = Rect[wIdx].x != lastCheckWindowLeft[wIdx] || Rect[wIdx].y != lastCheckWindowTop[wIdx];
|
||||
if (flag6)
|
||||
{
|
||||
NextCheckGameTick = GameMain.gameTick + 300L;
|
||||
}
|
||||
}
|
||||
lastCheckWindowLeft[wIdx] = Rect[wIdx].x;
|
||||
lastCheckWindowTop[wIdx] = Rect[wIdx].y;
|
||||
var flag7 = NextCheckGameTick <= GameMain.gameTick;
|
||||
if (flag7)
|
||||
{
|
||||
ConfigManager.CheckConfig(ConfigManager.Step.State);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WindowFunction(int windowId)
|
||||
{
|
||||
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
|
||||
var flag = CruiseAssistMainUI.ViewMode == CruiseAssistMainUIViewMode.Full;
|
||||
if (flag)
|
||||
{
|
||||
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
|
||||
var guistyle = new GUIStyle(GUI.skin.label)
|
||||
{
|
||||
fontSize = 12
|
||||
};
|
||||
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
|
||||
var text = ((AutoPilotPlugin.State == AutoPilotState.Inactive) ? "---" : ((AutoPilotPlugin.Conf.MinEnergyPer < AutoPilotPlugin.EnergyPer) ? "OK" : "NG"));
|
||||
guistyle.normal.textColor = ((text == "OK") ? Color.cyan : ((text == "NG") ? Color.red : Color.white));
|
||||
GUILayout.Label("Energy : " + text, guistyle, Array.Empty<GUILayoutOption>());
|
||||
var text2 = ((AutoPilotPlugin.State == AutoPilotState.Inactive) ? "---" : ((CruiseAssistPlugin.TargetStar == null) ? "---" : (GameMain.mainPlayer.warping ? "---" : ((!AutoPilotPlugin.Conf.LocalWarpFlag && GameMain.localStar != null && CruiseAssistPlugin.TargetStar.id == GameMain.localStar.id) ? "---" : ((CruiseAssistPlugin.TargetRange < (double)(AutoPilotPlugin.Conf.WarpMinRangeAU * 40000)) ? "---" : ((AutoPilotPlugin.WarperCount < 1) ? "NG" : "OK"))))));
|
||||
guistyle.normal.textColor = ((text2 == "OK") ? Color.cyan : ((text2 == "NG") ? Color.red : Color.white));
|
||||
GUILayout.Label("Warper : " + text2, guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
|
||||
var text3 = ((AutoPilotPlugin.State == AutoPilotState.Inactive) ? "---" : (AutoPilotPlugin.LeavePlanet ? "ON" : "OFF"));
|
||||
guistyle.normal.textColor = ((text3 == "ON") ? Color.cyan : Color.white);
|
||||
GUILayout.Label("Leave Planet : " + text3, guistyle, Array.Empty<GUILayoutOption>());
|
||||
var text4 = ((AutoPilotPlugin.State == AutoPilotState.Inactive) ? "---" : (AutoPilotPlugin.SpeedUp ? "ON" : "OFF"));
|
||||
guistyle.normal.textColor = ((text4 == "ON") ? Color.cyan : Color.white);
|
||||
GUILayout.Label("Spee UP : " + text4, guistyle, Array.Empty<GUILayoutOption>());
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
}
|
||||
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
|
||||
var guistyle2 = new GUIStyle(GUI.skin.label)
|
||||
{
|
||||
fixedWidth = 160f,
|
||||
fixedHeight = 32f,
|
||||
fontSize = 14,
|
||||
alignment = TextAnchor.MiddleLeft
|
||||
};
|
||||
var flag2 = AutoPilotPlugin.State == AutoPilotState.Inactive;
|
||||
if (flag2)
|
||||
{
|
||||
GUILayout.Label("Auto Pilot Inactive.", guistyle2, Array.Empty<GUILayoutOption>());
|
||||
}
|
||||
else
|
||||
{
|
||||
guistyle2.normal.textColor = Color.cyan;
|
||||
GUILayout.Label("Auto Pilot Active.", guistyle2, Array.Empty<GUILayoutOption>());
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
var guistyle3 = new GUIStyle(CruiseAssistMainUI.BaseButtonStyle)
|
||||
{
|
||||
fixedWidth = 50f,
|
||||
fixedHeight = 18f,
|
||||
fontSize = 11,
|
||||
alignment = TextAnchor.MiddleCenter
|
||||
};
|
||||
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
|
||||
var flag3 = GUILayout.Button("Config", guistyle3, Array.Empty<GUILayoutOption>());
|
||||
if (flag3)
|
||||
{
|
||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||
var show = AutoPilotConfigUI.Show;
|
||||
var num = wIdx;
|
||||
show[num] = !show[num];
|
||||
var flag4 = AutoPilotConfigUI.Show[wIdx];
|
||||
if (flag4)
|
||||
{
|
||||
AutoPilotConfigUI.TempMinEnergyPer = AutoPilotPlugin.Conf.MinEnergyPer.ToString();
|
||||
AutoPilotConfigUI.TempMaxSpeed = AutoPilotPlugin.Conf.MaxSpeed.ToString();
|
||||
AutoPilotConfigUI.TempWarpMinRangeAU = AutoPilotPlugin.Conf.WarpMinRangeAU.ToString();
|
||||
AutoPilotConfigUI.TempSpeedToWarp = AutoPilotPlugin.Conf.SpeedToWarp.ToString();
|
||||
}
|
||||
}
|
||||
var flag5 = GUILayout.Button("Start", guistyle3, Array.Empty<GUILayoutOption>());
|
||||
if (flag5)
|
||||
{
|
||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||
AutoPilotPlugin.State = AutoPilotState.Active;
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
|
||||
GUILayout.Button("-", guistyle3, Array.Empty<GUILayoutOption>());
|
||||
var flag6 = GUILayout.Button("Stop", guistyle3, Array.Empty<GUILayoutOption>());
|
||||
if (flag6)
|
||||
{
|
||||
VFAudio.Create("ui-click-0", null, Vector3.zero, true);
|
||||
AutoPilotPlugin.State = AutoPilotState.Inactive;
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
GUI.DragWindow();
|
||||
}
|
||||
|
||||
private static int wIdx;
|
||||
|
||||
public const float WindowWidthFull = 398f;
|
||||
|
||||
public const float WindowHeightFull = 150f;
|
||||
|
||||
public const float WindowWidthMini = 288f;
|
||||
|
||||
public const float WindowHeightMini = 70f;
|
||||
|
||||
public static Rect[] Rect = {
|
||||
new Rect(0f, 0f, 398f, 150f),
|
||||
new Rect(0f, 0f, 398f, 150f)
|
||||
};
|
||||
|
||||
private static float[] lastCheckWindowLeft = { float.MinValue, float.MinValue };
|
||||
|
||||
private static float[] lastCheckWindowTop = { float.MinValue, float.MinValue };
|
||||
|
||||
public static long NextCheckGameTick = long.MaxValue;
|
||||
}
|
||||
BIN
AutoPilot/package/icon.png
Normal file
BIN
AutoPilot/package/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
10
AutoPilot/package/manifest.json
Normal file
10
AutoPilot/package/manifest.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "AutoPilot",
|
||||
"version_number": "0.0.4",
|
||||
"website_url": "https://github.com/tanukinomori/DSPMod",
|
||||
"description": "Auto pilot to a planet or star system.",
|
||||
"dependencies": [
|
||||
"xiaoye97-BepInEx-5.4.17",
|
||||
"tanu-CruiseAssist-0.0.37"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user