From a145e22fcef05c42133371e59eae2a878b9b3781 Mon Sep 17 00:00:00 2001 From: Terry Hearst Date: Sat, 9 Sep 2023 03:23:03 -0400 Subject: [PATCH] Show custom skin in My Marble widget on the level select screen --- Patches/MarbleWidgetPatches.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Patches/MarbleWidgetPatches.cs diff --git a/Patches/MarbleWidgetPatches.cs b/Patches/MarbleWidgetPatches.cs new file mode 100644 index 0000000..6b95009 --- /dev/null +++ b/Patches/MarbleWidgetPatches.cs @@ -0,0 +1,31 @@ +using HarmonyLib; +using System; + +namespace CustomCosmeticLoader.Patches +{ + /* + * This is called on the LevelSelect screen to show the "My Marble" widget in the top left corner. Hijack the cosmetic + * and apply the custom texture here too (if configured) + */ + [HarmonyPatch(typeof(MarbleWidget), nameof(MarbleWidget.SetCosmetic), new Type[] {})] + internal class MarbleWidgetSetCosmeticLevelSelectPatch + { + static bool Prefix(MarbleWidget __instance) + { + if (!Config.enabled) + return true; + + if (!Config.inMainMenu) + return true; + + Cosmetic skin = Config.skinNameToHijack == "*" ? + (CosmeticManager.MySkin == null ? CosmeticManager.Skins[0] : CosmeticManager.MySkin) : + Shared.SkinToHijack; + Cosmetic hat = CosmeticManager.MyHat == null ? CosmeticManager.Hats[0] : CosmeticManager.MyHat; + + __instance.SetCosmetic(skin, hat); + Shared.ApplyCustomTexture(__instance.cosmeticDisplay.gameObject); + return false; // Skip original method, since we do everything it was supposed to + } + } +}