using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Hook;
using Bloodstone.API;
using Bloodstone.Hooks;
using Bloodstone.Network;
using Bloodstone.Util;
using Costura;
using HarmonyLib;
using Iced.Intel;
using Il2CppInterop.Common;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.Runtime;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.MethodInfo;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using ProjectM;
using ProjectM.Network;
using Standart.Hash.xxHash;
using Stunlock.Core;
using Stunlock.Network;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("deca")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Plugin framework and general utilities for V Rising mods.")]
[assembly: AssemblyFileVersion("0.2.2.0")]
[assembly: AssemblyInformationalVersion("0.2.2+5.Branch.main.Sha.06cc4d71c309542f4e6d1ea7dea4071ee7269779")]
[assembly: AssemblyProduct("Bloodstone")]
[assembly: AssemblyTitle("Bloodstone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.2.0")]
[module: UnverifiableCode]
internal class <Module>
{
static <Module>()
{
AssemblyLoader.Attach();
}
}
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;
}
}
public class IsUnmanagedAttribute : Attribute
{
}
public class IsExternalInit
{
}
}
namespace Bloodstone
{
[BepInPlugin("gg.deca.Bloodstone", "Bloodstone", "0.2.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BloodstonePlugin : BasePlugin
{
private ConfigEntry<bool> _enableReloadCommand;
private ConfigEntry<string> _reloadCommand;
private ConfigEntry<string> _reloadPluginsFolder;
public static ManualLogSource Logger { get; private set; }
internal static BloodstonePlugin Instance { get; private set; }
public BloodstonePlugin()
{
Logger = ((BasePlugin)this).Log;
Instance = this;
_enableReloadCommand = ((BasePlugin)this).Config.Bind<bool>("General", "EnableReloading", true, "Whether to enable the reloading feature (both client and server).");
_reloadCommand = ((BasePlugin)this).Config.Bind<string>("General", "ReloadCommand", "!reload", "Server text command to reload plugins. User must be an admin.");
_reloadPluginsFolder = ((BasePlugin)this).Config.Bind<string>("General", "ReloadablePluginsFolder", "BepInEx/BloodstonePlugins", "The folder to (re)load plugins from, relative to the game directory.");
}
public override void Load()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
if (VWorld.IsServer)
{
Chat.Initialize();
}
if (VWorld.IsClient)
{
KeybindManager.Load();
}
OnInitialize.Initialize();
GameFrame.Initialize();
SerializationHooks.Initialize();
ManualLogSource logger = Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(20, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Bloodstone v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.2.2");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
}
logger.LogInfo(val);
if (VWorld.IsClient || _enableReloadCommand.Value)
{
Reload.Initialize(_reloadCommand.Value, _reloadPluginsFolder.Value);
}
}
public override bool Unload()
{
if (VWorld.IsServer)
{
Chat.Uninitialize();
}
if (VWorld.IsClient)
{
KeybindManager.Save();
Keybindings.Uninitialize();
}
OnInitialize.Uninitialize();
GameFrame.Uninitialize();
SerializationHooks.Uninitialize();
return true;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "gg.deca.Bloodstone";
public const string PLUGIN_NAME = "Bloodstone";
public const string PLUGIN_VERSION = "0.2.2";
}
}
namespace Bloodstone.Util
{
public class Il2CppMethodResolver
{
private static ulong ExtractTargetAddress(in Instruction instruction)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Invalid comparison between Unknown and I4
OpKind op0Kind = ((Instruction)(ref instruction)).Op0Kind;
if ((int)op0Kind != 4)
{
if ((int)op0Kind == 5)
{
return ((Instruction)(ref instruction)).FarBranch32;
}
return ((Instruction)(ref instruction)).NearBranchTarget;
}
return ((Instruction)(ref instruction)).FarBranch16;
}
private unsafe static IntPtr ResolveMethodPointer(IntPtr methodPointer)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Invalid comparison between Unknown and I4
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Invalid comparison between Unknown and I4
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Invalid comparison between Unknown and I4
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Invalid comparison between Unknown and I4
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Invalid comparison between Unknown and I4
StreamCodeReader val = new StreamCodeReader((Stream)new UnmanagedMemoryStream((byte*)(void*)methodPointer, 256L, 256L, FileAccess.Read));
Decoder val2 = Decoder.Create((IntPtr.Size == 8) ? 64 : 32, (CodeReader)(object)val, (DecoderOptions)0);
val2.IP = (ulong)methodPointer.ToInt64();
Instruction instruction = default(Instruction);
while ((int)((Instruction)(ref instruction)).Mnemonic != 1620)
{
val2.Decode(ref instruction);
if ((int)((Instruction)(ref instruction)).Mnemonic != 308 && (int)((Instruction)(ref instruction)).Mnemonic != 7)
{
return methodPointer;
}
if ((int)((Instruction)(ref instruction)).Mnemonic == 7 && ((Instruction)(ref instruction)).Immediate32 != 16)
{
return methodPointer;
}
if ((int)((Instruction)(ref instruction)).Mnemonic == 308)
{
return new IntPtr((long)ExtractTargetAddress(in instruction));
}
}
return methodPointer;
}
public static IntPtr ResolveFromMethodInfo(INativeMethodInfoStruct methodInfo)
{
return ResolveMethodPointer(methodInfo.MethodPointer);
}
public unsafe static IntPtr ResolveFromMethodInfo(MethodInfo method)
{
FieldInfo il2CppMethodInfoPointerFieldForGeneratedMethod = Il2CppInteropUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod((MethodBase)method);
if (il2CppMethodInfoPointerFieldForGeneratedMethod == null)
{
throw new Exception($"Couldn't obtain method info for {method}");
}
return ResolveFromMethodInfo(UnityVersionHandler.Wrap((Il2CppMethodInfo*)(void*)(IntPtr)(il2CppMethodInfoPointerFieldForGeneratedMethod.GetValue(null) ?? ((object)IntPtr.Zero))) ?? throw new Exception($"Method info for {method} is invalid"));
}
}
public static class NativeHookUtil
{
public static INativeDetour Detour<T>(string typeName, string methodName, T to, out T original) where T : Delegate?
{
return Detour(Type.GetType(typeName), methodName, to, out original);
}
public static INativeDetour Detour<T>(Type type, string methodName, T to, out T original) where T : Delegate?
{
return Detour(type.GetMethod(methodName, AccessTools.all), to, out original);
}
public static INativeDetour Detour<T>(MethodInfo method, T to, out T original) where T : Delegate?
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
IntPtr intPtr = Il2CppMethodResolver.ResolveFromMethodInfo(method);
ManualLogSource logger = BloodstonePlugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(15, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Detouring ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(method.DeclaringType?.FullName);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(method.Name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" at ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(intPtr.ToString("X"));
}
logger.LogInfo(val);
return INativeDetour.CreateAndApply<T>(intPtr, to, ref original);
}
}
}
namespace Bloodstone.Network
{
internal class VBlittableNetworkMessage<T> : VNetworkMessage where T : unmanaged
{
public T Value { get; private set; }
public VBlittableNetworkMessage()
{
Value = default(T);
}
public VBlittableNetworkMessage(T instance)
{
Value = instance;
}
public unsafe void Deserialize(NetBufferIn reader)
{
int num = ((NetBufferIn)(ref reader)).ReadInt32();
if (num != Marshal.SizeOf<T>())
{
throw new Exception($"Received a message with invalid size {num} for type {typeof(T)}");
}
byte* ptr = stackalloc byte[(int)(uint)num];
for (int i = 0; i < num; i++)
{
ptr[i] = ((NetBufferIn)(ref reader)).ReadByte();
}
Value = Marshal.PtrToStructure<T>(new IntPtr(ptr));
}
public unsafe void Serialize(ref NetBufferOut writer)
{
int num = Marshal.SizeOf<T>();
byte* ptr = stackalloc byte[(int)(uint)num];
Marshal.StructureToPtr(Value, new IntPtr(ptr), fDeleteOld: false);
((NetBufferOut)(ref writer)).Write(num);
for (int i = 0; i < num; i++)
{
((NetBufferOut)(ref writer)).Write(ptr[i]);
}
}
}
internal class CustomNetworkEvent : Object
{
private static bool _isInitialized;
private static ComponentType _componentType;
public VNetworkMessage? Message;
public static ComponentType ComponentType
{
get
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if (!_isInitialized)
{
Inject();
}
return _componentType;
}
}
public CustomNetworkEvent()
: base(ClassInjector.DerivedConstructorPointer<CustomNetworkEvent>())
{
ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
}
internal void Serialize(ref NetBufferOut netBuffer)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
if (Message == null)
{
throw new Exception("Tried to serialize a CustomNetworkEvent with no message");
}
string text = MessageRegistry.DeriveKey(Message.GetType());
((NetBufferOut)(ref netBuffer)).Write(text, (Allocator)2);
try
{
Message.Serialize(ref netBuffer);
}
catch (Exception ex)
{
ManualLogSource logger = BloodstonePlugin.Logger;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(35, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to serialize network event ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(":");
}
logger.LogError(val);
BloodstonePlugin.Logger.LogError((object)ex);
}
}
private static void Inject()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//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_003b: Unknown result type (might be due to invalid IL or missing references)
ClassInjector.RegisterTypeInIl2Cpp(typeof(CustomNetworkEvent));
Type val = Il2CppType.From(typeof(CustomNetworkEvent));
if (TypeManager.FindTypeIndex(val).Value < 1)
{
TypeInfo val2 = TypeManager.BuildComponentType(val, new BuildComponentCache(1));
TypeManager.AddTypeInfoToTables(val, val2, "CustomNetworkEvent", 0);
}
_componentType = new ComponentType(val, (AccessMode)0);
_isInitialized = true;
}
}
internal static class EventDispatcher
{
internal static void SendToClient(int userIndex, VNetworkMessage msg)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: 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_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
if (!VWorld.IsServer)
{
throw new Exception("Cannot send network messages to client if not on the server");
}
string text = MessageRegistry.DeriveKey(msg.GetType());
if (!MessageRegistry._eventHandlers.ContainsKey(text))
{
throw new Exception("Network event " + text + " is not registered");
}
EntityManager entityManager = VWorld.Server.EntityManager;
Entity val = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[4]
{
ComponentType.ReadOnly<SendNetworkEventTag>(),
ComponentType.ReadOnly<NetworkEventType>(),
ComponentType.ReadOnly<SendEventToUser>(),
CustomNetworkEvent.ComponentType
});
((EntityManager)(ref entityManager)).SetComponentData<SendEventToUser>(val, new SendEventToUser
{
UserIndex = userIndex
});
((EntityManager)(ref entityManager)).SetComponentData<NetworkEventType>(val, new NetworkEventType
{
EventId = 1036301,
IsAdminEvent = false,
IsDebugEvent = false
});
((EntityManager)(ref entityManager)).SetComponentObject(val, CustomNetworkEvent.ComponentType, (Object)(object)new CustomNetworkEvent
{
Message = msg
});
}
internal static void SendToServer(VNetworkMessage msg)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
if (!VWorld.IsClient)
{
throw new Exception("Cannot send network messages to server if not on the client");
}
string text = MessageRegistry.DeriveKey(msg.GetType());
if (!MessageRegistry._eventHandlers.ContainsKey(text))
{
throw new Exception("Network event " + text + " is not registered");
}
EntityManager entityManager = VWorld.Client.EntityManager;
Entity val = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[3]
{
ComponentType.ReadOnly<NetworkEventType>(),
ComponentType.ReadOnly<SendNetworkEventTag>(),
CustomNetworkEvent.ComponentType
});
((EntityManager)(ref entityManager)).SetComponentData<NetworkEventType>(val, new NetworkEventType
{
EventId = 1036301,
IsAdminEvent = false,
IsDebugEvent = false
});
((EntityManager)(ref entityManager)).SetComponentObject(val, CustomNetworkEvent.ComponentType, (Object)(object)new CustomNetworkEvent
{
Message = msg
});
}
}
internal class MessageRegistry
{
internal static Dictionary<string, RegisteredEventHandler> _eventHandlers = new Dictionary<string, RegisteredEventHandler>();
internal static string DeriveKey(Type name)
{
return name.ToString();
}
internal static void Register<T>(RegisteredEventHandler 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 class RegisteredEventHandler
{
internal Action<NetBufferIn> OnReceiveFromServer { get; init; }
internal Action<FromCharacter, NetBufferIn> OnReceiveFromClient { get; init; }
}
internal static class SerializationHooks
{
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void SerializeEvent(IntPtr entityManager, NetworkEventType networkEventType, ref NetBufferOut netBufferOut, Entity entity);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void DeserializeEvent(IntPtr entityManager, IntPtr commandBuffer, ref NetBufferIn netBuffer, DeserializeNetworkEventParams eventParams);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void EventsReceived(IntPtr _this, ref NetBufferIn netBuffer);
private static class SerializeAndSendServerEventsSystem_Patch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(SerializeAndSendServerEventsSystem), "OnUpdate")]
private unsafe static void OnUpdatePrefix(SerializeAndSendServerEventsSystem __instance)
{
//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)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: 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_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Expected O, but got Unknown
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: 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)
EntityQuery val = ((Il2CppArrayBase<EntityQuery>)(object)((ComponentSystemBase)__instance).EntityQueries)[1];
NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
TypeIndex typeIndex = ComponentType.ReadOnly<SendEventToUser>().TypeIndex;
Enumerator<Entity> enumerator = val2.GetEnumerator();
NetBufferOut netBuffer = default(NetBufferOut);
bool flag = default(bool);
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
NetworkEventType componentData = ((EntityManager)(ref entityManager)).GetComponentData<NetworkEventType>(current);
if (componentData.EventId == 1036301)
{
entityManager = ((ComponentSystemBase)__instance).EntityManager;
CustomNetworkEvent componentObject = ((EntityManager)(ref entityManager)).GetComponentObject<CustomNetworkEvent>(current);
entityManager = ((ComponentSystemBase)__instance).EntityManager;
SendEventToUser componentDataRawRO = (SendEventToUser)(*((EntityManager)(ref entityManager)).GetComponentDataRawRO(current, typeIndex));
((NetBufferOut)(ref netBuffer))..ctor(new NativeArray<byte>(16384, (Allocator)2, (NativeArrayOptions)1), 0);
((NetBufferOut)(ref netBuffer)).Write((byte)1);
((NetBufferOut)(ref netBuffer)).Write(componentData.EventId);
componentObject.Serialize(ref netBuffer);
ManualLogSource logger = BloodstonePlugin.Logger;
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(63, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Functionality Disabled: Not sending CustomNetworkEvent to user ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(componentDataRawRO.UserIndex);
}
logger.LogWarning(val3);
entityManager = ((ComponentSystemBase)__instance).EntityManager;
((EntityManager)(ref entityManager)).DestroyEntity(current);
}
}
}
}
internal const int BLOODSTONE_NETWORK_EVENT_ID = 1036301;
private static INativeDetour? _serializeDetour;
private static INativeDetour? _deserializeDetour;
private static INativeDetour? _eventsReceivedDetour;
private static Harmony? _harmony;
public static SerializeEvent? SerializeOriginal;
public static DeserializeEvent? DeserializeOriginal;
public static EventsReceived? EventsReceivedOriginal;
public static void Initialize()
{
_serializeDetour = NativeHookUtil.Detour<SerializeEvent>(typeof(NetworkEvents_Serialize), "SerializeEvent", SerializeHook, out SerializeOriginal);
_deserializeDetour = NativeHookUtil.Detour<DeserializeEvent>(typeof(NetworkEvents_Serialize), "DeserializeEvent", DeserializeHook, out DeserializeOriginal);
if (VWorld.IsClient)
{
_eventsReceivedDetour = NativeHookUtil.Detour<EventsReceived>(typeof(ClientBootstrapSystem), "OnReliableEventsReceived", EventsReceivedHook, out EventsReceivedOriginal);
}
else if (VWorld.IsServer)
{
_harmony = Harmony.CreateAndPatchAll(typeof(SerializeAndSendServerEventsSystem_Patch), (string)null);
}
}
public static void Uninitialize()
{
((IDisposable)_serializeDetour)?.Dispose();
((IDisposable)_deserializeDetour)?.Dispose();
((IDisposable)_eventsReceivedDetour)?.Dispose();
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
public static void SerializeHook(IntPtr entityManager, NetworkEventType networkEventType, ref NetBufferOut netBufferOut, Entity entity)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: 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 (networkEventType.EventId != 1036301)
{
SerializeOriginal(entityManager, networkEventType, ref netBufferOut, entity);
return;
}
EntityManager entityManager2 = VWorld.Server.EntityManager;
CustomNetworkEvent obj = (CustomNetworkEvent)(object)((EntityManager)(ref entityManager2)).GetComponentObject<Object>(entity, CustomNetworkEvent.ComponentType);
((NetBufferOut)(ref netBufferOut)).Write(1036301u);
obj.Serialize(ref netBufferOut);
}
public static void DeserializeHook(IntPtr entityManager, IntPtr commandBuffer, ref NetBufferIn netBufferIn, DeserializeNetworkEventParams eventParams)
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_0021: 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_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
if (((NetBufferIn)(ref netBufferIn)).ReadUInt32() != 1036301)
{
netBufferIn.m_readPosition -= 32;
DeserializeOriginal(entityManager, commandBuffer, ref netBufferIn, eventParams);
return;
}
string text = ((NetBufferIn)(ref netBufferIn)).ReadString((Allocator)2);
if (!MessageRegistry._eventHandlers.ContainsKey(text))
{
return;
}
RegisteredEventHandler registeredEventHandler = MessageRegistry._eventHandlers[text];
bool flag = eventParams.FromCharacter.User == Entity.Null;
try
{
if (flag)
{
registeredEventHandler.OnReceiveFromServer(netBufferIn);
}
else
{
registeredEventHandler.OnReceiveFromClient(eventParams.FromCharacter, netBufferIn);
}
}
catch (Exception ex)
{
ManualLogSource logger = BloodstonePlugin.Logger;
bool flag2 = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(39, 1, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error handling incoming network event ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(":");
}
logger.LogError(val);
BloodstonePlugin.Logger.LogError((object)ex);
}
}
public static void EventsReceivedHook(IntPtr _this, ref NetBufferIn netBuffer)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
if (((NetBufferIn)(ref netBuffer)).ReadInt32() != 1036301)
{
netBuffer.m_readPosition -= 32;
EventsReceivedOriginal(_this, ref netBuffer);
return;
}
string text = ((NetBufferIn)(ref netBuffer)).ReadString((Allocator)2);
if (!MessageRegistry._eventHandlers.ContainsKey(text))
{
return;
}
RegisteredEventHandler registeredEventHandler = MessageRegistry._eventHandlers[text];
try
{
registeredEventHandler.OnReceiveFromServer(netBuffer);
}
catch (Exception ex)
{
ManualLogSource logger = BloodstonePlugin.Logger;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(39, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error handling incoming network event ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(":");
}
logger.LogError(val);
BloodstonePlugin.Logger.LogError((object)ex);
}
}
}
}
namespace Bloodstone.Hooks
{
public static class Chat
{
public delegate void ChatEventHandler(VChatEvent e);
private static Harmony? _harmony;
public static event ChatEventHandler? OnChatMessage;
public static void Initialize()
{
if (_harmony != null)
{
throw new Exception("Detour already initialized. You don't need to call this. The Bloodstone plugin will do it for you.");
}
_harmony = Harmony.CreateAndPatchAll(typeof(Chat), "gg.deca.Bloodstone");
}
public static void Uninitialize()
{
if (_harmony == null)
{
throw new Exception("Detour wasn't initialized. Are you trying to unload Bloodstone twice?");
}
_harmony.UnpatchSelf();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ChatMessageSystem), "OnUpdate")]
public static void OnUpdatePrefix(ChatMessageSystem __instance)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
EntityQuery _query_661171423_ = __instance.__query_661171423_0;
Enumerator<Entity> enumerator = ((EntityQuery)(ref _query_661171423_)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).GetEnumerator();
bool flag = default(bool);
while (enumerator.MoveNext())
{
Entity current = enumerator.Current;
EntityManager entityManager = VWorld.Server.EntityManager;
ChatMessageEvent componentData = ((EntityManager)(ref entityManager)).GetComponentData<ChatMessageEvent>(current);
entityManager = VWorld.Server.EntityManager;
FromCharacter componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<FromCharacter>(current);
VChatEvent vChatEvent = new VChatEvent(componentData2.User, componentData2.Character, ((object)(FixedString512Bytes)(ref componentData.MessageText)).ToString(), componentData.MessageType);
ManualLogSource logger = BloodstonePlugin.Logger;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(12, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Chat] [");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ChatMessageType>(vChatEvent.Type);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<FixedString64Bytes>(vChatEvent.User.CharacterName);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(vChatEvent.Message);
}
logger.LogInfo(val);
try
{
Chat.OnChatMessage?.Invoke(vChatEvent);
if (vChatEvent.Cancelled)
{
entityManager = VWorld.Server.EntityManager;
((EntityManager)(ref entityManager)).DestroyEntity(current);
}
}
catch (Exception ex)
{
BloodstonePlugin.Logger.LogError((object)"Error dispatching chat event:");
BloodstonePlugin.Logger.LogError((object)ex);
}
}
}
}
public class VChatEvent
{
public Entity SenderUserEntity { get; }
public Entity SenderCharacterEntity { get; }
public string Message { get; }
public ChatMessageType Type { get; }
public bool Cancelled { get; private set; }
public User User
{
get
{
//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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = VWorld.Server.EntityManager;
return ((EntityManager)(ref entityManager)).GetComponentData<User>(SenderUserEntity);
}
}
internal VChatEvent(Entity userEntity, Entity characterEntity, string message, ChatMessageType type)
{
//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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: 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)
SenderUserEntity = userEntity;
SenderCharacterEntity = characterEntity;
Message = message;
Type = type;
}
public void Cancel()
{
Cancelled = true;
}
}
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)
{
BloodstonePlugin.Logger.LogError((object)"Error dispatching OnUpdate event:");
BloodstonePlugin.Logger.LogError((object)ex);
}
}
private void LateUpdate()
{
try
{
GameFrame.OnLateUpdate?.Invoke();
}
catch (Exception ex)
{
BloodstonePlugin.Logger.LogError((object)"Error dispatching OnLateUpdate event:");
BloodstonePlugin.Logger.LogError((object)ex);
}
}
public static void Initialize()
{
if (!ClassInjector.IsTypeRegisteredInIl2Cpp<GameFrame>())
{
ClassInjector.RegisterTypeInIl2Cpp<GameFrame>();
}
_instance = ((BasePlugin)BloodstonePlugin.Instance).AddComponent<GameFrame>();
}
public static void Uninitialize()
{
GameFrame.OnUpdate = null;
GameFrame.OnLateUpdate = null;
Object.Destroy((Object)(object)_instance);
_instance = null;
}
}
internal static class Keybindings
{
private static Harmony _harmony;
private static INativeDetour _detour;
public static void Initialize()
{
if (VWorld.IsClient)
{
BloodstonePlugin.Logger.LogWarning((object)"Client Keybinding support has been disabled for 1.0 release change compatability. It may be rewritten in the future as needed.");
_harmony = Harmony.CreateAndPatchAll(typeof(Keybindings), (string)null);
}
}
public static void Uninitialize()
{
if (VWorld.IsClient)
{
((IDisposable)_detour).Dispose();
_harmony.UnpatchSelf();
}
}
}
internal static class OnInitialize
{
private static class ServerDetours
{
[HarmonyPatch(typeof(GameBootstrap), "Start")]
[HarmonyPostfix]
public static void Initialize()
{
InvokePlugins();
}
}
private static class ClientDetours
{
[HarmonyPatch(typeof(WorldBootstrapUtilities), "AddSystemsToWorld")]
[HarmonyPostfix]
public static void Initialize()
{
InvokePlugins();
}
}
private static Harmony _harmony;
public static bool HasInitialized { get; private set; }
public static void Initialize()
{
_harmony = Harmony.CreateAndPatchAll(VWorld.IsServer ? typeof(ServerDetours) : typeof(ClientDetours), (string)null);
}
public static void Uninitialize()
{
_harmony.UnpatchSelf();
}
private static void InvokePlugins()
{
BloodstonePlugin.Logger.LogInfo((object)"Game has bootstrapped. Worlds and systems now exist.");
if (HasInitialized)
{
return;
}
HasInitialized = true;
foreach (KeyValuePair<string, PluginInfo> plugin in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins)
{
plugin.Deconstruct(out var _, out var value);
if (value.Instance is IRunOnInitialized runOnInitialized)
{
runOnInitialized.OnGameInitialized();
}
}
foreach (BasePlugin loadedPlugin in Reload.LoadedPlugins)
{
if (loadedPlugin is IRunOnInitialized runOnInitialized2)
{
runOnInitialized2.OnGameInitialized();
}
}
}
}
}
namespace Bloodstone.API
{
public interface IRunOnInitialized
{
void OnGameInitialized();
}
public static class KeybindManager
{
private static string KeybindingsPath = Path.Join(Paths.ConfigPath, "keybindings.json");
internal static Dictionary<ButtonInputAction, Keybinding> _keybindingsByFlags = new Dictionary<ButtonInputAction, Keybinding>();
internal static Dictionary<int, Keybinding> _keybindingsByGuid = new Dictionary<int, Keybinding>();
internal static Dictionary<string, Keybinding> _keybindingsById = new Dictionary<string, Keybinding>();
internal static Dictionary<string, KeybindingBindings> _keybindingValues = new Dictionary<string, KeybindingBindings>();
public static Keybinding Register(KeybindingDescription description)
{
//IL_005c: 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)
if (_keybindingsById.ContainsKey(description.Id))
{
throw new ArgumentException("Keybinding with id " + description.Id + " already registered");
}
Keybinding keybinding = new Keybinding(description);
_keybindingsById.Add(description.Id, keybinding);
_keybindingsByGuid.Add(keybinding.AssetGuid, keybinding);
_keybindingsByFlags.Add(keybinding.InputFlag, keybinding);
if (!_keybindingValues.ContainsKey(description.Id))
{
_keybindingValues.Add(description.Id, new KeybindingBindings
{
Id = description.Id,
Primary = description.DefaultKeybinding,
Secondary = (KeyCode)0
});
}
return keybinding;
}
public static void Unregister(Keybinding keybinding)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
if (!_keybindingsById.ContainsKey(keybinding.Description.Id))
{
throw new ArgumentException("There was no keybinding with id " + keybinding.Description.Id + " registered");
}
_keybindingsByFlags.Remove(keybinding.InputFlag);
_keybindingsByGuid.Remove(keybinding.AssetGuid);
_keybindingsById.Remove(keybinding.Description.Id);
}
internal static void Load()
{
try
{
if (File.Exists(KeybindingsPath))
{
Dictionary<string, KeybindingBindings> dictionary = JsonSerializer.Deserialize<Dictionary<string, KeybindingBindings>>(File.ReadAllText(KeybindingsPath));
if (dictionary != null)
{
_keybindingValues = dictionary;
}
}
}
catch (Exception ex)
{
BloodstonePlugin.Logger.LogError((object)"Error loading keybindings, using defaults: ");
BloodstonePlugin.Logger.LogError((object)ex);
_keybindingValues = new Dictionary<string, KeybindingBindings>();
}
}
internal static void Save()
{
try
{
string contents = JsonSerializer.Serialize(_keybindingValues);
File.WriteAllText(KeybindingsPath, contents);
}
catch (Exception ex)
{
BloodstonePlugin.Logger.LogError((object)"Error saving custom keybindings: ");
BloodstonePlugin.Logger.LogError((object)ex);
}
}
}
public struct KeybindingDescription
{
public string Id;
public string Category;
public string Name;
public KeyCode DefaultKeybinding;
}
public class Keybinding
{
public KeybindingDescription Description { get; }
public KeyCode Primary => KeybindManager._keybindingValues[Description.Id].Primary;
public KeyCode Secondary => KeybindManager._keybindingValues[Description.Id].Secondary;
public bool IsPressed
{
get
{
//IL_0001: 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)
if (!Input.GetKeyDown(Primary))
{
return Input.GetKeyDown(Secondary);
}
return true;
}
}
internal ButtonInputAction InputFlag { get; private set; }
internal int AssetGuid { get; private set; }
public Keybinding(KeybindingDescription description)
{
Description = description;
ComputeInputFlag();
ComputeAssetGuid();
}
private void ComputeInputFlag()
{
//IL_0031: 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)
byte[] bytes = Encoding.UTF8.GetBytes(Description.Id);
ulong num = xxHash64.ComputeHash(bytes, bytes.Length, 0uL);
bool flag = false;
do
{
flag = false;
ButtonInputAction[] values = Enum.GetValues<ButtonInputAction>();
foreach (ButtonInputAction val in values)
{
if (num == (ulong)(long)val)
{
flag = true;
num--;
}
}
}
while (flag);
InputFlag = (ButtonInputAction)num;
}
private void ComputeAssetGuid()
{
byte[] bytes = Encoding.UTF8.GetBytes(Description.Id);
AssetGuid = (int)xxHash32.ComputeHash(bytes, bytes.Length, 0u);
}
}
internal class KeybindingBindings
{
public string Id { get; set; }
public KeyCode Primary { get; set; }
public KeyCode Secondary { get; set; }
}
[AttributeUsage(AttributeTargets.Class)]
public class ReloadableAttribute : Attribute
{
}
public static class VExtensions
{
public delegate void ActionRef<T>(ref T item);
public static void SendSystemMessage(this User user, string message)
{
//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)
if (!VWorld.IsServer)
{
throw new Exception("SendSystemMessage can only be called on the server.");
}
ServerChatUtils.SendSystemMessageToClient(VWorld.Server.EntityManager, user, message);
}
public static void WithComponentData<T>(this Entity entity, ActionRef<T> action) where T : struct
{
//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_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = VWorld.Game.EntityManager;
T item = ((EntityManager)(ref entityManager)).GetComponentData<T>(entity);
action(ref item);
entityManager = VWorld.Game.EntityManager;
((EntityManager)(ref entityManager)).SetComponentData<T>(entity, item);
}
}
public interface VNetworkMessage
{
void Serialize(ref NetBufferOut writer);
void Deserialize(NetBufferIn reader);
}
public static class VNetworkRegistry
{
public static void Unregister<T>()
{
MessageRegistry.Unregister<T>();
}
public static void UnregisterStruct<T>() where T : unmanaged
{
Unregister<VBlittableNetworkMessage<T>>();
}
public static void RegisterServerbound<T>(Action<FromCharacter, T> onMessageFromClient) where T : VNetworkMessage, new()
{
Action<FromCharacter, T> onMessageFromClient2 = onMessageFromClient;
MessageRegistry.Register<T>(new RegisteredEventHandler
{
OnReceiveFromServer = delegate
{
},
OnReceiveFromClient = delegate(FromCharacter user, NetBufferIn buf)
{
//IL_0008: 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)
T arg = new T();
arg.Deserialize(buf);
onMessageFromClient2(user, arg);
}
});
}
public static void RegisterServerboundStruct<T>(Action<FromCharacter, T> onMessageFromClient) where T : unmanaged
{
Action<FromCharacter, T> onMessageFromClient2 = onMessageFromClient;
RegisterServerbound(delegate(FromCharacter user, VBlittableNetworkMessage<T> msg)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
onMessageFromClient2(user, msg.Value);
});
}
public static void RegisterClientbound<T>(Action<T> onMessageFromServer) where T : VNetworkMessage, new()
{
Action<T> onMessageFromServer2 = onMessageFromServer;
MessageRegistry.Register<T>(new RegisteredEventHandler
{
OnReceiveFromServer = delegate(NetBufferIn buf)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
T obj = new T();
obj.Deserialize(buf);
onMessageFromServer2(obj);
},
OnReceiveFromClient = delegate
{
}
});
}
public static void RegisterClientboundStruct<T>(Action<T> onMessageFromServer) where T : unmanaged
{
Action<T> onMessageFromServer2 = onMessageFromServer;
RegisterClientbound(delegate(VBlittableNetworkMessage<T> msg)
{
onMessageFromServer2(msg.Value);
});
}
public static void RegisterBiDirectional<T>(Action<T> onMessageFromServer, Action<FromCharacter, T> onMessageFromClient) where T : VNetworkMessage, new()
{
Action<T> onMessageFromServer2 = onMessageFromServer;
Action<FromCharacter, T> onMessageFromClient2 = onMessageFromClient;
MessageRegistry.Register<T>(new RegisteredEventHandler
{
OnReceiveFromServer = delegate(NetBufferIn buf)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
T obj = new T();
obj.Deserialize(buf);
onMessageFromServer2(obj);
},
OnReceiveFromClient = delegate(FromCharacter user, NetBufferIn buf)
{
//IL_0008: 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)
T arg = new T();
arg.Deserialize(buf);
onMessageFromClient2(user, arg);
}
});
}
public static void RegisterBiDirectionalStruct<T>(Action<T> onMessageFromServer, Action<FromCharacter, T> onMessageFromClient) where T : unmanaged
{
Action<T> onMessageFromServer2 = onMessageFromServer;
Action<FromCharacter, T> onMessageFromClient2 = onMessageFromClient;
RegisterBiDirectional(delegate(VBlittableNetworkMessage<T> msg)
{
onMessageFromServer2(msg.Value);
}, delegate(FromCharacter user, VBlittableNetworkMessage<T> msg)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
onMessageFromClient2(user, msg.Value);
});
}
}
public static class VNetwork
{
public static void SendToClient(int userIndex, VNetworkMessage msg)
{
EventDispatcher.SendToClient(userIndex, msg);
}
public static void SendToClient(User user, VNetworkMessage msg)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
EventDispatcher.SendToClient(user.Index, msg);
}
public static void SendToClient(FromCharacter fromCharacter, VNetworkMessage msg)
{
//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_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
EntityManager entityManager = VWorld.Server.EntityManager;
EventDispatcher.SendToClient(((EntityManager)(ref entityManager)).GetComponentData<User>(fromCharacter.User).Index, msg);
}
public static void SendToClientStruct<T>(int userIndex, T msg) where T : unmanaged
{
SendToClient(userIndex, new VBlittableNetworkMessage<T>(msg));
}
public static void SendToClientStruct<T>(User user, T msg) where T : unmanaged
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
SendToClient(user, new VBlittableNetworkMessage<T>(msg));
}
public static void SendToClientStruct<T>(FromCharacter fromCharacter, T msg) where T : unmanaged
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
SendToClient(fromCharacter, new VBlittableNetworkMessage<T>(msg));
}
public static void SendToServer(VNetworkMessage msg)
{
EventDispatcher.SendToServer(msg);
}
public static void SendToServerStruct<T>(T msg) where T : unmanaged
{
SendToServer(new VBlittableNetworkMessage<T>(msg));
}
}
public static class VWorld
{
private static World? _clientWorld;
private static World? _serverWorld;
public static World Server
{
get
{
if (_serverWorld != null && _serverWorld.IsCreated)
{
return _serverWorld;
}
_serverWorld = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");
return _serverWorld;
}
}
public static World Client
{
get
{
if (_clientWorld != null && _clientWorld.IsCreated)
{
return _clientWorld;
}
_clientWorld = GetWorld("Client_0") ?? throw new Exception("There is no Client world (yet). Did you install a client mod on the server?");
return _clientWorld;
}
}
public static World Default => World.DefaultGameObjectInjectionWorld;
public static World Game
{
get
{
if (!IsClient)
{
return Server;
}
return Client;
}
}
public static bool IsServer => Application.productName == "VRisingServer";
public static bool IsClient => Application.productName == "VRising";
private static World? GetWorld(string name)
{
Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
while (enumerator.MoveNext())
{
World current = enumerator.Current;
if (current.Name == name)
{
_serverWorld = current;
return current;
}
}
return null;
}
}
public static class Reload
{
private class ReloadBehaviour : MonoBehaviour
{
private void Update()
{
if (_clientReloadKeybinding.IsPressed)
{
BloodstonePlugin.Logger.LogInfo((object)"Reloading client plugins...");
UnloadPlugins();
LoadPlugins();
}
}
}
private static string _reloadCommand;
private static string _reloadPluginsFolder;
private static ReloadBehaviour _clientBehavior;
private static Keybinding _clientReloadKeybinding;
public static List<BasePlugin> LoadedPlugins { get; } = new List<BasePlugin>();
internal static void Initialize(string reloadCommand, string reloadPluginsFolder)
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
_reloadCommand = reloadCommand;
_reloadPluginsFolder = reloadPluginsFolder;
Chat.OnChatMessage += HandleReloadCommand;
if (VWorld.IsClient)
{
KeybindingDescription description = default(KeybindingDescription);
description.Id = "gg.deca.Bloodstone.reload";
description.Category = "Bloodstone";
description.Name = "Reload Plugins";
description.DefaultKeybinding = (KeyCode)287;
_clientReloadKeybinding = KeybindManager.Register(description);
_clientBehavior = ((BasePlugin)BloodstonePlugin.Instance).AddComponent<ReloadBehaviour>();
}
LoadPlugins();
}
internal static void Uninitialize()
{
Chat.OnChatMessage -= HandleReloadCommand;
if ((Object)(object)_clientBehavior != (Object)null)
{
Object.Destroy((Object)(object)_clientBehavior);
}
}
private static void HandleReloadCommand(VChatEvent ev)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
if (!(ev.Message != _reloadCommand) && ev.User.IsAdmin)
{
ev.Cancel();
UnloadPlugins();
List<string> list = LoadPlugins();
if (list.Count > 0)
{
ev.User.SendSystemMessage("Reloaded " + string.Join(", ", list) + ". See console for details.");
}
else
{
ev.User.SendSystemMessage("Did not reload any plugins because no reloadable plugins were found. Check the console for more details.");
}
}
}
private static void UnloadPlugins()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
bool flag = default(bool);
for (int num = LoadedPlugins.Count - 1; num >= 0; num--)
{
BasePlugin val = LoadedPlugins[num];
if (!val.Unload())
{
ManualLogSource logger = BloodstonePlugin.Logger;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(47, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((object)val).GetType().FullName);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" does not support unloading, skipping...");
}
logger.LogWarning(val2);
}
else
{
LoadedPlugins.RemoveAt(num);
}
}
}
private static List<string> LoadPlugins()
{
if (!Directory.Exists(_reloadPluginsFolder))
{
return new List<string>();
}
return Directory.GetFiles(_reloadPluginsFolder, "*.dll").SelectMany(LoadPlugin).ToList();
}
private static List<string> LoadPlugin(string path)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Expected O, but got Unknown
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Expected O, but got Unknown
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Expected O, but got Unknown
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Expected O, but got Unknown
DefaultAssemblyResolver val = new DefaultAssemblyResolver();
((BaseAssemblyResolver)val).AddSearchDirectory(_reloadPluginsFolder);
((BaseAssemblyResolver)val).AddSearchDirectory(Paths.ManagedPath);
((BaseAssemblyResolver)val).AddSearchDirectory(Paths.BepInExAssemblyDirectory);
((BaseAssemblyResolver)val).AddSearchDirectory(Path.Combine(Paths.BepInExRootPath, "interop"));
AssemblyDefinition val2 = AssemblyDefinition.ReadAssembly(path, new ReaderParameters
{
AssemblyResolver = (IAssemblyResolver)(object)val
});
try
{
((AssemblyNameReference)val2.Name).Name = $"{((AssemblyNameReference)val2.Name).Name}-{DateTime.Now.Ticks}";
using MemoryStream memoryStream = new MemoryStream();
val2.Write((Stream)memoryStream);
List<string> list = new List<string>();
bool flag = default(bool);
foreach (Type pluginType in from x in Assembly.Load(memoryStream.ToArray()).GetTypes()
where typeof(BasePlugin).IsAssignableFrom(x)
select x)
{
if (!pluginType.GetCustomAttributes<ReloadableAttribute>().Any())
{
ManualLogSource logger = BloodstonePlugin.Logger;
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(48, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(pluginType.FullName);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" is not marked as reloadable, skipping...");
}
logger.LogWarning(val3);
}
else
{
if (LoadedPlugins.Any((BasePlugin x) => ((object)x).GetType() == pluginType))
{
continue;
}
try
{
BasePlugin val4 = (BasePlugin)Activator.CreateInstance(pluginType);
BepInPlugin metadata = MetadataHelper.GetMetadata((object)val4);
LoadedPlugins.Add(val4);
val4.Load();
list.Add(metadata.Name);
if (OnInitialize.HasInitialized && val4 is IRunOnInitialized runOnInitialized)
{
runOnInitialized.OnGameInitialized();
}
ManualLogSource logger2 = BloodstonePlugin.Logger;
BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(14, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Loaded plugin ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(pluginType.FullName);
}
logger2.LogInfo(val5);
}
catch (Exception ex)
{
ManualLogSource logger3 = BloodstonePlugin.Logger;
BepInExErrorLogInterpolatedStringHandler val6 = new BepInExErrorLogInterpolatedStringHandler(49, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(pluginType.FullName);
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" threw an exception during initialization:");
}
logger3.LogError(val6);
BloodstonePlugin.Logger.LogError((object)ex);
}
}
}
return list;
}
finally
{
((IDisposable)val2)?.Dispose();
}
}
}
}
namespace Costura
{
[CompilerGenerated]
internal static class AssemblyLoader
{
private static object nullCacheLock = new object();
private static Dictionary<string, bool> nullCache = new Dictionary<string, bool>();
private static Dictionary<string, string> assemblyNames = new Dictionary<string, string>();
private static Dictionary<string, string> symbolNames = new Dictionary<string, string>();
private static int isAttached;
private static string CultureToString(CultureInfo culture)
{
if (culture == null)
{
return "";
}
return culture.Name;
}
private static Assembly ReadExistingAssembly(AssemblyName name)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
Assembly[] assemblies = currentDomain.GetAssemblies();
Assembly[] array = assemblies;
foreach (Assembly assembly in array)
{
AssemblyName name2 = assembly.GetName();
if (string.Equals(name2.Name, name.Name, StringComparison.InvariantCultureIgnoreCase) && string.Equals(CultureToString(name2.CultureInfo), CultureToString(name.CultureInfo), StringComparison.InvariantCultureIgnoreCase))
{
return assembly;
}
}
return null;
}
private static void CopyTo(Stream source, Stream destination)
{
byte[] array = new byte[81920];
int count;
while ((count = source.Read(array, 0, array.Length)) != 0)
{
destination.Write(array, 0, count);
}
}
private static Stream LoadStream(string fullName)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
if (fullName.EndsWith(".compressed"))
{
using (Stream stream = executingAssembly.GetManifestResourceStream(fullName))
{
using DeflateStream source = new DeflateStream(stream, CompressionMode.Decompress);
MemoryStream memoryStream = new MemoryStream();
CopyTo(source, memoryStream);
memoryStream.Position = 0L;
return memoryStream;
}
}
return executingAssembly.GetManifestResourceStream(fullName);
}
private static Stream LoadStream(Dictionary<string, string> resourceNames, string name)
{
if (resourceNames.TryGetValue(name, out var value))
{
return LoadStream(value);
}
return null;
}
private static byte[] ReadStream(Stream stream)
{
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
return array;
}
private static Assembly ReadFromEmbeddedResources(Dictionary<string, string> assemblyNames, Dictionary<string, string> symbolNames, AssemblyName requestedAssemblyName)
{
string text = requestedAssemblyName.Name.ToLowerInvariant();
if (requestedAssemblyName.CultureInfo != null && !string.IsNullOrEmpty(requestedAssemblyName.CultureInfo.Name))
{
text = requestedAssemblyName.CultureInfo.Name + "." + text;
}
byte[] rawAssembly;
using (Stream stream = LoadStream(assemblyNames, text))
{
if (stream == null)
{
return null;
}
rawAssembly = ReadStream(stream);
}
using (Stream stream2 = LoadStream(symbolNames, text))
{
if (stream2 != null)
{
byte[] rawSymbolStore = ReadStream(stream2);
return Assembly.Load(rawAssembly, rawSymbolStore);
}
}
return Assembly.Load(rawAssembly);
}
public static Assembly ResolveAssembly(object sender, ResolveEventArgs e)
{
lock (nullCacheLock)
{
if (nullCache.ContainsKey(e.Name))
{
return null;
}
}
AssemblyName assemblyName = new AssemblyName(e.Name);
Assembly assembly = ReadExistingAssembly(assemblyName);
if ((object)assembly != null)
{
return assembly;
}
assembly = ReadFromEmbeddedResources(assemblyNames, symbolNames, assemblyName);
if ((object)assembly == null)
{
lock (nullCacheLock)
{
nullCache[e.Name] = true;
}
if ((assemblyName.Flags & AssemblyNameFlags.Retargetable) != 0)
{
assembly = Assembly.Load(assemblyName);
}
}
return assembly;
}
static AssemblyLoader()
{
assemblyNames.Add("standart.hash.xxhash", "costura.standart.hash.xxhash.dll.compressed");
assemblyNames.Add("system.text.json", "costura.system.text.json.dll.compressed");
}
public static void Attach()
{
if (Interlocked.Exchange(ref isAttached, 1) == 1)
{
return;
}
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs e)
{
lock (nullCacheLock)
{
if (nullCache.ContainsKey(e.Name))
{
return null;
}
}
AssemblyName assemblyName = new AssemblyName(e.Name);
Assembly assembly = ReadExistingAssembly(assemblyName);
if ((object)assembly != null)
{
return assembly;
}
assembly = ReadFromEmbeddedResources(assemblyNames, symbolNames, assemblyName);
if ((object)assembly == null)
{
lock (nullCacheLock)
{
nullCache[e.Name] = true;
}
if ((assemblyName.Flags & AssemblyNameFlags.Retargetable) != 0)
{
assembly = Assembly.Load(assemblyName);
}
}
return assembly;
};
}
}
}
internal class Bloodstone_ProcessedByFody
{
internal const string FodyVersion = "6.6.2.0";
internal const string Costura = "5.7.0";
}