PacketStruct.cpp 82 KB

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