using System; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: AssemblyTitle("Valheim")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Valheim")] [assembly: AssemblyCopyright("Copyright 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("1.0.9704.36035")] namespace ValheimMod; [BepInPlugin("Banderi.MinimapMod", "Rotating Minimap", "1.0.0")] [BepInProcess("valheim.exe")] public class ValheimMod_RotatingMinimap : BaseUnityPlugin { [HarmonyPatch(typeof(Minimap), "ForceRegen")] private class PinsUpdate3 { private static bool Prefix() { logger.LogWarning((object)"Forcing regen!"); return true; } } [HarmonyPatch(typeof(Minimap), "ClearPins")] private class MinimapClearPins { private static void Prefix(ref GameObject ___m_mapSmall) { logger.LogWarning((object)"Clearing pins!"); } } [HarmonyPatch(typeof(Minimap), "RemovePin")] [HarmonyPatch(new Type[] { typeof(PinData) })] private class MinimapRemovePin { private static void Prefix(ref GameObject ___m_mapSmall, PinData pin) { //IL_000b: 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) logger.LogWarning((object)$"Removing pin: {pin.m_pos} {pin.m_name} {pin.m_type}"); } } [HarmonyPatch(typeof(Minimap), "AddPin")] private class MinimapAddPin { private static void Postfix(ref GameObject ___m_mapSmall, Vector3 pos, PinType type, string name) { //IL_000a: 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) logger.LogWarning((object)$"Adding pin: {pos} {name} {type}"); init(___m_mapSmall); reparentPins(___m_mapSmall, newPinsParent); } } [HarmonyPatch(typeof(Minimap), "Update")] private class MinimapRotation { private static void Postfix(ref GameObject ___m_mapSmall, ref GameObject ___m_mapLarge, ref RectTransform ___m_smallMarker, ref RectTransform ___m_smallShipMarker, ref RectTransform ___m_windMarker) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) ___m_mapSmall.transform.rotation = Quaternion.Euler(0f, 0f, ((Quaternion)(ref lastPlayerRot)).eulerAngles.y); ((Component)___m_smallMarker).transform.rotation = Quaternion.Euler(0f, 0f, 0f); Quaternion rotation = ((Transform)___m_smallShipMarker).rotation; ((Transform)___m_smallShipMarker).rotation = Quaternion.Euler(0f, 0f, ((Quaternion)(ref lastPlayerRot)).eulerAngles.y) * rotation; Quaternion rotation2 = ((Transform)___m_windMarker).rotation; ((Transform)___m_windMarker).rotation = Quaternion.Euler(0f, 0f, ((Quaternion)(ref lastPlayerRot)).eulerAngles.y) * rotation2; } } [HarmonyPatch(typeof(Minimap), "WorldToMapPoint")] private class MinimapCenterPos { private static void Postfix(Vector3 p, float mx, float my) { //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_0013: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Vector3 position = ((Component)localPlayer).transform.position; if (p == position) { playerMinimapPinPos.x = mx; playerMinimapPinPos.y = my; } } } [HarmonyPatch(typeof(Minimap), "UpdatePlayerMarker")] private class MinimapCenterRot { private static void Postfix(Quaternion playerRot, ref RectTransform ___m_smallMarker, ref RectTransform ___m_smallShipMarker) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) lastPlayerRot = playerRot; } } [HarmonyPatch(typeof(Minimap), "MapPointToLocalGuiPos")] [HarmonyPatch(new Type[] { typeof(float), typeof(float), typeof(Rect), typeof(Rect) })] private class MinimapIcons { private static void Prefix(MapMode ___m_mode, ref float mx, ref float my) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_001d: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) if ((int)___m_mode != 2) { Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(mx, my); Vector2 val2 = val - playerMinimapPinPos; Vector2 val3 = Vector2.op_Implicit(Quaternion.Euler(0f, 0f, ((Quaternion)(ref lastPlayerRot)).eulerAngles.y) * Vector2.op_Implicit(val2)); Vector2 val4 = playerMinimapPinPos + val3; mx = val4.x; my = val4.y; } } } public static ManualLogSource logger; private readonly Harmony harmony = new Harmony("Banderi.MinimapMod"); private static GameObject newPinsParent; private static Quaternion lastPlayerRot; private static Vector2 origin; private static Vector2 playerMinimapPinPos; private void Awake() { logger = ((BaseUnityPlugin)this).Logger; logger.LogWarning((object)"MOD: Awaking..."); harmony.PatchAll(); } private static void reparentPins(GameObject A, GameObject B) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown if ((Object)(object)A == (Object)null) { logger.LogError((object)"Can not reparent: A is NULL"); return; } if ((Object)(object)B == (Object)null) { logger.LogError((object)"Can not reparent: B is NULL"); return; } foreach (Transform item in A.transform) { Transform val = item; ((Component)val).gameObject.transform.SetParent(B.transform); } } private static void init(GameObject map) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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_003e: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)newPinsParent != (Object)null)) { logger.LogWarning((object)"MOD: Initializing..."); origin = new Vector2(0f, 0f); newPinsParent = new GameObject(); newPinsParent.transform.position = map.transform.position; newPinsParent.transform.SetParent(map.transform.parent); logger.LogWarning((object)"MOD: ...Done!"); } } }