home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 5257 / source.7z / ps3_gundam_crossfire.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2012-01-24  |  21.8 KB  |  666 lines

  1. #include "xentax.h"
  2. #include "ps3_gundam_crossfire.h"
  3.  
  4. namespace PS3 { namespace GundamCrossfire {
  5.  
  6.  class extractor {
  7.   private :
  8.    std::string pathname;
  9.   private :
  10.    bool processTSB(const char* filename);
  11.    bool processBOB(const char* filename);
  12.    bool processMRG(const char* filename);
  13.   public :
  14.    bool extract(void);
  15.   public :
  16.    extractor(const char* pn);
  17.   ~extractor();
  18.  };
  19.  
  20. };};
  21.  
  22. namespace PS3 { namespace GundamCrossfire {
  23.  
  24.  extractor::extractor(const char* pn) : pathname(pn)
  25.  {
  26.  }
  27.  
  28.  extractor::~extractor()
  29.  {
  30.  }
  31.  
  32.  bool extractor::extract(void)
  33.  {
  34.   // process TSB files
  35.   if(false) {
  36.      std::deque<std::string> tsblist;
  37.      BuildFilenameList(tsblist, "tsb", pathname.c_str());
  38.      for(size_t i = 0; i < tsblist.size(); i++) {
  39.          cout << "Processing file " << (i + 1) << " of " << tsblist.size() << ": " << tsblist[i] << "." << endl;
  40.          if(!processTSB(tsblist[i].c_str())) return false;
  41.         }
  42.      cout << endl;
  43.     }
  44.  
  45.   // process BOB files
  46.   if(false) {
  47.      std::deque<std::string> boblist;
  48.      BuildFilenameList(boblist, "bob", pathname.c_str());
  49.      for(size_t i = 0; i < boblist.size(); i++) {
  50.          cout << "Processing file " << (i + 1) << " of " << boblist.size() << ": " << boblist[i] << "." << endl;
  51.          if(!processBOB(boblist[i].c_str())) return false;
  52.         }
  53.      cout << endl;
  54.     }
  55.  
  56.   // process MRG files
  57.   if(true) {
  58.      std::deque<std::string> mrglist;
  59.      BuildFilenameList(mrglist, "mrg", pathname.c_str());
  60.      for(size_t i = 0; i < mrglist.size(); i++) {
  61.          cout << "Processing file " << (i + 1) << " of " << mrglist.size() << ": " << mrglist[i] << "." << endl;
  62.          if(!processMRG(mrglist[i].c_str())) return false;
  63.         }
  64.      cout << endl;
  65.     }
  66.  
  67.   return true;
  68.  }
  69.  
  70.  bool extractor::processTSB(const char* filename)
  71.  {
  72.   // open file
  73.   ifstream ifile(filename, ios::binary);
  74.   if(!ifile) return error("Failed to open file.");
  75.  
  76.   // compute filesize
  77.   ifile.seekg(0, ios::end);
  78.   uint32 filesize = (uint32)ifile.tellg();
  79.   ifile.seekg(0, ios::beg);
  80.  
  81.   // read magic
  82.   uint32 magic = BE_read_uint32(ifile);
  83.   if(magic != 0x54455820) return error("Invalid TSB magic number.");
  84.  
  85.   uint16 unk01 = BE_read_uint16(ifile);
  86.  
  87.   // read number of textures
  88.   uint16 n_textures = BE_read_uint16(ifile);
  89.   if(!n_textures) return error("Unexpected number of textures.");
  90.  
  91.   uint32 start = BE_read_uint32(ifile); // start offset
  92.  
  93.   // read string
  94.   char buffer[17];
  95.   BE_read_array(ifile, &buffer[0], 16);
  96.   buffer[16] = '\0';
  97.   if(ifile.fail()) return error("Read failure.");
  98.   if(strcmpi(buffer, "BandaiPS3Project") != 0) return error("Expecting BandaiPS3Project.");
  99.  
  100.   // read file name offsets
  101.   deque<size_t> fno;
  102.   for(uint32 i = 0; i < n_textures; i++) {
  103.       uint32 temp1 = BE_read_uint16(ifile);
  104.       uint32 temp2 = BE_read_uint16(ifile);
  105.       uint32 temp3 = BE_read_uint16(ifile);
  106.       uint32 temp4 = BE_read_uint16(ifile);
  107.       if(ifile.fail()) return error("Read failure.");
  108.       fno.push_back(temp1);
  109.      }
  110.  
  111.   // read filenames
  112.   deque<string> ddslist;
  113.   for(uint32 i = 0; i < n_textures; i++)
  114.      {
  115.       // move to filename offset
  116.       ifile.seekg(fno[i]);
  117.       if(ifile.fail()) return error("Seek failure.");
  118.  
  119.       // read filename
  120.       char buffer[1024];
  121.       if(!read_string(ifile, buffer, 1024)) return error("Read failure.");
  122.  
  123.       // create directory to store dds files
  124.       std::string path = GetPathnameFromFilename(filename);
  125.       std::string shortname = GetShortFilenameWithoutExtension(filename);
  126.       stringstream ss;
  127.       ss << path << shortname << "\\";
  128.       CreateDirectoryA(ss.str().c_str(), NULL);
  129.  
  130.       // build texture filename
  131.       ss << buffer << ".dds";
  132.       ddslist.push_back(ss.str());
  133.      }
  134.  
  135.   // move to start of offset data
  136.   ifile.seekg(start);
  137.   if(ifile.fail()) return error("Seek failure.");
  138.  
  139.   // for each texture, save offset to data
  140.   deque<size_t> offsetlist;
  141.   for(uint32 i = 0; i < n_textures; i++) {
  142.       uint32 temp = BE_read_uint32(ifile);
  143.       if(ifile.fail()) return error("Read failure.");
  144.       offsetlist.push_back(temp);
  145.      }
  146.  
  147.   // save textures
  148.   for(uint32 i = 0; i < n_textures; i++)
  149.      {
  150.       // move to offset
  151.       ifile.seekg(offsetlist[i]);
  152.       if(ifile.fail()) return error("Seek failure.");
  153.  
  154.       // compute how much to read
  155.       uint32 datasize = 0;
  156.       if(i < (uint32)(n_textures - 1)) datasize = offsetlist[i + 1] - offsetlist[i];
  157.       else datasize = filesize - offsetlist[i];
  158.  
  159.       // read data
  160.       boost::shared_array<char> data(new char[datasize]);
  161.       BE_read_array(ifile, data.get(), datasize);
  162.  
  163.       // save data
  164.       ofstream ofile(ddslist[i].c_str(), ios::binary);
  165.       if(!ofile) return error("Failed to create file.");
  166.       ofile.write(data.get(), datasize);
  167.      }
  168.  
  169.   return true;
  170.  }
  171.  
  172.  bool extractor::processBOB(const char* filename)
  173.  {
  174.   // open file
  175.   ifstream ifile(filename, ios::binary);
  176.   if(!ifile) return error("Failed to open file.");
  177.  
  178.   // compute filesize
  179.   ifile.seekg(0, ios::end);
  180.   uint32 filesize = (uint32)ifile.tellg();
  181.   ifile.seekg(0, ios::beg);
  182.  
  183.   // read magic
  184.   uint32 magic = BE_read_uint32(ifile);
  185.   if(magic != 0x56424F20) return error("Invalid BOB magic number.");
  186.  
  187.   // read version
  188.   uint32 vers = BE_read_uint16(ifile);
  189.   if(vers != 0x0B) return error("Invalid BOB version.");
  190.  
  191.   // read 0x0100
  192.   uint32 unk01 = BE_read_uint16(ifile);
  193.   if(unk01 != 0x0100) return error("Expecting 0x0100.");
  194.  
  195.   // read surfaces
  196.   uint32 n_surfaces = BE_read_uint32(ifile);
  197.   if(n_surfaces == 0 || n_surfaces > 1000) return error("Unexpected number of surfaces.");
  198.  
  199.   // read surface offsets
  200.   deque<size_t> offsets;
  201.   for(size_t i = 0; i < n_surfaces; i++) {
  202.       uint32 temp = BE_read_uint32(ifile);
  203.       if(ifile.fail()) return error("Read failure.");
  204.       offsets.push_back(temp);
  205.      }
  206.  
  207.   // setup installation directory
  208.   char modelname[1024];
  209.   if(!read_string(ifile, modelname, 1024)) return error("Read failure.");
  210.   std::string modelpath = GetPathnameFromFilename(filename);
  211.   modelpath += modelname;
  212.   modelpath += "\\";
  213.   CreateDirectoryA(modelpath.c_str(), NULL);
  214.  
  215.   // buffer container
  216.   deque<VERTEX_BUFFER> vblist;
  217.   deque<INDEX_BUFFER> iblist;
  218.  
  219.   // read surfaces
  220.   for(size_t i = 0; i < n_surfaces; i++)
  221.      {
  222.       // create surfacename
  223.       stringstream ss;
  224.       ss << "surface_" << setfill('0') << setw(3) << i;
  225.       string surfacename = ss.str();
  226.  
  227.       // seek position
  228.       uint32 position = offsets[i];
  229.       ifile.seekg(position);
  230.       if(ifile.fail()) return error("Seek failure.");
  231.  
  232.       // read vertex buffer size
  233.       uint32 vbuffersize = BE_read_uint32(ifile);
  234.       if(ifile.fail()) return error("Read failure.");
  235.       if(!vbuffersize) return error("Unexpected vertex buffer size.");
  236.  
  237.       // read vertex buffer
  238.       boost::shared_array<char> vbuffer(new char[vbuffersize]);
  239.       ifile.read(vbuffer.get(), vbuffersize);
  240.       if(ifile.fail()) return error("Read failure.");
  241.  
  242.       // read index buffer parameter #1
  243.       uint32 ibuffersize = BE_read_uint32(ifile);
  244.       if(ifile.fail()) return error("Read failure.");
  245.       if(!ibuffersize) return error("Unexpected index buffer size.");
  246.  
  247.       // read index buffer parameter #2
  248.       uint32 iunknown = BE_read_uint32(ifile);
  249.       if(ifile.fail()) return error("Read failure.");
  250.  
  251.       // read index buffer
  252.       boost::shared_array<uint16> ibuffer(new uint16[ibuffersize/2]);
  253.       BE_read_array(ifile, ibuffer.get(), ibuffersize/2);
  254.       if(ifile.fail()) return error("Read failure.");
  255.  
  256.       // compute maximum index
  257.       uint16 max_index = 0;
  258.       maximum(ibuffer.get(), ibuffersize/2, max_index);
  259.       if(!max_index) return error("Unexpected maximum index.");
  260.  
  261.       // compute vertex size
  262.       uint32 vertexsize = vbuffersize/(max_index + 1);
  263.       if(!vertexsize) return error("Unexpected number of vertices.");
  264.  
  265.       // compute number of vertices
  266.       uint32 n_vertices = vbuffersize/vertexsize;
  267.       if(!n_vertices) return error("Unexpected number of vertices.");
  268.       cout << "vertices = " << n_vertices << ", " << "vertexsize = " << vertexsize << endl;
  269.  
  270.       // prepare vertex buffer
  271.       VERTEX_BUFFER vb;
  272.       vb.flags = VERTEX_POSITION | VERTEX_UV;
  273.       vb.elem = n_vertices;
  274.       vb.data.reset(new VERTEX[n_vertices]);
  275.  
  276.       // prepare index buffer
  277.       INDEX_BUFFER ib;
  278.       ib.format = FACE_FORMAT_UINT_16;
  279.       ib.type = FACE_TYPE_TRISTRIP;
  280.       ib.name = surfacename;
  281.       ib.reference = i;
  282.       ib.elem = ibuffersize/2;
  283.       ib.data.reset(new char[ibuffersize]);
  284.       memmove(ib.data.get(), ibuffer.get(), ibuffersize);
  285.  
  286.       // initialize vstream
  287.       binary_stream vstream(vbuffer, vbuffersize);
  288.       vstream.seek(0);
  289.  
  290.       // process vertices
  291.       if(vertexsize == 12)
  292.         {
  293.          // ??? mtp.bob
  294.          for(size_t j = 0; j < n_vertices; j++) {
  295.              float p01 = vstream.BE_read_float16(); // 2
  296.              float p02 = vstream.BE_read_float16(); // 4
  297.              float p03 = vstream.BE_read_float16(); // 6
  298.              float p04 = vstream.BE_read_float16(); // 8
  299.              float p05 = vstream.BE_read_float16(); // 10
  300.              float p06 = vstream.BE_read_float16(); // 12
  301.              vb.data[j].vx =  p01;
  302.              vb.data[j].vy =  p02;
  303.              vb.data[j].vz =  p03;
  304.              vb.data[j].tu =  p05;
  305.              vb.data[j].tv = -p06;
  306.             }
  307.         }
  308.       else if(vertexsize == 16)
  309.         {
  310.          // works good
  311.          for(size_t j = 0; j < n_vertices; j++) {
  312.              float p01 = vstream.BE_read_float16(); // 2
  313.              float p02 = vstream.BE_read_float16(); // 4
  314.              float p03 = vstream.BE_read_float16(); // 6
  315.              float p04 = vstream.BE_read_float16(); // 8
  316.              float p05 = vstream.BE_read_float16(); // 10
  317.              float p06 = vstream.BE_read_float16(); // 12
  318.              float p07 = vstream.BE_read_float16(); // 14
  319.              float p08 = vstream.BE_read_float16(); // 16
  320.              vb.data[j].vx =  p01;
  321.              vb.data[j].vy =  p02;
  322.              vb.data[j].vz =  p03;
  323.              vb.data[j].tu =  p07;
  324.              vb.data[j].tv = -p08;
  325.             }
  326.         }
  327.       else if(vertexsize == 20)
  328.         {
  329.          // works good
  330.          for(size_t j = 0; j < n_vertices; j++) {
  331.              float p01 = vstream.BE_read_float16(); // 2
  332.              float p02 = vstream.BE_read_float16(); // 4
  333.              float p03 = vstream.BE_read_float16(); // 6
  334.              float p04 = vstream.BE_read_float16(); // 8
  335.              float p05 = vstream.BE_read_float16(); // 10
  336.              float p06 = vstream.BE_read_float16(); // 12
  337.              float p07 = vstream.BE_read_float16(); // 14
  338.              float p08 = vstream.BE_read_float16(); // 16
  339.              float p09 = vstream.BE_read_float16(); // 18
  340.              float p10 = vstream.BE_read_float16(); // 20
  341.              vb.data[j].vx =  p01;
  342.              vb.data[j].vy =  p02;
  343.              vb.data[j].vz =  p03;
  344.              vb.data[j].tu =  p09;
  345.              vb.data[j].tv = -p10;
  346.             }
  347.         }
  348.       else if(vertexsize == 24)
  349.         {
  350.          for(size_t j = 0; j < n_vertices; j++) {
  351.              float p01 = vstream.BE_read_float16(); // 2
  352.              float p02 = vstream.BE_read_float16(); // 4
  353.              float p03 = vstream.BE_read_float16(); // 6
  354.              float p04 = vstream.BE_read_float16(); // 8
  355.              float p05 = vstream.BE_read_float16(); // 10
  356.              float p06 = vstream.BE_read_float16(); // 12
  357.              float p07 = vstream.BE_read_float16(); // 14
  358.              float p08 = vstream.BE_read_float16(); // 16
  359.              float p09 = vstream.BE_read_float16(); // 18
  360.              float p10 = vstream.BE_read_float16(); // 20
  361.              float p11 = vstream.BE_read_float16(); // 22
  362.              float p12 = vstream.BE_read_float16(); // 24
  363.              vb.data[j].vx = p01;
  364.              vb.data[j].vy = p02;
  365.              vb.data[j].vz = p03;
  366.              vb.data[j].tu = p11;
  367.              vb.data[j].tv = -p12;
  368.              //cout << p01 << endl;
  369.              //cout << p02 << endl;
  370.              //cout << p03 << endl;
  371.              //cout << p04 << endl;
  372.              //cout << p05 << endl;
  373.              //cout << p06 << endl;
  374.              //cout << p07 << endl;
  375.              //cout << p08 << endl;
  376.              //cout << p09 << endl;
  377.              //cout << p10 << endl;
  378.              //cout << p11 << endl;
  379.              //cout << p12 << endl;
  380.              //cout << endl;
  381.             }
  382.         }
  383.       else if(vertexsize == 26)
  384.         {
  385.          // works good
  386.          for(size_t j = 0; j < n_vertices; j++) {
  387.              vb.data[j].vx = vstream.BE_read_float16(); // 2
  388.              vb.data[j].vy = vstream.BE_read_float16(); // 4
  389.              vb.data[j].vz = vstream.BE_read_float16(); // 6
  390.              vstream.BE_read_float16(); // 8
  391.              vstream.BE_read_float16(); // 10
  392.              vstream.BE_read_float16(); // 12
  393.              vb.data[j].tu =  vstream.BE_read_float16(); // 14
  394.              vb.data[j].tv = -vstream.BE_read_float16(); // 16
  395.              vstream.BE_read_float16(); // 18
  396.              vstream.BE_read_float16(); // 20
  397.              vstream.BE_read_float16(); // 22
  398.              vstream.BE_read_float16(); // 24
  399.              vstream.BE_read_float16(); // 26
  400.             }
  401.         }
  402.       else if(vertexsize == 30)
  403.         {
  404.          // ???
  405.          for(size_t j = 0; j < n_vertices; j++) {
  406.              float p01 = vstream.BE_read_float16(); //  2
  407.              float p02 = vstream.BE_read_float16(); //  4
  408.              float p03 = vstream.BE_read_float16(); //  6
  409.              float p04 = vstream.BE_read_float16(); //  8
  410.              float p05 = vstream.BE_read_float16(); // 10
  411.              float p06 = vstream.BE_read_float16(); // 12
  412.              float p07 = vstream.BE_read_float16(); // 14
  413.              float p08 = vstream.BE_read_float16(); // 16
  414.              float p09 = vstream.BE_read_float16(); // 18
  415.              float p10 = vstream.BE_read_float16(); // 20
  416.              float p11 = vstream.BE_read_float16(); // 22
  417.              float p12 = vstream.BE_read_float16(); // 24
  418.              float p13 = vstream.BE_read_float16(); // 26
  419.              float p14 = vstream.BE_read_float16(); // 28
  420.              float p15 = vstream.BE_read_float16(); // 30
  421.              vb.data[j].vx =  p01;
  422.              vb.data[j].vy =  p02;
  423.              vb.data[j].vz =  p03;
  424.              vb.data[j].tu =  p11;
  425.              vb.data[j].tv = -p12;
  426.              //cout << p01 << endl;
  427.              //cout << p02 << endl;
  428.              //cout << p03 << endl;
  429.              //cout << p04 << endl;
  430.              //cout << p05 << endl;
  431.              //cout << p06 << endl;
  432.              //cout << p07 << endl;
  433.              //cout << p08 << endl;
  434.              //cout << p09 << endl;
  435.              //cout << p10 << endl;
  436.              //cout << p11 << endl;
  437.              //cout << p12 << endl;
  438.              //cout << p13 << endl;
  439.              //cout << p14 << endl;
  440.              //cout << p15 << endl;
  441.              //cout << endl;
  442.             }
  443.         }
  444.       else if(vertexsize == 34)
  445.         {
  446.          // works good
  447.          for(size_t j = 0; j < n_vertices; j++) {
  448.              float p01 = vstream.BE_read_float16(); //  2
  449.              float p02 = vstream.BE_read_float16(); //  4
  450.              float p03 = vstream.BE_read_float16(); //  6
  451.              float p04 = vstream.BE_read_float16(); //  8
  452.              float p05 = vstream.BE_read_float16(); // 10
  453.              float p06 = vstream.BE_read_float16(); // 12
  454.              float p07 = vstream.BE_read_float16(); // 14
  455.              float p08 = vstream.BE_read_float16(); // 16
  456.              float p09 = vstream.BE_read_float16(); // 18
  457.              float p10 = vstream.BE_read_float16(); // 20
  458.              float p11 = vstream.BE_read_float16(); // 22
  459.              float p12 = vstream.BE_read_float16(); // 24
  460.              float p13 = vstream.BE_read_float16(); // 26
  461.              float p14 = vstream.BE_read_float16(); // 28
  462.              float p15 = vstream.BE_read_float16(); // 30
  463.              float p16 = vstream.BE_read_float16(); // 32
  464.              float p17 = vstream.BE_read_float16(); // 34
  465.              vb.data[j].vx = p01;
  466.              vb.data[j].vy = p02;
  467.              vb.data[j].vz = p03;
  468.              vb.data[j].tu = p13;
  469.              vb.data[j].tv = -p14;
  470.              // cout << p01 << endl;
  471.              // cout << p02 << endl;
  472.              // cout << p03 << endl;
  473.              // cout << p04 << endl;
  474.              // cout << p05 << endl;
  475.              // cout << p06 << endl;
  476.              // cout << p07 << endl;
  477.              // cout << p08 << endl;
  478.              // cout << p09 << endl;
  479.              // cout << p10 << endl;
  480.              // cout << p11 << endl;
  481.              // cout << p12 << endl;
  482.              // cout << p13 << endl;
  483.              // cout << p14 << endl;
  484.              // cout << p15 << endl;
  485.              // cout << p16 << endl;
  486.              // cout << p17 << endl;
  487.              // cout << endl;
  488.             }
  489.         }
  490.       else {
  491.          cout << "vertexsize = " << vertexsize << endl;
  492.          return error("Unknown vertex format.");
  493.         }
  494.  
  495.       // insert buffers
  496.       vblist.push_back(vb);
  497.       iblist.push_back(ib);
  498.      }
  499.  
  500.   // save OBJ file
  501.   GeometryToOBJ(modelpath.c_str(), modelname, vblist, iblist);
  502.   return true;
  503.  }
  504.  
  505. bool extractor::processMRG(const char* filename)
  506. {
  507.  // open file
  508.  ifstream ifile(filename, ios::binary);
  509.  if(!ifile) return error("Failed to open file.");
  510.  
  511.  // compute filesize
  512.  ifile.seekg(0, ios::end);
  513.  uint32 filesize = (uint32)ifile.tellg();
  514.  ifile.seekg(0, ios::beg);
  515.  
  516.  // read magic
  517.  uint32 magic = BE_read_uint32(ifile);
  518.  if(magic != 0x4D524700) return error("Invalid MRG magic number.");
  519.  
  520.  // read filesize
  521.  uint32 filesize_actual = BE_read_uint32(ifile);
  522.  
  523.  // read number of sections
  524.  uint32 n_sections = BE_read_uint32(ifile);
  525.  if(!n_sections) return error("Unexpected number of MRG sections.");
  526.  
  527.  // read section table
  528.  deque<uint32> sections;
  529.  for(uint32 i = 0; i < n_sections; i++) {
  530.      sections.push_back(BE_read_uint32(ifile));
  531.      if(ifile.fail()) return error("Read failure.");
  532.     }
  533.  
  534.  // read unknown offset
  535.  uint32 unk_offset = BE_read_uint32(ifile);
  536.  if(ifile.fail()) return error("Read failure.");
  537.  
  538.  // setup installation directory
  539.  std::string shortname = GetShortFilenameWithoutExtension(filename);
  540.  std::string datapath = GetPathnameFromFilename(filename);
  541.  datapath += shortname;
  542.  datapath += "\\";
  543.  CreateDirectoryA(datapath.c_str(), NULL);
  544.  
  545.  // process sections
  546.  for(size_t i = 0; i < sections.size(); i++)
  547.     {
  548.      // move to section
  549.      ifile.seekg(sections[i]);
  550.      if(ifile.fail()) return error("Seek failure.");
  551.  
  552.      // how much to read
  553.      uint32 datasize = 0;
  554.      if(i == sections.size() - 1) datasize = filesize - sections[i];
  555.      else datasize = sections[i + 1] - sections[i];
  556.  
  557.      // read data
  558.      boost::shared_array<char> data(new char[datasize]);
  559.      ifile.read(data.get(), datasize);
  560.  
  561.      // read type
  562.      binary_stream bs(data, datasize);
  563.      uint32 type = bs.BE_read_uint32();
  564.  
  565.      // DDS
  566.      if(type == 0x44445320) {
  567.         stringstream ss;
  568.         ss << datapath << setfill('0') << setw(3) << i << ".dds";
  569.         ofstream ofile(ss.str(), ios::binary);
  570.         ofile.write(data.get(), datasize);
  571.        }
  572.      // VBO
  573.      else if(type == 0x56424F20) {
  574.         stringstream ss;
  575.         ss << datapath << setfill('0') << setw(3) << i << ".bob";
  576.         ofstream ofile(ss.str(), ios::binary);
  577.         ofile.write(data.get(), datasize);
  578.        }
  579.      // TEX
  580.      else if(type == 0x54455820) {
  581.         stringstream ss;
  582.         ss << datapath << setfill('0') << setw(3) << i << ".tsb";
  583.         ofstream ofile(ss.str(), ios::binary);
  584.         ofile.write(data.get(), datasize);
  585.        }
  586.      // PS3
  587.      else if(type == 0x50533320) {
  588.         stringstream ss;
  589.         ss << datapath << setfill('0') << setw(3) << i << ".ps3";
  590.         ofstream ofile(ss.str(), ios::binary);
  591.         ofile.write(data.get(), datasize);
  592.        }
  593.      // nested mrg file
  594.      else if(type == 0x4D524700) {
  595.         stringstream ss;
  596.         ss << datapath << setfill('0') << setw(3) << i << ".mrg";
  597.         ofstream ofile(ss.str(), ios::binary);
  598.         ofile.write(data.get(), datasize);
  599.        }
  600.      // dummy
  601.      else if(type == 0x64756D6D) {
  602.        }
  603.      // 0
  604.      else if(type == 0x0) { // usually at beginning before TEX
  605.        }
  606.      // 1
  607.      else if(type == 0x1) { // usually at beginning before TEX
  608.        }
  609.      // crap
  610.      else if(type == 0x2) {
  611.        }
  612.      // crap
  613.      else if(type == 0x64 || type == 0x1E9) {
  614.        }
  615.      // crap
  616.      else if(type == 0x10205800) {
  617.        }
  618.      // crap
  619.      else if(type >= 0x2D2D0000 && type <= 0x2D2DFFFF) { // from lua scripting
  620.        }
  621.      // crap
  622.      else if(type == 0x406C6973) { // @list
  623.        }
  624.      // crap
  625.      else if(type == 0x826C8268) {
  626.        }
  627.      // crap
  628.      else if(type == 0x82718264) {
  629.        }
  630.      // crap
  631.      else if(type == 0x8EAF95CA) {
  632.        }
  633.      // crap
  634.      else if(type >= 0xC1100000 || type <= 0xC1C80000) {
  635.        }
  636.      // crap
  637.      else if(type == 0xFFFFFFFF) {
  638.        }
  639.      else {
  640.         cout << "offset = " << sections[i] << endl;
  641.         stringstream ss;
  642.         ss << "Unknown type: " << type << ".";
  643.         return error(ss.str().c_str());
  644.        }
  645.     }
  646.  
  647.  return true;
  648. }
  649.  
  650. };}; // PS3::GundamCrossfire
  651.  
  652. namespace PS3 { namespace GundamCrossfire {
  653.  
  654. bool extract(void)
  655. {
  656.  char pathname[MAX_PATH];
  657.  GetModulePathname(pathname, MAX_PATH);
  658.  return extract(pathname);
  659. }
  660.  
  661. bool extract(const char* pathname)
  662. {
  663.  return extractor(pathname).extract();
  664. }
  665.  
  666. };}; // PS3::GundamCrossfire