be diff
786 lines
using System;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography;
using System.Text;
using System.Text;
using JetBrains.Annotations;
using JetBrains.Annotations;
using LibraryLoader;
using LibraryLoader;
using NLog;
using NLog;
using UnityEngine;
using UnityEngine;
namespace BattlEye
namespace BattlEye
{
{
public sealed class BEClient : IDisposable
public sealed class BEClient : IDisposable
{
{
public static string GetEditorDLLFolderPath()
public static string GetEditorDLLFolderPath()
{
{
return BEClient.ApplicationDataPath + "/../../tools/windows/Battleye/Windows/BattlEye/";
return BEClient.ApplicationDataPath + "/../../tools/windows/Battleye/Windows/BattlEye/";
}
}
private static string ApplicationDataPath
private static string ApplicationDataPath
{
{
get
get
{
{
if (string.IsNullOrEmpty(BEClient._applicationDataPath))
if (string.IsNullOrEmpty(BEClient._applicationDataPath))
{
{
BEClient._applicationDataPath = Application.dataPath;
BEClient._applicationDataPath = Application.dataPath;
}
}
return BEClient._applicationDataPath;
return BEClient._applicationDataPath;
}
}
}
}
public static string GetBuildDLLFolderPath()
public static string GetBuildDLLFolderPath()
{
{
return BEClient.ApplicationDataPath + "/../BattlEye/";
return BEClient.ApplicationDataPath + "/../BattlEye/";
}
}
public static string GetEditorBEWindowsPath()
public static string GetEditorBEWindowsPath()
{
{
return BEClient.ApplicationDataPath + "/../../tools/windows/Battleye/Windows/";
return BEClient.ApplicationDataPath + "/../../tools/windows/Battleye/Windows/";
}
}
public static string GetEditorDllPath()
public static string GetEditorDllPath()
{
{
return BEClient.GetEditorDLLFolderPath() + "BEClient_x64.dll";
return BEClient.GetEditorDLLFolderPath() + "BEClient_x64.dll";
}
}
public static string GetReleaseDllPath()
public static string GetReleaseDllPath()
{
{
return BEClient.GetBuildDLLFolderPath() + "BEClient_x64.dll";
return BEClient.GetBuildDLLFolderPath() + "BEClient_x64.dll";
}
}
public static string GetBEClientDllPath()
public static string GetBEClientDllPath()
{
{
return BEClient.GetReleaseDllPath();
return BEClient.GetReleaseDllPath();
}
}
public static void CacheStaticData()
public static void CacheStaticData()
{
{
string applicationDataPath = BEClient.ApplicationDataPath;
string applicationDataPath = BEClient.ApplicationDataPath;
}
}
public static CreateInstanceResult Start([NotNull] string gameNameWithVersion, uint serverAddress, ushort serverPort, [NotNull] IBattlEyeClientRequestHandler requestHandler, BEClient.LogDelegate logDelegate, BEClient.IsLogLevelEnabledDelegate isLogLevelEnabledDelegate)
public static CreateInstanceResult Start([NotNull] string gameNameWithVersion, uint serverAddress, ushort serverPort, [NotNull] IBattlEyeClientRequestHandler requestHandler, BEClient.LogDelegate logDelegate, BEClient.IsLogLevelEnabledDelegate isLogLevelEnabledDelegate)
{
{
object lockObject = BEClient.LockObject;
object lockObject = BEClient.LockObject;
CreateInstanceResult result;
CreateInstanceResult result;
lock (lockObject)
lock (lockObject)
{
{
CreateInstanceResult createInstanceResult = BEClient.CreateInstance(BEClient.GetBEClientDllPath(), logDelegate, isLogLevelEnabledDelegate);
CreateInstanceResult createInstanceResult = BEClient.CreateInstance(BEClient.GetBEClientDllPath(), logDelegate, isLogLevelEnabledDelegate);
if (BEClient.Instance != null)
if (BEClient.Instance != null)
{
{
BEClient.Instance.Init(gameNameWithVersion, serverAddress, serverPort, requestHandler);
BEClient.Instance.Init(gameNameWithVersion, serverAddress, serverPort, requestHandler);
}
}
result = createInstanceResult;
result = createInstanceResult;
}
}
return result;
return result;
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
public static void Stop()
public static void Stop()
{
{
object lockObject = BEClient.LockObject;
object lockObject = BEClient.LockObject;
lock (lockObject)
lock (lockObject)
{
{
if (!BEClient.IsInstanceSuccessfully())
if (!BEClient.IsInstanceSuccessfully())
{
{
return;
return;
}
}
BEClient.Instance._initializationStatus = BEClient.EInstanceStatus.Destroying;
BEClient.Instance._initializationStatus = BEClient.EInstanceStatus.Destroying;
}
}
BEClient.DestroyInstance();
BEClient.DestroyInstance();
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
public static void AcceptServerPacket(byte[] packet)
public static void AcceptServerPacket(byte[] packet)
{
{
object lockObject = BEClient.LockObject;
object lockObject = BEClient.LockObject;
lock (lockObject)
lock (lockObject)
{
{
if (BEClient.IsInstanceSuccessfully())
if (BEClient.IsInstanceSuccessfully())
{
{
BEClient.Instance.ReceivedPacket(packet);
BEClient.Instance.ReceivedPacket(packet);
}
}
}
}
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
public static void Update()
public static void Update()
{
{
object lockObject = BEClient.LockObject;
object lockObject = BEClient.LockObject;
lock (lockObject)
lock (lockObject)
{
{
if (BEClient.IsInstanceSuccessfully())
if (BEClient.IsInstanceSuccessfully())
{
{
BEClient.Instance.Run();
BEClient.Instance.Run();
}
}
}
}
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
public static void EncryptPacket(byte[] sourcePacket, int sourcePacketOffset, int sourcePacketLength, byte[] encryptedPacket, int encryptedPacketOffset, ref int encryptedPacketLength)
public static void EncryptPacket(byte[] sourcePacket, int sourcePacketOffset, int sourcePacketLength, byte[] encryptedPacket, int encryptedPacketOffset, ref int encryptedPacketLength)
{
{
object lockObject = BEClient.LockObject;
object lockObject = BEClient.LockObject;
lock (lockObject)
lock (lockObject)
{
{
if (BEClient.IsInstanceSuccessfully())
if (BEClient.IsInstanceSuccessfully())
{
{
BEClient.Instance.EncryptClientPacket(sourcePacket, sourcePacketOffset, sourcePacketLength, encryptedPacket, encryptedPacketOffset, ref encryptedPacketLength);
BEClient.Instance.EncryptClientPacket(sourcePacket, sourcePacketOffset, sourcePacketLength, encryptedPacket, encryptedPacketOffset, ref encryptedPacketLength);
}
}
}
}
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
public static void DecryptPacket(byte[] encryptedPacket, int encryptedPacketOffset, int encryptedPacketLength, byte[] decryptedPacket, int decryptedPacketOffset, ref int decryptedPacketLength)
public static void DecryptPacket(byte[] encryptedPacket, int encryptedPacketOffset, int encryptedPacketLength, byte[] decryptedPacket, int decryptedPacketOffset, ref int decryptedPacketLength)
{
{
object lockObject = BEClient.LockObject;
object lockObject = BEClient.LockObject;
lock (lockObject)
lock (lockObject)
{
{
if (BEClient.IsInstanceSuccessfully())
if (BEClient.IsInstanceSuccessfully())
{
{
BEClient.Instance.DecryptServerPacket(encryptedPacket, encryptedPacketOffset, encryptedPacketLength, decryptedPacket, decryptedPacketOffset, ref decryptedPacketLength);
BEClient.Instance.DecryptServerPacket(encryptedPacket, encryptedPacketOffset, encryptedPacketLength, decryptedPacket, decryptedPacketOffset, ref decryptedPacketLength);
}
}
}
}
}
}
private static bool IsInstanceSuccessfully()
private static bool IsInstanceSuccessfully()
{
{
return BEClient.Instance != null && BEClient.Instance._initializationStatus == BEClient.EInstanceStatus.SuccessfullyInitialized;
return BEClient.Instance != null && BEClient.Instance._initializationStatus == BEClient.EInstanceStatus.SuccessfullyInitialized;
}
}
public static byte[] OpenEncryptionKey
public static byte[] OpenEncryptionKey
{
{
get
get
{
{
object lockObject = BEClient.LockObject;
object lockObject = BEClient.LockObject;
byte[] openEncryptionKey;
byte[] openEncryptionKey;
lock (lockObject)
lock (lockObject)
{
{
if (!BEClient.IsInstanceSuccessfully())
if (!BEClient.IsInstanceSuccessfully())
{
{
throw new NotImplementedException();
throw new NotImplementedException();
}
}
openEncryptionKey = BEClient.Instance._openEncryptionKey;
openEncryptionKey = BEClient.Instance._openEncryptionKey;
}
}
return openEncryptionKey;
return openEncryptionKey;
}
}
}
}
public static int OpenEncryptionKeyLength
public static int OpenEncryptionKeyLength
{
{
get
get
{
{
object lockObject = BEClient.LockObject;
object lockObject = BEClient.LockObject;
int openEncryptionKeyLength;
int openEncryptionKeyLength;
lock (lockObject)
lock (lockObject)
{
{
if (!BEClient.IsInstanceSuccessfully())
if (!BEClient.IsInstanceSuccessfully())
{
{
throw new NotImplementedException();
throw new NotImplementedException();
}
}
openEncryptionKeyLength = BEClient.Instance._openEncryptionKeyLength;
openEncryptionKeyLength = BEClient.Instance._openEncryptionKeyLength;
}
}
return openEncryptionKeyLength;
return openEncryptionKeyLength;
}
}
}
}
private static CreateInstanceResult CreateInstance(string path, BEClient.LogDelegate logDelegate, BEClient.IsLogLevelEnabledDelegate isLogLevelEnabledDelegate)
private static CreateInstanceResult CreateInstance(string path, BEClient.LogDelegate logDelegate, BEClient.IsLogLevelEnabledDelegate isLogLevelEnabledDelegate)
{
{
BEClient._logger = new BEClient.Logger(logDelegate, isLogLevelEnabledDelegate);
BEClient._logger = new BEClient.Logger(logDelegate, isLogLevelEnabledDelegate);
BEClient._loaderUtility = new LibraryLoaderUtility(BEClient._logger);
BEClient._loaderUtility = new LibraryLoaderUtility(BEClient._logger);
LoadDllResult loadDllResult = BEClient._loaderUtility.LoadDll(path);
LoadDllResult loadDllResult = BEClient._loaderUtility.LoadDll(path);
if (loadDllResult.HasError)
if (loadDllResult.HasError)
{
{
return new CreateInstanceResult
return new CreateInstanceResult
{
{
LoadDllError = loadDllResult.ErrorCode
LoadDllError = loadDllResult.ErrorCode
};
};
}
}
GetFuncResult<BEClient.BEClientWrapper.BEClientInitFn> initFunction = BEClient.BEClientWrapper.GetInitFunction(loadDllResult.DllPtr);
GetFuncResult<BEClient.BEClientWrapper.BEClientInitFn> initFunction = BEClient.BEClientWrapper.GetInitFunction(loadDllResult.DllPtr);
if (initFunction.HasError)
if (initFunction.HasError)
{
{
BEClient._loaderUtility.ReleaseDll(loadDllResult.DllPtr);
BEClient._loaderUtility.ReleaseDll(loadDllResult.DllPtr);
return new CreateInstanceResult
return new CreateInstanceResult
{
{
LoadInitFuncError = initFunction.ErrorCode
LoadInitFuncError = initFunction.ErrorCode
};
};
}
}
GetFuncResult<BEClient.BEClientWrapper.BEClientGetVerFn> verFunction = BEClient.BEClientWrapper.GetVerFunction(loadDllResult.DllPtr);
GetFuncResult<BEClient.BEClientWrapper.BEClientGetVerFn> verFunction = BEClient.BEClientWrapper.GetVerFunction(loadDllResult.DllPtr);
if (verFunction.HasError)
if (verFunction.HasError)
{
{
BEClient._loaderUtility.ReleaseDll(loadDllResult.DllPtr);
BEClient._loaderUtility.ReleaseDll(loadDllResult.DllPtr);
return new CreateInstanceResult
return new CreateInstanceResult
{
{
LoadGetVerFuncError = verFunction.ErrorCode
LoadGetVerFuncError = verFunction.ErrorCode
};
};
}
}
BEClient.Instance = new BEClient(loadDllResult.DllPtr, initFunction.FuncDelegate, verFunction.FuncDelegate);
BEClient.Instance = new BEClient(loadDllResult.DllPtr, initFunction.FuncDelegate, verFunction.FuncDelegate);
BEClient._instanceGcHandle = GCHandle.Alloc(BEClient.Instance, GCHandleType.Pinned);
BEClient._instanceGcHandle = GCHandle.Alloc(BEClient.Instance, GCHandleType.Pinned);
return default(CreateInstanceResult);
return default(CreateInstanceResult);
}
}
private static void DestroyInstance()
private static void DestroyInstance()
{
{
if (BEClient.Instance == null)
{
return;
}
BEClient instance = BEClient.Instance;
BEClient instance = BEClient.Instance;
BEClient.Instance = null;
BEClient.Instance = null;
instance.Dispose();
instance.Dispose();
}
}
private BEClient(IntPtr beDllPtr, BEClient.BEClientWrapper.BEClientInitFn initFn, BEClient.BEClientWrapper.BEClientGetVerFn getVerFn)
private BEClient(IntPtr beDllPtr, BEClient.BEClientWrapper.BEClientInitFn initFn, BEClient.BEClientWrapper.BEClientGetVerFn getVerFn)
{
{
this._beDllPtr = beDllPtr;
this._beDllPtr = beDllPtr;
this._initFunction = initFn;
this._initFunction = initFn;
this._getVersionFunction = getVerFn;
this._getVersionFunction = getVerFn;
this._pinnedObjects = new List<GCHandle>(10);
this._pinnedObjects = new List<GCHandle>(10);
this._initializationStatus = BEClient.EInstanceStatus.NotInitialized;
this._initializationStatus = BEClient.EInstanceStatus.NotInitialized;
}
}
private void PinObject(object o)
private void PinObject(object o)
{
{
this._pinnedObjects.Add(GCHandle.Alloc(o, GCHandleType.Pinned));
this._pinnedObjects.Add(GCHandle.Alloc(o, GCHandleType.Pinned));
}
}
private void ReleaseUnmanagedResources()
private void ReleaseUnmanagedResources()
{
{
foreach (GCHandle gchandle in this._pinnedObjects)
foreach (GCHandle gchandle in this._pinnedObjects)
{
{
if (gchandle.IsAllocated)
if (gchandle.IsAllocated)
{
{
gchandle.Free();
gchandle.Free();
}
}
}
}
this._pinnedObjects.Clear();
this._pinnedObjects.Clear();
if (this._beDllPtr != IntPtr.Zero)
if (this._beDllPtr != IntPtr.Zero)
{
{
BEClient._instanceGcHandle.Free();
BEClient._instanceGcHandle.Free();
IntPtr beDllPtr = this._beDllPtr;
IntPtr beDllPtr = this._beDllPtr;
this._beDllPtr = IntPtr.Zero;
this._beDllPtr = IntPtr.Zero;
BEClient._loaderUtility.ReleaseDll(beDllPtr);
BEClient._loaderUtility.ReleaseDll(beDllPtr);
}
}
}
}
public void Dispose()
public void Dispose()
{
{
BEClient._logger.Log(LogLevel.Info, "Disposing BEClient", Array.Empty<object>());
BEClient._logger.Log(LogLevel.Info, "Disposing BEClient", Array.Empty<object>());
if (this._initializationStatus == BEClient.EInstanceStatus.SuccessfullyInitialized || this._initializationStatus == BEClient.EInstanceStatus.Destroying)
if (this._initializationStatus == BEClient.EInstanceStatus.SuccessfullyInitialized || this._initializationStatus == BEClient.EInstanceStatus.Destroying)
{
{
this.Exit();
this.Exit();
}
}
this.ReleaseUnmanagedResources();
this.ReleaseUnmanagedResources();
this._beClientData = null;
this._beClientData = null;
this._beClientDataExists = false;
this._beClientGameData = null;
this._beClientGameData = null;
this._initFunction = null;
this._initFunction = null;
this._getVersionFunction = null;
this._getVersionFunction = null;
this._initializationStatus = BEClient.EInstanceStatus.Destroyed;
this._initializationStatus = BEClient.EInstanceStatus.Destroyed;
this._requestHandler = null;
this._requestHandler = null;
this._requestHandlerExists = false;
GC.SuppressFinalize(this);
GC.SuppressFinalize(this);
}
}
~BEClient()
~BEClient()
{
{
this.ReleaseUnmanagedResources();
this.ReleaseUnmanagedResources();
}
}
private void PfnRequestRestart(int reasonCode)
private void PfnRequestRestart(int reasonCode)
{
{
BEClient._logger.Log(LogLevel.Info, "PfnRequestRestart({0})", new object[]
BEClient._logger.Log(LogLevel.Info, "PfnRequestRestart({0})", new object[]
{
{
reasonCode
reasonCode
});
});
BEClient.ERestartReason reason;
BEClient.ERestartReason reason;
if (reasonCode != 0)
if (reasonCode != 0)
{
{
if (reasonCode != 1)
if (reasonCode != 1)
{
{
reason = BEClient.ERestartReason.BATTLEYE_UnknownRestartReason;
reason = BEClient.ERestartReason.BATTLEYE_UnknownRestartReason;
}
}
else
else
{
{
reason = BEClient.ERestartReason.BATTLEYE_ServiceNeedsToBeUpdated;
reason = BEClient.ERestartReason.BATTLEYE_ServiceNeedsToBeUpdated;
}
}
}
}
else
else
{
{
reason = BEClient.ERestartReason.BATTLEYE_ServiceNotRunningProperly;
reason = BEClient.ERestartReason.BATTLEYE_ServiceNotRunningProperly;
}
}
this.OnRequestRestart(reason);
this.OnRequestRestart(reason);
}
}
private void PfnSendPacket(IntPtr packetPointer, int packetByteLength)
private void PfnSendPacket(IntPtr packetPointer, int packetByteLength)
{
{
byte[] array = new byte[packetByteLength];
byte[] array = new byte[packetByteLength];
Marshal.Copy(packetPointer, array, 0, packetByteLength);
Marshal.Copy(packetPointer, array, 0, packetByteLength);
this.OnSendPacket(array);
this.OnSendPacket(array);
}
}
private void PfnPrintMessage(string message)
private void PfnPrintMessage(string message)
{
{
BEClient._logger.Log(LogLevel.Info, message, Array.Empty<object>());
BEClient._logger.Log(LogLevel.Info, message, Array.Empty<object>());
}
}
private unsafe BEClient.EInstanceStatus Init([NotNull] string gameNameWithVersion, uint serverAddress, ushort serverPort, [NotNull] IBattlEyeClientRequestHandler requestHandler)
private unsafe BEClient.EInstanceStatus Init([NotNull] string gameNameWithVersion, uint serverAddress, ushort serverPort, [NotNull] IBattlEyeClientRequestHandler requestHandler)
{
{
if (this._initializationStatus != BEClient.EInstanceStatus.NotInitialized || this._initFunction == null)
{
return this._initializationStatus;
}
this._beClientData = new BEClient.BEClientWrapper.BECL_BE_DATA();
this._beClientData = new BEClient.BEClientWrapper.BECL_BE_DATA();
this._beClientDataExists = true;
this.PinObject(this._beClientData);
this.PinObject(this._beClientData);
this._beClientGameData = new BEClient.BEClientWrapper.BECL_GAME_DATA
this._beClientGameData = new BEClient.BEClientWrapper.BECL_GAME_DATA
{
{
pstrGameVersion = gameNameWithVersion,
pstrGameVersion = gameNameWithVersion,
uiAddress = serverAddress,
uiAddress = serverAddress,
usPort = serverPort,
usPort = serverPort,
pfnPrintMessage = new BEClient.BEClientWrapper.BECL_GAME_DATA.PrintMessageFn(this.PfnPrintMessage),
pfnPrintMessage = new BEClient.BEClientWrapper.BECL_GAME_DATA.PrintMessageFn(this.PfnPrintMessage),
pfnSendPacket = new BEClient.BEClientWrapper.BECL_GAME_DATA.SendPacketFn(this.PfnSendPacket),
pfnSendPacket = new BEClient.BEClientWrapper.BECL_GAME_DATA.SendPacketFn(this.PfnSendPacket),
pfnRequestRestart = new BEClient.BEClientWrapper.BECL_GAME_DATA.RequestRestartFn(this.PfnRequestRestart),
pfnRequestRestart = new BEClient.BEClientWrapper.BECL_GAME_DATA.RequestRestartFn(this.PfnRequestRestart),
pfnDisconnectPeer = null
pfnDisconnectPeer = null
};
};
BEClient._logger.Log(LogLevel.Debug, "Init: {0}", new object[]
BEClient._logger.Log(LogLevel.Debug, "Init: {0}", new object[]
{
{
this._beClientGameData
this._beClientGameData
});
});
this.PinObject(this._beClientGameData);
this.PinObject(this._beClientGameData);
this.PinObject(this._beClientGameData.pfnPrintMessage);
this.PinObject(this._beClientGameData.pfnPrintMessage);
this.PinObject(this._beClientGameData.pfnRequestRestart);
this.PinObject(this._beClientGameData.pfnRequestRestart);
this.PinObject(this._beClientGameData.pfnSendPacket);
this.PinObject(this._beClientGameData.pfnSendPacket);
this.PinObject(this._beClientGameData.pstrGameVersion);
this.PinObject(this._beClientGameData.pstrGameVersion);
this._openEncryptionKey = new byte[256];
this._openEncryptionKey = new byte[256];
this.PinObject(this._openEncryptionKey);
this.PinObject(this._openEncryptionKey);
fixed (byte* ptr = &this._openEncryptionKey[0])
fixed (byte* ptr = &this._openEncryptionKey[0])
{
{
byte* value = ptr;
byte* value = ptr;
this._beClientData.pvEncryptionKey = new IntPtr((void*)value);
this._beClientData.pvEncryptionKey = new IntPtr((void*)value);
this._beClientData.nEncryptionKeyLength = this._openEncryptionKey.Length;
this._beClientData.nEncryptionKeyLength = this._openEncryptionKey.Length;
this._initializationStatus = (this._initFunction(4, this._beClientGameData, this._beClientData) ? BEClient.EInstanceStatus.SuccessfullyInitialized : BEClient.EInstanceStatus.NotInitialized);
this._initializationStatus = (this._initFunction(4, this._beClientGameData, this._beClientData) ? BEClient.EInstanceStatus.SuccessfullyInitialized : BEClient.EInstanceStatus.NotInitialized);
}
}
this.PinObject(this._beClientData.pfnAddPeer);
this.PinObject(this._beClientData.pfnAddPeer);
this.PinObject(this._beClientData.pfnCommand);
this.PinObject(this._beClientData.pfnCommand);
this.PinObject(this._beClientData.pfnExit);
this.PinObject(this._beClientData.pfnExit);
this.PinObject(this._beClientData.pfnOnReceiveAuthTicket);
this.PinObject(this._beClientData.pfnOnReceiveAuthTicket);
this.PinObject(this._beClientData.pfnReceivedPacket);
this.PinObject(this._beClientData.pfnReceivedPacket);
this.PinObject(this._beClientData.pfnRemovePeer);
this.PinObject(this._beClientData.pfnRemovePeer);
this.PinObject(this._beClientData.pfnRun);
this.PinObject(this._beClientData.pfnRun);
this.PinObject(this._beClientData.pfnEncryptClientPacket);
this.PinObject(this._beClientData.pfnEncryptClientPacket);
this.PinObject(this._beClientData.pfnDecryptServerPacket);
this.PinObject(this._beClientData.pfnDecryptServerPacket);
this._requestHandler = requestHandler;
this._requestHandler = requestHandler;
this._requestHandlerExists = true;
this._openEncryptionKeyLength = this._beClientData.nEncryptionKeyLength;
this._openEncryptionKeyLength = this._beClientData.nEncryptionKeyLength;
if (this._initializationStatus == BEClient.EInstanceStatus.SuccessfullyInitialized)
if (this._initializationStatus == BEClient.EInstanceStatus.SuccessfullyInitialized)
{
{
BEClient._logger.Log(LogLevel.Info, "BEClient inited successfully", Array.Empty<object>());
BEClient._logger.Log(LogLevel.Info, "BEClient inited successfully", Array.Empty<object>());
}
}
else
else
{
{
BEClient._logger.Log(LogLevel.Error, "BEClient initialization failed", Array.Empty<object>());
BEClient._logger.Log(LogLevel.Error, "BEClient initialization failed", Array.Empty<object>());
}
}
BEClient._logger.Log(LogLevel.Trace, "Client key: len:{0} data:{1}", new object[]
BEClient._logger.Log(LogLevel.Trace, "Client key: len:{0} data:{1}", new object[]
{
{
this._openEncryptionKeyLength,
this._openEncryptionKeyLength,
BitConverter.ToString(this._openEncryptionKey, 0, this._openEncryptionKeyLength)
BitConverter.ToString(this._openEncryptionKey, 0, this._openEncryptionKeyLength)
});
});
return this._initializationStatus;
return this._initializationStatus;
}
}
private int GetVersion()
private int GetVersion()
{
{
return this._getVersionFunction();
return this._getVersionFunction();
}
}
private bool Exit()
private bool Exit()
{
{
if (this._initializationStatus != BEClient.EInstanceStatus.Destroying || !this._beClientDataExists)
{
return false;
}
BEClient._logger.Log(LogLevel.Info, "BEClient exit", Array.Empty<object>());
BEClient._logger.Log(LogLevel.Info, "BEClient exit", Array.Empty<object>());
bool flag = this._beClientData.pfnExit();
bool flag = this._beClientData.pfnExit();
if (flag)
if (flag)
{
{
BEClient._logger.Log(LogLevel.Info, "BEClient exit successfully", Array.Empty<object>());
BEClient._logger.Log(LogLevel.Info, "BEClient exit successfully", Array.Empty<object>());
return flag;
return flag;
}
}
BEClient._logger.Log(LogLevel.Error, "BEClient exit failure", Array.Empty<object>());
BEClient._logger.Log(LogLevel.Error, "BEClient exit failure", Array.Empty<object>());
return flag;
return flag;
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
private void Command(string pstrCommand)
private void Command(string pstrCommand)
{
{
if (this._initializationStatus != BEClient.EInstanceStatus.SuccessfullyInitialized || !this._beClientDataExists)
{
return;
}
GCHandle gchandle = GCHandle.Alloc(pstrCommand, GCHandleType.Pinned);
GCHandle gchandle = GCHandle.Alloc(pstrCommand, GCHandleType.Pinned);
this._beClientData.pfnCommand(pstrCommand);
this._beClientData.pfnCommand(pstrCommand);
gchandle.Free();
gchandle.Free();
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
private void Run()
private void Run()
{
{
if (this._initializationStatus != BEClient.EInstanceStatus.SuccessfullyInitialized || !this._beClientDataExists)
{
return;
}
BEClient._logger.Log(LogLevel.Trace, "BEClient.Run", Array.Empty<object>());
BEClient._logger.Log(LogLevel.Trace, "BEClient.Run", Array.Empty<object>());
this._beClientData.pfnRun();
this._beClientData.pfnRun();
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
private unsafe void ReceivedPacket(byte[] packet)
private unsafe void ReceivedPacket(byte[] packet)
{
{
if (this._initializationStatus != BEClient.EInstanceStatus.SuccessfullyInitialized || !this._beClientDataExists)
{
return;
}
BEClient._logger.Log(LogLevel.Debug, "ReceivedPacket packet size: {0}", new object[]
BEClient._logger.Log(LogLevel.Debug, "ReceivedPacket packet size: {0}", new object[]
{
{
packet.Length
packet.Length
});
});
int nLength = Marshal.SizeOf<byte>(packet[0]) * packet.Length;
int nLength = Marshal.SizeOf<byte>(packet[0]) * packet.Length;
fixed (byte* ptr = &packet[0])
fixed (byte* ptr = &packet[0])
{
{
byte* value = ptr;
byte* value = ptr;
IntPtr pvPacket = new IntPtr((void*)value);
IntPtr pvPacket = new IntPtr((void*)value);
this._beClientData.pfnReceivedPacket(pvPacket, nLength);
this._beClientData.pfnReceivedPacket(pvPacket, nLength);
}
}
}
}
private void OnRequestRestart(BEClient.ERestartReason reason)
private void OnRequestRestart(BEClient.ERestartReason reason)
{
{
if (this._initializationStatus != BEClient.EInstanceStatus.SuccessfullyInitialized || !this._requestHandlerExists)
{
return;
}
BEClient._logger.Log(LogLevel.Debug, "OnRequestRestart reason: {0}", new object[]
BEClient._logger.Log(LogLevel.Debug, "OnRequestRestart reason: {0}", new object[]
{
{
reason
reason
});
});
this._requestHandler.OnRequestRestart(reason);
this._requestHandler.OnRequestRestart(reason);
}
}
private void OnSendPacket(byte[] bePacket)
private void OnSendPacket(byte[] bePacket)
{
{
if (this._initializationStatus != BEClient.EInstanceStatus.SuccessfullyInitialized || !this._requestHandlerExists)
{
return;
}
BEClient._logger.Log(LogLevel.Debug, "OnSendPacket packet size: {0}", new object[]
BEClient._logger.Log(LogLevel.Debug, "OnSendPacket packet size: {0}", new object[]
{
{
bePacket.Length
bePacket.Length
});
});
this._requestHandler.OnSendPacket(bePacket);
this._requestHandler.OnSendPacket(bePacket);
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
private unsafe void EncryptClientPacket(byte[] sourcePacket, int sourcePacketOffset, int sourcePacketLength, byte[] encryptedPacket, int encryptedPacketOffset, ref int encryptedPacketLength)
private unsafe void EncryptClientPacket(byte[] sourcePacket, int sourcePacketOffset, int sourcePacketLength, byte[] encryptedPacket, int encryptedPacketOffset, ref int encryptedPacketLength)
{
{
BEClient._logger.Log(LogLevel.Debug, "EncryptClientPacket packet size: {0}", new object[]
BEClient._logger.Log(LogLevel.Debug, "EncryptClientPacket packet size: {0}", new object[]
{
{
sourcePacketLength
sourcePacketLength
});
});
if (this._initializationStatus != BEClient.EInstanceStatus.SuccessfullyInitialized || !this._beClientDataExists)
{
return;
}
fixed (byte* ptr = &sourcePacket[sourcePacketOffset])
fixed (byte* ptr = &sourcePacket[sourcePacketOffset])
{
{
byte* value = ptr;
byte* value = ptr;
fixed (byte* ptr2 = &encryptedPacket[encryptedPacketOffset])
fixed (byte* ptr2 = &encryptedPacket[encryptedPacketOffset])
{
{
byte* value2 = ptr2;
byte* value2 = ptr2;
this._beClientData.pfnEncryptClientPacket(new IntPtr((void*)value), sourcePacketLength, new IntPtr((void*)value2), ref encryptedPacketLength);
this._beClientData.pfnEncryptClientPacket(new IntPtr((void*)value), sourcePacketLength, new IntPtr((void*)value2), ref encryptedPacketLength);
}
}
}
}
}
}
[Conditional("BATTLEYE_ANTICHEAT")]
[Conditional("BATTLEYE_ANTICHEAT")]
private unsafe void DecryptServerPacket(byte[] encryptedPacket, int encryptedPacketOffset, int encryptedPacketLength, byte[] decryptedPacket, int decryptedPacketOffset, ref int decryptedPacketLength)
private unsafe void DecryptServerPacket(byte[] encryptedPacket, int encryptedPacketOffset, int encryptedPacketLength, byte[] decryptedPacket, int decryptedPacketOffset, ref int decryptedPacketLength)
{
{
BEClient._logger.Log(LogLevel.Debug, "DecryptServerPacket packet size: {0}", new object[]
BEClient._logger.Log(LogLevel.Debug, "DecryptServerPacket packet size: {0}", new object[]
{
{
encryptedPacketLength
encryptedPacketLength
});
});
if (this._initializationStatus != BEClient.EInstanceStatus.SuccessfullyInitialized || !this._beClientDataExists)
{
return;
}
fixed (byte* ptr = &encryptedPacket[encryptedPacketOffset])
fixed (byte* ptr = &encryptedPacket[encryptedPacketOffset])
{
{
byte* value = ptr;
byte* value = ptr;
fixed (byte* ptr2 = &decryptedPacket[decryptedPacketOffset])
fixed (byte* ptr2 = &decryptedPacket[decryptedPacketOffset])
{
{
byte* value2 = ptr2;
byte* value2 = ptr2;
this._beClientData.pfnDecryptServerPacket(new IntPtr((void*)value), encryptedPacketLength, new IntPtr((void*)value2), ref decryptedPacketLength);
this._beClientData.pfnDecryptServerPacket(new IntPtr((void*)value), encryptedPacketLength, new IntPtr((void*)value2), ref decryptedPacketLength);
}
}
}
}
}
}
public const string BECLIENT_DLL_NAME = "BEClient_x64.dll";
public const string BECLIENT_DLL_NAME = "BEClient_x64.dll";
public const string BECLIENT_WINDOWS_FOLDER_EDITOR = "/../../tools/windows/Battleye/Windows/";
public const string BECLIENT_WINDOWS_FOLDER_EDITOR = "/../../tools/windows/Battleye/Windows/";
public const string BECLIENT_BATTLEYE_FOLDER_NAME = "BattlEye/";
public const string BECLIENT_BATTLEYE_FOLDER_NAME = "BattlEye/";
public const string BECLIENT_DLL_FOLDER_EDITOR = "/../../tools/windows/Battleye/Windows/BattlEye/";
public const string BECLIENT_DLL_FOLDER_EDITOR = "/../../tools/windows/Battleye/Windows/BattlEye/";
public const string BELIENT_DLL_FOLDER = "/../BattlEye/";
public const string BELIENT_DLL_FOLDER = "/../BattlEye/";
private static string _applicationDataPath;
private static string _applicationDataPath;
private static BEClient.Logger _logger;
private static BEClient.Logger _logger;
private static LibraryLoaderUtility _loaderUtility;
private static LibraryLoaderUtility _loaderUtility;
private static readonly object LockObject = new object();
private static readonly object LockObject = new object();
private static BEClient Instance;
private static BEClient Instance;
private static GCHandle _instanceGcHandle;
private static GCHandle _instanceGcHandle;
private IntPtr _beDllPtr;
private IntPtr _beDllPtr;
private IBattlEyeClientRequestHandler _requestHandler;
private IBattlEyeClientRequestHandler _requestHandler;
private readonly List<GCHandle> _pinnedObjects;
private readonly List<GCHandle> _pinnedObjects;
private BEClient.BEClientWrapper.BEClientInitFn _initFunction;
private BEClient.BEClientWrapper.BEClientInitFn _initFunction;
private BEClient.BEClientWrapper.BEClientGetVerFn _getVersionFunction;
private BEClient.BEClientWrapper.BEClientGetVerFn _getVersionFunction;
private BEClient.BEClientWrapper.BECL_BE_DATA _beClientData;
private BEClient.BEClientWrapper.BECL_BE_DATA _beClientData;
private BEClient.BEClientWrapper.BECL_GAME_DATA _beClientGameData;
private BEClient.BEClientWrapper.BECL_GAME_DATA _beClientGameData;
private byte[] _openEncryptionKey;
private byte[] _openEncryptionKey;
private int _openEncryptionKeyLength;
private int _openEncryptionKeyLength;
private BEClient.EInstanceStatus _initializationStatus;
private BEClient.EInstanceStatus _initializationStatus;
private bool _beClientDataExists;
private bool _requestHandlerExists;
private sealed class BEClientWrapper
private sealed class BEClientWrapper
{
{
public static GetFuncResult<BEClient.BEClientWrapper.BEClientInitFn> GetInitFunction(IntPtr loadDll)
public static GetFuncResult<BEClient.BEClientWrapper.BEClientInitFn> GetInitFunction(IntPtr loadDll)
{
{
return BEClient._loaderUtility.GetFunction<BEClient.BEClientWrapper.BEClientInitFn>(loadDll, "Init");
return BEClient._loaderUtility.GetFunction<BEClient.BEClientWrapper.BEClientInitFn>(loadDll, "Init");
}
}
public static GetFuncResult<BEClient.BEClientWrapper.BEClientGetVerFn> GetVerFunction(IntPtr dllPtr)
public static GetFuncResult<BEClient.BEClientWrapper.BEClientGetVerFn> GetVerFunction(IntPtr dllPtr)
{
{
return BEClient._loaderUtility.GetFunction<BEClient.BEClientWrapper.BEClientGetVerFn>(dllPtr, "GetVer");
return BEClient._loaderUtility.GetFunction<BEClient.BEClientWrapper.BEClientGetVerFn>(dllPtr, "GetVer");
}
}
public const int BECLIENT_INTEGRATION_VERSION = 4;
public const int BECLIENT_INTEGRATION_VERSION = 4;
[StructLayout(LayoutKind.Sequential)]
[StructLayout(LayoutKind.Sequential)]
public class BECL_GAME_DATA
public class BECL_GAME_DATA
{
{
public override string ToString()
public override string ToString()
{
{
return string.Format("{0}: {1}, {2}: {3}, {4}: {5}", new object[]
return string.Format("{0}: {1}, {2}: {3}, {4}: {5}", new object[]
{
{
"pstrGameVersion",
"pstrGameVersion",
this.pstrGameVersion,
this.pstrGameVersion,
"uiAddress",
"uiAddress",
this.uiAddress,
this.uiAddress,
"usPort",
"usPort",
this.usPort
this.usPort
});
});
}
}
[MarshalAs(UnmanagedType.LPStr)]
[MarshalAs(UnmanagedType.LPStr)]
public string pstrGameVersion;
public string pstrGameVersion;
public uint uiAddress;
public uint uiAddress;
public ushort usPort;
public ushort usPort;
public BEClient.BEClientWrapper.BECL_GAME_DATA.PrintMessageFn pfnPrintMessage;
public BEClient.BEClientWrapper.BECL_GAME_DATA.PrintMessageFn pfnPrintMessage;
public BEClient.BEClientWrapper.BECL_GAME_DATA.RequestRestartFn pfnRequestRestart;
public BEClient.BEClientWrapper.BECL_GAME_DATA.RequestRestartFn pfnRequestRestart;
public BEClient.BEClientWrapper.BECL_GAME_DATA.SendPacketFn pfnSendPacket;
public BEClient.BEClientWrapper.BECL_GAME_DATA.SendPacketFn pfnSendPacket;
public BEClient.BEClientWrapper.BECL_GAME_DATA.DisconnectPeerFn pfnDisconnectPeer;
public BEClient.BEClientWrapper.BECL_GAME_DATA.DisconnectPeerFn pfnDisconnectPeer;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void PrintMessageFn([MarshalAs(UnmanagedType.LPStr)] string pstrMessage);
public delegate void PrintMessageFn([MarshalAs(UnmanagedType.LPStr)] string pstrMessage);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void RequestRestartFn(int iReason);
public delegate void RequestRestartFn(int iReason);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SendPacketFn(IntPtr pvPacket, int nLength);
public delegate void SendPacketFn(IntPtr pvPacket, int nLength);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void DisconnectPeerFn(IntPtr pvPeerGUID, int nGUIDLength, [MarshalAs(UnmanagedType.LPStr)] string pstrReason);
public delegate void DisconnectPeerFn(IntPtr pvPeerGUID, int nGUIDLength, [MarshalAs(UnmanagedType.LPStr)] string pstrReason);
}
}
[StructLayout(LayoutKind.Sequential)]
[StructLayout(LayoutKind.Sequential)]
public class BECL_BE_DATA
public class BECL_BE_DATA
{
{
public BEClient.BEClientWrapper.BECL_BE_DATA.ExitFn pfnExit;
public BEClient.BEClientWrapper.BECL_BE_DATA.ExitFn pfnExit;
public BEClient.BEClientWrapper.BECL_BE_DATA.RunFn pfnRun;
public BEClient.BEClientWrapper.BECL_BE_DATA.RunFn pfnRun;
public BEClient.BEClientWrapper.BECL_BE_DATA.CommandFn pfnCommand;
public BEClient.BEClientWrapper.BECL_BE_DATA.CommandFn pfnCommand;
public BEClient.BEClientWrapper.BECL_BE_DATA.ReceivedPacketFn pfnReceivedPacket;
public BEClient.BEClientWrapper.BECL_BE_DATA.ReceivedPacketFn pfnReceivedPacket;
public BEClient.BEClientWrapper.BECL_BE_DATA.OnReceiveAuthTicketFn pfnOnReceiveAuthTicket;
public BEClient.BEClientWrapper.BECL_BE_DATA.OnReceiveAuthTicketFn pfnOnReceiveAuthTicket;
public BEClient.BEClientWrapper.BECL_BE_DATA.AddPeerFn pfnAddPeer;
public BEClient.BEClientWrapper.BECL_BE_DATA.AddPeerFn pfnAddPeer;
public BEClient.BEClientWrapper.BECL_BE_DATA.RemovePeerFn pfnRemovePeer;
public BEClient.BEClientWrapper.BECL_BE_DATA.RemovePeerFn pfnRemovePeer;
public IntPtr pvEncryptionKey;
public IntPtr pvEncryptionKey;
public int nEncryptionKeyLength;
public int nEncryptionKeyLength;
public BEClient.BEClientWrapper.BECL_BE_DATA.EncryptClientPacketFn pfnEncryptClientPacket;
public BEClient.BEClientWrapper.BECL_BE_DATA.EncryptClientPacketFn pfnEncryptClientPacket;
public BEClient.BEClientWrapper.BECL_BE_DATA.DecryptServerPacketFn pfnDecryptServerPacket;
public BEClient.BEClientWrapper.BECL_BE_DATA.DecryptServerPacketFn pfnDecryptServerPacket;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate bool ExitFn();
public delegate bool ExitFn();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void RunFn();
public delegate void RunFn();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void CommandFn([MarshalAs(UnmanagedType.LPStr)] string pstrCommand);
public delegate void CommandFn([MarshalAs(UnmanagedType.LPStr)] string pstrCommand);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ReceivedPacketFn(IntPtr pvPacket, int nLength);
public delegate void ReceivedPacketFn(IntPtr pvPacket, int nLength);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void OnReceiveAuthTicketFn(IntPtr pvTicket, int nTicketLength);
public delegate void OnReceiveAuthTicketFn(IntPtr pvTicket, int nTicketLength);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void AddPeerFn(IntPtr pvPeerGUID, int nGUIDLength);
public delegate void AddPeerFn(IntPtr pvPeerGUID, int nGUIDLength);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void RemovePeerFn(IntPtr pvPeerGUID, int nGUIDLength);
public delegate void RemovePeerFn(IntPtr pvPeerGUID, int nGUIDLength);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void EncryptClientPacketFn(IntPtr pvPacket, int nLength, IntPtr pvEncryptedPacket, ref int pnEncryptedLength);
public delegate void EncryptClientPacketFn(IntPtr pvPacket, int nLength, IntPtr pvEncryptedPacket, ref int pnEncryptedLength);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void DecryptServerPacketFn(IntPtr pvPacket, int nLength, IntPtr pvDecryptedPacket, ref int pnDecryptedLength);
public delegate void DecryptServerPacketFn(IntPtr pvPacket, int nLength, IntPtr pvDecryptedPacket, ref int pnDecryptedLength);
}
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int BEClientGetVerFn();
public delegate int BEClientGetVerFn();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate bool BEClientInitFn(int iIntegrationVersion, [MarshalAs(UnmanagedType.LPStruct)] [In] BEClient.BEClientWrapper.BECL_GAME_DATA pGameData, [MarshalAs(UnmanagedType.LPStruct)] [Out] BEClient.BEClientWrapper.BECL_BE_DATA pBEData);
public delegate bool BEClientInitFn(int iIntegrationVersion, [MarshalAs(UnmanagedType.LPStruct)] [In] BEClient.BEClientWrapper.BECL_GAME_DATA pGameData, [MarshalAs(UnmanagedType.LPStruct)] [Out] BEClient.BEClientWrapper.BECL_BE_DATA pBEData);
}
}
public enum ERestartReason
public enum ERestartReason
{
{
BATTLEYE_UnknownRestartReason = -1,
BATTLEYE_UnknownRestartReason = -1,
BATTLEYE_ServiceNotRunningProperly,
BATTLEYE_ServiceNotRunningProperly,
BATTLEYE_ServiceNeedsToBeUpdated
BATTLEYE_ServiceNeedsToBeUpdated
}
}
private class Logger : ILogHandler
private class Logger : ILogHandler
{
{
public Logger(BEClient.LogDelegate logDelegate, BEClient.IsLogLevelEnabledDelegate isLogLevelEnabledDelegate)
public Logger(BEClient.LogDelegate logDelegate, BEClient.IsLogLevelEnabledDelegate isLogLevelEnabledDelegate)
{
{
this._logDelegate = logDelegate;
this._logDelegate = logDelegate;
this._isLogLevelEnabledDelegate = isLogLevelEnabledDelegate;
this._isLogLevelEnabledDelegate = isLogLevelEnabledDelegate;
}
}
public void Log(LogLevel logLevel, string format, params object[] args)
public void Log(LogLevel logLevel, string format, params object[] args)
{
{
if (this._logDelegate != null)
if (this._logDelegate != null)
{
{
this._logDelegate(logLevel, format, args);
this._logDelegate(logLevel, format, args);
return;
return;
}
}
if (logLevel == LogLevel.Error)
if (logLevel == LogLevel.Error)
{
{
Debug.LogErrorFormat(format, args);
Debug.LogErrorFormat(format, args);
return;
return;
}
}
Debug.LogFormat(format, args);
Debug.LogFormat(format, args);
}
}
public bool IsEnabled(LogLevel logLevel)
public bool IsEnabled(LogLevel logLevel)
{
{
return this._isLogLevelEnabledDelegate == null || this._isLogLevelEnabledDelegate(logLevel);
return this._isLogLevelEnabledDelegate == null || this._isLogLevelEnabledDelegate(logLevel);
}
}
private static string hashToString(byte[] data)
private static string hashToString(byte[] data)
{
{
BEClient.Logger.sBuilder.Clear();
BEClient.Logger.sBuilder.Clear();
for (int i = 0; i < data.Length; i++)
for (int i = 0; i < data.Length; i++)
{
{
BEClient.Logger.sBuilder.Append(data[i].ToString("x2"));
BEClient.Logger.sBuilder.Append(data[i].ToString("x2"));
}
}
return BEClient.Logger.sBuilder.ToString();
return BEClient.Logger.sBuilder.ToString();
}
}
public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
{
{
switch (logType)
switch (logType)
{
{
case LogType.Error:
case LogType.Error:
case LogType.Assert:
case LogType.Assert:
this._logDelegate(LogLevel.Error, format, args);
this._logDelegate(LogLevel.Error, format, args);
return;
return;
case LogType.Warning:
case LogType.Warning:
this._logDelegate(LogLevel.Warn, format, args);
this._logDelegate(LogLevel.Warn, format, args);
return;
return;
case LogType.Log:
case LogType.Log:
this._logDelegate(LogLevel.Debug, format, args);
this._logDelegate(LogLevel.Debug, format, args);
return;
return;
case LogType.Exception:
case LogType.Exception:
this._logDelegate(LogLevel.Error, format, args);
this._logDelegate(LogLevel.Error, format, args);
return;
return;
default:
default:
throw new ArgumentOutOfRangeException("logType", logType, null);
throw new ArgumentOutOfRangeException("logType", logType, null);
}
}
}
}
public void LogException(Exception exception, UnityEngine.Object context)
public void LogException(Exception exception, UnityEngine.Object context)
{
{
this._logDelegate(LogLevel.Error, exception.Message, Array.Empty<object>());
this._logDelegate(LogLevel.Error, exception.Message, Array.Empty<object>());
}
}
private readonly BEClient.LogDelegate _logDelegate;
private readonly BEClient.LogDelegate _logDelegate;
private readonly BEClient.IsLogLevelEnabledDelegate _isLogLevelEnabledDelegate;
private readonly BEClient.IsLogLevelEnabledDelegate _isLogLevelEnabledDelegate;
private static MD5 md5 = MD5.Create();
private static MD5 md5 = MD5.Create();
private static StringBuilder sBuilder = new StringBuilder();
private static StringBuilder sBuilder = new StringBuilder();
}
}
public delegate void LogDelegate(LogLevel logLevel, string format, params object[] args);
public delegate void LogDelegate(LogLevel logLevel, string format, params object[] args);
public delegate bool IsLogLevelEnabledDelegate(LogLevel logLevel);
public delegate bool IsLogLevelEnabledDelegate(LogLevel logLevel);
private enum EInstanceStatus
private enum EInstanceStatus
{
{
None,
None,
NotInitialized,
NotInitialized,
SuccessfullyInitialized,
SuccessfullyInitialized,
Destroying,
Destroying,
Destroyed
Destroyed
}
}
}
}
}
}