Decompiled source of LTOWMySimsCharacterPackMod v1.0.0

LTOWMySimsCharacterPackMod.dll

Decompiled 2 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
internal class <Module>
{
	static <Module>()
	{
	}
}
[CreateAssetMenu(menuName = "LTOWMySimsCharacterPackMod/AllAssets", order = 0)]
public class AllAssets : ScriptableObject
{
	[HideInInspector]
	public CharacterData[] allCharacterData;

	[Header("Netcode")]
	public GameObject networkHandler;

	public GameObject[] allNetworkPrefabs;

	[Header("Prefabs")]
	public GameObject simsSelectionUI;

	public GameObject plumbobPrefab;

	[Header("CharacterData")]
	public CharacterData noneSimData;

	public CharacterData sirCharlesSimData;

	public CharacterData cassandraSimData;
}
[CreateAssetMenu(menuName = "LTOWMySimsCharacterPackMod/CharacterData", order = 1)]
public class CharacterData : ScriptableObject
{
	public string characterName;

	public string outfitPostfix;

	[Header("Visuals")]
	public Mesh meshHead;

	public Mesh meshBody;

	[Space]
	public Material[] materialsHead = (Material[])(object)new Material[2];

	public Material materialBody;

	[Space(3f)]
	[Header("SFX")]
	public AudioClip[] sfxHurt = (AudioClip[])(object)new AudioClip[1];

	public AudioClip[] sfxDeath = (AudioClip[])(object)new AudioClip[1];

	[Space(3f)]
	[Header("Misc")]
	public bool silentSim;

	public bool notSelectable;
}
public class Configs
{
	private static ManualLogSource Logger;

	public static ConfigEntry<bool> voiceClipsMySims;

	public static ConfigEntry<bool> facialFeaturesAccessories;

	public static ConfigEntry<bool> headSeeThrough;

	public static ConfigEntry<bool> bodySeeThrough;

	public static ConfigEntry<bool> multiplayerSyncing;

	public static ConfigEntry<bool> saveData;

	public static ConfigEntry<bool> secretPlumbob;

	public static ConfigEntry<int> secretSirCharles;

	public static ConfigEntry<int> secretCassandra;

	public Configs(ConfigFile cfg)
	{
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Expected O, but got Unknown
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Expected O, but got Unknown
		voiceClipsMySims = cfg.Bind<bool>("Customization", "MySims Voice Clips", true, "Set whether or not pardners' yells will be replaced by voice clips of the selected MySims characters.");
		facialFeaturesAccessories = cfg.Bind<bool>("Customization", "Accessories Includes Face", false, "Set whether the in-game 'Show Accessories' button also toggles your pardner's eyes, eyebrows, and noses, or if it always hides them and only affects hats and moustaches.");
		headSeeThrough = cfg.Bind<bool>("Customization", "Zoomed-In Transparent Head", true, "Set whether or not your selected MySims model's head will turn partially see-through when the camera is zoomed in, for example while aiming, to allow better vision.");
		bodySeeThrough = cfg.Bind<bool>("Customization", "Zoomed-In Transparent Body", false, "Set whether or not your selected MySims model's body will turn partially see-through when the camera is zoomed in, for example while aiming, to allow better vision.");
		multiplayerSyncing = cfg.Bind<bool>("Data", "Synchronize in Multiplayer", false, "Set whether or not people will be able to see each other's selected MySims character models.\nIMPORTANT: If this config is set to true on the lobby host, the entire lobby must have this mod and this config set to true! Likewise, if this setting is false on the host, people who have it set to true cannot join that host's lobby.");
		saveData = cfg.Bind<bool>("Data", "Save and Load", true, "Set whether or not the MySims character you're playing as will be saved and loaded next time you open the game, and if MySims characters can be saved to and loaded from the Customize menu's save files.");
		secretPlumbob = cfg.Bind<bool>("Secret", "Selectable Objects", false, "Add a classic selection indicator.");
		secretSirCharles = cfg.Bind<int>("Secret", "Balloon Pilot", 10, new ConfigDescription("Chance to kick Ed out of business.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		secretCassandra = cfg.Bind<int>("Secret", "Ghost", 1, new ConfigDescription("Chance to get possessed by a different ghost.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
	}

	public static void DisplayConfigs()
	{
		if (FriendsPassCheck(configHasMultiplayerSyncFeatures: true))
		{
			if (voiceClipsMySims.Value)
			{
				Logger.LogInfo((object)"Config [MySims Voice Clips] is set to TRUE. MySims characters will replace the default pardner screams with MySims voice clips.");
			}
			else
			{
				Logger.LogInfo((object)"Config [MySims Voice Clips] is set to FALSE. The default pardner screams will play.");
			}
		}
		if (FriendsPassCheck())
		{
			if (facialFeaturesAccessories.Value)
			{
				Logger.LogInfo((object)"Config [Accessories Includes Face] is set to TRUE. Eyes, eyebrows, and noses will also be displayed on MySims characters if 'Show Accessories' is turned on.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Accessories Includes Face] is set to FALSE. Only moustaches and hats will be toggled by the in-game 'Show Accessories' button on the MySims selection.");
			}
			if (headSeeThrough.Value)
			{
				Logger.LogInfo((object)"Config [Zoomed-In Transparent Head] is set to TRUE. When playing with a MySims character, the character's head will turn see-through when zoomed-in, to allow better vision.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Zoomed-In Transparent Head] is set to FALSE. MySims characters' heads will always stay fully opaque.");
			}
			if (bodySeeThrough.Value)
			{
				Logger.LogInfo((object)"Config [Zoomed-In Transparent Body] is set to TRUE. When playing with a MySims character, the character's body will turn see-through when zoomed-in, to allow better vision.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Zoomed-In Transparent Body] is set to FALSE. MySims characters' bodies will always stay fully opaque.");
			}
		}
		if (multiplayerSyncing.Value)
		{
			Logger.LogInfo((object)"Config [Synchronize in Multiplayer] is set to TRUE. People will be able to see each other's Sims, but everyone must have this mod and setting enabled to join the lobby.");
		}
		else if (FriendsPassCheck(configHasMultiplayerSyncFeatures: true))
		{
			Logger.LogInfo((object)"Config [Synchronize in Multiplayer] is set to FALSE. Your selected Sim will only be visible locally, but you can play together people who aren't playing with this mod.");
		}
		if (FriendsPassCheck())
		{
			if (saveData.Value)
			{
				Logger.LogInfo((object)"Config [Save and Load] is set to TRUE. Your last MySims character will be loaded, and you will be able to save MySims characters to the Customize menu's save files.");
			}
			else
			{
				Logger.LogInfo((object)"Config [Save and Load] is set to FALSE. Your selected MySims character will only stay loaded for the duration of this play session.");
			}
		}
		if (secretPlumbob.Value)
		{
			Logger.LogDebug((object)"Config [Selectable Objects] is set to TRUE. Sul sul!");
		}
		if (secretSirCharles.Value > 0)
		{
			string empty = string.Empty;
			empty = ((secretSirCharles.Value >= 100) ? "And when Speedvi- I mean, Wormtown needed him the most, he returned..." : ((secretSirCharles.Value >= 75) ? "Talk about a comeback..." : ((secretSirCharles.Value >= 50) ? "Huh, he's actually getting the hang of it..." : ((secretSirCharles.Value < 25) ? "I thought he crashed last time..." : "I think he's more proficient with go-karts than with hot air balloons..."))));
			Logger.LogDebug((object)$"Config [Balloon Pilot] is set to a value of {secretSirCharles.Value}. {empty}");
		}
		if (secretCassandra.Value > 0 && FriendsPassCheck())
		{
			string empty2 = string.Empty;
			empty2 = ((secretCassandra.Value >= 100) ? "I always pick the Be Nice option whenever I see her around town." : ((secretCassandra.Value >= 75) ? "Wow, there's a full house on tonight's séance." : ((secretCassandra.Value >= 50) ? "A lot of spooky Sims are moving into town lately." : ((secretCassandra.Value < 25) ? "Looks like Violet is holding another séance by herself." : "Of course Goth Boy would attend the séances too."))));
			Logger.LogDebug((object)$"Config [Ghost] is set to a value of {secretCassandra.Value}. {empty2}");
		}
	}

	private static bool FriendsPassCheck(bool configHasMultiplayerSyncFeatures = false)
	{
		if (!FriendsPassManager.isFriendsPassVersion)
		{
			return true;
		}
		if (configHasMultiplayerSyncFeatures)
		{
			return multiplayerSyncing.Value;
		}
		return false;
	}
}
public class General
{
	private static ManualLogSource Logger;

	private static int simsClipsPlayed;

	public static InGameHumanCosmeticBuilder SwitchCosmeticsFromPlayerToDummy(InGameHumanCosmeticBuilder cosmetics)
	{
		if (!Object.op_Implicit((Object)(object)cosmetics))
		{
			Logger.LogDebug((object)"I");
			return null;
		}
		bool privateField = cosmetics.GetPrivateField<bool>("isDummy");
		ulong num = 1000000uL;
		if (privateField)
		{
			DummySyncDataHolder component = ((Component)cosmetics).GetComponent<DummySyncDataHolder>();
			if (Object.op_Implicit((Object)(object)component) && component.associatedPlayerID.Value != 1000000)
			{
				num = component.associatedPlayerID.Value;
			}
		}
		else if (((NetworkBehaviour)cosmetics).OwnerClientId != 1000000)
		{
			num = ((NetworkBehaviour)cosmetics).OwnerClientId;
		}
		if (num == 1000000)
		{
			Logger.LogDebug((object)"II");
			return cosmetics;
		}
		InGameHumanCosmeticBuilder[] array = Object.FindObjectsByType<InGameHumanCosmeticBuilder>((FindObjectsSortMode)0);
		if (array == null || array.Length == 0)
		{
			Logger.LogDebug((object)"III");
			return cosmetics;
		}
		InGameHumanCosmeticBuilder val = null;
		foreach (InGameHumanCosmeticBuilder val2 in array)
		{
			if (!Object.op_Implicit((Object)(object)val2))
			{
				continue;
			}
			bool privateField2 = val2.GetPrivateField<bool>("isDummy");
			if (privateField2 == privateField)
			{
				continue;
			}
			ulong num2 = 1000000uL;
			if (privateField2)
			{
				DummySyncDataHolder component2 = ((Component)val2).GetComponent<DummySyncDataHolder>();
				if (Object.op_Implicit((Object)(object)component2) && component2.associatedPlayerID.Value != 1000000)
				{
					num2 = component2.associatedPlayerID.Value;
				}
			}
			else if (((NetworkBehaviour)val2).OwnerClientId != 1000000)
			{
				num2 = ((NetworkBehaviour)val2).OwnerClientId;
			}
			if (num2 == num)
			{
				val = val2;
				break;
			}
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			Logger.LogDebug((object)"IV");
			return cosmetics;
		}
		Logger.LogDebug((object)$"SwitchCosmeticsFromPlayerToDummy(): {cosmetics} #{((NetworkBehaviour)cosmetics).NetworkObjectId} RETURNING {val} #{((NetworkBehaviour)val).NetworkObjectId}");
		return val;
	}

	public static CharacterData GetSim(int usingID)
	{
		if (ValidID(usingID, includeLength: false))
		{
			return Plugin.allAssets.allCharacterData[usingID];
		}
		return null;
	}

	public static CharacterData GetSpecialSim(int specialCase)
	{
		return specialCase switch
		{
			0 => Plugin.allAssets.sirCharlesSimData, 
			1 => Plugin.allAssets.cassandraSimData, 
			_ => null, 
		};
	}

	public static int DataLength()
	{
		if ((Object)(object)Plugin.allAssets == (Object)null || Plugin.allAssets.allCharacterData == null)
		{
			return 0;
		}
		return Plugin.allAssets.allCharacterData.Length;
	}

	public static bool ValidID(int localID, bool includeLength = true)
	{
		if (!includeLength)
		{
			if (localID >= 0)
			{
				return localID < DataLength();
			}
			return false;
		}
		if (localID >= 0)
		{
			return localID <= DataLength();
		}
		return false;
	}

	public static bool CanLoadOrSave()
	{
		if (!FriendsPassManager.isFriendsPassVersion)
		{
			return Configs.saveData.Value;
		}
		return false;
	}

	public static bool IsLoadedSaveEmpty(int _slotNumber)
	{
		if (File.Exists(Application.persistentDataPath + "/CloudSave/PardnerCustomization" + _slotNumber + ".json"))
		{
			return false;
		}
		if (_slotNumber > 0 && _slotNumber < MySimsCharacterManager.savedSelectedSims.Length && !string.IsNullOrEmpty(MySimsCharacterManager.savedSelectedSims[_slotNumber]))
		{
			return false;
		}
		return true;
	}

	public static void ResetToDefaults()
	{
		MySimsCharacterManager.SetNewLocalID(0);
		UISelectionScript.accessoriesVisible = false;
		if (Object.op_Implicit((Object)(object)UISelectionScript.Singleton))
		{
			UISelectionScript.Singleton.OnValueChanged_AccessoriesVisible();
		}
	}

	public static void RandomizeSim()
	{
		if (FriendsPassManager.isFriendsPassVersion)
		{
			return;
		}
		int num = 3;
		bool flag = ((Random.Range(0, num) == 0) ? true : false);
		Logger.LogDebug((object)$"doRandom? {flag}");
		if (flag)
		{
			int num2 = Random.Range(0, DataLength());
			bool flag2 = ((Random.Range(0, num) != 0) ? true : false);
			Logger.LogDebug((object)$"randomSimID = {num2} && randomAccVisibility = {flag2}");
			MySimsCharacterManager.SetNewLocalID(num2);
			UISelectionScript.accessoriesVisible = flag2;
			if (Object.op_Implicit((Object)(object)UISelectionScript.Singleton))
			{
				UISelectionScript.Singleton.OnValueChanged_AccessoriesVisible();
			}
		}
		else
		{
			ResetToDefaults();
		}
	}

	public static bool ShouldShowSim(CharacterData cData)
	{
		if (!Object.op_Implicit((Object)(object)cData) || (Object)(object)cData == (Object)(object)Plugin.allAssets.noneSimData)
		{
			return false;
		}
		return true;
	}

	public static bool ShouldShowSim(int simID)
	{
		return ShouldShowSim(GetSim(simID));
	}

	public static bool ShouldShowFace(CharacterData cData, bool accVisibility, bool accIncludesFacial)
	{
		if (!ShouldShowSim(cData))
		{
			return true;
		}
		if (accVisibility && accIncludesFacial)
		{
			return true;
		}
		return false;
	}

	public static bool ShouldShowAccessories(CharacterData cData, bool accVisibility)
	{
		if (!ShouldShowSim(cData))
		{
			return true;
		}
		if (accVisibility)
		{
			return true;
		}
		return false;
	}

	public static void PlayMySimsVoiceClip(AudioSource audioSource, AudioClip[] clipsArray, bool fromMultiplayer = false)
	{
		if (!((Object)(object)audioSource == (Object)null) && clipsArray != null && clipsArray.Length != 0)
		{
			AudioClip val = null;
			val = ((clipsArray.Length == 1) ? clipsArray[0] : ((!Object.op_Implicit((Object)(object)MapLayoutPrefabLoader.Singleton)) ? clipsArray[Random.Range(0, clipsArray.Length)] : clipsArray[new Random(MapLayoutPrefabLoader.Singleton.mapLayoutIndexChosenByServer + simsClipsPlayed).Next(0, clipsArray.Length)]));
			Logger.LogDebug((object)string.Format("{0}-player successfully playing '{1}'", fromMultiplayer ? "MULTI" : "SINGLE", val));
			audioSource.PlayOneShot(val, AudioManager.Singleton.sfxVolume);
			SetSimsClipsPlayed();
		}
	}

	public static void SetSimsClipsPlayed(int setTo = -1)
	{
		if (setTo == -1)
		{
			simsClipsPlayed++;
		}
		else
		{
			simsClipsPlayed = setTo;
		}
		Logger.LogDebug((object)$"simsClipsPlayed: {simsClipsPlayed}");
	}
}
public class HarmonyPatches
{
	[HarmonyPatch(typeof(NetworkManager))]
	public class MySimsNetworkManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SetSingleton")]
		public static void SetSingletonPostfix()
		{
			if (!Configs.multiplayerSyncing.Value)
			{
				return;
			}
			Logger.LogDebug((object)$"SetSingleton() on {NetworkManager.Singleton}");
			for (int i = 0; i < Plugin.allAssets.allNetworkPrefabs.Length; i++)
			{
				GameObject val = Plugin.allAssets.allNetworkPrefabs[i];
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.GetComponentInChildren<NetworkObject>()))
				{
					Logger.LogDebug((object)$"registering [{i}]: {val}");
					NetworkManager.Singleton.AddNetworkPrefab(val);
				}
			}
		}
	}

	[HarmonyPatch(typeof(GameManager))]
	public class MySimsgameManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("OnNetworkSpawn")]
		public static void OnNetworkSpawnPostfix(GameManager __instance)
		{
			if (Configs.multiplayerSyncing.Value && ((NetworkBehaviour)__instance).IsServer)
			{
				GameObject networkHandler = Plugin.allAssets.networkHandler;
				if (!Object.op_Implicit((Object)(object)networkHandler))
				{
					Logger.LogError((object)"failed to load NetworkHandler");
				}
				else
				{
					Object.Instantiate<GameObject>(networkHandler, ((Component)__instance).transform).GetComponent<NetworkObject>().Spawn(false);
				}
			}
		}
	}

	[HarmonyPatch(typeof(InGameHumanCosmeticBuilder))]
	public class MySimsInGameHumanCosmeticBuilderPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("CreateCosmetics")]
		public static void CreateCosmeticsPostfix(InGameHumanCosmeticBuilder __instance)
		{
			if (!Object.op_Implicit((Object)(object)__instance))
			{
				return;
			}
			if (!__instance.GetPrivateField<bool>("isDummy"))
			{
				if (((NetworkBehaviour)__instance).IsOwner)
				{
					int localID = MySimsCharacterManager.GetLocalID();
					if (General.ValidID(localID))
					{
						if (General.ShouldShowSim(localID))
						{
							MySimsCharacterManager.SetMySimsModel(__instance);
						}
						if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
						{
							MySimsNetworkHandler.Singleton.AddSimIdWithNewlySpawnedCosmetics(__instance);
						}
					}
				}
				else if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
				{
					MySimsNetworkHandler.Singleton.GetSimOfPlayer(__instance, askServer: false);
				}
				return;
			}
			DummySyncDataHolder component = ((Component)__instance).GetComponent<DummySyncDataHolder>();
			if (!Object.op_Implicit((Object)(object)component) || component.associatedPlayerID.Value == 1000000 || !Object.op_Implicit((Object)(object)NetworkManager.Singleton))
			{
				return;
			}
			if (component.associatedPlayerID.Value == NetworkManager.Singleton.LocalClientId)
			{
				int localID2 = MySimsCharacterManager.GetLocalID();
				if (General.ValidID(localID2))
				{
					if (General.ShouldShowSim(localID2))
					{
						MySimsCharacterManager.SetMySimsModel(__instance);
					}
					if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
					{
						MySimsNetworkHandler.Singleton.AddSimIdWithNewlySpawnedCosmetics(__instance);
					}
				}
			}
			else if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
			{
				MySimsNetworkHandler.Singleton.GetSimOfPlayer(__instance);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetDefaultMaterialsBackBecauseThePlayerChangedFromGhostBackToLiving")]
		public static void SetDefaultMaterialsBackBecauseThePlayerChangedFromGhostBackToLivingPostfix(InGameHumanCosmeticBuilder __instance)
		{
			if (!Object.op_Implicit((Object)(object)__instance))
			{
				return;
			}
			if (((NetworkBehaviour)__instance).IsOwner)
			{
				if (General.ValidID(MySimsCharacterManager.GetLocalID()))
				{
					MySimsCharacterManager.SetMySimsModel(__instance);
				}
			}
			else if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
			{
				MySimsNetworkHandler.Singleton.GetSimOfPlayer(__instance, askServer: false);
			}
		}
	}

	[HarmonyPatch(typeof(CharacterCustomizerManager))]
	public class MySimsCharacterCustomizerManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		public static void AwakePostfix(CharacterCustomizerManager __instance)
		{
			MySimsCharacterManager.SetUpOriginals(__instance);
			List<GameObject> privateField = __instance.GetPrivateField<List<GameObject>>("humanCustomizer_SubGroups");
			GameObject val = null;
			if (privateField != null && privateField.Count > 5)
			{
				val = privateField[5];
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				Logger.LogError((object)"failed to get BodyGroup UI");
				return;
			}
			GameObject simsSelectionUI = Plugin.allAssets.simsSelectionUI;
			if (!Object.op_Implicit((Object)(object)simsSelectionUI))
			{
				Logger.LogError((object)"failed to get MySimsSelectionUI");
			}
			else
			{
				Object.Instantiate<GameObject>(simsSelectionUI, val.transform, false);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("CreateNewDuplicatePlayerDummyOnMainMenuWaterTower")]
		public static void CreateNewDuplicatePlayerDummyOnMainMenuWaterTowerPrefix(CharacterCustomizerManager __instance)
		{
			Logger.LogDebug((object)"CreateNewDuplicatePlayerDummyOnMainMenuWaterTower()");
			MySimsCharacterManager.SetMySimsModel(null, __instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch("ResetPlayerModelToDefaults")]
		public static void ResetPlayerModelToDefaultsPrefix()
		{
			Logger.LogDebug((object)"ResetPlayerModelToDefaults()");
			General.ResetToDefaults();
		}

		[HarmonyPrefix]
		[HarmonyPatch("RandomizePlayer")]
		public static void RandomizePlayerPrefix()
		{
			Logger.LogDebug((object)"RandomizePlayer()");
			General.RandomizeSim();
		}

		[HarmonyPostfix]
		[HarmonyPatch("SaveBodyValues_Color")]
		public static void SaveBodyValues_ColorPostfix(CharacterCustomizerManager __instance)
		{
			Logger.LogDebug((object)"SaveBodyValues_Color()");
			if (General.ShouldShowSim(MySimsCharacterManager.GetLocalID()))
			{
				MySimsCharacterManager.SetMySimsModel(null, __instance);
			}
		}
	}

	[HarmonyPatch(typeof(CustomizerPresetManager))]
	public class MySimsCustomizerPresetManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SavePardnerCustomizationToJson")]
		public static void SavePardnerCustomizationToJsonPostfix(int _slotNumber)
		{
			if (General.CanLoadOrSave())
			{
				Logger.LogDebug((object)$"STARTING SAVING PROCESS! _slotNumber = {_slotNumber}");
				MySimsCharacterManager.SetUpToSaveData(_slotNumber);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("LoadPardnerCustomizationFromJson")]
		public static void LoadPardnerCustomizationFromJsonPostfix(int _slotNumber)
		{
			if (General.CanLoadOrSave())
			{
				if (General.IsLoadedSaveEmpty(_slotNumber))
				{
					MySimsCharacterManager.IgnoreNextLoadOrSave(ignoreLoad: true);
					General.ResetToDefaults();
				}
				else
				{
					Logger.LogDebug((object)$"STARTING LOADING PROCESS! slotNumber = {_slotNumber}");
					MySimsCharacterManager.SetUpToLoadData(_slotNumber);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("StoreSlotIndexForConfirmation")]
		public static void StoreSlotIndexForConfirmationPrefix(int _slotIndex)
		{
			if (_slotIndex == -1)
			{
				Logger.LogDebug((object)"StoreSlotIndexForConfirmation()");
				MySimsCharacterManager.IgnoreNextLoadOrSave(ignoreLoad: true);
				General.ResetToDefaults();
			}
		}
	}

	[HarmonyPatch(typeof(DummySyncDataHolder))]
	public class MySimsDummySyncDataHolderPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("associatedPlayerIdOnValueChanged")]
		public static void associatedPlayerIdOnValueChangedPostfix(DummySyncDataHolder __instance, ulong _old, ulong _new)
		{
			if (!Configs.multiplayerSyncing.Value || !Object.op_Implicit((Object)(object)__instance) || _new != 1000000 || _old == 1000000)
			{
				return;
			}
			Logger.LogDebug((object)$"playerId change from {_old} to {_new} on lobby dummy {__instance} #{((NetworkBehaviour)__instance).NetworkObjectId}, likely disconnect, manually removing cosmetics key on object");
			InGameHumanCosmeticBuilder componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<InGameHumanCosmeticBuilder>();
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				MySimsCharacterManager.SetMySimsModel(componentInChildren, null, Plugin.allAssets.noneSimData, 1);
				if (Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
				{
					MySimsNetworkHandler.Singleton.RemoveFromDictionary(((NetworkBehaviour)componentInChildren).NetworkObjectId, sync: false);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("IsGhostSyncBoolOnValueChanged")]
		public static void IsGhostSyncBoolOnValueChangedPostfix(DummySyncDataHolder __instance, bool _oldValue, bool _newValue)
		{
			if (!(Object.op_Implicit((Object)(object)__instance) && _newValue) || !Object.op_Implicit((Object)(object)NetworkManager.Singleton))
			{
				return;
			}
			Logger.LogDebug((object)$"isGhost change from {_oldValue} to {_newValue} on lobby dummy {__instance} #{((NetworkBehaviour)__instance).NetworkObjectId}, attempting to set ghost");
			InGameHumanCosmeticBuilder componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<InGameHumanCosmeticBuilder>();
			if (!Object.op_Implicit((Object)(object)componentInChildren))
			{
				Logger.LogWarning((object)"failed to find cosmetics");
				return;
			}
			InGameHumanCosmeticBuilder val = General.SwitchCosmeticsFromPlayerToDummy(componentInChildren);
			if (!Object.op_Implicit((Object)(object)val) || (Object)(object)val == (Object)(object)componentInChildren)
			{
				Logger.LogWarning((object)"failed to find other cosmetics");
			}
			else if (MySimsCharacterManager.CheckIfGhostIsReplaced(val))
			{
				Logger.LogDebug((object)"!!!ghost replaced to cassandra, trying to replace dummy!!!");
				CharacterData specialSim = General.GetSpecialSim(1);
				if (__instance.associatedPlayerID.Value == NetworkManager.Singleton.LocalClientId)
				{
					Logger.LogDebug((object)"local");
					MySimsCharacterManager.SetMySimsModel(componentInChildren, null, specialSim);
				}
				else if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
				{
					Logger.LogDebug((object)"netcode");
					int accessoriesCaseUsingCosmeticsKey = MySimsNetworkHandler.Singleton.GetAccessoriesCaseUsingCosmeticsKey(((NetworkBehaviour)componentInChildren).NetworkObjectId);
					int includeFaceCaseUsingCosmeticsKey = MySimsNetworkHandler.Singleton.GetIncludeFaceCaseUsingCosmeticsKey(((NetworkBehaviour)componentInChildren).NetworkObjectId);
					MySimsCharacterManager.SetMySimsModel(componentInChildren, null, specialSim, accessoriesCaseUsingCosmeticsKey, includeFaceCaseUsingCosmeticsKey);
				}
				else
				{
					Logger.LogDebug((object)"invalid");
				}
			}
		}
	}

	[HarmonyPatch(typeof(Player))]
	public class MySimsPlayerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("MakeDeathYell")]
		public static bool MakeDeathYellPrefix(Player __instance)
		{
			if (!Configs.voiceClipsMySims.Value)
			{
				return true;
			}
			Logger.LogDebug((object)"MakeDeathYell()");
			if (!Object.op_Implicit((Object)(object)__instance))
			{
				return true;
			}
			AudioSource privateField = __instance.GetPrivateField<AudioSource>("deathYellAudioSource");
			if (!Object.op_Implicit((Object)(object)privateField) || !Object.op_Implicit((Object)(object)AudioManager.Singleton))
			{
				return true;
			}
			if (Configs.multiplayerSyncing.Value)
			{
				InGameHumanCosmeticBuilder component = ((Component)__instance).GetComponent<InGameHumanCosmeticBuilder>();
				if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
				{
					return true;
				}
				CharacterData characterDataUsingCosmeticsKey = MySimsNetworkHandler.Singleton.GetCharacterDataUsingCosmeticsKey(((NetworkBehaviour)component).NetworkObjectId);
				if (!General.ShouldShowSim(characterDataUsingCosmeticsKey))
				{
					return true;
				}
				if (characterDataUsingCosmeticsKey.silentSim)
				{
					return false;
				}
				if (characterDataUsingCosmeticsKey.sfxDeath == null || characterDataUsingCosmeticsKey.sfxDeath.Length == 0)
				{
					return true;
				}
				General.PlayMySimsVoiceClip(privateField, characterDataUsingCosmeticsKey.sfxDeath, fromMultiplayer: true);
				return false;
			}
			if (Object.op_Implicit((Object)(object)GameManager.Singleton) && (Object)(object)((Component)__instance).gameObject == (Object)(object)GameManager.Singleton.localPlayerObject)
			{
				CharacterData sim = General.GetSim(MySimsCharacterManager.GetLocalID());
				if (!General.ShouldShowSim(sim))
				{
					return true;
				}
				if (sim.silentSim)
				{
					return false;
				}
				if (sim.sfxDeath == null || sim.sfxDeath.Length == 0)
				{
					return true;
				}
				General.PlayMySimsVoiceClip(privateField, sim.sfxDeath);
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("MakeGrabbedByWormNoise")]
		public static bool MakeGrabbedByWormPrefix(Player __instance)
		{
			if (!Configs.voiceClipsMySims.Value)
			{
				return true;
			}
			Logger.LogDebug((object)"MakeGrabbedByWormNoise()");
			if (!Object.op_Implicit((Object)(object)__instance))
			{
				return true;
			}
			AudioSource privateField = __instance.GetPrivateField<AudioSource>("injuredAudioSource");
			if (!Object.op_Implicit((Object)(object)privateField) || !Object.op_Implicit((Object)(object)AudioManager.Singleton))
			{
				return true;
			}
			if (Configs.multiplayerSyncing.Value)
			{
				InGameHumanCosmeticBuilder component = ((Component)__instance).GetComponent<InGameHumanCosmeticBuilder>();
				if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
				{
					return true;
				}
				CharacterData characterDataUsingCosmeticsKey = MySimsNetworkHandler.Singleton.GetCharacterDataUsingCosmeticsKey(((NetworkBehaviour)component).NetworkObjectId);
				if (!General.ShouldShowSim(characterDataUsingCosmeticsKey))
				{
					return true;
				}
				if (characterDataUsingCosmeticsKey.silentSim)
				{
					return false;
				}
				if (characterDataUsingCosmeticsKey.sfxHurt == null || characterDataUsingCosmeticsKey.sfxHurt.Length == 0)
				{
					return true;
				}
				General.PlayMySimsVoiceClip(privateField, characterDataUsingCosmeticsKey.sfxHurt, fromMultiplayer: true);
				return false;
			}
			if (Object.op_Implicit((Object)(object)GameManager.Singleton) && (Object)(object)((Component)__instance).gameObject == (Object)(object)GameManager.Singleton.localPlayerObject)
			{
				CharacterData sim = General.GetSim(MySimsCharacterManager.GetLocalID());
				if (!General.ShouldShowSim(sim))
				{
					return true;
				}
				if (sim.silentSim)
				{
					return false;
				}
				if (sim.sfxHurt == null || sim.sfxHurt.Length == 0)
				{
					return true;
				}
				General.PlayMySimsVoiceClip(privateField, sim.sfxHurt);
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("ChangeToGhost")]
		public static void ChangeToGhostPostfix(Player __instance)
		{
			if (Configs.secretCassandra.Value <= 0 || FriendsPassManager.isFriendsPassVersion || !Object.op_Implicit((Object)(object)__instance))
			{
				return;
			}
			Logger.LogDebug((object)$"ChangeToGhost() on {__instance} #{((NetworkBehaviour)__instance).NetworkObjectId}");
			if (((NetworkBehaviour)__instance).IsOwner)
			{
				int num = Random.Range(1, 101);
				Logger.LogDebug((object)num);
				if (num > Configs.secretCassandra.Value)
				{
					return;
				}
				InGameHumanCosmeticBuilder component = ((Component)__instance).GetComponent<InGameHumanCosmeticBuilder>();
				CharacterData specialSim = General.GetSpecialSim(1);
				if (Object.op_Implicit((Object)(object)component) && General.ShouldShowSim(specialSim))
				{
					Logger.LogDebug((object)"local");
					MySimsCharacterManager.SetMySimsModel(component, null, specialSim);
					if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
					{
						Logger.LogDebug((object)"netcode");
						MySimsNetworkHandler.Singleton.ChangeGhostToCassandraNonLocal(component);
					}
				}
			}
			else if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
			{
				InGameHumanCosmeticBuilder component2 = ((Component)__instance).GetComponent<InGameHumanCosmeticBuilder>();
				CharacterData specialSim2 = General.GetSpecialSim(1);
				if (Object.op_Implicit((Object)(object)component2) && General.ShouldShowSim(specialSim2) && MySimsCharacterManager.CheckIfGhostIsReplaced(component2))
				{
					int accessoriesCaseUsingCosmeticsKey = MySimsNetworkHandler.Singleton.GetAccessoriesCaseUsingCosmeticsKey(((NetworkBehaviour)component2).NetworkObjectId);
					int includeFaceCaseUsingCosmeticsKey = MySimsNetworkHandler.Singleton.GetIncludeFaceCaseUsingCosmeticsKey(((NetworkBehaviour)component2).NetworkObjectId);
					Logger.LogDebug((object)"client");
					MySimsCharacterManager.SetMySimsModel(component2, null, specialSim2, accessoriesCaseUsingCosmeticsKey, includeFaceCaseUsingCosmeticsKey);
				}
			}
		}
	}

	[HarmonyPatch(typeof(HudManager))]
	public class MySimsHudManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		public static void AwakePostfix()
		{
			if (Configs.secretPlumbob.Value)
			{
				GameObject plumbobPrefab = Plugin.allAssets.plumbobPrefab;
				if (!Object.op_Implicit((Object)(object)plumbobPrefab))
				{
					Logger.LogError((object)"failed to load plumbob");
				}
				else
				{
					Object.Instantiate<GameObject>(plumbobPrefab);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("SelectNewObjectForPickUpPopUp")]
		public static void SelectNewObjectForPickUpPopUpPostfix(HudManager __instance)
		{
			DoPlumbobHudManagerLogic(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("HidePickUpPopUp")]
		public static void HidePickUpPopUpPostfix(HudManager __instance)
		{
			DoPlumbobHudManagerLogic(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("SelectNewUsableObject")]
		public static void SelectNewUsableObjectPostfix(HudManager __instance)
		{
			DoPlumbobHudManagerLogic(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("HideUsablePopUp")]
		public static void HideUsablePopUpPostfix(HudManager __instance)
		{
			DoPlumbobHudManagerLogic(__instance);
		}

		private static void DoPlumbobHudManagerLogic(HudManager __instance)
		{
			if (Object.op_Implicit((Object)(object)__instance) && Configs.secretPlumbob.Value && Object.op_Implicit((Object)(object)PlumbobScript.Singleton))
			{
				PlumbobScript.Singleton.DoSetFollowObjectLogic(__instance);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ShowMapIsBuildingPopUp")]
		public static void ShowMapIsBuildingPopUpPostfix()
		{
			if (Configs.voiceClipsMySims.Value)
			{
				General.SetSimsClipsPlayed(0);
			}
			if (Configs.secretSirCharles.Value <= 0)
			{
				return;
			}
			Logger.LogDebug((object)"ShowMapIsBuildingPopUp()");
			int num = Random.Range(1, 101);
			Logger.LogDebug((object)num);
			if (num <= Configs.secretSirCharles.Value)
			{
				MySimsCharacterManager.ChangeEdDeLukaToSirCharles();
				if (Configs.multiplayerSyncing.Value && Object.op_Implicit((Object)(object)MySimsNetworkHandler.Singleton))
				{
					MySimsNetworkHandler.Singleton.ChangeBalloonPilotToSirCharlesNonLocal();
				}
			}
		}
	}

	[HarmonyPatch(typeof(EventFeedManager))]
	public class MySimsEventFeedManagerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("DisplayNewEventPopUp")]
		public static void DisplayNewEventPopUpPrefix(ref byte[] _eventStringByteArray)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			if (Configs.secretSirCharles.Value > 0 && Encoding.UTF8.GetString(_eventStringByteArray).Equals("Ed, The Air Balloon Pilot, is on their way") && MySimsCharacterManager.CheckIfBalloonPilotIsReplaced())
			{
				_eventStringByteArray = Encoding.UTF8.GetBytes("Sir Charles is on his way");
				if (Object.op_Implicit((Object)(object)GameManager.Singleton) && (int)GameManager.Singleton.playerType == 1)
				{
					Logger.LogDebug((object)"local player worm, should not see sir charles");
					MySimsCharacterManager.SetDissolveOnBalloonPilotModel();
				}
			}
		}
	}

	[HarmonyPatch(typeof(OptionsMenuManager))]
	public class MySimsOptionsMenuManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		public static void AwakePostfix(OptionsMenuManager __instance)
		{
			UISelectionScript.SetUpOriginals(__instance);
		}
	}

	[HarmonyPatch(typeof(Fpc), "FPC")]
	public class NewFpcFPC
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			Configs.DisplayConfigs();
			if (General.CanLoadOrSave())
			{
				MySimsCharacterManager.InitializeLoadAndSave();
			}
		}
	}

	private static ManualLogSource Logger;
}
public class MySimsCharacterManager
{
	private static ManualLogSource Logger;

	private static int localPlayerCharacterID;

	private static Mesh originalHeadMesh;

	private static Material originalHeadMat;

	private static Mesh originalBodyMesh;

	private static Material originalBodyMat;

	private static bool ignoreNextLoad;

	private static bool ignoreNextSave;

	public static string[] savedSelectedSims;

	public static bool[] savedAccessoriesVisible;

	public static void InitializeLoadAndSave()
	{
		savedSelectedSims = new string[6];
		savedAccessoriesVisible = new bool[6];
		new MySimsSaveData.SaveData().Load();
	}

	public static void IgnoreNextLoadOrSave(bool ignoreLoad)
	{
		if (ignoreLoad)
		{
			ignoreNextLoad = true;
		}
		else
		{
			ignoreNextSave = true;
		}
		Logger.LogDebug((object)$"preparing to ignore next load ({ignoreNextLoad}) or save ({ignoreNextSave})");
	}

	public static void SetUpToSaveData(int intoSlot)
	{
		if (savedSelectedSims == null || intoSlot < 0 || intoSlot >= savedSelectedSims.Length)
		{
			return;
		}
		if (ignoreNextSave)
		{
			ignoreNextSave = false;
			Logger.LogDebug((object)$"ignoreNextSave: {ignoreNextSave}");
			return;
		}
		string characterByIndex = GetCharacterByIndex();
		if (!string.IsNullOrEmpty(characterByIndex))
		{
			savedSelectedSims[intoSlot] = characterByIndex;
			savedAccessoriesVisible[intoSlot] = UISelectionScript.accessoriesVisible;
		}
		else
		{
			savedSelectedSims[intoSlot] = string.Empty;
			savedAccessoriesVisible[intoSlot] = false;
		}
		Logger.LogDebug((object)$"inserted into slot [{intoSlot}]: {savedSelectedSims[intoSlot]} ({savedAccessoriesVisible[intoSlot]})");
		new MySimsSaveData.SaveData().Save();
	}

	public static void SetUpToLoadData(int fromSlot)
	{
		if (!Object.op_Implicit((Object)(object)CharacterCustomizerManager.Singleton) || savedSelectedSims == null || fromSlot < 0 || fromSlot >= savedSelectedSims.Length)
		{
			return;
		}
		if (ignoreNextLoad)
		{
			ignoreNextLoad = false;
			Logger.LogDebug((object)$"ignoreNextLoad: {ignoreNextLoad}");
			return;
		}
		int characterByName = GetCharacterByName(savedSelectedSims[fromSlot]);
		if (characterByName != -1)
		{
			SetNewLocalID(characterByName);
			UISelectionScript.accessoriesVisible = savedAccessoriesVisible[fromSlot];
		}
		else
		{
			SetNewLocalID(0);
			UISelectionScript.accessoriesVisible = false;
		}
		SetMySimsModel(null, CharacterCustomizerManager.Singleton);
		if (Object.op_Implicit((Object)(object)UISelectionScript.Singleton))
		{
			UISelectionScript.Singleton.OnValueChanged_CharacterSelector();
			UISelectionScript.Singleton.OnValueChanged_AccessoriesVisible();
		}
		Logger.LogDebug((object)$"retrieved from slot [{fromSlot}]: {localPlayerCharacterID} ({UISelectionScript.accessoriesVisible})");
	}

	public static int GetLocalID()
	{
		return localPlayerCharacterID;
	}

	public static string GetCharacterByIndex(int byIndex = -1)
	{
		string text = string.Empty;
		if (byIndex == -1)
		{
			byIndex = localPlayerCharacterID;
		}
		if (byIndex >= 0 && byIndex < General.DataLength())
		{
			CharacterData sim = General.GetSim(byIndex);
			if (General.ShouldShowSim(sim))
			{
				text = sim.characterName;
				if (!string.IsNullOrEmpty(sim.outfitPostfix))
				{
					text = text + " (" + sim.outfitPostfix + ")";
				}
			}
		}
		Logger.LogDebug((object)$"GetCharacterByIndex({byIndex}) returning {text}");
		return text;
	}

	public static int GetCharacterByName(string byName)
	{
		int num = -1;
		for (int i = 0; i < General.DataLength(); i++)
		{
			CharacterData sim = General.GetSim(i);
			if (General.ShouldShowSim(sim))
			{
				string text = sim.characterName;
				if (!string.IsNullOrEmpty(sim.outfitPostfix))
				{
					text = text + " (" + sim.outfitPostfix + ")";
				}
				if (text == byName)
				{
					num = i;
					break;
				}
			}
		}
		Logger.LogDebug((object)$"GetCharacterByName({byName}) returning {num}");
		return num;
	}

	public static void SetNewLocalID(bool increase)
	{
		if (increase)
		{
			localPlayerCharacterID++;
			if (localPlayerCharacterID >= General.DataLength())
			{
				localPlayerCharacterID = 0;
			}
		}
		else
		{
			localPlayerCharacterID--;
			if (localPlayerCharacterID < 0)
			{
				localPlayerCharacterID = General.DataLength() - 1;
			}
		}
		OnValueChanged_LocalPlayerCharacterID();
	}

	public static void SetNewLocalID(int localID)
	{
		localPlayerCharacterID = Mathf.Clamp(localID, 0, General.DataLength() - 1);
		OnValueChanged_LocalPlayerCharacterID();
	}

	private static void OnValueChanged_LocalPlayerCharacterID()
	{
		if (Object.op_Implicit((Object)(object)UISelectionScript.Singleton))
		{
			UISelectionScript.Singleton.OnValueChanged_CharacterSelector();
		}
		if (Object.op_Implicit((Object)(object)CharacterCustomizerManager.Singleton))
		{
			SetMySimsModel(null, CharacterCustomizerManager.Singleton);
		}
	}

	public static void SetMySimsModel(InGameHumanCosmeticBuilder cosmetics = null, CharacterCustomizerManager customizer = null, CharacterData cData = null, int useVisibilityCase = -1, int includeFaceCase = -1)
	{
		CharacterData cData2 = (((Object)(object)cData == (Object)null) ? General.GetSim(GetLocalID()) : cData);
		bool useVisibility = UISelectionScript.accessoriesVisible;
		switch (useVisibilityCase)
		{
		case 0:
			useVisibility = false;
			break;
		case 1:
			useVisibility = true;
			break;
		}
		bool visibilityIncludesFace = Configs.facialFeaturesAccessories.Value;
		switch (includeFaceCase)
		{
		case 0:
			visibilityIncludesFace = false;
			break;
		case 1:
			visibilityIncludesFace = true;
			break;
		}
		bool flag = false;
		if (Object.op_Implicit((Object)(object)cosmetics))
		{
			flag = SetMySimsModelCosmetics(cosmetics, cData2, useVisibility, visibilityIncludesFace);
		}
		if (Object.op_Implicit((Object)(object)customizer))
		{
			flag = SetMySimsModelCustomizer(customizer, cData2, useVisibility, visibilityIncludesFace);
		}
		if (flag && Object.op_Implicit((Object)(object)cosmetics) && !cosmetics.GetPrivateField<bool>("isDummy"))
		{
			GameObject relevantObject = RetrieveRelevantObjectOfModel(cosmetics, customizer);
			GameObject headObject = RetrieveHeadObjectOfModel(cosmetics, customizer);
			ReplaceGroundDetectableMaterials(relevantObject, headObject);
			if (!Object.op_Implicit((Object)(object)cData))
			{
				ReplacePlayerDitherMaterials(relevantObject, headObject);
			}
		}
	}

	private static bool SetMySimsModelCosmetics(InGameHumanCosmeticBuilder __instance, CharacterData cData, bool useVisibility, bool visibilityIncludesFace)
	{
		if (!Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)Plugin.allAssets) || Plugin.allAssets.allCharacterData == null)
		{
			return false;
		}
		bool result = false;
		if (!General.ShouldShowSim(cData))
		{
			GameObject privateField = __instance.GetPrivateField<GameObject>("body");
			if (Object.op_Implicit((Object)(object)privateField))
			{
				SkinnedMeshRenderer component = privateField.GetComponent<SkinnedMeshRenderer>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.sharedMesh = originalBodyMesh;
					((Renderer)component).material = originalBodyMat;
				}
			}
			if (Object.op_Implicit((Object)(object)__instance.head))
			{
				MeshFilter component2 = ((Component)__instance.head).GetComponent<MeshFilter>();
				MeshRenderer component3 = ((Component)__instance.head).GetComponent<MeshRenderer>();
				if (Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)component3))
				{
					component2.sharedMesh = originalHeadMesh;
					((Renderer)component3).materials = (Material[])(object)new Material[1] { originalHeadMat };
				}
			}
		}
		else
		{
			GameObject privateField2 = __instance.GetPrivateField<GameObject>("body");
			if (Object.op_Implicit((Object)(object)privateField2))
			{
				SkinnedMeshRenderer component4 = privateField2.GetComponent<SkinnedMeshRenderer>();
				if (Object.op_Implicit((Object)(object)component4))
				{
					component4.sharedMesh = cData.meshBody;
					((Renderer)component4).material = cData.materialBody;
					result = true;
				}
			}
			if (Object.op_Implicit((Object)(object)__instance.head))
			{
				MeshFilter component5 = ((Component)__instance.head).GetComponent<MeshFilter>();
				MeshRenderer component6 = ((Component)__instance.head).GetComponent<MeshRenderer>();
				if (Object.op_Implicit((Object)(object)component5) && Object.op_Implicit((Object)(object)component6))
				{
					component5.sharedMesh = cData.meshHead;
					((Renderer)component6).materials = cData.materialsHead;
					result = true;
				}
			}
		}
		ToggleOriginalModelColor(__instance, !General.ShouldShowSim(cData));
		ToggleOriginalModelAccessories(__instance, General.ShouldShowFace(cData, useVisibility, visibilityIncludesFace), General.ShouldShowAccessories(cData, useVisibility));
		return result;
	}

	private static bool SetMySimsModelCustomizer(CharacterCustomizerManager __instance, CharacterData cData, bool useVisibility, bool visibilityIncludesFace)
	{
		if (!Object.op_Implicit((Object)(object)__instance) || !Object.op_Implicit((Object)(object)Plugin.allAssets) || Plugin.allAssets.allCharacterData == null)
		{
			return false;
		}
		bool result = false;
		if (!General.ShouldShowSim(cData))
		{
			GameObject privateField = __instance.GetPrivateField<GameObject>("spawned_Body");
			if (Object.op_Implicit((Object)(object)privateField))
			{
				SkinnedMeshRenderer component = privateField.GetComponent<SkinnedMeshRenderer>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.sharedMesh = originalBodyMesh;
					((Renderer)component).material = originalBodyMat;
				}
			}
			GameObject privateField2 = __instance.GetPrivateField<GameObject>("spawned_Head");
			if (Object.op_Implicit((Object)(object)privateField2))
			{
				MeshFilter component2 = privateField2.GetComponent<MeshFilter>();
				MeshRenderer component3 = privateField2.GetComponent<MeshRenderer>();
				if (Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)component3))
				{
					component2.sharedMesh = originalHeadMesh;
					((Renderer)component3).materials = (Material[])(object)new Material[1] { originalHeadMat };
				}
			}
		}
		else
		{
			GameObject privateField3 = __instance.GetPrivateField<GameObject>("spawned_Body");
			if (Object.op_Implicit((Object)(object)privateField3))
			{
				SkinnedMeshRenderer component4 = privateField3.GetComponent<SkinnedMeshRenderer>();
				if (Object.op_Implicit((Object)(object)component4))
				{
					component4.sharedMesh = cData.meshBody;
					((Renderer)component4).material = cData.materialBody;
					result = true;
				}
			}
			GameObject privateField4 = __instance.GetPrivateField<GameObject>("spawned_Head");
			if (Object.op_Implicit((Object)(object)privateField4))
			{
				MeshFilter component5 = privateField4.GetComponent<MeshFilter>();
				MeshRenderer component6 = privateField4.GetComponent<MeshRenderer>();
				if (Object.op_Implicit((Object)(object)component5) && Object.op_Implicit((Object)(object)component6))
				{
					component5.sharedMesh = cData.meshHead;
					((Renderer)component6).materials = cData.materialsHead;
					result = true;
				}
			}
		}
		ToggleOriginalModelColor(__instance, !General.ShouldShowSim(cData));
		ToggleOriginalModelAccessories(__instance, General.ShouldShowFace(cData, useVisibility, visibilityIncludesFace), General.ShouldShowAccessories(cData, useVisibility));
		return result;
	}

	public static void ToggleOriginalModelColor(InGameHumanCosmeticBuilder __instance, bool setTo)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)__instance))
		{
			return;
		}
		Color val = Color.white;
		if (setTo && Object.op_Implicit((Object)(object)MenuToGameBridger.Singleton))
		{
			val = MenuToGameBridger.Singleton.GetSafeColorForCosmeticPart(__instance.pcr.body_Color_Hex, __instance.pcr.body_Color_Index);
		}
		if (Object.op_Implicit((Object)(object)__instance.head))
		{
			MeshRenderer component = ((Component)__instance.head).GetComponent<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)component))
			{
				for (int i = 0; i < ((Renderer)component).materials.Length; i++)
				{
					((Renderer)component).materials[i].SetColor("_MainColor", val);
				}
			}
		}
		GameObject privateField = __instance.GetPrivateField<GameObject>("body");
		if (!Object.op_Implicit((Object)(object)privateField))
		{
			return;
		}
		SkinnedMeshRenderer component2 = privateField.GetComponent<SkinnedMeshRenderer>();
		if (Object.op_Implicit((Object)(object)component2))
		{
			for (int j = 0; j < ((Renderer)component2).materials.Length; j++)
			{
				((Renderer)component2).materials[j].SetColor("_MainColor", val);
			}
		}
	}

	public static void ToggleOriginalModelAccessories(InGameHumanCosmeticBuilder __instance, bool setFaceTo, bool setAccessoriesTo)
	{
		if (!Object.op_Implicit((Object)(object)__instance))
		{
			return;
		}
		Logger.LogDebug((object)$"{__instance}: setFaceTo = {setFaceTo} // setAccessoriesTo = {setAccessoriesTo}");
		if (Object.op_Implicit((Object)(object)__instance.rightEye))
		{
			Renderer[] componentsInChildren = __instance.rightEye.GetComponentsInChildren<Renderer>();
			if (componentsInChildren != null && componentsInChildren.Length != 0)
			{
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren[i]))
					{
						componentsInChildren[i].enabled = setFaceTo;
					}
				}
			}
		}
		if (Object.op_Implicit((Object)(object)__instance.leftEye))
		{
			Renderer[] componentsInChildren2 = __instance.leftEye.GetComponentsInChildren<Renderer>();
			if (componentsInChildren2 != null && componentsInChildren2.Length != 0)
			{
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren2[j]))
					{
						componentsInChildren2[j].enabled = setFaceTo;
					}
				}
			}
		}
		if (Object.op_Implicit((Object)(object)__instance.spawned_Nose))
		{
			Renderer[] componentsInChildren3 = __instance.spawned_Nose.GetComponentsInChildren<Renderer>();
			if (componentsInChildren3 != null && componentsInChildren3.Length != 0)
			{
				for (int k = 0; k < componentsInChildren3.Length; k++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren3[k]))
					{
						componentsInChildren3[k].enabled = setFaceTo;
					}
				}
			}
		}
		if (Object.op_Implicit((Object)(object)__instance.spawned_Eyebrow_Right))
		{
			Renderer[] componentsInChildren4 = __instance.spawned_Eyebrow_Right.GetComponentsInChildren<Renderer>();
			if (componentsInChildren4 != null && componentsInChildren4.Length != 0)
			{
				for (int l = 0; l < componentsInChildren4.Length; l++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren4[l]))
					{
						componentsInChildren4[l].enabled = setFaceTo;
					}
				}
			}
		}
		if (Object.op_Implicit((Object)(object)__instance.spawned_Eyebrow_Left))
		{
			Renderer[] componentsInChildren5 = __instance.spawned_Eyebrow_Left.GetComponentsInChildren<Renderer>();
			if (componentsInChildren5 != null && componentsInChildren5.Length != 0)
			{
				for (int m = 0; m < componentsInChildren5.Length; m++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren5[m]))
					{
						componentsInChildren5[m].enabled = setFaceTo;
					}
				}
			}
		}
		if (Object.op_Implicit((Object)(object)__instance.spawned_Mustache))
		{
			Renderer[] componentsInChildren6 = __instance.spawned_Mustache.GetComponentsInChildren<Renderer>();
			if (componentsInChildren6 != null && componentsInChildren6.Length != 0)
			{
				for (int n = 0; n < componentsInChildren6.Length; n++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren6[n]))
					{
						componentsInChildren6[n].enabled = setAccessoriesTo;
					}
				}
			}
		}
		if (Object.op_Implicit((Object)(object)__instance.spawned_Hat))
		{
			Renderer[] componentsInChildren7 = __instance.spawned_Hat.GetComponentsInChildren<Renderer>();
			if (componentsInChildren7 != null && componentsInChildren7.Length != 0)
			{
				for (int num = 0; num < componentsInChildren7.Length; num++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren7[num]))
					{
						componentsInChildren7[num].enabled = setAccessoriesTo;
					}
				}
			}
		}
		if (!Object.op_Implicit((Object)(object)__instance.spawned_Hat2))
		{
			return;
		}
		Renderer[] componentsInChildren8 = __instance.spawned_Hat2.GetComponentsInChildren<Renderer>();
		if (componentsInChildren8 == null || componentsInChildren8.Length == 0)
		{
			return;
		}
		for (int num2 = 0; num2 < componentsInChildren8.Length; num2++)
		{
			if (Object.op_Implicit((Object)(object)componentsInChildren8[num2]))
			{
				componentsInChildren8[num2].enabled = setAccessoriesTo;
			}
		}
	}

	public static void ToggleOriginalModelColor(CharacterCustomizerManager __instance, bool setTo)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)__instance))
		{
			return;
		}
		Color val = Color.white;
		if (setTo && Object.op_Implicit((Object)(object)MenuToGameBridger.Singleton) && Object.op_Implicit((Object)(object)CustomizerPresetManager.Singleton))
		{
			val = MenuToGameBridger.Singleton.GetSafeColorForCosmeticPart(Encoding.UTF8.GetBytes(CustomizerPresetManager.Singleton.pardnerCosmeticDataWeLastLoaded.BODY_COLOR_HEX), CustomizerPresetManager.Singleton.pardnerCosmeticDataWeLastLoaded.BODY_COLOR_INDEX);
		}
		GameObject privateField = __instance.GetPrivateField<GameObject>("spawned_Head");
		if (Object.op_Implicit((Object)(object)privateField))
		{
			MeshRenderer component = privateField.GetComponent<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)component))
			{
				for (int i = 0; i < ((Renderer)component).materials.Length; i++)
				{
					((Renderer)component).materials[i].SetColor("_MainColor", val);
				}
			}
		}
		GameObject privateField2 = __instance.GetPrivateField<GameObject>("spawned_Body");
		if (!Object.op_Implicit((Object)(object)privateField2))
		{
			return;
		}
		SkinnedMeshRenderer component2 = privateField2.GetComponent<SkinnedMeshRenderer>();
		if (Object.op_Implicit((Object)(object)component2))
		{
			for (int j = 0; j < ((Renderer)component2).materials.Length; j++)
			{
				((Renderer)component2).materials[j].SetColor("_MainColor", val);
			}
		}
	}

	public static void ToggleOriginalModelAccessories(CharacterCustomizerManager __instance, bool setFaceTo, bool setAccessoriesTo)
	{
		if (!Object.op_Implicit((Object)(object)__instance))
		{
			return;
		}
		Logger.LogDebug((object)$"{__instance} // setFaceTo = {setFaceTo} // setAccessoriesTo = {setAccessoriesTo}");
		GameObject privateField = __instance.GetPrivateField<GameObject>("spawned_EyeBallLeft");
		if (Object.op_Implicit((Object)(object)privateField))
		{
			Renderer[] componentsInChildren = privateField.GetComponentsInChildren<Renderer>();
			if (componentsInChildren != null && componentsInChildren.Length != 0)
			{
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren[i]))
					{
						componentsInChildren[i].enabled = setFaceTo;
					}
				}
			}
		}
		GameObject privateField2 = __instance.GetPrivateField<GameObject>("spawned_EyeBallRight");
		if (Object.op_Implicit((Object)(object)privateField2))
		{
			Renderer[] componentsInChildren2 = privateField2.GetComponentsInChildren<Renderer>();
			if (componentsInChildren2 != null && componentsInChildren2.Length != 0)
			{
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren2[j]))
					{
						componentsInChildren2[j].enabled = setFaceTo;
					}
				}
			}
		}
		GameObject privateField3 = __instance.GetPrivateField<GameObject>("spawned_EyeBrowLeft");
		if (Object.op_Implicit((Object)(object)privateField3))
		{
			Renderer[] componentsInChildren3 = privateField3.GetComponentsInChildren<Renderer>();
			if (componentsInChildren3 != null && componentsInChildren3.Length != 0)
			{
				for (int k = 0; k < componentsInChildren3.Length; k++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren3[k]))
					{
						componentsInChildren3[k].enabled = setFaceTo;
					}
				}
			}
		}
		GameObject privateField4 = __instance.GetPrivateField<GameObject>("spawned_EyeBrowRight");
		if (Object.op_Implicit((Object)(object)privateField4))
		{
			Renderer[] componentsInChildren4 = privateField4.GetComponentsInChildren<Renderer>();
			if (componentsInChildren4 != null && componentsInChildren4.Length != 0)
			{
				for (int l = 0; l < componentsInChildren4.Length; l++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren4[l]))
					{
						componentsInChildren4[l].enabled = setFaceTo;
					}
				}
			}
		}
		GameObject privateField5 = __instance.GetPrivateField<GameObject>("spawned_Hat");
		if (Object.op_Implicit((Object)(object)privateField5))
		{
			Renderer[] componentsInChildren5 = privateField5.GetComponentsInChildren<Renderer>();
			if (componentsInChildren5 != null && componentsInChildren5.Length != 0)
			{
				for (int m = 0; m < componentsInChildren5.Length; m++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren5[m]))
					{
						componentsInChildren5[m].enabled = setAccessoriesTo;
					}
				}
			}
		}
		GameObject privateField6 = __instance.GetPrivateField<GameObject>("spawned_Hat2");
		if (Object.op_Implicit((Object)(object)privateField6))
		{
			Renderer[] componentsInChildren6 = privateField6.GetComponentsInChildren<Renderer>();
			if (componentsInChildren6 != null && componentsInChildren6.Length != 0)
			{
				for (int n = 0; n < componentsInChildren6.Length; n++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren6[n]))
					{
						componentsInChildren6[n].enabled = setAccessoriesTo;
					}
				}
			}
		}
		GameObject privateField7 = __instance.GetPrivateField<GameObject>("spawned_Nose");
		if (Object.op_Implicit((Object)(object)privateField7))
		{
			Renderer[] componentsInChildren7 = privateField7.GetComponentsInChildren<Renderer>();
			if (componentsInChildren7 != null && componentsInChildren7.Length != 0)
			{
				for (int num = 0; num < componentsInChildren7.Length; num++)
				{
					if (Object.op_Implicit((Object)(object)componentsInChildren7[num]))
					{
						componentsInChildren7[num].enabled = setFaceTo;
					}
				}
			}
		}
		GameObject privateField8 = __instance.GetPrivateField<GameObject>("spawned_Mustache");
		if (!Object.op_Implicit((Object)(object)privateField8))
		{
			return;
		}
		Renderer[] componentsInChildren8 = privateField8.GetComponentsInChildren<Renderer>();
		if (componentsInChildren8 == null || componentsInChildren8.Length == 0)
		{
			return;
		}
		for (int num2 = 0; num2 < componentsInChildren8.Length; num2++)
		{
			if (Object.op_Implicit((Object)(object)componentsInChildren8[num2]))
			{
				componentsInChildren8[num2].enabled = setAccessoriesTo;
			}
		}
	}

	private static void ReplaceGroundDetectableMaterials(GameObject relevantObject, GameObject headObject)
	{
		if (!Object.op_Implicit((Object)(object)relevantObject) && !Object.op_Implicit((Object)(object)headObject))
		{
			Logger.LogWarning((object)"no objects were given to ReplaceGroundDetectableMaterials()!");
			return;
		}
		GroundDetectable componentInChildren = relevantObject.GetComponentInChildren<GroundDetectable>();
		if (Object.op_Implicit((Object)(object)componentInChildren))
		{
			List<Material> list = RetrieveMySimsMaterialsOnModel(relevantObject, headObject);
			if (list != null && list.Count > 0)
			{
				Logger.LogDebug((object)$"successfully replacing {list.Count} materials on {componentInChildren} #{componentInChildren}");
				componentInChildren.ReplaceMaterials(list.ToArray());
				componentInChildren.ResetVisability(0f, false, false);
			}
		}
	}

	private static void ReplacePlayerDitherMaterials(GameObject relevantObject, GameObject headObject)
	{
		if (!Configs.bodySeeThrough.Value && !Configs.headSeeThrough.Value)
		{
			Logger.LogDebug((object)"ReplacePlayerDitherMaterials(): A");
			return;
		}
		if (!Object.op_Implicit((Object)(object)relevantObject) && !Object.op_Implicit((Object)(object)headObject))
		{
			Logger.LogDebug((object)"ReplacePlayerDitherMaterials(): B");
			return;
		}
		if (!Object.op_Implicit((Object)(object)MenuToGameBridger.Singleton) || !Object.op_Implicit((Object)(object)MenuToGameBridger.Singleton.shader_ditherByDistance) || MenuToGameBridger.Singleton.ditherMaterialsOnOurPlayer == null)
		{
			Logger.LogDebug((object)"ReplacePlayerDitherMaterials(): C");
			return;
		}
		List<Material> list = new List<Material>();
		if (Configs.headSeeThrough.Value && Object.op_Implicit((Object)(object)headObject))
		{
			List<Material> list2 = RetrieveMySimsMaterialsOnModel(null, headObject);
			if (list2 != null && list2.Count > 0)
			{
				list.AddRange(list2);
			}
		}
		if (Configs.bodySeeThrough.Value && Object.op_Implicit((Object)(object)relevantObject))
		{
			List<Material> list3 = RetrieveMySimsMaterialsOnModel(relevantObject, null);
			if (list3 != null && list3.Count > 0)
			{
				list.AddRange(list3);
			}
		}
		if (list == null || list.Count <= 0)
		{
			return;
		}
		int num = 0;
		for (int i = 0; i < list.Count; i++)
		{
			Material item = list[i];
			if (!MenuToGameBridger.Singleton.ditherMaterialsOnOurPlayer.Contains(item))
			{
				list[i].shader = MenuToGameBridger.Singleton.shader_ditherByDistance;
				list[i].SetFloat("_Dither_Amount", 0.4f);
				list[i].SetFloat("_DitherMinDist", 0f);
				list[i].SetFloat("_DitherMaxDist", 2f);
				MenuToGameBridger.Singleton.ditherMaterialsOnOurPlayer.Add(item);
				num++;
			}
		}
		Logger.LogDebug((object)$"successfully added {num} materials on {MenuToGameBridger.Singleton}");
	}

	private static GameObject RetrieveRelevantObjectOfModel(InGameHumanCosmeticBuilder cosmetics, CharacterCustomizerManager customizer)
	{
		GameObject val = null;
		if (Object.op_Implicit((Object)(object)cosmetics))
		{
			val = ((Component)cosmetics).gameObject;
		}
		else if (Object.op_Implicit((Object)(object)customizer))
		{
			val = ((Component)customizer).gameObject;
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			Logger.LogWarning((object)$"RetrieveRelevantObjectOfModel() failed to find anything for {cosmetics} and {customizer}!");
		}
		return val;
	}

	private static GameObject RetrieveHeadObjectOfModel(InGameHumanCosmeticBuilder cosmetics, CharacterCustomizerManager customizer)
	{
		GameObject val = null;
		if (Object.op_Implicit((Object)(object)cosmetics) && Object.op_Implicit((Object)(object)cosmetics.head))
		{
			val = ((Component)cosmetics.head).gameObject;
		}
		else if (Object.op_Implicit((Object)(object)customizer))
		{
			val = customizer.GetPrivateField<GameObject>("spawned_Head");
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			Logger.LogWarning((object)$"RetrieveHeadObjectOfModel() failed to find anything for {cosmetics} and {customizer}!");
		}
		return val;
	}

	private static List<Material> RetrieveMySimsMaterialsOnModel(GameObject bodyObject, GameObject headObject)
	{
		if (!Object.op_Implicit((Object)(object)bodyObject) && !Object.op_Implicit((Object)(object)headObject))
		{
			return null;
		}
		List<Material> list = new List<Material>();
		if (Object.op_Implicit((Object)(object)bodyObject))
		{
			SkinnedMeshRenderer componentInChildren = bodyObject.GetComponentInChildren<SkinnedMeshRenderer>();
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				list.AddRange(((Renderer)componentInChildren).materials);
			}
		}
		if (Object.op_Implicit((Object)(object)headObject))
		{
			MeshRenderer component = headObject.GetComponent<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)component))
			{
				list.AddRange(((Renderer)component).materials);
			}
		}
		if (list != null && list.Count > 0)
		{
			Logger.LogDebug((object)$"RetrieveMySimsMaterialsOnModel() returning {list.Count} materials:");
			for (int i = 0; i < list.Count; i++)
			{
				Logger.LogDebug((object)$"[{i}]: {list[i]}");
			}
		}
		return list;
	}

	public static void ChangeEdDeLukaToSirCharles()
	{
		if (CheckIfBalloonPilotIsReplaced() || !Object.op_Implicit((Object)(object)EscapeBalloonManager.Singleton) || Configs.secretSirCharles.Value <= 0)
		{
			return;
		}
		GameObject privateField = EscapeBalloonManager.Singleton.GetPrivateField<GameObject>("ed_Dummy");
		Transform val = null;
		GameObject val2 = GameObject.Find("Balloon Escape Diorama");
		if (Object.op_Implicit((Object)(object)val2))
		{
			Transform val3 = val2.transform.Find("Balloon Dummy");
			if (Object.op_Implicit((Object)(object)val3))
			{
				val = val3.Find("Ed DeLuka Dummy");
			}
		}
		if (Object.op_Implicit((Object)(object)privateField) && Object.op_Implicit((Object)(object)val))
		{
			ReplaceBalloonPilotModel(privateField);
			ReplaceBalloonPilotModel(((Component)val).gameObject);
		}
	}

	private static void ReplaceBalloonPilotModel(GameObject pilotObject)
	{
		if (!Object.op_Implicit((Object)(object)pilotObject))
		{
			return;
		}
		CharacterData specialSim = General.GetSpecialSim(0);
		if (!General.ShouldShowSim(specialSim) || !Object.op_Implicit((Object)(object)EscapeBalloonManager.Singleton))
		{
			return;
		}
		Logger.LogDebug((object)"ReplaceBalloonPilotModel()");
		Transform obj = pilotObject.transform.Find("Art");
		object obj2;
		if (obj == null)
		{
			obj2 = null;
		}
		else
		{
			Transform obj3 = obj.Find("Clayman_01_rigged");
			if (obj3 == null)
			{
				obj2 = null;
			}
			else
			{
				Transform obj4 = obj3.Find("mixamorig:Hips");
				if (obj4 == null)
				{
					obj2 = null;
				}
				else
				{
					Transform obj5 = obj4.Find("mixamorig:Spine");
					if (obj5 == null)
					{
						obj2 = null;
					}
					else
					{
						Transform obj6 = obj5.Find("mixamorig:Spine1").Find("mixamorig:Spine2");
						if (obj6 == null)
						{
							obj2 = null;
						}
						else
						{
							Transform obj7 = obj6.Find("mixamorig:Neck");
							obj2 = ((obj7 != null) ? obj7.Find("mixamorig:Head") : null);
						}
					}
				}
			}
		}
		Transform val = (Transform)obj2;
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		try
		{
			Transform val2 = null;
			Transform val3 = null;
			Transform val4 = val.Find("EyeBrow_01 (1)");
			Transform val5 = val.Find("EyeBrow_01");
			Transform val6 = val.Find("Nose_03");
			Transform val7 = val.Find("Hat_01");
			Transform val8 = val.Find("Mustache_04");
			Transform val9 = val.Find("Hat_Santa");
			Transform val10 = val.Find("cc_Head_01");
			SkinnedMeshRenderer componentInChildren = pilotObject.GetComponentInChildren<SkinnedMeshRenderer>();
			MeshFilter val11 = null;
			MeshRenderer val12 = null;
			if (Object.op_Implicit((Object)(object)val10))
			{
				val2 = val10.Find("Eyeball_01 Left");
				val3 = val10.Find("Eyeball_01 Right");
				val11 = ((Component)val10).GetComponent<MeshFilter>();
				val12 = ((Component)val10).GetComponent<MeshRenderer>();
			}
			if (Object.op_Implicit((Object)(object)componentInChildren) && Object.op_Implicit((Object)(object)val11) && Object.op_Implicit((Object)(object)val12) && Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val4) && Object.op_Implicit((Object)(object)val5) && Object.op_Implicit((Object)(object)val6) && Object.op_Implicit((Object)(object)val7) && Object.op_Implicit((Object)(object)val8) && Object.op_Implicit((Object)(object)val9))
			{
				componentInChildren.sharedMesh = specialSim.meshBody;
				((Renderer)componentInChildren).material = specialSim.materialBody;
				val11.sharedMesh = specialSim.meshHead;
				((Renderer)val12).materials = specialSim.materialsHead;
				((Component)val2).gameObject.SetActive(false);
				((Component)val3).gameObject.SetActive(false);
				((Component)val4).gameObject.SetActive(false);
				((Component)val5).gameObject.SetActive(false);
				((Component)val6).gameObject.SetActive(false);
				((Component)val7).gameObject.SetActive(false);
				((Component)val8).gameObject.SetActive(false);
				((Component)val9).gameObject.SetActive(false);
				Logger.LogDebug((object)"successfully replaced model");
			}
			else
			{
				Logger.LogDebug((object)$"bodyContainer = {componentInChildren}");
				Logger.LogDebug((object)$"headMeshFilter = {val11}");
				Logger.LogDebug((object)$"headMeshRenderer = {val12}");
				Logger.LogDebug((object)$"ballL = {val2}");
				Logger.LogDebug((object)$"ballR = {val3}");
				Logger.LogDebug((object)$"brow1 = {val4}");
				Logger.LogDebug((object)$"brow2 = {val5}");
				Logger.LogDebug((object)$"nose = {val6}");
				Logger.LogDebug((object)$"hat = {val7}");
				Logger.LogDebug((object)$"stache = {val8}");
				Logger.LogDebug((object)$"santa = {val9}");
			}
		}
		catch
		{
			Logger.LogWarning((object)"error while replacing model");
		}
	}

	public static void SetDissolveOnBalloonPilotModel(float setTo = 1f)
	{
		Logger.LogDebug((object)$"SetDissolveOnBalloonPilotModel({setTo})");
		if (!Object.op_Implicit((Object)(object)EscapeBalloonManager.Singleton))
		{
			return;
		}
		GameObject privateField = EscapeBalloonManager.Singleton.GetPrivateField<GameObject>("ed_Dummy");
		if (!Object.op_Implicit((Object)(object)privateField))
		{
			return;
		}
		SkinnedMeshRenderer componentInChildren = privateField.GetComponentInChildren<SkinnedMeshRenderer>();
		MeshRenderer val = null;
		Transform obj = privateField.transform.Find("Art");
		object obj2;
		if (obj == null)
		{
			obj2 = null;
		}
		else
		{
			Transform obj3 = obj.Find("Clayman_01_rigged");
			if (obj3 == null)
			{
				obj2 = null;
			}
			else
			{
				Transform obj4 = obj3.Find("mixamorig:Hips");
				if (obj4 == null)
				{
					obj2 = null;
				}
				else
				{
					Transform obj5 = obj4.Find("mixamorig:Spine");
					if (obj5 == null)
					{
						obj2 = null;
					}
					else
					{
						Transform obj6 = obj5.Find("mixamorig:Spine1").Find("mixamorig:Spine2");
						if (obj6 == null)
						{
							obj2 = null;
						}
						else
						{
							Transform obj7 = obj6.Find("mixamorig:Neck");
							if (obj7 == null)
							{
								obj2 = null;
							}
							else
							{
								Transform obj8 = obj7.Find("mixamorig:Head");
								obj2 = ((obj8 != null) ? obj8.Find("cc_Head_01") : null);
							}
						}
					}
				}
			}
		}
		Transform val2 = (Transform)obj2;
		if (Object.op_Implicit((Object)(object)val2))
		{
			val = ((Component)val2).GetComponent<MeshRenderer>();
		}
		if (Object.op_Implicit((Object)(object)componentInChildren) && Object.op_Implicit((Object)(object)val))
		{
			((Renderer)componentInChildren).material.SetFloat("_Dissolve", setTo);
			Material[] materials = ((Renderer)val).materials;
			for (int i = 0; i < materials.Length; i++)
			{
				materials[i].SetFloat("_Dissolve", setTo);
			}
			Logger.LogDebug((object)"successfully set material floats");
		}
	}

	public static bool CheckIfBalloonPilotIsReplaced()
	{
		if (!Object.op_Implicit((Object)(object)EscapeBalloonManager.Singleton))
		{
			return false;
		}
		return CheckIfBodyIsReplaced(EscapeBalloonManager.Singleton.GetPrivateField<GameObject>("ed_Dummy"), 0);
	}

	public static bool CheckIfGhostIsReplaced(InGameHumanCosmeticBuilder cosmetics = null)
	{
		if (!Object.op_Implicit((Object)(object)cosmetics))
		{
			return false;
		}
		return CheckIfBodyIsReplaced(((Component)cosmetics).gameObject, 1);
	}

	private static bool CheckIfBodyIsReplaced(GameObject bodyObject, int specialSimID)
	{
		if (!Object.op_Implicit((Object)(object)bodyObject))
		{
			return false;
		}
		SkinnedMeshRenderer componentInChildren = bodyObject.GetComponentInChildren<SkinnedMeshRenderer>();
		if (!Object.op_Implicit((Object)(object)componentInChildren) || !Object.op_Implicit((Object)(object)componentInChildren.sharedMesh))
		{
			return false;
		}
		CharacterData specialSim = General.GetSpecialSim(specialSimID);
		if (!General.ShouldShowSim(specialSim))
		{
			return false;
		}
		if (Object.op_Implicit((Object)(object)specialSim.meshBody) && ((Object)componentInChildren.sharedMesh).name == ((Object)specialSim.meshBody).name)
		{
			Logger.LogDebug((object)$"CheckIfBodyIsReplaced() using GameObject {bodyObject} returned true");
			return true;
		}
		return false;
	}

	public static void SetUpOriginals(CharacterCustomizerManager manager)
	{
		if (!Object.op_Implicit((Object)(object)manager) || (Object.op_Implicit((Object)(object)originalHeadMesh) && Object.op_Implicit((Object)(object)originalHeadMat) && Object.op_Implicit((Object)(object)originalBodyMesh) && Object.op_Implicit((Object)(object)originalBodyMat)))
		{
			return;
		}
		GameObject privateField = manager.GetPrivateField<GameObject>("spawned_Head");
		if (Object.op_Implicit((Object)(object)privateField))
		{
			MeshFilter component = privateField.GetComponent<MeshFilter>();
			if (Object.op_Implicit((Object)(object)component))
			{
				originalHeadMesh = component.sharedMesh;
			}
			MeshRenderer component2 = privateField.GetComponent<MeshRenderer>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				originalHeadMat = ((Renderer)component2).sharedMaterial;
			}
		}
		GameObject privateField2 = manager.GetPrivateField<GameObject>("spawned_Body");
		if (Object.op_Implicit((Object)(object)privateField2))
		{
			SkinnedMeshRenderer component3 = privateField2.GetComponent<SkinnedMeshRenderer>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				originalBodyMesh = component3.sharedMesh;
				originalBodyMat = ((Renderer)component3).sharedMaterial;
			}
		}
		Logger.LogDebug((object)$"SetUpOriginals() got: originalHeadMesh = {originalHeadMesh} && originalHeadMat = {originalHeadMat} && originalBodyMesh = {originalBodyMesh} && originalBodyMat = {originalBodyMat}");
	}
}
public class MySimsNetworkHandler : NetworkBehaviour
{
	private static ManualLogSource Logger;

	public static MySimsNetworkHandler Singleton;

	public float maxWaitTime;

	public float waitInIntervalsOf;

	private Dictionary<ulong, float> cosmeticsNetIDsWithLocalSimIDs = new Dictionary<ulong, float>();

	private void Awake()
	{
		if (Object.op_Implicit((Object)(object)Singleton))
		{
			Singleton.ClearDictionary(sync: false);
			Logger.LogDebug((object)"destroying");
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
		else
		{
			Singleton = this;
			Logger.LogDebug((object)$"Awake on {this}");
		}
	}

	public void AddSimIdWithNewlySpawnedCosmetics(InGameHumanCosmeticBuilder cosmetics)
	{
		int num = MySimsCharacterManager.GetLocalID();
		bool flag = UISelectionScript.accessoriesVisible;
		bool flag2 = Configs.facialFeaturesAccessories.Value;
		if (!General.ShouldShowSim(General.GetSim(num)))
		{
			num = General.DataLength();
			flag = true;
			flag2 = false;
			Logger.LogDebug((object)$"local player not playing with sim, passing 'ignore'-value ({General.DataLength()}) to everyone");
		}
		Logger.LogDebug((object)$"locally sending ID {num}, VISIBILITY {flag}, and FACIAL {flag2} for {cosmetics} #{((NetworkBehaviour)cosmetics).NetworkObjectId}");
		AddToDictionary(((NetworkBehaviour)cosmetics).NetworkObjectId, num, flag, flag2, sync: true);
	}

	public void AddToDictionary(ulong cosmeticsId, int simId, bool accVisibility, bool accIncludesFace, bool sync)
	{
		AddToDictionaryLocal(cosmeticsId, simId, accVisibility, accIncludesFace);
		if (sync && Object.op_Implicit((Object)(object)NetworkManager.Singleton))
		{
			AddToDictionary_ServerRPC(cosmeticsId, simId, accVisibility, accIncludesFace, NetworkManager.Singleton.LocalClientId);
		}
	}

	[ServerRpc(RequireOwnership = false)]
	private void AddToDictionary_ServerRPC(ulong cosmeticsId, int simId, bool accVisibility, bool accIncludesFace, ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2398489992u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, cosmeticsId);
				BytePacker.WriteValueBitPacked(val2, simId);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref accVisibility, default(ForPrimitives));
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref accIncludesFace, default(ForPrimitives));
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2398489992u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				AddToDictionary_ClientRPC(cosmeticsId, simId, accVisibility, accIncludesFace, clientId);
			}
		}
	}

	[ClientRpc]
	private void AddToDictionary_ClientRPC(ulong cosmeticsId, int simId, bool accVisibility, bool accIncludesFace, ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(473811477u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, cosmeticsId);
				BytePacker.WriteValueBitPacked(val2, simId);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref accVisibility, default(ForPrimitives));
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref accIncludesFace, default(ForPrimitives));
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 473811477u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Object.op_Implicit((Object)(object)NetworkManager.Singleton) && NetworkManager.Singleton.LocalClientId != clientId)
			{
				AddToDictionaryLocal(cosmeticsId, simId, accVisibility, accIncludesFace);
			}
		}
	}

	private void AddToDictionaryLocal(ulong cosmeticsId, int simId, bool accVisibility, bool accIncludesFace)
	{
		RemoveFromDictionary(cosmeticsId, sync: false);
		float num = simId;
		if (accIncludesFace)
		{
			num += 0.5f;
		}
		if (!accVisibility)
		{
			num *= -1f;
		}
		cosmeticsNetIDsWithLocalSimIDs.Add(cosmeticsId, num);
		Logger.LogDebug((object)$"locally added cosmetic with sim: ({cosmeticsId}, {num})");
	}

	public void RemoveFromDictionary(ulong cosmeticsId, bool sync)
	{
		RemoveFromDictionaryLocal(cosmeticsId);
		if (sync && Object.op_Implicit((Object)(object)NetworkManager.Singleton))
		{
			RemoveFromDictionary_ServerRPC(cosmeticsId, NetworkManager.Singleton.LocalClientId);
		}
	}

	[ServerRpc(RequireOwnership = false)]
	private void RemoveFromDictionary_ServerRPC(ulong cosmeticsId, ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(14871763u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, cosmeticsId);
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 14871763u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				RemoveFromDictionary_ClientRPC(cosmeticsId, clientId);
			}
		}
	}

	[ClientRpc]
	private void RemoveFromDictionary_ClientRPC(ulong cosmeticsId, ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(552148118u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, cosmeticsId);
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 552148118u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Object.op_Implicit((Object)(object)NetworkManager.Singleton) && NetworkManager.Singleton.LocalClientId != clientId)
			{
				RemoveFromDictionaryLocal(cosmeticsId);
			}
		}
	}

	private void RemoveFromDictionaryLocal(ulong cosmeticsId)
	{
		if (DictionaryContainsKey(cosmeticsId))
		{
			Logger.LogDebug((object)$"!!!removing key {cosmeticsId} with old value {cosmeticsNetIDsWithLocalSimIDs[cosmeticsId]}!!!");
			cosmeticsNetIDsWithLocalSimIDs.Remove(cosmeticsId);
		}
	}

	public void ClearDictionary(bool sync)
	{
		ClearDictionaryLocal();
		if (sync && Object.op_Implicit((Object)(object)NetworkManager.Singleton))
		{
			ClearDictionary_ServerRPC(NetworkManager.Singleton.LocalClientId);
		}
	}

	[ServerRpc(RequireOwnership = false)]
	private void ClearDictionary_ServerRPC(ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2697501584u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2697501584u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClearDictionary_ClientRPC(clientId);
			}
		}
	}

	[ClientRpc]
	private void ClearDictionary_ClientRPC(ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1120511425u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1120511425u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Object.op_Implicit((Object)(object)NetworkManager.Singleton) && NetworkManager.Singleton.LocalClientId != clientId)
			{
				ClearDictionaryLocal();
			}
		}
	}

	private void ClearDictionaryLocal()
	{
		if (cosmeticsNetIDsWithLocalSimIDs != null && cosmeticsNetIDsWithLocalSimIDs.Count > 0)
		{
			Logger.LogDebug((object)"clearing Dictionary");
			cosmeticsNetIDsWithLocalSimIDs.Clear();
		}
	}

	public CharacterData GetCharacterDataUsingCosmeticsKey(ulong cosmeticsId)
	{
		if (DictionaryContainsKey(cosmeticsId))
		{
			int simIdUsingCosmeticsKey = GetSimIdUsingCosmeticsKey(cosmeticsId);
			if (simIdUsingCosmeticsKey >= 0 && simIdUsingCosmeticsKey < General.DataLength())
			{
				return General.GetSim(simIdUsingCosmeticsKey);
			}
		}
		return null;
	}

	public int GetSimIdUsingCosmeticsKey(ulong cosmeticsId)
	{
		if (DictionaryContainsKey(cosmeticsId))
		{
			return (int)Mathf.Abs(cosmeticsNetIDsWithLocalSimIDs[cosmeticsId]);
		}
		return 0;
	}

	public int GetAccessoriesCaseUsingCosmeticsKey(ulong cosmeticsId)
	{
		if (DictionaryContainsKey(cosmeticsId))
		{
			if (!(cosmeticsNetIDsWithLocalSimIDs[cosmeticsId] >= 0f))
			{
				return 0;
			}
			return 1;
		}
		return -1;
	}

	public int GetIncludeFaceCaseUsingCosmeticsKey(ulong cosmeticsId)
	{
		if (DictionaryContainsKey(cosmeticsId))
		{
			if (cosmeticsNetIDsWithLocalSimIDs[cosmeticsId] % 1f != 0.5f)
			{
				return 0;
			}
			return 1;
		}
		return -1;
	}

	private bool DictionaryContainsKey(ulong cosmeticsId)
	{
		if (cosmeticsNetIDsWithLocalSimIDs != null && cosmeticsNetIDsWithLocalSimIDs.Count > 0)
		{
			return cosmeticsNetIDsWithLocalSimIDs.ContainsKey(cosmeticsId);
		}
		return false;
	}

	public void GetSimOfPlayer(InGameHumanCosmeticBuilder regardingCosmetics, bool askServer = true)
	{
		if (Object.op_Implicit((Object)(object)regardingCosmetics))
		{
			Logger.LogInfo((object)$"staring Coroutine to retrieve simId!! regardingCosmetics = {regardingCosmetics}");
			((MonoBehaviour)this).StartCoroutine(WaitAndSeeIfCosmeticIsRegistered(regardingCosmetics, askServer));
		}
	}

	private IEnumerator WaitAndSeeIfCosmeticIsRegistered(InGameHumanCosmeticBuilder cosmetics, bool askServer)
	{
		if (askServer && !DictionaryContainsKey(((NetworkBehaviour)cosmetics).NetworkObjectId) && Object.op_Implicit((Object)(object)NetworkManager.Singleton))
		{
			RequestSimIdAtKey_ServerRPC(((NetworkBehaviour)cosmetics).NetworkObjectId, NetworkManager.Singleton.LocalClientId);
		}
		yield return null;
		float timeWaited = 0f;
		float placeholderIdForUnfound = -9999f;
		float num = TryAndGetSimIDWithKey(cosmetics, placeholderIdForUnfound);
		while (num == placeholderIdForUnfound && timeWaited < maxWaitTime)
		{
			yield return (object)new WaitForSeconds(waitInIntervalsOf);
			timeWaited += waitInIntervalsOf;
			num = TryAndGetSimIDWithKey(cosmetics, placeholderIdForUnfound);
		}
		if (num == placeholderIdForUnfound)
		{
			Logger.LogError((object)$"failed to retrieve simID using cosmetics {cosmetics}");
		}
		else if (num == (float)General.DataLength())
		{
			Logger.LogDebug((object)$"NOTE: found simId for cosmetics {cosmetics} returned 'ignore'-values {General.DataLength()}, ignoring");
		}
		else
		{
			ApplyRequestedIdLocal(cosmetics);
		}
	}

	private float TryAndGetSimIDWithKey(InGameHumanCosmeticBuilder cosmetics, float valueUnfound)
	{
		float num = valueUnfound;
		if (!Object.op_Implicit((Object)(object)cosmetics))
		{
			return num;
		}
		ulong networkObjectId = ((NetworkBehaviour)cosmetics).NetworkObjectId;
		if (DictionaryContainsKey(networkObjectId))
		{
			num = cosmeticsNetIDsWithLocalSimIDs[networkObjectId];
		}
		Logger.LogDebug((object)$"TryAndGetSimIDWithKey(): {num}");
		return num;
	}

	[ServerRpc(RequireOwnership = false)]
	private void RequestSimIdAtKey_ServerRPC(ulong cosmeticsId, ulong requesterClientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1698885614u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, cosmeticsId);
				BytePacker.WriteValueBitPacked(val2, requesterClientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1698885614u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && DictionaryContainsKey(cosmeticsId))
			{
				float num = cosmeticsNetIDsWithLocalSimIDs[cosmeticsId];
				Logger.LogDebug((object)$"RequestSimIdAtKey_ServerRPC() sending to requesterClientId [{requesterClientId}] value of cosmeticsId {cosmeticsId}: {num}");
				RequestSimIdAtKey_ClientRPC(cosmeticsId, requesterClientId, num);
			}
		}
	}

	[ClientRpc]
	private void RequestSimIdAtKey_ClientRPC(ulong cosmeticsId, ulong requesterClientId, float receivedSimId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1487646982u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, cosmeticsId);
				BytePacker.WriteValueBitPacked(val2, requesterClientId);
				((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref receivedSimId, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1487646982u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && Object.op_Implicit((Object)(object)NetworkManager.Singleton) && NetworkManager.Singleton.LocalClientId == requesterClientId)
			{
				int simId = (int)Mathf.Abs(receivedSimId);
				bool accVisibility = receivedSimId >= 0f;
				bool accIncludesFace = receivedSimId % 1f == 0.5f;
				AddToDictionary(cosmeticsId, simId, accVisibility, accIncludesFace, sync: false);
			}
		}
	}

	private void ApplyRequestedIdLocal(InGameHumanCosmeticBuilder ofCosmetics)
	{
		if (Object.op_Implicit((Object)(object)ofCosmetics))
		{
			int simIdUsingCosmeticsKey = GetSimIdUsingCosmeticsKey(((NetworkBehaviour)ofCosmetics).NetworkObjectId);
			CharacterData sim = General.GetSim(simIdUsingCosmeticsKey);
			int accessoriesCaseUsingCosmeticsKey = GetAccessoriesCaseUsingCosmeticsKey(((NetworkBehaviour)ofCosmetics).NetworkObjectId);
			int includeFaceCaseUsingCosmeticsKey = GetIncludeFaceCaseUsingCosmeticsKey(((NetworkBehaviour)ofCosmetics).NetworkObjectId);
			Logger.LogDebug((object)$"going to create model with ID {simIdUsingCosmeticsKey}, acc {accessoriesCaseUsingCosmeticsKey > 0}, and face {includeFaceCaseUsingCosmeticsKey > 0}");
			MySimsCharacterManager.SetMySimsModel(ofCosmetics, null, sim, accessoriesCaseUsingCosmeticsKey, includeFaceCaseUsingCosmeticsKey);
		}
	}

	public void ChangeGhostToCassandraNonLocal(InGameHumanCosmeticBuilder cosmetics)
	{
		if (Object.op_Implicit((Object)(object)cosmetics) && Object.op_Implicit((Object)(object)NetworkManager.Singleton))
		{
			ChangeGhostToCassandra_ServerRPC(((NetworkBehaviour)cosmetics).NetworkObjectId, NetworkManager.Singleton.LocalClientId);
		}
	}

	[ServerRpc(RequireOwnership = false)]
	private void ChangeGhostToCassandra_ServerRPC(ulong cosmeticsId, ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1524223247u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, cosmeticsId);
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1524223247u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ChangeGhostToCassandra_ClientRPC(cosmeticsId, clientId);
			}
		}
	}

	[ClientRpc]
	private void ChangeGhostToCassandra_ClientRPC(ulong cosmeticsId, ulong clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			ClientRpcParams val = default(ClientRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2793985922u, val, (RpcDelivery)0);
			BytePacker.WriteValueBitPacked(val2, cosmeticsId);
			BytePacker.WriteValueBitPacked(val2, clientId);
			((NetworkBehaviour)this).__endSendClientRp