using System.Reflection;
using HarmonyLib;
using UnityEngine;
namespace NecromancerTome
{
///
/// Mod entry point. The game finds this by scanning every assembly dropped in a
/// Mods/<ModFolder>/ directory for a type implementing IModApi.
///
public class ModEntry : IModApi
{
/// The mod's own folder, kept from InitMod so patches can find files we ship
/// (currently Resources/necroatlas for the custom block paint). Nothing else knows where
/// the mod lives - the game hands it over exactly once, right here.
public static Mod Instance;
public void InitMod(Mod _modInstance)
{
Instance = _modInstance;
var harmony = new Harmony("necromancertome.harmony");
harmony.PatchAll(Assembly.GetExecutingAssembly());
PetFollowPatch.Init();
// PyramidWardPatch.cs's TEFeaturePyramidWard needs no Init() call - it's discovered
// automatically by the engine's own TileEntityCompositeData reflection scan (see that
// file's class doc comment), not registered here like PetFollowPatch's UnityUpdate hook.
// Diagnostic-only, added 2026-08-28 while chasing "VictimPatch never logs anything at
// all for dropItemOnDeath, even though decompiling EntityAlive.OnEntityDeath()
// confirms it's called unconditionally right after the 'killed by' line seen in the
// log". This checks, at load time, whether Harmony actually attached our Prefix to
// that method at all - rules "patch never applied" in or out without waiting on
// another in-game death.
VerifyPrefixAttached(typeof(EntityAlive), "dropItemOnDeath");
VerifyPrefixAttached(typeof(Entity), "DropBagServer");
}
public static void VerifyPrefixAttached(System.Type type, string methodName)
{
MethodBase method = AccessTools.Method(type, methodName);
if (method == null)
{
Debug.LogWarning("[NecromancerTome] ModEntry: could not resolve " + type.Name + "." + methodName + " via AccessTools - method not found");
return;
}
Patches info = Harmony.GetPatchInfo(method);
int prefixCount = info != null && info.Prefixes != null ? info.Prefixes.Count : 0;
Debug.Log("[NecromancerTome] ModEntry: " + type.Name + "." + methodName + " resolved, has " + prefixCount + " prefix patch(es) attached after PatchAll");
}
}
}