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.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime; using Il2CppInterop.Runtime.Injection; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Microsoft.CodeAnalysis; using ProjectM; using ProjectM.Gameplay.Systems; using ProjectM.Network; using ProjectM.Scripting; using ProjectM.Shared; using ProjectM.UI; using Stunlock.Core; using Unity.Collections; using Unity.Entities; using Unity.Mathematics; using Unity.Transforms; using UnityEngine; using XPShared.Events; using XPShared.Hooks; using XPShared.Services; using XPShared.Transport.Messages; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("XPRising.XPShared")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Framework for transport between server and client for XPRising ClientUI")] [assembly: AssemblyFileVersion("0.5.2.0")] [assembly: AssemblyInformationalVersion("0.5.2+1.Branch.main.Sha.87328b40f46456fe5a53cd05519afe51105b8a20.87328b40f46456fe5a53cd05519afe51105b8a20")] [assembly: AssemblyProduct("XPRising.XPShared")] [assembly: AssemblyTitle("XPRising.XPShared")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.5.2.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.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = 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 XPShared { public static class Extensions { public delegate void WithRefHandler(ref T item); private static EntityManager EntityManager => Plugin.World.EntityManager; private static ClientGameManager ClientGameManager => Plugin.ClientGameManager; private static SystemService SystemService => Plugin.SystemService; private static PrefabCollectionSystem PrefabCollectionSystem => SystemService.PrefabCollectionSystem; public static void With(this Entity entity, WithRefHandler action) where T : struct { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) T item = entity.ReadRW(); action(ref item); EntityManager entityManager = EntityManager; ((EntityManager)(ref entityManager)).SetComponentData(entity, item); } public static void AddWith(this Entity entity, WithRefHandler action) where T : struct { //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_0008: Unknown result type (might be due to invalid IL or missing references) if (!entity.Has()) { entity.Add(); } entity.With(action); } public unsafe static void Write(this Entity entity, T componentData) where T : struct { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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) TypeIndex typeIndex = new ComponentType(Il2CppType.Of(), (AccessMode)0).TypeIndex; byte[] array = StructureToByteArray(componentData); int num = Marshal.SizeOf(); fixed (byte* ptr = array) { EntityManager entityManager = EntityManager; ((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, typeIndex, (void*)ptr, num); } } private static byte[] StructureToByteArray(T structure) where T : struct { int num = Marshal.SizeOf(structure); byte[] array = new byte[num]; IntPtr intPtr = Marshal.AllocHGlobal(num); Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true); Marshal.Copy(intPtr, array, 0, num); Marshal.FreeHGlobal(intPtr); return array; } private unsafe static T ReadRW(this Entity entity) where T : struct { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_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) TypeIndex typeIndex = new ComponentType(Il2CppType.Of(), (AccessMode)0).TypeIndex; EntityManager entityManager = EntityManager; return Marshal.PtrToStructure(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRW(entity, typeIndex))); } public unsafe static T Read(this Entity entity) where T : struct { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_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) TypeIndex typeIndex = new ComponentType(Il2CppType.Of(), (AccessMode)0).TypeIndex; EntityManager entityManager = EntityManager; return Marshal.PtrToStructure(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, typeIndex))); } public static DynamicBuffer ReadBuffer(this Entity entity) where T : struct { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).GetBuffer(entity, false); } public static DynamicBuffer AddBuffer(this Entity entity) where T : struct { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).AddBuffer(entity); } public unsafe static void* GetComponentData(this Entity entity, TypeIndex typeIndex) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, typeIndex); } public unsafe static void SetComponentData(this Entity entity, TypeIndex typeIndex, void* byteData, int size) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; ((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, typeIndex, byteData, size); } public unsafe static void* GetBufferData(this Entity entity, TypeIndex typeIndex) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).GetBufferRawRO(entity, typeIndex); } public static int GetBufferLength(this Entity entity, TypeIndex typeIndex) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).GetBufferLength(entity, typeIndex); } public static void SetBufferData(Entity prefabSource, T[] bufferArray) where T : struct { //IL_0000: 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_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) DynamicBuffer val = (prefabSource.Has() ? prefabSource.ReadBuffer() : prefabSource.AddBuffer()); val.Clear(); foreach (T val2 in bufferArray) { val.Add(val2); } } public static bool TryGetComponent(this Entity entity, out T componentData) where T : struct { //IL_0007: 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) componentData = default(T); if (entity.Has()) { componentData = entity.Read(); return true; } return false; } public static bool TryGetComponentObject(this Entity entity, EntityManager entityManager, out T componentObject) where T : class { //IL_0009: 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) componentObject = null; if (((EntityManager)(ref entityManager)).HasComponent(entity)) { componentObject = ((EntityManager)(ref entityManager)).GetComponentObject(entity); return componentObject != null; } return false; } public static bool TryRemoveComponent(this Entity entity) where T : struct { //IL_0000: 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 (entity.Has()) { entity.Remove(); return true; } return false; } public static bool Has(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).HasComponent(entity, new ComponentType(Il2CppType.Of(), (AccessMode)0)); } public static bool Has(this Entity entity, ComponentType componentType) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).HasComponent(entity, componentType); } public static void Add(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; ((EntityManager)(ref entityManager)).AddComponent(entity, new ComponentType(Il2CppType.Of(), (AccessMode)0)); } public static void Add(this Entity entity, ComponentType componentType) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; ((EntityManager)(ref entityManager)).AddComponent(entity, componentType); } public static void Remove(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; ((EntityManager)(ref entityManager)).RemoveComponent(entity, new ComponentType(Il2CppType.Of(), (AccessMode)0)); } public static bool TryGetFollowedPlayer(this Entity entity, out Entity player) { //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_000b: 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_001b: Unknown result type (might be due to invalid IL or missing references) player = Entity.Null; if (entity.TryGetComponent(out Follower componentData) && componentData.Followed._Value.TryGetPlayer(out player)) { return true; } return false; } public static bool TryGetPlayer(this Entity entity, out Entity player) { //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_000b: 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) player = Entity.Null; if (entity.Has()) { player = entity; return true; } return false; } public static bool IsPlayer(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if (entity.Has()) { return true; } return false; } public static bool IsDifferentPlayer(this Entity entity, Entity target) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (entity.IsPlayer() && target.IsPlayer() && !((Entity)(ref entity)).Equals(target)) { return true; } return false; } public static bool IsFollowingPlayer(this Entity entity) { //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) if (entity.TryGetComponent(out Follower componentData) && componentData.Followed._Value.IsPlayer()) { return true; } return false; } public static Entity GetBuffTarget(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) return CreateGameplayEventServerUtility.GetBuffTarget(EntityManager, entity); } public static Entity GetPrefabEntity(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_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) ClientGameManager clientGameManager = ClientGameManager; return ((ClientGameManager)(ref clientGameManager)).GetPrefabEntity(entity.Read()); } public static Entity GetSpellTarget(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) return CreateGameplayEventServerUtility.GetSpellTarget(EntityManager, entity); } public static bool TryGetTeamEntity(this Entity entity, out Entity teamEntity) { //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_000b: 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_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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) teamEntity = Entity.Null; if (entity.TryGetComponent(out TeamReference componentData)) { Entity value = componentData.Value._Value; if (value.Exists()) { teamEntity = value; return true; } } return false; } public static bool Exists(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) EntityManager entityManager = EntityManager; return ((EntityManager)(ref entityManager)).Exists(entity); } public static bool IsDisabled(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return entity.Has(); } public static bool HasConnectedCoffin(this Entity entity) { //IL_0000: 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) if (entity.TryGetComponent(out ServantConnectedCoffin componentData)) { return ((NetworkedEntity)(ref componentData.CoffinEntity)).GetEntityOnServer().Exists(); } return false; } public static bool IsVBlood(this Entity entity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return entity.Has(); } public static ulong GetSteamId(this Entity entity) { //IL_0000: 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_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_0025: Unknown result type (might be due to invalid IL or missing references) if (entity.TryGetComponent(out PlayerCharacter componentData)) { return componentData.UserEntity.Read().PlatformId; } if (entity.TryGetComponent(out User componentData2)) { return componentData2.PlatformId; } return 0uL; } public static NetworkId GetNetworkId(this Entity entity) { //IL_0000: 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) //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (entity.TryGetComponent(out NetworkId componentData)) { return componentData; } return NetworkId.Empty; } public static void ForEach(this IEnumerable source, Action action) { foreach (T item in source) { action(item); } } public static PrefabGUID GetPrefabGUID(this Entity entity) { //IL_0000: 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) //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (entity.TryGetComponent(out PrefabGUID componentData)) { return componentData; } return PrefabGUID.Empty; } public static Entity GetUserEntity(this Entity character) { //IL_0000: 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_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) if (character.TryGetComponent(out PlayerCharacter componentData)) { return componentData.UserEntity; } return Entity.Null; } public static User GetUser(this Entity entity) { //IL_0000: 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_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_0027: 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_0019: Unknown result type (might be due to invalid IL or missing references) if (entity.TryGetComponent(out PlayerCharacter componentData) && componentData.UserEntity.TryGetComponent(out User componentData2)) { return componentData2; } if (entity.TryGetComponent(out componentData2)) { return componentData2; } return User.Empty; } public static bool HasBuff(this Entity entity, PrefabGUID buffPrefabGUID) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return GameManager_Shared.HasBuff(EntityManager, entity, ((PrefabGUID)(ref buffPrefabGUID)).ToIdentifier()); } public static bool TryGetBuff(this Entity entity, PrefabGUID buffPrefabGUID, out Entity buffEntity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (GameManager_Shared.TryGetBuff(EntityManager, entity, ((PrefabGUID)(ref buffPrefabGUID)).ToIdentifier(), ref buffEntity)) { return true; } return false; } public static bool TryGetBuffer(this Entity entity, out DynamicBuffer dynamicBuffer) where T : struct { //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_0011: Unknown result type (might be due to invalid IL or missing references) if (GameManager_Shared.TryGetBuffer(EntityManager, entity, ref dynamicBuffer)) { return true; } dynamicBuffer = default(DynamicBuffer); return false; } public static float3 GetAimPosition(this Entity entity) { //IL_0000: 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_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) if (entity.TryGetComponent(out EntityInput componentData)) { return componentData.AimPosition; } return float3.zero; } public static bool TryGetPosition(this Entity entity, out float3 position) { //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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_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) position = float3.zero; if (entity.TryGetComponent(out Translation componentData)) { position = componentData.Value; return true; } return false; } public static float3 GetPosition(this Entity entity) { //IL_0000: 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_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) if (entity.TryGetComponent(out Translation componentData)) { return componentData.Value; } return float3.zero; } public static bool TryGetMatch(this HashSet<(ulong, ulong)> hashSet, ulong value, out (ulong, ulong) matchingPair) { matchingPair = default((ulong, ulong)); foreach (var item in hashSet) { if (item.Item1 == value || item.Item2 == value) { matchingPair = item; return true; } } return false; } public static bool IsCustomSpawned(this Entity entity) { //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) if (entity.TryGetComponent(out IsMinion componentData) && componentData.Value) { return true; } return false; } public static void Destroy(this Entity entity) { //IL_0000: 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_000d: Unknown result type (might be due to invalid IL or missing references) if (entity.Exists()) { DestroyUtility.Destroy(EntityManager, entity, (DestroyDebugReason)0, (string)null, 0); } } public static void SetTeam(this Entity entity, Entity teamSource) { //IL_0000: 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_0010: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_0059: Unknown result type (might be due to invalid IL or missing references) if (entity.Has() && entity.Has() && teamSource.TryGetComponent(out Team componentData) && teamSource.TryGetComponent(out TeamReference componentData2)) { Entity teamRefEntity = componentData2.Value._Value; int teamId = componentData.Value; entity.With((WithRefHandler)delegate(ref TeamReference teamReference) { //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) teamReference.Value._Value = teamRefEntity; }); entity.With((WithRefHandler)delegate(ref Team team) { team.Value = teamId; }); } } public static void SetFaction(this Entity entity, PrefabGUID factionPrefabGUID) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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) if (entity.Has()) { entity.With((WithRefHandler)delegate(ref FactionReference factionReference) { //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) factionReference.FactionGuid._Value = factionPrefabGUID; }); } } public static bool HasValue(this Entity entity) { //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) return entity != Entity.Null; } public static bool IsAllied(this Entity entity, Entity player) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) ClientGameManager clientGameManager = ClientGameManager; return ((ClientGameManager)(ref clientGameManager)).IsAllies(entity, player); } } public class FrameTimer { private bool _enabled; private bool _isRunning; private int _runCount; private int _maxRunCount; private DateTime _executeAfter = DateTime.MinValue; private DateTime _lastExecution = DateTime.MinValue; private DateTime _startTime = DateTime.MinValue; private TimeSpan _delay; private Action _action; private Func _delayGenerator; public TimeSpan TimeSinceLastRun => DateTime.Now - _lastExecution; public int RunCount => _runCount; public TimeSpan TimeSinceStart { get { if (!_enabled) { return DateTime.Now - _startTime; } return TimeSpan.Zero; } } public bool Enabled => _enabled; public FrameTimer Initialise(Action action, TimeSpan delay, int runCount = 1) { _delayGenerator = null; _delay = delay; _executeAfter = DateTime.Now + delay; _action = action; _maxRunCount = runCount; return this; } public FrameTimer Initialise(Action action, Func delayGenerator, int runCount = 1) { _delayGenerator = delayGenerator; _delay = _delayGenerator(); _executeAfter = DateTime.Now + _delay; _action = action; _maxRunCount = runCount; return this; } public void Start() { Refresh(); if (!_enabled) { _startTime = DateTime.Now; _runCount = 0; _lastExecution = DateTime.MinValue; GameFrame.OnUpdate += GameFrame_OnUpdate; _enabled = true; } } public void Stop() { if (_enabled) { GameFrame.OnUpdate -= GameFrame_OnUpdate; _enabled = false; } } private void Refresh() { if (_delayGenerator != null) { _delay = _delayGenerator(); } _executeAfter = DateTime.Now + _delay; } private void GameFrame_OnUpdate() { Update(); } private void Update() { if (!_enabled || _isRunning || _executeAfter >= DateTime.Now) { return; } _isRunning = true; try { _action(); _lastExecution = DateTime.Now; } catch (Exception ex) { Plugin.Log((LogLevel)2, "Timer failed " + ex.Message + "\n" + ex.StackTrace); Stop(); } finally { _runCount++; if (_maxRunCount > 0 && _runCount >= _maxRunCount) { Stop(); } else { Refresh(); } _isRunning = false; } } } public delegate void GameFrameUpdateEventHandler(); public class GameFrame : MonoBehaviour { private static GameFrame? _instance; public static event GameFrameUpdateEventHandler? OnUpdate; public static event GameFrameUpdateEventHandler? OnLateUpdate; private void Update() { try { GameFrame.OnUpdate?.Invoke(); } catch (Exception ex) { Plugin.Log((LogLevel)2, "Error dispatching OnUpdate event:"); Plugin.Log((LogLevel)2, ex.ToString()); } } private void LateUpdate() { try { GameFrame.OnLateUpdate?.Invoke(); } catch (Exception ex) { Plugin.Log((LogLevel)2, "Error dispatching OnLateUpdate event:"); Plugin.Log((LogLevel)2, ex.ToString()); } } public static void Initialize(Plugin plugin) { if (!ClassInjector.IsTypeRegisteredInIl2Cpp()) { ClassInjector.RegisterTypeInIl2Cpp(); } _instance = ((BasePlugin)plugin).AddComponent(); } public static void Uninitialize() { GameFrame.OnUpdate = null; GameFrame.OnLateUpdate = null; Object.Destroy((Object)(object)_instance); _instance = null; } } [BepInPlugin("XPRising.XPShared", "XPRising.XPShared", "0.5.2")] public class Plugin : BasePlugin { private static SystemService _systemService; private static ManualLogSource _logger; private static Harmony _harmonyBootPatch; public static World World; public static SystemService SystemService => _systemService ?? (_systemService = new SystemService(World)); public static ClientGameManager ClientGameManager => SystemService.ClientScriptMapper._ClientGameManager; public static bool IsDebug { get; private set; } public static bool IsServer => Application.productName == "VRisingServer"; public static bool IsClient => Application.productName == "VRising"; public static bool IsInitialised { get; private set; } public override void Load() { _logger = ((BasePlugin)this).Log; IsDebug = typeof(Plugin).Assembly.GetCustomAttribute()?.Configuration == "Debug"; VEvents.Initialize(); if (IsClient) { ClientChatPatch.Initialize(); } else if (IsServer) { ServerChatPatch.Initialize(); ChatService.ListenForClientRegister(); new ServerEvents.CombatEvents.PlayerKillModule(); } _harmonyBootPatch = Harmony.CreateAndPatchAll(typeof(GameManangerPatch), (string)null); GameFrame.Initialize(this); Log((LogLevel)16, "Plugin is loaded [version: 0.5.2]"); } public override bool Unload() { if (IsClient) { ClientChatPatch.Uninitialize(); } else if (IsServer) { ServerChatPatch.Uninitialize(); } GameFrame.Uninitialize(); return true; } public static void GameDataOnInitialize(World world) { World = world; IsInitialised = true; } public static void Log(LogLevel level, string message) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_0022: Expected O, but got Unknown //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (IsDebug || (int)level <= 16) { ManualLogSource logger = _logger; bool flag = default(bool); BepInExLogInterpolatedStringHandler val = new BepInExLogInterpolatedStringHandler(13, 2, level, ref flag); if (flag) { val.AppendFormatted(DateTime.Now, "u"); val.AppendLiteral(": [XPShared] "); val.AppendFormatted(message); } logger.Log(level, val); } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "XPRising.XPShared"; public const string PLUGIN_NAME = "XPRising.XPShared"; public const string PLUGIN_VERSION = "0.5.2"; } } namespace XPShared.Transport { public delegate void ServerMessageHandler(User fromCharacter, ClientAction msg); public class MessageHandler { public static event ServerMessageHandler OnServerMessageEvent; public static void ServerSendToClient(User toCharacter, T msg) where T : IChatMessage { //IL_0038: Unknown result type (might be due to invalid IL or missing references) Plugin.Log((LogLevel)32, $"[SERVER] [SEND] {msg.GetType()}"); ChatService.SendToClient(toCharacter, msg); } internal static void ServerReceiveFromClient(User fromCharacter, ClientAction msg) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) Plugin.Log((LogLevel)32, $"[SERVER] [RECEIVED] ClientAction {msg.Action} {msg.Value}"); MessageHandler.OnServerMessageEvent?.Invoke(fromCharacter, msg); } } public static class Utils { public static void ServerSetBarData(User playerCharacter, string barGroup, string bar, string header, float progressPercentage, string tooltip, ProgressSerialisedMessage.ActiveState activeState, string colour, string change = "", bool flash = false) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) ProgressSerialisedMessage msg = new ProgressSerialisedMessage { Group = barGroup, Label = bar, ProgressPercentage = progressPercentage, Header = header, Tooltip = tooltip, Active = activeState, Colour = colour, Change = change, Flash = flash }; MessageHandler.ServerSendToClient(playerCharacter, msg); } public static void ServerSetAction(User playerCharacter, string group, string id, string label, string colour = "#808080") { //IL_0023: Unknown result type (might be due to invalid IL or missing references) ActionSerialisedMessage msg = new ActionSerialisedMessage { Group = group, ID = id, Label = label, Colour = colour }; MessageHandler.ServerSendToClient(playerCharacter, msg); } public static void ServerSendNotification(User playerCharacter, string id, string message, LogLevel severity, string colourOverride = "") { //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_0023: Unknown result type (might be due to invalid IL or missing references) NotificationMessage msg = new NotificationMessage { ID = id, Message = message, Severity = severity, Colour = colourOverride }; MessageHandler.ServerSendToClient(playerCharacter, msg); } public static void ServerSendText(User playerCharacter, string group, string id, string title, string text) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) DisplayTextMessage msg = new DisplayTextMessage { Group = group, ID = id, Title = title, Text = text, Reset = true }; MessageHandler.ServerSendToClient(playerCharacter, msg); } public static void ServerSendText(User playerCharacter, string group, string id, string title, List text) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) foreach (DisplayTextMessage item in text.Select((string message, int index) => new DisplayTextMessage { Group = group, ID = id, Title = title, Text = message, Reset = (index == 0) })) { MessageHandler.ServerSendToClient(playerCharacter, item); } } } } namespace XPShared.Transport.Messages { public class ActionSerialisedMessage : IChatMessage { public string Group = ""; public string ID = ""; public string Label = ""; public string Colour = "#808080"; public bool Enabled = true; public void Serialize(BinaryWriter writer) { writer.Write(Group); writer.Write(ID); writer.Write(Label); writer.Write(Colour); writer.Write(Enabled); } public void Deserialize(BinaryReader reader) { Group = reader.ReadString(); ID = reader.ReadString(); Label = reader.ReadString(); Colour = reader.ReadString(); Enabled = reader.ReadBoolean(); } } public class ClientAction : IChatMessage { public enum ActionType { Connect, Disconnect, ButtonClick, Register } public ActionType Action { get; private set; } public string Value { get; private set; } public ClientAction() { Value = ""; } public ClientAction(ActionType actionType, string value) { Action = actionType; Value = value; } public void Serialize(BinaryWriter writer) { writer.Write(Enum.GetName(Action)); writer.Write(Value); } public void Deserialize(BinaryReader reader) { Action = Enum.Parse(reader.ReadString()); Value = reader.ReadString(); } } public class ClientRegisterMessage : IChatMessage { public int ClientNonce { get; private set; } public ulong SteamId { get; set; } public ClientRegisterMessage() { ClientNonce = 0; SteamId = 0uL; } public ClientRegisterMessage(int clientNonce, ulong steamId) { ClientNonce = clientNonce; SteamId = steamId; } public void Serialize(BinaryWriter writer) { writer.Write(ClientNonce); writer.Write(SteamId); } public void Deserialize(BinaryReader reader) { ClientNonce = reader.ReadInt32(); SteamId = reader.ReadUInt64(); } } public class ConnectedMessage : IChatMessage { public void Serialize(BinaryWriter writer) { } public void Deserialize(BinaryReader reader) { } } public class DisplayTextMessage : IChatMessage { public string Group = ""; public string ID = ""; public string Title = ""; public string Text = ""; public bool Reset = true; public void Serialize(BinaryWriter writer) { writer.Write(Group); writer.Write(ID); writer.Write(Title); writer.Write(Text); writer.Write(Reset); } public void Deserialize(BinaryReader reader) { Group = reader.ReadString(); ID = reader.ReadString(); Title = reader.ReadString(); Text = reader.ReadString(); Reset = reader.ReadBoolean(); } } public interface IChatMessage { internal const int CHAT_NETWORK_EVENT_ID = 218160557; internal static void WriteHeader(BinaryWriter writer, string type, int clientNonce) { writer.Write(218160557); writer.Write(clientNonce); writer.Write(type); } internal static bool ReadHeader(BinaryReader reader, out int clientNonce, out string type) { type = ""; clientNonce = 0; try { int num = reader.ReadInt32(); clientNonce = reader.ReadInt32(); type = reader.ReadString(); return num == 218160557; } catch (Exception ex) { Plugin.Log((LogLevel)32, "Failed to read chat message header: " + ex.Message); return false; } } void Serialize(BinaryWriter writer); void Deserialize(BinaryReader reader); } public class NotificationMessage : IChatMessage { public string ID = ""; public string Message = ""; public LogLevel Severity = (LogLevel)8; public string Colour = ""; public void Serialize(BinaryWriter writer) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected I4, but got Unknown writer.Write(ID); writer.Write(Message); writer.Write((int)Severity); writer.Write(Colour); } public void Deserialize(BinaryReader reader) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) ID = reader.ReadString(); Message = reader.ReadString(); Severity = (LogLevel)reader.ReadInt32(); Colour = reader.ReadString(); } } public class ProgressSerialisedMessage : IChatMessage { public enum ActiveState { Unchanged, NotActive, Active, OnlyActive, Remove } public string Group = ""; public string Label = ""; public string Header = ""; public float ProgressPercentage; public string Tooltip = ""; public ActiveState Active; public string Change = ""; public string Colour = ""; public bool Flash; public void Serialize(BinaryWriter writer) { writer.Write(Group); writer.Write(Label); writer.Write(Header); writer.Write(ProgressPercentage); writer.Write(Tooltip); writer.Write((int)Active); writer.Write(Change); writer.Write(Colour); writer.Write(Flash); } public void Deserialize(BinaryReader reader) { Group = reader.ReadString(); Label = reader.ReadString(); Header = reader.ReadString(); ProgressPercentage = reader.ReadSingle(); Tooltip = reader.ReadString(); Active = (ActiveState)reader.ReadInt32(); Change = reader.ReadString(); Colour = reader.ReadString(); Flash = reader.ReadBoolean(); } } } namespace XPShared.Services { public delegate void ClientRegisterMessageHandler(ulong steamId); public static class ChatService { private static readonly Dictionary EventHandlers = new Dictionary(); private static readonly Dictionary SupportedUsers = new Dictionary(); private static string ClientRegisterKey = DeriveKey(typeof(ClientRegisterMessage)); public static event ClientRegisterMessageHandler? OnClientRegisterEvent; private static string DeriveKey(Type name) { return name.ToString(); } internal static void Register(ChatEventHandler handler) { string text = DeriveKey(typeof(T)); if (EventHandlers.ContainsKey(text)) { throw new Exception("Network event " + text + " is already registered"); } EventHandlers.Add(text, handler); } internal static void Unregister() { string key = DeriveKey(typeof(T)); EventHandlers.Remove(key); } internal static void ListenForClientRegister() { if (!Plugin.IsClient) { RegisterType(delegate(ClientRegisterMessage message, ulong steamId) { Plugin.Log((LogLevel)16, $"got successful registry: {message.SteamId} -> {message.ClientNonce}"); SupportedUsers[message.SteamId] = message.ClientNonce; ChatService.OnClientRegisterEvent?.Invoke(message.SteamId); }); } } public static void SendToClient(User toCharacter, T msg) where T : IChatMessage { //IL_0011: 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_0035: 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) Plugin.Log((LogLevel)32, "[SERVER] [SEND] IChatMessage"); if (SupportedUsers.TryGetValue(toCharacter.PlatformId, out var value)) { FixedString512Bytes val = FixedString512Bytes.op_Implicit(SerialiseMessage(msg, value) ?? ""); ServerChatUtils.SendSystemMessageToClient(Plugin.World.EntityManager, toCharacter, ref val); } else { Plugin.Log((LogLevel)32, "user nonce not present in supportedUsers"); } } public static void RegisterType(Action onMessageEvent) where T : IChatMessage, new() { Register(new ChatEventHandler { OnReceiveMessage = delegate(BinaryReader binaryReader, ulong steamId) { T arg = new T(); arg.Deserialize(binaryReader); onMessageEvent(arg, steamId); } }); } public static void RegisterClientNonce(ulong steamId, int clientNonce) { if (!Plugin.IsServer) { SupportedUsers[steamId] = clientNonce; } } public static string SerialiseMessage(T msg, int clientNonce) where T : IChatMessage { using MemoryStream memoryStream = new MemoryStream(); using BinaryWriter writer = new BinaryWriter(memoryStream); IChatMessage.WriteHeader(writer, DeriveKey(msg.GetType()), clientNonce); msg.Serialize(writer); return Convert.ToBase64String(memoryStream.ToArray()); } internal static bool DeserialiseMessage(string message, ulong steamId) { string type = ""; try { using MemoryStream input = new MemoryStream(Convert.FromBase64String(message)); using BinaryReader binaryReader = new BinaryReader(input); if (!IChatMessage.ReadHeader(binaryReader, out var clientNonce, out type)) { return false; } int value; bool flag = SupportedUsers.TryGetValue(steamId, out value); bool num = type == ClientRegisterKey; bool flag2 = flag && clientNonce == value; if (num || flag2) { if (EventHandlers.TryGetValue(type, out ChatEventHandler value2)) { value2.OnReceiveMessage(binaryReader, steamId); } } else if (!flag2) { Plugin.Log((LogLevel)4, $"ClientNonce did not match: [registered: {flag}, actual: {clientNonce}, expected: {value}, event: {type}]"); } return true; } catch (FormatException) { Plugin.Log((LogLevel)32, "Invalid base64"); return false; } catch (Exception ex2) { Plugin.Log((LogLevel)2, "Error handling incoming network event " + type + ":"); Plugin.Log((LogLevel)2, ex2.ToString()); return false; } } } internal class ChatEventHandler { internal Action OnReceiveMessage { get; init; } } public class SystemService { private readonly World _world = world ?? throw new ArgumentNullException("world"); private ClientScriptMapper _clientScriptMapper; private PrefabCollectionSystem _prefabCollectionSystem; private GameDataSystem _gameDataSystem; private ManagedDataSystem _managedDataSystem; private TutorialSystem _tutorialSystem; private ServerScriptMapper _serverScriptMapper; private Singleton _networkIdSystem_Singleton; public ClientScriptMapper ClientScriptMapper => _clientScriptMapper ?? (_clientScriptMapper = GetSystem()); public PrefabCollectionSystem PrefabCollectionSystem => _prefabCollectionSystem ?? (_prefabCollectionSystem = GetSystem()); public GameDataSystem GameDataSystem => _gameDataSystem ?? (_gameDataSystem = GetSystem()); public ManagedDataSystem ManagedDataSystem => _managedDataSystem ?? (_managedDataSystem = GetSystem()); public TutorialSystem TutorialSystem => _tutorialSystem ?? (_tutorialSystem = GetSystem()); public ServerScriptMapper ServerScriptMapper => _serverScriptMapper ?? (_serverScriptMapper = GetSystem()); public Singleton NetworkIdSystem { get { //IL_0008: 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_002e: 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) ref Singleton networkIdSystem_Singleton = ref _networkIdSystem_Singleton; object obj = (object)default(Singleton); if (((object)Unsafe.As(ref networkIdSystem_Singleton)/*cast due to .constrained prefix*/).Equals(obj)) { _networkIdSystem_Singleton = GetSingleton(); } return _networkIdSystem_Singleton; } } public SystemService(World world) { } private T GetSystem() where T : ComponentSystemBase { return _world.GetExistingSystemManaged() ?? throw new InvalidOperationException("Failed to get " + Il2CppType.Of().FullName + " from the Server..."); } private T GetSingleton() { T singleton = ((ComponentSystemBase)ServerScriptMapper).GetSingleton(); if (singleton == null) { throw new InvalidOperationException($"[{_world.Name}] - failed to get singleton ({Il2CppType.Of().FullName})"); } return singleton; } } } namespace XPShared.Hooks { public static class ClientChatPatch { private static Harmony? _harmony; private static Entity _localCharacter = Entity.Null; private static Entity _localUser = Entity.Null; public static Entity LocalCharacter { get { //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_002e: 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_0022: Unknown result type (might be due to invalid IL or missing references) if (!(_localCharacter != Entity.Null)) { if (!ConsoleShared.TryGetLocalCharacterInCurrentWorld(ref _localCharacter, Plugin.World)) { return Entity.Null; } return _localCharacter; } return _localCharacter; } } public static Entity LocalUser { get { //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_002e: 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_0022: Unknown result type (might be due to invalid IL or missing references) if (!(_localUser != Entity.Null)) { if (!ConsoleShared.TryGetLocalUserInCurrentWorld(ref _localUser, Plugin.World)) { return Entity.Null; } return _localUser; } return _localUser; } } public static ulong LocalSteamId { get { //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_0014: Unknown result type (might be due to invalid IL or missing references) if (!(_localUser != Entity.Null)) { return 0uL; } return _localUser.GetSteamId(); } } public static void Initialize() { if (_harmony != null) { throw new Exception("Detour already initialized. Plugin will do this for you."); } _harmony = Harmony.CreateAndPatchAll(typeof(ClientChatPatch), "XPRising.XPShared"); } public static void Uninitialize() { if (_harmony == null) { throw new Exception("Detour wasn't initialized. Are you trying to unload twice?"); } _harmony.UnpatchSelf(); } [HarmonyBefore(new string[] { "CrimsonChatFilter" })] [HarmonyPrefix] [HarmonyPatch(typeof(ClientChatSystem), "OnUpdate")] private unsafe static void OnUpdatePrefix(ClientChatSystem __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_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_0030: 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_0039: 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_003f: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Invalid comparison between Unknown and I4 //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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) if (!Plugin.IsClient) { return; } EntityQuery receiveChatMessagesQuery = __instance._ReceiveChatMessagesQuery; Enumerator enumerator = ((EntityQuery)(ref receiveChatMessagesQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator(); while (enumerator.MoveNext()) { Entity current = enumerator.Current; EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager; ChatMessageServerEvent componentData = ((EntityManager)(ref entityManager)).GetComponentData(current); if ((int)componentData.MessageType == 6 && ChatService.DeserialiseMessage(((object)(*(FixedString512Bytes*)(&componentData.MessageText))/*cast due to .constrained prefix*/).ToString(), LocalSteamId)) { entityManager = ((ComponentSystemBase)__instance).EntityManager; ((EntityManager)(ref entityManager)).DestroyEntity(current); } } } public static void ResetUser() { //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_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) _localUser = Entity.Null; _localCharacter = Entity.Null; } } public class GameManangerPatch { [HarmonyPatch(typeof(GameDataManager), "OnUpdate")] [HarmonyPostfix] private static void GameDataManagerOnUpdatePostfix(GameDataManager __instance) { try { if (__instance.GameDataInitialized) { Plugin.GameDataOnInitialize(((ComponentSystemBase)__instance).World); } } catch (Exception ex) { Plugin.Log((LogLevel)2, ex.ToString()); } } } public static class ServerChatPatch { private static Harmony? _harmony; private static EntityManager EntityManager => Plugin.World.EntityManager; public static void Initialize() { if (_harmony != null) { throw new Exception("Detour already initialized. Plugin will do this for you."); } _harmony = Harmony.CreateAndPatchAll(typeof(ServerChatPatch), "XPRising.XPShared"); } public static void Uninitialize() { if (_harmony == null) { throw new Exception("Detour wasn't initialized. Are you trying to unload twice?"); } _harmony.UnpatchSelf(); } [HarmonyBefore(new string[] { "CrimsonChatFilter" })] [HarmonyPatch(typeof(ChatMessageSystem), "OnUpdate")] [HarmonyPrefix] private unsafe static void OnUpdatePrefix(ChatMessageSystem __instance) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_0078: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: 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) if (!Plugin.IsInitialised || !Plugin.IsServer) { return; } EntityQuery val = ((Il2CppArrayBase)(object)((ComponentSystemBase)__instance).EntityQueries)[0]; NativeArray val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)); val = ((Il2CppArrayBase)(object)((ComponentSystemBase)__instance).EntityQueries)[0]; NativeArray val3 = ((EntityQuery)(ref val)).ToComponentDataArray(AllocatorHandle.op_Implicit((Allocator)2)); try { for (int i = 0; i < val2.Length; i++) { Entity val4 = val2[i]; ChatMessageEvent val5 = val3[i]; Plugin.Log((LogLevel)32, ((object)(*(FixedString512Bytes*)(&val5.MessageText))/*cast due to .constrained prefix*/).ToString()); ulong steamId = val4.Read().Character.GetSteamId(); if (ChatService.DeserialiseMessage(((object)(*(FixedString512Bytes*)(&val5.MessageText))/*cast due to .constrained prefix*/).ToString(), steamId)) { EntityManager entityManager = EntityManager; ((EntityManager)(ref entityManager)).DestroyEntity(val4); } } } finally { val2.Dispose(); val3.Dispose(); } } } } namespace XPShared.Events { public static class ServerEvents { public static class BuffEvents { public class BuffGained : VEvents.IGameEvent { public PrefabGUID GUID { get; set; } } public class BuffLost : VEvents.IGameEvent { public PrefabGUID GUID { get; set; } } } public static class CombatEvents { public class CombatStart : VEvents.IGameEvent { public ulong SteamId { get; set; } } public class CombatEnd : VEvents.IGameEvent { public ulong SteamId { get; set; } } public class PlayerKillMob : VEvents.DynamicGameEvent { } public class PlayerKillModule : VEvents.GameEvent { public class Patch { [HarmonyPatch(typeof(DeathEventListenerSystem), "OnUpdate")] public static void Postfix(DeathEventListenerSystem __instance) { //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_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_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_0038: 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_003e: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //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_0096: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: 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_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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_00bc: 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_00cb: 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_00d2: 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_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) if (_instance == null || !_instance.HasSubscribers) { return; } EntityQuery deathEventQuery = __instance._DeathEventQuery; Enumerator enumerator = ((EntityQuery)(ref deathEventQuery)).ToComponentDataArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator(); EntityOwner val2 = default(EntityOwner); while (enumerator.MoveNext()) { DeathEvent current = enumerator.Current; Entity val = current.Killer; EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager; if (((EntityManager)(ref entityManager)).HasComponent(current.Died)) { continue; } entityManager = ((ComponentSystemBase)__instance).EntityManager; if (!((EntityManager)(ref entityManager)).HasComponent(current.Died)) { continue; } entityManager = ((ComponentSystemBase)__instance).EntityManager; if (!((EntityManager)(ref entityManager)).HasComponent(current.Died) || ((Entity)(ref val)).Equals(current.Died)) { continue; } entityManager = ((ComponentSystemBase)__instance).EntityManager; if (((EntityManager)(ref entityManager)).HasComponent(val)) { entityManager = ((ComponentSystemBase)__instance).EntityManager; if (((EntityManager)(ref entityManager)).TryGetComponentData(val, ref val2)) { val = val2.Owner; } } entityManager = ((ComponentSystemBase)__instance).EntityManager; if (((EntityManager)(ref entityManager)).HasComponent(val)) { _instance?.Raise(new PlayerKillMob { Source = val, Target = current.Died }); } } } } private static PlayerKillModule? _instance; private static Harmony? _harmony; public override void Initialize() { _harmony = Harmony.CreateAndPatchAll(typeof(Patch), "XPRising.XPShared"); } public override void Uninitialize() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } public PlayerKillModule() { _instance = this; VEvents.ModuleRegistry.Register(_instance); } } } } public class VEvents { public interface IGameEvent { } public abstract class DynamicGameEvent : EventArgs, IGameEvent { private readonly Dictionary _components = new Dictionary(); public Entity Source { get; set; } public Entity? Target { get; set; } public void AddComponent(T component) where T : struct { _components[typeof(T)] = component; } public bool TryGetComponent(out T component) where T : struct { if (_components.TryGetValue(typeof(T), out object value) && value is T val) { component = val; return true; } component = default(T); return false; } } public abstract class GameEvent where T : IGameEvent, new() { public delegate void EventModuleHandler(T args); public bool HasSubscribers => this.EventHandler != null; public event EventModuleHandler? EventHandler; protected void Raise(T args) { this.EventHandler?.Invoke(args); } public void Subscribe(EventModuleHandler handler) { EventHandler += handler; } public void Unsubscribe(EventModuleHandler handler) { EventHandler -= handler; } public abstract void Initialize(); public abstract void Uninitialize(); } public static class ModuleRegistry { private static readonly Dictionary _modules = new Dictionary(); public static void Register(GameEvent module) where T : IGameEvent, new() { module.Initialize(); _modules[typeof(T)] = module; } public static void Subscribe(Action handler) where T : IGameEvent, new() { if (_modules.TryGetValue(typeof(T), out object value)) { ((GameEvent)value).Subscribe(handler.Invoke); } else { Plugin.Log((LogLevel)4, "[Subscribe] No registered module for event type! (" + typeof(T).Name + ")"); } } public static void Unsubscribe(Action handler) where T : IGameEvent, new() { if (_modules.TryGetValue(typeof(T), out object value)) { ((GameEvent)value).Unsubscribe(handler.Invoke); } else { Plugin.Log((LogLevel)4, "[Unsubscribe] No registered module for event type! (" + typeof(T).Name + ")"); } } public static bool TryGet(out GameEvent? module) where T : IGameEvent, new() { if (_modules.TryGetValue(typeof(T), out object value)) { Plugin.Log((LogLevel)4, $"try get counts: {_modules.Count})"); module = (GameEvent)value; return true; } module = null; return false; } } private static bool _initialized; public static void Initialize() { if (!_initialized) { _initialized = true; } } } }