diff --git a/PatchEntryPoint.cs b/PatchEntryPoint.cs index 02dbaa8..1618b39 100644 --- a/PatchEntryPoint.cs +++ b/PatchEntryPoint.cs @@ -1,5 +1,8 @@ using HarmonyLib; using System; +using System.IO; +using System.Reflection; +using UnityEngine; using UnityEngine.SceneManagement; namespace CustomCosmeticLoader @@ -8,6 +11,8 @@ namespace CustomCosmeticLoader { private static bool IsPatched = false; + public static Texture2D skin; + public static void Start() { SceneManager.sceneLoaded += beginPatch; @@ -20,7 +25,16 @@ namespace CustomCosmeticLoader new Harmony("com.thearst3rd.customcosmeticloader").PatchAll(); IsPatched = true; SceneManager.sceneLoaded -= beginPatch; + LoadCosmetics(); } } + + private static void LoadCosmetics() + { + string skinFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + skinFile = Path.Combine(skinFile, "skin.png"); + skin = new Texture2D(2, 2); + skin.LoadImage(File.ReadAllBytes(skinFile)); + } } } diff --git a/Patches/MarbleControllerPatches.cs b/Patches/MarbleControllerPatches.cs new file mode 100644 index 0000000..e061e8a --- /dev/null +++ b/Patches/MarbleControllerPatches.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using System; + +namespace CustomCosmeticLoader.Patches +{ + [HarmonyPatch(typeof(MarbleController))] + [HarmonyPatch("ApplyMyCosmetics")] + internal class MarbleControllerApplyMyCosmeticsPatch + { + private static Cosmetic mirageSkin = null; + + [HarmonyPostfix] + static void Postfix(MarbleController __instance) + { + if (mirageSkin == null) + { + // We hijack one skin (Mirage) since it's one of the basic skins with no animations/different UVs/etc + foreach (Cosmetic skin in CosmeticManager.Skins) + { + if (skin.Id == "Swirl_M") + { + mirageSkin = skin; + break; + } + } + + if (mirageSkin == null) //whut + return; + } + + MarbleHolder mHolder = __instance.MHolder; + string actualSkinId = mHolder.CosmeticSet.skin; + mHolder.SetMarble(mirageSkin); + // Setting the skin id here allows others in multiplayer/replays to see your normal skin + mHolder.CosmeticSet.skin = actualSkinId; + } + } +} diff --git a/Patches/MarbleHolderPatches.cs b/Patches/MarbleHolderPatches.cs new file mode 100644 index 0000000..d2ebfab --- /dev/null +++ b/Patches/MarbleHolderPatches.cs @@ -0,0 +1,27 @@ +using HarmonyLib; +using System; +using UnityEngine; + +namespace CustomCosmeticLoader.Patches +{ + [HarmonyPatch(typeof(MarbleHolder))] + [HarmonyPatch("SetMarble")] + internal class MarbleHolderSetMarblePatch + { + static void Postfix(MarbleHolder __instance, Cosmetic marbleObject) + { + if (marbleObject.Id != "Swirl_M") + return; // I only hijack this one skin, "Mirage" + + MeshRenderer[] componentsInChildren = __instance.currentMarble.GetComponentsInChildren(); + for (int i = 0; i < componentsInChildren.Length; i++) + { + Material[] materials = componentsInChildren[i].materials; + foreach (Material material in materials) + { + material.mainTexture = PatchEntryPoint.skin; + } + } + } + } +}