Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ToyBox/classes/MonkeyPatchin/Multiclass/LevelUP+Multiclass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> 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 {
Expand Down