private void exportBtn_Click(object sender, EventArgs e) { SaveFileDialog ef = new SaveFileDialog(); ef.Title = rm.GetString("exportModelBld"); ef.Filter = rm.GetString("modelFile"); if (ef.ShowDialog() == DialogResult.OK) { if (ef.FileName.EndsWith(".obj")) { try { NsbmdGlRenderer rendererOBJ = new NsbmdGlRenderer { Model = _nsbmd.models[0] }; rendererOBJ.RipModel(ef.FileName); } catch { MessageBox.Show(rm.GetString("invalidFile"), null, MessageBoxButtons.OK, MessageBoxIcon.Stop); } return; } File.Copy(bldPath + "\\" + listBox1.SelectedIndex.ToString("D4"), ef.FileName, true); } return; }
private void exportBtn_Click(object sender, EventArgs e) // Export model { SaveFileDialog ef = new SaveFileDialog(); ef.Title = rm.GetString("exportModelBld"); ef.Filter = rm.GetString("modelFile"); if (ef.ShowDialog() == DialogResult.OK) { if (ef.FileName.EndsWith(".obj")) { try { NsbmdGlRenderer rendererOBJ = new NsbmdGlRenderer { Model = _nsbmd.models[0] }; rendererOBJ.RipModel(ef.FileName); } catch { MessageBox.Show(rm.GetString("invalidFile"), null, MessageBoxButtons.OK, MessageBoxIcon.Stop); } return; } BinaryWriter export = new BinaryWriter(File.Create(ef.FileName)); BinaryReader read = new BinaryReader(File.OpenRead(bldPath + "\\" + "model" + "\\" + listBox1.SelectedIndex.ToString("D4"))); for (int i = 0; i < 0xe; i++) { export.Write(read.ReadByte()); // Reads header bytes and writes them to file } export.Write((Int16)0x0002); // Writes texture flag export.Write((Int16)0x0018); export.Write((Int16)0x0); export.Write(0x0); // Writes blank BTX offset read.BaseStream.Position += 0x6; for (int i = 0; i < read.BaseStream.Length - 0x14; i++) { export.Write(read.ReadByte()); // Writes model section } read.Close(); string tex; if (!checkBox1.Checked) { tex = Form1.workingFolder + @"data\a\1\7\bldtilesets" + "\\" + comboBox1.SelectedIndex.ToString("D4"); } else { tex = Form1.workingFolder + @"data\a\1\7\bld2tilesets" + "\\" + comboBox1.SelectedIndex.ToString("D4"); } System.IO.BinaryReader readTex = new System.IO.BinaryReader(File.OpenRead(tex)); long texLength = readTex.BaseStream.Length - 0x14; readTex.BaseStream.Position = 0x14; long texOffset = export.BaseStream.Position; for (int i = 0; i < texLength; i++) { export.Write(readTex.ReadByte()); // Writes BTX section } export.BaseStream.Position = 0x8; export.Write((int)(new FileInfo(bldPath + "\\" + "model" + "\\" + listBox1.SelectedIndex.ToString("D4")).Length + 0x4 + texLength)); export.BaseStream.Position = 0x14; export.Write((int)texOffset); export.Close(); readTex.Close(); } return; }