using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using MatcherExtensions;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("JoryDeathQOL")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Tweaks death to be less annoying")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("JoryDeathQOL")]
[assembly: AssemblyTitle("JoryDeathQOL")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace JoryDeathQOL
{
internal class RestedInfo
{
public float ttl;
public float time;
public static RestedInfo FromSE(StatusEffect se)
{
if ((Object)(object)se == (Object)null)
{
return null;
}
RestedInfo restedInfo = new RestedInfo();
restedInfo.ttl = se.m_ttl;
restedInfo.time = se.m_time;
return restedInfo;
}
}
[BepInPlugin("com.joryjuky.deathqol", "JoryDeathQol", "1.0.0")]
public class DeathQOL : BaseUnityPlugin
{
private const string pluginGUID = "com.joryjuky.deathqol";
private const string pluginName = "JoryDeathQol";
private const string pluginVersion = "1.0.0";
private static RestedInfo restedInfo = null;
private static readonly MethodInfo FoodClear = AccessTools.Method(typeof(List<Food>), "Clear", (Type[])null, (Type[])null);
private static readonly MethodInfo ReduceSkills = AccessTools.Method(typeof(Skills), "OnDeath", (Type[])null, (Type[])null);
private static readonly int Rested = StringExtensionMethods.GetStableHashCode("Rested");
private void Awake()
{
Harmony.CreateAndPatchAll(typeof(DeathQOL), (string)null);
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(Player), "OnDeath")]
private static IEnumerable<CodeInstruction> DeathTranspiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
return MatcherExtension.RemoveMethodCall(new CodeMatcher(instructions, (ILGenerator)null), FoodClear).RemoveMethodCall(ReduceSkills).InstructionEnumeration();
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Player), "OnDeath")]
private static void SaveRested(Player __instance)
{
StatusEffect statusEffect = ((Character)__instance).m_seman.GetStatusEffect(Rested);
restedInfo = RestedInfo.FromSE(statusEffect);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Player), "OnSpawned")]
private static void LoadRested(Player __instance)
{
if (restedInfo != null)
{
StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(Rested);
statusEffect.m_ttl = restedInfo.ttl;
statusEffect.m_time = restedInfo.time;
((Character)__instance).m_seman.AddStatusEffect(statusEffect, false, 0, 0f);
restedInfo = null;
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "JoryDeathQOL";
public const string PLUGIN_NAME = "JoryDeathQOL";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace MatcherExtensions
{
public static class MatcherExtension
{
public static CodeMatcher RemoveMethodCall(this CodeMatcher matcher, MethodInfo method)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
return matcher.MatchForward(false, (CodeMatch[])(object)new CodeMatch[3]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, method)), (string)null)
}).RemoveInstructions(3);
}
}
}