-
Notifications
You must be signed in to change notification settings - Fork 0
/
MM2.cs
137 lines (113 loc) · 3.71 KB
/
MM2.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using ProjectFox.CoreEngine.Collections;
using IPSLib;
namespace MM2Randomizer;
public static class MM2
{
private static readonly Equipment[]
weapons =
{
Equipment.AtomicFire,
Equipment.AirShooter,
Equipment.LeafShield,
Equipment.BubbleLead,
Equipment.QuickBoomerang,
Equipment.FlashStopper,
Equipment.MetalBlade,
Equipment.CrashBomber
},
items =
{
Equipment.Item1,
Equipment.Item3,
Equipment.None,
Equipment.None,
Equipment.None,
Equipment.None,
Equipment.None,
Equipment.Item2,
};
private static readonly StageIndex[] stages =
{
StageIndex.HeatStage,
StageIndex.AirStage,
StageIndex.WoodStage,
StageIndex.BubbleStage,
StageIndex.QuickStage,
StageIndex.FlashStage,
StageIndex.MetalStage,
StageIndex.CrashStage
};
private static int GetSeed()
{
int ms = Environment.TickCount;
DateTime now = DateTime.Now;
return ms ^ ((now.Year * 10000) + (now.Month * 100) + now.Day);
}
private static IPS ShuffleItemsPatch(ref string spoiler, Random r = null, bool heatManNoItem2 = false)
{
r ??= new(GetSeed());
spoiler += "\n";
AutoSizedArray<Equipment> equips = new(items);
byte[] data = new byte[equips.Length];
Address address = Address.HeatStageItem;
for (int i = 0; equips.Length > 0; i++, address++)
{
int n = r.Next(equips.Length - (heatManNoItem2 && i == 0 ? 1 : 0));
Equipment e = equips[n];
spoiler += $"{address} => {e}\n";
data[i] = (byte)e;
equips.RemoveAt(n);
}
IPS ips = new();
ips.Add(false, (int)Address.HeatStageItem, data);
return ips;
}
private static IPS ShuffleStagesPatch(ref string spoiler, Random r = null)
{
r ??= new(GetSeed());
spoiler += "\n";
AutoSizedArray<StageIndex> stages = new(MM2.stages);
byte[] data = new byte[stages.Length];
Address address = Address.BubbleStagePtr;
for (int i = 0; stages.Length > 0; i++, address++)
{
int n = r.Next(stages.Length);
StageIndex si = stages[n];
spoiler += $"{address} => {si}\n";
data[i] = (byte)si;
stages.RemoveAt(n);
}
IPS ips = new();
ips.Add(false, (int)Address.BubbleStagePtr, data);
return ips;
}
private static IPS ShuffleWeaponsPatch(ref string spoiler, Random r = null)
{
r ??= new(GetSeed());
AutoSizedArray<Equipment> equips = new(weapons);
byte[] data = new byte[equips.Length];
Address address = Address.HeatStageWeapon;
for (int i = 0; equips.Length > 0; i++, address++)
{
int n = r.Next(equips.Length);
Equipment e = equips[n];
spoiler += $"{address} => {e}\n";
data[i] = (byte)e;
equips.RemoveAt(n);
}
IPS ips = new();
ips.Add(false, (int)Address.WeaponBitMasks, data);
return ips;
}
public static void Generate(ref IPS ips, ref int seed, out string spoiler, bool heatManNoItem2 = false, bool shuffleLevels = false)
{
if (seed == 0) seed = GetSeed();
ips ??= new();
spoiler = $"--- MM2R Spoiler Log ---\nSeed: {seed}\n\n";
Random r = new(seed);
ips.Add(ShuffleWeaponsPatch(ref spoiler, r), false);
ips.Add(ShuffleItemsPatch(ref spoiler, r, heatManNoItem2), false);
if (shuffleLevels) ips.Add(ShuffleStagesPatch(ref spoiler, r), false);
}
}