mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 04:53:30 +08:00
WIP
This commit is contained in:
57
CheatEnabler/AbnormalDiabler.cs
Normal file
57
CheatEnabler/AbnormalDiabler.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
using HarmonyLib;
|
||||||
|
|
||||||
|
namespace CheatEnabler;
|
||||||
|
public static class AbnormalDisabler
|
||||||
|
{
|
||||||
|
public static ConfigEntry<bool> Enabled;
|
||||||
|
private static Dictionary<int, AbnormalityDeterminator> _savedDeterminators;
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyBeforeGameSave")]
|
||||||
|
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnAssemblerRecipePick")]
|
||||||
|
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnGameBegin")]
|
||||||
|
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnMechaForgeTaskComplete")]
|
||||||
|
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUnlockTech")]
|
||||||
|
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUseConsole")]
|
||||||
|
private static bool DisableAbnormalLogic()
|
||||||
|
{
|
||||||
|
return !Enabled.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(AbnormalityLogic), "InitDeterminators")]
|
||||||
|
private static void DisableAbnormalDeterminators(AbnormalityLogic __instance)
|
||||||
|
{
|
||||||
|
_savedDeterminators = __instance.determinators;
|
||||||
|
Enabled.SettingChanged += (_, _) =>
|
||||||
|
{
|
||||||
|
if (Enabled.Value)
|
||||||
|
{
|
||||||
|
_savedDeterminators = __instance.determinators;
|
||||||
|
__instance.determinators = new Dictionary<int, AbnormalityDeterminator>();
|
||||||
|
foreach (var p in _savedDeterminators)
|
||||||
|
{
|
||||||
|
p.Value.OnUnregEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__instance.determinators = _savedDeterminators;
|
||||||
|
foreach (var p in _savedDeterminators)
|
||||||
|
{
|
||||||
|
p.Value.OnRegEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_savedDeterminators = __instance.determinators;
|
||||||
|
if (!Enabled.Value) return;
|
||||||
|
__instance.determinators = new Dictionary<int, AbnormalityDeterminator>();
|
||||||
|
foreach (var p in _savedDeterminators)
|
||||||
|
{
|
||||||
|
p.Value.OnUnregEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
|
using BepInEx.Configuration;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
|
||||||
namespace CheatEnabler;
|
namespace CheatEnabler;
|
||||||
@@ -10,11 +11,12 @@ namespace CheatEnabler;
|
|||||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||||
public class CheatEnabler : BaseUnityPlugin
|
public class CheatEnabler : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
private new static readonly BepInEx.Logging.ManualLogSource Logger =
|
public new static readonly BepInEx.Logging.ManualLogSource Logger =
|
||||||
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
||||||
|
|
||||||
private bool _devShortcuts = true;
|
private static bool _initialized = false;
|
||||||
private bool _disableAbnormalChecks = true;
|
private static KeyboardShortcut _shortcut = KeyboardShortcut.Deserialize("H + LeftControl");
|
||||||
|
private static UIConfigWindow _configWin;
|
||||||
private bool _alwaysInfiniteResource = true;
|
private bool _alwaysInfiniteResource = true;
|
||||||
private bool _waterPumpAnywhere = true;
|
private bool _waterPumpAnywhere = true;
|
||||||
private static bool _sitiVeinsOnBirthPlanet = true;
|
private static bool _sitiVeinsOnBirthPlanet = true;
|
||||||
@@ -33,9 +35,9 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
_devShortcuts = Config.Bind("General", "DevShortcuts", _devShortcuts, "enable DevMode shortcuts").Value;
|
DevShortcuts.Enabled = Config.Bind("General", "DevShortcuts", true, "enable DevMode shortcuts");
|
||||||
_disableAbnormalChecks = Config.Bind("General", "DisableAbnormalChecks", _disableAbnormalChecks,
|
AbnormalDisabler.Enabled = Config.Bind("General", "DisableAbnormalChecks", false,
|
||||||
"disable all abnormal checks").Value;
|
"disable all abnormal checks");
|
||||||
_alwaysInfiniteResource = Config.Bind("General", "AlwaysInfiniteResource", _alwaysInfiniteResource,
|
_alwaysInfiniteResource = Config.Bind("General", "AlwaysInfiniteResource", _alwaysInfiniteResource,
|
||||||
"always infinite resource").Value;
|
"always infinite resource").Value;
|
||||||
_unlockTechToMaximumLevel = Config.Bind("General", "UnlockTechToMaxLevel", _unlockTechToMaximumLevel,
|
_unlockTechToMaximumLevel = Config.Bind("General", "UnlockTechToMaxLevel", _unlockTechToMaximumLevel,
|
||||||
@@ -69,16 +71,10 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
|
|
||||||
// UI Patch
|
// UI Patch
|
||||||
Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch));
|
Harmony.CreateAndPatchAll(typeof(UI.MyWindowManager.Patch));
|
||||||
|
Harmony.CreateAndPatchAll(typeof(CheatEnabler));
|
||||||
|
|
||||||
if (_devShortcuts)
|
|
||||||
{
|
|
||||||
Harmony.CreateAndPatchAll(typeof(DevShortcuts));
|
Harmony.CreateAndPatchAll(typeof(DevShortcuts));
|
||||||
}
|
|
||||||
|
|
||||||
if (_disableAbnormalChecks)
|
|
||||||
{
|
|
||||||
Harmony.CreateAndPatchAll(typeof(AbnormalDisabler));
|
Harmony.CreateAndPatchAll(typeof(AbnormalDisabler));
|
||||||
}
|
|
||||||
|
|
||||||
if (_alwaysInfiniteResource)
|
if (_alwaysInfiniteResource)
|
||||||
{
|
{
|
||||||
@@ -116,61 +112,38 @@ public class CheatEnabler : BaseUnityPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DevShortcuts
|
private void Update()
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
if (!GameMain.isRunning)
|
||||||
[HarmonyPatch(typeof(PlayerController), "Init")]
|
|
||||||
private static void PlayerControllerInit(PlayerController __instance)
|
|
||||||
{
|
{
|
||||||
var cnt = __instance.actions.Length;
|
return;
|
||||||
var newActions = new PlayerAction[cnt + 1];
|
|
||||||
for (var i = 0; i < cnt; i++)
|
|
||||||
{
|
|
||||||
newActions[i] = __instance.actions[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var test = new PlayerAction_Test();
|
if (VFInput.inputing)
|
||||||
test.Init(__instance.player);
|
{
|
||||||
newActions[cnt] = test;
|
return;
|
||||||
__instance.actions = newActions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
if (_shortcut.IsDown())
|
||||||
[HarmonyPatch(typeof(PlayerAction_Test), "GameTick")]
|
|
||||||
private static void PlayerAction_TestGameTick(PlayerAction_Test __instance)
|
|
||||||
{
|
{
|
||||||
var lastActive = __instance.active;
|
if (_configWin.active)
|
||||||
__instance.Update();
|
|
||||||
if (lastActive != __instance.active)
|
|
||||||
{
|
{
|
||||||
UIRealtimeTip.PopupAhead(
|
_configWin._Close();
|
||||||
(lastActive ? "Developer Mode Shortcuts Disabled" : "Developer Mode Shortcuts Enabled").Translate(),
|
}
|
||||||
false);
|
else
|
||||||
|
{
|
||||||
|
UIRoot.instance.uiGame.ShutPlayerInventory();
|
||||||
|
_configWin.Open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AbnormalDisabler
|
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnCreate")]
|
||||||
|
public static void UIGame__OnCreate_Postfix()
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
if (_initialized) return;
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyBeforeGameSave")]
|
_initialized = true;
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnAssemblerRecipePick")]
|
_configWin = UIConfigWindow.CreateInstance();
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnGameBegin")]
|
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnMechaForgeTaskComplete")]
|
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUnlockTech")]
|
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), "NotifyOnUseConsole")]
|
|
||||||
private static bool DisableAbnormalLogic()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPrefix]
|
|
||||||
[HarmonyPatch(typeof(AbnormalityLogic), "InitDeterminators")]
|
|
||||||
private static bool DisableAbnormalDeterminators(ref Dictionary<int, AbnormalityDeterminator> ___determinators)
|
|
||||||
{
|
|
||||||
___determinators = new Dictionary<int, AbnormalityDeterminator>();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AlwaysInfiniteResource
|
private class AlwaysInfiniteResource
|
||||||
|
|||||||
48
CheatEnabler/DevShortcuts.cs
Normal file
48
CheatEnabler/DevShortcuts.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using BepInEx.Configuration;
|
||||||
|
using HarmonyLib;
|
||||||
|
|
||||||
|
namespace CheatEnabler;
|
||||||
|
public class DevShortcuts
|
||||||
|
{
|
||||||
|
public static ConfigEntry<bool> Enabled;
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(PlayerController), "Init")]
|
||||||
|
private static void PlayerController_Init_Postfix(PlayerController __instance)
|
||||||
|
{
|
||||||
|
var cnt = __instance.actions.Length;
|
||||||
|
var newActions = new PlayerAction[cnt + 1];
|
||||||
|
for (var i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
newActions[i] = __instance.actions[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
var test = new PlayerAction_Test();
|
||||||
|
test.Init(__instance.player);
|
||||||
|
newActions[cnt] = test;
|
||||||
|
__instance.actions = newActions;
|
||||||
|
|
||||||
|
Enabled.SettingChanged += (_, _) =>
|
||||||
|
{
|
||||||
|
if (!Enabled.Value)
|
||||||
|
{
|
||||||
|
test.active = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(PlayerAction_Test), "GameTick")]
|
||||||
|
private static void PlayerAction_Test_GameTick_Postfix(PlayerAction_Test __instance)
|
||||||
|
{
|
||||||
|
if (!Enabled.Value) return;
|
||||||
|
var lastActive = __instance.active;
|
||||||
|
__instance.Update();
|
||||||
|
if (lastActive != __instance.active)
|
||||||
|
{
|
||||||
|
UIRealtimeTip.PopupAhead(
|
||||||
|
(lastActive ? "Developer Mode Shortcuts Disabled" : "Developer Mode Shortcuts Enabled").Translate(),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using BepInEx.Configuration;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@@ -11,8 +12,10 @@ public class MyCheckBox : MonoBehaviour
|
|||||||
public Image checkImage;
|
public Image checkImage;
|
||||||
public RectTransform rectTrans;
|
public RectTransform rectTrans;
|
||||||
public Text labelText;
|
public Text labelText;
|
||||||
|
|
||||||
public event Action OnChecked;
|
public event Action OnChecked;
|
||||||
|
private bool _checked;
|
||||||
|
private ConfigEntry<bool> _configAssigned;
|
||||||
|
|
||||||
public bool Checked
|
public bool Checked
|
||||||
{
|
{
|
||||||
get => _checked;
|
get => _checked;
|
||||||
@@ -23,30 +26,25 @@ public class MyCheckBox : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _checked;
|
public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, ConfigEntry<bool> config, string label = "", int fontSize = 15)
|
||||||
|
{
|
||||||
|
var cb = CreateCheckBox(x, y, parent, config.Value, label, fontSize);
|
||||||
|
cb._configAssigned = config;
|
||||||
|
cb.OnChecked += () => config.Value = !config.Value;
|
||||||
|
config.SettingChanged += (_, _) => cb.Checked = config.Value;
|
||||||
|
return cb;
|
||||||
|
}
|
||||||
|
|
||||||
public static MyCheckBox CreateCheckBox(bool check, Transform parent = null, float x = 0f, float y = 0f, string label = "", int fontSize = 15)
|
public static MyCheckBox CreateCheckBox(float x, float y, RectTransform parent, bool check, string label = "", int fontSize = 15)
|
||||||
{
|
{
|
||||||
var buildMenu = UIRoot.instance.uiGame.buildMenu;
|
var buildMenu = UIRoot.instance.uiGame.buildMenu;
|
||||||
var src = buildMenu.uxFacilityCheck;
|
var src = buildMenu.uxFacilityCheck;
|
||||||
|
|
||||||
var go = Instantiate(src.gameObject);
|
var go = Instantiate(src.gameObject);
|
||||||
var rect = go.transform as RectTransform;
|
|
||||||
if (rect == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
go.name = "my-checkbox";
|
go.name = "my-checkbox";
|
||||||
var cb = go.AddComponent<MyCheckBox>();
|
var cb = go.AddComponent<MyCheckBox>();
|
||||||
cb._checked = check;
|
cb._checked = check;
|
||||||
if (parent != null)
|
var rect = Util.NormalizeRectWithTopLeft(cb, x, y, parent);
|
||||||
{
|
|
||||||
rect.SetParent(parent);
|
|
||||||
}
|
|
||||||
rect.anchorMax = new Vector2(0f, 1f);
|
|
||||||
rect.anchorMin = new Vector2(0f, 1f);
|
|
||||||
rect.pivot = new Vector2(0f, 1f);
|
|
||||||
rect.anchoredPosition3D = new Vector3(x, -y, 0f);
|
|
||||||
|
|
||||||
cb.rectTrans = rect;
|
cb.rectTrans = rect;
|
||||||
cb.uiButton = go.GetComponent<UIButton>();
|
cb.uiButton = go.GetComponent<UIButton>();
|
||||||
|
|||||||
123
CheatEnabler/UI/MySlider.cs
Normal file
123
CheatEnabler/UI/MySlider.cs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace CheatEnabler.UI;
|
||||||
|
|
||||||
|
// MySlider modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MySlider.cs
|
||||||
|
|
||||||
|
public class MySlider : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Slider slider;
|
||||||
|
public RectTransform rectTrans;
|
||||||
|
public Text labelText;
|
||||||
|
public string labelFormat;
|
||||||
|
public event Action OnValueChanged;
|
||||||
|
private float _value;
|
||||||
|
public float Value
|
||||||
|
{
|
||||||
|
get => _value;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
OnValueSet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RectTransform CreateSlider(float x, float y, RectTransform parent, float value, float minValue, float maxValue, string format = "{0}", float width = 0f)
|
||||||
|
{
|
||||||
|
var optionWindow = UIRoot.instance.optionWindow;
|
||||||
|
var src = optionWindow.audioVolumeComp;
|
||||||
|
|
||||||
|
var go = Instantiate(src.gameObject);
|
||||||
|
//sizeDelta = 240, 20
|
||||||
|
go.name = "my-slider";
|
||||||
|
go.SetActive(true);
|
||||||
|
var sl = go.AddComponent<MySlider>();
|
||||||
|
sl._value = value;
|
||||||
|
var rect = Util.NormalizeRectWithTopLeft(sl, x, y, parent);
|
||||||
|
sl.rectTrans = rect;
|
||||||
|
if (width > 0)
|
||||||
|
{
|
||||||
|
rect.sizeDelta = new Vector2(width, rect.sizeDelta.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
sl.slider = go.GetComponent<Slider>();
|
||||||
|
sl.slider.minValue = minValue;
|
||||||
|
sl.slider.maxValue = maxValue;
|
||||||
|
sl.slider.onValueChanged.RemoveAllListeners();
|
||||||
|
sl.slider.onValueChanged.AddListener(sl.SliderChanged);
|
||||||
|
sl.labelText = sl.slider.handleRect.Find("Text")?.GetComponent<Text>();
|
||||||
|
if (sl.labelText != null)
|
||||||
|
{
|
||||||
|
sl.labelText.fontSize = 14;
|
||||||
|
if (sl.labelText.transform is RectTransform rectTrans)
|
||||||
|
{
|
||||||
|
rectTrans.sizeDelta = new Vector2(22f, 22f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sl.labelFormat = format;
|
||||||
|
|
||||||
|
var bg = sl.slider.transform.Find("Background")?.GetComponent<Image>();
|
||||||
|
if (bg != null)
|
||||||
|
{
|
||||||
|
bg.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
|
||||||
|
}
|
||||||
|
var fill = sl.slider.fillRect.GetComponent<Image>();
|
||||||
|
if (fill != null)
|
||||||
|
{
|
||||||
|
fill.color = new Color(1f, 1f, 1f, 0.28f);
|
||||||
|
}
|
||||||
|
sl.OnValueSet();
|
||||||
|
sl.UpdateLabel();
|
||||||
|
|
||||||
|
return sl.rectTrans;
|
||||||
|
}
|
||||||
|
public void OnValueSet()
|
||||||
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
var sliderVal = _value;
|
||||||
|
if (_value.Equals(slider.value)) return;
|
||||||
|
if (sliderVal > slider.maxValue)
|
||||||
|
{
|
||||||
|
_value = sliderVal = slider.maxValue;
|
||||||
|
}
|
||||||
|
else if (sliderVal < slider.minValue)
|
||||||
|
{
|
||||||
|
_value = sliderVal = slider.minValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
slider.value = sliderVal;
|
||||||
|
UpdateLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void UpdateLabel()
|
||||||
|
{
|
||||||
|
if (labelText != null)
|
||||||
|
{
|
||||||
|
labelText.text = _value.ToString(labelFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetLabelText(string text)
|
||||||
|
{
|
||||||
|
if (labelText != null)
|
||||||
|
{
|
||||||
|
labelText.text = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SliderChanged(float val)
|
||||||
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
var newVal = Mathf.Round(slider.value);
|
||||||
|
if (_value.Equals(newVal)) return;
|
||||||
|
_value = newVal;
|
||||||
|
UpdateLabel();
|
||||||
|
OnValueChanged?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,17 +1,221 @@
|
|||||||
using HarmonyLib;
|
using System;
|
||||||
|
using HarmonyLib;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace CheatEnabler.UI;
|
namespace CheatEnabler.UI;
|
||||||
|
|
||||||
// MyWindowManager modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MyWindowCtl.cs
|
// MyWindow modified from LSTM: https://github.com/hetima/DSP_LSTM/blob/main/LSTM/MyWindowCtl.cs
|
||||||
|
|
||||||
|
public class MyWindow: ManualBehaviour
|
||||||
|
{
|
||||||
|
private readonly Dictionary<InputField, Tuple<UnityAction<string>, UnityAction<string>>> _inputFields = new();
|
||||||
|
protected bool EventRegistered { get; private set; }
|
||||||
|
|
||||||
|
public virtual void TryClose()
|
||||||
|
{
|
||||||
|
_Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool IsWindowFunctional()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Open()
|
||||||
|
{
|
||||||
|
_Open();
|
||||||
|
transform.SetAsLastSibling();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close() => _Close();
|
||||||
|
|
||||||
|
public void SetTitle(string title)
|
||||||
|
{
|
||||||
|
var txt = gameObject.transform.Find("panel-bg/title-text")?.gameObject.GetComponent<Text>();
|
||||||
|
if (txt)
|
||||||
|
{
|
||||||
|
txt.text = title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddElement(float x, float y, RectTransform rect, RectTransform parent = null)
|
||||||
|
{
|
||||||
|
if (rect != null)
|
||||||
|
{
|
||||||
|
Util.NormalizeRectWithTopLeft(rect, x, y, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Text AddText(float x, float y, RectTransform parent, string label, int fontSize = 14, string objName = "label")
|
||||||
|
{
|
||||||
|
var src = UIRoot.instance.uiGame.assemblerWindow.stateText;
|
||||||
|
var txt = Instantiate(src);
|
||||||
|
txt.gameObject.name = objName;
|
||||||
|
txt.text = label;
|
||||||
|
txt.color = new Color(1f, 1f, 1f, 0.4f);
|
||||||
|
txt.alignment = TextAnchor.MiddleLeft;
|
||||||
|
txt.fontSize = fontSize;
|
||||||
|
if (txt.transform is RectTransform rect)
|
||||||
|
{
|
||||||
|
rect.sizeDelta = new Vector2(txt.preferredWidth + 40f, 30f);
|
||||||
|
}
|
||||||
|
AddElement(x, y, txt.rectTransform, parent);
|
||||||
|
return txt;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InputField AddInputField(float x, float y, RectTransform parent, string text = "", int fontSize = 16, string objName = "input", UnityAction<string> onChanged = null, UnityAction<string> onEditEnd = null)
|
||||||
|
{
|
||||||
|
var stationWindow = UIRoot.instance.uiGame.stationWindow;
|
||||||
|
//public InputField nameInput;
|
||||||
|
var inputField = Instantiate(stationWindow.nameInput);
|
||||||
|
inputField.gameObject.name = "search-field";
|
||||||
|
Destroy(inputField.GetComponent<UIButton>());
|
||||||
|
inputField.GetComponent<Image>().color = new Color(1f, 1f, 1f, 0.05f);
|
||||||
|
var rect = Util.NormalizeRectWithTopLeft(inputField, x, y, parent);
|
||||||
|
rect.sizeDelta = new Vector2(210, rect.sizeDelta.y);
|
||||||
|
inputField.textComponent.text = text;
|
||||||
|
inputField.textComponent.fontSize = fontSize;
|
||||||
|
_inputFields[inputField] = Tuple.Create(onChanged, onEditEnd);
|
||||||
|
if (EventRegistered)
|
||||||
|
{
|
||||||
|
if (onChanged != null)
|
||||||
|
inputField.onValueChanged.AddListener(onChanged);
|
||||||
|
if (onEditEnd != null)
|
||||||
|
inputField.onEndEdit.AddListener(onEditEnd);
|
||||||
|
}
|
||||||
|
return inputField;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnRegEvent()
|
||||||
|
{
|
||||||
|
base._OnRegEvent();
|
||||||
|
if (EventRegistered) return;
|
||||||
|
foreach (var t in _inputFields)
|
||||||
|
{
|
||||||
|
var inputField = t.Key;
|
||||||
|
if (t.Value.Item1 != null)
|
||||||
|
inputField.onValueChanged.AddListener(t.Value.Item1);
|
||||||
|
if (t.Value.Item2 != null)
|
||||||
|
inputField.onEndEdit.AddListener(t.Value.Item2);
|
||||||
|
}
|
||||||
|
EventRegistered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnUnregEvent()
|
||||||
|
{
|
||||||
|
base._OnUnregEvent();
|
||||||
|
if (!EventRegistered) return;
|
||||||
|
EventRegistered = false;
|
||||||
|
foreach (var t in _inputFields)
|
||||||
|
{
|
||||||
|
var inputField = t.Key;
|
||||||
|
if (t.Value.Item1 != null)
|
||||||
|
inputField.onValueChanged.RemoveListener(t.Value.Item1);
|
||||||
|
if (t.Value.Item2 != null)
|
||||||
|
inputField.onEndEdit.RemoveListener(t.Value.Item2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MyWindowWithTabs : MyWindow
|
||||||
|
{
|
||||||
|
private readonly List<Tuple<RectTransform, UIButton>> _tabs = new();
|
||||||
|
public override void TryClose()
|
||||||
|
{
|
||||||
|
_Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsWindowFunctional()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RectTransform AddTab(float x, int index, RectTransform parent, string label)
|
||||||
|
{
|
||||||
|
var tab = new GameObject();
|
||||||
|
var tabRect = tab.AddComponent<RectTransform>();
|
||||||
|
Util.NormalizeRectWithMargin(tabRect, 54f + 28f, 36f, 0f, 0f, parent);
|
||||||
|
tab.name = "tab-" + index;
|
||||||
|
var swarmPanel = UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.swarmPanel;
|
||||||
|
var src = swarmPanel.orbitButtons[0];
|
||||||
|
var btn = Instantiate(src);
|
||||||
|
var btnRect = Util.NormalizeRectWithTopLeft(btn, x, 54f, parent);
|
||||||
|
btnRect.sizeDelta = new Vector2(100f, 24f);
|
||||||
|
btn.transform.Find("frame").gameObject.SetActive(false);
|
||||||
|
if (btn.transitions.Length >= 3)
|
||||||
|
{
|
||||||
|
btn.transitions[0].normalColor = new Color(0.1f, 0.1f, 0.1f, 0.68f);
|
||||||
|
btn.transitions[0].highlightColorOverride = new Color(0.9906f, 0.5897f, 0.3691f, 0.4f);
|
||||||
|
btn.transitions[1].normalColor = new Color(1f, 1f, 1f, 0.6f);
|
||||||
|
btn.transitions[1].highlightColorOverride = new Color(0.2f, 0.1f, 0.1f, 0.9f);
|
||||||
|
}
|
||||||
|
|
||||||
|
var btnText = btn.transform.Find("Text").GetComponent<Text>();
|
||||||
|
btnText.text = label;
|
||||||
|
btnText.fontSize = 16;
|
||||||
|
btn.data = index;
|
||||||
|
|
||||||
|
_tabs.Add(Tuple.Create(tabRect, btn));
|
||||||
|
if (EventRegistered)
|
||||||
|
{
|
||||||
|
btn.onClick += OnTabButtonClick;
|
||||||
|
}
|
||||||
|
return tabRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnRegEvent()
|
||||||
|
{
|
||||||
|
if (!EventRegistered)
|
||||||
|
{
|
||||||
|
foreach (var t in _tabs)
|
||||||
|
{
|
||||||
|
t.Item2.onClick += OnTabButtonClick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base._OnRegEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnUnregEvent()
|
||||||
|
{
|
||||||
|
if (EventRegistered)
|
||||||
|
{
|
||||||
|
foreach (var t in _tabs)
|
||||||
|
{
|
||||||
|
t.Item2.onClick -= OnTabButtonClick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base._OnUnregEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void SetCurrentTab(int index) => OnTabButtonClick(index);
|
||||||
|
|
||||||
|
private void OnTabButtonClick(int index)
|
||||||
|
{
|
||||||
|
foreach (var t in _tabs)
|
||||||
|
{
|
||||||
|
var btn = t.Item2;
|
||||||
|
if (btn.data != index)
|
||||||
|
{
|
||||||
|
btn.highlighted = false;
|
||||||
|
t.Item1.gameObject.SetActive(false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
btn.highlighted = true;
|
||||||
|
t.Item1.gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class MyWindowManager
|
public static class MyWindowManager
|
||||||
{
|
{
|
||||||
private static readonly List<ManualBehaviour> Windows = new(4);
|
private static readonly List<ManualBehaviour> Windows = new(4);
|
||||||
private static bool _inited = false;
|
private static bool _initialized = false;
|
||||||
|
|
||||||
public static T CreateWindow<T>(string name, string title = "") where T : Component
|
public static T CreateWindow<T>(string name, string title = "") where T : MyWindow
|
||||||
{
|
{
|
||||||
var srcWin = UIRoot.instance.uiGame.tankWindow;
|
var srcWin = UIRoot.instance.uiGame.tankWindow;
|
||||||
var src = srcWin.gameObject;
|
var src = srcWin.gameObject;
|
||||||
@@ -19,10 +223,10 @@ public static class MyWindowManager
|
|||||||
go.name = name;
|
go.name = name;
|
||||||
go.SetActive(false);
|
go.SetActive(false);
|
||||||
Object.Destroy(go.GetComponent<UITankWindow>());
|
Object.Destroy(go.GetComponent<UITankWindow>());
|
||||||
var win = go.AddComponent<T>() as ManualBehaviour;
|
var win = go.AddComponent<T>() as MyWindow;
|
||||||
if (win == null)
|
if (win == null)
|
||||||
return null;
|
return null;
|
||||||
//shadow
|
|
||||||
for (var i = 0; i < go.transform.childCount; i++)
|
for (var i = 0; i < go.transform.childCount; i++)
|
||||||
{
|
{
|
||||||
var child = go.transform.GetChild(i).gameObject;
|
var child = go.transform.GetChild(i).gameObject;
|
||||||
@@ -34,10 +238,6 @@ public static class MyWindowManager
|
|||||||
{
|
{
|
||||||
btn.onClick.AddListener(win._Close);
|
btn.onClick.AddListener(win._Close);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (child.name != "shadow" && child.name != "panel-bg")
|
else if (child.name != "shadow" && child.name != "panel-bg")
|
||||||
{
|
{
|
||||||
@@ -45,33 +245,14 @@ public static class MyWindowManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTitle(win, title);
|
win.SetTitle(title);
|
||||||
win._Create();
|
win._Create();
|
||||||
if (_inited)
|
if (_initialized)
|
||||||
{
|
{
|
||||||
win._Init(win.data);
|
win._Init(win.data);
|
||||||
}
|
}
|
||||||
Windows.Add(win);
|
Windows.Add(win);
|
||||||
return win as T;
|
return (T)win;
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetTitle(ManualBehaviour win, string title)
|
|
||||||
{
|
|
||||||
var txt = GetTitleText(win);
|
|
||||||
if (txt)
|
|
||||||
{
|
|
||||||
txt.text = title;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static Text GetTitleText(ManualBehaviour win)
|
|
||||||
{
|
|
||||||
return win.gameObject.transform.Find("panel-bg/title-text")?.gameObject.GetComponent<Text>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static RectTransform GetRectTransform(ManualBehaviour win)
|
|
||||||
{
|
|
||||||
return win.GetComponent<RectTransform>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -83,17 +264,6 @@ public static class MyWindowManager
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static void OpenWindow(ManualBehaviour win)
|
|
||||||
{
|
|
||||||
win._Open();
|
|
||||||
win.transform.SetAsLastSibling();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CloseWindow(ManualBehaviour win)
|
|
||||||
{
|
|
||||||
win._Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Patch
|
public static class Patch
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -122,7 +292,7 @@ public static class MyWindowManager
|
|||||||
{
|
{
|
||||||
win._Init(win.data);
|
win._Init(win.data);
|
||||||
}
|
}
|
||||||
_inited = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnFree")]
|
[HarmonyPostfix, HarmonyPatch(typeof(UIGame), "_OnFree")]
|
||||||
@@ -152,7 +322,10 @@ public static class MyWindowManager
|
|||||||
{
|
{
|
||||||
foreach (var win in Windows)
|
foreach (var win in Windows)
|
||||||
{
|
{
|
||||||
win._Close();
|
if (win is MyWindow theWin && theWin.IsWindowFunctional())
|
||||||
|
{
|
||||||
|
theWin.TryClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
66
CheatEnabler/UI/Util.cs
Normal file
66
CheatEnabler/UI/Util.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace CheatEnabler.UI;
|
||||||
|
|
||||||
|
public static class Util
|
||||||
|
{
|
||||||
|
|
||||||
|
public static RectTransform NormalizeRectWithTopLeft(Component cmp, float left, float top, Transform parent = null)
|
||||||
|
{
|
||||||
|
if (cmp.transform is not RectTransform rect) return null;
|
||||||
|
if (parent != null)
|
||||||
|
{
|
||||||
|
rect.SetParent(parent, false);
|
||||||
|
}
|
||||||
|
rect.anchorMax = new Vector2(0f, 1f);
|
||||||
|
rect.anchorMin = new Vector2(0f, 1f);
|
||||||
|
rect.pivot = new Vector2(0f, 1f);
|
||||||
|
rect.anchoredPosition3D = new Vector3(left, -top, 0f);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RectTransform NormalizeRectWithBottomLeft(Component cmp, float left, float bottom, Transform parent = null)
|
||||||
|
{
|
||||||
|
if (cmp.transform is not RectTransform rect) return null;
|
||||||
|
if (parent != null)
|
||||||
|
{
|
||||||
|
rect.SetParent(parent, false);
|
||||||
|
}
|
||||||
|
rect.anchorMax = new Vector2(0f, 0f);
|
||||||
|
rect.anchorMin = new Vector2(0f, 0f);
|
||||||
|
rect.pivot = new Vector2(0f, 0f);
|
||||||
|
rect.anchoredPosition3D = new Vector3(left, bottom, 0f);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RectTransform NormalizeRectWithMargin(Component cmp, float top, float left, float bottom, float right, Transform parent = null)
|
||||||
|
{
|
||||||
|
if (cmp.transform is not RectTransform rect) return null;
|
||||||
|
if (parent != null)
|
||||||
|
{
|
||||||
|
rect.SetParent(parent, false);
|
||||||
|
}
|
||||||
|
rect.anchoredPosition3D = Vector3.zero;
|
||||||
|
rect.localScale = Vector3.one;
|
||||||
|
rect.anchorMax = Vector2.one;
|
||||||
|
rect.anchorMin = Vector2.zero;
|
||||||
|
rect.pivot = new Vector2(0.5f, 0.5f);
|
||||||
|
rect.offsetMax = new Vector2(-right, -top);
|
||||||
|
rect.offsetMin = new Vector2(left, bottom);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RectTransform NormalizeRectCenter(GameObject go, float width = 0, float height = 0)
|
||||||
|
{
|
||||||
|
if (go.transform is not RectTransform rect) return null;
|
||||||
|
rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||||
|
rect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||||
|
rect.pivot = new Vector2(0.5f, 0.5f);
|
||||||
|
if (width > 0 && height > 0)
|
||||||
|
{
|
||||||
|
rect.sizeDelta = new Vector2(width, height);
|
||||||
|
}
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
62
CheatEnabler/UIConfigWindow.cs
Normal file
62
CheatEnabler/UIConfigWindow.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace CheatEnabler;
|
||||||
|
|
||||||
|
public class UIConfigWindow : UI.MyWindowWithTabs
|
||||||
|
{
|
||||||
|
private RectTransform _windowTrans;
|
||||||
|
|
||||||
|
public static UIConfigWindow CreateInstance()
|
||||||
|
{
|
||||||
|
return UI.MyWindowManager.CreateWindow<UIConfigWindow>("CEConfigWindow", "CheatEnabler Config");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnCreate()
|
||||||
|
{
|
||||||
|
_windowTrans = GetComponent<RectTransform>();
|
||||||
|
_windowTrans.sizeDelta = new Vector2(640f, 428f);
|
||||||
|
|
||||||
|
CreateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateUI()
|
||||||
|
{
|
||||||
|
//General tab
|
||||||
|
var tab1 = AddTab(36f, 0, _windowTrans, "General");
|
||||||
|
var x = 0f;
|
||||||
|
var y = 0f;
|
||||||
|
UI.MyCheckBox.CreateCheckBox(x, y, tab1, DevShortcuts.Enabled, "Enable Dev Shortcuts");
|
||||||
|
y += 26f;
|
||||||
|
UI.MyCheckBox.CreateCheckBox(x, y, tab1, AbnormalDisabler.Enabled, "Disable Abnormal Checks");
|
||||||
|
SetCurrentTab(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnDestroy()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool _OnInit()
|
||||||
|
{
|
||||||
|
_windowTrans.anchoredPosition = new Vector2(0, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnFree()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnOpen()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnClose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _OnUpdate()
|
||||||
|
{
|
||||||
|
if (!VFInput.escape || VFInput.inputing) return;
|
||||||
|
VFInput.UseEscape();
|
||||||
|
_Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user