Decompiled source of Whitelist v1.0.0

off_grid.Whitelist.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
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.Cryptography;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("off_grid.Whitelist")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Whitelist")]
[assembly: AssemblyTitle("off_grid.Whitelist")]
[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 Whitelist
{
	[BepInPlugin("off_grid.Whitelist", "Whitelist", "1.0.0")]
	public class Whitelist : BaseUnityPlugin, IOnEventCallback, IInRoomCallbacks
	{
		private bool configSynced;

		private bool LobbyStatus;

		private string localHash;

		public ConfigFile config;

		private string? ConfigVersion;

		public static Whitelist Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			InitializeConfig();
			Patch();
			PhotonNetwork.AddCallbackTarget((object)this);
			Logger.LogInfo((object)"off_grid.Whitelist v1.0.0 has fully loaded!");
			localHash = GenerateModHash();
			UpdateLocalHashConfig(localHash);
		}

		private void InitializeConfig()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "DAa Mods");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string text2 = Path.Combine(text, "config.cfg");
			config = new ConfigFile(text2, true);
			ConfigVersion = config.Bind<string>("Version", "Current Version", "", (ConfigDescription)null).Value;
			if (ConfigVersion != "1.0.0")
			{
				config.Clear();
				DefineConfig();
			}
		}

		private void DefineConfig()
		{
			config.Bind<string>("Version", "Current Version", "1.0.0", "Autoupdates the config / lets the mod know what version of config it is.");
			config.Bind<string>("Hash", "Hash", "", "Hash used to check if mods are the same");
		}

		private void OnDestroy()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}

		private void OnEnable()
		{
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		private void OnDisable()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}

		private void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("off_grid.Whitelist");
			}
			Harmony.PatchAll();
		}

		private string GenerateModHash()
		{
			string path = Path.Combine(Paths.PluginPath);
			using MD5 mD = MD5.Create();
			string[] files = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);
			byte[] buffer = files.Select(File.ReadAllBytes).SelectMany((byte[] b) => b).ToArray();
			byte[] array = mD.ComputeHash(buffer);
			return BitConverter.ToString(array).Replace("-", "").ToLowerInvariant();
		}

		private void Update()
		{
			if (PhotonNetwork.InRoom && !LobbyStatus)
			{
				LobbyStatus = true;
				if (PhotonNetwork.IsMasterClient)
				{
					SendHashToPlayers();
				}
				else
				{
					((MonoBehaviour)this).StartCoroutine(WaitForConfigSync());
				}
			}
			if (!PhotonNetwork.InRoom && LobbyStatus)
			{
				LobbyStatus = false;
			}
		}

		public void OnEvent(EventData photonEvent)
		{
			if (photonEvent.Code == 1 && photonEvent.CustomData is object[] array && array.Length != 0 && array[0] is string text && text != localHash)
			{
				PhotonNetwork.Disconnect();
				Logger.LogError((object)(text ?? ""));
				Logger.LogError((object)(localHash ?? ""));
				Logger.LogError((object)"Mod hashes do not match. Disconnecting from the server.");
			}
		}

		private void SendHashToPlayers()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[1] { localHash };
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)0
			};
			PhotonNetwork.RaiseEvent((byte)1, (object)array, val, SendOptions.SendReliable);
		}

		private IEnumerator WaitForConfigSync()
		{
			while (!configSynced)
			{
				yield return null;
			}
		}

		public void OnPlayerEnteredRoom(Player newPlayer)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				SendHashToPlayer(newPlayer);
			}
		}

		private void UpdateLocalHashConfig(string hash)
		{
			ConfigEntry<string> val = config.Bind<string>("Hash", "Hash", "", "Hash used to check if mods are the same");
			if (val.Value != hash)
			{
				val.Value = hash;
				config.Save();
			}
		}

		private void SendHashToPlayer(Player player)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[1] { localHash };
			RaiseEventOptions val = new RaiseEventOptions();
			val.TargetActors = new int[1] { player.ActorNumber };
			RaiseEventOptions val2 = val;
			PhotonNetwork.RaiseEvent((byte)1, (object)array, val2, SendOptions.SendReliable);
		}

		public void OnPlayerLeftRoom(Player otherPlayer)
		{
		}

		public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
		{
		}

		public void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
		{
		}

		public void OnMasterClientSwitched(Player newMasterClient)
		{
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "off_grid.Whitelist";

		public const string PLUGIN_NAME = "Whitelist";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MissingItems.Patches
{
	internal class NetworkHandler
	{
	}
}