Guest User

Untitled

a guest
May 31st, 2025
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.77 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using BepInEx;
  6. using UnityEngine;
  7.  
  8. namespace Snaitf.Dinkum.HideAndSeek
  9. {
  10.     [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
  11.     public class Plugin : BaseUnityPlugin
  12.     {
  13.         int modID = 258;
  14.  
  15.         int numNPCs;
  16.         mapIcon[] icons;
  17.         bool setup = false;
  18.  
  19.         private void Awake()
  20.         {
  21.             Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
  22.  
  23.             Config.Bind<int>("!Developer", "NexusID", modID, "Nexus Mod ID. You can find it on the mod's page on Nexus.").Value = modID;
  24.             Config.Save();
  25.         }
  26.  
  27.         private void Setup()
  28.         {
  29.             numNPCs = NPCManager.manage.NPCDetails.Count();
  30.  
  31.             icons = new mapIcon[numNPCs];
  32.  
  33.             for (int id = 0; id < numNPCs; id++)
  34.             {
  35.                 icons[id] = Instantiate<mapIcon>(RenderMap.Instance.mapIconPrefab, RenderMap.Instance.mapParent).GetComponent<mapIcon>();
  36.                 icons[id].CurrentIconType = mapIcon.iconType.Special;
  37.  
  38.                 Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Snaitf.Dinkum.HideAndSeek.Resources." + id + ".png");
  39.                 if (stream == null)
  40.                     stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Snaitf.Dinkum.HideAndSeek.Resources.default.png");
  41.                 byte[] array = new BinaryReader(stream).ReadBytes((int)stream.Length);
  42.                 Texture2D texture2D = new(1, 2);
  43.                 ImageConversion.LoadImage(texture2D, array);
  44.  
  45.                 icons[id].Icon.sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), Vector2.zero);
  46.                 icons[id].IconName = NPCManager.manage.NPCDetails[id].NPCName;
  47.                 icons[id].container.SetActive(false);
  48.             }
  49.  
  50.             setup = true;
  51.         }
  52.  
  53.         private void Update()
  54.         {
  55.             if (!NetworkMapSharer.Instance.localChar)
  56.             {
  57.                 setup = false;
  58.                 return;
  59.             }
  60.  
  61.             if (!setup)
  62.                 Setup();
  63.  
  64.             List<int> onMap = new();
  65.             foreach (NPCMapAgent agent in NPCManager.manage.npcsOnMap)
  66.             {
  67.                 if (!icons[agent.npcId].container.activeSelf)
  68.                     icons[agent.npcId].container.SetActive(true);
  69.  
  70.                 icons[agent.npcId].SetPosition((int)agent.currentPosition.x / 2, (int)agent.currentPosition.z / 2);
  71.                 if (icons[agent.npcId].ping.activeSelf)
  72.                     if (!NetworkMapSharer.Instance.mapPoints.Contains(icons[agent.npcId].MyMapPoint))
  73.                         NetworkMapSharer.Instance.mapPoints.Add(icons[agent.npcId].MyMapPoint);
  74.  
  75.                 if (agent.npcId == 11)
  76.                     foreach (Vehicle vehicle in SaveLoad.saveOrLoad.vehiclesToSave)
  77.                         if (vehicle.saveId == 10)
  78.                             icons[agent.npcId].SetPosition((int)vehicle.currentPosition.x / 2, (int)vehicle.currentPosition.z / 2);
  79.  
  80.                 if (!RenderMap.Instance.mapIcons.Contains(icons[agent.npcId]))
  81.                     RenderMap.Instance.mapIcons.Add(icons[agent.npcId]);
  82.                
  83.                 if (!onMap.Contains(agent.npcId))
  84.                     onMap.Add(agent.npcId);
  85.             }
  86.  
  87.             for (int id = 0; id < numNPCs; id++)
  88.             {
  89.                 if (!onMap.Contains(id) || RealWorldTimeLight.time.CurrentWorldArea != WorldArea.MAIN_ISLAND)
  90.                 {
  91.                     RenderMap.Instance.mapIcons.Remove(icons[id]);
  92.                     icons[id].container.SetActive(false);
  93.                 }
  94.             }
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment