Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 69 additions & 8 deletions src/CosmeticsPatches.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using HarmonyLib;
using System.Collections.Generic;

namespace AUnlocker;

Expand Down Expand Up @@ -59,22 +60,82 @@ public static void Postfix(HatManager __instance)

[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.FixedUpdate))]
public static class DontShowCosmeticsInGame_PlayerControl_FixedUpdate_Postfix
{
{
private static readonly Dictionary<byte, float> LastCheckTime = new();

/// <summary>
/// Don't show any cosmetics in-game (only client-side).
/// </summary>
/// <param name="__instance">The <c>PlayerControl</c> instance.</param>
public static void Postfix(PlayerControl __instance)
{
if (!AUnlocker.DontShowCosmeticsInGame.Value) return;
__instance.SetHat("", 0);
__instance.SetSkin("", 0);
__instance.SetVisor("", 0);
__instance.SetNamePlate("");
__instance.SetPet("", 0);
if (!AUnlocker.DontShowCosmeticsInGame.Value)
{
LastCheckTime.Clear();
return;
}

if (__instance == null) return;
if (__instance.Data == null) return;

var outfit = __instance.Data.DefaultOutfit;
if (outfit == null) return;
if (outfit.IsIncomplete) return;

float now = UnityEngine.Time.time;

if (LastCheckTime.TryGetValue(__instance.PlayerId, out float lastTime))
{
if (now - lastTime < 0.25f)
return;
}

LastCheckTime[__instance.PlayerId] = now;

bool hasHat = HasCosmetic(outfit.HatId);
bool hasSkin = HasCosmetic(outfit.SkinId);
bool hasVisor = HasCosmetic(outfit.VisorId);
bool hasPet = HasCosmetic(outfit.PetId);
bool hasNamePlate = HasCosmetic(outfit.NamePlateId);

if (!hasHat && !hasSkin && !hasVisor && !hasPet && !hasNamePlate)
return;

try
{
if (hasHat && !string.IsNullOrEmpty(HatData.EmptyId))
__instance.SetHat(HatData.EmptyId, outfit.ColorId);

if (hasSkin && !string.IsNullOrEmpty(SkinData.EmptyId))
__instance.SetSkin(SkinData.EmptyId, outfit.ColorId);

if (hasVisor && !string.IsNullOrEmpty(VisorData.EmptyId))
__instance.SetVisor(VisorData.EmptyId, outfit.ColorId);

if (hasNamePlate)
__instance.SetNamePlate("");

if (hasPet && !string.IsNullOrEmpty(PetData.EmptyId))
__instance.SetPet(PetData.EmptyId, outfit.ColorId);
}
catch
{
}
}
}

private static bool HasCosmetic(string id)
{
if (string.IsNullOrEmpty(id))
return false;

string missingId = NetworkedPlayerInfo.PlayerOutfit.MISSING_COSMETIC_ID;

if (!string.IsNullOrEmpty(missingId) && id == missingId)
return false;

return true;
}
}
[HarmonyPatch(typeof(PlayerPurchasesData), nameof(PlayerPurchasesData.GetPurchase))]
public static class UnlockCosmetics_PlayerPurchasesData_GetPurchase_Prefix
{
Expand Down