PacketStruct.cpp 82 KB

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