Skip to content

Commit

Permalink
Added OnInitialize callsite back in
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeswick96 authored and shdwp committed Apr 14, 2020
1 parent abb162e commit 470dd0c
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using HarmonyLib;
using SandBox.GauntletUI;
using TaleWorlds.CampaignSystem.ViewModelCollection;
using TaleWorlds.Core;

namespace UIExtenderLibModule.ViewModel.Patches
Expand All @@ -23,4 +24,25 @@ public static MethodBase TargetMethod()

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> input) => ViewModelPatchUtil.TranspilerForVMInstantiation(input);
}
}

// OnInitialize - only runs once each time party screen is opened BUT DOES NOT RUN ON THE FIRST OPEN
[HarmonyPatch]
public static class GauntletPartyScreenOnInitializeCallsite
{
public static MethodBase TargetMethod()
{
Type type = typeof(GauntletPartyScreen);
MethodInfo interfaceMethod = type.GetInterface(nameof(IGameStateListener)).GetMethod("OnInitialize");
if (interfaceMethod == null) return null;

InterfaceMapping map = type.GetInterfaceMap(interfaceMethod.DeclaringType ?? throw new NullReferenceException("Cannot find GauntletPartyScreen IGameStateListener.OnInitialize method"));
return map.TargetMethods[Array.IndexOf(map.InterfaceMethods, interfaceMethod)];
}

public static void Prefix()
{
ViewModelComponent component = UIExtenderLibModule.SharedInstance.ViewModelComponent;
component.RefreshMixinsForTypes(new[] {typeof(PartyVM)});
}
}
}

0 comments on commit 470dd0c

Please sign in to comment.