using System.Reflection; using MegaCrit.Sts2.Core.Logging; using MegaCrit.Sts2.Core.Modding; using MegaCrit.Sts2.Core.Nodes.Combat; using STS2RitsuLib; using STS2RitsuLib.Interop; using STS2RitsuLib.Scaffolding.Godot.NodeAttachments; using STS2RitsuLib.Patching.Core; namespace VulnerabilityIndicator.Scripts; /// /// Mod entry point. Initializes RitsuLib, registers patches, lifecycle observers, /// and sets up node attachments for the vulnerability indicator. /// [ModInitializer(nameof(Init))] public class Entry { public const string ModId = "VulnerabilityIndicator"; public static readonly Logger Logger = RitsuLibFramework.CreateLogger(ModId); public static void Init() { var assembly = Assembly.GetExecutingAssembly(); RitsuLibFramework.EnsureGodotScriptsRegistered(assembly, Logger); ModTypeDiscoveryHub.RegisterModAssembly(ModId, assembly); // Subscribe to lifecycle events (card drawn, discarded, played, turns, etc.) // to keep vulnerability indicators up to date. RitsuLibFramework.SubscribeLifecycle(new VulnerabilityLifecycleObserver()); // Register the node attachment that places vulnerability indicators // on the combat UI. The indicator creates per-side icons. ModNodeAttachmentRegistry.For(ModId) .RegisterReadyChild( "vuln_indicator", static _ => new UI.VulnerabilityPlayerIndicator(), static (parent, node) => node.Bind(parent), new NodeAttachmentOptions { Name = "VulnerabilityPlayerIndicator", Order = 100, DuplicatePolicy = NodeAttachmentDuplicatePolicy.ReuseExistingByName, SetupTiming = NodeAttachmentSetupTiming.AfterAdd, IncludeDerivedParentTypes = true, }); // Register Harmony patches via RitsuLib patcher. var patcher = RitsuLibFramework.CreatePatcher(ModId, "indicator-patches"); patcher.RegisterPatch(); if (!patcher.PatchAll()) { Logger.Warn("Some patches failed to apply."); } Logger.Info("Vulnerability Indicator mod initialized!"); } }