Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SavePlayerVolume v1.0.0
SavePlayerVolume.dll
Decompiled 10 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("SavePlayerVolume")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+82f5489839a1a6872dda35eae21f242005e3ef8c")] [assembly: AssemblyProduct("SavePlayerVolume")] [assembly: AssemblyTitle("SavePlayerVolume")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.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 SavePlayerVolume { [BepInPlugin("SavePlayerVolume", "SavePlayerVolume", "1.0.0")] public class Plugin : BaseUnityPlugin { public class Patches { public static string SavePath = Application.persistentDataPath + "\\playervolumes.txt"; private static Dictionary<ulong, float> PlayerVolumes; private static float DefaultVolume = 0f; private static void SaveToFile() { File.WriteAllLines(SavePath, PlayerVolumes.Select((KeyValuePair<ulong, float> kvp) => $"{kvp.Key};{kvp.Value}")); } private static Dictionary<ulong, float> LoadFromFile() { if (File.Exists(SavePath)) { Dictionary<ulong, float> dictionary = new Dictionary<ulong, float>(); IEnumerable<string> enumerable = File.ReadLines(SavePath); foreach (string item in enumerable) { string[] array = item.Split(';'); dictionary.Add(Convert.ToUInt64(array[0]), Convert.ToSingle(array[1])); } return dictionary; } return new Dictionary<ulong, float>(); } [HarmonyPatch(typeof(QuickMenuManager), "Update")] [HarmonyPostfix] private static void Update(QuickMenuManager __instance) { PlayerListSlot[] playerListSlots = __instance.playerListSlots; PlayerListSlot[] playerListSlots2 = __instance.playerListSlots; for (int i = 0; i < playerListSlots.Length; i++) { PlayerListSlot val = playerListSlots[i]; bool flag = val.volumeSlider.value == DefaultVolume; if (val.isConnected && flag && PlayerVolumes.TryGetValue(val.playerSteamId, out var value)) { PlayerListSlot val2 = val; val2.volumeSlider.value = value; playerListSlots2[i] = val2; PlayerVolumes[val.playerSteamId] = value; } } Traverse.Create((object)__instance).Field("playerListSlots").SetValue((object)playerListSlots2); } [HarmonyPatch(typeof(QuickMenuManager), "Start")] [HarmonyPostfix] private static void InitializePlayerVolumesFromFile() { PlayerVolumes = LoadFromFile(); } [HarmonyPatch(typeof(QuickMenuManager), "CloseQuickMenu")] [HarmonyPostfix] private static void SavePlayerVolumesToFile(QuickMenuManager __instance) { PlayerListSlot[] playerListSlots = __instance.playerListSlots; foreach (PlayerListSlot val in playerListSlots) { bool flag = val.volumeSlider.value == DefaultVolume; if (val.isConnected && !flag) { PlayerVolumes[val.playerSteamId] = val.volumeSlider.value; } } SaveToFile(); } } public static Plugin Instance; private void Awake() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown ((BaseUnityPlugin)this).Logger.LogInfo((object)"Initializing SavePlayerVolume"); Instance = this; Harmony val = new Harmony("SavePlayerVolume"); val.PatchAll(typeof(Patches)); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Initialized SavePlayerVolume"); } } public static class PluginInfo { public const string PLUGIN_GUID = "SavePlayerVolume"; public const string PLUGIN_NAME = "SavePlayerVolume"; public const string PLUGIN_VERSION = "1.0.0"; } }