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 TrueNorthCompass v1.0.0
TrueNorthCompass/TrueNorthCompass.dll
Decompiled 4 hours agousing System; using System.Collections; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("JotunnModStub")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("JotunnModStub")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.0.0")] namespace NorthCompassMod; [HarmonyPatch(typeof(ItemStand), "CanAttach")] public static class ItemStand_CanAttach_CompassPatch { [HarmonyPostfix] private static void Postfix(ItemData item, ref bool __result) { if (item?.m_shared != null && item.m_shared.m_name == "$item_northcompass") { __result = true; } } } [HarmonyPatch(typeof(Humanoid), "UseItem")] public static class Humanoid_UseItem_CompassPatch { [HarmonyPrefix] private static bool Prefix(Humanoid __instance, Inventory inventory, ItemData item, bool fromInventoryGui) { if (item?.m_shared == null) { return true; } if (item.m_shared.m_name != "$item_northcompass") { return true; } bool flag = false; Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val != null) { GameObject hovering = val.m_hovering; flag = (Object)(object)hovering != (Object)null && (Object)(object)hovering.GetComponentInParent<ItemStand>() != (Object)null; } if (flag) { return true; } Player val2 = (Player)(object)((__instance is Player) ? __instance : null); if (val2 != null) { ((MonoBehaviour)val2).StartCoroutine(PanLookToNorth(val2)); } return false; } private static IEnumerator PanLookToNorth(Player player) { Vector3 startFlatDir = ((Character)player).GetLookDir(); startFlatDir.y = 0f; ((Vector3)(ref startFlatDir)).Normalize(); Quaternion startYaw = Quaternion.LookRotation(startFlatDir); Quaternion targetYaw = Quaternion.LookRotation(Vector3.forward); float t = 0f; while (t < 1.8f) { if (t > 0.2f) { Vector2 mouseDelta = ZInput.GetMouseDelta(); float gamepadX = ZInput.GetJoyRightStickX(); float gamepadY = ZInput.GetJoyRightStickY(); if (((Vector2)(ref mouseDelta)).magnitude > 0.1f || Mathf.Abs(gamepadX) > 0.1f || Mathf.Abs(gamepadY) > 0.1f) { yield break; } } t += Time.deltaTime; float eased = 1f - Mathf.Pow(1f - Mathf.Clamp01(t / 1.8f), 2f); Quaternion current = Quaternion.Slerp(startYaw, targetYaw, eased); ((Character)player).SetLookDir(current * Vector3.forward, 0f); yield return null; } ((Character)player).SetLookDir(targetYaw * Vector3.forward, 0f); ((Character)player).Message((MessageType)2, "You're now facing north.", 0, (Sprite)null, false); } } [BepInPlugin("com.mods.truenorthcompass", "True North Compass", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class NorthCompassPlugin : BaseUnityPlugin { public const string PluginGUID = "com.mods.truenorthcompass"; public const string PluginName = "True North Compass"; public const string PluginVersion = "0.1.0"; public const string CompassNameToken = "$item_northcompass"; private readonly Harmony _harmony = new Harmony("com.mods.truenorthcompass"); private void Awake() { PrefabManager.OnVanillaPrefabsAvailable += AddCompassItem; _harmony.PatchAll(); Logger.LogInfo((object)"True North Compass 0.1.0 loaded"); } private void AddCompassItem() { //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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) ItemConfig val = new ItemConfig { Name = "$item_northcompass", Description = "$item_northcompass_desc", Amount = 1, CraftingStation = CraftingStations.Forge.ToString() }; val.AddRequirement("Bronze", 5, 0); val.AddRequirement("Iron", 1, 0); CustomItem val2 = new CustomItem("NorthCompassMod_Compass", "ShieldBronzeBuckler", val); SharedData shared = val2.ItemDrop.m_itemData.m_shared; shared.m_name = "$item_northcompass"; shared.m_description = "$item_northcompass_desc"; shared.m_maxStackSize = 1; shared.m_weight = 1f; shared.m_useDurability = false; shared.m_equipStatusEffect = null; shared.m_blockPower = 0f; shared.m_deflectionForce = 0f; shared.m_timedBlockBonus = 1f; shared.m_movementModifier = 0f; shared.m_skillType = (SkillType)0; Texture2D val3 = LoadRawTexture("compass_icon.rgba"); if ((Object)(object)val3 != (Object)null) { Sprite val4 = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0.5f)); shared.m_icons = (Sprite[])(object)new Sprite[1] { val4 }; } LoadRealCompassModel(((Component)val2.ItemDrop).gameObject); ItemManager.Instance.AddItem(val2); PrefabManager.OnVanillaPrefabsAvailable -= AddCompassItem; } private void LoadRealCompassModel(GameObject itemPrefab) { //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: 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_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) MeshRenderer[] componentsInChildren = itemPrefab.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val in componentsInChildren) { ((Renderer)val).enabled = false; } SkinnedMeshRenderer[] componentsInChildren2 = itemPrefab.GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer val2 in componentsInChildren2) { ((Renderer)val2).enabled = false; } ParticleSystem[] componentsInChildren3 = itemPrefab.GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem val3 in componentsInChildren3) { val3.Stop(true, (ParticleSystemStopBehavior)0); } string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName ?? "", "truenorthcompass"); if (!File.Exists(text)) { Logger.LogWarning((object)("truenorthcompass AssetBundle not found at " + text + " - the item will have no visible mesh.")); return; } AssetBundle val4 = AssetBundle.LoadFromFile(text); if ((Object)(object)val4 == (Object)null) { Logger.LogWarning((object)"Failed to load the truenorthcompass AssetBundle (file may be corrupt)."); return; } GameObject val5 = val4.LoadAsset<GameObject>("CompassModel"); if ((Object)(object)val5 == (Object)null) { Logger.LogWarning((object)"'CompassModel' not found inside the truenorthcompass AssetBundle - check the Prefab's exact name in Unity."); val4.Unload(false); return; } Transform val6 = null; Transform[] componentsInChildren4 = itemPrefab.GetComponentsInChildren<Transform>(true); foreach (Transform val7 in componentsInChildren4) { if (((Object)val7).name == "attach") { val6 = val7; break; } } Transform val8 = (((Object)(object)val6 != (Object)null) ? val6 : itemPrefab.transform); if ((Object)(object)val6 == (Object)null) { Logger.LogWarning((object)"No 'attach' child found on the base item - Item Stand display may not show the model."); } GameObject val9 = Object.Instantiate<GameObject>(val5, val8, false); ((Object)val9).name = "CompassMesh_Real"; val9.transform.localScale = Vector3.one * 0.19f; Transform transform = val9.transform; transform.localPosition += Vector3.up * -0.05f; if ((Object)(object)val6 != (Object)null) { val9.transform.localRotation = Quaternion.Inverse(val6.localRotation) * Quaternion.Euler(0f, 180f, 0f); } val4.Unload(false); } private Texture2D LoadRawTexture(string fileName) { //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Expected O, but got Unknown string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName ?? "", fileName); if (!File.Exists(text)) { Logger.LogWarning((object)(fileName + " not found at " + text + ".")); return null; } byte[] array = File.ReadAllBytes(text); if (array.Length < 8) { Logger.LogWarning((object)(fileName + " is too small to be valid.")); return null; } int num = BitConverter.ToInt32(array, 0); int num2 = BitConverter.ToInt32(array, 4); int num3 = num * num2 * 4; if (num <= 0 || num2 <= 0 || array.Length < 8 + num3) { Logger.LogWarning((object)(fileName + " appears corrupt.")); return null; } byte[] array2 = new byte[num3]; Array.Copy(array, 8, array2, 0, num3); Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false); val.LoadRawTextureData(array2); val.Apply(); return val; } }