114 lines
2.9 KiB
C#
114 lines
2.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using HarmonyLib;
|
|
using NeoModLoader.api;
|
|
using NeoModLoader.services;
|
|
using UnityEngine;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
/// <summary>
|
|
/// Idle Spectator entry: I key AFK camera director over WorldLog events.
|
|
/// </summary>
|
|
public class ModClass : MonoBehaviour, IMod, IConfigurable, ILocalizable
|
|
{
|
|
private ModDeclare _declare;
|
|
private GameObject _gameObject;
|
|
private Harmony _harmony;
|
|
private ModConfig _config;
|
|
|
|
/// <summary>Absolute path to this mod's folder (parent of mod.json).</summary>
|
|
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);
|
|
EventCatalogConfig.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();
|
|
}
|
|
}
|