Main.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #include <Ogre.h>
  2. #include "../../common/OgreBase.h"
  3. #include "../../common/Logger.h"
  4. #include "DatFile.h"
  5. #include "MimFile.h"
  6. std::vector< Field > fields;
  7. int state;
  8. void
  9. fill_names()
  10. {
  11. Ogre::ConfigFile cf;
  12. cf.load( "export.cfg" );
  13. Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
  14. while( seci.hasMoreElements() )
  15. {
  16. Field field;
  17. Ogre::String names = seci.peekNextKey();
  18. Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext();
  19. if( names == "" )
  20. {
  21. continue;
  22. }
  23. Ogre::StringVector name = Ogre::StringUtil::split( names, ":", 2 );
  24. if( name.size() < 3 )
  25. {
  26. LOGGER->Log( "In \"" + names + "\" not enough data. Must be 3.\n" );
  27. continue;
  28. }
  29. field.name = name[ 0 ];
  30. field.scale = Ogre::StringConverter::parseReal( name[ 2 ] );
  31. Ogre::StringVector tex_size = Ogre::StringUtil::split( name[ 1 ], "x", 1 );
  32. field.tex_width = Ogre::StringConverter::parseInt( tex_size[ 0 ] );
  33. field.tex_height = Ogre::StringConverter::parseInt( tex_size[ 1 ] );
  34. LOGGER->Log( "Export map \"" + field.name + "\" with tex_width=" + IntToString( field.tex_width ) + ", tex_height=" + IntToString( field.tex_height ) + ".\n" );
  35. Ogre::ConfigFile::SettingsMultiMap::iterator i;
  36. for( i = settings->begin(); i != settings->end(); ++i )
  37. {
  38. FiledAnimation animation;
  39. animation.name = i->first;
  40. Ogre::StringVector anim = Ogre::StringUtil::split( i->second, "|" );
  41. if( anim.size() < 1 )
  42. {
  43. LOGGER->Log( "In \"" + i->second + "\" not enough data separated by \"|\". Must be at least 1.\n" );
  44. continue;
  45. }
  46. float total_time = 0;
  47. LOGGER->Log( "Animation \"" + animation.name + "\" added.\n" );
  48. // go through all frames
  49. for( unsigned int j = 0; j < anim.size(); ++j )
  50. {
  51. Ogre::StringVector frame_data = Ogre::StringUtil::split( anim[ j ], ";", 2 );
  52. if( frame_data.size() < 2 )
  53. {
  54. total_time += Ogre::StringConverter::parseReal( anim[ j ] );
  55. LOGGER->Log( "In \"" + anim[ j ] + "\" not enough data separated by \";\". Must be more than 1. Insert pause this way.\n" );
  56. continue;
  57. }
  58. FieldKeyFrame frame;
  59. total_time += Ogre::StringConverter::parseReal( frame_data[ 0 ] );
  60. frame.time = total_time;
  61. for( unsigned int k = 1; k < frame_data.size(); ++k )
  62. {
  63. Ogre::StringVector frame_data_settings = Ogre::StringUtil::split( frame_data[ k ], "=", 1 );
  64. if( frame_data_settings.size() != 2 )
  65. {
  66. LOGGER->Log( "In \"" + frame_data[ k ] + "\" not enough data separated by \"=\". Must be 2.\n" );
  67. continue;
  68. }
  69. if( frame_data_settings[ 0 ] == "animation" )
  70. {
  71. Ogre::StringVector animation_settings = Ogre::StringUtil::split( frame_data_settings[ 1 ], " ", 1 );
  72. if( animation_settings.size() != 2 )
  73. {
  74. LOGGER->Log( "In \"" + frame_data_settings[ 1 ] + "\" not enough data separated by \" \". Must be 2.\n" );
  75. continue;
  76. }
  77. frame.animation_id = Ogre::StringConverter::parseInt( animation_settings[ 0 ] );
  78. if( animation_settings[ 1 ] == "blank" )
  79. {
  80. frame.blank = true;
  81. }
  82. else
  83. {
  84. frame.animation_frame = Ogre::StringConverter::parseInt( animation_settings[ 1 ] );
  85. }
  86. }
  87. else if( frame_data_settings[ 0 ] == "clut" )
  88. {
  89. Ogre::StringVector clut_total_settings = Ogre::StringUtil::split( frame_data_settings[ 1 ], ",", 1 );
  90. if( clut_total_settings.size() != 2 )
  91. {
  92. LOGGER->Log( "In \"" + frame_data_settings[ 1 ] + "\" not enough data separated by \",\". Must be 2.\n" );
  93. continue;
  94. }
  95. Ogre::StringVector clut_palette_settings = Ogre::StringUtil::split( clut_total_settings[ 0 ], " ", 2 );
  96. if( clut_palette_settings.size() != 3 )
  97. {
  98. LOGGER->Log( "In \"" + clut_total_settings[ 0 ] + "\" not enough data separated by \" \". Must be 3.\n" );
  99. continue;
  100. }
  101. frame.clut_y = Ogre::StringConverter::parseInt( clut_palette_settings[ 0 ] ) + 0x1e0;
  102. frame.clut_start = Ogre::StringConverter::parseInt( clut_palette_settings[ 1 ] );
  103. frame.clut_width = Ogre::StringConverter::parseInt( clut_palette_settings[ 2 ] );
  104. Ogre::StringVector clut_mod_settings = Ogre::StringUtil::split( clut_total_settings[ 1 ], ":", 1 );
  105. if( clut_mod_settings.size() != 2 )
  106. {
  107. LOGGER->Log( "In \"" + clut_total_settings[ 1 ] + "\" not enough data separated by \":\". Must be 2.\n" );
  108. continue;
  109. }
  110. frame.mod_type = clut_mod_settings[ 0 ];
  111. Ogre::Vector3 rgb = Ogre::StringConverter::parseVector3( clut_mod_settings[ 1 ] );
  112. frame.mod_r = rgb.x;
  113. frame.mod_g = rgb.y;
  114. frame.mod_b = rgb.z;
  115. }
  116. else
  117. {
  118. LOGGER->Log( "Unknown animation type \"" + frame_data_settings[ 0 ] + "\".\n");
  119. continue;
  120. }
  121. }
  122. animation.keyframes.push_back( frame );
  123. LOGGER->Log( "Keyframe added at time \"" + FloatToString( frame.time ) + "\". Settings blank=\"" + BoolToString( frame.blank ) + "\", animation_id=\"" + IntToString( frame.animation_id ) + "\", animation_frame=\"" + IntToString( frame.animation_frame ) + "\" clut_y=\"" + IntToString( frame.clut_y ) + "\", clut_start=\"" + IntToString( frame.clut_start ) + "\", clut_width=\"" + IntToString( frame.clut_width ) + "\", mod_type=\"" + frame.mod_type + "\", mod_r=\"" + FloatToString( frame.mod_r ) + "\", mod_g=\"" + FloatToString( frame.mod_g ) + "\", mod_b=\"" + FloatToString( frame.mod_b ) + "\".\n" );
  124. }
  125. animation.time = total_time;
  126. field.animations.push_back( animation );
  127. }
  128. fields.push_back( field );
  129. }
  130. }
  131. int
  132. main( int argc, char *argv[] )
  133. {
  134. InitializeOgreBase( "FFVII Field Dat Exporter" );
  135. fill_names();
  136. Field f = {};
  137. f.name = "C:\\Users\\paul\\Downloads\\data\\data\\en\\nmkin_1";
  138. fields.push_back(f);
  139. /*
  140. for (int f = 0; f < fields.size(); ++f)
  141. {
  142. DatFile dat("data/jp/" + fields[f].name + ".dat");
  143. dat.DumpScriptData("export_jp/" + fields[f].name + "_script.txt");
  144. dat.DumpTextData("export_jp/" + fields[f].name + "_text.txt", false);
  145. dat.DumpWalkmeshData("export_jp/" + fields[f].name + "_wm.xml");
  146. }
  147. for (int f = 0; f < fields.size(); ++f)
  148. {
  149. DatFile dat("data/jp_in/" + fields[f].name + ".dat");
  150. dat.DumpScriptData("export_jp_in/" + fields[f].name + "_script.txt");
  151. dat.DumpTextData("export_jp_in/" + fields[f].name + "_text.txt", false);
  152. dat.DumpWalkmeshData("export_jp_in/" + fields[f].name + "_wm.xml");
  153. }
  154. */
  155. for (unsigned int f = 0; f < fields.size(); ++f)
  156. {
  157. DatFile dat( fields[ f ].name + ".dat" );
  158. MimFile mim( fields[ f ].name + ".mim" );
  159. dat.DumpScript( "export_en/", fields[ f ] );
  160. dat.DumpText( "export_en/", fields[ f ], true );
  161. dat.DumpTriggersMovements( "export_en/", fields[ f ] );
  162. dat.DumpWalkmesh( "export_en/", fields[ f ] );
  163. dat.DumpBackground( "export_en/", fields[ f ], mim );
  164. }
  165. //DatFile::DumpSoundOpcodesData("sound.txt");
  166. DeinitializeOgreBase();
  167. return 0;
  168. }