Exemplo n.º 1
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.º 2
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;

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

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

            new ExportedLevel(LevelFile, BGFile).Write(bw);
            bw.Close();
        }
        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;
            }
        }
Exemplo n.º 4
0
        private void NarcReplace(string NarcName, string f1)
        {
            NarcFilesystem fs = new NarcFilesystem(ROM.FS.getFileByName(NarcName));

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

            fs.close();
        }
Exemplo n.º 5
0
        public BNBL(DSFileSystem.File f)
        {
            this.f = f;
            f.beginEdit(this);

            InitializeComponent();

            Text += " - " + f.name;

            LoadBNBL();
            Show();
        }
Exemplo n.º 6
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.º 7
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));

            NSMBe5.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.º 8
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.º 9
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;
     }
 }
Exemplo n.º 10
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");
         DSFileSystem.File file = ROM.FS.getFileById(131);
         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.º 11
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 == patchHeader || header == oldPatchHeader))
            {
                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();
                    NSMBe5.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.º 12
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));
        }
Exemplo n.º 13
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");
                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));
            }
        }