9
3

PacketStruct.h 22 KB

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