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 BepInEx.Configuration;
using BepInEx.Logging;
using CarryRegeneration.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.Kirshoo.CarryRegeneration")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: AssemblyProduct("com.github.Kirshoo.CarryRegeneration")]
[assembly: AssemblyTitle("CarryRegeneration")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace CarryRegeneration
{
[BepInPlugin("com.github.Kirshoo.CarryRegeneration", "CarryRegeneration", "1.2.1")]
public class Plugin : BaseUnityPlugin
{
internal static ConfigEntry<float> RegenerationRate;
internal static ConfigEntry<KeyCode> DebugPassoutButton;
public const string Id = "com.github.Kirshoo.CarryRegeneration";
internal static ManualLogSource Log { get; private set; }
public static string Name => "CarryRegeneration";
public static string Version => "1.2.1";
private void Awake()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
RegenerationRate = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RegenerationRate", 0.5f, "Rate at which death timer will decrease at.\r\nHigher numbers will make it 'regenerate' faster, while lower - slower.\r\nIf set to 0 or lower, will disable regeneration all together.");
new Harmony("com.github.Kirshoo.CarryRegeneration").PatchAll(typeof(PassoutPatch));
Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
}
}
}
namespace CarryRegeneration.Patches
{
internal class PassoutPatch
{
private static List<int> IndicesOfLoadingCharacterData(List<CodeInstruction> list)
{
List<int> list2 = new List<int>();
for (int i = 0; i < list.Count; i++)
{
if (i >= 1 && list[i - 1].opcode == OpCodes.Ldarg_0 && list[i].opcode == OpCodes.Ldfld && (FieldInfo)list[i].operand == AccessTools.Field(typeof(Character), "data"))
{
list2.Add(i - 1);
}
}
return list2;
}
public static bool IsAfterFixVersion(BuildVersion current)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
if (current.MajorVersion == 1)
{
return current.MinorVersion > 43;
}
return false;
}
private static bool IsCarriedCheck(List<CodeInstruction> list, int index, BuildVersion version)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
FieldInfo fieldInfo = AccessTools.Field(typeof(Character), "data");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(CharacterData), "carrier");
MethodInfo methodInfo = AccessTools.Method(typeof(Object), "op_Implicit", new Type[1] { typeof(Object) }, (Type[])null);
List<OpCode> list2 = new List<OpCode>();
if (IsAfterFixVersion(version))
{
list2.AddRange(new OpCode[2]
{
OpCodes.Brfalse,
OpCodes.Brfalse_S
});
}
else
{
list2.AddRange(new OpCode[2]
{
OpCodes.Brtrue,
OpCodes.Brtrue_S
});
}
if (list[index].opcode == OpCodes.Ldarg_0 && list[index + 1].opcode == OpCodes.Ldfld && (FieldInfo)list[index + 1].operand == fieldInfo && list[index + 2].opcode == OpCodes.Ldfld && (FieldInfo)list[index + 2].operand == fieldInfo2 && list[index + 3].opcode == OpCodes.Call && (MethodInfo)list[index + 3].operand == methodInfo)
{
return list2.Contains(list[index + 4].opcode);
}
return false;
}
[HarmonyPatch(typeof(Character), "UpdateVariablesFixed")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> AddTimeIfCarried(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
BuildVersion version = default(BuildVersion);
((BuildVersion)(ref version))..ctor(Application.version);
Plugin.Log.LogDebug((object)("Running PEAK v" + ((BuildVersion)(ref version)).ToMatchmaking()));
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = -1;
for (int i = 0; i < list.Count - 4; i++)
{
if (IsCarriedCheck(list, i, version))
{
num = i;
break;
}
}
if (num == -1)
{
Plugin.Log.LogError((object)"[Transpiler] Unable to find the carrier check");
return instructions;
}
Plugin.Log.LogDebug((object)$"[Transpiler] Found carrier check on {num}");
Label exitCodeBlockLabel = (Label)list[num - 1].operand;
Label label = il.DefineLabel();
Label label2 = il.DefineLabel();
list[num].labels.Add(label2);
Plugin.Log.LogDebug((object)$"[Transpiler] Added label to {list[num].opcode}. Total amount of labels: {list[num].labels.Count}");
List<CodeInstruction> list2 = new List<CodeInstruction>(GetIsCarriedCheckInstructions(label2));
List<CodeInstruction> collection = new List<CodeInstruction>(GetDeathTimerIncrementInstructions(exitCodeBlockLabel));
Plugin.Log.LogDebug((object)"[Transpiler] Loaded the code instructions to inject");
int num2 = num;
while (list[num2].opcode != OpCodes.Brfalse_S && list[num2].opcode != OpCodes.Brfalse && num2 > 0)
{
num2--;
}
if (num2 <= 0)
{
Plugin.Log.LogError((object)"[Transpiler] Unable to find the next code block jump");
return instructions;
}
Plugin.Log.LogDebug((object)$"[Transpiler] Found end of interact is pressed check at {num2}");
list2[0].labels.Add(label);
list[num2].operand = label;
Plugin.Log.LogDebug((object)"[Transpiler] Changed label to point to injected check");
list.InsertRange(num, list2);
list.InsertRange(num + list2.Count, collection);
return list;
}
private static IEnumerable<CodeInstruction> GetIsCarriedCheckInstructions(Label labelToJumpTo)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Expected O, but got Unknown
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Expected O, but got Unknown
return (IEnumerable<CodeInstruction>)(object)new CodeInstruction[5]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Character), "data")),
new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(CharacterData), "carrier")),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Object), "op_Implicit", new Type[1] { typeof(Object) }, (Type[])null)),
new CodeInstruction(OpCodes.Brfalse, (object)labelToJumpTo)
};
}
private static IEnumerable<CodeInstruction> GetDeathTimerIncrementInstructions(Label exitCodeBlockLabel)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Expected O, but got Unknown
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Expected O, but got Unknown
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Expected O, but got Unknown
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Expected O, but got Unknown
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Expected O, but got Unknown
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Expected O, but got Unknown
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Expected O, but got Unknown
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Expected O, but got Unknown
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Expected O, but got Unknown
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Expected O, but got Unknown
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f1: Expected O, but got Unknown
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Expected O, but got Unknown
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Expected O, but got Unknown
float num = Mathf.Max(Plugin.RegenerationRate.Value, 0f);
return (IEnumerable<CodeInstruction>)(object)new CodeInstruction[20]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Character), "data")),
new CodeInstruction(OpCodes.Dup, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(CharacterData), "deathTimer")),
new CodeInstruction(OpCodes.Ldc_R4, (object)num),
new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(Time), "fixedDeltaTime")),
new CodeInstruction(OpCodes.Mul, (object)null),
new CodeInstruction(OpCodes.Ldc_R4, (object)60f),
new CodeInstruction(OpCodes.Div, (object)null),
new CodeInstruction(OpCodes.Sub, (object)null),
new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(CharacterData), "deathTimer")),
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Character), "data")),
new CodeInstruction(OpCodes.Ldc_R4, (object)0f),
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Character), "data")),
new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(CharacterData), "deathTimer")),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Mathf), "Max", new Type[2]
{
typeof(float),
typeof(float)
}, (Type[])null)),
new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(CharacterData), "deathTimer")),
new CodeInstruction(OpCodes.Br, (object)exitCodeBlockLabel)
};
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}