Replies: 5 comments 25 replies
-
Goddamn, why isit so complicated. |
Beta Was this translation helpful? Give feedback.
2 replies
-
I refined the code a bit
|
Beta Was this translation helpful? Give feedback.
0 replies
-
@winstxnhdw This is the final patch I got! FakeReloadPatch.cs#pragma warning disable IDE1006
using HarmonyLib;
using System.Collections;
using UnityEngine;
[HarmonyPatch(typeof(ShotgunItem))]
class FakeReloadPatch {
[HarmonyPatch("FindAmmoInInventory")] // Always allow reload without shotgun shell.
[HarmonyPrefix]
static bool PrefixFindAmmoInInventory(ShotgunItem __instance, ref int __result) {
__result = 0;
return false;
}
[HarmonyPatch("ItemInteractLeftRight")] // If shotgun is full empty to allow reload.
[HarmonyPrefix]
static bool PrefixItemInteractLeftRight(ShotgunItem __instance, ref int ___shellsLoaded) {
if (___shellsLoaded >= 2) {
___shellsLoaded = 0;
}
return true;
}
[HarmonyPatch("reloadGunAnimation")] // Repatch reloadGunAnimation() to do not delete item on reload.
[HarmonyPrefix]
static bool PrefixReloadGunAnimation(ShotgunItem __instance) {
__instance.isReloading = true;
if (__instance.shellsLoaded <= 0) {
__instance.playerHeldBy.playerBodyAnimator.SetBool("ReloadShotgun", true);
__instance.shotgunShellLeft.enabled = false;
__instance.shotgunShellRight.enabled = false;
}
else {
__instance.playerHeldBy.playerBodyAnimator.SetBool("ReloadShotgun2", true);
__instance.shotgunShellRight.enabled = false;
}
__instance.StartCoroutine(CustomReloadCoroutine(__instance));
return false;
}
static IEnumerator CustomReloadCoroutine(ShotgunItem instance) {
yield return new WaitForSeconds(0.3f);
instance.gunAudio.PlayOneShot(instance.gunReloadSFX);
instance.gunAnimator.SetBool("Reloading", true);
instance.ReloadGunEffectsServerRpc(true);
yield return new WaitForSeconds(0.95f);
instance.shotgunShellInHand.enabled = true;
instance.shotgunShellInHandTransform.SetParent(instance.playerHeldBy.leftHandItemTarget);
instance.shotgunShellInHandTransform.localPosition = new Vector3(-0.0555f, 0.1469f, -0.0655f);
instance.shotgunShellInHandTransform.localEulerAngles = new Vector3(-1.956f, 143.856f, -16.427f);
yield return new WaitForSeconds(0.95f);
// instance.playerHeldBy.DestroyItemInSlotAndSync(instance.ammoSlotToUse);
// instance.ammoSlotToUse = -1;
instance.shellsLoaded = Mathf.Clamp(instance.shellsLoaded + 1, 0, 2);
instance.shotgunShellLeft.enabled = true;
if (instance.shellsLoaded == 2) {
instance.shotgunShellRight.enabled = true;
}
instance.shotgunShellInHand.enabled = false;
instance.shotgunShellInHandTransform.SetParent(instance.transform);
yield return new WaitForSeconds(0.45f);
instance.gunAudio.PlayOneShot(instance.gunReloadFinishSFX);
instance.gunAnimator.SetBool("Reloading", false);
instance.playerHeldBy.playerBodyAnimator.SetBool("ReloadShotgun", false);
instance.playerHeldBy.playerBodyAnimator.SetBool("ReloadShotgun2", false);
instance.isReloading = false;
instance.ReloadGunEffectsServerRpc(false);
}
} InfiniteAmmoPatch.cs#pragma warning disable IDE1006
using HarmonyLib;
[HarmonyPatch(typeof(ShotgunItem), nameof(ShotgunItem.ItemActivate))] // Load shell if empty on fire.
class InfiniteShotgunAmmoPatch {
static void Prefix(EnemyAI? ___heldByEnemy, ref int ___shellsLoaded, ref bool ___isReloading) {
if (___heldByEnemy is not null || ___isReloading) return;
if (___shellsLoaded <= 0) {
___shellsLoaded = 1;
}
}
} |
Beta Was this translation helpful? Give feedback.
7 replies
-
This is Lit. |
Beta Was this translation helpful? Give feedback.
2 replies
-
@winstxnhdw I found a way better way pulling off the Fake Shotgun Reload, without patching the entire coroutine! it's pretty simple I don't know why I didn't think about it, all I did was make it where if the shotgun is Reloading it forcibly interrupts the DestroyItemInSlotAndSync until IsReloading Is false; FakeReloadPatch
Also don't forget to update the InfiniteAmmoPatch.csInfiniteAmmoPatch.cs
|
Beta Was this translation helpful? Give feedback.
14 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I made a patch that allows you to reload the Shotgun at any time, to make it less suspicious of you having infinite ammo.
FakeReloadPatch.cs
InfiniteAmmoPatch.cs
Beta Was this translation helpful? Give feedback.
All reactions