Decompiled source of REPOLib v1.0.1

REPOLib.dll

Decompiled 14 hours ago
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Extensions;
using REPOLib.Modules;
using REPOLib.Objects;
using REPOLib.Patches;
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("Zehs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2025 Zehs")]
[assembly: AssemblyDescription("Library for adding content to R.E.P.O.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+3893580e5a571353ee71c6e6083cbc72657e3f1f")]
[assembly: AssemblyProduct("REPOLib")]
[assembly: AssemblyTitle("REPOLib")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ZehsTeam/REPOLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 REPOLib
{
	internal static class ConfigManager
	{
		public static ConfigFile ConfigFile { get; private set; }

		public static ConfigEntry<bool> ExtendedLogging { get; private set; }

		public static void Initialize(ConfigFile configFile)
		{
			ConfigFile = configFile;
			BindConfigs();
		}

		private static void BindConfigs()
		{
			ExtendedLogging = ConfigFile.Bind<bool>("General", "ExtendedLogging", false, "Enable extended logging.");
		}
	}
	internal static class Logger
	{
		public static ManualLogSource ManualLogSource { get; private set; }

		public static void Initialize(ManualLogSource manualLogSource)
		{
			ManualLogSource = manualLogSource;
		}

		public static void LogInfo(object data, bool extended = false)
		{
			Log((LogLevel)16, data, extended);
		}

		public static void LogWarning(object data, bool extended = false)
		{
			Log((LogLevel)4, data, extended);
		}

		public static void LogError(object data, bool extended = false)
		{
			Log((LogLevel)2, data, extended);
		}

		public static void Log(LogLevel logLevel, object data, bool extended = false)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!extended || IsExtendedLoggingEnabled())
			{
				ManualLogSource manualLogSource = ManualLogSource;
				if (manualLogSource != null)
				{
					manualLogSource.Log(logLevel, data);
				}
			}
		}

		private static bool IsExtendedLoggingEnabled()
		{
			if (ConfigManager.ExtendedLogging == null)
			{
				return false;
			}
			return ConfigManager.ExtendedLogging.Value;
		}
	}
	[BepInPlugin("REPOLib", "REPOLib", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("REPOLib");

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger.Initialize(Logger.CreateLogSource("REPOLib"));
			Logger.LogInfo("REPOLib has awoken!");
			_harmony.PatchAll(typeof(RunManagerPatch));
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "REPOLib";

		public const string PLUGIN_NAME = "REPOLib";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace REPOLib.Patches
{
	[HarmonyPatch(typeof(RunManager))]
	internal static class RunManagerPatch
	{
		private static bool _patchedAwake;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch()
		{
			if (!_patchedAwake)
			{
				_patchedAwake = true;
				NetworkPrefabs.Initialize();
				Valuables.RegisterValuables();
			}
		}
	}
}
namespace REPOLib.Objects
{
	public class CustomPrefabPool : IPunPrefabPool
	{
		public readonly Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>();

		private IPunPrefabPool _originalPool;

		public IPunPrefabPool OriginalPool
		{
			get
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Expected O, but got Unknown
				if (_originalPool == null)
				{
					_originalPool = (IPunPrefabPool)new DefaultPool();
				}
				return _originalPool;
			}
			set
			{
				if (value != null && !(value is CustomPrefabPool))
				{
					_originalPool = value;
				}
			}
		}

		public CustomPrefabPool()
		{
		}

		public CustomPrefabPool(IPunPrefabPool existingPool)
		{
			OriginalPool = existingPool;
		}

		public void RegisterPrefab(string prefabId, GameObject prefab)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (Prefabs.TryGetValue(prefabId, out var value))
			{
				LogLevel logLevel = (LogLevel)(((Object)(object)value == (Object)(object)prefab) ? 4 : 2);
				Logger.Log(logLevel, "CustomPrefabPool failed to register network prefab. Network prefab already exists with the prefab id: \"" + prefabId + "\"");
			}
			else
			{
				Prefabs[prefabId] = prefab;
				Logger.LogInfo("CustomPrefabPool registered network prefab: \"" + prefabId + "\"", extended: true);
			}
		}

		public GameObject Instantiate(string prefabId, Vector3 position, Quaternion rotation)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (!TryGetPrefab(ref prefabId, out var prefab))
			{
				return OriginalPool.Instantiate(prefabId, position, rotation);
			}
			bool activeSelf = prefab.activeSelf;
			if (activeSelf)
			{
				prefab.SetActive(false);
			}
			GameObject result = Object.Instantiate<GameObject>(prefab, position, rotation);
			if (activeSelf)
			{
				prefab.SetActive(true);
			}
			Logger.LogInfo($"CustomPrefabPool spawned network prefab: \"{prefabId}\" at position {position}, rotation {((Quaternion)(ref rotation)).eulerAngles}", extended: true);
			return result;
		}

		public bool TryGetPrefab(ref string prefabId, out GameObject prefab)
		{
			if (Prefabs.TryGetValue(prefabId, out prefab))
			{
				return true;
			}
			string text = prefabId.Substring(prefabId.LastIndexOf('/') + 1);
			if (Prefabs.TryGetValue(text, out prefab))
			{
				prefabId = text;
				return true;
			}
			return false;
		}

		public void Destroy(GameObject gameObject)
		{
			Object.Destroy((Object)(object)gameObject);
		}
	}
	public class LevelValuableComparer : IEqualityComparer<LevelValuables>
	{
		public bool Equals(LevelValuables x, LevelValuables y)
		{
			if ((Object)(object)x == (Object)null || (Object)(object)y == (Object)null)
			{
				return false;
			}
			return ((Object)x).name == ((Object)y).name;
		}

		public int GetHashCode(LevelValuables obj)
		{
			return ((Object)obj).name?.GetHashCode() ?? 0;
		}
	}
}
namespace REPOLib.Modules
{
	public static class NetworkPrefabs
	{
		private static CustomPrefabPool _customPrefabPool;

		internal static CustomPrefabPool CustomPrefabPool
		{
			get
			{
				if (_customPrefabPool == null)
				{
					_customPrefabPool = new CustomPrefabPool();
				}
				return _customPrefabPool;
			}
			private set
			{
				_customPrefabPool = value;
			}
		}

		internal static void Initialize()
		{
			Logger.LogInfo("Initializing NetworkPrefabs.");
			if (PhotonNetwork.PrefabPool == null)
			{
				Logger.LogError("NetworkPrefabs failed to initialize. PhotonNetwork.PrefabPool is null.");
				return;
			}
			if (PhotonNetwork.PrefabPool is CustomPrefabPool)
			{
				Logger.LogWarning("NetworkPrefabs failed to initialize. PhotonNetwork.PrefabPool is already a CustomPrefabPool.");
				return;
			}
			Logger.LogInfo($"PhotonNetwork.PrefabPool = {((object)PhotonNetwork.PrefabPool).GetType()}", extended: true);
			CustomPrefabPool.OriginalPool = PhotonNetwork.PrefabPool;
			PhotonNetwork.PrefabPool = (IPunPrefabPool)(object)CustomPrefabPool;
			Logger.LogInfo("Replaced PhotonNetwork.PrefabPool with CustomPrefabPool.");
			Logger.LogInfo($"PhotonNetwork.PrefabPool = {((object)PhotonNetwork.PrefabPool).GetType()}", extended: true);
			Logger.LogInfo("Finished initializing NetworkPrefabs.");
		}

		public static void RegisterNetworkPrefab(GameObject prefab)
		{
			RegisterNetworkPrefab(((Object)prefab).name, prefab);
		}

		public static void RegisterNetworkPrefab(string prefabId, GameObject prefab)
		{
			CustomPrefabPool.RegisterPrefab(prefabId, prefab);
		}
	}
	public static class Valuables
	{
		private static readonly HashSet<LevelValuables> _valuablePresets = new HashSet<LevelValuables>(new LevelValuableComparer());

		private static readonly List<GameObject> _valuablesToRegister = new List<GameObject>();

		private static bool _registeredValuables = false;

		private static void CacheValuablePresets()
		{
			if ((Object)(object)RunManager.instance == (Object)null)
			{
				Logger.LogError("Failed to cache LevelValuables. RunManager instance is null.");
				return;
			}
			foreach (Level level in RunManager.instance.levels)
			{
				foreach (LevelValuables valuablePreset in level.ValuablePresets)
				{
					_valuablePresets.Add(valuablePreset);
				}
			}
		}

		internal static void RegisterValuables()
		{
			if (_registeredValuables)
			{
				return;
			}
			CacheValuablePresets();
			if (_valuablesToRegister.Count == 0)
			{
				Logger.LogError("Failed to register valuables. LevelValuables list is empty!");
				return;
			}
			foreach (GameObject item in _valuablesToRegister)
			{
				foreach (LevelValuables valuablePreset in _valuablePresets)
				{
					valuablePreset.AddValuable(item);
				}
			}
			_valuablesToRegister.Clear();
			_registeredValuables = true;
		}

		public static void RegisterValuable(GameObject prefab)
		{
			RegisterValuable(((Object)prefab).name, prefab);
		}

		public static void RegisterValuable(string prefabId, GameObject prefab)
		{
			if (_registeredValuables)
			{
				Logger.LogError("Failed to register valuable \"" + prefabId + "\". You can only register valuables in awake!");
			}
			else if (!_valuablesToRegister.Contains(prefab))
			{
				NetworkPrefabs.RegisterNetworkPrefab(prefabId, prefab);
				_valuablesToRegister.Add(prefab);
			}
		}
	}
}
namespace REPOLib.Extensions
{
	internal static class LevelValuablesExtension
	{
		public static bool HasValuable(this LevelValuables levelValuables, GameObject prefab)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			ValuableObject val = default(ValuableObject);
			if (!prefab.TryGetComponent<ValuableObject>(ref val))
			{
				return false;
			}
			List<GameObject> list = levelValuables.GetList(val.volumeType);
			return list.Contains(prefab);
		}

		public static void AddValuable(this LevelValuables levelValuables, GameObject prefab)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			ValuableObject val = default(ValuableObject);
			if (!levelValuables.HasValuable(prefab) && prefab.TryGetComponent<ValuableObject>(ref val))
			{
				List<GameObject> list = levelValuables.GetList(val.volumeType);
				list.Add(prefab);
			}
		}

		public static List<GameObject> GetList(this LevelValuables levelValuables, Type volumeType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected I4, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			List<GameObject> list = (int)volumeType switch
			{
				0 => levelValuables.tiny, 
				1 => levelValuables.small, 
				2 => levelValuables.medium, 
				3 => levelValuables.big, 
				4 => levelValuables.wide, 
				5 => levelValuables.tall, 
				6 => levelValuables.veryTall, 
				_ => null, 
			};
			if (list == null)
			{
				Logger.LogWarning($"LevelValuablesExtension.GetList: Unknown ValuableVolume.Type \"{volumeType}\"");
				return new List<GameObject>();
			}
			return list;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}