Fix stuff

This commit is contained in:
Sardelka9515
2023-02-16 18:56:56 +08:00
parent e5f426690f
commit 6e2b4aff2f
12 changed files with 44 additions and 17 deletions

View File

@ -3,6 +3,7 @@ using RageCoop.Core;
using RageCoop.Core.Scripting;
using System;
using System.Collections.Generic;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
using static RageCoop.Core.Scripting.CustomEvents;
@ -85,6 +86,26 @@ namespace RageCoop.Client.Scripting
[UnmanagedCallersOnly(EntryPoint = nameof(GetLastResultLenInChars))]
public static int GetLastResultLenInChars() => _lastResult?.Length ?? 0;
[UnmanagedCallersOnly(EntryPoint = nameof(RegisterCustomEventHandler))]
public static bool RegisterCustomEventHandler(CustomEventHash hash, IntPtr ptrHandler)
{
try
{
lock (CustomEventHandlers)
{
if (!CustomEventHandlers.TryGetValue(hash, out var handlers))
CustomEventHandlers.Add(hash, handlers = new());
handlers.Add(new(ptrHandler));
}
return true;
}
catch (Exception ex)
{
Log.Error(nameof(RegisterCustomEventHandler), ex);
return false;
}
}
/// <summary>
/// Convert Entity ID to handle
/// </summary>