add missing funcs to Player, add Velocity and Vectors

This commit is contained in:
sylvessa 2026-03-23 08:03:45 -05:00
parent fac8269fed
commit a5e39efa04
7 changed files with 758 additions and 6 deletions

View file

@ -175,6 +175,7 @@ typedef int(__stdcall *fn_fire_inventory_click)(int entityId,
const char *titleUtf8, int titleByteLen);
typedef int(__stdcall *fn_fire_bed_enter)(int entityId, int dimId, int bedX, int bedY, int bedZ);
typedef void(__stdcall *fn_fire_bed_leave)(int entityId, int dimId, int bedX, int bedY, int bedZ);
typedef void(__stdcall *fn_set_entity_callbacks)(void *setSneaking, void *setVelocity, void *setAllowFlight);
struct OpenContainerInfo
{
@ -215,6 +216,7 @@ static fn_fire_player_portal s_managedFirePlayerPortal = nullptr;
static fn_fire_inventory_click s_managedFireInventoryClick = nullptr;
static fn_fire_bed_enter s_managedFireBedEnter = nullptr;
static fn_fire_bed_leave s_managedFireBedLeave = nullptr;
static fn_set_entity_callbacks s_managedSetEntityCallbacks = nullptr;
static bool s_initialized = false;
@ -326,13 +328,13 @@ static void __cdecl NativeSetFallDistance(int entityId, float distance)
}
}
// double[13] = { x, y, z, health, maxHealth, fallDistance, gameMode, walkSpeed, yaw, pitch, dimension, isSleeping, sleepTimer }
// double[20] = { x, y, z, health, maxHealth, fallDistance, gameMode, walkSpeed, yaw, pitch, dimension, isSleeping, sleepTimer, sneaking, sprinting, onGround, velocityX, velocityY, velocityZ, allowFlight }
static void __cdecl NativeGetPlayerSnapshot(int entityId, double *outData)
{
auto player = FindPlayer(entityId);
if (!player)
{
memset(outData, 0, 13 * sizeof(double));
memset(outData, 0, 20 * sizeof(double));
outData[3] = 20.0;
outData[4] = 20.0;
outData[7] = 0.1;
@ -352,6 +354,13 @@ static void __cdecl NativeGetPlayerSnapshot(int entityId, double *outData)
outData[10] = (double)player->dimension;
outData[11] = player->isSleeping() ? 1.0 : 0.0;
outData[12] = (double)player->getSleepTimer();
outData[13] = player->isSneaking() ? 1.0 : 0.0;
outData[14] = player->isSprinting() ? 1.0 : 0.0;
outData[15] = player->onGround ? 1.0 : 0.0;
outData[16] = player->xd;
outData[17] = player->yd;
outData[18] = player->zd;
outData[19] = player->abilities.mayfly ? 1.0 : 0.0;
}
static void __cdecl NativeBroadcastMessage(const char *utf8, int len)
@ -1276,6 +1285,53 @@ static void __cdecl NativeSetHeldItemSlot(int entityId, int slot)
player->connection->queueSend(std::make_shared<SetCarriedItemPacket>(slot));
}
static void __cdecl NativeSetSneaking(int entityId, int sneak)
{
auto player = FindPlayer(entityId);
if (player)
{
player->setSneaking(sneak != 0);
}
}
static void __cdecl NativeSetVelocity(int entityId, double x, double y, double z)
{
auto player = FindPlayer(entityId);
if (player)
{
player->xd = x;
player->yd = y;
player->zd = z;
player->hurtMarked = true;
return;
}
auto entity = FindEntity(entityId);
if (entity)
{
entity->xd = x;
entity->yd = y;
entity->zd = z;
entity->hurtMarked = true;
}
}
static void __cdecl NativeSetAllowFlight(int entityId, int allowFlight)
{
auto player = FindPlayer(entityId);
if (player)
{
player->abilities.mayfly = (allowFlight != 0);
if (!player->abilities.mayfly)
{
player->abilities.flying = false;
}
if (player->connection)
{
player->connection->send(std::make_shared<PlayerAbilitiesPacket>(&player->abilities));
}
}
}
static std::wstring FindNet10SystemRoot()
{
// overengineered
@ -1518,6 +1574,7 @@ void Initialize()
ok = ok && GetManagedEntryPoint(loadAssembly, assemblyPath.c_str(), typeName, L"FireInventoryClick", (void **)&s_managedFireInventoryClick);
ok = ok && GetManagedEntryPoint(loadAssembly, assemblyPath.c_str(), typeName, L"FireBedEnter", (void **)&s_managedFireBedEnter);
ok = ok && GetManagedEntryPoint(loadAssembly, assemblyPath.c_str(), typeName, L"FireBedLeave", (void **)&s_managedFireBedLeave);
ok = ok && GetManagedEntryPoint(loadAssembly, assemblyPath.c_str(), typeName, L"SetEntityCallbacks", (void **)&s_managedSetEntityCallbacks);
if (!ok)
{
@ -1574,6 +1631,11 @@ void Initialize()
(void *)&NativeSetItemMeta,
(void *)&NativeSetHeldItemSlot);
s_managedSetEntityCallbacks(
(void *)&NativeSetSneaking,
(void *)&NativeSetVelocity,
(void *)&NativeSetAllowFlight);
LogInfo("fourkit", "FourKit initialized successfully.");
}