예제 #1
0
        private async void Randomize(object sender, EventArgs e)
        {
            if (working)
            {
                return;
            }
            ReadControlFlags(this);
            RandomizerOptions rand = options.Copy();

            rand.Language = (string)language.SelectedValue ?? "ENGLISH";
            if (!File.Exists(exe.Text) || game == FromGame.UNKNOWN)
            {
                setStatus("Game exe not set", true);
                return;
            }
            string gameDir = Path.GetDirectoryName(exe.Text);

            if (!File.Exists($@"{gameDir}\map\MapStudio\m10_02_00_00.msb"))
            {
                setStatus("Did not find unpacked installation at game path", true);
                return;
            }
            if (rand["start"] && !rand["boss"] && !rand["world"])
            {
                setStatus("Cannot start outside of Asylum if no Asylum fog gates are randomized", true);
                return;
            }
            if (fixedseed.Text.Trim() != "")
            {
                if (uint.TryParse(fixedseed.Text.Trim(), out uint seed))
                {
                    rand.Seed = (int)seed;
                }
                else
                {
                    setStatus("Invalid fixed seed", true);
                    return;
                }
            }
            else
            {
                rand.Seed = new Random().Next();
            }
            working         = true;
            randomizeL.Text = $"Seed: {rand.Seed}";
            randb.Text      = $"Randomizing...";
            setStatus("Randomizing...");
            randb.BackColor = Color.LightYellow;
            Randomizer randomizer = new Randomizer();
            await Task.Factory.StartNew(() => {
                Directory.CreateDirectory("runs");
                string runId      = $@"runs\{DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss")}_log_{rand.Seed}_{rand.ConfigHash()}.txt";
                TextWriter log    = File.CreateText(runId);
                TextWriter stdout = Console.Out;
                Console.SetOut(log);
                try
                {
                    ItemReader.Result itemInfo = randomizer.Randomize(rand, game, gameDir, gameDir);
                    setStatus($"Done. Info in {runId}" + (itemInfo.Randomized ? $" | Key item hash: {itemInfo.ItemHash}" : ""));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    setStatus($"Error! See error message in {runId}", true);
                }
                finally
                {
                    log.Close();
                    Console.SetOut(stdout);
                }
            });

            randb.Enabled   = true;
            randb.Text      = $"Randomize!";
            randb.BackColor = SystemColors.Control;
            working         = false;
            UpdateExePath();
        }
예제 #2
0
        private async void Randomize(object sender, EventArgs e)
        {
            if (working)
            {
                return;
            }
            ReadControlFlags(this);
            // TODO: Allow this to be empty
            string gameDir = null;

            if (!string.IsNullOrWhiteSpace(exe.Text))
            {
                gameDir = Path.GetDirectoryName(exe.Text);
                if (!File.Exists($@"{gameDir}\Data0.bdt"))
                {
                    SetError("Error: Data0.bdt not found for the mod to merge. Leave it blank to use Fog Gate Randomizer by itself.");
                    return;
                }
                if (new DirectoryInfo(gameDir).FullName == Directory.GetCurrentDirectory())
                {
                    SetError("Error: Data0.bdt is not from a different mod! Leave it blank to use Fog Gate Randomizer by itself.");
                    return;
                }
            }
            if (fixedseed.Text.Trim() != "")
            {
                if (uint.TryParse(fixedseed.Text.Trim(), out uint seed))
                {
                    options.Seed = (int)seed;
                }
                else
                {
                    SetError("Invalid fixed seed");
                    return;
                }
            }
            else
            {
                options.Seed = new Random().Next();
            }
            fixedseed.Text = options.Seed.ToString();
            UpdateOptions(null, null);  // Can split up maybe
            SetError();

            working = true;
            string prevText = randb.Text;

            randb.Text = $"Randomizing...";
            setStatus("Randomizing...");
            RandomizerOptions rand = options.Copy();

            randb.BackColor = Color.LightYellow;
            Randomizer randomizer = new Randomizer();
            await Task.Factory.StartNew(() => {
                Directory.CreateDirectory("spoiler_logs");
                string runId      = $@"spoiler_logs\{DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss")}_log_{rand.Seed}_{rand.ConfigHash()}.txt";
                TextWriter log    = File.CreateText(runId);
                TextWriter stdout = Console.Out;
                Console.SetOut(log);
                try
                {
                    ItemReader.Result itemInfo = randomizer.Randomize(rand, FromGame.DS3, gameDir, Directory.GetCurrentDirectory());
                    setStatus($"Done. Info in {runId} | Restart your game!" + (itemInfo.Randomized ? $" | Key item hash: {itemInfo.ItemHash}" : ""), success: true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    SetError($"Error encountered: {ex.Message}\r\n\r\nIt may work to try again with a different seed. {(gameDir == null ? "" : "The merged mod might also not be compatible. ")}See most recent file in spoiler_logs directory for the full error.");
                    setStatus($"Error! See error message in {runId}", true);
                }
                finally
                {
                    log.Close();
                    Console.SetOut(stdout);
                }
            });

            randb.Enabled   = true;
            randb.Text      = prevText;
            randb.BackColor = SystemColors.Control;
            working         = false;
            UpdateExePath();
        }