Decompiled source of ContentLib v0.1.0

ContentLib.dll

Decompiled a month ago
using System;
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 DefaultNamespace;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Ashley.MeshSplitter")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("com.rlabrecque.steamworks.net")]
[assembly: IgnoresAccessChecksTo("Discord")]
[assembly: IgnoresAccessChecksTo("HBAO.Demo.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("HBAO.Runtime")]
[assembly: IgnoresAccessChecksTo("HBAO.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("MeshSplit")]
[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("pworld")]
[assembly: IgnoresAccessChecksTo("sc.posteffects.runtime")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Modules.Unity.Addressables")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Modules.UnityLocalization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Tayx.Graphy")]
[assembly: IgnoresAccessChecksTo("Unity.Addressables")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InternalAPIEngineBridge.013")]
[assembly: IgnoresAccessChecksTo("Unity.Localization")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.PlayableGraphVisualizer")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipeline.Universal.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Shaders")]
[assembly: IgnoresAccessChecksTo("Unity.ResourceManager")]
[assembly: IgnoresAccessChecksTo("Unity.ScriptableBuildPipeline")]
[assembly: IgnoresAccessChecksTo("Unity.Splines")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("Zorro.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Zorro.PhotonUtility")]
[assembly: IgnoresAccessChecksTo("Zorro.Recorder")]
[assembly: IgnoresAccessChecksTo("Zorro.Settings.Runtime")]
[assembly: IgnoresAccessChecksTo("Zorro.UI.Runtime")]
[assembly: AssemblyCompany("Novinity")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A Content Warning API that allows for easy addition of custom monsters, items, maps, and more.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+0976b9633455fd263508fb96bcc4fb1108f2944e")]
[assembly: AssemblyProduct("ContentLib")]
[assembly: AssemblyTitle("ContentLib")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Novinity/ContentLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 ContentLib
{
	[BepInPlugin("ContentLib", "ContentLib", "0.1.0")]
	[ContentWarningPlugin("ContentLib", "0.1.0", false)]
	public class Plugin : BaseUnityPlugin
	{
		public bool shopInitialized = false;

		public static Plugin 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;
			Patch();
			Logger.LogInfo((object)"ContentLib v0.1.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("ContentLib");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ContentLib";

		public const string PLUGIN_NAME = "ContentLib";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace ContentLib.Modules
{
	public class BundleHelper
	{
		public static AssetBundle LoadAssetBundle(string filename)
		{
			Plugin.Logger.LogDebug((object)("Loading Asset Bundle " + filename));
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, filename));
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)("Failed to load asset bundle " + filename + " [" + directoryName + "]"));
				return null;
			}
			return val;
		}

		public static AssetBundle LoadAssetBundleFromDirectPath(string path)
		{
			Plugin.Logger.LogDebug((object)("Loading Asset Bundle from path " + path));
			AssetBundle val = AssetBundle.LoadFromFile(path);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)("Failed to load asset bundle " + path));
				return null;
			}
			return val;
		}
	}
	public class ContentHandler
	{
		public static List<ContentEvent> EventList = new List<ContentEvent>();

		public static void RegisterEvent(ContentEvent contentEvent)
		{
			Plugin.Logger.LogInfo((object)("[ContentLib] Registering content event for " + contentEvent.GetName()));
			EventList.Add(contentEvent);
		}

		public static ushort GetEventID(string contentEventName)
		{
			string contentEventName2 = contentEventName;
			Plugin.Logger.LogDebug((object)EventList.Count);
			int num = EventList.FindIndex((ContentEvent match) => ((object)match).GetType().Name == contentEventName2);
			if (num == -1)
			{
				for (int i = 0; i < EventList.Count; i++)
				{
					Plugin.Logger.LogDebug((object)$"[ContentLib_Debug] {((object)EventList[i]).GetType().Name}, {contentEventName2}, {((object)EventList[i]).GetType().Name == contentEventName2}");
				}
				Plugin.Logger.LogError((object)("[ContentLib] GetEventID for " + contentEventName2 + " returned -1"));
			}
			return (ushort)(2000 + num);
		}
	}
	[HarmonyPatch(typeof(ContentEventIDMapper))]
	internal class ContentEventIDMapperPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("GetContentEvent")]
		public static bool GetContentEventPrefix(ref ushort id, ref ContentEvent __result)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			Plugin.Logger.LogDebug((object)$"[ContentLib_Debug] GetContentEvent was called: {id} Normalized: {id - 2000} EventList count: {ContentHandler.EventList.Count}");
			if (id - 2000 < 0)
			{
				return true;
			}
			ContentEvent val = ContentHandler.EventList[id - 2000];
			if (val == null)
			{
				return true;
			}
			__result = (ContentEvent)Activator.CreateInstance(((object)val).GetType());
			return false;
		}
	}
	[HarmonyPatch]
	public class ContentLoader
	{
		public static void AddObjectToPool(GameObject go)
		{
			IPunPrefabPool prefabPool = PhotonNetwork.PrefabPool;
			((DefaultPool)(((prefabPool is DefaultPool) ? prefabPool : null)?)).ResourceCache.Add(((Object)go).name, go);
		}

		private static void AddMonstersToRoundSpawner(RoundSpawner spawner)
		{
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			Plugin.Logger.LogDebug((object)"[ContentLib] Adding monsters to round spawner");
			List<IBudgetCost> list = new List<IBudgetCost>();
			int num = 0;
			foreach (Monsters.CustomMonster registeredMonster in Monsters.registeredMonsters)
			{
				float weight = registeredMonster.weight;
				if (Random.value <= weight)
				{
					IBudgetCost val = LoadMonster(registeredMonster);
					list.Add(val);
					num += val.Cost;
				}
			}
			spawner.testBudget += num;
			spawner.possibleSpawns = spawner.possibleSpawns.Concat(list.Select((IBudgetCost m) => m.gameObject)).ToArray();
		}

		private static IBudgetCost LoadMonster(Monsters.CustomMonster customMonster)
		{
			return customMonster.objectPrefab.GetComponent<IBudgetCost>();
		}

		[HarmonyPatch(typeof(RoundSpawner))]
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Postfix_RoundSpawner_Start(RoundSpawner __instance)
		{
			Plugin.Logger.LogDebug((object)"[ContentLib] RoundSpawner postfix called");
			AddMonstersToRoundSpawner(__instance);
		}
	}
	public class Monsters
	{
		public class CustomMonster
		{
			public GameObject objectPrefab;

			public float weight = 1f;

			public string name = "";

			public string modName = "Unknown";

			public CustomMonster(GameObject objectPrefab, float weight)
			{
				this.weight = weight;
				this.objectPrefab = objectPrefab;
				name = ((Object)objectPrefab).name;
			}
		}

		public static List<CustomMonster> registeredMonsters = new List<CustomMonster>();

		public static CustomMonster RegisterMonster(CustomMonster monster)
		{
			CustomMonster monster2 = monster;
			CustomMonster customMonster = registeredMonsters.FirstOrDefault((CustomMonster x) => x == monster2);
			if (customMonster != null)
			{
				Plugin.Logger.LogWarning((object)("[ContentLib] Attempted to register monster that is already registered! - Monster Name: " + customMonster.name));
				return null;
			}
			Plugin.Logger.LogInfo((object)("[ContentLib] Registering monster with name " + monster2.name));
			if (monster2.modName == "Unknown")
			{
				Assembly callingAssembly = Assembly.GetCallingAssembly();
				string name = callingAssembly.GetName().Name;
				monster2.modName = name;
			}
			FixMaterials(monster2.objectPrefab);
			ContentLoader.AddObjectToPool(monster2.objectPrefab);
			registeredMonsters.Add(monster2);
			return monster2;
		}

		public static CustomMonster RegisterMonster(GameObject objectPrefab, float weight)
		{
			GameObject objectPrefab2 = objectPrefab;
			CustomMonster customMonster = registeredMonsters.FirstOrDefault((CustomMonster x) => (Object)(object)x.objectPrefab == (Object)(object)objectPrefab2);
			if (customMonster != null)
			{
				Plugin.Logger.LogWarning((object)("[ContentLib] Attempted to register monster prefab that is already registered! - Monster Name: " + customMonster.name + ", Prefab Name: " + ((Object)objectPrefab2).name));
				return null;
			}
			CustomMonster monster = new CustomMonster(objectPrefab2, weight);
			return RegisterMonster(monster);
		}

		public static CustomMonster[] RegisterAllInBundle(AssetBundle assetBundle, int weight = 1)
		{
			IEnumerable<GameObject> enumerable = from v in assetBundle.LoadAllAssets<GameObject>()
				where v.GetComponent<IBudgetCost>() != null
				select v;
			List<CustomMonster> list = new List<CustomMonster>();
			foreach (GameObject item in enumerable)
			{
				list.Add(RegisterMonster(item, weight));
			}
			return list.ToArray();
		}

		public static void UseMonsterMaterial(GameObject gameObject)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Material material = new Material(((Renderer)Resources.Load<GameObject>("Zombe").GetComponentInChildren<SkinnedMeshRenderer>()).material);
			Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>();
			foreach (Renderer val in componentsInChildren)
			{
				val.material = material;
			}
		}

		private static void FixMaterials(GameObject gameObject)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>();
			foreach (Renderer val in componentsInChildren)
			{
				for (int j = 0; j < val.materials.Length; j++)
				{
					Material val2 = new Material(Shader.Find(((Object)val.materials[j].shader).name));
					val2.CopyMatchingPropertiesFromMaterial(val.materials[j]);
					val.materials[j] = val2;
				}
			}
		}

		public static void SetCustomMaterial(Renderer renderer, Material material)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Material val = new Material(Shader.Find(((Object)material.shader).name));
			val.CopyMatchingPropertiesFromMaterial(material);
			renderer.material = val;
		}

		public static void SetCustomMaterial(Renderer renderer, Material material, int index)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Material val = new Material(Shader.Find(((Object)material.shader).name));
			val.CopyMatchingPropertiesFromMaterial(material);
			renderer.materials[index] = val;
		}

		public static void SetCustomMaterial(Renderer[] renderers, Material material)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Material val = new Material(Shader.Find(((Object)material.shader).name));
			val.CopyMatchingPropertiesFromMaterial(material);
			foreach (Renderer val2 in renderers)
			{
				val2.material = val;
			}
		}

		public static void SetCustomMaterial(GameObject monsterPrefab, Material material)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Material val = new Material(Shader.Find(((Object)material.shader).name));
			val.CopyMatchingPropertiesFromMaterial(material);
			Renderer[] componentsInChildren = monsterPrefab.GetComponentsInChildren<Renderer>();
			foreach (Renderer val2 in componentsInChildren)
			{
				val2.material = val;
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}