static bool Prefix(KingdomManagementVM __instance)
 {
     try
     {
         if (Clan.PlayerClan.IsUnderMercenaryService)
         {
             InformationManager.ShowInquiry(new InquiryData("Ending Mercenary Contract",
                                                            $"Your mercenary contract will end and you will no longer be affiliated with {Clan.PlayerClan.Kingdom.Name.ToString()}.",
                                                            true, true, new TextObject("{=5Unqsx3N}Confirm").ToString(),
                                                            GameTexts.FindText("str_cancel").ToString(),
                                                            () =>
             {
                 ChangeKingdomAction.ApplyByLeaveKingdomAsMercenaryForNoPayment(Clan.PlayerClan, Clan.PlayerClan.Kingdom);
                 typeof(KingdomManagementVM).GetMethod("ExecuteClose", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                 .Invoke(__instance, null);
             },
                                                            null));
             return(false);
         }
     }
     catch (Exception ex)
     {
         FileLog.Log($"An error occurred in the leaving Kingdom as mercenary fix:\n\n{ex.ToStringFull()}");
     }
     return(true);
 }
        public static void RefreshValuesPatch(KingdomManagementVM __instance)
        {
            MethodInfo forceDecideDecision = __instance.GetType().GetMethod("ForceDecideDecision", BindingFlags.NonPublic | BindingFlags.Instance);
            Action <KingdomDecision> forceDecideDecisionAction = (Action <KingdomDecision>)Delegate.CreateDelegate(typeof(Action <KingdomDecision>), __instance, forceDecideDecision);

            __instance.Clan      = new KingdomClanVMExtensionVM(forceDecideDecisionAction);
            __instance.Diplomacy = new KingdomDiplomacyVMExtensionVM(forceDecideDecisionAction);

            int currentCategoryFieldInfo =
                (int)typeof(KingdomManagementVM).GetField("_currentCategory", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
            // KingdomCategoryVM currentCategoryFieldInfo =
            //                (KingdomCategoryVM)typeof(KingdomManagementVM).GetField("_currentCategory", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
            //                        MethodInfo setCurrentCategoryMethodInfo = __instance.GetType().GetMethod("SetCurrentCategory", BindingFlags.NonPublic | BindingFlags.Instance);
            MethodInfo setCurrentCategoryMethodInfo = __instance.GetType().GetMethod("SetSelectedCategory", BindingFlags.NonPublic | BindingFlags.Instance);

            if (currentCategoryFieldInfo == 0)
            {
                setCurrentCategoryMethodInfo.Invoke(__instance, new object[] { __instance.Clan });
            }
            else if (currentCategoryFieldInfo == 4)
            {
                setCurrentCategoryMethodInfo.Invoke(__instance, new object[] { __instance.Diplomacy });
            }

            /*
             * if (currentCategoryFieldInfo is KingdomClanVM)
             * {
             *  setCurrentCategoryMethodInfo.Invoke(__instance, new object[] { __instance.Clan });
             * }
             * else if (currentCategoryFieldInfo is KingdomDiplomacyVM)
             * {
             *  setCurrentCategoryMethodInfo.Invoke(__instance, new object[] { __instance.Diplomacy });
             * }
             */
        }
 public static void ExecuteClosePatch(KingdomManagementVM __instance)
 {
     ((KingdomDiplomacyVMExtensionVM)__instance.Diplomacy).OnClose();
     ((KingdomClanVMExtensionVM)__instance.Clan).OnClose();
 }