EnemyFile.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. #include "EnemyFile.h"
  2. #include "FFVIIString.h"
  3. #include "../../common/Logger.h"
  4. Ogre::String
  5. ElementIdToString( const int element_id )
  6. {
  7. switch( element_id )
  8. {
  9. case 0x00: return "Fire";
  10. case 0x02: return "Lighting";
  11. case 0x03: return "Earth";
  12. case 0x05: return "Gravity";
  13. case 0x07: return "Wind";
  14. case 0x0b: return "Hit";
  15. case 0x0c: return "Punch";
  16. case 0x0d: return "Shoot";
  17. }
  18. return "UnknownElement0x" + HexToString( element_id, 4, '0' );
  19. }
  20. Ogre::String
  21. ElementEffectIdToString( const int effect_id )
  22. {
  23. switch( effect_id )
  24. {
  25. case 0x02: return "DoubleDamage";
  26. case 0x05: return "Nullify";
  27. }
  28. return "UnknownElementEffect0x" + HexToString( effect_id, 4, '0' );
  29. }
  30. Ogre::String
  31. StatusIdToString( const int status_id )
  32. {
  33. switch( status_id )
  34. {
  35. case 0x00: return "Death";
  36. case 0x02: return "Sleep";
  37. case 0x03: return "Poison";
  38. case 0x04: return "Sadness";
  39. case 0x05: return "Fury";
  40. case 0x06: return "Confusion";
  41. case 0x07: return "Silence";
  42. case 0x0a: return "Stop";
  43. case 0x0b: return "Frog";
  44. case 0x0c: return "Small";
  45. case 0x15: return "DeathSentence";
  46. case 0x19: return "Paralysis";
  47. case 0x1a: return "Darkness";
  48. }
  49. return "UnknownStatusId0x" + HexToString( status_id, 4, '0' );
  50. }
  51. Ogre::String
  52. ItemIdToString( const int item_id )
  53. {
  54. switch( item_id )
  55. {
  56. case 0x00: return "Potion";
  57. case 0x03: return "Ether";
  58. case 0x14: return "Grenade";
  59. }
  60. return "UnknownItemId0x" + HexToString( item_id, 4, '0' );
  61. }
  62. Ogre::String
  63. AttackIdToString( const int attack_id )
  64. {
  65. switch( attack_id )
  66. {
  67. case 0x001b: return "Fire";
  68. case 0x0110: return "MachineGun";
  69. case 0x0111: return "Tonfa";
  70. case 0x0112: return "Bite";
  71. case 0x0113: return "Tentacle";
  72. case 0x0114: return "Drilldrive";
  73. case 0x0115: return "Handclaw";
  74. case 0x0116: return "BeamGun";
  75. case 0x0117: return "LaserCannon";
  76. case 0x0118: return "WMachineGun";
  77. case 0x0119: return "SmokeShot";
  78. case 0x011a: return "Rifle";
  79. case 0x011b: return "ScorpionTail";
  80. case 0x011c: return "SearchScope";
  81. case 0x011d: return "Rifle";
  82. case 0x011e: return "TailLaser";
  83. case 0x011f: return "Empty0x11f";
  84. case 0x0120: return "Empty0x120";
  85. }
  86. return "UnknownAttackId0x" + HexToString( attack_id, 4, '0' );
  87. }
  88. Ogre::String
  89. StageIdToFileName( const int stage_id )
  90. {
  91. switch( stage_id )
  92. {
  93. case 0x09: return "sector_1_train_station";
  94. case 0x0c: return "reactor_1_entrance";
  95. }
  96. return "UnknownStageId0x" + HexToString( stage_id, 4, '0' );
  97. }
  98. EnemyFile::EnemyFile( const Ogre::String &file ):
  99. File( file )
  100. {
  101. DumpData();
  102. }
  103. EnemyFile::EnemyFile( File *file, const u32 &offset, const u32 &length ):
  104. File( file, offset, length )
  105. {
  106. DumpData();
  107. }
  108. EnemyFile::EnemyFile( u8* buffer, const u32 &offset, const u32 &length ):
  109. File( buffer, offset, length )
  110. {
  111. DumpData();
  112. }
  113. EnemyFile::EnemyFile( File *file ):
  114. File( file )
  115. {
  116. DumpData();
  117. }
  118. EnemyFile::~EnemyFile()
  119. {
  120. }
  121. void
  122. EnemyFile::DumpData()
  123. {
  124. Logger* export_text = new Logger( "enemy.lua" );
  125. bool added = false;
  126. int enemy_data_offset = 0x0298;
  127. int enemy_ai_offset = 0x0e80;
  128. for( int k = 0 ; k < 3; ++k )
  129. {
  130. if( GetU16LE( k * 0x02 ) == 0xffff )
  131. {
  132. continue;
  133. }
  134. FFVIIString name;
  135. name.resize( 32 );
  136. std::copy( buffer_ + enemy_data_offset + k * 184, buffer_ + enemy_data_offset + k * 184 + 0x20, name.begin() );
  137. Ogre::String r_name = FFVIIStringToString( name );
  138. export_text->Log( "-- " + Ogre::String( r_name.c_str() ) + "(" + IntToString( GetU16LE( k * 0x02 ) ) + ")\n" );
  139. export_text->Log( Ogre::String( r_name.c_str() ) + "= {\n" );
  140. export_text->Log( " max_hp = " + IntToString( GetU32LE( enemy_data_offset + k * 184 + 0xa4 ) ) + ",\n" );
  141. export_text->Log( " max_mp = " + IntToString( GetU16LE( enemy_data_offset + k * 184 + 0x9c ) ) + ",\n" );
  142. export_text->Log( "\n" );
  143. export_text->Log( " level = " + IntToString( GetU8( enemy_data_offset + k * 184 + 0x20 ) ) + ",\n" );
  144. export_text->Log( " physical_power = " + IntToString( GetU8( enemy_data_offset + k * 184 + 0x24 ) ) + ",\n" );
  145. export_text->Log( " physical_defense = " + IntToString( GetU8( enemy_data_offset + k * 184 + 0x25 ) ) + ",\n" );
  146. export_text->Log( " physical_dodge = " + IntToString( GetU8( enemy_data_offset + k * 184 + 0x23 ) ) + ",\n" );
  147. export_text->Log( " magic_power = " + IntToString( GetU8( enemy_data_offset + k * 184 + 0x26 ) ) + ",\n" );
  148. export_text->Log( " magic_defense = " + IntToString( GetU8( enemy_data_offset + k * 184 + 0x27 ) ) + ",\n" );
  149. export_text->Log( " speed = " + IntToString( GetU8( enemy_data_offset + k * 184 + 0x21 ) ) + ",\n" );
  150. export_text->Log( " luck = " + IntToString( GetU8( enemy_data_offset + k * 184 + 0x22 ) ) + ",\n" );
  151. export_text->Log( "\n" );
  152. export_text->Log( " back_damage_multiplier = " + FloatToString( GetU8( enemy_data_offset + k * 184 + 0xa2 ) / 8.0f ) + ",\n" );
  153. export_text->Log( "\n" );
  154. export_text->Log( " morph_item = " + ItemIdToString( GetU16LE( enemy_data_offset + k * 184 + 0xa0 ) ) + ",\n" );
  155. export_text->Log( "\n" );
  156. export_text->Log( " reward_exp = " + IntToString( GetU32LE( enemy_data_offset + k * 184 + 0xa8 ) ) + ",\n" );
  157. export_text->Log( " reward_ap = " + IntToString( GetU16LE( enemy_data_offset + k * 184 + 0x9e ) ) + ",\n" );
  158. export_text->Log( " reward_gil = " + IntToString( GetU32LE( enemy_data_offset + k * 184 + 0xac ) ) + ",\n" );
  159. export_text->Log( "\n" );
  160. export_text->Log( " reward_items_drop = {" );
  161. added = false;
  162. for( int l = 0; l < 4; ++l )
  163. {
  164. u8 rate = GetU8( enemy_data_offset + k * 184 + 0x88 + l );
  165. u16 item_id = GetU16LE( enemy_data_offset + k * 184 + 0x8c + l * 0x02 );
  166. if( item_id != 65535 && rate < 0x80 )
  167. {
  168. added = true;
  169. export_text->Log( "\n " + ItemIdToString( item_id ) + " = " + IntToString( rate ) + "," );
  170. }
  171. if( added == true && l == 3 )
  172. {
  173. export_text->Log( "\n " );
  174. }
  175. }
  176. export_text->Log( "},\n");
  177. export_text->Log( "\n" );
  178. export_text->Log( " elements = {" );
  179. bool added = false;
  180. for( int l = 0; l < 8; ++l )
  181. {
  182. int element_id = GetU8( enemy_data_offset + k * 184 + 0x28 + l );
  183. if( element_id != 255 )
  184. {
  185. added = true;
  186. int effect = GetU8( enemy_data_offset + k * 184 + 0x30 + l );
  187. export_text->Log( "\n " + ElementIdToString( element_id ) + " = \"" + ElementEffectIdToString( effect ) + "\"," );
  188. }
  189. if( added == true && l == 7 )
  190. {
  191. export_text->Log( "\n " );
  192. }
  193. }
  194. export_text->Log( "},\n");
  195. export_text->Log( "\n" );
  196. u32 status_immunes = GetU32LE( enemy_data_offset + k * 184 + 0xb0 );
  197. export_text->Log( " status_immunes = {" );
  198. added = false;
  199. for( int l = 0; l < 32; ++l )
  200. {
  201. if( ( ( status_immunes >> l ) & 1 ) == 0 )
  202. {
  203. added = true;
  204. export_text->Log( "\n " + StatusIdToString( l ) + "," );
  205. }
  206. if( added == true && l == 31 )
  207. {
  208. export_text->Log( "\n " );
  209. }
  210. }
  211. export_text->Log( "},\n");
  212. export_text->Log( "\n" );
  213. export_text->Log( " attacks = {" );
  214. added = false;
  215. for( int l = 0; l < 16; ++l )
  216. {
  217. int script_id = GetU8( enemy_data_offset + k * 184 + 0x38 + l );
  218. int attack_id = GetU16LE( enemy_data_offset + k * 184 + 0x48 + l * 0x02 );
  219. int camera_movement = GetU16LE( enemy_data_offset + k * 184 + 0x68 + l * 0x02 );
  220. if( attack_id != 65535 )
  221. {
  222. added = true;
  223. if( l != 0 )
  224. {
  225. export_text->Log( "," );
  226. }
  227. export_text->Log( "\n " + AttackIdToString( attack_id ) + " = {" );
  228. bool ext_added = false;
  229. if( script_id != 255 )
  230. {
  231. ext_added = true;
  232. export_text->Log( "\n script_id = " + IntToString( script_id ) + "," );
  233. }
  234. if( camera_movement != 65535 )
  235. {
  236. ext_added = true;
  237. export_text->Log( "\n camera_movement = " + IntToString( camera_movement ) + "," );
  238. }
  239. if( ext_added == true )
  240. {
  241. export_text->Log( "\n " );
  242. }
  243. export_text->Log( "}" );
  244. }
  245. if( added == true && l == 15 )
  246. {
  247. export_text->Log( "\n " );
  248. }
  249. }
  250. export_text->Log( "},\n");
  251. export_text->Log( "\n" );
  252. export_text->Log( " items_steal = {" );
  253. added = false;
  254. for( int l = 0; l < 4; ++l )
  255. {
  256. u8 rate = GetU8( enemy_data_offset + k * 184 + 0x88 + l );
  257. u16 item_id = GetU16LE( enemy_data_offset + k * 184 + 0x8c + l * 0x02 );
  258. if( item_id != 65535 && rate >= 0x80 )
  259. {
  260. added = true;
  261. export_text->Log( "\n " + ItemIdToString( item_id ) + " = " + IntToString( rate - 0x80 ) + "," );
  262. }
  263. if( added == true && l == 3 )
  264. {
  265. export_text->Log( "\n " );
  266. }
  267. }
  268. export_text->Log( "},\n");
  269. export_text->Log( "\n" );
  270. int berserk = GetU16LE( enemy_data_offset + k * 184 + 0x94 );
  271. if( berserk != 65535 )
  272. {
  273. export_text->Log( " berserk_attack = " + AttackIdToString( berserk ) + ",\n\n" );
  274. }
  275. export_text->Log( " manipulate_attacks = {");
  276. added = false;
  277. for( int l = 0; l < 3; ++l )
  278. {
  279. int attack_id = GetU16LE( enemy_data_offset + k * 184 + 0x94 + l * 0x02 );
  280. if( attack_id != 65535 )
  281. {
  282. added = true;
  283. export_text->Log( "\n " + AttackIdToString( attack_id ) + "," );
  284. }
  285. if( added == true && l == 2 )
  286. {
  287. export_text->Log( "\n " );
  288. }
  289. }
  290. export_text->Log( "},\n");
  291. //export_text->Log( "\n unknown_0x9a = \"0x" + HexToString( GetU16LE( enemy_data_offset + k * 184 + 0x9a ), 4, '0' ) + ",\n" );
  292. /*
  293. LOGGER->Log("AI:\n");
  294. int ai_offset = enemy_ai_offset + GetU16LE(enemy_ai_offset + k * 2);
  295. for (int l = 0; l < 0x10; ++l)
  296. {
  297. u16 local_script_offset = GetU16LE(ai_offset + l * 2);
  298. if (local_script_offset == 0xFFFF)
  299. {
  300. continue;
  301. }
  302. LOGGER->Log("script %x:\n", l);
  303. int script_offset = ai_offset + local_script_offset;
  304. int pointer = 0;
  305. bool run = true;
  306. for (; run == true;)
  307. {
  308. u8 opcode = GetU8(script_offset + pointer);
  309. u8 opcode_h = opcode >> 4;
  310. u8 opcode_l = opcode & 0xF;
  311. LOGGER->Log("0x%04x ", pointer);
  312. if (GetU8(script_offset + pointer + 0) == 0x00 &&
  313. GetU8(script_offset + pointer + 3) == 0x52 &&
  314. GetU8(script_offset + pointer + 4) == 0x70)
  315. {
  316. int address1 = GetU16LE(script_offset + pointer + 1) >> 3;
  317. int bits1 = GetU16LE(script_offset + pointer + 1) & 7;
  318. int jump = GetU16LE(script_offset + pointer + 5);
  319. LOGGER->Log("JumpIfTrue(bit[0x%04x + 0x%02x])(0x%04x);\n", address1, bits1, jump);
  320. pointer += 7;
  321. continue;
  322. }
  323. if (GetU8(script_offset + pointer + 0) == 0x01 &&
  324. GetU8(script_offset + pointer + 3) == 0x52 &&
  325. GetU8(script_offset + pointer + 4) == 0x70)
  326. {
  327. int address1 = GetU16LE(script_offset + pointer + 1) >> 3;
  328. int bits1 = GetU16LE(script_offset + pointer + 1) & 7;
  329. int jump = GetU16LE(script_offset + pointer + 5);
  330. LOGGER->Log("JumpIfTrue(b[0x%04x + 0x%02x])(0x%04x);\n", address1, bits1, jump);
  331. pointer += 7;
  332. continue;
  333. }
  334. if (GetU8(script_offset + pointer + 0) == 0x00 &&
  335. GetU8(script_offset + pointer + 3) == 0x70)
  336. {
  337. int address1 = GetU16LE(script_offset + pointer + 1) >> 3;
  338. int bits1 = GetU16LE(script_offset + pointer + 1) & 7;
  339. int jump = GetU16LE(script_offset + pointer + 4);
  340. LOGGER->Log("JumpIfFalse(bit[0x%04x + 0x%02x])(0x%04x);\n", address1, bits1, jump);
  341. pointer += 6;
  342. continue;
  343. }
  344. if (GetU8(script_offset + pointer + 0) == 0x01 &&
  345. GetU8(script_offset + pointer + 3) == 0x60 &&
  346. GetU8(script_offset + pointer + 5) == 0x35 &&
  347. GetU8(script_offset + pointer + 6) == 0x60 &&
  348. GetU8(script_offset + pointer + 8) == 0x40 &&
  349. GetU8(script_offset + pointer + 9) == 0x70)
  350. {
  351. int address1 = GetU16LE(script_offset + pointer + 1) >> 3;
  352. int bits1 = GetU16LE(script_offset + pointer + 1) & 7;
  353. int value1 = GetU8(script_offset + pointer + 4);
  354. int value2 = GetU8(script_offset + pointer + 7);
  355. int jump = GetU16LE(script_offset + pointer + 10);
  356. LOGGER->Log("JumpIf((b[0x%04x + 0x%02x] & 0x%02x) != 0x%02x)(0x%04x);\n", address1, bits1, value1, value2, jump);
  357. pointer += 12;
  358. continue;
  359. }
  360. if (GetU8(script_offset + pointer + 0) == 0x02 &&
  361. GetU8(script_offset + pointer + 1) == 0x60 &&
  362. GetU8(script_offset + pointer + 2) == 0x20 &&
  363. GetU8(script_offset + pointer + 3) == 0x00 &&
  364. GetU8(script_offset + pointer + 4) == 0x26 &&
  365. GetU8(script_offset + pointer + 5) == 0x40 &&
  366. GetU8(script_offset + pointer + 6) == 0x80 &&
  367. GetU8(script_offset + pointer + 7) == 0x60 &&
  368. GetU8(script_offset + pointer + 8) == 0x00 &&
  369. GetU8(script_offset + pointer + 9) == 0x40 &&
  370. GetU8(script_offset + pointer + 10) == 0x70)
  371. {
  372. int address = GetU16LE(script_offset + pointer + 11);
  373. LOGGER->Log("JumpIfSelfNotInFrontRow(0x%04x);\n", address);
  374. pointer += 13;
  375. continue;
  376. }
  377. if (GetU8(script_offset + pointer + 0) == 0x02 &&
  378. GetU8(script_offset + pointer + 1) == 0x80 &&
  379. GetU8(script_offset + pointer + 2) == 0x20 &&
  380. GetU8(script_offset + pointer + 3) == 0x00 &&
  381. GetU8(script_offset + pointer + 4) == 0x26 &&
  382. GetU8(script_offset + pointer + 5) == 0x40 &&
  383. GetU8(script_offset + pointer + 6) == 0x80 &&
  384. GetU8(script_offset + pointer + 7) == 0x60 &&
  385. GetU8(script_offset + pointer + 8) == 0x00 &&
  386. GetU8(script_offset + pointer + 9) == 0x40 &&
  387. GetU8(script_offset + pointer + 10) == 0x70)
  388. {
  389. int address = GetU16LE(script_offset + pointer + 11);
  390. LOGGER->Log("JumpIfNotAllFriendsInFrontRow(0x%04x);\n", address);
  391. pointer += 13;
  392. continue;
  393. }
  394. if (GetU8(script_offset + pointer + 0) == 0x02 &&
  395. GetU8(script_offset + pointer + 1) == 0x80 &&
  396. GetU8(script_offset + pointer + 2) == 0x20 &&
  397. GetU8(script_offset + pointer + 3) == 0x00 &&
  398. GetU8(script_offset + pointer + 4) == 0x26 &&
  399. GetU8(script_offset + pointer + 5) == 0x40 &&
  400. GetU8(script_offset + pointer + 6) == 0x80 &&
  401. GetU8(script_offset + pointer + 7) == 0x60 &&
  402. GetU8(script_offset + pointer + 8) == 0x01 &&
  403. GetU8(script_offset + pointer + 9) == 0x40 &&
  404. GetU8(script_offset + pointer + 10) == 0x70)
  405. {
  406. int address = GetU16LE(script_offset + pointer + 11);
  407. LOGGER->Log("JumpIfNotAllFriendsInBackRow(0x%04x);\n", address);
  408. pointer += 13;
  409. continue;
  410. }
  411. if (GetU8(script_offset + pointer + 0) == 0x02 &&
  412. GetU8(script_offset + pointer + 1) == 0xA0 &&
  413. GetU8(script_offset + pointer + 2) == 0x20 &&
  414. GetU8(script_offset + pointer + 3) == 0x00 &&
  415. GetU8(script_offset + pointer + 4) == 0x26 &&
  416. GetU8(script_offset + pointer + 5) == 0x40 &&
  417. GetU8(script_offset + pointer + 6) == 0x80 &&
  418. GetU8(script_offset + pointer + 7) == 0x60 &&
  419. GetU8(script_offset + pointer + 8) == 0x00 &&
  420. GetU8(script_offset + pointer + 9) == 0x40 &&
  421. GetU8(script_offset + pointer + 10) == 0x70)
  422. {
  423. int address = GetU16LE(script_offset + pointer + 11);
  424. LOGGER->Log("JumpIfNotAllOpponentsInFrontRow(0x%04x);\n", address);
  425. pointer += 13;
  426. continue;
  427. }
  428. if (GetU8(script_offset + pointer + 0) == 0x02 &&
  429. GetU8(script_offset + pointer + 1) == 0xA0 &&
  430. GetU8(script_offset + pointer + 2) == 0x20 &&
  431. GetU8(script_offset + pointer + 3) == 0x00 &&
  432. GetU8(script_offset + pointer + 4) == 0x26 &&
  433. GetU8(script_offset + pointer + 5) == 0x40 &&
  434. GetU8(script_offset + pointer + 6) == 0x80 &&
  435. GetU8(script_offset + pointer + 7) == 0x60 &&
  436. GetU8(script_offset + pointer + 8) == 0x01 &&
  437. GetU8(script_offset + pointer + 9) == 0x40 &&
  438. GetU8(script_offset + pointer + 10) == 0x70)
  439. {
  440. int address = GetU16LE(script_offset + pointer + 11);
  441. LOGGER->Log("JumpIfNotAllOpponentsInBackRow(0x%04x);\n", address);
  442. pointer += 13;
  443. continue;
  444. }
  445. if (GetU8(script_offset + pointer + 0) == 0x02 &&
  446. GetU8(script_offset + pointer + 1) == 0xA0 &&
  447. GetU8(script_offset + pointer + 2) == 0x20 &&
  448. GetU8(script_offset + pointer + 3) == 0x00 &&
  449. GetU8(script_offset + pointer + 4) == 0x1a &&
  450. GetU8(script_offset + pointer + 5) == 0x40 &&
  451. GetU8(script_offset + pointer + 6) == 0x80 &&
  452. GetU8(script_offset + pointer + 7) == 0x60 &&
  453. GetU8(script_offset + pointer + 8) == 0x00 &&
  454. GetU8(script_offset + pointer + 9) == 0x40 &&
  455. GetU8(script_offset + pointer + 10) == 0x70)
  456. {
  457. int address = GetU16LE(script_offset + pointer + 11);
  458. LOGGER->Log("JumpIfAllOpponentsInDarknessStatus(0x%04x);\n", address);
  459. pointer += 13;
  460. continue;
  461. }
  462. if ((GetU8(script_offset + pointer + 0) == 0x10 || GetU8(script_offset + pointer + 0) == 0x11 || GetU8(script_offset + pointer + 0) == 0x12) &&
  463. GetU8(script_offset + pointer + 3) == 0x60 &&
  464. GetU8(script_offset + pointer + 5) == 0x90)
  465. {
  466. int address = GetU16LE(script_offset + pointer + 1) >> 3;
  467. int bits = GetU16LE(script_offset + pointer + 1) & 7;
  468. int value = GetU8(script_offset + pointer + 4);
  469. LOGGER->Log("[0x%04x + 0x%02x] = b(0x%02x);\n", address, bits, value);
  470. pointer += 6;
  471. continue;
  472. }
  473. if ((GetU8(script_offset + pointer + 0) == 0x10 || GetU8(script_offset + pointer + 0) == 0x11 || GetU8(script_offset + pointer + 0) == 0x12) &&
  474. GetU8(script_offset + pointer + 3) == 0x61 &&
  475. GetU8(script_offset + pointer + 6) == 0x90)
  476. {
  477. int address = GetU16LE(script_offset + pointer + 1) >> 3;
  478. int bits = GetU16LE(script_offset + pointer + 1) & 7;
  479. int value = GetU16LE(script_offset + pointer + 4);
  480. LOGGER->Log("[0x%04x + 0x%02x] = h(0x%04x);\n", address, bits, value);
  481. pointer += 7;
  482. continue;
  483. }
  484. if ((GetU8(script_offset + pointer + 0) == 0x10 || GetU8(script_offset + pointer + 0) == 0x11 || GetU8(script_offset + pointer + 0) == 0x12) &&
  485. GetU8(script_offset + pointer + 3) == 0x62 &&
  486. GetU8(script_offset + pointer + 7) == 0x90)
  487. {
  488. int address = GetU16LE(script_offset + pointer + 1) >> 3;
  489. int bits = GetU16LE(script_offset + pointer + 1) & 7;
  490. int value = (GetU16LE(script_offset + pointer + 4) << 1) | GetU8(script_offset + pointer + 6);
  491. LOGGER->Log("[0x%04x + 0x%02x] = w(0x%08x);\n", address, bits, value);
  492. pointer += 8;
  493. continue;
  494. }
  495. if (GetU8(script_offset + pointer + 0) == 0x11 &&
  496. GetU8(script_offset + pointer + 3) == 0x01 &&
  497. GetU8(script_offset + pointer + 6) == 0x60 &&
  498. GetU8(script_offset + pointer + 8) == 0x35 &&
  499. GetU8(script_offset + pointer + 9) == 0x90)
  500. {
  501. int address1 = GetU16LE(script_offset + pointer + 1) >> 3;
  502. int bits1 = GetU16LE(script_offset + pointer + 1) & 7;
  503. int address2 = GetU16LE(script_offset + pointer + 4) >> 3;
  504. int bits2 = GetU16LE(script_offset + pointer + 4) & 7;
  505. int value = GetU8(script_offset + pointer + 7);
  506. LOGGER->Log("[0x%04x + 0x%02x] = b(b[0x%04x + 0x%02x] & 0x%02x);\n", address1, bits1, address2, bits2, value);
  507. pointer += 10;
  508. continue;
  509. }
  510. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  511. GetU8(script_offset + pointer + 3) == 0x02 &&
  512. GetU8(script_offset + pointer + 6) == 0x90)
  513. {
  514. int address1 = GetU16LE(script_offset + pointer + 1) >> 3;
  515. int bits1 = GetU16LE(script_offset + pointer + 1) & 7;
  516. int address2 = GetU16LE(script_offset + pointer + 4) >> 3;
  517. int bits2 = GetU16LE(script_offset + pointer + 4) & 7;
  518. LOGGER->Log("[0x%04x + 0x%02x] = h(h[0x%04x + 0x%02x]);\n", address1, bits1, address2, bits2);
  519. pointer += 7;
  520. continue;
  521. }
  522. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  523. GetU8(script_offset + pointer + 3) == 0x61 &&
  524. GetU8(script_offset + pointer + 6) == 0x90)
  525. {
  526. int address = GetU16LE(script_offset + pointer + 1) >> 3;
  527. int bits = GetU16LE(script_offset + pointer + 1) & 7;
  528. int value = GetU8(script_offset + pointer + 4) | (GetU8(script_offset + pointer + 5) << 8);
  529. LOGGER->Log("[0x%04x + 0x%02x] = h(0x%04x);\n", address, bits, value);
  530. pointer += 7;
  531. continue;
  532. }
  533. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  534. GetU8(script_offset + pointer + 1) == 0x70 &&
  535. GetU8(script_offset + pointer + 2) == 0x20 &&
  536. GetU8(script_offset + pointer + 3) == 0x02 &&
  537. GetU8(script_offset + pointer + 4) == 0xA0 &&
  538. GetU8(script_offset + pointer + 5) == 0x20 &&
  539. GetU8(script_offset + pointer + 6) == 0x00 &&
  540. GetU8(script_offset + pointer + 7) == 0x26 &&
  541. GetU8(script_offset + pointer + 8) == 0x40 &&
  542. GetU8(script_offset + pointer + 9) == 0x80 &&
  543. GetU8(script_offset + pointer + 10) == 0x60 &&
  544. GetU8(script_offset + pointer + 11) == 0x01 &&
  545. GetU8(script_offset + pointer + 12) == 0x40 &&
  546. GetU8(script_offset + pointer + 13) == 0x82 &&
  547. GetU8(script_offset + pointer + 14) == 0x90)
  548. {
  549. LOGGER->Log("SetRandomOpponentInBackRowToAttack();\n");
  550. pointer += 15;
  551. continue;
  552. }
  553. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  554. GetU8(script_offset + pointer + 1) == 0x70 &&
  555. GetU8(script_offset + pointer + 2) == 0x20 &&
  556. GetU8(script_offset + pointer + 3) == 0x02 &&
  557. GetU8(script_offset + pointer + 4) == 0xA0 &&
  558. GetU8(script_offset + pointer + 5) == 0x20 &&
  559. GetU8(script_offset + pointer + 6) == 0x00 &&
  560. GetU8(script_offset + pointer + 7) == 0x26 &&
  561. GetU8(script_offset + pointer + 8) == 0x40 &&
  562. GetU8(script_offset + pointer + 9) == 0x80 &&
  563. GetU8(script_offset + pointer + 10) == 0x60 &&
  564. GetU8(script_offset + pointer + 11) == 0x00 &&
  565. GetU8(script_offset + pointer + 12) == 0x40 &&
  566. GetU8(script_offset + pointer + 13) == 0x82 &&
  567. GetU8(script_offset + pointer + 14) == 0x90)
  568. {
  569. LOGGER->Log("SetRandomOpponentInFrontRowToAttack();\n");
  570. pointer += 15;
  571. continue;
  572. }
  573. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  574. GetU8(script_offset + pointer + 1) == 0x70 &&
  575. GetU8(script_offset + pointer + 2) == 0x20 &&
  576. GetU8(script_offset + pointer + 3) == 0x02 &&
  577. GetU8(script_offset + pointer + 4) == 0xA0 &&
  578. GetU8(script_offset + pointer + 5) == 0x20 &&
  579. GetU8(script_offset + pointer + 6) == 0x03 &&
  580. GetU8(script_offset + pointer + 7) == 0x60 &&
  581. GetU8(script_offset + pointer + 8) == 0x41 &&
  582. GetU8(script_offset + pointer + 9) == 0x80 &&
  583. GetU8(script_offset + pointer + 10) == 0x85 &&
  584. GetU8(script_offset + pointer + 11) == 0x82 &&
  585. GetU8(script_offset + pointer + 12) == 0x90)
  586. {
  587. LOGGER->Log("SetRandomOpponentWithLowestCurrentHP();\n");
  588. pointer += 13;
  589. continue;
  590. }
  591. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  592. GetU8(script_offset + pointer + 1) == 0x70 &&
  593. GetU8(script_offset + pointer + 2) == 0x20 &&
  594. GetU8(script_offset + pointer + 3) == 0x02 &&
  595. GetU8(script_offset + pointer + 4) == 0xA0 &&
  596. GetU8(script_offset + pointer + 5) == 0x20 &&
  597. GetU8(script_offset + pointer + 6) == 0x03 &&
  598. GetU8(script_offset + pointer + 7) == 0x60 &&
  599. GetU8(script_offset + pointer + 8) == 0x41 &&
  600. GetU8(script_offset + pointer + 9) == 0x80 &&
  601. GetU8(script_offset + pointer + 10) == 0x84 &&
  602. GetU8(script_offset + pointer + 11) == 0x82 &&
  603. GetU8(script_offset + pointer + 12) == 0x90)
  604. {
  605. LOGGER->Log("SetRandomOpponentWithHighestCurrentHP();\n");
  606. pointer += 13;
  607. continue;
  608. }
  609. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  610. GetU8(script_offset + pointer + 1) == 0x70 &&
  611. GetU8(script_offset + pointer + 2) == 0x20 &&
  612. GetU8(script_offset + pointer + 3) == 0x02 &&
  613. GetU8(script_offset + pointer + 4) == 0xA0 &&
  614. GetU8(script_offset + pointer + 5) == 0x20 &&
  615. GetU8(script_offset + pointer + 6) == 0x02 &&
  616. GetU8(script_offset + pointer + 7) == 0x10 &&
  617. GetU8(script_offset + pointer + 8) == 0x41 &&
  618. GetU8(script_offset + pointer + 9) == 0x80 &&
  619. GetU8(script_offset + pointer + 10) == 0x85 &&
  620. GetU8(script_offset + pointer + 11) == 0x82 &&
  621. GetU8(script_offset + pointer + 12) == 0x90)
  622. {
  623. LOGGER->Log("SetRandomOpponentWithLowestMagicDefence();\n");
  624. pointer += 13;
  625. continue;
  626. }
  627. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  628. GetU8(script_offset + pointer + 1) == 0x70 &&
  629. GetU8(script_offset + pointer + 2) == 0x20 &&
  630. GetU8(script_offset + pointer + 3) == 0x02 &&
  631. GetU8(script_offset + pointer + 4) == 0xA0 &&
  632. GetU8(script_offset + pointer + 5) == 0x20 &&
  633. GetU8(script_offset + pointer + 6) == 0x02 &&
  634. GetU8(script_offset + pointer + 7) == 0x00 &&
  635. GetU8(script_offset + pointer + 8) == 0x41 &&
  636. GetU8(script_offset + pointer + 9) == 0x80 &&
  637. GetU8(script_offset + pointer + 10) == 0x85 &&
  638. GetU8(script_offset + pointer + 11) == 0x82 &&
  639. GetU8(script_offset + pointer + 12) == 0x90)
  640. {
  641. LOGGER->Log("SetRandomOpponentWithLowestDefence();\n");
  642. pointer += 13;
  643. continue;
  644. }
  645. if (GetU8(script_offset + pointer + 0) == 0x12 &&
  646. GetU8(script_offset + pointer + 1) == 0x70 &&
  647. GetU8(script_offset + pointer + 2) == 0x20 &&
  648. GetU8(script_offset + pointer + 3) == 0x02 &&
  649. GetU8(script_offset + pointer + 4) == 0xA0 &&
  650. GetU8(script_offset + pointer + 5) == 0x20 &&
  651. GetU8(script_offset + pointer + 6) == 0x82 &&
  652. GetU8(script_offset + pointer + 7) == 0x90)
  653. {
  654. LOGGER->Log("SetRandomOpponentToAttack();\n");
  655. pointer += 8;
  656. continue;
  657. }
  658. if (GetU8(script_offset + pointer + 0) == 0x60 &&
  659. GetU8(script_offset + pointer + 2) == 0x02 &&
  660. GetU8(script_offset + pointer + 5) == 0x92)
  661. {
  662. int action = GetU8(script_offset + pointer + 1);
  663. int address1 = GetU16LE(script_offset + pointer + 3) >> 3;
  664. int bits1 = GetU16LE(script_offset + pointer + 3) & 7;
  665. LOGGER->Log("RunCommand(0x%02x, h[0x%04x + 0x%02x]);\n", action, address1, bits1);
  666. pointer += 6;
  667. continue;
  668. }
  669. if (GetU8(script_offset + pointer + 0) == 0x81 &&
  670. GetU8(script_offset + pointer + 1) == 0x01 &&
  671. GetU8(script_offset + pointer + 4) == 0x34 &&
  672. GetU8(script_offset + pointer + 5) == 0x52 &&
  673. GetU8(script_offset + pointer + 6) == 0x70)
  674. {
  675. int address1 = GetU16LE(script_offset + pointer + 2) >> 3;
  676. int bits1 = GetU16LE(script_offset + pointer + 2) & 7;
  677. int jump = GetU16LE(script_offset + pointer + 7);
  678. LOGGER->Log("JumpIfRandomNot(1/b[0x%04x + 0x%02x])(0x%04x);\n", address1, bits1, jump);
  679. pointer += 9;
  680. continue;
  681. }
  682. if (GetU8(script_offset + pointer + 0) == 0x81 &&
  683. GetU8(script_offset + pointer + 1) == 0x60 &&
  684. GetU8(script_offset + pointer + 3) == 0x34 &&
  685. GetU8(script_offset + pointer + 4) == 0x52 &&
  686. GetU8(script_offset + pointer + 5) == 0x70)
  687. {
  688. int value = GetU8(script_offset + pointer + 2);
  689. int jump = GetU16LE(script_offset + pointer + 6);
  690. LOGGER->Log("JumpIfRandomNot(1/0x%02x)(0x%04x);\n", value, jump);
  691. pointer += 8;
  692. continue;
  693. }
  694. switch (opcode)
  695. {
  696. case 0x00:
  697. case 0x01:
  698. case 0x02:
  699. case 0x03:
  700. {
  701. LOGGER->Log("0x%02x LoadValue(0x%04x)\n", opcode, GetU16LE(script_offset + pointer + 1));
  702. pointer += 3;
  703. }
  704. break;
  705. case 0x10:
  706. case 0x11:
  707. case 0x12:
  708. case 0x13:
  709. {
  710. LOGGER->Log("0x%02x PushAddress(0x%04x)\n", opcode, GetU16LE(script_offset + pointer + 1));
  711. pointer += 3;
  712. }
  713. break;
  714. case 0x30:
  715. {
  716. LOGGER->Log("0x%02x MathAdd()\n", opcode);
  717. pointer += 1;
  718. }
  719. break;
  720. case 0x31:
  721. {
  722. LOGGER->Log("0x%02x MathSub()\n", opcode);
  723. pointer += 1;
  724. }
  725. break;
  726. case 0x32:
  727. {
  728. LOGGER->Log("0x%02x MathMul()\n", opcode);
  729. pointer += 1;
  730. }
  731. break;
  732. case 0x33:
  733. {
  734. LOGGER->Log("0x%02x MathDiv()\n", opcode);
  735. pointer += 1;
  736. }
  737. break;
  738. case 0x34:
  739. {
  740. LOGGER->Log("0x%02x MathMod()\n", opcode);
  741. pointer += 1;
  742. }
  743. break;
  744. case 0x35:
  745. {
  746. LOGGER->Log("0x%02x MathAnd()\n", opcode);
  747. pointer += 1;
  748. }
  749. break;
  750. case 0x36:
  751. {
  752. LOGGER->Log("0x%02x MathOr()\n", opcode);
  753. pointer += 1;
  754. }
  755. break;
  756. case 0x37:
  757. {
  758. LOGGER->Log("0x%02x MathNor()\n", opcode);
  759. pointer += 1;
  760. }
  761. break;
  762. case 0x40:
  763. {
  764. LOGGER->Log("0x%02x CompareEqual()\n", opcode);
  765. pointer += 1;
  766. }
  767. break;
  768. case 0x41:
  769. {
  770. LOGGER->Log("0x%02x CompareNotEqual()\n", opcode);
  771. pointer += 1;
  772. }
  773. break;
  774. case 0x42:
  775. {
  776. LOGGER->Log("0x%02x CompareGreaterEqual()\n", opcode);
  777. pointer += 1;
  778. }
  779. break;
  780. case 0x43:
  781. {
  782. LOGGER->Log("0x%02x CompareLessEqual()\n", opcode);
  783. pointer += 1;
  784. }
  785. break;
  786. case 0x44:
  787. {
  788. LOGGER->Log("0x%02x CompareGreater()\n", opcode);
  789. pointer += 1;
  790. }
  791. break;
  792. case 0x45:
  793. {
  794. LOGGER->Log("0x%02x CompareLess()\n", opcode);
  795. pointer += 1;
  796. }
  797. break;
  798. case 0x50:
  799. {
  800. LOGGER->Log("0x%02x LogAnd()\n", opcode);
  801. pointer += 1;
  802. }
  803. break;
  804. case 0x51:
  805. {
  806. LOGGER->Log("0x%02x LogOr()\n", opcode);
  807. pointer += 1;
  808. }
  809. break;
  810. case 0x52:
  811. {
  812. LOGGER->Log("0x%02x LogNot()\n", opcode);
  813. pointer += 1;
  814. }
  815. break;
  816. case 0x60:
  817. {
  818. u32 value = GetU8(script_offset + pointer + 1);
  819. LOGGER->Log("0x%02x PushImmediate(0x%02x)\n", opcode, value);
  820. pointer += 2;
  821. }
  822. break;
  823. case 0x61:
  824. {
  825. u32 value = GetU8(script_offset + pointer + 1) | (GetU8(script_offset + pointer + 2) << 8);
  826. LOGGER->Log("0x%02x PushImmediate(0x%04x)\n", opcode, value);
  827. pointer += 3;
  828. }
  829. break;
  830. case 0x70:
  831. {
  832. LOGGER->Log("0x%02x JumpIfFalse(0x%04x)\n", opcode, GetU16LE(script_offset + pointer + 1));
  833. pointer += 3;
  834. }
  835. break;
  836. case 0x71:
  837. {
  838. LOGGER->Log("0x%02x JumpIfNotEqual(0x%04x)\n", opcode, GetU16LE(script_offset + pointer + 1));
  839. pointer += 3;
  840. }
  841. break;
  842. case 0x72:
  843. {
  844. LOGGER->Log("0x%02x JumpTo(0x%04x)\n", opcode, GetU16LE(script_offset + pointer + 1));
  845. pointer += 3;
  846. }
  847. break;
  848. case 0x73:
  849. {
  850. LOGGER->Log("0x%02x FinishScript()\n", opcode);
  851. run = false;
  852. pointer += 1;
  853. }
  854. break;
  855. case 0x75:
  856. {
  857. LOGGER->Log("0x%02x LinkScriptToOtherPlayer()\n", opcode);
  858. pointer += 1;
  859. }
  860. break;
  861. case 0x80:
  862. {
  863. LOGGER->Log("0x%02x FilterValueByMask()\n", opcode);
  864. pointer += 1;
  865. }
  866. break;
  867. case 0x81:
  868. {
  869. LOGGER->Log("0x%02x MathRandom()\n", opcode);
  870. pointer += 1;
  871. }
  872. break;
  873. case 0x82:
  874. {
  875. LOGGER->Log("0x%02x PickRandomBit()\n", opcode);
  876. pointer += 1;
  877. }
  878. break;
  879. case 0x83:
  880. {
  881. LOGGER->Log("0x%02x CountActiveBits()\n", opcode);
  882. pointer += 1;
  883. }
  884. break;
  885. case 0x84:
  886. {
  887. LOGGER->Log("0x%02x GetHighestMask()\n", opcode);
  888. pointer += 1;
  889. }
  890. break;
  891. case 0x85:
  892. {
  893. LOGGER->Log("0x%02x GetLowestMask()\n", opcode);
  894. pointer += 1;
  895. }
  896. break;
  897. case 0x86:
  898. {
  899. LOGGER->Log("0x%02x GetMPCost()\n", opcode);
  900. pointer += 1;
  901. }
  902. break;
  903. case 0x87:
  904. {
  905. LOGGER->Log("0x%02x SetBit()\n", opcode);
  906. pointer += 1;
  907. }
  908. break;
  909. case 0x90:
  910. {
  911. LOGGER->Log("0x%02x StoreValue()\n", opcode);
  912. pointer += 1;
  913. }
  914. break;
  915. case 0x91:
  916. {
  917. LOGGER->Log("0x%02x Pop()\n", opcode);
  918. pointer += 1;
  919. }
  920. break;
  921. case 0x92:
  922. {
  923. LOGGER->Log("0x%02x RunCommand()\n", opcode);
  924. pointer += 1;
  925. }
  926. break;
  927. case 0x93:
  928. {
  929. LOGGER->Log("0x%02x DisplayText(", opcode);
  930. pointer += 1;
  931. FFVIIString text;
  932. unsigned char letter = GetU8(script_offset + pointer);
  933. while (true)
  934. {
  935. if (letter == 0xea || letter == 0xeb || letter == 0xec || letter == 0xed || letter == 0xee || letter == 0xef || letter == 0xf0 || letter == 0xf1)
  936. {
  937. LOGGER->Log("[variable%02x", letter);
  938. LOGGER->Log("%02x", GetU8(script_offset + pointer + 1));
  939. LOGGER->Log("%02x]", GetU8(script_offset + pointer + 2));
  940. pointer += 3;
  941. }
  942. else
  943. {
  944. LOGGER->Log("%02x", letter);
  945. text.push_back(letter);
  946. pointer += 1;
  947. if (letter == 0xff)
  948. {
  949. break;
  950. }
  951. }
  952. letter = GetU8(script_offset + pointer);
  953. }
  954. RString r_text = FFVIIStringToRString(text);
  955. LOGGER->Log(")(%s)\n", r_text.c_str());
  956. }
  957. break;
  958. case 0x94:
  959. {
  960. LOGGER->Log("0x%02x CopyUnitsData()\n", opcode);
  961. pointer += 1;
  962. }
  963. break;
  964. case 0x95:
  965. {
  966. LOGGER->Log("0x%02x ExchangeByteWithMemory(800f83a4 + 2 <-> memorybank1/2)\n", opcode);
  967. pointer += 1;
  968. }
  969. break;
  970. case 0x96:
  971. {
  972. LOGGER->Log("0x%02x GetUnitsElementalDefense()\n", opcode);
  973. pointer += 1;
  974. }
  975. break;
  976. case 0xA0:
  977. {
  978. LOGGER->Log("0x%02x DebugTextOutput(", opcode);
  979. pointer += 1;
  980. unsigned char pop = GetU8(script_offset + pointer);
  981. pointer += 1;
  982. char letter[2];
  983. letter[1] = 0;
  984. letter[0] = GetU8(script_offset + pointer);
  985. while (letter[0] != 0)
  986. {
  987. LOGGER->Log("%s", letter);
  988. pointer += 1;
  989. letter[0] = GetU8(script_offset + pointer);
  990. }
  991. pointer += 1;
  992. LOGGER->Log(")(pop %d var from stack)\n", pop);
  993. }
  994. break;
  995. default:
  996. {
  997. LOGGER->Log("0x%02x Unknown\n", opcode);
  998. run = false;
  999. }
  1000. }
  1001. }
  1002. LOGGER->Log("\n", l);
  1003. }
  1004. */
  1005. export_text->Log( "},\n\n\n" );
  1006. }
  1007. // <entity_model name="Background" file_name="models/battle/stages/reactor_1.mesh" position="0 0 0" direction="0" />
  1008. // <entity_model name="Mp1" file_name="models/battle/units/mp.mesh" position="-5 2.5 0" direction="0" />
  1009. // <entity_model name="Mp2" file_name="models/battle/units/mp.mesh" position="-5 2.5 0" direction="0" />
  1010. int set_up_1_offset = 0x0008;
  1011. int set_up_2_offset = 0x0058;
  1012. int formation_offset = 0x0118;
  1013. for( int k = 0 ; k < 4; ++k )
  1014. {
  1015. delete export_text;
  1016. export_text = new Logger( "battle_" + IntToString( k ) + ".xml" );
  1017. export_text->Log( "<map>\n" );
  1018. export_text->Log( " <entity_model name=\"Background\" file_name=\"models/ffvii/battle/stages/" + StageIdToFileName( GetU16LE( set_up_1_offset + k * 20 + 0x00 ) ) + ".mesh\" position=\"0 0 0\" direction=\"0\" />\n\n" );
  1019. /*
  1020. LOGGER->Log("unknown: ");
  1021. for (int l = 0; l < 18; ++l)
  1022. {
  1023. LOGGER->Log(" %02x", GetU8(set_up_1_offset + 0x02 + k * 20 + l));
  1024. }
  1025. LOGGER->Log("\n");
  1026. LOGGER->Log("unknown: ");
  1027. for (int l = 0; l < 48; ++l)
  1028. {
  1029. LOGGER->Log(" %02x", GetU8(set_up_2_offset + k * 48 + l));
  1030. }
  1031. LOGGER->Log("\n");
  1032. LOGGER->Log("formation:\n");
  1033. */
  1034. for( int l = 0; l < 6; ++l )
  1035. {
  1036. Ogre::Vector3 position = Ogre::Vector3(
  1037. ( s16 )GetU16LE( formation_offset + k * 96 + l * 16 + 0x02 ),
  1038. ( s16 )GetU16LE( formation_offset + k * 96 + l * 16 + 0x06 ),
  1039. ( s16 )GetU16LE( formation_offset + k * 96 + l * 16 + 0x04 )
  1040. );
  1041. position /= 512.0f;
  1042. export_text->Log( " <entity_model name=\"" + IntToString( ( s16 )GetU16LE( formation_offset + k * 96 + l * 16 + 0x00 ) ) + "\" file_name=\"models/ffvii/battle/stages/" + StageIdToFileName( GetU16LE( set_up_1_offset + k * 20 + 0x00 ) ) + ".mesh\" position=\"" + Ogre::StringConverter::toString( position ) + "\" direction=\"0\" />\n" );
  1043. /*
  1044. xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "row", "%d", GetU16LE(formation_offset + 0x08 + k * 96 + l * 16));
  1045. xmlTextWriterEndElement(writer);
  1046. int enemy_id = (Sint16)GetU16LE(formation_offset + 0x00 + k * 96 + l * 16);
  1047. if (enemy_id != -1)
  1048. {
  1049. LOGGER->Log("Enemy Id %04d\t", (Sint16)GetU16LE(formation_offset + 0x00 + k * 96 + l * 16));
  1050. LOGGER->Log("Position:");
  1051. LOGGER->Log(" x(%04d)", (Sint16)GetU16LE(formation_offset + 0x02 + k * 96 + l * 16));
  1052. LOGGER->Log(" y(%04d)", (Sint16)GetU16LE(formation_offset + 0x04 + k * 96 + l * 16));
  1053. LOGGER->Log(" z(%04d)\t", (Sint16)GetU16LE(formation_offset + 0x06 + k * 96 + l * 16));
  1054. LOGGER->Log("Row %d\t", (Sint16)GetU16LE(formation_offset + 0x08 + k * 96 + l * 16));
  1055. LOGGER->Log("unknown: ");
  1056. for (int l = 0; l < 6; ++l)
  1057. {
  1058. LOGGER->Log(" %02x", GetU8(formation_offset + 0x0A + k * 96 + l * 16));
  1059. }
  1060. LOGGER->Log("\n");
  1061. }
  1062. */
  1063. }
  1064. }
  1065. // attack names and id
  1066. delete export_text;
  1067. export_text = new Logger( "enemy_attacks.lua" );
  1068. int attack_data = 0x04c0;
  1069. int attack_id_offset = 0x0840;
  1070. int attack_names_offset = 0x0880;
  1071. for( int k = 0; k < 32; ++k )
  1072. {
  1073. int attack_id = GetU16LE( attack_id_offset + k * 0x02 );
  1074. if( attack_id != 65535 )
  1075. {
  1076. FFVIIString name;
  1077. name.resize(32);
  1078. std::copy( buffer_ + attack_names_offset + k * 0x20, buffer_ + attack_names_offset + 0x20 + k * 0x20, name.begin() );
  1079. export_text->Log( "-- " + Ogre::String( FFVIIStringToString( name ).c_str() ) + " (" + IntToString( GetU16LE( attack_id_offset + k * 0x02 ) ) + ")\n" );
  1080. export_text->Log( Ogre::String( AttackIdToString( attack_id ) ) + " = {\n" );
  1081. export_text->Log( " mp_cost = " + IntToString( GetU16LE( attack_data + k * 0x1c + 0x04 ) ) + ",\n" );
  1082. export_text->Log( " power = " + FloatToString( GetU8( attack_data + k * 0x1c + 0x0f ) / 16.0f ) + ",\n" );
  1083. export_text->Log( " hit = " + IntToString( GetU8( attack_data + k * 0x1c + 0 ) ) + ",\n" );
  1084. export_text->Log( "\n");
  1085. export_text->Log( " formula = \"0x" + HexToString( GetU8( attack_data + k * 0x1c + 0x0e ), 2, '0' ) + "\",\n" );
  1086. export_text->Log( " target = \"0x" + HexToString( GetU8( attack_data + k * 0x1c + 0x0c ), 2, '0' ) + "\",\n" );
  1087. export_text->Log( " additional_effect = \"0x" + HexToString( GetU8( attack_data + k * 0x1c + 0x12 ), 2, '0' ) + "\",\n" );
  1088. export_text->Log( " additional_effect_modifier = \"0x" + HexToString( GetU8( attack_data + k * 0x1c + 0x13 ), 2, '0' ) + "\",\n" );
  1089. export_text->Log( " special = \"0x" + HexToString( GetU16LE( attack_data + k * 0x1c + 0x1a ), 4, '0' ) + "\",\n" );
  1090. export_text->Log( "\n");
  1091. int restore_type = GetU8( attack_data + k * 0x1c + 0x10 );
  1092. if( restore_type == 0 )
  1093. {
  1094. export_text->Log( " restore_type = \"restore_hp\"\n\n" );
  1095. }
  1096. else if( restore_type == 1 )
  1097. {
  1098. export_text->Log( " restore_type = \"restore_mp\"\n\n" );
  1099. }
  1100. else if( restore_type == 2 )
  1101. {
  1102. export_text->Log( " restore_type = \"restore_status\"\n\n" );
  1103. }
  1104. u16 elements = GetU16LE( attack_data + k * 0x1c + 0x18 );
  1105. export_text->Log( " elements = {" );
  1106. added = false;
  1107. if( elements != 65535 )
  1108. {
  1109. for( int l = 0; l < 16; ++l )
  1110. {
  1111. if( ( ( elements >> l ) & 1 ) != 0 )
  1112. {
  1113. added = true;
  1114. export_text->Log( "\n " + ElementIdToString( l ) + "," );
  1115. }
  1116. if( added == true && l == 15 )
  1117. {
  1118. export_text->Log( "\n " );
  1119. }
  1120. }
  1121. }
  1122. export_text->Log( "},\n\n");
  1123. u8 status_chance = GetU8( attack_data + k * 0x1c + 0x11 );
  1124. u8 status_type = status_chance >> 6;
  1125. status_chance = ( status_chance & 0x3f ) << 2;
  1126. u32 status = GetU32LE( attack_data + k * 0x1c + 0x14 );
  1127. if( status != 0xffffffff )
  1128. {
  1129. if( status_type == 0 )
  1130. {
  1131. export_text->Log( " status_add = {" );
  1132. }
  1133. else if( status_type == 1 )
  1134. {
  1135. export_text->Log( " status_remove = {" );
  1136. }
  1137. else if( status_type == 2 )
  1138. {
  1139. export_text->Log( " status_switch = {" );
  1140. }
  1141. for( int l = 0; l < 32; ++l )
  1142. {
  1143. if( ( ( status >> l ) & 1 ) != 0 )
  1144. {
  1145. export_text->Log( "\n " + StatusIdToString( l ) + "," );
  1146. }
  1147. if( l == 31 )
  1148. {
  1149. export_text->Log( "\n " );
  1150. }
  1151. }
  1152. export_text->Log( "},\n\n");
  1153. }
  1154. export_text->Log( " target_hurt_script_id = " + IntToString( GetU8( attack_data + k * 0x1c + 0x02 ) ) + ",\n" );
  1155. int sound_id = GetU16LE( attack_data + k * 0x1c + 6 );
  1156. if( sound_id != 65535 )
  1157. {
  1158. export_text->Log( " sound_id_normal = " + IntToString( sound_id ) + ",\n" );
  1159. export_text->Log( " sound_id_cricical = " + IntToString( sound_id ) + ",\n" );
  1160. export_text->Log( " sound_id_miss = " + IntToString( sound_id ) + ",\n" );
  1161. }
  1162. int attack_effect_id = GetU8( attack_data + k * 0x1c + 0x0d );
  1163. if( attack_effect_id != 255 )
  1164. {
  1165. export_text->Log( " attack_effect_id = " + IntToString( attack_effect_id ) + ",\n" );
  1166. }
  1167. int impact_effect_id = GetU8( attack_data + k * 0x1c + 0x01 );
  1168. if( impact_effect_id != 255 )
  1169. {
  1170. export_text->Log( " impact_effect_id = " + IntToString( impact_effect_id ) + ",\n" );
  1171. }
  1172. int camera_id = GetU16LE( attack_data + k * 0x1c + 0x08 );
  1173. if( camera_id != 65535 )
  1174. {
  1175. export_text->Log( " camera_id_single = " + IntToString( camera_id ) + ",\n" );
  1176. }
  1177. camera_id = GetU16LE( attack_data + k * 0x1c + 0x0a );
  1178. if( camera_id != 65535 )
  1179. {
  1180. export_text->Log( " camera_id_multiple = " + IntToString( camera_id ) + ",\n" );
  1181. }
  1182. export_text->Log( "},\n\n\n" );
  1183. }
  1184. }
  1185. }