Exemplo n.º 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string langDir = System.IO.Path.Combine(Application.StartupPath, "Languages");
            string langFileName = System.IO.Path.Combine(langDir, Properties.Settings.Default.LanguageFile + ".ini");
            if (System.IO.File.Exists(langFileName))
            {
                System.IO.StreamReader rdr = new StreamReader(langFileName);
                LanguageManager.Load(rdr.ReadToEnd().Split('\n'));
                rdr.Close();
            }
            else
            {
                MessageBox.Show("File " + langFileName + " could not be found, so the language has defaulted to English.");
                LanguageManager.Load(Properties.Resources.English.Split('\n'));
            }

            string[] args = Environment.GetCommandLineArgs();

            if(args.Length == 2)
            {
                Console.Out.WriteLine("Loading ROM: "+args[1]);

                NitroROMFilesystem fs = new NitroROMFilesystem(args[1]);
                ROM.load(fs);

                SpriteData.Load();
                if (Properties.Settings.Default.mdi)
                    new MdiParentForm().Show();
                else
                    new LevelChooser().Show();
            }
            else
            {
                new StartForm().Show();
            }

            Application.Run();

            /*

            if(args.Length > 2 && args[2] == "asmpatch")
            {
                PatchMaker pm = new PatchMaker(ROM.romfile.Directory);
                pm.restore();
                pm.generatePatch();
            }
            else if(args.Length > 2 && args[2] == "getcodeaddr")
            {
                PatchMaker pm = new PatchMaker(ROM.romfile.Directory);
                pm.restore();
                Console.Out.WriteLine(String.Format("{0:X8}", pm.getCodeAddr()));
            }*/
        }
Exemplo n.º 2
0
        private void openRomButton_Click(object sender, EventArgs e)
        {

            string path = "";
            string[] backups = null;

            if (Properties.Settings.Default.BackupFiles != "" &&
                MessageBox.Show(LanguageManager.Get("StartForm", "OpenBackups"), LanguageManager.Get("StartForm", "OpenBackupsTitle"), MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                backups = Properties.Settings.Default.BackupFiles.Split(';');
                path = backups[0];
            }
            else
            {
                OpenFileDialog openROMDialog = new OpenFileDialog();
                openROMDialog.Filter = LanguageManager.Get("Filters", "rom");
                if (Properties.Settings.Default.ROMFolder != "")
                    openROMDialog.InitialDirectory = Properties.Settings.Default.ROMFolder;
                if (openROMDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    path = openROMDialog.FileName;
            }

            if (path == "")
                return;

            try
            {
                NitroROMFilesystem fs = new NitroROMFilesystem(path);
                Properties.Settings.Default.ROMFolder = System.IO.Path.GetDirectoryName(path);
                Properties.Settings.Default.Save();

                if (backups != null)
                    for (int l = 1; l < backups.Length; l++)
                        ROM.fileBackups.Add(backups[l]);

                run(fs);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        /**
         * 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));
        }
Exemplo n.º 4
0
 public Arm9BinaryHandler(NitroROMFilesystem fs)
 {
     f = fs.arm9binFile;
     this.fs = fs;
 }
Exemplo n.º 5
0
        public void makeBinBackup(int file)
        {
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(ROM.romfile.Directory.FullName+"/bak");
            Console.Out.WriteLine("Backing up " + file + " "+dir.FullName);
            if (!dir.Exists)
                dir.Create();

            dir = ROM.romfile.Directory;
            System.IO.FileStream fs;

            try
            {
                if (file == -1)
                    fs = new System.IO.FileStream(dir.FullName + "/bak/" + "main.bin", System.IO.FileMode.CreateNew);
                else
                    fs = new System.IO.FileStream(dir.FullName + "/bak/" + file + ".bin", System.IO.FileMode.CreateNew);
            }
            catch (System.IO.IOException) {return;}

            File f = ROM.FS.arm9binFile;
            if (file != -1)
            {
                f = ROM.FS.arm9ovs[file];
                ROM.FS.arm9ovs[file].decompress(); //b4ckupz r 41w4ys cmpr3zzd
            }

            fs.Write(f.getContents(), 0, f.fileSize);
            fs.Close();
        }
Exemplo n.º 6
0
        public static void load(String filename)
        {
            ROM.filename = filename;
            FS = new NitroROMFilesystem(filename);
            romfile = new System.IO.FileInfo(filename);

            ByteArrayInputStream header = new ByteArrayInputStream(FS.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();
            }
        }