using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
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 BepInEx.Unity.IL2CPP.Utils.Collections;
using CrimsonClans.Services;
using CrimsonClans.Structs;
using CrimsonClans.Utilities;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Text;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Clan;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Shared;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Scenes;
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("CrimsonClans")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Extension to Clans: Hearts per Clan and more!")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+Branch.master.Sha.7ee4eb8963cf56582723b0a46beacc5101eae9cd.7ee4eb8963cf56582723b0a46beacc5101eae9cd")]
[assembly: AssemblyProduct("CrimsonClans")]
[assembly: AssemblyTitle("CrimsonClans")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 CrimsonClans
{
internal static class Core
{
private static MonoBehaviour monoBehaviour;
public const int MAX_REPLY_LENGTH = 509;
public static bool _hasInitialized = false;
public static World Server { get; } = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");
public static EntityManager EntityManager { get; } = Server.EntityManager;
public static GameDataSystem GameDataSystem { get; } = Server.GetExistingSystemManaged<GameDataSystem>();
public static PrefabCollectionSystem PrefabCollectionSystem { get; internal set; }
public static RelicDestroySystem RelicDestroySystem { get; internal set; }
public static ServerScriptMapper ServerScriptMapper { get; internal set; }
public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();
public static Database DB { get; internal set; }
public static CastleHeartService CastleHearts { get; internal set; }
public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }
public static void LogException(Exception e, [CallerMemberName] string caller = null)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 5, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failure in ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(caller);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nMessage: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.Message);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Inner:");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.Message);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n\nStack: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.StackTrace);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nInner Stack: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.StackTrace);
}
logInstance.LogError(val);
}
internal static void InitializeAfterLoaded()
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
if (!_hasInitialized)
{
PrefabCollectionSystem = Server.GetExistingSystemManaged<PrefabCollectionSystem>();
RelicDestroySystem = Server.GetExistingSystemManaged<RelicDestroySystem>();
ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
DB = new Database();
CastleHearts = new CastleHeartService();
_hasInitialized = true;
ManualLogSource logInstance = Plugin.LogInstance;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("InitializeAfterLoaded");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" completed");
}
logInstance.LogInfo(val);
}
}
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 Coroutine StartCoroutine(IEnumerator routine)
{
//IL_0012: 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_0027: Expected O, but got Unknown
if ((Object)(object)monoBehaviour == (Object)null)
{
GameObject val = new GameObject("CrimsonShards");
monoBehaviour = (MonoBehaviour)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
Object.DontDestroyOnLoad((Object)val);
}
return monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
}
public static void StopCoroutine(Coroutine coroutine)
{
if (!((Object)(object)monoBehaviour == (Object)null))
{
monoBehaviour.StopCoroutine(coroutine);
}
}
}
public static class Extensions
{
public unsafe static T Read<T>(this Entity entity) where T : struct
{
//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_0015: 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)
ComponentType val = default(ComponentType);
((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
EntityManager entityManager = Core.EntityManager;
return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex)));
}
public static bool Has<T>(this Entity entity)
{
//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_0015: 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)
ComponentType val = default(ComponentType);
((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
EntityManager entityManager = Core.EntityManager;
return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
}
public static void DestroyWithReason(this Entity entity)
{
//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_0008: 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_0014: 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_0022: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
((EntityManager)(ref entityManager)).AddComponent<Disabled>(entity);
DestroyUtility.CreateDestroyEvent(Core.EntityManager, entity, (DestroyReason)0, (DestroyDebugReason)32);
DestroyUtility.Destroy(Core.EntityManager, entity, (DestroyDebugReason)0, (string)null, 0);
}
public static void Dump(this Entity entity, string filePath)
{
//IL_0041: 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_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
File.AppendAllText(filePath, "--------------------------------------------------" + Environment.NewLine);
File.AppendAllText(filePath, "Dumping components of " + ((object)(Entity)(ref entity)).ToString() + ":" + Environment.NewLine);
EntityManager entityManager = Core.Server.EntityManager;
Enumerator<ComponentType> enumerator = ((EntityManager)(ref entityManager)).GetComponentTypes(entity, (Allocator)2).GetEnumerator();
while (enumerator.MoveNext())
{
ComponentType current = enumerator.Current;
File.AppendAllText(filePath, ((object)(ComponentType)(ref current)).ToString() + Environment.NewLine);
}
File.AppendAllText(filePath, "--------------------------------------------------" + Environment.NewLine);
File.AppendAllText(filePath, DumpEntity(entity));
}
private static string DumpEntity(Entity entity, bool fullDump = true)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
StringBuilder val = new StringBuilder();
EntityDebuggingUtility.DumpEntity(Core.Server, entity, fullDump, val);
return ((Object)val).ToString();
}
}
[BepInPlugin("CrimsonClans", "CrimsonClans", "1.1.1")]
public class Plugin : BasePlugin
{
private Harmony _harmony;
public static readonly string ConfigFiles = Path.Combine(Paths.ConfigPath, "CrimsonClans");
internal static Plugin Instance { get; private set; }
public static Settings Settings { get; private set; }
public static Harmony Haromy => Instance._harmony;
public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;
public override void Load()
{
Instance = this;
Settings = default(Settings);
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
Settings.InitConfig();
}
public override bool Unload()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
return true;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "CrimsonClans";
public const string PLUGIN_NAME = "CrimsonClans";
public const string PLUGIN_VERSION = "1.1.1";
}
}
namespace CrimsonClans.Utilities
{
public static class RaidTime
{
private static readonly List<DayOfWeek> WeekendDays = new List<DayOfWeek>(2)
{
DayOfWeek.Saturday,
DayOfWeek.Sunday
};
public static bool IsRaidTimeNow()
{
return IsRaidTime(DateTime.Now);
}
public static bool IsRaidTime(DateTime dateTime)
{
//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_0022: Expected I4, but got Unknown
CastleDamageMode castleDamageMode = Core.ServerGameSettingsSystem._Settings.CastleDamageMode;
switch ((int)castleDamageMode)
{
case 0:
return false;
case 1:
return true;
case 2:
{
PlayerInteractionSettings playerInteractionSettings = Core.ServerGameSettingsSystem._Settings.PlayerInteractionSettings;
StartEndTimeData window = (IsWeekend(dateTime) ? playerInteractionSettings.VSCastleWeekendTime : playerInteractionSettings.VSCastleWeekdayTime);
return IsInWindow(dateTime, window);
}
default:
return false;
}
}
private static bool IsWeekend(DateTime dateTime)
{
return WeekendDays.Contains(dateTime.DayOfWeek);
}
private static bool IsInWindow(DateTime dateTime, StartEndTimeData window)
{
TimeSpan timeOfDay = dateTime.TimeOfDay;
TimeSpan timeSpan = new TimeSpan(window.StartHour, window.StartMinute, 0).Subtract(TimeSpan.FromMinutes(Settings.PreRaidBuffer.Value));
TimeSpan timeSpan2 = new TimeSpan(window.EndHour, window.EndMinute, 0).Add(TimeSpan.FromMinutes(Settings.PostRaidBuffer.Value));
if (timeOfDay >= timeSpan)
{
return timeOfDay < timeSpan2;
}
return false;
}
}
}
namespace CrimsonClans.Structs
{
public class Database
{
public static string JoinCooldownPath = Path.Combine(Plugin.ConfigFiles, "joincooldowns.json");
public List<Cooldown> Cooldowns { get; set; }
public Database()
{
CreateFiles();
LoadFiles();
}
private void LoadFiles()
{
string text = "";
if (Settings.LeaveCooldown.Value > 0)
{
text = File.ReadAllText(JoinCooldownPath);
Cooldowns = JsonSerializer.Deserialize<List<Cooldown>>(text);
}
}
private static void CreateFiles()
{
if (!File.Exists(JoinCooldownPath) && Settings.LeaveCooldown.Value > 0)
{
string contents = JsonSerializer.Serialize(new List<(ulong, DateTime)>());
File.WriteAllText(JoinCooldownPath, contents);
}
}
public static void SaveFiles()
{
string contents = JsonSerializer.Serialize(Core.DB.Cooldowns);
File.WriteAllText(JoinCooldownPath, contents);
}
}
[Serializable]
public struct Cooldown
{
public ulong PlayerId { get; set; }
public DateTime Time { get; set; }
public Cooldown(ulong playerId, DateTime time)
{
PlayerId = playerId;
Time = time;
}
}
[StructLayout(LayoutKind.Sequential, Size = 1)]
public readonly struct Settings
{
public static ConfigEntry<bool> LockInvite;
public static ConfigEntry<bool> LockCreate;
public static ConfigEntry<bool> LockLeave;
public static ConfigEntry<bool> LockKick;
public static ConfigEntry<bool> LockEdit;
public static ConfigEntry<int> PreRaidBuffer;
public static ConfigEntry<int> PostRaidBuffer;
public static ConfigEntry<int> LeaveCooldown;
public static ConfigEntry<bool> KickCooldown;
public static ConfigEntry<int> HeartsPerClan;
private static readonly List<string> OrderedSections = new List<string> { "General", "Raid Time - Buffers", "Raid Time - Ability Locks", "Cooldowns" };
private static readonly List<string> directoryPaths = new List<string>(1) { Plugin.ConfigFiles };
public static void InitConfig()
{
foreach (string directoryPath in directoryPaths)
{
CreateDirectories(directoryPath);
}
HeartsPerClan = InitConfigEntry(OrderedSections[0], "HeartsPerClan", 1, "The amount of castle hearts a clan can have.");
PreRaidBuffer = InitConfigEntry(OrderedSections[1], "PreRaidBufferMins", 30, "The number of minutes prior to the raid window to lock clan operation.");
PostRaidBuffer = InitConfigEntry(OrderedSections[1], "PostRaidBufferMins", 0, "The number of minutes past the raid window to lock clan operation.");
LockInvite = InitConfigEntry(OrderedSections[2], "Invite", defaultValue: true, "If this is set to true, clans will be unable to invite players to their clan during raid time.");
LockCreate = InitConfigEntry(OrderedSections[2], "Create", defaultValue: true, "If this is set to true, clans will be unable to be created during raid time.");
LockEdit = InitConfigEntry(OrderedSections[2], "Edit", defaultValue: true, "If this is set to true, clans will be unable to change their details during raid time.");
LockKick = InitConfigEntry(OrderedSections[2], "Kick", defaultValue: false, "If this is set to true, clans will be unable to kick players from the clan during raid time.");
LockLeave = InitConfigEntry(OrderedSections[2], "Leave", defaultValue: false, "If this is set to true, players will be unable to leave clans during raid time.");
LeaveCooldown = InitConfigEntry(OrderedSections[3], "JoinCooldown", 0, "The number of minutes that a player must wait to join a clan after leaving a prior clan.");
KickCooldown = InitConfigEntry(OrderedSections[3], "KickCooldown", defaultValue: false, "If this is set to true, being kicked from a clan will apply a join cooldown to a player as if they left the clan on their own.");
ReorderConfigSections();
}
private static ConfigEntry<T> InitConfigEntry<T>(string section, string key, T defaultValue, string description)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
ConfigEntry<T> val = ((BasePlugin)Plugin.Instance).Config.Bind<T>(section, key, defaultValue, description);
string text = Path.Combine(Paths.ConfigPath, "CrimsonClans.cfg");
ConfigEntry<T> val2 = default(ConfigEntry<T>);
if (File.Exists(text) && new ConfigFile(text, true).TryGetEntry<T>(section, key, ref val2))
{
val.Value = val2.Value;
}
return val;
}
private static void CreateDirectories(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
private static void ReorderConfigSections()
{
string path = Path.Combine(Paths.ConfigPath, "CrimsonClans.cfg");
if (!File.Exists(path))
{
return;
}
List<string> list = File.ReadAllLines(path).ToList();
Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
string text = "";
foreach (string item in list)
{
if (item.StartsWith("["))
{
text = item.Trim('[', ']');
dictionary[text] = new List<string> { item };
}
else if (!string.IsNullOrWhiteSpace(text))
{
dictionary[text].Add(item);
}
}
using StreamWriter streamWriter = new StreamWriter(path, append: false);
foreach (string orderedSection in OrderedSections)
{
if (!dictionary.ContainsKey(orderedSection))
{
continue;
}
foreach (string item2 in dictionary[orderedSection])
{
streamWriter.WriteLine(item2);
}
streamWriter.WriteLine();
}
}
}
}
namespace CrimsonClans.Services
{
internal class CastleHeartService
{
public static EntityQuery CastleHeartQuery;
public static EntityQuery ClanQuery;
public CastleHeartService()
{
//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_001c: Expected O, but got Unknown
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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_0036: 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_0051: 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_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: 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)
EntityManager entityManager = Core.EntityManager;
EntityQueryDesc[] array = new EntityQueryDesc[1];
EntityQueryDesc val = new EntityQueryDesc();
val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[2]
{
ComponentType.ReadOnly<CastleHeart>(),
ComponentType.ReadOnly<Team>()
});
array[0] = val;
CastleHeartQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
entityManager = Core.EntityManager;
EntityQueryDesc[] array2 = new EntityQueryDesc[1];
val = new EntityQueryDesc();
val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<ClanTeam>() });
array2[0] = val;
ClanQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array2);
}
public static bool CanPlaceHeart(Entity character)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
return CountTeamHearts(character) < Settings.HeartsPerClan.Value;
}
public static bool CanJoinClan(Entity character, Entity clan)
{
//IL_0000: 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)
return CountTeamHearts(character) + CountTeamHearts(clan) < Settings.HeartsPerClan.Value;
}
private static int CountTeamHearts(Entity entity)
{
//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_0008: 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_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: 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_002b: 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_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: 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_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
if (!((EntityManager)(ref entityManager)).HasComponent<Team>(entity))
{
return 0;
}
Team val = entity.Read<Team>();
int num = 0;
NativeArray<Entity> val2 = ((EntityQuery)(ref CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
Enumerator<Entity> enumerator = val2.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
entityManager = Core.EntityManager;
if (((EntityManager)(ref entityManager)).HasComponent<Team>(current))
{
Team val3 = current.Read<Team>();
if (val.Value.Equals(val3.Value))
{
num++;
}
}
}
return num;
}
finally
{
val2.Dispose();
}
}
public static bool TryGetClanByID(NetworkId clandId, out Entity clan)
{
//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_0010: 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_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_0022: 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_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_002c: 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_0035: 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)
NativeArray<Entity> val = ((EntityQuery)(ref ClanQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
Enumerator<Entity> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
NetworkId val2 = current.Read<NetworkId>();
if (((NetworkId)(ref val2)).Equals(clandId))
{
clan = current;
val.Dispose();
return true;
}
}
val.Dispose();
clan = Entity.Null;
return false;
}
public static bool TryGetCastleHeartByID(NetworkId castleId, out Entity castle)
{
//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_0010: 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_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_0022: 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_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_002c: 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_0035: 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)
NativeArray<Entity> val = ((EntityQuery)(ref CastleHeartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
Enumerator<Entity> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
NetworkId val2 = current.Read<NetworkId>();
if (((NetworkId)(ref val2)).Equals(castleId))
{
castle = current;
val.Dispose();
return true;
}
}
val.Dispose();
castle = Entity.Null;
return false;
}
}
}
namespace CrimsonClans.Patches
{
[HarmonyPatch(typeof(CastleHeartEventSystem), "OnUpdate")]
internal class CastleHeartEventSystemPatch
{
public static void Prefix(CastleHeartEventSystem __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_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_0014: 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_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_002a: 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_0032: 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_003a: Invalid comparison between Unknown and I4
//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_0042: 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_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: 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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: 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)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: 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_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: 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_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
EntityQuery castleHeartInteractEventQuery = __instance._CastleHeartInteractEventQuery;
NativeArray<Entity> val = ((EntityQuery)(ref castleHeartInteractEventQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
Enumerator<Entity> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
CastleHeartInteractEvent val2 = current.Read<CastleHeartInteractEvent>();
if ((int)val2.EventType == 3)
{
FromCharacter val3 = current.Read<FromCharacter>();
if ((!CastleHeartService.TryGetCastleHeartByID(val2.CastleHeart, out var castle) || !castle.Has<UserOwner>() || !(castle.Read<UserOwner>().Owner._Entity.Read<User>() == val3.User.Read<User>())) && !CastleHeartService.CanPlaceHeart(val3.Character))
{
ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, val3.User.Read<User>(), "You or your clan have reached the maximum number of castle hearts.");
current.DestroyWithReason();
}
}
}
val.Dispose();
}
}
[HarmonyPatch(typeof(ClanSystem_Server), "OnUpdate")]
internal class ClanSystemServerPatch
{
public static void Prefix(ClanSystem_Server __instance)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_004e: 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_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: 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_00d6: 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)
(EntityQuery, string)[] array = new(EntityQuery, string)[6]
{
(__instance._InvitePlayerToClanQuery, "Invite"),
(__instance._ClanInviteResponseQuery, "Response"),
(__instance._KickRequestQuery, "Kick"),
(__instance._CreateClanEventQuery, "Create"),
(__instance._LeaveClanEventQuery, "Leave"),
(__instance._EditClanEventQuery, "Edit")
};
for (int i = 0; i < array.Length; i++)
{
(EntityQuery, string) tuple = array[i];
EntityQuery item = tuple.Item1;
string item2 = tuple.Item2;
NativeArray<Entity> val = ((EntityQuery)(ref item)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
Enumerator<Entity> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
if (!HandleRaidWindow(current, item2) && !HandleLeaveCooldown(current, item2))
{
HandleJoinResponseWithCooldown(current, item2);
}
}
val.Dispose();
}
}
private static bool HandleRaidWindow(Entity entity, string type)
{
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
if (type == "Invite" && !Settings.LockInvite.Value)
{
return false;
}
if (type == "Response" && !Settings.LockInvite.Value)
{
return false;
}
if (type == "Kick" && !Settings.LockKick.Value)
{
return false;
}
if (type == "Create" && !Settings.LockCreate.Value)
{
return false;
}
if (type == "Leave" && !Settings.LockLeave.Value)
{
return false;
}
if (type == "Edit" && !Settings.LockEdit.Value)
{
return false;
}
if (RaidTime.IsRaidTimeNow())
{
Cancel(entity, "The Clan " + type + " ability is disabled during the raid window.");
return true;
}
return false;
}
private static bool HandleLeaveCooldown(Entity entity, string type)
{
//IL_002b: 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_0036: 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_00e3: 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_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: 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_006a: 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)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: 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_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: 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_0086: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
if (type == "Leave" || type == "Kick")
{
if (Settings.LeaveCooldown.Value == 0)
{
return false;
}
User val = entity.Read<FromCharacter>().User.Read<User>();
if (type == "Kick")
{
if (!Settings.KickCooldown.Value)
{
return false;
}
Kick_Request val2 = entity.Read<Kick_Request>();
EntityManager entityManager = Core.EntityManager;
DynamicBuffer<ClanMemberStatus> buffer = ((EntityManager)(ref entityManager)).GetBuffer<ClanMemberStatus>(val.ClanEntity._Entity, false);
entityManager = Core.EntityManager;
DynamicBuffer<SyncToUserBuffer> buffer2 = ((EntityManager)(ref entityManager)).GetBuffer<SyncToUserBuffer>(val.ClanEntity._Entity, false);
for (int i = 0; i < buffer.Length; i++)
{
if (buffer[i].UserIndex == val2.TargetUserIndex)
{
val = buffer2[i].UserEntity.Read<User>();
break;
}
}
}
Core.DB.Cooldowns.Add(new Cooldown(val.PlatformId, DateTime.Now.AddMinutes(Settings.LeaveCooldown.Value)));
Database.SaveFiles();
return true;
}
return false;
}
private static bool HandleJoinResponseWithCooldown(Entity entity, string type)
{
//IL_0015: 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_0038: 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_003e: 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_0041: 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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
if (type != "Response")
{
return false;
}
ClanInviteResponse val = entity.Read<ClanInviteResponse>();
if (!((object)(InviteRequestResponse)(ref val.Response)).Equals((object)(InviteRequestResponse)1))
{
return false;
}
FromCharacter val2 = entity.Read<FromCharacter>();
User user = val2.User.Read<User>();
if (Settings.LeaveCooldown.Value != 0 && Core.DB.Cooldowns.Exists((Cooldown x) => x.PlayerId == user.PlatformId && x.Time > DateTime.Now))
{
Cancel(entity, "You are on cooldown from joining a clan for " + FormatRemainder(Core.DB.Cooldowns.First((Cooldown x) => x.PlayerId == user.PlatformId && x.Time > DateTime.Now).Time - DateTime.Now) + ".");
return true;
}
if (!CastleHeartService.TryGetClanByID(val.ClanId, out var clan))
{
return false;
}
if (!CastleHeartService.CanJoinClan(val2.Character, clan))
{
Cancel(entity, "Joining the clan would result in exceeding the maximum number of castle hearts.");
return true;
}
return false;
}
private static void Cancel(Entity entity, string cancelReason)
{
//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_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: 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)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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_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_0022: 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_002f: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = Core.EntityManager;
FromCharacter componentData = ((EntityManager)(ref entityManager)).GetComponentData<FromCharacter>(entity);
entityManager = Core.EntityManager;
User componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<User>(componentData.User);
ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, componentData2, cancelReason);
entity.DestroyWithReason();
}
private static string FormatRemainder(TimeSpan remainder)
{
string text = string.Empty;
if (remainder.Days > 0)
{
text += $"{remainder.Days} days, ";
}
if (remainder.Hours > 0)
{
text += $"{remainder.Hours} hours, ";
}
if (remainder.Minutes > 0)
{
text += $"{remainder.Minutes} minutes";
}
if (text.EndsWith(", "))
{
text = text.Substring(0, text.Length - 2);
}
return text;
}
}
[HarmonyPatch]
internal static class InitializationPatch
{
[HarmonyPatch(typeof(SceneSystem), "ShutdownStreamingSupport")]
[HarmonyPostfix]
private static void ShutdownStreamingSupportPostfix()
{
Core.InitializeAfterLoaded();
if (Core._hasInitialized)
{
Plugin.Haromy.Unpatch((MethodBase)typeof(SceneSystem).GetMethod("ShutdownStreamingSupport"), typeof(InitializationPatch).GetMethod("OneShot_AfterLoad_InitializationPatch"));
}
}
}
[HarmonyPatch(typeof(PlaceTileModelSystem), "OnUpdate")]
internal class PlaceTileModelSystemPatch
{
public static void Prefix(PlaceTileModelSystem __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_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_0014: 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_0021: 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_0027: 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_002d: 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_0043: 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_0049: 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_004f: 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_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: 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_0073: Unknown result type (might be due to invalid IL or missing references)
EntityQuery buildTileQuery = __instance._BuildTileQuery;
NativeArray<Entity> val = ((EntityQuery)(ref buildTileQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
Enumerator<Entity> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
if (current.Read<BuildTileModelEvent>().PrefabGuid == new PrefabGUID(-485210554))
{
FromCharacter val2 = current.Read<FromCharacter>();
User val3 = val2.User.Read<User>();
if (!CastleHeartService.CanPlaceHeart(val2.Character))
{
ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, val3, "You or your clan have reached the maximum number of castle hearts.");
current.DestroyWithReason();
}
}
}
val.Dispose();
}
}
}