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 System.Text.Json; using System.Text.Json.Serialization; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem.Collections.Generic; using KinCaller.Services; using Microsoft.CodeAnalysis; using ProjectM; using ProjectM.CastleBuilding; using ProjectM.Network; using ProjectM.Terrain; using Stunlock.Core; using Unity.Collections; using Unity.Entities; using Unity.Mathematics; using Unity.Transforms; 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("KinCaller")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Controls the destination of dominated prisoners when using the Dusk Caller")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+7d91ebf340ecfdc7e93dbabf97e47d6ef697db26")] [assembly: AssemblyProduct("KinCaller")] [assembly: AssemblyTitle("KinCaller")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [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 KinCaller { internal static class Core { internal 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 ManualLogSource Log { get; } = Plugin.LogInstance; public static ExtraditionService Extradition { get; private set; } public static CastleTerritoryService CastleTerritory { get; private 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 log = Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 5, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failure in "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(caller); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nMessage: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(e.Message); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Inner:"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(e.InnerException?.Message); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n\nStack: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(e.StackTrace); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nInner Stack: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(e.InnerException?.StackTrace); } log.LogError(val); } internal static void InitializeAfterLoaded() { if (!_hasInitialized) { CastleTerritory = new CastleTerritoryService(); Extradition = new ExtraditionService(); _hasInitialized = true; Log.LogInfo((object)"[KinCaller] Initialized."); } } private static World GetWorld(string name) { Enumerator enumerator = World.s_AllWorlds.GetEnumerator(); while (enumerator.MoveNext()) { World current = enumerator.Current; if (current.Name == name) { return current; } } return null; } } public static class ECSExtensions { public unsafe static void Write(this Entity entity, T componentData) where T : struct { //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_002d: 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_002f: Unknown result type (might be due to invalid IL or missing references) ComponentType val = default(ComponentType); ((ComponentType)(ref val))..ctor(Il2CppType.Of(), (AccessMode)0); int num = Marshal.SizeOf(); byte* ptr = stackalloc byte[(int)(uint)num]; Marshal.StructureToPtr(componentData, (IntPtr)ptr, fDeleteOld: false); EntityManager entityManager = Core.EntityManager; ((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num); } public unsafe static T Read(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(), (AccessMode)0); EntityManager entityManager = Core.EntityManager; return Marshal.PtrToStructure(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex))); } public static bool Has(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(), (AccessMode)0); EntityManager entityManager = Core.EntityManager; return ((EntityManager)(ref entityManager)).HasComponent(entity, val); } } [BepInPlugin("KinCaller", "KinCaller", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BasePlugin { private Harmony _harmony; private static Plugin Instance; public static Harmony Harmony => Instance._harmony; public static ManualLogSource LogInstance { get; private set; } public override void Load() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown Instance = this; 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("KinCaller"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted("1.0.0"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!"); } log.LogInfo(val); LogInstance = ((BasePlugin)this).Log; _harmony = new Harmony("KinCaller"); _harmony.PatchAll(Assembly.GetExecutingAssembly()); CommandRegistry.RegisterAll(); } public override bool Unload() { CommandRegistry.UnregisterAssembly(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } return true; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "KinCaller"; public const string PLUGIN_NAME = "KinCaller"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace KinCaller.Services { internal class CastleTerritoryService { private const float BLOCK_SIZE = 10f; private readonly Dictionary _blockToTerritory = new Dictionary(); private readonly EntityQuery _heartQuery; public CastleTerritoryService() { //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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //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_004e: 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) EntityManager entityManager = Core.EntityManager; EntityQueryDesc[] array = new EntityQueryDesc[1]; EntityQueryDesc val = new EntityQueryDesc(); val.All = Il2CppStructArray.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly() }); val.Options = (EntityQueryOptions)2; array[0] = val; _heartQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array); BuildBlockMap(); } private void BuildBlockMap() { //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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //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_003c: 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_0045: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_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_0064: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = Core.EntityManager; EntityQueryDesc[] array = new EntityQueryDesc[1]; EntityQueryDesc val = new EntityQueryDesc(); val.All = Il2CppStructArray.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly() }); val.Options = (EntityQueryOptions)2; array[0] = val; EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array); try { NativeArray val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { Enumerator enumerator = val3.GetEnumerator(); while (enumerator.MoveNext()) { Entity current = enumerator.Current; int castleTerritoryIndex = current.Read().CastleTerritoryIndex; entityManager = Core.EntityManager; DynamicBuffer buffer = ((EntityManager)(ref entityManager)).GetBuffer(current, false); for (int i = 0; i < buffer.Length; i++) { _blockToTerritory[buffer[i].BlockCoordinate] = castleTerritoryIndex; } } } finally { val3.Dispose(); } } finally { ((EntityQuery)(ref val2)).Dispose(); } } public int GetTerritoryIndex(float3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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_000d: Unknown result type (might be due to invalid IL or missing references) int2 key = ConvertPosToBlockCoord(pos); if (!_blockToTerritory.TryGetValue(key, out var value)) { return -1; } return value; } public Entity GetHeartForTerritory(int territoryIndex) { //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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0004: 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_0030: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_004e: 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_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_0079: Unknown result type (might be due to invalid IL or missing references) if (territoryIndex == -1) { return Entity.Null; } EntityQuery heartQuery = _heartQuery; NativeArray val = ((EntityQuery)(ref heartQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { Enumerator enumerator = val.GetEnumerator(); while (enumerator.MoveNext()) { Entity current = enumerator.Current; Entity castleTerritoryEntity = current.Read().CastleTerritoryEntity; if (!((Entity)(ref castleTerritoryEntity)).Equals(Entity.Null) && castleTerritoryEntity.Read().CastleTerritoryIndex == territoryIndex) { return current; } } } finally { val.Dispose(); } return Entity.Null; } private static int2 ConvertPosToBlockCoord(float3 pos) { //IL_0000: 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_004c: Unknown result type (might be due to invalid IL or missing references) int num = (int)math.floor(pos.x * 2f) + 6400; int num2 = (int)math.floor(pos.z * 2f) + 6400; return new int2((int)math.floor((float)num / 10f), (int)math.floor((float)num2 / 10f)); } } internal class ExtraditionService { public enum RoutingOutcome { MarkedTerritory, OwnCastle, Vanilla } private class SaveData { [JsonInclude] public Dictionary Players { get; set; } = new Dictionary(); } private readonly Dictionary _targetTerritory = new Dictionary(); private static readonly string SaveDir = Path.Combine(Paths.ConfigPath, "KinCaller"); private static readonly string SavePath = Path.Combine(SaveDir, "target_territories.json"); private readonly EntityQuery _prisonCellQuery; public ExtraditionService() { //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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_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_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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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.op_Implicit((ComponentType[])(object)new ComponentType[4] { new ComponentType(Il2CppType.Of(), (AccessMode)1), new ComponentType(Il2CppType.Of(), (AccessMode)1), new ComponentType(Il2CppType.Of(), (AccessMode)1), new ComponentType(Il2CppType.Of(), (AccessMode)1) }); val.Options = (EntityQueryOptions)2; array[0] = val; _prisonCellQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array); Load(); } public void SetTargetTerritory(Entity userEntity, int territoryIndex) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) ulong steamId = GetSteamId(userEntity); if (steamId != 0L && territoryIndex >= 0) { _targetTerritory[steamId] = territoryIndex; Save(); } } public bool ClearTarget(Entity userEntity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) ulong steamId = GetSteamId(userEntity); if (steamId == 0L) { return false; } if (!_targetTerritory.Remove(steamId)) { return false; } Save(); return true; } public int GetTargetTerritory(Entity userEntity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) ulong steamId = GetSteamId(userEntity); if (steamId == 0L) { return -1; } if (!_targetTerritory.TryGetValue(steamId, out var value)) { return -1; } return value; } public (Entity Cell, RoutingOutcome Outcome) FindBestCell(Entity casterUser, Entity prisoner, Entity currentCell) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0020: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: 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_00ba: 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_00c3: 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_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_0053: 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_00cf: 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_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_006e: 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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) if (((Entity)(ref casterUser)).Equals(Entity.Null)) { return (Cell: Entity.Null, Outcome: RoutingOutcome.Vanilla); } LocalToWorld val = prisoner.Read(); float3 position = ((LocalToWorld)(ref val)).Position; ulong steamId = GetSteamId(casterUser); if (steamId != 0L && _targetTerritory.TryGetValue(steamId, out var value)) { Entity heartForTerritory = Core.CastleTerritory.GetHeartForTerritory(value); if (!((Entity)(ref heartForTerritory)).Equals(Entity.Null) && IsOwnerAllied(GetHeartOwnerFromHeart(heartForTerritory), casterUser)) { if (GetCellTerritoryIndex(currentCell) == value) { return (Cell: currentCell, Outcome: RoutingOutcome.MarkedTerritory); } Entity item = FindNearestEmptyInTerritory(value, position, currentCell); if (!((Entity)(ref item)).Equals(Entity.Null)) { return (Cell: item, Outcome: RoutingOutcome.MarkedTerritory); } } } if (GetHeartOwner(currentCell) == casterUser) { return (Cell: currentCell, Outcome: RoutingOutcome.OwnCastle); } Entity item2 = FindNearestEmptyInOwnCastle(casterUser, position, currentCell); if (!((Entity)(ref item2)).Equals(Entity.Null)) { return (Cell: item2, Outcome: RoutingOutcome.OwnCastle); } return (Cell: Entity.Null, Outcome: RoutingOutcome.Vanilla); } public int CountEmptyCellsInTerritory(int territoryIndex) { //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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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_002a: 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) EntityQuery prisonCellQuery = _prisonCellQuery; NativeArray val = ((EntityQuery)(ref prisonCellQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { int num = 0; Enumerator enumerator = val.GetEnumerator(); while (enumerator.MoveNext()) { Entity current = enumerator.Current; if (IsCellEmpty(current) && GetCellTerritoryIndex(current) == territoryIndex) { num++; } } return num; } finally { val.Dispose(); } } public static void RedirectPrisoner(Entity prisoner, Entity fromCell, Entity toCell) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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_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_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_0019: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0029: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_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_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) PrisonCell componentData = fromCell.Read(); componentData.ImprisonedEntity = NetworkedEntity.op_Implicit(Entity.Null); fromCell.Write(componentData); PrisonCell componentData2 = toCell.Read(); componentData2.ImprisonedEntity = NetworkedEntity.op_Implicit(prisoner); toCell.Write(componentData2); Imprisoned componentData3 = prisoner.Read(); componentData3.PrisonCellEntity = toCell; prisoner.Write(componentData3); } private Entity FindNearestEmptyInTerritory(int territoryIndex, float3 referencePos, Entity exclude = default(Entity)) { //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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_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_0035: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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_0052: 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_005e: 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_0074: Unknown result type (might be due to invalid IL or missing references) EntityQuery prisonCellQuery = _prisonCellQuery; NativeArray val = ((EntityQuery)(ref prisonCellQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { Entity result = Entity.Null; float num = float.MaxValue; Enumerator enumerator = val.GetEnumerator(); while (enumerator.MoveNext()) { Entity current = enumerator.Current; if (!(current == exclude) && IsCellEmpty(current) && GetCellTerritoryIndex(current) == territoryIndex) { LocalToWorld val2 = current.Read(); float num2 = math.distancesq(referencePos, ((LocalToWorld)(ref val2)).Position); if (num2 < num) { num = num2; result = current; } } } return result; } finally { val.Dispose(); } } private Entity FindNearestEmptyInOwnCastle(Entity userEntity, float3 referencePos, Entity exclude = default(Entity)) { //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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_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_0035: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: 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_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_0057: 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_005a: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) EntityQuery prisonCellQuery = _prisonCellQuery; NativeArray val = ((EntityQuery)(ref prisonCellQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { Entity result = Entity.Null; float num = float.MaxValue; Enumerator enumerator = val.GetEnumerator(); while (enumerator.MoveNext()) { Entity current = enumerator.Current; if (!(current == exclude) && IsCellEmpty(current) && !(GetHeartOwner(current) != userEntity)) { LocalToWorld val2 = current.Read(); float num2 = math.distancesq(referencePos, ((LocalToWorld)(ref val2)).Position); if (num2 < num) { num = num2; result = current; } } } return result; } finally { val.Dispose(); } } private void Load() { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown if (!File.Exists(SavePath)) { return; } bool flag = default(bool); try { SaveData saveData = JsonSerializer.Deserialize(File.ReadAllText(SavePath)); if (saveData?.Players == null) { return; } foreach (var (s, num2) in saveData.Players) { if (ulong.TryParse(s, out var result) && num2 >= 0) { _targetTerritory[result] = num2; } } ManualLogSource log = Core.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(54, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[KinCaller] Loaded extradition targets for "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(_targetTerritory.Count); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" player(s)."); } log.LogInfo(val); } catch (Exception ex) { ManualLogSource log2 = Core.Log; BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(52, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[KinCaller] Failed to load target_territories.json: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted(ex.Message); } log2.LogError(val2); } } private void Save() { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown try { Directory.CreateDirectory(SaveDir); SaveData value = new SaveData { Players = _targetTerritory.ToDictionary((KeyValuePair kvp) => kvp.Key.ToString(), (KeyValuePair kvp) => kvp.Value) }; string text = SavePath + ".tmp"; File.WriteAllText(text, JsonSerializer.Serialize(value, new JsonSerializerOptions { WriteIndented = true })); File.Move(text, SavePath, overwrite: true); } catch (Exception ex) { ManualLogSource log = Core.Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(52, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[KinCaller] Failed to save target_territories.json: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex.Message); } log.LogError(val); } } private static ulong GetSteamId(Entity userEntity) { //IL_0002: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (((Entity)(ref userEntity)).Equals(Entity.Null) || !userEntity.Has()) { return 0uL; } return userEntity.Read().PlatformId; } private static bool IsCellEmpty(Entity cell) { //IL_0000: 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_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_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_0020: Unknown result type (might be due to invalid IL or missing references) if (!cell.Has()) { return false; } PrisonCell val = cell.Read(); Entity entityOnServer = ((NetworkedEntity)(ref val.ImprisonedEntity)).GetEntityOnServer(); return ((Entity)(ref entityOnServer)).Equals(Entity.Null); } private static int GetCellTerritoryIndex(Entity cell) { //IL_0000: 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_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_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_0020: 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) if (!cell.Has()) { return -1; } CastleHeartConnection val = cell.Read(); Entity entityOnServer = ((NetworkedEntity)(ref val.CastleHeartEntity)).GetEntityOnServer(); if (((Entity)(ref entityOnServer)).Equals(Entity.Null)) { return -1; } return GetCastleTerritoryIndex(entityOnServer); } internal static bool IsOwnerAllied(Entity ownerUser, Entity casterUser) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_002d: 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_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_0041: 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_0047: 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_0057: 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_0073: 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) if (((Entity)(ref ownerUser)).Equals(Entity.Null)) { return false; } if (ownerUser == casterUser) { return true; } if (!casterUser.Has() || !ownerUser.Has()) { return false; } User val = casterUser.Read(); Entity entityOnServer = ((NetworkedEntity)(ref val.ClanEntity)).GetEntityOnServer(); val = ownerUser.Read(); Entity entityOnServer2 = ((NetworkedEntity)(ref val.ClanEntity)).GetEntityOnServer(); if (((Entity)(ref entityOnServer)).Equals(Entity.Null) || ((Entity)(ref entityOnServer2)).Equals(Entity.Null)) { return false; } return entityOnServer == entityOnServer2; } internal static Entity GetHeartOwner(Entity cell) { //IL_0000: 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_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_0008: Unknown result type (might be due to invalid IL or missing references) if (!cell.Has()) { return Entity.Null; } CastleHeartConnection val = cell.Read(); return GetHeartOwnerFromHeart(((NetworkedEntity)(ref val.CastleHeartEntity)).GetEntityOnServer()); } internal static Entity GetHeartOwnerFromHeart(Entity heart) { //IL_0002: 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_000e: 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_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_002a: Unknown result type (might be due to invalid IL or missing references) if (((Entity)(ref heart)).Equals(Entity.Null) || !heart.Has()) { return Entity.Null; } UserOwner val = heart.Read(); return ((NetworkedEntity)(ref val.Owner)).GetEntityOnServer(); } internal static int GetCastleTerritoryIndex(Entity heartEntity) { //IL_0000: 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_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_0015: 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_0024: 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_002f: Unknown result type (might be due to invalid IL or missing references) if (!heartEntity.Has()) { return -1; } Entity castleTerritoryEntity = heartEntity.Read().CastleTerritoryEntity; if (((Entity)(ref castleTerritoryEntity)).Equals(Entity.Null) || !castleTerritoryEntity.Has()) { return -1; } return castleTerritoryEntity.Read().CastleTerritoryIndex; } internal unsafe static string GetCastleTerritoryRegionName(Entity heartEntity) { //IL_0000: 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_0019: 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_0028: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) if (!heartEntity.Has()) { return string.Empty; } Entity castleTerritoryEntity = heartEntity.Read().CastleTerritoryEntity; if (((Entity)(ref castleTerritoryEntity)).Equals(Entity.Null) || !castleTerritoryEntity.Has()) { return string.Empty; } WorldRegionType region = castleTerritoryEntity.Read().Region; return Regex.Replace(((object)(*(WorldRegionType*)(®ion))/*cast due to .constrained prefix*/).ToString().Replace("_", ""), "(?()) { obj = "unknown"; } else { User val = heartOwnerFromHeart.Read(); obj = ((object)(*(FixedString64Bytes*)(&val.CharacterName))/*cast due to .constrained prefix*/).ToString(); } string text = ((castleTerritoryIndex < 0) ? "no plot" : ((castleTerritoryRegionName.Length > 0) ? $"Plot {castleTerritoryIndex}, {castleTerritoryRegionName}" : $"Plot {castleTerritoryIndex}")); return (string?)obj + "'s castle (" + text + ")"; } internal static string DescribeCellPlain(Entity cell) { //IL_0000: 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_001c: Unknown result type (might be due to invalid IL or missing references) if (!cell.Has()) { return "an unknown cell"; } CastleHeartConnection val = cell.Read(); return DescribeHeartPlain(((NetworkedEntity)(ref val.CastleHeartEntity)).GetEntityOnServer()); } } } namespace KinCaller.Patches { [HarmonyPatch(typeof(BuffSystem_Spawn_Server), "OnUpdate")] internal static class ImprisonSuccessfulBuffPatch { private const int ImprisonSuccessfulPlayerBuff = -1939804277; private const int SendToPrisonInvulnerabilityBuff = -1988445418; private static string P(string s) { return "" + s + ""; } private static string G(string s) { return "" + s + ""; } private static string M(string s) { return "" + s + ""; } private unsafe static string CellLocation(Entity cell, bool includeName = true) { //IL_0000: 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_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_0025: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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_00eb: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0114: 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_011b: Unknown result type (might be due to invalid IL or missing references) if (!cell.Has()) { return string.Empty; } CastleHeartConnection val = cell.Read(); Entity entityOnServer = ((NetworkedEntity)(ref val.CastleHeartEntity)).GetEntityOnServer(); if (((Entity)(ref entityOnServer)).Equals(Entity.Null)) { return string.Empty; } int castleTerritoryIndex = ExtraditionService.GetCastleTerritoryIndex(entityOnServer); string castleTerritoryRegionName = ExtraditionService.GetCastleTerritoryRegionName(entityOnServer); string text = ((castleTerritoryIndex < 0) ? string.Empty : ((castleTerritoryRegionName.Length > 0) ? (G("(Plot ") + P($"{castleTerritoryIndex}") + G(", " + castleTerritoryRegionName + ")")) : (G("(Plot ") + P($"{castleTerritoryIndex}") + G(")")))); if (!includeName) { return text; } if (!entityOnServer.Has()) { return text; } UserOwner val2 = entityOnServer.Read(); Entity entityOnServer2 = ((NetworkedEntity)(ref val2.Owner)).GetEntityOnServer(); if (((Entity)(ref entityOnServer2)).Equals(Entity.Null) || !entityOnServer2.Has()) { return text; } User val3 = entityOnServer2.Read(); string s = ((object)(*(FixedString64Bytes*)(&val3.CharacterName))/*cast due to .constrained prefix*/).ToString(); string text2 = G("in ") + M(s) + G("'s castle"); if (text.Length <= 0) { return text2; } return text2 + " " + text; } private static string Join(string main, string loc) { if (loc.Length <= 0) { return main; } return main + " " + loc; } private static bool HasBuff(Entity e, int guid) { //IL_0002: 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_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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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) if (((Entity)(ref e)).Equals(Entity.Null) || !e.Has()) { return false; } EntityManager entityManager = Core.EntityManager; DynamicBuffer buffer = ((EntityManager)(ref entityManager)).GetBuffer(e, false); for (int i = 0; i < buffer.Length; i++) { if (buffer[i].PrefabGuid._Value == guid) { return true; } } return false; } [HarmonyPrefix] private unsafe static void Prefix(BuffSystem_Spawn_Server __instance) { //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_0033: 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_0058: 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_0072: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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_00a7: 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: 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_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: 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_00f8: 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_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0138: 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_013c: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: 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_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_0369: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Expected O, but got Unknown //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Expected O, but got Unknown //IL_022c: 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_0397: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_0296: 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) if (!Core._hasInitialized) { return; } EntityQuery query = __instance._Query; NativeArray val = ((EntityQuery)(ref query)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { Enumerator enumerator = val.GetEnumerator(); FixedString512Bytes val3 = default(FixedString512Bytes); bool flag3 = default(bool); while (enumerator.MoveNext()) { Entity current = enumerator.Current; try { if (current.Read()._Value != -1939804277) { continue; } Entity owner = current.Read().Owner; if (((Entity)(ref owner)).Equals(Entity.Null) || !owner.Has() || !HasBuff(owner, -1988445418)) { continue; } Entity target = current.Read().Target; if (!target.Has()) { continue; } Entity userEntity = target.Read().UserEntity; if (((Entity)(ref userEntity)).Equals(Entity.Null)) { continue; } Entity prisonCellEntity = owner.Read().PrisonCellEntity; if (((Entity)(ref prisonCellEntity)).Equals(Entity.Null)) { continue; } (Entity Cell, ExtraditionService.RoutingOutcome Outcome) tuple = Core.Extradition.FindBestCell(userEntity, owner, prisonCellEntity); Entity item = tuple.Cell; ExtraditionService.RoutingOutcome item2 = tuple.Outcome; bool flag = !((Entity)(ref item)).Equals(Entity.Null) && !((Entity)(ref item)).Equals(prisonCellEntity); bool flag2 = Core.Extradition.GetTargetTerritory(userEntity) >= 0; if (flag) { ExtraditionService.RedirectPrisoner(owner, prisonCellEntity, item); } if (userEntity.Has()) { User val2 = userEntity.Read(); ((FixedString512Bytes)(ref val3))..ctor(item2 switch { ExtraditionService.RoutingOutcome.MarkedTerritory => Join(G("Prisoner routed to ") + M("your") + P(" marked territory"), CellLocation(item)), ExtraditionService.RoutingOutcome.OwnCastle => flag2 ? Join(G("No room in ") + M("your") + P(" marked territory;") + G(" routed to ") + M("your") + G(" castle holding cell instead"), CellLocation(item, includeName: false)) : Join(G("Prisoner routed to ") + M("your") + G(" castle holding cell"), CellLocation(item, includeName: false)), _ => flag2 ? Join(G("No room in ") + M("your") + G(" marked territory or castle; prisoner held"), CellLocation(prisonCellEntity)) : Join(G("No empty cell in ") + M("your") + G(" castle; prisoner held"), CellLocation(prisonCellEntity)), }); ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, val2, ref val3); } object obj; if (!userEntity.Has()) { obj = "Unknown"; } else { User val4 = userEntity.Read(); obj = ((object)(*(FixedString64Bytes*)(&val4.CharacterName))/*cast due to .constrained prefix*/).ToString(); } string text = (string)obj; if (flag) { ManualLogSource log = Core.Log; BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(36, 3, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("[KinCaller] "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted(text); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" routed prisoner to "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted(ExtraditionService.DescribeCellPlain(item)); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" ["); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted(item2); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("]."); } log.LogInfo(val5); } else { ManualLogSource log2 = Core.Log; BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(34, 3, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("[KinCaller] "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted(text); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" left prisoner in "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted(ExtraditionService.DescribeCellPlain(prisonCellEntity)); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" ["); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted(item2); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("]."); } log2.LogInfo(val5); } } catch (Exception e) { Core.LogException(e, "Prefix"); } } } finally { val.Dispose(); } } } [HarmonyPatch(typeof(SpawnTeamSystem_OnPersistenceLoad), "OnUpdate")] public static class InitializationPatch { [HarmonyPostfix] public static void OneShot_AfterLoad_InitializationPatch() { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown Core.InitializeAfterLoaded(); try { MethodInfo method = typeof(SpawnTeamSystem_OnPersistenceLoad).GetMethod("OnUpdate", Type.EmptyTypes); MethodInfo method2 = typeof(InitializationPatch).GetMethod("OneShot_AfterLoad_InitializationPatch"); if (method != null && method2 != null) { Plugin.Harmony.Unpatch((MethodBase)method, method2); } else { Core.Log.LogWarning((object)"[KinCaller] Could not resolve OnUpdate/OneShot for unpatch; patch will remain installed."); } } catch (Exception ex) { ManualLogSource log = Core.Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[KinCaller] Failed to unpatch InitializationPatch: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex.Message); } log.LogError(val); } } } [HarmonyPatch(typeof(SetMapMarkerSystem), "OnUpdate")] internal static class SetMapMarkerSystemPatch { private const int DominateBuff = -1447419822; private static string P(string s) { return "" + s + ""; } private static string G(string s) { return "" + s + ""; } private static string M(string s) { return "" + s + ""; } [HarmonyPrefix] private unsafe static void Prefix(SetMapMarkerSystem __instance) { //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_0033: 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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_0064: 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_006b: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007f: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: 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_00c5: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown //IL_0152: 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_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0119: 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_0133: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) if (!Core._hasInitialized) { return; } EntityQuery query = __instance._Query; NativeArray val = ((EntityQuery)(ref query)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); try { Enumerator enumerator = val.GetEnumerator(); bool flag = default(bool); while (enumerator.MoveNext()) { Entity current = enumerator.Current; try { FromCharacter val2 = current.Read(); if (!HasDominateBuff(val2.Character)) { continue; } Entity user = val2.User; if (!user.Has()) { continue; } User val3 = user.Read(); float2 position = current.Read().Position; int territoryIndex = Core.CastleTerritory.GetTerritoryIndex(new float3(position.x, 0f, position.y)); Entity heartForTerritory = Core.CastleTerritory.GetHeartForTerritory(territoryIndex); Entity heartOwnerFromHeart = ExtraditionService.GetHeartOwnerFromHeart(heartForTerritory); if (!((Entity)(ref heartForTerritory)).Equals(Entity.Null) && ExtraditionService.IsOwnerAllied(heartOwnerFromHeart, user) && Core.Extradition.GetTargetTerritory(user) != territoryIndex) { Core.Extradition.SetTargetTerritory(user, territoryIndex); ManualLogSource log = Core.Log; BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(39, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[KinCaller] "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted(val3.CharacterName); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" set DuskCaller target to "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted(ExtraditionService.DescribeHeartPlain(heartForTerritory)); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("."); } log.LogInfo(val4); int castleTerritoryIndex = ExtraditionService.GetCastleTerritoryIndex(heartForTerritory); string castleTerritoryRegionName = ExtraditionService.GetCastleTerritoryRegionName(heartForTerritory); bool num = heartOwnerFromHeart == user; object obj; if (!heartOwnerFromHeart.Has()) { obj = ""; } else { User val5 = heartOwnerFromHeart.Read(); obj = ((object)(*(FixedString64Bytes*)(&val5.CharacterName))/*cast due to .constrained prefix*/).ToString(); } string text = (string)obj; string text2 = (num ? (M("your") + G(" territory")) : ((text.Length > 0) ? (M(text) + G("'s territory")) : G("an allied territory"))); string text3 = ((castleTerritoryIndex >= 0) ? (" " + ((castleTerritoryRegionName.Length > 0) ? (G("(Plot ") + P($"{castleTerritoryIndex}") + G(", " + castleTerritoryRegionName + ")")) : (G("(Plot ") + P($"{castleTerritoryIndex}") + G(")")))) : ""); int num2 = Core.Extradition.CountEmptyCellsInTerritory(territoryIndex); string text4 = ((num2 > 0) ? (G(". ") + P($"{num2}") + G((num2 == 1) ? " empty holding cell." : " empty holding cells.")) : (G(". ") + P("0") + G(" empty holding cells. Prisoners will fall back to ") + M("your") + G(" nearest castle."))); Send(val3, P("DuskCaller target set ") + G("to ") + text2 + text3 + text4); } } catch (Exception e) { Core.LogException(e, "Prefix"); } } } finally { val.Dispose(); } } private static bool HasDominateBuff(Entity character) { //IL_0002: 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_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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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) if (((Entity)(ref character)).Equals(Entity.Null) || !character.Has()) { return false; } EntityManager entityManager = Core.EntityManager; DynamicBuffer buffer = ((EntityManager)(ref entityManager)).GetBuffer(character, false); for (int i = 0; i < buffer.Length; i++) { if (buffer[i].PrefabGuid._Value == -1447419822) { return true; } } return false; } private static void Send(User user, string message) { //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) FixedString512Bytes val = FixedString512Bytes.op_Implicit(message); ServerChatUtils.SendSystemMessageToClient(Core.EntityManager, user, ref val); } } } namespace KinCaller.Commands { [CommandGroup("caller", null)] internal class CallerCommands { private static string P(string s) { return "" + s + ""; } private static string G(string s) { return "" + s + ""; } private static string M(string s) { return "" + s + ""; } private static bool NotReady(ChatCommandContext ctx) { if (Core.Extradition != null && Core.CastleTerritory != null) { return false; } ctx.Reply(G("Still starting up, please try again in a moment.")); return true; } [Command("status", null, null, "Show your current extradition target territory.", null, false)] public unsafe static void Status(ChatCommandContext ctx) { //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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: 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_00f8: 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_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0100: 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_018c: 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_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) if (NotReady(ctx)) { return; } Entity senderUserEntity = ctx.Event.SenderUserEntity; int targetTerritory = Core.Extradition.GetTargetTerritory(senderUserEntity); if (targetTerritory < 0) { ctx.Reply(G("No DuskCaller target set. Captures go to ") + M("your") + G(" own holding cells. While dominating, place a map marker on ") + M("your") + G(" own or an allied territory to route captures there instead.")); return; } Entity heartForTerritory = Core.CastleTerritory.GetHeartForTerritory(targetTerritory); if (((Entity)(ref heartForTerritory)).Equals(Entity.Null)) { ctx.Reply(G("Target territory: Plot ") + P($"{targetTerritory}") + G(". No castle there now. Prisoners will route to ") + M("your") + G(" nearest castle until you re-mark.")); return; } Entity heartOwnerFromHeart = ExtraditionService.GetHeartOwnerFromHeart(heartForTerritory); if (!ExtraditionService.IsOwnerAllied(heartOwnerFromHeart, senderUserEntity)) { ctx.Reply(G("Target territory: Plot ") + P($"{targetTerritory}") + G(". No longer ") + M("your") + G(" own or an allied castle. Prisoners will route to ") + M("your") + G(" nearest castle. Re-mark to update.")); return; } bool num = heartOwnerFromHeart == senderUserEntity; object obj; if (!heartOwnerFromHeart.Has()) { obj = "Unknown"; } else { User val = heartOwnerFromHeart.Read(); obj = ((object)(*(FixedString64Bytes*)(&val.CharacterName))/*cast due to .constrained prefix*/).ToString(); } string s = (string)obj; string castleTerritoryRegionName = ExtraditionService.GetCastleTerritoryRegionName(heartForTerritory); string text = (num ? (M("your") + G(" territory")) : (M(s) + G("'s territory"))); string text2 = ((castleTerritoryRegionName.Length > 0) ? (", " + castleTerritoryRegionName) : ""); ctx.Reply(P("DuskCaller target: ") + text + " " + G("(Plot ") + P($"{targetTerritory}") + G(text2 + ")")); int num2 = Core.Extradition.CountEmptyCellsInTerritory(targetTerritory); ctx.Reply((num2 > 0) ? (G("Empty holding cells in that territory: ") + P($"{num2}")) : (G("Empty holding cells in that territory: ") + P("0") + G(". Prisoners will fall back to ") + M("your") + G(" nearest castle."))); } [Command("clear", null, null, "Clear your extradition target territory.", null, false)] public static void Clear(ChatCommandContext ctx) { //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_001a: Unknown result type (might be due to invalid IL or missing references) if (!NotReady(ctx)) { Entity senderUserEntity = ctx.Event.SenderUserEntity; if (Core.Extradition.ClearTarget(senderUserEntity)) { ctx.Reply(P("DuskCaller target cleared.") + " " + G("Captures now go to ") + M("your") + G(" own holding cells.")); } else { ctx.Reply(G("You have no DuskCaller target set.")); } } } } }