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 PocketObliterator v0.1.0
plugins\PocketObliterator\PocketObliterator.dll
Decompiled 16 hours agousing System; using System.Collections.Generic; 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 HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Laoch")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) Laoch")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0+df5194d004b78140b7e469191e6ad0ef8b7ab52b")] [assembly: AssemblyProduct("PocketObliterator")] [assembly: AssemblyTitle("PocketObliterator")] [assembly: InternalsVisibleTo("PocketObliterator.Harness")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PocketObliterator { internal static class Lightning { private const string FallbackPrefab = "lightningAOE"; private static GameObject prefab; private static float ringDamage = 10f; private static float ringRadius = 2.42f; internal static float RingDamage { get { Resolve(); return ringDamage; } } internal static float RingRadius { get { Resolve(); return ringRadius; } } private static bool Resolve() { if ((Object)(object)prefab != (Object)null) { return true; } ZNetScene instance = ZNetScene.instance; if ((Object)(object)instance == (Object)null) { return false; } foreach (GameObject prefab in instance.m_prefabs) { Incinerator val = (((Object)(object)prefab == (Object)null) ? null : prefab.GetComponent<Incinerator>()); if ((Object)(object)val != (Object)null && (Object)(object)val.m_lightingAOEs != (Object)null) { Lightning.prefab = val.m_lightingAOEs; break; } } if ((Object)(object)Lightning.prefab == (Object)null) { Lightning.prefab = instance.GetPrefab("lightningAOE"); } if ((Object)(object)Lightning.prefab == (Object)null) { return false; } float num = -1f; Aoe[] componentsInChildren = Lightning.prefab.GetComponentsInChildren<Aoe>(true); foreach (Aoe val2 in componentsInChildren) { if (!(val2.m_radius <= num)) { num = val2.m_radius; ringRadius = val2.m_radius; ringDamage = val2.m_damage.m_lightning; } } return true; } internal static void Strike(Player player) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) if (!Settings.Lightning.Value || (Object)(object)player == (Object)null) { return; } if (Resolve()) { GameObject val = Object.Instantiate<GameObject>(prefab, ((Component)player).transform.position, Quaternion.identity); Aoe[] componentsInChildren = val.GetComponentsInChildren<Aoe>(true); foreach (Aoe obj in componentsInChildren) { obj.m_damage = default(DamageTypes); ((Behaviour)obj).enabled = false; } Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } } else { PocketObliteratorPlugin.Log.LogWarning((object)"Obliterator lightning prefab not found; skipping the visual."); } float num = ringDamage * Settings.DamageMultiplier.Value; if (!Settings.DamageEnabled.Value || num <= 0f) { return; } Shock(player, num, Settings.CanKill.Value, otherPlayer: false); if (!Settings.ShockBystanders.Value) { return; } foreach (Player allPlayer in Player.GetAllPlayers()) { if ((Object)(object)allPlayer != (Object)(object)player && !((Character)allPlayer).IsDead() && Vector3.Distance(((Component)allPlayer).transform.position, ((Component)player).transform.position) <= ringRadius) { Shock(allPlayer, num, canKill: false, otherPlayer: true); } } } private static void Shock(Player target, float lightning, bool canKill, bool otherPlayer) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown HitData val = new HitData { m_point = ((Character)target).GetCenterPoint(), m_dir = Vector3.up, m_ignorePVP = otherPlayer }; val.m_damage.m_lightning = lightning; if (!canKill) { float num = ((Character)target).GetHealth() - 1f; if (Taken(target, val, lightning) > num) { float num2 = 0f; float num3 = lightning; for (int i = 0; i < 24; i++) { float num4 = (num2 + num3) / 2f; if (Taken(target, val, num4) > num) { num3 = num4; } else { num2 = num4; } } val.m_damage.m_lightning = num2; } } if (val.m_damage.m_lightning > 0f) { ((Character)target).Damage(val); } } internal static float Taken(Player target, HitData hit, float lightning) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) HitData obj = hit.Clone(); obj.m_damage.m_lightning = lightning; DamageModifier val = default(DamageModifier); obj.ApplyResistance(((Character)target).GetDamageModifiers((WeakSpot)null), ref val); obj.ApplyArmor(((Character)target).GetBodyArmor()); return obj.GetTotalDamage(); } } internal static class Obliterator { internal const int Width = 6; internal const int Height = 4; private static readonly FieldRef<Container, Inventory> InventoryField = AccessTools.FieldRefAccess<Container, Inventory>("m_inventory"); internal static Container Current { get; private set; } internal static bool IsOpen { get { if ((Object)(object)Current != (Object)null && (Object)(object)InventoryGui.instance != (Object)null && InventoryGui.instance.IsContainerOpen()) { return (Object)(object)InventoryGui.instance.m_currentContainer == (Object)(object)Current; } return false; } } internal static Inventory Items { get { if (!((Object)(object)Current == (Object)null)) { return InventoryField.Invoke(Current); } return null; } } internal static bool IsOurs(Container c) { if ((Object)(object)c != (Object)null) { return (Object)(object)c == (Object)(object)Current; } return false; } internal static void Open() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown InventoryGui instance = InventoryGui.instance; Player localPlayer = Player.m_localPlayer; if (!((Object)(object)instance == (Object)null) && !((Object)(object)localPlayer == (Object)null)) { Discard(); GameObject val = new GameObject("PocketObliterator"); val.SetActive(false); val.transform.SetParent(((Component)localPlayer).transform, false); Container val2 = val.AddComponent<Container>(); InventoryField.Invoke(val2) = new Inventory("$piece_incinerator", (Sprite)null, 6, 4); Current = val2; instance.Show(val2, 1); } } internal static void CloseAndObliterate() { Inventory items = Items; Player localPlayer = Player.m_localPlayer; if (items == null) { return; } if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead()) { ReturnItems(localPlayer); return; } int num = items.NrOfItemsIncludingStacks(); items.RemoveAll(); if (num > 0) { Lightning.Strike(localPlayer); } } internal static void DiscardIfClosed(InventoryGui gui) { if ((Object)(object)Current != (Object)null && (Object)(object)gui != (Object)null && (Object)(object)gui.m_currentContainer != (Object)(object)Current) { Discard(); } } internal static void ReturnItems(Player player) { //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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) Inventory items = Items; if (items == null) { return; } foreach (ItemData item in new List<ItemData>(items.GetAllItems())) { items.RemoveItem(item); if (!((Object)(object)player == (Object)null)) { Inventory inventory = ((Humanoid)player).GetInventory(); if (!inventory.CanAddItem(item, -1) || !inventory.AddItem(item)) { ItemDrop.DropItem(item, item.m_stack, ((Component)player).transform.position + Vector3.up + Random.insideUnitSphere * 0.5f, Quaternion.identity); } } } } private static void Discard() { if ((Object)(object)Current != (Object)null) { Object.Destroy((Object)(object)((Component)Current).gameObject); } Current = null; } } internal static class ObliteratorButton { [CompilerGenerated] private static class <>O { public static UnityAction <0>__Open; } internal const string TileName = "PocketObliterator"; private static Sprite icon; internal static Transform Tile { get { if (!((Object)(object)InventoryGui.instance == (Object)null) && !((Object)(object)InventoryGui.instance.m_player == (Object)null)) { return ((Transform)InventoryGui.instance.m_player).Find("PocketObliterator"); } return null; } } internal static void Ensure(InventoryGui gui) { //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Expected O, but got Unknown RectTransform val = (((Object)(object)gui == (Object)null) ? null : gui.m_player); if ((Object)(object)val == (Object)null || (Object)(object)((Transform)val).Find("PocketObliterator") != (Object)null) { return; } Transform obj = ((Transform)val).Find("Armor"); RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null); Transform obj2 = ((Transform)val).Find("Weight"); RectTransform val3 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null); if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null) { PocketObliteratorPlugin.Log.LogWarning((object)"Inventory layout changed: armor/weight tiles not found, no Obliterator button."); return; } GameObject val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject, (Transform)(object)val); ((Object)val4).name = "PocketObliterator"; Transform obj3 = val4.transform.Find("armor_icon"); Image val5 = ((obj3 != null) ? ((Component)obj3).GetComponent<Image>() : null); Sprite val6 = Icon(); if ((Object)(object)val5 != (Object)null && (Object)(object)val6 != (Object)null) { val5.sprite = val6; } Transform obj4 = val4.transform.Find("ac_text"); TMP_Text val7 = ((obj4 != null) ? ((Component)obj4).GetComponent<TMP_Text>() : null); if ((Object)(object)val7 != (Object)null) { val7.text = Localization.instance.Localize("$piece_incinerator"); val7.enableAutoSizing = true; val7.fontSizeMax = val7.fontSize; val7.fontSizeMin = 8f; } GameObject val8 = new GameObject("Click", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); val8.transform.SetParent(val4.transform, false); RectTransform val9 = (RectTransform)val8.transform; val9.anchorMin = Vector2.zero; val9.anchorMax = Vector2.one; val9.offsetMin = Vector2.zero; val9.offsetMax = Vector2.zero; ((Graphic)val8.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0f); ButtonClickedEvent onClick = val8.GetComponent<Button>().onClick; object obj5 = <>O.<0>__Open; if (obj5 == null) { UnityAction val10 = Obliterator.Open; <>O.<0>__Open = val10; obj5 = (object)val10; } ((UnityEvent)onClick).AddListener((UnityAction)obj5); Transform transform = val4.transform; Place((RectTransform)(object)((transform is RectTransform) ? transform : null), val2, val3); } internal static void Reposition() { InventoryGui instance = InventoryGui.instance; if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.m_player == (Object)null)) { Transform obj = ((Transform)instance.m_player).Find("PocketObliterator"); RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null); Transform obj2 = ((Transform)instance.m_player).Find("Armor"); RectTransform val2 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null); Transform obj3 = ((Transform)instance.m_player).Find("Weight"); RectTransform val3 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null); if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null) { Place(val, val2, val3); } } } private static void Place(RectTransform tile, RectTransform armor, RectTransform weight) { //IL_0001: 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_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.Lerp(((Transform)armor).localPosition, ((Transform)weight).localPosition, 0.5f); ((Transform)tile).localPosition = val + new Vector3((float)Settings.ButtonOffsetX.Value, (float)Settings.ButtonOffsetY.Value, 0f); } private static Sprite Icon() { if ((Object)(object)icon != (Object)null) { return icon; } ZNetScene instance = ZNetScene.instance; if ((Object)(object)instance == (Object)null) { return null; } foreach (GameObject prefab in instance.m_prefabs) { if (!((Object)(object)prefab == (Object)null) && !((Object)(object)prefab.GetComponent<Incinerator>() == (Object)null)) { Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { icon = component.m_icon; break; } } } return icon; } } [HarmonyPatch(typeof(Container), "IsOwner")] internal static class ContainerIsOwnerPatch { private static bool Prefix(Container __instance, ref bool __result) { if (!Obliterator.IsOurs(__instance)) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(Container), "SetInUse")] internal static class ContainerSetInUsePatch { private static bool Prefix(Container __instance) { return !Obliterator.IsOurs(__instance); } } [HarmonyPatch(typeof(Container), "StackAll")] internal static class ContainerStackAllPatch { private static bool Prefix(Container __instance) { return !Obliterator.IsOurs(__instance); } } [HarmonyPatch(typeof(Container), "TakeAll")] internal static class ContainerTakeAllPatch { private static bool Prefix(Container __instance, ref bool __result) { if (!Obliterator.IsOurs(__instance)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(InventoryGui), "Hide")] internal static class HidePatch { private static void Prefix(InventoryGui __instance) { if (Obliterator.IsOurs(__instance.m_currentContainer)) { Obliterator.CloseAndObliterate(); } } private static void Postfix(InventoryGui __instance) { Obliterator.DiscardIfClosed(__instance); } } [HarmonyPatch(typeof(InventoryGui), "CloseContainer")] internal static class CloseContainerPatch { private static void Prefix(InventoryGui __instance) { if (Obliterator.IsOurs(__instance.m_currentContainer)) { Obliterator.CloseAndObliterate(); } } private static void Postfix(InventoryGui __instance) { Obliterator.DiscardIfClosed(__instance); } } [HarmonyPatch(typeof(InventoryGui), "Show", new Type[] { typeof(Container), typeof(int) })] internal static class ShowPatch { private static void Prefix(InventoryGui __instance, Container container) { if (Obliterator.IsOurs(__instance.m_currentContainer) && (Object)(object)container != (Object)(object)__instance.m_currentContainer) { Obliterator.CloseAndObliterate(); } } private static void Postfix(InventoryGui __instance) { Obliterator.DiscardIfClosed(__instance); ObliteratorButton.Ensure(__instance); } } [HarmonyPatch(typeof(Game), "Logout")] internal static class LogoutPatch { private static void Prefix() { if ((Object)(object)Obliterator.Current != (Object)null) { Obliterator.ReturnItems(Player.m_localPlayer); } } } [BepInPlugin("com.laoch.pocketobliterator", "PocketObliterator", "0.1.0")] public class PocketObliteratorPlugin : BaseUnityPlugin { public const string PluginGuid = "com.laoch.pocketobliterator"; public const string PluginName = "PocketObliterator"; public const string PluginVersion = "0.1.0"; internal static PocketObliteratorPlugin Instance { get; private set; } internal static ManualLogSource Log { get; private set; } private void Awake() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; Settings.Bind(((BaseUnityPlugin)this).Config); new Harmony("com.laoch.pocketobliterator").PatchAll(typeof(PocketObliteratorPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"PocketObliterator 0.1.0 loaded. Open your inventory and click the Obliterator."); } } internal static class Settings { internal static ConfigEntry<bool> Lightning { get; private set; } internal static ConfigEntry<bool> DamageEnabled { get; private set; } internal static ConfigEntry<float> DamageMultiplier { get; private set; } internal static ConfigEntry<bool> CanKill { get; private set; } internal static ConfigEntry<bool> ShockBystanders { get; private set; } internal static ConfigEntry<int> ButtonOffsetX { get; private set; } internal static ConfigEntry<int> ButtonOffsetY { get; private set; } internal static void Bind(ConfigFile config) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown Lightning = config.Bind<bool>("1 - Lightning", "Strike", true, "Lightning strikes you when the Obliterator closes and destroys what you put in it. Off = items just vanish."); DamageEnabled = config.Bind<bool>("1 - Lightning", "Damage", true, "The strike hurts you, like standing next to the real Obliterator. Off = the lightning is for show."); DamageMultiplier = config.Bind<float>("1 - Lightning", "Damage multiplier", 1f, new ConfigDescription("1 = the same damage as standing next to the real Obliterator. 0.5 = half, 0 = none.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); CanKill = config.Bind<bool>("1 - Lightning", "Can kill you", false, "Off (default): the strike can never take your last health. On: it can, same as the real Obliterator."); ShockBystanders = config.Bind<bool>("1 - Lightning", "Shock bystanders", false, "Other players standing right next to you also get zapped (never lethal, uses the damage settings above). For laughs."); ButtonOffsetX = config.Bind<int>("2 - Button", "Offset X", 0, new ConfigDescription("Moves the inventory button sideways. The default sits between the armor and weight tiles, where a trash can mod would be too.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-300, 300), Array.Empty<object>())); ButtonOffsetY = config.Bind<int>("2 - Button", "Offset Y", 0, new ConfigDescription("Moves the inventory button up (+) or down (-).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-300, 300), Array.Empty<object>())); ButtonOffsetX.SettingChanged += delegate { ObliteratorButton.Reposition(); }; ButtonOffsetY.SettingChanged += delegate { ObliteratorButton.Reposition(); }; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }