add more missing useful funcs

This commit is contained in:
sylvessa 2026-03-23 19:10:35 -05:00
parent f60d75dabb
commit a91abed6a1
4 changed files with 260 additions and 4 deletions

View file

@ -36,6 +36,8 @@
#include "..\Minecraft.World\Player.h"
#include "..\Minecraft.World\PlayerAbilitiesPacket.h"
#include "..\Minecraft.World\SetCarriedItemPacket.h"
#include "..\Minecraft.World\SetExperiencePacket.h"
#include "..\Minecraft.World\SetHealthPacket.h"
#include "..\Minecraft.World\LevelSoundPacket.h"
#include "..\Minecraft.World\SimpleContainer.h"
#include "..\Minecraft.World\Slot.h"
@ -177,6 +179,7 @@ typedef int(__stdcall *fn_fire_inventory_click)(int entityId,
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, void *playSound, void *setSleepingIgnored);
typedef void(__stdcall *fn_set_experience_callbacks)(void *setLevel, void *setExp, void *giveExp, void *giveExpLevels, void *setFoodLevel, void *setSaturation, void *setExhaustion);
struct OpenContainerInfo
{
@ -218,6 +221,7 @@ 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 fn_set_experience_callbacks s_managedSetExperienceCallbacks = nullptr;
static bool s_initialized = false;
@ -329,16 +333,18 @@ static void __cdecl NativeSetFallDistance(int entityId, float distance)
}
}
// double[21] = { x, y, z, health, maxHealth, fallDistance, gameMode, walkSpeed, yaw, pitch, dimension, isSleeping, sleepTimer, sneaking, sprinting, onGround, velocityX, velocityY, velocityZ, allowFlight, sleepingIgnored }
// double[27] = { x, y, z, health, maxHealth, fallDistance, gameMode, walkSpeed, yaw, pitch, dimension, isSleeping, sleepTimer, sneaking, sprinting, onGround, velocityX, velocityY, velocityZ, allowFlight, sleepingIgnored, experienceLevel, experienceProgress, totalExperience, foodLevel, saturation, exhaustion }
static void __cdecl NativeGetPlayerSnapshot(int entityId, double *outData)
{
auto player = FindPlayer(entityId);
if (!player)
{
memset(outData, 0, 21 * sizeof(double));
memset(outData, 0, 27 * sizeof(double));
outData[3] = 20.0;
outData[4] = 20.0;
outData[7] = 0.1;
outData[24] = 20.0;
outData[25] = 5.0;
return;
}
outData[0] = player->x;
@ -363,6 +369,13 @@ static void __cdecl NativeGetPlayerSnapshot(int entityId, double *outData)
outData[18] = player->zd;
outData[19] = player->abilities.mayfly ? 1.0 : 0.0;
outData[20] = player->fk_sleepingIgnored ? 1.0 : 0.0;
outData[21] = (double)player->experienceLevel;
outData[22] = (double)player->experienceProgress;
outData[23] = (double)player->totalExperience;
FoodData *fd = player->getFoodData();
outData[24] = fd ? (double)fd->getFoodLevel() : 20.0;
outData[25] = fd ? (double)fd->getSaturationLevel() : 5.0;
outData[26] = fd ? (double)fd->getExhaustionLevel() : 0.0;
}
static void __cdecl NativeBroadcastMessage(const char *utf8, int len)
@ -1352,6 +1365,73 @@ static void __cdecl NativeSetSleepingIgnored(int entityId, int ignored)
}
}
static void __cdecl NativeSetLevel(int entityId, int level)
{
auto player = FindPlayer(entityId);
if (!player) return;
player->experienceLevel = level;
if (player->connection)
player->connection->send(std::make_shared<SetExperiencePacket>(player->experienceProgress, player->totalExperience, player->experienceLevel));
}
static void __cdecl NativeSetExp(int entityId, float exp)
{
auto player = FindPlayer(entityId);
if (!player) return;
player->experienceProgress = exp;
if (player->connection)
player->connection->send(std::make_shared<SetExperiencePacket>(player->experienceProgress, player->totalExperience, player->experienceLevel));
}
static void __cdecl NativeGiveExp(int entityId, int amount)
{
auto player = FindPlayer(entityId);
if (!player) return;
player->increaseXp(amount);
if (player->connection)
player->connection->send(std::make_shared<SetExperiencePacket>(player->experienceProgress, player->totalExperience, player->experienceLevel));
}
static void __cdecl NativeGiveExpLevels(int entityId, int amount)
{
auto player = FindPlayer(entityId);
if (!player) return;
player->giveExperienceLevels(amount);
if (player->connection)
player->connection->send(std::make_shared<SetExperiencePacket>(player->experienceProgress, player->totalExperience, player->experienceLevel));
}
static void __cdecl NativeSetFoodLevel(int entityId, int foodLevel)
{
auto player = FindPlayer(entityId);
if (!player) return;
FoodData *fd = player->getFoodData();
if (!fd) return;
fd->setFoodLevel(foodLevel);
if (player->connection)
player->connection->send(std::make_shared<SetHealthPacket>(player->getHealth(), fd->getFoodLevel(), fd->getSaturationLevel(), eTelemetryChallenges_Unknown));
}
static void __cdecl NativeSetSaturation(int entityId, float saturation)
{
auto player = FindPlayer(entityId);
if (!player) return;
FoodData *fd = player->getFoodData();
if (!fd) return;
fd->setSaturation(saturation);
if (player->connection)
player->connection->send(std::make_shared<SetHealthPacket>(player->getHealth(), fd->getFoodLevel(), fd->getSaturationLevel(), eTelemetryChallenges_Unknown));
}
static void __cdecl NativeSetExhaustion(int entityId, float exhaustion)
{
auto player = FindPlayer(entityId);
if (!player) return;
FoodData *fd = player->getFoodData();
if (!fd) return;
fd->setExhaustion(exhaustion);
}
static std::wstring FindNet10SystemRoot()
{
// overengineered
@ -1595,6 +1675,7 @@ void Initialize()
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);
ok = ok && GetManagedEntryPoint(loadAssembly, assemblyPath.c_str(), typeName, L"SetExperienceCallbacks", (void **)&s_managedSetExperienceCallbacks);
if (!ok)
{
@ -1658,6 +1739,15 @@ void Initialize()
(void *)&NativePlaySound,
(void *)&NativeSetSleepingIgnored);
s_managedSetExperienceCallbacks(
(void *)&NativeSetLevel,
(void *)&NativeSetExp,
(void *)&NativeGiveExp,
(void *)&NativeGiveExpLevels,
(void *)&NativeSetFoodLevel,
(void *)&NativeSetSaturation,
(void *)&NativeSetExhaustion);
LogInfo("fourkit", "FourKit initialized successfully.");
}