using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("StaminAndGrabbin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StaminAndGrabbin")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("713ee666-bacf-4c21-9552-dfef16ee9771")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace StaminAndGrabbin
{
[BepInPlugin("StaminAndGrabbin", "StaminAndGrabbin", "1.0.0.2")]
public class StaminAndGrabbin : BaseUnityPlugin
{
private const string modGUID = "StaminAndGrabbin";
private const string modName = "StaminAndGrabbin";
private const string modVersion = "1.0.0.2";
private readonly Harmony harmony = new Harmony("StaminAndGrabbin");
private static StaminAndGrabbin Instance;
internal ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("StaminAndGrabbin");
mls.LogInfo((object)"Mods loaded: Stamina Patch, LandmineUponDeath, MetalRecharging");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
}
}
namespace StaminAndGrabbin.Recharge_Metal_Objects
{
[HarmonyPatch(typeof(HUDManager))]
internal class ChatPatch
{
private static bool _justExploded;
private static SpawnableMapObject _landmine;
[HarmonyPatch("AddPlayerChatMessageServerRpc")]
[HarmonyPatch("AddChatMessage")]
[HarmonyPostfix]
private static void onServerMessageAdded(HUDManager __instance, ref string chatMessage)
{
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
if (_justExploded || (Object)(object)((NetworkBehaviour)__instance).NetworkManager == (Object)null || !chatMessage.Contains("iexplode"))
{
return;
}
string[] array = chatMessage.Split(new char[1] { '-' });
if (array.Length != 3)
{
return;
}
ulong playerID = ulong.Parse(array[1]);
PlayerControllerB val = ((IEnumerable<PlayerControllerB>)__instance.playersManager.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.playerClientId == playerID));
if (_landmine == null)
{
_landmine = __instance.playersManager.levels.SelectMany((SelectableLevel x) => x.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => ((Object)x.prefabToSpawn).name == "Landmine"));
}
if (!((Object)(object)val == (Object)null) && _landmine != null)
{
if (!((NetworkBehaviour)__instance).NetworkManager.IsHost && !((NetworkBehaviour)__instance).NetworkManager.IsServer)
{
LandminePatch.LastExplosionWasCharger = true;
return;
}
LandminePatch.LastExplosionWasCharger = true;
Debug.Log((object)"GO BOOM!");
_justExploded = true;
Vector3 val2 = ((Component)val).transform.position - new Vector3(0f, 0.25f, 0f);
GameObject val3 = Object.Instantiate<GameObject>(_landmine.prefabToSpawn, val2, Quaternion.identity, RoundManager.Instance.mapPropsContainer.transform);
Landmine componentInChildren = val3.GetComponentInChildren<Landmine>();
val3.GetComponent<NetworkObject>().Spawn(true);
componentInChildren.ExplodeMineServerRpc();
Unexplode();
}
}
private static async Task Unexplode()
{
await Task.Delay(200);
_justExploded = false;
}
public static void sendExplosionChat()
{
if (!((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null))
{
int num = (int)GameNetworkManager.Instance.localPlayerController.playerClientId;
HUDManager.Instance.AddTextToChatOnServer("<size=0>-" + num + "-iexplode</size>", num);
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class InteractPerformedPatch
{
private static bool _swappingTwoHandedValue;
[HarmonyPatch("Interact_performed")]
[HarmonyPrefix]
internal static void interactPerformedPrefix(PlayerControllerB __instance)
{
if (!((Object)(object)__instance.hoveringOverTrigger == (Object)null) && __instance.twoHanded)
{
Transform parent = ((Component)__instance.hoveringOverTrigger).transform.parent;
if (!((Object)(object)parent == (Object)null) && !(((Object)((Component)parent).gameObject).name != "ChargeStationTrigger"))
{
_swappingTwoHandedValue = true;
__instance.twoHanded = false;
}
}
}
[HarmonyPatch("Interact_performed")]
[HarmonyPostfix]
internal static void interactPerformedPostFix(PlayerControllerB __instance)
{
if (_swappingTwoHandedValue)
{
_swappingTwoHandedValue = false;
__instance.twoHanded = true;
}
}
}
[HarmonyPatch(typeof(ItemCharger))]
internal class ItemChargerPatch
{
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static bool itemChargerUpdate(ItemCharger __instance, ref float ___updateInterval, ref InteractTrigger ___triggerScript)
{
if ((Object)(object)NetworkManager.Singleton == (Object)null)
{
return false;
}
if (___updateInterval > 1f)
{
___updateInterval = 0f;
if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
{
GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
if ((Object)(object)currentlyHeldObjectServer == (Object)null || (!currentlyHeldObjectServer.itemProperties.isConductiveMetal && !currentlyHeldObjectServer.itemProperties.requiresBattery))
{
___triggerScript.interactable = false;
___triggerScript.disabledHoverTip = "(Requires battery-powered or metal item)";
}
else
{
___triggerScript.interactable = true;
}
___triggerScript.twoHandedItemAllowed = true;
return false;
}
}
___updateInterval += Time.deltaTime;
return false;
}
[HarmonyPatch("ChargeItem")]
[HarmonyPrefix]
private static void itemChargerCharge(ItemCharger __instance)
{
GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
if ((Object)(object)currentlyHeldObjectServer != (Object)null && !currentlyHeldObjectServer.itemProperties.requiresBattery && currentlyHeldObjectServer.itemProperties.isConductiveMetal)
{
LandminePatch.LastExplosionWasLocalPlayer = true;
ChatPatch.sendExplosionChat();
}
}
}
[HarmonyPatch(typeof(Landmine))]
internal class LandminePatch
{
public static bool LastExplosionWasLocalPlayer;
public static bool LastExplosionWasCharger;
[HarmonyPatch("SpawnExplosion")]
[HarmonyPrefix]
private static bool SpawnExplosion(Vector3 explosionPosition, bool spawnExplosionEffect = false, float killRange = 1f, float damageRange = 1f)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"Spawning Explosion");
Debug.Log((object)"Charger:");
Debug.Log((object)LastExplosionWasCharger);
Debug.Log((object)LastExplosionWasLocalPlayer);
if (!LastExplosionWasLocalPlayer)
{
return true;
}
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
Vector3 val = (((Component)localPlayerController.gameplayCamera).transform.position - explosionPosition) * 80f / Vector3.Distance(((Component)localPlayerController.gameplayCamera).transform.position, explosionPosition);
if (LastExplosionWasLocalPlayer)
{
localPlayerController.KillPlayer(val, true, (CauseOfDeath)3, 0, default(Vector3));
}
LastExplosionWasCharger = false;
LastExplosionWasLocalPlayer = false;
int num = ~LayerMask.GetMask(new string[1] { "Room" });
num = ~LayerMask.GetMask(new string[1] { "Colliders" });
Collider[] array = Physics.OverlapSphere(explosionPosition, 10f, num);
for (int i = 0; i < array.Length; i++)
{
Rigidbody component = ((Component)array[i]).GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null)
{
component.AddExplosionForce(70f, explosionPosition, 10f);
}
}
return false;
}
}
}
namespace StaminAndGrabbin.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class StaminaPatch
{
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static void betterSprint(ref float ___sprintMultiplier, ref bool ___isSprinting, ref float ___exhaustionEffectLerp, ref bool ___isExhausted, ref float ___sprintMeter)
{
if (___isSprinting)
{
___sprintMultiplier = 3f;
}
else
{
___sprintMultiplier = 1.5f;
}
}
[HarmonyPatch("LateUpdate")]
[HarmonyPrefix]
private static void longerSprint(ref bool ___isWalking, ref int ___isMovementHindered, ref float ___sprintTime, ref bool ___isSprinting, ref bool ___isExhausted, ref float ___sprintMeter)
{
___sprintTime = 25f;
}
[HarmonyPatch("LateUpdate")]
[HarmonyPostfix]
private static void fasterRecharge(ref float ___carryWeight, ref float ___drunkness, ref bool ___isExhausted, ref bool ___isSprinting, ref float ___sprintTime, ref float ___sprintMeter, ref bool ___isWalking, ref int ___isMovementHindered)
{
float num = 1f;
if (___drunkness > 0.02f)
{
num *= Mathf.Abs(StartOfRound.Instance.drunknessSpeedEffect.Evaluate(___drunkness) - 1.25f);
}
if (___isSprinting)
{
___sprintMeter = Mathf.Clamp(___sprintMeter - Time.deltaTime / ___sprintTime * ___carryWeight * num, 0f, 1f);
return;
}
if (___isMovementHindered > 0)
{
if (___isWalking)
{
___sprintMeter = Mathf.Clamp(___sprintMeter - Time.deltaTime / ___sprintTime * num * 0.5f, 0f, 1f);
}
return;
}
if (!___isWalking)
{
___sprintMeter = Mathf.Clamp(___sprintMeter + Time.deltaTime / (___sprintTime - 9f) * num, 0f, 1f);
}
else
{
___sprintMeter = Mathf.Clamp(___sprintMeter + Time.deltaTime / (___sprintTime - 4f) * num, 0f, 1f);
}
if (___isExhausted && ___sprintMeter > 0.2f)
{
___isExhausted = false;
}
}
}
}
namespace StaminAndGrabbin.LandMineUponDeath
{
internal class LandMineUponDeath : Landmine
{
}
}