コード例 #1
0
        public CompressedFile(File parent, CompressionType ct)
        {
            nameP      = parent.name;
            parentFile = parent;
            comp       = ct;

            if (comp == CompressionType.MaybeCompressed)
            {
                comp = parent.guessCompression(false);
            }

            if (comp == CompressionType.None)
            {
                fileSizeP = parent.fileSize;
            }
            else if (comp == CompressionType.LZ)
            {
                fileSizeP = ROM.LZ77_GetDecompressedSize(parent.getInterval(0, 4), false);
            }
            else if (comp == CompressionType.LZWithHeader)
            {
                fileSizeP = ROM.LZ77_GetDecompressedSize(parent.getInterval(0, 8), true);
            }
            else if (comp == CompressionType.Yaz0)
            {
                fileSizeP = ROM.Yaz0_Decompress(parent.getContents()).Length;
            }
        }
コード例 #2
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++;
            }
        }
コード例 #3
0
        public InternalLevelSource(string filename, string levelname, string loadFileName)
        {
            //If load from NARC in FS
            if (filename.Contains("@"))
            {
                string fileName = filename.Split('@')[0];
                string narcName = filename.Split('@')[1];
                narcFs    = new NarcFilesystem(ROM.FS.getFileByName(narcName + ".narc"));
                levelFile = narcFs.getFileByName(fileName + ".bin");
                BGDatFile = narcFs.getFileByName(fileName + "_bgdat.bin");
            }
            //If load from FS
            else
            {
                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;
            }
        }
コード例 #4
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();
        }
コード例 #5
0
        public override Stream load()
        {
            f.beginEdit(this);
            str = new MemoryStream();
            byte[] data = f.getContents();
            if (lz)
            {
                data = ROM.LZ77_Decompress(data, false);
            }

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

            return(str);
        }
コード例 #6
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;
        }
コード例 #7
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, true);
            f.replace(CompFile, this);
            UpdateFileInfo();
            f.endEdit(this);
        }
コード例 #8
0
 public InternalLevelSource(int LevelID, string levelname, string loadFileName)
 {
     levelFile      = ROM.FS.getFileById(LevelID);
     BGDatFile      = ROM.FS.getFileById(LevelID + 1);
     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;
     }
 }
コード例 #9
0
        private void compressFileButton_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 = RawFile;

            CompressFilePrompt compressFilePrompt = new CompressFilePrompt();

            if (compressFilePrompt.Canceled)
            {
                f.endEdit(this);
                return;
            }

            if (compressFilePrompt.ChosenCompression == CompressedFile.CompressionType.LZ)
            {
                CompFile = ROM.LZ77_Compress(CompFile, false);
            }
            else if (compressFilePrompt.ChosenCompression == CompressedFile.CompressionType.LZWithHeader)
            {
                CompFile = ROM.LZ77_Compress(CompFile, true);
            }
            else if (compressFilePrompt.ChosenCompression == CompressedFile.CompressionType.Yaz0)
            {
                CompFile = ROM.Yaz0_Compress(CompFile);
            }

            f.replace(CompFile, this);
            UpdateFileInfo();
            f.endEdit(this);
        }
コード例 #10
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, false);
                f.replace(RawFile, this);
                UpdateFileInfo();
                f.endEdit(this);
            }
            catch (Exception)
            {
                MessageBox.Show(LanguageManager.Get("FilesystemBrowser", "DecompressionFail"));
                if (f.beingEditedBy(this))
                {
                    f.endEdit(this);
                }
            }
        }
コード例 #11
0
        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(patchHeader);

            //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 (NSMBe5.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));

                NSMBe5.DSFileSystem.File orig = origROM.getFileByName(f.name);
                //check same version
                if (orig == null)
                {
                    new ErrorMSGBox("", "", "In this case it is recommended that you continue.", "This ROM has more files than the original clean ROM or a file was renamed!\n\nPlease make an XDelta patch instead.\n\nExport will end now.").ShowDialog();
                    bw.Write((byte)0);
                    bw.Close();
                    origROM.close();
                    progress.SetCurrentAction("");
                    progress.WriteLine(string.Format(LanguageManager.Get("Patch", "ExportReady"), fileCount));
                    return;
                }
                else 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));
        }
コード例 #12
0
 public override byte[] getContents()
 {
     if (comp == CompressionType.LZ)
     {
         return(ROM.LZ77_Decompress(parentFile.getContents(), false));
     }
     else if (comp == CompressionType.LZWithHeader)
     {
         return(ROM.LZ77_Decompress(parentFile.getContents(), true));
     }
     else if (comp == CompressionType.Yaz0)
     {
         return(ROM.Yaz0_Decompress(parentFile.getContents()));
     }
     else
     {
         return(parentFile.getContents());
     }
 }
コード例 #13
0
ファイル: ROMUserInfo.cs プロジェクト: poudink/NSMB-Editor
        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");
                DSFileSystem.File        file    = ROM.FS.getFileById(131);
                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));
            }
        }