From d2176afff96a506d3f8aa5ed95384fa1f89dfa53 Mon Sep 17 00:00:00 2001 From: davidon-top Date: Sat, 20 Jan 2024 13:52:41 +0100 Subject: [PATCH] Initial Commit --- .gitignore | 3 + CruelMan.csproj | 13 ++ CruelMan/CruelMan.cs | 20 +++ CruelMan/CruelManLoader.cs | 39 ++++++ CruelMan/Modules/Module.cs | 92 ++++++++++++++ CruelMan/Modules/ModuleManager.cs | 46 +++++++ CruelMan/Modules/Modules/AddStamina.cs | 48 ++++++++ CruelMan/Modules/Modules/GuardianPowers.cs | 129 ++++++++++++++++++++ CruelMan/Modules/Modules/InfCarry.cs | 15 +++ CruelMan/Modules/Modules/InstantDmg.cs | 57 +++++++++ CruelMan/Modules/Modules/JumpHeight.cs | 38 ++++++ CruelMan/Modules/Modules/Menu.cs | 25 ++++ CruelMan/Modules/Modules/NoDeath.cs | 13 ++ CruelMan/Modules/Modules/NotInAttack.cs | 13 ++ CruelMan/Modules/Modules/Speed.cs | 34 ++++++ CruelMan/Modules/Settings/ActionSetting.cs | 9 ++ CruelMan/Modules/Settings/BooleanSetting.cs | 9 ++ CruelMan/Modules/Settings/NumberSetting.cs | 7 ++ CruelMan/Modules/Settings/Setting.cs | 8 ++ CruelMan/Modules/Settings/TextSetting.cs | 5 + CruelMan/UI/MainUI.cs | 109 +++++++++++++++++ CruelMan/Utils/Log.cs | 21 ++++ README.md | 25 ++++ 23 files changed, 778 insertions(+) create mode 100644 .gitignore create mode 100644 CruelMan.csproj create mode 100644 CruelMan/CruelMan.cs create mode 100644 CruelMan/CruelManLoader.cs create mode 100644 CruelMan/Modules/Module.cs create mode 100644 CruelMan/Modules/ModuleManager.cs create mode 100644 CruelMan/Modules/Modules/AddStamina.cs create mode 100644 CruelMan/Modules/Modules/GuardianPowers.cs create mode 100644 CruelMan/Modules/Modules/InfCarry.cs create mode 100644 CruelMan/Modules/Modules/InstantDmg.cs create mode 100644 CruelMan/Modules/Modules/JumpHeight.cs create mode 100644 CruelMan/Modules/Modules/Menu.cs create mode 100644 CruelMan/Modules/Modules/NoDeath.cs create mode 100644 CruelMan/Modules/Modules/NotInAttack.cs create mode 100644 CruelMan/Modules/Modules/Speed.cs create mode 100644 CruelMan/Modules/Settings/ActionSetting.cs create mode 100644 CruelMan/Modules/Settings/BooleanSetting.cs create mode 100644 CruelMan/Modules/Settings/NumberSetting.cs create mode 100644 CruelMan/Modules/Settings/Setting.cs create mode 100644 CruelMan/Modules/Settings/TextSetting.cs create mode 100644 CruelMan/UI/MainUI.cs create mode 100644 CruelMan/Utils/Log.cs create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d83a8c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin +obj +libs diff --git a/CruelMan.csproj b/CruelMan.csproj new file mode 100644 index 0000000..3082a54 --- /dev/null +++ b/CruelMan.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.1 + + + + + + + + + diff --git a/CruelMan/CruelMan.cs b/CruelMan/CruelMan.cs new file mode 100644 index 0000000..d3cca69 --- /dev/null +++ b/CruelMan/CruelMan.cs @@ -0,0 +1,20 @@ +using CruelMan.Modules; +using CruelMan.UI; +using UnityEngine; + +namespace CruelMan { + public class CM : MonoBehaviour { + public static GameObject go; + public static CMLoader loader; + + public static void Init(CMLoader loader) { + CM.loader = loader; + + CM.go = new GameObject("CruelMan"); + Object.DontDestroyOnLoad(CM.go); + + go.AddComponent(); + go.AddComponent(); + } + } +} diff --git a/CruelMan/CruelManLoader.cs b/CruelMan/CruelManLoader.cs new file mode 100644 index 0000000..5807756 --- /dev/null +++ b/CruelMan/CruelManLoader.cs @@ -0,0 +1,39 @@ +using BepInEx; +using CruelMan.Modules; +using CruelMan.Utils; +using HarmonyLib; + +namespace CruelMan { + + [BepInPlugin("top.davidon.valheim.cruelman", "CruelMan", "1.0.0")] + public class CMLoader : BaseUnityPlugin { + public readonly Harmony harmony = new Harmony("top.davidon.valheim.cruelman"); + + public void Awake() { + Log.Info("Awake CruelMan"); + harmony.PatchAll(); + UnityEngine.Object.DontDestroyOnLoad(this); + + CM.Init(this); + } + + [HarmonyPatch(typeof(Player), "OnDeath")] + class DeathPatch { + static bool Prefix() { + return !ModuleManager.instance.GetModule().Enabled; + } + } + + [HarmonyPatch(typeof(Player), nameof(Player.InAttack))] + class AttackPathh { + static bool Prefix() { + return !ModuleManager.instance.GetModule().Enabled; + } + static void Postfix(ref bool __result) { + if (ModuleManager.instance.GetModule().Enabled) { + __result = false; + } + } + } + } +} diff --git a/CruelMan/Modules/Module.cs b/CruelMan/Modules/Module.cs new file mode 100644 index 0000000..6c097a2 --- /dev/null +++ b/CruelMan/Modules/Module.cs @@ -0,0 +1,92 @@ +using System.Collections.Generic; +using CruelMan.Modules.Settings; +using CruelMan.Utils; +using UnityEngine; + +namespace CruelMan.Modules { + public enum ModuleType { + Movement = 0, + Stats = 1, + Combat = 2, + Misc = 3 + } + + public abstract class Module { + public abstract string Name { get; } + public abstract string Command { get; } + public abstract string Description { get; } + public abstract ModuleType Type { get; } + public bool Enabled { get; set; } = false; + public KeyCode bind { get; set; } = KeyCode.None; + public List Settings = new List(); + + public void Register() { + ModuleManager.instance.modules.Add(this); + new Terminal.ConsoleCommand($"cm{Command}", Description, delegate (Terminal.ConsoleEventArgs args) { + Toggle(); + args.Context.AddString($"Toggled {Name}"); + }); + Init(); + Log.Info($"Registered module {Name}"); + } + + public void Toggle() { + if (Enabled) { + Disable(); + } else { + Enable(); + } + } + + public void Enable() { + Enabled = true; + Log.Info($"{Name} enabled"); + OnEnable(); + } + + public void Disable() { + Enabled = false; + Log.Info($"{Name} disabled"); + OnDisable(); + } + + public void Update() { + if (Input.GetKeyDown(bind)) { + Toggle(); + } + foreach (Setting s in Settings) { + if (s is ActionSetting) { + ActionSetting a = (ActionSetting)s; + if (Input.GetKeyDown(a.bind)) { + a.Run(this); + } + } + } + if (Enabled) { + OnUpdate(); + } + } + + protected abstract void Init(); + + protected abstract void OnEnable(); + protected abstract void OnDisable(); + + protected abstract void OnUpdate(); + public virtual void Refresh() {} + + protected void AddSetting() where T : Setting, new() { + T setting = new T(); + Settings.Add(setting); + } + + public T GetSetting() where T : Setting, new() { + foreach (Setting s in Settings) { + if (s is T) { + return (T)s; + } + } + throw new System.Exception("Setting not found"); + } + } +} diff --git a/CruelMan/Modules/ModuleManager.cs b/CruelMan/Modules/ModuleManager.cs new file mode 100644 index 0000000..aa90678 --- /dev/null +++ b/CruelMan/Modules/ModuleManager.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace CruelMan.Modules { + public class ModuleManager : MonoBehaviour { + public static ModuleManager instance; + public List modules = new List(); + + public void Awake() { + instance = this; + AddModules(); + } + + public void Update() { + foreach (Module module in modules) { + module.Update(); + } + } + + private void AddModules() { + AddModule(); + AddModule(); + AddModule(); + AddModule(); + AddModule(); + AddModule(); + AddModule(); + AddModule(); + AddModule(); + } + + private void AddModule() where T : Module, new() { + T module = new T(); + module.Register(); + } + + public T GetModule() where T : Module, new() { + foreach (Module module in modules) { + if (module is T) { + return (T)module; + } + } + throw new System.Exception("Module not found"); + } + } +} diff --git a/CruelMan/Modules/Modules/AddStamina.cs b/CruelMan/Modules/Modules/AddStamina.cs new file mode 100644 index 0000000..b36b792 --- /dev/null +++ b/CruelMan/Modules/Modules/AddStamina.cs @@ -0,0 +1,48 @@ +using System.Reflection; +using CruelMan.Modules.Settings; + +namespace CruelMan.Modules { + public class AddStamina : Module { + public override string Name => "Add Stamina"; + public override string Command => "addstamina"; + public override string Description => "Adds stamina to the player"; + public override ModuleType Type => ModuleType.Stats; + + protected override void Init() { + AddSetting(); + AddSetting(); + AddSetting(); + } + protected override void OnDisable() {} + protected override void OnEnable() {} + protected override void OnUpdate() { + if (GetSetting().Value) { + FieldInfo fi = typeof(Player).GetField("m_stamina", BindingFlags.NonPublic | BindingFlags.Instance); + fi.SetValue(Player.m_localPlayer, GetSetting().Value); + } + } + } + + public class NoChange : BooleanSetting { + public override string Name => "No Change"; + public override string Description => "Prevents stamina from changing"; + } + + public class Stamina : NumberSetting { + public override string Name => "Stamina"; + public override string Description => "The amount of stamina to add"; + public override float Min {get;set;} = 0; + public override float Max {get;set;} = 300; + public override float Value {get;set;} = 0; + } + + public class SetStamina : ActionSetting { + public override string Name => "Set Stamina"; + public override string Description => "Sets the stamina to the value"; + + public override void Run(Module module) { + FieldInfo fi = typeof(Player).GetField("m_stamina", BindingFlags.NonPublic | BindingFlags.Instance); + fi.SetValue(Player.m_localPlayer, module.GetSetting().Value); + } + } +} diff --git a/CruelMan/Modules/Modules/GuardianPowers.cs b/CruelMan/Modules/Modules/GuardianPowers.cs new file mode 100644 index 0000000..ddf49af --- /dev/null +++ b/CruelMan/Modules/Modules/GuardianPowers.cs @@ -0,0 +1,129 @@ +using System.Reflection; +using CruelMan.Modules.Settings; + +namespace CruelMan.Modules { + public class GuardianPowers : Module { + public override string Name => "Guardian Powers"; + public override string Command => "guardian"; + public override string Description => "Enable guardian power"; + public override ModuleType Type => ModuleType.Misc; + + protected override void Init() { + AddSetting(); + AddSetting(); + AddSetting(); + AddSetting(); + AddSetting(); + AddSetting(); + AddSetting(); + AddSetting(); + AddSetting(); + AddSetting(); + } + protected override void OnDisable() {} + protected override void OnEnable() {} + protected override void OnUpdate() { + if (GetSetting().Value) { + Player.m_localPlayer.m_guardianPowerCooldown = 0f; + } + } + public void SetGP(string name) { + FieldInfo fi = typeof(Player).GetField("m_guardianPower", BindingFlags.NonPublic | BindingFlags.Instance); + fi.SetValue(Player.m_localPlayer, name); + + int hash = ((!string.IsNullOrEmpty(name)) ? StringExtensionMethods.GetStableHashCode(name) : 0); + FieldInfo fi2 = typeof(Player).GetField("m_guardianPowerHash", BindingFlags.NonPublic | BindingFlags.Instance); + fi2.SetValue(Player.m_localPlayer, hash); + + FieldInfo fi3 = typeof(Player).GetField("m_guardianSE", BindingFlags.NonPublic | BindingFlags.Instance); + fi3.SetValue(Player.m_localPlayer, ObjectDB.instance.GetStatusEffect(hash)); + } + } + + public class NoCooldown : BooleanSetting { + public override string Name => "No Cooldown"; + public override string Description => "Enable no cooldown"; + } + + public class Activate : ActionSetting { + public override string Name => "Activate"; + public override string Description => "Activate guardian power"; + + public override void Run(Module module) { + Player.m_localPlayer.ActivateGuardianPower(); + } + } + + public class SetEikthyr : ActionSetting { + public override string Name => "Set Eikthyr"; + public override string Description => "Set guardian power to Eikthyr"; + + public override void Run(Module module) { + ((GuardianPowers)module).SetGP("GP_Eikthyr"); + } + } + + public class SetTheElder : ActionSetting { + public override string Name => "Set The Elder"; + public override string Description => "Set guardian power to The Elder"; + + public override void Run(Module module) { + ((GuardianPowers)module).SetGP("GP_TheElder"); + } + } + + public class SetBonemass : ActionSetting { + public override string Name => "Set Bonemass"; + public override string Description => "Set guardian power to Bonemass"; + + public override void Run(Module module) { + ((GuardianPowers)module).SetGP("GP_Bonemass"); + } + } + + public class SetModer : ActionSetting { + public override string Name => "Set Moder"; + public override string Description => "Set guardian power to Moder"; + + public override void Run(Module module) { + ((GuardianPowers)module).SetGP("GP_Moder"); + } + } + + public class SetYagluth : ActionSetting { + public override string Name => "Set Yagluth"; + public override string Description => "Set guardian power to Yagluth"; + + public override void Run(Module module) { + ((GuardianPowers)module).SetGP("GP_Yagluth"); + } + } + + public class SetQueen : ActionSetting { + public override string Name => "Set Queen"; + public override string Description => "Set guardian power to Queen"; + + public override void Run(Module module) { + ((GuardianPowers)module).SetGP("GP_Queen"); + } + } + + public class SetAshlands : ActionSetting { + public override string Name => "Set Ashlands"; + public override string Description => "Set guardian power to Ashlands"; + + public override void Run(Module module) { + ((GuardianPowers)module).SetGP("GP_Ashlands"); + } + } + + public class SetDeepNorth : ActionSetting { + public override string Name => "Set Deep North"; + public override string Description => "Set guardian power to Deep North"; + + public override void Run(Module module) { + ((GuardianPowers)module).SetGP("GP_DeepNorth"); + } + } + +} diff --git a/CruelMan/Modules/Modules/InfCarry.cs b/CruelMan/Modules/Modules/InfCarry.cs new file mode 100644 index 0000000..52c4f9a --- /dev/null +++ b/CruelMan/Modules/Modules/InfCarry.cs @@ -0,0 +1,15 @@ +namespace CruelMan.Modules { + public class InfCarry : Module { + public override string Name => "InfCarry"; + public override string Command => "infcarry"; + public override string Description => "Allows you to carry infinite weight"; + public override ModuleType Type => ModuleType.Movement; + + protected override void Init() {} + protected override void OnDisable() {} + protected override void OnEnable() {} + protected override void OnUpdate() { + Player.m_localPlayer.m_maxCarryWeight = 1000000; + } + } +} diff --git a/CruelMan/Modules/Modules/InstantDmg.cs b/CruelMan/Modules/Modules/InstantDmg.cs new file mode 100644 index 0000000..052969c --- /dev/null +++ b/CruelMan/Modules/Modules/InstantDmg.cs @@ -0,0 +1,57 @@ +using System.Reflection; +using CruelMan.Modules.Settings; +using UnityEngine; + +namespace CruelMan.Modules { + public class InstantDmg : Module { + public override string Name { get; } = "InstantDmg"; + public override string Command { get; } = "instantdmg"; + public override string Description { get; } = "Instantly kills the target"; + public override ModuleType Type { get; } = ModuleType.Combat; + + protected override void Init() { + AddSetting(); + AddSetting(); + GetSetting().bind = KeyCode.Delete; + } + protected override void OnDisable() {} + protected override void OnEnable() {} + protected override void OnUpdate() {} + } + + public class InstantDmgDo : ActionSetting { + public override string Name { get; } = "InstantDmg"; + public override string Description { get; } = "Instantly kills the target"; + + public override void Run(Module module) { + HitData hd = new HitData(); + hd.m_damage.m_damage = module.GetSetting().Value; + hd.m_dodgeable = false; + hd.m_blockable = false; + hd.m_ignorePVP = true; + hd.m_pushForce = 0; + hd.m_point = Player.m_localPlayer.transform.position; + hd.m_dir = Player.m_localPlayer.transform.forward; + hd.m_hitType = HitData.HitType.PlayerHit; + hd.SetAttacker(Player.m_localPlayer); + + FieldInfo fi = typeof(Player).GetField("m_hoveringCreature", BindingFlags.NonPublic | BindingFlags.Instance); + Character target = (Character)fi.GetValue(Player.m_localPlayer); + if (target == Player.m_localPlayer) { + target = null; + } + if (target == null) { + return; + } + target.Damage(hd); + } + } + + public class Damage : NumberSetting { + public override string Name { get; } = "Damage"; + public override string Description { get; } = "The amount of damage to deal"; + public override float Min { get; set; } = 0; + public override float Max { get; set; } = 1000; + public override float Value { get; set; } = 0; + } +} diff --git a/CruelMan/Modules/Modules/JumpHeight.cs b/CruelMan/Modules/Modules/JumpHeight.cs new file mode 100644 index 0000000..7b838a1 --- /dev/null +++ b/CruelMan/Modules/Modules/JumpHeight.cs @@ -0,0 +1,38 @@ +using CruelMan.Modules.Settings; +using UnityEngine; + +namespace CruelMan.Modules { + public class JumpHeight : Module { + public override string Name { get; } = "JumpHeight"; + public override string Command { get; } = "jumpheight"; + public override string Description { get; } = "Changes your jump height"; + public override ModuleType Type { get; } = ModuleType.Movement; + public float oldJumpHeight = 0f; + + protected override void Init() { + AddSetting(); + } + protected override void OnEnable() { + oldJumpHeight = Player.m_localPlayer.m_jumpForce; + } + protected override void OnDisable() { + Player.m_localPlayer.m_jumpForce = oldJumpHeight; + } + protected override void OnUpdate() { + if (Input.GetKey(KeyCode.LeftShift)) { + Player.m_localPlayer.m_jumpForce = GetSetting().Value; + } else { + Player.m_localPlayer.m_jumpForce = oldJumpHeight; + } + } + } + + public class JumpHeightVal : NumberSetting { + public override string Name => "Value"; + public override string Description => "Jump Height value"; + + public override float Value { get; set; } = 10f; + public override float Min { get; set; } = 0f; + public override float Max { get; set; } = 100f; + } +} diff --git a/CruelMan/Modules/Modules/Menu.cs b/CruelMan/Modules/Modules/Menu.cs new file mode 100644 index 0000000..021afb3 --- /dev/null +++ b/CruelMan/Modules/Modules/Menu.cs @@ -0,0 +1,25 @@ +using CruelMan.UI; +using UnityEngine; + +namespace CruelMan.Modules { + public class Menu : Module { + public override string Name { get; } = "Menu"; + public override string Command { get; } = "menu"; + public override string Description { get; } = "Opens the main mod menu"; + public override ModuleType Type { get; } = ModuleType.Misc; + + protected override void Init() { + bind = KeyCode.End; + } + + protected override void OnEnable() { + CM.go.GetComponent().menuOpen = true; + } + + protected override void OnDisable() { + CM.go.GetComponent().menuOpen = false; + } + + protected override void OnUpdate() {} + } +} diff --git a/CruelMan/Modules/Modules/NoDeath.cs b/CruelMan/Modules/Modules/NoDeath.cs new file mode 100644 index 0000000..9bb1196 --- /dev/null +++ b/CruelMan/Modules/Modules/NoDeath.cs @@ -0,0 +1,13 @@ +namespace CruelMan.Modules { + public class NoDeath : Module { + public override string Name { get; } = "NoDeath"; + public override string Command { get; } = "nodeath"; + public override string Description { get; } = "Prevents you from dying"; + public override ModuleType Type { get; } = ModuleType.Combat; + + protected override void Init() {} + protected override void OnDisable() {} + protected override void OnEnable() {} + protected override void OnUpdate() {} + } +} diff --git a/CruelMan/Modules/Modules/NotInAttack.cs b/CruelMan/Modules/Modules/NotInAttack.cs new file mode 100644 index 0000000..b173d42 --- /dev/null +++ b/CruelMan/Modules/Modules/NotInAttack.cs @@ -0,0 +1,13 @@ +namespace CruelMan.Modules { + public class NotInAttack : Module { + public override string Name { get; } = "NoAttackCooldown"; + public override string Command { get; } = "nodattack"; + public override string Description { get; } = "Always sets that your not in an attack"; + public override ModuleType Type { get; } = ModuleType.Combat; + + protected override void Init() {} + protected override void OnDisable() {} + protected override void OnEnable() {} + protected override void OnUpdate() {} + } +} diff --git a/CruelMan/Modules/Modules/Speed.cs b/CruelMan/Modules/Modules/Speed.cs new file mode 100644 index 0000000..97c6488 --- /dev/null +++ b/CruelMan/Modules/Modules/Speed.cs @@ -0,0 +1,34 @@ +using CruelMan.Modules.Settings; + +namespace CruelMan.Modules { + public class Speed : Module { + public override string Name { get; } = "Speed"; + public override string Command { get; } = "speed"; + public override string Description { get; } = "Fast as fuck boiii"; + public override ModuleType Type { get; } = ModuleType.Movement; + public float oldSpeed = 0f; + + protected override void Init() { + AddSetting(); + } + protected override void OnEnable() { + oldSpeed = Player.m_localPlayer.m_runSpeed; + } + protected override void OnDisable() { + Player.m_localPlayer.m_runSpeed = oldSpeed; + } + protected override void OnUpdate() { + Player.m_localPlayer.m_runSpeed = GetSetting().Value; + } + } + + public class SpeedVal : NumberSetting + { + public override string Name => "Value"; + public override string Description => "Run Speed value"; + + public override float Value { get; set; } = 20f; + public override float Min { get; set; } = 0f; + public override float Max { get; set; } = 500f; + } +} diff --git a/CruelMan/Modules/Settings/ActionSetting.cs b/CruelMan/Modules/Settings/ActionSetting.cs new file mode 100644 index 0000000..7c7d352 --- /dev/null +++ b/CruelMan/Modules/Settings/ActionSetting.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace CruelMan.Modules.Settings { + public abstract class ActionSetting : Setting { + public KeyCode bind { get; set; } = KeyCode.None; + + public abstract void Run(Module module); + } +} diff --git a/CruelMan/Modules/Settings/BooleanSetting.cs b/CruelMan/Modules/Settings/BooleanSetting.cs new file mode 100644 index 0000000..5e79389 --- /dev/null +++ b/CruelMan/Modules/Settings/BooleanSetting.cs @@ -0,0 +1,9 @@ +namespace CruelMan.Modules.Settings { + public abstract class BooleanSetting : Setting { + public bool Value = false; + + public void Toggle() { + Value = !Value; + } + } +} diff --git a/CruelMan/Modules/Settings/NumberSetting.cs b/CruelMan/Modules/Settings/NumberSetting.cs new file mode 100644 index 0000000..9664378 --- /dev/null +++ b/CruelMan/Modules/Settings/NumberSetting.cs @@ -0,0 +1,7 @@ +namespace CruelMan.Modules.Settings { + public abstract class NumberSetting : Setting { + public abstract float Value { get; set; } + public abstract float Min {get; set; } + public abstract float Max {get;set;} + } +} diff --git a/CruelMan/Modules/Settings/Setting.cs b/CruelMan/Modules/Settings/Setting.cs new file mode 100644 index 0000000..eb078a9 --- /dev/null +++ b/CruelMan/Modules/Settings/Setting.cs @@ -0,0 +1,8 @@ +namespace CruelMan.Modules.Settings { + public abstract class Setting { + public abstract string Name { get; } + public abstract string Description { get; } + + public Setting() {} + } +} diff --git a/CruelMan/Modules/Settings/TextSetting.cs b/CruelMan/Modules/Settings/TextSetting.cs new file mode 100644 index 0000000..a54e156 --- /dev/null +++ b/CruelMan/Modules/Settings/TextSetting.cs @@ -0,0 +1,5 @@ +namespace CruelMan.Modules.Settings { + public abstract class TextSetting : Setting { + public virtual string value { get; set; } = ""; + } +} diff --git a/CruelMan/UI/MainUI.cs b/CruelMan/UI/MainUI.cs new file mode 100644 index 0000000..219f88a --- /dev/null +++ b/CruelMan/UI/MainUI.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using CruelMan.Modules; +using CruelMan.Modules.Settings; +using UnityEngine; + +namespace CruelMan.UI { + public class MainUI : MonoBehaviour { + public bool menuOpen = false; + + public List openSettings = null; + public Module openSettingsModule = null; + public Rect settingsWindow = new Rect(140, 10, 220, 600); + + public Rect ModuleMovementWindow = new Rect(10, 10, 200, 500); + public Rect ModuleStatsWindow = new Rect(220, 10, 200, 500); + public Rect ModuleCombatWindow = new Rect(440, 10, 200, 500); + public Rect ModuleMiscWindow = new Rect(660, 10, 200, 500); + + public void OnGUI() { + if (!menuOpen) { + return; + } + + // windowRect = GUI.Window(0, windowRect, MainWindow, "CruelMan"); + ModuleMovementWindow = GUI.Window(0, ModuleMovementWindow, MainWindow, "Movement"); + ModuleStatsWindow = GUI.Window(1, ModuleStatsWindow, MainWindow, "Stats"); + ModuleCombatWindow = GUI.Window(2, ModuleCombatWindow, MainWindow, "Combat"); + ModuleMiscWindow = GUI.Window(3, ModuleMiscWindow, MainWindow, "Misc"); + + if (openSettings != null) { + settingsWindow = GUI.Window(99, settingsWindow, SettingsWindow, openSettingsModule.Name); + } + } + + public void MainWindow(int windowID) { + ModuleType mt = (ModuleType)windowID; + + int lastY = 20; + + foreach (Module module in ModuleManager.instance.modules) { + if (module.Type == mt) { + if (module.Enabled) { + GUI.color = Color.green; + } else { + GUI.color = Color.red; + } + if (GUI.Button(new Rect(10, lastY, 150, 20), module.Name)) { + module.Toggle(); + } + if (GUI.Button(new Rect(160, lastY, 20, 20), "S")) { + if (openSettingsModule == module) { + openSettingsModule.Refresh(); + openSettingsModule = null; + openSettings = null; + } else { + openSettingsModule = module; + openSettings = module.Settings; + } + } + GUI.color = Color.white; + lastY += 20; + } + } + + GUI.DragWindow(new Rect(0, 0, 10000, 10000)); + } + + public void SettingsWindow(int windowID) { + if (GUI.Button(new Rect(10, 20, 95, 20), "Apply")) { + openSettingsModule.Refresh(); + openSettingsModule = null; + openSettings = null; + } + + openSettingsModule.bind = (KeyCode)Enum.Parse(typeof(KeyCode), GUI.TextField(new Rect(105, 20, 95, 20), openSettingsModule.bind.ToString())); + + int lastY = 70; + + foreach (Setting setting in openSettings) { + if (setting is BooleanSetting) { + BooleanSetting bs = (BooleanSetting)setting; + bs.Value = GUI.Toggle(new Rect(10, lastY, 100, 20), bs.Value, bs.Name); + lastY += 20; + } else if (setting is NumberSetting) { + NumberSetting ns = (NumberSetting)setting; + ns.Value = GUI.HorizontalSlider(new Rect(10, lastY, 100, 20), ns.Value, ns.Min, ns.Max); + lastY += 20; + } else if (setting is TextSetting) { + TextSetting ts = (TextSetting)setting; + ts.value = GUI.TextField(new Rect(10, lastY, 100, 20), ts.value); + lastY += 20; + } else if (setting is ActionSetting) { + ActionSetting as_ = (ActionSetting)setting; + if (GUI.Button(new Rect(10, lastY, 100, 20), as_.Name)) { + as_.Run(openSettingsModule); + } + lastY += 20; + } + } + + GUI.DragWindow(new Rect(0, 0, 10000, 10000)); + } + + public void ToggleMenu() { + menuOpen = !menuOpen; + } + } +} diff --git a/CruelMan/Utils/Log.cs b/CruelMan/Utils/Log.cs new file mode 100644 index 0000000..5b85e5f --- /dev/null +++ b/CruelMan/Utils/Log.cs @@ -0,0 +1,21 @@ +namespace CruelMan.Utils { + public static class Log { + public static void Info(string message) { +#if DEBUG + UnityEngine.Debug.Log($"[CruelMan] {message}"); +#endif + } + + public static void Warn(string message) { +#if DEBUG + UnityEngine.Debug.LogWarning($"[CruelMan] {message}"); +#endif + } + + public static void Error(string message) { +#if DEBUG + UnityEngine.Debug.LogError($"[CruelMan] {message}"); +#endif + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..f86929c --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +## required dlls in the libs folder +- 0Harmony +- assembly_utils +- assembly_valheim +- BepInEx +- UnityEngine +### Unity dlls +- InputSystem +- InputSystem.ForUI +- CoreModule +- IMGUIModule +- InputLegacyModule +- InputModule +- JSONSerializeModule +- ParticleSystemModule +- Physics2DModule +- PhysicsModule +- TextRenderingModule +- UI +- UIElementsModule +- UIElementsNativeModule +- UIModule +- UnityCurlModule +- XR.LegacyInputHelpers +- XRModule