Decompiled source of REPOShopLib v2.0.0

REPOShopLib.dll

Decompiled 14 hours ago
using System;
using System.Collections;
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using REPOLib.Modules;
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: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("DirtyGames")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("REPOShopLib")]
[assembly: AssemblyTitle("REPOShopLib")]
[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 REPOShopLib
{
	[BepInPlugin("DirtyGames.REPOShopLib", "REPOShopLib", "2.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class REPOShopLib : BaseUnityPlugin
	{
		internal static REPOShopLib Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		public void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		public void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class ShopUtils
	{
		private static string? _activeShopName = null;

		public static bool _removeShopRooms = false;

		public static bool _forceSpecificShop = false;

		private static readonly Dictionary<string, List<GameObject>> _shopRooms = new Dictionary<string, List<GameObject>>();

		private static readonly Dictionary<string, GameObject> _namedShops = new Dictionary<string, GameObject>();

		public static bool EnableRandomShopSelection = false;

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

		public static int DefaultRoomCount => _defaultRooms.Count;

		public static void CacheDefaultRooms(List<GameObject> source)
		{
			_defaultRooms.Clear();
			_defaultRooms.AddRange(source.Where((GameObject r) => (Object)(object)r != (Object)null));
			Debug.Log((object)$"[REPOShopLib] Cached {_defaultRooms.Count} default shop room(s).");
		}

		public static void RegisterNamedShop(string name, GameObject prefab)
		{
			if (string.IsNullOrWhiteSpace(name) || (Object)(object)prefab == (Object)null)
			{
				Debug.LogWarning((object)"[REPOShopLib] Invalid name or null prefab passed to RegisterNamedShop.");
				return;
			}
			if (_namedShops.ContainsKey(name))
			{
				Debug.LogWarning((object)("[REPOShopLib] Shop '" + name + "' is already registered. Overwriting."));
			}
			_namedShops[name] = prefab;
			Debug.Log((object)("[REPOShopLib] Registered named shop: " + name));
		}

		public static void SetActiveShop(string name)
		{
			if (!_namedShops.ContainsKey(name))
			{
				Debug.LogError((object)("[REPOShopLib] No shop registered under name '" + name + "'."));
				return;
			}
			_forceSpecificShop = true;
			_activeShopName = name;
			Debug.Log((object)("[REPOShopLib] Active shop set to: " + name));
		}

		public static void UseRandomShop()
		{
			_forceSpecificShop = false;
		}

		internal static void InjectActiveShop()
		{
			RunManager instance = RunManager.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.levelCurrent != (Object)(object)instance.levelShop)
			{
				return;
			}
			if (EnableRandomShopSelection && !_forceSpecificShop && _namedShops.Count > 0)
			{
				int index = Random.Range(0, _namedShops.Count);
				_activeShopName = new List<string>(_namedShops.Keys)[index];
				Debug.Log((object)("[REPOShopLib] Randomly selected active shop: " + _activeShopName));
			}
			if (string.IsNullOrEmpty(_activeShopName))
			{
				Debug.LogWarning((object)"[REPOShopLib] No active shop set and no shops available to select.");
				return;
			}
			if (!_namedShops.TryGetValue(_activeShopName, out GameObject value))
			{
				Debug.LogError((object)("[REPOShopLib] Active shop '" + _activeShopName + "' not found in registered shops."));
				return;
			}
			string text = "Level/Shop/Modules/" + ((Object)value).name;
			if ((Object)(object)Resources.Load<GameObject>(text) != (Object)(object)value)
			{
				NetworkPrefabs.RegisterNetworkPrefab(text, value);
			}
			instance.levelShop.ModulesNormal1.Clear();
			instance.levelShop.ModulesNormal1.Add(value);
			Debug.Log((object)("[REPOShopLib] Injected shop prefab: " + ((Object)value).name));
			Debug.Log((object)"[REPOShopLib] Registered shops:");
			foreach (string key in _namedShops.Keys)
			{
				Debug.Log((object)(" - " + key));
			}
		}

		internal static void InjectRegisteredShopRoom()
		{
			RunManager instance = RunManager.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.levelCurrent != (Object)(object)instance.levelShop)
			{
				return;
			}
			instance.levelShop.ModulesDeadEnd1.Clear();
			if (string.IsNullOrEmpty(_activeShopName))
			{
				Debug.LogWarning((object)"[REPOShopLib] No active shop name for room injection.");
				return;
			}
			if (!_shopRooms.TryGetValue(_activeShopName, out List<GameObject> value) || value.Count == 0)
			{
				Debug.Log((object)("[REPOShopLib] No shop rooms registered for '" + _activeShopName + "', falling back to default rooms."));
				{
					foreach (GameObject defaultRoom in _defaultRooms)
					{
						instance.levelShop.ModulesDeadEnd1.Add(defaultRoom);
						Debug.Log((object)("[REPOShopLib] Restored default shop room: " + ((Object)defaultRoom).name));
					}
					return;
				}
			}
			foreach (GameObject item in value)
			{
				NetworkPrefabs.RegisterNetworkPrefab("Level/Shop/Modules/" + ((Object)item).name, item);
				instance.levelShop.ModulesDeadEnd1.Add(item);
				Debug.Log((object)("[REPOShopLib] Injected shop room prefab: " + ((Object)item).name));
			}
		}

		public static void RegisterShopRoom(string shopName, GameObject prefab)
		{
			if (!((Object)(object)prefab == (Object)null) && !string.IsNullOrEmpty(shopName))
			{
				if (!_shopRooms.TryGetValue(shopName, out List<GameObject> value))
				{
					value = new List<GameObject>();
					_shopRooms[shopName] = value;
				}
				if (!value.Contains(prefab))
				{
					value.Add(prefab);
					Debug.Log((object)("[REPOShopLib] Registered shop room prefab: " + ((Object)prefab).name + " for shop '" + shopName + "'"));
				}
			}
		}

		public static void RemoveShopRooms()
		{
			_removeShopRooms = true;
		}

		public static void ClearRegisteredShopRooms()
		{
			_shopRooms.Clear();
			Debug.Log((object)"[REPOShopLib] Cleared all registered shop room prefabs.");
		}
	}
	public static class BundleUtils
	{
		public static AssetBundle? LoadEmbeddedBundle(Assembly assembly, string resourceName)
		{
			using Stream stream = assembly.GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				Debug.LogError((object)("[REPOShopLib] Failed to find embedded resource: " + resourceName));
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return AssetBundle.LoadFromMemory(memoryStream.ToArray());
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "Start")]
	public class LevelGeneratorShopPatch
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			if (ShopUtils._removeShopRooms)
			{
				RunManager instance = RunManager.instance;
				if ((Object)(object)instance == (Object)null || (Object)(object)instance.levelCurrent != (Object)(object)instance.levelShop)
				{
					return;
				}
				instance.levelShop.ModulesDeadEnd1.Clear();
				Debug.Log((object)"[REPOShopLib] Cleared all shop rooms from ModulesDeadEnd1.");
				ShopUtils._removeShopRooms = false;
			}
			ShopUtils.InjectActiveShop();
			ShopUtils.InjectRegisteredShopRoom();
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "Start")]
	public class ShopMusicPlacement
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			RunManager instance = RunManager.instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.levelCurrent != (Object)(object)instance.levelShop))
			{
				((MonoBehaviour)REPOShopLib.Instance).StartCoroutine(DelayedMusicFix());
			}
		}

		private static IEnumerator DelayedMusicFix()
		{
			yield return (object)new WaitForSeconds(0.25f);
			GameObject[] allGameObjects = Resources.FindObjectsOfTypeAll<GameObject>();
			GameObject[] array = allGameObjects;
			foreach (GameObject obj in array)
			{
				if (((Object)obj).name.Contains("Shop Music"))
				{
					AudioSource audio = obj.GetComponent<AudioSource>();
					if ((Object)(object)audio != (Object)null)
					{
						audio.outputAudioMixerGroup = AudioManager.instance.MusicMasterGroup;
						Debug.Log((object)("[REPOShopLib] Assigned mixer to: " + ((Object)obj).name));
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "Awake")]
	public class DefaultShopRegistration
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			RunManager instance = RunManager.instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.levelShop == (Object)null))
			{
				GameObject val = ((IEnumerable<GameObject>)instance.levelShop.ModulesNormal1).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == "Module - Shop - N - Generic"));
				if ((Object)(object)val != (Object)null)
				{
					ShopUtils.RegisterNamedShop("Vanilla", val);
					Debug.Log((object)"[REPOShopLib] Registered Vanilla shop: Module - Shop - N - Generic");
				}
				if (ShopUtils.DefaultRoomCount == 0 && instance.levelShop.ModulesDeadEnd1.Count > 0)
				{
					ShopUtils.CacheDefaultRooms(instance.levelShop.ModulesDeadEnd1);
				}
			}
		}
	}
}