9
3

PacketStruct.cpp 82 KB

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