Skip to content

Commit

Permalink
-SaveValue configs now save to a dedicated folder
Browse files Browse the repository at this point in the history
-PMLSettings GUI now has DBM toggle
-DBM is now handled with a SaveValue config.
  • Loading branch information
Nagord committed Nov 14, 2022
1 parent 34b34b3 commit f954269
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
11 changes: 3 additions & 8 deletions PulsarModLoader/Chat/Commands/DebugModeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace PulsarModLoader.Chat.Commands
{
class DebugModeCommand : ChatCommand
{
public static bool DebugMode = false;

public override string[] CommandAliases()
{
return new string[] { "debugmode", "dbm" };
Expand All @@ -20,15 +18,12 @@ public override string Description()
public override void Execute(string arguments)
{
//Toggle DebugMode value
DebugMode = !DebugMode;

//Write new DebugMode value to settings xml file
PLXMLOptionsIO.Instance.CurrentOptions.SetStringValue("PMLDebugMode", DebugMode.ToString());
PMLConfig.DebugMode.Value = !PMLConfig.DebugMode.Value;

//notify player of new DebugMode value
Messaging.Notification($"PMLDebugMode is now {DebugMode}");
Messaging.Notification($"PMLDebugMode is now {PMLConfig.DebugMode}");

if (!DebugMode)
if (!PMLConfig.DebugMode)
PLInGameUI.Instance.CurrentVersionLabel.text = PulsarModLoader.Patches.GameVersion.Version;
}

Expand Down
10 changes: 10 additions & 0 deletions PulsarModLoader/CustomGUI/PMLSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ class PMLSettings : ModSettingsMenu
public override string Name() => "PulsarModLoader";
public override void Draw()
{
if (Button("Debug Mode: " + (PMLConfig.DebugMode ? "Enabled" : "Disabled")))
{
PMLConfig.DebugMode.Value = !PMLConfig.DebugMode.Value;

if (!PMLConfig.DebugMode)
{
PLInGameUI.Instance.CurrentVersionLabel.text = PulsarModLoader.Patches.GameVersion.Version;
}
}

GUI.skin.label.alignment = TextAnchor.UpperLeft;
BeginHorizontal();
{
Expand Down
9 changes: 3 additions & 6 deletions PulsarModLoader/PMLConfig.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
using Valve.Newtonsoft.Json;
using Valve.Newtonsoft.Json.Converters;
using UnityEngine;

namespace PulsarModLoader
{
Expand All @@ -12,6 +7,8 @@ public static class PMLConfig
public static SaveValue<UnityEngine.TextAnchor> ModInfoTextAnchor =
new SaveValue<TextAnchor>("ModInfoTextAnchor", TextAnchor.UpperLeft);

public static SaveValue<bool> DebugMode = new SaveValue<bool>("DebugMode", false);

public static void SetDefault()
{
ModInfoTextAnchor.Value = TextAnchor.UpperLeft;
Expand Down
2 changes: 1 addition & 1 deletion PulsarModLoader/Patches/DebugReadout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DebugReadout
{
static void Postfix(PLInGameUI __instance)
{
if (DebugModeCommand.DebugMode && PLServer.Instance != null && PLEncounterManager.Instance != null && PLNetworkManager.Instance != null && GameVersion.Version != string.Empty)
if (PMLConfig.DebugMode && PLServer.Instance != null && PLEncounterManager.Instance != null && PLNetworkManager.Instance != null && GameVersion.Version != string.Empty)
{
Vector3 pos;
if (PLNetworkManager.Instance.LocalPlayer != null)
Expand Down
19 changes: 7 additions & 12 deletions PulsarModLoader/Patches/PLGlobalStart.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using HarmonyLib;
using System.IO;
using System.Reflection;
using UnityEngine;

namespace PulsarModLoader.Patches
Expand All @@ -14,23 +13,19 @@ static void Prefix()
{
if (!modsLoaded)
{
//DebugModeSetting
if (bool.TryParse(PLXMLOptionsIO.Instance.CurrentOptions.GetStringValue("PMLDebugMode"), out bool result))
{
Chat.Commands.DebugModeCommand.DebugMode = result;
}

//PML Config
//string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/PulsarModLoaderConfig.json";
//if (!File.Exists(path)) PMLConfig.CreateDefaultConfig(path, true);
//else PMLConfig.CreateConfigFromFile(path);

//Modmanager GUI Init.
new GameObject("ModManager", typeof(CustomGUI.GUIMain)) { hideFlags = HideFlags.HideAndDontSave };

//SaveDataManager Init()
new SaveData.SaveDataManager();

//Create ModConfigs Directory for SaveValue class
string ModConfigDir = SaveValueManager.GetConfigFolder();
if (!Directory.Exists(ModConfigDir))
{
Directory.CreateDirectory(ModConfigDir);
}

//ModLoading
string modsDir = Path.Combine(Directory.GetCurrentDirectory(), "Mods");
ModManager.Instance.LoadModsDirectory(modsDir);
Expand Down
1 change: 1 addition & 0 deletions PulsarModLoader/SaveData/SaveDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void LoadDatas(BinaryReader reader, bool ldarg3)
for (int i = 0; i < count; i++)
{
//SaveDataHeader
Logger.Info($"{reader.BaseStream.Position}");
string harmonyIdent = reader.ReadString(); //HarmonyIdentifier
string SavDatIdent = reader.ReadString(); //SaveDataIdentifier
uint VersionID = reader.ReadUInt32(); //VersionID
Expand Down
16 changes: 9 additions & 7 deletions PulsarModLoader/SaveValue.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using HarmonyLib;
using PulsarModLoader.Utilities;
using Valve.Newtonsoft.Json;
using Valve.Newtonsoft.Json.Converters;

namespace PulsarModLoader
{
internal class SaveValueManager
internal class SaveValueManager
{
public static string GetConfigFolder()
{
return Path.Combine(Directory.GetCurrentDirectory(), "ModConfigs");
}

private static JsonSerializerSettings serializerSettings;
static SaveValueManager()
{
Expand Down Expand Up @@ -55,7 +57,7 @@ internal static T GetValueFor<T>(string id, Assembly mod, T @default)
private static string GetConfigFile(Assembly mod)
{
if (ModToConfigFile.ContainsKey(mod)) return ModToConfigFile[mod];
string newFile = mod.Location.Replace(".dll", ".json");
string newFile = Path.Combine(GetConfigFolder(), mod.GetName().Name + ".json");
ModToConfigFile.Add(mod, newFile);
if (!ModToCacheValues.ContainsKey(mod) && File.Exists(newFile))
ModToCacheValues.Add(mod, JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(newFile)));
Expand Down
2 changes: 1 addition & 1 deletion PulsarModLoader/Utilities/ExceptionWarningPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private static void OnUnityLog(string line, string stackTrace, LogType type)
{
string id = String.Format("{0:X}", DateTime.UtcNow.GetHashCode()).Substring(0, 7).ToUpper();
string msg = $"<color='#{ColorUtility.ToHtmlStringRGB(Color.red)}'>Exception!</color> {id}";
if (DebugModeCommand.DebugMode)
if (PMLConfig.DebugMode)
{
Messaging.Notification(msg);
}
Expand Down
2 changes: 1 addition & 1 deletion PulsarModLoader/Utilities/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void Info(string message)
}

string line;
if (Chat.Commands.DebugModeCommand.DebugMode)
if (PMLConfig.DebugMode)
{
MethodBase invoker = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod();
string type = invoker.DeclaringType.ToString();
Expand Down
2 changes: 1 addition & 1 deletion PulsarModLoader/Utilities/Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ internal static void AntiNullReferenceException(string args)

Logger.Info($"NullReferenceException! Target -> {targetMethod.Name}({args}); Caller -> {who?.ReflectedType?.FullName}.{who?.Name}({who?.GetParameters()?.ToStringFull()});");

if (Chat.Commands.DebugModeCommand.DebugMode)
if (PMLConfig.DebugMode)
Messaging.Notification("NullReferenceException! Check the logs!");
}

Expand Down

0 comments on commit f954269

Please sign in to comment.