Decompiled source of StarterKit v0.1.0

StarterKit.dll

Decompiled 5 months ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.Scripting;
using StarterKit.Configs;
using StarterKit.Database;
using StarterKit.Utils;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("StarterKit")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Give new Vampiries start equipment.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+88a19ef3c3dcdf2bf647b7f8306760ebcb940a96")]
[assembly: AssemblyProduct("StarterKit")]
[assembly: AssemblyTitle("StarterKit")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace StarterKit
{
	[BepInPlugin("StarterKit", "StarterKit", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static ManualLogSource Logger;

		internal static Plugin Instance;

		public override void Load()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			Instance = this;
			Logger = ((BasePlugin)this).Log;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("StarterKit");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			_harmony = new Harmony("StarterKit");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			MainConfig.ConfigInit();
			DB.LoadData();
			CommandRegistry.RegisterAll();
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "StarterKit";

		public const string PLUGIN_NAME = "StarterKit";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace StarterKit.Utils
{
	internal class Helper
	{
		private static World? _serverWorld;

		public static ServerGameManager serverGameManager = Server.GetExistingSystemManaged<ServerScriptMapper>()._ServerGameManager;

		public static EntityManager EntityManager => Server.EntityManager;

		public static GameDataSystem gameData => Server.GetExistingSystemManaged<GameDataSystem>();

		public static PrefabCollectionSystem PrefabCollection => Server.GetExistingSystemManaged<PrefabCollectionSystem>();

		public static Dictionary<string, PrefabGUID> NameToGuid => PrefabCollection.NameToPrefabGuidDictionary;

		public static World Server
		{
			get
			{
				if (_serverWorld != null)
				{
					return _serverWorld;
				}
				_serverWorld = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");
				return _serverWorld;
			}
		}

		public static bool IsServer => Application.productName == "VRisingServer";

		public static void GiveStartKit(ChatCommandContext ctx, List<RecordKit> kit)
		{
			//IL_001a: 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_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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			foreach (RecordKit item in kit)
			{
				Entity val = AddItemToInventory(ctx.Event.SenderCharacterEntity, NameToGuid[item.Name], item.Amount);
				int itemSlot = InventoryUtilities.GetItemSlot(EntityManager, ctx.Event.SenderCharacterEntity, NameToGuid[item.Name], val);
				EquipEquipment(ctx.Event.SenderCharacterEntity, itemSlot);
			}
		}

		public static Entity AddItemToInventory(Entity recipient, PrefabGUID guid, int amount)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				AddItemResponse val = ((ServerGameManager)(ref serverGameManager)).TryAddInventoryItem(recipient, guid, amount);
				return val.NewEntity;
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogFatal((object)ex);
			}
			return default(Entity);
		}

		public static void EquipEquipment(Entity player, int slot)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0031: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Server.EntityManager;
			Entity val = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[2]
			{
				ComponentType.ReadWrite<FromCharacter>(),
				ComponentType.ReadWrite<EquipItemEvent>()
			});
			entityManager = Server.EntityManager;
			PlayerCharacter componentData = ((EntityManager)(ref entityManager)).GetComponentData<PlayerCharacter>(player);
			Entity userEntity = componentData.UserEntity;
			entityManager = Server.EntityManager;
			((EntityManager)(ref entityManager)).SetComponentData<FromCharacter>(val, new FromCharacter
			{
				User = userEntity,
				Character = player
			});
			entityManager = Server.EntityManager;
			((EntityManager)(ref entityManager)).SetComponentData<EquipItemEvent>(val, new EquipItemEvent
			{
				SlotIndex = slot
			});
		}

		private static World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name)
				{
					return current;
				}
			}
			return null;
		}
	}
}
namespace StarterKit.Hooks
{
	[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserConnected")]
	public static class OnUserConnected_Patch
	{
		public static void Postfix(ServerBootstrapSystem __instance, NetConnectionId netConnectionId)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0029: 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_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)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
				int num = __instance._NetEndPointToApprovedUserIndex[netConnectionId];
				ServerClient val = ((Il2CppArrayBase<ServerClient>)(object)__instance._ApprovedUsersLookup)[num];
				Entity userEntity = val.UserEntity;
				EntityManager entityManager2 = ((ComponentSystemBase)__instance).EntityManager;
				User componentData = ((EntityManager)(ref entityManager2)).GetComponentData<User>(userEntity);
				if (!DB.UsedKits.ContainsKey(componentData.PlatformId))
				{
					DB.UsedKits.TryAdd(componentData.PlatformId, value: false);
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(TriggerPersistenceSaveSystem), "TriggerSave")]
	public class TriggerPersistenceSaveSystem_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(SaveReason reason, FixedString128Bytes saveName, ServerRuntimeSettings saveConfig)
		{
			DB.SaveData();
		}
	}
}
namespace StarterKit.Database
{
	internal struct RecordKit
	{
		public string Name { get; set; }

		public int Amount { get; set; }

		public RecordKit(string name, int amount)
		{
			Name = name;
			Amount = amount;
		}
	}
	internal class DB
	{
		private static readonly string FileDirectory = Path.Combine("BepInEx", "config", "StarterKit");

		private static readonly string FileStartKits = "StartKits.json";

		private static readonly string FileUsedKits = "UsedKits.json";

		private static readonly string PathStarterKits = Path.Combine(FileDirectory, FileStartKits);

		private static readonly string PathUsedKits = Path.Combine(FileDirectory, FileUsedKits);

		public static ConcurrentDictionary<string, List<RecordKit>> StartKits = new ConcurrentDictionary<string, List<RecordKit>>();

		public static ConcurrentDictionary<ulong, bool> UsedKits = new ConcurrentDictionary<ulong, bool>();

		public static bool EnabledKitCommand = true;

		public static string MessageAlreadyUsedKit = "";

		public static string MessageOnGivenKit = "";

		internal static void SaveData()
		{
			File.WriteAllText(PathStarterKits, JsonSerializer.Serialize(StartKits, new JsonSerializerOptions
			{
				WriteIndented = true
			}));
			File.WriteAllText(PathUsedKits, JsonSerializer.Serialize(UsedKits, new JsonSerializerOptions
			{
				WriteIndented = true
			}));
			Plugin.Logger.LogWarning((object)"StartKit, UsedKits DB Saved.");
		}

		internal static void LoadData()
		{
			if (!Directory.Exists(FileDirectory))
			{
				Directory.CreateDirectory(FileDirectory);
			}
			LoadStarterKit();
			LoadUsedKits();
			SaveData();
		}

		internal static void LoadUsedKits()
		{
			if (!File.Exists(PathUsedKits))
			{
				UsedKits.Clear();
				Plugin.Logger.LogWarning((object)"UsedKits DB Created.");
			}
			else
			{
				string json = File.ReadAllText(PathUsedKits);
				UsedKits = JsonSerializer.Deserialize<ConcurrentDictionary<ulong, bool>>(json);
				Plugin.Logger.LogWarning((object)"UsedKits DB Populated");
			}
		}

		internal static void LoadStarterKit()
		{
			if (!File.Exists(PathStarterKits))
			{
				StartKits.Clear();
				StartKits.TryAdd("startkit", new List<RecordKit>
				{
					new RecordKit("Item_Boots_T09_Dracula_Brute", 1),
					new RecordKit("Item_Chest_T09_Dracula_Brute", 1),
					new RecordKit("Item_Gloves_T09_Dracula_Brute", 1),
					new RecordKit("Item_Legs_T09_Dracula_Brute", 1)
				});
				Plugin.Logger.LogWarning((object)"StartKit DB Created.");
			}
			else
			{
				string json = File.ReadAllText(PathStarterKits);
				StartKits = JsonSerializer.Deserialize<ConcurrentDictionary<string, List<RecordKit>>>(json);
				Plugin.Logger.LogWarning((object)"StartKit DB Populated");
			}
		}
	}
}
namespace StarterKit.Configs
{
	internal class MainConfig
	{
		private static readonly string FileDirectory = Path.Combine("BepInEx", "config");

		private static readonly string FileName = "StarterKit.cfg";

		private static readonly string fullPath = Path.Combine(FileDirectory, FileName);

		private static readonly ConfigFile Conf = new ConfigFile(fullPath, true);

		public static ConfigEntry<string> MessageOnGivenKit;

		public static ConfigEntry<string> MessageAlreadyUsedKit;

		public static ConfigEntry<bool> EnabledKitCommand;

		public static void ConfigInit()
		{
			EnabledKitCommand = Conf.Bind<bool>("StarterKit", "EnableKitCommand", true, "Enable kit command..");
			MessageOnGivenKit = Conf.Bind<string>("StarterKit", "MessageOnGivenKit", "Enjoy your <color=#ffffffff>free gear pack</color> and let the battle begin!", "Message when kit given player.");
			MessageAlreadyUsedKit = Conf.Bind<string>("StarterKit", "MessageAlreadyUsedKit", "You have already used the starter kit.", "Message when the player has already used a kit and will try to use it again.");
			ConfigBind();
		}

		public static void ConfigBind()
		{
			DB.EnabledKitCommand = EnabledKitCommand.Value;
			DB.MessageAlreadyUsedKit = MessageAlreadyUsedKit.Value;
			DB.MessageOnGivenKit = MessageOnGivenKit.Value;
		}
	}
}
namespace StarterKit.Commands
{
	internal class KitCommands
	{
		[Command("kit", null, null, "Give new vampire start kit.", null, false)]
		public static void KitCommand(ChatCommandContext ctx, string KitName = "StartKit")
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (DB.EnabledKitCommand)
			{
				ulong platformId = ctx.User.PlatformId;
				if (DB.StartKits.TryGetValue(KitName.ToLower(), out var value))
				{
					if (DB.UsedKits.TryGetValue(platformId, out var value2))
					{
						if (!value2)
						{
							Helper.GiveStartKit(ctx, value);
							DB.UsedKits[platformId] = true;
							ctx.Reply("Enjoy your <color=#ffffffff>free gear pack</color> and let the battle begin!");
						}
						else
						{
							ctx.Reply("You have already used the starter kit.");
						}
					}
				}
				else
				{
					ctx.Reply("Kit with name [" + KitName + "] not found.");
				}
			}
			else
			{
				ctx.Reply("Command disabled by admins.");
			}
		}
	}
}