Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
AddonHandler.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "AddonHandler.h"
7#include "DatabaseEnv.h"
8#include "Log.h"
9#include "Opcodes.h"
10#include "zlib.h"
11
13
15
17{
18 ByteBuffer AddOnPacked;
19 uLongf AddonRealSize;
20 uint32 CurrentPosition;
21 uint32 TempValue;
22
23 // broken addon packet, can't be received from real client
24 if (source->rpos() + 4 > source->size())
25 return false;
26
27 *source >> TempValue; // get real size of the packed structure
28
29 // empty addon packet, nothing process, can't be received from real client
30 if (!TempValue)
31 return false;
32
33 AddonRealSize = TempValue; // temp value because ZLIB only excepts uLongf
34
35 CurrentPosition = source->rpos(); // get the position of the pointer in the structure
36
37 AddOnPacked.resize(AddonRealSize); // resize target for zlib action
38
39 if (uncompress(AddOnPacked.contents(), &AddonRealSize, source->contents() + CurrentPosition, source->size() - CurrentPosition) == Z_OK)
40 {
42
43 uint32 addonsCount;
44 AddOnPacked >> addonsCount; // addons count?
45
46 for (uint32 i = 0; i < addonsCount; ++i)
47 {
48 std::string addonName;
49 uint8 enabled;
50 uint32 crc, unk2;
51
52 // check next addon data format correctness
53 if (AddOnPacked.rpos() + 1 > AddOnPacked.size())
54 return false;
55
56 AddOnPacked >> addonName;
57
58 // recheck next addon data format correctness
59 if (AddOnPacked.rpos() + 1 + 4 + 4 > AddOnPacked.size())
60 return false;
61
62 AddOnPacked >> enabled >> crc >> unk2;
63
64 SF_LOG_DEBUG("network", "ADDON: Name: %s, Enabled: 0x%x, CRC: 0x%x, Unknown2: 0x%x", addonName.c_str(), enabled, crc, unk2);
65
66 uint8 state = (enabled ? 2 : 1);
67 *target << uint8(state);
68
69 uint8 unk1 = (enabled ? 1 : 0);
70 *target << uint8(unk1);
71 if (unk1)
72 {
73 uint8 unk = (crc != 0x4c1c776d); // If addon is Standard addon CRC
74 *target << uint8(unk);
75 if (unk)
76 {
77 unsigned char tdata[256] =
78 {
79 0xC3, 0x5B, 0x50, 0x84, 0xB9, 0x3E, 0x32, 0x42, 0x8C, 0xD0, 0xC7, 0x48, 0xFA, 0x0E, 0x5D, 0x54,
80 0x5A, 0xA3, 0x0E, 0x14, 0xBA, 0x9E, 0x0D, 0xB9, 0x5D, 0x8B, 0xEE, 0xB6, 0x84, 0x93, 0x45, 0x75,
81 0xFF, 0x31, 0xFE, 0x2F, 0x64, 0x3F, 0x3D, 0x6D, 0x07, 0xD9, 0x44, 0x9B, 0x40, 0x85, 0x59, 0x34,
82 0x4E, 0x10, 0xE1, 0xE7, 0x43, 0x69, 0xEF, 0x7C, 0x16, 0xFC, 0xB4, 0xED, 0x1B, 0x95, 0x28, 0xA8,
83 0x23, 0x76, 0x51, 0x31, 0x57, 0x30, 0x2B, 0x79, 0x08, 0x50, 0x10, 0x1C, 0x4A, 0x1A, 0x2C, 0xC8,
84 0x8B, 0x8F, 0x05, 0x2D, 0x22, 0x3D, 0xDB, 0x5A, 0x24, 0x7A, 0x0F, 0x13, 0x50, 0x37, 0x8F, 0x5A,
85 0xCC, 0x9E, 0x04, 0x44, 0x0E, 0x87, 0x01, 0xD4, 0xA3, 0x15, 0x94, 0x16, 0x34, 0xC6, 0xC2, 0xC3,
86 0xFB, 0x49, 0xFE, 0xE1, 0xF9, 0xDA, 0x8C, 0x50, 0x3C, 0xBE, 0x2C, 0xBB, 0x57, 0xED, 0x46, 0xB9,
87 0xAD, 0x8B, 0xC6, 0xDF, 0x0E, 0xD6, 0x0F, 0xBE, 0x80, 0xB3, 0x8B, 0x1E, 0x77, 0xCF, 0xAD, 0x22,
88 0xCF, 0xB7, 0x4B, 0xCF, 0xFB, 0xF0, 0x6B, 0x11, 0x45, 0x2D, 0x7A, 0x81, 0x18, 0xF2, 0x92, 0x7E,
89 0x98, 0x56, 0x5D, 0x5E, 0x69, 0x72, 0x0A, 0x0D, 0x03, 0x0A, 0x85, 0xA2, 0x85, 0x9C, 0xCB, 0xFB,
90 0x56, 0x6E, 0x8F, 0x44, 0xBB, 0x8F, 0x02, 0x22, 0x68, 0x63, 0x97, 0xBC, 0x85, 0xBA, 0xA8, 0xF7,
91 0xB5, 0x40, 0x68, 0x3C, 0x77, 0x86, 0x6F, 0x4B, 0xD7, 0x88, 0xCA, 0x8A, 0xD7, 0xCE, 0x36, 0xF0,
92 0x45, 0x6E, 0xD5, 0x64, 0x79, 0x0F, 0x17, 0xFC, 0x64, 0xDD, 0x10, 0x6F, 0xF3, 0xF5, 0xE0, 0xA6,
93 0xC3, 0xFB, 0x1B, 0x8C, 0x29, 0xEF, 0x8E, 0xE5, 0x34, 0xCB, 0xD1, 0x2A, 0xCE, 0x79, 0xC3, 0x9A,
94 0x0D, 0x36, 0xEA, 0x01, 0xE0, 0xAA, 0x91, 0x20, 0x54, 0xF0, 0x72, 0xD8, 0x1E, 0xC7, 0x89, 0xD2
95 };
96 target->append(tdata, sizeof(tdata));
97 }
98
99 *target << uint32(0);
100 }
101
102 uint8 unk3 = (enabled ? 0 : 1);
103 *target << uint8(unk3);
104 if (unk3)
105 {
106 // String, 256 (null terminated?)
107 *target << uint8(0);
108 }
109 }
110
111 uint32 unk4;
112 AddOnPacked >> unk4;
113
114 uint32 count = 0;
115 *target << uint32(count);
116
117 if (AddOnPacked.rpos() != AddOnPacked.size())
118 SF_LOG_DEBUG("network", "packet under read!");
119 }
120 else
121 {
122 SF_LOG_ERROR("network", "Addon packet uncompress error :(");
123 return false;
124 }
125 return true;
126}
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define SF_LOG_DEBUG(filterType__,...)
Definition Log.h:134
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
bool BuildAddonPacket(WorldPacket *Source, WorldPacket *Target)
size_t rpos() const
Definition ByteBuffer.h:470
void resize(size_t newsize)
Definition ByteBuffer.h:612
void append(T value)
Definition ByteBuffer.h:147
size_t size() const
Definition ByteBuffer.h:609
uint8 * contents()
Definition ByteBuffer.h:605
void Initialize(Opcodes opcode, size_t newres=200)
Definition WorldPacket.h:31
@ SMSG_ADDON_INFO
Definition Opcodes.h:509