Decompiled source of TestModPleaseIgnore v1.0.0

TMPI.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
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 Bloodstone.API;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using ProjectM;
using TMPI.Augments;
using TMPI.Core;
using Unity.Collections;
using Unity.Entities;
using VRising.GameData;
using VRising.GameData.Methods;
using VRising.GameData.Models;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TMPI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5af46a5de12e23c1bcbc95f673fb15f9ceb81a2b")]
[assembly: AssemblyProduct("TMPI")]
[assembly: AssemblyTitle("TMPI")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TMPI
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "TMPI";

		public const string PLUGIN_NAME = "TMPI";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace TMPI.Hooks
{
	[HarmonyPatch]
	internal class VBloodConsumed
	{
		[HarmonyPatch(typeof(VBloodSystem), "OnUpdate")]
		[HarmonyPrefix]
		public static void OnUpdate(VBloodSystem __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.EventList.IsEmpty)
			{
				return;
			}
			EntityManager entityManager = VWorld.Server.EntityManager;
			Enumerator<VBloodConsumed> enumerator = __instance.EventList.GetEnumerator();
			PlayerCharacter val = default(PlayerCharacter);
			PrefabGUID val4 = default(PrefabGUID);
			Entity val5 = default(Entity);
			bool flag = default(bool);
			while (enumerator.MoveNext())
			{
				VBloodConsumed current = enumerator.Current;
				if (!((EntityManager)(ref entityManager)).TryGetComponentData<PlayerCharacter>(current.Target, ref val))
				{
					continue;
				}
				Entity val2 = __instance._PrefabCollectionSystem._PrefabGuidToEntityMap[current.Source];
				Entity userEntity = val.UserEntity;
				ConvertedAssetData val3 = __instance._PrefabCollectionSystem._PrefabDataLookup[current.Source];
				string text = ((object)(FixedString128)(ref val3.AssetName)).ToString();
				string text2 = ((object)(FixedString64)(ref val.Name)).ToString();
				UserModel userByCharacterName = GameData.Users.GetUserByCharacterName(text2);
				Entity character = userByCharacterName.FromCharacter.Character;
				try
				{
					if (text == "CHAR_ChurchOfLight_Paladin_VBlood")
					{
						((PrefabGUID)(ref val4))..ctor(2019195024);
						if (InventoryUtilities.TryGetInventoryEntity(entityManager, character, ref val5, 0))
						{
							InventoryUtilitiesServer.TryRemoveItem(entityManager, val5, val4, 1);
						}
						AddItemToInventory(val4, 1, userByCharacterName);
					}
				}
				catch (Exception ex)
				{
					ManualLogSource logger = Plugin.Logger;
					BepInExErrorLogInterpolatedStringHandler val6 = new BepInExErrorLogInterpolatedStringHandler(7, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Error: ");
						((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<Exception>(ex);
					}
					logger.LogError(val6);
				}
			}
		}

		public static void AddItemToInventory(PrefabGUID guid, int amount, UserModel user)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Entity val = default(Entity);
			UserModelMethods.TryGiveItem(user, guid, 1, ref val);
		}
	}
}
namespace TMPI.Core
{
	[BepInPlugin("TMPI", "TMPI", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin, IRunOnInitialized
	{
		private Harmony _harmony;

		public static ManualLogSource Logger;

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

		public static bool shardDrop;

		public static bool setBonus;

		internal static Plugin Instance { get; private set; }

		public override void Load()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			Instance = this;
			Logger = ((BasePlugin)this).Log;
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			ServerEvents.OnGameDataInitialized += GameDataOnInitialize;
			GameData.OnInitialize += new OnGameDataInitializedEventHandler(GameDataOnInitialize);
			InitConfig();
		}

		private void GameDataOnInitialize(World world)
		{
			ArmorModifierSystem.ModifyArmorPrefabEquipmentSet();
		}

		private void InitConfig()
		{
			shardDrop = ((BasePlugin)this).Config.Bind<bool>("Config", "ShardDrop", false, "Enables shard drop from Solarus.").Value;
			setBonus = ((BasePlugin)this).Config.Bind<bool>("Config", "SetBonus", false, "Enables Bloodmoon set bonus for Death gear.").Value;
			if (!Directory.Exists(ConfigPath))
			{
				Directory.CreateDirectory(ConfigPath);
			}
		}

		public override bool Unload()
		{
			((BasePlugin)this).Config.Clear();
			_harmony.UnpatchSelf();
			return true;
		}

		public void OnGameInitialized()
		{
		}
	}
	public delegate void OnGameDataInitializedEventHandler(World world);
	internal class ServerEvents
	{
		internal static event OnGameDataInitializedEventHandler OnGameDataInitialized;

		[HarmonyPatch(typeof(LoadPersistenceSystemV2), "SetLoadState")]
		[HarmonyPostfix]
		private static void ServerStartupStateChange_Postfix(State loadState, LoadPersistenceSystemV2 __instance)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			try
			{
				if ((int)loadState == 4)
				{
					ServerEvents.OnGameDataInitialized?.Invoke(((ComponentSystemBase)__instance).World);
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)ex);
			}
		}
	}
	public static class Utilities
	{
		public static Type Il2CppTypeGet(Type type)
		{
			return Type.GetType(type.ToString());
		}

		public static ComponentType ComponentTypeGet(string component)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return ComponentType.ReadOnly(Type.GetType(component));
		}

		public static bool HasComponent<T>(Entity entity) where T : struct
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, ComponentTypeOther<T>());
		}

		public static bool AddComponent<T>(Entity entity) where T : struct
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			return ((EntityManager)(ref entityManager)).AddComponent(entity, ComponentTypeOther<T>());
		}

		public static void AddComponentData<T>(Entity entity, T componentData) where T : struct
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			AddComponent<T>(entity);
			SetComponentData(entity, componentData);
		}

		public static bool RemoveComponent<T>(Entity entity) where T : struct
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			return ((EntityManager)(ref entityManager)).RemoveComponent(entity, ComponentTypeOther<T>());
		}

		public unsafe static T GetComponentData<T>(Entity entity) where T : struct
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			void* componentDataRawRO = ((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, ComponentTypeIndex<T>());
			return Marshal.PtrToStructure<T>(new IntPtr(componentDataRawRO));
		}

		public unsafe static void SetComponentData<T>(Entity entity, T componentData) where T : struct
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			int num = Marshal.SizeOf(componentData);
			fixed (byte* ptr = StructureToByteArray(componentData))
			{
				EntityManager entityManager = VWorld.Server.EntityManager;
				((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, ComponentTypeIndex<T>(), (void*)ptr, num);
			}
		}

		private static ComponentType ComponentTypeOther<T>()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return new ComponentType(Il2CppType.Of<T>(), (AccessMode)0);
		}

		private static int ComponentTypeIndex<T>()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ComponentTypeOther<T>().TypeIndex;
		}

		private static byte[] StructureToByteArray<T>(T structure) where T : struct
		{
			int num = Marshal.SizeOf(structure);
			byte[] array = new byte[num];
			IntPtr intPtr = Marshal.AllocHGlobal(num);
			try
			{
				Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
				Marshal.Copy(intPtr, array, 0, num);
				return array;
			}
			finally
			{
				Marshal.FreeHGlobal(intPtr);
			}
		}
	}
}
namespace TMPI.Augments
{
	public static class ArmorModifierSystem
	{
		public static void ModifyArmorPrefabEquipmentSet()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			List<PrefabGUID> list = new List<PrefabGUID>
			{
				new PrefabGUID(1055898174),
				new PrefabGUID(1400688919),
				new PrefabGUID(125611165),
				new PrefabGUID(-204401621)
			};
			PrefabGUID equipmentSet = default(PrefabGUID);
			((PrefabGUID)(ref equipmentSet))..ctor(35317589);
			bool flag = default(bool);
			foreach (PrefabGUID item in list)
			{
				Entity prefabEntityByPrefabGUID = GetPrefabEntityByPrefabGUID(item, entityManager);
				if (prefabEntityByPrefabGUID != Entity.Null)
				{
					EquippableData componentData = Utilities.GetComponentData<EquippableData>(prefabEntityByPrefabGUID);
					componentData.EquipmentSet = equipmentSet;
					Utilities.SetComponentData<EquippableData>(prefabEntityByPrefabGUID, componentData);
					continue;
				}
				ManualLogSource logger = Plugin.Logger;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(39, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not find prefab entity for GUID: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<PrefabGUID>(item);
				}
				logger.LogInfo(val);
			}
		}

		public static Entity GetPrefabEntityByPrefabGUID(PrefabGUID prefabGUID, EntityManager entityManager)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PrefabCollectionSystem existingSystem = ((EntityManager)(ref entityManager)).World.GetExistingSystem<PrefabCollectionSystem>();
				return existingSystem._PrefabGuidToEntityMap[prefabGUID];
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(7, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
				return Entity.Null;
			}
		}
	}
}