Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Incognito Mode v0.5.0
Plugins/VentureValheim.IncognitoMode.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Splatform; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("VentureValheim.IncognitoMode")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("VentureValheim.IncognitoMode")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("7BDF2320-F171-4843-84B4-95C86CD03E77")] [assembly: AssemblyFileVersion("0.5.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.5.0.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace VentureValheim.IncognitoMode { [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("com.orianaventure.mod.IncognitoMode", "IncognitoMode", "0.5.0")] public class IncognitoModePlugin : BaseUnityPlugin { private const string ModName = "IncognitoMode"; private const string ModVersion = "0.5.0"; private const string Author = "com.orianaventure.mod"; private const string ModGUID = "com.orianaventure.mod.IncognitoMode"; private static string ConfigFileName = "com.orianaventure.mod.IncognitoMode.cfg"; private static string ConfigFileFullPath; private readonly Harmony HarmonyInstance = new Harmony("com.orianaventure.mod.IncognitoMode"); public static readonly ManualLogSource IncognitoModeLogger; internal static ConfigEntry<string> CE_HiddenByItems; internal static ConfigEntry<string> CE_HiddenDisplayName; internal static ConfigEntry<bool> CE_HideNameInChat; internal static ConfigEntry<bool> CE_HidePlatformTag; internal static ConfigEntry<bool> CE_HideHud; private readonly ConfigurationManagerAttributes AdminConfig = new ConfigurationManagerAttributes { IsAdminOnly = true }; private readonly ConfigurationManagerAttributes ClientConfig = new ConfigurationManagerAttributes { IsAdminOnly = false }; public static string GetHiddenByItems() { return CE_HiddenByItems.Value; } public static string GetHiddenDisplayName() { return CE_HiddenDisplayName.Value; } public static bool GetHideNameInChat() { return CE_HideNameInChat.Value; } public static bool GetHidePlatformTag() { return CE_HidePlatformTag.Value; } public static bool GetHideHud() { return CE_HideHud.Value; } private void AddConfig<T>(string key, string section, string description, bool synced, T value, ref ConfigEntry<T> configEntry) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown string extendedDescription = GetExtendedDescription(description, synced); configEntry = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(extendedDescription, (AcceptableValueBase)null, new object[1] { synced ? AdminConfig : ClientConfig })); } public string GetExtendedDescription(string description, bool synchronizedSetting) { return description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"); } public void Awake() { AddConfig("HiddenByItems", "General", "Prefab names of helmet/shoulder items that can hide a Player's name (comma-separated string).", synced: true, "HelmetRoot, HelmetFenring, HelmetPadded, HelmetMage_Ashlands, HelmetFlametal", ref CE_HiddenByItems); AddConfig("HiddenDisplayName", "General", "The hidden Player's display name (string).", synced: true, "???", ref CE_HiddenDisplayName); AddConfig("HideNameInChat", "General", "When hidden also hides the name in chat (boolean).", synced: true, value: true, ref CE_HideNameInChat); AddConfig("HidePlatformTag", "General", "When hidden also hides steam/xbox platform tags (boolean).", synced: true, value: false, ref CE_HidePlatformTag); AddConfig("HideHud", "General", "When hidden completely hides the hud as if the player is sneaking (boolean).", synced: true, value: false, ref CE_HideHud); IncognitoModeLogger.LogInfo((object)"I wear a mask, and that mask is not to hide who I am, but to create who I am."); Assembly executingAssembly = Assembly.GetExecutingAssembly(); HarmonyInstance.PatchAll(executingAssembly); SetupWatcher(); } public void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } private void SetupWatcher() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName); fileSystemWatcher.Changed += ReadConfigValues; fileSystemWatcher.Created += ReadConfigValues; fileSystemWatcher.Renamed += ReadConfigValues; fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; } private void ReadConfigValues(object sender, FileSystemEventArgs e) { if (!File.Exists(ConfigFileFullPath)) { return; } try { IncognitoModeLogger.LogDebug((object)"Attempting to reload configuration..."); ((BaseUnityPlugin)this).Config.Reload(); } catch { IncognitoModeLogger.LogError((object)("There was an issue loading " + ConfigFileName)); } } static IncognitoModePlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; IncognitoModeLogger = Logger.CreateLogSource("IncognitoMode"); CE_HiddenByItems = null; CE_HiddenDisplayName = null; CE_HideNameInChat = null; CE_HidePlatformTag = null; CE_HideHud = null; } } public class IncognitoMode { [HarmonyPatch(typeof(EnemyHud), "TestShow")] public static class Patch_EnemyHud_TestShow { private static void Postfix(EnemyHud __instance, Character c, ref bool __result) { if (__result && IncognitoModePlugin.GetHideHud() && c.IsPlayer() && !((Object)(object)c.m_nview == (Object)null)) { ZDO zDO = c.m_nview.GetZDO(); if (zDO != null && zDO.GetBool("VV_NameHidden", false)) { __result = false; } } } } [HarmonyPatch(typeof(Player), "GetHoverName")] public static class Patch_Player_GetHoverName { private static void Postfix(Player __instance, ref string __result) { if (!IncognitoModePlugin.GetHideHud() && !((Object)(object)((Character)__instance).m_nview == (Object)null)) { ZDO zDO = ((Character)__instance).m_nview.GetZDO(); if (zDO != null && zDO.GetBool("VV_NameHidden", false)) { __result = GetDisplayName(); } } } } [HarmonyPatch(typeof(Player), "SetupVisEquipment")] public static class Patch_Player_SetupVisEquipment { private static void Postfix(Player __instance) { if (!((Object)(object)((Character)__instance).m_nview == (Object)null) && ((Character)__instance).m_nview.IsOwner()) { ZDO zDO = ((Character)__instance).m_nview.GetZDO(); if (zDO != null) { Instance.Update(); bool flag = ItemSetsHidden(((Humanoid)__instance).m_helmetItem) || ItemSetsHidden(((Humanoid)__instance).m_shoulderItem) || ItemSetsHidden(((Humanoid)__instance).m_utilityItem) || ItemSetsHidden(((Humanoid)__instance).m_trinketItem); zDO.Set("VV_NameHidden", flag); } } } } [HarmonyPriority(500)] [HarmonyPatch(typeof(ZNet), "TryGetPlayerByPlatformUserID")] public static class Patch_ZNet_TryGetPlayerByPlatformUserID { private static void Postfix(Terminal __instance, PlatformUserID platformUserID, ref PlayerInfo playerInfo, bool __result) { if (!__result || !IncognitoModePlugin.GetHideNameInChat()) { return; } Player val = null; List<Player> s_players = Player.s_players; for (int i = 0; i < s_players.Count; i++) { if (((ZDOID)(ref ((Character)s_players[i]).m_nview.GetZDO().m_uid)).ID.Equals(((ZDOID)(ref playerInfo.m_characterID)).ID)) { val = s_players[i]; break; } } bool flag = false; if ((Object)(object)val != (Object)null && (Object)(object)((Character)val).m_nview != (Object)null) { ZDO zDO = ((Character)val).m_nview.GetZDO(); if (zDO != null) { flag = zDO.GetBool("VV_NameHidden", false); } } if (flag) { playerInfo.m_name = GetDisplayName(); } } } private static readonly IncognitoMode _instance = new IncognitoMode(); private const string NAME_HIDDEN = "VV_NameHidden"; private string ItemPrefabsString = ""; private HashSet<string> ItemPrefabs = new HashSet<string>(); public static IncognitoMode Instance => _instance; private IncognitoMode() { } public static string GetDisplayName() { return IncognitoModePlugin.GetHiddenDisplayName() ?? "???"; } public static bool ItemSetsHidden(ItemData item) { if (item != null && (Object)(object)item.m_dropPrefab != (Object)null) { return Instance.ItemPrefabs.Contains(((Object)item.m_dropPrefab).name); } return false; } public void Update() { if (IncognitoModePlugin.GetHiddenByItems().Equals(Instance.ItemPrefabsString)) { return; } ItemPrefabsString = IncognitoModePlugin.GetHiddenByItems(); ItemPrefabs = new HashSet<string>(); if (!Utility.IsNullOrWhiteSpace(ItemPrefabsString)) { string[] array = ItemPrefabsString.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { ItemPrefabs.Add(array[i].Trim()); } } } } }