using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CrimsonJanitor.Structs;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using ProjectM.Shared;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using VAMP;
using VAMP.Services;
using VAMP.Utilities;
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("CrimsonJanitor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("One Janitor vs A World of Rats")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+7.Branch.master.Sha.e36e9f5fc7bb267ed2dd23fb39417b61a87b5b86.e36e9f5fc7bb267ed2dd23fb39417b61a87b5b86")]
[assembly: AssemblyProduct("CrimsonJanitor")]
[assembly: AssemblyTitle("CrimsonJanitor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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;
}
}
}
[HarmonyPatch(typeof(ReactToInventoryChangedSystem), "OnUpdate")]
internal class ContainerPatch
{
private struct Contraband
{
public PrefabGUID itemEntity;
public Entity playerEntity;
public int amount;
public Contraband(PrefabGUID itemEntity, Entity playerEntity, int amount)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: 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)
this.itemEntity = itemEntity;
this.playerEntity = playerEntity;
this.amount = amount;
}
}
private static List<Contraband> Contraban = new List<Contraband>();
public static void Prefix(ReactToInventoryChangedSystem __instance)
{
//IL_006d: 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_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_0080: 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_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_0098: 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_0028: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: 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_00d8: 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_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: 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_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: 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_013c: 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_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: 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)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: 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_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_0281: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_0288: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
if (Contraban.Count > 0)
{
foreach (Contraband item in Contraban)
{
InventoryUtilitiesServer.TryRemoveItemFromInventories(Core.EntityManager, item.playerEntity, item.itemEntity, item.amount);
}
Contraban.Clear();
Contraban.TrimExcess();
}
EntityQuery _query_2096870026_ = __instance.__query_2096870026_0;
NativeArray<Entity> val = ((EntityQuery)(ref _query_2096870026_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
try
{
Enumerator<Entity> enumerator2 = val.GetEnumerator();
InventoryChangedEvent val2 = default(InventoryChangedEvent);
while (enumerator2.MoveNext())
{
Entity current2 = enumerator2.Current;
if (!EntityUtil.TryGetComponent<InventoryChangedEvent>(current2, ref val2))
{
continue;
}
Entity inventoryEntity = val2.InventoryEntity;
ref InventoryChangedEventType changeType = ref val2.ChangeType;
object obj = (object)(InventoryChangedEventType)1;
if (!((object)Unsafe.As<InventoryChangedEventType, InventoryChangedEventType>(ref changeType)/*cast due to .constrained prefix*/).Equals(obj) || !EntityUtil.Has<InventoryConnection>(inventoryEntity))
{
continue;
}
InventoryConnection val3 = EntityUtil.Read<InventoryConnection>(inventoryEntity);
if (!EntityUtil.Has<PlayerCharacter>(val3.InventoryOwner))
{
continue;
}
User val4 = EntityUtil.Read<User>(EntityUtil.Read<PlayerCharacter>(val3.InventoryOwner).UserEntity);
if (!EntityUtil.Has<Attached>(inventoryEntity))
{
continue;
}
Attached val5 = EntityUtil.Read<Attached>(inventoryEntity);
if (!EntityUtil.Has<Interactor>(val5.Parent))
{
continue;
}
Interactor val6 = EntityUtil.Read<Interactor>(val5.Parent);
if (!EntityUtil.Has<CastleHeartConnection>(val6.Target))
{
continue;
}
CastleHeartConnection val7 = EntityUtil.Read<CastleHeartConnection>(val6.Target);
CastleHeart val8 = EntityUtil.Read<CastleHeart>(val7.CastleHeartEntity._Entity);
if (!((CastleHeart)(ref val8)).IsDecaying())
{
continue;
}
User val9 = val4;
if (EntityUtil.Has<UserOwner>(val7.CastleHeartEntity._Entity))
{
UserOwner val10 = EntityUtil.Read<UserOwner>(val7.CastleHeartEntity._Entity);
if (EntityUtil.Exists(val10.Owner._Entity))
{
val9 = EntityUtil.Read<User>(val10.Owner._Entity);
}
}
if (val9 == val4)
{
continue;
}
bool flag = false;
if (!((Entity)(ref val4.ClanEntity._Entity)).Equals(Entity.Null) && !((Entity)(ref val9.ClanEntity._Entity)).Equals(Entity.Null) && ((Entity)(ref val9.ClanEntity._Entity)).Equals(val4.ClanEntity._Entity))
{
flag = true;
}
if ((!flag || Settings.AllyCleaner.Value) && Settings.RatLooting.Value)
{
ChatUtil.SystemSendUser(val4, Settings.RatMessage.Value);
if (EntityUtil.Exists(val2.ItemEntity) && !InventoryUtilitiesServer.TryRemoveItemFromInventories(Core.EntityManager, val4.LocalCharacter._Entity, val2.Item, val2.Amount))
{
Contraban.Add(new Contraband(val2.Item, val4.LocalCharacter._Entity, val2.Amount));
}
DestroyUtility.Destroy(Core.EntityManager, current2, (DestroyDebugReason)0, (string)null, 0);
}
}
val.Dispose();
}
catch (Exception)
{
}
}
}
namespace CrimsonJanitor
{
[BepInPlugin("CrimsonJanitor", "CrimsonJanitor", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
private Harmony _harmony;
public static Plugin Instance { get; private set; }
public static Harmony Harmony => Instance._harmony;
public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;
public static Settings Settings { get; private set; }
public override void Load()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
Instance = this;
Settings = default(Settings);
if (Settings.InitConfig())
{
_harmony = new Harmony("CrimsonJanitor");
_harmony.PatchAll(Assembly.GetExecutingAssembly());
CommandRegistry.RegisterAll();
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>("CrimsonJanitor");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
log.LogInfo(val);
}
}
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 = "CrimsonJanitor";
public const string PLUGIN_NAME = "CrimsonJanitor";
public const string PLUGIN_VERSION = "0.1.0";
}
}
namespace CrimsonJanitor.Structs
{
[StructLayout(LayoutKind.Sequential, Size = 1)]
public readonly struct Settings
{
private static readonly List<string> OrderedSections = new List<string> { "Config", "Options" };
public static ConfigEntry<bool> ToggleMod { get; private set; }
public static ConfigEntry<bool> DecayingOnly { get; private set; }
public static ConfigEntry<bool> AllyCleaner { get; private set; }
public static ConfigEntry<bool> RatLooting { get; private set; }
public static ConfigEntry<string> RatMessage { get; private set; }
public static bool InitConfig()
{
ToggleMod = InitConfigEntry(OrderedSections[0], "ToggleMod", defaultValue: true, "Enable or disable the mod.");
DecayingOnly = InitConfigEntry(OrderedSections[1], "DecayingOnly", defaultValue: true, "If true, only castles destroyed while in decay will be affected by this mod.");
AllyCleaner = InitConfigEntry(OrderedSections[1], "AllyCleaner", defaultValue: false, "If true, allies destroying castle will also trigger the janitor.");
RatLooting = InitConfigEntry(OrderedSections[1], "NoRatLooting", defaultValue: false, "If true, players will not be able to loot castles while they are in decay.");
RatMessage = InitConfigEntry(OrderedSections[1], "RatMessage", "You cannot loot this castle while it is decaying.", "The message that will be sent to players who try to loot a castle while it is decaying.");
ReorderConfigSections();
return ToggleMod.Value;
}
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, "CrimsonJanitor.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 ReorderConfigSections()
{
string path = Path.Combine(Paths.ConfigPath, "CrimsonJanitor.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 CrimsonJanitor.Patches
{
[HarmonyPatch(typeof(CastleHeartEventSystem), "OnUpdate")]
internal class CastleHeartEventSystemPatch
{
public static void Prefix(CastleHeartEventSystem __instance)
{
//IL_0002: 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_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_001c: 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_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_0032: 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_0053: 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_005b: 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)
//IL_0061: 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_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: 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_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: 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_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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_00c2: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Invalid comparison between Unknown and I4
//IL_00d5: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: 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_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
NativeArray<Entity> val = default(NativeArray<Entity>);
try
{
EntityQuery castleHeartInteractEventQuery = __instance._CastleHeartInteractEventQuery;
val = ((EntityQuery)(ref castleHeartInteractEventQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
Enumerator<Entity> enumerator = val.GetEnumerator();
Entity val6 = default(Entity);
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
if (!EntityUtil.Exists(current) || !EntityUtil.Has<CastleHeartInteractEvent>(current) || !EntityUtil.Has<FromCharacter>(current))
{
continue;
}
CastleHeartInteractEvent val2 = EntityUtil.Read<CastleHeartInteractEvent>(current);
FromCharacter val3 = EntityUtil.Read<FromCharacter>(current);
if (!EntityUtil.Exists(val3.User) || !EntityUtil.Has<User>(val3.User))
{
continue;
}
User val4 = EntityUtil.Read<User>(val3.User);
User val5 = val4;
if (CastleHeartService.TryGetByID(val2.CastleHeart, ref val6) && EntityUtil.Exists(val6) && EntityUtil.Has<UserOwner>(val6))
{
UserOwner val7 = EntityUtil.Read<UserOwner>(val6);
if (EntityUtil.Exists(val7.Owner._Entity))
{
val5 = EntityUtil.Read<User>(val7.Owner._Entity);
}
}
bool num = val5 == val4;
bool flag = false;
if (!((Entity)(ref val4.ClanEntity._Entity)).Equals(Entity.Null) && !((Entity)(ref val5.ClanEntity._Entity)).Equals(Entity.Null) && ((Entity)(ref val5.ClanEntity._Entity)).Equals(val4.ClanEntity._Entity))
{
flag = true;
}
if (num || flag || (int)val2.EventType != 5)
{
continue;
}
if (Settings.DecayingOnly.Value)
{
CastleHeart val8 = EntityUtil.Read<CastleHeart>(val6);
if (!((CastleHeart)(ref val8)).IsDecaying())
{
continue;
}
}
Enumerator<Entity> enumerator2 = CastleHeartHelpers.GetConnectedTileModels(val6, Core.EntityManager, (Allocator)2).GetEnumerator();
while (enumerator2.MoveNext())
{
Entity current2 = enumerator2.Current;
if (EntityUtil.Has<ServantCoffinstation>(current2))
{
ServantCoffinstation val9 = EntityUtil.Read<ServantCoffinstation>(current2);
if (!((Entity)(ref val9.ConnectedServant._Entity)).Equals(Entity.Null))
{
ItemUtil.ClearEntityInventory(val9.ConnectedServant._Entity, false);
EntityUtil.DestroyWithReason(val9.ConnectedServant._Entity);
}
}
if (EntityUtil.Has<InventoryInstanceElement>(current2))
{
ItemUtil.ClearEntityInventory(current2, true);
}
EntityUtil.DestroyWithReason(current2);
}
}
}
catch (Exception ex)
{
Plugin.LogInstance.LogError((object)ex);
}
finally
{
val.Dispose();
}
}
}
}