miuu-custom-cosmetic-loader/Patches/MarbleWidgetPatches.cs

31 lines
954 B
C#

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 ?? CosmeticManager.Skins[0]) :
Shared.SkinToHijack;
Cosmetic hat = CosmeticManager.MyHat ?? CosmeticManager.Hats[0];
__instance.SetCosmetic(skin, hat);
Shared.ApplyCustomTexture(__instance.cosmeticDisplay.gameObject);
return false; // Skip original method, since we do everything it was supposed to
}
}
}