Exemple #1
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));
            }
        }
Exemple #2
0
 public ExportedLevel(File LevelFile, File BGFile)
 {
     this.LevelFile = LevelFile.getContents();
     this.BGFile = BGFile.getContents();
     this.LevelFileID = LevelFile.id;
     this.BGFileID = BGFile.id;
 }
        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;
        }
Exemple #4
0
        private void decompressFileButton_Click(object sender, EventArgs e)
        {
            File f = fileTreeView.SelectedNode.Tag as File;

            try
            {
                try
                {
                    f.beginEdit(this);
                }
                catch (AlreadyEditingException)
                {
                    MessageBox.Show(LanguageManager.Get("Errors", "File"));
                    return;
                }
                byte[] CompFile = f.getContents();
                byte[] RawFile  = ROM.LZ77_Decompress(CompFile);
                f.replace(RawFile, this);
                UpdateFileInfo();
                f.endEdit(this);
            }
            catch (Exception)
            {
                MessageBox.Show(LanguageManager.Get("FilesystemBrowser", "DecompressionFail"));
                if (f.beingEditedBy(this))
                {
                    f.endEdit(this);
                }
            }
        }
Exemple #5
0
        private void loadOvTable(String dirName, int id, Directory parent, File table)
        {
            Directory dir = new Directory(this, parent, true, dirName, id);

            addDir(dir);
            parent.childrenDirs.Add(dir);

            ByteArrayInputStream tbl = new ByteArrayInputStream(table.getContents());

            int i = 0;

            while (tbl.lengthAvailable(32))
            {
                uint   ovId            = tbl.readUInt();
                uint   ramAddr         = tbl.readUInt();
                uint   ramSize         = tbl.readUInt();
                uint   bssSize         = tbl.readUInt();
                uint   staticInitStart = tbl.readUInt();
                uint   staticInitEnd   = tbl.readUInt();
                ushort fileID          = tbl.readUShort();
                tbl.skip(6); //unused 0's

                File f = loadFile(dirName + "_" + ovId + ".bin", fileID, dir);
//                f.isSystemFile = true;

                i++;
            }
        }
Exemple #6
0
        private void extractFile(File f, String fileName)
        {
            byte[]     tempFile = f.getContents();
            FileStream wfs      = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);

            wfs.Write(tempFile, 0, tempFile.GetLength(0));
            wfs.Dispose();
        }
Exemple #7
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;
        }
Exemple #8
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;
        }
Exemple #9
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();
        }
Exemple #10
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;
 }
 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;
 }
 public override byte[] getContents()
 {
     if (comp != CompressionType.NoComp)
     {
         byte[] data;
         if (comp == CompressionType.LZWithHeaderComp)
         {
             data = ROM.LZ77_DecompressWithHeader(parentFile.getContents());
         }
         else
         {
             data = ROM.LZ77_Decompress(parentFile.getContents());
         }
         byte[] thisdata = new byte[inlineLen];
         Array.Copy(data, inlineOffs, thisdata, 0, inlineLen);
         return(thisdata);
     }
     else
     {
         return(base.getContents());
     }
 }
        public override Stream load()
        {
            f.beginEdit(this);
            str = new MemoryStream();
            byte[] data = f.getContents();
            if (lz)
            {
                data = ROM.LZ77_Decompress(data);
            }

            str.Write(data, 0, data.Length);

            return(str);
        }
        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;
        }
        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;
        }
        private void extractFileButton_Click(object sender, EventArgs e)
        {
            File f = fileTreeView.SelectedNode.Tag as File;

            string FileName = f.name;

            extractFileDialog.FileName = FileName;
            if (extractFileDialog.ShowDialog() == DialogResult.OK)
            {
                string     DestFileName = extractFileDialog.FileName;
                byte[]     TempFile     = f.getContents();
                FileStream wfs          = new FileStream(DestFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                wfs.Write(TempFile, 0, TempFile.GetLength(0));
                wfs.Dispose();
            }
        }
Exemple #17
0
 public override byte[] getContents()
 {
     if (comp == CompressionType.LZWithHeader)
     {
         return(ROM.LZ77_DecompressWithHeader(parentFile.getContents()));
     }
     else if (comp == CompressionType.LZ)
     {
         return(ROM.LZ77_Decompress(parentFile.getContents()));
     }
     else
     {
         return(parentFile.getContents());
     }
 }
 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;
     }
 }
 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;
     }
 }
Exemple #20
0
        private void decompressWithHeaderButton_Click(object sender, EventArgs e)
        {
            File f = fileTreeView.SelectedNode.Tag as File;

            try
            {
                try
                {
                    f.beginEdit(this);
                }
                catch (AlreadyEditingException)
                {
                    MessageBox.Show(LanguageManager.Get("Errors", "File"));
                    return;
                }

                if (f.getUintAt(0) != 0x37375A4C)
                {
                    MessageBox.Show(LanguageManager.Get("Errors", "NoLZHeader"));
                    f.endEdit(this);
                    return;
                }

                byte[] CompFile = f.getContents();
                byte[] CompFileWithoutHeader = new byte[CompFile.Length - 4];
                Array.Copy(CompFile, 4, CompFileWithoutHeader, 0, CompFileWithoutHeader.Length);
                byte[] RawFile = ROM.LZ77_Decompress(CompFileWithoutHeader);
                f.replace(RawFile, this);
                UpdateFileInfo();
                f.endEdit(this);
            }
            catch (Exception)
            {
                MessageBox.Show(LanguageManager.Get("FilesystemBrowser", "DecompressionFail"));
                if (f.beingEditedBy(this))
                {
                    f.endEdit(this);
                }
            }
        }
Exemple #21
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));
        }
Exemple #22
0
        private void compressWithHeaderButton_Click(object sender, EventArgs e)
        {
            File f = fileTreeView.SelectedNode.Tag as File;

            try
            {
                f.beginEdit(this);
            }
            catch (AlreadyEditingException)
            {
                MessageBox.Show(LanguageManager.Get("Errors", "File"));
                return;
            }

            byte[] RawFile  = f.getContents();
            byte[] CompFile = ROM.LZ77_Compress(RawFile);

            byte[] CompFileWithHeader = new byte[CompFile.Length + 4];
            Array.Copy(CompFile, 0, CompFileWithHeader, 4, CompFile.Length);
            f.replace(CompFileWithHeader, this);
            f.setUintAt(0, 0x37375A4C);
            UpdateFileInfo();
            f.endEdit(this);
        }
Exemple #23
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));
			}
    	}
Exemple #24
0
 public static void ExportLevel(File srcLevelFile, File srcBGFile, System.IO.BinaryWriter bw)
 {
     ExportLevel(srcLevelFile.id, srcBGFile.id, srcLevelFile.getContents(), srcBGFile.getContents(), bw);
 }
Exemple #25
0
 public NSMBLevel(File levelFile, File bgFile, NSMBGraphics GFX)
 {
     LoadLevel(levelFile, bgFile, levelFile.getContents(), bgFile.getContents(), GFX);
 }
Exemple #26
0
 public static void ExportLevel(File srcLevelFile, File srcBGFile, System.IO.BinaryWriter bw)
 {
     bw.Write("NSMBe4 Exported Level");
     bw.Write((ushort)1);
     bw.Write((ushort)srcLevelFile.id);
     bw.Write((ushort)srcBGFile.id);
     byte[] LevelFileData = srcLevelFile.getContents();
     bw.Write(LevelFileData.Length);
     bw.Write(LevelFileData);
     byte[] BGFileData = srcBGFile.getContents();
     bw.Write(BGFileData.Length);
     bw.Write(BGFileData);
 }
Exemple #27
0
        public NSMBLevel(File levelFile, File bgFile, 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.
            byte[] eLevelFile = levelFile.getContents();
            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.
            byte[] eBGFile = bgFile.getContents();

            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();
        }
        /**
         * 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));
        }
Exemple #29
0
 public NSMBLevel(File levelFile, File bgFile, NSMBGraphics GFX)
 {
     this.LevelFile = levelFile;
     this.BGFile = bgFile;
     LoadLevel(levelFile.getContents(), bgFile.getContents(), GFX);
 }
 private void extractFile(File f, String fileName)
 {
     byte[] tempFile = f.getContents();
     FileStream wfs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
     wfs.Write(tempFile, 0, tempFile.GetLength(0));
     wfs.Dispose();
 }
        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));
            }
        }
Exemple #32
0
        public static void load(Filesystem fs)
        {
            filename = fs.getRomPath();
            FS = fs;
            if(fs is NitroROMFilesystem)
                romfile = new System.IO.FileInfo(filename);

            arm9binFile = FS.getFileByName("arm9.bin");
            arm9ovFile = FS.getFileByName("arm9ovt.bin");
            arm9ovs = loadOvTable(arm9ovFile);
            arm7binFile = FS.getFileByName("arm7.bin");
            arm7ovFile = FS.getFileByName("arm7ovt.bin");
            arm7ovs = loadOvTable(arm7ovFile);
            rsaSigFile = FS.getFileByName("rsasig.bin");
            headerFile = FS.getFileByName("header.bin");

            ByteArrayInputStream header = new ByteArrayInputStream(headerFile.getContents());
            romInternalName = header.ReadString(12);
            romGamecode = header.ReadString(4);

            if (romGamecode == "A2DE")
                Region = Origin.US;
            else if (romGamecode == "A2DP")
                Region = Origin.EU;
            else if (romGamecode == "A2DJ")
                Region = Origin.JP;
            else if (romGamecode == "A2DK")
                Region = Origin.KR;
            else
            {
                isNSMBRom = false;
                Region = Origin.UNK;
            }

            if (isNSMBRom)
            {
                UserInfo = new ROMUserInfo(filename);
                LoadOverlay0();
            }
        }
Exemple #33
0
        private static Overlay[] loadOvTable(File table)
        {
            Overlay[] ovs = new Overlay[table.fileSize/32];

            ByteArrayInputStream tbl = new ByteArrayInputStream(table.getContents());

            int i = 0;
            while (tbl.lengthAvailable(32))
            {
                uint ovId = tbl.readUInt();
                uint ramAddr = tbl.readUInt();
                uint ramSize = tbl.readUInt();
                uint bssSize = tbl.readUInt();
                uint staticInitStart = tbl.readUInt();
                uint staticInitEnd = tbl.readUInt();
                ushort fileID = tbl.readUShort();
                tbl.skip(6); //unused 0's

                ovs[ovId] = new Overlay(FS.getFileById(fileID), table, (uint)i*32);

                i++;
            }

            return ovs;
        }
        private void loadOvTable(String dirName, int id, Directory parent, File table)
        {
            Directory dir = new Directory(this, parent, true, dirName, id);
            addDir(dir);
            parent.childrenDirs.Add(dir);

            ByteArrayInputStream tbl = new ByteArrayInputStream(table.getContents());

            int i = 0;
            while (tbl.lengthAvailable(32))
            {
                uint ovId = tbl.readUInt();
                uint ramAddr = tbl.readUInt();
                uint ramSize = tbl.readUInt();
                uint bssSize = tbl.readUInt();
                uint staticInitStart = tbl.readUInt();
                uint staticInitEnd = tbl.readUInt();
                ushort fileID = tbl.readUShort();
                tbl.skip(6); //unused 0's

                File f = loadFile(dirName+"_"+ovId+".bin", fileID, dir);
            //                f.isSystemFile = true;

                i++;
            }
        }
        private void loadOvTable(String dirName, int id, Directory parent, File table, out OverlayFile[] arr)
        {
            Directory dir = new Directory(this, parent, true, dirName, id);
            addDir(dir);
            parent.childrenDirs.Add(dir);

            ByteArrayInputStream tbl = new ByteArrayInputStream(table.getContents());
            arr = new OverlayFile[tbl.available / 32];

            int i = 0;
            while (tbl.lengthAvailable(32))
            {
                uint ovId = tbl.readUInt();
                uint ramAddr = tbl.readUInt();
                uint ramSize = tbl.readUInt();
                uint bssSize = tbl.readUInt();
                uint staticInitStart = tbl.readUInt();
                uint staticInitEnd = tbl.readUInt();
                ushort fileID = tbl.readUShort();
                tbl.skip(6); //unused 0's

                OverlayFile f = loadOvFile(fileID, dir, table, tbl.getPos() - 0x20);
                f.isSystemFile = true;
                arr[i] = f;

                i++;

            }
        }
Exemple #36
0
 private void writeFileContents(File f, System.IO.BinaryWriter bw)
 {
     bw.Write((int)f.fileSize);
     bw.Write(f.getContents());
 }