mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-21 17:43:51 +00:00
add some vehicle related funcs, fix entity getting (temp)
This commit is contained in:
parent
32f058d078
commit
d6c4500c75
6 changed files with 231 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
// todo: split into files for better readability
|
||||
// todo: this needs to be made way more neat and less duplicate stuff
|
||||
|
||||
#include "FourKitBridge.h"
|
||||
#include "Common/StringUtils.h"
|
||||
|
|
@ -40,6 +41,7 @@
|
|||
#include "..\Minecraft.World\SetHealthPacket.h"
|
||||
#include "..\Minecraft.World\LevelSoundPacket.h"
|
||||
#include "..\Minecraft.World\LevelParticlesPacket.h"
|
||||
#include "..\Minecraft.World\SetEntityLinkPacket.h"
|
||||
#include "..\Minecraft.World\SimpleContainer.h"
|
||||
#include "..\Minecraft.World\Slot.h"
|
||||
#include "..\Minecraft.World\Tile.h"
|
||||
|
|
@ -182,6 +184,7 @@ typedef void(__stdcall *fn_fire_bed_leave)(int entityId, int dimId, int bedX, in
|
|||
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);
|
||||
typedef void(__stdcall *fn_set_particle_callbacks)(void *spawnParticle);
|
||||
typedef void(__stdcall *fn_set_vehicle_callbacks)(void *setPassenger, void *leaveVehicle, void *eject, void *getVehicleId, void *getPassengerId, void *getEntityInfo);
|
||||
|
||||
struct OpenContainerInfo
|
||||
{
|
||||
|
|
@ -225,6 +228,7 @@ 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 fn_set_particle_callbacks s_managedSetParticleCallbacks = nullptr;
|
||||
static fn_set_vehicle_callbacks s_managedSetVehicleCallbacks = nullptr;
|
||||
|
||||
static bool s_initialized = false;
|
||||
|
||||
|
|
@ -1445,6 +1449,76 @@ static void __cdecl NativeSpawnParticle(int entityId, int particleId, float x, f
|
|||
player->connection->send(std::make_shared<LevelParticlesPacket>(std::wstring(buf), x, y, z, offsetX, offsetY, offsetZ, speed, count));
|
||||
}
|
||||
|
||||
static int __cdecl NativeSetPassenger(int entityId, int passengerEntityId)
|
||||
{
|
||||
auto entity = FindEntity(entityId);
|
||||
auto passenger = FindEntity(passengerEntityId);
|
||||
if (!entity || !passenger) return 0;
|
||||
passenger->ride(entity);
|
||||
PlayerList *list = MinecraftServer::getPlayerList();
|
||||
if (list)
|
||||
list->broadcastAll(std::make_shared<SetEntityLinkPacket>(SetEntityLinkPacket::RIDING, passenger, entity), entity->dimension);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int __cdecl NativeLeaveVehicle(int entityId)
|
||||
{
|
||||
auto entity = FindEntity(entityId);
|
||||
if (!entity || !entity->riding) return 0;
|
||||
int dim = entity->riding->dimension;
|
||||
entity->ride(nullptr);
|
||||
PlayerList *list = MinecraftServer::getPlayerList();
|
||||
if (list)
|
||||
list->broadcastAll(std::make_shared<SetEntityLinkPacket>(SetEntityLinkPacket::RIDING, entity, nullptr), dim);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int __cdecl NativeEject(int entityId)
|
||||
{
|
||||
auto entity = FindEntity(entityId);
|
||||
if (!entity) return 0;
|
||||
auto riderPtr = entity->rider.lock();
|
||||
if (!riderPtr) return 0;
|
||||
riderPtr->ride(nullptr);
|
||||
PlayerList *list = MinecraftServer::getPlayerList();
|
||||
if (list)
|
||||
list->broadcastAll(std::make_shared<SetEntityLinkPacket>(SetEntityLinkPacket::RIDING, riderPtr, nullptr), entity->dimension);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int __cdecl NativeGetVehicleId(int entityId)
|
||||
{
|
||||
auto entity = FindEntity(entityId);
|
||||
if (!entity || !entity->riding) return -1;
|
||||
return entity->riding->entityId;
|
||||
}
|
||||
|
||||
static int __cdecl NativeGetPassengerId(int entityId)
|
||||
{
|
||||
auto entity = FindEntity(entityId);
|
||||
if (!entity) return -1;
|
||||
auto riderPtr = entity->rider.lock();
|
||||
if (!riderPtr) return -1;
|
||||
return riderPtr->entityId;
|
||||
}
|
||||
|
||||
static void __cdecl NativeGetEntityInfo(int entityId, double *outData)
|
||||
{
|
||||
// this stinks iof shit and more shit
|
||||
outData[0] = -1;
|
||||
outData[1] = 0;
|
||||
outData[2] = 0;
|
||||
outData[3] = 0;
|
||||
outData[4] = 0;
|
||||
auto entity = FindEntity(entityId);
|
||||
if (!entity) return;
|
||||
outData[0] = (double)MapEntityType((int)entity->GetType());
|
||||
outData[1] = entity->x;
|
||||
outData[2] = entity->y;
|
||||
outData[3] = entity->z;
|
||||
outData[4] = (double)entity->dimension;
|
||||
}
|
||||
|
||||
static std::wstring FindNet10SystemRoot()
|
||||
{
|
||||
// overengineered
|
||||
|
|
@ -1690,6 +1764,7 @@ void Initialize()
|
|||
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);
|
||||
ok = ok && GetManagedEntryPoint(loadAssembly, assemblyPath.c_str(), typeName, L"SetParticleCallbacks", (void **)&s_managedSetParticleCallbacks);
|
||||
ok = ok && GetManagedEntryPoint(loadAssembly, assemblyPath.c_str(), typeName, L"SetVehicleCallbacks", (void **)&s_managedSetVehicleCallbacks);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
|
|
@ -1765,6 +1840,14 @@ void Initialize()
|
|||
s_managedSetParticleCallbacks(
|
||||
(void *)&NativeSpawnParticle);
|
||||
|
||||
s_managedSetVehicleCallbacks(
|
||||
(void *)&NativeSetPassenger,
|
||||
(void *)&NativeLeaveVehicle,
|
||||
(void *)&NativeEject,
|
||||
(void *)&NativeGetVehicleId,
|
||||
(void *)&NativeGetPassengerId,
|
||||
(void *)&NativeGetEntityInfo);
|
||||
|
||||
LogInfo("fourkit", "FourKit initialized successfully.");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue