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 MotikofusUI v0.5.0
MotikofusUi.dll
Decompiled a week agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")] [assembly: AssemblyCompany("MotikofusUi")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("MotikofusUi")] [assembly: AssemblyTitle("MotikofusUi")] [assembly: AssemblyVersion("1.0.0.0")] [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 MotikofusUi { [BepInPlugin("com.motikofus.motikofusui", "MotikofusUi", "1.0.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource LogSource; internal static ConfigEntry<bool> ConfigEnableStatusEffects; internal static ConfigEntry<bool> ConfigEnableTrashCan; internal static ConfigEntry<bool> ConfigEnableArmorHud; internal static ConfigEntry<float> ConfigArmorHudOffsetX; internal static ConfigEntry<float> ConfigArmorHudOffsetY; private void Awake() { //IL_00f7: Unknown result type (might be due to invalid IL or missing references) LogSource = ((BaseUnityPlugin)this).Logger; ConfigEnableStatusEffects = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Status Effects", "EnableStatusEffectsMod", true, "Enables or disables the movement and visual modification of status effects."); ConfigEnableTrashCan = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Trash Can", "EnableTrashCan", true, "Enables or disables the inventory trash can slot."); ConfigEnableArmorHud = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Armor HUD", "EnableArmorHud", true, "Enables or disables the permanent armor durability HUD."); ConfigArmorHudOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("3. Armor HUD", "OffsetX", -180f, "Horizontal position offset.To place it above your power [-1875x, -875y]"); ConfigArmorHudOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("3. Armor HUD", "OffsetY", -60f, "Vertical position offset."); ConfigArmorHudOffsetX.SettingChanged += UpdateArmorHudPosition; ConfigArmorHudOffsetY.SettingChanged += UpdateArmorHudPosition; LogSource.LogInfo((object)"MotikofusUi loaded successfully."); new Harmony("com.motikofus.motikofusui").PatchAll(); } private void UpdateArmorHudPosition(object sender, EventArgs e) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.Find("Hud/MotikofusArmorHud"); if ((Object)(object)val != (Object)null) { RectTransform component = val.GetComponent<RectTransform>(); if ((Object)(object)component != (Object)null) { component.anchoredPosition = new Vector2(ConfigArmorHudOffsetX.Value, ConfigArmorHudOffsetY.Value); } } } public static Sprite LoadSpriteFromResource(string resourceName) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) Assembly executingAssembly = Assembly.GetExecutingAssembly(); using Stream stream = executingAssembly.GetManifestResourceStream(resourceName); if (stream == null) { LogSource.LogError((object)("Ressource introuvable : " + resourceName)); return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); Type type = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { Type type2 = assembly.GetType("UnityEngine.ImageConversion"); if (type2 != null) { type = type2; break; } } if (type != null) { type.GetMethod("LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) })?.Invoke(null, new object[2] { val, array }); } else { LogSource.LogError((object)"Impossible de trouver UnityEngine.ImageConversion."); } return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } } public static class UnityExtensions { public static T GetOrAddComponent<T>(this GameObject gameObject) where T : Component { T val = gameObject.GetComponent<T>(); if ((Object)(object)val == (Object)null) { val = gameObject.AddComponent<T>(); } return val; } } public class TrashCanDropHandler : MonoBehaviour, IDropHandler, IEventSystemHandler { public void OnDrop(PointerEventData eventData) { DeleteDraggedItem(); } public static void DeleteDraggedItem() { InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance == (Object)null) { return; } object? obj = typeof(InventoryGui).GetField("m_dragItem", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(instance); ItemData val = (ItemData)((obj is ItemData) ? obj : null); if (val == null) { return; } Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { object? obj2 = typeof(InventoryGui).GetField("m_dragInventory", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(instance); Inventory val2 = (Inventory)(((obj2 is Inventory) ? obj2 : null) ?? ((Humanoid)localPlayer).GetInventory()); if (val2 != null && val2.ContainsItem(val)) { int stack = val.m_stack; string name = val.m_shared.m_name; string playerName = localPlayer.GetPlayerName(); val2.RemoveItem(val); Plugin.LogSource.LogInfo((object)$"{playerName} delete {stack} x {name} (from inventory/chest)"); typeof(InventoryGui).GetMethod("SetupDragItem", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(instance, new object[3] { null, null, 0 }); } } } } [HarmonyPatch(typeof(Player), "Awake")] public class PlayerPatch { [HarmonyPostfix] private static void Postfix(Player __instance) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Expected O, but got Unknown //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || !((Character)__instance).IsPlayer() || !Plugin.ConfigEnableStatusEffects.Value) { return; } GameObject val = GameObject.Find("StatusEffects"); if ((Object)(object)val == (Object)null) { return; } val.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); HorizontalLayoutGroup val2 = default(HorizontalLayoutGroup); if (val.TryGetComponent<HorizontalLayoutGroup>(ref val2)) { Object.Destroy((Object)(object)val2); } VerticalLayoutGroup orAddComponent = val.GetOrAddComponent<VerticalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)orAddComponent).spacing = 15f; ((HorizontalOrVerticalLayoutGroup)orAddComponent).childControlWidth = false; ((HorizontalOrVerticalLayoutGroup)orAddComponent).childControlHeight = false; ((HorizontalOrVerticalLayoutGroup)orAddComponent).childForceExpandWidth = false; ((HorizontalOrVerticalLayoutGroup)orAddComponent).childForceExpandHeight = false; RectTransform val3 = default(RectTransform); if (val.TryGetComponent<RectTransform>(ref val3)) { val3.anchorMin = new Vector2(1f, 1f); val3.anchorMax = new Vector2(1f, 1f); val3.pivot = new Vector2(1f, 1f); val3.anchoredPosition = new Vector2(120f, -250f); } HorizontalLayoutGroup val5 = default(HorizontalLayoutGroup); RectTransform val7 = default(RectTransform); Text val8 = default(Text); foreach (Transform item in val.transform) { Transform val4 = item; if (((Component)val4).TryGetComponent<HorizontalLayoutGroup>(ref val5)) { Object.Destroy((Object)(object)val5); } foreach (Transform item2 in val4) { Transform val6 = item2; string text = ((Object)val6).name.ToLower(); if (!((Component)val6).TryGetComponent<RectTransform>(ref val7)) { continue; } bool flag = text.Contains("timer") || text.Contains("time"); bool flag2 = ((Component)val6).TryGetComponent<Text>(ref val8) || text.Contains("text") || text.Contains("name"); if (flag) { val7.anchoredPosition = new Vector2(165f, -38f); } else if (flag2 && ((Object)(object)((Component)val6).GetComponent<Image>() == (Object)null || (Object)(object)val8 != (Object)null)) { val7.anchoredPosition = new Vector2(70f, -38f); } if ((Object)(object)val8 != (Object)null) { if ((Object)(object)((Component)val8).GetComponent<Shadow>() == (Object)null) { Shadow val9 = ((Component)val8).gameObject.AddComponent<Shadow>(); val9.effectColor = new Color(0f, 0f, 0f, 0.9f); val9.effectDistance = new Vector2(1f, -1f); } if ((Object)(object)((Component)val8).GetComponent<Outline>() == (Object)null) { Outline val10 = ((Component)val8).gameObject.AddComponent<Outline>(); ((Shadow)val10).effectColor = new Color(0f, 0f, 0f, 0.8f); ((Shadow)val10).effectDistance = new Vector2(1f, 1f); } } } } } } [HarmonyPatch(typeof(InventoryGui), "Show")] public class InventoryGuiShowPatch { [HarmonyPostfix] private static void Postfix(InventoryGui __instance) { //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Expected O, but got Unknown //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Expected O, but got Unknown //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || !Plugin.ConfigEnableTrashCan.Value) { return; } Transform val = ((Component)__instance).transform.Find("root/Player"); if ((Object)(object)val == (Object)null || (Object)(object)val.Find("MotikofusCustomSlot") != (Object)null) { return; } Transform val2 = val.Find("Armor"); Transform val3 = val.Find("Weight"); if (!((Object)(object)val2 != (Object)null) || !((Object)(object)val3 != (Object)null)) { return; } GameObject val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject, val); ((Object)val4).name = "MotikofusCustomSlot"; val4.transform.SetAsFirstSibling(); RectTransform component = val4.GetComponent<RectTransform>(); RectTransform component2 = ((Component)val2).GetComponent<RectTransform>(); RectTransform component3 = ((Component)val3).GetComponent<RectTransform>(); if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null && (Object)(object)component3 != (Object)null) { float num = (component2.anchoredPosition.y + component3.anchoredPosition.y) / 2f - 70f; component.anchoredPosition = new Vector2(component2.anchoredPosition.x, num); } Sprite val5 = Plugin.LoadSpriteFromResource("MotikofusUI.trashcan.png"); if ((Object)(object)val5 != (Object)null) { foreach (Transform item in val4.transform) { Transform val6 = item; if (((Object)val6).name != "bkg") { Object.Destroy((Object)(object)((Component)val6).gameObject); } } GameObject val7 = new GameObject("TrashIcon", new Type[2] { typeof(RectTransform), typeof(Image) }); val7.transform.SetParent(val4.transform, false); RectTransform component4 = val7.GetComponent<RectTransform>(); Vector2 val8 = default(Vector2); ((Vector2)(ref val8))..ctor(0.5f, 0.5f); component4.anchorMax = val8; component4.anchorMin = val8; component4.sizeDelta = new Vector2(60f, 60f); component4.anchoredPosition = Vector2.zero; Image component5 = val7.GetComponent<Image>(); component5.sprite = val5; ((Graphic)component5).color = Color.white; } val4.AddComponent<TrashCanDropHandler>(); } } [HarmonyPatch(typeof(Hud), "Awake")] public class ArmorHudPatch { [HarmonyPostfix] private static void Postfix(Hud __instance) { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance == (Object)null) && Plugin.ConfigEnableArmorHud.Value) { Transform transform = ((Component)__instance).transform; if (!((Object)(object)transform.Find("MotikofusArmorHud") != (Object)null)) { GameObject val = new GameObject("MotikofusArmorHud", new Type[2] { typeof(RectTransform), typeof(VerticalLayoutGroup) }); val.transform.SetParent(transform, false); RectTransform component = val.GetComponent<RectTransform>(); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(1f, 1f); component.pivot = val2; Vector2 anchorMin = (component.anchorMax = val2); component.anchorMin = anchorMin; component.anchoredPosition = new Vector2(Plugin.ConfigArmorHudOffsetX.Value, Plugin.ConfigArmorHudOffsetY.Value); VerticalLayoutGroup component2 = val.GetComponent<VerticalLayoutGroup>(); ((HorizontalOrVerticalLayoutGroup)component2).spacing = 6f; bool flag = (((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = false); bool flag3 = (((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = flag); bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = flag3); ((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = childControlWidth; val.AddComponent<ArmorHudController>(); } } } } public class ArmorHudController : MonoBehaviour { private readonly List<ArmorSlotUI> slots = new List<ArmorSlotUI>(); private void Start() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0118: 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_012c: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Expected O, but got Unknown //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[4] { "Helmet", "Chest", "Legs", "Cape" }; string[] array2 = array; foreach (string text in array2) { GameObject val = new GameObject("Slot_" + text, new Type[2] { typeof(RectTransform), typeof(Image) }); val.transform.SetParent(((Component)this).transform, false); val.GetComponent<RectTransform>().sizeDelta = new Vector2(36f, 36f); ((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.6f); GameObject val2 = new GameObject("Icon", new Type[2] { typeof(RectTransform), typeof(Image) }); val2.transform.SetParent(val.transform, false); RectTransform component = val2.GetComponent<RectTransform>(); component.anchorMin = Vector2.zero; component.anchorMax = Vector2.one; Vector2 sizeDelta = (component.anchoredPosition = Vector2.zero); component.sizeDelta = sizeDelta; ((Behaviour)val2.GetComponent<Image>()).enabled = false; GameObject val3 = new GameObject("DurabilityBar", new Type[2] { typeof(RectTransform), typeof(Image) }); val3.transform.SetParent(val.transform, false); RectTransform component2 = val3.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(0f, 0f); component2.anchorMax = new Vector2(1f, 0f); component2.sizeDelta = new Vector2(0f, 4f); component2.anchoredPosition = new Vector2(0f, 2f); ((Graphic)val3.GetComponent<Image>()).color = Color.green; slots.Add(new ArmorSlotUI { slotObject = val, iconImage = val2.GetComponent<Image>(), durabilityBar = val3.GetComponent<Image>() }); } } private void Update() { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Invalid comparison between Unknown and I4 //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Invalid comparison between Unknown and I4 //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Invalid comparison between Unknown and I4 //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Invalid comparison between Unknown and I4 //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Inventory val = ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null); if (val == null) { return; } ItemData val2 = null; ItemData val3 = null; ItemData val4 = null; ItemData val5 = null; foreach (ItemData equippedItem in val.GetEquippedItems()) { if (equippedItem?.m_shared != null) { if ((int)equippedItem.m_shared.m_itemType == 6) { val2 = equippedItem; } else if ((int)equippedItem.m_shared.m_itemType == 7) { val3 = equippedItem; } else if ((int)equippedItem.m_shared.m_itemType == 11) { val4 = equippedItem; } else if ((int)equippedItem.m_shared.m_itemType == 17) { val5 = equippedItem; } } } ItemData[] array = (ItemData[])(object)new ItemData[4] { val2, val3, val4, val5 }; for (int i = 0; i < slots.Count; i++) { ItemData val6 = array[i]; ArmorSlotUI armorSlotUI = slots[i]; if (val6 != null) { armorSlotUI.iconImage.sprite = val6.GetIcon(); ((Behaviour)armorSlotUI.iconImage).enabled = true; if (val6.m_shared.m_useDurability) { float num = Mathf.Clamp01(val6.m_durability / val6.GetMaxDurability()); ((Component)armorSlotUI.durabilityBar).gameObject.SetActive(true); ((Transform)((Graphic)armorSlotUI.durabilityBar).rectTransform).localScale = new Vector3(num, 1f, 1f); ((Graphic)armorSlotUI.durabilityBar).color = (Color)((num > 0.5f) ? Color.green : ((num > 0.2f) ? new Color(1f, 0.64f, 0f) : Color.red)); } else { ((Component)armorSlotUI.durabilityBar).gameObject.SetActive(false); } } else { ((Behaviour)armorSlotUI.iconImage).enabled = false; ((Component)armorSlotUI.durabilityBar).gameObject.SetActive(false); } } } } public class ArmorSlotUI { public GameObject slotObject; public Image iconImage; public Image durabilityBar; } }