9
3

PacketStruct.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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 SetIfFlagSetVariable(const char* variable);
  75. void SetIfFlagNotSetVariable(const char* variable);
  76. void SetIsSet(bool val);
  77. void SetIsOptional(bool val);
  78. int8 GetPackedIndex();
  79. const char* GetPackedSizeVariable();
  80. const char* GetArraySizeVariable();
  81. int8 GetDefaultValue();
  82. int8 GetOversized();
  83. int8 GetOversizedByte();
  84. int8 GetMaxArraySize();
  85. int8 GetType();
  86. int8 GetType2();
  87. const char* GetName();
  88. string GetStringName();
  89. int32 GetLength();
  90. bool AddToStruct();
  91. int8 GetAddType();
  92. int32 GetItemSize();
  93. bool GetIfSet();
  94. const char* GetIfSetVariable();
  95. bool GetIfNotSet();
  96. const char* GetIfNotSetVariable();
  97. bool GetIfEquals();
  98. const char* GetIfEqualsVariable();
  99. bool GetIfNotEquals();
  100. const char* GetIfNotEqualsVariable();
  101. bool GetIfFlagSet();
  102. const char* GetIfFlagSetVariable();
  103. bool GetIfFlagNotSet();
  104. const char* GetIfFlagNotSetVariable();
  105. bool IsSet();
  106. bool IsOptional();
  107. int32 GetDataSizeInBytes();
  108. private:
  109. bool is_set;
  110. bool if_not_set;
  111. bool optional;
  112. bool if_set;
  113. bool if_not_equals;
  114. bool if_equals;
  115. bool if_flag_set;
  116. bool if_flag_not_set;
  117. string if_flag_not_set_variable;
  118. string if_flag_set_variable;
  119. string if_not_equals_variable;
  120. string if_equals_variable;
  121. string if_not_set_variable;
  122. string if_set_variable;
  123. int8 oversized;
  124. int8 oversized_byte;
  125. bool add;
  126. int8 addType;
  127. int8 maxArraySize;
  128. string array_size_variable;
  129. string name;
  130. int8 type;
  131. int8 default_value;
  132. int8 type2;
  133. int32 length;
  134. int32 item_size;
  135. };
  136. class PacketStruct : public DataBuffer {
  137. public:
  138. PacketStruct();
  139. PacketStruct(PacketStruct* packet, bool sub);
  140. PacketStruct(PacketStruct* packet, int16 in_client_version);
  141. ~PacketStruct();
  142. void add(DataStruct* data);
  143. void reAddAll(int32 length);
  144. void add(PacketStruct* packet_struct);
  145. void addPacketArrays(PacketStruct* packet);
  146. void deletePacketArrays(PacketStruct* packet);
  147. void deleteDataStructs(vector<DataStruct*>* data_structs);
  148. void setSmallStringByName(const char* name, const char* text, int32 index = 0);
  149. void setMediumStringByName(const char* name, const char* text, int32 index = 0);
  150. void setLargeStringByName(const char* name, const char* text, int32 index = 0);
  151. void setSmallString(DataStruct* data_struct, const char* text, int32 index = 0);
  152. void setMediumString(DataStruct* data_struct, const char* text, int32 index = 0);
  153. void setLargeString(DataStruct* data_struct, const char* text, int32 index = 0);
  154. void renameSubstructArray(const char* substruct, int32 index);
  155. 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) {
  156. char tmp[15] = { 0 };
  157. sprintf(tmp, "_%i_%i", substruct_index1, substruct_index2);
  158. string name2 = string(substruct_name1).append("_").append(substruct_name2).append("_").append(name).append(tmp);
  159. setData(findStruct(name2.c_str(), index), data, index);
  160. }
  161. template<class Data> void setSubstructDataByName(const char* substruct_name, const char* name, Data data, int32 substruct_index = 0, int32 index = 0) {
  162. char tmp[10] = { 0 };
  163. sprintf(tmp, "_%i", substruct_index);
  164. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  165. setData(findStruct(name2.c_str(), index), data, index);
  166. }
  167. template<class Data> void setSubstructColorByName(const char* substruct_name, const char* name, Data data, int32 substruct_index = 0, int32 index = 0) {
  168. char tmp[10] = { 0 };
  169. sprintf(tmp, "_%i", substruct_index);
  170. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  171. setColor(findStruct(name2.c_str(), index), data, index);
  172. }
  173. template<class Data> void setSubstructArrayDataByName(const char* substruct_name, const char* name, Data data, int32 index = 0, int32 substruct_index = 0) {
  174. char tmp[10] = { 0 };
  175. sprintf(tmp, "_%i", substruct_index);
  176. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  177. setData(findStruct(name2.c_str(), substruct_index, index), data, index);
  178. }
  179. template<class Data> void setSubstructArrayColorByName(const char* substruct_name, const char* name, Data data, int32 substruct_index = 0, int32 index = 0) {
  180. char tmp[10] = { 0 };
  181. sprintf(tmp, "_%i", substruct_index);
  182. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  183. setColor(findStruct(name2.c_str(), index, substruct_index), data, index);
  184. }
  185. template<class Data> void setDataByName(const char* name, Data data, int32 index = 0, bool use_second_type = false) {
  186. setData(findStruct(name, index), data, index, use_second_type);
  187. }
  188. template<class Data> void setDataByName(const char* name, Data* data, int32 index = 0, bool use_second_type = false) {
  189. setData(findStruct(name, index), data, index, use_second_type);
  190. }
  191. template<class Data> void setSubArrayDataByName(const char* name, Data data, int32 index1 = 0, int32 index2 = 0, int32 index3 = 0) {
  192. char tmp[20] = { 0 };
  193. sprintf(tmp, "%i_%i", index1, index2);
  194. string name2 = string(name).append(tmp);
  195. setData(findStruct(name2.c_str(), index2, index3), data, index3);
  196. }
  197. template<class Data> void setArrayDataByName(const char* name, Data data, int32 index1 = 0, int32 index2 = 0, bool use_second_type = false) {
  198. char tmp[10] = { 0 };
  199. sprintf(tmp, "_%i", index1);
  200. string name2 = string(name).append(tmp);
  201. setData(findStruct(name2.c_str(), index1, index2), data, index2, use_second_type);
  202. }
  203. void setArrayAddToPacketByName(const char* name, bool new_val, int32 index1 = 0, int32 index2 = 0) {
  204. char tmp[10] = { 0 };
  205. sprintf(tmp, "_%i", index1);
  206. string name2 = string(name).append(tmp);
  207. DataStruct* data = findStruct(name2.c_str(), index2);
  208. if (data)
  209. data->SetAddToStruct(new_val);
  210. }
  211. void setAddToPacketByName(const char* name, bool new_val, int32 index = 0) {
  212. DataStruct* data = findStruct(name, index);
  213. if (data)
  214. data->SetAddToStruct(new_val);
  215. }
  216. void setAddTypePacketByName(const char* name, int8 new_val, int32 index = 0) {
  217. DataStruct* data = findStruct(name, index);
  218. if (data)
  219. data->SetAddType(new_val);
  220. }
  221. const char* GetOpcodeType();
  222. bool IsSubPacket();
  223. void IsSubPacket(bool new_val);
  224. int32 GetSubPacketSize();
  225. void SetSubPacketSize(int32 new_size);
  226. void SetOpcodeType(const char* opcodeType);
  227. int32 GetArraySizeByName(const char* name, int32 index);
  228. int32 GetArraySize(DataStruct* data_struct, int32 index);
  229. int32 GetArraySize(const char* name, int32 index);
  230. void LoadFromPacketStruct(PacketStruct* packet, char* substruct_name = 0);
  231. bool GetVariableIsSet(const char* name);
  232. bool GetVariableIsNotSet(const char* name);
  233. int8 getType_int8_ByName(const char* name, int32 index = 0, bool force = false);
  234. int16 getType_int16_ByName(const char* name, int32 index = 0, bool force = false);
  235. int32 getType_int32_ByName(const char* name, int32 index = 0, bool force = false);
  236. int64 getType_int64_ByName(const char* name, int32 index = 0, bool force = false);
  237. sint8 getType_sint8_ByName(const char* name, int32 index = 0, bool force = false);
  238. sint16 getType_sint16_ByName(const char* name, int32 index = 0, bool force = false);
  239. sint32 getType_sint32_ByName(const char* name, int32 index = 0, bool force = false);
  240. sint64 getType_sint64_ByName(const char* name, int32 index = 0, bool force = false);
  241. float getType_float_ByName(const char* name, int32 index = 0, bool force = false);
  242. double getType_double_ByName(const char* name, int32 index = 0, bool force = false);
  243. char getType_char_ByName(const char* name, int32 index = 0, bool force = false);
  244. EQ2_8BitString getType_EQ2_8BitString_ByName(const char* name, int32 index = 0, bool force = false);
  245. EQ2_16BitString getType_EQ2_16BitString_ByName(const char* name, int32 index = 0, bool force = false);
  246. EQ2_32BitString getType_EQ2_32BitString_ByName(const char* name, int32 index = 0, bool force = false);
  247. EQ2_Color getType_EQ2_Color_ByName(const char* name, int32 index = 0, bool force = false);
  248. EQ2_EquipmentItem getType_EQ2_EquipmentItem_ByName(const char* name, int32 index = 0, bool force = false);
  249. int8 getType_int8(DataStruct* data_struct, int32 index = 0, bool force = false);
  250. int16 getType_int16(DataStruct* data_struct, int32 index = 0, bool force = false);
  251. int32 getType_int32(DataStruct* data_struct, int32 index = 0, bool force = false);
  252. int64 getType_int64(DataStruct* data_struct, int32 index = 0, bool force = false);
  253. sint8 getType_sint8(DataStruct* data_struct, int32 index = 0, bool force = false);
  254. sint16 getType_sint16(DataStruct* data_struct, int32 index = 0, bool force = false);
  255. sint32 getType_sint32(DataStruct* data_struct, int32 index = 0, bool force = false);
  256. sint64 getType_sint64(DataStruct* data_struct, int32 index = 0, bool force = false);
  257. float getType_float(DataStruct* data_struct, int32 index = 0, bool force = false);
  258. double getType_double(DataStruct* data_struct, int32 index = 0, bool force = false);
  259. char getType_char(DataStruct* data_struct, int32 index = 0, bool force = false);
  260. EQ2_8BitString getType_EQ2_8BitString(DataStruct* data_struct, int32 index = 0, bool force = false);
  261. EQ2_16BitString getType_EQ2_16BitString(DataStruct* data_struct, int32 index = 0, bool force = false);
  262. EQ2_32BitString getType_EQ2_32BitString(DataStruct* data_struct, int32 index = 0, bool force = false);
  263. EQ2_Color getType_EQ2_Color(DataStruct* data_struct, int32 index = 0, bool force = false);
  264. EQ2_EquipmentItem getType_EQ2_EquipmentItem(DataStruct* data_struct, int32 index = 0, bool force = false);
  265. void setDataType(DataStruct* data_struct, char data, int32 index);
  266. void setDataType(DataStruct* data_struct, int8 data, int32 index);
  267. void setDataType(DataStruct* data_struct, int16 data, int32 index);
  268. void setDataType(DataStruct* data_struct, int32 data, int32 index);
  269. void setDataType(DataStruct* data_struct, int64 data, int32 index);
  270. void setDataType(DataStruct* data_struct, sint8 data, int32 index);
  271. void setDataType(DataStruct* data_struct, sint16 data, int32 index);
  272. void setDataType(DataStruct* data_struct, sint32 data, int32 index);
  273. void setDataType(DataStruct* data_struct, sint64 data, int32 index);
  274. void setDataType(DataStruct* data_struct, float data, int32 index);
  275. void setDataType(DataStruct* data_struct, double data, int32 index);
  276. void setData(DataStruct* data_struct, EQ2_8BitString* input_string, int32 index, bool use_second_type = false);
  277. void setData(DataStruct* data_struct, EQ2_16BitString* input_string, int32 index, bool use_second_type = false);
  278. void setData(DataStruct* data_struct, EQ2_32BitString* input_string, int32 index, bool use_second_type = false);
  279. template<class Data> void setData(DataStruct* data_struct, Data* data, int32 index, bool use_second_type = false) {
  280. if (!data_struct)
  281. return;
  282. data_struct->SetIsOptional(false);
  283. int8 type_to_use = (use_second_type) ? data_struct->GetType2() : data_struct->GetType();
  284. if (type_to_use >= DATA_STRUCT_EQ2_8BIT_STRING && type_to_use <= DATA_STRUCT_EQ2_32BIT_STRING) {
  285. if (type_to_use == DATA_STRUCT_EQ2_8BIT_STRING) {
  286. setSmallString(data_struct, data, index);
  287. }
  288. else if (type_to_use == DATA_STRUCT_EQ2_16BIT_STRING) {
  289. setMediumString(data_struct, data, index);
  290. }
  291. else {
  292. setLargeString(data_struct, data, index);
  293. }
  294. }
  295. else {
  296. if (data_struct && index == 0 && data_struct->GetLength() > 1) {
  297. if (type_to_use == DATA_STRUCT_CHAR) {
  298. for (int32 i = 0; data && i < data_struct->GetLength() && i < strlen(data); i++)
  299. setData(data_struct, data[i], i);
  300. }
  301. else {
  302. for (int32 i = 0; i < data_struct->GetLength(); i++)
  303. setData(data_struct, data[i], i);
  304. }
  305. }
  306. else
  307. setData(data_struct, *data, index);
  308. }
  309. }
  310. template<class Data> void setData(DataStruct* data_struct, Data data, int32 index, bool use_second_type = false) {
  311. if (data_struct && index < data_struct->GetLength()) {
  312. data_struct->SetIsOptional(false);
  313. int8 type_to_use = (use_second_type) ? data_struct->GetType2() : data_struct->GetType();
  314. if (use_second_type) {
  315. // Need to figure out why type2 always seems to be 205
  316. // since only items use type2 for now just hardcoded the value needed (BAD!!!)
  317. //type_to_use = DATA_STRUCT_SINT16; // 9;
  318. data_struct->SetType(type_to_use);
  319. }
  320. switch (type_to_use) {
  321. case DATA_STRUCT_INT8:
  322. setDataType(data_struct, (int8)data, index);
  323. break;
  324. case DATA_STRUCT_INT16:
  325. setDataType(data_struct, (int16)data, index);
  326. break;
  327. case DATA_STRUCT_INT32:
  328. setDataType(data_struct, (int32)data, index);
  329. break;
  330. case DATA_STRUCT_INT64:
  331. setDataType(data_struct, (int64)data, index);
  332. break;
  333. case DATA_STRUCT_SINT8:
  334. setDataType(data_struct, (sint8)data, index);
  335. break;
  336. case DATA_STRUCT_SINT16:
  337. setDataType(data_struct, (sint16)data, index);
  338. break;
  339. case DATA_STRUCT_SINT32:
  340. setDataType(data_struct, (sint32)data, index);
  341. break;
  342. case DATA_STRUCT_SINT64:
  343. setDataType(data_struct, (sint64)data, index);
  344. break;
  345. case DATA_STRUCT_CHAR:
  346. setDataType(data_struct, (char)data, index);
  347. break;
  348. case DATA_STRUCT_FLOAT:
  349. setDataType(data_struct, (float)data, index);
  350. break;
  351. case DATA_STRUCT_DOUBLE:
  352. setDataType(data_struct, (double)data, index);
  353. break;
  354. case DATA_STRUCT_COLOR:
  355. setColor(data_struct, *((EQ2_Color*)&data), index);
  356. break;
  357. case DATA_STRUCT_EQUIPMENT:
  358. setEquipmentByName(data_struct, *((EQ2_EquipmentItem*)&data), index);
  359. break;
  360. case DATA_STRUCT_ITEM:
  361. break;
  362. }
  363. }
  364. }
  365. template<class Data> void setSubArrayLengthByName(const char* name, Data data, int32 index1 = 0, int32 index2 = 0) {
  366. char tmp[10] = { 0 };
  367. sprintf(tmp, "_%i", index1);
  368. string name2 = string(name).append(tmp);
  369. DataStruct* data_struct = findStruct(name2.c_str(), index2);
  370. setData(data_struct, data, index2);
  371. UpdateArrayByArrayLength(data_struct, index2, data);
  372. }
  373. template<class Data> void setArrayLengthByName(const char* name, Data data, int32 index = 0) {
  374. DataStruct* data_struct = findStruct(name, index);
  375. setData(data_struct, data, index);
  376. UpdateArrayByArrayLength(data_struct, index, data);
  377. }
  378. template<class Data> void setSubstructArrayLengthByName(const char* substruct_name, const char* name, Data data, int32 substruct_index = 0, int32 index = 0) {
  379. char tmp[10] = { 0 };
  380. sprintf(tmp, "_%i", substruct_index);
  381. string name2 = string(substruct_name).append("_").append(name).append(tmp);
  382. DataStruct* data_struct = findStruct(name2.c_str(), index);
  383. setData(data_struct, data, index);
  384. UpdateArrayByArrayLength(data_struct, index, data);
  385. }
  386. void UpdateArrayByArrayLengthName(const char* name, int32 index, int32 size);
  387. void UpdateArrayByArrayLength(DataStruct* data_struct, int32 index, int32 size);
  388. bool StructLoadData(DataStruct* data_struct, void* data, int32 len, bool useType2 = false);
  389. bool LoadPacketData(uchar* data, int32 data_len);
  390. bool CheckFlagExists(const char* name);
  391. void setColorByName(const char* name, EQ2_Color* data, int32 index = 0) {
  392. if (data)
  393. setColorByName(name, data->red, data->green, data->blue, index);
  394. }
  395. void setColorByName(const char* name, EQ2_Color data, int32 index = 0) {
  396. setColorByName(name, data.red, data.green, data.blue, index);
  397. }
  398. void setColor(DataStruct* data_struct, EQ2_Color data, int32 index = 0) {
  399. if (data_struct) {
  400. EQ2_Color* ptr = (EQ2_Color*)struct_data[data_struct];
  401. ptr[index] = data;
  402. }
  403. }
  404. void setColorByName(const char* name, int8 red, int8 green, int8 blue, int32 index = 0) {
  405. setColor(findStruct(name, index), red, green, blue, index);
  406. }
  407. void setColor(DataStruct* data, int8 red, int8 green, int8 blue, int32 index);
  408. void setEquipmentByName(DataStruct* data_struct, EQ2_EquipmentItem data, int32 index = 0) {
  409. if (data_struct) {
  410. EQ2_EquipmentItem* ptr = (EQ2_EquipmentItem*)struct_data[data_struct];
  411. ptr[index] = data;
  412. }
  413. }
  414. #ifdef WORLD
  415. void setItem(DataStruct* ds, Item* item, Player* player, int32 index, sint8 offset = 0, bool loot_item = false);
  416. void setItemByName(const char* name, Item* item, Player* player, int32 index = 0, sint8 offset = 0, bool loot_item = false);
  417. void setItemArrayDataByName(const char* name, Item* item, Player* player, int32 index1 = 0, int32 index2 = 0, sint8 offset = 0, bool loot_item = false);
  418. #endif
  419. void setEquipmentByName(const char* name, EQ2_EquipmentItem data, int32 index = 0) {
  420. setEquipmentByName(findStruct(name, index), data, index);
  421. }
  422. void setEquipmentByName(const char* name, EQ2_EquipmentItem* data, int32 size) {
  423. DataStruct* data_struct = findStruct(name, 0);
  424. if (data_struct) {
  425. for (int32 i = 0; i < size; i++)
  426. setEquipmentByName(data_struct, data[i], i);
  427. }
  428. }
  429. 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) {
  430. setEquipment(findStruct(name, index), type, c_red, c_blue, c_green, h_red, h_blue, h_green, index);
  431. }
  432. 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);
  433. void remove(DataStruct* data);
  434. vector<DataStruct*>* getStructs() { return &structs; }
  435. DataStruct* findStruct(const char* name, int32 index);
  436. DataStruct* findStruct(const char* name, int32 index1, int32 index2);
  437. void remove(const char* name);
  438. void remove(int32 position);
  439. void serializePacket(bool clear = true);
  440. void AddSerializedData(DataStruct* data, int32 index = 0, string* datastring = 0);
  441. EQ2Packet* serialize();
  442. EQ2Packet* serializeCountPacket(int16 version, int8 offset = 0, uchar* orig_packet = 0, uchar* xor_packet = 0);
  443. string* serializeString();
  444. int32 GetVersion() { return version; }
  445. void SetVersion(int32 in_version) { version = in_version; }
  446. bool SetOpcode(const char* new_opcode);
  447. EmuOpcode GetOpcode() { return opcode; }
  448. const char* GetName() { return name.c_str(); }
  449. void SetName(const char* in_name) { name = string(in_name); }
  450. bool LoadedSuccessfully() { return loadedSuccessfully; }
  451. bool IsStringValueType(string in_name, int32 index);
  452. bool IsColorValueType(string in_name, int32 index);
  453. int32 GetTotalPacketSize();
  454. PacketStruct* GetPacketStructByName(const char* name);
  455. void* GetStructPointer(DataStruct* data_struct, bool erase = false);
  456. void PrintPacket();
  457. string GetSQLQuery(const char* table_name);
  458. vector<DataStruct*> GetDataStructs();
  459. void AddPackedData();
  460. void ResetData();
  461. void AddFlag(const char* name);
  462. private:
  463. PacketStruct* parent;
  464. int32 sub_packet_size;
  465. string opcode_type;
  466. bool sub_packet;
  467. bool loadedSuccessfully;
  468. string name;
  469. EmuOpcode opcode;
  470. int16 version;
  471. int16 client_version;
  472. vector<PacketStruct*> arrays;
  473. vector<string> flags;
  474. map<DataStruct*, void*> struct_data;
  475. map<int8, string> packed_data;
  476. map<string, DataStruct*> struct_map;
  477. vector<DataStruct*> structs;
  478. vector<DataStruct*> orig_structs;
  479. vector<PacketStruct*> orig_packets;
  480. };
  481. #endif