Skip to content

Commit

Permalink
Improved method of adding ammo
Browse files Browse the repository at this point in the history
  • Loading branch information
FragileDeviations committed Aug 2, 2024
1 parent e6160d3 commit 58f8187
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Main : MelonMod
internal const string Description = "Infinite ammo. What else?";
internal const string Author = "SoulWithMae";
internal const string Company = "Weather Electric";
internal const string Version = "1.0.1";
internal const string Version = "1.1.0";
internal const string DownloadLink = "https://thunderstore.io/c/bonelab/p/SoulWithMae/InfiniteAmmo/";

public override void OnInitializeMelon()
Expand Down
34 changes: 23 additions & 11 deletions Patching/Patching.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using HarmonyLib;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Data;
// ReSharper disable InconsistentNaming

namespace WeatherElectric.InfiniteAmmo.Patching;

Expand All @@ -11,22 +13,32 @@ public static class AmmoInventoryPatch
public static void Awake(AmmoInventory __instance)
{
if (!Preferences.Enabled.Value) return;
ModConsole.Msg("Adding shit ton of ammo", 1);
__instance.AddCartridge(__instance.lightAmmoGroup, 500000);
__instance.AddCartridge(__instance.mediumAmmoGroup, 500000);
__instance.AddCartridge(__instance.heavyAmmoGroup, 500000);

__instance.AddCartridge(__instance.lightAmmoGroup, 1000);
__instance.AddCartridge(__instance.mediumAmmoGroup, 1000);
__instance.AddCartridge(__instance.heavyAmmoGroup, 1000);
}

[HarmonyPatch(nameof(AmmoInventory.RemoveCartridge))]
[HarmonyPostfix]
public static void RemoveCartridge(AmmoInventory __instance)
public static void RemoveCartridge(AmmoInventory __instance, CartridgeData cartridge, int count)
{
if (!Preferences.Enabled.Value) return;
#if DEBUG
ModConsole.Msg("Adding a shit ton of ammo", 1);
#endif
__instance.AddCartridge(__instance.lightAmmoGroup, 1);
__instance.AddCartridge(__instance.mediumAmmoGroup, 1);
__instance.AddCartridge(__instance.heavyAmmoGroup, 1);

var group = __instance.GetGroupByCartridge(cartridge);
if (group == null) return;

switch (group)
{
case "light":
__instance.AddCartridge(__instance.lightAmmoGroup, count);
break;
case "medium":
__instance.AddCartridge(__instance.mediumAmmoGroup, count);
break;
case "heavy":
__instance.AddCartridge(__instance.heavyAmmoGroup, count);
break;
}
}
}

0 comments on commit 58f8187

Please sign in to comment.