Advertisement
spacechase0

Harmony patch for Portia minimap icons

Jan 3rd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using Harmony;
  2. using Pathea.ActorNs;
  3. using Pathea.MapNs;
  4. using Pathea.ModuleNs;
  5. using Pathea.UISystemNs;
  6. using System.Reflection;
  7. using UnityEngine;
  8.  
  9. namespace AlwaysMinimapPortraits
  10. {
  11.     [HarmonyPatch(typeof(Actor_IMap))]
  12.     [HarmonyPatch("GetIconInfo")]
  13.     public static class GetIconInfoPatch
  14.     {
  15.         private static FieldInfo overrideSpriteField = null;
  16.        
  17.         public static void Postfix(Actor_IMap __instance, ref PresetIcon __iconInfo, ref Actor __mActor)
  18.         {
  19.             if ( overrideSpriteField == null )
  20.             {
  21.                 overrideSpriteField = typeof(PresetIcon).GetField("overrideSprite", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  22.             }
  23.  
  24.             var sprite = overrideSpriteField.GetValue(__iconInfo);
  25.  
  26.             if ( __instance.GetIcon() == MapIcon.NPC )
  27.             {
  28.                 ActorInfo actorInfo = Module<ActorMgr>.Self.GetActorInfo(__mActor.TmpltId);
  29.                 if (!string.IsNullOrEmpty(actorInfo.miniHeadIcon))
  30.                 {
  31.                     __iconInfo.SetOverrideSprite(UIUtils.GetSpriteByPath(actorInfo.miniHeadIcon), false, Vector2.zero);
  32.                 }
  33.                 else
  34.                 {
  35.                     __iconInfo.SetOverrideSprite(UIUtils.GetSpriteByPath(actorInfo.icon), true, new Vector2(30f, 31.5f));
  36.                 }
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement