Decompiled source of BestBuffedMap v2.0.0

BestBuffedMap.dll

Decompiled a day ago
using System;
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 BestBuffedMap;
using HarmonyLib;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Scripting;
using Stunlock.Core;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using VRisingPlots;
using VRisingPlots.Models;
using VRisingPlots.Services;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Irozer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Only the best of the best")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+db76233898d6b3842914f6fed3a52a2471b8285a")]
[assembly: AssemblyProduct("BestBuffedMap")]
[assembly: AssemblyTitle("BestBuffedMap")]
[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 BestBuffedMap
{
	[BepInPlugin("com.tonpseudo.BestBuffedMap", "BestBuffedMap", "1.0.0")]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static ManualLogSource Logger;

		public static Plugin Instance { get; private set; }

		public override void Load()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			Instance = this;
			Logger = ((BasePlugin)this).Log;
			string path = Path.Combine(Paths.ConfigPath, "BestBuffedMap");
			if (!Directory.Exists(path))
			{
				Directory.CreateDirectory(path);
			}
			PlotsSettings.Init(Paths.ConfigPath);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(46, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("aa.BestBuffedMap");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" est en cours de chargement...");
			}
			log.LogInfo(val);
			CommandRegistry.RegisterAll();
			_harmony = new Harmony("com.tonpseudo.BestBuffedMap");
			_harmony.PatchAll();
			((BasePlugin)this).Log.LogInfo((object)"BestBuffedMap est chargé et prêt !");
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return ((BasePlugin)this).Unload();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "aa.BestBuffedMap";

		public const string PLUGIN_NAME = "BestBuffedMap";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace VRisingPlots
{
	public static class Core
	{
		public static World Server { get; } = GetWorld("Server") ?? throw new Exception("Server World not found. Did you install the mod on the server?");


		public static EntityManager EntityManager => Server.EntityManager;

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

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


		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;
		}

		public static void LogException(Exception e, [CallerMemberName] string caller = null)
		{
			Debug.LogError(Object.op_Implicit($"[VRisingPlots] Exception in {caller}: {e.Message}\n{e.StackTrace}"));
		}
	}
	public static class PlotsSettings
	{
		private static ConfigFile config;

		public static ConfigEntry<bool> EnableBuffedPlots;

		public static ConfigEntry<bool> EnableCaveStairs;

		public static void Init(string configPath)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			config = new ConfigFile(Path.Combine(configPath, "BestBuffedMap/VRisingPlots.cfg"), true);
			EnableBuffedPlots = config.Bind<bool>("Plots", "EnableBuffedPlots", true, "Automatically spawn Buffed_Plots.json on server start.");
			EnableCaveStairs = config.Bind<bool>("Plots", "EnableCaveStairs", true, "Automatically spawn Cave_Stairs.json on server start.");
		}
	}
}
namespace VRisingPlots.Utils
{
	public static class VWorld
	{
		public static World Server
		{
			get
			{
				Enumerator<World> enumerator = World.All.GetEnumerator();
				while (enumerator.MoveNext())
				{
					World current = enumerator.Current;
					if (current.Name == "Server")
					{
						return current;
					}
				}
				return null;
			}
		}

		public static EntityManager ServerEntityManager => Server.EntityManager;
	}
}
namespace VRisingPlots.Services
{
	public class PrefabSpawnerService
	{
		private static PrefabSpawnerService _instance;

		private static readonly ManualLogSource Log = Logger.CreateLogSource("PrefabSpawnerService");

		private static bool _loaded = false;

		public static PrefabSpawnerService Instance => _instance ?? (_instance = new PrefabSpawnerService());

		private static string FlagFilePath => Path.Combine(Paths.ConfigPath, "BestBuffedMap/Plots", ".spawned");

		public void LoadAllPrefabs()
		{
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			if (_loaded)
			{
				return;
			}
			_loaded = true;
			string text = Path.Combine(Paths.ConfigPath, "BestBuffedMap/Plots");
			bool flag = default(bool);
			if (!Directory.Exists(text))
			{
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(47, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plots folder not found at ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", skipping auto-load.");
				}
				Log.LogWarning(val);
				return;
			}
			if (File.Exists(FlagFilePath))
			{
				Log.LogInfo((object)"Plots already spawned on a previous run, skipping.");
				return;
			}
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			if (PlotsSettings.EnableBuffedPlots.Value)
			{
				hashSet.Add("Buffed_Plots.json");
			}
			if (PlotsSettings.EnableCaveStairs.Value)
			{
				hashSet.Add("Cave_Stairs.json");
			}
			if (hashSet.Count == 0)
			{
				Log.LogInfo((object)"All plots are disabled in config, skipping auto-load.");
				return;
			}
			int num = 0;
			BepInExInfoLogInterpolatedStringHandler val2;
			foreach (string item in hashSet)
			{
				string text2 = Path.Combine(text, item);
				if (!File.Exists(text2))
				{
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(21, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" not found, skipping.");
					}
					Log.LogWarning(val);
					continue;
				}
				try
				{
					LoadPrefabFromFile(text2);
					num++;
					val2 = new BepInExInfoLogInterpolatedStringHandler(8, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded.");
					}
					Log.LogInfo(val2);
				}
				catch (Exception ex)
				{
					BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(16, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Error loading ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(item);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
					}
					Log.LogError(val3);
				}
			}
			File.WriteAllText(FlagFilePath, DateTime.UtcNow.ToString("o"));
			val2 = new BepInExInfoLogInterpolatedStringHandler(46, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Auto-loaded ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" prefab file(s) from Plots folder.");
			}
			Log.LogInfo(val2);
		}

		public void LoadPrefabFromFile(string filePath)
		{
			if (!File.Exists(filePath))
			{
				return;
			}
			try
			{
				PrefabExport prefabExport = JsonSerializer.Deserialize<PrefabExport>(File.ReadAllText(filePath), new JsonSerializerOptions
				{
					PropertyNameCaseInsensitive = true
				});
				if (prefabExport?.Entities != null)
				{
					SpawnEntities(prefabExport.Entities);
				}
			}
			catch (Exception e)
			{
				Core.LogException(e, "LoadPrefabFromFile");
			}
		}

		private void SpawnEntities(List<EntityData> entities)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0044: 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_0055: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Invalid comparison between Unknown and I4
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			PrefabGUID val = default(PrefabGUID);
			Entity val2 = default(Entity);
			float3 value = default(float3);
			foreach (EntityData entity in entities)
			{
				if (!Core.PrefabCollection.SpawnableNameToPrefabGuidDictionary.TryGetValue(entity.prefab, ref val) || !Core.PrefabCollection._PrefabGuidToEntityMap.TryGetValue(val, ref val2))
				{
					continue;
				}
				Entity val3 = ((EntityManager)(ref entityManager)).Instantiate(val2);
				((float3)(ref value))..ctor(entity.pos[0], entity.pos[1], entity.pos[2]);
				quaternion value2 = quaternion.Euler(math.radians(entity.rot[0]), math.radians(entity.rot[1]), math.radians(entity.rot[2]), (RotationOrder)4);
				((EntityManager)(ref entityManager)).SetComponentData<Translation>(val3, new Translation
				{
					Value = value
				});
				((EntityManager)(ref entityManager)).SetComponentData<Rotation>(val3, new Rotation
				{
					Value = value2
				});
				if (!((EntityManager)(ref entityManager)).HasComponent<Immortal>(val3))
				{
					((EntityManager)(ref entityManager)).AddComponent<Immortal>(val3);
				}
				((EntityManager)(ref entityManager)).SetComponentData<Immortal>(val3, new Immortal
				{
					IsImmortal = true
				});
				if (((EntityManager)(ref entityManager)).HasComponent<EntityCategory>(val3))
				{
					EntityCategory componentData = ((EntityManager)(ref entityManager)).GetComponentData<EntityCategory>(val3);
					if ((int)((EntityCategory)(ref componentData)).MaterialCategory == 3)
					{
						((EntityCategory)(ref componentData)).MaterialCategory = (MaterialCategory)2;
						((EntityManager)(ref entityManager)).SetComponentData<EntityCategory>(val3, componentData);
					}
				}
				if (((EntityManager)(ref entityManager)).HasComponent<Health>(val3))
				{
					Health componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<Health>(val3);
					componentData2.Value = ((ModifiableFloat)(ref componentData2.MaxHealth)).Value;
					componentData2.IsDead = false;
					((EntityManager)(ref entityManager)).SetComponentData<Health>(val3, componentData2);
				}
			}
		}
	}
}
namespace VRisingPlots.Patches
{
	[HarmonyPatch(typeof(ServerBootstrapSystem), "OnUserConnected")]
	public static class ServerReadyPatch
	{
		private static bool _initialized;

		[HarmonyPostfix]
		public static void Postfix()
		{
			if (!_initialized)
			{
				_initialized = true;
				Plugin.Logger.LogInfo((object)"[VRisingPlots] Server ready — loading plots...");
				PrefabSpawnerService.Instance.LoadAllPrefabs();
			}
		}
	}
}
namespace VRisingPlots.Models
{
	public class PrefabExport
	{
		public List<EntityData> Entities { get; set; }
	}
	public class EntityData
	{
		public string prefab { get; set; }

		public List<float> pos { get; set; }

		public List<float> rot { get; set; }

		public List<float> tilePos { get; set; }

		public List<float> tileBoundsMin { get; set; }

		public List<float> tileBoundsMax { get; set; }

		public bool notCastleTeam { get; set; }
	}
}
namespace VRisingPlots.Commands
{
	internal class PrefabCommands
	{
		[Command("loadprefab", "lp", null, "Load a prefab JSON file from the Plots folder", null, true)]
		public static void HandleLoadPrefab(ChatCommandContext ctx, string fileName)
		{
			string text = Path.Combine(Path.Combine(Paths.ConfigPath, "BestBuffedMap/Plots"), fileName);
			if (!text.EndsWith(".json"))
			{
				text += ".json";
			}
			if (!File.Exists(text))
			{
				ctx.Reply("<color=#ff0000>Error: File not found at " + text + "</color>");
				return;
			}
			ctx.Reply("<color=#ffff00>Loading prefab: " + fileName + "...</color>");
			PrefabSpawnerService.Instance.LoadPrefabFromFile(text);
			ctx.Reply("<color=#00ff00>Success! Entities have been spawned.</color>");
		}

		[Command("loadallprefabs", "lap", null, "Load all JSON files from the Plots folder", null, true)]
		public static void HandleLoadAllPrefabs(ChatCommandContext ctx)
		{
			string path = Path.Combine(Paths.ConfigPath, "BestBuffedMap/Plots");
			if (!Directory.Exists(path))
			{
				ctx.Reply("<color=#ff0000>Error: Plots folder does not exist.</color>");
				return;
			}
			string[] files = Directory.GetFiles(path, "*.json");
			if (files.Length == 0)
			{
				ctx.Reply("<color=#eeaa00>No JSON files found.</color>");
				return;
			}
			ctx.Reply($"<color=#ffff00>Loading {files.Length} file(s)...</color>");
			int num = 0;
			string[] array = files;
			foreach (string text in array)
			{
				try
				{
					PrefabSpawnerService.Instance.LoadPrefabFromFile(text);
					num++;
				}
				catch (Exception ex)
				{
					ctx.Reply($"<color=#ff0000>Error on {Path.GetFileName(text)}: {ex.Message}</color>");
				}
			}
			ctx.Reply($"<color=#00ff00>Done! {num} file(s) loaded.</color>");
		}

		[Command("plots-reset", "pr", null, "Remove the .spawned flag to allow re-spawning on next server start", null, true)]
		public static void HandleReset(ChatCommandContext ctx)
		{
			string path = Path.Combine(Paths.ConfigPath, "BestBuffedMap/Plots", ".spawned");
			if (!File.Exists(path))
			{
				ctx.Reply("<color=#ffff00>No .spawned flag found — plots will already load on next start.</color>");
				return;
			}
			File.Delete(path);
			ctx.Reply("<color=#00ff00>.spawned flag removed. Plots will reload on the next server start.</color>");
		}
	}
}