ScriptFile.cpp 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133
  1. #include "ScriptFile.h"
  2. #include "../../common/Logger.h"
  3. Logger* export_script;
  4. std::vector< StackItem > stack;
  5. Ogre::String raw_script;
  6. u32 script_offset;
  7. u32 script_pointer;
  8. u32 script_stored_pointer;
  9. u32 script_pointer_end;
  10. u8 control;
  11. ScriptFile::ScriptFile(const Ogre::String &file):
  12. File(file)
  13. {
  14. }
  15. ScriptFile::ScriptFile(File *file, const u32 offset, const u32 length):
  16. File(file, offset, length)
  17. {
  18. }
  19. ScriptFile::ScriptFile(u8* buffer, const u32 offset, const u32 length):
  20. File(buffer, offset, length)
  21. {
  22. }
  23. ScriptFile::ScriptFile(File *file):
  24. File(file)
  25. {
  26. }
  27. ScriptFile::~ScriptFile()
  28. {
  29. }
  30. void
  31. ScriptFile::DumpScripts()
  32. {
  33. export_script = new Logger("scripts.txt");
  34. u32 number_of_entity = GetU8( 0x03 );
  35. for ( int entity = 0; entity < number_of_entity; ++entity )
  36. {
  37. if ( GetU16LE( 0x80 + entity * 0x8 + 0x2) == 0 )
  38. {
  39. continue;
  40. }
  41. export_script->Log( "ENTITY: entity_id = 0x" + HexToString( entity, 2, '0' ) + "\n" );
  42. script_offset = 0x80 + GetU16LE( 0x80 + entity * 0x8 );
  43. u32 number_of_scripts = GetU8(script_offset + 1);
  44. for ( int i = 0; i < number_of_scripts; ++i )
  45. {
  46. raw_script = "";
  47. u16 script_type = GetU16LE( script_offset + 2 + i * 0x4 );
  48. script_pointer = script_offset + 2 + GetU16LE( script_offset + 2 + i * 0x4 + 2 );
  49. script_pointer_end = script_pointer;
  50. export_script->Log( "SCRIPT: script_id = 0x" + HexToString( script_type, 2, '0' ) + "\n" );
  51. //export_script->Log( "script = w[8007aecc];\n" );
  52. //export_script->Log( "mask = 8007ae10;\n" );
  53. for( ; script_pointer <= script_pointer_end; )
  54. {
  55. u8 opcode = GetU8( script_pointer );
  56. raw_script += " " + HexToString( opcode, 2, '0' );
  57. //export_script->Log( "0x" + HexToString( script_pointer, 4, '0' ) + " 0x" + HexToString( script_pointer_end, 4, '0' ) + "\n" );
  58. if( opcode != 0x02 && opcode != 0x03 && opcode != 0x06 && opcode != 0x0b )
  59. {
  60. script_stored_pointer = script_pointer;
  61. }
  62. if( opcode != 0x05 )
  63. {
  64. export_script->Log( "0x" + HexToString( script_stored_pointer, 4, '0' ) );
  65. }
  66. // Jump
  67. if( opcode == 0x01 )
  68. {
  69. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  70. s16 jump = GetU16LE( script_pointer + 1 ) + script_pointer + 3;
  71. AdvanceScript( 0, jump );
  72. script_pointer += 3;
  73. export_script->Log( " JumpTo( 0x" + HexToString( jump, 4, '0' ) + " ); //" + raw_script + "\n" );
  74. raw_script = "";
  75. }
  76. // Jump If False
  77. else if( opcode == 0x02 )
  78. {
  79. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  80. s16 jump = GetU16LE( script_pointer + 1 ) + script_pointer + 3;
  81. AdvanceScript( 3, jump );
  82. export_script->Log(" JumpIf( " + GetStringFromStack() + " == false )To( 0x" + HexToString( jump, 4, '0' ) + " ); //" + raw_script + "\n" );
  83. raw_script = "";
  84. }
  85. // Jump If True
  86. else if( opcode == 0x03 )
  87. {
  88. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  89. s16 jump = GetU16LE( script_pointer + 1 ) + script_pointer + 3;
  90. AdvanceScript( 3, jump );
  91. export_script->Log(" JumpIf( " + GetStringFromStack() + " == true )To( 0x" + HexToString( jump, 4, '0' ) + " ); //" + raw_script + "\n" );
  92. raw_script = "";
  93. }
  94. // Return
  95. else if( opcode == 0x04 )
  96. {
  97. export_script->Log(" Return(); //" + raw_script + "\n" );
  98. raw_script = "";
  99. script_pointer += 1;
  100. }
  101. // StackSubRoutine
  102. else if( opcode == 0x05 )
  103. {
  104. script_stored_pointer = script_pointer;
  105. AdvanceScript( 1 );
  106. StackOpcodeParse();
  107. u8 advance_op = GetU8( script_pointer );
  108. if ( advance_op != 0x02 && advance_op != 0x03 && advance_op != 0x06 && advance_op != 0x0b )
  109. {
  110. export_script->Log( "0x" + HexToString( script_stored_pointer, 4, '0' ) );
  111. export_script->Log( " " + GetStringFromStack() + "; //" + raw_script + "\n" );
  112. raw_script = "";
  113. }
  114. }
  115. else if (opcode == 0x06)
  116. {
  117. AdvanceScript( 1 );
  118. u8 case_option = GetU8( script_pointer );
  119. raw_script += " " + HexToString( case_option, 2, '0' );
  120. u16 default_jump = GetU16LE( script_pointer + 1 ) + script_pointer + 3;
  121. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  122. AdvanceScript( 0, default_jump );
  123. export_script->Log(" JumpSwitch( " + GetStringFromStack() + " )" );
  124. for ( int i = 0; i < case_option; ++i )
  125. {
  126. raw_script += " " + HexToString( GetU8( script_pointer + 3 + i * 4 + 0 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 3 + i * 4 + 1 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 3 + i * 4 + 2 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 3 + i * 4 + 3 ), 2, '0' );
  127. u16 value = GetU16LE( script_pointer + 3 + i * 4 + 0);
  128. u16 jump = GetU16LE( script_pointer + 3 + i * 4 + 2) + script_pointer + 3;
  129. AdvanceScript( 0, jump );
  130. export_script->Log("( case " + HexToString( value, 4, '0' ) + ": jump_to:0x" + HexToString( jump, 4, '0' ) + ")" );
  131. }
  132. export_script->Log("( default: jump_to:0x" + HexToString( default_jump, 4, '0' ) + "); //" + raw_script + "\n" );
  133. raw_script = "";
  134. AdvanceScript( 3 + case_option * 4 );
  135. }
  136. else if( opcode == 0x07 )
  137. {
  138. Ogre::String data1 = HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  139. Ogre::String data2 = HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  140. raw_script += " " + data1 + " " + data2;
  141. AdvanceScript( 3 );
  142. export_script->Log( " InitScriptEntity( entity_id = 0x" + data1 + ", shared_id = 0x" + data2 + " ); //" + raw_script + "\n" );
  143. raw_script = "";
  144. }
  145. else if( opcode == 0x08 )
  146. {
  147. Ogre::String data1 = HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  148. Ogre::String data2 = HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  149. raw_script += " " + data1 + " " + data2;
  150. AdvanceScript( 3 );
  151. export_script->Log( " InitType3Entity( entity_id = 0x" + data1 + ", shared_id = 0x" + data2 + " ); //" + raw_script + "\n" );
  152. raw_script = "";
  153. }
  154. else if( opcode == 0x09 )
  155. {
  156. Ogre::String data1 = HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  157. Ogre::String data2 = HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  158. raw_script += " " + data1 + " " + data2;
  159. AdvanceScript( 3 );
  160. export_script->Log( " InitModelEntity( entity_id = 0x" + data1 + ", shared_id = 0x" + data2 + " ); //" + raw_script + "\n" );
  161. raw_script = "";
  162. }
  163. else if( opcode == 0x0b )
  164. {
  165. AdvanceScript( 1 );
  166. u8 case_option = GetU8( script_pointer );
  167. s16 range_start = GetU16LE( script_pointer + 1 );
  168. u16 default_jump = GetU16LE( script_pointer + 3 ) + script_pointer;
  169. AdvanceScript( 0, default_jump );
  170. raw_script += " " + HexToString( case_option, 2, '0' );
  171. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  172. raw_script += " " + HexToString( GetU8( script_pointer + 3 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 4 ), 2, '0' );
  173. export_script->Log(" JumpSwitch( " + GetStringFromStack() + " )" );
  174. for ( int i = 0; i < case_option; ++i )
  175. {
  176. raw_script += " " + HexToString( GetU8( script_pointer + 5 + i * 2 + 0 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 5 + i * 2 + 1 ), 2, '0' );
  177. u16 jump = GetU16LE( script_pointer + 5 + i * 2) + script_pointer;
  178. AdvanceScript( 0, jump );
  179. export_script->Log("( case 0x" + HexToString( i + range_start, 4, '0' ) + ": jump_to:0x" + HexToString( jump, 4, '0' ) + ")" );
  180. }
  181. export_script->Log("( default: jump_to:0x" + HexToString( default_jump, 4, '0' ) + "); //" + raw_script + "\n" );
  182. raw_script = "";
  183. AdvanceScript( 5 + case_option * 2 );
  184. }/*
  185. // switch in row
  186. else if (opcode == 0x0d)
  187. {
  188. u16 case_option = GetU16LE(script_offset + script_pointer);
  189. s16 range_start = GetU16LE(script_offset + script_pointer + 2);
  190. u16 default_jump = GetU16LE(script_offset + script_pointer + 4);
  191. export_script->Log("\t0x0b_JumpSwitchInRow(range_start:0x%04x)(default:0x%04x)", range_start, script_offset + default_jump + script_pointer + 1);
  192. for (int i = 0; i < case_option; ++i)
  193. {
  194. u16 jump = GetU16LE(script_offset + script_pointer + 6 + i * 2);
  195. export_script->Log("(jump:0x%04x)", script_offset + jump + script_pointer + 1);
  196. }
  197. script_pointer += 6 + case_option * 2;
  198. export_script->Log("; // pop 1 value from stack\n");
  199. }*/
  200. else if( opcode == 0x10 )
  201. {
  202. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  203. control = GetU8( script_pointer + 1 );
  204. AdvanceScript( 2 );
  205. Ogre::String priority = Get8Variable();
  206. Ogre::String entity_id = Get8Variable();
  207. raw_script += " " + HexToString( GetU8( script_pointer ), 2, '0' );
  208. Ogre::String script_id = HexToString( GetU8( script_pointer ), 2, '0' );
  209. AdvanceScript( 1 );
  210. export_script->Log( " RunScriptAsync( priority = " + priority + ", entity_id = " + entity_id + ", script_id = 0x" + script_id + " ); //" + raw_script + "\n" );
  211. raw_script = "";
  212. }
  213. else if( opcode == 0x14 )
  214. {
  215. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  216. control = GetU8( script_pointer + 1 );
  217. AdvanceScript( 2 );
  218. Ogre::String priority = Get8Variable();
  219. Ogre::String entity_id = Get8Variable();
  220. raw_script += " " + HexToString( GetU8( script_pointer ), 2, '0' );
  221. Ogre::String script_id = HexToString( GetU8( script_pointer ), 2, '0' );
  222. AdvanceScript( 1 );
  223. export_script->Log( " RunScriptStartSync( priority = " + priority + ", entity_id = " + entity_id + ", script_id = 0x" + script_id + " ); //" + raw_script + "\n" );
  224. raw_script = "";
  225. }
  226. else if( opcode == 0x1c )
  227. {
  228. Ogre::String data = HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  229. Ogre::String entity_id = HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  230. raw_script += " " + data + " " + entity_id;
  231. AdvanceScript( 3 );
  232. export_script->Log( " MoveScriptToEnd( entity_id = 0x" + entity_id + " ); //" + raw_script + "\n" );
  233. raw_script = "";
  234. }
  235. else if( opcode == 0x1d )
  236. {
  237. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  238. control = GetU8( script_pointer + 1 );
  239. AdvanceScript( 2 );
  240. Ogre::String x = Get16Variable();
  241. Ogre::String z = Get16Variable();
  242. export_script->Log( " SetEntityPositionByXZ( x = " + x + ", z = " + z + " ); //" + raw_script + "\n" );
  243. raw_script = "";
  244. }
  245. else if( opcode == 0x1f )
  246. {
  247. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  248. control = GetU8( script_pointer + 1 );
  249. AdvanceScript( 2 );
  250. Ogre::String window_id = Get8Variable();
  251. Ogre::String style = Get8Variable();
  252. Ogre::String text_id = Get16Variable();
  253. export_script->Log( " WindowSync( window_id = " + window_id + ", style = " + style + ", text_id = " + text_id + " ); //" + raw_script + "\n" );
  254. raw_script = "";
  255. }
  256. else if( opcode == 0x20 )
  257. {
  258. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  259. control = GetU8( script_pointer + 1 );
  260. AdvanceScript( 2 );
  261. Ogre::String window_id = Get8Variable();
  262. Ogre::String style = Get8Variable();
  263. Ogre::String text_id = Get16Variable();
  264. export_script->Log( " WindowAsync( window_id = " + window_id + ", style = " + style + ", text_id = " + text_id + " ); //" + raw_script + "\n" );
  265. raw_script = "";
  266. }
  267. else if( opcode == 0x21 )
  268. {
  269. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  270. control = GetU8( script_pointer + 1 );
  271. AdvanceScript( 2 );
  272. export_script->Log( " 0x21( " + Get8Variable() + " ); //" + raw_script + "\n" );
  273. raw_script = "";
  274. }
  275. else if( opcode == 0x22 )
  276. {
  277. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  278. control = GetU8( script_pointer + 1 );
  279. AdvanceScript( 2 );
  280. export_script->Log( " Wait( " + Get8Variable() + " ); //" + raw_script + "\n" );
  281. raw_script = "";
  282. }
  283. else if( opcode == 0x23 )
  284. {
  285. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  286. control = GetU8( script_pointer + 1 );
  287. AdvanceScript( 2 );
  288. Ogre::String x = Get16Variable();
  289. Ogre::String y = Get16Variable();
  290. export_script->Log( " MoveToPosition( x = " + x + ", y = " + y + " ); //" + raw_script + "\n" );
  291. raw_script = "";
  292. }
  293. else if( opcode == 0x25 )
  294. {
  295. AdvanceScript( 1 );
  296. export_script->Log( " ResetEntityData30_50_63_78(); //" + raw_script + "\n" );
  297. raw_script = "";
  298. }
  299. else if( opcode == 0x26 )
  300. {
  301. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  302. control = GetU8( script_pointer + 1 );
  303. AdvanceScript( 2 );
  304. Ogre::String value = Get8Variable();
  305. export_script->Log( " SetEntityData5c( " + value + " ); //" + raw_script + "\n" );
  306. raw_script = "";
  307. }
  308. else if( opcode == 0x27 )
  309. {
  310. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  311. control = GetU8( script_pointer + 1 );
  312. AdvanceScript( 2 );
  313. export_script->Log( " Set800c9df1( " + Get8Variable() + " ); //" + raw_script + "\n" );
  314. raw_script = "";
  315. }
  316. else if( opcode == 0x29)
  317. {
  318. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  319. control = GetU8( script_pointer + 1 );
  320. AdvanceScript( 2 );
  321. if( control & 0x01 )
  322. {
  323. export_script->Log( "ERROR uexpected situation in opcode 0x29" );
  324. break;
  325. }
  326. raw_script += " " + HexToString( GetU8( script_pointer + 0 ), 2, '0' );
  327. u8 number = GetU8( script_pointer + 0 );
  328. AdvanceScript( 1 );
  329. export_script->Log( " SetDataForType3Entity( number = " + HexToString( number, 2, '0' ) );
  330. for ( int i = 0; i < number; ++i )
  331. {
  332. Ogre::String value1 = Get16Variable();
  333. Ogre::String value2 = Get16Variable();
  334. export_script->Log(", " + value1 + ", " + value2 );
  335. }
  336. export_script->Log(" ); //" + raw_script + "\n" );
  337. raw_script = "";
  338. }
  339. else if( opcode == 0x2a )
  340. {
  341. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  342. control = GetU8( script_pointer + 1 );
  343. AdvanceScript( 2 );
  344. Ogre::String value1 = Get8Variable();
  345. Ogre::String value2 = Get16Variable();
  346. export_script->Log( " 0x2a( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  347. raw_script = "";
  348. }
  349. else if( opcode == 0x2b )
  350. {
  351. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  352. control = GetU8( script_pointer + 1 );
  353. AdvanceScript( 2 );
  354. Ogre::String value = Get16Variable();
  355. export_script->Log( " 0x2b( " + value + " ); //" + raw_script + "\n" );
  356. raw_script = "";
  357. }
  358. else if( opcode == 0x2c )
  359. {
  360. AdvanceScript( 1 );
  361. export_script->Log( " [ script + 0x16ed ] = h( GetCurrentEntityId() ); //" + raw_script + "\n" );
  362. raw_script = "";
  363. }
  364. else if( opcode == 0x2d )
  365. {
  366. AdvanceScript( 1 );
  367. export_script->Log( " 0x2d(); //" + raw_script + "\n" );
  368. raw_script = "";
  369. }
  370. else if( opcode == 0x2e )
  371. {
  372. AdvanceScript( 1 );
  373. export_script->Log( " 0x2e(); //" + raw_script + "\n" );
  374. raw_script = "";
  375. }
  376. else if( opcode == 0x2f )
  377. {
  378. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  379. control = GetU8( script_pointer + 1 );
  380. AdvanceScript( 2 );
  381. Ogre::String value1 = Get16Variable();
  382. Ogre::String value2 = Get8Variable();
  383. export_script->Log( " Set32and34inEntityStruct( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  384. raw_script = "";
  385. }
  386. else if( opcode == 0x33 )
  387. {
  388. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  389. control = GetU8( script_pointer + 1 );
  390. AdvanceScript( 2 );
  391. Ogre::String value = Get16Variable();
  392. export_script->Log( " SetEntityData54( animation_id = " + value + " ); //" + raw_script + "\n" );
  393. raw_script = "";
  394. }
  395. else if( opcode == 0x34 )
  396. {
  397. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  398. control = GetU8( script_pointer + 1 );
  399. AdvanceScript( 2 );
  400. Ogre::String value = Get16Variable();
  401. export_script->Log( " SetEntityData56( animation_id = " + value + " ); //" + raw_script + "\n" );
  402. raw_script = "";
  403. }
  404. else if( opcode == 0x35 )
  405. {
  406. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  407. control = GetU8( script_pointer + 1 );
  408. AdvanceScript( 2 );
  409. Ogre::String value = Get16Variable();
  410. export_script->Log( " SetEntityData58( animation_id = " + value + " ); //" + raw_script + "\n" );
  411. raw_script = "";
  412. }
  413. else if( opcode == 0x36 )
  414. {
  415. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  416. control = GetU8( script_pointer + 1 );
  417. AdvanceScript( 2 );
  418. Ogre::String rot = Get8Variable();
  419. export_script->Log( " SetEntityRotation( rotation = " + rot + " ); //" + raw_script + "\n" );
  420. raw_script = "";
  421. }
  422. else if( opcode == 0x3a )
  423. {
  424. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  425. control = GetU8( script_pointer + 1 );
  426. AdvanceScript( 2 );
  427. Ogre::String entity_id = Get8Variable();
  428. Ogre::String value = Get8Variable();
  429. export_script->Log( " 0x3a( entity_id = " + entity_id + ", " + value + " ); //" + raw_script + "\n" );
  430. raw_script = "";
  431. }
  432. else if( opcode == 0x3d )
  433. {
  434. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  435. control = GetU8( script_pointer + 1 );
  436. AdvanceScript( 2 );
  437. Ogre::String value1 = Get8Variable();
  438. Ogre::String value2 = Get8Variable();
  439. export_script->Log( " SetEntityData60and61( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  440. raw_script = "";
  441. }
  442. else if( opcode == 0x40 )
  443. {
  444. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  445. control = GetU8( script_pointer + 1 );
  446. AdvanceScript( 2 );
  447. Ogre::String animation_id = Get16Variable();
  448. export_script->Log( " PlayEntityAnimation( animation_id = " + animation_id + " ); //" + raw_script + "\n" );
  449. raw_script = "";
  450. }
  451. else if( opcode == 0x41 )
  452. {
  453. AdvanceScript( 1 );
  454. export_script->Log( " WaitUntilAnimationComplete(); //" + raw_script + "\n" );
  455. raw_script = "";
  456. }
  457. else if( opcode == 0x43 )
  458. {
  459. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  460. control = GetU8( script_pointer + 1 );
  461. AdvanceScript( 2 );
  462. Ogre::String entity_id = Get8Variable();
  463. export_script->Log( " InitAdditionalScriptEntityForCurrentEntity( entity_id = " + entity_id + " ); //" + raw_script + "\n" );
  464. raw_script = "";
  465. }
  466. else if( opcode == 0x47 )
  467. {
  468. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  469. control = GetU8( script_pointer + 1 );
  470. AdvanceScript( 2 );
  471. Ogre::String flags = Get8Variable();
  472. export_script->Log( " SetEntityCollisionFlags( flags = " + flags + " ); //" + raw_script + "\n" );
  473. raw_script = "";
  474. }
  475. else if( opcode == 0x48 )
  476. {
  477. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  478. control = GetU8( script_pointer + 1 );
  479. AdvanceScript( 2 );
  480. Ogre::String value1 = Get16Variable();
  481. Ogre::String value2 = Get8Variable();
  482. export_script->Log( " 0x48( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  483. raw_script = "";
  484. }
  485. else if( opcode == 0x4b )
  486. {
  487. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  488. control = GetU8( script_pointer + 1 );
  489. AdvanceScript( 2 );
  490. Ogre::String value = Get8Variable();
  491. Ogre::String solid = Get8Variable();
  492. Ogre::String talk = Get8Variable();
  493. export_script->Log( " SetEntityCollision( " + value + ", solid_radius = " + solid + ", talk_radius = " + talk + " ); //" + raw_script + "\n" );
  494. raw_script = "";
  495. }
  496. else if( opcode == 0x50 )
  497. {
  498. AdvanceScript( 1 );
  499. export_script->Log( " WaitUntilRotationComplete(); //" + raw_script + "\n" );
  500. raw_script = "";
  501. }
  502. else if( opcode == 0x51 )
  503. {
  504. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  505. control = GetU8( script_pointer + 1 );
  506. AdvanceScript( 2 );
  507. Ogre::String entity_id = Get8Variable();
  508. Ogre::String steps = Get8Variable();
  509. export_script->Log( " SetEntityRotateToEntity( entity_id = " + entity_id + ", steps = " + steps + " ); //" + raw_script + "\n" );
  510. raw_script = "";
  511. }
  512. else if( opcode == 0x52 )
  513. {
  514. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  515. control = GetU8( script_pointer + 1 );
  516. AdvanceScript( 2 );
  517. Ogre::String value = Get16Variable();
  518. export_script->Log( " SetEntityData74( " + value + " ); //" + raw_script + "\n" );
  519. raw_script = "";
  520. }
  521. else if( opcode == 0x54 )
  522. {
  523. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  524. control = GetU8( script_pointer + 1 );
  525. AdvanceScript( 2 );
  526. Ogre::String value = Get8Variable();
  527. export_script->Log( " 0x54( " + value + " ); //" + raw_script + "\n" );
  528. raw_script = "";
  529. }
  530. else if( opcode == 0x55 )
  531. {
  532. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  533. control = GetU8( script_pointer + 1 );
  534. AdvanceScript( 2 );
  535. Ogre::String value = Get8Variable();
  536. export_script->Log( " SetEntityData5f( " + value + " ); //" + raw_script + "\n" );
  537. raw_script = "";
  538. }
  539. else if( opcode == 0x56 )
  540. {
  541. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  542. control = GetU8( script_pointer + 1 );
  543. AdvanceScript( 2 );
  544. Ogre::String rotation = Get8Variable();
  545. Ogre::String steps = Get8Variable();
  546. export_script->Log( " SetEntityRotateToRotation( rotation = " + rotation + ", steps = " + steps + " ); //" + raw_script + "\n" );
  547. raw_script = "";
  548. }
  549. else if( opcode == 0x59 )
  550. {
  551. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  552. control = GetU8( script_pointer + 1 );
  553. AdvanceScript( 2 );
  554. Ogre::String value1 = Get8Variable();
  555. Ogre::String value2 = Get8Variable();
  556. Ogre::String value3 = Get8Variable();
  557. Ogre::String value4 = Get8Variable();
  558. export_script->Log( " CallFuncc1368( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + " ); //" + raw_script + "\n" );
  559. raw_script = "";
  560. }
  561. else if( opcode == 0x5b )
  562. {
  563. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  564. control = GetU8( script_pointer + 1 );
  565. AdvanceScript( 2 );
  566. Ogre::String value1 = Get8Variable();
  567. Ogre::String value2 = Get8Variable();
  568. export_script->Log( " CallFuncc142c( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  569. raw_script = "";
  570. }
  571. else if( opcode == 0x61 )
  572. {
  573. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  574. control = GetU8( script_pointer + 1 );
  575. AdvanceScript( 2 );
  576. Ogre::String value1 = Get8Variable();
  577. Ogre::String value2 = Get16Variable();
  578. export_script->Log( " CallFuncc17f0( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  579. raw_script = "";
  580. }
  581. else if( opcode == 0x62 )
  582. {
  583. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  584. control = GetU8( script_pointer + 1 );
  585. AdvanceScript( 2 );
  586. Ogre::String character_id = Get8Variable(); // must be less than 9 or else we must not read next value
  587. Ogre::String value1 = Get8Variable();
  588. export_script->Log( " CharacterSet34Flag00000200( character_id = " + character_id + ", " + value1 + " ); //" + raw_script + "\n" );
  589. raw_script = "";
  590. }
  591. else if( opcode == 0x65 )
  592. {
  593. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  594. control = GetU8( script_pointer + 1 );
  595. AdvanceScript( 2 );
  596. Ogre::String value1 = Get8Variable();
  597. Ogre::String value2 = Get8Variable();
  598. Ogre::String value3 = Get8Variable();
  599. export_script->Log( " CallFuncc18d4( " + value1 + ", " + value2 + ", " + value3 + " ); //" + raw_script + "\n" );
  600. raw_script = "";
  601. }
  602. else if( opcode == 0x66 )
  603. {
  604. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  605. control = GetU8( script_pointer + 1 );
  606. AdvanceScript( 2 );
  607. Ogre::String value1 = Get8Variable();
  608. Ogre::String value2 = Get16Variable();
  609. export_script->Log( " Set8007bba8( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  610. raw_script = "";
  611. }
  612. else if( opcode == 0x67 )
  613. {
  614. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  615. control = GetU8( script_pointer + 1 );
  616. AdvanceScript( 2 );
  617. Ogre::String value1 = Get8Variable();
  618. Ogre::String value2 = Get8Variable();
  619. export_script->Log( " Set16e8and16ea( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  620. raw_script = "";
  621. }
  622. else if( opcode == 0x68 )
  623. {
  624. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  625. control = GetU8( script_pointer + 1 );
  626. AdvanceScript( 2 );
  627. Ogre::String value = Get8Variable();
  628. export_script->Log( " Set8007bbf4( " + value + " ); //" + raw_script + "\n" );
  629. raw_script = "";
  630. }
  631. else if( opcode == 0x6a )
  632. {
  633. AdvanceScript( 1 );
  634. export_script->Log( " Set16f8to1(); //" + raw_script + "\n" );
  635. raw_script = "";
  636. }
  637. else if( opcode == 0x6f )
  638. {
  639. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  640. control = GetU8( script_pointer + 1 );
  641. AdvanceScript( 2 );
  642. Ogre::String value1 = Get16Variable();
  643. Ogre::String value2 = Get16Variable();
  644. Ogre::String value3 = Get8Variable();
  645. Ogre::String value4 = Get8Variable();
  646. export_script->Log( " CallFuncc0df4( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + " ); //" + raw_script + "\n" );
  647. raw_script = "";
  648. }
  649. else if( opcode == 0x75 )
  650. {
  651. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  652. control = GetU8( script_pointer + 1 );
  653. AdvanceScript( 2 );
  654. Ogre::String value1 = Get8Variable();
  655. Ogre::String value2 = Get8Variable();
  656. export_script->Log( " 0x75( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  657. raw_script = "";
  658. }
  659. else if( opcode == 0x7a )
  660. {
  661. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  662. control = GetU8( script_pointer + 1 );
  663. AdvanceScript( 2 );
  664. Ogre::String value = Get16Variable();
  665. export_script->Log( " SetEntityData4c( animation_id = " + value + " ); //" + raw_script + "\n" );
  666. raw_script = "";
  667. }
  668. else if( opcode == 0x7b )
  669. {
  670. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  671. control = GetU8( script_pointer + 1 );
  672. AdvanceScript( 2 );
  673. Ogre::String value = Get16Variable();
  674. export_script->Log( " SetEntityData4e( animation_id = " + value + " ); //" + raw_script + "\n" );
  675. raw_script = "";
  676. }
  677. else if( opcode == 0x7e )
  678. {
  679. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  680. control = GetU8( script_pointer + 1 );
  681. AdvanceScript( 2 );
  682. Ogre::String value1 = Get8Variable();
  683. export_script->Log( " CallFuncc0bcc( " + value1 + " ); //" + raw_script + "\n" );
  684. raw_script = "";
  685. }
  686. else if( opcode == 0x7f )
  687. {
  688. AdvanceScript( 1 );
  689. export_script->Log( " 0x7f(); //" + raw_script + "\n" );
  690. raw_script = "";
  691. }
  692. else if( opcode == 0x80 )
  693. {
  694. AdvanceScript( 1 );
  695. export_script->Log( " 0x80(); //" + raw_script + "\n" );
  696. raw_script = "";
  697. }
  698. else if( opcode == 0x86 )
  699. {
  700. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  701. control = GetU8( script_pointer + 1 );
  702. AdvanceScript( 2 );
  703. Ogre::String value1 = Get8Variable();
  704. Ogre::String value2 = Get8Variable();
  705. Ogre::String value3 = Get8Variable();
  706. Ogre::String value4 = Get8Variable();
  707. export_script->Log( " SetEntityData7c_7d_7e_7f( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + " ); //" + raw_script + "\n" );
  708. raw_script = "";
  709. }
  710. else if( opcode == 0x88 )
  711. {
  712. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  713. control = GetU8( script_pointer + 1 );
  714. AdvanceScript( 2 );
  715. Ogre::String value1 = Get8Variable();
  716. Ogre::String value2 = Get16Variable();
  717. Ogre::String value3 = Get16Variable();
  718. Ogre::String value4 = Get16Variable();
  719. export_script->Log( " CallFuncaba98( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + " ); //" + raw_script + "\n" );
  720. raw_script = "";
  721. }
  722. else if( opcode == 0x8b )
  723. {
  724. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  725. control = GetU8( script_pointer + 1 );
  726. AdvanceScript( 2 );
  727. Ogre::String value1 = Get8Variable();
  728. Ogre::String value2 = Get8Variable();
  729. export_script->Log( " SetEntityData6a_6b( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  730. raw_script = "";
  731. }
  732. else if( opcode == 0x8e )
  733. {
  734. AdvanceScript( 1 );
  735. export_script->Log( " 0x8e(); //" + raw_script + "\n" );
  736. raw_script = "";
  737. }
  738. else if( opcode == 0x8f )
  739. {
  740. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  741. control = GetU8( script_pointer + 1 );
  742. AdvanceScript( 2 );
  743. Ogre::String entity_id = Get8Variable();
  744. Ogre::String value1 = Get8Variable();
  745. Ogre::String value2 = Get8Variable();
  746. Ogre::String value3 = Get8Variable();
  747. export_script->Log( " 0x8f( entity_id = " + entity_id + ", " + value1 + ", " + value2 + ", " + value3 + " ); //" + raw_script + "\n" );
  748. raw_script = "";
  749. }
  750. else if( opcode == 0x90 )
  751. {
  752. AdvanceScript( 1 );
  753. export_script->Log( " [ script + 0x1700 ] = h( -1 ); //" + raw_script + "\n" );
  754. raw_script = "";
  755. }
  756. else if( opcode == 0x92 )
  757. {
  758. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  759. control = GetU8( script_pointer + 1 );
  760. AdvanceScript( 2 );
  761. Ogre::String value1 = Get8Variable();
  762. Ogre::String value2 = Get16Variable();
  763. Ogre::String value3 = Get8Variable();
  764. Ogre::String value4 = Get8Variable();
  765. Ogre::String value5 = Get8Variable();
  766. Ogre::String value6 = Get8Variable();
  767. Ogre::String value7 = Get8Variable();
  768. export_script->Log( " CallFuncc02d0( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + ", " + value5 + ", " + value6 + ", " + value7 + " ); //" + raw_script + "\n" );
  769. raw_script = "";
  770. }
  771. else if( opcode == 0x93 )
  772. {
  773. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  774. control = GetU8( script_pointer + 1 );
  775. AdvanceScript( 2 );
  776. Ogre::String flags = Get8Variable();
  777. export_script->Log( " SetEntityFlagsTo0f( flags = " + flags + " ); //" + raw_script + "\n" );
  778. raw_script = "";
  779. }
  780. else if( opcode == 0x94 )
  781. {
  782. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  783. control = GetU8( script_pointer + 1 );
  784. AdvanceScript( 2 );
  785. Ogre::String value1 = Get16Variable();
  786. Ogre::String value2 = Get8Variable();
  787. Ogre::String value3 = Get8Variable();
  788. export_script->Log( " SetEntityData76_90_91( " + value1 + ", " + value2 + ", " + value3 + " ); //" + raw_script + "\n" );
  789. raw_script = "";
  790. }
  791. else if( opcode == 0x9a )
  792. {
  793. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  794. control = GetU8( script_pointer + 1 );
  795. AdvanceScript( 2 );
  796. Ogre::String value1 = Get16Variable();
  797. Ogre::String value2 = Get8Variable();
  798. export_script->Log( " CallFuncc778c( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  799. raw_script = "";
  800. }
  801. else if( opcode == 0x9c )
  802. {
  803. AdvanceScript( 1 );
  804. export_script->Log( " Play76Animation(); //" + raw_script + "\n" );
  805. raw_script = "";
  806. }
  807. else if( opcode == 0x9d )
  808. {
  809. AdvanceScript( 1 );
  810. export_script->Log( " PlaySomeAnimation(); //" + raw_script + "\n" );
  811. raw_script = "";
  812. }
  813. else if( opcode == 0x9f )
  814. {
  815. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  816. control = GetU8( script_pointer + 1 );
  817. AdvanceScript( 2 );
  818. Ogre::String entity_id = Get8Variable();
  819. Ogre::String value1 = Get8Variable();
  820. Ogre::String value2 = Get8Variable();
  821. Ogre::String value3 = Get8Variable();
  822. export_script->Log( " 0x9f( entity_id = " + entity_id + ", " + value1 + ", " + value2 + ", " + value3 + " ); //" + raw_script + "\n" );
  823. raw_script = "";
  824. }
  825. else if( opcode == 0xa1 )
  826. {
  827. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  828. control = GetU8( script_pointer + 1 );
  829. AdvanceScript( 2 );
  830. Ogre::String x = Get16Variable();
  831. Ogre::String y = Get16Variable();
  832. Ogre::String z = Get16Variable();
  833. export_script->Log( " SetEntityPositionByXYZ( x = " + x + ", y = " + y + ", z = " + z + " ); //" + raw_script + "\n" );
  834. raw_script = "";
  835. }
  836. else if( opcode == 0xa8 )
  837. {
  838. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  839. control = GetU8( script_pointer + 1 );
  840. AdvanceScript( 2 );
  841. Ogre::String value = Get8Variable();
  842. export_script->Log( " 0xa8( " + value + " ); //" + raw_script + "\n" );
  843. raw_script = "";
  844. }
  845. else if( opcode == 0xa9 )
  846. {
  847. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  848. control = GetU8( script_pointer + 1 );
  849. AdvanceScript( 2 );
  850. Ogre::String value = Get8Variable();
  851. export_script->Log( " Set8007ae2cAnd8007ae30WithScreenXYForEntity( " + value + " ); //" + raw_script + "\n" );
  852. raw_script = "";
  853. }
  854. else if( opcode == 0xaa )
  855. {
  856. AdvanceScript( 1 );
  857. export_script->Log( " [80073998] = w(w[80073998] & fffbffff); //" + raw_script + "\n" );
  858. raw_script = "";
  859. }
  860. else if( opcode == 0xab )
  861. {
  862. AdvanceScript( 1 );
  863. export_script->Log( " [80073998] = w(w[80073998] | 00040000); //" + raw_script + "\n" );
  864. raw_script = "";
  865. }
  866. else if( opcode == 0xb3 )
  867. {
  868. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  869. control = GetU8( script_pointer + 1 );
  870. AdvanceScript( 2 );
  871. Ogre::String value1 = Get8Variable();
  872. Ogre::String value2 = Get8Variable();
  873. Ogre::String value3 = Get16Variable();
  874. Ogre::String value4 = Get16Variable();
  875. Ogre::String value5 = Get16Variable();
  876. export_script->Log( " CallFuncafac0( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + ", " + value5 + " ); //" + raw_script + "\n" );
  877. raw_script = "";
  878. }
  879. else if( opcode == 0xb4 )
  880. {
  881. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  882. control = GetU8( script_pointer + 1 );
  883. AdvanceScript( 2 );
  884. Ogre::String value = Get16Variable();
  885. export_script->Log( " 0xb4( " + value + " ); //" + raw_script + "\n" );
  886. raw_script = "";
  887. }
  888. else if( opcode == 0xc5 )
  889. {
  890. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  891. control = GetU8( script_pointer + 1 );
  892. AdvanceScript( 2 );
  893. Ogre::String value1 = Get16Variable();
  894. Ogre::String value2 = Get16Variable();
  895. export_script->Log( " CallDynamic8006794c_1c_83c( " + value1 + ", " + value2 + ", 0x00, 0x00, 0x00 ); //" + raw_script + "\n" );
  896. raw_script = "";
  897. }
  898. else if( opcode == 0xc6 )
  899. {
  900. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  901. control = GetU8( script_pointer + 1 );
  902. AdvanceScript( 2 );
  903. Ogre::String value1 = Get16Variable();
  904. Ogre::String value2 = Get16Variable();
  905. Ogre::String value3 = Get24Variable();
  906. export_script->Log( " CallDynamic8006794c_1c_83c( " + value1 + ", " + value2 + ", " + value3 + ", 0x00, 0x00 ); //" + raw_script + "\n" );
  907. raw_script = "";
  908. }
  909. else if( opcode == 0xc7 )
  910. {
  911. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  912. control = GetU8( script_pointer + 1 );
  913. AdvanceScript( 2 );
  914. Ogre::String value1 = Get16Variable();
  915. Ogre::String value2 = Get16Variable();
  916. Ogre::String value3 = Get24Variable();
  917. Ogre::String value4 = Get8Variable();
  918. export_script->Log( " CallDynamic8006794c_1c_83c( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + ", 0x00 ); //" + raw_script + "\n" );
  919. raw_script = "";
  920. }
  921. else if( opcode == 0xc8 )
  922. {
  923. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  924. control = GetU8( script_pointer + 1 );
  925. AdvanceScript( 2 );
  926. Ogre::String value1 = Get16Variable();
  927. Ogre::String value2 = Get16Variable();
  928. Ogre::String value3 = Get24Variable();
  929. Ogre::String value4 = Get8Variable();
  930. Ogre::String value5 = Get8Variable();
  931. export_script->Log( " CallDynamic8006794c_1c_83c( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + ", " + value5 + " ); //" + raw_script + "\n" );
  932. raw_script = "";
  933. }
  934. else if( opcode == 0xca )
  935. {
  936. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  937. control = GetU8( script_pointer + 1 );
  938. AdvanceScript( 2 );
  939. Ogre::String value1 = Get8Variable();
  940. Ogre::String value2 = Get8Variable();
  941. export_script->Log( " CallFuncc196c( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  942. raw_script = "";
  943. }
  944. else if( opcode == 0xcb )
  945. {
  946. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  947. control = GetU8( script_pointer + 1 );
  948. AdvanceScript( 2 );
  949. Ogre::String value1 = Get8Variable();
  950. Ogre::String value2 = Get8Variable();
  951. export_script->Log( " CallFuncc47e4( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  952. raw_script = "";
  953. }
  954. else if( opcode == 0xce )
  955. {
  956. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  957. control = GetU8( script_pointer + 1 );
  958. AdvanceScript( 2 );
  959. Ogre::String value = Get24Variable();
  960. export_script->Log( " 0xce( " + value + " ); //" + raw_script + "\n" );
  961. raw_script = "";
  962. }
  963. else if( opcode == 0xd7 )
  964. {
  965. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  966. control = GetU8( script_pointer + 1 );
  967. AdvanceScript( 2 );
  968. Ogre::String value = Get8Variable();
  969. export_script->Log( " Set8007bc14to0x2cIfValueEqual8007bc10( " + value + " ); //" + raw_script + "\n" );
  970. raw_script = "";
  971. }
  972. else if( opcode == 0xd9 )
  973. {
  974. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  975. control = GetU8( script_pointer + 1 );
  976. AdvanceScript( 2 );
  977. Ogre::String character_id = Get8Variable();
  978. Ogre::String status_mask = Get8Variable();
  979. export_script->Log( " CharacterRemoveStatuses( character_id = " + character_id + ", status_mask = " + status_mask + " ); //" + raw_script + "\n" );
  980. raw_script = "";
  981. }
  982. else if( opcode == 0xda )
  983. {
  984. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  985. control = GetU8( script_pointer + 1 );
  986. AdvanceScript( 2 );
  987. Ogre::String value1 = Get8Variable();
  988. Ogre::String value2 = Get8Variable();
  989. Ogre::String value3 = Get8Variable();
  990. Ogre::String value4 = Get16Variable();
  991. Ogre::String value5 = Get16Variable();
  992. export_script->Log( " CallFuncafac0( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + ", " + value5 + " ); //" + raw_script + "\n" );
  993. raw_script = "";
  994. }
  995. else if( opcode == 0xdc )
  996. {
  997. AdvanceScript( 1 );
  998. export_script->Log( " PerformJump(); //" + raw_script + "\n" );
  999. raw_script = "";
  1000. }
  1001. else if( opcode == 0xdd )
  1002. {
  1003. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1004. control = GetU8( script_pointer + 1 );
  1005. AdvanceScript( 2 );
  1006. Ogre::String character_id = Get8Variable();
  1007. export_script->Log( " PartyRemove( character_id = " + character_id + " ); //" + raw_script + "\n" );
  1008. raw_script = "";
  1009. }
  1010. else if( opcode == 0xde )
  1011. {
  1012. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1013. control = GetU8( script_pointer + 1 );
  1014. AdvanceScript( 2 );
  1015. Ogre::String character_id = Get8Variable();
  1016. Ogre::String string_id = Get16Variable();
  1017. export_script->Log( " CharacterSetName( character_id = " + character_id + ", string_id = " + string_id + " ); //" + raw_script + "\n" );
  1018. raw_script = "";
  1019. }
  1020. else if( opcode == 0xe2 )
  1021. {
  1022. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1023. control = GetU8( script_pointer + 1 );
  1024. AdvanceScript( 2 );
  1025. Ogre::String x = Get16Variable();
  1026. Ogre::String y = Get16Variable();
  1027. Ogre::String z = Get16Variable();
  1028. Ogre::String steps = Get8Variable();
  1029. export_script->Log( " Jump( x = " + x + ", y = " + y + ", z = " + z + ", steps = " + steps + " ); //" + raw_script + "\n" );
  1030. raw_script = "";
  1031. }
  1032. else if( opcode == 0xe3 )
  1033. {
  1034. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1035. control = GetU8( script_pointer + 1 );
  1036. AdvanceScript( 2 );
  1037. export_script->Log( " Set8007bbd8( " + Get8Variable() + " ); //" + raw_script + "\n" );
  1038. raw_script = "";
  1039. }
  1040. else if( opcode == 0xec )
  1041. {
  1042. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1043. control = GetU8( script_pointer + 1 );
  1044. AdvanceScript( 2 );
  1045. Ogre::String value1 = Get8Variable();
  1046. Ogre::String value2 = Get8Variable();
  1047. Ogre::String value3 = Get8Variable();
  1048. Ogre::String value4 = Get8Variable();
  1049. Ogre::String value5 = Get8Variable();
  1050. Ogre::String value6 = Get8Variable();
  1051. export_script->Log( " 0xec( " + value1 + ", " + value2 + ", " + value3 + ", " + value4 + ", " + value5 + ", " + value6 + " ); //" + raw_script + "\n" );
  1052. raw_script = "";
  1053. }
  1054. else if( opcode == 0xef )
  1055. {
  1056. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1057. control = GetU8( script_pointer + 1 );
  1058. AdvanceScript( 2 );
  1059. export_script->Log( " Set8007bbe0_8007bbe8( " + Get8Variable() + " ); //" + raw_script + "\n" );
  1060. raw_script = "";
  1061. }
  1062. else if( opcode == 0xf1 )
  1063. {
  1064. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1065. control = GetU8( script_pointer + 1 );
  1066. AdvanceScript( 2 );
  1067. Ogre::String character_id = Get8Variable();
  1068. Ogre::String hp = Get16Variable();
  1069. export_script->Log( " CharacterSetHP( character_id = " + character_id + ", hp = " + hp + " ); //" + raw_script + "\n" );
  1070. raw_script = "";
  1071. }
  1072. else if( opcode == 0xf2 )
  1073. {
  1074. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1075. control = GetU8( script_pointer + 1 );
  1076. AdvanceScript( 2 );
  1077. Ogre::String character_id = Get8Variable();
  1078. Ogre::String mp = Get16Variable();
  1079. export_script->Log( " CharacterSetMP( character_id = " + character_id + ", mp = " + mp + " ); //" + raw_script + "\n" );
  1080. raw_script = "";
  1081. }
  1082. else if( opcode == 0xf7 )
  1083. {
  1084. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1085. control = GetU8( script_pointer + 1 );
  1086. AdvanceScript( 2 );
  1087. Ogre::String value1 = Get8Variable();
  1088. export_script->Log( " CallFunc54fe0( " + value1 + " ); //" + raw_script + "\n" );
  1089. raw_script = "";
  1090. }
  1091. else if( opcode == 0xf8 )
  1092. {
  1093. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1094. control = GetU8( script_pointer + 1 );
  1095. AdvanceScript( 2 );
  1096. Ogre::String value1 = Get8Variable();
  1097. Ogre::String value2 = Get8Variable();
  1098. Ogre::String value3 = Get8Variable();
  1099. export_script->Log( " CallFunc54e88( " + value1 + ", " + value2 + ", " + value3 + " ); //" + raw_script + "\n" );
  1100. raw_script = "";
  1101. }
  1102. else if( opcode == 0xfd )
  1103. {
  1104. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1105. control = GetU8( script_pointer + 1 );
  1106. AdvanceScript( 2 );
  1107. Ogre::String value1 = Get8Variable();
  1108. Ogre::String value2 = Get16Variable();
  1109. export_script->Log( " CallDynamic8006794c_1c_8bc( " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  1110. raw_script = "";
  1111. }
  1112. else if( opcode == 0xfe )
  1113. {
  1114. raw_script += " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1115. control = GetU8( script_pointer + 1 );
  1116. AdvanceScript( 2 );
  1117. Ogre::String character_id = Get8Variable();
  1118. Ogre::String type = Get8Variable();
  1119. Ogre::String preset_id = Get8Variable();
  1120. Ogre::String value1 = Get8Variable();
  1121. Ogre::String value2 = Get8Variable();
  1122. export_script->Log( " CharacterInit( character_id = " + character_id + ", type = " + type + ", preset_id = " + preset_id + ", " + value1 + ", " + value2 + " ); //" + raw_script + "\n" );
  1123. raw_script = "";
  1124. }
  1125. else
  1126. {
  1127. export_script->Log( " MISSING OPCODE 0x" + HexToString( opcode, 2, '0' ) + "\n" );
  1128. break;
  1129. }
  1130. }
  1131. export_script->Log( "\n" );
  1132. }
  1133. export_script->Log( "\n\n\n" );
  1134. }
  1135. delete export_script;
  1136. }
  1137. void
  1138. ScriptFile::StackOpcodeParse()
  1139. {
  1140. Ogre::String result;
  1141. stack.clear();
  1142. for ( ;; )
  1143. {
  1144. u8 stack_opcode = GetU8( script_pointer );
  1145. //export_script->Log( "StackOpcodeParse: 0x" + HexToString( script_pointer, 4, '0' ) + " opcode: 0x" + HexToString( stack_opcode, 2, '0' ) + "\n" );
  1146. raw_script += " " + HexToString( stack_opcode, 2, '0' );
  1147. AdvanceScript( 1 );
  1148. if( stack_opcode == 0x04 )
  1149. {
  1150. Ogre::String value = GetStringFromStack();
  1151. StackItem item;
  1152. item.value_int = 0;
  1153. item.value_string = "( " + value + "++ )";
  1154. stack.push_back( item );
  1155. }
  1156. else if( stack_opcode == 0x05 )
  1157. {
  1158. Ogre::String value = GetStringFromStack();
  1159. StackItem item;
  1160. item.value_int = 0;
  1161. item.value_string = "( " + value + "-- )";
  1162. stack.push_back( item );
  1163. }
  1164. else if (stack_opcode == 0x0e)
  1165. {
  1166. Ogre::String value1 = GetStringFromStack();
  1167. StackItem item;
  1168. item.value_int = 0;
  1169. item.value_string = "( " + value1 + " == false )";
  1170. stack.push_back( item );
  1171. }
  1172. else if( stack_opcode == 0x11 )
  1173. {
  1174. Ogre::String value1 = GetStringFromStack();
  1175. Ogre::String value2 = GetStringFromStack();
  1176. StackItem item;
  1177. item.value_int = 0;
  1178. item.value_string = "( " + value1 + " * " + value2 + " )";
  1179. stack.push_back( item );
  1180. }
  1181. else if( stack_opcode == 0x12 )
  1182. {
  1183. Ogre::String value1 = GetStringFromStack();
  1184. Ogre::String value2 = GetStringFromStack();
  1185. StackItem item;
  1186. item.value_int = 0;
  1187. item.value_string = "( " + value1 + " / " + value2 + " )";
  1188. stack.push_back( item );
  1189. }
  1190. else if( stack_opcode == 0x13 )
  1191. {
  1192. Ogre::String value1 = GetStringFromStack();
  1193. Ogre::String value2 = GetStringFromStack();
  1194. StackItem item;
  1195. item.value_int = 0;
  1196. item.value_string = "( " + value1 + " % " + value2 + " )";
  1197. stack.push_back( item );
  1198. }
  1199. else if( stack_opcode == 0x14 )
  1200. {
  1201. Ogre::String value1 = GetStringFromStack();
  1202. Ogre::String value2 = GetStringFromStack();
  1203. StackItem item;
  1204. item.value_int = 0;
  1205. item.value_string = "( " + value1 + " + " + value2 + " )";
  1206. stack.push_back( item );
  1207. }
  1208. else if (stack_opcode == 0x15)
  1209. {
  1210. Ogre::String value1 = GetStringFromStack();
  1211. Ogre::String value2 = GetStringFromStack();
  1212. StackItem item;
  1213. item.value_int = 0;
  1214. item.value_string = "( " + value1 + " - " + value2 + " )";
  1215. stack.push_back( item );
  1216. }
  1217. else if (stack_opcode == 0x16)
  1218. {
  1219. Ogre::String value1 = GetStringFromStack();
  1220. Ogre::String value2 = GetStringFromStack();
  1221. StackItem item;
  1222. item.value_int = 0;
  1223. item.value_string = "( " + value2 + " << " + value1 + " )";
  1224. stack.push_back( item );
  1225. }
  1226. else if (stack_opcode == 0x17)
  1227. {
  1228. Ogre::String value1 = GetStringFromStack();
  1229. Ogre::String value2 = GetStringFromStack();
  1230. StackItem item;
  1231. item.value_int = 0;
  1232. item.value_string = "( " + value2 + " >> " + value1 + " )";
  1233. stack.push_back( item );
  1234. }
  1235. else if (stack_opcode == 0x18)
  1236. {
  1237. Ogre::String value1 = GetStringFromStack();
  1238. Ogre::String value2 = GetStringFromStack();
  1239. StackItem item;
  1240. item.value_int = 0;
  1241. item.value_string = "( " + value2 + " < " + value1 + " )";
  1242. stack.push_back( item );
  1243. }
  1244. else if (stack_opcode == 0x19)
  1245. {
  1246. Ogre::String value1 = GetStringFromStack();
  1247. Ogre::String value2 = GetStringFromStack();
  1248. StackItem item;
  1249. item.value_int = 0;
  1250. item.value_string = "( " + value2 + " > " + value1 + " )";
  1251. stack.push_back( item );
  1252. }
  1253. else if (stack_opcode == 0x1a)
  1254. {
  1255. Ogre::String value1 = GetStringFromStack();
  1256. Ogre::String value2 = GetStringFromStack();
  1257. StackItem item;
  1258. item.value_int = 0;
  1259. item.value_string = "( " + value2 + " <= " + value1 + " )";
  1260. stack.push_back( item );
  1261. }
  1262. else if (stack_opcode == 0x1b)
  1263. {
  1264. Ogre::String value1 = GetStringFromStack();
  1265. Ogre::String value2 = GetStringFromStack();
  1266. StackItem item;
  1267. item.value_int = 0;
  1268. item.value_string = "( " + value2 + " >= " + value1 + " )";
  1269. stack.push_back( item );
  1270. }
  1271. else if (stack_opcode == 0x20)
  1272. {
  1273. Ogre::String value1 = GetStringFromStack();
  1274. Ogre::String value2 = GetStringFromStack();
  1275. StackItem item;
  1276. item.value_int = 0;
  1277. item.value_string = "( " + value2 + " == " + value1 + " )";
  1278. stack.push_back( item );
  1279. }
  1280. else if (stack_opcode == 0x21)
  1281. {
  1282. Ogre::String value1 = GetStringFromStack();
  1283. Ogre::String value2 = GetStringFromStack();
  1284. StackItem item;
  1285. item.value_int = 0;
  1286. item.value_string = "( " + value2 + " != " + value1 + " )";
  1287. stack.push_back( item );
  1288. }
  1289. else if (stack_opcode == 0x22)
  1290. {
  1291. Ogre::String value = GetStringFromStack();
  1292. Ogre::String parameter = GetStringFromStack();
  1293. Ogre::String mask = GetStringFromStack();
  1294. StackItem item;
  1295. item.value_int = 0;
  1296. item.value_string = "MultipleEqual( mask = " + mask + ", parameter = " + parameter + ", value = " + value + " )";
  1297. stack.push_back( item );
  1298. }
  1299. else if (stack_opcode == 0x24)
  1300. {
  1301. Ogre::String value1 = GetStringFromStack();
  1302. Ogre::String value2 = GetStringFromStack();
  1303. StackItem item;
  1304. item.value_int = 0;
  1305. item.value_string = "( " + value2 + " & " + value1 + " )";
  1306. stack.push_back( item );
  1307. }
  1308. else if (stack_opcode == 0x25)
  1309. {
  1310. Ogre::String value1 = GetStringFromStack();
  1311. Ogre::String value2 = GetStringFromStack();
  1312. StackItem item;
  1313. item.value_int = 0;
  1314. item.value_string = "( " + value2 + " XOR " + value1 + " )";
  1315. stack.push_back( item );
  1316. }
  1317. else if (stack_opcode == 0x27)
  1318. {
  1319. Ogre::String value1 = GetStringFromStack();
  1320. Ogre::String value2 = GetStringFromStack();
  1321. StackItem item;
  1322. item.value_int = 0;
  1323. item.value_string = "( " + value2 + " && " + value1 + " )";
  1324. stack.push_back( item );
  1325. }
  1326. else if (stack_opcode == 0x28)
  1327. {
  1328. Ogre::String value1 = GetStringFromStack();
  1329. Ogre::String value2 = GetStringFromStack();
  1330. StackItem item;
  1331. item.value_int = 0;
  1332. item.value_string = "( " + value2 + " || " + value1 + " )";
  1333. stack.push_back( item );
  1334. }
  1335. else if( stack_opcode == 0x29 )
  1336. {
  1337. raw_script += " " + HexToString( GetU8( script_pointer + 0 ), 2, '0' );
  1338. u16 data = GetU8( script_pointer + 0 );
  1339. AdvanceScript( 1 );
  1340. StackItem item;
  1341. item.value_int = 0x18000000 | data;
  1342. item.value_string = "";
  1343. stack.push_back( item );
  1344. }
  1345. else if( stack_opcode == 0x2a )
  1346. {
  1347. Ogre::String value = GetStringFromStack();
  1348. StackItem item;
  1349. item.value_int = 0;
  1350. item.value_string = "CountActiveBits( " + value + " )";
  1351. stack.push_back( item );
  1352. }
  1353. else if (stack_opcode == 0x2b)
  1354. {
  1355. Ogre::String parameter = GetStringFromStack();
  1356. Ogre::String mask = GetStringFromStack();
  1357. StackItem item;
  1358. item.value_int = 0;
  1359. item.value_string = "GetUnitParameter( mask = " + mask + ", parameter = " + parameter + " )";
  1360. stack.push_back( item );
  1361. }
  1362. else if( stack_opcode == 0x2c )
  1363. {
  1364. Ogre::String value = GetStringFromStack();
  1365. StackItem item;
  1366. item.value_int = 0;
  1367. item.value_string = StoreVariableByStack( value );
  1368. stack.push_back( item );
  1369. }
  1370. else if (stack_opcode == 0x2d)
  1371. {
  1372. Ogre::String value = GetStringFromStack();
  1373. Ogre::String parameter = GetStringFromStack();
  1374. Ogre::String mask = GetStringFromStack();
  1375. StackItem item;
  1376. item.value_int = 0;
  1377. item.value_string = "StoreUnitsParamsByMask( mask = " + mask + ", parameter = " + parameter + ", value = " + value + " )";
  1378. stack.push_back( item );
  1379. }
  1380. else if( stack_opcode == 0x32 )
  1381. {
  1382. Ogre::String value1 = GetStringFromStack();
  1383. Ogre::String value2 = GetStringFromStack();
  1384. StackItem item;
  1385. item.value_int = 0;
  1386. item.value_string = "( " + value2 + " += " + value1 + " )";
  1387. stack.push_back( item );
  1388. }
  1389. else if( stack_opcode == 0x33 )
  1390. {
  1391. Ogre::String value1 = GetStringFromStack();
  1392. Ogre::String value2 = GetStringFromStack();
  1393. StackItem item;
  1394. item.value_int = 0;
  1395. item.value_string = "( " + value2 + " -= " + value1 + " )";
  1396. stack.push_back( item );
  1397. }
  1398. else if( stack_opcode == 0x35 )
  1399. {
  1400. Ogre::String value1 = GetStringFromStack();
  1401. Ogre::String value2 = GetStringFromStack();
  1402. StackItem item;
  1403. item.value_int = 0;
  1404. item.value_string = "( " + value2 + " >>= " + value1 + " )";
  1405. stack.push_back( item );
  1406. }
  1407. else if( stack_opcode == 0x3d )
  1408. {
  1409. Ogre::String value1 = GetStringFromStack();
  1410. Ogre::String value2 = GetStringFromStack();
  1411. StackItem item;
  1412. item.value_int = 0;
  1413. item.value_string = "( " + value2 + " &= " + value1 + " )";
  1414. stack.push_back( item );
  1415. }
  1416. else if( stack_opcode == 0x3e )
  1417. {
  1418. Ogre::String value1 = GetStringFromStack();
  1419. Ogre::String value2 = GetStringFromStack();
  1420. StackItem item;
  1421. item.value_int = 0;
  1422. item.value_string = "( " + value2 + " ^= " + value1 + " )";
  1423. stack.push_back( item );
  1424. }
  1425. else if( stack_opcode == 0x3f )
  1426. {
  1427. Ogre::String value1 = GetStringFromStack();
  1428. Ogre::String value2 = GetStringFromStack();
  1429. StackItem item;
  1430. item.value_int = 0;
  1431. item.value_string = "( " + value2 + " |= " + value1 + " )";
  1432. stack.push_back( item );
  1433. }
  1434. else if( stack_opcode == 0x4d )
  1435. {
  1436. Ogre::String value = GetStringFromStack();
  1437. StackItem item;
  1438. item.value_int = 0;
  1439. item.value_string = "PickRandomActiveBit( " + value + " )";
  1440. stack.push_back( item );
  1441. }
  1442. else if( stack_opcode == 0x4f )
  1443. {
  1444. Ogre::String value = GetStringFromStack();
  1445. StackItem item;
  1446. item.value_int = 0;
  1447. item.value_string = "IsButtonPressed( " + value + " )";
  1448. stack.push_back( item );
  1449. }
  1450. else if( stack_opcode == 0x52 )
  1451. {
  1452. Ogre::String value = GetStringFromStack();
  1453. StackItem item;
  1454. item.value_int = 0;
  1455. item.value_string = "GetCurrentHpForCharacter( " + value + " )";
  1456. stack.push_back( item );
  1457. }
  1458. else if (stack_opcode == 0x54)
  1459. {
  1460. Ogre::String value = GetStringFromStack();
  1461. Ogre::String parameter = GetStringFromStack();
  1462. Ogre::String mask = GetStringFromStack();
  1463. StackItem item;
  1464. item.value_int = 0;
  1465. item.value_string = "MultipleAnd( mask = " + mask + ", parameter = " + parameter + ", value = " + value + " )";
  1466. stack.push_back( item );
  1467. }
  1468. else if( stack_opcode == 0x5d )
  1469. {
  1470. Ogre::String value1 = GetStringFromStack();
  1471. Ogre::String value2 = GetStringFromStack();
  1472. StackItem item;
  1473. item.value_int = 0;
  1474. item.value_string = "GetCurrentEntityRotationTo( " + value2 + ", " + value1 + " )";
  1475. stack.push_back( item );
  1476. }
  1477. else if( stack_opcode == 0x62 )
  1478. {
  1479. Ogre::String value = GetStringFromStack();
  1480. StackItem item;
  1481. item.value_int = 0;
  1482. item.value_string = "GetSinByRotation( " + value + " )";
  1483. stack.push_back( item );
  1484. }
  1485. else if( stack_opcode == 0x64 )
  1486. {
  1487. Ogre::String value = GetStringFromStack( 0 );
  1488. StackItem item;
  1489. item.value_int = 0;
  1490. item.value_string = "0x64stack( " + value + " )";
  1491. stack.push_back( item );
  1492. }
  1493. else if( stack_opcode == 0x66 )
  1494. {
  1495. Ogre::String value1 = GetStringFromStack();
  1496. Ogre::String value2 = GetStringFromStack();
  1497. StackItem item;
  1498. item.value_int = 0;
  1499. item.value_string = "GetRotationBy( " + value2 + ", " + value1 + " )";
  1500. stack.push_back( item );
  1501. }
  1502. else if( stack_opcode == 0x6b )
  1503. {
  1504. Ogre::String value1 = GetStringFromStack();
  1505. StackItem item;
  1506. item.value_int = 0;
  1507. item.value_string = "CallFunc4b85c( " + value1 + " )";
  1508. stack.push_back( item );
  1509. }
  1510. else if( stack_opcode == 0x6d )
  1511. {
  1512. Ogre::String value1 = GetStringFromStack();
  1513. StackItem item;
  1514. item.value_int = 0;
  1515. item.value_string = "CallFunc378c4( " + value1 + " )";
  1516. stack.push_back( item );
  1517. }
  1518. else if( stack_opcode == 0x78 )
  1519. {
  1520. raw_script += " " + HexToString( GetU8( script_pointer + 0 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1521. u16 data = ( GetU8( script_pointer + 0 ) << 8 ) | GetU8( script_pointer + 1 );
  1522. AdvanceScript( 2 );
  1523. StackItem item;
  1524. item.value_int = 0x10000000 | data;
  1525. item.value_string = "";
  1526. stack.push_back( item );
  1527. }
  1528. else if( stack_opcode == 0x79 )
  1529. {
  1530. raw_script += " " + HexToString( GetU8( script_pointer + 0 ), 2, '0' );
  1531. u16 data = GetU8( script_pointer + 0 );
  1532. AdvanceScript( 1 );
  1533. StackItem item;
  1534. item.value_int = 0x14000000 | data;
  1535. item.value_string = "";
  1536. stack.push_back( item );
  1537. }
  1538. else if (stack_opcode == 0x7a)
  1539. {
  1540. raw_script += " " + HexToString( GetU8( script_pointer ), 2, '0' );
  1541. u8 type = GetU8( script_pointer );
  1542. AdvanceScript( 1 );
  1543. StackItem item;
  1544. item.value_int = 0;
  1545. switch (type)
  1546. {
  1547. case 0x00: item.value_string = "GetRandomByte()"; break;
  1548. case 0x02: item.value_string = "bu[script + 16ec]"; break;
  1549. case 0x03: item.value_string = "funcb0124( 0xc00, 0xffffffff, 0, 0, 0 )"; break;
  1550. case 0x06: item.value_string = "w[w[w[8006794c] + 1c] + 560]"; break;
  1551. case 0x09: item.value_string = "Func4ecc4()"; break;
  1552. case 0x0c: item.value_string = "w[8007ae2c]"; break;
  1553. case 0x0d: item.value_string = "w[8007ae30]"; break;
  1554. case 0x13: item.value_string = "Count80083248()"; break;
  1555. default: item.value_string = "Unimplemented type 0x" + HexToString( type , 2, '0' ) + " for stack opcode 0x7a.";
  1556. }
  1557. stack.push_back( item );
  1558. }
  1559. else if( stack_opcode == 0x7d )
  1560. {
  1561. raw_script += " " + HexToString( GetU8( script_pointer ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1562. u16 data = GetU16LE( script_pointer );
  1563. AdvanceScript( 2 );
  1564. StackItem item;
  1565. item.value_int = 0x1c000000 | data;
  1566. item.value_string = "";
  1567. stack.push_back( item );
  1568. }
  1569. else if( stack_opcode == 0x7e )
  1570. {
  1571. raw_script += " " + HexToString( GetU8( script_pointer ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 2 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 3 ), 2, '0' );
  1572. u32 data = GetU32LE( script_pointer ) & 0x03ffffff;
  1573. AdvanceScript( 4 );
  1574. StackItem item;
  1575. item.value_int = 0x1c000000 | data;
  1576. item.value_string = "";
  1577. stack.push_back( item );
  1578. }
  1579. // FinishSubRoutine
  1580. else if( stack_opcode == 0x7f )
  1581. {
  1582. return;
  1583. }
  1584. // AddCommand
  1585. else if( stack_opcode >= 0x80 )
  1586. {
  1587. StackItem item;
  1588. item.value_int = StackOpcode80Parse( stack_opcode );
  1589. item.value_string = "";
  1590. stack.push_back( item );
  1591. }
  1592. else
  1593. {
  1594. //export_script->Log( "0x" + HexToString( script_position, 4, '0' ) );
  1595. export_script->Log( " MISSING STACK OPCODE 0x" + HexToString( stack_opcode, 2, '0' ) + "; //" + raw_script + "\n" );
  1596. raw_script = "";
  1597. return;
  1598. }
  1599. }
  1600. }
  1601. u32
  1602. ScriptFile::StackOpcode80Parse( u32 stack_opcode )
  1603. {
  1604. u32 command = stack_opcode & 0x03;
  1605. command <<= 0x1a;
  1606. u32 A1 = stack_opcode & 0x1c;
  1607. A1 <<= 0x1b;
  1608. command |= A1;
  1609. u8 data = GetU8( script_pointer );
  1610. raw_script += " " + HexToString( data, 2, '0' );
  1611. AdvanceScript( 1 );
  1612. command |= data;
  1613. if (stack_opcode & 0x20)
  1614. {
  1615. data = GetU8( script_pointer );
  1616. raw_script += " " + HexToString( data, 2, '0' );
  1617. AdvanceScript( 1 );
  1618. data <<= 0x8;
  1619. command |= data;
  1620. }
  1621. //export_script->Log( "StackOpcode80Parse command: " + HexToString( command, 2, '0') + "\n" );
  1622. return command;
  1623. }
  1624. Ogre::String
  1625. ScriptFile::LoadVariable( const StackItem& item )
  1626. {
  1627. if( item.value_string != "" )
  1628. {
  1629. return "ERROR: LoadVariable must hanble top calue of stack as int. But value is \"" + stack.back().value_string + "\".";
  1630. }
  1631. u32 command = item.value_int;
  1632. //export_script->Log( "Load with command: " + HexToString( command, 2, '0') + "\n" );
  1633. if( ( command >> 0x18 ) == 0x10 )
  1634. {
  1635. switch (command & 0xff)
  1636. {
  1637. case 0x0: return "GetXPositionFromEntity( 0x" + HexToString( ( command >> 0x8 ) & 0xff, 2, '0' ) + " )";
  1638. case 0x1: return "GetYPositionFromEntity( 0x" + HexToString( ( command >> 0x8 ) & 0xff, 2, '0' ) + " )";
  1639. case 0x2: return "GetZPositionFromEntity( 0x" + HexToString( ( command >> 0x8 ) & 0xff, 2, '0' ) + " )";
  1640. case 0x3: return "GetYRotationFromEntity( 0x" + HexToString( ( command >> 0x8 ) & 0xff, 2, '0' ) + " )";
  1641. case 0x4: return "GetFlagsFromEntity( 0x" + HexToString( ( command >> 0x8 ) & 0xff, 2, '0' ) + " )";
  1642. case 0x5: return "GetMainEntityIdFromEntity( 0x" + HexToString( ( command >> 0x8 ) & 0xff, 2, '0' ) + " )";
  1643. case 0x6: return "GetCurrentScriptPriorityFromEntity( 0x" + HexToString( ( command >> 0x8 ) & 0xff, 2, '0' ) + " )";
  1644. case 0x7: return "Get[3a]FromEntity( 0x" + HexToString( ( command >> 0x8 ) & 0xff, 2, '0' ) + " )";
  1645. default: return "Unimplemented 0x" + HexToString( ( command >> 0x18 ), 2, '0' ) + " with type 0x" + HexToString( ( command & 0xff ), 2, '0' ) + " load.";
  1646. }
  1647. }
  1648. else if( ( command >> 0x18 ) == 0x14 )
  1649. {
  1650. Ogre::String ret = "Get";
  1651. if( ( command & 0x7 ) == 2 )
  1652. {
  1653. ret += "Party";
  1654. }
  1655. else if( ( command & 0x7 ) == 3 )
  1656. {
  1657. ret += "Enemy";
  1658. }
  1659. else if( ( command & 0x7 ) == 4 )
  1660. {
  1661. ret += "Units";
  1662. }
  1663. else
  1664. {
  1665. ret += "Unknown" + HexToString( ( command & 0x7 ), 2, '0' );
  1666. }
  1667. ret += "Mask()";
  1668. return ret;
  1669. }
  1670. else if( ( command >> 0x18 ) == 0x18 )
  1671. {
  1672. switch ( ( command << 6 ) >> 6 )
  1673. {
  1674. case 0x0: return "GetXPositionFromEntity()";
  1675. case 0x1: return "GetYPositionFromEntity()";
  1676. case 0x2: return "GetZPositionFromEntity()";
  1677. case 0x3: return "GetYRotationFromEntity()";
  1678. case 0x4: return "GetFlagsFromEntity()";
  1679. case 0x5: return "GetMainEntityIdFromEntity()";
  1680. case 0x6: return "GetCurrentScriptPriorityFromEntity()";
  1681. case 0x7: return "Get[3a]FromEntity()";
  1682. default: return "Unimplemented 0x" + HexToString( ( command >> 0x18 ), 2, '0' ) + " with type 0x" + HexToString( ( ( command << 6 ) >> 6 ), 2, '0' ) + " load.";
  1683. }
  1684. }
  1685. else if( ( command >> 0x18 ) == 0x1c )
  1686. {
  1687. return "0x" + HexToString( ( command << 0x6 ) >> 0x6, 8, '0' );
  1688. }
  1689. else if( ( command >> 0x18 ) == 0x20 )
  1690. {
  1691. return "(bu[ 0x8007aef0 + 0x" + HexToString( ( command & 0xffff ) >> 0x3, 4, '0' ) + " ] >> 0x" + HexToString( command & 0x7, 2, '0' ) + ") & 1";
  1692. }
  1693. else if( ( command >> 0x18 ) == 0x24 )
  1694. {
  1695. return "(bu[ script + 0x" + HexToString( ( command & 0xffff ) >> 0x3, 4, '0' ) + " ] >> 0x" + HexToString( command & 0x7, 2, '0' ) + ") & 1";
  1696. }
  1697. else if( ( command >> 0x18 ) == 0x48 )
  1698. {
  1699. return "b3[ w[ 0x8007bcf8 ] + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1700. }
  1701. else if( ( command >> 0x18 ) == 0x80 )
  1702. {
  1703. return "b[ 0x8007aef0 + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1704. }
  1705. else if( ( command >> 0x18 ) == 0x88 )
  1706. {
  1707. return "b[ w[ 0x8007bcf8 ] + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1708. }
  1709. else if( ( command >> 0x18 ) == 0xa0 )
  1710. {
  1711. return "bu[ 0x8007aef0 + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1712. }
  1713. else if( ( command >> 0x18 ) == 0xa4 )
  1714. {
  1715. return "bu[ script + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1716. }
  1717. else if( ( command >> 0x18 ) == 0xa8 )
  1718. {
  1719. return "bu[ w[ 0x8007bcf8 ] + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1720. }
  1721. else if( ( command >> 0x18 ) == 0xc0 )
  1722. {
  1723. return "h[ 0x8007aef0 + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1724. }
  1725. else if( ( command >> 0x18 ) == 0xc4 )
  1726. {
  1727. return "h[ script + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1728. }
  1729. else if( ( command >> 0x18 ) == 0xe0 )
  1730. {
  1731. return "hu[ 0x8007aef0 + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1732. }
  1733. else if( ( command >> 0x18 ) == 0xe4 )
  1734. {
  1735. return "hu[ script + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1736. }
  1737. else if( ( command >> 0x18 ) == 0xe8 )
  1738. {
  1739. return "hu[ w[ 0x8007bcf8 ] + 0x" + HexToString( ( command & 0xffff ), 4, '0' ) + " ]";
  1740. }
  1741. return "Unimplemented 0x" + HexToString( ( command >> 0x18 ), 2, '0' ) + " load.";
  1742. }
  1743. Ogre::String
  1744. ScriptFile::GetStringFromStack( int position )
  1745. {
  1746. StackItem item;
  1747. if( position >= 0 )
  1748. {
  1749. item = stack[ stack.size() - 1 - position ];
  1750. }
  1751. else
  1752. {
  1753. item = stack.back();
  1754. stack.pop_back();
  1755. }
  1756. Ogre::String stack_result = "";
  1757. if ( item.value_string != "" )
  1758. {
  1759. Ogre::String string = item.value_string;
  1760. return string;
  1761. }
  1762. else
  1763. {
  1764. return LoadVariable( item );
  1765. }
  1766. }
  1767. Ogre::String
  1768. ScriptFile::StoreVariableByStack( const Ogre::String& value )
  1769. {
  1770. if ( stack.back().value_string != "" )
  1771. {
  1772. return "ERROR: StoreVariableByStack must hanble top calue of stack as int. But value is \"" + stack.back().value_string + "\".";
  1773. }
  1774. u32 command = stack.back().value_int;
  1775. //export_script->Log( "Save with command: " + HexToString( command, 2, '0') + " value: " + value + "\n" );
  1776. stack.pop_back();
  1777. if ( ( command >> 0x18 ) == 0x14 )
  1778. {
  1779. return "[ masks + 0x" + HexToString( ( command & 0x7 ) * 2, 2, '0' ) + " ] = h( " + value + " )";
  1780. }
  1781. else if ( ( command >> 0x18 ) == 0x20 )
  1782. {
  1783. if ( value == "0x00000000" )
  1784. {
  1785. return "[ 0x8007aef0 + 0x" + HexToString( (command & 0xffff) >> 0x3, 4, '0' ) + " ] = b( b[ 0x8007aef0 + 0x" + HexToString( (command & 0xffff) >> 0x3, 4, '0' ) + " ] & 0x" + HexToString( 0xff ^ (1 << (command & 0x7)), 2, '0' ) + " )";
  1786. }
  1787. else
  1788. {
  1789. return "[ 0x8007aef0 + 0x" + HexToString( (command & 0xffff) >> 0x3, 4, '0' ) + " ] = b( b[ 0x8007aef0 + 0x" + HexToString( (command & 0xffff) >> 0x3, 4, '0' ) + " ] | 0x" + HexToString( 1 << (command & 0x7), 2, '0' ) + " )";
  1790. }
  1791. }
  1792. else if ( ( command >> 0x18 ) == 0x24 )
  1793. {
  1794. if ( value == "0x00000000" )
  1795. {
  1796. return "[ script + 0x" + HexToString( (command & 0xffff) >> 0x3, 4, '0' ) + " ] = b( b[ script + 0x" + HexToString( (command & 0xffff) >> 0x3, 4, '0' ) + " ] & 0x" + HexToString( 0xff ^ (1 << (command & 0x7)), 2, '0' ) + " )";
  1797. }
  1798. else
  1799. {
  1800. return "[ script + 0x" + HexToString( (command & 0xffff) >> 0x3, 4, '0' ) + " ] = b( b[ script + 0x" + HexToString( (command & 0xffff) >> 0x3, 4, '0' ) + " ] | 0x" + HexToString( 1 << (command & 0x7), 2, '0' ) + " )";
  1801. }
  1802. }
  1803. else if ( ( command >> 0x18 ) == 0x48 )
  1804. {
  1805. return "[ w[ 0x8007bcf8 ] + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = b3( " + value + " )";
  1806. }
  1807. else if ( ( command >> 0x18 ) == 0x88 )
  1808. {
  1809. return "[ w[ 0x8007bcf8 ] + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = b( " + value + " )";
  1810. }
  1811. else if ( ( command >> 0x18 ) == 0xa0 )
  1812. {
  1813. return "[ 0x8007aef0 + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = b( " + value + " )";
  1814. }
  1815. else if ( ( command >> 0x18 ) == 0xa4 )
  1816. {
  1817. return "[ script + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = b( " + value + " )";
  1818. }
  1819. else if ( ( command >> 0x18 ) == 0xa8 )
  1820. {
  1821. return "[ w[ 0x8007bcf8 ] + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = b( " + value + " )";
  1822. }
  1823. else if ( ( command >> 0x18 ) == 0xc0 )
  1824. {
  1825. return "[ 0x8007aef0 + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = h( " + value + " )";
  1826. }
  1827. else if ( ( command >> 0x18 ) == 0xc4 )
  1828. {
  1829. return "[ script + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = h( " + value + " )";
  1830. }
  1831. else if ( ( command >> 0x18 ) == 0xe0 )
  1832. {
  1833. return "[ 0x8007aef0 + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = h( " + value + " )";
  1834. }
  1835. else if ( ( command >> 0x18 ) == 0xe4 )
  1836. {
  1837. return "[ script + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = h( " + value + " )";
  1838. }
  1839. else if ( ( command >> 0x18 ) == 0xe8 )
  1840. {
  1841. return "[ w[ 0x8007bcf8 ] + 0x" + HexToString( (command & 0xffff), 4, '0' ) + " ] = h( " + value + " )";
  1842. }
  1843. return "Unimplemented 0x" + HexToString( ( command >> 0x18 ), 2, '0' ) + " store.";
  1844. }
  1845. Ogre::String
  1846. ScriptFile::Get8Variable()
  1847. {
  1848. if( control & 1 )
  1849. {
  1850. control >>= 1;
  1851. StackOpcodeParse();
  1852. return GetStringFromStack();
  1853. }
  1854. else
  1855. {
  1856. control >>= 1;
  1857. u8 data = GetU8( script_pointer );
  1858. raw_script += " " + HexToString( data, 2, '0' );
  1859. AdvanceScript( 1 );
  1860. return "0x" + HexToString( data, 2, '0' );
  1861. }
  1862. }
  1863. Ogre::String
  1864. ScriptFile::Get16Variable()
  1865. {
  1866. if (control & 1)
  1867. {
  1868. control >>= 1;
  1869. StackOpcodeParse();
  1870. return GetStringFromStack();
  1871. }
  1872. else
  1873. {
  1874. control >>= 1;
  1875. u16 data = GetU16LE( script_pointer );
  1876. raw_script += " " + HexToString( GetU8( script_pointer + 0 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' );
  1877. AdvanceScript( 2 );
  1878. return "0x" + HexToString( data, 4, '0' );
  1879. }
  1880. }
  1881. Ogre::String
  1882. ScriptFile::Get24Variable()
  1883. {
  1884. if (control & 1)
  1885. {
  1886. control >>= 1;
  1887. StackOpcodeParse();
  1888. return GetStringFromStack();
  1889. }
  1890. else
  1891. {
  1892. control >>= 1;
  1893. u32 data = GetU16LE( script_pointer ) | ( GetU8( script_pointer + 2 ) << 0x10 );
  1894. raw_script += " " + HexToString( GetU8( script_pointer + 0 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 1 ), 2, '0' ) + " " + HexToString( GetU8( script_pointer + 2 ), 2, '0' );
  1895. AdvanceScript( 3 );
  1896. return "0x" + HexToString( data, 6, '0' );
  1897. }
  1898. }
  1899. void
  1900. ScriptFile::AdvanceScript( u32 value, u32 jump )
  1901. {
  1902. script_pointer += value;
  1903. script_pointer_end = (script_pointer > script_pointer_end) ? script_pointer : script_pointer_end;
  1904. script_pointer_end = ( jump > script_pointer_end ) ? jump : script_pointer_end;
  1905. }