private void WriteRom(string filename)
        {
            string usedFilename = FileName.Fix(filename, string.Format(romLocations.SeedFileString, seed));

            using (var rom = new FileStream(usedFilename, FileMode.OpenOrCreate))
            {
                var romImg = applyBasePatch(romImage, romRegion ? Resources.ALttP_JP_MOD : Resources.ALttP_US_MOD);
                rom.Write(romImg, 0, 8388608);

                foreach (var location in romLocations.Locations)
                {
                    rom.Seek(romRegion ? location.Address_JP : location.Address_US, SeekOrigin.Begin);
                    var newItem = (byte)location.Item.HexValue;

                    rom.Write(new [] { newItem }, 0, 1);

                    location.WriteItemCheck?.Invoke(rom, location.Item.Type, romRegion);
                }

                WriteSeedInRom(rom);
                rom.Close();
            }

            log?.WriteLog(usedFilename);
        }
Ejemplo n.º 2
0
        public string CreateRom(string filename, string seed)
        {
            itemsPos = 0;

            if (string.IsNullOrWhiteSpace(seed))
            {
                GenerateItemList();
            }
            else
            {
                ParseSeed(seed);
            }

            var rom = new FileStream(FileName.Fix(filename, GetSeed()), FileMode.OpenOrCreate);

            rom.Write(Resources.RomImage, 0, 3145728);

            WriteMajorItems(ref rom);

            WriteMinorItems(ref rom);

            //Handle the Etecoon's item
            rom.Seek(EXTRA_CHOZO_PB_ADDR + 2, SeekOrigin.Begin);
            WriteItem(ref rom, chozoPickups[items[itemsPos]]);

            WriteControls(rom);

            rom.Close();

            return(GetSeed());
        }
Ejemplo n.º 3
0
        private void WriteRom(string filename)
        {
            string usedFilename = FileName.Fix(filename, string.Format(romLocations.SeedFileString, seed));

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

                foreach (var location in romLocations.Locations)
                {
                    rom.Seek(location.Address, SeekOrigin.Begin);
                    var newItem = (byte)location.Item.HexValue;

                    rom.Write(new [] { newItem }, 0, 1);

                    location.WriteItemCheck?.Invoke(rom, location.Item.Type);
                }

                WriteSeedInRom(rom);

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

                rom.Close();
            }

            log?.WriteLog(usedFilename);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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;
            }
        }
        private void WriteRom(string filename)
        {
            string usedFilename  = FileName.Fix(filename, string.Format(romLocations.SeedFileString, seed));
            var    hideLocations = !(romLocations is RomLocationsCasual);

            using (var rom = new FileStream(usedFilename, FileMode.OpenOrCreate))
            {
                //rom.Write(Resources.RomImageSMPB072VP, 0, 3211264);
                //For the vanilla palettes version


                rom.Write(Resources.RomImage, 0, 4194304);


                foreach (var location in romLocations.Locations)
                {
                    rom.Seek(location.Address, SeekOrigin.Begin);
                    var newItem = new byte[2];

                    if (!location.NoHidden && location.Item.Type != ItemType.Nothing && location.Item.Type != ItemType.ChargeBeam && location.ItemStorageType == ItemStorageType.Normal)
                    {
                        // hide the item half of the time (to be a jerk)
                        if (hideLocations && random.Next(2) == 0)
                        {
                            location.ItemStorageType = ItemStorageType.Hidden;
                        }
                    }

                    switch (location.ItemStorageType)
                    {
                    case ItemStorageType.Normal:
                        newItem = StringToByteArray(location.Item.Normal);
                        break;

                    case ItemStorageType.Hidden:
                        newItem = StringToByteArray(location.Item.Hidden);
                        break;

                    case ItemStorageType.Chozo:
                        newItem = StringToByteArray(location.Item.Chozo);
                        break;
                    }

                    rom.Write(newItem, 0, 2);

                    if (location.Item.Type == ItemType.Nothing)
                    {
                        // give same index as morph ball
                        rom.Seek(location.Address + 4, SeekOrigin.Begin);
                        rom.Write(StringToByteArray("\x0c"), 0, 1);
                    }

                    if (location.Item.Type == ItemType.ChargeBeam)
                    {
                        // we have 4 copies of charge to reduce tedium, give them all the same index
                        //I chose to remove this for now to make it a bit more obvious that there aren't mistakes in the randomizing process
                        rom.Seek(location.Address + 4, SeekOrigin.Begin);
                        rom.Write(StringToByteArray("\xff"), 0, 1);
                        //index ff may cause problems
                    }
                }

                WriteSeedInRom(rom);
                WriteControls(rom);

                rom.Close();
            }

            if (log != null)
            {
                log.WriteLog(usedFilename);
            }
        }
Ejemplo n.º 7
0
        private void WriteRom(string filename)
        {
            string usedFilename  = FileName.Fix(filename, string.Format(romLocations.SeedFileString, seed));
            var    hideLocations = !(romLocations is RomLocationsCasual);

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

                foreach (var location in romLocations.Locations)
                {
                    rom.Seek(location.Address, SeekOrigin.Begin);
                    var newItem = new byte[2];

                    if (!location.NoHidden && location.Item.Type != ItemType.Nothing && location.Item.Type != ItemType.ChargeBeam && location.ItemStorageType == ItemStorageType.Normal)
                    {
                        // hide the item half of the time (to be a jerk)
                        if (hideLocations && random.Next(2) == 0)
                        {
                            location.ItemStorageType = ItemStorageType.Hidden;
                        }
                    }

                    switch (location.ItemStorageType)
                    {
                    case ItemStorageType.Normal:
                        newItem = StringToByteArray(location.Item.Normal);
                        break;

                    case ItemStorageType.Hidden:
                        newItem = StringToByteArray(location.Item.Hidden);
                        break;

                    case ItemStorageType.Chozo:
                        newItem = StringToByteArray(location.Item.Chozo);
                        break;
                    }

                    rom.Write(newItem, 0, 2);

                    if (location.Item.Type == ItemType.Nothing)
                    {
                        // give same index as morph ball
                        rom.Seek(location.Address + 4, SeekOrigin.Begin);
                        rom.Write(StringToByteArray("\x1a"), 0, 1);
                    }

                    if (location.Item.Type == ItemType.ChargeBeam)
                    {
                        // we have 4 copies of charge to reduce tedium, give them all the same index
                        rom.Seek(location.Address + 4, SeekOrigin.Begin);
                        rom.Write(StringToByteArray("\xff"), 0, 1);
                    }
                }

                WriteSeedInRom(rom);
                WriteControls(rom);

                rom.Close();
            }

            if (log != null)
            {
                log.WriteLog(usedFilename);
            }
        }