Exemplo n.º 1
0
        public LevelHexEditor(string LevelFilename)
        {
            InitializeComponent();
            if (Properties.Settings.Default.mdi)
                this.MdiParent = MdiParentForm.instance;
            this.LevelFilename = LevelFilename;

            LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
            LevelFile.beginEdit(this);
            byte[] eLevelFile = LevelFile.getContents();
            Blocks = new byte[][] { null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            int FilePos = 0;
            for (int BlockIdx = 0; BlockIdx < 14; BlockIdx++) {
                int BlockOffset = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;
                int BlockSize = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;

                Blocks[BlockIdx] = new byte[BlockSize];
                Array.Copy(eLevelFile, BlockOffset, Blocks[BlockIdx], 0, BlockSize);
            }

            LoadBlock(0);
            this.Icon = Properties.Resources.nsmbe;
        }
Exemplo n.º 2
0
        public byte[] doRequest(byte type, byte[] data = null, File f = null)
        {
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            if (data == null)
            {
                bout.writeInt(1);
                bout.writeByte(type);
            }
            else
            {
                bout.writeInt(data.Length+1);
                bout.writeByte(type);
                bout.write(data);
            }
            byte[] aout = bout.getArray();
            stream.Write(aout, 0, aout.Length);
            stream.Flush();

            byte[] resp = readBytes(8);
            ByteArrayInputStream bin = new ByteArrayInputStream(resp);
            int error = bin.readInt();
            int len = bin.readInt();
            resp = readBytes(len);

            if (error == 2) throw new AlreadyEditingException(f);
            if (error != 0)
            {
                ByteArrayInputStream i = new ByteArrayInputStream(resp);
                string s = i.ReadString();
                throw new Exception("Network error: " + s);
            }

            return resp;
        }
Exemplo n.º 3
0
 public BannerFile(Filesystem parent, Directory parentDir, File headerFile)
     : base(parent, parentDir, -8, "banner.bin", headerFile, 0x68, 0, true)
 {
     endFile = null;
     fileSizeP = 0x840;
     refreshOffsets();
 }
Exemplo n.º 4
0
        private void importLevelButton_Click(object sender, EventArgs e)
        {
            if (levelTreeView.SelectedNode == null)
            {
                return;
            }

            // Figure out what file to import
            if (importLevelDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            // Get the files
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;

            DSFileSystem.File LevelFile = ROM.getLevelFile(LevelFilename);
            DSFileSystem.File BGFile    = ROM.getBGDatFile(LevelFilename);

            // Load it
            try
            {
                ExternalLevelSource level = new ExternalLevelSource(importLevelDialog.FileName);
                level.level.Import(LevelFile, BGFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 5
0
        private void importLevelButton_Click(object sender, EventArgs e)
        {
            if (levelTreeView.SelectedNode == null)
            {
                return;
            }

            // Figure out what file to import
            if (importLevelDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            // Get the files
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;

            NSMBe4.DSFileSystem.File LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
            NSMBe4.DSFileSystem.File BGFile    = ROM.FS.getFileByName(LevelFilename + "_bgdat.bin");

            // Load it
            FileStream    fs    = new FileStream(importLevelDialog.FileName, FileMode.Open);
            BinaryReader  br    = new BinaryReader(fs);
            ExportedLevel exlvl = new ExportedLevel(br);

            if (exlvl.hasError())
            {
                MessageBox.Show(exlvl.ErrorMessage, exlvl.ErrorTitle);
            }
            else
            {
                exlvl.Import(LevelFile, BGFile);
            }
            br.Close();
        }
Exemplo n.º 6
0
        private void exportLevelButton_Click(object sender, EventArgs e)
        {
            if (levelTreeView.SelectedNode == null)
            {
                return;
            }

            // Figure out what file to export to
            if (exportLevelDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            // Get the files
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;

            NSMBe4.DSFileSystem.File LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
            NSMBe4.DSFileSystem.File BGFile    = ROM.FS.getFileByName(LevelFilename + "_bgdat.bin");

            // Load it
            FileStream   fs = new FileStream(exportLevelDialog.FileName, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);

            new ExportedLevel(LevelFile, BGFile).Write(bw);
            bw.Close();
        }
Exemplo n.º 7
0
        private void importClipboard_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show((LanguageManager.Get("LevelChooser", "replaceclipboard")), (LanguageManager.Get("LevelChooser", "replaceclipboardtitle")), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }
            try
            {
                string leveltxt = Clipboard.GetText();
                if (!(leveltxt.StartsWith("NSMBeLevel|") && leveltxt.EndsWith("|")))
                {
                    throw new Exception();
                }
                leveltxt = leveltxt.Substring(11, leveltxt.Length - 12);
                byte[] levelfile          = ROM.LZ77_Decompress(Convert.FromBase64String(leveltxt));
                ByteArrayInputStream strm = new ByteArrayInputStream(levelfile);
                BinaryReader         br   = new BinaryReader(strm);

                string LevelFilename = (string)levelTreeView.SelectedNode.Tag;
                NSMBe4.DSFileSystem.File LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
                NSMBe4.DSFileSystem.File BGFile    = ROM.FS.getFileByName(LevelFilename + "_bgdat.bin");
                new ExportedLevel(br).Import(LevelFile, BGFile);
                br.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show((LanguageManager.Get("LevelChooser", "clipinvalidlevel")));
            }
        }
Exemplo n.º 8
0
        public static void gotSection(File f, int offs, int size)
        {
            uint magic = f.getUintAt(offs);

            if (magic == 0x504C5454) //PLTT
                new PaletteViewer(new InlineFile(f, offs + 0x18, size - 0x18, f.name)).Show();
            else if (magic == 0x43484152) //CHAR
            {
                LevelChooser.showImgMgr();
                int tileWidth = f.getUshortAt(offs + 0xA);
                if (tileWidth == 0xFFFF)
                    tileWidth = 8;
                LevelChooser.imgMgr.m.addImage(new Image2D(new InlineFile(f, offs + 0x20, size - 0x20, f.name), 8*tileWidth, true, false));
            }
            else if (magic == 0x5343524E) //SCRN
            {
                if (LevelChooser.imgMgr == null) return;
                Image2D img = LevelChooser.imgMgr.m.getSelectedImage();
                Palette[] pals = LevelChooser.imgMgr.m.getPalettes();
                if (img == null) return;
                if (pals == null) return;
                if (pals.Length == 0) return;
                InlineFile ff = new InlineFile(f, offs + 0x14, size - 0x14, f.name);
                Tilemap t = new Tilemap(ff, 32, img, pals, 0, 0);
                new TilemapEditorWindow(t).Show();
            }
            else
                Console.WriteLine(String.Format("Unknown magic: {0:X8}", magic));
        }
Exemplo n.º 9
0
 public ExportedLevel(File LevelFile, File BGFile)
 {
     this.LevelFile = LevelFile.getContents();
     this.BGFile = BGFile.getContents();
     this.LevelFileID = LevelFile.id;
     this.BGFileID = BGFile.id;
 }
Exemplo n.º 10
0
 public InlineFile(File parent, int offs, int len, string name)
 {
     nameP = name;
     fileSizeP = len;
     parentFile = parent;
     inlineOffs = offs;
     inlineLen = len;
 }
Exemplo n.º 11
0
 public Image2D(File f, int width, bool is4bpp, bool isLZCompressed)
 {
     this.f = f;
     this.is4bppI = is4bpp;
     this.width = width;
     this.isLZCompressed = isLZCompressed;
     reload();
 }
Exemplo n.º 12
0
        public FilePalette(File f, string name)
        {
            this.f = f;
            this.name = name;

            pal = arrayToPalette(f.getContents());
            if(pal.Length != 0)
                pal[0] = NSMBGraphics.ReallyTransparent;
        }
Exemplo n.º 13
0
        public Image3Dformat5(File f, File f5, int width, int height)
        {
            this.f = f;
            this.f5 = f5;
//            f.beginEdit(this);
//            f5.beginEdit(this);
            this.width = width;
            this.height = height;
        }
Exemplo n.º 14
0
        public FilePalette(File f, string name)
        {
            this.f = f;
            this.name = name;

            pal = arrayToPalette(f.getContents());
            if(pal.Length != 0)
                pal[0] = Color.Transparent;
        }
Exemplo n.º 15
0
        public Image3D(File f, bool color0, int width, int height, int format)
        {
            this.f = f;
            this.color0Transp = color0;
            this.width = width;
            this.height = height;
            this.format = format;

//            f.beginEdit(this);
            data = f.getContents();
        }
Exemplo n.º 16
0
 public InlineFile(File parent, int offs, int len, string name, Directory parentDir, CompressionType comp)
     : base(parent.parent, parentDir, parent.name + " - " + name + ":" + offs.ToString("X") + ":" + len)
 {
     parentFile = parent;
     inlineOffs = offs;
     inlineLen = len;
     this.comp = comp;
     this.fixedFile = true;
     this.canChangeOffset = false;
     refreshOffsets();
 }
Exemplo n.º 17
0
        private void NarcReplace(string NarcName, string f1)
        {
            NarcFilesystem fs = new NarcFilesystem(ROM.FS.getFileByName(NarcName));

            NSMBe4.DSFileSystem.File f = fs.getFileByName(f1);
            f.beginEdit(this);
            f.replace(ROM.FS.getFileByName(f1).getContents(), this);
            f.endEdit(this);

            fs.close();
        }
Exemplo n.º 18
0
 public PaletteViewer(File f)
 {
     InitializeComponent();
     LanguageManager.ApplyToContainer(this, "PaletteViewer");
     this.MdiParent = MdiParentForm.instance;
     this.f = f;
     this.pal = FilePalette.arrayToPalette(f.getContents());
     if (pal.Length < 256)
         is4bpp.Checked = true;
     updatePalettes();
     pictureBox1.Invalidate();
     this.Icon = Properties.Resources.nsmbe;
 }
Exemplo n.º 19
0
        public LZFile(File parent, CompressionType ct)
        {
            nameP = parent.name;
            parentFile = parent;
            comp = ct;

            if (comp == CompressionType.None)
                fileSizeP = parent.fileSize;
            else if (comp == CompressionType.LZ)
                fileSizeP = ROM.LZ77_GetDecompressedSize(parent.getInterval(0, 4));
            else if (comp == CompressionType.LZWithHeader)
                fileSizeP = ROM.LZ77_GetDecompressedSizeWithHeader(parent.getInterval(0, 8));
        }
Exemplo n.º 20
0
        public Tilemap(File f, int tileWidth, Image2D i, Palette[] pals, int tileOffset, int paletteOffset)
        {
            this.f = f;
            this.width = tileWidth;
            this.tileOffset = tileOffset;
            this.paletteOffset = paletteOffset;

            this.tileset = i;
            this.palettes = pals;
            this.tileCount = tileset.getWidth() * tileset.getHeight() / 64;

            load();
        }
Exemplo n.º 21
0
 public PaletteViewer(File f)
 {
     InitializeComponent();
     this.MdiParent = MdiParentForm.instance;
     this.f = f;
     fileLz = new LZFile(f, LZFile.CompressionType.LZ);
     this.pal = FilePalette.arrayToPalette(ROM.LZ77_Decompress(f.getContents()));
     if (pal.Length < 256)
         is4bpp.Checked = true;
     updatePalettes();
     pictureBox1.Invalidate();
     this.Icon = Properties.Resources.nsmbe;
 }
Exemplo n.º 22
0
        public static void load(File f)
        {
            int size = f.fileSize;

            int offs = 0x10; //Asisuming always same header size.
            while (offs+8 <= size)
            {
                uint magic = f.getUintAt(offs);
                uint sectionSize = f.getUintAt(offs + 4);
                if (sectionSize == 0) break; //Some files appear to have extra 0's at the end !?
                gotSection(f, offs, (int)sectionSize);
                offs += (int) sectionSize;
            }
        }
Exemplo n.º 23
0
        private void exportClipboard_Click(object sender, EventArgs e)
        {
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;

            DSFileSystem.File LevelFile = ROM.getLevelFile(LevelFilename);
            DSFileSystem.File BGFile    = ROM.getBGDatFile(LevelFilename);

            ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);
            BinaryWriter         bw   = new BinaryWriter(strm);

            new ExportedLevel(LevelFile, BGFile).Write(bw);
            ClipboardLevelSource.copyData(strm.getData());
            bw.Close();
        }
Exemplo n.º 24
0
        private void exportClipboard_Click(object sender, EventArgs e)
        {
            string LevelFilename = (string)levelTreeView.SelectedNode.Tag;

            NSMBe4.DSFileSystem.File LevelFile = ROM.FS.getFileByName(LevelFilename + ".bin");
            NSMBe4.DSFileSystem.File BGFile    = ROM.FS.getFileByName(LevelFilename + "_bgdat.bin");

            ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]);
            BinaryWriter         bw   = new BinaryWriter(strm);

            new ExportedLevel(LevelFile, BGFile).Write(bw);
            Clipboard.SetText("NSMBeLevel|" + Convert.ToBase64String(ROM.LZ77_Compress(strm.getData())) + "|");
            bw.Close();
        }
Exemplo n.º 25
0
        public FileHexEditor(File f)
        {
            InitializeComponent();

            this.MdiParent = MdiParentForm.instance;

            this.f = f;
            f.beginEdit(this);

            LanguageManager.ApplyToContainer(this, "FileHexEditor");
            this.Text = string.Format(LanguageManager.Get("FileHexEditor", "_TITLE"), f.name);

            hexBox1.ByteProvider = new DynamicByteProvider(f.getContents());
            this.Icon = Properties.Resources.nsmbe;
        }
Exemplo n.º 26
0
        //WTF was this for?!
        //private void NarcReplace(string NarcName, string f1, string f2) { }

        private void NarcReplace(string NarcName, string f1, ushort f2)
        {
            NarcFilesystem fs = new NarcFilesystem(ROM.FS.getFileByName(NarcName));

            NSMBe4.DSFileSystem.File f = fs.getFileByName(f1);
            if (f == null)
            {
                Console.Out.WriteLine("No File: " + NarcName + "/" + f1);
            }
            else
            {
                f.beginEdit(this);
                f.replace(ROM.FS.getFileById(f2).getContents(), this);
                f.endEdit(this);
            }
            fs.close();
        }
Exemplo n.º 27
0
 private void importClipboard_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show((LanguageManager.Get("LevelChooser", "replaceclipboard")), (LanguageManager.Get("LevelChooser", "replaceclipboardtitle")), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
     {
         return;
     }
     try
     {
         string               LevelFilename = (string)levelTreeView.SelectedNode.Tag;
         DSFileSystem.File    LevelFile     = ROM.getLevelFile(LevelFilename);
         DSFileSystem.File    BGFile        = ROM.getBGDatFile(LevelFilename);
         ClipboardLevelSource level         = new ClipboardLevelSource();
         level.level.Import(LevelFile, BGFile);
     }
     catch (Exception ex)
     {
         MessageBox.Show((LanguageManager.Get("LevelChooser", "clipinvalidlevel")));
     }
 }
Exemplo n.º 28
0
        public OverlayFile(Filesystem parent, Directory parentDir,
            int id,  File alFile, int alBeg, int alEnd,
            File ovTableFile, uint ovTableOffs)
            : base(parent, parentDir, true, id, ":::", alFile, alBeg, alEnd)
        {
            this.nameP = string.Format(LanguageManager.Get("NitroClass", "OverlayFile"),
                id, ramAddr.ToString("X"), ramSize.ToString("X"));

            this.ovTableFile = ovTableFile;
            this.ovTableOffs = ovTableOffs;

            ovId = ovTableFile.getUintAt((int)ovTableOffs + 0x00);
            ramAddr = ovTableFile.getUintAt((int)ovTableOffs + 0x04);
            ramSize = ovTableFile.getUintAt((int)ovTableOffs + 0x08);
            bssSize = ovTableFile.getUintAt((int)ovTableOffs + 0x0C);
            staticInitStart = ovTableFile.getUintAt((int)ovTableOffs + 0x10);
            staticInitEnd = ovTableFile.getUintAt((int)ovTableOffs + 0x14);

            nameP = String.Format("{0:X8} - {1:X8}, OV {2}, FILE {3}", ramAddr, ramAddr + ramSize - 1, ovId, id);
        }
Exemplo n.º 29
0
        public static void Import(File destLevelFile, File destBGFile, byte[] levelFile, byte[] bgFile)
        {
            try {
                destLevelFile.beginEdit(destBGFile);
            } catch (AlreadyEditingException) {
                MessageBox.Show(LanguageManager.Get("Errors", "Level"));
                return;
            }

            try {
                destBGFile.beginEdit(destLevelFile);
            } catch (AlreadyEditingException) {
                MessageBox.Show(LanguageManager.Get("Errors", "Level"));
                return;
            }

            destLevelFile.replace(levelFile, destBGFile);
            destLevelFile.endEdit(destBGFile);
            destBGFile.replace(bgFile, destLevelFile);
            destBGFile.endEdit(destLevelFile);
        }
 public InternalLevelSource(string filename, string levelname, string loadFileName)
 {
     levelFile      = ROM.getLevelFile(filename);
     BGDatFile      = ROM.getBGDatFile(filename);
     this.filename  = filename;
     this.levelname = levelname;
     if (loadFileName == "")
     {
         levelData = levelFile.getContents();
         BGDatData = BGDatFile.getContents();
     }
     else
     {
         FileStream    fs    = new FileStream(loadFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
         BinaryReader  br    = new BinaryReader(fs);
         ExportedLevel level = new ExportedLevel(br);
         br.Close();
         levelData = level.LevelFile;
         BGDatData = level.BGDatFile;
     }
 }
Exemplo n.º 31
0
 public InternalLevelSource(string filename, string levelname, string loadFileName)
 {
     levelFile = ROM.getLevelFile(filename);
     BGDatFile = ROM.getBGDatFile(filename);
     this.filename = filename;
     this.levelname = levelname;
     if (loadFileName == "")
     {
         levelData = levelFile.getContents();
         BGDatData = BGDatFile.getContents();
     }
     else
     {
         FileStream fs = new FileStream(loadFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
         BinaryReader br = new BinaryReader(fs);
         ExportedLevel level = new ExportedLevel(br);
         br.Close();
         levelData = level.LevelFile;
         BGDatData = level.BGDatFile;
     }
 }
Exemplo n.º 32
0
 public void SaveFile()
 {
     try
     {
         string text = string.Empty;
         //System.IO.StreamWriter s = new System.IO.StreamWriter(new System.IO.FileStream(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write));
         // Write lists
         foreach (KeyValuePair <string, Dictionary <int, string> > list in lists)
         {
             text += "[" + list.Key + "]\n";
             foreach (KeyValuePair <int, string> item in list.Value)
             {
                 text += item.Key.ToString() + "=" + item.Value + "\n";
             }
         }
         // Write descriptions
         foreach (KeyValuePair <int, List <string> > item in descriptions)
         {
             int num = 0;
             text += "[" + item.Key.ToString() + "]\n";
             foreach (string desc in item.Value)
             {
                 if (desc != string.Empty)
                 {
                     text += num.ToString() + "=" + desc + "\n";
                 }
                 num++;
             }
         }
         DSFileSystem.File file = ROM.FS.getFileByName("00DUMMY");
         file.beginEdit(this);
         file.replace(System.Text.Encoding.ASCII.GetBytes(text), this);
         file.endEdit(this);
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(String.Format(LanguageManager.Get("ROMUserInfo", "ErrorWrite"), ex.Message));
     }
 }
Exemplo n.º 33
0
        public LZFile(File parent, CompressionType ct)
        {
        	nameP = parent.name;
            parentFile = parent;
			comp = ct;

            // If we think it might be compressed, try decompressing it. If it succeeds, assume it was compressed.
            if (comp == CompressionType.MaybeLZ) {
                try {
                    ROM.LZ77_Decompress(parentFile.getContents());
                    comp = CompressionType.LZ;
                } catch {
                    comp = CompressionType.None;
                }
            }

            if (comp == CompressionType.None)
        		fileSizeP = parent.fileSize;
            else if (comp == CompressionType.LZ)
            	fileSizeP = ROM.LZ77_GetDecompressedSize(parent.getInterval(0, 4));
            else if (comp == CompressionType.LZWithHeader)
            	fileSizeP = ROM.LZ77_GetDecompressedSizeWithHeader(parent.getInterval(0, 8));
        }
Exemplo n.º 34
0
 public void Import(File destLevelFile, File destBGFile)
 {
     Import(destLevelFile, destBGFile, LevelFile, BGFile);
 }
Exemplo n.º 35
0
 public NSMBLevel(File levelFile, File bgFile, byte[] eLevelFile, byte[] eBGFile, NSMBGraphics GFX)
 {
     LoadLevel(levelFile, bgFile, eLevelFile, eBGFile, GFX);
 }
Exemplo n.º 36
0
 public Image2D(File f, int width, bool is4bpp)
     : this(f, width, is4bpp, true)
 {
 }
Exemplo n.º 37
0
        /**
         * PATCH FILE FORMAT
         *
         * - String "NSMBe4 Exported Patch"
         * - Some files (see below)
         * - byte 0
         *
         * STRUCTURE OF A FILE
         * - byte 1
         * - File name as a string
         * - File ID as ushort (to check for different versions, only gives a warning)
         * - File length as uint
         * - File contents as byte[]
         */

        private void patchExport_Click(object sender, EventArgs e)
        {
            //output to show to the user
            bool differentRomsWarning = false; // tells if we have shown the warning
            int  fileCount            = 0;

            //load the original rom
            MessageBox.Show(LanguageManager.Get("Patch", "SelectROM"), LanguageManager.Get("Patch", "Export"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            if (openROMDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            NitroROMFilesystem origROM = new NitroROMFilesystem(openROMDialog.FileName);

            //open the output patch
            MessageBox.Show(LanguageManager.Get("Patch", "SelectLocation"), LanguageManager.Get("Patch", "Export"), MessageBoxButtons.OK, MessageBoxIcon.Information);
            if (savePatchDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            FileStream fs = new FileStream(savePatchDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None);

            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write("NSMBe4 Exported Patch");

            //DO THE PATCH!!
            ProgressWindow progress = new ProgressWindow(LanguageManager.Get("Patch", "ExportProgressTitle"));

            progress.Show();
            progress.SetMax(ROM.FS.allFiles.Count);
            int progVal = 0;

            MessageBox.Show(LanguageManager.Get("Patch", "StartingPatch"), LanguageManager.Get("Patch", "Export"), MessageBoxButtons.OK, MessageBoxIcon.Information);

            foreach (NSMBe4.DSFileSystem.File f in ROM.FS.allFiles)
            {
                if (f.isSystemFile)
                {
                    continue;
                }

                Console.Out.WriteLine("Checking " + f.name);
                progress.SetCurrentAction(string.Format(LanguageManager.Get("Patch", "ComparingFile"), f.name));

                NSMBe4.DSFileSystem.File orig = origROM.getFileByName(f.name);
                //check same version
                if (!differentRomsWarning && f.id != orig.id)
                {
                    if (MessageBox.Show(LanguageManager.Get("Patch", "ExportDiffVersions"), LanguageManager.Get("General", "Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        differentRomsWarning = true;
                    }
                    else
                    {
                        fs.Close();
                        return;
                    }
                }

                byte[] oldFile = orig.getContents();
                byte[] newFile = f.getContents();

                if (!arrayEqual(oldFile, newFile))
                {
                    //include file in patch
                    string fileName = orig.name;
                    Console.Out.WriteLine("Including: " + fileName);
                    progress.WriteLine(string.Format(LanguageManager.Get("Patch", "IncludedFile"), fileName));
                    fileCount++;

                    bw.Write((byte)1);
                    bw.Write(fileName);
                    bw.Write((ushort)f.id);
                    bw.Write((uint)newFile.Length);
                    bw.Write(newFile, 0, newFile.Length);
                }
                progress.setValue(++progVal);
            }
            bw.Write((byte)0);
            bw.Close();
            origROM.close();
            progress.SetCurrentAction("");
            progress.WriteLine(string.Format(LanguageManager.Get("Patch", "ExportReady"), fileCount));
        }
Exemplo n.º 38
0
        public ROMUserInfo(string ROMPath)
        {
            //FilePath = ROMPath.Substring(0, ROMPath.LastIndexOf('.') + 1) + "txt";
            int lineNum = 0;

            try
            {
                //if (!System.IO.File.Exists(FilePath)) return;
                //System.IO.StreamReader s = new System.IO.StreamReader(FilePath);
                DSFileSystem.File        file    = ROM.FS.getFileByName("00DUMMY");
                string[]                 lines   = System.Text.Encoding.ASCII.GetString(file.getContents()).Split('\n');
                List <string>            curList = null;
                Dictionary <int, string> curDict = null;
                bool readDescriptions            = false;
                for (lineNum = 0; lineNum < lines.Length; lineNum++)
                {
                    string line = lines[lineNum];
                    if (line != "")
                    {
                        if (line.StartsWith("["))
                        {
                            line = line.Substring(1, line.Length - 2);
                            int num;
                            if (int.TryParse(line, out num))
                            {
                                readDescriptions = true;
                                curList          = new List <string>();
                                for (int l = 0; l < 256; l++)
                                {
                                    curList.Add("");
                                }
                                descriptions.Add(num, curList);
                            }
                            else
                            {
                                readDescriptions = false;
                                curDict          = new Dictionary <int, string>();
                                lists.Add(line, curDict);
                            }
                        }
                        else if (curList != null || curDict != null)
                        {
                            int    num  = int.Parse(line.Substring(0, line.IndexOf("=")).Trim());
                            string name = line.Substring(line.IndexOf("=") + 1).Trim();
                            if (readDescriptions)
                            {
                                if (num < 256)
                                {
                                    curList[num] = name;
                                }
                            }
                            else
                            {
                                curDict.Add(num, name);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(String.Format(LanguageManager.Get("ROMUserInfo", "ErrorRead"), lineNum + 1, ex.Message));
            }
        }
Exemplo n.º 39
0
        private void patchImport_Click(object sender, EventArgs e)
        {
            //output to show to the user
            bool differentRomsWarning = false; // tells if we have shown the warning
            int  fileCount            = 0;

            //open the input patch
            if (openPatchDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            FileStream   fs = new FileStream(openPatchDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader br = new BinaryReader(fs);

            string header = br.ReadString();

            if (header != "NSMBe4 Exported Patch")
            {
                MessageBox.Show(
                    LanguageManager.Get("Patch", "InvalidFile"),
                    LanguageManager.Get("Patch", "Unreadable"),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                br.Close();
                return;
            }


            ProgressWindow progress = new ProgressWindow(LanguageManager.Get("Patch", "ImportProgressTitle"));

            progress.Show();

            byte filestartByte = br.ReadByte();

            try
            {
                while (filestartByte == 1)
                {
                    string fileName = br.ReadString();
                    progress.WriteLine(string.Format(LanguageManager.Get("Patch", "ReplacingFile"), fileName));
                    ushort origFileID          = br.ReadUInt16();
                    NSMBe4.DSFileSystem.File f = ROM.FS.getFileByName(fileName);
                    uint length = br.ReadUInt32();

                    byte[] newFile = new byte[length];
                    br.Read(newFile, 0, (int)length);
                    filestartByte = br.ReadByte();

                    if (f != null)
                    {
                        ushort fileID = (ushort)f.id;

                        if (!differentRomsWarning && origFileID != fileID)
                        {
                            MessageBox.Show(LanguageManager.Get("Patch", "ImportDiffVersions"), LanguageManager.Get("General", "Warning"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            differentRomsWarning = true;
                        }
                        if (!f.isSystemFile)
                        {
                            Console.Out.WriteLine("Replace " + fileName);
                            f.beginEdit(this);
                            f.replace(newFile, this);
                            f.endEdit(this);
                        }
                        fileCount++;
                    }
                }
            }
            catch (AlreadyEditingException)
            {
                MessageBox.Show(string.Format(LanguageManager.Get("Patch", "Error"), fileCount), LanguageManager.Get("General", "Completed"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            br.Close();
            MessageBox.Show(string.Format(LanguageManager.Get("Patch", "ImportReady"), fileCount), LanguageManager.Get("General", "Completed"), MessageBoxButtons.OK, MessageBoxIcon.Information);
//            progress.Close();
        }
Exemplo n.º 40
0
   		ushort unk; //Let's save it just in case.
   		
    	public Bncd(File f)
    	{
    		ByteArrayInputStream inp = new ByteArrayInputStream(f.getContents());
    		inp.readInt(); //Magic;
    		unk = inp.readUShort();
    		ushort entryCount = inp.readUShort();
    		uint entriesOffset = inp.readUInt();
    		uint subEntriesOffset = inp.readUInt();
    		uint dataOffset = inp.readUInt();
    		uint dataSize = inp.readUInt();
    		
    		inp.seek(entriesOffset);
    		
    		//Stores tilenum, tilecount to imageid
    		Dictionary<uint, int> imagesDict = new Dictionary<uint, int> ();
    		
    		for(uint entryId = 0; entryId < entryCount; entryId++)
    		{
    			BncdEntry e = new BncdEntry();
    			e.width = inp.readByte();
    			e.height = inp.readByte();
    			
    			uint subEntryIdx = inp.readUShort();
    			uint subEntryCt = inp.readUShort();
    			
    			inp.savePos();
    			inp.seek(subEntriesOffset + subEntryIdx*12);
    			for(int i = 0; i < subEntryCt; i++)
    			{
    				BncdSubEntry se = new BncdSubEntry();
    				e.subEntries.Add(se);
    				
    				se.oamAttr0 = inp.readUShort();
    				se.oamAttr1 = inp.readUShort();
    				se.unk = inp.readUInt();
    				se.tileNumber = inp.readUShort();
    				se.tileCount = inp.readUShort();
    				
    				uint imageCode = (uint) ((se.tileNumber << 16) | se.tileCount);
    				int imageId = imagesDict.Count;
    				if(imagesDict.ContainsKey(imageCode))
    					imageId = imagesDict[imageCode];
    				else
    				{
    					imagesDict[imageCode] = imageId;
				    	BncdImage img = new BncdImage();
				    	images.Add(img);
				    	img.tileNumber = se.tileNumber;
				    	img.tileCount = se.tileCount;

				    	int oamShape = se.oamAttr0>>14;
				    	int oamSize = se.oamAttr1>>14;

				    	img.tileWidth = widths[oamSize, oamShape];
					}
					    				
    				se.imageId = imageId;
    			}
    			inp.loadPos();
    		}
    		
            LevelChooser.showImgMgr();
			int tileLen = 8*8/2;
			foreach(BncdImage img in images)
			{
		        File imgFile = new InlineFile(f, (int)dataOffset+img.tileNumber*tileLen, img.tileCount*tileLen, f.name);
		        LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 8*img.tileWidth, true, false));
			}
    	}
Exemplo n.º 41
0
 public Overlay(File file, File ovTableFile, uint ovTableOffs)
 {
     this.f = file;
     this.ovTableFile = ovTableFile;
     this.ovTableOffs = ovTableOffs;
 }
Exemplo n.º 42
0
 public static void ExportLevel(File srcLevelFile, File srcBGFile, System.IO.BinaryWriter bw)
 {
     ExportLevel(srcLevelFile.id, srcBGFile.id, srcLevelFile.getContents(), srcBGFile.getContents(), bw);
 }
Exemplo n.º 43
0
        private void LoadLevel(File levelFile, File bgFile, byte[] eLevelFile, byte[] eBGFile, NSMBGraphics GFX)
        {
            this.LevelFile = levelFile;
            this.BGFile = bgFile;
            this.GFX = GFX;

            int FilePos;

            for(int x = 0; x < 512; x++)
                for (int y = 0; y < 256; y++)
                {
                    levelTilemap[x,y] = (x + y) % 512;
                }

            // Level loading time yay.
            // Since I don't know the format for every block, I will just load them raw.
            Blocks = new byte[][] { null, null, null, null, null, null, null, null, null, null, null, null, null, null };

            FilePos = 0;
            for (int BlockIdx = 0; BlockIdx < 14; BlockIdx++) {
                int BlockOffset = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;
                int BlockSize = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24;
                FilePos += 4;

                Blocks[BlockIdx] = new byte[BlockSize];
                Array.Copy(eLevelFile, BlockOffset, Blocks[BlockIdx], 0, BlockSize);
            }

            // Now objects.

            int ObjectCount = eBGFile.Length / 10;
            Objects = new List<NSMBObject>(ObjectCount);
            FilePos = 0;
            for (int ObjectIdx = 0; ObjectIdx < ObjectCount; ObjectIdx++) {
                int ObjID = eBGFile[FilePos] | (eBGFile[FilePos + 1] << 8);
                int ObjX = eBGFile[FilePos + 2] | (eBGFile[FilePos + 3] << 8);
                int ObjY = eBGFile[FilePos + 4] | (eBGFile[FilePos + 5] << 8);
                int ObjWidth = eBGFile[FilePos + 6] | (eBGFile[FilePos + 7] << 8);
                int ObjHeight = eBGFile[FilePos + 8] | (eBGFile[FilePos + 9] << 8);
                Objects.Add(new NSMBObject(ObjID & 4095, (ObjID & 61440) >> 12, ObjX, ObjY, ObjWidth, ObjHeight, GFX));
                FilePos += 10;
            }

            /*
             * Sprite struct:
             * Offs Len Dat
             * 0x0   2   Sprite id
             * 0x2   2   X
             * 0x4   2   Y
             * 0x6   6   Dat
             * 0xD   end
             */

            // Sprites
            byte[] SpriteBlock = Blocks[6];
            int SpriteCount = (SpriteBlock.Length - 2) / 12;
            Sprites = new List<NSMBSprite>(SpriteCount);
            FilePos = 0;
            for (int SpriteIdx = 0; SpriteIdx < SpriteCount; SpriteIdx++) {
                NSMBSprite Sprite = new NSMBSprite(this);
                Sprite.Type = SpriteBlock[FilePos] | (SpriteBlock[FilePos + 1] << 8);
                Sprite.X = SpriteBlock[FilePos + 2] | (SpriteBlock[FilePos + 3] << 8);
                Sprite.Y = SpriteBlock[FilePos + 4] | (SpriteBlock[FilePos + 5] << 8);
                Sprite.Data = new byte[6];
                FilePos += 6;
                Sprite.Data[0] = SpriteBlock[FilePos + 1];
                Sprite.Data[1] = SpriteBlock[FilePos + 0];
                Sprite.Data[2] = SpriteBlock[FilePos + 5];
                Sprite.Data[3] = SpriteBlock[FilePos + 4];
                Sprite.Data[4] = SpriteBlock[FilePos + 3];
                Sprite.Data[5] = SpriteBlock[FilePos + 2];
            //                Array.Copy(SpriteBlock, FilePos + 6, Sprite.Data, 0, 6);
                Sprites.Add(Sprite);
                FilePos += 6;
            }

            // Entrances.
            byte[] EntranceBlock = Blocks[5];
            int EntranceCount = EntranceBlock.Length / 20;
            Entrances = new List<NSMBEntrance>(EntranceCount);
            FilePos = 0;
            for (int EntIdx = 0; EntIdx < EntranceCount; EntIdx++) {
                NSMBEntrance Entrance = new NSMBEntrance();
                Entrance.X = EntranceBlock[FilePos] | (EntranceBlock[FilePos + 1] << 8);
                Entrance.Y = EntranceBlock[FilePos + 2] | (EntranceBlock[FilePos + 3] << 8);
                Entrance.CameraX = EntranceBlock[FilePos + 4] | (EntranceBlock[FilePos + 5] << 8);
                Entrance.CameraY = EntranceBlock[FilePos + 6] | (EntranceBlock[FilePos + 7] << 8);
                Entrance.Number = EntranceBlock[FilePos + 8];
                Entrance.DestArea = EntranceBlock[FilePos + 9];
                Entrance.ConnectedPipeID = EntranceBlock[FilePos + 10];
                Entrance.DestEntrance = EntranceBlock[FilePos + 12];
                Entrance.Type = EntranceBlock[FilePos + 14];
                Entrance.Settings = EntranceBlock[FilePos + 15];
                Entrance.Unknown1 = EntranceBlock[FilePos + 16];
                Entrance.EntryView = EntranceBlock[FilePos + 18];
                Entrance.Unknown2 = EntranceBlock[FilePos + 19];
                //Array.Copy(EntranceBlock, FilePos, Entrance.Data, 0, 20);
                Entrances.Add(Entrance);
                FilePos += 20;
            }

            // Views
            ByteArrayInputStream ViewBlock = new ByteArrayInputStream(Blocks[7]);
            ByteArrayInputStream CamBlock = new ByteArrayInputStream(Blocks[1]);
            Views = new List<NSMBView>();
            while (ViewBlock.lengthAvailable(16))
                Views.Add(NSMBView.read(ViewBlock, CamBlock));

            // Zones
            ByteArrayInputStream ZoneBlock = new ByteArrayInputStream(Blocks[8]);
            Zones = new List<NSMBView>();
            while (ZoneBlock.lengthAvailable(12))
                Zones.Add(NSMBView.readZone(ZoneBlock));

            // Paths

            ByteArrayInputStream PathBlock = new ByteArrayInputStream(Blocks[10]);
            ByteArrayInputStream PathNodeBlock = new ByteArrayInputStream(Blocks[12]);

            Paths = new List<NSMBPath>();
            while (!PathBlock.end())
            {
                Paths.Add(NSMBPath.read(PathBlock, PathNodeBlock, false));
            }

            PathBlock = new ByteArrayInputStream(Blocks[9]);
            PathNodeBlock = new ByteArrayInputStream(Blocks[11]);

            ProgressPaths = new List<NSMBPath>();
            while (!PathBlock.end())
            {
                ProgressPaths.Add(NSMBPath.read(PathBlock, PathNodeBlock, true));
            }

            CalculateSpriteModifiers();
            repaintAllTilemap();
        }
Exemplo n.º 44
0
 public NSMBLevel(File levelFile, File bgFile, NSMBGraphics GFX)
 {
     LoadLevel(levelFile, bgFile, levelFile.getContents(), bgFile.getContents(), GFX);
 }