DatFile.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. #ifndef DATFILE_H
  2. #define DATFILE_H
  3. #include "../../common/Logger.h"
  4. #include "common/LzsFile.h"
  5. #include "../../common/Surface.h"
  6. #include "MimFile.h"
  7. enum eOpcodes
  8. {
  9. RET = 0x0,
  10. REQ = 0x01,
  11. REQSW = 0x02,
  12. REQEW = 0x03,
  13. RETTO = 0x07,
  14. JOIN = 0x08,
  15. SPLIT = 0x09,
  16. SPTYE = 0x0A,
  17. GTPYE = 0x0B,
  18. SPECIAL = 0x0F,
  19. JMPF = 0x10,
  20. JMPFL = 0x11,
  21. JMPB = 0x12,
  22. JMPBL = 0x13,
  23. IFUB = 0x14,
  24. IFUBL = 0x15,
  25. IFSW = 0x16,
  26. IFSWL = 0x17,
  27. IFUW = 0x18,
  28. TUTOR = 0x21,
  29. WAIT = 0x24,
  30. NFADE = 0x25,
  31. BLINK = 0x26,
  32. KAWAI = 0x28,
  33. WCLS = 0x2E,
  34. WSIZW = 0x2F,
  35. IFKEY = 0x30,
  36. IFKEYON = 0x31,
  37. UC = 0x33,
  38. WSPCL = 0x36,
  39. STTIM = 0x38,
  40. GOLDU = 0x39,
  41. GOLDD = 0x3A,
  42. CHGLD = 0x3B,
  43. MHMMX = 0x3E,
  44. HMPMAX3 = 0x3F,
  45. MESSAGE = 0x40,
  46. MPNAM = 0x43,
  47. ASK = 0x48,
  48. MENU = 0x49,
  49. MENU2 = 0x4A,
  50. BTLTB = 0x4B,
  51. WINDOW = 0x50,
  52. WMODE = 0x52,
  53. WREST = 0x53,
  54. WCLSE = 0x54,
  55. STITM = 0x58,
  56. CKITM = 0x5A,
  57. SMTRA = 0x5B,
  58. SHAKE = 0x5E,
  59. MAPJUMP = 0x60,
  60. SCRLC = 0x62,
  61. SCRLA = 0x63,
  62. SCR2D = 0x64,
  63. SCRCC = 0x65,
  64. SCR2DC = 0x66,
  65. SCRLW = 0x67,
  66. SCR2DL = 0x68,
  67. VWOFT = 0x6A,
  68. FADE = 0x6B,
  69. FADEW = 0x6C,
  70. IDLCK = 0x6D,
  71. LSTMP = 0x6E,
  72. BATTLE = 0x70,
  73. BTLON = 0x71,
  74. BTLMD = 0x72,
  75. PLUS_ = 0x76, // PLUS!
  76. PLUS2_ = 0x77, // PLUS2!
  77. MINUS_ = 0x78, // MINUS!
  78. MINUS2_= 0x79, // MINUS2!
  79. INC_= 0x7A, // INC!
  80. TALKON = 0x7E,
  81. SETBYTE = 0x80,
  82. SETWORD = 0x81,
  83. BITON = 0x82,
  84. BITOFF = 0x83,
  85. PLUS = 0x85,
  86. MINUS = 0x87,
  87. MUL = 0x89,
  88. MOD = 0x8D,
  89. AND = 0x8F,
  90. AND2 = 0x90,
  91. OR = 0x91,
  92. OR2 = 0x92,
  93. INC = 0x95,
  94. DEC = 0x97,
  95. RANDOM = 0x99,
  96. PC = 0xA0,
  97. opCodeCHAR = 0xA1,
  98. DFANM = 0xA2,
  99. ANIME1 = 0xA3,
  100. VISI = 0xA4,
  101. XYZI = 0xA5,
  102. XYI = 0xA6,
  103. MOVE = 0xA8,
  104. CMOVE = 0xA9,
  105. MOVA = 0xAA,
  106. TURA = 0xAB,
  107. ANIMW = 0xAC,
  108. FMOVE = 0xAD,
  109. ANIME2 = 0xAE,
  110. ANIM_1 = 0xAF, // ANIM!1
  111. CANM_1 = 0xB1, // CANM!1
  112. MSPED = 0xB2,
  113. DIR = 0xB3,
  114. TURNGEN = 0xB4,
  115. TURN = 0xB5,
  116. DIRA = 0xB6,
  117. GETDIR = 0xB7,
  118. GETAXY = 0xB8,
  119. GETAI = 0xB9,
  120. ANIM_2 = 0xBA, // ANIM!2
  121. CANIM2 = 0xBB,
  122. CANM_2 = 0xBC, // CANM!2
  123. ASPED = 0xBD,
  124. CC = 0xBF,
  125. JUMP = 0xC0,
  126. AXYZI = 0xC1,
  127. LADER = 0xC2,
  128. OFST = 0xC3,
  129. OFSTW = 0xC4,
  130. TALKR = 0xC5,
  131. CLIDR = 0xC6,
  132. SOLID = 0xC7,
  133. PRTYP = 0xC8,
  134. PRTYM = 0xC9,
  135. PRTYE = 0xCA,
  136. MMBUD = 0xCD,
  137. MMBLK = 0xCE,
  138. LINE = 0xD0,
  139. LINON = 0xD1,
  140. MPJPO = 0xD2,
  141. SLINE = 0xD3,
  142. PMJMP = 0xD8,
  143. AKAO2 = 0xDA,
  144. ANIMB = 0xDD,
  145. TURNW = 0xDE,
  146. BGON = 0xE0,
  147. BGOFF = 0xE1,
  148. BGCLR = 0xE4,
  149. STPAL = 0xE5,
  150. LDPAL = 0xE6,
  151. CPPAL = 0xE7,
  152. ADPAL = 0xE9,
  153. MPPAL2 = 0xEA,
  154. STPLS = 0xEB,
  155. LDPLS = 0xEC,
  156. RTPAL2 = 0xEE,
  157. ADPAL2 = 0xEF,
  158. MUSIC = 0xF0,
  159. SOUND = 0xF1,
  160. AKAO = 0xF2,
  161. MULCK = 0xF5,
  162. BMUSC = 0xF6,
  163. PMVIE = 0xF8,
  164. MOVIE = 0xF9,
  165. MVIEF = 0xFA,
  166. MVCAM = 0xFB,
  167. FMUSC = 0xFC,
  168. CHMST = 0xFE
  169. };
  170. struct FieldKeyFrame
  171. {
  172. FieldKeyFrame():
  173. time( 0 ),
  174. blank( false ),
  175. animation_id( 0 ),
  176. animation_frame( 0 ),
  177. clut_y( -1 ),
  178. clut_start( 0 ),
  179. clut_width( 0 ),
  180. mod_type( "add" ),
  181. mod_r( 0 ),
  182. mod_g( 0 ),
  183. mod_b( 0 )
  184. {
  185. }
  186. float time;
  187. bool blank;
  188. int animation_id;
  189. int animation_frame;
  190. int clut_y;
  191. int clut_start;
  192. int clut_width;
  193. Ogre::String mod_type;
  194. float mod_r;
  195. float mod_g;
  196. float mod_b;
  197. };
  198. struct FiledAnimation
  199. {
  200. Ogre::String name;
  201. float time;
  202. std::vector< FieldKeyFrame > keyframes;
  203. };
  204. struct Field
  205. {
  206. Ogre::String name;
  207. float scale;
  208. int tex_width;
  209. int tex_height;
  210. std::vector< FiledAnimation > animations;
  211. };
  212. struct DatModelData
  213. {
  214. int face_id;
  215. int number_of_bones;
  216. int number_of_parts;
  217. int number_of_animation;
  218. int global_model_id;
  219. };
  220. struct SurfaceTexData
  221. {
  222. Surface* surface;
  223. u16 page_x;
  224. u16 page_y;
  225. u16 clut_x;
  226. u16 clut_y;
  227. u8 bpp;
  228. int clut_start;
  229. int clut_width;
  230. Ogre::String mod_type;
  231. float mod_r;
  232. float mod_g;
  233. float mod_b;
  234. };
  235. struct KeyFrame
  236. {
  237. float time;
  238. u8 src_x;
  239. u8 src_y;
  240. u16 clut_x;
  241. u16 clut_y;
  242. u8 bpp;
  243. u8 page_x;
  244. u8 page_y;
  245. int clut_start;
  246. int clut_width;
  247. Ogre::String mod_type;
  248. float mod_r;
  249. float mod_g;
  250. float mod_b;
  251. };
  252. struct Animation
  253. {
  254. float time;
  255. Ogre::String name;
  256. std::vector< KeyFrame > keyframes;
  257. };
  258. struct Tile
  259. {
  260. Tile():
  261. animated( false )
  262. {
  263. }
  264. bool animated;
  265. u8 background;
  266. s16 dest_x;
  267. s16 dest_y;
  268. u8 src_x;
  269. u8 src_y;
  270. u16 clut_x;
  271. u16 clut_y;
  272. u8 bpp;
  273. u8 page_x;
  274. u8 page_y;
  275. float depth;
  276. u8 blending;
  277. u8 animation_id;
  278. u8 animation_frame;
  279. std::vector< Animation > animations;
  280. };
  281. struct AddedTile
  282. {
  283. u8 background;
  284. u8 src_x;
  285. u8 src_y;
  286. u16 clut_x;
  287. u16 clut_y;
  288. u8 bpp;
  289. u8 page_x;
  290. u8 page_y;
  291. int clut_start;
  292. int clut_width;
  293. Ogre::String mod_type;
  294. float mod_r;
  295. float mod_g;
  296. float mod_b;
  297. float x;
  298. float y;
  299. float width;
  300. float height;
  301. };
  302. class DatFile : public LzsFile
  303. {
  304. public:
  305. DatFile( const Ogre::String& file );
  306. DatFile( File* file );
  307. DatFile( File* file, const u32 offset, const u32 length );
  308. DatFile( u8* buffer, const u32 offset, const u32 length );
  309. virtual ~DatFile();
  310. void DumpText( const Ogre::String& export_path, const Field& field, bool english );
  311. void DumpScript( const Ogre::String& export_path, const Field& field );
  312. void DumpWalkmesh( const Ogre::String& export_path, const Field& field );
  313. void GetCamera( Ogre::Vector3& position, Ogre::Quaternion& orientation, Ogre::Degree& fov, const Field& field );
  314. void GetScreenRange( int& min_x, int& min_y, int& max_x, int& max_y );
  315. void DumpBackground( const Ogre::String& export_path, const Field& field, MimFile& mim );
  316. void DumpTriggersMovements( const Ogre::String& export_path, const Field& field );
  317. static void DumpSoundOpcodesData( const Ogre::String& export_file );
  318. void AdvanceScript( u32 value, u32& current, u32& end );
  319. Ogre::String ParseVariableName( int slot, int value );
  320. Ogre::String ParseGetVariable( int get_slot, int get_value, unsigned int hex = 0, float fixed = 1.0f );
  321. Ogre::String SetVariable( int set_slot, int set_value, Ogre::String get_string );
  322. Ogre::String SetBitChange( int set_slot, int set_value, int get_slot, int get_value, bool on );
  323. Ogre::String ParseRelation( int relation, Ogre::String string1, Ogre::String string2 );
  324. Ogre::String PaddingString();
  325. Ogre::String ArgumentString( int script, int number );
  326. Ogre::String OffsetString( int val );
  327. bool TileCompare( const Tile& tile, const FieldKeyFrame& keyframe, MimFile& mim );
  328. void AddTile( const Tile& tile, MimFile& mim, Logger* export_text );
  329. AddedTile 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 );
  330. private:
  331. std::vector< int > m_Dialogs;
  332. static std::vector< Ogre::String > m_SoundOpcodes;
  333. std::vector< SurfaceTexData > m_Surfaces;
  334. Surface* full_image;
  335. int x_32;
  336. int y_32;
  337. int x_16;
  338. int y_16;
  339. int n_16;
  340. std::vector< AddedTile > m_AddedTiles;
  341. };
  342. #endif // DATFILE_H