-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSeldomArchipelago.cs
285 lines (259 loc) · 13.2 KB
/
SeldomArchipelago.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
using Mono.Cecil.Cil;
using MonoMod.Cil;
using System;
using SeldomArchipelago.Systems;
using Terraria;
using Terraria.Achievements;
using Terraria.DataStructures;
using Terraria.GameContent.Events;
using Terraria.ID;
using Terraria.ModLoader;
using System.IO;
using System.Reflection;
namespace SeldomArchipelago
{
public class SeldomArchipelago : Mod
{
// Terraria is single-threaded so this *should* be fine
bool temp;
public override void Load()
{
var archipelagoSystem = ModContent.GetInstance<ArchipelagoSystem>();
// Begin cursed IL editing
// Torch God reward Terraria.Player:13794
IL.Terraria.Player.TorchAttack += il =>
{
var cursor = new ILCursor(il);
cursor.GotoNext(i => i.MatchLdsfld(typeof(Main).GetField(nameof(Main.netMode))));
cursor.EmitDelegate(() => archipelagoSystem.QueueLocationClient("Torch God"));
cursor.Emit(OpCodes.Ret);
};
// Allow Torch God even if you have `unlockedBiomeTorches`
IL.Terraria.Player.UpdateTorchLuck_ConsumeCountersAndCalculate += il =>
{
var cursor = new ILCursor(il);
cursor.GotoNext(i => i.MatchLdfld(typeof(Player).GetField(nameof(Player.unlockedBiomeTorches))));
cursor.Index++;
cursor.Emit(OpCodes.Pop);
cursor.Emit(OpCodes.Ldc_I4_0);
cursor.GotoNext(i => i.MatchLdcI4(ItemID.TorchGodsFavor));
cursor.Emit(OpCodes.Pop);
cursor.Emit(OpCodes.Ldc_I4_0);
};
// General event clear locations
IL.Terraria.NPC.SetEventFlagCleared += il =>
{
var cursor = new ILCursor(il);
cursor.Emit(OpCodes.Ldarg_1);
cursor.EmitDelegate((int id) =>
{
var location = id switch
{
GameEventClearedID.DefeatedSlimeKing => "King Slime",
GameEventClearedID.DefeatedEyeOfCthulu => "Eye of Cthulhu",
GameEventClearedID.DefeatedEaterOfWorldsOrBrainOfChtulu => "Evil Boss",
GameEventClearedID.DefeatedGoblinArmy => "Goblin Army",
GameEventClearedID.DefeatedQueenBee => "Queen Bee",
GameEventClearedID.DefeatedSkeletron => "Skeletron",
GameEventClearedID.DefeatedDeerclops => "Deerclops",
GameEventClearedID.DefeatedWallOfFleshAndStartedHardmode => "Wall of Flesh",
GameEventClearedID.DefeatedPirates => "Pirate Invasion",
GameEventClearedID.DefeatedQueenSlime => "Queen Slime",
GameEventClearedID.DefeatedTheTwins => "The Twins",
GameEventClearedID.DefeatedDestroyer => "The Destroyer",
GameEventClearedID.DefeatedSkeletronPrime => "Skeletron Prime",
GameEventClearedID.DefeatedPlantera => "Plantera",
GameEventClearedID.DefeatedGolem => "Golem",
GameEventClearedID.DefeatedMartians => "Martian Madness",
GameEventClearedID.DefeatedFishron => "Duke Fishron",
GameEventClearedID.DefeatedHalloweenTree => "Mourning Wood",
GameEventClearedID.DefeatedHalloweenKing => "Pumpking",
GameEventClearedID.DefeatedChristmassTree => "Everscream",
GameEventClearedID.DefeatedSantank => "Santa-NK1",
GameEventClearedID.DefeatedIceQueen => "Ice Queen",
GameEventClearedID.DefeatedFrostArmy => "Frost Legion",
GameEventClearedID.DefeatedEmpressOfLight => "Empress of Light",
GameEventClearedID.DefeatedAncientCultist => "Lunatic Cultist",
GameEventClearedID.DefeatedMoonlord => "Moon Lord",
_ => null,
};
if (location != null) archipelagoSystem.QueueLocation(location);
});
cursor.Emit(OpCodes.Ret);
};
// Old One's Army locations
IL.Terraria.GameContent.Events.DD2Event.WinInvasionInternal += il =>
{
var cursor = new ILCursor(il);
foreach (var (flagName, tier) in new Tuple<string, int>[] {
Tuple.Create(nameof(DD2Event.DownedInvasionT1), 1),
Tuple.Create(nameof(DD2Event.DownedInvasionT2), 2),
Tuple.Create(nameof(DD2Event.DownedInvasionT3), 3),
})
{
var flag = typeof(DD2Event).GetField(flagName);
cursor.GotoNext(i => i.MatchStsfld(flag));
cursor.EmitDelegate<Action>(() => temp = (bool)flag.GetValue(null));
cursor.Index++;
cursor.EmitDelegate(() =>
{
flag.SetValue(null, temp);
archipelagoSystem.QueueLocation($"Old One's Army Tier {tier}");
});
}
};
IL.Terraria.NPC.DoDeathEvents += il =>
{
var cursor = new ILCursor(il);
// Prevent NPC.downedTower* from being set
foreach (var flag in new string[] { nameof(NPC.downedTowerSolar), nameof(NPC.downedTowerVortex), nameof(NPC.downedTowerNebula), nameof(NPC.downedTowerStardust) })
{
var field = typeof(NPC).GetField(flag, BindingFlags.Static | BindingFlags.Public);
cursor.GotoNext(i => i.MatchStsfld(field));
// Crimes
cursor.EmitDelegate<Action>(() => temp = (bool)field.GetValue(null));
cursor.Index++;
cursor.EmitDelegate(() => field.SetValue(null, temp));
}
// Prevent NPC.downedMechBossAny from being set
while (cursor.TryGotoNext(i => i.MatchStsfld(typeof(NPC).GetField(nameof(NPC.downedMechBossAny)))))
{
cursor.EmitDelegate<Action>(() => temp = NPC.downedMechBossAny);
cursor.Index++;
cursor.EmitDelegate<Action>(() => NPC.downedMechBossAny = temp);
}
// Prevent Hardmode generation Terraria.NPC:69104
cursor.GotoNext(i => i.MatchCall(typeof(WorldGen).GetMethod(nameof(WorldGen.StartHardmode))));
cursor.EmitDelegate(() =>
{
temp = Main.hardMode;
Main.hardMode = true;
});
cursor.Index++;
cursor.EmitDelegate<Action>(() => Main.hardMode = temp);
};
IL.Terraria.WorldGen.UpdateLunarApocalypse += il =>
{
var cursor = new ILCursor(il);
cursor.GotoNext(i => i.MatchCall(typeof(WorldGen).GetMethod(nameof(WorldGen.StartImpendingDoom))));
cursor.Index--;
cursor.EmitDelegate(() => archipelagoSystem.QueueLocation("Lunar Events"));
};
// Stop loading achievements from disk
IL.Terraria.Achievements.AchievementManager.Load += il =>
{
var cursor = new ILCursor(il);
cursor.Emit(OpCodes.Ret);
};
if (Main.netMode != NetmodeID.Server) Main.Achievements.OnAchievementCompleted += OnAchievementCompleted;
}
public override void HandlePacket(BinaryReader reader, int whoAmI)
{
var message = reader.ReadString();
var archipelagoSystem = ModContent.GetInstance<ArchipelagoSystem>();
if (message == "") archipelagoSystem.Chat(archipelagoSystem.Status(), whoAmI);
else if (message.StartsWith("deathlink")) archipelagoSystem.TriggerDeathlink(message.Substring(9), whoAmI);
else if (message.StartsWith("[DeathLink]"))
{
var player = Main.player[Main.myPlayer];
if (player.active && !player.dead) player.Hurt(PlayerDeathReason.ByCustomReason(message), 999999, 1);
}
else archipelagoSystem.QueueLocation(message);
}
public override void Unload()
{
if (Main.netMode != NetmodeID.Server) Main.Achievements.OnAchievementCompleted -= OnAchievementCompleted;
}
void OnAchievementCompleted(Achievement achievement)
{
var name = achievement.Name switch
{
"TIMBER" => "Timber!!",
"BENCHED" => "Benched",
"OBTAIN_HAMMER" => "Stop! Hammer Time!",
"MATCHING_ATTIRE" => "Matching Attire",
"FASHION_STATEMENT" => "Fashion Statement",
"OOO_SHINY" => "Ooo! Shiny!",
"NO_HOBO" => "No Hobo",
"HEAVY_METAL" => "Heavy Metal",
"FREQUENT_FLYER" => "The Frequent Flyer",
"DYE_HARD" => "Dye Hard",
"LUCKY_BREAK" => "Lucky Break",
"STAR_POWER" => "Star Power",
"YOU_CAN_DO_IT" => "You Can Do It!",
"TURN_GNOME_TO_STATUE" => "Heliophobia",
"ARCHAEOLOGIST" => "Archaeologist",
"PET_THE_PET" => "Feeling Petty",
"FLY_A_KITE_ON_A_WINDY_DAY" => "A Rather Blustery Day",
"PRETTY_IN_PINK" => "Pretty in Pink",
"MARATHON_MEDALIST" => "Marathon Medalist",
"SERVANT_IN_TRAINING" => "Servant-in-Training",
"GOOD_LITTLE_SLAVE" => "10 Fishing Quests",
"TROUT_MONKEY" => "Trout Monkey",
"GLORIOUS_GOLDEN_POLE" => "Glorious Golden Pole",
"FAST_AND_FISHIOUS" => "Fast and Fishious",
"SUPREME_HELPER_MINION" => "Supreme Helper Minion!",
"INTO_ORBIT" => "Into Orbit",
"WATCH_YOUR_STEP" => "Watch Your Step!",
"THROWING_LINES" => "Throwing Lines",
"VEHICULAR_MANSLAUGHTER" => "Vehicular Manslaughter",
"FIND_A_FAIRY" => "Hey! Listen!",
"I_AM_LOOT" => "I Am Loot!",
"HEART_BREAKER" => "Heart Breaker",
"HOLD_ON_TIGHT" => "Hold on Tight!",
"LIKE_A_BOSS" => "Like a Boss",
"JEEPERS_CREEPERS" => "Jeepers Creepers",
"DECEIVER_OF_FOOLS" => "Deceiver of Fools",
"DIE_TO_DEAD_MANS_CHEST" => "Dead Men Tell No Tales",
"BULLDOZER" => "Bulldozer",
"THERE_ARE_SOME_WHO_CALL_HIM" => "There are Some Who Call Him...",
"ITS_GETTING_HOT_IN_HERE" => "It's Getting Hot in Here",
"ROCK_BOTTOM" => "Rock Bottom",
"SMASHING_POPPET" => "Smashing, Poppet!",
"TALK_TO_NPC_AT_MAX_HAPPINESS" => "Leading Landlord",
"COMPLETELY_AWESOME" => "Completely Awesome",
"STICKY_SITUATION" => "Sticky Situation",
"THE_CAVALRY" => "The Cavalry",
"BLOODBATH" => "Bloodbath",
"TIL_DEATH" => "Til Death...",
"FOUND_GRAVEYARD" => "Quiet Neighborhood",
"THROW_A_PARTY" => "Jolly Jamboree",
"MINER_FOR_FIRE" => "Miner for Fire",
"GO_LAVA_FISHING" => "Hot Reels!",
"GET_TERRASPARK_BOOTS" => "Boots of the Hero",
"WHERES_MY_HONEY" => "Where's My Honey?",
"NOT_THE_BEES" => "Not the Bees!",
"DUNGEON_HEIST" => "Dungeon Heist",
"BEGONE_EVIL" => "Begone, Evil!",
"EXTRA_SHINY" => "Extra Shiny!",
"HEAD_IN_THE_CLOUDS" => "Head in the Clouds",
"GELATIN_WORLD_TOUR" => "Gelatin World Tour",
"DEFEAT_DREADNAUTILUS" => "Don't Dread on Me",
"PRISMANCER" => "Prismancer",
"GET_A_LIFE" => "Get a Life",
"TOPPED_OFF" => "Topped Off",
"BUCKETS_OF_BOLTS" => "Buckets of Bolts",
"MECHA_MAYHEM" => "Mecha Mayhem",
"DRAX_ATTAX" => "Drax Attax",
"PHOTOSYNTHESIS" => "Photosynthesis",
"FUNKYTOWN" => "Funkytown",
"IT_CAN_TALK" => "It Can Talk?!",
"REAL_ESTATE_AGENT" => "Real Estate Agent",
"ROBBING_THE_GRAVE" => "Robbing the Grave",
"BIG_BOOTY" => "Big Booty",
"RAINBOWS_AND_UNICORNS" => "Rainbows and Unicorns",
"TEMPLE_RAIDER" => "Temple Raider",
"SWORD_OF_THE_HERO" => "Sword of the Hero",
"KILL_THE_SUN" => "Kill the Sun",
"BALEFUL_HARVEST" => "Baleful Harvest",
"ICE_SCREAM" => "Ice Scream",
"SLAYER_OF_WORLDS" => "Slayer of Worlds",
"SICK_THROW" => "Sick Throw",
"YOU_AND_WHAT_ARMY" => "You and What Army?",
"GET_ZENITH" => "Zenith",
_ => null,
};
if (name != null) ModContent.GetInstance<ArchipelagoSystem>().QueueLocationClient(name);
}
}
}