9
3

PacketStruct.cpp 83 KB

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