namespace Aeshnidae.Codex; [HarmonyPatch] public static class Patches { /// Everyone gets a Codex as they enter the world, if they have none. [HarmonyPostfix] [HarmonyPatch(typeof(Player), nameof(Player.PlayerEnterWorld))] public static void PostPlayerEnterWorld(Player __instance) { try { if (Mod.Settings.GrantOnLogin) Codex.Ensure(__instance, announce: Codex.Find(__instance) is null); } catch (Exception ex) { ModManager.Log($"[{Mod.Name}] login grant failed: {ex.Message}", ModManager.LogLevel.Warn); } } /// /// Opening the book from the pack: rebuild the pages first, then let ACE send /// them exactly as it sends any book. /// [HarmonyPrefix] [HarmonyPatch(typeof(Book), nameof(Book.ActOnUse))] public static void PreActOnUse(Book __instance, WorldObject worldObject) { try { if (worldObject is Player player && Codex.IsCodex(__instance)) Codex.Rebuild(player, __instance); } catch (Exception ex) { ModManager.Log($"[{Mod.Name}] rebuild on use failed: {ex.Message}", ModManager.LogLevel.Warn); } } }