diff --git a/ToyBox/classes/MonkeyPatchin/Multiclass/LevelUP+Multiclass.cs b/ToyBox/classes/MonkeyPatchin/Multiclass/LevelUP+Multiclass.cs index 7f75f4ac1..8f07f2f2f 100644 --- a/ToyBox/classes/MonkeyPatchin/Multiclass/LevelUP+Multiclass.cs +++ b/ToyBox/classes/MonkeyPatchin/Multiclass/LevelUP+Multiclass.cs @@ -12,12 +12,17 @@ //using Kingmaker.UI._ConsoleUI.Models; //using Kingmaker.UI.RestCamp; using Kingmaker.UnitLogic; +using Kingmaker.UnitLogic.Abilities.Blueprints; +using Kingmaker.UnitLogic.Abilities; using Kingmaker.UnitLogic.Class.LevelUp; using Kingmaker.UnitLogic.Class.LevelUp.Actions; using Kingmaker.Utility; using ModKit; using System; +using System.Collections.Generic; using System.Linq; +using System.Reflection.Emit; +using System.Reflection; using ToyBox.classes.Infrastructure; //using Kingmaker.UI._ConsoleUI.GroupChanger; //using Kingmaker.UI.LevelUp.Phase; @@ -226,6 +231,32 @@ public static bool Apply(LevelUpState state, UnitDescriptor unit) { } } + // fix CopiedFromScroll not being copied over + [HarmonyPatch(typeof(UnitHelper), nameof(UnitHelper.CopySpellbook))] + private static class UnitHelper_CopySpellbook { + private static AbilityData AddSave(Spellbook th, int lvl, BlueprintAbility ab, bool ev, AbilityData from) { + var added = th.AddKnown(lvl, ab, ev); + added.IsTemporary = from.IsTemporary; + added.CopiedFromScroll = from.CopiedFromScroll; + added.IsFromMythicSpellList = from.IsFromMythicSpellList; + added.IsMysticTheurgeCombinedSpell = from.IsMysticTheurgeCombinedSpell; + added.m_Fact = from.Fact; // SourceItem, SourceItemEquipmentBlueprint, SourceItemUsableBlueprint + return added; + } + + public static IEnumerable Transpiler(IEnumerable instruction) { + var search = AccessTools.Method(typeof(Spellbook), nameof(Spellbook.AddKnown)); + foreach (var c in instruction) { + if (c.opcode == OpCodes.Callvirt && c.operand is MethodInfo i && i == search) { + yield return new CodeInstruction(OpCodes.Ldloc_S, 6); + yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(UnitHelper_CopySpellbook), nameof(UnitHelper_CopySpellbook.AddSave))); + continue; + } + yield return c; + } + } + } + // Fixed a vanilla PFK bug that caused dragon bloodline to be displayed in Magus' feats tree [HarmonyPatch(typeof(ApplyClassMechanics), nameof(ApplyClassMechanics.ApplyProgressions))] private static class ApplyClassMechanics_ApplyProgressions_Patch {