Skip to content

Commit

Permalink
Fixes for broken Owlcat mod events
Browse files Browse the repository at this point in the history
  • Loading branch information
Vek17 committed Nov 3, 2022
1 parent 88ae6b0 commit d7b3188
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Version 0.5.4
* Contains fix for broken IAfterRulebookEventTriggerHandler, and IBeforeRulebookEventTriggerHandler events

## Version 0.5.3
* Removed old GetComponent method as it has been replaced by owlcat tooling.
* ContextArcaneSpellFailureIncrease now handles shields more correctly.
Expand Down
2 changes: 1 addition & 1 deletion Repository.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Releases": [
{
"Id": "TabletopTweaks-Core",
"Version": "0.5.3"
"Version": "0.5.4"
}
]
}
61 changes: 61 additions & 0 deletions TabletopTweaks-Core/Bugfixes/General/EventTriggers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using HarmonyLib;
using Kingmaker.Blueprints;
using Kingmaker.PubSubSystem;
using Kingmaker.RuleSystem;
using Kingmaker.RuleSystem.Rules;
using Kingmaker.RuleSystem.Rules.Damage;
using Kingmaker.Visual.CharacterSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace TabletopTweaks.Core.Bugfixes.General {
internal class EventTriggers {
// Breaks generics
//[HarmonyPatch]
static class Rulebook_EventHandler_Ensure {
static MethodBase TargetMethod() {
return AccessTools.Method(typeof(Rulebook), "TriggerEventInternal").MakeGenericMethod(new Type[] { typeof(RulebookEvent) });
}
static bool Prefix(Rulebook __instance, RulebookEvent evt) {
Type T = evt.GetType();
Main.TTTContext.Logger.Log($"TriggerEventInternal<{T.Name}>");
Type handlerType = typeof(Rulebook.EventHandler<>).MakeGenericType(new Type[] { T });
Main.TTTContext.Logger.Log($"Handler Type: {handlerType.Name}<{handlerType.GetGenericArguments()[0].Name}>");
var handlerConstructors = AccessTools.GetDeclaredConstructors(handlerType);
var handlerConstructor = handlerConstructors.FirstOrDefault();
try {
var newHandler = handlerConstructor.Invoke(null);
Main.TTTContext.Logger.Log($"New Handler Type: {newHandler.GetType().Name}<{newHandler.GetType().GetGenericArguments()[0].Name}>");
var instanceField = AccessTools.Field(handlerType, "s_Instance");
var beforeEvent = AccessTools.Field(handlerType, "m_BeforeEvent");
var afterEvent = AccessTools.Field(handlerType, "m_AfterEvent");
instanceField.SetValue(null, newHandler);
var test = instanceField.GetValue(null);
Main.TTTContext.Logger.Log($"HasAfterEvent: {afterEvent.GetValue(newHandler) != null}");
Main.TTTContext.Logger.Log($"HasBeforeEvent: {beforeEvent.GetValue(newHandler) != null}");
Main.TTTContext.Logger.Log($"Set complete: {newHandler == test}");

} catch(Exception e) {
Main.TTTContext.Logger.Log($"{handlerConstructor?.FullDescription()}");
Main.TTTContext.Logger.LogError(e.ToString());
Main.TTTContext.Logger.LogError(e.Message);
}
return true;
}
}
[HarmonyPatch]
static class Rulebook_EventHandler_CleanUp {
static MethodBase TargetMethod() {
return AccessTools.Method(typeof(Rulebook.EventHandler<>).MakeGenericType(typeof(RulebookEvent)), "CleanUp");
}
static bool Prefix() {
return false;
}
}
}
}
2 changes: 1 addition & 1 deletion TabletopTweaks-Core/Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"Repository": "https://raw.githubusercontent.com/Vek17/TabletopTweaks-Core/master/Repository.json",
"Requirements": [],
"LoadAfter": ["MewsiferConsole.Mod"],
"Version": "0.5.3"
"Version": "0.5.4"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Kingmaker.Blueprints;
using Kingmaker.Blueprints.Items.Weapons;
using Kingmaker.Blueprints.JsonSystem;
using Kingmaker.Enums;
using Kingmaker.PubSubSystem;
Expand All @@ -25,7 +26,9 @@ public class TitanStrikeComponent : UnitFactComponentDelegate,

public void OnEventAboutToTrigger(RuleCalculateWeaponStats evt) {
if (evt.Weapon.Blueprint.Type.IsUnarmed) {
evt.IncreaseWeaponSize(1);
evt.WeaponDamageDice.Modify(
WeaponDamageScaleTable.Scale(evt.WeaponDamageDice.ModifiedValue, Size.Large, Size.Medium), base.Fact
);
}
}

Expand Down
1 change: 1 addition & 0 deletions TabletopTweaks-Core/TabletopTweaks-Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bugfixes\General\ContextRankConfigFix.cs" />
<Compile Include="Bugfixes\General\EventTriggers.cs" />
<Compile Include="Bugfixes\General\PropertyFixes.cs" />
<Compile Include="Bugfixes\General\RuleCalculateCMDFix.cs" />
<Compile Include="Config\Blueprints.cs" />
Expand Down

0 comments on commit d7b3188

Please sign in to comment.