using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.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.4.10.0")]
[assembly: AssemblyInformationalVersion("0.4.10+1.Branch.main.Sha.3a00a3be192f5367ac14e9e3d61c7e44d6b32d92.3a00a3be192f5367ac14e9e3d61c7e44d6b32d92")]
[assembly: AssemblyProduct("XPRising.XPShared")]
[assembly: AssemblyTitle("XPRising.XPShared")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.10.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.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]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace XPShared
{
public static class Extensions
{
public delegate void WithRefHandler<T>(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<T>(this Entity entity, WithRefHandler<T> 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<T>();
action(ref item);
EntityManager entityManager = EntityManager;
((EntityManager)(ref entityManager)).SetComponentData<T>(entity, item);
}
public static void AddWith<T>(this Entity entity, WithRefHandler<T> 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<T>())
{
entity.Add<T>();
}
entity.With(action);
}
public unsafe static void Write<T>(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<T>(), (AccessMode)0).TypeIndex;
byte[] array = StructureToByteArray(componentData);
int num = Marshal.SizeOf<T>();
fixed (byte* ptr = array)
{
EntityManager entityManager = EntityManager;
((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, typeIndex, (void*)ptr, num);
}
}
private static byte[] StructureToByteArray<T>(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<T>(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<T>(), (AccessMode)0).TypeIndex;
EntityManager entityManager = EntityManager;
return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRW(entity, typeIndex)));
}
public unsafe static T Read<T>(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<T>(), (AccessMode)0).TypeIndex;
EntityManager entityManager = EntityManager;
return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, typeIndex)));
}
public static DynamicBuffer<T> ReadBuffer<T>(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<T>(entity, false);
}
public static DynamicBuffer<T> AddBuffer<T>(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<T>(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<T>(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<T> val = (prefabSource.Has<T>() ? prefabSource.ReadBuffer<T>() : prefabSource.AddBuffer<T>());
val.Clear();
foreach (T val2 in bufferArray)
{
val.Add(val2);
}
}
public static bool TryGetComponent<T>(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<T>())
{
componentData = entity.Read<T>();
return true;
}
return false;
}
public static bool TryGetComponentObject<T>(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<T>(entity))
{
componentObject = ((EntityManager)(ref entityManager)).GetComponentObject<T>(entity);
return componentObject != null;
}
return false;
}
public static bool TryRemoveComponent<T>(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<T>())
{
entity.Remove<T>();
return true;
}
return false;
}
public static bool Has<T>(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<T>(), (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<T>(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<T>(), (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<T>(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<T>(), (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<Follower>(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<PlayerCharacter>())
{
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<VampireTag>())
{
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<Follower>(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<PrefabGUID>());
}
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<TeamReference>(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<Disabled>();
}
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<ServantConnectedCoffin>(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<VBloodUnit>();
}
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<PlayerCharacter>(out PlayerCharacter componentData))
{
return componentData.UserEntity.Read<User>().PlatformId;
}
if (entity.TryGetComponent<User>(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<NetworkId>(out NetworkId componentData))
{
return componentData;
}
return NetworkId.Empty;
}
public static void ForEach<T>(this IEnumerable<T> source, Action<T> 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<PrefabGUID>(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<PlayerCharacter>(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<PlayerCharacter>(out PlayerCharacter componentData) && componentData.UserEntity.TryGetComponent<User>(out User componentData2))
{
return componentData2;
}
if (entity.TryGetComponent<User>(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<T>(this Entity entity, out DynamicBuffer<T> 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<T>(EntityManager, entity, ref dynamicBuffer))
{
return true;
}
dynamicBuffer = default(DynamicBuffer<T>);
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<EntityInput>(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<Translation>(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<Translation>(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<IsMinion>(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<Team>() && entity.Has<TeamReference>() && teamSource.TryGetComponent<Team>(out Team componentData) && teamSource.TryGetComponent<TeamReference>(out TeamReference componentData2))
{
Entity teamRefEntity = componentData2.Value._Value;
int teamId = componentData.Value;
entity.With<TeamReference>((WithRefHandler<TeamReference>)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<Team>((WithRefHandler<Team>)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<FactionReference>())
{
entity.With<FactionReference>((WithRefHandler<FactionReference>)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<TimeSpan> _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<TimeSpan> 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<GameFrame>())
{
ClassInjector.RegisterTypeInIl2Cpp<GameFrame>();
}
_instance = ((BasePlugin)plugin).AddComponent<GameFrame>();
}
public static void Uninitialize()
{
GameFrame.OnUpdate = null;
GameFrame.OnLateUpdate = null;
Object.Destroy((Object)(object)_instance);
_instance = null;
}
}
[BepInPlugin("XPRising.XPShared", "XPRising.XPShared", "0.4.10")]
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;
if (IsClient)
{
ClientChatPatch.Initialize();
}
else if (IsServer)
{
ServerChatPatch.Initialize();
ChatService.ListenForClientRegister();
}
_harmonyBootPatch = Harmony.CreateAndPatchAll(typeof(GameManangerPatch), (string)null);
IsDebug = typeof(Plugin).Assembly.GetCustomAttribute<AssemblyConfigurationAttribute>()?.Configuration == "Debug";
GameFrame.Initialize(this);
Log((LogLevel)16, "Plugin is loaded [version: 0.4.10]");
}
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>(DateTime.Now, "u");
val.AppendLiteral(": [XPShared] ");
val.AppendFormatted<string>(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.4.10";
}
}
namespace XPShared.Transport
{
public delegate void ServerMessageHandler(User fromCharacter, ClientAction msg);
public class MessageHandler
{
public static event ServerMessageHandler OnServerMessageEvent;
public static void ServerSendToClient<T>(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 = "")
{
//IL_0055: 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 = (change != "")
};
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);
}
}
}
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<ActionType>(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 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
}
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<string, ChatEventHandler> EventHandlers = new Dictionary<string, ChatEventHandler>();
private static readonly Dictionary<ulong, int> SupportedUsers = new Dictionary<ulong, int>();
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<T>(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<T>()
{
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<T>(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<T>(Action<T, ulong> onMessageEvent) where T : IChatMessage, new()
{
Action<T, ulong> onMessageEvent2 = onMessageEvent;
Register<T>(new ChatEventHandler
{
OnReceiveMessage = delegate(BinaryReader binaryReader, ulong steamId)
{
T arg = new T();
arg.Deserialize(binaryReader);
onMessageEvent2(arg, steamId);
}
});
}
public static void RegisterClientNonce(ulong steamId, int clientNonce)
{
if (!Plugin.IsServer)
{
SupportedUsers[steamId] = clientNonce;
}
}
public static string SerialiseMessage<T>(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<BinaryReader, ulong> 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<ClientScriptMapper>());
public PrefabCollectionSystem PrefabCollectionSystem => _prefabCollectionSystem ?? (_prefabCollectionSystem = GetSystem<PrefabCollectionSystem>());
public GameDataSystem GameDataSystem => _gameDataSystem ?? (_gameDataSystem = GetSystem<GameDataSystem>());
public ManagedDataSystem ManagedDataSystem => _managedDataSystem ?? (_managedDataSystem = GetSystem<ManagedDataSystem>());
public TutorialSystem TutorialSystem => _tutorialSystem ?? (_tutorialSystem = GetSystem<TutorialSystem>());
public ServerScriptMapper ServerScriptMapper => _serverScriptMapper ?? (_serverScriptMapper = GetSystem<ServerScriptMapper>());
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)
if (((object)(Singleton)(ref _networkIdSystem_Singleton)).Equals((object)default(Singleton)))
{
_networkIdSystem_Singleton = GetSingleton<Singleton>();
}
return _networkIdSystem_Singleton;
}
}
public SystemService(World world)
{
}
private T GetSystem<T>() where T : ComponentSystemBase
{
return _world.GetExistingSystemManaged<T>() ?? throw new InvalidOperationException("Failed to get " + Il2CppType.Of<T>().FullName + " from the Server...");
}
private T GetSingleton<T>()
{
T singleton = ((ComponentSystemBase)ServerScriptMapper).GetSingleton<T>();
if (singleton == null)
{
throw new InvalidOperationException($"[{_world.Name}] - failed to get singleton ({Il2CppType.Of<T>().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 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<Entity> 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<ChatMessageServerEvent>(current);
if ((int)componentData.MessageType == 6 && ChatService.DeserialiseMessage(((object)(FixedString512Bytes)(ref componentData.MessageText)).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 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<EntityQuery>)(object)((ComponentSystemBase)__instance).EntityQueries)[0];
NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
val = ((Il2CppArrayBase<EntityQuery>)(object)((ComponentSystemBase)__instance).EntityQueries)[0];
NativeArray<ChatMessageEvent> val3 = ((EntityQuery)(ref val)).ToComponentDataArray<ChatMessageEvent>(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)(ref val5.MessageText)).ToString());
ulong steamId = val4.Read<FromCharacter>().Character.GetSteamId();
if (ChatService.DeserialiseMessage(((object)(FixedString512Bytes)(ref val5.MessageText)).ToString(), steamId))
{
EntityManager entityManager = EntityManager;
((EntityManager)(ref entityManager)).DestroyEntity(val4);
}
}
}
finally
{
val2.Dispose();
val3.Dispose();
}
}
}
}