Feature/plugin api experimental (#12)

* added a null check to fix crash, expose internal latency value (its buggy)

* fix latency calculations

* sending packets from c#

* world save event, move shutdown def, move called location of shutdown, expose FourKit.FireEvent

* add docs

---------

Co-authored-by: sylvessa <225480449+sylvessa@users.noreply.github.com>
This commit is contained in:
DrPerkyLegit 2026-04-05 22:21:22 -04:00 committed by GitHub
parent 682989c8f1
commit 21b5accc69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1420 additions and 20 deletions

View file

@ -17,14 +17,15 @@ namespace FourKitBridge
{
typedef void(__stdcall *fn_initialize)();
typedef int(__stdcall* fn_fire_player_prelogin)(const char* nameUtf8, int nameByteLen, const char* ipUtf8, int ipByteLen, int port);
typedef void(__stdcall *fn_shutdown)();
typedef void(__stdcall *fn_fire_world_save)();
typedef int(__stdcall *fn_fire_player_prelogin)(const char* nameUtf8, int nameByteLen, const char* ipUtf8, int ipByteLen, int port);
typedef int(__stdcall *fn_fire_player_login)(const char* nameUtf8, int nameByteLen, const char* ipUtf8, int ipByteLen, int port, int type, unsigned long long* offlineXUID, unsigned long long* onlineXUID);
typedef void(__stdcall *fn_fire_player_join)(int entityId, const char *nameUtf8, int nameByteLen, const char *uuidUtf8, int uuidByteLen, unsigned long long offlineXUID, unsigned long long onlineXUID);
typedef void(__stdcall *fn_fire_player_quit)(int entityId);
typedef int(__stdcall *fn_fire_player_kick)(int entityId, int disconnectReason,
const char *reasonUtf8, int reasonByteLen,
char *outBuf, int outBufSize, int *outLen);
typedef void(__stdcall *fn_shutdown)();
typedef int(__stdcall *fn_fire_player_move)(int entityId,
double fromX, double fromY, double fromZ,
double toX, double toY, double toZ,
@ -56,7 +57,8 @@ typedef int(__stdcall *fn_fire_player_death)(int entityId,
const char *deathMsgUtf8, int deathMsgByteLen, int exp,
char *outMsgBuf, int outMsgBufSize, int *outMsgLen, int *outKeepInventory,
int *outNewExp, int *outNewLevel, int *outKeepLevel);
typedef void(__stdcall *fn_set_player_callbacks)(void *kickPlayer, void *banPlayer, void *banPlayerIp, void *getPlayerAddress);
typedef void(__stdcall *fn_set_player_callbacks)(void *kickPlayer, void *banPlayer, void *banPlayerIp, void *getPlayerAddress, void *getPlayerLatency);
typedef void(__stdcall *fn_set_player_connection_callbacks)(void *sendRaw);
typedef long long(__stdcall *fn_fire_player_drop_item)(int entityId,
int itemId, int itemCount, int itemAux,
int *outItemId, int *outItemCount, int *outItemAux);
@ -103,13 +105,14 @@ struct OpenContainerInfo
static std::unordered_map<int, OpenContainerInfo> s_openContainerInfo;
static fn_initialize s_managedInit = nullptr;
static fn_shutdown s_managedShutdown = nullptr;
static fn_fire_world_save s_managedFireWorldSave = nullptr;
static fn_fire_player_prelogin s_managedFirePreLogin = nullptr;
static fn_fire_player_login s_managedFireLogin = nullptr;
static fn_fire_player_join s_managedFireJoin = nullptr;
static fn_update_entity_id s_managedUpdateEntityId = nullptr;
static fn_fire_player_quit s_managedFireQuit = nullptr;
static fn_fire_player_kick s_managedFireKick = nullptr;
static fn_shutdown s_managedShutdown = nullptr;
static fn_fire_player_move s_managedFireMove = nullptr;
static fn_set_native_callbacks s_managedSetCallbacks = nullptr;
static fn_set_world_callbacks s_managedSetWorldCallbacks = nullptr;
@ -122,6 +125,7 @@ static fn_fire_sign_change s_managedFireSignChange = nullptr;
static fn_fire_entity_death s_managedFireEntityDeath = nullptr;
static fn_fire_player_death s_managedFirePlayerDeath = nullptr;
static fn_set_player_callbacks s_managedSetPlayerCallbacks = nullptr;
static fn_set_player_connection_callbacks s_managedSetPlayerConnectionCallbacks = nullptr;
static fn_fire_player_drop_item s_managedFirePlayerDropItem = nullptr;
static fn_set_inventory_callbacks s_managedSetInventoryCallbacks = nullptr;
static fn_fire_player_interact s_managedFirePlayerInteract = nullptr;
@ -171,13 +175,14 @@ void Initialize()
struct { const wchar_t *name; void **target; } entries[] = {
{L"Initialize", (void **)&s_managedInit},
{L"FirePlayerPreLogin", (void**)&s_managedFirePreLogin},
{L"Shutdown", (void **)&s_managedShutdown},
{L"FireWorldSave", (void **)&s_managedFireWorldSave},
{L"FirePlayerPreLogin", (void **)&s_managedFirePreLogin},
{L"FirePlayerLogin", (void **)&s_managedFireLogin},
{L"FirePlayerJoin", (void **)&s_managedFireJoin},
{L"FirePlayerQuit", (void **)&s_managedFireQuit},
{L"FirePlayerKick", (void **)&s_managedFireKick},
{L"FirePlayerMove", (void **)&s_managedFireMove},
{L"Shutdown", (void **)&s_managedShutdown},
{L"SetNativeCallbacks", (void **)&s_managedSetCallbacks},
{L"SetWorldCallbacks", (void **)&s_managedSetWorldCallbacks},
{L"UpdatePlayerEntityId", (void **)&s_managedUpdateEntityId},
@ -189,7 +194,8 @@ void Initialize()
{L"FireSignChange", (void **)&s_managedFireSignChange},
{L"FireEntityDeath", (void **)&s_managedFireEntityDeath},
{L"FirePlayerDeath", (void **)&s_managedFirePlayerDeath},
{L"SetPlayerCallbacks", (void **)&s_managedSetPlayerCallbacks},
{L"SetPlayerCallbacks", (void**)&s_managedSetPlayerCallbacks},
{L"SetPlayerConnectionCallbacks", (void **)&s_managedSetPlayerConnectionCallbacks},
{L"FirePlayerDropItem", (void **)&s_managedFirePlayerDropItem},
{L"SetInventoryCallbacks", (void **)&s_managedSetInventoryCallbacks},
{L"FirePlayerInteract", (void **)&s_managedFirePlayerInteract},
@ -257,7 +263,11 @@ void Initialize()
(void *)&NativeKickPlayer,
(void *)&NativeBanPlayer,
(void *)&NativeBanPlayerIp,
(void *)&NativeGetPlayerAddress);
(void *)&NativeGetPlayerAddress,
(void *)&NativeGetPlayerLatency);
s_managedSetPlayerConnectionCallbacks(
(void*)&NativeSendRaw);
s_managedSetInventoryCallbacks(
(void *)&NativeGetPlayerInventory,
@ -314,6 +324,18 @@ void Shutdown()
LogInfo("fourkit", "FourKit shut down.");
}
void FireWorldSave()
{
if (!s_initialized || !s_managedFireWorldSave)
{
return;
}
s_managedFireWorldSave();
LogDebugf("fourkit", "Fired WorldSave");
}
bool FirePlayerPreLogin(const std::wstring& name, const std::string& ip, int port)
{
if (!s_initialized || !s_managedFirePreLogin)