the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "InputOutputStream.h"
3#include "PacketListener.h"
4#include "BasicTypeContainers.h"
5#include "CustomPayloadPacket.h"
6
7// Mojang-defined custom packets
8const wstring CustomPayloadPacket::CUSTOM_BOOK_PACKET = L"MC|BEdit";
9const wstring CustomPayloadPacket::CUSTOM_BOOK_SIGN_PACKET = L"MC|BSign";
10const wstring CustomPayloadPacket::TEXTURE_PACK_PACKET = L"MC|TPack";
11const wstring CustomPayloadPacket::TRADER_LIST_PACKET = L"MC|TrList";
12const wstring CustomPayloadPacket::TRADER_SELECTION_PACKET = L"MC|TrSel";
13const wstring CustomPayloadPacket::SET_ADVENTURE_COMMAND_PACKET = L"MC|AdvCdm";
14const wstring CustomPayloadPacket::SET_BEACON_PACKET = L"MC|Beacon";
15const wstring CustomPayloadPacket::SET_ITEM_NAME_PACKET = L"MC|ItemName";
16
17CustomPayloadPacket::CustomPayloadPacket()
18{
19}
20
21CustomPayloadPacket::CustomPayloadPacket(const wstring &identifier, byteArray data)
22{
23 this->identifier = identifier;
24 this->data = data;
25
26 if (data.data != NULL)
27 {
28 length = data.length;
29
30 if (length > Short::MAX_VALUE)
31 {
32 app.DebugPrintf("Payload may not be larger than 32K\n");
33#ifndef _CONTENT_PACKAGE
34 __debugbreak();
35#endif
36 //throw new IllegalArgumentException("Payload may not be larger than 32k");
37 }
38 }
39}
40
41void CustomPayloadPacket::read(DataInputStream *dis)
42{
43 identifier = readUtf(dis, 20);
44 length = dis->readShort();
45
46 if (length > 0 && length < Short::MAX_VALUE)
47 {
48 if(data.data != NULL)
49 {
50 delete [] data.data;
51 }
52 data = byteArray(length);
53 dis->readFully(data);
54 }
55}
56
57void CustomPayloadPacket::write(DataOutputStream *dos)
58{
59 writeUtf(identifier, dos);
60 dos->writeShort((short) length);
61 if (data.data != NULL)
62 {
63 dos->write(data);
64 }
65}
66
67void CustomPayloadPacket::handle(PacketListener *listener)
68{
69 listener->handleCustomPayload( shared_from_this() );
70}
71
72int CustomPayloadPacket::getEstimatedSize()
73{
74 return 2 + identifier.length() * 2 + 2 + length;
75}