Decompiled source of JsonFileIO v0.0.3

JsonSaveSystem.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("NGA")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Persistent player progression! Raid, stash loot, and deploy with seemless scene/loadout saving.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("JsonSaveSystem")]
[assembly: AssemblyTitle("BepInEx Plugin Title")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace NGA
{
	[BepInPlugin("NGA.JsonFileIO", "JsonFileIO", "0.0.1")]
	[BepInProcess("h3vr.exe")]
	public class JsonSaveSystem : BaseUnityPlugin
	{
		[Serializable]
		public class ExtensibleDictionary
		{
			[Serializable]
			public class DictionaryEntry
			{
				public string key;

				public string value;
			}

			public List<DictionaryEntry> entries = new List<DictionaryEntry>();

			public List<string> keys = new List<string>();

			public void InsertOrUpdateEntry(string key, string value)
			{
				if (!keys.Contains(key))
				{
					entries.Add(new DictionaryEntry
					{
						key = key,
						value = value
					});
					keys.Add(key);
					return;
				}
				DictionaryEntry dictionaryEntry = entries.Find((DictionaryEntry entry) => entry.key == key);
				if (dictionaryEntry != null)
				{
					dictionaryEntry.value = value;
				}
				else
				{
					Logger.LogWarning((object)("Failed to update value for key '" + key + "'."));
				}
			}

			public void AddEntry(string key, string value)
			{
				if (!keys.Contains(key))
				{
					entries.Add(new DictionaryEntry
					{
						key = key,
						value = value
					});
					keys.Add(key);
				}
				else
				{
					Logger.LogWarning((object)("Key '" + key + "' already exists in the dictionary."));
				}
			}

			public void RemoveEntry(string key)
			{
				entries.RemoveAll((DictionaryEntry entry) => entry.key == key);
				keys.Remove(key);
			}

			public string GetValue(string key)
			{
				foreach (DictionaryEntry entry in entries)
				{
					if (entry.key == key)
					{
						return entry.value;
					}
				}
				return null;
			}

			public string ToJson()
			{
				return JsonUtility.ToJson((object)this);
			}

			public static ExtensibleDictionary FromJson(string json)
			{
				return JsonUtility.FromJson<ExtensibleDictionary>(json);
			}

			public bool ContainsKey(string key)
			{
				return keys.Contains(key);
			}
		}

		public static class FileIO
		{
			private static string GetModFolderPath(string myModFolderName)
			{
				if (string.IsNullOrEmpty(myModFolderName))
				{
					Logger.LogError((object)"My mod folder cannot be empty or null");
					return null;
				}
				string text = Paths.PluginPath + "/" + myModFolderName + "/";
				if (Directory.Exists(text))
				{
					return text;
				}
				Logger.LogError((object)("Mod folder provided does not exist: " + text));
				return null;
			}

			public static void WriteToFile(string myModFolderName, string fileName, string content)
			{
				string modFolderPath = GetModFolderPath(myModFolderName);
				if (modFolderPath == null)
				{
					Logger.LogError((object)"WriteToFile: The mod folder is not valid in FileIO");
					return;
				}
				string path = Path.Combine(modFolderPath, fileName);
				File.WriteAllText(path, content);
			}

			public static string ReadFile(string myModFolderName, string fileName)
			{
				string modFolderPath = GetModFolderPath(myModFolderName);
				if (modFolderPath == null)
				{
					Logger.LogError((object)"ReadFile: The mod folder is not valid in FileIO");
					return null;
				}
				string text = Path.Combine(modFolderPath, fileName);
				if (File.Exists(text))
				{
					return File.ReadAllText(text);
				}
				Logger.LogError((object)("ReadFile: File not found: " + text));
				return null;
			}
		}

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("NGA.JsonSaveSystem");
			Logger.LogMessage((object)"New harmony");
			val.PatchAll();
			Logger.LogMessage((object)"Hello, world! Sent from NGA.JsonSaveSystem 0.0.1");
		}

		private void SetUpConfigFields()
		{
		}
	}
}