Show custom skin on main menu
This commit is contained in:
parent
294c0ba205
commit
6a7104ea0d
5 changed files with 100 additions and 34 deletions
16
Config.cs
16
Config.cs
|
@ -15,12 +15,14 @@ namespace CustomCosmeticLoader
|
||||||
|
|
||||||
public const string PROPERTY_ENABLED = "enabled";
|
public const string PROPERTY_ENABLED = "enabled";
|
||||||
public const string PROPERTY_CURRENT_SKIN = "currentSkin";
|
public const string PROPERTY_CURRENT_SKIN = "currentSkin";
|
||||||
public const string PROPERTY_SKIN_TO_HIJACK = "skinToHijack";
|
public const string PROPERTY_SKIN_NAME_TO_HIJACK = "skinNameToHijack";
|
||||||
|
public const string PROPERTY_IN_MAIN_MENU = "inMainMenu";
|
||||||
public const string PROPERTY_IN_COSMETIC_MENU = "inCosmeticMenu";
|
public const string PROPERTY_IN_COSMETIC_MENU = "inCosmeticMenu";
|
||||||
|
|
||||||
public static bool enabled = true;
|
public static bool enabled = true;
|
||||||
public static string currentSkin;
|
public static string currentSkin;
|
||||||
public static string skinToHijack = "Swirl_M"; // Mirage, simple skin with nice properties
|
public static string skinNameToHijack = "Swirl_M"; // Mirage, simple skin with nice properties
|
||||||
|
public static bool inMainMenu = true;
|
||||||
public static bool inCosmeticMenu = false;
|
public static bool inCosmeticMenu = false;
|
||||||
|
|
||||||
public static Dictionary<string, Texture2D> skins = new Dictionary<string, Texture2D>();
|
public static Dictionary<string, Texture2D> skins = new Dictionary<string, Texture2D>();
|
||||||
|
@ -71,8 +73,11 @@ namespace CustomCosmeticLoader
|
||||||
currentSkin = skins.Keys.ToList()[0];
|
currentSkin = skins.Keys.ToList()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data[PROPERTY_SKIN_TO_HIJACK] != null)
|
if (data[PROPERTY_SKIN_NAME_TO_HIJACK] != null)
|
||||||
skinToHijack = data[PROPERTY_SKIN_TO_HIJACK].Value;
|
skinNameToHijack = data[PROPERTY_SKIN_NAME_TO_HIJACK].Value;
|
||||||
|
|
||||||
|
if (data[PROPERTY_IN_MAIN_MENU] != null)
|
||||||
|
inMainMenu = data[PROPERTY_IN_MAIN_MENU].AsBool;
|
||||||
|
|
||||||
if (data[PROPERTY_IN_COSMETIC_MENU] != null)
|
if (data[PROPERTY_IN_COSMETIC_MENU] != null)
|
||||||
inCosmeticMenu = data[PROPERTY_IN_COSMETIC_MENU].AsBool;
|
inCosmeticMenu = data[PROPERTY_IN_COSMETIC_MENU].AsBool;
|
||||||
|
@ -84,7 +89,8 @@ namespace CustomCosmeticLoader
|
||||||
{
|
{
|
||||||
{ PROPERTY_ENABLED, enabled ? "true" : "false" },
|
{ PROPERTY_ENABLED, enabled ? "true" : "false" },
|
||||||
{ PROPERTY_CURRENT_SKIN, currentSkin },
|
{ PROPERTY_CURRENT_SKIN, currentSkin },
|
||||||
{ PROPERTY_SKIN_TO_HIJACK, skinToHijack },
|
{ PROPERTY_SKIN_NAME_TO_HIJACK, skinNameToHijack },
|
||||||
|
{ PROPERTY_IN_MAIN_MENU, inMainMenu ? "true" : "false" },
|
||||||
{ PROPERTY_IN_COSMETIC_MENU, inCosmeticMenu ? "true" : "false" },
|
{ PROPERTY_IN_COSMETIC_MENU, inCosmeticMenu ? "true" : "false" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
32
Patches/MainMenuPanelPatches.cs
Normal file
32
Patches/MainMenuPanelPatches.cs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
using HarmonyLib;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace CustomCosmeticLoader.Patches
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(MainMenuPanel), nameof(MainMenuPanel.SetupImages), new Type[] { typeof(bool) })]
|
||||||
|
internal class MainMenuPanelSetupImagesPatch
|
||||||
|
{
|
||||||
|
static void Postfix(MainMenuPanel __instance)
|
||||||
|
{
|
||||||
|
if (!Config.enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!Config.inMainMenu)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Config.skinNameToHijack == "*")
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Shared.SkinToHijack == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (__instance.cosmeticDisplay)
|
||||||
|
{
|
||||||
|
__instance.cosmeticDisplay.Clear();
|
||||||
|
GameObjectAllocator.Deinitialize(__instance.cosmeticDisplay.gameObject);
|
||||||
|
__instance.cosmeticDisplay.Setup(Shared.SkinToHijack, CosmeticType.Skin, true, true);
|
||||||
|
Shared.ApplyCustomTexture(__instance.cosmeticDisplay.CachedCosmeticGameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,38 +7,21 @@ namespace CustomCosmeticLoader.Patches
|
||||||
[HarmonyPatch(typeof(MarbleController), nameof(MarbleController.ApplyMyCosmetics))]
|
[HarmonyPatch(typeof(MarbleController), nameof(MarbleController.ApplyMyCosmetics))]
|
||||||
internal class MarbleControllerApplyMyCosmeticsPatch
|
internal class MarbleControllerApplyMyCosmeticsPatch
|
||||||
{
|
{
|
||||||
private static Cosmetic hijackSkin = null;
|
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
static void Postfix(MarbleController __instance)
|
static void Postfix(MarbleController __instance)
|
||||||
{
|
{
|
||||||
if (!Config.enabled)
|
if (!Config.enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Config.skinToHijack == "*")
|
if (Config.skinNameToHijack == "*")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (hijackSkin == null)
|
if (Shared.SkinToHijack == null)
|
||||||
{
|
return;
|
||||||
foreach (Cosmetic skin in CosmeticManager.Skins)
|
|
||||||
{
|
|
||||||
if (skin.Id == Config.skinToHijack)
|
|
||||||
{
|
|
||||||
hijackSkin = skin;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hijackSkin == null)
|
|
||||||
{
|
|
||||||
Debug.LogWarning("Couldn't hijack skin " + Config.skinToHijack);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MarbleHolder mHolder = __instance.MHolder;
|
MarbleHolder mHolder = __instance.MHolder;
|
||||||
string actualSkinId = mHolder.CosmeticSet.skin;
|
string actualSkinId = mHolder.CosmeticSet.skin;
|
||||||
mHolder.SetMarble(hijackSkin);
|
mHolder.SetMarble(Shared.SkinToHijack);
|
||||||
// Setting the skin id here allows others in multiplayer/replays to see your normal skin
|
// Setting the skin id here allows others in multiplayer/replays to see your normal skin
|
||||||
mHolder.CosmeticSet.skin = actualSkinId;
|
mHolder.CosmeticSet.skin = actualSkinId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,13 @@ namespace CustomCosmeticLoader.Patches
|
||||||
if (!Config.enabled)
|
if (!Config.enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (marbleObject.Id != Config.skinToHijack && Config.skinToHijack != "*")
|
if (marbleObject.Id != Config.skinNameToHijack && Config.skinNameToHijack != "*")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Config.inCosmeticMenu && __instance == CosmeticPanel.cosmHolder)
|
if (!Config.inCosmeticMenu && __instance == CosmeticPanel.cosmHolder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MeshRenderer[] componentsInChildren = __instance.currentMarble.GetComponentsInChildren<MeshRenderer>();
|
Shared.ApplyCustomTexture(__instance.currentMarble);
|
||||||
for (int i = 0; i < componentsInChildren.Length; i++)
|
|
||||||
{
|
|
||||||
Material[] materials = componentsInChildren[i].materials;
|
|
||||||
foreach (Material material in materials)
|
|
||||||
material.mainTexture = Config.skins[Config.currentSkin];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
51
Shared.cs
Normal file
51
Shared.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace CustomCosmeticLoader
|
||||||
|
{
|
||||||
|
public static class Shared
|
||||||
|
{
|
||||||
|
private static Cosmetic skinToHijack;
|
||||||
|
private static bool noSkinToHijack = false;
|
||||||
|
|
||||||
|
public static Cosmetic SkinToHijack
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (noSkinToHijack)
|
||||||
|
return null;
|
||||||
|
if (skinToHijack == null)
|
||||||
|
{
|
||||||
|
DetermineSkinToHijack();
|
||||||
|
if (skinToHijack == null)
|
||||||
|
Debug.LogWarning("Couldn't hijack skin " + Config.skinNameToHijack);
|
||||||
|
}
|
||||||
|
|
||||||
|
return skinToHijack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DetermineSkinToHijack()
|
||||||
|
{
|
||||||
|
foreach (Cosmetic skin in CosmeticManager.Skins)
|
||||||
|
{
|
||||||
|
if (skin.Id == Config.skinNameToHijack)
|
||||||
|
{
|
||||||
|
skinToHijack = skin;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ApplyCustomTexture(GameObject marbleObject)
|
||||||
|
{
|
||||||
|
MeshRenderer[] componentsInChildren = marbleObject.GetComponentsInChildren<MeshRenderer>();
|
||||||
|
for (int i = 0; i < componentsInChildren.Length; i++)
|
||||||
|
{
|
||||||
|
Material[] materials = componentsInChildren[i].materials;
|
||||||
|
foreach (Material material in materials)
|
||||||
|
material.mainTexture = Config.skins[Config.currentSkin];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue