-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIXTweaks.cs
341 lines (284 loc) · 15.7 KB
/
IXTweaks.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
using System;
//using System.Numerics;
using UnityEngine;
using BepInEx;
using BepInEx.Logging;
using LobbyCompatibility.Attributes;
using LobbyCompatibility.Enums;
using MonoMod.Cil;
using LethalLib.Modules;
using MoreShipUpgrades.API;
using Mono.Cecil.Cil;
using System.IO;
using System.Reflection;
using IXTweaks.MonoBehaviors;
using GameNetcodeStuff;
using MoreShipUpgrades.UpgradeComponents.TierUpgrades.Enemies;
using MoreShipUpgrades.Managers;
using Unity.Collections;
using IL;
using UnityEngine.Scripting;
using MoreShipUpgrades.UpgradeComponents.Items;
namespace IXTweaks;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency("BMX.LobbyCompatibility", BepInDependency.DependencyFlags.HardDependency)]
[BepInDependency("com.sigurd.csync")]
[BepInDependency(LethalLib.Plugin.ModGUID)]
[BepInDependency(MoreShipUpgrades.Misc.Metadata.GUID, BepInDependency.DependencyFlags.HardDependency)]
[LobbyCompatibility(CompatibilityLevel.ClientOnly, VersionStrictness.None)]
public class IXTweaks : BaseUnityPlugin
{
public static IXTweaks Instance { get; private set; } = null!;
internal new static ManualLogSource Logger { get; private set; } = null!;
internal static new IXTweaksConfig? Config;
public static AssetBundle IXTweaksAssets;
private void Awake() {
Logger = base.Logger;
Instance = this;
// Load config
Config = new IXTweaksConfig(base.Config);
// Load assets
string sAssemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
IXTweaksAssets = AssetBundle.LoadFromFile(Path.Combine(sAssemblyLocation, "ixtweaks"));
if (IXTweaksAssets == null) {
Logger.LogError("Failed to load custom assets."); // ManualLogSource for your plugin
return;
}
RegisterRPCs();
// Basic item imports
RegisterItem("JeremiahTheSlug.asset", Config.commonItemDropWeight, Config.commonItemMinVal, Config.commonItemMaxVal, "Assets/IXTweaks/Scraps/");
//RegisterItem("Celsius.asset", Config.commonItemDropWeight, Config.commonItemMinVal, Config.commonItemMaxVal, "Assets/IXTweaks/Scraps/");
//RegisterItem("RoastedNutCoffee.asset", Config.commonItemDropWeight, Config.commonItemMinVal, Config.commonItemMaxVal, "Assets/IXTweaks/Scraps/");
//RegisterItem("MagicMushrooms.asset", Config.commonItemDropWeight, Config.commonItemMinVal, Config.commonItemMaxVal, "Assets/IXTweaks/Scraps/");
//RegisterItem("Loaf.asset", Config.commonItemDropWeight, Config.commonItemMinVal, Config.commonItemMaxVal, "Assets/IXTweaks/Scraps/");
RegisterItem("NyQuil.asset", Config.rareItemDropWeight, Config.rareItemMinVal, Config.rareItemMaxVal, "Assets/IXTweaks/Scraps/");
//RegisterItem("VampireTeeth.asset", Config.rareItemDropWeight, Config.rareItemMinVal, Config.rareItemMaxVal, "Assets/IXTweaks/Scraps/");
//RegisterItem("AirForceOnes.asset", Config.rareItemDropWeight, Config.rareItemMinVal, Config.rareItemMaxVal, "Assets/IXTweaks/Scraps/");
//RegisterItem("PaperAirplane.asset", Config.rareItemDropWeight, Config.rareItemMinVal, Config.rareItemMaxVal, "Assets/IXTweaks/Scraps/");
//RegisterItem("7LeafClover.asset", Config.legendaryItemDropWeight, Config.legendaryItemMinVal, Config.legendaryItemMaxVal, "Assets/IXTweaks/Scraps/");
RegisterHunterDrop("HygrodereChunk.asset", "Blob", Config.slimeSampleMinVal, Config.slimeSampleMaxVal, Config.slimeHunterLevel, "Assets/IXTweaks/Samples/");
RegisterHunterDrop("NutcrackerHead.asset", "Nutcracker", Config.nutcrackerSampleMinVal, Config.nutcrackerSampleMaxVal, Config.nutcrackerHunterLevel, "Assets/IXTweaks/Samples/");
RegisterHunterDrop("CoilHead.asset", "Spring", Config.springSampleMinVal, Config.springSampleMaxVal, Config.springHunterLevel, "Assets/IXTweaks/Samples/");
RegisterHunterDrop("JesterBox.asset", "Jester", Config.jesterSampleMinVal, Config.jesterSampleMaxVal, Config.jesterHunterLevel, "Assets/IXTweaks/Samples/");
RegisterHunterDrop("EuropeanBlood.asset", "Butler", Config.butlerSampleMinVal, Config.butlerSampleMaxVal, Config.butlerHunterLevel, "Assets/IXTweaks/Samples/");
RegisterHunterDrop("BrokenMask.asset", "Masked", Config.maskedSampleMinVal, Config.maskedSampleMaxVal, Config.maskedHunterLevel, "Assets/IXTweaks/Samples/");
// Register items that take a little more work for some special payoff ;)
RegisterSpecialItems();
// Add patches
Patch();
Logger.LogInfo($"{MyPluginInfo.PLUGIN_GUID} v{MyPluginInfo.PLUGIN_VERSION} has loaded!");
}
internal static void Patch() {
Logger.LogDebug("Patching...");
// Slime hunter patches
On.BlobAI.HitEnemy += DropSampleOnHappy;
IL.BlobAI.HitEnemy += PissedPatch;
On.BlobAI.OnCollideWithPlayer += PissedOffInstaKill;
On.BlobAI.Update += SlimeGas;
// Audio patches
On.FlowermanAI.Start += BrackenAudioPatch;
On.HoarderBugAI.Start += HorderBugAudioPatch;
// Invinsible enemy wrapper patches
//IL.EnemyAI.KillEnemy += InvinsiblePatch;
Logger.LogDebug("Attempting Damage Wrapper");
On.EnemyAI.HitEnemy += DamageWrapperIfApplicable;
Logger.LogDebug("Attempting Awake Wrapper");
On.EnemyAI.Start += ApplyWrapperOnAwake;
Logger.LogDebug("Finished patching!");
}
private static void HorderBugAudioPatch(On.HoarderBugAI.orig_Start orig, HoarderBugAI self) {
// Perform general start method
orig(self);
// Load in audio files from asset bundle and place them in array
string basePath = "Assets/IXtweaks/Assets/SFXs/";
AudioClip[] clips = new AudioClip[18];
for(int i = 0; i < 18; i++) {
clips[i] = IXTweaksAssets.LoadAsset<AudioClip>(basePath + (i + 1).ToString() + ".wav");
Debug.Log(basePath + (i + 1).ToString() + ".wav");
}
// Patch loot bug passive audio
self.chitterSFX = clips;
self.angryScreechSFX = clips;
}
private static void BrackenAudioPatch(On.FlowermanAI.orig_Start orig, FlowermanAI self) {
// Perform general start method
orig(self);
// Load in audio files from asset bundle and place them in array
string basePath = "Assets/IXtweaks/Assets/SFXs/";
AudioClip clip = IXTweaksAssets.LoadAsset<AudioClip>(basePath + "12Brack.wav");
// Patch bracken anger noise with audio patches
self.creatureAngerVoice.clip = clip;
}
private static void ApplyWrapperOnAwake(On.EnemyAI.orig_Start orig, EnemyAI self) {
// Initalize enemy AI
orig(self);
// If the enemy is of a certain AI bracket, add the wrapper to them
if (self.GetComponent<SpringManAI>())
self.gameObject.AddComponent<InvinsibleEnemyWrapper>().internalHealth = Config.springHitPoints;
if (self.GetComponent<JesterAI>())
self.gameObject.AddComponent<InvinsibleEnemyWrapper>().internalHealth = Config.jesterHitPoints;
if (self.GetComponent<PufferAI>())
self.gameObject.AddComponent<InvinsibleEnemyWrapper>().internalHealth = Config.pufferHitPoints;
//if (self.GetComponent<ClaySurgeonAI>())
// self.gameObject.AddComponent<InvinsibleEnemyWrapper>().internalHealth = 4;
}
private static void DamageWrapperIfApplicable(On.EnemyAI.orig_HitEnemy orig, EnemyAI self, int force, PlayerControllerB playerWhoHit, bool playHitSFX, int hitID) {
// Reg call
orig(self, force, playerWhoHit, playHitSFX, hitID);
// If this AI has a health wrapper call the damage event within it
if (self.GetComponent<InvinsibleEnemyWrapper>() != null) {
if (self.GetComponent<SpringManAI>() != null || self.GetComponent<JesterAI>() != null)
self.GetComponent<InvinsibleEnemyWrapper>().DamageWrapper(force, true, playerWhoHit);
else
self.GetComponent<InvinsibleEnemyWrapper>().DamageWrapper(force, false, playerWhoHit);
}
}
private static void PissedPatch(ILContext il) {
// Create a cursor off of the context
ILCursor c = new(il);
// First, navigate the cursor to the instruction after the angered timer is set to insert our new logic
c.GotoNext(
MoveType.After,
x => x.MatchLdarg(0),
x => x.MatchLdcR4(18),
x => x.MatchStfld<BlobAI>("angeredTimer")
);
// Remove this statement
c.Index -= 2;
for(int i = 0; i < 3; i++)
c.Remove();
// Insert logic for only setting anger if not pissed off
c.Emit(OpCodes.Ldarg_0);
c.EmitDelegate<Action<BlobAI>>(self => {
if (self.angeredTimer < 1000f)
self.angeredTimer = 18f;
});
}
private static void SlimeGas(On.BlobAI.orig_Update orig, BlobAI self) {
// Perform normal logic
orig(self);
// Check if the slime is pissed off
if(self.angeredTimer > 1000f) {
// Ensure fast persuit speed
self.agent.speed = 3f;
}
}
private static void PissedOffInstaKill(On.BlobAI.orig_OnCollideWithPlayer orig, BlobAI self, Collider other) {
// Check if the slime is pissed off and collided with the player
PlayerControllerB playerControllerB = self.MeetsStandardPlayerCollisionConditions(other);
if(self.angeredTimer > 1000f && playerControllerB != null) {
playerControllerB.DamagePlayer(1000);
if (playerControllerB.isPlayerDead) {
self.SlimeKillPlayerEffectServerRpc((int)playerControllerB.playerClientId);
}
}
// Perform normal logic
orig(self, other);
}
private static void DropSampleOnHappy(On.BlobAI.orig_HitEnemy orig, BlobAI self, int force, PlayerControllerB playerWhoHit, bool playHitSFX, int hitID) {
// Perform normal logic
orig(self, force, playerWhoHit, playHitSFX, hitID);
// Check if the slime WAS tammed before this hit
Logger.LogDebug("Hit Slime");
Logger.LogDebug((self.angeredTimer - 19f));
if(self.tamedTimer > 0f && (self.angeredTimer - 19f) <= 0f) { // Not messin up the condition dis time :)
// In such case, make the slime permanantly angry
Logger.LogInfo("Slime was habby, make him angy >:(");
self.angeredTimer = Mathf.Infinity;
self.tamedTimer = 0f;
self.thisSlimeMaterial.SetColor(Shader.PropertyToID("_Gradient_Color"), Color.red);
self.thisSlimeMaterial.SetFloat("_Frequency", 8f);
self.thisSlimeMaterial.SetFloat("_Ripple_Density", self.slimeJiggleDensity * 3f);
self.thisSlimeMaterial.SetFloat("_Amplitude", self.slimeJiggleAmplitude * 3f);
GameNetworkManager.Instance.localPlayerController.JumpToFearLevel(0.4f);
// SFX off of the slimes's audio source
AudioSource slimeSource = self.GetComponent<AudioSource>();
AudioClip angrySlimeSFX = IXTweaksAssets.LoadAsset<AudioClip>("Assets/IXTweaks/Assets/SFXs/AngrySlimeGurgle.wav");
slimeSource.PlayOneShot(angrySlimeSFX);
WalkieTalkie.TransmitOneShotAudio(slimeSource, angrySlimeSFX, 100f);
RoundManager.Instance.PlayAudibleNoise(self.transform.position, 10f, 100f, 0, StartOfRound.Instance.hangarDoorsClosed);
// Then, using LGU drop a slime sample if the player has the provided hunter conditions met
if (MoreShipUpgrades.Misc.Upgrades.BaseUpgrade.GetActiveUpgrade(Hunter.UPGRADE_NAME) && Hunter.CanHarvest("blob")) {
Logger.LogInfo("Slime drop loot for hunter");
ItemManager.Instance.SpawnSample("blob", self.transform.position);
}
}
}
private void RegisterSpecialItems() {
// Windex is a spray item cause... I mean it is a spray bottle :p
Item windex = RegisterItem("Windex.asset", Config.commonItemDropWeight, Config.commonItemMinVal, Config.commonItemMaxVal, "Assets/IXTweaks/Scraps/");
Utilities.FixMixerGroups(windex.spawnPrefab);
// Apply spray script and populate it appropriately
FakeSprayItem script = windex.spawnPrefab.AddComponent<FakeSprayItem>();
script.grabbable = true;
script.grabbableToEnemies = true;
script.itemProperties = windex;
script.fullSprayEffect = script.transform.GetChild(2);
script.emptySprayEffect = script.transform.GetChild(2).GetChild(1).GetComponent<ParticleSystem>();
script.spraySFXr = script.GetComponent<AudioSource>();
Logger.LogDebug(string.Join(", ", IXTweaksAssets.GetAllAssetNames()));
script.spraySFX = IXTweaksAssets.LoadAsset<AudioClip>("Assets/IXTweaks/Assets/SFXs/WeedKillerSpray.mp3");
script.emptySFX = IXTweaksAssets.LoadAsset<AudioClip>("Assets/IXTweaks/Assets/SFXs/WeedKillerEmpty.mp3");
// Scissors is a powerful weapon dropped by the clay surgeon
//Item scissors = RegisterHunterDrop("Scissors.asset", "Barber", "Assets/IXTweaks/Samples/");
//Utilities.FixMixerGroups(scissors.spawnPrefab);
//Scissors sci = scissors.spawnPrefab.AddComponent<Scissors>();
//Destroy(scissors.spawnPrefab.GetComponent<MonsterSample>());
//sci.grabbable = true;
//sci.grabbableToEnemies = true;
//sci.itemProperties = scissors;
//sci.sfx = sci.GetComponent<AudioSource>();
//Logger.LogDebug(sci.sfx);
//sci.anim = sci.transform.GetChild(1).GetComponent<Animator>();
//Logger.LogDebug(sci.anim);
//sci.snipSFX = IXTweaksAssets.LoadAsset<AudioClip>("Assets/IXTweaks/Assets/SFXs/Snip.mp3");
}
private Item RegisterHunterDrop(string itemName, string monsterName, int min, int max, int level, string pathToItem="Assets/IXTweaks/Samples/")
{
// loads asset from the asset bundle we provided
Item item = IXTweaksAssets.LoadAsset<Item>(pathToItem + itemName);
// Apply min and max
item.minValue = min;
item.maxValue = max;
if (item == null)
Logger.LogError($"Failed to load {itemName} from IXTweaksAssets");
else {
HunterSamples.RegisterSample(item, monsterName, level, true, true, 100);
Utilities.FixMixerGroups(item.spawnPrefab);
return item;
}
return null;
}
private Item RegisterItem(string itemName, int weight, int min, int max, string pathToItem="Assets/IXTweaks/Scraps/")
{
// loads asset from the asset bundle we provided
Item item = IXTweaksAssets.LoadAsset<Item>(pathToItem + itemName);
// Apply min and max
item.minValue = min;
item.maxValue = max;
if (item == null)
Logger.LogError($"Failed to load {itemName} from IXTweaksAssets");
else
{
Items.RegisterScrap(item, weight, Levels.LevelTypes.All);
NetworkPrefabs.RegisterNetworkPrefab(item.spawnPrefab);
Utilities.FixMixerGroups(item.spawnPrefab);
// Provided we imported into LethalLib successfully, we can return our item
return item;
}
// Return null if the item is imported unsucessfully
return null;
}
private void RegisterRPCs() {
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in types) {
MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
foreach (MethodInfo method in methods) {
object[] attributes = method.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), false);
if (attributes.Length > 0) {
method.Invoke(null, null);
}
}
}
}
}