using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LC_MultiplayerVolumeFix.Config;
using LC_MultiplayerVolumeFix.Hooks;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Confusified.MultiplayerSaveVolume")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0d01125ee6acf3ef03665238074a0a8a8d09f887")]
[assembly: AssemblyProduct("Save Multiplayer Volumes")]
[assembly: AssemblyTitle("Confusified.MultiplayerSaveVolume")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 LC_MultiplayerVolumeFix
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Confusified.MultiplayerSaveVolume", "Save Multiplayer Volumes", "1.0.0")]
public class LC_MultiplayerVolumeFix : BaseUnityPlugin
{
internal static ConfigFile steamid_cfg = new ConfigFile(Application.persistentDataPath + "/Confusified.MultiplayerSaveVolume", false);
internal static ConfigFile cfg = new ConfigFile(Paths.ConfigPath + "/Confusified.MultiplayerSaveVolume.cfg", false);
public static bool MoreCompanyDetected = false;
public static LC_MultiplayerVolumeFix Instance { get; private set; } = null;
internal static ManualLogSource Logger { get; private set; } = null;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
Hook();
Application.wantsToQuit += VolumeHandler.SaveAllPlayerVolumes;
MoreCompanyDetected = Chainloader.PluginInfos.ContainsKey("me.swipez.melonloader.morecompany");
Logger.LogInfo((object)"Save Multiplayer Volumes v1.0.0 has loaded!");
}
internal static void Hook()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
Logger.LogDebug((object)"Hooking...");
Harmony val = new Harmony("Confusified.MultiplayerSaveVolume");
try
{
val.PatchAll(Assembly.GetExecutingAssembly());
}
catch (Exception arg)
{
Logger.LogError((object)$"Error while patching: {arg}");
}
Logger.LogDebug((object)"Finished Hooking");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Confusified.MultiplayerSaveVolume";
public const string PLUGIN_NAME = "Save Multiplayer Volumes";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace LC_MultiplayerVolumeFix.Hooks
{
[HarmonyPatch(typeof(QuickMenuManager))]
public static class VolumeFix
{
public static Dictionary<ulong, float> LocalEntries = new Dictionary<ulong, float>();
[HarmonyPatch("AddUserToPlayerList")]
[HarmonyPrefix]
[HarmonyAfter(new string[] { "me.swipez.melonloader.morecompany" })]
private static void PlayerJoined(QuickMenuManager __instance, ulong steamId, string playerName, int playerObjectId)
{
LC_MultiplayerVolumeFix.Logger.LogDebug((object)"Player joined");
Slider volumeSlider;
if (LC_MultiplayerVolumeFix.MoreCompanyDetected)
{
LC_MultiplayerVolumeFix.Logger.LogDebug((object)"Detected MoreCompany");
Transform val = __instance.playerListPanel.transform.Find("Image");
Transform child = val.GetChild(val.childCount - 1);
child = child.GetChild(0);
Transform child2 = child.GetChild(playerObjectId);
volumeSlider = ((Component)child2.GetChild(child2.childCount - 1)).GetComponent<Slider>();
}
else
{
volumeSlider = __instance.playerListSlots[playerObjectId].volumeSlider;
}
float value = 0.5f;
if (LocalEntries.ContainsKey(steamId))
{
LocalEntries.TryGetValue(steamId, out value);
LC_MultiplayerVolumeFix.Logger.LogDebug((object)"Got volume from current session");
}
else
{
ConfigEntry<float> val2 = LC_MultiplayerVolumeFix.steamid_cfg.Bind<float>("steam_id", $"{steamId}", 0.5f, (ConfigDescription)null);
VolumeHandler.ConfigEntries.Add(steamId, val2);
value = val2.Value;
LC_MultiplayerVolumeFix.Logger.LogDebug((object)"Got volume from cfg");
}
volumeSlider.normalizedValue = value;
((UnityEvent<float>)(object)volumeSlider.onValueChanged).AddListener((UnityAction<float>)delegate(float newValue)
{
UpdateVolumeValue(newValue, volumeSlider, steamId);
});
}
private static void UpdateVolumeValue(float newValue, Slider volumeSlider, ulong steamId)
{
float num = (newValue - volumeSlider.minValue) / (volumeSlider.maxValue - volumeSlider.minValue);
if (num <= 0f)
{
num = -70f;
}
if (LocalEntries.ContainsKey(steamId))
{
LocalEntries.Remove(steamId);
}
LocalEntries.Add(steamId, num);
LC_MultiplayerVolumeFix.Logger.LogDebug((object)$"updated: {num}");
}
}
}
namespace LC_MultiplayerVolumeFix.Config
{
public static class VolumeHandler
{
public const float DEFAULT_PLAYER_VOLUME = 0.5f;
public static Dictionary<ulong, ConfigEntry<float>> ConfigEntries = new Dictionary<ulong, ConfigEntry<float>>();
public static bool SaveAllPlayerVolumes()
{
foreach (ulong key in VolumeFix.LocalEntries.Keys)
{
if (VolumeFix.LocalEntries.TryGetValue(key, out var value))
{
ConfigEntry<float> value2;
if (ConfigEntries.ContainsKey(key))
{
ConfigEntries.TryGetValue(key, out value2);
}
else
{
value2 = LC_MultiplayerVolumeFix.steamid_cfg.Bind<float>("steam_id", $"{key}", 0.5f, (ConfigDescription)null);
}
value2.Value = value;
}
}
if (VolumeFix.LocalEntries.Keys.Count > 0)
{
LC_MultiplayerVolumeFix.Logger.LogDebug((object)"Saved player volumes.");
}
return true;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}