Skip to content

Commit

Permalink
Add BinaryStream.writeType(mce::UUID) (#606)
Browse files Browse the repository at this point in the history
* Add BinaryStream.write(mce::UUID)
* Small fix for FormResponsePacketEvent hook
  • Loading branch information
S3v3Nice authored Jul 25, 2022
1 parent 947c1b4 commit bf4082a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
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

0 comments on commit bf4082a

Please sign in to comment.