Beispiel #1
0
        static void Main(string[] args)
        {
            // Force english language, for exceptions
            System.Threading.Thread.CurrentThread.CurrentCulture   = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;

            if (args.Length == 0)
            {
                Console.WriteLine(AppDomain.CurrentDomain.FriendlyName + " [asm_patch] <options...>");
                Console.WriteLine();
                Console.WriteLine("RUN MODE");
                Console.WriteLine("\t--macro           Generate patch file as preprocessor macro (default)");
                Console.WriteLine("\t--procedure       Generate patch file as inline procedure");
                Console.WriteLine("\t--memory          Write the code directly into Fallout2.exe");
                Console.WriteLine();
                Console.WriteLine("SSL GENERATION");
                Console.WriteLine("\t--no-lower        Hex values won't be lowercased");
                Console.WriteLine("\t--no-macro-guard  Macros won't be guarded with begin/end");
                Console.WriteLine("\t--no-pack         Force using write_byte() function only");
                Console.WriteLine("\t--update-file     Apply changes to given file");
                Console.WriteLine("\t--malloc          Use dynamically allocated memory in patches where requested");
                Console.WriteLine();
                Console.WriteLine("GENERATORS");
                Console.WriteLine("\t--sfall-assert    Generate a patch to assert that code is correct");
                Console.WriteLine();
                Console.WriteLine("PATCH VARIABLES");
                Console.WriteLine("\t--memory-args     Set memory variables");
                Console.WriteLine();
                Console.WriteLine("DEBUGGING");
                Console.WriteLine("\t-r                Console.ReadKey() on exit");
                Console.WriteLine();
                Console.WriteLine("ERROR HANDLING");
                Console.WriteLine("\t-strict           Use strict error handling");

                return;
            }

            bool malloc    = false;
            bool readKey   = false;
            bool runEngine = true;
            var  engine    = new PatchEngine();

            foreach (var a in args)
            {
                // run mode
                if (a == "--macro")
                {
                    engine.runMode = RunMode.Macro;
                }
                else if (a == "--procedure")
                {
                    engine.runMode = RunMode.Procedure;
                }
                else if (a == "--memory")
                {
                    engine.runMode = RunMode.Memory;
                }
                // ssl generation
                else if (a == "--no-pack")
                {
                    engine.protossl.Pack = false;
                }
                else if (a == "--no-lower")
                {
                    engine.protossl.Lower = false;
                }
                else if (a == "--no-macro-guard")
                {
                    engine.protossl.MacroGuard = false;
                }
                else if (a == "--malloc")
                {
                    engine.protossl.Malloc = true;
                }
                else if (a == "-r")
                {
                    readKey = true;
                }
                else if (a == "-strict")
                {
                    Error.Strict = true;
                }
                else if (a.StartsWith("--memory-args="))
                {
                    engine.ParseMemoryArgs(a);
                }
                else if (a.StartsWith("--sfall-assert=")) // --sfall-assert=name,hook_address,bytes
                {
                    Asserts.Sfall.ParseAndRunAssertArgs(a);
                    runEngine = false;
                }
                else if (a.StartsWith("--update-file="))
                {
                    string filename = a.Replace("--update-file=", "");
                    engine.currentFilename = filename;
                    engine.updateFile.SetData(filename, engine.SafeReadAllLines(filename));
                }
                else
                {
                    if (Directory.Exists(a))
                    {
                        Directory.GetFiles(a, "*.asm").OrderBy(x => x).ToList().ForEach(x => engine.AddPatch(x));
                    }
                    else
                    {
                        engine.AddPatch(a);
                    }
                }
            }

            if (runEngine)
            {
                engine.Run();
            }

            if (readKey)
            {
                Console.ReadKey();
            }
        }
Beispiel #2
0
        public void LoadSettings(FileParser.Block block)
        {
            string fileName = block.GetString("ROM");

            if (!System.IO.File.Exists(fileName))
            {
                string prompt = "File " + fileName + " does not exist anymore. Do you want to load another ROM?";
                if (fileName != "" && MessageBox.Show(prompt, "ROM not found.", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "z64 ROMs|*.z64";
                if (SM64RAM.EmulationState.instance.ROMName != "")
                {
                    fileName = SM64RAM.EmulationState.instance.ROMName;
                }
                else
                {
                    if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }
                    fileName = dlg.FileName;
                }
            }
            RAMControl.LoadROM(fileName);
            runLevelScripts.Clear();
            if (SM64RAM.EmulationState.instance.ROM == null)
            {
                EmulationState.messages.AppendMessage("An error occured while loading the ROM. Make sure no other programs are using the ROM file right now and try again.", "Error");
                return;
            }

            segmentedAddress     = block.GetInt("Base Offset", false);
            txtBaseOffset.Text   = segmentedAddress.ToString("X8");
            Settings.importScale = block.GetInt("Import Scale", false);
            if (Settings.importScale == 0)
            {
                Settings.importScale = 1000;
            }
            numScale.Value = Math.Max((int)numScale.Minimum, Math.Min((int)numScale.Maximum, (int)Settings.importScale));

            FileParser.Block globalBlock = block.GetBlock("Globals", false);
            if (globalBlock != null)
            {
                globalsControl.LoadSettings(globalBlock);
            }

            //Apply patches if necessary / desired
            string patchString = block.GetString("Patches", false);

            if (patchString != "" && MessageBox.Show("Apply level patches?", "Patch ROM", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                PatchEngine.Run(patchString, Path.GetDirectoryName(block.fileName));
            }

            runLevelScripts.AddRange(block.GetIntArray("Run level scripts"));
            RunLevelScripts();

            textureLibrary.textures.Clear();
            displayLists.Clear();
            collisionMaps.Clear();
            SuspendLayout();
            tabImports.TabPages.Clear();
            tabImports.TabPages.Add(tabPagePlus);

            //Load Display List Data
            int numDls = block.GetInt("NumDisplayLists");

            for (int i = 0; i < numDls; i++)
            {
                DisplayListControl newControl = new DisplayListControl();
                newControl.PerformLayout();
                newControl.LoadSettings(block.GetBlock("DisplayList" + i));
                AddDisplayList(newControl);
            }

            textureLibrary.LoadSettings(block.GetBlock("Textures", false));

            //Load Collision Map Data
            int numCMaps = block.GetInt("NumCollisionMaps");

            for (int i = 0; i < numCMaps; i++)
            {
                CollisionControl newControl = new CollisionControl();
                newControl.PerformLayout();
                newControl.LoadSettings(block.GetBlock("CollisionMap" + i));
                AddCollision(newControl);
            }
            ResumeLayout();
        }