static void Postfix(int cost, bool format, ref string __result)
 {
     try
     {
         if (!Main.enabled)
         {
             return;
         }
         if (!Main.settings.currencyFallback)
         {
             return;
         }
         if (!KingdomCurrencyFallback.CanSpend(cost))
         {
             return;
         }
         string           costFormat      = KingdomCurrencyFallback.costFormat;
         string           costSplitFormat = KingdomCurrencyFallback.costSplitFormat;
         var              originalFormat  = (!format) ? KingdomUIRoot.Instance.Texts.KingdomProjectStartBPCostStartLabelFormat : KingdomUIRoot.Instance.Texts.KingdomProjectStartBPCostFormat;
         Tuple <int, int> costSplit       = KingdomCurrencyFallback.SplitCost(cost);
         if (costSplit.Item2 == 0)
         {
             __result = string.Format(costFormat, string.Format(originalFormat, costSplit.Item1));
         }
         else
         {
             __result = string.Format(costSplitFormat, string.Format(originalFormat, costSplit.Item1), costSplit.Item2);
         }
     }
     catch (Exception ex)
     {
         Main.Error(ex);
         return;
     }
 }
 static void Postfix(TextMeshProUGUI ___m_DescText, GlobalMapLocation ___m_Location,
                     GameObject ___m_StandartControllers, GameObject ___m_OkControllers)
 {
     try
     {
         if (!Main.enabled)
         {
             return;
         }
         if (!Main.settings.currencyFallback)
         {
             return;
         }
         LocationData.ResourceStateType resource = ___m_Location.Data.Resource;
         if (resource == ResourceStateType.CantClaimWrongRegion)
         {
             return;
         }
         if (resource != ResourceStateType.CanClaim)
         {
             return;
         }
         if (!KingdomCurrencyFallback.CanSpend(KingdomRoot.Instance.DefaultMapResourceCost))
         {
             return;
         }
         string           resourceCostSplitFormat = KingdomCurrencyFallback.resourceCostSplitFormat;
         UITextGlobalMap  globalMap = Game.Instance.BlueprintRoot.LocalizedTexts.UserInterfacesText.GlobalMap;
         Tuple <int, int> costSplit = KingdomCurrencyFallback.SplitCost(KingdomRoot.Instance.DefaultMapResourceCost);
         if (costSplit.Item2 == 0)
         {
             return;
         }
         var bpText = string.Format(resourceCostSplitFormat, costSplit.Item1, costSplit.Item2);
         ___m_DescText.text = string.Format(globalMap.ResourceAvailable, bpText, KingdomState.Instance.BuildPoints);
         ___m_StandartControllers.SetActive(true);
         ___m_OkControllers.SetActive(false);
     }
     catch (Exception ex)
     {
         Main.Error(ex);
     }
 }
            static bool Prefix(object __instance, BlueprintSettlementBuilding building, SettlementBuilding settlementBuilding, SettlementState settlement,
                               Image ___Slots, TextMeshProUGUI ___Cost, Image ___DiscountLayer)
            {
                try
                {
                    if (!Main.enabled)
                    {
                        return(true);
                    }
                    if (!Main.settings.currencyFallback)
                    {
                        return(true);
                    }

                    string costFormat      = KingdomCurrencyFallback.costFormat;
                    string costSplitFormat = KingdomCurrencyFallback.costSplitFormat;

                    ___Slots.sprite = KingdomUIRoot.Instance.Settlement.GetSlotSprite(building.SlotCount);

                    if (settlementBuilding == null)
                    {
                        int actualCost = settlement.GetActualCost(building, out bool isDiscounted);
                        ___DiscountLayer?.gameObject?.SetActive(actualCost == 0 || isDiscounted);

                        if (actualCost == 0)
                        {
                            ___Cost.text = string.Format(costFormat, KingdomUIRoot.Instance.Texts.BuildFreeCost);
                        }
                        else
                        {
                            Tuple <int, int> costSplit = KingdomCurrencyFallback.SplitCost(actualCost);

                            LocalizedString format = isDiscounted ? KingdomUIRoot.Instance.Texts.BuildPointsDiscountFormat : KingdomUIRoot.Instance.Texts.BuildPointsFormat;

                            if (costSplit.Item2 == 0)
                            {
                                ___Cost.text = string.Format(costFormat, string.Format(format, costSplit.Item1));
                            }
                            else
                            {
                                ___Cost.text = string.Format(costSplitFormat, string.Format(format, costSplit.Item1), costSplit.Item2);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            ___DiscountLayer.gameObject.SetActive(false);
                        }
                        catch (NullReferenceException) {
                            //accessing ___DiscountLayer.gameObject after the gameObject has been destroyed causes the getter to throw an exception
                        }
                        ___Cost.text = string.Format(costFormat, string.Format(KingdomUIRoot.Instance.Texts.BuildPointsFormat, settlementBuilding.Owner.GetSellPrice(building)));
                    }

                    SetColor(__instance, building, settlementBuilding, settlement);
                    return(false);
                }
                catch (Exception ex)
                {
                    Main.Error(ex);
                    return(true);
                }
            }