Decompiled source of AdvancedREPO Config Reloaded v1.0.3

plugins/ConfigSyncReloaded.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ConfigSyncReloaded")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConfigSyncReloaded")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("72bc5bdb-d737-4143-9787-ddf2788733dd")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace AdvancedREPO.Config;

[BepInPlugin("potatoepet.advancedrepo.config", "AdvancedREPO.Config (Reloaded)", "1.0.3")]
public class Plugin : BaseUnityPlugin
{
	public static ManualLogSource Log;

	private void Awake()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"Initializing AdvancedREPO.Config Reloaded...");
		GameObject val = new GameObject("ConfigSync");
		Object.DontDestroyOnLoad((Object)(object)val);
		val.AddComponent<ConfigSync>();
		Log.LogInfo((object)"AdvancedREPO.Config Reloaded initialized!");
	}
}
public class ConfigSync : MonoBehaviourPunCallbacks
{
	public static ConfigSync Instance { get; private set; }

	private void Awake()
	{
		if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
		{
			Object.Destroy((Object)(object)this);
			return;
		}
		Instance = this;
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		if ((Object)(object)((Component)this).GetComponent<PhotonView>() == (Object)null)
		{
			((Component)this).gameObject.AddComponent<PhotonView>();
		}
	}

	public void SendConfigUpdate(string key, object value)
	{
		if (PhotonNetwork.IsMasterClient)
		{
			if (value is bool flag)
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_ReceiveConfigBool", (RpcTarget)1, new object[2] { key, flag });
			}
			else if (value is float num)
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_ReceiveConfigFloat", (RpcTarget)1, new object[2] { key, num });
			}
			else if (value is int num2)
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_ReceiveConfigInt", (RpcTarget)1, new object[2] { key, num2 });
			}
			else if (value is string text)
			{
				((MonoBehaviourPun)this).photonView.RPC("RPC_ReceiveConfigString", (RpcTarget)1, new object[2] { key, text });
			}
		}
	}

	[PunRPC]
	private void RPC_ReceiveConfigBool(string key, bool value)
	{
		SyncUtils.ReceiveConfigValue(key, value);
	}

	[PunRPC]
	private void RPC_ReceiveConfigFloat(string key, float value)
	{
		SyncUtils.ReceiveConfigValue(key, value);
	}

	[PunRPC]
	private void RPC_ReceiveConfigInt(string key, int value)
	{
		SyncUtils.ReceiveConfigValue(key, value);
	}

	[PunRPC]
	private void RPC_ReceiveConfigString(string key, string value)
	{
		SyncUtils.ReceiveConfigValue(key, value);
	}
}
internal static class SyncUtils
{
	private static Dictionary<string, ConfigField> _configs = new Dictionary<string, ConfigField>();

	public static void RegisterConfig(string key, ConfigField field)
	{
		_configs[key] = field;
	}

	public static void ReceiveConfigValue<T>(string key, T value)
	{
		if (_configs.TryGetValue(key, out var value2) && value2 is ConfigField<T> configField)
		{
			configField.ReceiveSyncedValue(value);
		}
	}
}
public abstract class ConfigField
{
	internal bool Sync = false;

	internal string Key = null;

	public virtual void AddToSync()
	{
	}

	internal virtual void SyncWithClients()
	{
	}
}
public class ConfigField<T> : ConfigField
{
	public delegate void SettingChangedHandler(object sender, EventArgs e);

	public delegate void ValueChangedHandler(object sender, EventArgs e);

	private bool ReceivedSynced = false;

	private ConfigEntry<T> _Entry;

	private T OldValue;

	private T _SyncedValue;

	public ConfigEntry<T> Entry
	{
		get
		{
			return _Entry;
		}
		set
		{
			if (_Entry != null)
			{
				_Entry.SettingChanged -= SettingChangedListener;
			}
			_Entry = value;
			OldValue = _Entry.Value;
			_Entry.SettingChanged += SettingChangedListener;
		}
	}

	internal T SyncedValue
	{
		get
		{
			return _SyncedValue;
		}
		set
		{
			ReceivedSynced = true;
			bool flag = !EqualityComparer<T>.Default.Equals(value, Value);
			_SyncedValue = value;
			if (flag)
			{
				this.ValueChanged?.Invoke(this, EventArgs.Empty);
			}
		}
	}

	public T Value
	{
		get
		{
			if (Sync && ReceivedSynced)
			{
				return SyncedValue;
			}
			return (_Entry != null) ? _Entry.Value : default(T);
		}
		set
		{
			if (_Entry != null)
			{
				_Entry.Value = value;
			}
		}
	}

	public event SettingChangedHandler SettingChanged;

	public event ValueChangedHandler ValueChanged;

	private void SettingChangedListener(object sender, EventArgs e)
	{
		bool flag = !EqualityComparer<T>.Default.Equals(OldValue, Entry.Value);
		OldValue = Entry.Value;
		T value = Value;
		this.SettingChanged?.Invoke(sender, e);
		if (flag)
		{
			this.ValueChanged?.Invoke(this, EventArgs.Empty);
		}
		if ((!Sync || flag) && (!Sync || !EqualityComparer<T>.Default.Equals(SyncedValue, Entry.Value)) && Sync)
		{
			SyncWithClients();
		}
	}

	internal override void SyncWithClients()
	{
		if ((Object)(object)ConfigSync.Instance != (Object)null && PhotonNetwork.IsMasterClient)
		{
			ConfigSync.Instance.SendConfigUpdate(Key, Entry.Value);
		}
	}

	public void Register()
	{
		SyncUtils.RegisterConfig(Key, this);
	}

	public void ReceiveSyncedValue(T value)
	{
		SyncedValue = value;
	}
}
public static class ConfigBuilderStatic
{
	public static ConfigField<T> Sync<T>(this ConfigEntry<T> entry)
	{
		return ConfigBuilder<T>.Sync(entry, Assembly.GetCallingAssembly().GetName().Name);
	}
}
public class ConfigBuilder<T>
{
	private static Dictionary<string, ConfigFile> AssignedFiles = new Dictionary<string, ConfigFile>(StringComparer.OrdinalIgnoreCase);

	private ConfigFile _File;

	private bool _Sync = false;

	private string _Description;

	private string _Section;

	private string _Key;

	private T[] _Acceptable;

	private T _Min;

	private T _Max;

	private T _Default;

	private ConfigEntry<T> _Entry;

	private string _ModName;

	public ConfigBuilder()
	{
		_ModName = Assembly.GetCallingAssembly().GetName().Name;
	}

	public ConfigBuilder(string modName)
	{
		_ModName = modName;
	}

	public static ConfigField<T> Sync(ConfigEntry<T> entry, string modName = null)
	{
		return new ConfigBuilder<T>(modName ?? Assembly.GetCallingAssembly().GetName().Name).Entry(entry).Sync().Build();
	}

	public static ConfigBuilder<T> FromConfigEntry(ConfigEntry<T> entry)
	{
		return new ConfigBuilder<T>(Assembly.GetCallingAssembly().GetName().Name).Entry(entry);
	}

	public ConfigBuilder<T> Entry(ConfigEntry<T> entry)
	{
		_Entry = entry;
		return this;
	}

	private static ConfigFile FindFile(string modName, string fileName)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		string text = Path.Combine(Paths.ConfigPath, modName, fileName);
		if (!AssignedFiles.ContainsKey(text))
		{
			AssignedFiles.Add(text, new ConfigFile(text, true));
		}
		return AssignedFiles[text];
	}

	public ConfigBuilder<T> Description(string description)
	{
		_Description = description;
		return this;
	}

	public ConfigBuilder<T> Section(string section)
	{
		_Section = section;
		return this;
	}

	public ConfigBuilder<T> Key(string key)
	{
		_Key = key;
		return this;
	}

	public ConfigBuilder<T> Range(T min, T max)
	{
		_Min = min;
		_Max = max;
		return this;
	}

	public ConfigBuilder<T> Default(T @default)
	{
		_Default = @default;
		return this;
	}

	public ConfigBuilder<T> Acceptable(T[] values)
	{
		_Acceptable = values;
		return this;
	}

	public ConfigBuilder<T> Sync(bool val = true)
	{
		_Sync = val;
		return this;
	}

	public ConfigBuilder<T> File(ConfigFile file)
	{
		_File = file;
		return this;
	}

	public ConfigBuilder<T> File(string fileName)
	{
		_File = FindFile(_ModName, fileName);
		return this;
	}

	public ConfigField<T> Build()
	{
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Expected O, but got Unknown
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Expected O, but got Unknown
		//IL_0190: Expected O, but got Unknown
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Expected O, but got Unknown
		ConfigField<T> ret = new ConfigField<T>();
		ret.Sync = _Sync;
		if (_Entry != null)
		{
			ret.Entry = _Entry;
		}
		else if (_File != null)
		{
			AcceptableValueBase val = null;
			if (_Min != null && _Max != null && default(T) is IComparable<T>)
			{
				Type type = typeof(AcceptableValueRange<>).MakeGenericType(typeof(T));
				val = (AcceptableValueBase)Activator.CreateInstance(type, _Min, _Max);
			}
			else if (_Acceptable != null && default(T) is IEquatable<T>)
			{
				Type type2 = typeof(AcceptableValueList<>).MakeGenericType(typeof(T));
				val = (AcceptableValueBase)Activator.CreateInstance(type2, _Acceptable);
			}
			ret.Entry = _File.Bind<T>(new ConfigDefinition(_Section, _Key), _Default, new ConfigDescription(_Description, val, Array.Empty<object>()));
		}
		ret.Key = _ModName;
		if (!string.IsNullOrEmpty(((ConfigEntryBase)ret.Entry).Definition.Section))
		{
			ConfigField<T> configField = ret;
			configField.Key = configField.Key + ":" + ((ConfigEntryBase)ret.Entry).Definition.Section;
		}
		ConfigField<T> configField2 = ret;
		configField2.Key = configField2.Key + ":" + ((ConfigEntryBase)ret.Entry).Definition.Key;
		if (ret.Sync)
		{
			ret.Entry.SettingChanged += delegate
			{
				if (!EqualityComparer<T>.Default.Equals(ret.SyncedValue, ret.Entry.Value))
				{
					ret.SyncWithClients();
				}
			};
		}
		ret.Register();
		return ret;
	}
}