Example #1
0
        private void WriteRom(RandomizerOptions options)
        {
            string usedFilename = FileName.Fix(options.Filename, string.Format(romLocations.SeedFileString, seed), complexity);

            using (var rom = new FileStream(usedFilename, FileMode.OpenOrCreate))
            {
                rom.Write(Resources.RomImage, 0, 2097152);

                if (options.NoRandomization)
                {
                    return;
                }

                foreach (var location in romLocations.Locations)
                {
                    var newItem = (byte)location.Item.HexValue;
                    rom.WriteBytes(location.Address, newItem);
                    location.WriteItemCheck?.Invoke(rom, location.Item);
                }
                foreach (var location in romLocations.SpecialLocations)
                {
                    if (location.Address != default(int))
                    {
                        var newItem = (byte)location.Item.HexValue;
                        rom.WriteBytes(location.Address, newItem);
                    }
                    location.WriteItemCheck?.Invoke(rom, location.Item);
                }

                WriteSeedInRom(rom, options);
                WriteRngItems(rom);
                rom.WriteBytes(0x180033, (byte)options.HeartBeepSpeed);
                rom.WriteBytes(0x180040, (byte)random.Next(0x20));

                if (options.SramTrace)
                {
                    WriteSramTraceToRom(rom);
                }

                if (RandomizerVersion.Debug)
                {
                    WriteDebugModeToRom(rom);
                }

                rom.Close();
            }

            log?.WriteLog(usedFilename);
        }
Example #2
0
        public string CreateRom(RandomizerOptions options)
        {
            try
            {
                String filePath = FileName.Fix(options.Filename, string.Format(romLocations.SeedFileString, seed), complexity);
                if (filePath.Contains("\\") && !Directory.Exists(filePath.Substring(0, filePath.LastIndexOf('\\'))))
                {
                    Directory.CreateDirectory(filePath.Substring(0, filePath.LastIndexOf('\\')));
                }

                if (!options.NoRandomization)
                {
                    GenerateItemList();
                    RandomizeQuestItems();
                    GenerateItemPositions();

                    if (log != null || options.ShowComplexity)
                    {
                        CalculateComplexity();
                    }

                    if (RandomizerVersion.Debug)
                    {
                        SetupTestItems(romLocations.Locations);
                    }

                    if (options.SpoilerOnly)
                    {
                        return(log?.GetLogOutput());
                    }
                }
                WriteRom(options);

                return("");
            }
            catch (Exception ex)
            {
                var newEx = new RandomizationException(string.Format("Error creating seed: {0}.", string.Format(romLocations.SeedFileString, seed)), ex);

                throw newEx;
            }
        }