diff --git a/SubnauticaModSystem/PrawnsuitLightswitch/Config.cs b/SubnauticaModSystem/PrawnsuitLightswitch/Config.cs index 9508885..0b9e882 100644 --- a/SubnauticaModSystem/PrawnsuitLightswitch/Config.cs +++ b/SubnauticaModSystem/PrawnsuitLightswitch/Config.cs @@ -1,10 +1,14 @@ using System; +using SMLHelper.V2.Json; +using SMLHelper.V2.Options; +using SMLHelper.V2.Options.Attributes; namespace PrawnsuitLightswitch { - [Serializable] - class Config - { - public bool PrawnsuitLightsUseEnergy = true; - } + [Menu("Prawnsuit Lightswitch")] + public class Config : ConfigFile + { + [Toggle("Lights Use Energy")] + public bool PrawnsuitLightsUseEnergy = true; + } } diff --git a/SubnauticaModSystem/PrawnsuitLightswitch/Mod.cs b/SubnauticaModSystem/PrawnsuitLightswitch/Mod.cs index f4d62f3..6f36b4e 100644 --- a/SubnauticaModSystem/PrawnsuitLightswitch/Mod.cs +++ b/SubnauticaModSystem/PrawnsuitLightswitch/Mod.cs @@ -1,56 +1,25 @@ -using Common.Mod; -using Harmony; +using HarmonyLib; +using BepInEx; using System; using System.Reflection; +using SMLHelper.V2.Handlers; namespace PrawnsuitLightswitch { - static class Mod + [BepInPlugin(GUID, PluginName, VersionString)] + public class Mod : BaseUnityPlugin { public static Config config; - private static string modDirectory; + private const string PluginName = "PrawnsuitLightswitch"; + private const string VersionString = "1.0.3"; + private const string GUID = "com.PrawnsuitLightswitch.mod"; - public static void Patch(string modDirectory = null) + private void Awake() { - Mod.modDirectory = modDirectory ?? "Subnautica_Data/Managed"; - LoadConfig(); - - HarmonyInstance harmony = HarmonyInstance.Create("com.PrawnsuitLightswitch.mod"); + Harmony harmony = new Harmony(GUID); harmony.PatchAll(Assembly.GetExecutingAssembly()); - - Logger.Log("Patched"); - } - - public static string GetModPath() - { - return Environment.CurrentDirectory + "/" + modDirectory; - } - - public static string GetAssetPath(string filename) - { - return GetModPath() + "/Assets/" + filename; - } - - private static string GetModInfoPath() - { - return GetModPath() + "/mod.json"; - } - - private static void LoadConfig() - { - config = ModUtils.LoadConfig(GetModInfoPath()); - ValidateConfig(); - } - - private static void ValidateConfig() - { - Config defaultConfig = new Config(); - if (config == null) - { - config = defaultConfig; - return; - } + config = OptionsPanelHandler.Main.RegisterModOptions(); } } } \ No newline at end of file diff --git a/SubnauticaModSystem/PrawnsuitLightswitch/ModLoaderIntegration.cs b/SubnauticaModSystem/PrawnsuitLightswitch/ModLoaderIntegration.cs deleted file mode 100644 index d0b2ff3..0000000 --- a/SubnauticaModSystem/PrawnsuitLightswitch/ModLoaderIntegration.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace PrawnsuitLightswitch -{ - // QMods by qwiso https://github.com/Qwiso/QModManager - public static class QPatch - { - public static void Patch() - { - Mod.Patch("QMods/PrawnsuitLightswitch"); - } - } -} \ No newline at end of file diff --git a/SubnauticaModSystem/PrawnsuitLightswitch/Patches/Exosuit_Patches.cs b/SubnauticaModSystem/PrawnsuitLightswitch/Patches/Exosuit_Patches.cs index 3373d54..2d08b32 100644 --- a/SubnauticaModSystem/PrawnsuitLightswitch/Patches/Exosuit_Patches.cs +++ b/SubnauticaModSystem/PrawnsuitLightswitch/Patches/Exosuit_Patches.cs @@ -1,5 +1,5 @@ using Common.Mod; -using Harmony; +using HarmonyLib; using System; using System.Collections; using System.Collections.Generic; @@ -10,16 +10,23 @@ namespace PrawnsuitLightswitch.Patches { - [HarmonyPatch(typeof(Exosuit))] - [HarmonyPatch("Awake")] - class Exosuit_Awake_Patch + class Exosuit_ToggleLights { - private static void Postfix(Exosuit __instance) + private static GameObject seamoth; + private static IEnumerator SetupToggle(Exosuit __instance) { - Logger.Log("Exosuit Awake"); + Logger.Log("Setup Lights Toggle Start"); + CoroutineTask request = CraftData.GetPrefabForTechTypeAsync(TechType.Seamoth); + yield return request; + seamoth = request.GetResult(); + if (seamoth is null) + { + Logger.Log("Couldn't get seamoth prefab"); + yield break; + } + var toggleLights = __instance.GetComponent(); - var seamothPrefab = Resources.Load("WorldEntities/Tools/SeaMoth"); - var toggleLightsPrefab = seamothPrefab.GetComponent().toggleLights; + var toggleLightsPrefab = seamoth.GetComponent().toggleLights; if (toggleLights == null) { @@ -33,9 +40,21 @@ private static void Postfix(Exosuit __instance) toggleLights.offSound = toggleLightsPrefab.offSound; toggleLights.energyPerSecond = toggleLightsPrefab.energyPerSecond; } - + toggleLights.lightsParent = __instance.transform.Find("lights_parent").gameObject; toggleLights.energyMixin = __instance.GetComponent(); + Logger.Log("Setup Lights Toggle Finish"); + } + + [HarmonyPatch(typeof(Exosuit))] + [HarmonyPatch("Awake")] + class Exosuit_Awake_Patch + { + private static void Postfix(Exosuit __instance) + { + Logger.Log("Exosuit Awake"); + __instance.StartCoroutine(SetupToggle(__instance)); + } } } @@ -67,28 +86,32 @@ class Exosuit_UpdateUIText_Patch { private static readonly FieldInfo Exosuit_uiStringPrimary = typeof(Exosuit).GetField("uiStringPrimary", BindingFlags.NonPublic | BindingFlags.Instance); private static readonly FieldInfo Exosuit_rightArm = typeof(Exosuit).GetField("rightArm", BindingFlags.NonPublic | BindingFlags.Instance); - private static readonly FieldInfo Exosuit_leftArm = typeof(Exosuit).GetField("leftArm", BindingFlags.NonPublic | BindingFlags.Instance); - public static GameInput.Button lightsBinding; + private static readonly FieldInfo Exosuit_leftArm = typeof(Exosuit).GetField("leftArm", BindingFlags.NonPublic | BindingFlags.Instance); + public static GameInput.Button lightsBinding; private static void Postfix(Exosuit __instance) { - bool hasPropCannon = Exosuit_rightArm.GetValue(__instance) is ExosuitPropulsionArm || Exosuit_leftArm.GetValue(__instance) is ExosuitPropulsionArm; - var toggleLights = __instance.GetComponent(); - string lightsString = LanguageCache.GetButtonFormat((!toggleLights.lightsActive) ? "Lights On ({0})" : "Lights Off ({0})", lightsBinding); - string exitString = string.Join("\n", ((string)Exosuit_uiStringPrimary.GetValue(__instance)).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Take(1).ToArray()); - var primaryString = string.Join("\n", ((string)Exosuit_uiStringPrimary.GetValue(__instance)).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray()) + System.Environment.NewLine + lightsString; - var secondaryString = string.Empty; - if (hasPropCannon) - { - lightsBinding = GameInput.Button.Deconstruct; - secondaryString = exitString; - } - else - { - lightsBinding = GameInput.Button.AltTool; - primaryString = primaryString + System.Environment.NewLine + exitString; - } - HandReticle.main.SetUseTextRaw(primaryString, secondaryString); + bool hasPropCannon = Exosuit_rightArm.GetValue(__instance) is ExosuitPropulsionArm || Exosuit_leftArm.GetValue(__instance) is ExosuitPropulsionArm; + var toggleLights = __instance.GetComponent(); + if (toggleLights != null) + { + string lightsString = LanguageCache.GetButtonFormat((!toggleLights.lightsActive) ? "Lights On ({0})" : "Lights Off ({0})", lightsBinding); + string exitString = string.Join("\n", ((string)Exosuit_uiStringPrimary.GetValue(__instance)).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Take(1).ToArray()); + var primaryString = string.Join("\n", ((string)Exosuit_uiStringPrimary.GetValue(__instance)).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray()) + System.Environment.NewLine + lightsString; + var secondaryString = string.Empty; + if (hasPropCannon) + { + lightsBinding = GameInput.Button.Deconstruct; + secondaryString = exitString; + } + else + { + lightsBinding = GameInput.Button.AltTool; + primaryString = primaryString + System.Environment.NewLine + exitString; + } + HandReticle.main.SetTextRaw(HandReticle.TextType.Use, primaryString); + HandReticle.main.SetTextRaw(HandReticle.TextType.UseSubscript, secondaryString); + } } } } diff --git a/SubnauticaModSystem/PrawnsuitLightswitch/PrawnsuitLightswitch.csproj b/SubnauticaModSystem/PrawnsuitLightswitch/PrawnsuitLightswitch.csproj index 572de39..945a442 100644 --- a/SubnauticaModSystem/PrawnsuitLightswitch/PrawnsuitLightswitch.csproj +++ b/SubnauticaModSystem/PrawnsuitLightswitch/PrawnsuitLightswitch.csproj @@ -1,123 +1,122 @@ - - - - - Debug - AnyCPU - {7E1DE3EC-3325-4F95-B306-616E1FA23B40} - Library - Properties - PrawnsuitLightswitch - PrawnsuitLightswitch - v4.7.1 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - Always - - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\0Harmony-1.2.0.1.dll - - - False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Assembly-CSharp.dll - - - False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Assembly-CSharp-firstpass.dll - - - False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Newtonsoft.Json.dll - - - D:\SteamLibrary\steamapps\common\Subnautica\QMods\Modding Helper\SMLHelper.dll - - - - - - - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.dll - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.CoreModule.dll - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.ImageConversionModule.dll - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.JSONSerializeModule.dll - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.TextRenderingModule.dll - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UI.dll - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UIElementsModule.dll - - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UIModule.dll - - - - - - - - - - - True - True - Resources.resx - - - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - - - - + + + + + Debug + AnyCPU + {7E1DE3EC-3325-4F95-B306-616E1FA23B40} + Library + Properties + PrawnsuitLightswitch + PrawnsuitLightswitch + v4.7.1 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + Always + + + + D:\SteamLibrary\steamapps\common\Subnautica\BepInEx\core\0Harmony.dll + + + False + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Assembly-CSharp.dll + + + False + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Assembly-CSharp-firstpass.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\BepInEx\core\BepInEx.dll + + + False + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Newtonsoft.Json.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\QMods\Modding Helper\SMLHelper.dll + + + + + + + + + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.CoreModule.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.ImageConversionModule.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.JSONSerializeModule.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.TextRenderingModule.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UI.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UIElementsModule.dll + + + D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UIModule.dll + + + + + + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + + + + xcopy $(TargetPath) D:\SteamLibrary\steamapps\common\Subnautica\QMods\$(ProjectName)\ /q /y xcopy $(ProjectDir)mod.json D:\SteamLibrary\steamapps\common\Subnautica\QMods\$(ProjectName)\ /q /y xcopy $(ProjectDir)Assets D:\SteamLibrary\steamapps\common\Subnautica\QMods\$(ProjectName)\Assets\ /q /y /i xcopy $(TargetPath) D:\EpicGames\Subnautica\QMods\$(ProjectName)\ /q /y xcopy $(ProjectDir)mod.json D:\EpicGames\Subnautica\QMods\$(ProjectName)\ /q /y -xcopy $(ProjectDir)Assets D:\EpicGames\Subnautica\QMods\$(ProjectName)\Assets\ /q /y /i - +xcopy $(ProjectDir)Assets D:\EpicGames\Subnautica\QMods\$(ProjectName)\Assets\ /q /y /i + \ No newline at end of file diff --git a/SubnauticaModSystem/PrawnsuitLightswitch/mod.json b/SubnauticaModSystem/PrawnsuitLightswitch/mod.json deleted file mode 100644 index d9d12fb..0000000 --- a/SubnauticaModSystem/PrawnsuitLightswitch/mod.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "Id": "PrawnsuitLightswitch", - "DisplayName": "PrawnsuitLightswitch", - "Author": "RandyKnapp", - "Version": "1.0.2", - "Requires": [ "0Harmony-1.2.0.1.dll" ], - "Enable": true, - "AssemblyName": "PrawnsuitLightswitch.dll", - "EntryMethod": "PrawnsuitLightswitch.QPatch.Patch", - "Config": { - "PrawnsuitLightsUseEnergy": true - } -} \ No newline at end of file