private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     var fileStream = new FileStream(bldPath + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open);
     file_2 = bldPath + "\\" + listBox1.SelectedIndex.ToString("D4");
     _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
     #region Create texture
     File.Create(Path.GetTempPath() + "BLDtexture.nsbtx").Close();
     BinaryWriter writeBLDtexture = new BinaryWriter(File.OpenWrite(Path.GetTempPath() + "BLDtexture.nsbtx"));
     writeBLDtexture.Write((UInt32)0x30585442);
     writeBLDtexture.Write((UInt32)0x0001FEFF);
     fileStream.Position = 0x8;
     int nsbmdSize = fileStream.ReadByte() + (fileStream.ReadByte() << 8) + (fileStream.ReadByte() << 16) + (fileStream.ReadByte() << 24);
     fileStream.Position = 0x14;
     int nsbmdTexOffset = fileStream.ReadByte() + (fileStream.ReadByte() << 8) + (fileStream.ReadByte() << 16) + (fileStream.ReadByte() << 24);
     int texSize = nsbmdSize - nsbmdTexOffset + 0x14;
     writeBLDtexture.Write((UInt32)texSize);
     writeBLDtexture.Write((UInt32)0x00010010);
     writeBLDtexture.Write((UInt32)0x00000014);
     fileStream.Position = nsbmdTexOffset;
     for (int i = 0; i < texSize - 0x14; i++)
     {
         writeBLDtexture.Write((byte)fileStream.ReadByte());
     }
     fileStream.Close();
     writeBLDtexture.Close();
     _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Path.GetTempPath() + "BLDtexture.nsbtx")), out _nsbmd.Textures, out _nsbmd.Palettes);
     #endregion
     try
     {
         _nsbmd.MatchTextures();
     }
     catch { }
     RenderBuilding(null, null);
     comboBox1.SelectedIndex = 0;
 }
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     renderer.ClearOBJ();
     if (comboBox1.SelectedIndex == 0)
     {
         var fileStream = new FileStream(bldPath + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open);
         file_2 = bldPath + "\\" + listBox1.SelectedIndex.ToString("D4");
         _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
         fileStream.Close();
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Path.GetTempPath() + "BLDtexture.nsbtx")), out _nsbmd.Textures, out _nsbmd.Palettes);
         try
         {
             _nsbmd.MatchTextures();
         }
         catch { }
         simpleOpenGlControl1.Invalidate();
         RenderBuilding(null, null);
     }
     else
     {
         _nsbmd.models[0].Palettes.Clear();
         _nsbmd.models[0].Textures.Clear();
         var fileStream = new FileStream(bldPath + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open);
         file_2 = bldPath + "\\" + listBox1.SelectedIndex.ToString("D4");
         _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
         fileStream.Close();
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(editorTileset + "\\" + (comboBox1.SelectedIndex - 1).ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes);
         try
         {
             _nsbmd.MatchTextures();
         }
         catch { }
         simpleOpenGlControl1.Invalidate();
         RenderBuilding(null, null);
     }
 }
 // Select Tileset
 private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
 {
     renderer.ClearOBJ();
     if (comboBox7.SelectedIndex == 0)
     {
         Gl.glDisable(Gl.GL_TEXTURE_2D);
         var fileStream = new FileStream(Path.GetTempPath() + "map.nsbmd", FileMode.Open);
         file_2 = Path.GetTempPath() + "map.nsbmd";
         _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
         fileStream.Close();
         simpleOpenGlControl2.Invalidate();
         button20_Click(null, null);
     }
     else
     {
         _nsbmd.models[0].Palettes.Clear();
         _nsbmd.models[0].Textures.Clear();
         Gl.glEnable(Gl.GL_TEXTURE_2D);
         var fileStream = new FileStream(Path.GetTempPath() + "map.nsbmd", FileMode.Open);
         file_2 = Path.GetTempPath() + "map.nsbmd";
         _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
         fileStream.Close();
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(workingFolder + @"data\a\0\1\tilesets" + "\\" + (comboBox7.SelectedIndex - 1).ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes);
         try
         {
             _nsbmd.MatchTextures();
         }
         catch { }
         simpleOpenGlControl2.Invalidate();
         button20_Click(null, null);
     }
 }
Exemple #4
0
        /// <summary>
        /// Load actual map.
        /// </summary>
        /// <param name="file">Map file.</param>
        private static void LoadMap(FileInfo file)
        {
            // Init file read.
            var fileStream = new FileStream(file.FullName, FileMode.Open);
            var reader = new BinaryReader(fileStream);
            Stream nsbmdStream = fileStream;

            // Abort on invalid filesize.
            if (fileStream.Length < 4)
                return ;

            // Read first 4 bytes to determine if
            // file is raw NSBMD.
            var firstFileBytes = reader.ReadInt32();
            fileStream.Position = 0;

            // The file is _definitely_ no NSBMD.
            // Treat it as Pokemon map.
            if (firstFileBytes != Nsbmd.NDS_TYPE_BMD0)
            {
                var demuxer = new PkmnMapDemuxer(reader);
                var memStream = new MemoryStream(demuxer.DemuxBMDBytes()); // Extract BMD bytes from map.
                fileStream.Close();
                fileStream.Dispose();
                nsbmdStream = memStream;
            }

            // Load nsbmd from stream.
            _nsbmd = NsbmdLoader.LoadNsbmd(nsbmdStream);
            nsbmdStream.Close();
            nsbmdStream.Dispose();

            // Material names used in model.
            var modelUsedMaterialList =
                GetMaterialListForNsbmd(_nsbmd);

            // Find matching texture file.
            _usedTextureFile = GetTextureFileToUseForModel(modelUsedMaterialList);

            // If no texture file found, abort.
            if (String.IsNullOrEmpty(_usedTextureFile))
            {
                return ;

                //MessageBox.Show("No matching texture file found! Aborting now...");
                //Environment.Exit(-1);
            }

            // Load materials from external texture file.
            IEnumerable<NsbmdMaterial> loadedMaterials = null;
            var usedTextureFile = new FileInfo(_textureDirectory.FullName + @"\" + _usedTextureFile);

            loadedMaterials = NsbtxLoader.LoadNsbtx(usedTextureFile);

            // Set materials in NSBMD.
            _nsbmd.models[0].Materials.AddRange(loadedMaterials);
            _nsbmd.materials = loadedMaterials;
            _nsbmd.MatchTextures();
        }
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     var fileStream = new FileStream(bldPath + "\\" + "model" + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open);
     file_2 = bldPath + "\\" + "model" + "\\" + listBox1.SelectedIndex.ToString("D4");
     _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
     if (!checkBox1.Checked)
     {
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Form1.workingFolder + @"data\a\1\7\bldtilesets" + "\\" + comboBox1.SelectedIndex.ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes);
     }
     else
     {
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Form1.workingFolder + @"data\a\1\7\bld2tilesets" + "\\" + comboBox1.SelectedIndex.ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes);
     }
     try
     {
         _nsbmd.MatchTextures();
     }
     catch { }
     RenderBuilding(null, null);
     fileStream.Close();
     System.IO.BinaryReader readHeader = new System.IO.BinaryReader(File.OpenRead(bldPath + "\\" + "header" + "\\" + listBox1.SelectedIndex.ToString("D4")));
     numericUpDown1.Value = readHeader.ReadUInt16(); // ID
     readHeader.BaseStream.Position += 2;
     numericUpDown2.Value = readHeader.ReadUInt16(); // Door ID
     numericUpDown3.Value = readHeader.ReadInt16(); // X
     numericUpDown4.Value = readHeader.ReadInt16(); // Y
     numericUpDown5.Value = readHeader.ReadInt16(); // Z
     readHeader.Close();
 }