[Solved] Modifying Trade Price dynamically

Started by Prince Kasta, June 26, 2019, 11:51:04 AM

Previous topic - Next topic

Prince Kasta

First time trying to mod, I want to modify prices when dealing with specific conditions but I can't find a way to change anything including where I think the price calculation is done (TradeUtility.GetPricePlayerBuy/Sell, right?)
I tried to create a Harmony pre/post fix for those methods but it doesn't seem to trigger when I test trades
with this code.


       [HarmonyPatch(typeof(TradeUtility), "GetPricePlayerSell", null)]
        public static class TradeUtility_GetPricePlayerSell_PrePostfix_Patch
        {
            public static void PreFix(float __result)
            {
                Log.Warning("PreFix");
            }
            public static void PostFix(float __result)
            {
                Log.Warning("PostFix");
            }
        }
        [HarmonyPatch(typeof(TradeUtility), "GetPricePlayerBuy", null)]
        public static class TradeUtility_GetPricePlayerBuy_PrePostfix_Patch
        {
            public static void PreFix(float __result)
            {
                Log.Warning("PreFix2");
            }
            public static void PostFix(float __result)
            {
                Log.Warning("PostFix2");
            }
        }

My other harmony patch for something else works correctly and these patches show up when I log all harmony patches in the debug console. Are they not the correct methods to do this?
Related things that I could find seem to be readonly.
Is what I'm trying to do possible, if so how?

K

The problem is the name of your patching methods. You have PreFix and PostFix, not Prefix and Postfix. They're capitalization sensitive if you choose not to tag them. This patch, for example, does work:

    [HarmonyPatch(typeof(TradeUtility), "GetPricePlayerSell")]
    public static class TradeUtility_GetPricePlayerSellPatch
    {
        public static void Prefix(float __result)
        {
            Log.Warning("Prefix");
        }
    }


This patch is executed at the beginning of every trade encounter and you can modify the buy and sell prices there. You also might want to take a look at the Tradeable class to get an idea of the way that prices are generated, particularly the InitPriceDataIfNeeded method.

Prince Kasta

That is what I get for not copy-pasting the correctly written method and doing in from memory for no reason, so much time waste on a uppercase/lowercase typo.

I know about InitPriceDataIfNeeded  That how I got to these methods.

Thank you so much for the help, I was about to give up on this part and it would seriously mess up what I wanted from my mod and just because a typo.
.