Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BinaryStream.writeType(mce::UUID) #606

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion LiteLoader/Header/MC/BinaryStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ class BinaryStream : public ReadOnlyBinaryStream {
template <>
MCAPI void writeType(class MoveActorAbsoluteData const&);
template <>
MCAPI void writeType(class mce::UUID const&);
inline void writeType(class mce::UUID const& uuid)
{
for (const unsigned char b : dAccess<unsigned char[16]>(&uuid, 0))
{
writeByte(b);
}
}
template <>
MCAPI void writeType(class NetworkItemInstanceDescriptor const&);
template <>
Expand Down
53 changes: 21 additions & 32 deletions LiteLoader/Kernel/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2088,8 +2088,9 @@ TInstanceHook(int, "?startSleepInBed@Player@@UEAA?AW4BedSleepingResult@@AEBVBloc
return original(this, blk);
}

////////////// MobSpawn //////////////
#include <MC/Spawner.hpp>

////////////// MobSpawn //////////////
TInstanceHook(Mob*, "?spawnMob@Spawner@@QEAAPEAVMob@@AEAVBlockSource@@AEBUActorDefinitionIdentifier@@PEAVActor@@AEBVVec3@@_N44@Z",
Spawner, BlockSource* a2, ActorDefinitionIdentifier* a3, Actor* a4, Vec3& a5, bool a6, bool a7, bool a8) {
IF_LISTENED(MobSpawnEvent) {
Expand All @@ -2104,45 +2105,33 @@ TInstanceHook(Mob*, "?spawnMob@Spawner@@QEAAPEAVMob@@AEAVBlockSource@@AEBUActorD
return original(this, a2, a3, a4, a5, a6, a7, a8);
}

////////////// FormResponsePacket //////////////
#include "Impl/FormPacketHelper.h"

////////////// FormResponsePacket //////////////
TClasslessInstanceHook(void, "?handle@?$PacketHandlerDispatcherInstance@VModalFormResponsePacket@@$0A@@@UEBAXAEBVNetworkIdentifier@@AEAVNetEventCallback@@AEAV?$shared_ptr@VPacket@@@std@@@Z",
NetworkIdentifier* id, ServerNetworkHandler* handler, void* pPacket) {
try {
Packet* packet = *(Packet**)pPacket;
ServerPlayer* sp = handler->getServerPlayer(*id, 0);
Packet* packet = *(Packet**)pPacket;
ServerPlayer* sp = handler->getServerPlayer(*id, 0);

if (sp) {
unsigned formId = dAccess<unsigned>(packet, 48);
string data = dAccess<string>(packet, 56);
if (sp) {
unsigned formId = dAccess<unsigned>(packet, 48);
string data = dAccess<string>(packet, 56);

if (data.back() == '\n')
data.pop_back();
if (data.back() == '\n')
data.pop_back();

IF_LISTENED(FormResponsePacketEvent) {
FormResponsePacketEvent ev{};
ev.mServerPlayer = sp;
ev.mFormId = formId;
ev.mJsonData = data;
IF_LISTENED(FormResponsePacketEvent) {
FormResponsePacketEvent ev{};
ev.mServerPlayer = sp;
ev.mFormId = formId;
ev.mJsonData = data;

if (!ev.call())
return;
}
IF_LISTENED_END(PlayerBedEnterEvent)

HandleFormPacket(sp, formId, data);
if (!ev.call())
return;
}
} catch (const seh_exception& e) {
logger.error("Event Callback Failed!");
logger.error("SEH Uncaught Exception Detected!");
logger.error("{}", TextEncoding::toUTF8(e.what()));
logger.error("In Event: onFormResponsePacket");
PrintCurrentStackTraceback();
} catch (...) {
logger.error("Event Callback Failed!");
logger.error("Uncaught Exception Detected!");
logger.error("In Event: onFormResponsePacket");
PrintCurrentStackTraceback();
IF_LISTENED_END(FormResponsePacketEvent)

HandleFormPacket(sp, formId, data);
}

original(this, id, handler, pPacket);
Expand Down