-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpecialStuffModule.cs
462 lines (424 loc) · 21.8 KB
/
SpecialStuffModule.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
global using SpecialStuffPack.Tools;
global using SpecialStuffPack.Components;
global using SpecialStuffPack.GungeonAPI;
global using SpecialStuffPack.ItemAPI;
global using SpecialStuffPack.Items;
global using SpecialStuffPack.SynergyAPI;
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Collections;
global using System.Reflection;
global using System.Text;
global using Gungeon;
global using MonoMod.RuntimeDetour;
global using UnityEngine;
global using SpecialStuffPack.Placeables;
global using SpecialStuffPack.Enemies;
global using Dungeonator;
global using SpecialStuffPack.Controls;
global using Random = UnityEngine.Random;
global using Object = UnityEngine.Object;
global using SpecialStuffPack.Items.Passives;
global using SpecialStuffPack.Items.Guns;
global using SpecialStuffPack.Items.Actives;
global using BepInEx;
global using HarmonyLib;
global using SpecialStuffPack.EnumExtensions;
global using HutongGames.PlayMaker;
global using HutongGames.PlayMaker.Actions;
global using InControl;
global using System.Reflection.Emit;
//global using Mono.Cecil.Cil;
global using SpecialStuffPack.StatusEffects;
global using static SpecialStuffPack.ItemAPI.ItemBuilder;
global using static SpecialStuffPack.ItemAPI.GunBuilder;
global using static SpecialStuffPack.SynergyAPI.SynergyBuilder;
global using ModifyMethod = StatModifier.ModifyMethod;
using UnityEngine.Networking;
using System.IO;
using SpecialStuffPack.CursorAPI;
using SpecialStuffPack.Characters;
using SpecialStuffPack.Items.Pickups;
using System.Diagnostics;
using Alexandria.SoundAPI;
using SpecialStuffPack.SaveAPI;
namespace SpecialStuffPack
{
[BepInPlugin(GUID, NAME, VERSION)]
[BepInDependency(ETGModMainBehaviour.GUID)]
[BepInDependency(Alexandria.Alexandria.GUID)]
[HarmonyPatch]
public class SpecialStuffModule : BaseUnityPlugin
{
public const string GUID = "spapi.etg.specialstuffpack";
public const string NAME = "SpecialAPI's Stuff";
public const string VERSION = "2.0.0";
public const string LOG_VERSION = $"{VERSION}";
public static readonly Color LogColor = new Color32(217, 57, 106, 255);
public static Texture2D spCultistBosscard;
public static int EverhoodCursorId = -1;
[HarmonyPatch(typeof(AkSoundEngine), nameof(AkSoundEngine.PostEvent), typeof(string), typeof(GameObject))]
[HarmonyPrefix]
public static void Funny(ref string in_pszEventName)
{
if(GameManager.Options != null && GameManager.Options.CurrentCursorIndex == EverhoodCursorId)
{
if(in_pszEventName == "Play_UI_menu_confirm_01" || in_pszEventName == "Play_UI_menu_cancel_01" || in_pszEventName == "Play_UI_menu_back_01" || in_pszEventName == "Play_UI_menu_unpause_01")
{
in_pszEventName = "EverhoodMenuConfirm";
}
if(in_pszEventName == "Play_UI_menu_select_01" || in_pszEventName == "Play_UI_menu_pause_01")
{
in_pszEventName = "EverhoodMenuSelect";
}
}
}
public static int? GetActiveItemUICount(PlayerItem input)
{
if (input is GreenCandle)
{
return (input as GreenCandle).Flames;
}
return null;
}
public void Awake()
{
BepInEx.Logging.Logger.Listeners.Add(new LogRecorder());
var asm = Assembly.GetExecutingAssembly();
foreach(var type in asm.GetTypes())
{
var custom = type.GetCustomAttributes(false);
if (custom != null)
{
var extension = custom.OfType<EnumExtensionAttribute>().FirstOrDefault();
if(extension != null && extension.type != null && extension.type.IsEnum)
{
foreach(var f in type.GetFields(BindingFlags.Public | BindingFlags.Static))
{
f.SetValue(null, ETGModCompatibility.ExtendEnum(GUID, f.Name, extension.type));
}
}
}
}
new Harmony(GUID).PatchAll();
//asset bundle setup
AssetBundleManager.LoadBundle();
spCultistBosscard = AssetBundleManager.Load<Texture2D>("cultist_bosscard");
SaveAPIManager.Setup();
//saveapi setup
ETGModMainBehaviour.WaitForGameManagerStart(GMStart);
}
public void GMStart(GameManager g)
{
try
{
ETGModConsole.Log($"{NAME} {LOG_VERSION} started loading.").Foreground = LogColor;
var stopwatch = new Stopwatch();
stopwatch.Start();
InitStatics();
SoundManager.LoadSoundbanksFromAssembly();
//init apis
InitItemBuilder();
InitSynergyBuilder();
GungeonAPIMain.Init();
GoopDatabase.Init();
VFXDatabase.Init();
var vfxcoll = EasyCollectionSetup("SpecialVFXCollection");
GetItemById<HealPlayerItem>(412).healingAmount = 1f;
GetItemById(326).AddComponent<SPCultistBandana>();
ETGMod.Databases.Strings.Core.Set("#PLAYER_NAME_" + PlayableCharactersE.SPCultist.ToString().ToUpper(), "Cultist");
ETGMod.Databases.Strings.Core.Set("#PLAYER_NICK_" + PlayableCharactersE.SPCultist.ToString().ToUpper(), "child");
ETGMod.Databases.Strings.Core.Set("#SPAPI_RAT_NOTE_SP_CULTIST",
"Don't know how to fight, do you? You also don't have a main character for me to beat up, so have these keys as a consolation prize instead.\n\n" +
"Later, %INSULT! - R.R.");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_INTRODUCTION", "I break mods and am a stupid feature.");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_AGREE", "Save and Quit (and probably break everything)");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_DISAGREE", "Pick This Option");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_BRINGING_CRYOELEVATOR", "*sounds of mods breaking*");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_NOT_BRINGING_CRYOELEVATOR", "Good.");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_OUCH", "Oh no... It's arriving...");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_CHANGEDMIND", "I am a dumb design decition and shouldn't have been in the game to begin with.");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_DIDCHANGEMIND", "Unbreak everything");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_DIDNTCHANGEMIND", "Remain in the broken spaghetti land");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_BRINGING_ELEVATOR", "Is that mass of frozen spaghetti gone? Good.");
ETGMod.Databases.Strings.Core.Set("#CRYOBUTTON_ANNOYED", "I wouldn't recommend wasting your time on a dumb feature such as me.");
RedGun.globalIndoctrinateInteractable = AssetBundleManager.Load<GameObject>("IndoctrinateFollowerInteractable");
var interactable = RedGun.globalIndoctrinateInteractable.AddComponent<IndoctrinateFollowerInteractable>();
interactable.AddComponent<tk2dSprite>().SetSprite(BulletKinEnemy.sprite.Collection, BulletKinEnemy.sprite.spriteId);
interactable.AddComponent<tk2dSpriteAnimator>().Library = BulletKinEnemy.spriteAnimator.Library;
interactable.noRedgunKey = SetString("#INDOCTRINATE_NOREDGUN", "I can only be converted by the Red Gun.");
interactable.notEnoughAmmoKey = SetString("#INDOCTRINATE_NOTENOUGH", "You don't have enough resources to convert me!");
interactable.validKey = SetString("#INDOCTRINATE_VALID", "Convert me to your cult, I will follow your teachings faithfully.");
interactable.yesKey = SetString("#INDOCTRINATE_YES", "<Indoctrinate follower <Lose %AMMO ammo>>");
interactable.yesHealthKey = SetString("#INDOCTRINATE_YESHEALTH", "<Indoctrinate follower <Lose %HEART_SYMBOL>>");
interactable.noKey = SetString("#INDOCTRINATE_NO", "<Walk away>");
tk2dSprite.AddComponent(LinkedStatusEffect.LinkVFX = AssetBundleManager.Load<GameObject>("LinkedVFX"), vfxcoll, AddSpriteToCollection("linked_001", vfxcoll)).CurrentSprite.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleCenter);
tk2dSprite.AddComponent(DivineProtectionStatusEffect.DivineVFX = AssetBundleManager.Load<GameObject>("DivineProtectionVFX"), vfxcoll, AddSpriteToCollection("divine_protection_001", vfxcoll)).CurrentSprite.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleCenter);
tk2dSprite.AddComponent(RupturedStatusEffect.RupturedVFX = AssetBundleManager.Load<GameObject>("RupturedVFX"), vfxcoll, AddSpriteToCollection("ruptured_001", vfxcoll)).CurrentSprite.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleCenter);
tk2dSprite.AddComponent(FrailStatusEffect.FrailVFX = AssetBundleManager.Load<GameObject>("FrailVFX"), vfxcoll, AddSpriteToCollection("frail_001", vfxcoll)).CurrentSprite.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleCenter);
tk2dSprite.AddComponent(ScarStatusEffect.ScarVFX = AssetBundleManager.Load<GameObject>("ScarVFX"), vfxcoll, AddSpriteToCollection("scar_001", vfxcoll)).CurrentSprite.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleCenter);
SoundManager.AddCustomSwitchData("WPN_Guns", "SPAPI_Silent", "Play_WPN_Gun_Shot_01");
SoundManager.AddCustomSwitchData("WPN_Guns", "SPAPI_Silent", "Play_WPN_Gun_Reload_01");
//init items
WoodenToken.Init();
PayToWin.Init();
FusedAmmolet.Init();
BoxOfStuff.Init();
ProtectiveArmorItem.Init();
ShacklesItem.Init();
RatWhistle.Init();
SubscribeButton.Init();
ExtraChestItem.Init();
MirrorOfTruth.Init();
BadLuckClover.Init();
Calendar.Init();
GreenCandle.Init();
GlassBell.Init();
ShootingStar.Init();
WishingOrb.Init();
Butter.Init();
LegitCoupon.Init();
BinaryGun.Init();
AsteroidBelt.Init();
GravediggerShovel.Init();
HandheldCatapult.Init();
GoldKey.Init();
AmethystItem.Init();
OpalItem.Init();
EmeraldItem.Init();
AquamarineItem.Init();
RubyItem.Init();
DiamondItem.Init();
OtherworldlyAssistance.Init();
HotCoal.Init();
GuardianOfTime.Init();
MarblesItem.Init();
FrailHeart.Init();
UndyingTotem.Init();
Watermelon.Init();
ConsoleController.Init();
StaticRoll.Init();
MirroredBullet.Init();
BloodyScales.Init();
Plushie.Init();
BossChest.Init();
Chaos.Init();
Launcher.Init();
BalancingPole.Init();
InfinityCrystal.Init();
EnergyDrink.Init();
AmmoFlower.Init();
FlatBullets.Init();
AkNAN.Init();
CactiClub.Init();
HelloWorld.Init();
Frogun.Init();
Revolvever.Init();
AkPI.Init();
RoundBullets.Init();
OrbOfKnowledge.Init();
AkSoundEngineGun.Init();
EnderGun.Init();
LeatherWhip.Init();
PistolWhip.Init();
WhipCream.Init();
SynergyCompletionGun.Init();
SusShotgun.Init();
RedGun.Init();
LeadFists.Init();
HeartPiece.Init();
HotSauce.Init();
MagicBag.Init();
BananaJam.Init();
CrownBullets.Init();
RedAmmolet.Init();
MarkedCalendar.Init();
Shredder.Init();
RustyBullets.Init();
RustyAmmoBox.Init();
WoodenDice.Init();
Bug.Init();
AlexandriaBook.Init();
BrokenCalculator.Init();
BrokenMask.Init();
TarotCards.Init();
LeaderDeck.Init();
Magnificus.Init();
FossilFuel.Init();
SniperGun.Init();
//ChamberChamberChamber.Init();
//CCCAbstractions.Init();
GoldenShotgun.Init();
UglyGun.Init();
HDGun.Init();
ReverseAK.Init();
AkEpsilon.Init();
RifleAK.Init();
//MetaGun.Init();
BloodyHand.Init();
PowerTriangle.Init();
SecondHeart.Init();
PandorasBox.Init();
PowerfulBullets.Init();
BulletShootingGun.Init();
FrogWand.Init();
Slingshot.Init();
Ak312.Init();
Bait.Init();
GlassBullets.Init();
ChamberOfMirrors.Init();
RaggedBullets.Init();
Trepanation.Init();
BellRinger.Init();
Anvil.Init();
HyperDarkBlaster.Init();
Sepulchrifle.Init();
//Evergun.Init();
//SoulGun.Init();
//PastsRewardItem.Init();
//ForceOfTwilight.Init();
CursorMaker.BuildCursor(AssetBundleManager.Load<Texture2D>("Mouse"));
CursorMaker.BuildCursor(AssetBundleManager.Load<Texture2D>("GenericCursor"));
EverhoodCursorId = CursorMaker.BuildCursor(AssetBundleManager.Load<Texture2D>("EverhoodHand"));
CursorMaker.BuildCursor(AssetBundleManager.Load<Texture2D>("SuperliminalCursor"));
CursorMaker.BuildCursor(AssetBundleManager.Load<Texture2D>("SuperliminalSmiley"));
CursorMaker.BuildCursor(AssetBundleManager.Load<Texture2D>("WillYouSnailLevelEditorCursor"));
CursorMaker.BuildCursor(AssetBundleManager.Load<Texture2D>("BabaCursor"));
Item["boxofstuff"].associatedItemChanceMods = Item.Where(x => x.Value != null && x.Value.quality >= PickupObject.ItemQuality.D && x.Value.quality <= PickupObject.ItemQuality.S).Select(x => new LootModData
{
AssociatedPickupId = x.Value.PickupObjectId,
DropRateMultiplier = 1.25f
}).ToArray();
//LilChest.SetupChests();
//init synergies
SpecialSynergies.Init();
//init characters
//MrGiando.Init();
//init enemies
SpecialEnemies.AddAdvancedDragunAmmonomiconEntry();
SpecialEnemies.AddNinja();
SpecialEnemies.SetupAk47VeteranPrefab();
//init placeables
SpecialPlaceables.InitLockUnlockPedestal();
SpecialPlaceables.InitDiamondShrine();
//SpecialPlaceables.InitSomethingSpecialPlaceable();
//SpecialPlaceables.InitDoor(); //bye bye stupid door
//CCCChallenge.Init();
//add other stuff
EnemyDatabase.GetOrLoadByGuid("465da2bb086a4a88a803f79fe3a27677").AddComponent<DragunDeathChecks>();
//add hooks
new Hook(typeof(GameUIItemController).GetMethod("UpdateItem"), typeof(SpecialStuffModule).GetMethod("ItemUIUpdateHook"));
new Hook(
typeof(RoomHandler).GetMethod("PostGenerationCleanup", BindingFlags.Instance | BindingFlags.Public),
typeof(SpecialStuffModule).GetMethod("FixBadDodgerollCode")
);
//add sewer grate rooms
/*foreach (var asset in AssetBundleManager.specialeverything.GetAllAssetNames())
{
if (asset.ToLowerInvariant().StartsWith("assets/rooms/sewerentrance"))
{
//RoomFactory.AddRoomToSewerGratePool(RoomFactory.BuildFromTextAsset(AssetBundleManager.Load<TextAsset>(asset)));
}
}*/
//new Hook(typeof(Gun).GetMethod("HandleSpecificEndGunShoot", BindingFlags.NonPublic | BindingFlags.Instance), typeof(SpecialStuffModule).GetMethod("HandleChargeBurst"));
ETGModConsole.Commands.AddGroup(globalPrefix);
var group = ETGModConsole.Commands.GetGroup(globalPrefix);
ETGModConsole.CommandDescriptions.Add(globalPrefix, $"Group used by commands added by {NAME}.");
group.AddUnit("use_active", UseItem, ETGModConsole.GiveAutocompletionSettings);
ETGModConsole.CommandDescriptions.Add($"{globalPrefix} use_active", "Uses the given active item once. If a second argument is given, it specifies how many times the item should be used.");
group.AddUnit("showhitboxes", x => ETGModConsole.SwitchValue(x.FirstOrDefault(), ref showHitboxes, "Show Hitboxes"));
ETGModConsole.CommandDescriptions.Add($"{globalPrefix} showhitboxes", "Toggles Hitbox display.");
TCultistHandler.Init();
SpecialOptions.Setup();
SpecialInput.Setup();
//WindowsWindowNamer.RenameWindow();
stopwatch.Stop();
ETGModConsole.Log($"{NAME} {LOG_VERSION} loaded successfully.").Foreground = LogColor;
ETGModConsole.Log($"{NAME} took {stopwatch.Elapsed} to load").Foreground = LogColor;
ETGModConsole.Log($"Use the feedback form in the F8 menu to send feedback and report bugs.").Foreground = LogColor;
ETGModConsole.Log($"You can also use the command \"{globalPrefix} feedback\".").Foreground = LogColor;
}
catch (Exception ex)
{
ETGModConsole.Log($"Something bad happened while loading {NAME}: " + ex).Foreground = LogColor;
}
}
public void Update()
{
if (showHitboxes && PhysicsEngine.Instance != null && PhysicsEngine.Instance.AllRigidbodies != null)
{
foreach (var obj in PhysicsEngine.Instance.AllRigidbodies)
{
if (obj && obj.sprite && Vector2.Distance(obj.sprite.WorldCenter, GameManager.Instance.PrimaryPlayer.sprite.WorldCenter) < 8)
{
HitboxMonitor.DisplayHitbox(obj);
}
}
}
}
public static void FixBadDodgerollCode(Action<RoomHandler> orig, RoomHandler room)
{
PrototypeDungeonRoom old = room.area.prototypeRoom;
orig(room);
room.area.prototypeRoom ??= old;
}
public static bool HandleChargeBurst(Func<Gun, ProjectileModule, bool, ProjectileData, bool, bool> orig, Gun self, ProjectileModule module, bool canAttack, ProjectileData overrideProjectileData, bool playEffects)
{
bool result = orig(self, module, canAttack, overrideProjectileData, playEffects);
return result;
}
public static void ItemUIUpdateHook(Action<GameUIItemController, PlayerItem, List<PlayerItem>> orig, GameUIItemController self, PlayerItem current, List<PlayerItem> items)
{
orig(self, current, items);
if (!GameUIRoot.Instance.ForceHideItemPanel && !self.temporarilyPreventVisible && current != null)
{
if (!((current.canStack && current.numberOfUses > 1 && current.consumable) || (current.numberOfUses > 1 && current.UsesNumberOfUsesBeforeCooldown && !current.IsOnCooldown)) && !(current is EstusFlaskItem) && (!(current is RatPackItem) ||
current.IsOnCooldown) && GetActiveItemUICount(current) != null)
{
self.ItemCountLabel.IsVisible = true;
self.ItemCountLabel.Text = GetActiveItemUICount(current).Value.ToString();
}
}
}
public void UseItem(string[] args)
{
if (args.Length < 1)
{
ETGModConsole.Log("Item not given!");
return;
}
if (!Game.Items.ContainsID(args[0]))
{
ETGModConsole.Log("Invalid item " + args[0] + "!");
return;
}
if (Game.Items[args[0]] is not PlayerItem)
{
ETGModConsole.Log("Invalid item " + args[0] + "!");
return;
}
if (!GameManager.Instance.PrimaryPlayer)
{
ETGModConsole.Log("Player doesn't exist!");
return;
}
int numToSpawn = 1;
if (args.Length > 1)
{
if(!int.TryParse(args[1], out numToSpawn))
{
numToSpawn = 1;
}
}
for(int i = 0; i < numToSpawn; i++)
{
GameObject item = Instantiate(Game.Items[args[0]].gameObject, GameManager.Instance.PrimaryPlayer.CenterPosition, Quaternion.identity);
item.GetComponent<PlayerItem>().DoEffect(GameManager.Instance.PrimaryPlayer);
Destroy(item);
}
}
public static string globalPrefix = "spapi";
public static bool showHitboxes;
}
}