9
3

PacketStruct.cpp 82 KB

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