コード例 #1
0
ファイル: Randomizer.cs プロジェクト: jewinters/maelstrom
        // update battle archive
        private static void BattleOps(int seed, SpoilerFile spoilerFile, State settings)
        {
            Debug.WriteLine("battle ops start");
            while (true)
            {
                try
                {
                    CreateOrRestoreArchiveBackup(Globals.BattlePath);
                    var battleSource = new FileSource(Globals.BattlePath);

                    // boss shuffle
                    if (settings.BossEnable)
                    {
                        var bossMap = Boss.Randomise(seed, settings);
                        if (settings.SpoilerFile)
                        {
                            spoilerFile.AddBosses(bossMap);
                        }
                        Boss.Apply(battleSource, bossMap);
                    }

                    // loot shuffle
                    var drops  = settings.LootDrops;
                    var steals = settings.LootSteals;
                    var draws  = settings.LootDraws;

                    if (drops || steals || draws)
                    {
                        var shuffle = LootShuffle.Randomise(battleSource, seed, settings);
                        if (settings.SpoilerFile)
                        {
                            spoilerFile.AddLoot(shuffle, drops, steals, draws);
                        }
                    }

                    if (settings.BossEnable || drops || steals || draws)
                    {
                        battleSource.Encode();
                    }

                    break;
                }
                catch (Exception x)
                {
                    if (x is IOException || x is UnauthorizedAccessException || x is FileNotFoundException)
                    {
                        if (HandleFileException(Globals.BattlePath) == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            Debug.WriteLine("battle ops end");
        }
コード例 #2
0
ファイル: Randomizer.cs プロジェクト: jewinters/maelstrom
        private static void MainOps(int seed, SpoilerFile spoilerFile, State settings)
        {
            Debug.WriteLine("main ops start");
            while (true)
            {
                try
                {
                    CreateOrRestoreArchiveBackup(Globals.MainPath);
                    var mainSource = new FileSource(Globals.MainPath);

                    // ability shuffle
                    if (settings.GfAbilitiesEnable)
                    {
                        var shuffle = AbilityShuffle.Randomise(mainSource, seed, settings);
                        if (settings.SpoilerFile)
                        {
                            spoilerFile.AddAbilities(shuffle);
                        }
                    }

                    mainSource.Encode();
                    break;
                }
                catch (Exception x)
                {
                    if (x is IOException || x is UnauthorizedAccessException || x is FileNotFoundException)
                    {
                        if (HandleFileException(Globals.MainPath) == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            Debug.WriteLine("main ops end");
        }
コード例 #3
0
ファイル: Randomizer.cs プロジェクト: jewinters/maelstrom
        // update multiple files on 2nd pass
        private static void FinalOps(int seed, string seedString, SpoilerFile spoilerFile, State settings)
        {
            Debug.WriteLine("final ops start");
            while (true)
            {
                try
                {
                    // weapon shuffle
                    if (settings.UpgradeEnable)
                    {
                        var mainSource = new FileSource(Globals.MainPath);
                        var menuSource = new FileSource(Globals.MenuPath);

                        var shuffle = WeaponShuffle.Randomise(seed);
                        if (settings.SpoilerFile)
                        {
                            spoilerFile.AddWeapons(mainSource, shuffle);
                        }
                        WeaponShuffle.Apply(menuSource, shuffle);

                        menuSource.Encode();
                    }

                    // free roam rewards
                    if (settings.FreeRoam || settings.BossEnable)
                    {
                        var battleSource = new FileSource(Globals.BattlePath);
                        var fieldSource  = new FileSource(Globals.FieldPath);

                        if (settings.FreeRoam)
                        {
                            Reward.SetRewards(battleSource, fieldSource, seed);
                        }
                        if (settings.BossEnable)
                        {
                            Boss.ApplyEdeaFix(battleSource, fieldSource);
                        }

                        battleSource.Encode();
                        fieldSource.Encode();
                    }
                    break;
                }
                catch (Exception x)
                {
                    if (x is IOException || x is UnauthorizedAccessException || x is FileNotFoundException)
                    {
                        if (HandleFileException(Globals.BattlePath) == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            // save spoiler file
            if (settings.SpoilerFile)
            {
                // strip illegal chars from filename

                File.WriteAllText("spoilers." + SanitizeFileName(seedString) + ".txt", spoilerFile.ToString());
            }
            Debug.WriteLine("final ops end");
        }
コード例 #4
0
ファイル: Randomizer.cs プロジェクト: jewinters/maelstrom
        // update menu archive
        private static void MenuOps(int seed, SpoilerFile spoilerFile, State settings)
        {
            Debug.WriteLine("menu ops start");
            while (true)
            {
                try
                {
                    CreateOrRestoreArchiveBackup(Globals.MenuPath);
                    var menuSource = new FileSource(Globals.MenuPath);

                    // preset names
                    if (settings.NameEnable)
                    {
                        PresetNames.Apply(menuSource, settings);
                    }

                    // shop shuffle
                    if (settings.ShopEnable)
                    {
                        var shuffle = ShopShuffle.Randomise(seed, settings);
                        if (settings.SpoilerFile)
                        {
                            spoilerFile.AddShops(shuffle);
                        }
                        ShopShuffle.Apply(menuSource, shuffle);
                    }

                    // draw point shuffle
                    if (!Globals.Remastered)
                    {
                        if (settings.DrawPointEnable)
                        {
                            var shuffle = DrawPointShuffle.Randomise(seed, settings);
                            if (settings.SpoilerFile)
                            {
                                spoilerFile.AddDrawPoints(shuffle);
                            }
                            DrawPointShuffle.Apply(menuSource, shuffle);
                        }
                        else
                        {
                            DrawPointShuffle.RemovePatch(Globals.ExePath);
                        }
                    }

                    if (settings.NameEnable || settings.ShopEnable || (settings.DrawPointEnable && !Globals.Remastered))
                    {
                        menuSource.Encode();
                    }

                    break;
                }
                catch (Exception x)
                {
                    if (x is IOException || x is UnauthorizedAccessException || x is FileNotFoundException)
                    {
                        if (HandleFileException(Globals.MenuPath) == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            Debug.WriteLine("menu ops end");
        }
コード例 #5
0
ファイル: Randomizer.cs プロジェクト: jewinters/maelstrom
        // update field archive (and af3dn.p)
        private static void FieldOps(int seed, string seedString, SpoilerFile spoilerFile, State settings)
        {
            Debug.WriteLine("field ops start");
            while (true)
            {
                try
                {
                    CreateOrRestoreArchiveBackup(Globals.FieldPath);
                    var fieldSource = new FileSource(Globals.FieldPath);

                    // apply free roam
                    if (settings.FreeRoam)
                    {
                        FreeRoam.Apply(fieldSource, seedString);
                    }
                    else
                    {
                        FreeRoam.Remove();
                    }

                    // apply card shuffle
                    if (settings.CardEnable)
                    {
                        var shuffle = CardShuffle.Shuffle(seed);
                        if (settings.SpoilerFile)
                        {
                            spoilerFile.AddCards(shuffle);
                        }
                        CardShuffle.Apply(fieldSource, shuffle);
                    }

                    // apply music shuffle
                    if (settings.MusicEnable)
                    {
                        var shuffle = MusicShuffle.Randomise(seed, settings);
                        if (settings.SpoilerFile)
                        {
                            spoilerFile.AddMusic(shuffle);
                        }
                        MusicShuffle.Apply(fieldSource, shuffle);
                    }

                    // write to file
                    if (settings.FreeRoam || settings.CardEnable || settings.MusicEnable)
                    {
                        fieldSource.Encode();
                    }

                    break;
                }
                catch (Exception x)
                {
                    if (x is IOException || x is UnauthorizedAccessException || x is FileNotFoundException)
                    {
                        if (HandleFileException(Globals.FieldPath) == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            Debug.WriteLine("field ops end");
        }
コード例 #6
0
ファイル: Randomizer.cs プロジェクト: jewinters/maelstrom
        public static void Go()
        {
            Debug.WriteLine("randomizer start");

            var settings = State.Current.Clone();

            Globals.ExePath = settings.GameLocation;

            if (!File.Exists(Globals.ExePath))
            {
                HandleExeException(Globals.ExePath);
                return;
            }

            // update game version
            if (!DetectVersion(Globals.ExePath))
            {
                HandleExeException(Globals.ExePath);
                return;
            }

            // set region
            Globals.RegionCode = settings.Language;

            // generate new seed if not fixed
            if (!settings.SeedFixed)
            {
                settings.SeedValue = (new Random().Next(-1, int.MaxValue) + 1).ToString();
            }
            var seedString = settings.SeedValue;

            // update seed history
            if (State.Current.History == null)
            {
                State.Current.History = new List <string>();
            }
            State.Current.History.RemoveAll(s => s == seedString);
            State.Current.History.Insert(0, seedString);
            if (State.Current.History.Count > 50)
            {
                State.Current.History = State.Current.History.Take(50).ToList();
            }

            // use seed string's hash code as the seed (or parse if possible)
            if (!int.TryParse(seedString, out int seed))
            {
                seed = seedString.GetHashCode();
            }

            var spoilerFile = new SpoilerFile();

            if (Globals.Remastered)
            {
                UnpackOnFirstRun();
            }

            Parallel.Invoke
            (
                () => BattleOps(seed, spoilerFile, settings),
                () => FieldOps(seed, seedString, spoilerFile, settings),
                () => MenuOps(seed, spoilerFile, settings),
                () => MainOps(seed, spoilerFile, settings)
            );

            FinalOps(seed, seedString, spoilerFile, settings);
            if (Globals.Remastered)
            {
                RepackArchive();
            }

            Debug.WriteLine("randomizer end");
        }