Decompiled source of KinThrone v1.1.0

KinThrone.dll

Decompiled 2 weeks 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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProjectM;
using Stunlock.Core;
using Unity.Entities;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("KinThrone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("KinThrone")]
[assembly: AssemblyTitle("KinThrone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace KinThrone
{
	internal static class Core
	{
		public static bool _initialized;

		public static World Server { get; } = GetServerWorld() ?? throw new Exception("Couldn't find Server world!");


		public static EntityManager EntityManager { get; } = Server.EntityManager;


		public static PrefabCollectionSystem PrefabCollectionSystem { get; set; }

		public static ManualLogSource Log => Plugin.LogInstance;

		public static void Initialize()
		{
			if (!_initialized)
			{
				PrefabCollectionSystem = Server.GetExistingSystemManaged<PrefabCollectionSystem>();
				AddAncientRelicBuffs();
				_initialized = true;
			}
		}

		private static World GetServerWorld()
		{
			return ((IEnumerable<World>)World.s_AllWorlds.ToArray()).FirstOrDefault((Func<World, bool>)((World world) => world.Name == "Server"));
		}

		private static void AddAncientRelicBuffs()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			PrefabGUID val = default(PrefabGUID);
			((PrefabGUID)(ref val))..ctor(559608494);
			Entity val2 = default(Entity);
			if (PrefabCollectionSystem._PrefabGuidToEntityMap.TryGetValue(val, ref val2))
			{
				EntityManager entityManager = EntityManager;
				DynamicBuffer<ApplyBuffOnGameplayEvent> buffer = ((EntityManager)(ref entityManager)).GetBuffer<ApplyBuffOnGameplayEvent>(val2, false);
				ApplyBuffOnGameplayEvent val3 = buffer[1];
				val3.Buff1 = new PrefabGUID(-1703886455);
				val3.Buff2 = new PrefabGUID(-1161197991);
				val3.Buff3 = new PrefabGUID(-238197495);
				buffer[1] = val3;
			}
		}
	}
	[HarmonyPatch]
	internal static class InitializationPatch
	{
		[HarmonyPatch(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate")]
		[HarmonyPostfix]
		private static void OnUpdatePostfix()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				Core.Initialize();
				if (Core._initialized)
				{
					ManualLogSource log = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(15, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("KinThrone");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.0");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] initialized!");
					}
					log.LogInfo(val);
					Plugin.Harmony.Unpatch((MethodBase)typeof(SpawnTeamSystem_OnPersistenceLoad).GetMethod("OnUpdate"), typeof(InitializationPatch).GetMethod("OnUpdatePostfix"));
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Core.Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(47, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("KinThrone");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.1.0");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("] failed to initialize, exiting on try-catch: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}
	}
	[BepInPlugin("kindred.KinThrone", "KinThrone", "1.1.0")]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static readonly string ConfigPath = Path.Combine(Paths.ConfigPath, "KinThrone");

		internal static Plugin Instance { get; set; }

		public static Harmony Harmony => Instance._harmony;

		public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;

		public override void Load()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Instance = this;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val;
			if (Application.productName != "VRisingServer")
			{
				ManualLogSource logInstance = LogInstance;
				val = new BepInExInfoLogInterpolatedStringHandler(43, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("KinThrone");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is a server mod and won't load on clients!");
				}
				logInstance.LogInfo(val);
				return;
			}
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			ManualLogSource log = Core.Log;
			val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("KinThrone");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] loaded!");
			}
			log.LogInfo(val);
		}

		public override bool Unload()
		{
			((BasePlugin)this).Config.Clear();
			_harmony.UnpatchSelf();
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "kindred.KinThrone";

		public const string PLUGIN_NAME = "KinThrone";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}