9
3

PacketStruct.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __EQ2_PACKETSTRUCT__
  17. #define __EQ2_PACKETSTRUCT__
  18. #include "types.h"
  19. #include "DataBuffer.h"
  20. #include "opcodemgr.h"
  21. #include <vector>
  22. #include <map>
  23. #ifdef WORLD
  24. class Item;
  25. class Player;
  26. #endif
  27. extern map<int16,OpcodeManager*>EQOpcodeManager;
  28. using namespace std;
  29. #define DATA_STRUCT_NONE 0
  30. #define DATA_STRUCT_INT8 1
  31. #define DATA_STRUCT_INT16 2
  32. #define DATA_STRUCT_INT32 3
  33. #define DATA_STRUCT_INT64 4
  34. #define DATA_STRUCT_FLOAT 5
  35. #define DATA_STRUCT_DOUBLE 6
  36. #define DATA_STRUCT_COLOR 7
  37. #define DATA_STRUCT_SINT8 8
  38. #define DATA_STRUCT_SINT16 9
  39. #define DATA_STRUCT_SINT32 10
  40. #define DATA_STRUCT_CHAR 11
  41. #define DATA_STRUCT_EQ2_8BIT_STRING 12
  42. #define DATA_STRUCT_EQ2_16BIT_STRING 13
  43. #define DATA_STRUCT_EQ2_32BIT_STRING 14
  44. #define DATA_STRUCT_EQUIPMENT 15
  45. #define DATA_STRUCT_ARRAY 16
  46. #define DATA_STRUCT_ITEM 17
  47. #define DATA_STRUCT_SINT64 18
  48. class DataStruct{
  49. public:
  50. DataStruct();
  51. DataStruct(DataStruct* data_struct);
  52. DataStruct(const char* new_name, int8 new_type, int32 new_length = 1, int8 new_type2 = DATA_STRUCT_NONE);
  53. DataStruct(const char* new_name, const char* new_type, int32 new_length = 1, const char* new_type2 = 0);
  54. DataStruct(const char* new_name, int32 new_length);
  55. void SetType(const char* new_type, int8* output_type);
  56. void SetType(int8 new_type);
  57. void SetName(const char* new_name);
  58. void SetLength(int32 new_length);
  59. void SetArraySizeVariable(const char* new_name);
  60. void SetDefaultValue(int8 new_val);
  61. void SetMaxArraySize(int8 size);
  62. void SetOversized(int8 val);
  63. void SetOversizedByte(int8 val);
  64. void SetAddToStruct(bool val);
  65. void SetAddType(int8 new_type);
  66. void SetPackedIndex(int8 new_index);
  67. void SetPackedSizeVariable(const char* new_name);
  68. void SetPacked(const char* value);
  69. void SetItemSize(int32 val);
  70. void SetIfSetVariable(const char* variable);
  71. void SetIfNotSetVariable(const char* variable);
  72. void SetIfEqualsVariable(const char* variable);
  73. void SetIfNotEqualsVariable(const char* variable);
  74. void SetIsSet(bool val);
  75. int8 GetPackedIndex();
  76. const char* GetPackedSizeVariable();
  77. const char* GetArraySizeVariable();
  78. int8 GetDefaultValue();
  79. int8 GetOversized();
  80. int8 GetOversizedByte();
  81. int8 GetMaxArraySize();
  82. int8 GetType();
  83. int8 GetType2();
  84. const char* GetName();
  85. string GetStringName();
  86. int32 GetLength();
  87. bool AddToStruct();
  88. int8 GetAddType();
  89. int32 GetItemSize();
  90. bool GetIfSet();
  91. const char* GetIfSetVariable();
  92. bool GetIfNotSet();
  93. const char* GetIfNotSetVariable();
  94. bool GetIfEquals();
  95. const char* GetIfEqualsVariable();
  96. bool GetIfNotEquals();
  97. const char* GetIfNotEqualsVariable();
  98. bool IsSet();
  99. int32 GetDataSizeInBytes();
  100. private:
  101. bool is_set;
  102. bool if_not_set;
  103. bool if_set;
  104. bool if_not_equals;
  105. bool if_equals;
  106. string if_not_equals_variable;
  107. string if_equals_variable;
  108. string if_not_set_variable;
  109. string if_set_variable;
  110. int8 oversized;
  111. int8 oversized_byte;
  112. bool add;
  113. int8 addType;
  114. int8 maxArraySize;
  115. string array_size_variable;
  116. string name;
  117. int8 type;
  118. int8 default_value;
  119. int8 type2;
  120. int32 length;
  121. int32 item_size;
  122. };
  123. class PacketStruct : public DataBuffer{
  124. public:
  125. PacketStruct();
  126. PacketStruct(PacketStruct* packet, bool sub);
  127. PacketStruct(PacketStruct* packet, int16 in_client_version);
  128. ~PacketStruct();
  129. void add(DataStruct* data);
  130. void reAddAll(int32 length);
  131. void add(PacketStruct* packet_struct);
  132. void addPacketArrays(PacketStruct* packet);
  133. void deletePacketArrays(PacketStruct* packet);
  134. void deleteDataStructs(vector<DataStruct*>* data_structs);
  135. void setSmallStringByName(const char* name, const char* text, int32 index = 0);
  136. void setMediumStringByName(const char* name, const char* text, int32 index = 0);
  137. void setLargeStringByName(const char* name, const char* text, int32 index = 0);
  138. void setSmallString(DataStruct* data_struct, const char* text, int32 index = 0);
  139. void setMediumString(DataStruct* data_struct, const char* text, int32 index = 0);
  140. void setLargeString(DataStruct* data_struct, const char* text, int32 index = 0);
  141. void renameSubstructArray(const char* substruct, int32 index);
  142. template<class Data> void setSubstructSubstructDataByName(const char* substruct_name1, const char* substruct_name2, const char* name, Data data, int32 substruct_index1 = 0, int32 substruct_index2 = 0, int32 index = 0){
  143. char tmp[15] = {0};
  144. sprintf(tmp,"_%i_%i",substruct_index1, substruct_index2);
  145. string name2 = string(substruct_name1).append("_").append(substruct_name2).append("_").append(name).append(tmp);
  146. setData(findStruct(name2.c_str(), index), data, index);
  147. }
  148. template<class Data> void setSubstructDataByName(const char* substruct_name, const char* name, Data data, int32 substruct_index = 0, int32 index = 0){
  149. char tmp[10] = {0};
  150. sprintf(tmp,"_%i",substruct_index);
  151. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  152. setData(findStruct(name2.c_str(), index), data, index);
  153. }
  154. template<class Data> void setSubstructColorByName(const char* substruct_name, const char* name, Data data, int32 substruct_index = 0, int32 index = 0){
  155. char tmp[10] = {0};
  156. sprintf(tmp,"_%i",substruct_index);
  157. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  158. setColor(findStruct(name2.c_str(), index), data, index);
  159. }
  160. template<class Data> void setSubstructArrayDataByName(const char* substruct_name, const char* name, Data data, int32 index = 0, int32 substruct_index = 0){
  161. char tmp[10] = {0};
  162. sprintf(tmp,"_%i",substruct_index);
  163. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  164. setData(findStruct(name2.c_str(), substruct_index, index), data, index);
  165. }
  166. template<class Data> void setSubstructArrayColorByName(const char* substruct_name, const char* name, Data data, int32 substruct_index = 0, int32 index = 0){
  167. char tmp[10] = {0};
  168. sprintf(tmp,"_%i",substruct_index);
  169. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  170. setColor(findStruct(name2.c_str(), index, substruct_index), data, index);
  171. }
  172. template<class Data> void setDataByName(const char* name, Data data, int32 index = 0, bool use_second_type = false){
  173. setData(findStruct(name, index), data, index, use_second_type);
  174. }
  175. template<class Data> void setDataByName(const char* name, Data* data, int32 index = 0, bool use_second_type = false){
  176. setData(findStruct(name, index), data, index, use_second_type);
  177. }
  178. template<class Data> void setSubArrayDataByName(const char* name, Data data, int32 index1 = 0, int32 index2 = 0, int32 index3 = 0){
  179. char tmp[20] = {0};
  180. sprintf(tmp,"%i_%i", index1, index2);
  181. string name2 = string(name).append(tmp);
  182. setData(findStruct(name2.c_str(), index2, index3), data, index3);
  183. }
  184. template<class Data> void setArrayDataByName(const char* name, Data data, int32 index1 = 0, int32 index2 = 0, bool use_second_type = false){
  185. char tmp[10] = {0};
  186. sprintf(tmp,"_%i",index1);
  187. string name2 = string(name).append(tmp);
  188. setData(findStruct(name2.c_str(), index1, index2), data, index2, use_second_type);
  189. }
  190. void setArrayAddToPacketByName(const char* name, bool new_val, int32 index1 = 0, int32 index2 = 0){
  191. char tmp[10] = {0};
  192. sprintf(tmp,"_%i",index1);
  193. string name2 = string(name).append(tmp);
  194. DataStruct* data = findStruct(name2.c_str(), index2);
  195. if(data)
  196. data->SetAddToStruct(new_val);
  197. }
  198. void setAddToPacketByName(const char* name, bool new_val, int32 index = 0){
  199. DataStruct* data = findStruct(name, index);
  200. if(data)
  201. data->SetAddToStruct(new_val);
  202. }
  203. void setAddTypePacketByName(const char* name, int8 new_val, int32 index = 0){
  204. DataStruct* data = findStruct(name, index);
  205. if(data)
  206. data->SetAddType(new_val);
  207. }
  208. const char* GetOpcodeType();
  209. bool IsSubPacket();
  210. void IsSubPacket(bool new_val);
  211. int32 GetSubPacketSize();
  212. void SetSubPacketSize(int32 new_size);
  213. void SetOpcodeType(const char* opcodeType);
  214. int32 GetArraySizeByName(const char* name, int32 index);
  215. int32 GetArraySize(DataStruct* data_struct, int32 index);
  216. int32 GetArraySize(const char* name, int32 index);
  217. void LoadFromPacketStruct(PacketStruct* packet, char* substruct_name = 0);
  218. bool GetVariableIsSet(const char* name);
  219. bool GetVariableIsNotSet(const char* name);
  220. int8 getType_int8_ByName(const char* name, int32 index = 0, bool force = false);
  221. int16 getType_int16_ByName(const char* name, int32 index = 0, bool force = false);
  222. int32 getType_int32_ByName(const char* name, int32 index = 0, bool force = false);
  223. int64 getType_int64_ByName(const char* name, int32 index = 0, bool force = false);
  224. sint8 getType_sint8_ByName(const char* name, int32 index = 0, bool force = false);
  225. sint16 getType_sint16_ByName(const char* name, int32 index = 0, bool force = false);
  226. sint32 getType_sint32_ByName(const char* name, int32 index = 0, bool force = false);
  227. sint64 getType_sint64_ByName(const char* name, int32 index = 0, bool force = false);
  228. float getType_float_ByName(const char* name, int32 index = 0, bool force = false);
  229. double getType_double_ByName(const char* name, int32 index = 0, bool force = false);
  230. char getType_char_ByName(const char* name, int32 index = 0, bool force = false);
  231. EQ2_8BitString getType_EQ2_8BitString_ByName(const char* name, int32 index = 0, bool force = false);
  232. EQ2_16BitString getType_EQ2_16BitString_ByName(const char* name, int32 index = 0, bool force = false);
  233. EQ2_32BitString getType_EQ2_32BitString_ByName(const char* name, int32 index = 0, bool force = false);
  234. EQ2_Color getType_EQ2_Color_ByName(const char* name, int32 index = 0, bool force = false);
  235. EQ2_EquipmentItem getType_EQ2_EquipmentItem_ByName(const char* name, int32 index = 0, bool force = false);
  236. int8 getType_int8(DataStruct* data_struct, int32 index = 0, bool force = false);
  237. int16 getType_int16(DataStruct* data_struct, int32 index = 0, bool force = false);
  238. int32 getType_int32(DataStruct* data_struct, int32 index = 0, bool force = false);
  239. int64 getType_int64(DataStruct* data_struct, int32 index = 0, bool force = false);
  240. sint8 getType_sint8(DataStruct* data_struct, int32 index = 0, bool force = false);
  241. sint16 getType_sint16(DataStruct* data_struct, int32 index = 0, bool force = false);
  242. sint32 getType_sint32(DataStruct* data_struct, int32 index = 0, bool force = false);
  243. sint64 getType_sint64(DataStruct* data_struct, int32 index = 0, bool force = false);
  244. float getType_float(DataStruct* data_struct, int32 index = 0, bool force = false);
  245. double getType_double(DataStruct* data_struct, int32 index = 0, bool force = false);
  246. char getType_char(DataStruct* data_struct, int32 index = 0, bool force = false);
  247. EQ2_8BitString getType_EQ2_8BitString(DataStruct* data_struct, int32 index = 0, bool force = false);
  248. EQ2_16BitString getType_EQ2_16BitString(DataStruct* data_struct, int32 index = 0, bool force = false);
  249. EQ2_32BitString getType_EQ2_32BitString(DataStruct* data_struct, int32 index = 0, bool force = false);
  250. EQ2_Color getType_EQ2_Color(DataStruct* data_struct, int32 index = 0, bool force = false);
  251. EQ2_EquipmentItem getType_EQ2_EquipmentItem(DataStruct* data_struct, int32 index = 0, bool force = false);
  252. void setDataType(DataStruct* data_struct, char data, int32 index);
  253. void setDataType(DataStruct* data_struct, int8 data, int32 index);
  254. void setDataType(DataStruct* data_struct, int16 data, int32 index);
  255. void setDataType(DataStruct* data_struct, int32 data, int32 index);
  256. void setDataType(DataStruct* data_struct, int64 data, int32 index);
  257. void setDataType(DataStruct* data_struct, sint8 data, int32 index);
  258. void setDataType(DataStruct* data_struct, sint16 data, int32 index);
  259. void setDataType(DataStruct* data_struct, sint32 data, int32 index);
  260. void setDataType(DataStruct* data_struct, sint64 data, int32 index);
  261. void setDataType(DataStruct* data_struct, float data, int32 index);
  262. void setDataType(DataStruct* data_struct, double data, int32 index);
  263. void setData(DataStruct* data_struct, EQ2_8BitString* input_string, int32 index, bool use_second_type = false);
  264. void setData(DataStruct* data_struct, EQ2_16BitString* input_string, int32 index, bool use_second_type = false);
  265. void setData(DataStruct* data_struct, EQ2_32BitString* input_string, int32 index, bool use_second_type = false);
  266. template<class Data> void setData(DataStruct* data_struct, Data* data, int32 index, bool use_second_type = false){
  267. if (!data_struct)
  268. return;
  269. int8 type_to_use = (use_second_type) ? data_struct->GetType2() : data_struct->GetType();
  270. if(type_to_use >= DATA_STRUCT_EQ2_8BIT_STRING && type_to_use <= DATA_STRUCT_EQ2_32BIT_STRING){
  271. if(type_to_use == DATA_STRUCT_EQ2_8BIT_STRING){
  272. setSmallString(data_struct, data, index);
  273. }
  274. else if(type_to_use == DATA_STRUCT_EQ2_16BIT_STRING){
  275. setMediumString(data_struct, data, index);
  276. }
  277. else{
  278. setLargeString(data_struct, data, index);
  279. }
  280. }
  281. else {
  282. if(data_struct && index == 0 && data_struct->GetLength() > 1){
  283. if(type_to_use == DATA_STRUCT_CHAR){
  284. for(int32 i=0;data && i<data_struct->GetLength() && i < strlen(data);i++)
  285. setData(data_struct, data[i], i);
  286. }
  287. else{
  288. for(int32 i=0;i<data_struct->GetLength();i++)
  289. setData(data_struct, data[i], i);
  290. }
  291. }
  292. else
  293. setData(data_struct, *data, index);
  294. }
  295. }
  296. template<class Data> void setData(DataStruct* data_struct, Data data, int32 index, bool use_second_type = false){
  297. if(data_struct && index < data_struct->GetLength()){
  298. int8 type_to_use = (use_second_type) ? data_struct->GetType2() : data_struct->GetType();
  299. if (use_second_type) {
  300. // Need to figure out why type2 always seems to be 205
  301. // since only items use type2 for now just hardcoded the value needed (BAD!!!)
  302. //type_to_use = DATA_STRUCT_SINT16; // 9;
  303. data_struct->SetType(type_to_use);
  304. }
  305. switch(type_to_use){
  306. case DATA_STRUCT_INT8:
  307. setDataType(data_struct, (int8)data, index);
  308. break;
  309. case DATA_STRUCT_INT16:
  310. setDataType(data_struct, (int16)data, index);
  311. break;
  312. case DATA_STRUCT_INT32:
  313. setDataType(data_struct, (int32)data, index);
  314. break;
  315. case DATA_STRUCT_INT64:
  316. setDataType(data_struct, (int64)data, index);
  317. break;
  318. case DATA_STRUCT_SINT8:
  319. setDataType(data_struct, (sint8)data, index);
  320. break;
  321. case DATA_STRUCT_SINT16:
  322. setDataType(data_struct, (sint16)data, index);
  323. break;
  324. case DATA_STRUCT_SINT32:
  325. setDataType(data_struct, (sint32)data, index);
  326. break;
  327. case DATA_STRUCT_SINT64:
  328. setDataType(data_struct, (sint64)data, index);
  329. break;
  330. case DATA_STRUCT_CHAR:
  331. setDataType(data_struct, (char)data, index);
  332. break;
  333. case DATA_STRUCT_FLOAT:
  334. setDataType(data_struct, (float)data, index);
  335. break;
  336. case DATA_STRUCT_DOUBLE:
  337. setDataType(data_struct, (double)data, index);
  338. break;
  339. case DATA_STRUCT_COLOR:
  340. setColor(data_struct, *((EQ2_Color*)&data), index);
  341. break;
  342. case DATA_STRUCT_EQUIPMENT:
  343. setEquipmentByName(data_struct, *((EQ2_EquipmentItem*)&data), index);
  344. break;
  345. case DATA_STRUCT_ITEM:
  346. break;
  347. }
  348. }
  349. }
  350. template<class Data> void setSubArrayLengthByName(const char* name, Data data, int32 index1 = 0, int32 index2 = 0){
  351. char tmp[10] = {0};
  352. sprintf(tmp,"_%i",index1);
  353. string name2 = string(name).append(tmp);
  354. DataStruct* data_struct = findStruct(name2.c_str(), index2);
  355. setData(data_struct, data, index2);
  356. UpdateArrayByArrayLength(data_struct, index2, data);
  357. }
  358. template<class Data> void setArrayLengthByName(const char* name, Data data, int32 index = 0){
  359. DataStruct* data_struct = findStruct(name, index);
  360. setData(data_struct, data, index);
  361. UpdateArrayByArrayLength(data_struct, index, data);
  362. }
  363. template<class Data> void setSubstructArrayLengthByName(const char* substruct_name, const char* name, Data data, int32 substruct_index = 0, int32 index = 0){
  364. char tmp[10] = {0};
  365. sprintf(tmp,"_%i",substruct_index);
  366. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  367. DataStruct* data_struct = findStruct(name2.c_str(), index);
  368. setData(data_struct, data, index);
  369. UpdateArrayByArrayLength(data_struct, index, data);
  370. }
  371. void UpdateArrayByArrayLengthName(const char* name, int32 index, int32 size);
  372. void UpdateArrayByArrayLength(DataStruct* data_struct, int32 index, int32 size);
  373. bool StructLoadData(DataStruct* data_struct, void* data, int32 len, bool useType2 = false);
  374. bool LoadPacketData(uchar* data, int32 data_len);
  375. void setColorByName(const char* name, EQ2_Color* data, int32 index = 0){
  376. if(data)
  377. setColorByName(name, data->red, data->green, data->blue, index);
  378. }
  379. void setColorByName(const char* name, EQ2_Color data, int32 index = 0){
  380. setColorByName(name, data.red, data.green, data.blue, index);
  381. }
  382. void setColor(DataStruct* data_struct, EQ2_Color data, int32 index = 0){
  383. if(data_struct){
  384. EQ2_Color* ptr = (EQ2_Color*)struct_data[data_struct];
  385. ptr[index] = data;
  386. }
  387. }
  388. void setColorByName(const char* name, int8 red, int8 green, int8 blue, int32 index = 0){
  389. setColor(findStruct(name, index), red, green, blue, index);
  390. }
  391. void setColor(DataStruct* data, int8 red, int8 green, int8 blue, int32 index);
  392. void setEquipmentByName(DataStruct* data_struct, EQ2_EquipmentItem data, int32 index = 0){
  393. if(data_struct){
  394. EQ2_EquipmentItem* ptr = (EQ2_EquipmentItem*)struct_data[data_struct];
  395. ptr[index] = data;
  396. }
  397. }
  398. #ifdef WORLD
  399. void setItem(DataStruct* ds, Item* item, Player* player, int32 index, sint8 offset = 0);
  400. void setItemByName(const char* name, Item* item, Player* player, int32 index = 0, sint8 offset = 0);
  401. void setItemArrayDataByName(const char* name, Item* item, Player* player, int32 index1 = 0, int32 index2 = 0, sint8 offset = 0);
  402. #endif
  403. void setEquipmentByName(const char* name, EQ2_EquipmentItem data, int32 index = 0){
  404. setEquipmentByName(findStruct(name, index), data, index);
  405. }
  406. void setEquipmentByName(const char* name, EQ2_EquipmentItem* data, int32 size){
  407. DataStruct* data_struct = findStruct(name, 0);
  408. if(data_struct){
  409. for(int32 i=0;i<size;i++)
  410. setEquipmentByName(data_struct, data[i], i);
  411. }
  412. }
  413. void setEquipmentByName(const char* name, int32 type, int8 c_red, int8 c_blue, int8 c_green, int8 h_red, int8 h_blue, int8 h_green, int32 index = 0){
  414. setEquipment(findStruct(name,index), type, c_red, c_blue, c_green, h_red, h_blue, h_green, index);
  415. }
  416. void setEquipment(DataStruct* data, int16 type, int8 c_red, int8 c_blue, int8 c_green, int8 h_red, int8 h_blue, int8 h_green, int32 index);
  417. void remove(DataStruct* data);
  418. vector<DataStruct*>* getStructs(){ return &structs; }
  419. DataStruct* findStruct(const char* name, int32 index);
  420. DataStruct* findStruct(const char* name, int32 index1, int32 index2);
  421. void remove(const char* name);
  422. void remove(int32 position);
  423. void serializePacket(bool clear = true);
  424. void AddSerializedData(DataStruct* data, int32 index = 0, string* datastring = 0);
  425. EQ2Packet* serialize();
  426. EQ2Packet* serializeCountPacket(int16 version, int8 offset = 0, uchar* orig_packet = 0, uchar* xor_packet = 0);
  427. string* serializeString();
  428. int32 GetVersion(){ return version; }
  429. void SetVersion(int32 in_version){ version = in_version; }
  430. bool SetOpcode(const char* new_opcode);
  431. EmuOpcode GetOpcode(){ return opcode; }
  432. const char* GetName(){ return name.c_str(); }
  433. void SetName(const char* in_name){ name = string(in_name); }
  434. bool LoadedSuccessfully() { return loadedSuccessfully; }
  435. bool IsStringValueType(string in_name, int32 index);
  436. bool IsColorValueType(string in_name, int32 index);
  437. int32 GetTotalPacketSize();
  438. PacketStruct* GetPacketStructByName(const char* name);
  439. void* GetStructPointer(DataStruct* data_struct, bool erase = false);
  440. void PrintPacket();
  441. string GetSQLQuery(const char* table_name);
  442. vector<DataStruct*> GetDataStructs();
  443. void AddPackedData();
  444. void ResetData();
  445. private:
  446. PacketStruct* parent;
  447. int32 sub_packet_size;
  448. string opcode_type;
  449. bool sub_packet;
  450. bool loadedSuccessfully;
  451. string name;
  452. EmuOpcode opcode;
  453. int16 version;
  454. int16 client_version;
  455. vector<PacketStruct*> arrays;
  456. map<DataStruct*, void*> struct_data;
  457. map<int8, string> packed_data;
  458. map<string, DataStruct*> struct_map;
  459. vector<DataStruct*> structs;
  460. vector<DataStruct*> orig_structs;
  461. vector<PacketStruct*> orig_packets;
  462. };
  463. #endif