PacketStruct.cpp 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691
  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. #include <iostream>
  17. #include <exception>
  18. #include "PacketStruct.h"
  19. #include "ConfigReader.h"
  20. #include "../common/debug.h"
  21. #include "MiscFunctions.h"
  22. #include "Log.h"
  23. #ifdef WORLD
  24. #include "../WorldServer/Items/Items.h"
  25. #include "../WorldServer/Player.h"
  26. #endif
  27. extern ConfigReader configReader;
  28. using namespace std;
  29. DataStruct::DataStruct() {
  30. item_size = 0;
  31. type = 0;
  32. type2 = 0;
  33. length = 1;
  34. if_flag_set = false;
  35. if_flag_not_set = false;
  36. if_set = false;
  37. if_not_set = false;
  38. if_not_equals = false;
  39. if_equals = false;
  40. is_set = false;
  41. optional = false;
  42. oversized = 0;
  43. oversized_byte = 0;
  44. add = false;
  45. addType = 0;
  46. maxArraySize = 0;
  47. default_value = 0;
  48. }
  49. DataStruct::DataStruct(DataStruct* data_struct) {
  50. type = data_struct->GetType();
  51. type2 = data_struct->GetType2();
  52. length = data_struct->GetLength();
  53. name = data_struct->GetName();
  54. array_size_variable = data_struct->array_size_variable;
  55. default_value = data_struct->default_value;
  56. add = true;
  57. addType = type;
  58. oversized = data_struct->GetOversized();
  59. oversized_byte = data_struct->GetOversizedByte();
  60. maxArraySize = data_struct->GetMaxArraySize();
  61. if_flag_set = false;
  62. if_flag_not_set = false;
  63. if_set = false;
  64. if_not_set = false;
  65. if_not_equals = false;
  66. if_equals = false;
  67. optional = false;
  68. if (data_struct->GetIfSet())
  69. SetIfSetVariable(data_struct->GetIfSetVariable());
  70. if (data_struct->GetIfNotSet())
  71. SetIfNotSetVariable(data_struct->GetIfNotSetVariable());
  72. if (data_struct->GetIfNotEquals())
  73. SetIfNotEqualsVariable(data_struct->GetIfNotEqualsVariable());
  74. if (data_struct->GetIfEquals())
  75. SetIfEqualsVariable(data_struct->GetIfEqualsVariable());
  76. if (data_struct->GetIfFlagSet())
  77. SetIfFlagSetVariable(data_struct->GetIfFlagSetVariable());
  78. if (data_struct->GetIfFlagNotSet())
  79. SetIfFlagNotSetVariable(data_struct->GetIfFlagNotSetVariable());
  80. item_size = 0;
  81. is_set = false;
  82. }
  83. DataStruct::DataStruct(const char* new_name, const char* new_type, int32 new_length, const char* new_type2) {
  84. name = string(new_name);
  85. type = 0;
  86. type2 = 0;
  87. SetType(new_type, &type);
  88. if (new_type2)
  89. SetType(new_type2, &type2);
  90. length = new_length;
  91. add = true;
  92. addType = type;
  93. if_set = false;
  94. if_not_set = false;
  95. is_set = false;
  96. if_not_equals = false;
  97. item_size = 0;
  98. }
  99. const char* DataStruct::GetArraySizeVariable() {
  100. return array_size_variable.c_str();
  101. }
  102. void DataStruct::SetArraySizeVariable(const char* new_name) {
  103. array_size_variable = string(new_name);
  104. }
  105. void DataStruct::SetType(const char* new_type, int8* output_type) {
  106. if (strlen(new_type) > 3 && strncasecmp("int", new_type, 3) == 0) {
  107. if (strncasecmp("int8", new_type, 4) == 0)
  108. *output_type = DATA_STRUCT_INT8;
  109. else if (strncasecmp("int16", new_type, 5) == 0)
  110. *output_type = DATA_STRUCT_INT16;
  111. else if (strncasecmp("int32", new_type, 5) == 0)
  112. *output_type = DATA_STRUCT_INT32;
  113. else if (strncasecmp("int64", new_type, 5) == 0)
  114. *output_type = DATA_STRUCT_INT64;
  115. }
  116. else if (strlen(new_type) > 4 && strncasecmp("sint", new_type, 4) == 0) {
  117. if (strncasecmp("sint8", new_type, 5) == 0)
  118. *output_type = DATA_STRUCT_SINT8;
  119. else if (strncasecmp("sint16", new_type, 6) == 0)
  120. *output_type = DATA_STRUCT_SINT16;
  121. else if (strncasecmp("sint32", new_type, 6) == 0)
  122. *output_type = DATA_STRUCT_SINT32;
  123. else if (strncasecmp("sint64", new_type, 6) == 0)
  124. *output_type = DATA_STRUCT_SINT64;
  125. }
  126. else if (strlen(new_type) == 4 && strncasecmp("char", new_type, 4) == 0)
  127. *output_type = DATA_STRUCT_CHAR;
  128. else if (strlen(new_type) == 5 && strncasecmp("float", new_type, 5) == 0)
  129. *output_type = DATA_STRUCT_FLOAT;
  130. else if (strlen(new_type) == 6 && strncasecmp("double", new_type, 6) == 0)
  131. *output_type = DATA_STRUCT_DOUBLE;
  132. else if (strlen(new_type) >= 5 && strncasecmp("EQ2_", new_type, 4) == 0) {
  133. if (strncasecmp("EQ2_8", new_type, 5) == 0)
  134. *output_type = DATA_STRUCT_EQ2_8BIT_STRING;
  135. else if (strncasecmp("EQ2_16", new_type, 6) == 0)
  136. *output_type = DATA_STRUCT_EQ2_16BIT_STRING;
  137. else if (strncasecmp("EQ2_32", new_type, 6) == 0)
  138. *output_type = DATA_STRUCT_EQ2_32BIT_STRING;
  139. else if (strncasecmp("EQ2_E", new_type, 5) == 0)
  140. *output_type = DATA_STRUCT_EQUIPMENT;
  141. else if (strncasecmp("EQ2_C", new_type, 5) == 0)
  142. *output_type = DATA_STRUCT_COLOR;
  143. else if (strncasecmp("EQ2_I", new_type, 5) == 0)
  144. *output_type = DATA_STRUCT_ITEM;
  145. }
  146. else if (strlen(new_type) >= 5) {
  147. if (strncasecmp("Array", new_type, 5) == 0)
  148. *output_type = DATA_STRUCT_ARRAY;
  149. }
  150. else
  151. LogWrite(PACKET__ERROR, 0, "Packet", "Invalid Type: %s", new_type);
  152. }
  153. DataStruct::DataStruct(const char* new_name, int32 new_length) {
  154. name = string(new_name);
  155. length = new_length;
  156. if_set = false;
  157. if_not_set = false;
  158. is_set = false;
  159. item_size = 0;
  160. }
  161. DataStruct::DataStruct(const char* new_name, int8 new_type, int32 new_length, int8 new_type2) {
  162. name = string(new_name);
  163. type = new_type;
  164. length = new_length;
  165. type2 = new_type2;
  166. addType = type;
  167. if_set = false;
  168. if_not_set = false;
  169. is_set = false;
  170. item_size = 0;
  171. }
  172. void DataStruct::SetType(int8 new_type) {
  173. type = new_type;
  174. addType = type;
  175. }
  176. void DataStruct::SetMaxArraySize(int8 size) {
  177. maxArraySize = size;
  178. }
  179. void DataStruct::SetOversized(int8 val) {
  180. oversized = val;
  181. }
  182. void DataStruct::SetDefaultValue(int8 new_val) {
  183. default_value = new_val;
  184. }
  185. void DataStruct::SetName(const char* new_name) {
  186. name = string(new_name);
  187. }
  188. void DataStruct::SetLength(int32 new_length) {
  189. length = new_length;
  190. }
  191. void DataStruct::SetOversizedByte(int8 val) {
  192. oversized_byte = val;
  193. }
  194. void DataStruct::SetItemSize(int32 val) {
  195. item_size = val;
  196. }
  197. void DataStruct::SetIfEqualsVariable(const char* variable) {
  198. if (variable) {
  199. if_equals = true;
  200. if_equals_variable = string(variable);
  201. }
  202. else
  203. if_equals = false;
  204. }
  205. void DataStruct::SetIfNotEqualsVariable(const char* variable) {
  206. if (variable) {
  207. if_not_equals = true;
  208. if_not_equals_variable = string(variable);
  209. }
  210. else
  211. if_not_equals = false;
  212. }
  213. void DataStruct::SetIfFlagNotSetVariable(const char* variable) {
  214. if (variable) {
  215. if_flag_not_set = true;
  216. if_flag_not_set_variable = string(variable);
  217. }
  218. else
  219. if_flag_not_set = false;
  220. }
  221. void DataStruct::SetIfFlagSetVariable(const char* variable) {
  222. if (variable) {
  223. if_flag_set = true;
  224. if_flag_set_variable = string(variable);
  225. }
  226. else
  227. if_flag_set = false;
  228. }
  229. void DataStruct::SetIfSetVariable(const char* variable) {
  230. if (variable) {
  231. if_set = true;
  232. if_set_variable = string(variable);
  233. }
  234. else
  235. if_set = false;
  236. }
  237. void DataStruct::SetIfNotSetVariable(const char* variable) {
  238. if (variable) {
  239. if_not_set = true;
  240. if_not_set_variable = string(variable);
  241. }
  242. else
  243. if_not_set = false;
  244. }
  245. void DataStruct::SetIsSet(bool val) {
  246. is_set = val;
  247. }
  248. bool DataStruct::IsSet() {
  249. return is_set;
  250. }
  251. void DataStruct::SetIsOptional(bool val) {
  252. optional = val;
  253. }
  254. bool DataStruct::IsOptional() {
  255. return optional;
  256. }
  257. int32 DataStruct::GetItemSize() {
  258. return item_size;
  259. }
  260. bool DataStruct::GetIfSet() {
  261. return if_set;
  262. }
  263. const char* DataStruct::GetIfSetVariable() {
  264. if (if_set_variable.length() > 0)
  265. return if_set_variable.c_str();
  266. return 0;
  267. }
  268. bool DataStruct::GetIfNotSet() {
  269. return if_not_set;
  270. }
  271. const char* DataStruct::GetIfNotSetVariable() {
  272. if (if_not_set_variable.length() > 0)
  273. return if_not_set_variable.c_str();
  274. return 0;
  275. }
  276. bool DataStruct::GetIfEquals() {
  277. return if_equals;
  278. }
  279. const char* DataStruct::GetIfEqualsVariable() {
  280. if (if_equals_variable.length() > 0)
  281. return if_equals_variable.c_str();
  282. return 0;
  283. }
  284. bool DataStruct::GetIfNotEquals() {
  285. return if_not_equals;
  286. }
  287. const char* DataStruct::GetIfNotEqualsVariable() {
  288. if (if_not_equals_variable.length() > 0)
  289. return if_not_equals_variable.c_str();
  290. return 0;
  291. }
  292. bool DataStruct::GetIfFlagSet() {
  293. return if_flag_set;
  294. }
  295. const char* DataStruct::GetIfFlagSetVariable() {
  296. if (if_flag_set_variable.length() > 0)
  297. return if_flag_set_variable.c_str();
  298. return 0;
  299. }
  300. bool DataStruct::GetIfFlagNotSet() {
  301. return if_flag_not_set;
  302. }
  303. const char* DataStruct::GetIfFlagNotSetVariable() {
  304. if (if_flag_not_set_variable.length() > 0)
  305. return if_flag_not_set_variable.c_str();
  306. return 0;
  307. }
  308. int8 DataStruct::GetDefaultValue() {
  309. return default_value;
  310. }
  311. int8 DataStruct::GetType() {
  312. return type;
  313. }
  314. int8 DataStruct::GetType2() {
  315. return type2;
  316. }
  317. const char* DataStruct::GetName() {
  318. return name.c_str();
  319. }
  320. int8 DataStruct::GetOversized() {
  321. return oversized;
  322. }
  323. int8 DataStruct::GetOversizedByte() {
  324. return oversized_byte;
  325. }
  326. int8 DataStruct::GetMaxArraySize() {
  327. return maxArraySize;
  328. }
  329. int32 DataStruct::GetLength() {
  330. return length;
  331. }
  332. string DataStruct::GetStringName() {
  333. return name;
  334. }
  335. bool DataStruct::AddToStruct() {
  336. return add;
  337. }
  338. void DataStruct::SetAddToStruct(bool val) {
  339. add = val;
  340. }
  341. int8 DataStruct::GetAddType() {
  342. return addType;
  343. }
  344. void DataStruct::SetAddType(int8 new_type) {
  345. addType = new_type;
  346. }
  347. string DataStruct::AppendVariable(string orig, const char* val) {
  348. if (!val)
  349. return orig;
  350. if(orig.length() == 0)
  351. return string(val);
  352. if (orig.find(",") < 0xFFFFFFFF) { //has more than one already
  353. string valstr = string(val);
  354. vector<string>* varnames = SplitString(orig, ',');
  355. if (varnames) {
  356. for (int32 i = 0; i < varnames->size(); i++) {
  357. if (valstr.compare(varnames->at(i)) == 0) {
  358. return orig; //already in the variable, no need to append
  359. }
  360. }
  361. safe_delete(varnames);
  362. }
  363. }
  364. return orig.append(",").append(val);
  365. }
  366. int32 DataStruct::GetDataSizeInBytes() {
  367. int32 ret = 0;
  368. switch (type) {
  369. case DATA_STRUCT_INT8:
  370. ret = length * sizeof(int8);
  371. break;
  372. case DATA_STRUCT_INT16:
  373. ret = length * sizeof(int16);
  374. break;
  375. case DATA_STRUCT_INT32:
  376. ret = length * sizeof(int32);
  377. break;
  378. case DATA_STRUCT_INT64:
  379. ret = length * sizeof(int64);
  380. break;
  381. case DATA_STRUCT_SINT8:
  382. ret = length * sizeof(sint8);
  383. break;
  384. case DATA_STRUCT_SINT16:
  385. ret = length * sizeof(sint16);
  386. break;
  387. case DATA_STRUCT_SINT32:
  388. ret = length * sizeof(sint32);
  389. break;
  390. case DATA_STRUCT_SINT64:
  391. ret = length * sizeof(sint64);
  392. break;
  393. case DATA_STRUCT_FLOAT:
  394. ret = length * sizeof(float);
  395. break;
  396. case DATA_STRUCT_DOUBLE:
  397. ret = length * sizeof(double);
  398. break;
  399. case DATA_STRUCT_ARRAY:
  400. // Array elements won't have a size so get out now to avoid the warning.
  401. break;
  402. default:
  403. LogWrite(PACKET__WARNING, 0, "DataStruct", "Tried retrieving a data size from an unsupported data struct type in GetDataSizeInBytes()");
  404. break;
  405. }
  406. return ret;
  407. }
  408. PacketStruct::PacketStruct(PacketStruct* packet, int16 in_client_version) {
  409. parent = packet->parent;
  410. client_version = in_client_version;
  411. vector<DataStruct*>::iterator itr2;
  412. name = packet->name;
  413. for (itr2 = packet->structs.begin(); itr2 != packet->structs.end(); itr2++) {
  414. add(new DataStruct(*itr2));
  415. }
  416. vector<string>::iterator itr;
  417. for (itr = packet->flags.begin(); itr != packet->flags.end(); itr++) {
  418. AddFlag((*itr).c_str());
  419. }
  420. sub_packet = false;
  421. opcode = packet->opcode;
  422. version = packet->version;
  423. opcode_type = packet->opcode_type;
  424. sub_packet_size = 1;
  425. addPacketArrays(packet);
  426. }
  427. PacketStruct::PacketStruct() {
  428. parent = 0;
  429. opcode = OP_Unknown;
  430. opcode_type = string("");
  431. }
  432. PacketStruct::PacketStruct(PacketStruct* packet, bool sub) {
  433. vector<DataStruct*>::iterator itr2;
  434. for (itr2 = packet->structs.begin(); itr2 != packet->structs.end(); itr2++) {
  435. add(new DataStruct(*itr2));
  436. }
  437. vector<string>::iterator itr;
  438. for (itr = packet->flags.begin(); itr != packet->flags.end(); itr++) {
  439. AddFlag((*itr).c_str());
  440. }
  441. sub_packet = sub;
  442. opcode = packet->opcode;
  443. version = packet->version;
  444. opcode_type = packet->opcode_type;
  445. name = packet->name;
  446. sub_packet_size = 0;
  447. parent = 0;
  448. }
  449. PacketStruct::~PacketStruct() {
  450. deleteDataStructs(&structs);
  451. deleteDataStructs(&orig_structs);
  452. deletePacketArrays(this);
  453. struct_map.clear();
  454. struct_data.clear();
  455. flags.clear();
  456. }
  457. void PacketStruct::deleteDataStructs(vector<DataStruct*>* data_structs) {
  458. if ( !data_structs || data_structs->size() == 0 )
  459. return;
  460. DataStruct* data = 0;
  461. vector<DataStruct*>::iterator itr;
  462. for (itr = data_structs->begin(); itr != data_structs->end(); itr++) {
  463. data = *itr;
  464. void* ptr = GetStructPointer(data);
  465. // stop the struct_data from growing with old data/ptr info, memory leaking and eventual buffer overflow (crash)
  466. map<DataStruct*, void*>::iterator datastr = struct_data.find(data);
  467. if (datastr != struct_data.end())
  468. struct_data.erase(datastr);
  469. switch (data->GetType()) {
  470. case DATA_STRUCT_EQ2_8BIT_STRING: {
  471. EQ2_8BitString* real_ptr = (EQ2_8BitString*)ptr;
  472. safe_delete(real_ptr);
  473. break;
  474. }
  475. case DATA_STRUCT_EQ2_16BIT_STRING: {
  476. EQ2_16BitString* real_ptr = (EQ2_16BitString*)ptr;
  477. safe_delete(real_ptr);
  478. break;
  479. }
  480. case DATA_STRUCT_EQ2_32BIT_STRING: {
  481. EQ2_32BitString* real_ptr = (EQ2_32BitString*)ptr;
  482. safe_delete(real_ptr);
  483. break;
  484. }
  485. case DATA_STRUCT_EQUIPMENT: {
  486. EQ2_EquipmentItem* real_ptr = (EQ2_EquipmentItem*)ptr;
  487. safe_delete_array(real_ptr);
  488. break;
  489. }
  490. case DATA_STRUCT_DOUBLE: {
  491. double* real_ptr = (double*)ptr;
  492. safe_delete_array(real_ptr);
  493. break;
  494. }
  495. case DATA_STRUCT_FLOAT: {
  496. float* real_ptr = (float*)ptr;
  497. safe_delete_array(real_ptr);
  498. break;
  499. }
  500. case DATA_STRUCT_INT8: {
  501. int8* real_ptr = (int8*)ptr;
  502. safe_delete_array(real_ptr);
  503. break;
  504. }
  505. case DATA_STRUCT_INT16: {
  506. int16* real_ptr = (int16*)ptr;
  507. safe_delete_array(real_ptr);
  508. break;
  509. }
  510. case DATA_STRUCT_INT32: {
  511. int32* real_ptr = (int32*)ptr;
  512. safe_delete_array(real_ptr);
  513. break;
  514. }
  515. case DATA_STRUCT_INT64: {
  516. int64* real_ptr = (int64*)ptr;
  517. safe_delete_array(real_ptr);
  518. break;
  519. }
  520. case DATA_STRUCT_SINT8: {
  521. sint8* real_ptr = (sint8*)ptr;
  522. safe_delete_array(real_ptr);
  523. break;
  524. }
  525. case DATA_STRUCT_SINT16: {
  526. sint16* real_ptr = (sint16*)ptr;
  527. safe_delete_array(real_ptr);
  528. break;
  529. }
  530. case DATA_STRUCT_SINT32: {
  531. sint32* real_ptr = (sint32*)ptr;
  532. safe_delete_array(real_ptr);
  533. break;
  534. }
  535. case DATA_STRUCT_SINT64: {
  536. sint64* real_ptr = (sint64*)ptr;
  537. safe_delete_array(real_ptr);
  538. break;
  539. }
  540. case DATA_STRUCT_ITEM: {
  541. uchar* real_ptr = (uchar*)ptr;
  542. safe_delete_array(real_ptr);
  543. break;
  544. }
  545. case DATA_STRUCT_CHAR: {
  546. char* real_ptr = (char*)ptr;
  547. safe_delete_array(real_ptr);
  548. break;
  549. }
  550. case DATA_STRUCT_COLOR: {
  551. EQ2_Color* real_ptr = (EQ2_Color*)ptr;
  552. safe_delete_array(real_ptr);
  553. break;
  554. }
  555. }
  556. ptr = 0;
  557. safe_delete(data);
  558. }
  559. }
  560. void PacketStruct::deletePacketArrays(PacketStruct* packet) {
  561. if (!packet)
  562. return;
  563. vector<PacketStruct*>::iterator itr;
  564. for (itr = packet->arrays.begin(); itr != packet->arrays.end(); itr++)
  565. safe_delete(*itr);
  566. packet->arrays.clear();
  567. for (itr = packet->orig_packets.begin(); itr != packet->orig_packets.end(); itr++)
  568. safe_delete(*itr);
  569. packet->orig_packets.clear();
  570. }
  571. void PacketStruct::renameSubstructArray(const char* substruct, int32 index) {
  572. vector<PacketStruct*>::iterator itr;
  573. char tmp[10] = { 0 };
  574. sprintf(tmp, "%i", index);
  575. for (itr = arrays.begin(); itr != arrays.end(); itr++) {
  576. (*itr)->SetName(string(substruct).append("_").append((*itr)->GetName()).append("_").append(tmp).c_str());
  577. }
  578. }
  579. void PacketStruct::addPacketArrays(PacketStruct* packet) {
  580. if (!packet)
  581. return;
  582. vector<PacketStruct*>::iterator itr;
  583. for (itr = packet->arrays.begin(); itr != packet->arrays.end(); itr++) {
  584. PacketStruct* tmp = new PacketStruct(*itr, true);
  585. tmp->addPacketArrays(*itr);
  586. add(tmp);
  587. }
  588. }
  589. bool PacketStruct::IsStringValueType(string in_name, int32 index) {
  590. DataStruct* data = findStruct(in_name.c_str(), index);
  591. switch (data->GetType()) {
  592. case DATA_STRUCT_CHAR:
  593. case DATA_STRUCT_EQ2_8BIT_STRING:
  594. case DATA_STRUCT_EQ2_16BIT_STRING:
  595. case DATA_STRUCT_EQ2_32BIT_STRING:
  596. return true;
  597. }
  598. return false;
  599. }
  600. bool PacketStruct::IsColorValueType(string in_name, int32 index) {
  601. DataStruct* data = findStruct(in_name.c_str(), index);
  602. if (data->GetType() == DATA_STRUCT_COLOR)
  603. return true;
  604. else
  605. return false;
  606. }
  607. void PacketStruct::setColor(DataStruct* data, int8 red, int8 green, int8 blue, int32 index = 0) {
  608. if (data && data->GetType() == DATA_STRUCT_COLOR) {
  609. EQ2_Color* color = (EQ2_Color*)GetStructPointer(data);
  610. color[index].blue = blue;
  611. color[index].red = red;
  612. color[index].green = green;
  613. if (blue > 0 || green > 0 || red > 0)
  614. data->SetIsSet(true);
  615. }
  616. }
  617. void PacketStruct::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) {
  618. if (data) {
  619. EQ2_EquipmentItem* equipment = (EQ2_EquipmentItem*)GetStructPointer(data);
  620. EQ2_Color* color = (EQ2_Color*)&equipment[index].color;
  621. EQ2_Color* highlight = (EQ2_Color*)&equipment[index].highlight;
  622. equipment[index].type = type;
  623. color->blue = c_blue;
  624. color->red = c_red;
  625. color->green = c_green;
  626. highlight->blue = h_blue;
  627. highlight->red = h_red;
  628. highlight->green = h_green;
  629. if (c_red > 0 || c_blue > 0 || c_green > 0 || h_red > 0 || h_blue > 0 || h_green > 0)
  630. data->SetIsSet(true);
  631. }
  632. }
  633. void PacketStruct::add(PacketStruct* packet_struct) {
  634. packet_struct->parent = this;
  635. arrays.push_back(packet_struct);
  636. }
  637. const char* PacketStruct::GetOpcodeType() {
  638. return opcode_type.c_str();
  639. }
  640. void PacketStruct::SetOpcodeType(const char* in_type) {
  641. if (in_type)
  642. opcode_type = string(in_type);
  643. else
  644. opcode_type = string("");
  645. }
  646. void PacketStruct::setDataType(DataStruct* data_struct, sint8 data, int32 index) {
  647. if (data_struct) {
  648. sint8* ptr = (sint8*)GetStructPointer(data_struct);
  649. ptr[index] = data;
  650. if (data != 0 && data != -1)
  651. data_struct->SetIsSet(true);
  652. }
  653. }
  654. void PacketStruct::setDataType(DataStruct* data_struct, sint16 data, int32 index) {
  655. if (data_struct) {
  656. sint16* ptr = (sint16*)GetStructPointer(data_struct);
  657. ptr[index] = data;
  658. if (data != 0 && data != -1)
  659. data_struct->SetIsSet(true);
  660. }
  661. }
  662. void PacketStruct::setDataType(DataStruct* data_struct, sint32 data, int32 index) {
  663. if (data_struct) {
  664. sint32* ptr = (sint32*)GetStructPointer(data_struct);
  665. ptr[index] = data;
  666. if (data != 0 && data != -1)
  667. data_struct->SetIsSet(true);
  668. }
  669. }
  670. void PacketStruct::setDataType(DataStruct* data_struct, sint64 data, int32 index) {
  671. if (data_struct) {
  672. sint64* ptr = (sint64*)GetStructPointer(data_struct);
  673. ptr[index] = data;
  674. if (data > 0)
  675. data_struct->SetIsSet(true);
  676. }
  677. }
  678. void PacketStruct::setDataType(DataStruct* data_struct, char data, int32 index) {
  679. if (data_struct) {
  680. char* ptr = (char*)GetStructPointer(data_struct);
  681. ptr[index] = data;
  682. if (data > 0)
  683. data_struct->SetIsSet(true);
  684. }
  685. }
  686. void PacketStruct::setDataType(DataStruct* data_struct, int8 data, int32 index) {
  687. if (data_struct) {
  688. int8* ptr = (int8*)GetStructPointer(data_struct);
  689. ptr[index] = data;
  690. if (data > 0)
  691. data_struct->SetIsSet(true);
  692. }
  693. }
  694. void PacketStruct::setDataType(DataStruct* data_struct, int16 data, int32 index) {
  695. if (data_struct) {
  696. int16* ptr = (int16*)GetStructPointer(data_struct);
  697. ptr[index] = data;
  698. if (data > 0)
  699. data_struct->SetIsSet(true);
  700. }
  701. }
  702. void PacketStruct::setDataType(DataStruct* data_struct, int32 data, int32 index) {
  703. if (data_struct) {
  704. int32* ptr = (int32*)GetStructPointer(data_struct);
  705. ptr[index] = data;
  706. if (data > 0)
  707. data_struct->SetIsSet(true);
  708. }
  709. }
  710. void PacketStruct::setDataType(DataStruct* data_struct, int64 data, int32 index) {
  711. if (data_struct) {
  712. int64* ptr = (int64*)GetStructPointer(data_struct);
  713. ptr[index] = data;
  714. if (data > 0)
  715. data_struct->SetIsSet(true);
  716. }
  717. }
  718. void PacketStruct::setDataType(DataStruct* data_struct, float data, int32 index) {
  719. if (data_struct) {
  720. float* ptr = (float*)GetStructPointer(data_struct);
  721. ptr[index] = data;
  722. if (data > 0)
  723. data_struct->SetIsSet(true);
  724. }
  725. }
  726. void PacketStruct::setDataType(DataStruct* data_struct, double data, int32 index) {
  727. if (data_struct) {
  728. double* ptr = (double*)GetStructPointer(data_struct);
  729. ptr[index] = data;
  730. if (data > 0)
  731. data_struct->SetIsSet(true);
  732. }
  733. }
  734. void PacketStruct::setData(DataStruct* data_struct, EQ2_8BitString* input_string, int32 index, bool use_second_type) {
  735. if (data_struct) {
  736. EQ2_8BitString* tmp = (EQ2_8BitString*)GetStructPointer(data_struct);
  737. tmp->data = input_string->data;
  738. tmp->size = input_string->data.length();
  739. if (input_string->data.length() > 0)
  740. data_struct->SetIsSet(true);
  741. }
  742. }
  743. void PacketStruct::setData(DataStruct* data_struct, EQ2_16BitString* input_string, int32 index, bool use_second_type) {
  744. if (data_struct) {
  745. EQ2_16BitString* tmp = (EQ2_16BitString*)GetStructPointer(data_struct);
  746. tmp->data = input_string->data;
  747. tmp->size = input_string->data.length();
  748. if (input_string->data.length() > 0)
  749. data_struct->SetIsSet(true);
  750. }
  751. }
  752. void PacketStruct::setData(DataStruct* data_struct, EQ2_32BitString* input_string, int32 index, bool use_second_type) {
  753. if (data_struct) {
  754. EQ2_32BitString* tmp = (EQ2_32BitString*)GetStructPointer(data_struct);
  755. tmp->data = input_string->data;
  756. tmp->size = input_string->data.length();
  757. if (input_string->data.length() > 0)
  758. data_struct->SetIsSet(true);
  759. }
  760. }
  761. void PacketStruct::add(DataStruct* data) {
  762. structs.push_back(data);
  763. struct_map[data->GetStringName()] = data;
  764. switch (data->GetType()) {
  765. case DATA_STRUCT_INT8: {
  766. struct_data[data] = new int8[data->GetLength()];
  767. int8* ptr = (int8*)GetStructPointer(data);
  768. if (data->GetLength() > 1) {
  769. int8 default_val = data->GetDefaultValue();
  770. memset(ptr, default_val, data->GetLength() * sizeof(int8));
  771. }
  772. else
  773. ptr[0] = 0;
  774. break;
  775. }
  776. case DATA_STRUCT_INT16: {
  777. struct_data[data] = new int16[data->GetLength()];
  778. int16* ptr = (int16*)GetStructPointer(data);
  779. if (data->GetLength() > 1) {
  780. int8 default_val = data->GetDefaultValue();
  781. memset(ptr, default_val, data->GetLength() * sizeof(int16));
  782. }
  783. else
  784. ptr[0] = 0;
  785. break;
  786. }
  787. case DATA_STRUCT_INT32: {
  788. struct_data[data] = new int32[data->GetLength()];
  789. int32* ptr = (int32*)GetStructPointer(data);
  790. if (data->GetLength() > 1) {
  791. int8 default_val = data->GetDefaultValue();
  792. memset(ptr, default_val, data->GetLength() * sizeof(int32));
  793. }
  794. else
  795. ptr[0] = 0;
  796. break;
  797. }
  798. case DATA_STRUCT_INT64: {
  799. struct_data[data] = new int64[data->GetLength()];
  800. int64* ptr = (int64*)GetStructPointer(data);
  801. if (data->GetLength() > 1) {
  802. int8 default_val = data->GetDefaultValue();
  803. memset(ptr, default_val, data->GetLength() * sizeof(int64));
  804. }
  805. else
  806. ptr[0] = 0;
  807. break;
  808. }
  809. case DATA_STRUCT_SINT8: {
  810. struct_data[data] = new sint8[data->GetLength()];
  811. sint8* ptr = (sint8*)GetStructPointer(data);
  812. if (data->GetLength() > 1)
  813. memset(ptr, 0, data->GetLength() * sizeof(sint8));
  814. else
  815. ptr[0] = 0;
  816. break;
  817. }
  818. case DATA_STRUCT_SINT16: {
  819. struct_data[data] = new sint16[data->GetLength()];
  820. sint16* ptr = (sint16*)GetStructPointer(data);
  821. if (data->GetLength() > 1)
  822. memset(ptr, 0, data->GetLength() * sizeof(sint16));
  823. else
  824. ptr[0] = 0;
  825. break;
  826. }
  827. case DATA_STRUCT_SINT32: {
  828. struct_data[data] = new sint32[data->GetLength()];
  829. sint32* ptr = (sint32*)GetStructPointer(data);
  830. if (data->GetLength() > 1)
  831. memset(ptr, 0, data->GetLength() * sizeof(sint32));
  832. else
  833. ptr[0] = 0;
  834. break;
  835. }
  836. case DATA_STRUCT_SINT64: {
  837. struct_data[data] = new sint64[data->GetLength()];
  838. sint64* ptr = (sint64*)GetStructPointer(data);
  839. if (data->GetLength() > 1)
  840. memset(ptr, 0, data->GetLength() * sizeof(sint64));
  841. else
  842. ptr[0] = 0;
  843. break;
  844. }
  845. case DATA_STRUCT_CHAR: {
  846. struct_data[data] = new char[data->GetLength()];
  847. char* ptr = (char*)GetStructPointer(data);
  848. if (data->GetLength() > 1)
  849. memset(ptr, 0, data->GetLength() * sizeof(char));
  850. else
  851. ptr[0] = 0;
  852. break;
  853. }
  854. case DATA_STRUCT_FLOAT: {
  855. struct_data[data] = new float[data->GetLength()];
  856. float* ptr = (float*)GetStructPointer(data);
  857. if (data->GetLength() > 1)
  858. memset(ptr, 0, data->GetLength() * sizeof(float));
  859. else
  860. ptr[0] = 0;
  861. break;
  862. }
  863. case DATA_STRUCT_DOUBLE: {
  864. struct_data[data] = new double[data->GetLength()];
  865. double* ptr = (double*)GetStructPointer(data);
  866. if (data->GetLength() > 1)
  867. memset(ptr, 0, data->GetLength() * sizeof(double));
  868. else
  869. ptr[0] = 0;
  870. break;
  871. }
  872. case DATA_STRUCT_ARRAY: {
  873. data->SetLength(0);
  874. break;
  875. }
  876. case DATA_STRUCT_EQ2_8BIT_STRING: {
  877. string name2 = data->GetStringName();
  878. for (int32 i = 1; i < data->GetLength(); i++) {
  879. DataStruct* new_data = new DataStruct(data);
  880. char blah[10] = { 0 };
  881. sprintf(blah, "%i", i);
  882. name2.append("_").append(blah);
  883. new_data->SetName(name2.c_str());
  884. new_data->SetLength(1);
  885. EQ2_8BitString* tmp = new EQ2_8BitString;
  886. tmp->size = 0;
  887. struct_data[new_data] = tmp;
  888. structs.push_back(new_data);
  889. }
  890. data->SetLength(1);
  891. EQ2_8BitString* tmp = new EQ2_8BitString;
  892. tmp->size = 0;
  893. struct_data[data] = tmp;
  894. break;
  895. }
  896. case DATA_STRUCT_EQ2_16BIT_STRING: {
  897. string name2 = data->GetStringName();
  898. for (int32 i = 1; i < data->GetLength(); i++) {
  899. DataStruct* new_data = new DataStruct(data);
  900. char blah[10] = { 0 };
  901. sprintf(blah, "%i", i);
  902. name2.append("_").append(blah);
  903. new_data->SetName(name2.c_str());
  904. new_data->SetLength(1);
  905. EQ2_16BitString* tmp = new EQ2_16BitString;
  906. tmp->size = 0;
  907. struct_data[new_data] = tmp;
  908. structs.push_back(new_data);
  909. }
  910. data->SetLength(1);
  911. EQ2_16BitString* tmp = new EQ2_16BitString;
  912. tmp->size = 0;
  913. struct_data[data] = tmp;
  914. break;
  915. }
  916. case DATA_STRUCT_EQ2_32BIT_STRING: {
  917. string name2 = data->GetStringName();
  918. for (int32 i = 1; i < data->GetLength(); i++) {
  919. DataStruct* new_data = new DataStruct(data);
  920. char blah[10] = { 0 };
  921. sprintf(blah, "%i", i);
  922. name2.append("_").append(blah);
  923. new_data->SetName(name2.c_str());
  924. new_data->SetLength(1);
  925. EQ2_32BitString* tmp = new EQ2_32BitString;
  926. tmp->size = 0;
  927. struct_data[new_data] = tmp;
  928. structs.push_back(new_data);
  929. }
  930. data->SetLength(1);
  931. EQ2_32BitString* tmp = new EQ2_32BitString;
  932. tmp->size = 0;
  933. struct_data[data] = tmp;
  934. break;
  935. }
  936. case DATA_STRUCT_COLOR: {
  937. struct_data[data] = new EQ2_Color[data->GetLength()];
  938. EQ2_Color* ptr = (EQ2_Color*)GetStructPointer(data);
  939. for (int16 i = 0; i < data->GetLength(); i++) {
  940. ptr[i].red = 0;
  941. ptr[i].blue = 0;
  942. ptr[i].green = 0;
  943. }
  944. break;
  945. }
  946. case DATA_STRUCT_EQUIPMENT: {
  947. struct_data[data] = new EQ2_EquipmentItem[data->GetLength()];
  948. EQ2_EquipmentItem* ptr = (EQ2_EquipmentItem*)GetStructPointer(data);
  949. for (int16 i = 0; i < data->GetLength(); i++) {
  950. memset(&ptr[i].color, 0, sizeof(ptr[i].color));
  951. memset(&ptr[i].highlight, 0, sizeof(ptr[i].highlight));
  952. ptr[i].type = 0;
  953. }
  954. break;
  955. }
  956. case DATA_STRUCT_ITEM: {
  957. struct_data[data] = new uchar[10000];
  958. char* ptr = (char*)GetStructPointer(data);
  959. memset(ptr, 0, 10000);
  960. break;
  961. }
  962. }
  963. }
  964. void PacketStruct::remove(DataStruct* data) {
  965. vector<DataStruct*>::iterator itr;
  966. for (itr = structs.begin(); itr != structs.end(); itr++) {
  967. if (data == (*itr)) {
  968. structs.erase(itr);
  969. safe_delete(data);
  970. return;
  971. }
  972. }
  973. }
  974. DataStruct* PacketStruct::findStruct(const char* name, int32 index) {
  975. return findStruct(name, index, index);
  976. }
  977. DataStruct* PacketStruct::findStruct(const char* name, int32 index1, int32 index2) {
  978. DataStruct* data = 0;
  979. if (struct_map.count(string(name)) > 0) {
  980. data = struct_map[string(name)];
  981. if (data && index2 < data->GetLength())
  982. return data;
  983. }
  984. vector<DataStruct*>::iterator itr;
  985. PacketStruct* packet = 0;
  986. vector<PacketStruct*>::iterator itr2;
  987. string name2 = string(name);
  988. if (index1 < 0xFFFF) {
  989. char blah[10] = { 0 };
  990. sprintf(blah, "_%i", index1);
  991. name2.append(blah);
  992. }
  993. if (struct_map.count(name2) > 0) {
  994. data = struct_map[name2];
  995. if (data && index2 < data->GetLength())
  996. return data;
  997. }
  998. for (itr2 = arrays.begin(); itr2 != arrays.end(); itr2++) {
  999. packet = *itr2;
  1000. data = packet->findStruct(name, index1, index2);
  1001. if (data != 0)
  1002. return data;
  1003. }
  1004. return 0;
  1005. }
  1006. void PacketStruct::remove(const char* name) {
  1007. DataStruct* data = 0;
  1008. vector<DataStruct*>::iterator itr;
  1009. for (itr = structs.begin(); itr != structs.end(); itr++) {
  1010. data = *itr;
  1011. if (strcmp(name, data->GetName()) == 0) {
  1012. structs.erase(itr);
  1013. safe_delete(data);
  1014. return;
  1015. }
  1016. }
  1017. }
  1018. string* PacketStruct::serializeString() {
  1019. serializePacket();
  1020. return getDataString();
  1021. }
  1022. void PacketStruct::setSmallString(DataStruct* data_struct, const char* text, int32 index) {
  1023. EQ2_8BitString* string_data = new EQ2_8BitString;
  1024. string_data->data = string(text);
  1025. string_data->size = string_data->data.length();
  1026. setData(data_struct, string_data, index);
  1027. safe_delete(string_data);
  1028. }
  1029. void PacketStruct::setMediumString(DataStruct* data_struct, const char* text, int32 index) {
  1030. EQ2_16BitString* string_data = new EQ2_16BitString;
  1031. string_data->data = string(text);
  1032. string_data->size = string_data->data.length();
  1033. setData(data_struct, string_data, index);
  1034. safe_delete(string_data);
  1035. }
  1036. void PacketStruct::setLargeString(DataStruct* data_struct, const char* text, int32 index) {
  1037. EQ2_32BitString* string_data = new EQ2_32BitString;
  1038. string_data->data = string(text);
  1039. string_data->size = string_data->data.length();
  1040. setData(data_struct, string_data, index);
  1041. safe_delete(string_data);
  1042. }
  1043. void PacketStruct::setSmallStringByName(const char* name, const char* text, int32 index) {
  1044. setSmallString(findStruct(name, index), text, index);
  1045. }
  1046. void PacketStruct::setMediumStringByName(const char* name, const char* text, int32 index) {
  1047. setMediumString(findStruct(name, index), text, index);
  1048. }
  1049. void PacketStruct::setLargeStringByName(const char* name, const char* text, int32 index) {
  1050. setLargeString(findStruct(name, index), text, index);
  1051. }
  1052. bool PacketStruct::GetVariableIsSet(const char* name) {
  1053. DataStruct* ds2 = findStruct(name, 0);
  1054. if (!ds2 || !ds2->IsSet())
  1055. return false;
  1056. return true;
  1057. }
  1058. bool PacketStruct::GetVariableIsNotSet(const char* name) {
  1059. DataStruct* ds2 = findStruct(name, 0);
  1060. if (ds2 && ds2->IsSet())
  1061. return false;
  1062. return true;
  1063. }
  1064. bool PacketStruct::CheckFlagExists(const char* name) {
  1065. vector<string>::iterator itr;
  1066. for (itr = flags.begin(); itr != flags.end(); itr++) {
  1067. if (*itr == string(name))
  1068. return true;
  1069. }
  1070. return false;
  1071. }
  1072. void PacketStruct::AddFlag(const char* name) {
  1073. if (flags.size() > 0) {
  1074. vector<string>::iterator itr;
  1075. for (itr = flags.begin(); itr != flags.end(); itr++) {
  1076. if (*itr == string(name))
  1077. return;
  1078. }
  1079. }
  1080. flags.push_back(string(name));
  1081. }
  1082. bool PacketStruct::LoadPacketData(uchar* data, int32 data_len) {
  1083. loadedSuccessfully = true;
  1084. DataStruct* data_struct = 0;
  1085. try {
  1086. InitializeLoadData(data, data_len);
  1087. vector<DataStruct*>::iterator itr;
  1088. for (itr = structs.begin(); itr != structs.end(); itr++) {
  1089. data_struct = *itr;
  1090. if (!data_struct->AddToStruct())
  1091. continue;
  1092. if (data_struct->GetIfSet() && data_struct->GetIfSetVariable()) {
  1093. string varname = string(data_struct->GetIfSetVariable());
  1094. if (varname.find(",") < 0xFFFFFFFF) {
  1095. vector<string>* varnames = SplitString(varname, ',');
  1096. if (varnames) {
  1097. bool should_continue = true;
  1098. for (int32 i = 0; i < varnames->size(); i++) {
  1099. if (GetVariableIsSet(varnames->at(i).c_str())) {
  1100. should_continue = false;
  1101. break;
  1102. }
  1103. }
  1104. safe_delete(varnames);
  1105. if (should_continue)
  1106. continue;
  1107. }
  1108. }
  1109. else {
  1110. // Check to see if the variable contains %i, if it does assume we are in an array
  1111. // and get the current index from the end of the data struct's name
  1112. char name[250] = { 0 };
  1113. if (varname.find("%i") < 0xFFFFFFFF) {
  1114. vector<string>* varnames = SplitString(data_struct->GetName(), '_');
  1115. int index = atoi(varnames->at(varnames->size() - 1).c_str());
  1116. sprintf(name, varname.c_str(), index);
  1117. }
  1118. else
  1119. strcpy(name, varname.c_str());
  1120. if (!GetVariableIsSet(name))
  1121. continue;
  1122. }
  1123. }
  1124. if (data_struct->GetIfNotSet() && data_struct->GetIfNotSetVariable()) {
  1125. string varname = string(data_struct->GetIfNotSetVariable());
  1126. if (varname.find(",") < 0xFFFFFFFF) {
  1127. vector<string>* varnames = SplitString(varname, ',');
  1128. if (varnames) {
  1129. bool should_continue = false;
  1130. for (int32 i = 0; i < varnames->size(); i++) {
  1131. if (!GetVariableIsNotSet(varnames->at(i).c_str())) {
  1132. should_continue = true;
  1133. break;
  1134. }
  1135. }
  1136. safe_delete(varnames);
  1137. if (should_continue)
  1138. continue;
  1139. }
  1140. }
  1141. else {
  1142. // Check to see if the variable contains %i, if it does assume we are in an array
  1143. // and get the current index from the end of the data struct's name
  1144. char name[250] = { 0 };
  1145. if (varname.find("%i") < 0xFFFFFFFF) {
  1146. vector<string>* varnames = SplitString(data_struct->GetName(), '_');
  1147. int index = atoi(varnames->at(varnames->size() - 1).c_str());
  1148. sprintf(name, varname.c_str(), index);
  1149. }
  1150. else
  1151. strcpy(name, varname.c_str());
  1152. if (!GetVariableIsNotSet(name))
  1153. continue;
  1154. }
  1155. }
  1156. // Quick implementaion of IfVariableNotEquals
  1157. // probably not what it was intended for as it currently just checks to see if the given variable equals 1
  1158. // should probably change it so you can define what the variable should or shouldn't equal
  1159. //
  1160. // ie: IfVariableNotEquals="stat_type_%i=1"
  1161. // would be a check to make sure that stat_type_%i does not equal 1 and if it does exclude this element
  1162. if (data_struct->GetIfNotEquals() && data_struct->GetIfNotEqualsVariable()) {
  1163. // Get the variable name
  1164. string varname = string(data_struct->GetIfNotEqualsVariable());
  1165. char name[250] = { 0 };
  1166. // Check to see if the variable has %i in the name, if it does assume we are in an array and get the current
  1167. // index and replace it
  1168. if (varname.find("%i") < 0xFFFFFFFF) {
  1169. // Get the current index by getting the number at the end of the name
  1170. vector<string>* varnames = SplitString(data_struct->GetName(), '_');
  1171. int index = atoi(varnames->at(varnames->size() - 1).c_str());
  1172. string substr = "stat_type";
  1173. if (strncmp(varname.c_str(), substr.c_str(), strlen(substr.c_str())) == 0) {
  1174. // adorn_stat_subtype 18 chars
  1175. string temp = varname.substr(12);
  1176. char temp2[20] = { 0 };
  1177. int index2 = atoi(temp.c_str());
  1178. itoa(index2, temp2, 10);
  1179. varname = varname.substr(0, 12).append(temp2).append("_%i");
  1180. }
  1181. sprintf(name, varname.c_str(), index);
  1182. safe_delete(varnames);
  1183. }
  1184. else
  1185. strcpy(name, varname.c_str());
  1186. // Get the data for the variable
  1187. int16 value = 0;
  1188. DataStruct* data_struct2 = findStruct(name, 0);
  1189. value = getType_int16(data_struct2);
  1190. // Hack for items as it is the only struct that currently uses IfVariableNotEquals
  1191. if (value == 1)
  1192. continue;
  1193. }
  1194. // copy and paste of the code above for IfEquals
  1195. if (data_struct->GetIfEquals() && data_struct->GetIfEqualsVariable()) {
  1196. // Get the variable name
  1197. string varname = string(data_struct->GetIfEqualsVariable());
  1198. char name[250] = { 0 };
  1199. // Check to see if the variable has %i in the name, if it does assume we are in an array and get the current
  1200. // index and replace it
  1201. if (varname.find("%i") < 0xFFFFFFFF) {
  1202. // Get the current index by getting the number at the end of the name
  1203. vector<string>* varnames = SplitString(data_struct->GetName(), '_');
  1204. int index = atoi(varnames->at(varnames->size() - 1).c_str());
  1205. string substr = "stat_type";
  1206. if (strncmp(varname.c_str(), substr.c_str(), strlen(substr.c_str())) == 0) {
  1207. // adorn_stat_subtype 18 chars
  1208. string temp = varname.substr(12);
  1209. char temp2[20] = { 0 };
  1210. int index2 = atoi(temp.c_str());
  1211. itoa(index2, temp2, 10);
  1212. varname = varname.substr(0, 12).append(temp2).append("_%i");
  1213. }
  1214. sprintf(name, varname.c_str(), index);
  1215. safe_delete(varnames);
  1216. }
  1217. else
  1218. strcpy(name, varname.c_str());
  1219. // Get the data for the variable
  1220. int16 value = 0;
  1221. DataStruct* data_struct2 = findStruct(name, 0);
  1222. value = getType_int16(data_struct2);
  1223. // Hack for items as it is the only struct that currently uses IfVariableNotEquals
  1224. if (value != 1)
  1225. continue;
  1226. }
  1227. // The following is tailored to items as they are the only structs that use type2
  1228. // if more type2's are needed outside of the item stats array we need to think up an element
  1229. // to determine when to use type2 over type.
  1230. // Added checks for set stats and adorn stats - Zcoretri
  1231. bool useType2 = false;
  1232. if (data_struct->GetType2() > 0) {
  1233. int16 type = 0;
  1234. char name[250] = { 0 };
  1235. vector<string>* varnames = SplitString(data_struct->GetName(), '_');
  1236. string struct_name = data_struct->GetName();
  1237. if (struct_name.find("set") < 0xFFFFFFFF) {
  1238. string tmp = "set_stat_type";
  1239. struct_name.replace(0, 9, tmp);
  1240. sprintf(name, "%s", struct_name.c_str());
  1241. }
  1242. else if (struct_name.find("adorn") < 0xFFFFFFFF) {
  1243. string tmp = "adorn_stat_type";
  1244. struct_name.replace(0, 9, tmp);
  1245. sprintf(name, "%s", struct_name.c_str());
  1246. }
  1247. else {
  1248. // set name to stat_type_# (where # is the current index of the array we are in)
  1249. sprintf(name, "%s_%s", "stat_type", varnames->at(varnames->size() - 1).c_str());
  1250. }
  1251. // Look up the value for stat_type
  1252. DataStruct* data_struct2 = findStruct(name, 0);
  1253. type = getType_int16(data_struct2);
  1254. // If stat_type == 6 we use a float, else we use sint16
  1255. if (type != 6)
  1256. useType2 = true;
  1257. safe_delete(varnames);
  1258. }
  1259. if (!StructLoadData(data_struct, GetStructPointer(data_struct), data_struct->GetLength(), useType2))
  1260. {
  1261. loadedSuccessfully = false;
  1262. break;
  1263. }
  1264. }
  1265. }
  1266. catch (...) {
  1267. loadedSuccessfully = false;
  1268. }
  1269. return loadedSuccessfully;
  1270. }
  1271. bool PacketStruct::StructLoadData(DataStruct* data_struct, void* data, int32 len, bool useType2) {
  1272. int8 type = 0;
  1273. if (useType2) {
  1274. type = data_struct->GetType2();
  1275. // Need to change the data the struct expects to type2
  1276. data_struct->SetType(type);
  1277. LogWrite(PACKET__DEBUG, 7, "Items", "Using type2 = %i", type);
  1278. }
  1279. else
  1280. type = data_struct->GetType();
  1281. switch (type) {
  1282. case DATA_STRUCT_INT8:
  1283. LoadData((int8*)data, len);
  1284. data_struct->SetIsSet(*((int8*)data) > 0);
  1285. break;
  1286. case DATA_STRUCT_INT16:
  1287. if (data_struct->GetOversized() > 0) {
  1288. LoadData((int8*)data, len);
  1289. if (getType_int16(data_struct) == data_struct->GetOversizedByte()) {
  1290. LoadData((int16*)data, len);
  1291. }
  1292. }
  1293. else {
  1294. LoadData((int16*)data, len);
  1295. }
  1296. data_struct->SetIsSet(*((int16*)data) > 0);
  1297. break;
  1298. case DATA_STRUCT_INT32:
  1299. if (data_struct->GetOversized() > 0) {
  1300. LoadData((int8*)data, len);
  1301. if (getType_int32(data_struct) == data_struct->GetOversizedByte()) {
  1302. LoadData((int32*)data, len);
  1303. }
  1304. else
  1305. LoadData((int8*)data, len);
  1306. }
  1307. else {
  1308. LoadData((int32*)data, len);
  1309. }
  1310. data_struct->SetIsSet(*((int32*)data) > 0);
  1311. break;
  1312. case DATA_STRUCT_INT64:
  1313. LoadData((int64*)data, len);
  1314. data_struct->SetIsSet(*((int64*)data) > 0);
  1315. break;
  1316. case DATA_STRUCT_SINT8:
  1317. LoadData((sint8*)data, len);
  1318. data_struct->SetIsSet(*((sint8*)data) > 0);
  1319. break;
  1320. case DATA_STRUCT_SINT16:
  1321. if (data_struct->GetOversized() > 0) {
  1322. LoadData((sint8*)data, len);
  1323. sint8 val = (sint8)getType_sint16(data_struct);
  1324. if (val < 0) //necessary because when using memcpy from a smaller data type to a larger one, the sign is lost
  1325. setData(data_struct, val, 0);
  1326. if (getType_sint16(data_struct) == data_struct->GetOversizedByte())
  1327. LoadData((sint16*)data, len);
  1328. }
  1329. else
  1330. LoadData((sint16*)data, len);
  1331. data_struct->SetIsSet(*((sint16*)data) > 0);
  1332. break;
  1333. case DATA_STRUCT_SINT32:
  1334. LoadData((sint32*)data, len);
  1335. data_struct->SetIsSet(*((sint32*)data) > 0);
  1336. break;
  1337. case DATA_STRUCT_SINT64:
  1338. LoadData((sint64*)data, len);
  1339. data_struct->SetIsSet(*((sint64*)data) > 0);
  1340. break;
  1341. case DATA_STRUCT_CHAR:
  1342. LoadData((char*)data, len);
  1343. data_struct->SetIsSet(data > 0);
  1344. break;
  1345. case DATA_STRUCT_FLOAT:
  1346. LoadData((float*)data, len);
  1347. data_struct->SetIsSet(*((float*)data) > 0);
  1348. break;
  1349. case DATA_STRUCT_DOUBLE:
  1350. LoadData((double*)data, len);
  1351. data_struct->SetIsSet(*((double*)data) > 0);
  1352. break;
  1353. case DATA_STRUCT_EQ2_8BIT_STRING: {
  1354. LoadDataString((EQ2_8BitString*)data);
  1355. data_struct->SetIsSet(((EQ2_8BitString*)data)->data.length() > 0);
  1356. break;
  1357. }
  1358. case DATA_STRUCT_EQ2_16BIT_STRING: {
  1359. LoadDataString((EQ2_16BitString*)data);
  1360. data_struct->SetIsSet(((EQ2_16BitString*)data)->data.length() > 0);
  1361. break;
  1362. }
  1363. case DATA_STRUCT_EQ2_32BIT_STRING: {
  1364. LoadDataString((EQ2_32BitString*)data);
  1365. data_struct->SetIsSet(((EQ2_32BitString*)data)->data.length() > 0);
  1366. break;
  1367. }
  1368. case DATA_STRUCT_COLOR: {
  1369. if (strcmp(GetName(), "CreateCharacter") == 0 || strcmp(GetName(), "WS_SubmitCharCust") == 0)
  1370. CreateEQ2Color((EQ2_Color*)data);
  1371. else
  1372. LoadData((EQ2_Color*)data, len);
  1373. break;
  1374. }
  1375. case DATA_STRUCT_EQUIPMENT: {
  1376. LoadData((EQ2_EquipmentItem*)data);
  1377. break;
  1378. }
  1379. case DATA_STRUCT_ARRAY: {
  1380. int32 size = GetArraySize(data_struct, 0);
  1381. if (size > 0xFFFF) {
  1382. LogWrite(PACKET__WARNING, 1, "Packet", "Possible corrupt packet while loading struct array, orig array size: %u in struct name %s, data name %s", size, GetName(), (data_struct && data_struct->GetName()) ? data_struct->GetName() : "??");
  1383. return false;
  1384. }
  1385. PacketStruct* ps = GetPacketStructByName(data_struct->GetName());
  1386. if (ps && ps->GetSubPacketSize() != size) {
  1387. if (data_struct->GetMaxArraySize() > 0 && size > data_struct->GetMaxArraySize())
  1388. size = data_struct->GetMaxArraySize();
  1389. ps->reAddAll(size);
  1390. }
  1391. if (ps && size > 0) {
  1392. //for(int i=0;i<size && (GetLoadLen()-GetLoadPos()) > 0;i++){
  1393. ps->LoadPacketData(GetLoadBuffer() + GetLoadPos(), GetLoadLen() - GetLoadPos());
  1394. SetLoadPos(GetLoadPos() + ps->GetLoadPos());
  1395. //}
  1396. }
  1397. break;
  1398. }
  1399. default: {
  1400. data_struct->SetIsSet(false);
  1401. }
  1402. }
  1403. return true;
  1404. }
  1405. PacketStruct* PacketStruct::GetPacketStructByName(const char* name) {
  1406. PacketStruct* ps = 0;
  1407. vector<PacketStruct*>::iterator itr;
  1408. for (itr = arrays.begin(); itr != arrays.end(); itr++) {
  1409. ps = *itr;
  1410. if (strcmp(ps->GetName(), name) == 0)
  1411. return ps;
  1412. ps = ps->GetPacketStructByName(name);
  1413. if (ps)
  1414. return ps;
  1415. }
  1416. return 0;
  1417. }
  1418. void PacketStruct::reAddAll(int32 length) {
  1419. vector<DataStruct*>::iterator itr;
  1420. DataStruct* ds = 0;
  1421. PacketStruct* ps = 0;
  1422. vector<PacketStruct*>::iterator packet_itr;
  1423. if (orig_structs.size() == 0)
  1424. orig_structs = structs;
  1425. else
  1426. deleteDataStructs(&structs);
  1427. structs.clear();
  1428. if (orig_packets.size() == 0 && arrays.size() > 0)
  1429. orig_packets = arrays;
  1430. else {
  1431. for (packet_itr = arrays.begin(); packet_itr != arrays.end(); packet_itr++) {
  1432. ps = *packet_itr;
  1433. safe_delete(ps);
  1434. }
  1435. }
  1436. arrays.clear();
  1437. for (int16 i = 0; i < length; i++) {
  1438. for (packet_itr = orig_packets.begin(); packet_itr != orig_packets.end(); packet_itr++) {
  1439. ps = *packet_itr;
  1440. PacketStruct* new_packet = new PacketStruct(ps, true);
  1441. char tmp[20] = { 0 };
  1442. sprintf(tmp, "_%i", i);
  1443. string name = string(new_packet->GetName());
  1444. name.append(tmp);
  1445. new_packet->SetName(name.c_str());
  1446. add(new_packet);
  1447. }
  1448. for (itr = orig_structs.begin(); itr != orig_structs.end(); itr++) {
  1449. ds = *itr;
  1450. DataStruct* new_data = new DataStruct(ds);
  1451. char tmp[20] = { 0 };
  1452. sprintf(tmp, "_%i", i);
  1453. string name = new_data->GetStringName();
  1454. if (IsSubPacket() && parent->IsSubPacket()) {
  1455. string parent_name = string(GetName());
  1456. try {
  1457. if (parent_name.rfind("_") < 0xFFFFFFFF)
  1458. sprintf(tmp, "%i_%i", atoi(parent_name.substr(parent_name.rfind("_") + 1).c_str()), i);
  1459. }
  1460. catch (...) {
  1461. sprintf(tmp, "_%i", i);
  1462. }
  1463. }
  1464. name.append(tmp);
  1465. new_data->SetName(name.c_str());
  1466. if (new_data->GetType() == DATA_STRUCT_ARRAY) {
  1467. string old_size_arr = string(new_data->GetArraySizeVariable());
  1468. new_data->SetArraySizeVariable(old_size_arr.append(tmp).c_str());
  1469. }
  1470. add(new_data);
  1471. }
  1472. }
  1473. sub_packet_size = length;
  1474. }
  1475. int32 PacketStruct::GetArraySize(DataStruct* data_struct, int32 index) {
  1476. if (data_struct) {
  1477. const char* name = data_struct->GetArraySizeVariable();
  1478. return GetArraySize(name, index);
  1479. }
  1480. return 0;
  1481. }
  1482. int32 PacketStruct::GetArraySize(const char* name, int32 index) {
  1483. int32 ret = 0;
  1484. DataStruct* ds = findStruct(name, index);
  1485. if (ds) {
  1486. if (ds->GetType() == DATA_STRUCT_INT8) {
  1487. int8* tmp = (int8*)GetStructPointer(ds);
  1488. ret = *tmp;
  1489. }
  1490. else if (ds->GetType() == DATA_STRUCT_INT16) {
  1491. int16* tmp = (int16*)GetStructPointer(ds);
  1492. ret = *tmp;
  1493. }
  1494. else if (ds->GetType() == DATA_STRUCT_INT32) {
  1495. int32* tmp = (int32*)GetStructPointer(ds);
  1496. ret = *tmp;
  1497. }
  1498. else if (ds->GetType() == DATA_STRUCT_INT64) {
  1499. int64* tmp = (int64*)GetStructPointer(ds);
  1500. ret = *tmp;
  1501. }
  1502. }
  1503. return ret;
  1504. }
  1505. void PacketStruct::UpdateArrayByArrayLength(DataStruct* data_struct, int32 index, int32 size) {
  1506. if (data_struct) {
  1507. PacketStruct* packet = 0;
  1508. DataStruct* data = 0;
  1509. vector<DataStruct*>::iterator itr;
  1510. for (itr = structs.begin(); itr != structs.end(); itr++) {
  1511. data = *itr;
  1512. if (strcmp(data->GetArraySizeVariable(), data_struct->GetName()) == 0) {
  1513. packet = GetPacketStructByName(data->GetName());
  1514. if (packet)
  1515. packet->reAddAll(size);
  1516. return;
  1517. }
  1518. }
  1519. vector<PacketStruct*>::iterator itr2;
  1520. for (itr2 = arrays.begin(); itr2 != arrays.end(); itr2++) {
  1521. packet = *itr2;
  1522. packet->UpdateArrayByArrayLength(data_struct, index, size);
  1523. }
  1524. }
  1525. }
  1526. void PacketStruct::UpdateArrayByArrayLengthName(const char* name, int32 index, int32 size) {
  1527. UpdateArrayByArrayLength(findStruct(name, index), index, size);
  1528. }
  1529. int32 PacketStruct::GetArraySizeByName(const char* name, int32 index) {
  1530. DataStruct* ds1 = findStruct(name, index);
  1531. return GetArraySize(ds1, index);
  1532. }
  1533. int16 PacketStruct::GetOpcodeValue(int16 client_version) {
  1534. int16 opcode = 0xFFFF;
  1535. bool client_cmd = false;
  1536. int16 OpcodeVersion = 0;
  1537. #ifndef LOGIN
  1538. if (GetOpcode() == OP_ClientCmdMsg && strlen(GetOpcodeType()) > 0 && !IsSubPacket())
  1539. client_cmd = true;
  1540. #endif
  1541. if (client_cmd) {
  1542. EmuOpcode sub_opcode = EQOpcodeManager[0]->NameSearch(GetOpcodeType());
  1543. if (sub_opcode != OP_Unknown) { //numbers should be used at OpcodeTypes, define them!
  1544. OpcodeVersion = GetOpcodeVersion(client_version);
  1545. if (EQOpcodeManager.count(OpcodeVersion) > 0) {
  1546. opcode = EQOpcodeManager[OpcodeVersion]->EmuToEQ(sub_opcode);
  1547. if (opcode == 0xCDCD) {
  1548. LogWrite(PACKET__ERROR, 0, "Packet", "Could not find valid opcode for opcode: %s and client_version: %i", EQOpcodeManager[OpcodeVersion]->EmuToName(sub_opcode), client_version);
  1549. }
  1550. }
  1551. }
  1552. }
  1553. else {
  1554. OpcodeVersion = GetOpcodeVersion(client_version);
  1555. if (EQOpcodeManager.count(OpcodeVersion) > 0) {
  1556. opcode = EQOpcodeManager[OpcodeVersion]->EmuToEQ(GetOpcode());
  1557. if (opcode == 0xCDCD) {
  1558. LogWrite(PACKET__ERROR, 0, "Packet", "Could not find valid opcode for opcode: %s and client_version: %i", EQOpcodeManager[OpcodeVersion]->EmuToName(GetOpcode()), client_version);
  1559. }
  1560. }
  1561. }
  1562. #ifndef LOGIN
  1563. if(opcode == 0)
  1564. opcode = 0xFFFF;
  1565. #endif
  1566. return opcode;
  1567. }
  1568. void PacketStruct::serializePacket(bool clear) {
  1569. if (clear)
  1570. Clear();
  1571. bool client_cmd = false;
  1572. string client_data;
  1573. #ifndef LOGIN
  1574. if (GetOpcode() == OP_ClientCmdMsg && strlen(GetOpcodeType()) > 0 && !IsSubPacket())
  1575. client_cmd = true;
  1576. #endif
  1577. DataStruct* data = 0;
  1578. vector<DataStruct*>::iterator itr;
  1579. for (itr = structs.begin(); itr != structs.end(); itr++) {
  1580. data = *itr;
  1581. if (data->IsOptional())//this would be false if the datastruct WAS optional, but was set
  1582. continue;
  1583. if (data->AddToStruct()) {
  1584. if (data->GetIfFlagNotSet() && CheckFlagExists(data->GetIfFlagNotSetVariable()))
  1585. continue;
  1586. if (data->GetIfFlagSet() && !CheckFlagExists(data->GetIfFlagSetVariable()))
  1587. continue;
  1588. if (data->GetIfSet() && data->GetIfSetVariable()) {
  1589. string varname = string(data->GetIfSetVariable());
  1590. if (varname.find(",") < 0xFFFFFFFF) {
  1591. vector<string>* varnames = SplitString(varname, ',');
  1592. if (varnames) {
  1593. bool should_continue = true;
  1594. for (int32 i = 0; i < varnames->size(); i++) {
  1595. if (GetVariableIsSet(varnames->at(i).c_str())) {
  1596. should_continue = false;
  1597. break;
  1598. }
  1599. }
  1600. safe_delete(varnames);
  1601. if (should_continue)
  1602. continue;
  1603. }
  1604. }
  1605. else {
  1606. if (!GetVariableIsSet(varname.c_str()))
  1607. continue;
  1608. }
  1609. }
  1610. if (data->GetIfNotSet() && data->GetIfNotSetVariable()) {
  1611. string varname = string(data->GetIfNotSetVariable());
  1612. if (varname.find(",") < 0xFFFFFFFF) {
  1613. vector<string>* varnames = SplitString(varname, ',');
  1614. if (varnames) {
  1615. bool should_continue = false;
  1616. for (int32 i = 0; i < varnames->size(); i++) {
  1617. if (!GetVariableIsNotSet(varnames->at(i).c_str())) {
  1618. should_continue = true;
  1619. break;
  1620. }
  1621. }
  1622. safe_delete(varnames);
  1623. if (should_continue)
  1624. continue;
  1625. }
  1626. }
  1627. else {
  1628. // Check to see if the variable contains %i, if it does assume we are in an array
  1629. // and get the current index from the end of the data struct's name
  1630. char name[250] = { 0 };
  1631. if (varname.find("%i") < 0xFFFFFFFF) {
  1632. vector<string>* varnames = SplitString(varname, '_');
  1633. vector<string>* indexes = SplitString(data->GetName(), '_');
  1634. int index = 0;
  1635. if (indexes->size() > 0)
  1636. index = atoi(indexes->at(indexes->size() - 1).c_str());
  1637. sprintf(name, varname.c_str(), index);
  1638. }
  1639. else
  1640. strcpy(name, varname.c_str());
  1641. if (!GetVariableIsNotSet(name))
  1642. continue;
  1643. }
  1644. }
  1645. // Quick implementaion of IfVariableNotEquals
  1646. // probably not what it was intended for as it currently just checks to see if the given variable equals 1
  1647. // should probably change it so you can define what the variable should or shouldn't equal
  1648. //
  1649. // ie: IfVariableNotEquals="stat_type_%i=1"
  1650. // would be a check to make sure that stat_type_%i does not equal 1 and if it does exclude this element
  1651. if (data->GetIfNotEquals() && data->GetIfNotEqualsVariable()) {
  1652. // Get the variable name
  1653. string varname = string(data->GetIfNotEqualsVariable());
  1654. char name[250] = { 0 };
  1655. // Check to see if the variable has %i in the name, if it does assume we are in an array and get the current
  1656. // index and replace it
  1657. if (varname.find("%i") < 0xFFFFFFFF) {
  1658. // Get the current index by getting the number at the end of the name
  1659. vector<string>* varnames = SplitString(data->GetName(), '_');
  1660. int index = atoi(varnames->at(varnames->size() - 1).c_str());
  1661. string substr = "stat_type";
  1662. if (strncmp(varname.c_str(), substr.c_str(), strlen(substr.c_str())) == 0) {
  1663. // adorn_stat_subtype 18 chars
  1664. string temp = varname.substr(12);
  1665. char temp2[20] = { 0 };
  1666. int index2 = atoi(temp.c_str());
  1667. itoa(index2, temp2, 10);
  1668. varname = varname.substr(0, 12).append(temp2).append("_%i");
  1669. }
  1670. sprintf(name, varname.c_str(), index);
  1671. safe_delete(varnames);
  1672. }
  1673. else
  1674. strcpy(name, varname.c_str());
  1675. // Get the data for the variable
  1676. int16 value = 0;
  1677. DataStruct* data_struct2 = findStruct(name, 0);
  1678. value = getType_int16(data_struct2);
  1679. // Hack for items as it is the only struct that currently uses IfVariableNotEquals
  1680. if (value == 1)
  1681. continue;
  1682. }
  1683. // copy and paste of the code above for IfEquals
  1684. if (data->GetIfEquals() && data->GetIfEqualsVariable()) {
  1685. // Get the variable name
  1686. string varname = string(data->GetIfEqualsVariable());
  1687. char name[250] = { 0 };
  1688. // Check to see if the variable has %i in the name, if it does assume we are in an array and get the current
  1689. // index and replace it
  1690. if (varname.find("%i") < 0xFFFFFFFF) {
  1691. // Get the current index by getting the number at the end of the name
  1692. vector<string>* varnames = SplitString(data->GetName(), '_');
  1693. int index = 0;
  1694. if (varnames)
  1695. index = atoi(varnames->at(varnames->size() - 1).c_str());
  1696. string substr = "stat_type";
  1697. if (strncmp(varname.c_str(), substr.c_str(), strlen(substr.c_str())) == 0) {
  1698. // adorn_stat_subtype 18 chars
  1699. string temp = varname.substr(12);
  1700. char temp2[20] = { 0 };
  1701. int index2 = atoi(temp.c_str());
  1702. itoa(index2, temp2, 10);
  1703. varname = varname.substr(0, 12).append(temp2).append("_%i");
  1704. }
  1705. sprintf(name, varname.c_str(), index);
  1706. safe_delete(varnames);
  1707. }
  1708. else
  1709. strcpy(name, varname.c_str());
  1710. // Get the data for the variable
  1711. int16 value = 0;
  1712. DataStruct* data_struct2 = findStruct(name, 0);
  1713. value = getType_int16(data_struct2);
  1714. // Hack for items as it is the only struct that currently uses IfVariableNotEquals
  1715. if (value != 1)
  1716. continue;
  1717. }
  1718. if (client_cmd)
  1719. AddSerializedData(data, 0, &client_data);
  1720. else
  1721. AddSerializedData(data);
  1722. }
  1723. }
  1724. #ifndef LOGIN
  1725. if (client_cmd) {
  1726. int16 opcode_val = GetOpcodeValue(client_version);
  1727. Clear();
  1728. int32 size = client_data.length() + 3; //gotta add the opcode and oversized
  1729. int8 oversized = 0xFF;
  1730. int16 OpcodeVersion = GetOpcodeVersion(client_version);
  1731. if (opcode_val == EQOpcodeManager[OpcodeVersion]->EmuToEQ(OP_EqExamineInfoCmd) && client_version > 546)
  1732. size += (size - 9);
  1733. if (client_version <= 283) {
  1734. if (size >= 255) {
  1735. StructAddData(oversized, sizeof(int8), 0);
  1736. StructAddData(size, sizeof(int16), 0);
  1737. }
  1738. else {
  1739. StructAddData(size, sizeof(int8), 0);
  1740. }
  1741. StructAddData(oversized, sizeof(int8), 0);
  1742. StructAddData(opcode_val, sizeof(int16), 0);
  1743. }
  1744. else {
  1745. StructAddData(size, sizeof(int32), 0);
  1746. StructAddData(oversized, sizeof(int8), 0);
  1747. StructAddData(opcode_val, sizeof(int16), 0);
  1748. }
  1749. AddData(client_data);
  1750. }
  1751. #endif
  1752. }
  1753. int32 PacketStruct::GetTotalPacketSize() {
  1754. int32 retSize = 0;
  1755. DataStruct* data = 0;
  1756. vector<DataStruct*>::iterator itr;
  1757. EQ2_8BitString* tmp1 = 0;
  1758. EQ2_16BitString* tmp2 = 0;
  1759. EQ2_32BitString* tmp3 = 0;
  1760. for (itr = structs.begin(); itr != structs.end(); itr++) {
  1761. data = *itr;
  1762. switch (data->GetType()) {
  1763. case DATA_STRUCT_INT8:
  1764. case DATA_STRUCT_SINT8:
  1765. case DATA_STRUCT_CHAR:
  1766. retSize += (1 * data->GetLength());
  1767. break;
  1768. case DATA_STRUCT_SINT16:
  1769. case DATA_STRUCT_INT16:
  1770. retSize += (2 * data->GetLength());
  1771. break;
  1772. case DATA_STRUCT_INT32:
  1773. case DATA_STRUCT_SINT32:
  1774. case DATA_STRUCT_FLOAT:
  1775. case DATA_STRUCT_DOUBLE:
  1776. retSize += (4 * data->GetLength());
  1777. break;
  1778. case DATA_STRUCT_SINT64:
  1779. case DATA_STRUCT_INT64:
  1780. retSize += (8 * data->GetLength());
  1781. break;
  1782. case DATA_STRUCT_EQ2_8BIT_STRING:
  1783. tmp1 = (EQ2_8BitString*)GetStructPointer(data);
  1784. if (tmp1) {
  1785. for (int16 i = 0; i < data->GetLength(); i++)
  1786. retSize += tmp1[i].data.length();
  1787. }
  1788. retSize += (1 * data->GetLength());
  1789. break;
  1790. case DATA_STRUCT_EQ2_16BIT_STRING: {
  1791. tmp2 = (EQ2_16BitString*)GetStructPointer(data);
  1792. if (tmp2) {
  1793. for (int16 i = 0; i < data->GetLength(); i++)
  1794. retSize += tmp2[i].data.length();
  1795. }
  1796. retSize += (2 * data->GetLength());
  1797. break;
  1798. }
  1799. case DATA_STRUCT_EQ2_32BIT_STRING: {
  1800. tmp3 = (EQ2_32BitString*)GetStructPointer(data);
  1801. if (tmp3) {
  1802. for (int16 i = 0; i < data->GetLength(); i++)
  1803. retSize += tmp3[i].data.length();
  1804. }
  1805. retSize += (4 * data->GetLength());
  1806. break;
  1807. }
  1808. case DATA_STRUCT_ARRAY: {
  1809. int32 size = GetArraySize(data, 0);
  1810. PacketStruct* ps = GetPacketStructByName(data->GetName());
  1811. if (ps && ps->GetSubPacketSize() != size) {
  1812. ps->reAddAll(size);
  1813. }
  1814. if (ps && size > 0)
  1815. retSize += ps->GetTotalPacketSize();
  1816. break;
  1817. }
  1818. case DATA_STRUCT_COLOR: {
  1819. retSize += ((sizeof(int8) * 3) * data->GetLength());
  1820. break;
  1821. }
  1822. case DATA_STRUCT_EQUIPMENT: {
  1823. retSize += ((((sizeof(int8) * 3) * 2) + sizeof(int16)) * data->GetLength());
  1824. break;
  1825. }
  1826. }
  1827. }
  1828. return retSize;
  1829. }
  1830. void PacketStruct::AddSerializedData(DataStruct* data, int32 index, string* datastring) {
  1831. switch (data->GetAddType()) {
  1832. case DATA_STRUCT_INT8:
  1833. StructAddData((int8*)GetStructPointer(data), data->GetLength(), sizeof(int8), datastring);
  1834. break;
  1835. case DATA_STRUCT_INT16:
  1836. if (data->GetOversized() > 0) {
  1837. if (*((int16*)GetStructPointer(data)) >= data->GetOversized()) {
  1838. StructAddData(data->GetOversizedByte(), sizeof(int8), datastring);
  1839. StructAddData((int16*)GetStructPointer(data), data->GetLength(), sizeof(int16), datastring);
  1840. }
  1841. else
  1842. StructAddData((int8*)GetStructPointer(data), data->GetLength(), sizeof(int8), datastring);
  1843. }
  1844. else
  1845. StructAddData((int16*)GetStructPointer(data), data->GetLength(), sizeof(int16), datastring);
  1846. break;
  1847. case DATA_STRUCT_INT32:
  1848. if (data->GetOversized() > 0) {
  1849. if (*((int32*)GetStructPointer(data)) >= data->GetOversized()) {
  1850. StructAddData(data->GetOversizedByte(), sizeof(int8), datastring);
  1851. StructAddData((int32*)GetStructPointer(data), data->GetLength(), sizeof(int32), datastring);
  1852. }
  1853. else
  1854. StructAddData((int16*)GetStructPointer(data), data->GetLength(), sizeof(int16), datastring);
  1855. }
  1856. else
  1857. StructAddData((int32*)GetStructPointer(data), data->GetLength(), sizeof(int32), datastring);
  1858. break;
  1859. case DATA_STRUCT_INT64:
  1860. StructAddData((int64*)GetStructPointer(data), data->GetLength(), sizeof(int64), datastring);
  1861. break;
  1862. case DATA_STRUCT_SINT8:
  1863. StructAddData((sint8*)GetStructPointer(data), data->GetLength(), sizeof(sint8), datastring);
  1864. break;
  1865. case DATA_STRUCT_SINT16:
  1866. if (data->GetOversized() > 0) {
  1867. sint16 val = *((sint16*)GetStructPointer(data));
  1868. if (val >= data->GetOversized() || val <= (data->GetOversized() * -1)) {
  1869. StructAddData(data->GetOversizedByte(), sizeof(sint8), datastring);
  1870. StructAddData((sint16*)GetStructPointer(data), data->GetLength(), sizeof(sint16), datastring);
  1871. }
  1872. else
  1873. StructAddData((sint8*)GetStructPointer(data), data->GetLength(), sizeof(sint8), datastring);
  1874. }
  1875. else
  1876. StructAddData((sint16*)GetStructPointer(data), data->GetLength(), sizeof(sint16), datastring);
  1877. break;
  1878. case DATA_STRUCT_SINT32:
  1879. StructAddData((sint32*)GetStructPointer(data), data->GetLength(), sizeof(sint32), datastring);
  1880. break;
  1881. case DATA_STRUCT_SINT64:
  1882. StructAddData((sint64*)GetStructPointer(data), data->GetLength(), sizeof(sint64), datastring);
  1883. break;
  1884. case DATA_STRUCT_CHAR:
  1885. StructAddData((char*)GetStructPointer(data), data->GetLength(), sizeof(char), datastring);
  1886. break;
  1887. case DATA_STRUCT_FLOAT:
  1888. StructAddData((float*)GetStructPointer(data), data->GetLength(), sizeof(float), datastring);
  1889. break;
  1890. case DATA_STRUCT_DOUBLE:
  1891. StructAddData((double*)GetStructPointer(data), data->GetLength(), sizeof(double), datastring);
  1892. break;
  1893. case DATA_STRUCT_EQ2_8BIT_STRING: {
  1894. for (int16 i = 0; i < data->GetLength(); i++) {
  1895. EQ2_8BitString* ds = (EQ2_8BitString*)GetStructPointer(data);
  1896. AddDataString(ds[i], datastring);
  1897. }
  1898. break;
  1899. }
  1900. case DATA_STRUCT_EQ2_16BIT_STRING: {
  1901. for (int16 i = 0; i < data->GetLength(); i++) {
  1902. EQ2_16BitString* ds = (EQ2_16BitString*)GetStructPointer(data);
  1903. AddDataString(ds[i], datastring);
  1904. }
  1905. break;
  1906. }
  1907. case DATA_STRUCT_EQ2_32BIT_STRING: {
  1908. for (int16 i = 0; i < data->GetLength(); i++) {
  1909. EQ2_32BitString* ds = (EQ2_32BitString*)GetStructPointer(data);
  1910. AddDataString(ds[i], datastring);
  1911. }
  1912. break;
  1913. }
  1914. case DATA_STRUCT_ARRAY: {
  1915. int32 size = GetArraySize(data, 0);
  1916. PacketStruct* ps = GetPacketStructByName(data->GetName());
  1917. if (ps && ps->GetSubPacketSize() != size) {
  1918. ps->reAddAll(size);
  1919. }
  1920. if (ps && size > 0) {
  1921. ps->serializePacket();
  1922. string data = *(ps->getDataString());
  1923. AddData(data, datastring);
  1924. }
  1925. break;
  1926. }
  1927. case DATA_STRUCT_COLOR: {
  1928. StructAddData((EQ2_Color*)GetStructPointer(data), data->GetLength(), sizeof(EQ2_Color), datastring);
  1929. break;
  1930. }
  1931. case DATA_STRUCT_EQUIPMENT: {
  1932. StructAddData((EQ2_EquipmentItem*)GetStructPointer(data), data->GetLength(), sizeof(EQ2_EquipmentItem), datastring);
  1933. break;
  1934. }
  1935. case DATA_STRUCT_ITEM: {
  1936. //DumpPacket((uchar*)GetStructPointer(data), data->GetItemSize());
  1937. AddCharArray((char*)GetStructPointer(data), data->GetItemSize(), datastring);
  1938. break;
  1939. }
  1940. }
  1941. }
  1942. int8 PacketStruct::getType_int8_ByName(const char* name, int32 index, bool force) {
  1943. DataStruct* data_struct = findStruct(name, index);
  1944. return getType_int8(data_struct, index, force);
  1945. }
  1946. int16 PacketStruct::getType_int16_ByName(const char* name, int32 index, bool force) {
  1947. DataStruct* data_struct = findStruct(name, index);
  1948. return getType_int16(data_struct, index, force);
  1949. }
  1950. int32 PacketStruct::getType_int32_ByName(const char* name, int32 index, bool force) {
  1951. DataStruct* data_struct = findStruct(name, index);
  1952. return getType_int32(data_struct, index, force);
  1953. }
  1954. int64 PacketStruct::getType_int64_ByName(const char* name, int32 index, bool force) {
  1955. DataStruct* data_struct = findStruct(name, index);
  1956. return getType_int64(data_struct, index, force);
  1957. }
  1958. sint8 PacketStruct::getType_sint8_ByName(const char* name, int32 index, bool force) {
  1959. DataStruct* data_struct = findStruct(name, index);
  1960. return getType_sint8(data_struct, index, force);
  1961. }
  1962. sint16 PacketStruct::getType_sint16_ByName(const char* name, int32 index, bool force) {
  1963. DataStruct* data_struct = findStruct(name, index);
  1964. return getType_sint16(data_struct, index, force);
  1965. }
  1966. sint32 PacketStruct::getType_sint32_ByName(const char* name, int32 index, bool force) {
  1967. DataStruct* data_struct = findStruct(name, index);
  1968. return getType_sint32(data_struct, index, force);
  1969. }
  1970. sint64 PacketStruct::getType_sint64_ByName(const char* name, int32 index, bool force) {
  1971. DataStruct* data_struct = findStruct(name, index);
  1972. return getType_sint64(data_struct, index, force);
  1973. }
  1974. float PacketStruct::getType_float_ByName(const char* name, int32 index, bool force) {
  1975. DataStruct* data_struct = findStruct(name, index);
  1976. return getType_float(data_struct, index, force);
  1977. }
  1978. double PacketStruct::getType_double_ByName(const char* name, int32 index, bool force) {
  1979. DataStruct* data_struct = findStruct(name, index);
  1980. return getType_double(data_struct, index, force);
  1981. }
  1982. char PacketStruct::getType_char_ByName(const char* name, int32 index, bool force) {
  1983. DataStruct* data_struct = findStruct(name, index);
  1984. return getType_char(data_struct, index, force);
  1985. }
  1986. EQ2_8BitString PacketStruct::getType_EQ2_8BitString_ByName(const char* name, int32 index, bool force) {
  1987. DataStruct* data_struct = findStruct(name, index);
  1988. return getType_EQ2_8BitString(data_struct, index, force);
  1989. }
  1990. EQ2_16BitString PacketStruct::getType_EQ2_16BitString_ByName(const char* name, int32 index, bool force) {
  1991. DataStruct* data_struct = findStruct(name, index);
  1992. return getType_EQ2_16BitString(data_struct, index, force);
  1993. }
  1994. EQ2_32BitString PacketStruct::getType_EQ2_32BitString_ByName(const char* name, int32 index, bool force) {
  1995. DataStruct* data_struct = findStruct(name, index);
  1996. return getType_EQ2_32BitString(data_struct, index, force);
  1997. }
  1998. EQ2_Color PacketStruct::getType_EQ2_Color_ByName(const char* name, int32 index, bool force) {
  1999. DataStruct* data_struct = findStruct(name, index);
  2000. return getType_EQ2_Color(data_struct, index, force);
  2001. }
  2002. EQ2_EquipmentItem PacketStruct::getType_EQ2_EquipmentItem_ByName(const char* name, int32 index, bool force) {
  2003. DataStruct* data_struct = findStruct(name, index);
  2004. return getType_EQ2_EquipmentItem(data_struct, index, force);
  2005. }
  2006. int8 PacketStruct::getType_int8(DataStruct* data_struct, int32 index, bool force) {
  2007. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_INT8) || force)) {
  2008. int8* ptr = (int8*)GetStructPointer(data_struct);
  2009. return ptr[index];
  2010. }
  2011. return 0;
  2012. }
  2013. int16 PacketStruct::getType_int16(DataStruct* data_struct, int32 index, bool force) {
  2014. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_INT16) || force)) {
  2015. int16* ptr = (int16*)GetStructPointer(data_struct);
  2016. return ptr[index];
  2017. }
  2018. return 0;
  2019. }
  2020. int32 PacketStruct::getType_int32(DataStruct* data_struct, int32 index, bool force) {
  2021. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_INT32) || force)) {
  2022. int32* ptr = (int32*)GetStructPointer(data_struct);
  2023. return ptr[index];
  2024. }
  2025. return 0;
  2026. }
  2027. int64 PacketStruct::getType_int64(DataStruct* data_struct, int32 index, bool force) {
  2028. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_INT64) || force)) {
  2029. int64* ptr = (int64*)GetStructPointer(data_struct);
  2030. return ptr[index];
  2031. }
  2032. return 0;
  2033. }
  2034. sint8 PacketStruct::getType_sint8(DataStruct* data_struct, int32 index, bool force) {
  2035. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_SINT8) || force)) {
  2036. sint8* ptr = (sint8*)GetStructPointer(data_struct);
  2037. return ptr[index];
  2038. }
  2039. return 0;
  2040. }
  2041. sint16 PacketStruct::getType_sint16(DataStruct* data_struct, int32 index, bool force) {
  2042. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_SINT16) || force)) {
  2043. sint16* ptr = (sint16*)GetStructPointer(data_struct);
  2044. return ptr[index];
  2045. }
  2046. return 0;
  2047. }
  2048. sint32 PacketStruct::getType_sint32(DataStruct* data_struct, int32 index, bool force) {
  2049. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_SINT32) || force)) {
  2050. sint32* ptr = (sint32*)GetStructPointer(data_struct);
  2051. return ptr[index];
  2052. }
  2053. return 0;
  2054. }
  2055. sint64 PacketStruct::getType_sint64(DataStruct* data_struct, int32 index, bool force) {
  2056. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_SINT64) || force)) {
  2057. sint64* ptr = (sint64*)GetStructPointer(data_struct);
  2058. return ptr[index];
  2059. }
  2060. return 0;
  2061. }
  2062. float PacketStruct::getType_float(DataStruct* data_struct, int32 index, bool force) {
  2063. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_FLOAT) || force)) {
  2064. float* ptr = (float*)GetStructPointer(data_struct);
  2065. return ptr[index];
  2066. }
  2067. return 0;
  2068. }
  2069. double PacketStruct::getType_double(DataStruct* data_struct, int32 index, bool force) {
  2070. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_DOUBLE) || force)) {
  2071. double* ptr = (double*)GetStructPointer(data_struct);
  2072. return ptr[index];
  2073. }
  2074. return 0;
  2075. }
  2076. char PacketStruct::getType_char(DataStruct* data_struct, int32 index, bool force) {
  2077. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_CHAR) || force)) {
  2078. char* ptr = (char*)GetStructPointer(data_struct);
  2079. return ptr[index];
  2080. }
  2081. return 0;
  2082. }
  2083. EQ2_8BitString PacketStruct::getType_EQ2_8BitString(DataStruct* data_struct, int32 index, bool force) {
  2084. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_EQ2_8BIT_STRING) || force)) {
  2085. EQ2_8BitString* ptr = (EQ2_8BitString*)GetStructPointer(data_struct);
  2086. return ptr[index];
  2087. }
  2088. EQ2_8BitString ret;
  2089. ret.size = 0;
  2090. return ret;
  2091. }
  2092. EQ2_16BitString PacketStruct::getType_EQ2_16BitString(DataStruct* data_struct, int32 index, bool force) {
  2093. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_EQ2_16BIT_STRING) || force)) {
  2094. EQ2_16BitString* ptr = (EQ2_16BitString*)GetStructPointer(data_struct);
  2095. return ptr[index];
  2096. }
  2097. EQ2_16BitString ret;
  2098. ret.size = 0;
  2099. return ret;
  2100. }
  2101. EQ2_32BitString PacketStruct::getType_EQ2_32BitString(DataStruct* data_struct, int32 index, bool force) {
  2102. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_EQ2_32BIT_STRING) || force)) {
  2103. EQ2_32BitString* ptr = (EQ2_32BitString*)GetStructPointer(data_struct);
  2104. return ptr[index];
  2105. }
  2106. EQ2_32BitString ret;
  2107. ret.size = 0;
  2108. return ret;
  2109. }
  2110. EQ2_Color PacketStruct::getType_EQ2_Color(DataStruct* data_struct, int32 index, bool force) {
  2111. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_COLOR) || force)) {
  2112. EQ2_Color* ptr = (EQ2_Color*)GetStructPointer(data_struct);
  2113. return ptr[index];
  2114. }
  2115. EQ2_Color ret;
  2116. ret.blue = 0;
  2117. ret.red = 0;
  2118. ret.green = 0;
  2119. return ret;
  2120. }
  2121. EQ2_EquipmentItem PacketStruct::getType_EQ2_EquipmentItem(DataStruct* data_struct, int32 index, bool force) {
  2122. if (data_struct && ((data_struct->GetType() == DATA_STRUCT_EQUIPMENT) || force)) {
  2123. EQ2_EquipmentItem* ptr = (EQ2_EquipmentItem*)GetStructPointer(data_struct);
  2124. return ptr[index];
  2125. }
  2126. EQ2_EquipmentItem ret;
  2127. ret.color.blue = 0;
  2128. ret.color.red = 0;
  2129. ret.color.green = 0;
  2130. ret.highlight.blue = 0;
  2131. ret.highlight.red = 0;
  2132. ret.highlight.green = 0;
  2133. ret.type = 0;
  2134. return ret;
  2135. }
  2136. bool PacketStruct::SetOpcode(const char* new_opcode) {
  2137. opcode = EQOpcodeManager[0]->NameSearch(new_opcode);
  2138. if (opcode == OP_Unknown) {
  2139. #ifndef MINILOGIN
  2140. LogWrite(PACKET__ERROR, 0, "Packet", "Warning: PacketStruct '%s' uses an unknown opcode named '%s', this struct cannot be serialized directly.", GetName(), new_opcode);
  2141. #endif
  2142. return false;
  2143. }
  2144. return true;
  2145. }
  2146. EQ2Packet* PacketStruct::serialize() {
  2147. serializePacket();
  2148. if (GetOpcode() != OP_Unknown)
  2149. return new EQ2Packet(GetOpcode(), getData(), getDataSize());
  2150. else {
  2151. #ifndef MINILOGIN
  2152. LogWrite(PACKET__ERROR, 0, "Packet", "Warning: PacketStruct '%s' uses an unknown opcode and cannot be serialized directly.", GetName());
  2153. #endif
  2154. return 0;
  2155. }
  2156. }
  2157. EQ2Packet* PacketStruct::serializeCountPacket(int16 version, int8 offset, uchar* orig_packet, uchar* xor_packet) {
  2158. string* packet_data = serializeString();
  2159. uchar* data = (uchar*)packet_data->c_str();
  2160. int32 size = packet_data->size();
  2161. uchar* packed_data = new uchar[size + 20];
  2162. memset(packed_data, 0, size + 20);
  2163. if (orig_packet && xor_packet) {
  2164. memcpy(xor_packet, data + 6, size - 6 - offset);
  2165. Encode(xor_packet, orig_packet, size - 6 - offset);
  2166. size = Pack(packed_data, xor_packet, size - 6 - offset, size + 20, version);
  2167. }
  2168. else
  2169. size = Pack(packed_data, data + 6, packet_data->size() - 6 - offset, packet_data->size() + 20, version);
  2170. uchar* combined = new uchar[size + sizeof(int16) + offset];
  2171. memset(combined, 0, size + sizeof(int16) + offset);
  2172. uchar* ptr = combined;
  2173. memcpy(ptr, data, sizeof(int16));
  2174. ptr += sizeof(int16);
  2175. memcpy(ptr, packed_data, size);
  2176. if (offset > 0) {
  2177. ptr += size;
  2178. uchar* ptr2 = data;
  2179. ptr2 += packet_data->size() - offset;
  2180. memcpy(ptr, ptr2, offset);
  2181. }
  2182. EQ2Packet* app = new EQ2Packet(GetOpcode(), combined, size + sizeof(int16) + offset);
  2183. safe_delete_array(packed_data);
  2184. safe_delete_array(combined);
  2185. return app;
  2186. }
  2187. bool PacketStruct::IsSubPacket() {
  2188. return sub_packet;
  2189. }
  2190. void PacketStruct::IsSubPacket(bool new_val) {
  2191. sub_packet = new_val;
  2192. }
  2193. int32 PacketStruct::GetSubPacketSize() {
  2194. return sub_packet_size;
  2195. }
  2196. void PacketStruct::SetSubPacketSize(int32 new_size) {
  2197. sub_packet_size = new_size;
  2198. }
  2199. void* PacketStruct::GetStructPointer(DataStruct* data_struct, bool erase) {
  2200. try {
  2201. map<DataStruct*, void*>::iterator tmpitr = struct_data.find(data_struct);
  2202. if (tmpitr != struct_data.end()) {
  2203. if (erase)
  2204. struct_data.erase(data_struct);
  2205. return tmpitr->second;
  2206. }
  2207. else {
  2208. PacketStruct* packet = 0;
  2209. vector<PacketStruct*>::iterator itr2;
  2210. for (itr2 = arrays.begin(); itr2 != arrays.end(); itr2++) {
  2211. packet = *itr2;
  2212. if (packet) {
  2213. void* tmp = packet->GetStructPointer(data_struct, erase);
  2214. if (tmp != 0)
  2215. return tmp;
  2216. }
  2217. }
  2218. }
  2219. }
  2220. catch (...) {
  2221. cout << "Caught Exception...\n";
  2222. }
  2223. return 0;
  2224. }
  2225. vector<DataStruct*> PacketStruct::GetDataStructs() {
  2226. vector<DataStruct*> ret;
  2227. DataStruct* ds = 0;
  2228. vector<DataStruct*>::iterator itr;
  2229. for (itr = structs.begin(); itr != structs.end(); itr++) {
  2230. ds = *itr;
  2231. if (ds->GetType() == DATA_STRUCT_ARRAY) {
  2232. int32 size = GetArraySize(ds, 0);
  2233. PacketStruct* ps = GetPacketStructByName(ds->GetName());
  2234. if (ps && ps->GetSubPacketSize() != size) {
  2235. ps->reAddAll(size);
  2236. }
  2237. if (ps) {
  2238. vector<DataStruct*> ret2 = ps->GetDataStructs();
  2239. vector<DataStruct*>::iterator itr2;
  2240. for (itr2 = ret2.begin(); itr2 != ret2.end(); itr2++) {
  2241. ret.push_back(*itr2);
  2242. }
  2243. }
  2244. }
  2245. else if (ds->GetLength() == 0 && ds->GetType() == DATA_STRUCT_ARRAY) {
  2246. int32 size = GetArraySize(ds, 0);
  2247. PacketStruct* ps = GetPacketStructByName(ds->GetName());
  2248. if (ps && ps->GetSubPacketSize() != size) {
  2249. ps->reAddAll(size);
  2250. }
  2251. if (ps) {
  2252. vector<DataStruct*> ret2 = ps->GetDataStructs();
  2253. vector<DataStruct*>::iterator itr2;
  2254. for (itr2 = ret2.begin(); itr2 != ret2.end(); itr2++) {
  2255. ret.push_back(*itr2);
  2256. }
  2257. }
  2258. }
  2259. else
  2260. ret.push_back(ds);
  2261. }
  2262. return ret;
  2263. }
  2264. void PacketStruct::PrintPacket() {
  2265. DataStruct* ds = 0;
  2266. vector<DataStruct*>::iterator itr;
  2267. for (itr = structs.begin(); itr != structs.end(); itr++) {
  2268. ds = *itr;
  2269. if (!ds->AddToStruct())
  2270. continue;
  2271. for (int16 i = 0; i < ds->GetLength(); i++) {
  2272. cout << "Name: " << ds->GetName() << " \tIndex: " << i << " \tType: ";
  2273. switch (ds->GetType()) {
  2274. case DATA_STRUCT_INT8:
  2275. printf("int8\t\tData: %i", getType_int8_ByName(ds->GetName(), i));
  2276. break;
  2277. case DATA_STRUCT_INT16:
  2278. printf("int16\t\tData: %i", getType_int16_ByName(ds->GetName(), i));
  2279. break;
  2280. case DATA_STRUCT_INT32:
  2281. printf("int32\t\tData: %u", getType_int32_ByName(ds->GetName(), i));
  2282. break;
  2283. case DATA_STRUCT_INT64:
  2284. printf("int64\t\tData: %llu", getType_int64_ByName(ds->GetName(), i));
  2285. break;
  2286. case DATA_STRUCT_SINT8:
  2287. printf("sint8\t\tData: %i", getType_sint8_ByName(ds->GetName(), i));
  2288. break;
  2289. case DATA_STRUCT_SINT16:
  2290. printf("sint16\t\tData: %i", getType_sint16_ByName(ds->GetName(), i));
  2291. break;
  2292. case DATA_STRUCT_SINT32:
  2293. printf("sint32\t\tData: %i", getType_sint32_ByName(ds->GetName(), i));
  2294. break;
  2295. case DATA_STRUCT_SINT64:
  2296. printf("sint64\t\tData: %lli", getType_sint64_ByName(ds->GetName(), i));
  2297. break;
  2298. case DATA_STRUCT_CHAR:
  2299. printf("char\t\tData: %c", getType_char_ByName(ds->GetName(), i));
  2300. break;
  2301. case DATA_STRUCT_FLOAT:
  2302. printf("float\t\tData: %f", getType_float_ByName(ds->GetName(), i));
  2303. break;
  2304. case DATA_STRUCT_DOUBLE:
  2305. printf("double\t\tData: %f", getType_double_ByName(ds->GetName(), i));
  2306. break;
  2307. case DATA_STRUCT_EQ2_8BIT_STRING:
  2308. printf("EQ2_8BitString\tData: %s", getType_EQ2_8BitString_ByName(ds->GetName(), i).data.c_str());
  2309. break;
  2310. case DATA_STRUCT_EQ2_16BIT_STRING:
  2311. printf("EQ2_16BitString\tData: %s", getType_EQ2_16BitString_ByName(ds->GetName(), i).data.c_str());
  2312. break;
  2313. case DATA_STRUCT_EQ2_32BIT_STRING: {
  2314. printf("EQ2_32BitString\tData: %s", getType_EQ2_32BitString_ByName(ds->GetName(), i).data.c_str());
  2315. break;
  2316. }
  2317. case DATA_STRUCT_ITEM: {
  2318. if (ds->GetItemSize() > 0) {
  2319. DumpPacket((uchar*)GetStructPointer(ds), ds->GetItemSize());
  2320. }
  2321. break;
  2322. }
  2323. case DATA_STRUCT_ARRAY: {
  2324. int32 size = GetArraySize(ds, 0);
  2325. PacketStruct* ps = GetPacketStructByName(ds->GetName());
  2326. if (ps && ps->GetSubPacketSize() != size) {
  2327. ps->reAddAll(size);
  2328. }
  2329. if (ps) {
  2330. cout << "Array:\tData: \n";
  2331. ps->PrintPacket();
  2332. }
  2333. break;
  2334. }
  2335. case DATA_STRUCT_COLOR: {
  2336. cout.unsetf(ios_base::dec);
  2337. cout.setf(ios_base::hex);
  2338. printf("EQ2_Color\tData: ");
  2339. EQ2_Color tmp = getType_EQ2_Color_ByName(ds->GetName(), i);
  2340. printf("R: %i", tmp.red);
  2341. printf(", G: %i", tmp.green);
  2342. printf(", B: %i", tmp.blue);
  2343. break;
  2344. }
  2345. case DATA_STRUCT_EQUIPMENT: {
  2346. cout.unsetf(ios_base::dec);
  2347. cout.setf(ios_base::hex);
  2348. printf("EQ2_EquipmentItem\tData: ");
  2349. EQ2_EquipmentItem tmp = getType_EQ2_EquipmentItem_ByName(ds->GetName(), i);
  2350. printf("type: ");
  2351. printf(" ,color R: %i", tmp.color.red);
  2352. printf(" ,color G: %i", tmp.color.green);
  2353. printf(" ,color B: %i", tmp.color.blue);
  2354. printf(" ,hl R: %i", tmp.highlight.red);
  2355. printf(" ,hl G: %i", tmp.highlight.green);
  2356. printf(" ,hl B: %i", tmp.highlight.blue);
  2357. break;
  2358. }
  2359. }
  2360. cout << endl;
  2361. }
  2362. if (ds->GetLength() == 0 && ds->GetType() == DATA_STRUCT_ARRAY) {
  2363. int32 size = GetArraySize(ds, 0);
  2364. PacketStruct* ps = GetPacketStructByName(ds->GetName());
  2365. if (ps && ps->GetSubPacketSize() != size) {
  2366. ps->reAddAll(size);
  2367. }
  2368. if (ps) {
  2369. cout << "Array:\tData: \n";
  2370. ps->PrintPacket();
  2371. }
  2372. }
  2373. }
  2374. }
  2375. void PacketStruct::LoadFromPacketStruct(PacketStruct* packet, char* substruct_name) {
  2376. vector<DataStruct*>::iterator itr;
  2377. DataStruct* ds = 0;
  2378. char name[512];
  2379. //scatman (1/30/2012): these declarations are here to get rid of a linux compile error "taking address of temporary"
  2380. EQ2_8BitString str8;
  2381. EQ2_16BitString str16;
  2382. EQ2_32BitString str32;
  2383. EQ2_EquipmentItem equip;
  2384. for (itr = structs.begin(); itr != structs.end(); itr++) {
  2385. ds = *itr;
  2386. for (int16 i = 0; i < ds->GetLength(); i++) {
  2387. memset(name, 0, sizeof(name));
  2388. if (substruct_name)
  2389. snprintf(name, sizeof(name), "%s_%s_0", substruct_name, ds->GetName());
  2390. else
  2391. strncpy(name, ds->GetName(), sizeof(name));
  2392. name[sizeof(name) - 1] = '\0';
  2393. switch (ds->GetType()) {
  2394. case DATA_STRUCT_INT8:
  2395. setData(ds, packet->getType_int8_ByName(name, i), i);
  2396. break;
  2397. case DATA_STRUCT_SINT8:
  2398. setData(ds, packet->getType_sint8_ByName(name, i), i);
  2399. break;
  2400. case DATA_STRUCT_CHAR:
  2401. setData(ds, packet->getType_char_ByName(name, i), i);
  2402. break;
  2403. case DATA_STRUCT_SINT16:
  2404. setData(ds, packet->getType_sint16_ByName(name, i), i);
  2405. break;
  2406. case DATA_STRUCT_INT16:
  2407. setData(ds, packet->getType_int16_ByName(name, i), i);
  2408. break;
  2409. case DATA_STRUCT_INT32:
  2410. setData(ds, packet->getType_int32_ByName(name, i), i);
  2411. break;
  2412. case DATA_STRUCT_INT64:
  2413. setData(ds, packet->getType_int64_ByName(name, i), i);
  2414. break;
  2415. case DATA_STRUCT_SINT32:
  2416. setData(ds, packet->getType_sint32_ByName(name, i), i);
  2417. break;
  2418. case DATA_STRUCT_SINT64:
  2419. setData(ds, packet->getType_sint64_ByName(name, i), i);
  2420. break;
  2421. case DATA_STRUCT_FLOAT:
  2422. setData(ds, packet->getType_float_ByName(name, i), i);
  2423. break;
  2424. case DATA_STRUCT_DOUBLE:
  2425. setData(ds, packet->getType_double_ByName(name, i), i);
  2426. break;
  2427. case DATA_STRUCT_EQ2_8BIT_STRING:
  2428. str8 = packet->getType_EQ2_8BitString_ByName(name, i);
  2429. setData(ds, &str8, i);
  2430. break;
  2431. case DATA_STRUCT_EQ2_16BIT_STRING:
  2432. str16 = packet->getType_EQ2_16BitString_ByName(name, i);
  2433. setData(ds, &str16, i);
  2434. break;
  2435. case DATA_STRUCT_EQ2_32BIT_STRING:
  2436. str32 = packet->getType_EQ2_32BitString_ByName(name, i);
  2437. setData(ds, &str32, i);
  2438. break;
  2439. case DATA_STRUCT_ARRAY: {
  2440. int32 size = GetArraySize(ds, 0);
  2441. PacketStruct* ps = GetPacketStructByName(ds->GetName());
  2442. if (ps && size > 0)
  2443. ps->LoadFromPacketStruct(packet, substruct_name);
  2444. break;
  2445. }
  2446. case DATA_STRUCT_COLOR:
  2447. setColor(ds, packet->getType_EQ2_Color_ByName(name, i), i);
  2448. break;
  2449. case DATA_STRUCT_EQUIPMENT:
  2450. equip = packet->getType_EQ2_EquipmentItem_ByName(name, i);
  2451. setEquipmentByName(ds->GetName(), &equip, i);
  2452. break;
  2453. default:
  2454. break;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. #ifdef WORLD
  2460. void PacketStruct::setItem(DataStruct* ds, Item* item, Player* player, int32 index, sint8 offset, bool loot_item) {
  2461. if (!ds)
  2462. return;
  2463. uchar* ptr = (uchar*)GetStructPointer(ds);
  2464. PacketStruct* packet = item->PrepareItem(client_version, false, loot_item);
  2465. if (packet) {
  2466. int16 item_version = GetItemPacketType(packet->GetVersion());
  2467. item->serialize(packet, true, player, item_version);
  2468. string* generic_string_data = packet->serializeString();
  2469. int32 size = generic_string_data->length();
  2470. //DumpPacket((uchar*)generic_string_data->c_str(), size);
  2471. if (size <= 13)
  2472. return;
  2473. size -= (9 + offset);
  2474. if (client_version > 546 && item->IsBag() == false && item->IsBauble() == false && item->IsFood() == false && (offset == 0 || offset == -1 || offset == 2))
  2475. size = (size * 2) - 5;
  2476. uchar* out_data = new uchar[size + 1];
  2477. uchar* out_ptr = out_data;
  2478. memcpy(out_ptr, (uchar*)generic_string_data->c_str() + (9 + offset), generic_string_data->length() - (9 + offset));
  2479. //DumpPacket((uchar*)generic_string_data->c_str() + (9 + offset), size);
  2480. //without these it will prompt for your character name
  2481. if (offset == 0 || offset == -1 || offset == 2) {
  2482. if (client_version <= 546 && item->details.count > 0)
  2483. out_data[0] = item->details.count;
  2484. else
  2485. out_data[0] = 1;
  2486. }
  2487. //
  2488. out_ptr += generic_string_data->length() - (10 + offset);
  2489. if (client_version > 546 && item->IsBag() == false && item->IsBauble() == false && item->IsFood() == false && (offset == 0 || offset == -1 || offset == 2)) {
  2490. out_data[4] = 0x80;
  2491. memcpy(out_ptr, (uchar*)generic_string_data->c_str() + (13 + offset), generic_string_data->length() - (13 + offset));
  2492. }
  2493. ds->SetItemSize(size);
  2494. //printf("Item Name: %s\n",item->name.c_str());
  2495. //DumpPacket(out_data, size);
  2496. memcpy(ptr, out_data, size);
  2497. safe_delete_array(out_data);
  2498. delete packet;
  2499. }
  2500. //DumpPacket(ptr2, ds->GetItemSize());
  2501. }
  2502. void PacketStruct::setItemByName(const char* name, Item* item, Player* player, int32 index, sint8 offset, bool loot_item) {
  2503. setItem(findStruct(name, index), item, player, index, offset, loot_item);
  2504. }
  2505. void PacketStruct::setItemArrayDataByName(const char* name, Item* item, Player* player, int32 index1, int32 index2, sint8 offset, bool loot_item) {
  2506. char tmp[10] = { 0 };
  2507. sprintf(tmp, "_%i", index1);
  2508. string name2 = string(name).append(tmp);
  2509. setItem(findStruct(name2.c_str(), index1, index2), item, player, index2, offset, loot_item);
  2510. }
  2511. void PacketStruct::ResetData() {
  2512. vector<DataStruct*>::iterator itr;
  2513. for (itr = structs.begin(); itr != structs.end(); itr++) {
  2514. DataStruct* ds = *itr;
  2515. void* ptr = GetStructPointer(ds);
  2516. if (!ptr)
  2517. continue;
  2518. switch (ds->GetType())
  2519. {
  2520. case DATA_STRUCT_EQ2_8BIT_STRING: {
  2521. EQ2_8BitString* real_ptr = (EQ2_8BitString*)ptr;
  2522. real_ptr->size = 0;
  2523. real_ptr->data.clear();
  2524. break;
  2525. }
  2526. case DATA_STRUCT_EQ2_16BIT_STRING: {
  2527. EQ2_16BitString* real_ptr = (EQ2_16BitString*)ptr;
  2528. real_ptr->size = 0;
  2529. real_ptr->data.clear();
  2530. break;
  2531. }
  2532. case DATA_STRUCT_EQ2_32BIT_STRING: {
  2533. EQ2_32BitString* real_ptr = (EQ2_32BitString*)ptr;
  2534. real_ptr->size = 0;
  2535. real_ptr->data.clear();
  2536. break;
  2537. }
  2538. case DATA_STRUCT_EQUIPMENT: {
  2539. memset(ptr, 0, sizeof(EQ2_EquipmentItem) * ds->GetLength());
  2540. break;
  2541. }
  2542. case DATA_STRUCT_DOUBLE: {
  2543. memset(ptr, 0, sizeof(double) * ds->GetLength());
  2544. break;
  2545. }
  2546. case DATA_STRUCT_FLOAT: {
  2547. memset(ptr, 0, sizeof(float) * ds->GetLength());
  2548. break;
  2549. }
  2550. case DATA_STRUCT_INT8: {
  2551. memset(ptr, 0, sizeof(int8) * ds->GetLength());
  2552. break;
  2553. }
  2554. case DATA_STRUCT_INT16: {
  2555. memset(ptr, 0, sizeof(int16) * ds->GetLength());
  2556. break;
  2557. }
  2558. case DATA_STRUCT_INT32: {
  2559. memset(ptr, 0, sizeof(int32) * ds->GetLength());
  2560. break;
  2561. }
  2562. case DATA_STRUCT_INT64: {
  2563. memset(ptr, 0, sizeof(int64) * ds->GetLength());
  2564. break;
  2565. }
  2566. case DATA_STRUCT_SINT8: {
  2567. memset(ptr, 0, sizeof(sint8) * ds->GetLength());
  2568. break;
  2569. }
  2570. case DATA_STRUCT_SINT16: {
  2571. memset(ptr, 0, sizeof(sint16) * ds->GetLength());
  2572. break;
  2573. }
  2574. case DATA_STRUCT_SINT32: {
  2575. memset(ptr, 0, sizeof(sint32) * ds->GetLength());
  2576. break;
  2577. }
  2578. case DATA_STRUCT_SINT64: {
  2579. memset(ptr, 0, sizeof(sint64) * ds->GetLength());
  2580. break;
  2581. }
  2582. case DATA_STRUCT_ITEM: {
  2583. memset(ptr, 0, 10000 * ds->GetLength());
  2584. break;
  2585. }
  2586. case DATA_STRUCT_CHAR: {
  2587. memset(ptr, 0, sizeof(char) * ds->GetLength());
  2588. break;
  2589. }
  2590. case DATA_STRUCT_COLOR: {
  2591. memset(ptr, 0, sizeof(EQ2_Color) * ds->GetLength());
  2592. break;
  2593. }
  2594. }
  2595. }
  2596. vector<PacketStruct*>::iterator itr2;
  2597. for (itr2 = arrays.begin(); itr2 != arrays.end(); itr2++)
  2598. (*itr2)->ResetData();
  2599. }
  2600. #endif