forked from Galamoz/HyperMetroidRandomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
88 lines (79 loc) · 3.32 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CommandLine; // from NuGet
using SuperMetroidRandomizer.Random;
namespace SuperMetroidRandomizer
{
static class Program
{
public class Options
{
[Option('s', "seed", Required = false, Default = 0, HelpText = "Seed number to produce the same randomization as someone else using the same copy of this program (0 or unset -> random seed)")]
public int seed { get; set; }
[Option('d', "difficulty", Required = true, HelpText = "Difficulty: Casual, Veteran, Masochist, or Max")]
public string difficulty { get; set; }
}
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
CommandLine.Parser.Default.ParseArguments<Options>(args)
.WithParsed(Main2)
.WithNotParsed(HandleParserError);
}
public static void HandleParserError(IEnumerable<Error> errs)
{
Environment.Exit(1);
}
static public void Main2(Options cli)
{
string difficultyStr = cli.difficulty;
difficultyStr = difficultyStr.ToLower();
if (difficultyStr.Length > 0 ) {
difficultyStr = char.ToUpper(difficultyStr[0]) + difficultyStr.Substring(1);
}
RandomizerDifficulty difficulty;
switch (difficultyStr) {
case "Casual":
difficulty = RandomizerDifficulty.Casual;
break;
case "Veteran":
difficulty = RandomizerDifficulty.Speedrunner;
break;
case "Masochist":
difficulty = RandomizerDifficulty.Masochist;
break;
case "Max":
difficulty = RandomizerDifficulty.Max;
break;
default:
Console.WriteLine("--difficulty <Casual, Veteran, Masochist, Max> is required");
return;
}
int seed;
if (cli.seed == 0) {
seed = (new SeedRandom()).Next(10 * 1000 * 1000); // 10 million possible random seeds.
} else {
seed = cli.seed;
}
string romname = string.Format("Hyper Metroid {0}{1:0000000}.sfc",
(difficulty == RandomizerDifficulty.Max ? 'X' : difficultyStr[0]),
seed);
var romLocations = SuperMetroidRandomizer.Rom.RomLocationsFactory.GetRomLocations(difficulty);
var randomizerV11 = new RandomizerV11(seed, romLocations, null);
string ret = randomizerV11.CreateRom(romname);
if (ret == "OK")
{
Console.WriteLine("Wrote: {0}", romname);
} else {
// ret should contain an error
Console.WriteLine("(Version {0})", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
Console.WriteLine(ret);
Environment.Exit(1);
}
}
}
}