Пример #1
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);
                }
            }
        }
Пример #2
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;
        }
 public override void enableWrite()
 {
     if (editing)
     {
         return;
     }
     levelFile.beginEdit(this);
     BGDatFile.beginEdit(this);
     editing = true;
 }
Пример #4
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();
        }
        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);
        }
Пример #6
0
        private void replaceFileButton_Click(object sender, EventArgs e)
        {
            if (fileTreeView.SelectedNode.Tag is File)
            {
                File f = fileTreeView.SelectedNode.Tag as File;

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

                string FileName = f.name;
                replaceFileDialog.FileName = FileName;
                if (replaceFileDialog.ShowDialog() != DialogResult.OK)
                {
                    UpdateFileInfo();
                    f.endEdit(this);
                    return;
                }

/*
 *              if(f is OverlayFile)
 *              {
 *                  DialogResult r = MessageBox.Show(LanguageManager.Get("FilesystemBrowser", "ImportOverlay"), LanguageManager.Get("FilesystemBrowser", "ImportOverlayTitle"), MessageBoxButtons.YesNoCancel);
 *                  if(r == DialogResult.Cancel)
 *                  {
 *                      UpdateFileInfo();
 *                      f.endEdit(this);
 *                      return;
 *                  }
 *
 *                  (f as OverlayFile).isCompressed = r == DialogResult.Yes;
 *              }*/
                replaceFile(f, replaceFileDialog.FileName);

                UpdateFileInfo();
                f.endEdit(this);
            }
            else
            {
                if (extractDirectoryDialog.ShowDialog() == DialogResult.OK)
                {
                    Directory d = fileTreeView.SelectedNode.Tag as Directory;
                    replaceDirectory(d, extractDirectoryDialog.SelectedPath);
                }
            }
        }
Пример #7
0
        private void replaceFileButton_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;
            }

            string FileName = f.name;

            replaceFileDialog.FileName = FileName;
            if (replaceFileDialog.ShowDialog() != DialogResult.OK)
            {
                UpdateFileInfo();
                f.endEdit(this);
                return;
            }

/*
 *          if(f is OverlayFile)
 *          {
 *              DialogResult r = MessageBox.Show("You're importing an overlay file. Is it a compressed overlay?\n\n(Overlays are compressed by default, so it probably is unless you decompressed it)", "Something", MessageBoxButtons.YesNoCancel);
 *              if(r == DialogResult.Cancel)
 *              {
 *                  UpdateFileInfo();
 *                  f.endEdit(this);
 *                  return;
 *              }
 *
 *              (f as OverlayFile).isCompressed = r == DialogResult.Yes;
 *          }*/

            string     SrcFileName = replaceFileDialog.FileName;
            FileStream rfs         = new FileStream(SrcFileName, FileMode.Open, FileAccess.Read, FileShare.Read);

            byte[] TempFile = new byte[rfs.Length];
            rfs.Read(TempFile, 0, (int)rfs.Length);
            rfs.Dispose();
            f.replace(TempFile, this);

            UpdateFileInfo();
            f.endEdit(this);
        }
Пример #8
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;
        }
Пример #9
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;
        }
Пример #10
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();
        }
Пример #11
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);
        }
Пример #12
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);
                }
            }
        }
Пример #13
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));
     }
 }
Пример #14
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);
        }
Пример #15
0
 public override void startEdition()
 {
     parentFile.beginEdit(this);
 }
Пример #16
0
        public static void ImportLevel(File destLevelFile, File destBGFile, System.IO.BinaryReader br)
        {
            try
            {
                destLevelFile.beginEdit(br);
            }
            catch (AlreadyEditingException)
            {
                MessageBox.Show(LanguageManager.Get("Errors", "Level"));
                return;
            }

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

            string Header = br.ReadString();
            if (Header != "NSMBe4 Exported Level") {
                MessageBox.Show(
                    LanguageManager.Get("NSMBLevel", "InvalidFile"),
                    LanguageManager.Get("NSMBLevel", "Unreadable"),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ushort FileVersion = br.ReadUInt16();
            if (FileVersion > 1) {
                MessageBox.Show(
                    LanguageManager.Get("NSMBLevel", "OldVersion"),
                    LanguageManager.Get("NSMBLevel", "Unusable"),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ushort SavedLevelFileID = br.ReadUInt16();
            ushort SavedBGFileID = br.ReadUInt16();
            if (SavedLevelFileID != destLevelFile.id) {
                DialogResult dr = MessageBox.Show(
                    LanguageManager.Get("NSMBLevel", "Mismatch"),
                    LanguageManager.Get("General", "Warning"),
                    MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dr == DialogResult.No) {
                    return;
                }
            }

            int LevelFileLength = br.ReadInt32();
            byte[] LevelFileData = br.ReadBytes(LevelFileLength);
            destLevelFile.replace(LevelFileData, br);
            destLevelFile.endEdit(br);

            int BGFileLength = br.ReadInt32();
            byte[] BGFileData = br.ReadBytes(BGFileLength);
            destBGFile.replace(BGFileData, br);
            destBGFile.endEdit(br);
        }
Пример #17
0
 void readFileContents(File f, System.IO.BinaryReader br)
 {
     int len = br.ReadInt32();
     byte[] data = new byte[len];
     br.Read(data, 0, len);
     f.beginEdit(this);
     f.replace(data, this);
     f.endEdit(this);
 }
Пример #18
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();
        }
Пример #19
0
 public override void editionStarted()
 {
     parentFile.beginEdit(this);
 }