Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using BepInEx;
- using UnityEngine;
- namespace Snaitf.Dinkum.HideAndSeek
- {
- [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
- public class Plugin : BaseUnityPlugin
- {
- int modID = 258;
- int numNPCs;
- mapIcon[] icons;
- bool setup = false;
- private void Awake()
- {
- Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
- Config.Bind<int>("!Developer", "NexusID", modID, "Nexus Mod ID. You can find it on the mod's page on Nexus.").Value = modID;
- Config.Save();
- }
- private void Setup()
- {
- numNPCs = NPCManager.manage.NPCDetails.Count();
- icons = new mapIcon[numNPCs];
- for (int id = 0; id < numNPCs; id++)
- {
- icons[id] = Instantiate<mapIcon>(RenderMap.Instance.mapIconPrefab, RenderMap.Instance.mapParent).GetComponent<mapIcon>();
- icons[id].CurrentIconType = mapIcon.iconType.Special;
- Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Snaitf.Dinkum.HideAndSeek.Resources." + id + ".png");
- if (stream == null)
- stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Snaitf.Dinkum.HideAndSeek.Resources.default.png");
- byte[] array = new BinaryReader(stream).ReadBytes((int)stream.Length);
- Texture2D texture2D = new(1, 2);
- ImageConversion.LoadImage(texture2D, array);
- icons[id].Icon.sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), Vector2.zero);
- icons[id].IconName = NPCManager.manage.NPCDetails[id].NPCName;
- icons[id].container.SetActive(false);
- }
- setup = true;
- }
- private void Update()
- {
- if (!NetworkMapSharer.Instance.localChar)
- {
- setup = false;
- return;
- }
- if (!setup)
- Setup();
- List<int> onMap = new();
- foreach (NPCMapAgent agent in NPCManager.manage.npcsOnMap)
- {
- if (!icons[agent.npcId].container.activeSelf)
- icons[agent.npcId].container.SetActive(true);
- icons[agent.npcId].SetPosition((int)agent.currentPosition.x / 2, (int)agent.currentPosition.z / 2);
- if (icons[agent.npcId].ping.activeSelf)
- if (!NetworkMapSharer.Instance.mapPoints.Contains(icons[agent.npcId].MyMapPoint))
- NetworkMapSharer.Instance.mapPoints.Add(icons[agent.npcId].MyMapPoint);
- if (agent.npcId == 11)
- foreach (Vehicle vehicle in SaveLoad.saveOrLoad.vehiclesToSave)
- if (vehicle.saveId == 10)
- icons[agent.npcId].SetPosition((int)vehicle.currentPosition.x / 2, (int)vehicle.currentPosition.z / 2);
- if (!RenderMap.Instance.mapIcons.Contains(icons[agent.npcId]))
- RenderMap.Instance.mapIcons.Add(icons[agent.npcId]);
- if (!onMap.Contains(agent.npcId))
- onMap.Add(agent.npcId);
- }
- for (int id = 0; id < numNPCs; id++)
- {
- if (!onMap.Contains(id) || RealWorldTimeLight.time.CurrentWorldArea != WorldArea.MAIN_ISLAND)
- {
- RenderMap.Instance.mapIcons.Remove(icons[id]);
- icons[id].container.SetActive(false);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment