Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Berserk v1.0.0
Berserk.dll
Decompiled 13 hours agousing System; using System.Diagnostics; 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 Berserk.Patches; using Character_Stats; using HarmonyLib; using Microsoft.CodeAnalysis; 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 = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("headclef")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+e7acae4dc078c4bf75f0ba4a4c4358f8e3cc91db")] [assembly: AssemblyProduct("Berserk")] [assembly: AssemblyTitle("Berserk")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 Berserk { [BepInPlugin("headclef.Berserk", "Berserk", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Berserk : BaseUnityPlugin { private const string PluginGuid = "headclef.Berserk"; private const string PluginName = "Berserk"; private const string PluginVersion = "1.0.0"; internal static ConfigEntry<KeyboardShortcut> ToggleKey; internal static ConfigEntry<float> HealthDrainPerSecond; internal static ConfigEntry<int> StrengthBonus; internal static ConfigEntry<int> LaunchBonus; internal static ConfigEntry<bool> CanBeLethal; internal static ConfigEntry<bool> ShowIndicator; private static Texture2D? _whiteTex; internal static Berserk Instance { get; private set; } internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } public static bool IsActive => BerserkPatch.IsActive; public static int ActiveStrengthBonus => BerserkPatch.ActiveStrengthBonus; public static int ActiveLaunchBonus => BerserkPatch.ActiveLaunchBonus; private static Texture2D WhiteTex { get { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_0024: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_whiteTex == (Object)null) { _whiteTex = new Texture2D(1, 1); _whiteTex.SetPixel(0, 0, Color.white); _whiteTex.Apply(); } return _whiteTex; } } private void Awake() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown //IL_0054: Expected O, but got Unknown Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; BindConfiguration(); if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } private void OnDestroy() { BerserkPatch.ForceDeactivate(); Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void BindConfiguration() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Berserk", "Toggle Key", new KeyboardShortcut((KeyCode)98, Array.Empty<KeyCode>()), "Key to toggle the berserk state on and off."); HealthDrainPerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("Berserk", "Health Drain Per Second", 10f, new ConfigDescription("Health drained every second while berserk is active. Can kill you (see Can Be Lethal).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); StrengthBonus = ((BaseUnityPlugin)this).Config.Bind<int>("Berserk", "Strength Bonus", 5, new ConfigDescription("Temporary Strength levels added while berserk is active (real grab/throw power plus everything that reads your Strength level).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50), Array.Empty<object>())); LaunchBonus = ((BaseUnityPlugin)this).Config.Bind<int>("Berserk", "Launch Bonus", 5, new ConfigDescription("Temporary Tumble Launch levels added while berserk is active (real launch force plus everything that reads your Launch level).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50), Array.Empty<object>())); CanBeLethal = ((BaseUnityPlugin)this).Config.Bind<bool>("Berserk", "Can Be Lethal", true, "If true, the drain can take you to 0 HP and kill you. If false, the drain stops at 1 HP and never kills you directly."); ShowIndicator = ((BaseUnityPlugin)this).Config.Bind<bool>("Berserk", "Show Indicator", true, "Show the on-screen BERSERK indicator while the state is active."); } private static void FillRect(Rect r, Color c) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Color color = GUI.color; GUI.color = c; GUI.DrawTexture(r, (Texture)(object)WhiteTex); GUI.color = color; } private static void DrawBorder(Rect r, float t, Color c) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) FillRect(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, t), c); FillRect(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - t, ((Rect)(ref r)).width, t), c); FillRect(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), c); FillRect(new Rect(((Rect)(ref r)).xMax - t, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), c); } private void OnGUI() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) if (ShowIndicator.Value && BerserkPatch.IsActive) { float num = Mathf.PingPong(Time.unscaledTime * 2.2f, 1f); float num2 = ((float)Screen.width - 220f) / 2f; float num3 = 52f; Rect val = default(Rect); ((Rect)(ref val))..ctor(num2, num3, 220f, 42f); FillRect(val, new Color(0.42f, 0f, 0f, Mathf.Lerp(0.55f, 0.82f, num))); DrawBorder(val, 2f, new Color(1f, 0.22f, 0.12f, Mathf.Lerp(0.55f, 1f, num))); GUIStyle val2 = new GUIStyle { alignment = (TextAnchor)4, fontSize = 21, fontStyle = (FontStyle)1 }; val2.normal.textColor = new Color(0f, 0f, 0f, 0.85f); GUI.Label(new Rect(num2 + 2f, num3 + 2f, 220f, 42f), "BERSERK", val2); val2.normal.textColor = Color.Lerp(new Color(1f, 0.45f, 0.32f), new Color(1f, 0.12f, 0.06f), num); GUI.Label(val, "BERSERK", val2); } } } } namespace Berserk.Patches { [HarmonyPatch] internal static class BerserkPatch { private static bool _active; private static float _drainAccum; private static PlayerAvatar? _appliedAvatar; private static string? _overlaySteamId; private static int _appliedStrengthBonus; private static int _appliedLaunchBonus; private static float _appliedGrabDelta; internal static bool IsActive => _active; internal static int ActiveStrengthBonus => _active ? _appliedStrengthBonus : 0; internal static int ActiveLaunchBonus => _active ? _appliedLaunchBonus : 0; private static bool TogglePressed() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = Berserk.ToggleKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey == 0 || !Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey)) { return false; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers) { if (!Input.GetKey(modifier)) { return false; } } return true; } [HarmonyPatch(typeof(PlayerController), "Update")] [HarmonyPostfix] private static void PlayerController_Update_Postfix(PlayerController __instance) { try { if ((Object)(object)__instance != (Object)(object)PlayerController.instance) { return; } PlayerAvatar playerAvatarScript = __instance.playerAvatarScript; if (_active && ((Object)(object)playerAvatarScript == (Object)null || playerAvatarScript.deadSet || !SemiFunc.RunIsLevel())) { Deactivate(); return; } if (TogglePressed()) { if (_active) { Deactivate(); } else if ((Object)(object)playerAvatarScript != (Object)null && !playerAvatarScript.deadSet && SemiFunc.RunIsLevel()) { Activate(playerAvatarScript); } } if (_active && (Object)(object)playerAvatarScript != (Object)null) { DrainTick(playerAvatarScript); } } catch (Exception ex) { Berserk.Logger.LogError((object)("Berserk update exception: " + ex.Message)); Deactivate(); } } private static void DrainTick(PlayerAvatar avatar) { PlayerHealth playerHealth = avatar.playerHealth; if ((Object)(object)playerHealth == (Object)null) { return; } float value = Berserk.HealthDrainPerSecond.Value; if (value <= 0f) { return; } _drainAccum += value * Time.deltaTime; if (_drainAccum < 1f) { return; } int num = (int)_drainAccum; _drainAccum -= num; int num2 = playerHealth.health - num; if (num2 <= 0) { if (Berserk.CanBeLethal.Value) { playerHealth.health = 0; Deactivate(); avatar.PlayerDeath(-1); } else { playerHealth.health = 1; } } else { playerHealth.health = num2; } } private static void Activate(PlayerAvatar avatar) { if (_active) { return; } string text = (((Object)(object)PlayerController.instance != (Object)null) ? PlayerController.instance.playerSteamID : null); if (!string.IsNullOrEmpty(text)) { int value = Berserk.StrengthBonus.Value; int value2 = Berserk.LaunchBonus.Value; Character_Stats.SetTemporaryBonus(text, "Strength", value); Character_Stats.SetTemporaryBonus(text, "Launch", value2); float num = 0.2f * (float)value; if ((Object)(object)avatar.physGrabber != (Object)null) { PhysGrabber physGrabber = avatar.physGrabber; physGrabber.grabStrength += num; } if ((Object)(object)avatar.tumble != (Object)null) { PlayerTumble tumble = avatar.tumble; tumble.tumbleLaunch += value2; } _appliedAvatar = avatar; _overlaySteamId = text; _appliedStrengthBonus = value; _appliedLaunchBonus = value2; _appliedGrabDelta = num; _drainAccum = 0f; _active = true; } } private static void Deactivate() { if (!_active) { return; } _active = false; PlayerAvatar appliedAvatar = _appliedAvatar; if ((Object)(object)appliedAvatar != (Object)null) { if ((Object)(object)appliedAvatar.physGrabber != (Object)null) { PhysGrabber physGrabber = appliedAvatar.physGrabber; physGrabber.grabStrength -= _appliedGrabDelta; } if ((Object)(object)appliedAvatar.tumble != (Object)null) { PlayerTumble tumble = appliedAvatar.tumble; tumble.tumbleLaunch -= _appliedLaunchBonus; } } if (!string.IsNullOrEmpty(_overlaySteamId)) { Character_Stats.ClearTemporaryBonus(_overlaySteamId, "Strength"); Character_Stats.ClearTemporaryBonus(_overlaySteamId, "Launch"); } _appliedAvatar = null; _overlaySteamId = null; _appliedStrengthBonus = 0; _appliedLaunchBonus = 0; _appliedGrabDelta = 0f; _drainAccum = 0f; } [HarmonyPatch(typeof(SemiFunc), "OnSceneSwitch")] [HarmonyPrefix] private static void OnSceneSwitch_Prefix() { ForceDeactivate(); } internal static void ForceDeactivate() { try { Deactivate(); } catch { } } } }