コード例 #1
0
ファイル: BNBL.cs プロジェクト: szymbar15/NSMB-Editor
        private void SaveFile_Click(object sender, EventArgs e)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(memoryStream))
                {
                    bw.Write("JNBL".ToCharArray());

                    bw.BaseStream.Position = 0x6;
                    bw.BaseStream.WriteByte((byte)numberOfTouchObjs_UpDown.Value);

                    if (numberOfTouchObjs_UpDown.Value == 0)
                    {
                        f.replace(memoryStream.ToArray(), this);
                        return;
                    }

                    for (int i = 1; i <= numberOfTouchObjs_UpDown.Value; i++)
                    {
                        bw.BaseStream.Position = 0x8 - 0x6 + (i * 0x6);
                        bw.BaseStream.WriteByte(objn_xPos[i]);
                        bw.BaseStream.Position = 0xA - 0x6 + (i * 0x6);
                        bw.BaseStream.WriteByte(objn_yPos[i]);
                        bw.BaseStream.Position = 0xC - 0x6 + (i * 0x6);
                        bw.BaseStream.WriteByte(objn_width[i]);
                        bw.BaseStream.Position = 0xD - 0x6 + (i * 0x6);
                        bw.BaseStream.WriteByte(objn_height[i]);
                    }

                    f.replace(memoryStream.ToArray(), this);
                }
            }
        }
コード例 #2
0
        private void SaveFile_Click(object sender, EventArgs e)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(memoryStream))
                {
                    bw.Write("JNCL".ToCharArray());

                    bw.BaseStream.Position = 0x6;
                    bw.BaseStream.WriteByte((byte)numberOfObjs_UpDown.Value);

                    if (numberOfObjs_UpDown.Value == 0)
                    {
                        f.replace(memoryStream.ToArray(), this);
                        return;
                    }

                    for (int i = 1; i <= numberOfObjs_UpDown.Value; i++)
                    {
                        bw.BaseStream.Position = 0x8 - 0x8 + (i * 0x8);
                        if (objn_xAlign[i] == 0)
                        {
                            bw.Write(objn_xPos[i]);
                        }
                        else if (objn_xAlign[i] == 1)
                        {
                            bw.Write((ushort)(objn_xPos[i] + 0x1000));
                        }
                        else if (objn_xAlign[i] == 2)
                        {
                            bw.Write((ushort)(objn_xPos[i] + 0x2000));
                        }

                        bw.BaseStream.Position = 0xA - 0x8 + (i * 0x8);
                        if (objn_yAlign[i] == 0)
                        {
                            bw.Write(objn_yPos[i]);
                        }
                        else if (objn_yAlign[i] == 1)
                        {
                            bw.Write((ushort)(objn_yPos[i] + 0x1000));
                        }
                        else if (objn_yAlign[i] == 2)
                        {
                            bw.Write((ushort)(objn_yPos[i] + 0x2000));
                        }

                        bw.BaseStream.Position = 0xC - 0x8 + (i * 0x8);
                        bw.BaseStream.WriteByte(objn_graphicID[i]);
                    }

                    bw.Write((ushort)0); //Padding
                    bw.Write((byte)0);   //Padding

                    f.replace(memoryStream.ToArray(), this);
                }
            }
        }
コード例 #3
0
        private void replaceFile(File f, String inputFile)
        {
            // NOTE: f.beginEdit(this) must be called before this function
            FileStream rfs = new FileStream(inputFile, 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);
        }
コード例 #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();
        }
コード例 #5
0
        public override void save()
        {
            byte[] data = str.ToArray();

            if (lz)
            {
                data = ROM.LZ77_Compress(data);
            }

            f.replace(data, this);
        }
コード例 #6
0
        public override void replace(byte[] newFile, object editor)
        {
            if (!isAGoodEditor(editor))
            {
                throw new Exception("NOT CORRECT EDITOR " + name);
            }

            if (comp == CompressionType.LZ)
            {
                parentFile.replace(ROM.LZ77_Compress(newFile, false), this);
            }
            else if (comp == CompressionType.LZWithHeader)
            {
                parentFile.replace(ROM.LZ77_Compress(newFile, true), this);
            }
            else if (comp == CompressionType.Yaz0)
            {
                parentFile.replace(ROM.Yaz0_Compress(newFile), this);
            }
            else
            {
                parentFile.replace(newFile, this);
            }
        }
コード例 #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();
        }
コード例 #8
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);
        }
コード例 #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
ファイル: ROMUserInfo.cs プロジェクト: poudink/NSMB-Editor
 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));
     }
 }
コード例 #12
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();
        }
コード例 #13
0
 public override void save(ExportedLevel level)
 {
     levelFile.replace(level.LevelFile, this);
     BGDatFile.replace(level.BGDatFile, this);
 }
コード例 #14
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     byte[] data = ((DynamicByteProvider)hexBox1.ByteProvider).Bytes.ToArray();
     f.replace(data, this);
 }