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 HarmonyLib;
using UltimateRevive.Patches;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UltimateRevive")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UltimateRevive")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f6d01380-ae72-46c1-999b-efd8e0c25027")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace UltimateRevive
{
[BepInPlugin("Godji.UltimateRevive", "REPO Ultimate Revive", "1.0.0")]
public class UltimateRevive : BaseUnityPlugin
{
private const string modGUID = "Godji.UltimateRevive";
private const string modName = "REPO Ultimate Revive";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Godji.UltimateRevive");
private static UltimateRevive Instance;
internal ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("Godji.UltimateRevive");
ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
mls.LogInfo((object)"[Godji] Ultiumate Revive Inited.");
harmony.PatchAll(typeof(UltimateRevive));
harmony.PatchAll(typeof(ShopManagerPatch));
harmony.PatchAll(typeof(PlayerControllerPatch));
harmony.PatchAll(typeof(PhysGrabCartPatch));
}
}
}
namespace UltimateRevive.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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
if (!SemiFunc.RunIsShop() && PlayerControllerPatch.isGrab)
{
FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerAvatar), "playerName");
object value = fieldInfo.GetValue(PlayerControllerPatch.grabHead.playerAvatar);
PlayerHealth playerHealth = PlayerController.instance.playerAvatarScript.playerHealth;
FieldInfo fieldInfo2 = AccessTools.Field(typeof(PlayerHealth), "health");
int num = (int)fieldInfo2.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_0017: Unknown result type (might be due to invalid IL or missing references)
InputControl val = ((InputControl)Keyboard.current)[ConfigManager.reviveKey.Value];
if (!((ButtonControl)val).wasPressedThisFrame)
{
return;
}
PlayerDeathHead grabHead = PlayerControllerPatch.grabHead;
bool isGrab = PlayerControllerPatch.isGrab;
PlayerHealth playerHealth = PlayerController.instance.playerAvatarScript.playerHealth;
FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerHealth), "health");
int num = (int)fieldInfo.GetValue(playerHealth);
int value = ConfigManager.hpCost.Value;
if (num >= value && num >= num - value && isGrab)
{
FieldInfo fieldInfo2 = AccessTools.Field(typeof(PlayerDeathHead), "inExtractionPoint");
if (!(bool)fieldInfo2.GetValue(grabHead))
{
fieldInfo2.SetValue(grabHead, true);
grabHead.Revive();
playerHealth.Hurt(value, true, -1);
fieldInfo2.SetValue(grabHead, false);
}
}
}
}
[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)"[UltimateRevive] Added keyboard event listener");
}
}
}
}