using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UltimateRevive.Patch;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("UltimateRevive")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UltimateRevive")]
[assembly: AssemblyTitle("UltimateRevive")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace UltimateRevive
{
[BepInPlugin("Godji.UltimateRevive", "REPO Ultimate Revive", "1.0.2")]
public class UltimateRevive : BaseUnityPlugin
{
public const string modGUID = "Godji.UltimateRevive";
public const string modName = "REPO Ultimate Revive";
public const string modVersion = "1.0.2";
public readonly Harmony harmony = new Harmony("Godji.UltimateRevive");
public static UltimateRevive instance;
public ManualLogSource mls;
public 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 初始化完成");
harmony.PatchAll(typeof(UltimateRevive));
harmony.PatchAll(typeof(ShopManagerPatch));
harmony.PatchAll(typeof(PlayerControllerPatch));
harmony.PatchAll(typeof(PhysGrabCartPatch));
harmony.PatchAll(typeof(PlayerAvatarPatch));
}
}
}
namespace UltimateRevive.Patch
{
public class ConfigManager
{
public static ConfigEntry<int> hpCost;
public static ConfigEntry<string> reviveKey;
public static void Initialize(ConfigFile config)
{
hpCost = config.Bind<int>("復活 HP 設定", "HP 消耗", 1, "復活時消耗的 HP");
reviveKey = config.Bind<string>("控制", "復活按鍵", "h", "用於觸發復活的按鍵");
}
}
[HarmonyPatch(typeof(PhysGrabCart))]
public class PhysGrabCartPatch
{
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void displayText()
{
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: 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);
int value2 = ConfigManager.hpCost.Value;
string value3 = ConfigManager.reviveKey.Value;
if ((int)AccessTools.Field(typeof(PlayerHealth), "health").GetValue(PlayerController.instance.playerAvatarScript.playerHealth) <= value2)
{
Color val = default(Color);
((Color)(ref val))..ctor(1f, 0f, 0f);
ItemInfoExtraUI.instance.ItemInfoText($"你的 HP 低於 {value2}", val);
}
else
{
Color val2 = default(Color);
((Color)(ref val2))..ctor(0.2f, 0.8f, 0.1f);
ItemInfoExtraUI.instance.ItemInfoText($"按下 [{value3}] 消耗 {value2} HP 復活 {value}", val2);
}
}
}
}
[HarmonyPatch(typeof(PlayerAvatar))]
public class PlayerAvatarPatch
{
[HarmonyPatch("ReviveRPC")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> transpiler(IEnumerable<CodeInstruction> instruction)
{
List<CodeInstruction> list = instruction.ToList();
list.RemoveRange(0, 4);
return list.AsEnumerable();
}
}
[HarmonyPatch(typeof(PlayerController))]
public class PlayerControllerPatch
{
public static PlayerDeathHead grabHead;
public static bool isGrab;
[HarmonyPatch("FixedUpdate")]
[HarmonyPostfix]
public static void PlayerGrabHeadPatch(PlayerController __instance)
{
if (!((Object)(object)__instance != (Object)null))
{
return;
}
if (!__instance.physGrabActive || !((Object)(object)__instance.physGrabObject != (Object)null))
{
isGrab = false;
return;
}
PlayerDeathHead component = __instance.physGrabObject.GetComponent<PlayerDeathHead>();
if ((Object)(object)component != (Object)null && (Object)(object)component.playerAvatar != (Object)null)
{
grabHead = component;
isGrab = true;
}
}
}
public class ReviveManager : MonoBehaviour
{
public void Update()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (!((ButtonControl)((InputControl)Keyboard.current)[ConfigManager.reviveKey.Value]).wasPressedThisFrame)
{
return;
}
PlayerDeathHead grabHead = PlayerControllerPatch.grabHead;
bool isGrab = PlayerControllerPatch.isGrab;
PlayerHealth playerHealth = PlayerController.instance.playerAvatarScript.playerHealth;
int num = (int)AccessTools.Field(typeof(PlayerHealth), "health").GetValue(playerHealth);
int value = ConfigManager.hpCost.Value;
if (num > value && isGrab)
{
FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerDeathHead), "inExtractionPoint");
if (!(bool)fieldInfo.GetValue(grabHead))
{
fieldInfo.SetValue(grabHead, true);
grabHead.Revive();
fieldInfo.SetValue(grabHead, false);
playerHealth.Hurt(value, true, -1);
}
}
}
}
[HarmonyPatch(typeof(ShopManager))]
public class ShopManagerPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
public 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)"[Ultimate Revive] 新增鍵盤事件 Listener");
}
}
}
}