Open sbtoonz opened 1 year ago
[HarmonyPatch(typeof(StoreGui), nameof(StoreGui.Awake))]
[HarmonyPrefix]
public static bool Awake_Pretfix(StoreGui __instance)
{
if(__instance.gameObject.name.StartsWith("Auga"))return false;
if (!Auga.Assets.StoreGui) return true;
if (Auga.HasBetterTrader)
{
return true;
}
Auga.Assets.StoreGui = (GameObject)Object.Instantiate(Auga.Assets.StoreGui,
__instance.gameObject.GetComponentInParent<Transform>(), false);
return true;
}
[HarmonyPatch(typeof(StoreGui), nameof(StoreGui.Awake))]
[HarmonyPostfix]
public static void AwakePostfix(StoreGui __instance)
{
if (__instance.gameObject.name.StartsWith("Auga")) return;
StoreGui.m_instance = Auga.Assets.StoreGui.GetComponent<StoreGui>();
__instance.m_itemlistBaseSize = Auga.Assets.StoreGui.GetComponent<StoreGui>().m_listRoot.rect.height;
Auga.Assets.StoreGui.GetComponent<StoreGui>().m_coinPrefab = ObjectDB.instance.GetItemPrefab("Coins").GetComponent<ItemDrop>();
Auga.Assets.StoreGui.transform.Find("Store").gameObject.AddComponent<MovableHudElement>().Init(TextAnchor.UpperLeft, 140, -180);
}
Consider this a proof of concept but it will properly patch the original storeGUI.awake without killing it for other objects trying to patch
Instantiate the copy of Auga store
And then assign agua store instance to StoreGui.m_instance
The ONLY interaction with store is done through StoreGui.instance.Show(Trader thistrader)
therefore just replacing the instance call is merely enough to emplace your custom UIX object
I patch into this for many mods
even some that were auga compatibile before mistlands updates
https://github.com/RandyKnapp/Auga/blob/main/Auga/Store_Setup.cs#L19
https://github.com/RandyKnapp/Auga/blob/main/Auga/SetupHelper.cs#L22
maybe soemething like this instead?
please dont just destroy the vanilla objects... just disable them.. and reassign the appropriate variables for your new scripts
Sure its a chunk more to go through and code
https://github.com/VMP-Valheim/InventoryOverhaul/blob/master/ModFrame/Mod.cs#L159-L202
but it will definitely retain compatibility to any mod that is patching these things
@Vapok It's been almost a year since I was modding valheim UIX stuff, so take this with a grain of salt, but I do vividly recall being able to pipe my own things into their work flow without having to Destroy() or DistroyImmediate() the GO I was working to edit/replace at runtime
I would be more than willing to attempt to go through each patch of Auga and attempt to set it up in similar fashions in order to not cripple other mods that patch into these items
examples of failing patches using Store.Awake as patch target
https://github.com/sbtoonz/Trader_2.0/blob/master/Trader2.0/Patches.cs#L194-L195
https://github.com/sbtoonz/unforgibbable/blob/master/Unforgibbable/Patches.cs#L82-L89