From 86e71d164cfbeb8f2d08f0600f3debaec183db40 Mon Sep 17 00:00:00 2001 From: Lordfirespeed <28568841+Lordfirespeed@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:26:51 +0000 Subject: [PATCH 1/2] to file-scoped namespaces --- MoreCompany/AudioMixerPatches.cs | 45 +- MoreCompany/Behaviors/SpinDragger.cs | 57 +- MoreCompany/ChatPatches.cs | 268 +++-- MoreCompany/Cosmetics/CosmeticApplication.cs | 157 ++- MoreCompany/Cosmetics/CosmeticInstance.cs | 67 +- MoreCompany/Cosmetics/CosmeticRegistry.cs | 283 +++-- MoreCompany/DebugCommandRegistry.cs | 139 ++- MoreCompany/EnemyAIPatches.cs | 1035 +++++++++--------- MoreCompany/HudPatches.cs | 841 +++++++------- MoreCompany/MainClass.cs | 569 +++++----- MoreCompany/ManualHarmonyPatches.cs | 11 +- MoreCompany/MimicPatches.cs | 51 +- MoreCompany/ReflectionUtils.cs | 73 +- MoreCompany/ShipTeleporterPatches.cs | 23 +- MoreCompany/SpectatePatches.cs | 47 +- MoreCompany/StartPatches.cs | 193 ++-- MoreCompany/TerminalStartDebugPatches.cs | 21 +- MoreCompany/Utils/AssemblyChecker.cs | 23 +- MoreCompany/Utils/BundleUtilities.cs | 55 +- MoreCompany/VersionPatches.cs | 255 +++-- 20 files changed, 2096 insertions(+), 2117 deletions(-) diff --git a/MoreCompany/AudioMixerPatches.cs b/MoreCompany/AudioMixerPatches.cs index 9496837..72dca1f 100644 --- a/MoreCompany/AudioMixerPatches.cs +++ b/MoreCompany/AudioMixerPatches.cs @@ -3,38 +3,37 @@ using UnityEngine; using UnityEngine.Audio; -namespace MoreCompany +namespace MoreCompany; + +[HarmonyPatch(typeof(AudioMixer), "SetFloat")] +public static class AudioMixerSetFloatPatch { - [HarmonyPatch(typeof(AudioMixer), "SetFloat")] - public static class AudioMixerSetFloatPatch + public static bool Prefix(string name, float value) { - public static bool Prefix(string name, float value) + if (name.StartsWith("PlayerVolume") || name.StartsWith("PlayerPitch")) { - if (name.StartsWith("PlayerVolume") || name.StartsWith("PlayerPitch")) - { - string cutName = name.Replace("PlayerVolume", "").Replace("PlayerPitch", ""); - int playerObjectNumber = int.Parse(cutName); + string cutName = name.Replace("PlayerVolume", "").Replace("PlayerPitch", ""); + int playerObjectNumber = int.Parse(cutName); - PlayerControllerB playerControllerB = StartOfRound.Instance.allPlayerScripts[playerObjectNumber]; - AudioSource voiceSource = playerControllerB.currentVoiceChatAudioSource; - if (playerControllerB != null && voiceSource) + PlayerControllerB playerControllerB = StartOfRound.Instance.allPlayerScripts[playerObjectNumber]; + AudioSource voiceSource = playerControllerB.currentVoiceChatAudioSource; + if (playerControllerB != null && voiceSource) + { + if (name.StartsWith("PlayerVolume")) { - if (name.StartsWith("PlayerVolume")) - { - voiceSource.volume = value/16; - } - else if (name.StartsWith("PlayerPitch")) - { - voiceSource.pitch = value; - } + voiceSource.volume = value/16; + } + else if (name.StartsWith("PlayerPitch")) + { + voiceSource.pitch = value; } - - return false; } - - return true; + + return false; } + + return true; } } \ No newline at end of file diff --git a/MoreCompany/Behaviors/SpinDragger.cs b/MoreCompany/Behaviors/SpinDragger.cs index 30dae44..2058757 100644 --- a/MoreCompany/Behaviors/SpinDragger.cs +++ b/MoreCompany/Behaviors/SpinDragger.cs @@ -5,43 +5,42 @@ using UnityEngine.InputSystem.Controls; using UnityEngine.UI; -namespace MoreCompany.Behaviors +namespace MoreCompany.Behaviors; + +public class SpinDragger : MonoBehaviour, IPointerDownHandler, IPointerUpHandler { - public class SpinDragger : MonoBehaviour, IPointerDownHandler, IPointerUpHandler - { - public float speed = 1f; - Vector2 lastMousePosition; - bool dragging = false; - Vector3 rotationalVelocity = Vector3.zero; - public float dragSpeed = 1f; - public float airDrag = 0.99f; - public GameObject target; + public float speed = 1f; + Vector2 lastMousePosition; + bool dragging = false; + Vector3 rotationalVelocity = Vector3.zero; + public float dragSpeed = 1f; + public float airDrag = 0.99f; + public GameObject target; - private void Update() + private void Update() + { + if (dragging) { - if (dragging) - { - Vector3 mouseDelta = Mouse.current.position.ReadValue() - lastMousePosition; - rotationalVelocity += new Vector3(0, -mouseDelta.x, 0) * dragSpeed; - lastMousePosition = Mouse.current.position.ReadValue(); - } + Vector3 mouseDelta = Mouse.current.position.ReadValue() - lastMousePosition; + rotationalVelocity += new Vector3(0, -mouseDelta.x, 0) * dragSpeed; + lastMousePosition = Mouse.current.position.ReadValue(); + } - rotationalVelocity *= airDrag; + rotationalVelocity *= airDrag; - target.transform.Rotate(rotationalVelocity * Time.deltaTime * speed, Space.World); - } + target.transform.Rotate(rotationalVelocity * Time.deltaTime * speed, Space.World); + } - public void OnPointerDown(PointerEventData eventData) - { - lastMousePosition = Mouse.current.position.ReadValue(); - dragging = true; - } + public void OnPointerDown(PointerEventData eventData) + { + lastMousePosition = Mouse.current.position.ReadValue(); + dragging = true; + } - public void OnPointerUp(PointerEventData eventData) - { - dragging = false; - } + public void OnPointerUp(PointerEventData eventData) + { + dragging = false; } } \ No newline at end of file diff --git a/MoreCompany/ChatPatches.cs b/MoreCompany/ChatPatches.cs index a4368f8..618caca 100644 --- a/MoreCompany/ChatPatches.cs +++ b/MoreCompany/ChatPatches.cs @@ -8,195 +8,193 @@ using Unity.Netcode; using UnityEngine; -namespace MoreCompany +namespace MoreCompany; + +[HarmonyPatch(typeof(HUDManager), "AddTextToChatOnServer")] +public static class SendChatToServerPatch { - - [HarmonyPatch(typeof(HUDManager), "AddTextToChatOnServer")] - public static class SendChatToServerPatch + public static bool Prefix(HUDManager __instance, string chatMessage, int playerId = -1) { - public static bool Prefix(HUDManager __instance, string chatMessage, int playerId = -1) + if (StartOfRound.Instance.IsHost) { - if (StartOfRound.Instance.IsHost) + // DEBUG COMMANDS + if (chatMessage.StartsWith("/mc") && DebugCommandRegistry.commandEnabled) { - // DEBUG COMMANDS - if (chatMessage.StartsWith("/mc") && DebugCommandRegistry.commandEnabled) - { - String command = chatMessage.Replace("/mc ", ""); - DebugCommandRegistry.HandleCommand(command.Split(' ')); - return false; - } - } - - if (chatMessage.StartsWith("[morecompanycosmetics]")) - { - ReflectionUtils.InvokeMethod(__instance, "AddPlayerChatMessageServerRpc", new object[] {chatMessage, 99}); + String command = chatMessage.Replace("/mc ", ""); + DebugCommandRegistry.HandleCommand(command.Split(' ')); return false; } - - return true; } + + if (chatMessage.StartsWith("[morecompanycosmetics]")) + { + ReflectionUtils.InvokeMethod(__instance, "AddPlayerChatMessageServerRpc", new object[] {chatMessage, 99}); + return false; + } + + return true; } +} - [HarmonyPatch(typeof(HUDManager), "AddPlayerChatMessageServerRpc")] - public static class ServerReceiveMessagePatch - { - public static string previousDataMessage = ""; +[HarmonyPatch(typeof(HUDManager), "AddPlayerChatMessageServerRpc")] +public static class ServerReceiveMessagePatch +{ + public static string previousDataMessage = ""; - public static bool Prefix(HUDManager __instance, ref string chatMessage, int playerId) + public static bool Prefix(HUDManager __instance, ref string chatMessage, int playerId) + { + NetworkManager networkManager = __instance.NetworkManager; + if (networkManager == null || !networkManager.IsListening) { - NetworkManager networkManager = __instance.NetworkManager; - if (networkManager == null || !networkManager.IsListening) - { - return false; - } + return false; + } - if (chatMessage.StartsWith("[morecompanycosmetics]") && networkManager.IsServer) - { - previousDataMessage = chatMessage; - chatMessage = "[replacewithdata]"; - } - - return true; + if (chatMessage.StartsWith("[morecompanycosmetics]") && networkManager.IsServer) + { + previousDataMessage = chatMessage; + chatMessage = "[replacewithdata]"; } + + return true; } +} - [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] - public static class ConnectClientToPlayerObjectPatch +[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] +public static class ConnectClientToPlayerObjectPatch +{ + public static void Postfix(PlayerControllerB __instance) { - public static void Postfix(PlayerControllerB __instance) + string built = "[morecompanycosmetics]"; + built += ";" + __instance.playerClientId; + foreach (var cosmetic in CosmeticRegistry.locallySelectedCosmetics) { - string built = "[morecompanycosmetics]"; - built += ";" + __instance.playerClientId; - foreach (var cosmetic in CosmeticRegistry.locallySelectedCosmetics) - { - built += ";" + cosmetic; - } - HUDManager.Instance.AddTextToChatOnServer(built); + built += ";" + cosmetic; } + HUDManager.Instance.AddTextToChatOnServer(built); } +} - [HarmonyPatch(typeof(HUDManager), "AddChatMessage")] - public static class AddChatMessagePatch +[HarmonyPatch(typeof(HUDManager), "AddChatMessage")] +public static class AddChatMessagePatch +{ + public static bool Prefix(HUDManager __instance, string chatMessage, string nameOfUserWhoTyped = "") { - public static bool Prefix(HUDManager __instance, string chatMessage, string nameOfUserWhoTyped = "") + if (chatMessage.StartsWith("[replacewithdata]") || chatMessage.StartsWith("[morecompanycosmetics]")) { - if (chatMessage.StartsWith("[replacewithdata]") || chatMessage.StartsWith("[morecompanycosmetics]")) - { - return false; - } - - return true; + return false; } + + return true; } +} - [HarmonyPatch(typeof(HUDManager), "AddPlayerChatMessageClientRpc")] - public static class ClientReceiveMessagePatch - { - public static bool ignoreSample = false; +[HarmonyPatch(typeof(HUDManager), "AddPlayerChatMessageClientRpc")] +public static class ClientReceiveMessagePatch +{ + public static bool ignoreSample = false; - public static bool Prefix(HUDManager __instance, ref string chatMessage, int playerId) + public static bool Prefix(HUDManager __instance, ref string chatMessage, int playerId) + { + NetworkManager networkManager = __instance.NetworkManager; + if (networkManager == null || !networkManager.IsListening) { - NetworkManager networkManager = __instance.NetworkManager; - if (networkManager == null || !networkManager.IsListening) - { - return false; - } + return false; + } - if (networkManager.IsServer) + if (networkManager.IsServer) + { + if (chatMessage.StartsWith("[replacewithdata]")) { - if (chatMessage.StartsWith("[replacewithdata]")) - { - chatMessage = ServerReceiveMessagePatch.previousDataMessage; - HandleDataMessage(chatMessage); - } - else if (chatMessage.StartsWith("[morecompanycosmetics]")) - { - // The server already handled this when the server branch was dealing with it. - return false; - } + chatMessage = ServerReceiveMessagePatch.previousDataMessage; + HandleDataMessage(chatMessage); } - else + else if (chatMessage.StartsWith("[morecompanycosmetics]")) { - if (chatMessage.StartsWith("[morecompanycosmetics]")) - { - HandleDataMessage(chatMessage); - } + // The server already handled this when the server branch was dealing with it. + return false; } - - return true; } - - private static void HandleDataMessage(string chatMessage) + else { - if (ignoreSample) + if (chatMessage.StartsWith("[morecompanycosmetics]")) { - return; + HandleDataMessage(chatMessage); } - chatMessage = chatMessage.Replace("[morecompanycosmetics]", ""); - string[] splitMessage = chatMessage.Split(';'); - string playerIdString = splitMessage[1]; + } - int playerIdNumeric = int.Parse(playerIdString); + return true; + } + + private static void HandleDataMessage(string chatMessage) + { + if (ignoreSample) + { + return; + } + chatMessage = chatMessage.Replace("[morecompanycosmetics]", ""); + string[] splitMessage = chatMessage.Split(';'); + string playerIdString = splitMessage[1]; + + int playerIdNumeric = int.Parse(playerIdString); - CosmeticApplication existingCosmeticApplication = StartOfRound.Instance.allPlayerScripts[playerIdNumeric].transform.Find("ScavengerModel") - .Find("metarig").gameObject.GetComponent(); + CosmeticApplication existingCosmeticApplication = StartOfRound.Instance.allPlayerScripts[playerIdNumeric].transform.Find("ScavengerModel") + .Find("metarig").gameObject.GetComponent(); - if (existingCosmeticApplication) - { - existingCosmeticApplication.ClearCosmetics(); - GameObject.Destroy(existingCosmeticApplication); - } + if (existingCosmeticApplication) + { + existingCosmeticApplication.ClearCosmetics(); + GameObject.Destroy(existingCosmeticApplication); + } - CosmeticApplication cosmeticApplication = StartOfRound.Instance.allPlayerScripts[playerIdNumeric].transform.Find("ScavengerModel") - .Find("metarig").gameObject.AddComponent(); + CosmeticApplication cosmeticApplication = StartOfRound.Instance.allPlayerScripts[playerIdNumeric].transform.Find("ScavengerModel") + .Find("metarig").gameObject.AddComponent(); - cosmeticApplication.ClearCosmetics(); + cosmeticApplication.ClearCosmetics(); - List cosmeticsToApply = new List(); + List cosmeticsToApply = new List(); - foreach (var cosmeticId in splitMessage) + foreach (var cosmeticId in splitMessage) + { + if (cosmeticId == playerIdString) { - if (cosmeticId == playerIdString) - { - continue; - } - cosmeticsToApply.Add(cosmeticId); - - if (MainClass.showCosmetics) - { - cosmeticApplication.ApplyCosmetic(cosmeticId, true); - } + continue; } - - if (playerIdNumeric == StartOfRound.Instance.thisClientPlayerId) + cosmeticsToApply.Add(cosmeticId); + + if (MainClass.showCosmetics) { - cosmeticApplication.ClearCosmetics(); + cosmeticApplication.ApplyCosmetic(cosmeticId, true); } + } - foreach (var cosmeticSpawned in cosmeticApplication.spawnedCosmetics) - { - cosmeticSpawned.transform.localScale *= CosmeticRegistry.COSMETIC_PLAYER_SCALE_MULT; - } + if (playerIdNumeric == StartOfRound.Instance.thisClientPlayerId) + { + cosmeticApplication.ClearCosmetics(); + } + + foreach (var cosmeticSpawned in cosmeticApplication.spawnedCosmetics) + { + cosmeticSpawned.transform.localScale *= CosmeticRegistry.COSMETIC_PLAYER_SCALE_MULT; + } - MainClass.playerIdsAndCosmetics.Remove(playerIdNumeric); - MainClass.playerIdsAndCosmetics.Add(playerIdNumeric, cosmeticsToApply); + MainClass.playerIdsAndCosmetics.Remove(playerIdNumeric); + MainClass.playerIdsAndCosmetics.Add(playerIdNumeric, cosmeticsToApply); - if (GameNetworkManager.Instance.isHostingGame && (playerIdNumeric != 0)) + if (GameNetworkManager.Instance.isHostingGame && (playerIdNumeric != 0)) + { + ignoreSample = true; + foreach (var keyPair in MainClass.playerIdsAndCosmetics) { - ignoreSample = true; - foreach (var keyPair in MainClass.playerIdsAndCosmetics) + string built = "[morecompanycosmetics]"; + built += ";" + keyPair.Key; + foreach (var cosmetic in keyPair.Value) { - string built = "[morecompanycosmetics]"; - built += ";" + keyPair.Key; - foreach (var cosmetic in keyPair.Value) - { - built += ";" + cosmetic; - } - HUDManager.Instance.AddTextToChatOnServer(built); + built += ";" + cosmetic; } - - ignoreSample = false; + HUDManager.Instance.AddTextToChatOnServer(built); } + + ignoreSample = false; } } } \ No newline at end of file diff --git a/MoreCompany/Cosmetics/CosmeticApplication.cs b/MoreCompany/Cosmetics/CosmeticApplication.cs index 226784d..ea35ce7 100644 --- a/MoreCompany/Cosmetics/CosmeticApplication.cs +++ b/MoreCompany/Cosmetics/CosmeticApplication.cs @@ -2,107 +2,106 @@ using System.Collections.Generic; using UnityEngine; -namespace MoreCompany.Cosmetics +namespace MoreCompany.Cosmetics; + +public class CosmeticApplication : MonoBehaviour { - public class CosmeticApplication : MonoBehaviour - { - public Transform head; - public Transform hip; - public Transform lowerArmRight; - public Transform shinLeft; - public Transform shinRight; - public Transform chest; - public List spawnedCosmetics = new List(); + public Transform head; + public Transform hip; + public Transform lowerArmRight; + public Transform shinLeft; + public Transform shinRight; + public Transform chest; + public List spawnedCosmetics = new List(); - public void Awake() - { - head = transform.Find("spine").Find("spine.001").Find("spine.002").Find("spine.003").Find("spine.004"); - chest = transform.Find("spine").Find("spine.001").Find("spine.002").Find("spine.003"); - lowerArmRight = transform.Find("spine").Find("spine.001").Find("spine.002").Find("spine.003").Find("shoulder.R").Find("arm.R_upper").Find("arm.R_lower"); - hip = transform.Find("spine"); - shinLeft = transform.Find("spine").Find("thigh.L").Find("shin.L"); - shinRight = transform.Find("spine").Find("thigh.R").Find("shin.R"); + public void Awake() + { + head = transform.Find("spine").Find("spine.001").Find("spine.002").Find("spine.003").Find("spine.004"); + chest = transform.Find("spine").Find("spine.001").Find("spine.002").Find("spine.003"); + lowerArmRight = transform.Find("spine").Find("spine.001").Find("spine.002").Find("spine.003").Find("shoulder.R").Find("arm.R_upper").Find("arm.R_lower"); + hip = transform.Find("spine"); + shinLeft = transform.Find("spine").Find("thigh.L").Find("shin.L"); + shinRight = transform.Find("spine").Find("thigh.R").Find("shin.R"); - RefreshAllCosmeticPositions(); - } + RefreshAllCosmeticPositions(); + } - private void OnDisable() + private void OnDisable() + { + foreach (var spawnedCosmetic in spawnedCosmetics) { - foreach (var spawnedCosmetic in spawnedCosmetics) - { - spawnedCosmetic.gameObject.SetActive(false); - } + spawnedCosmetic.gameObject.SetActive(false); } + } - private void OnEnable() + private void OnEnable() + { + foreach (var spawnedCosmetic in spawnedCosmetics) { - foreach (var spawnedCosmetic in spawnedCosmetics) - { - spawnedCosmetic.gameObject.SetActive(true); - } + spawnedCosmetic.gameObject.SetActive(true); } + } - public void ClearCosmetics() + public void ClearCosmetics() + { + foreach (var spawnedCosmetic in spawnedCosmetics) { - foreach (var spawnedCosmetic in spawnedCosmetics) - { - GameObject.Destroy(spawnedCosmetic.gameObject); - } - spawnedCosmetics.Clear(); + GameObject.Destroy(spawnedCosmetic.gameObject); } + spawnedCosmetics.Clear(); + } - public void ApplyCosmetic(string cosmeticId, bool startEnabled) + public void ApplyCosmetic(string cosmeticId, bool startEnabled) + { + if (CosmeticRegistry.cosmeticInstances.ContainsKey(cosmeticId)) { - if (CosmeticRegistry.cosmeticInstances.ContainsKey(cosmeticId)) + CosmeticInstance cosmeticInstance = CosmeticRegistry.cosmeticInstances[cosmeticId]; + GameObject cosmeticInstanceGameObject = GameObject.Instantiate(cosmeticInstance.gameObject); + cosmeticInstanceGameObject.SetActive(startEnabled); + CosmeticInstance cosmeticInstanceBehavior = cosmeticInstanceGameObject.GetComponent(); + spawnedCosmetics.Add(cosmeticInstanceBehavior); + if (startEnabled) { - CosmeticInstance cosmeticInstance = CosmeticRegistry.cosmeticInstances[cosmeticId]; - GameObject cosmeticInstanceGameObject = GameObject.Instantiate(cosmeticInstance.gameObject); - cosmeticInstanceGameObject.SetActive(startEnabled); - CosmeticInstance cosmeticInstanceBehavior = cosmeticInstanceGameObject.GetComponent(); - spawnedCosmetics.Add(cosmeticInstanceBehavior); - if (startEnabled) - { - ParentCosmetic(cosmeticInstanceBehavior); - } + ParentCosmetic(cosmeticInstanceBehavior); } } + } - public void RefreshAllCosmeticPositions() + public void RefreshAllCosmeticPositions() + { + foreach (var spawnedCosmetic in spawnedCosmetics) { - foreach (var spawnedCosmetic in spawnedCosmetics) - { - ParentCosmetic(spawnedCosmetic); - } + ParentCosmetic(spawnedCosmetic); } + } - private void ParentCosmetic(CosmeticInstance cosmeticInstance) + private void ParentCosmetic(CosmeticInstance cosmeticInstance) + { + Transform targetTransform = null; + switch (cosmeticInstance.cosmeticType) { - Transform targetTransform = null; - switch (cosmeticInstance.cosmeticType) - { - case CosmeticType.HAT: - targetTransform = head; - break; - case CosmeticType.R_LOWER_ARM: - targetTransform = lowerArmRight; - break; - case CosmeticType.HIP: - targetTransform = hip; - break; - case CosmeticType.L_SHIN: - targetTransform = shinLeft; - break; - case CosmeticType.R_SHIN: - targetTransform = shinRight; - break; - case CosmeticType.CHEST: - targetTransform = chest; - break; - } - - cosmeticInstance.transform.position = targetTransform.position; - cosmeticInstance.transform.rotation = targetTransform.rotation; - cosmeticInstance.transform.parent = targetTransform; + case CosmeticType.HAT: + targetTransform = head; + break; + case CosmeticType.R_LOWER_ARM: + targetTransform = lowerArmRight; + break; + case CosmeticType.HIP: + targetTransform = hip; + break; + case CosmeticType.L_SHIN: + targetTransform = shinLeft; + break; + case CosmeticType.R_SHIN: + targetTransform = shinRight; + break; + case CosmeticType.CHEST: + targetTransform = chest; + break; } + + cosmeticInstance.transform.position = targetTransform.position; + cosmeticInstance.transform.rotation = targetTransform.rotation; + cosmeticInstance.transform.parent = targetTransform; } } \ No newline at end of file diff --git a/MoreCompany/Cosmetics/CosmeticInstance.cs b/MoreCompany/Cosmetics/CosmeticInstance.cs index 3d49aa8..20c635a 100644 --- a/MoreCompany/Cosmetics/CosmeticInstance.cs +++ b/MoreCompany/Cosmetics/CosmeticInstance.cs @@ -1,45 +1,44 @@ using MoreCompany.Utils; using UnityEngine; -namespace MoreCompany.Cosmetics +namespace MoreCompany.Cosmetics; + +public class CosmeticInstance : MonoBehaviour { - public class CosmeticInstance : MonoBehaviour - { - public CosmeticType cosmeticType; - public string cosmeticId; - public Texture2D icon; - } + public CosmeticType cosmeticType; + public string cosmeticId; + public Texture2D icon; +} - public class CosmeticGeneric - { - public virtual string gameObjectPath { get; } - public virtual string cosmeticId { get;} - public virtual string textureIconPath { get; } - public CosmeticType cosmeticType { get; } +public class CosmeticGeneric +{ + public virtual string gameObjectPath { get; } + public virtual string cosmeticId { get;} + public virtual string textureIconPath { get; } + public CosmeticType cosmeticType { get; } - public void LoadFromBundle(AssetBundle bundle) - { - GameObject cosmeticInstance = bundle.LoadPersistentAsset(gameObjectPath); - Texture2D icon = bundle.LoadPersistentAsset(textureIconPath); + public void LoadFromBundle(AssetBundle bundle) + { + GameObject cosmeticInstance = bundle.LoadPersistentAsset(gameObjectPath); + Texture2D icon = bundle.LoadPersistentAsset(textureIconPath); - CosmeticInstance cosmeticInstanceBehavior = cosmeticInstance.AddComponent(); - cosmeticInstanceBehavior.cosmeticId = cosmeticId; - cosmeticInstanceBehavior.icon = icon; - cosmeticInstanceBehavior.cosmeticType = cosmeticType; + CosmeticInstance cosmeticInstanceBehavior = cosmeticInstance.AddComponent(); + cosmeticInstanceBehavior.cosmeticId = cosmeticId; + cosmeticInstanceBehavior.icon = icon; + cosmeticInstanceBehavior.cosmeticType = cosmeticType; - MainClass.StaticLogger.LogInfo("Loaded cosmetic: " + cosmeticId + " from bundle: " + bundle.name); - CosmeticRegistry.cosmeticInstances.Add(cosmeticId, cosmeticInstanceBehavior); - } + MainClass.StaticLogger.LogInfo("Loaded cosmetic: " + cosmeticId + " from bundle: " + bundle.name); + CosmeticRegistry.cosmeticInstances.Add(cosmeticId, cosmeticInstanceBehavior); } +} - public enum CosmeticType - { - HAT, - WRIST, - CHEST, - R_LOWER_ARM, - HIP, - L_SHIN, - R_SHIN - } +public enum CosmeticType +{ + HAT, + WRIST, + CHEST, + R_LOWER_ARM, + HIP, + L_SHIN, + R_SHIN } \ No newline at end of file diff --git a/MoreCompany/Cosmetics/CosmeticRegistry.cs b/MoreCompany/Cosmetics/CosmeticRegistry.cs index 504bd0a..1d10413 100644 --- a/MoreCompany/Cosmetics/CosmeticRegistry.cs +++ b/MoreCompany/Cosmetics/CosmeticRegistry.cs @@ -4,122 +4,140 @@ using UnityEngine; using UnityEngine.UI; -namespace MoreCompany.Cosmetics +namespace MoreCompany.Cosmetics; + +public class CosmeticRegistry { - public class CosmeticRegistry - { - public static Dictionary cosmeticInstances = new Dictionary(); + public static Dictionary cosmeticInstances = new Dictionary(); - public static GameObject cosmeticGUI; - private static GameObject displayGuy; - private static CosmeticApplication cosmeticApplication; - public static List locallySelectedCosmetics = new List(); + public static GameObject cosmeticGUI; + private static GameObject displayGuy; + private static CosmeticApplication cosmeticApplication; + public static List locallySelectedCosmetics = new List(); - public const float COSMETIC_PLAYER_SCALE_MULT = 0.38f; + public const float COSMETIC_PLAYER_SCALE_MULT = 0.38f; - public static void LoadCosmeticsFromBundle(AssetBundle bundle) + public static void LoadCosmeticsFromBundle(AssetBundle bundle) + { + foreach (var potentialPrefab in bundle.GetAllAssetNames()) { - foreach (var potentialPrefab in bundle.GetAllAssetNames()) + if (!potentialPrefab.EndsWith(".prefab")) { - if (!potentialPrefab.EndsWith(".prefab")) - { - continue; - } - GameObject cosmeticInstance = bundle.LoadPersistentAsset(potentialPrefab); - CosmeticInstance cosmeticInstanceBehavior = cosmeticInstance.GetComponent(); - if (cosmeticInstanceBehavior == null) - { - continue; - } - MainClass.StaticLogger.LogInfo("Loaded cosmetic: " + cosmeticInstanceBehavior.cosmeticId + " from bundle"); - if (cosmeticInstances.ContainsKey(cosmeticInstanceBehavior.cosmeticId)) - { - MainClass.StaticLogger.LogError("Duplicate cosmetic id: " + cosmeticInstanceBehavior.cosmeticId); - continue; - } - - cosmeticInstances.Add(cosmeticInstanceBehavior.cosmeticId, cosmeticInstanceBehavior); + continue; + } + GameObject cosmeticInstance = bundle.LoadPersistentAsset(potentialPrefab); + CosmeticInstance cosmeticInstanceBehavior = cosmeticInstance.GetComponent(); + if (cosmeticInstanceBehavior == null) + { + continue; } + MainClass.StaticLogger.LogInfo("Loaded cosmetic: " + cosmeticInstanceBehavior.cosmeticId + " from bundle"); + if (cosmeticInstances.ContainsKey(cosmeticInstanceBehavior.cosmeticId)) + { + MainClass.StaticLogger.LogError("Duplicate cosmetic id: " + cosmeticInstanceBehavior.cosmeticId); + continue; + } + + cosmeticInstances.Add(cosmeticInstanceBehavior.cosmeticId, cosmeticInstanceBehavior); } + } - public static void LoadCosmeticsFromAssembly(Assembly assembly, AssetBundle bundle) + public static void LoadCosmeticsFromAssembly(Assembly assembly, AssetBundle bundle) + { + foreach (var type in assembly.GetTypes()) { - foreach (var type in assembly.GetTypes()) + if (type.IsSubclassOf(typeof(CosmeticGeneric))) { - if (type.IsSubclassOf(typeof(CosmeticGeneric))) - { - CosmeticGeneric cosmeticGeneric = (CosmeticGeneric) type.GetConstructor(new System.Type[] { }).Invoke(new object[] { }); - cosmeticGeneric.LoadFromBundle(bundle); - } + CosmeticGeneric cosmeticGeneric = (CosmeticGeneric) type.GetConstructor(new System.Type[] { }).Invoke(new object[] { }); + cosmeticGeneric.LoadFromBundle(bundle); } } + } - public static void SpawnCosmeticGUI() - { - cosmeticGUI = GameObject.Instantiate(MainClass.cosmeticGUIInstance); - cosmeticGUI.transform.Find("Canvas").Find("GlobalScale").transform.localScale = new Vector3(2, 2, 2); + public static void SpawnCosmeticGUI() + { + cosmeticGUI = GameObject.Instantiate(MainClass.cosmeticGUIInstance); + cosmeticGUI.transform.Find("Canvas").Find("GlobalScale").transform.localScale = new Vector3(2, 2, 2); - displayGuy = cosmeticGUI.transform.Find("Canvas").Find("GlobalScale").Find("CosmeticsScreen").Find("ObjectHolder") - .Find("ScavengerModel").Find("metarig").gameObject; + displayGuy = cosmeticGUI.transform.Find("Canvas").Find("GlobalScale").Find("CosmeticsScreen").Find("ObjectHolder") + .Find("ScavengerModel").Find("metarig").gameObject; - cosmeticApplication = displayGuy.AddComponent(); + cosmeticApplication = displayGuy.AddComponent(); - GameObject enableCosmeticsButton = cosmeticGUI.transform.Find("Canvas").Find("GlobalScale").Find("CosmeticsScreen").Find("EnableButton").gameObject; - enableCosmeticsButton.GetComponent