Support showing custom marbles in multiplayer

This commit is contained in:
Terry Hearst 2023-09-03 22:29:29 -04:00
parent 6a7104ea0d
commit 8e92d3a0fb
5 changed files with 40 additions and 7 deletions

View file

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net48</TargetFramework> <TargetFramework>net48</TargetFramework>
</PropertyGroup> </PropertyGroup>
<Import Project="$(ProjectDir)UserProperties.xml" /> <Import Project="$(ProjectDir)UserProperties.xml" />
<Target Name="VerifyModReferences" BeforeTargets="Build"> <Target Name="VerifyModReferences" BeforeTargets="Build">

View file

@ -17,9 +17,6 @@ namespace CustomCosmeticLoader.Patches
if (Config.skinNameToHijack == "*") if (Config.skinNameToHijack == "*")
return; return;
if (Shared.SkinToHijack == null)
return;
if (__instance.cosmeticDisplay) if (__instance.cosmeticDisplay)
{ {
__instance.cosmeticDisplay.Clear(); __instance.cosmeticDisplay.Clear();

View file

@ -16,7 +16,8 @@ namespace CustomCosmeticLoader.Patches
if (Config.skinNameToHijack == "*") if (Config.skinNameToHijack == "*")
return; return;
if (Shared.SkinToHijack == null) // Shouldn't happen I don't think but we do this elsewhere in mp
if (NetworkManager.IsMultiplayer)
return; return;
MarbleHolder mHolder = __instance.MHolder; MarbleHolder mHolder = __instance.MHolder;

View file

@ -1,5 +1,6 @@
using HarmonyLib; using HarmonyLib;
using System; using System;
using System.Reflection;
using UnityEngine; using UnityEngine;
namespace CustomCosmeticLoader.Patches namespace CustomCosmeticLoader.Patches
@ -17,8 +18,42 @@ namespace CustomCosmeticLoader.Patches
if (!Config.inCosmeticMenu && __instance == CosmeticPanel.cosmHolder) if (!Config.inCosmeticMenu && __instance == CosmeticPanel.cosmHolder)
return; return;
// If this is a networked game, ONLY apply to my marble and not anyone else happening to use our SkinToHijack
if (NetworkManager.IsMultiplayer)
{
MarbleController controller = __instance.GetComponentInParent<MarbleController>();
if (!controller.isMyClientMarble())
return;
}
Shared.ApplyCustomTexture(__instance.currentMarble); Shared.ApplyCustomTexture(__instance.currentMarble);
} }
} }
[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;
FieldInfo mbcField = typeof(MarbleHolder).GetField("mbc", BindingFlags.NonPublic | BindingFlags.Instance);
MarbleController controller = mbcField.GetValue(__instance) as MarbleController;
if (controller == null)
return;
// 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;
}
}
} }

View file

@ -20,7 +20,7 @@ namespace CustomCosmeticLoader
if (skinToHijack == null) if (skinToHijack == null)
Debug.LogWarning("Couldn't hijack skin " + Config.skinNameToHijack); Debug.LogWarning("Couldn't hijack skin " + Config.skinNameToHijack);
} }
return skinToHijack; return skinToHijack;
} }
} }