2023-08-26 17:59:50 -04:00
|
|
|
|
using HarmonyLib;
|
2023-09-04 02:30:54 -04:00
|
|
|
|
using Parse.Common.Internal;
|
2023-08-26 17:59:50 -04:00
|
|
|
|
using System;
|
2023-09-03 22:29:29 -04:00
|
|
|
|
using System.Reflection;
|
2023-08-26 17:59:50 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace CustomCosmeticLoader.Patches
|
|
|
|
|
{
|
2023-09-04 02:30:54 -04:00
|
|
|
|
internal static class MarbleHolderValues
|
|
|
|
|
{
|
|
|
|
|
private static FieldInfo _mbcField = typeof(MarbleHolder).GetField("mbc", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
public static FieldInfo MbcField
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _mbcField;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-02 23:19:35 -04:00
|
|
|
|
[HarmonyPatch(typeof(MarbleHolder), nameof(MarbleHolder.SetMarble))]
|
2023-08-26 17:59:50 -04:00
|
|
|
|
internal class MarbleHolderSetMarblePatch
|
|
|
|
|
{
|
|
|
|
|
static void Postfix(MarbleHolder __instance, Cosmetic marbleObject)
|
|
|
|
|
{
|
2023-08-27 02:44:35 -04:00
|
|
|
|
if (!Config.enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-09-03 02:06:53 -04:00
|
|
|
|
if (marbleObject.Id != Config.skinNameToHijack && Config.skinNameToHijack != "*")
|
2023-08-27 02:44:35 -04:00
|
|
|
|
return;
|
2023-09-03 00:21:15 -04:00
|
|
|
|
|
|
|
|
|
if (!Config.inCosmeticMenu && __instance == CosmeticPanel.cosmHolder)
|
|
|
|
|
return;
|
2023-09-03 22:29:29 -04:00
|
|
|
|
|
2023-09-04 02:30:54 -04:00
|
|
|
|
Texture2D skin = null;
|
|
|
|
|
|
2023-09-03 22:29:29 -04:00
|
|
|
|
if (NetworkManager.IsMultiplayer)
|
|
|
|
|
{
|
2023-09-04 02:30:54 -04:00
|
|
|
|
MarbleController controller = MarbleHolderValues.MbcField.GetValue(__instance) as MarbleController;
|
|
|
|
|
if (controller == null)
|
2023-09-03 22:29:29 -04:00
|
|
|
|
return;
|
2023-09-04 02:30:54 -04:00
|
|
|
|
if (!controller.isMyClientMarble())
|
|
|
|
|
{
|
|
|
|
|
if (!Config.otherPlayers.ContainsKey(controller.nickname))
|
|
|
|
|
return;
|
|
|
|
|
skin = Config.skins[Config.otherPlayers[controller.nickname]];
|
|
|
|
|
}
|
2023-09-03 22:29:29 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 02:30:54 -04:00
|
|
|
|
Shared.ApplyCustomTexture(__instance.currentMarble, skin);
|
2023-08-26 17:59:50 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-03 22:29:29 -04:00
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(MarbleHolder), nameof(MarbleHolder.CheckSet))]
|
|
|
|
|
internal class MarbleHolderCheckSetPatch
|
|
|
|
|
{
|
|
|
|
|
static void Postfix(MarbleHolder __instance, Cosmetic.Set cs)
|
|
|
|
|
{
|
|
|
|
|
if (!Config.enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!NetworkManager.IsMultiplayer)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-09-04 02:30:54 -04:00
|
|
|
|
MarbleController controller = MarbleHolderValues.MbcField.GetValue(__instance) as MarbleController;
|
2023-09-03 22:29:29 -04:00
|
|
|
|
|
|
|
|
|
if (controller == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-09-04 02:30:54 -04:00
|
|
|
|
if (!controller.isMyClientMarble())
|
|
|
|
|
{
|
|
|
|
|
if (!Config.otherPlayers.ContainsKey(controller.nickname))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 22:29:29 -04:00
|
|
|
|
// Don't hijack the soccer ball or zombie skins
|
|
|
|
|
if (cs.skin == "SoccerBall_V4" || cs.skin == "Zombie")
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__instance.SetMarble(Shared.SkinToHijack);
|
|
|
|
|
__instance.CosmeticSet.skin = cs.skin;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-26 17:59:50 -04:00
|
|
|
|
}
|