using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NoDeathPenalty")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+8f04ede6c58024ed53d539a18ae19bcec43c7ba0")]
[assembly: AssemblyProduct("NoDeathPenalty")]
[assembly: AssemblyTitle("No Death Penalty")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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")]
[Microsoft.CodeAnalysis.Embedded]
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")]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace Microsoft.CodeAnalysis
{
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace NoDeathPenalty
{
[BepInPlugin("nozwock.NoDeathPenalty", "No Death Penalty", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch]
private class Patch_PlayerGamePlayData_PlayerDeathPenalty
{
public static bool patchedGold;
public static bool patchedExp;
private static MethodBase TargetMethod()
{
return GetAsyncMethod(typeof(PlayerGamePlayData), "PlayerDeathPenalty");
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
patchedGold = false;
patchedExp = false;
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (CodeInstructionExtensions.IsLdloc(list[i], (LocalBuilder)null) && CodeInstructionExtensions.LoadsConstant(list[i + 1], 0L) && CodeInstructionExtensions.Calls(list[i + 2], AccessTools.PropertySetter(typeof(PlayerGamePlayData), "CurrentGold")))
{
list[i].opcode = OpCodes.Nop;
list[i + 1].opcode = OpCodes.Nop;
list[i + 2].opcode = OpCodes.Nop;
patchedGold = true;
}
if (CodeInstructionExtensions.IsLdloc(list[i], (LocalBuilder)null) && CodeInstructionExtensions.LoadsConstant(list[i + 1], 0L) && CodeInstructionExtensions.Calls(list[i + 2], AccessTools.PropertySetter(typeof(PlayerGamePlayData), "CurrentExp")))
{
list[i].opcode = OpCodes.Nop;
list[i + 1].opcode = OpCodes.Nop;
list[i + 2].opcode = OpCodes.Nop;
patchedExp = true;
}
}
return list.AsEnumerable();
}
}
[HarmonyPatch(typeof(PlayerDeadRecord), "StorePlayerDataBeforeDead")]
private class Patch_PlayerDeadRecord_StorePlayerDataBeforeDead
{
private static void Postfix(PlayerDeadRecord __instance)
{
if (Patch_PlayerGamePlayData_PlayerDeathPenalty.patchedGold)
{
((FlagField<float>)(object)__instance.ContainMoney).CurrentValue = 0f;
}
if (Patch_PlayerGamePlayData_PlayerDeathPenalty.patchedExp)
{
((FlagField<float>)(object)__instance.ContainEXP).CurrentValue = 0f;
}
}
}
internal static ManualLogSource Logger;
private static Harmony harmony;
public const string Id = "nozwock.NoDeathPenalty";
public static string Name => "No Death Penalty";
public static string Version => "1.0.2";
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
Logger.LogInfo((object)"Plugin nozwock.NoDeathPenalty is loaded!");
harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "nozwock.NoDeathPenalty");
foreach (MethodBase patchedMethod in harmony.GetPatchedMethods())
{
Logger.LogInfo((object)("Patched method: " + patchedMethod.DeclaringType?.FullName + "." + patchedMethod.Name));
}
if (harmony.GetPatchedMethods().Count() == 0)
{
Logger.LogError((object)"Failed to apply Harmony patches.");
}
}
private void OnDestroy()
{
Logger.LogInfo((object)"Unloading plugin nozwock.NoDeathPenalty");
Harmony obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
}
private static MethodBase GetAsyncMethod(Type type, string name)
{
return AccessTools.Method(AccessTools.Method(type, name, (Type[])null, (Type[])null).GetCustomAttribute<AsyncStateMachineAttribute>().StateMachineType, "MoveNext", (Type[])null, (Type[])null);
}
}
}