using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BetaRevive.Patches;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyInformationalVersion("1.0.0+8f41a9c25f0e8021aded727f76dc64312c882efa")]
[assembly: AssemblyTitle("BetaRevive")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetaRevive")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e18e20df-9b8c-4dd3-8bab-7ccaaca633f0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BetaRevive
{
[BepInPlugin("xero.BetaRevive", "REPO Beta Revive", "1.0.0")]
public class BetaRevive : BaseUnityPlugin
{
private const string modGUID = "xero.BetaRevive";
private const string modName = "REPO Beta Revive";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("xero.BetaRevive");
private static BetaRevive Instance;
internal ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("xero.BetaRevive");
ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
mls.LogInfo((object)"[xero] Ultimate Revive Inited.");
harmony.PatchAll(typeof(BetaRevive));
harmony.PatchAll(typeof(ShopManagerPatch));
harmony.PatchAll(typeof(PlayerControllerPatch));
harmony.PatchAll(typeof(PhysGrabCartPatch));
}
}
}
namespace BetaRevive.Patches
{
internal class ConfigManager
{
public static ConfigEntry<int> hpCost;
public static ConfigEntry<string> reviveKey;
public static void Initialize(ConfigFile cfg)
{
hpCost = cfg.Bind<int>("Revive HP Settings", "StaminaCost", 20, "The amount of hp consumed when reviving.");
reviveKey = cfg.Bind<string>("Controls", "ReviveKey", "h", "The key used to trigger a revive.");
}
}
[HarmonyPatch(typeof(PhysGrabCart))]
internal class PhysGrabCartPatch
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void displayText()
{
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
if (!SemiFunc.RunIsShop() && PlayerControllerPatch.isGrab)
{
object value = AccessTools.Field(typeof(PlayerAvatar), "playerName").GetValue(PlayerControllerPatch.grabHead.playerAvatar);
PlayerHealth playerHealth = PlayerController.instance.playerAvatarScript.playerHealth;
int num = (int)AccessTools.Field(typeof(PlayerHealth), "health").GetValue(playerHealth);
int value2 = ConfigManager.hpCost.Value;
string value3 = ConfigManager.reviveKey.Value;
if (num < value2)
{
Color val = default(Color);
((Color)(ref val))..ctor(1f, 0f, 0f);
ItemInfoExtraUI.instance.ItemInfoText($"Your HP is below {value2}", val);
}
else
{
Color val2 = default(Color);
((Color)(ref val2))..ctor(0.2f, 0.8f, 0.1f);
ItemInfoExtraUI.instance.ItemInfoText($"Press [{value3}] to revive {value} with {value2} HP", val2);
}
}
}
}
[HarmonyPatch(typeof(PlayerController))]
internal class PlayerControllerPatch
{
public static PlayerDeathHead grabHead;
public static bool isGrab;
[HarmonyPatch("FixedUpdate")]
[HarmonyPostfix]
private static void PlayerGrabHeadPatch(PlayerController __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
if (__instance.physGrabActive && (Object)(object)__instance.physGrabObject != (Object)null)
{
PlayerDeathHead component = __instance.physGrabObject.GetComponent<PlayerDeathHead>();
if ((Object)(object)component != (Object)null && (Object)(object)component.playerAvatar != (Object)null)
{
grabHead = component;
isGrab = true;
}
}
else
{
isGrab = false;
}
}
}
internal class ReviveManager : MonoBehaviour
{
private void Update()
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
if (!PlayerControllerPatch.isGrab || !((Object)(object)PlayerControllerPatch.grabHead != (Object)null))
{
return;
}
if (!Enum.TryParse<Key>(ConfigManager.reviveKey.Value, ignoreCase: true, out Key result))
{
Debug.Log((object)"[BetaRevive] Invalid revive key in config");
return;
}
ButtonControl val = (ButtonControl)(object)Keyboard.current[result];
if (val == null || !val.wasPressedThisFrame)
{
return;
}
PlayerDeathHead grabHead = PlayerControllerPatch.grabHead;
if ((Object)(object)grabHead.playerAvatar == (Object)null)
{
Debug.Log((object)"[BetaRevive] No avatar found on grabbed head");
return;
}
PlayerHealth playerHealth = PlayerController.instance.playerAvatarScript.playerHealth;
int num = (int)AccessTools.Field(typeof(PlayerHealth), "health").GetValue(playerHealth);
int value = ConfigManager.hpCost.Value;
if (num >= value)
{
string text = SemiFunc.PlayerGetSteamID(PlayerAvatar.instance);
SemiFunc.PlayerGetSteamID(grabHead.playerAvatar);
grabHead.Revive();
int num2 = num - value;
StatsManager.instance.SetPlayerHealth(text, num2, false);
string arg = (AccessTools.Field(((object)grabHead.playerAvatar).GetType(), "playerName")?.GetValue(grabHead.playerAvatar) as string) ?? "Unknown";
Debug.Log((object)$"[BetaRevive] Revived {arg} and reduced local HP to {num2}");
}
else
{
Debug.Log((object)"[BetaRevive] No tienes suficiente HP para revivir");
}
}
}
[HarmonyPatch(typeof(ShopManager))]
internal class ShopManagerPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void keyboardListener(ShopManager __instance)
{
if ((Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).gameObject.GetComponent<ReviveManager>() == (Object)null)
{
((Component)__instance).gameObject.AddComponent<ReviveManager>();
Debug.Log((object)"[BetaRevive] Added keyboard event listener");
}
}
}
}