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 HarmonyLib;
using Microsoft.CodeAnalysis;
[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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TumbleLaunchRebalance")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+81904c0ac01d4a594d11d7cc2df73b2e9a0eb3e6")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("TumbleLaunchRebalance")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace TumbleLaunchRebalance
{
[BepInPlugin("TumbleLaunchRebalance", "My first plugin", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private static bool _patchFailed;
private static ConfigEntry<int> _configTumbleDamageOnHitEnemy;
private static ConfigEntry<int> _configTumbleUpgradesNeededForMaxReduction;
private static ConfigEntry<float> _configTumbleUpgradeMaxDamageReduction;
internal static ManualLogSource Logger;
private void LoadConfig()
{
_configTumbleDamageOnHitEnemy = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "TumbleDamageOnHitEnemy", 0, "The amount of damage the player is dealt when hitting an enemy while tumbling.");
_configTumbleUpgradesNeededForMaxReduction = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "TumbleUpgradesNeededForMaxReduction", 8, "The number of Tumble Launch upgrades the player needs to reach the max damage reduction. E.g. 5 means the player will reach maximum tumble damage reduction on their 5th upgrade.");
_configTumbleUpgradeMaxDamageReduction = ((BaseUnityPlugin)this).Config.Bind<float>("Balance", "MaxDamageReduction", 1f, "The maximum reduction to damage (while tumbling) that can be attained. E.g. 0.75 means the player can reach 75% reduction in damage, in which 100 damage would become -> 25.");
}
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin TumbleLaunchRebalance is loading...");
LoadConfig();
Harmony val = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
if (_patchFailed)
{
Logger.LogFatal((object)"Failure to patch, reverting!");
Harmony.UnpatchID(val.Id);
}
else
{
Logger.LogInfo((object)"Plugin TumbleLaunchRebalance loaded!");
}
}
[HarmonyPatch(typeof(PlayerTumble), "HitEnemy")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> PatchTumbleDamage(IEnumerable<CodeInstruction> instructions)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Expected O, but got Unknown
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Expected O, but got Unknown
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Expected O, but got Unknown
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Expected O, but got Unknown
try
{
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_I4_5, (object)null, (string)null)
});
if (!val.IsValid)
{
Logger.LogFatal((object)"Failed to find patch location for first HitEnemy, reverting!");
_patchFailed = true;
return instructions;
}
val.Set(OpCodes.Ldc_I4, (object)_configTumbleDamageOnHitEnemy.Value);
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[4]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_I4_5, (object)null, (string)null)
});
if (!val.IsValid)
{
Logger.LogFatal((object)"Failed to find patch location for second HitEnemy, reverting!");
_patchFailed = true;
return instructions;
}
val.Set(OpCodes.Ldc_I4, (object)_configTumbleDamageOnHitEnemy.Value);
return val.InstructionEnumeration();
}
catch (Exception ex)
{
Logger.LogFatal((object)("Exception caught while patching HitEnemy, reverting! Message: " + ex.Message));
_patchFailed = true;
return instructions;
}
}
[HarmonyPatch(typeof(PlayerTumble), "BreakImpact")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> PatchTumbleDamageReduction(IEnumerable<CodeInstruction> instructions)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Expected O, but got Unknown
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Expected O, but got Unknown
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Expected O, but got Unknown
try
{
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[5]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlayerTumble), "playerAvatar"), (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlayerAvatar), "playerHealth"), (string)null),
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(PlayerTumble), "impactHurtDamage"), (string)null)
});
val.Advance(1);
if (!val.IsValid)
{
Logger.LogFatal((object)"Failed to find patch location for Damage Reduction Patch, reverting!");
_patchFailed = true;
return instructions;
}
val.Advance(1);
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null)
});
val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
{
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Plugin), "CalculateTumbleDamage", (Type[])null, (Type[])null))
});
val.Start();
return val.InstructionEnumeration();
}
catch (Exception ex)
{
Logger.LogFatal((object)("Exception caught while patching BreakImpact, reverting! Message: " + ex.Message));
_patchFailed = true;
return instructions;
}
}
public static int CalculateTumbleDamage(int damage, PlayerTumble tumble)
{
try
{
if (_configTumbleUpgradesNeededForMaxReduction.Value == 0)
{
return (int)(1f - _configTumbleUpgradeMaxDamageReduction.Value) * damage;
}
int num = StatsManager.instance.playerUpgradeLaunch[SemiFunc.PlayerGetSteamID(tumble.playerAvatar)];
float num2 = 1f - _configTumbleUpgradeMaxDamageReduction.Value * (float)Math.Min(num / _configTumbleUpgradesNeededForMaxReduction.Value, 1);
return (int)num2 * damage;
}
catch (Exception ex)
{
Logger.LogFatal((object)("Exception thrown while calculating tumble damage reduction! Message: " + ex.Message));
return damage;
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TumbleLaunchRebalance";
public const string PLUGIN_NAME = "My first plugin";
public const string PLUGIN_VERSION = "1.0.0";
}
}