using System; using System.IO; using HarmonyLib; using NeoModLoader.api; using NeoModLoader.services; using UnityEngine; namespace IdleSpectator; /// /// Idle Spectator entry: I key AFK camera director over WorldLog events. /// public class ModClass : MonoBehaviour, IMod, IConfigurable, ILocalizable { private ModDeclare _declare; private GameObject _gameObject; private Harmony _harmony; private ModConfig _config; /// Absolute path to this mod's folder (parent of mod.json). public static string ModFolder { get; private set; } public static ModClass Instance { get; private set; } public ModDeclare GetDeclaration() { return _declare; } public GameObject GetGameObject() { return _gameObject; } public string GetUrl() { return ""; } public ModConfig GetConfig() { return _config; } public string GetLocaleFilesDirectory(ModDeclare pModDeclare) { return Path.Combine(pModDeclare.FolderPath, "Locales"); } public void OnLoad(ModDeclare pModDecl, GameObject pGameObject) { Instance = this; _declare = pModDecl; _gameObject = pGameObject; ModFolder = pModDecl.FolderPath; _config = ModSettings.Load(pModDecl); InterestScoringConfig.LoadFromModFolder(ModFolder); _harmony = new Harmony(pModDecl.UID); ApplyHarmonyPatches(pModDecl.Name); LogService.LogInfo($"[{pModDecl.Name}]: Harmony patches applied"); LogService.LogInfo($"[{pModDecl.Name}]: Press I for Idle Spectator, L for Lore"); Chronicle.EnsureWindow(); } private void ApplyHarmonyPatches(string modName) { Exception firstFailure = null; foreach (Type type in typeof(ModClass).Assembly.GetTypes()) { try { new PatchClassProcessor(_harmony, type).Patch(); } catch (Exception ex) { LogService.LogError($"[{modName}]: Harmony failed on {type.FullName}: {ex}"); if (ex.InnerException != null) { LogService.LogError($"[{modName}]: Inner: {ex.InnerException}"); } if (firstFailure == null) { firstFailure = ex; } } } if (firstFailure != null) { throw firstFailure; } } private void Update() { AgentHarness.Update(); SpectatorMode.PollInput(); Chronicle.PollInput(); InterestDirector.Update(); if (!AgentHarness.FreezeDirector) { SpeciesDiscovery.Update(); } WatchCaption.Update(); Chronicle.Update(); FocusRelationshipArrows.PinFocusActor(); StateProbe.Update(); AutoTest.Update(); } }