DatFile.cpp 150 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641
  1. #include "DatFile.h"
  2. #include <OgreStringConverter.h>
  3. #include <OgreVector3.h>
  4. class surface_find
  5. {
  6. public:
  7. surface_find( const SurfaceTexData& a ):
  8. m_Surface(a)
  9. {
  10. }
  11. bool
  12. operator()( const SurfaceTexData& a ) const
  13. {
  14. return ( a.page_x == m_Surface.page_x ) &&
  15. ( a.page_y == m_Surface.page_y ) &&
  16. ( a.clut_y == m_Surface.clut_y ) &&
  17. ( a.clut_x == m_Surface.clut_x ) &&
  18. ( a.bpp == m_Surface.bpp ) &&
  19. ( a.clut_start == m_Surface.clut_start ) &&
  20. ( a.clut_width == m_Surface.clut_width ) &&
  21. ( a.mod_type == m_Surface.mod_type ) &&
  22. ( a.mod_r == m_Surface.mod_r ) &&
  23. ( a.mod_g == m_Surface.mod_g ) &&
  24. ( a.mod_b == m_Surface.mod_b );
  25. }
  26. private:
  27. SurfaceTexData m_Surface;
  28. };
  29. class added_tile_find
  30. {
  31. public:
  32. added_tile_find( const AddedTile& a ):
  33. m_Tile( a )
  34. {
  35. }
  36. bool
  37. operator()( const AddedTile& a ) const
  38. {
  39. return ( a.background == m_Tile.background ) &&
  40. ( a.src_x == m_Tile.src_x ) &&
  41. ( a.src_y == m_Tile.src_y ) &&
  42. ( a.clut_x == m_Tile.clut_x ) &&
  43. ( a.clut_y == m_Tile.clut_y ) &&
  44. ( a.bpp == m_Tile.bpp ) &&
  45. ( a.page_x == m_Tile.page_x ) &&
  46. ( a.page_y == m_Tile.page_y ) &&
  47. ( a.clut_start == m_Tile.clut_start ) &&
  48. ( a.clut_width == m_Tile.clut_width ) &&
  49. ( a.mod_type == m_Tile.mod_type ) &&
  50. ( a.mod_r == m_Tile.mod_r ) &&
  51. ( a.mod_g == m_Tile.mod_g ) &&
  52. ( a.mod_b == m_Tile.mod_b );
  53. }
  54. private:
  55. AddedTile m_Tile;
  56. };
  57. class anim_time_sort
  58. {
  59. public:
  60. bool
  61. operator()( const KeyFrame& x, const KeyFrame& y ) const
  62. {
  63. return x.time < y.time;
  64. }
  65. };
  66. class anim_name_sort
  67. {
  68. public:
  69. bool
  70. operator()( const Animation& x, const Animation& y ) const
  71. {
  72. return x.name < y.name;
  73. }
  74. };
  75. std::vector< Ogre::String > DatFile::m_SoundOpcodes;
  76. //////////////////////////////////////////////
  77. static const unsigned short english_chars[256] = {
  78. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  79. 0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x2600, 0x2700, 0x2800, 0x2900, 0x2A00, 0x2B00, 0x2C00, 0x2D00, 0x2E00, 0x2F00, // 0x00 - 0x0F
  80. 0x3000, 0x3100, 0x3200, 0x3300, 0x3400, 0x3500, 0x3600, 0x3700, 0x3800, 0x3900, 0x3A00, 0x3B00, 0x3C00, 0x3D00, 0x3E00, 0x3F00, // 0x10 - 0x1F
  81. 0x4000, 0x4100, 0x4200, 0x4300, 0x4400, 0x4500, 0x4600, 0x4700, 0x4800, 0x4900, 0x4A00, 0x4B00, 0x4C00, 0x4D00, 0x4E00, 0x4F00, // 0x20 - 0x2F
  82. 0x5000, 0x5100, 0x5200, 0x5300, 0x5400, 0x5500, 0x5600, 0x5700, 0x5800, 0x5900, 0x5A00, 0x5B00, 0x5C00, 0x5D00, 0x5E00, 0x5F00, // 0x30 - 0x3F
  83. 0x6000, 0x6100, 0x6200, 0x6300, 0x6400, 0x6500, 0x6600, 0x6700, 0x6800, 0x6900, 0x6A00, 0x6B00, 0x6C00, 0x6D00, 0x6E00, 0x6F00, // 0x40 - 0x4F
  84. 0x7000, 0x7100, 0x7200, 0x7300, 0x7400, 0x7500, 0x7600, 0x7700, 0x7800, 0x7900, 0x7A00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x50 - 0x5F
  85. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x60 - 0x6F
  86. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x70 - 0x7F
  87. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x80 - 0x8F
  88. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x90 - 0x9F
  89. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2620, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xA0 - 0xAF
  90. 0x0000, 0x0000, 0x1C20, 0x1D20, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xB0 - 0xBF
  91. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xC0 - 0xCF
  92. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xD0 - 0xDF
  93. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0D00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xE0 - 0xEF
  94. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xF0 - 0xFF
  95. };
  96. static const unsigned short japanese_chars[256] = {
  97. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  98. 0xD030, 0x7030, 0xD330, 0x7330, 0xD630, 0x7630, 0xD930, 0x0000, 0xDC30, 0x7C30, 0xAC30, 0x4C30, 0xAE30, 0x4E30, 0xB030, 0x5030, // 0x00 - 0x0F
  99. 0xB230, 0x5230, 0xB430, 0x5430, 0xB630, 0x5630, 0xB830, 0x5830, 0xBA30, 0x5A30, 0xBC30, 0x5C30, 0xBE30, 0x5E30, 0xC030, 0x6030, // 0x10 - 0x1F
  100. 0x0000, 0x0000, 0xC530, 0x0000, 0xC730, 0x6730, 0xC930, 0x6930, 0x0000, 0xD130, 0x7130, 0xD430, 0x0000, 0xD730, 0x7730, 0xDA30, // 0x20 - 0x2F
  101. 0x0000, 0xDD30, 0x0000, 0x3000, 0x3100, 0x3200, 0x3300, 0x3400, 0x3500, 0x3600, 0x3700, 0x3800, 0x3900, 0x0130, 0x0230, 0x2000, // 0x30 - 0x3F
  102. 0xCF30, 0x6F30, 0xD230, 0x7230, 0xD530, 0x7530, 0xD830, 0x7830, 0xDB30, 0x7B30, 0xAB30, 0x4B30, 0xAD30, 0x4D30, 0xAF30, 0x4F30, // 0x40 - 0x4F
  103. 0xB130, 0x5130, 0xB330, 0x5330, 0xB530, 0x5530, 0xB730, 0x5730, 0xB930, 0x5930, 0xBB30, 0x5B30, 0xBD30, 0x5D30, 0xBF30, 0x5F30, // 0x50 - 0x5F
  104. 0xC130, 0x6130, 0xC430, 0x6430, 0xC630, 0x6630, 0xC830, 0x6830, 0xA630, 0x4630, 0xA230, 0x4230, 0xA430, 0x4430, 0xA830, 0x4830, // 0x60 - 0x6F
  105. 0xAA30, 0x4A30, 0xCA30, 0x6A30, 0xCB30, 0x6B30, 0x0000, 0x6C30, 0xCD30, 0x6D30, 0xCE30, 0x6E30, 0xDE30, 0x7E30, 0xDF30, 0x7F30, // 0x70 - 0x7F
  106. 0xE030, 0x8030, 0xE130, 0x8130, 0xE230, 0x8230, 0xE930, 0x8930, 0xEA30, 0x8A30, 0xEB30, 0x8B30, 0xEC30, 0x8C30, 0xED30, 0x8D30, // 0x80 - 0x8F
  107. 0xE430, 0x8430, 0xE630, 0x0000, 0x0000, 0x8830, 0xEF30, 0x8F30, 0xF330, 0x9330, 0x0000, 0x9230, 0xC330, 0x6330, 0xE330, 0x8330, // 0x90 - 0x9F
  108. 0xE530, 0x8530, 0xE730, 0x8730, 0xA130, 0x4130, 0xA330, 0x0000, 0xA530, 0x0000, 0xA730, 0x4730, 0x0000, 0x4930, 0x01FF, 0x1FFF, // 0xA0 - 0xAF
  109. 0x0E30, 0x0F30, 0x0000, 0x0000, 0x4100, 0x4200, 0x4300, 0x4400, 0x4500, 0x4600, 0x4700, 0x4800, 0x4900, 0x4A00, 0x4B00, 0x4C00, // 0xB0 - 0xBF
  110. 0x4D00, 0x4E00, 0x4F00, 0x5000, 0x5100, 0x5200, 0x5300, 0x5400, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFB30, 0x0000, // 0xC0 - 0xCF
  111. 0xFC30, 0x7E00, 0x2620, 0x0000, 0x0000, 0x0000, 0x0000, 0x1030, 0x1130, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C30, 0x0D30, 0x08FF, // 0xD0 - 0xDF
  112. 0x09FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0D00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xE0 - 0xEF
  113. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xF0 - 0xFF
  114. };
  115. static const unsigned short japanese_chars_fa[256] = {
  116. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  117. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00 - 0x0F
  118. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x10 - 0x1F
  119. 0x0672, 0x7F4F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3478, 0x4466, 0x8364, 0x0000, 0x0000, 0x0000, // 0x20 - 0x2F
  120. 0x0000, 0x0000, 0x0000, 0x0000, 0x666B, 0x5E79, 0x0000, 0x0000, 0xA898, 0x0000, 0x176C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x30 - 0x3F
  121. 0x885B, 0x0000, 0x7D54, 0x0000, 0xD552, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6297, 0x0000, 0x0000, 0x0000, 0x0854, 0x0000, // 0x40 - 0x4F
  122. 0x0000, 0x0000, 0x0E66, 0x0000, 0x0000, 0x9C62, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x004E, 0x0000, 0x0580, // 0x50 - 0x5F
  123. 0x0000, 0x0000, 0x857F, 0x0000, 0x0000, 0x0000, 0x9950, 0x6856, 0x0000, 0x549B, 0xD56C, 0x0000, 0x0000, 0x0000, 0x0000, 0xFA51, // 0x60 - 0x6F
  124. 0x0163, 0xF876, 0x4B62, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xB965, 0x4C88, 0x0000, // 0x70 - 0x7F
  125. 0x9A5B, 0x0000, 0x0000, 0x4D52, 0x1F77, 0x0000, 0x9A89, 0x1752, 0x8C5F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xDE56, 0x0000, // 0x80 - 0x8F
  126. 0x9A7D, 0x7565, 0x0000, 0x0000, 0x0000, 0x0000, 0x3E5C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0882, 0x0000, 0x0000, // 0x90 - 0x9F
  127. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3E5F, 0x0000, 0x0000, 0x0000, 0x4266, 0x0000, 0x0000, 0x2662, 0x0000, // 0xA0 - 0xAF
  128. 0x0000, 0x0000, 0x0000, 0x0000, 0xB751, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xEA8C, 0x0000, 0x0000, 0x0000, // 0xB0 - 0xBF
  129. 0xCD53, 0x0000, 0xEE76, 0x0000, 0x0000, 0x9B52, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7551, 0x0000, 0x0000, 0x0000, // 0xC0 - 0xCF
  130. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xD0 - 0xDF
  131. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xE0 - 0xEF
  132. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xF0 - 0xFF
  133. };
  134. static const unsigned short japanese_chars_fb[256] = {
  135. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  136. 0x0000, 0x0000, 0xB182, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0B4E, 0x0000, 0x6551, 0x4851, 0x0D4E, 0x505B, 0x9B4F, 0x4B5C, // 0x00 - 0x0F
  137. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8E96, 0x0000, 0x0000, 0xE890, 0x0000, 0x3458, 0x0000, 0xF24E, 0x9395, 0x0000, 0x0000, // 0x10 - 0x1F
  138. 0x5096, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x554F, 0x0000, 0x9965, 0x0000, 0x0A4E, 0x0000, 0x8B4E, 0x0000, 0x0000, // 0x20 - 0x2F
  139. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6559, 0x0000, 0x0000, 0x0000, 0x0000, 0x5167, 0x0000, 0x0000, 0x0000, 0x0000, // 0x30 - 0x3F
  140. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x40 - 0x4F
  141. 0x0000, 0x0000, 0xCA8E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xBA87, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x50 - 0x5F
  142. 0x0000, 0x7751, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xB672, 0x4B61, 0x0000, // 0x60 - 0x6F
  143. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8B95, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x70 - 0x7F
  144. 0x0000, 0x0C54, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7354, 0x0000, 0x0000, 0x0000, 0x0D50, 0x0000, 0x0000, 0x0000, // 0x80 - 0x8F
  145. 0x0000, 0xBA4E, 0xCA4E, 0x0000, 0x0000, 0x535F, 0x0000, 0x0000, 0xDB98, 0xE54E, 0x1659, 0x0000, 0x0000, 0x0000, 0xAB8E, 0x0000, // 0x90 - 0x9F
  146. 0xCB65, 0x0000, 0x0000, 0x0000, 0x5F6A, 0xB068, 0x0000, 0x8970, 0xB065, 0x214E, 0x2C67, 0x1B54, 0x0000, 0x8551, 0x5C4F, 0x668B, // 0xA0 - 0xAF
  147. 0x7972, 0x0000, 0x0000, 0x0000, 0x747A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xB38D, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xB0 - 0xBF
  148. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7795, 0x0000, 0x0000, 0x5458, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8B89, // 0xC0 - 0xCF
  149. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4351, 0x0000, 0x0000, 0x0000, 0x427D, 0x0000, 0x0000, 0x0D54, 0x0000, 0x0000, // 0xD0 - 0xDF
  150. 0x0000, 0x1062, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xE0 - 0xEF
  151. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xF0 - 0xFF
  152. };
  153. static const unsigned short japanese_chars_fc[256] = {
  154. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  155. 0x0000, 0x0000, 0x188A, 0x0000, 0x7890, 0x6A75, 0x5788, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00 - 0x0F
  156. 0x9358, 0xC35F, 0x0000, 0x0000, 0x0000, 0x0000, 0x5390, 0x0000, 0x0000, 0x0000, 0x0000, 0xFB5D, 0x0000, 0x0000, 0x0000, 0x0000, // 0x10 - 0x1F
  157. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x884E, 0x0000, 0x3D84, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x20 - 0x2F
  158. 0xE565, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x30 - 0x3F
  159. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x296E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x40 - 0x4F
  160. 0x0000, 0x0000, 0x7153, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x008A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x50 - 0x5F
  161. 0x3159, 0x5765, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x60 - 0x6F
  162. 0x0000, 0x0000, 0xBC62, 0x0000, 0x0000, 0x0000, 0x5965, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x70 - 0x7F
  163. 0x0000, 0x0000, 0x0000, 0x0000, 0xC253, 0xE577, 0x5E80, 0x0000, 0xD54E, 0x2552, 0xC696, 0xE14F, 0x2875, 0x0000, 0x0000, 0x0000, // 0x80 - 0x8F
  164. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xE965, 0x0000, 0x0000, 0x0000, 0x0000, 0x718A, 0x305E, 0x0000, 0x0000, 0x0000, // 0x90 - 0x9F
  165. 0x0000, 0xF258, 0x6E6D, 0x0000, 0xA052, 0x0000, 0x047D, 0x0000, 0x3C79, 0x5F67, 0x0000, 0x3775, 0x0000, 0x0000, 0x0000, 0xCB7A, // 0xA0 - 0xAF
  166. 0x0000, 0xFA4F, 0x0000, 0x0000, 0x0000, 0xC179, 0x0000, 0x0000, 0x1250, 0x114F, 0x0000, 0x0000, 0x0000, 0xA952, 0x0000, 0x0000, // 0xB0 - 0xBF
  167. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xAC8A, 0x0000, 0x0000, 0xF167, 0x0000, 0x0000, // 0xC0 - 0xCF
  168. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xD0 - 0xDF
  169. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xE0 - 0xEF
  170. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xF0 - 0xFF
  171. };
  172. static const unsigned short japanese_chars_fd[256] = {
  173. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  174. 0x0000, 0x1D4F, 0x0000, 0xA263, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00 - 0x0F
  175. 0xE682, 0x0000, 0xF056, 0x0000, 0x0000, 0x0000, 0x0000, 0xA25B, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x10 - 0x1F
  176. 0x0000, 0x2B59, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xB88C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xDD4F, 0x2F5E, // 0x20 - 0x2F
  177. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7289, 0x0000, 0x216B, 0x0000, 0x207D, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x30 - 0x3F
  178. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xB78C, 0x0000, 0x0000, 0x0000, 0x7C5E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x40 - 0x4F
  179. 0x0000, 0x0000, 0x0000, 0x0000, 0x8179, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x50 - 0x5F
  180. 0x0000, 0x975E, 0x0000, 0x0000, 0x0000, 0xCA7D, 0x1478, 0x0000, 0x0000, 0x8766, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x60 - 0x6F
  181. 0xC599, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x70 - 0x7F
  182. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFD88, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x80 - 0x8F
  183. 0x0000, 0x0000, 0x3293, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5453, 0x0000, 0x0000, // 0x90 - 0x9F
  184. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8D8E, 0x0000, 0x0000, 0x0000, 0x0000, 0x3052, 0x0000, 0x0000, 0x0000, 0x0000, // 0xA0 - 0xAF
  185. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xB0 - 0xBF
  186. 0x9F52, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5291, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xC0 - 0xCF
  187. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xD0 - 0xDF
  188. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xE0 - 0xEF
  189. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xF0 - 0xFF
  190. };
  191. static const unsigned short japanese_chars_fe[256] = {
  192. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  193. 0x0000, 0x0000, 0x0000, 0x667D, 0x0000, 0x0000, 0x0000, 0xAD65, 0x0000, 0x0000, 0xB96C, 0x0000, 0xD550, 0x585B, 0x0000, 0x0000, // 0x00 - 0x0F
  194. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x10 - 0x1F
  195. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8B4F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x20 - 0x2F
  196. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x9758, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x30 - 0x3F
  197. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x40 - 0x4F
  198. 0x0000, 0x0000, 0x0000, 0xB48C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4256, 0xF158, 0x0000, 0x0000, 0x0000, 0x0000, // 0x50 - 0x5F
  199. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xB54F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x60 - 0x6F
  200. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1D8B, 0x0000, 0x0000, 0x0000, 0xA14F, 0x206B, 0xC45B, 0xD95F, // 0x70 - 0x7F
  201. 0x0000, 0x944E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xA65E, 0x0000, 0x0000, 0x0000, 0x0000, 0x988A, // 0x80 - 0x8F
  202. 0x0000, 0x0000, 0x298F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x668A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x90 - 0x9F
  203. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7272, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xA0 - 0xAF
  204. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xC079, 0x0000, 0xFD8E, 0x0000, 0x0000, 0x0000, // 0xB0 - 0xBF
  205. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3B52, // 0xC0 - 0xCF
  206. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xD0 - 0xDF
  207. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xE0 - 0xEF
  208. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0xF0 - 0xFF
  209. };
  210. static const std::map<int, Ogre::String> MapIdToFieldName
  211. {
  212. { 0x74, "ffvii_md1stin" },
  213. { 0x75, "ffvii_md1_1" },
  214. { 0x76, "ffvii_md1_2" }
  215. };
  216. Ogre::String
  217. MapIdToString( const int map_id )
  218. {
  219. auto it = MapIdToFieldName.find(map_id);
  220. if (it != std::end(MapIdToFieldName))
  221. {
  222. return it->second;
  223. }
  224. return "Unknown_0x" + HexToString( map_id, 4, '0' );
  225. }
  226. float
  227. MapIdToScale( const int map_id )
  228. {
  229. switch( map_id )
  230. {
  231. case 0x75: return 2.0f;
  232. }
  233. return 1.0f;
  234. }
  235. DatFile::DatFile(const Ogre::String &file):
  236. LzsFile(file)
  237. {
  238. }
  239. DatFile::DatFile(File *file, const u32 offset, const u32 length):
  240. LzsFile(file, offset, length)
  241. {
  242. }
  243. DatFile::DatFile(u8* buffer, const u32 offset, const u32 length):
  244. LzsFile(buffer, offset, length)
  245. {
  246. }
  247. DatFile::DatFile(File *file):
  248. LzsFile(file)
  249. {
  250. }
  251. DatFile::~DatFile()
  252. {
  253. delete full_image;
  254. for( u8 i = 0; i < m_Surfaces.size(); ++i )
  255. {
  256. delete m_Surfaces[ i ].surface;
  257. }
  258. m_Surfaces.clear();
  259. }
  260. void
  261. DatFile::DumpText( const Ogre::String& export_path, const Field& field, bool english )
  262. {
  263. std::sort( m_Dialogs.begin(), m_Dialogs.end() );
  264. m_Dialogs.erase( std::unique( m_Dialogs.begin(), m_Dialogs.end()), m_Dialogs.end() );
  265. Logger* export_text = new Logger( export_path + "maps/ffvii_field/" + field.name + "_text.txt" );
  266. // get sector 1 offset (scripts and dialog)
  267. u32 offset_to_sector = 0x1C;
  268. u16 offset_to_dialogs = GetU16LE( offset_to_sector + 0x04 );
  269. std::vector< unsigned char > dialog;
  270. dialog.push_back(0xFF);
  271. dialog.push_back(0xFE);
  272. for (unsigned int i = 0; i < m_Dialogs.size(); ++i)
  273. {
  274. // get offset of string data
  275. u32 offset = offset_to_sector + offset_to_dialogs + GetU16LE(offset_to_sector + offset_to_dialogs + 0x02 + m_Dialogs[i] * 0x02);
  276. export_text->Log(dialog);
  277. dialog.clear();
  278. export_text->LogW( "<dialog id=\"" + IntToString(m_Dialogs[i]) + "\">" );
  279. for (unsigned char temp = 0x00; ; ++offset)
  280. {
  281. temp = GetU8(offset);
  282. if (temp == 0xFF)
  283. {
  284. break;
  285. }
  286. if (temp == 0xE0 && english == true)
  287. {
  288. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  289. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  290. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  291. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  292. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  293. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  294. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  295. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  296. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  297. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  298. }
  299. else if (temp == 0xE1 && english == true)
  300. {
  301. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  302. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  303. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  304. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  305. }
  306. else if (temp == 0xE2 && english == true)
  307. {
  308. dialog.push_back(english_chars[0x0C] >> 8); dialog.push_back(english_chars[0x0C] & 0xFF);
  309. dialog.push_back(english_chars[0x00] >> 8); dialog.push_back(english_chars[0x00] & 0xFF);
  310. }
  311. else if (temp == 0xE8)
  312. {
  313. export_text->Log(dialog);
  314. dialog.clear();
  315. export_text->LogW("<new_window />");
  316. }
  317. else if (temp == 0xEA)
  318. {
  319. export_text->Log(dialog);
  320. dialog.clear();
  321. export_text->LogW("<character id=\"0\" />");
  322. }
  323. else if (temp == 0xEB)
  324. {
  325. export_text->Log(dialog);
  326. dialog.clear();
  327. export_text->LogW("<character id=\"1\" />");
  328. }
  329. else if (temp == 0xEC)
  330. {
  331. export_text->Log(dialog);
  332. dialog.clear();
  333. export_text->LogW("<character id=\"2\" />");
  334. }
  335. else if (temp == 0xED)
  336. {
  337. export_text->Log(dialog);
  338. dialog.clear();
  339. export_text->LogW("<character id=\"3\" />");
  340. }
  341. else if (temp == 0xEE)
  342. {
  343. export_text->Log(dialog);
  344. dialog.clear();
  345. export_text->LogW("<character id=\"4\" />");
  346. }
  347. else if (temp == 0xEF)
  348. {
  349. export_text->Log(dialog);
  350. dialog.clear();
  351. export_text->LogW("<character id=\"5\" />");
  352. }
  353. else if (temp == 0xF0)
  354. {
  355. export_text->Log(dialog);
  356. dialog.clear();
  357. export_text->LogW("<character id=\"6\" />");
  358. }
  359. else if (temp == 0xF1)
  360. {
  361. export_text->Log(dialog);
  362. dialog.clear();
  363. export_text->LogW("<character id=\"7\" />");
  364. }
  365. else if (temp == 0xF2)
  366. {
  367. export_text->Log(dialog);
  368. dialog.clear();
  369. export_text->LogW("<character id=\"8\" />");
  370. }
  371. else if (temp == 0xF3)
  372. {
  373. export_text->Log(dialog);
  374. dialog.clear();
  375. export_text->LogW("<character party_id=\"0\" />");
  376. }
  377. else if (temp == 0xF4)
  378. {
  379. export_text->Log(dialog);
  380. dialog.clear();
  381. export_text->LogW("<character party_id=\"1\" />");
  382. }
  383. else if (temp == 0xF5)
  384. {
  385. export_text->Log(dialog);
  386. dialog.clear();
  387. export_text->LogW("<character party_id=\"2\" />");
  388. }
  389. else if (temp == 0xF6)
  390. {
  391. export_text->Log(dialog);
  392. dialog.clear();
  393. export_text->LogW("<image id=\"circle\" />");
  394. }
  395. else if (temp == 0xF7)
  396. {
  397. export_text->Log(dialog);
  398. dialog.clear();
  399. export_text->LogW("<image id=\"triangle\" />");
  400. }
  401. else if (temp == 0xF8)
  402. {
  403. export_text->Log(dialog);
  404. dialog.clear();
  405. export_text->LogW("<image id=\"square\" />");
  406. }
  407. else if (temp == 0xF9)
  408. {
  409. export_text->Log(dialog);
  410. dialog.clear();
  411. export_text->LogW("<image id=\"cross\" />");
  412. }
  413. else if ((temp == 0xFA || temp == 0xFB ||temp == 0xFC ||temp == 0xFD) && english == false)
  414. {
  415. ++offset;
  416. unsigned char temp2 = GetU8(offset);
  417. if (temp == 0xFA)
  418. {
  419. if (japanese_chars_fa[temp2] != 0x0000)
  420. {
  421. dialog.push_back(japanese_chars_fa[temp2] >> 8); dialog.push_back(japanese_chars_fa[temp2] & 0xFF);
  422. }
  423. else
  424. {
  425. export_text->Log(dialog);
  426. dialog.clear();
  427. export_text->LogW("[MISSING 0xFA " + HexToString(temp2, 2, '0') + "]");
  428. }
  429. }
  430. else if (temp == 0xFB)
  431. {
  432. if (japanese_chars_fb[temp2] != 0x0000)
  433. {
  434. dialog.push_back(japanese_chars_fb[temp2] >> 8); dialog.push_back(japanese_chars_fb[temp2] & 0xFF);
  435. }
  436. else
  437. {
  438. export_text->Log(dialog);
  439. dialog.clear();
  440. export_text->LogW("[MISSING 0xFB " + HexToString(temp2, 2, '0') + "]");
  441. }
  442. }
  443. else if (temp == 0xFC)
  444. {
  445. if (japanese_chars_fc[temp2] != 0x0000)
  446. {
  447. dialog.push_back(japanese_chars_fc[temp2] >> 8); dialog.push_back(japanese_chars_fc[temp2] & 0xFF);
  448. }
  449. else
  450. {
  451. export_text->Log(dialog);
  452. dialog.clear();
  453. export_text->LogW("[MISSING 0xFC " + HexToString(temp2, 2, '0') + "]");
  454. }
  455. }
  456. else if( temp == 0xFD )
  457. {
  458. if( japanese_chars_fd[ temp2 ] != 0x0000 )
  459. {
  460. dialog.push_back( japanese_chars_fd[ temp2 ] >> 8 ); dialog.push_back( japanese_chars_fd[ temp2 ] & 0xFF );
  461. }
  462. else
  463. {
  464. export_text->Log( dialog );
  465. dialog.clear();
  466. export_text->LogW( "[MISSING 0xFD " + HexToString( temp2, 2, '0' ) + "]" );
  467. }
  468. }
  469. }
  470. else if (temp == 0xFE)
  471. {
  472. ++offset;
  473. unsigned char temp2 = GetU8(offset);
  474. if (temp2 == 0xD4)
  475. {
  476. export_text->Log(dialog);
  477. dialog.clear();
  478. export_text->LogW("<colour id=\"red\" />");
  479. }
  480. else if (temp2 == 0xD5)
  481. {
  482. export_text->Log(dialog);
  483. dialog.clear();
  484. export_text->LogW("<colour id=\"purple\" />");
  485. }
  486. else if (temp2 == 0xD6)
  487. {
  488. export_text->Log(dialog);
  489. dialog.clear();
  490. export_text->LogW("<colour id=\"green\" />");
  491. }
  492. else if (temp2 == 0xD7)
  493. {
  494. export_text->Log(dialog);
  495. dialog.clear();
  496. export_text->LogW("<colour id=\"cyan\" />");
  497. }
  498. else if (temp2 == 0xD8)
  499. {
  500. export_text->Log(dialog);
  501. dialog.clear();
  502. export_text->LogW("<colour id=\"yellow\" />");
  503. }
  504. else if (temp2 == 0xD9)
  505. {
  506. export_text->Log(dialog);
  507. dialog.clear();
  508. export_text->LogW("<colour id=\"white\" />");
  509. }
  510. else if (temp2 == 0xDC)
  511. {
  512. export_text->Log(dialog);
  513. dialog.clear();
  514. export_text->LogW("<pause_ok />");
  515. }
  516. else if (temp2 == 0xDD)
  517. {
  518. u16 wait = GetU16LE(offset + 1);
  519. ++offset;
  520. ++offset;
  521. export_text->Log(dialog);
  522. dialog.clear();
  523. export_text->LogW("<pause wait=\"" + IntToString(wait) + "\" />");
  524. }
  525. else
  526. {
  527. if (japanese_chars_fe[temp2] != 0x0000 && english == false)
  528. {
  529. dialog.push_back(japanese_chars_fe[temp2] >> 8); dialog.push_back(japanese_chars_fe[temp2] & 0xFF);
  530. }
  531. else
  532. {
  533. export_text->Log(dialog);
  534. dialog.clear();
  535. export_text->LogW("[MISSING 0xFE " + HexToString(temp2, 2, '0') + "]");
  536. }
  537. }
  538. }
  539. else
  540. {
  541. if (japanese_chars[temp] != 0x0000 && english == false)
  542. {
  543. dialog.push_back(japanese_chars[temp] >> 8); dialog.push_back(japanese_chars[temp] & 0xFF);
  544. }
  545. else if (english_chars[temp] != 0x0000 && english == true)
  546. {
  547. dialog.push_back(english_chars[temp] >> 8); dialog.push_back(english_chars[temp] & 0xFF);
  548. }
  549. else
  550. {
  551. export_text->Log(dialog);
  552. dialog.clear();
  553. export_text->LogW("[MISSING CHAR " + HexToString(temp, 2, '0') + "]");
  554. }
  555. }
  556. }
  557. export_text->Log(dialog);
  558. dialog.clear();
  559. export_text->LogW("</dialog>\n\n");
  560. }
  561. delete export_text;
  562. }
  563. void
  564. DatFile::DumpScript(const Ogre::String& export_path, const Field& field)
  565. {
  566. Logger* export_script = new Logger(export_path + "maps/ffvii_field/" + field.name + "_script.txt");
  567. // get sector 1 offset (scripts and dialog)
  568. u32 start_address = GetU32LE(0);
  569. u32 offset_to_sector = 0x1c;
  570. u8 number_of_entity = GetU8(offset_to_sector + 0x02);
  571. u16 string_offset = GetU16LE(offset_to_sector + 0x04);
  572. u16 number_of_extra_offsets = GetU16LE(offset_to_sector + 0x06);
  573. float downscaler = 128.0f * field.scale;
  574. std::vector< Ogre::String > entity_list;
  575. for (u8 i = 0; i < number_of_entity; ++i)
  576. {
  577. // get entity name
  578. Ogre::String name = Ogre::String(reinterpret_cast<char*>(m_Buffer)+offset_to_sector + 0x20 + i * 0x08);
  579. if (name == "")
  580. {
  581. name = "unnamed_" + IntToString(i);
  582. }
  583. entity_list.push_back(name);
  584. }
  585. for (u8 i = 0; i < number_of_entity; ++i)
  586. {
  587. export_script->Log(entity_list[i] + "\n");
  588. u32 prev_script = 0;
  589. bool one_ret_check = false;
  590. for (u8 j = 0; j < 32; ++j)
  591. {
  592. u32 script = offset_to_sector + GetU16LE(offset_to_sector + 0x20 + number_of_entity * 0x08 + number_of_extra_offsets * 0x04 + i * 0x40 + j * 0x02);
  593. u32 end = script;
  594. u8 opcode = GetU8(script);
  595. if (opcode == 0x00 && j != 0) // skip if script contain only RET opcode and this is not init script
  596. {
  597. continue;
  598. }
  599. if (prev_script == script)
  600. {
  601. continue;
  602. }
  603. prev_script = script;
  604. export_script->Log("script_" + IntToString(j) + ":\n");
  605. for (; script <= end;)
  606. {
  607. export_script->Log(OffsetString(script) + " (end " + OffsetString(end) + "): ");
  608. u8 opcode = GetU8(script);
  609. switch (opcode)
  610. {
  611. case RET:
  612. {
  613. export_script->Log("return\n");
  614. if (j == 0 && one_ret_check == false) // in init we need to meet ret at least once
  615. {
  616. AdvanceScript(1, script, end);
  617. one_ret_check = true;
  618. }
  619. else
  620. {
  621. script += 1;
  622. }
  623. } break;
  624. case REQ:
  625. {
  626. u8 entity_id = GetU8(script + 1);
  627. u8 priority = GetU8(script + 2) >> 5;
  628. u8 script_id = GetU8(script + 2) & 0x1F;
  629. export_script->Log("script:request( \"" + entity_list[entity_id] + "\", \"script_" + IntToString(script_id) + "\", " + IntToString(priority) + " )\n");
  630. AdvanceScript(3, script, end);
  631. } break;
  632. case REQSW:
  633. {
  634. u8 entity_id = GetU8(script + 1);
  635. u8 priority = GetU8(script + 2) >> 5;
  636. u8 script_id = GetU8(script + 2) & 0x1F;
  637. export_script->Log("script:request_start_sync( \"" + entity_list[entity_id] + "\", \"script_" + IntToString(script_id) + "\", " + IntToString(priority) + " )\n");
  638. AdvanceScript(3, script, end);
  639. } break;
  640. case REQEW:
  641. {
  642. u8 entity_id = GetU8(script + 1);
  643. u8 priority = GetU8(script + 2) >> 5;
  644. u8 script_id = GetU8(script + 2) & 0x1F;
  645. export_script->Log("script:request_end_sync( \"" + entity_list[entity_id] + "\", \"script_" + IntToString(script_id) + "\", " + IntToString(priority) + " )\n");
  646. AdvanceScript(3, script, end);
  647. } break;
  648. case RETTO:
  649. {
  650. u8 priority = GetU8(script + 1) >> 5;
  651. u8 script_id = GetU8(script + 1) & 0x1F;
  652. export_script->Log(
  653. "return_to( \"script_" +
  654. IntToString(script_id) +
  655. "\", " +
  656. IntToString(priority) +
  657. " );\n"
  658. );
  659. script += 2;
  660. } break;
  661. case JOIN:
  662. {
  663. export_script->Log(
  664. "[UNREVERSED] JOIN(" +
  665. ArgumentString(script + 1, 1) +
  666. ");\n"
  667. );
  668. AdvanceScript(2, script, end);
  669. } break;
  670. case SPLIT:
  671. {
  672. export_script->Log(
  673. "[UNREVERSED] SPLIT(" +
  674. ArgumentString(script + 1, 14) +
  675. ");\n"
  676. );
  677. AdvanceScript(15, script, end);
  678. } break;
  679. case SPTYE:
  680. {
  681. export_script->Log(
  682. "game:party_set( " +
  683. ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 3)) +
  684. ", " +
  685. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 4)) +
  686. ", " +
  687. ParseGetVariable(GetU8(script + 2) >> 4, GetU8(script + 5)) +
  688. " );\n"
  689. );
  690. AdvanceScript(6, script, end);
  691. } break;
  692. case GTPYE:
  693. {
  694. export_script->Log(
  695. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 3), "game:party_get_id_of_member( 0 )") +
  696. SetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 4), "game:party_get_id_of_member( 1 )") +
  697. SetVariable(GetU8(script + 2) >> 4, GetU8(script + 5), "game:party_get_id_of_member( 2 )")
  698. );
  699. AdvanceScript(6, script, end);
  700. } break;
  701. case SPECIAL:
  702. {
  703. u8 special_opcode = GetU8(script + 1);
  704. if (special_opcode == 0xF5) // ARROW
  705. {
  706. export_script->Log(
  707. "game:pointer_enable( " +
  708. BoolToString(!(GetU8(script + 2))) +
  709. " )\n"
  710. );
  711. AdvanceScript(3, script, end);
  712. }
  713. else if (special_opcode == 0xF9) // FLMAT
  714. {
  715. export_script->Log("game:fill_materia()\n");
  716. AdvanceScript(2, script, end);
  717. }
  718. else if (special_opcode == 0xFB) // BTLLK
  719. {
  720. export_script->Log(
  721. "game:battle_enable( " +
  722. BoolToString(!(GetU8(script + 2))) +
  723. " )\n"
  724. );
  725. AdvanceScript(3, script, end);
  726. }
  727. else if (special_opcode == 0xFC) // MVLCK
  728. {
  729. export_script->Log(
  730. "game:movie_enable( " +
  731. BoolToString(!(GetU8(script + 2))) +
  732. " )\n"
  733. );
  734. AdvanceScript(3, script, end);
  735. }
  736. else if (special_opcode == 0xFD) // SPCNM
  737. {
  738. export_script->Log(
  739. "[UNREVERSED] SPECIAL SPCNM(" +
  740. ArgumentString(script + 2, 2) +
  741. ");\n"
  742. );
  743. AdvanceScript(4, script, end);
  744. }
  745. else if (special_opcode == 0xFE) // RSGLB
  746. {
  747. export_script->Log("game:global_reset()\n");
  748. AdvanceScript(2, script, end);
  749. }
  750. else
  751. {
  752. export_script->Log("[SPECIAL OPCODE " + HexToString(special_opcode, 2, '0') + "]\n");
  753. script += 2;
  754. }
  755. } break;
  756. case JMPF:
  757. {
  758. u32 temp_end = script + GetU8(script + 1) + 1;
  759. export_script->Log("jumpto( " + OffsetString(temp_end) + " );\n");
  760. end = (temp_end > end) ? temp_end : end;
  761. script += 2;
  762. } break;
  763. case JMPFL:
  764. {
  765. u32 temp_end = script + GetU16LE(script + 1) + 1;
  766. export_script->Log(
  767. "jumpto( " +
  768. OffsetString(temp_end) +
  769. " );\n"
  770. );
  771. end = (temp_end > end) ? temp_end : end;
  772. script += 3;
  773. } break;
  774. case JMPB:
  775. {
  776. export_script->Log(
  777. "jumpto( " +
  778. OffsetString(script - GetU8(script + 1)) +
  779. " );\n"
  780. );
  781. script += 2;
  782. } break;
  783. case JMPBL:
  784. {
  785. export_script->Log(
  786. "jumpto( " +
  787. OffsetString(script - GetU16LE(script + 1)) +
  788. " );\n"
  789. );
  790. script += 3;
  791. } break;
  792. case IFUB:
  793. {
  794. u32 temp_end = script + GetU8(script + 5) + 5;
  795. export_script->Log(
  796. "if ( " +
  797. ParseRelation(GetU8(script + 4), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)), ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3))) +
  798. " ) then continue else jumpto(" + OffsetString(temp_end) + ");\n"
  799. );
  800. end = (temp_end > end) ? temp_end : end;
  801. script += 6;
  802. } break;
  803. case IFUBL:
  804. {
  805. u32 temp_end = script + GetU16LE(script + 5) + 5;
  806. export_script->Log(
  807. "if ( " +
  808. ParseRelation(GetU8(script + 4), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)), ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3))) +
  809. " ) then continue else jumpto(" + OffsetString(temp_end) + ");\n"
  810. );
  811. end = (temp_end > end) ? temp_end : end;
  812. script += 7;
  813. } break;
  814. case IFSW:
  815. {
  816. u32 temp_end = script + GetU8(script + 7) + 7;
  817. export_script->Log(
  818. "if ( " +
  819. ParseRelation(GetU8(script + 6), ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 2)), ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 4))) +
  820. " ) then continue else jumpto(" + OffsetString(temp_end) + ");\n"
  821. );
  822. // If we find a jump back to this address, then this if statement is actually a while()
  823. end = (temp_end > end) ? temp_end : end;
  824. script += 8;
  825. } break;
  826. case IFSWL:
  827. {
  828. u32 temp_end = script + GetU16LE(script + 7) + 7;
  829. export_script->Log(
  830. "if ( " +
  831. ParseRelation(GetU8(script + 6), ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 2)), ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 4))) +
  832. " ) then continue else jumpto(" + OffsetString(temp_end) + ");\n"
  833. );
  834. end = (temp_end > end) ? temp_end : end;
  835. script += 9;
  836. } break;
  837. case IFUW:
  838. {
  839. u32 temp_end = script + GetU8(script + 7) + 7;
  840. export_script->Log(
  841. "if ( " +
  842. ParseRelation(GetU8(script + 6), ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 2)), ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 4))) +
  843. " ) then continue else jumpto(" + OffsetString(temp_end) + ");\n"
  844. );
  845. end = (temp_end > end) ? temp_end : end;
  846. script += 8;
  847. } break;
  848. case TUTOR:
  849. {
  850. export_script->Log(
  851. "[UNREVERSED] TUTOR(" +
  852. ArgumentString(script + 1, 1) +
  853. ");\n"
  854. );
  855. AdvanceScript(2, script, end);
  856. } break;
  857. case WAIT:
  858. {
  859. export_script->Log("script:wait( " + FloatToString(GetU16LE(script + 1) / 30.0f) + " )\n");
  860. AdvanceScript(3, script, end);
  861. } break;
  862. case NFADE:
  863. {
  864. u8 type = GetU8(script + 3);
  865. if (type == 0)
  866. {
  867. export_script->Log("fade:clear();\n");
  868. }
  869. else
  870. {
  871. export_script->Log(
  872. "[NEEDS TO CHECK NFADE time needs to be divided] fade:fade(" +
  873. ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 4)) +
  874. ", " +
  875. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 5)) +
  876. ", " +
  877. ParseGetVariable(GetU8(script + 2) >> 4, GetU16LE(script + 6)) +
  878. ", " +
  879. ((type == 12) ? "Fade.SUBTRACT" : "Fade.ADD") +
  880. ", " +
  881. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU16LE(script + 7)) +
  882. ");\n"
  883. );
  884. }
  885. AdvanceScript(9, script, end);
  886. } break;
  887. case BLINK:
  888. {
  889. export_script->Log(
  890. entity_list[i] +
  891. ":enable_eye_blink(" +
  892. BoolToString(!(GetU8(script + 1))) +
  893. ");\n"
  894. );
  895. AdvanceScript(2, script, end);
  896. } break;
  897. case KAWAI:
  898. {
  899. u8 kawai_length = GetU8(script + 1);
  900. export_script->Log(
  901. "[UNREVERSED] KAWAI(" +
  902. ArgumentString(script + 1, kawai_length - 1) +
  903. ");\n"
  904. );
  905. AdvanceScript(kawai_length, script, end);
  906. } break;
  907. case WCLS:
  908. {
  909. export_script->Log(
  910. "[UNREVERSED] WCLS(" +
  911. ArgumentString(script + 1, 1) +
  912. ");\n"
  913. );
  914. AdvanceScript(2, script, end);
  915. } break;
  916. case WSIZW:
  917. {
  918. u8 type = GetU8(script + 2);
  919. export_script->Log(
  920. "-- resize window (id = " +
  921. IntToString(GetU8(script + 1)) +
  922. ", x = " +
  923. IntToString(GetU16LE(script + 2)) +
  924. ", y = " +
  925. IntToString(GetU16LE(script + 4)) +
  926. ", width = " +
  927. IntToString(GetU16LE(script + 6)) +
  928. ", height = " +
  929. IntToString(GetU16LE(script + 8)) +
  930. ");\n"
  931. );
  932. AdvanceScript(10, script, end);
  933. } break;
  934. case IFKEY:
  935. {
  936. u32 temp_end = script + GetU8(script + 3) + 3;
  937. export_script->Log(
  938. "if (pressed buttons \"" +
  939. HexToString(GetU16LE(script + 1), 4, '0') +
  940. "\") then continue else jumpto(" + OffsetString(temp_end) + ");\n"
  941. );
  942. end = (temp_end > end) ? temp_end : end;
  943. script += 4;
  944. } break;
  945. case IFKEYON:
  946. {
  947. u32 temp_end = script + GetU8(script + 3) + 3;
  948. export_script->Log(
  949. "if (first pressed buttons \"" +
  950. HexToString(GetU16LE(script + 1), 4, '0') +
  951. "\") then continue else jumpto(" + OffsetString(temp_end) + ");\n"
  952. );
  953. end = (temp_end > end) ? temp_end : end;
  954. script += 4;
  955. } break;
  956. case UC:
  957. {
  958. export_script->Log(
  959. "field:pc_lock(" +
  960. BoolToString(GetU8(script + 1) > 0) +
  961. ");\n"
  962. );
  963. AdvanceScript(2, script, end);
  964. } break;
  965. case WSPCL:
  966. {
  967. export_script->Log(
  968. "[UNREVERSED] WSPCL(" +
  969. ArgumentString(script + 1, 4) +
  970. ");\n"
  971. );
  972. AdvanceScript(5, script, end);
  973. } break;
  974. case STTIM:
  975. {
  976. export_script->Log(
  977. "game:set_timer(hours(" +
  978. ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 3)) +
  979. "), minutes(" +
  980. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 4)) +
  981. "), seconds(" +
  982. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU8(script + 5)) +
  983. "));\n"
  984. );
  985. AdvanceScript(6, script, end);
  986. } break;
  987. case GOLDU:
  988. {
  989. export_script->Log(
  990. "game:add_money(upper(" +
  991. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 4)) +
  992. "), lower(" +
  993. ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 2)) +
  994. "));\n"
  995. );
  996. AdvanceScript(6, script, end);
  997. } break;
  998. case GOLDD:
  999. {
  1000. export_script->Log(
  1001. "game:remove_money(upper(" +
  1002. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 4)) +
  1003. "), lower(" +
  1004. ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 2)) +
  1005. "));\n"
  1006. );
  1007. AdvanceScript(6, script, end);
  1008. } break;
  1009. case CHGLD:
  1010. {
  1011. export_script->Log(
  1012. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), "game:get_money_lower()") +
  1013. SetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3), "game:get_money_top()")
  1014. );
  1015. AdvanceScript(4, script, end);
  1016. } break;
  1017. case MHMMX:
  1018. {
  1019. export_script->Log(
  1020. "game:restore_hp_mp_status_to_all();\n"
  1021. );
  1022. AdvanceScript(1, script, end);
  1023. } break;
  1024. case HMPMAX3:
  1025. {
  1026. export_script->Log(
  1027. "game:party_restore_hp_mp();\n"
  1028. );
  1029. AdvanceScript(1, script, end);
  1030. } break;
  1031. case MESSAGE:
  1032. {
  1033. m_Dialogs.push_back(GetU8(script + 2));
  1034. export_script->Log(
  1035. "message:show_text_wait(" +
  1036. IntToString(GetU8(script + 1)) +
  1037. ", " +
  1038. IntToString(GetU8(script + 2)) +
  1039. ", x, y);\n"
  1040. );
  1041. AdvanceScript(3, script, end);
  1042. } break;
  1043. case MPNAM:
  1044. {
  1045. m_Dialogs.push_back(GetU8(script + 1));
  1046. export_script->Log(
  1047. "field:map_name(" +
  1048. IntToString(GetU8(script + 1)) +
  1049. ");\n"
  1050. );
  1051. AdvanceScript(2, script, end);
  1052. } break;
  1053. case ASK:
  1054. {
  1055. m_Dialogs.push_back(GetU8(script + 3));
  1056. export_script->Log(
  1057. "message:show_text_wait(" +
  1058. IntToString(GetU8(script + 2)) +
  1059. ", " +
  1060. IntToString(GetU8(script + 3)) +
  1061. ", x, y); -- ASK cursor at \"" +
  1062. ParseGetVariable(GetU8(script + 1), GetU8(script + 6)) +
  1063. "\", start " +
  1064. IntToString(GetU8(script + 4)) +
  1065. ", end " +
  1066. IntToString(GetU8(script + 5)) +
  1067. "\n"
  1068. );
  1069. AdvanceScript(7, script, end);
  1070. } break;
  1071. case MENU:
  1072. {
  1073. export_script->Log(
  1074. "[UNREVERSED] MENU(" +
  1075. ArgumentString(script + 1, 3) +
  1076. ");\n"
  1077. );
  1078. AdvanceScript(4, script, end);
  1079. } break;
  1080. case MENU2:
  1081. {
  1082. export_script->Log(
  1083. "field:menu_lock(" +
  1084. BoolToString(GetU8(script + 1) > 0) +
  1085. ");\n"
  1086. );
  1087. AdvanceScript(2, script, end);
  1088. } break;
  1089. case BTLTB:
  1090. {
  1091. export_script->Log(
  1092. "field:set_battle_table(" +
  1093. IntToString(GetU8(script + 1)) +
  1094. ");\n"
  1095. );
  1096. AdvanceScript(2, script, end);
  1097. } break;
  1098. case WINDOW:
  1099. {
  1100. export_script->Log(
  1101. "-- set window parameters (id = " +
  1102. IntToString(GetU8(script + 1)) +
  1103. ", x = " +
  1104. IntToString(GetU16LE(script + 2)) +
  1105. ", y = " +
  1106. IntToString(GetU16LE(script + 4)) +
  1107. ", width = " +
  1108. IntToString(GetU16LE(script + 6)) +
  1109. ", height = " +
  1110. IntToString(GetU16LE(script + 8)) +
  1111. ");\n"
  1112. );
  1113. AdvanceScript(10, script, end);
  1114. } break;
  1115. case WMODE:
  1116. {
  1117. u8 type = GetU8(script + 2);
  1118. export_script->Log(
  1119. "-- set window mode (id = " +
  1120. IntToString(GetU8(script + 1)) +
  1121. ", MessageStyle." +
  1122. ((type == 0) ? "SOLID" : ((type == 1) ? "NONE" : "TRANSPARENT")) +
  1123. ", disable input from player: " +
  1124. BoolToString(GetU8(script + 3) > 0) +
  1125. ");\n"
  1126. );
  1127. AdvanceScript(4, script, end);
  1128. } break;
  1129. case WREST:
  1130. {
  1131. export_script->Log(
  1132. "-- reset window to default (id = " +
  1133. IntToString(GetU8(script + 1)) +
  1134. ");\n"
  1135. );
  1136. AdvanceScript(2, script, end);
  1137. } break;
  1138. case WCLSE:
  1139. {
  1140. export_script->Log(
  1141. "[UNREVERSED] WCLSE(" +
  1142. ArgumentString(script + 1, 1) +
  1143. ");\n"
  1144. );
  1145. AdvanceScript(2, script, end);
  1146. } break;
  1147. case STITM:
  1148. {
  1149. export_script->Log(
  1150. "game:item_add(" +
  1151. ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 2)) +
  1152. ", " +
  1153. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 4)) +
  1154. ");\n"
  1155. );
  1156. AdvanceScript(5, script, end);
  1157. } break;
  1158. case CKITM:
  1159. {
  1160. export_script->Log(
  1161. SetVariable(GetU8(script + 1), GetU8(script + 4), "game:get_number_of_item(" + IntToString(GetU16LE(script + 2)) + ")")
  1162. );
  1163. AdvanceScript(5, script, end);
  1164. } break;
  1165. case SMTRA:
  1166. {
  1167. export_script->Log(
  1168. "game:materia_add(" +
  1169. ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 3)) +
  1170. ", " +
  1171. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 4)) +
  1172. ", " +
  1173. ParseGetVariable(GetU8(script + 2) >> 4, GetU16LE(script + 5)) +
  1174. ", " +
  1175. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU8(script + 6)) +
  1176. ");\n"
  1177. );
  1178. AdvanceScript(7, script, end);
  1179. } break;
  1180. case SHAKE:
  1181. {
  1182. export_script->Log(
  1183. "[UNREVERSED] SHAKE(" +
  1184. ArgumentString(script + 1, 7) +
  1185. ");\n"
  1186. );
  1187. AdvanceScript(8, script, end);
  1188. } break;
  1189. case MAPJUMP:
  1190. {
  1191. export_script->Log(
  1192. "field:jump_to_map(" +
  1193. IntToString(GetU16LE(script + 1)) +
  1194. ", " +
  1195. IntToString(GetU16LE(script + 3)) +
  1196. ", " +
  1197. IntToString(GetU16LE(script + 5)) +
  1198. ", " +
  1199. IntToString(GetU16LE(script + 7)) +
  1200. ", " +
  1201. FloatToString((GetU8(script + 9) / 256.0f) * 360.0f) +
  1202. ");\n"
  1203. );
  1204. AdvanceScript(10, script, end);
  1205. } break;
  1206. case SCRLC:
  1207. {
  1208. int type = GetU8(script + 4);
  1209. export_script->Log(
  1210. "field:screen_set_scroll_to_pc(" +
  1211. ((type == 4) ? "Field.NONE" : ((type == 5) ? "Field.LINEAR" : ((type == 6) ? "Field.SMOOTH" : "Unknown_type_" + IntToString(type)))) +
  1212. ", " +
  1213. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 2), 0, 30.0f) +
  1214. ");\n"
  1215. );
  1216. AdvanceScript(5, script, end);
  1217. } break;
  1218. case SCRLA:
  1219. {
  1220. int type = GetU8(script + 5);
  1221. export_script->Log(
  1222. "field:screen_set_scroll_to_entity(" +
  1223. entity_list[GetU8(script + 4)] +
  1224. ", " +
  1225. ((type == 1) ? "Field.NONE" : ((type == 2) ? "Field.LINEAR" : ((type == 3) ? "Field.SMOOTH" : "Unknown_type_" + IntToString(type)))) +
  1226. ", " +
  1227. ParseGetVariable(GetU8(script + 1), GetU16LE(script + 2), 0, 30.0f) +
  1228. ");\n"
  1229. );
  1230. AdvanceScript(6, script, end);
  1231. } break;
  1232. case SCR2D:
  1233. {
  1234. export_script->Log("background2d:scroll_to_position( " + ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 2)) + ", " + ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 4)) + ", Background2D.NONE, 0 )\n");
  1235. AdvanceScript(6, script, end);
  1236. } break;
  1237. case SCRCC:
  1238. {
  1239. export_script->Log("background2d:autoscroll_to_entity( --[[ player entity object here ]] )\n");
  1240. AdvanceScript(1, script, end);
  1241. } break;
  1242. case SCR2DC:
  1243. {
  1244. export_script->Log("background2d:scroll_to_position( " + ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 3)) + ", " + ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 5)) + ", Background2D.SMOOTH, " + ParseGetVariable(GetU8(script + 2) & 0x0F, (s16)GetU16LE(script + 7), 0, 30.0f) + " )\n");
  1245. AdvanceScript(9, script, end);
  1246. } break;
  1247. case SCRLW:
  1248. {
  1249. export_script->Log("background2d:scroll_sync()\n");
  1250. AdvanceScript(1, script, end);
  1251. } break;
  1252. case SCR2DL:
  1253. {
  1254. export_script->Log("background2d:scroll_to_position( " + ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 3)) + ", " + ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 5)) + ", Background2D.LINEAR, " + ParseGetVariable(GetU8(script + 2) & 0x0F, (s16)GetU16LE(script + 7), 0, 30.0f) + " )\n");
  1255. AdvanceScript(9, script, end);
  1256. } break;
  1257. case VWOFT:
  1258. {
  1259. export_script->Log(
  1260. "[UNREVERSED] VWOFT(" +
  1261. ArgumentString(script + 1, 6) +
  1262. ");\n"
  1263. );
  1264. AdvanceScript(7, script, end);
  1265. } break;
  1266. case FADE:
  1267. {
  1268. u8 type = GetU8(script + 7);
  1269. if (type == 4)
  1270. {
  1271. export_script->Log("fade:black();\n");
  1272. }
  1273. else
  1274. {
  1275. u8 speed = GetU8(script + 6);
  1276. u8 start = GetU8(script + 8);
  1277. export_script->Log(
  1278. "[NEEDS TO CHECK FADE] fade:fade( " +
  1279. ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 3)) +
  1280. ", " +
  1281. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 4)) +
  1282. ", " +
  1283. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU16LE(script + 5)) +
  1284. ", " +
  1285. ((type == 1 || type == 2 || type == 7 || type == 8) ? "Fade.SUBTRACT" : "Fade.ADD") +
  1286. ", " +
  1287. IntToString(speed) +
  1288. ", " +
  1289. IntToString(start) +
  1290. " );\n"
  1291. );
  1292. }
  1293. AdvanceScript(9, script, end);
  1294. } break;
  1295. case FADEW:
  1296. {
  1297. export_script->Log("fade:wait();\n");
  1298. AdvanceScript(1, script, end);
  1299. } break;
  1300. case IDLCK:
  1301. {
  1302. export_script->Log(
  1303. "field:lock_walkmesh( " +
  1304. IntToString(GetU16LE(script + 1)) +
  1305. ", " +
  1306. BoolToString(GetU8(script + 3) > 0) +
  1307. " );\n"
  1308. );
  1309. AdvanceScript(4, script, end);
  1310. } break;
  1311. case LSTMP:
  1312. {
  1313. export_script->Log(
  1314. SetVariable(GetU8(script + 1), GetU8(script + 2), "field:get_last_map()")
  1315. );
  1316. AdvanceScript(3, script, end);
  1317. } break;
  1318. case BATTLE:
  1319. {
  1320. export_script->Log(
  1321. "field:battle_run( " +
  1322. ParseGetVariable(GetU8(script + 1), GetU16LE(script + 2)) +
  1323. " );\n"
  1324. );
  1325. AdvanceScript(4, script, end);
  1326. } break;
  1327. case BTLON:
  1328. {
  1329. export_script->Log(
  1330. "field:random_encounter_on( " +
  1331. BoolToString(!(GetU8(script + 1))) +
  1332. " );\n"
  1333. );
  1334. AdvanceScript(2, script, end);
  1335. } break;
  1336. case BTLMD:
  1337. {
  1338. export_script->Log(
  1339. "[UNREVERSED] BTLMD(" +
  1340. ArgumentString(script + 1, 2) +
  1341. ");\n"
  1342. );
  1343. AdvanceScript(3, script, end);
  1344. } break;
  1345. case PLUS_:
  1346. {
  1347. export_script->Log(
  1348. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), "( ( " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " + " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)) + " > 255 ) ? 255 : " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " + " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)) + " )")
  1349. );
  1350. AdvanceScript(4, script, end);
  1351. } break;
  1352. case PLUS2_:
  1353. {
  1354. export_script->Log(
  1355. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), "( ( " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " + " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 3)) + " > 65535 ) ? 65535 : " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " + " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 3)) + " )")
  1356. );
  1357. AdvanceScript(5, script, end);
  1358. } break;
  1359. case MINUS_:
  1360. {
  1361. export_script->Log(
  1362. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), "( ( " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " - " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)) + " < 0 ) ? 0 : " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " - " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)) + " )")
  1363. );
  1364. AdvanceScript(4, script, end);
  1365. } break;
  1366. case MINUS2_:
  1367. {
  1368. export_script->Log(SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), "( ( " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " - " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 3)) + " < 0 ) ? 0 : " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " - " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 3)) + " )"));
  1369. AdvanceScript(5, script, end);
  1370. } break;
  1371. case INC_:
  1372. {
  1373. export_script->Log(SetVariable(GetU8(script + 1), GetU8(script + 2), "( ( " + ParseGetVariable(GetU8(script + 1), GetU8(script + 2)) + " + 1 > 255 ) ? 255 : " + ParseGetVariable(GetU8(script + 1), GetU8(script + 2)) + " + 1 )"));
  1374. AdvanceScript(3, script, end);
  1375. } break;
  1376. case TALKON:
  1377. {
  1378. export_script->Log(
  1379. entity_list[i] +
  1380. ":set_talkable( " +
  1381. BoolToString(!(GetU8(script + 1))) +
  1382. " );\n"
  1383. );
  1384. AdvanceScript(2, script, end);
  1385. } break;
  1386. case SETBYTE:
  1387. {
  1388. export_script->Log(
  1389. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)))
  1390. );
  1391. AdvanceScript(4, script, end);
  1392. } break;
  1393. case SETWORD:
  1394. {
  1395. export_script->Log(SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 3))));
  1396. AdvanceScript(5, script, end);
  1397. } break;
  1398. case BITON:
  1399. {
  1400. export_script->Log(SetBitChange(GetU8(script + 1) >> 4, GetU8(script + 2), GetU8(script + 1) & 0x0F, GetU8(script + 3), true));
  1401. AdvanceScript(4, script, end);
  1402. } break;
  1403. case BITOFF:
  1404. {
  1405. export_script->Log(SetBitChange(GetU8(script + 1) >> 4, GetU8(script + 2), GetU8(script + 1) & 0x0F, GetU8(script + 3), false));
  1406. AdvanceScript(4, script, end);
  1407. } break;
  1408. case PLUS:
  1409. {
  1410. export_script->Log(
  1411. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " + " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)))
  1412. );
  1413. AdvanceScript(4, script, end);
  1414. } break;
  1415. case MINUS:
  1416. {
  1417. export_script->Log(
  1418. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " - " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)))
  1419. );
  1420. AdvanceScript(4, script, end);
  1421. } break;
  1422. case MUL:
  1423. {
  1424. export_script->Log(
  1425. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), "((" + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " * " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)) + " > 255) ? 255 : " + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " * " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)) + ")")
  1426. );
  1427. AdvanceScript(4, script, end);
  1428. } break;
  1429. case MOD:
  1430. {
  1431. export_script->Log(
  1432. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " % " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)))
  1433. );
  1434. AdvanceScript(4, script, end);
  1435. } break;
  1436. case AND:
  1437. {
  1438. export_script->Log(
  1439. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " & " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)))
  1440. );
  1441. AdvanceScript(4, script, end);
  1442. } break;
  1443. case AND2:
  1444. {
  1445. export_script->Log(
  1446. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " & " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 3)))
  1447. );
  1448. AdvanceScript(5, script, end);
  1449. } break;
  1450. case OR:
  1451. {
  1452. export_script->Log(SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " | " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3))));
  1453. AdvanceScript(4, script, end);
  1454. } break;
  1455. case OR2:
  1456. {
  1457. export_script->Log(
  1458. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + " | " + ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 3)))
  1459. );
  1460. AdvanceScript(5, script, end);
  1461. } break;
  1462. case INC:
  1463. {
  1464. export_script->Log(
  1465. SetVariable(GetU8(script + 1), GetU8(script + 2), ParseGetVariable(GetU8(script + 1), GetU8(script + 2)) + " + 1")
  1466. );
  1467. AdvanceScript(3, script, end);
  1468. } break;
  1469. case DEC:
  1470. {
  1471. export_script->Log(
  1472. SetVariable(GetU8(script + 1), GetU8(script + 2), ParseGetVariable(GetU8(script + 1), GetU8(script + 2)) + " - 1")
  1473. );
  1474. AdvanceScript(3, script, end);
  1475. } break;
  1476. case RANDOM:
  1477. {
  1478. export_script->Log(
  1479. SetVariable(GetU8(script + 1), GetU8(script + 2), "math.rand()")
  1480. );
  1481. AdvanceScript(3, script, end);
  1482. } break;
  1483. case PC:
  1484. {
  1485. export_script->Log("set_entity_to_character( \"" + entity_list[i] + "\", " + IntToString(GetU8(script + 1)) + " );\n");
  1486. AdvanceScript(2, script, end);
  1487. } break;
  1488. case opCodeCHAR:
  1489. {
  1490. export_script->Log("-- assosiate entity with model (CHAR) argument doesn't matter\n");
  1491. AdvanceScript(2, script, end);
  1492. } break;
  1493. case DFANM:
  1494. {
  1495. export_script->Log(entity_list[i] + ":set_default_animation( \"" + IntToString(GetU8(script + 1)) + "\" ) -- speed=" + FloatToString(1.0f / GetU8(script + 2)) + "\n");
  1496. export_script->Log(" " + entity_list[i] + ":play_animation( \"" + IntToString(GetU8(script + 1)) + "\" )\n");
  1497. AdvanceScript(3, script, end);
  1498. } break;
  1499. case ANIME1:
  1500. {
  1501. export_script->Log(entity_list[i] + ":play_animation( \"" + IntToString(GetU8(script + 1)) + "\" ) -- speed=" + FloatToString(1.0f / GetU8(script + 2)) + "\n");
  1502. export_script->Log(" " + entity_list[i] + ":animation_sync()\n");
  1503. AdvanceScript(3, script, end);
  1504. } break;
  1505. case VISI:
  1506. {
  1507. export_script->Log(entity_list[i] + ":set_visible( " + BoolToString(GetU8(script + 1) > 0) + " )\n");
  1508. AdvanceScript(2, script, end);
  1509. } break;
  1510. case XYZI:
  1511. {
  1512. export_script->Log(entity_list[i] + ":set_position( " + ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 3), 0, downscaler) + ", " + ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 5), 0, downscaler) + ", " + ParseGetVariable(GetU8(script + 2) >> 4, (s16)GetU16LE(script + 7), 0, downscaler) + " ) -- triangle_id=" + ParseGetVariable(GetU8(script + 2) & 0x0F, (s16)GetU16LE(script + 9)) + "\n");
  1513. AdvanceScript(11, script, end);
  1514. } break;
  1515. case XYI:
  1516. {
  1517. export_script->Log(
  1518. entity_list[i] +
  1519. ":set_2d_position_triangle( " +
  1520. ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 3), false, downscaler) +
  1521. ", " +
  1522. ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 5), false, downscaler) +
  1523. ", triangle_id=" +
  1524. ParseGetVariable(GetU8(script + 2) >> 4, (s16)GetU16LE(script + 7)) +
  1525. ");\n"
  1526. );
  1527. AdvanceScript(9, script, end);
  1528. } break;
  1529. case MOVE:
  1530. {
  1531. export_script->Log(entity_list[i] + ":move_to_position( " + ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 2), false, downscaler) + ", " + ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 4), false, downscaler) + " )\n");
  1532. export_script->Log(" " + entity_list[i] + ":move_sync()\n");
  1533. AdvanceScript(6, script, end);
  1534. } break;
  1535. case CMOVE:
  1536. {
  1537. export_script->Log(
  1538. entity_list[i] +
  1539. ":set_rotation_lock( true );\n" +
  1540. entity_list[i] +
  1541. ":move_to_position( " +
  1542. ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 2), 0, downscaler) +
  1543. ", " +
  1544. ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 4), 0, downscaler) +
  1545. ", false );\n" +
  1546. entity_list[i] +
  1547. ":set_rotation_lock( false );\n"
  1548. );
  1549. AdvanceScript(6, script, end);
  1550. } break;
  1551. case MOVA:
  1552. {
  1553. export_script->Log(
  1554. entity_list[i] +
  1555. ":move_to_model( " +
  1556. entity_list[GetU8(script + 1)] +
  1557. ", true );\n"
  1558. );
  1559. AdvanceScript(2, script, end);
  1560. } break;
  1561. case TURA:
  1562. {
  1563. u8 type = GetU8(script + 2);
  1564. export_script->Log(
  1565. entity_list[i] +
  1566. ":turn_to_entity( " +
  1567. entity_list[GetU8(script + 1)] +
  1568. ", " +
  1569. ((type == 0) ? "Entity.CLOCKWISE" : ((type == 1) ? "Entity.ANTICLOCKWISE" : "Entity.CLOSEST")) +
  1570. ", " +
  1571. FloatToString(GetU8(script + 3) / 30.0f) +
  1572. ");\n"
  1573. );
  1574. AdvanceScript(4, script, end);
  1575. } break;
  1576. case ANIMW:
  1577. {
  1578. export_script->Log(
  1579. entity_list[i] +
  1580. ":set_animation_wait();\n"
  1581. );
  1582. AdvanceScript(1, script, end);
  1583. } break;
  1584. case FMOVE:
  1585. {
  1586. export_script->Log(
  1587. entity_list[i] +
  1588. ":move_to_position( \"" +
  1589. ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 2)) +
  1590. ", " +
  1591. ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 4)) +
  1592. ", false );\n"
  1593. );
  1594. AdvanceScript(6, script, end);
  1595. } break;
  1596. case ANIME2:
  1597. {
  1598. export_script->Log(
  1599. entity_list[i] +
  1600. ":play_animation( \"" +
  1601. IntToString(GetU8(script + 1)) +
  1602. "\", 0, -1, " +
  1603. FloatToString(1.0f / GetU8(script + 2)) +
  1604. ", false );\n"
  1605. );
  1606. AdvanceScript(3, script, end);
  1607. } break;
  1608. case ANIM_1:
  1609. {
  1610. export_script->Log(entity_list[i] + ":play_animation_stop( \"" + IntToString(GetU8(script + 1)) + "\" ) -- speed=" + FloatToString(1.0f / GetU8(script + 2)) + "\n");
  1611. AdvanceScript(3, script, end);
  1612. } break;
  1613. case CANM_1:
  1614. {
  1615. export_script->Log(
  1616. entity_list[i] +
  1617. ":play_animation( \"" +
  1618. IntToString(GetU8(script + 1)) +
  1619. "\", " +
  1620. FloatToString(GetU8(script + 2) / 30.0f) +
  1621. ", " +
  1622. FloatToString(GetU8(script + 3) / 30.0f) +
  1623. ", " +
  1624. FloatToString(1.0f / GetU8(script + 4)) +
  1625. ", true );\n"
  1626. );
  1627. AdvanceScript(5, script, end);
  1628. } break;
  1629. case MSPED:
  1630. {
  1631. export_script->Log(entity_list[i] + ":set_move_speed( " + ParseGetVariable(GetU8(script + 1), GetU16LE(script + 2), 0, 256.0f * downscaler / (30.0f)) + " )\n");
  1632. AdvanceScript(4, script, end);
  1633. } break;
  1634. case DIR:
  1635. {
  1636. export_script->Log(entity_list[i] + ":set_direction( " + ParseGetVariable(GetU8(script + 1), GetU8(script + 2), 0, 256.0f / 360.0f) + " )\n");
  1637. AdvanceScript(3, script, end);
  1638. } break;
  1639. case TURNGEN:
  1640. {
  1641. u8 type = GetU8(script + 3);
  1642. u8 calc = GetU8(script + 5);
  1643. export_script->Log(entity_list[i] + ":turn_to_direction( " + ParseGetVariable(GetU8(script + 1), GetU8(script + 2), 0, 256.0f / 360.0f) + ", " + ((type == 0) ? "Entity.CLOCKWISE" : ((type == 1) ? "Entity.ANTICLOCKWISE" : "Entity.CLOSEST")) + ", " + ((calc == 1) ? "Entity.LINEAR" : "Entity.SMOOTH") + ", " + FloatToString(GetU8(script + 4) / 30.0f) + " )\n");
  1644. export_script->Log(entity_list[i] + ":turn_sync()\n");
  1645. AdvanceScript(6, script, end);
  1646. } break;
  1647. case TURN:
  1648. {
  1649. u8 calc = GetU8(script + 5);
  1650. export_script->Log(
  1651. entity_list[i] +
  1652. ":turn_to_direction( " +
  1653. ParseGetVariable(GetU8(script + 1), GetU16LE(script + 2), 0, 256.0f / 360.0f) +
  1654. ", Entity.CLOCKWISE, " +
  1655. ((calc == 1) ? "Field.LINEAR" : "Field.SMOOTH") +
  1656. ", " +
  1657. FloatToString(GetU8(script + 4) / 30.0f) +
  1658. " );\n"
  1659. );
  1660. export_script->Log(entity_list[i] + ":turn_sync()\n");
  1661. AdvanceScript(6, script, end);
  1662. } break;
  1663. case DIRA:
  1664. {
  1665. export_script->Log(entity_list[i] + ":set_direction( \"" + entity_list[GetU8(script + 1)] + "\" )\n");
  1666. AdvanceScript(2, script, end);
  1667. } break;
  1668. case GETDIR:
  1669. {
  1670. export_script->Log(
  1671. SetVariable(GetU8(script + 1), GetU8(script + 3), entity_list[GetU8(script + 2)] + ":get_direction()")
  1672. );
  1673. AdvanceScript(4, script, end);
  1674. } break;
  1675. case GETAXY:
  1676. {
  1677. export_script->Log(
  1678. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 3), entity_list[GetU8(script + 2)] + ":get_x()") +
  1679. SetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 4), entity_list[GetU8(script + 2)] + ":get_y()")
  1680. );
  1681. AdvanceScript(5, script, end);
  1682. } break;
  1683. case GETAI:
  1684. {
  1685. export_script->Log(SetVariable(GetU8(script + 1), GetU8(script + 3), entity_list[GetU8(script + 2)] + ":get_move_triangle_id()"));
  1686. AdvanceScript(4, script, end);
  1687. } break;
  1688. case ANIM_2: // ANIM!2
  1689. {
  1690. export_script->Log(entity_list[i] + ":play_animation_stop( \"" + IntToString(GetU8(script + 1)) + "\" ) -- speed=" + FloatToString(1.0f / GetU8(script + 2)) + "\n");
  1691. export_script->Log(" " + entity_list[i] + ":animation_sync()\n");
  1692. AdvanceScript(3, script, end);
  1693. } break;
  1694. case CANIM2:
  1695. {
  1696. export_script->Log(entity_list[i] + ":play_animation( \"" + IntToString(GetU8(script + 1)) + "\", " + FloatToString(GetU8(script + 2) / 30.0f) + ", " + FloatToString(GetU8(script + 3) / 30.0f) + " ) -- speed=" + FloatToString(1.0f / GetU8(script + 4)) + "\n");
  1697. export_script->Log(" " + entity_list[i] + ":animation_sync()\n");
  1698. AdvanceScript(5, script, end);
  1699. } break;
  1700. case CANM_2:
  1701. {
  1702. export_script->Log(entity_list[i] + ":play_animation_stop( \"" + IntToString(GetU8(script + 1)) + "\", " + FloatToString(GetU8(script + 2) / 30.0f) + ", " + FloatToString(GetU8(script + 3) / 30.0f) + " ) -- speed=" + FloatToString(1.0f / GetU8(script + 4)) + "\n");
  1703. export_script->Log(" " + entity_list[i] + ":animation_sync()\n");
  1704. AdvanceScript(5, script, end);
  1705. } break;
  1706. case ASPED:
  1707. {
  1708. export_script->Log("-- set speed of entity animation to \"" + ParseGetVariable(GetU8(script + 1), GetU16LE(script + 2), 0, 0x10) + "\"\n");
  1709. AdvanceScript(4, script, end);
  1710. } break;
  1711. case CC:
  1712. {
  1713. export_script->Log(
  1714. "field:set_player_entity( " +
  1715. entity_list[GetU8(script + 1)] +
  1716. " );\n"
  1717. );
  1718. AdvanceScript(2, script, end);
  1719. } break;
  1720. case JUMP:
  1721. {
  1722. export_script->Log(
  1723. entity_list[i] +
  1724. ":jump_to_position( " +
  1725. ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 3)) +
  1726. ", " +
  1727. ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 5)) +
  1728. ", " +
  1729. ParseGetVariable(GetU8(script + 2) >> 4, GetU16LE(script + 7)) +
  1730. ", " +
  1731. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU16LE(script + 9), 0, 30.0f) +
  1732. " );\n"
  1733. );
  1734. AdvanceScript(11, script, end);
  1735. } break;
  1736. case AXYZI:
  1737. {
  1738. export_script->Log(
  1739. SetVariable(GetU8(script + 1) >> 4, GetU8(script + 4), entity_list[GetU8(script + 3)] + ":get_x()") +
  1740. SetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 5), entity_list[GetU8(script + 3)] + ":get_y()") +
  1741. SetVariable(GetU8(script + 2) >> 4, GetU8(script + 6), entity_list[GetU8(script + 3)] + ":get_z()") +
  1742. SetVariable(GetU8(script + 2) & 0x0F, GetU8(script + 7), entity_list[GetU8(script + 3)] + ":get_move_triangle_id()")
  1743. );
  1744. AdvanceScript(8, script, end);
  1745. } break;
  1746. case LADER:
  1747. {
  1748. u8 type = GetU8(script + 11);
  1749. export_script->Log(
  1750. entity_list[i] +
  1751. ":climb_to_position( " +
  1752. ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 3)) +
  1753. ", " +
  1754. ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 5)) +
  1755. ", " +
  1756. ParseGetVariable(GetU8(script + 2) >> 4, (s16)GetU16LE(script + 7)) +
  1757. ", " +
  1758. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU16LE(script + 9)) +
  1759. ", " +
  1760. ((type == 0) ? "Entity.UP_TO_DOWN" : ((type == 1) ? "Entity.DOWN_TO_UP" : ((type == 2) ? "Entity.LEFT_TO_RIGHT" : ((type == 1) ? "Entity.RIGHT_TO_LEFT" : "")))) +
  1761. " ); -- direction needs to be seted to \"" +
  1762. FloatToString((GetU8(script + 13) / 256.0f) * 360.0f) +
  1763. "\" and animation during climbing is \"" +
  1764. IntToString(GetU8(script + 12)) +
  1765. "\" with speed \"" +
  1766. FloatToString(1.0f / GetU8(script + 14)) +
  1767. "\"\n"
  1768. );
  1769. AdvanceScript(15, script, end);
  1770. } break;
  1771. case OFST:
  1772. {
  1773. u8 type = GetU8(script + 3);
  1774. export_script->Log(entity_list[i] + ":offset_to_position( " + ParseGetVariable(GetU8(script + 1) >> 4, (s16)GetU16LE(script + 4), 0, downscaler) + ", " + ParseGetVariable(GetU8(script + 1) & 0x0F, (s16)GetU16LE(script + 6), false, downscaler) + ", " + ParseGetVariable(GetU8(script + 2) >> 4, (s16)GetU16LE(script + 8), false, downscaler) + ", " + ((type == 2) ? "Entity.SMOOTH" : "Entity.LINEAR") + ", " + ParseGetVariable(GetU8(script + 2) & 0x0F, GetU16LE(script + 10), 0, 30.0f) + " )\n");
  1775. AdvanceScript(12, script, end);
  1776. } break;
  1777. case OFSTW:
  1778. {
  1779. export_script->Log(entity_list[i] + ":offset_sync()\n");
  1780. AdvanceScript(1, script, end);
  1781. } break;
  1782. case TALKR:
  1783. {
  1784. export_script->Log(
  1785. entity_list[i] +
  1786. ":set_talk_range( " +
  1787. ParseGetVariable(GetU8(script + 1), GetU8(script + 2)) +
  1788. " );\n"
  1789. );
  1790. AdvanceScript(3, script, end);
  1791. } break;
  1792. case CLIDR:
  1793. {
  1794. export_script->Log(
  1795. entity_list[i] +
  1796. ":set_solid_range( " +
  1797. ParseGetVariable(GetU8(script + 1), GetU8(script + 2)) +
  1798. " );\n"
  1799. );
  1800. AdvanceScript(3, script, end);
  1801. } break;
  1802. case SOLID:
  1803. {
  1804. export_script->Log(entity_list[i] + ":set_solid( " + BoolToString(!(GetU8(script + 1))) + " )\n");
  1805. AdvanceScript(2, script, end);
  1806. } break;
  1807. case PRTYP:
  1808. {
  1809. export_script->Log(
  1810. "game:party_add( " +
  1811. IntToString(GetU8(script + 1)) +
  1812. " );\n"
  1813. );
  1814. AdvanceScript(2, script, end);
  1815. } break;
  1816. case PRTYM:
  1817. {
  1818. export_script->Log(
  1819. "game:party_remove( " +
  1820. IntToString(GetU8(script + 1)) +
  1821. " );\n"
  1822. );
  1823. AdvanceScript(2, script, end);
  1824. } break;
  1825. case PRTYE:
  1826. {
  1827. export_script->Log(
  1828. "game:party_set( " +
  1829. IntToString(GetU8(script + 1)) +
  1830. ", " +
  1831. IntToString(GetU8(script + 2)) +
  1832. ", " +
  1833. IntToString(GetU8(script + 3)) +
  1834. " );\n"
  1835. );
  1836. AdvanceScript(4, script, end);
  1837. } break;
  1838. case MMBUD:
  1839. {
  1840. export_script->Log(
  1841. "game:character_enable( " +
  1842. IntToString(GetU8(script + 2)) +
  1843. ", " +
  1844. BoolToString(GetU8(script + 1) > 0) +
  1845. " );\n"
  1846. );
  1847. AdvanceScript(3, script, end);
  1848. } break;
  1849. case MMBLK:
  1850. {
  1851. export_script->Log(
  1852. "[UNREVERSED] MMBLK(" +
  1853. ArgumentString(script + 1, 1) +
  1854. ");\n"
  1855. );
  1856. AdvanceScript(2, script, end);
  1857. } break;
  1858. case LINE:
  1859. {
  1860. export_script->Log(
  1861. "-- define line point1( " +
  1862. IntToString(GetU16LE(script + 1)) +
  1863. ", " +
  1864. IntToString(GetU16LE(script + 3)) +
  1865. ", " +
  1866. IntToString(GetU16LE(script + 5)) +
  1867. "), point2(" +
  1868. IntToString(GetU16LE(script + 7)) +
  1869. ", " +
  1870. IntToString(GetU16LE(script + 9)) +
  1871. ", " +
  1872. IntToString(GetU16LE(script + 11)) +
  1873. " )\n"
  1874. );
  1875. AdvanceScript(13, script, end);
  1876. } break;
  1877. case LINON:
  1878. {
  1879. export_script->Log(
  1880. "-- turn line " +
  1881. Ogre::String((GetU8(script + 1) == 1) ? "on" : "off") +
  1882. "\n"
  1883. );
  1884. AdvanceScript(2, script, end);
  1885. } break;
  1886. case MPJPO:
  1887. {
  1888. export_script->Log(
  1889. "field:gateway_enable( " +
  1890. Ogre::String((GetU8(script + 1) == 1) ? "false" : "true") +
  1891. " );\n"
  1892. );
  1893. AdvanceScript(2, script, end);
  1894. } break;
  1895. case SLINE:
  1896. {
  1897. u8 type = GetU8(script + 2);
  1898. export_script->Log(
  1899. "-- redefine line point1( " +
  1900. ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 4)) +
  1901. ", " +
  1902. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 6)) +
  1903. ", " +
  1904. ParseGetVariable(GetU8(script + 2) >> 4, GetU8(script + 8)) +
  1905. "), point2(" +
  1906. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU8(script + 10)) +
  1907. ", " +
  1908. ParseGetVariable(GetU8(script + 3) >> 4, GetU8(script + 12)) +
  1909. ", " +
  1910. ParseGetVariable(GetU8(script + 3) & 0x0F, GetU8(script + 14)) +
  1911. " )\n"
  1912. );
  1913. AdvanceScript(16, script, end);
  1914. } break;
  1915. case PMJMP:
  1916. {
  1917. export_script->Log(
  1918. "[UNREVERSED] PMJMP(" +
  1919. ArgumentString(script + 1, 2) +
  1920. ");\n"
  1921. );
  1922. AdvanceScript(3, script, end);
  1923. } break;
  1924. case AKAO2:
  1925. {
  1926. u8 sub_opcode = GetU8(script + 4);
  1927. Ogre::String sound = "music:execute_akao( " +
  1928. HexToString(sub_opcode, 2, '0') +
  1929. ", " +
  1930. ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 5), 4) +
  1931. ", " +
  1932. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 7), 4) +
  1933. ", " +
  1934. ParseGetVariable(GetU8(script + 2) >> 4, GetU16LE(script + 9), 4) +
  1935. ", " +
  1936. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU16LE(script + 11), 4) +
  1937. ", " +
  1938. ParseGetVariable(GetU8(script + 3) >> 4, GetU16LE(script + 13), 4) +
  1939. ", " +
  1940. ParseGetVariable(GetU8(script + 3) & 0x0F, GetU16LE(script + 15), 4) +
  1941. " );\n";
  1942. m_SoundOpcodes.push_back(sound);
  1943. export_script->Log(sound);
  1944. AdvanceScript(15, script, end);
  1945. } break;
  1946. case ANIMB:
  1947. {
  1948. export_script->Log(
  1949. entity_list[i] +
  1950. ":animation_stop();\n"
  1951. );
  1952. AdvanceScript(1, script, end);
  1953. } break;
  1954. case TURNW:
  1955. {
  1956. export_script->Log(
  1957. entity_list[i] +
  1958. ":set_turn_wait();\n"
  1959. );
  1960. AdvanceScript(1, script, end);
  1961. } break;
  1962. case BGON:
  1963. {
  1964. export_script->Log(
  1965. "field:background_on( \"" +
  1966. ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) +
  1967. "\", " +
  1968. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)) +
  1969. " ); -- turns on layer of background animation with given id\n"
  1970. );
  1971. AdvanceScript(4, script, end);
  1972. } break;
  1973. case BGOFF:
  1974. {
  1975. export_script->Log(
  1976. "field:background_off( \"" +
  1977. ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) +
  1978. "\", " +
  1979. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 3)) +
  1980. " ); -- turns off layer of background animation with given id\n"
  1981. );
  1982. AdvanceScript(4, script, end);
  1983. } break;
  1984. case BGCLR:
  1985. {
  1986. export_script->Log(
  1987. "field:background_clear( \"" +
  1988. ParseGetVariable(GetU8(script + 1), GetU8(script + 2)) +
  1989. "\" ); -- turns off all layer of background animation with given id\n"
  1990. );
  1991. AdvanceScript(3, script, end);
  1992. } break;
  1993. case STPAL:
  1994. {
  1995. export_script->Log("-- store palette \"" + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2)) + "\" to slot \"0x" + ParseGetVariable(GetU8(script + 1) & 0x0f, GetU8(script + 3), 2) + "\" starting from clut_x=\"0x00\" and with width=\"0x" + HexToString(GetU8(script + 4) + 1, 2, '0') + "\"\n");
  1996. AdvanceScript(5, script, end);
  1997. } break;
  1998. case LDPAL:
  1999. {
  2000. export_script->Log("-- load palette \"" + ParseGetVariable(GetU8(script + 1) & 0x0f, GetU8(script + 3)) + "\" from slot \"0x" + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), 2) + "\" starting from clut_x=\"0x00\" and with width=\"0x" + HexToString(GetU8(script + 4) + 1, 2, '0') + "\"\n");
  2001. AdvanceScript(5, script, end);
  2002. } break;
  2003. case CPPAL:
  2004. {
  2005. export_script->Log("-- copy palette stored in slot \"0x" + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 2), 2) + "\" with width=\"0x" + HexToString(GetU8(script + 4) + 1, 2, '0') + " to slot \"0x" + ParseGetVariable(GetU8(script + 1) & 0x0f, GetU8(script + 3), 2) + "\"\n");
  2006. AdvanceScript(5, script, end);
  2007. } break;
  2008. case ADPAL:
  2009. {
  2010. export_script->Log("-- add to palette stored in slot \"0x" + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 4), 2) + "\" with width=\"0x" + HexToString(GetU8(script + 9) + 1, 2, '0') + "\" with values R=\"" + ParseGetVariable(GetU8(script + 3) >> 4, GetU8(script + 8)) + "\", G=\"" + ParseGetVariable(GetU8(script + 2) & 0x0f, GetU8(script + 7)) + "\", B=\"" + ParseGetVariable(GetU8(script + 2) >> 4, GetU8(script + 6)) + "\" and store it to slot \"0x" + ParseGetVariable(GetU8(script + 1) & 0x0f, GetU8(script + 5), 2) + "\"\n");
  2011. AdvanceScript(10, script, end);
  2012. } break;
  2013. case MPPAL2:
  2014. {
  2015. export_script->Log("-- multiply palette stored in slot \"0x" + ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 4), 2) + "\" with width=\"0x" + HexToString(GetU8(script + 9) + 1, 2, '0') + " with values R=\"" + ParseGetVariable(GetU8(script + 3) >> 4, GetU8(script + 8)) + "\", G=\"" + ParseGetVariable(GetU8(script + 2) & 0x0f, GetU8(script + 7)) + "\", B=\"" + ParseGetVariable(GetU8(script + 2) >> 4, GetU8(script + 6)) + "\" (note: 64 - 1.0f, 32 - 0.5f) and store it to slot \"0x" + ParseGetVariable(GetU8(script + 1) & 0x0f, GetU8(script + 5), 2) + "\"\n");
  2016. AdvanceScript(10, script, end);
  2017. } break;
  2018. case STPLS:
  2019. {
  2020. export_script->Log("-- store palette \"" + IntToString(GetU8(script + 1)) + "\" to slot \"0x" + HexToString(GetU8(script + 2), 2, '0') + "\" starting from clut_x=\"0x" + HexToString(GetU8(script + 3), 2, '0') + "\" and with width=\"0x" + HexToString(GetU8(script + 4) + 1, 2, '0') + "\"\n");
  2021. AdvanceScript(5, script, end);
  2022. } break;
  2023. case LDPLS:
  2024. {
  2025. export_script->Log("-- load palette \"" + IntToString(GetU8(script + 2)) + "\" from slot \"0x" + HexToString(GetU8(script + 1), 2, '0') + "\" starting from clut_x=\"0x" + HexToString(GetU8(script + 3), 2, '0') + "\" and with width=\"0x" + HexToString(GetU8(script + 4) + 1, 2, '0') + "\"\n");
  2026. AdvanceScript(5, script, end);
  2027. } break;
  2028. case RTPAL2:
  2029. {
  2030. export_script->Log("[UNREVERSED] RTPAL2( " + ArgumentString(script + 1, 7) + " );\n");
  2031. AdvanceScript(8, script, end);
  2032. } break;
  2033. case ADPAL2:
  2034. {
  2035. export_script->Log("[UNREVERSED] ADPAL2( " + ArgumentString(script + 1, 10) + ");\n");
  2036. AdvanceScript(11, script, end);
  2037. } break;
  2038. case MUSIC:
  2039. {
  2040. Ogre::String sound = "music:execute_akao( " +
  2041. HexToString(0x10, 2, '0') +
  2042. ", pointer_to_field_AKAO_" +
  2043. IntToString(GetU8(script + 1)) +
  2044. " ); -- play field music\n";
  2045. m_SoundOpcodes.push_back(sound);
  2046. export_script->Log(sound);
  2047. AdvanceScript(2, script, end);
  2048. } break;
  2049. case SOUND:
  2050. {
  2051. Ogre::String sound = "music:execute_akao( " +
  2052. HexToString(0x20, 2, '0') +
  2053. ", " +
  2054. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU8(script + 4), true) +
  2055. ", " +
  2056. ParseGetVariable(GetU8(script + 1) >> 4, GetU16LE(script + 2), true) +
  2057. " ); -- play sound\n";
  2058. m_SoundOpcodes.push_back(sound);
  2059. export_script->Log(sound);
  2060. AdvanceScript(5, script, end);
  2061. } break;
  2062. case AKAO:
  2063. {
  2064. u8 sub_opcode = GetU8(script + 4);
  2065. Ogre::String sound = "music:execute_akao( " +
  2066. HexToString(sub_opcode, 2, '0') +
  2067. ", " +
  2068. ParseGetVariable(GetU8(script + 1) >> 4, GetU8(script + 5), true) +
  2069. ", " +
  2070. ParseGetVariable(GetU8(script + 1) & 0x0F, GetU16LE(script + 7), true) +
  2071. ", " +
  2072. ParseGetVariable(GetU8(script + 2) >> 4, GetU16LE(script + 9), true) +
  2073. ", " +
  2074. ParseGetVariable(GetU8(script + 2) & 0x0F, GetU16LE(script + 11), true) +
  2075. ", " +
  2076. ParseGetVariable(GetU8(script + 3) >> 4, GetU16LE(script + 13), true) +
  2077. ", " +
  2078. ParseGetVariable(GetU8(script + 3) & 0x0F, GetU16LE(script + 15), true) +
  2079. " );\n";
  2080. m_SoundOpcodes.push_back(sound);
  2081. export_script->Log(sound);
  2082. AdvanceScript(14, script, end);
  2083. } break;
  2084. case MULCK:
  2085. {
  2086. export_script->Log(
  2087. "music:lock( " +
  2088. BoolToString(GetU8(script + 1) > 0) +
  2089. " );\n"
  2090. );
  2091. AdvanceScript(2, script, end);
  2092. } break;
  2093. case BMUSC:
  2094. {
  2095. export_script->Log(
  2096. "[UNREVERSED] BMUSC(" +
  2097. IntToString(GetU8(script + 1)) +
  2098. ");\n"
  2099. );
  2100. AdvanceScript(2, script, end);
  2101. } break;
  2102. case PMVIE:
  2103. {
  2104. export_script->Log(
  2105. "field:movie_set( " +
  2106. IntToString(GetU8(script + 1)) +
  2107. " );\n"
  2108. );
  2109. AdvanceScript(2, script, end);
  2110. } break;
  2111. case MOVIE:
  2112. {
  2113. export_script->Log("field:play_movie();\n");
  2114. AdvanceScript(1, script, end);
  2115. } break;
  2116. case MVIEF:
  2117. {
  2118. export_script->Log(
  2119. SetVariable(GetU8(script + 1), GetU8(script + 2), "field:get_movie_frame()")
  2120. );
  2121. AdvanceScript(3, script, end);
  2122. } break;
  2123. case MVCAM:
  2124. {
  2125. export_script->Log(
  2126. "field:movie_camera_enable( " +
  2127. BoolToString(!GetU8(script + 1)) +
  2128. " );\n"
  2129. );
  2130. AdvanceScript(2, script, end);
  2131. } break;
  2132. case FMUSC:
  2133. {
  2134. export_script->Log(
  2135. "[UNREVERSED] FMUSC(" +
  2136. ArgumentString(script + 1, 1) +
  2137. ");\n"
  2138. );
  2139. AdvanceScript(2, script, end);
  2140. } break;
  2141. case CHMST:
  2142. {
  2143. export_script->Log(
  2144. SetVariable(GetU8(script + 1), GetU8(script + 2), "field:is_music_playing()")
  2145. );
  2146. AdvanceScript(3, script, end);
  2147. } break;
  2148. default:
  2149. {
  2150. export_script->Log("[OPCODE " + HexToString(opcode, 2, '0') + "]\n");
  2151. script += 1;
  2152. } break;
  2153. } // end switch
  2154. }
  2155. export_script->Log("\n");
  2156. }
  2157. }
  2158. delete export_script;
  2159. }
  2160. void
  2161. DatFile::DumpSoundOpcodesData( const Ogre::String& export_file )
  2162. {
  2163. std::sort( m_SoundOpcodes.begin(), m_SoundOpcodes.end() );
  2164. m_SoundOpcodes.erase(std::unique(m_SoundOpcodes.begin(), m_SoundOpcodes.end()), m_SoundOpcodes.end());
  2165. Logger* export_sound = new Logger(export_file);
  2166. for (unsigned int i = 0; i < m_SoundOpcodes.size(); ++i)
  2167. {
  2168. export_sound->Log(m_SoundOpcodes[i]);
  2169. }
  2170. delete export_sound;
  2171. }
  2172. void
  2173. DatFile::AdvanceScript(u32 value, u32& current, u32& end)
  2174. {
  2175. current += value;
  2176. u32 temp_end = current;
  2177. end = (temp_end > end) ? temp_end : end;
  2178. }
  2179. // A map of slots to values to value names, for example slot 1 value 3 = "love_point_aeris"
  2180. std::map<int, std::map<int, Ogre::String>> VariableNamesMap
  2181. {
  2182. // Slot 1
  2183. { 1, { { 3, "love_point_aeris" },
  2184. { 4, "love_point_tifa" },
  2185. { 5, "love_point_yuffie" },
  2186. { 6, "love_point_barret" },
  2187. { 21, "timer_minutes" },
  2188. { 22, "timer_seconds" },
  2189. { 23, "timer_frames" },
  2190. { 36, "graveyard_item" },
  2191. { 48, "item_mask2" },
  2192. { 80, "battle_love_aeris" },
  2193. { 81, "battle_love_tifa" },
  2194. { 82, "battle_love_yuffie" },
  2195. { 83, "battle_love_barret" },
  2196. { 164, "graveyard_train" },
  2197. { 225, "act1_1_flags1" },
  2198. { 226, "act1_1_flags2" } }
  2199. },
  2200. // Slot 2
  2201. { 2, { { 0, "progress_game" },
  2202. { 28, "menu_appear" },
  2203. { 30, "menu_selectable" }
  2204. } },
  2205. // Slot 3
  2206. { 3, { { 66, "act1_1_flags3" },
  2207. { 111, "flower_flag" },
  2208. { 112, "act1_3_flags5" },
  2209. { 126, "act1_3_unknown" },
  2210. { 127, "tunnel_room" },
  2211. { 128, "act1_3_flags1" },
  2212. { 129, "act1_3_flags2" },
  2213. { 130, "act1_3_flags3" },
  2214. { 131, "act1_3_flags4" },
  2215. { 208, "act1_2_flags1" },
  2216. { 209, "act1_2_flags2" },
  2217. { 210, "act1_2_flags3" },
  2218. { 211, "act1_2_flags4" },
  2219. { 212, "act1_2_flags5" },
  2220. { 213, "act1_2_flags6" },
  2221. { 214, "act1_2_flags7" },
  2222. { 215, "act1_2_flags8" },
  2223. { 216, "act1_2_flags9" },
  2224. { 217, "act1_7_flags1" },
  2225. { 223, "act1_1_flags4" },
  2226. } },
  2227. // Slot 13
  2228. { 13, { { 30, "pointer" },
  2229. { 31, "materia_full" },
  2230. { 91, "save_flag" }
  2231. } },
  2232. // Slot 15
  2233. { 15, { { 32, "sector1_item" },
  2234. { 33, "sector5_item" },
  2235. { 80, "subway_item" }
  2236. } }
  2237. };
  2238. Ogre::String
  2239. DatFile::ParseVariableName(int slot, int value)
  2240. {
  2241. auto slotMap = VariableNamesMap.find(slot);
  2242. if (slotMap != std::end(VariableNamesMap))
  2243. {
  2244. auto valueStr = slotMap->second.find(value);
  2245. if (valueStr != std::end(slotMap->second))
  2246. {
  2247. return valueStr->second;
  2248. }
  2249. }
  2250. LOGGER->Log("\n[WARNING] ParseVariableName " + IntToString(value) + " for slot " + IntToString(slot) + " not implemented.\n");
  2251. return "";
  2252. }
  2253. Ogre::String
  2254. DatFile::ParseGetVariable( int get_slot, int get_value, unsigned int hex, float fixed )
  2255. {
  2256. if( get_slot == 0 )
  2257. {
  2258. if( hex > 0 )
  2259. {
  2260. return HexToString( get_value, hex, '0' );
  2261. }
  2262. else
  2263. {
  2264. return FloatToString( get_value / fixed );
  2265. }
  2266. }
  2267. else if( get_slot == 1 || get_slot == 2 || get_slot == 3 || get_slot == 13 || get_slot == 15 )
  2268. {
  2269. return "game:variable_get( \"" + ParseVariableName( get_slot, get_value ) + "\" )";
  2270. }
  2271. else if( get_slot == 5 )
  2272. {
  2273. return "temp5_" + HexToString( get_value, 2, '0' );
  2274. }
  2275. else if( get_slot == 6 )
  2276. {
  2277. return "temp6_" + HexToString( get_value, 2, '0' );
  2278. }
  2279. LOGGER->Log( "\n[WARNING] ParseGetVariable " + IntToString( get_value ) + " for slot " + IntToString( get_slot ) + " not implemented.\n" );
  2280. return "";
  2281. }
  2282. Ogre::String
  2283. DatFile::SetVariable( int set_slot, int set_value, Ogre::String get_string )
  2284. {
  2285. if (set_slot == 1 || set_slot == 2 || set_slot == 3 || set_slot == 13 || set_slot == 15)
  2286. {
  2287. return "game:variable_set(\"" + ParseVariableName(set_slot, set_value) + "\", " + get_string + ");\n";
  2288. }
  2289. else if (set_slot == 5)
  2290. {
  2291. return "temp5_" + HexToString( set_value, 2, '0' ) + " = " + get_string + ";\n";
  2292. }
  2293. else if (set_slot == 6)
  2294. {
  2295. return "temp6_" + HexToString( set_value, 2, '0' ) + " = " + get_string + ";\n";
  2296. }
  2297. LOGGER->Log("\n[WARNING] SetVariable " + IntToString(set_value) + " for slot " + IntToString(set_slot) + " not implemented.\n");
  2298. return "";
  2299. }
  2300. Ogre::String
  2301. DatFile::SetBitChange(int set_slot, int set_value, int get_slot, int get_value, bool on)
  2302. {
  2303. if (set_slot == 1 || set_slot == 3 || set_slot == 5 || set_slot == 13 || set_slot == 15)
  2304. {
  2305. if (on == true)
  2306. {
  2307. return SetVariable(set_slot, set_value, "(" + ParseGetVariable(set_slot, set_value) + " | (1 << " + ParseGetVariable(get_slot, get_value) + "))");
  2308. }
  2309. else
  2310. {
  2311. return SetVariable(set_slot, set_value, "(" + ParseGetVariable(set_slot, set_value) + " & XOR(1 << " + ParseGetVariable(get_slot, get_value) + "))");
  2312. }
  2313. }
  2314. LOGGER->Log("\n[WARNING] SetBitChange " + IntToString(set_value) + " for slot " + IntToString(set_slot) + " not implemented.\n");
  2315. return "";
  2316. }
  2317. Ogre::String
  2318. DatFile::ParseRelation(int relation, Ogre::String string1, Ogre::String string2)
  2319. {
  2320. switch (relation)
  2321. {
  2322. case 0: return string1 + " == " + string2;
  2323. case 1: return string1 + " != " + string2;
  2324. case 2: return string1 + " > " + string2;
  2325. case 3: return string1 + " < " + string2;
  2326. case 4: return string1 + " >= " + string2;
  2327. case 5: return string1 + " <= " + string2;
  2328. case 6: return string1 + " & " + string2;
  2329. case 7: return string1 + " ^ " + string2;
  2330. case 8: return string1 + " | " + string2;
  2331. case 9: return string1 + " & (1 << " + string2 + ")";
  2332. case 10: return "!(" + string1 + " & (1 << " + string2 + "))";
  2333. }
  2334. return "";
  2335. }
  2336. Ogre::String
  2337. DatFile::ArgumentString(int script, int number)
  2338. {
  2339. Ogre::String ret = "";
  2340. for (int i = 0; i < number; ++i)
  2341. {
  2342. ret += HexToString(GetU8(script + i), 2, '0');
  2343. if (i + 1 < number)
  2344. {
  2345. ret += ", ";
  2346. }
  2347. }
  2348. return ret;
  2349. }
  2350. Ogre::String
  2351. DatFile::OffsetString(int val)
  2352. {
  2353. return HexToString(val, 4, '0');
  2354. }
  2355. void
  2356. DatFile::GetCamera( Ogre::Vector3& position, Ogre::Quaternion& orientation, Ogre::Degree& fov, const Field& field )
  2357. {
  2358. float downscaler = 128.0f * field.scale;
  2359. // sector 4
  2360. u32 offset_to_camera = 0x1c + GetU32LE( 0x0c ) - GetU32LE( 0x00 );
  2361. LOGGER->Log( "offset_to_camera = " + HexToString( offset_to_camera, 8, '0' ) + "\n" );
  2362. // get camera matrix (3 vectors)
  2363. Ogre::Matrix3 matrix;
  2364. matrix[ 0 ][ 0 ] = ( s16 )GetU16LE( offset_to_camera + 0x00 ) / 4096.0f;
  2365. matrix[ 1 ][ 0 ] = ( s16 )GetU16LE( offset_to_camera + 0x02 ) / 4096.0f;
  2366. matrix[ 2 ][ 0 ] = ( s16 )GetU16LE( offset_to_camera + 0x04 ) / 4096.0f;
  2367. matrix[ 0 ][ 1 ] = ( s16 )GetU16LE( offset_to_camera + 0x06 ) / 4096.0f;
  2368. matrix[ 1 ][ 1 ] = ( s16 )GetU16LE( offset_to_camera + 0x08 ) / 4096.0f;
  2369. matrix[ 2 ][ 1 ] = ( s16 )GetU16LE( offset_to_camera + 0x0a ) / 4096.0f;
  2370. matrix[ 0 ][ 2 ] = ( s16 )GetU16LE( offset_to_camera + 0x0c ) / 4096.0f;
  2371. matrix[ 1 ][ 2 ] = ( s16 )GetU16LE( offset_to_camera + 0x0e ) / 4096.0f;
  2372. matrix[ 2 ][ 2 ] = ( s16 )GetU16LE( offset_to_camera + 0x12 ) / 4096.0f;
  2373. // get camera position in camera space
  2374. position.x = -( s32 )GetU32LE( offset_to_camera + 0x14 ) / downscaler;
  2375. position.y = -( s32 )GetU32LE( offset_to_camera + 0x18 ) / downscaler;
  2376. position.z = -( s32 )GetU32LE( offset_to_camera + 0x1c ) / downscaler;
  2377. orientation.FromRotationMatrix( matrix );
  2378. position = orientation * position;
  2379. matrix[ 0 ][ 0 ] = matrix[ 0 ][ 0 ];
  2380. matrix[ 1 ][ 0 ] = matrix[ 1 ][ 0 ];
  2381. matrix[ 2 ][ 0 ] = matrix[ 2 ][ 0 ];
  2382. matrix[ 0 ][ 1 ] = -matrix[ 0 ][ 1 ];
  2383. matrix[ 1 ][ 1 ] = -matrix[ 1 ][ 1 ];
  2384. matrix[ 2 ][ 1 ] = -matrix[ 2 ][ 1 ];
  2385. matrix[ 0 ][ 2 ] = -matrix[ 0 ][ 2 ];
  2386. matrix[ 1 ][ 2 ] = -matrix[ 1 ][ 2 ];
  2387. matrix[ 2 ][ 2 ] = -matrix[ 2 ][ 2 ];
  2388. orientation.FromRotationMatrix( matrix );
  2389. float focal_length = GetU16LE( offset_to_camera + 0x24 );
  2390. fov = Ogre::Degree( Ogre::Radian( 2 * atanf( 240.0f / ( 2.0f * focal_length ) ) ) );
  2391. LOGGER->Log( "Field camera matrix : " + Ogre::StringConverter::toString( matrix ) + "\n" );
  2392. LOGGER->Log( "Camera position : " + Ogre::StringConverter::toString( position ) + "\n" );
  2393. LOGGER->Log( "Camera focal_length : " + FloatToString( focal_length ) + "\n");
  2394. LOGGER->Log( "Unknown (depth que?): DQB = " + HexToString( GetU32LE( offset_to_camera + 0x20 ), 8, '0' ) + ", DQA = " + HexToString( GetU16LE( offset_to_camera + 0x26 ), 4, '0' ) + "\n" );
  2395. }
  2396. void
  2397. DatFile::GetScreenRange( int& min_x, int& min_y, int& max_x, int& max_y )
  2398. {
  2399. // sector 5
  2400. u32 offset_to_triggers = 0x1c + GetU32LE( 0x10 ) - GetU32LE( 0x00 );
  2401. min_x = ( s16 )GetU16LE( offset_to_triggers + 0x0c ) * 3;
  2402. min_y = ( s16 )GetU16LE( offset_to_triggers + 0x0e ) * 3;
  2403. max_x = ( s16 )GetU16LE( offset_to_triggers + 0x10 ) * 3;
  2404. max_y = ( s16 )GetU16LE( offset_to_triggers + 0x12 ) * 3;
  2405. //LOGGER->Log(LOGGER_INFO, "Screen range: x: max = %d", max_x);
  2406. //LOGGER->Log(LOGGER_INFO, " min = %d", min_x);
  2407. //LOGGER->Log(LOGGER_INFO, " y: max = %d", max_y);
  2408. //LOGGER->Log(LOGGER_INFO, " min = %d", min_y);
  2409. //LOGGER->Log(LOGGER_INFO, "Leftover info %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %08x %08x %08x %08x %08x %08x", GetU8(offset_to_triggers + 0x14), GetU8(offset_to_triggers + 0x15), GetU8(offset_to_triggers + 0x16), GetU8(offset_to_triggers + 0x17), GetU8(offset_to_triggers + 0x18), GetU8(offset_to_triggers + 0x19), GetU8(offset_to_triggers + 0x1A), GetU8(offset_to_triggers + 0x1B), GetU8(offset_to_triggers + 0x1C), GetU8(offset_to_triggers + 0x1D), GetU8(offset_to_triggers + 0x1E), GetU8(offset_to_triggers + 0x1F), GetU32LE(offset_to_triggers + 0x20), GetU32LE(offset_to_triggers + 0x24), GetU32LE(offset_to_triggers + 0x28), GetU32LE(offset_to_triggers + 0x2C), GetU32LE(offset_to_triggers + 0x30), GetU32LE(offset_to_triggers + 0x34));
  2410. }
  2411. void
  2412. DatFile::DumpBackground( const Ogre::String& export_path, const Field& field, MimFile& mim )
  2413. {
  2414. Logger* export_text = new Logger( export_path + "maps/ffvii_field/" + field.name + "_bg.xml" );
  2415. int width = field.tex_width;
  2416. int height = field.tex_height;
  2417. // set camera for depth calculation
  2418. Ogre::Vector3 position = Ogre::Vector3::ZERO;
  2419. Ogre::Quaternion orientation = Ogre::Quaternion::IDENTITY;
  2420. Ogre::Degree fov = Ogre::Degree( 90 );
  2421. GetCamera( position, orientation, fov, field );
  2422. int min_x, min_y, max_x, max_y;
  2423. GetScreenRange( min_x, min_y, max_x, max_y );
  2424. export_text->Log( "<background2d" );
  2425. export_text->Log( " image=\"maps/ffvii/field/" + field.name + ".png\"" );
  2426. export_text->Log( " position=\"" + Ogre::StringConverter::toString( position ) + "\"" );
  2427. export_text->Log( " orientation=\"" + Ogre::StringConverter::toString( orientation ) + "\"" );
  2428. export_text->Log( " fov=\"" + Ogre::StringConverter::toString( fov ) + "\"" );
  2429. export_text->Log( " range=\"" + IntToString( min_x ) + " " + IntToString( min_y ) + " " + IntToString( max_x ) + " " + IntToString( max_y ) + "\"" );
  2430. export_text->Log( " clip=\"" + IntToString( 320 * 3 ) + " " + IntToString( 240 * 3 ) + "\"" );
  2431. export_text->Log( ">\n" );
  2432. full_image = CreateSurface( width, height );
  2433. x_32 = 0; y_32 = 0; x_16 = 0; y_16 = 0; n_16 = 0;
  2434. // sector 3
  2435. u32 offset_to_background = 0x1c + GetU32LE( 0x08 ) - GetU32LE( 0x00 );
  2436. u32 offset_to_1 = offset_to_background + 0x10;
  2437. u32 offset_to_2 = offset_to_background + GetU32LE( offset_to_background + 0x00 );
  2438. u32 offset_to_3 = offset_to_background + GetU32LE( offset_to_background + 0x04 );
  2439. u32 offset_to_4 = offset_to_background + GetU32LE( offset_to_background + 0x08 );
  2440. u32 offset_to_5 = offset_to_background + GetU32LE( offset_to_background + 0x0c );
  2441. u32 s1 = offset_to_1;
  2442. u32 s2 = offset_to_2;
  2443. u32 s3 = offset_to_3;
  2444. u32 s4 = offset_to_4;
  2445. u32 s5 = offset_to_5;
  2446. // get global texture setting
  2447. u16 g_page_x = GetU16LE( s3 ) & 0x000f;
  2448. u16 g_page_y = ( GetU16LE( s3 ) & 0x0010 ) >> 0x04;
  2449. u8 g_blending = ( GetU16LE( s3 ) & 0x0060 ) >> 0x05;
  2450. u8 g_bpp = ( GetU16LE( s3 ) & 0x0180 ) >> 0x07;
  2451. s3 += 0x02;
  2452. std::vector< Tile > tiles;
  2453. for( ; s1 < offset_to_2; s1 += 0x06 )
  2454. {
  2455. if( GetU16LE(s1) == 0x7ffe )
  2456. {
  2457. g_page_x = GetU16LE( s3 ) & 0x000f;
  2458. g_page_y = ( GetU16LE( s3 ) & 0x0010 ) >> 0x04;
  2459. g_blending = ( GetU16LE( s3 ) & 0x0060 ) >> 0x05;
  2460. g_bpp = ( GetU16LE( s3 ) & 0x0180 ) >> 0x07;
  2461. s3 += 0x02;
  2462. s1 += 0x06;
  2463. }
  2464. if( GetU16LE( s1 ) == 0x7fff )
  2465. {
  2466. s1 += 0x02;
  2467. break;
  2468. }
  2469. u16 sprite_num = GetU16LE( s1 + 0x04 );
  2470. for( u16 i = 0; i < sprite_num; ++i )
  2471. {
  2472. Tile tile;
  2473. tile.background = 0;
  2474. tile.dest_x = GetU16LE( s2 + 0x00 );
  2475. tile.dest_y = GetU16LE( s2 + 0x02 );
  2476. tile.src_x = GetU8( s2 + 0x04 );
  2477. tile.src_y = GetU8( s2 + 0x05 );
  2478. tile.clut_y = ( GetU16LE( s2 + 0x06 ) & 0xffc0 ) >> 6;
  2479. tile.clut_x = ( GetU16LE( s2 + 0x06 ) & 0x003f ) << 4;
  2480. tile.bpp = g_bpp;
  2481. tile.page_x = u8(g_page_x);
  2482. tile.page_y = u8(g_page_y);
  2483. tile.depth = 999;
  2484. tile.blending = 0;
  2485. tile.animation_id = 0;
  2486. tile.animation_frame = 0;
  2487. tiles.push_back( tile );
  2488. s2 += 0x08;
  2489. }
  2490. }
  2491. for( ; s1 < offset_to_2; s1 += 0x06 )
  2492. {
  2493. if( GetU16LE( s1 ) == 0x7fff )
  2494. {
  2495. s1 += 0x02;
  2496. break;
  2497. }
  2498. u16 sprite_num = GetU16LE( s1 + 0x04 );
  2499. for( u32 i = 0; i < sprite_num; ++i )
  2500. {
  2501. Tile tile;
  2502. tile.background = 1;
  2503. tile.dest_x = GetU16LE( s4 + 0x00 );
  2504. tile.dest_y = GetU16LE( s4 + 0x02 );
  2505. tile.src_x = u8(GetU16LE( s4 + 0x04 ));
  2506. tile.src_y = u8(GetU16LE( s4 + 0x05 ));
  2507. tile.clut_y = ( GetU16LE( s4 + 0x06 ) & 0xffc0 ) >> 6;
  2508. tile.clut_x = ( GetU16LE( s4 + 0x06 ) & 0x003f ) << 4;
  2509. tile.bpp = ( GetU16LE( s4 + 0x08 ) & 0x0180 ) >> 0x07;
  2510. tile.page_x = GetU16LE( s4 + 0x08 ) & 0x000f;
  2511. tile.page_y = ( GetU16LE( s4 + 0x08 ) & 0x0010 ) >> 0x04;
  2512. tile.depth = GetU16LE( s4 + 0x0a ) / ( 32.0f * field.scale );
  2513. tile.blending = ( GetU16LE( s4 + 0x08 ) & 0x60 ) >> 0x05;
  2514. tile.animation_id = GetU8( s4 + 0x0c ) & 0x0f;
  2515. tile.animation_frame = GetU8( s4 + 0x0d );
  2516. tiles.push_back( tile );
  2517. s4 += 0x0e;
  2518. }
  2519. }
  2520. /*
  2521. for( ; s1 < offset_to_2; s1 += 0x06 )
  2522. {
  2523. if( GetU16LE( s1 ) == 0x7ffe )
  2524. {
  2525. g_page_x = GetU16LE( s3 ) & 0x000f;
  2526. g_page_y = ( GetU16LE( s3 ) & 0x0010 ) >> 0x04;
  2527. g_blending = ( GetU16LE( s3 ) & 0x0060 ) >> 0x05;
  2528. g_bpp = ( GetU16LE( s3 ) & 0x0180 ) >> 0x07;
  2529. s3 += 0x02;
  2530. //LOGGER->Log( "Set global tex page x = " + HexToString( g_page_x, 4, '0' ) +", tex page y = " + HexToString( g_page_y, 4, '0' ) + ", blending = " + HexToString( g_blending, 2, '0' ) + ", bpp = " + HexToString( g_bpp, 2, '0' ) + "\n" );
  2531. s1 += 0x06;
  2532. }
  2533. if( GetU16LE( s1 ) == 0x7fff )
  2534. {
  2535. s1 += 0x02;
  2536. break;
  2537. }
  2538. u16 sprite_num = GetU16LE( s1 + 0x04 );
  2539. for( u32 i = 0; i < sprite_num; ++i )
  2540. {
  2541. Tile tile;
  2542. tile.background = 2;
  2543. tile.dest_x = GetU16LE( s5 + 0x00 );
  2544. tile.dest_y = GetU16LE( s5 + 0x02 );
  2545. tile.src_x = GetU8( s5 + 0x04 );
  2546. tile.src_y = GetU8( s5 + 0x05 );
  2547. tile.clut_y = ( GetU16LE( s5 + 0x06 ) & 0xffc0 ) >> 6;
  2548. tile.clut_x = ( GetU16LE( s5 + 0x06 ) & 0x003f ) << 4;
  2549. tile.bpp = g_bpp;
  2550. tile.page_x = g_page_x;
  2551. tile.page_y = g_page_y;
  2552. tile.depth = 0;
  2553. tile.blending = g_blending;
  2554. tile.animation = GetU8( s5 + 0x08 ) & 0x0f;
  2555. tile.animation_index = GetU8( s5 + 0x09 );
  2556. tiles.push_back( tile );
  2557. s5 += 0x0a;
  2558. }
  2559. }
  2560. // add layer 4 sprite
  2561. for( ; s1 < offset_to_2; s1 += 0x06 )
  2562. {
  2563. if( GetU16LE( s1 ) == 0x7ffe )
  2564. {
  2565. g_page_x = GetU16LE( s3 ) & 0x000f;
  2566. g_page_y = ( GetU16LE( s3 ) & 0x0010 ) >> 0x04;
  2567. g_blending = ( GetU16LE( s3 ) & 0x0060 ) >> 0x05;
  2568. g_bpp = ( GetU16LE( s3 ) & 0x0180 ) >> 0x07;
  2569. s3 += 0x02;
  2570. //LOGGER->Log( "Set global tex page x = " + ToHexString( g_page_x, 4, '0' ) +", tex page y = " + ToHexString( g_page_y, 4, '0' ) + ", blending = " + ToHexString( g_blending, 2, '0' ) + ", bpp = " + ToHexString( g_bpp, 2, '0' ) + "\n" );
  2571. s1 += 0x06;
  2572. }
  2573. if( GetU16LE( s1 ) == 0x7fff )
  2574. {
  2575. break;
  2576. }
  2577. u16 sprite_num = GetU16LE( s1 + 0x04 );
  2578. for( u32 i = 0; i < sprite_num; ++i )
  2579. {
  2580. Tile tile;
  2581. tile.background = 3;
  2582. tile.dest_x = GetU16LE( s5 + 0x00 );
  2583. tile.dest_y = GetU16LE( s5 + 0x02 );
  2584. tile.src_x = GetU8( s5 + 0x04 );
  2585. tile.src_y = GetU8( s5 + 0x05 );
  2586. tile.clut_y = ( GetU16LE( s5 + 0x06 ) & 0xffc0 ) >> 6;
  2587. tile.clut_x = ( GetU16LE( s5 + 0x06 ) & 0x003f ) << 4;
  2588. tile.bpp = g_bpp;
  2589. tile.page_x = g_page_x;
  2590. tile.page_y = g_page_y;
  2591. tile.depth = 0;
  2592. tile.blending = g_blending;
  2593. tile.animation = GetU8( s5 + 0x08 ) & 0x0f;
  2594. tile.animation_index = GetU8( s5 + 0x09 );
  2595. tiles.push_back( tile );
  2596. s5 += 0x0a;
  2597. }
  2598. }
  2599. */
  2600. // unify animations
  2601. std::vector< Tile > temp_tiles;
  2602. for( unsigned int i = 0; i < field.animations.size(); ++i )
  2603. {
  2604. LOGGER->Log( "Start add animation \"" + field.animations[ i ].name + "\".\n" );
  2605. for( unsigned int j = 0; j < field.animations[ i ].keyframes.size(); ++j )
  2606. {
  2607. if( field.animations[ i ].keyframes[ j ].blank != true )
  2608. {
  2609. LOGGER->Log( "Start add not blank keyframe at time \"" + FloatToString( field.animations[ i ].keyframes[ j ].time ) + "\".\n" );
  2610. for( unsigned int k = 0; k < tiles.size(); ++k )
  2611. {
  2612. if( TileCompare( tiles[ k ], field.animations[ i ].keyframes[ j ], mim ) == true )
  2613. {
  2614. tiles[ k ].animated = true;
  2615. Tile tile;
  2616. unsigned int l = 0;
  2617. for( ; l < temp_tiles.size(); ++l )
  2618. {
  2619. if( tiles[ k ].dest_x == temp_tiles[ l ].dest_x &&
  2620. tiles[ k ].dest_y == temp_tiles[ l ].dest_y &&
  2621. tiles[ k ].blending == temp_tiles[ l ].blending &&
  2622. ( tiles[ k ].animation_id == temp_tiles[ l ].animation_id ||
  2623. tiles[ k ].depth == temp_tiles[ l ].depth ) )
  2624. {
  2625. LOGGER->Log( "Temp_tile found use existed one.\n" );
  2626. tile = temp_tiles[ l ];
  2627. break;
  2628. }
  2629. }
  2630. if( l == temp_tiles.size() )
  2631. {
  2632. LOGGER->Log( "Temp_tile not found add new one.\n" );
  2633. tile = tiles[ k ];
  2634. }
  2635. LOGGER->Log( "Search for existed animation in temp_tiles.\n" );
  2636. unsigned int m = 0;
  2637. for( ; m < tile.animations.size(); ++m )
  2638. {
  2639. if( tile.animations[ m ].name == field.animations[ i ].name )
  2640. {
  2641. LOGGER->Log( "Animation found.\n" );
  2642. break;
  2643. }
  2644. }
  2645. if( m == tile.animations.size() )
  2646. {
  2647. LOGGER->Log( "Animation not found add new one.\n" );
  2648. Animation animation;
  2649. animation.name = field.animations[ i ].name;
  2650. animation.time = field.animations[ i ].time;
  2651. tile.animations.push_back( animation );
  2652. }
  2653. KeyFrame frame;
  2654. frame.time = field.animations[ i ].keyframes[ j ].time;
  2655. frame.src_x = tiles[ k ].src_x;
  2656. frame.src_y = tiles[ k ].src_y;
  2657. frame.clut_x = tiles[ k ].clut_x;
  2658. frame.clut_y = tiles[ k ].clut_y;
  2659. frame.bpp = tiles[ k ].bpp;
  2660. frame.page_x = tiles[ k ].page_x;
  2661. frame.page_y = tiles[ k ].page_y;
  2662. frame.clut_start = field.animations[ i ].keyframes[ j ].clut_start;
  2663. frame.clut_width = field.animations[ i ].keyframes[ j ].clut_width;
  2664. frame.mod_type = field.animations[ i ].keyframes[ j ].mod_type;
  2665. frame.mod_r = field.animations[ i ].keyframes[ j ].mod_r;
  2666. frame.mod_g = field.animations[ i ].keyframes[ j ].mod_g;
  2667. frame.mod_b = field.animations[ i ].keyframes[ j ].mod_b;
  2668. tile.animations[ m ].keyframes.push_back( frame );
  2669. LOGGER->Log( "Keyframe at time \"" + FloatToString( field.animations[ i ].keyframes[ j ].time ) + "\" added.\n" );
  2670. if( l == temp_tiles.size() )
  2671. {
  2672. temp_tiles.push_back( tile );
  2673. }
  2674. else
  2675. {
  2676. temp_tiles[ l ] = tile;
  2677. }
  2678. }
  2679. }
  2680. }
  2681. else
  2682. {
  2683. LOGGER->Log( "Start add blank keyframe at time \"" + FloatToString( field.animations[ i ].keyframes[ j ].time ) + "\".\n" );
  2684. for( unsigned int k = 0; k < tiles.size(); ++k )
  2685. {
  2686. if( tiles[ k ].animation_id == field.animations[ i ].keyframes[ j ].animation_id && tiles[ k ].animation_frame == 1 )
  2687. {
  2688. Tile tile;
  2689. unsigned int l = 0;
  2690. for( ; l < temp_tiles.size(); ++l )
  2691. {
  2692. if( tiles[ k ].dest_x == temp_tiles[ l ].dest_x &&
  2693. tiles[ k ].dest_y == temp_tiles[ l ].dest_y &&
  2694. tiles[ k ].blending == temp_tiles[ l ].blending &&
  2695. ( tiles[ k ].animation_id == temp_tiles[ l ].animation_id ||
  2696. tiles[ k ].depth == temp_tiles[ l ].depth ) )
  2697. {
  2698. LOGGER->Log( "Temp_tile found use existed one.\n" );
  2699. tile = temp_tiles[ l ];
  2700. break;
  2701. }
  2702. }
  2703. if( l == temp_tiles.size() )
  2704. {
  2705. LOGGER->Log( "Temp_tile not found add new one.\n" );
  2706. tile = tiles[ k ];
  2707. }
  2708. LOGGER->Log( "Search for existed animation in temp_tiles.\n" );
  2709. unsigned int m = 0;
  2710. for( ; m < tile.animations.size(); ++m )
  2711. {
  2712. if( tile.animations[ m ].name == field.animations[ i ].name )
  2713. {
  2714. LOGGER->Log( "Animation found.\n" );
  2715. break;
  2716. }
  2717. }
  2718. if( m == tile.animations.size() )
  2719. {
  2720. LOGGER->Log( "Animation not found add new one.\n" );
  2721. Animation animation;
  2722. animation.name = field.animations[ i ].name;
  2723. animation.time = field.animations[ i ].time;
  2724. tile.animations.push_back( animation );
  2725. }
  2726. KeyFrame frame;
  2727. frame.time = field.animations[ i ].keyframes[ j ].time;
  2728. frame.src_x = 0;
  2729. frame.src_y = 0;
  2730. frame.clut_x = 0;
  2731. frame.clut_y = 0;
  2732. frame.bpp = 0;
  2733. frame.page_x = 0;
  2734. frame.page_y = 0;
  2735. frame.mod_type = "";
  2736. tile.animations[ m ].keyframes.push_back( frame );
  2737. LOGGER->Log( "Keyframe at time \"" + FloatToString( field.animations[ i ].keyframes[ j ].time ) + "\" added.\n" );
  2738. if( l == temp_tiles.size() )
  2739. {
  2740. temp_tiles.push_back( tile );
  2741. }
  2742. else
  2743. {
  2744. temp_tiles[ l ] = tile;
  2745. }
  2746. }
  2747. }
  2748. }
  2749. }
  2750. }
  2751. for( unsigned int i = 0; i < tiles.size(); ++i )
  2752. {
  2753. if( tiles[ i ].animated != true )
  2754. {
  2755. temp_tiles.push_back( tiles[ i ] );
  2756. }
  2757. }
  2758. LOGGER->Log( "Start sorting all tiles.\n" );
  2759. for( unsigned int i = 0; i < temp_tiles.size(); ++i )
  2760. {
  2761. for (unsigned int l = 0; l < temp_tiles[i].animations.size(); ++l)
  2762. {
  2763. std::sort( temp_tiles[ i ].animations[ l ].keyframes.begin(), temp_tiles[ i ].animations[ l ].keyframes.end(), anim_time_sort() );
  2764. }
  2765. std::sort( temp_tiles[ i ].animations.begin(), temp_tiles[ i ].animations.end(), anim_name_sort() );
  2766. }
  2767. LOGGER->Log( "Finish sorting all tiles.\n" );
  2768. tiles = temp_tiles;
  2769. LOGGER->Log( "Start add tiles to file.\n" );
  2770. for( unsigned int i = 0; i < tiles.size(); ++i )
  2771. {
  2772. AddTile( tiles[ i ], mim, export_text );
  2773. }
  2774. LOGGER->Log( "Finish add tiles to file.\n" );
  2775. Ogre::TexturePtr ptex;
  2776. Ogre::HardwarePixelBufferSharedPtr buffer;
  2777. ptex = Ogre::TextureManager::getSingleton().createManual( "DynaTex", "General", Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_R8G8B8A8, Ogre::TU_STATIC );
  2778. buffer = ptex->getBuffer( 0, 0 );
  2779. buffer->lock( Ogre::HardwareBuffer::HBL_DISCARD );
  2780. const Ogre::PixelBox& pb = buffer->getCurrentLock();
  2781. for( s32 y = 0; y < height; ++y )
  2782. {
  2783. u32* data = static_cast< u32* >( pb.data ) + y * pb.rowPitch;
  2784. for( s32 x = 0; x < width; ++x )
  2785. {
  2786. u32 clut = full_image->pixels[ y * width * 4 + x * 4 + 3 ]
  2787. | ( full_image->pixels[ y * width * 4 + x * 4 + 2 ] << 8 )
  2788. | ( full_image->pixels[ y * width * 4 + x * 4 + 1 ] << 16 )
  2789. | ( full_image->pixels[ y * width * 4 + x * 4 + 0 ] << 24 );
  2790. data[ x ] = clut;
  2791. }
  2792. }
  2793. Ogre::Image image;
  2794. image.loadDynamicImage( ( Ogre::uchar* )pb.data, width, height, Ogre::PF_R8G8B8A8 );
  2795. image.save( export_path + "maps/ffvii_field/" + field.name + ".png" );
  2796. buffer->unlock();
  2797. Ogre::TextureManager::getSingleton().remove( "DynaTex" );
  2798. export_text->Log( "</background2d>" );
  2799. delete export_text;
  2800. }
  2801. bool
  2802. DatFile::TileCompare( const Tile& tile, const FieldKeyFrame& keyframe, MimFile& mim )
  2803. {
  2804. bool ret = true;
  2805. // compare animations
  2806. if( keyframe.animation_id != tile.animation_id )
  2807. {
  2808. ret = false;
  2809. }
  2810. else if( keyframe.animation_id != 0 )
  2811. {
  2812. if( ( 1 << keyframe.animation_frame ) != tile.animation_frame )
  2813. {
  2814. ret = false;
  2815. }
  2816. }
  2817. // compare palette
  2818. if( keyframe.clut_y != -1 )
  2819. {
  2820. if( keyframe.clut_y != tile.clut_y )
  2821. {
  2822. ret = false;
  2823. }
  2824. /*
  2825. else
  2826. {
  2827. // set size depending on background
  2828. u8 size = ( tile.background > 1 ) ? 32 : 16;
  2829. if( mim.ClutCheck( tile.page_x, tile.page_y, tile.clut_x, tile.bpp, tile.src_x, tile.src_y, size, size, keyframe.clut_x, keyframe.clut_width ) == false )
  2830. {
  2831. ret = false;
  2832. }
  2833. }
  2834. */
  2835. }
  2836. return ret;
  2837. }
  2838. void
  2839. DatFile::AddTile( const Tile& tile, MimFile& mim, Logger* export_text )
  2840. {
  2841. AddedTile added_main_tile = AddTileTex( tile.background, tile.src_x, tile.src_y, tile.clut_x, tile.clut_y, tile.bpp, tile.page_x, tile.page_y, mim, 0, 0, "", 1, 1, 1 );
  2842. Ogre::String blending_str = "";
  2843. if( tile.blending == 0 )
  2844. {
  2845. blending_str = "alpha";
  2846. }
  2847. else if( tile.blending == 1 )
  2848. {
  2849. blending_str = "add";
  2850. }
  2851. else if( tile.blending == 2 )
  2852. {
  2853. blending_str = "subtract";
  2854. }
  2855. // else if( tile.blending == 3 )
  2856. // {
  2857. // blending_str = "add"; // source + 0.25 * destination
  2858. // }
  2859. else
  2860. {
  2861. LOGGER->Log( "Tile blending with type \"" + Ogre::StringConverter::toString( tile.blending ) + "\" not supported." );
  2862. }
  2863. export_text->Log(
  2864. " <tile destination=\"" +
  2865. Ogre::StringConverter::toString( tile.dest_x * 3 ) +
  2866. " " +
  2867. Ogre::StringConverter::toString( tile.dest_y * 3 ) +
  2868. "\" width=\"" +
  2869. Ogre::StringConverter::toString( added_main_tile.width * 3 ) +
  2870. "\" height=\"" +
  2871. Ogre::StringConverter::toString( added_main_tile.height * 3 ) +
  2872. "\" uv=\"" +
  2873. Ogre::StringConverter::toString( added_main_tile.x / ( float ) full_image->width ) +
  2874. " " +
  2875. Ogre::StringConverter::toString( added_main_tile.y / ( float ) full_image->height ) +
  2876. " " +
  2877. Ogre::StringConverter::toString( ( added_main_tile.x + added_main_tile.width ) / ( float ) full_image->width ) +
  2878. " " +
  2879. Ogre::StringConverter::toString( ( added_main_tile.y + added_main_tile.height ) / ( float ) full_image->height ) +
  2880. "\" depth=\"" +
  2881. Ogre::StringConverter::toString( ( tile.depth > 0.002f ) ? tile.depth : 0.002f ) +
  2882. "\" blending=\"" + blending_str + "\""
  2883. );
  2884. if( tile.animations.size() == 0 )
  2885. {
  2886. export_text->Log( " />\n" );
  2887. }
  2888. else
  2889. {
  2890. export_text->Log( ">\n" );
  2891. for( unsigned int l = 0; l < tile.animations.size(); ++l )
  2892. {
  2893. export_text->Log( " <animation name=\"" + tile.animations[ l ].name + "\" length=\"" + Ogre::StringConverter::toString( tile.animations[ l ].time ) + "\" >" );
  2894. for( unsigned int i = 0; i < tile.animations[ l ].keyframes.size(); ++i )
  2895. {
  2896. export_text->Log( "<keyframe" );
  2897. export_text->Log( " time=\"" + Ogre::StringConverter::toString( tile.animations[ l ].keyframes[ i ].time ) + "\"" );
  2898. //LOGGER->Log( "Animation tile pixels src_x=\"" + IntToString( tile.animation_key.keyframes[ i ].src_x ) + "\" src_y=\"" + IntToString( tile.animation_key.keyframes[ i ].src_y ) + "\"\n" );
  2899. AddedTile added_tile = AddTileTex( tile.background, tile.animations[ l ].keyframes[ i ].src_x, tile.animations[ l ].keyframes[ i ].src_y, tile.animations[ l ].keyframes[ i ].clut_x, tile.animations[ l ].keyframes[ i ].clut_y, tile.animations[ l ].keyframes[ i ].bpp, tile.animations[ l ].keyframes[ i ].page_x, tile.animations[ l ].keyframes[ i ].page_y, mim, tile.animations[ l ].keyframes[ i ].clut_start, tile.animations[ l ].keyframes[ i ].clut_width, tile.animations[ l ].keyframes[ i ].mod_type, tile.animations[ l ].keyframes[ i ].mod_r, tile.animations[ l ].keyframes[ i ].mod_g, tile.animations[ l ].keyframes[ i ].mod_b );
  2900. //LOGGER->Log( "Animation tile pixels x=\"" + IntToString( x ) + "\" y=\"" + IntToString( y ) + "\"\n" );
  2901. export_text->Log( " uv=\""
  2902. +Ogre::StringConverter::toString( added_tile.x / ( float ) full_image->width )
  2903. +" "
  2904. +Ogre::StringConverter::toString( added_tile.y / ( float ) full_image->height )
  2905. +" "
  2906. +Ogre::StringConverter::toString( ( added_tile.x + added_tile.width ) / ( float ) full_image->width )
  2907. +" "
  2908. +Ogre::StringConverter::toString( ( added_tile.y + added_tile.height ) / ( float ) full_image->height )
  2909. +"\""
  2910. );
  2911. export_text->Log( "/>" );
  2912. }
  2913. export_text->Log( "</animation>\n" );
  2914. }
  2915. export_text->Log( " </tile>\n" );
  2916. }
  2917. }
  2918. AddedTile
  2919. DatFile::AddTileTex( const u8 background, const u8 src_x, const u8 src_y, const u16 clut_x, const u16 clut_y, const u8 bpp, const u8 page_x, const u8 page_y, MimFile& mim, const int clut_start, const int clut_width, const Ogre::String& mod_type, const float mod_r, const float mod_g, const float mod_b )
  2920. {
  2921. AddedTile tile;
  2922. tile.background = background;
  2923. tile.src_x = src_x;
  2924. tile.src_y = src_y;
  2925. tile.clut_x = clut_x;
  2926. tile.clut_y = clut_y;
  2927. tile.bpp = bpp;
  2928. tile.page_x = page_x;
  2929. tile.page_y = page_x;
  2930. tile.clut_start = clut_start;
  2931. tile.clut_width = clut_width;
  2932. tile.mod_type = mod_type;
  2933. tile.mod_r = mod_r;
  2934. tile.mod_g = mod_g;
  2935. tile.mod_b = mod_b;
  2936. std::vector< AddedTile >::iterator tile_it = std::find_if( m_AddedTiles.begin(), m_AddedTiles.end(), added_tile_find( tile ) );
  2937. if( tile_it != m_AddedTiles.end() )
  2938. {
  2939. return *tile_it;
  2940. }
  2941. SurfaceTexData surface;
  2942. surface.page_x = page_x;
  2943. surface.page_y = page_y;
  2944. surface.clut_x = clut_x;
  2945. surface.clut_y = clut_y;
  2946. surface.bpp = bpp;
  2947. surface.clut_start = clut_start;
  2948. surface.clut_width = clut_width;
  2949. surface.mod_type = mod_type;
  2950. surface.mod_r = mod_r;
  2951. surface.mod_g = mod_g;
  2952. surface.mod_b = mod_b;
  2953. std::vector< SurfaceTexData >::iterator it = std::find_if( m_Surfaces.begin(), m_Surfaces.end(), surface_find( surface ) );
  2954. if( it == m_Surfaces.end() )
  2955. {
  2956. surface.surface = mim.GetSurface( page_x, page_y, clut_x, clut_y, bpp, clut_start, clut_width, mod_type, mod_r, mod_g, mod_b );
  2957. m_Surfaces.push_back( surface );
  2958. }
  2959. else
  2960. {
  2961. surface = *it;
  2962. }
  2963. // set size depending on background
  2964. u8 size = ( background > 1 ) ? 32 : 16;
  2965. Surface* sub_image = CreateSubSurface( src_x, src_y, size, size, surface.surface );
  2966. if( sub_image->width == 32 )
  2967. {
  2968. tile.x = float(x_32);
  2969. tile.y = float(y_32);
  2970. x_32 += 32;
  2971. if( x_32 == full_image->width )
  2972. {
  2973. y_32 += 32;
  2974. x_32 = 0;
  2975. }
  2976. }
  2977. else if( sub_image->width == 16 )
  2978. {
  2979. // if we start new 16x16*4 block
  2980. if( n_16 == 0 )
  2981. {
  2982. x_16 = x_32;
  2983. y_16 = y_32;
  2984. x_32 += 32;
  2985. if( x_32 == full_image->width )
  2986. {
  2987. y_32 += 32;
  2988. x_32 = 0;
  2989. }
  2990. }
  2991. tile.x = float(x_16);
  2992. tile.y = float(y_16);
  2993. ++n_16;
  2994. if( n_16 == 1 || n_16 == 3 )
  2995. {
  2996. x_16 += 16;
  2997. }
  2998. else if( n_16 == 2 )
  2999. {
  3000. x_16 -= 16;
  3001. y_16 += 16;
  3002. }
  3003. else if( n_16 == 4 )
  3004. {
  3005. n_16 = 0;
  3006. }
  3007. }
  3008. CopyToSurface( full_image, int(tile.x), int(tile.y), sub_image );
  3009. tile.width = size;
  3010. tile.height = size;
  3011. m_AddedTiles.push_back( tile );
  3012. return tile;
  3013. }
  3014. void
  3015. DatFile::DumpWalkmesh( const Ogre::String& export_path, const Field& field )
  3016. {
  3017. Logger* export_script = new Logger( export_path + "/maps/ffvii_field/" + field.name + "_wm.xml" );
  3018. export_script->Log( "<walkmesh>\n" );
  3019. // get sector 2 offset (walkmesh)
  3020. u32 offset_to_walkmesh = 0x1C + GetU32LE( 0x04 ) - GetU32LE( 0x00 );
  3021. u32 number_of_poly = GetU32LE( offset_to_walkmesh );
  3022. int start_walkmesh = offset_to_walkmesh + 0x04;
  3023. int start_access = offset_to_walkmesh + 0x04 + number_of_poly * 0x18;
  3024. float downscaler = 128.0f * field.scale;
  3025. Ogre::Vector3 A, B, C;
  3026. for( u32 i = 0; i < number_of_poly; ++i )
  3027. {
  3028. A.x = ( s16 )GetU16LE( start_walkmesh + 0x00 ) / downscaler;
  3029. A.y = ( s16 )GetU16LE( start_walkmesh + 0x02 ) / downscaler;
  3030. A.z = ( s16 )GetU16LE( start_walkmesh + 0x04 ) / downscaler;
  3031. B.x = ( s16 )GetU16LE( start_walkmesh + 0x08 ) / downscaler;
  3032. B.y = ( s16 )GetU16LE( start_walkmesh + 0x0A ) / downscaler;
  3033. B.z = ( s16 )GetU16LE( start_walkmesh + 0x0C ) / downscaler;
  3034. C.x = ( s16 )GetU16LE( start_walkmesh + 0x10 ) / downscaler;
  3035. C.y = ( s16 )GetU16LE( start_walkmesh + 0x12 ) / downscaler;
  3036. C.z = ( s16 )GetU16LE( start_walkmesh + 0x14 ) / downscaler;
  3037. export_script->Log(
  3038. " <triangle a=\"" +
  3039. Ogre::StringConverter::toString( A ) +
  3040. "\" b=\"" +
  3041. Ogre::StringConverter::toString( B ) +
  3042. "\" c=\"" +
  3043. Ogre::StringConverter::toString( C ) +
  3044. "\" a_b=\"" +
  3045. IntToString( ( s16 )GetU16LE( start_access + 0x00 ) ) +
  3046. "\" b_c=\"" +
  3047. IntToString( ( s16 )GetU16LE( start_access + 0x02 ) ) +
  3048. "\" c_a=\"" +
  3049. IntToString( ( s16 )GetU16LE( start_access + 0x04 ) ) +
  3050. "\"/>\n"
  3051. );
  3052. // go to the next triangle
  3053. start_walkmesh += 0x18;
  3054. start_access += 0x06;
  3055. }
  3056. export_script->Log( "</walkmesh>" );
  3057. delete export_script;
  3058. }
  3059. void
  3060. DatFile::DumpTriggersMovements( const Ogre::String& export_path, const Field& field )
  3061. {
  3062. Logger* export_script = new Logger( export_path + "/maps/ffvii_field/" + field.name + "_triggers.xml" );
  3063. // get sector 5 triggers
  3064. u32 offset_to_triggers = 0x1c + GetU32LE( 0x10 ) - GetU32LE( 0x00 );
  3065. u32 start_triggers = offset_to_triggers + 0x38;
  3066. float downscaler_this = 128.0f * field.scale;
  3067. for( u32 i = 0; i < 12; ++i )
  3068. {
  3069. s16 map_id = GetU16LE( start_triggers + 0x12 );
  3070. // if not inactive gateway
  3071. if( map_id != 32767 )
  3072. {
  3073. float downscaler_next = 128.0f * MapIdToScale( map_id );
  3074. Ogre::Vector3 point1( ( s16 )GetU16LE( start_triggers + 0x00 ) / downscaler_this,
  3075. ( s16 )GetU16LE( start_triggers + 0x02 ) / downscaler_this,
  3076. ( s16 )GetU16LE( start_triggers + 0x04 ) / downscaler_this );
  3077. Ogre::Vector3 point2( ( s16 )GetU16LE( start_triggers + 0x06 ) / downscaler_this,
  3078. ( s16 )GetU16LE( start_triggers + 0x08 ) / downscaler_this,
  3079. ( s16 )GetU16LE( start_triggers + 0x0a ) / downscaler_this );
  3080. Ogre::Vector3 position( ( s16 )GetU16LE( start_triggers + 0x0c ) / downscaler_next,
  3081. ( s16 )GetU16LE( start_triggers + 0x0e ) / downscaler_next,
  3082. ( s16 )GetU16LE( start_triggers + 0x10 ) / downscaler_next );
  3083. float direction = 360.0f * GetU8( start_triggers + 0x14 ) / 255.0f;
  3084. export_script->Log( " <entity_trigger name=\"Gateway" + IntToString( i ) + "\" point1=\"" + Ogre::StringConverter::toString( point1 ) + "\" point2=\"" + Ogre::StringConverter::toString( point2 ) + "\" enabled=\"true\" />\n" );
  3085. export_script->Log( " <entity_point name=\"Spawn_"+ field.name + "\" position=\"" + Ogre::StringConverter::toString( position ) + "\" rotation=\"" + FloatToString( direction ) + "\" />\n" );
  3086. export_script->Log( " <!-- map \"" + MapIdToString( map_id ) + "\" -->\n" );
  3087. }
  3088. start_triggers += 0x18;
  3089. }
  3090. // movement rotation
  3091. u32 movement = GetU32LE( offset_to_triggers + 0x08 );
  3092. export_script->Log( "<movement_rotation degree=\"" + Ogre::StringConverter::toString( 180.0f * ( ( float )movement - 32768.0f ) / 32768.0f ) + "\" />\n" );
  3093. delete export_script;
  3094. }