Decompiled source of GuildsAPI Doors Chests v1.0.0

GuildsAPI_Doors_Chests.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Guilds;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GuildsAPI_Doors_Chests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GuildsAPI_Doors_Chests")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9048CA6E-FC30-424E-AF51-5D22475C5FBB")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GuildsAPI_Doors_Chests
{
	[HarmonyPatch(typeof(Door), "Interact")]
	public static class HookInteract_Door
	{
		private static bool Prefix(Door __instance, ref bool __result, bool alt)
		{
			string @string = __instance.m_nview.m_zdo.GetString("OwnedByGuild", "");
			if (string.IsNullOrEmpty(@string))
			{
				return true;
			}
			bool @bool = __instance.m_nview.m_zdo.GetBool("GuildProtection_AnyoneCanAccess", false);
			if (@bool && !alt)
			{
				return true;
			}
			if (@string == GuildsAPI_Doors_Chests.GetMyOwnGuildGUID())
			{
				if (alt)
				{
					__instance.m_nview.m_zdo.Set("GuildProtection_AnyoneCanAccess", !@bool);
					MessageHud.instance.ShowMessage((MessageType)2, "Anyone can access: " + (@bool ? "Yes" : "No"), 0, (Sprite)null);
					__result = false;
					return false;
				}
				__result = true;
				return true;
			}
			MessageHud.instance.ShowMessage((MessageType)2, "This door is owned by another guild.", 0, (Sprite)null);
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(Door), "GetHoverText")]
	public static class HookHoverText_Door
	{
		private static void Postfix(Door __instance, ref string __result)
		{
			string @string = __instance.m_nview.m_zdo.GetString("OwnedByGuild", "");
			if (!string.IsNullOrEmpty(@string))
			{
				bool @bool = __instance.m_nview.m_zdo.GetBool("GuildProtection_AnyoneCanAccess", false);
				bool flag = @string == GuildsAPI_Doors_Chests.GetMyOwnGuildGUID();
				__result += (flag ? "\n<color=green><b>This door is owned by your guild</b></color>" : "\n<color=red><b>This door is owned by another guild</b></color>");
				__result = __result + "\nAnyone can access: " + (@bool ? "<color=green>Yes</color>" : "<color=red>No</color>");
				__result += Localization.instance.Localize("\n[<color=yellow><b>L. Shift + $KEY_Use</b></color>] Toggle access");
			}
		}
	}
	[BepInPlugin("GuildsAPI_Doors_Chests", "GuildsAPI_Doors_Chests", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class GuildsAPI_Doors_Chests : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Piece), "CanBeRemoved")]
		private static class Piece_CanBeRemoved_Patch
		{
			private static void Postfix(Piece __instance, ref bool __result)
			{
				string @string = __instance.m_nview.m_zdo.GetString("OwnedByGuild", "");
				if (!string.IsNullOrEmpty(@string))
				{
					bool flag = @string == GetMyOwnGuildGUID();
					__result &= flag;
					__result |= Player.m_debugMode;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "PlacePiece")]
		public static class HookBuild
		{
			public static void PlacedPiece(GameObject obj)
			{
				Guild ownGuild = API.GetOwnGuild();
				if (ownGuild != null)
				{
					obj.GetComponent<ZNetView>().m_zdo.Set("OwnedByGuild", ownGuild.GUID);
				}
			}

			[UsedImplicitly]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				MethodInfo method = AccessTools.Method(typeof(HookBuild), "PlacedPiece", new Type[1] { typeof(GameObject) }, (Type[])null);
				foreach (CodeInstruction instruction in instructions)
				{
					yield return instruction;
					if (instruction.opcode == OpCodes.Stloc_3)
					{
						yield return new CodeInstruction(OpCodes.Ldloc_S, (object)3);
						yield return new CodeInstruction(OpCodes.Call, (object)method);
					}
				}
			}
		}

		public class CustomGuildsGUID
		{
			public string GUID;
		}

		private const string GUID = "GuildsAPI_Doors_Chests";

		private const string NAME = "GuildsAPI_Doors_Chests";

		private const string VERSION = "1.0.0";

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("GuildsAPI_Doors_Chests").PatchAll();
		}

		public static string GetMyOwnGuildGUID()
		{
			return API.GetOwnGuild()?.GUID;
		}
	}
}
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 Guilds
{
	[PublicAPI]
	internal static class API
	{
		public delegate void AchievementCompleted(PlayerReference player, string achievment);

		public delegate void GuildJoined(Guild guild, PlayerReference player);

		public delegate void GuildLeft(Guild guild, PlayerReference player);

		public delegate void GuildCreated(Guild guild);

		public delegate void GuildDeleted(Guild guild);

		public static bool IsLoaded()
		{
			return false;
		}

		public static Guild? GetPlayerGuild(PlayerReference player)
		{
			return null;
		}

		public static Guild? GetPlayerGuild(Player player)
		{
			return GetPlayerGuild(PlayerReference.fromPlayer(player));
		}

		public static Guild? GetOwnGuild()
		{
			return GetPlayerGuild(PlayerReference.forOwnPlayer());
		}

		public static Guild? GetGuild(string name)
		{
			return null;
		}

		public static Guild? GetGuild(int id)
		{
			return null;
		}

		public static List<Guild> GetGuilds()
		{
			return new List<Guild>();
		}

		public static PlayerReference GetGuildLeader(Guild guild)
		{
			return guild.Members.FirstOrDefault<KeyValuePair<PlayerReference, GuildMember>>((KeyValuePair<PlayerReference, GuildMember> r) => r.Value.rank == Ranks.Leader).Key;
		}

		public static Guild? CreateGuild(string name, PlayerReference leader)
		{
			return null;
		}

		public static bool DeleteGuild(Guild guild)
		{
			return false;
		}

		public static bool RenameGuild(Guild guild, string newName)
		{
			return true;
		}

		public static bool SaveGuild(Guild guild)
		{
			return false;
		}

		public static bool AddPlayerToGuild(PlayerReference player, Guild guild)
		{
			if (GetPlayerGuild(player) == null)
			{
				guild.Members.Add(player, new GuildMember());
				SaveGuild(guild);
				return true;
			}
			return false;
		}

		public static bool RemovePlayerFromGuild(PlayerReference player)
		{
			Guild playerGuild = GetPlayerGuild(player);
			if (playerGuild != null)
			{
				playerGuild.Members.Remove(player);
				SaveGuild(playerGuild);
				return true;
			}
			return false;
		}

		public static Ranks GetPlayerRank(PlayerReference player)
		{
			return GetPlayerGuild(player)?.Members[player].rank ?? Ranks.Leader;
		}

		public static bool UpdatePlayerRank(PlayerReference player, Ranks newRank)
		{
			Guild playerGuild = GetPlayerGuild(player);
			if (playerGuild != null)
			{
				GuildMember guildMember = playerGuild.Members[player];
				guildMember.rank = newRank;
				playerGuild.Members[player] = guildMember;
				SaveGuild(playerGuild);
				return true;
			}
			return false;
		}

		public static IEnumerable<PlayerReference> GetOnlinePlayers(Guild? guild = null)
		{
			HashSet<PlayerReference> hashSet = new HashSet<PlayerReference>(ZNet.instance.m_players.Select(PlayerReference.fromPlayerInfo));
			if (guild != null)
			{
				return guild.Members.Keys.Where(hashSet.Contains);
			}
			foreach (PlayerReference item in GetGuilds().SelectMany((Guild g) => g.Members.Keys))
			{
				hashSet.Remove(item);
			}
			return hashSet;
		}

		public static Guild? GetOwnAppliedGuild()
		{
			return GetPlayerAppliedGuild(PlayerReference.forOwnPlayer());
		}

		public static Guild? GetPlayerAppliedGuild(PlayerReference player)
		{
			return null;
		}

		public static bool ApplyToGuild(PlayerReference player, string description, Guild guild)
		{
			RemovePlayerApplication(player);
			guild.Applications[player] = new Application
			{
				description = description
			};
			return SaveGuild(guild);
		}

		public static bool RemovePlayerApplication(PlayerReference player, Guild? guild = null)
		{
			Guild playerAppliedGuild = GetPlayerAppliedGuild(player);
			if (playerAppliedGuild != null && (guild == null || playerAppliedGuild == guild))
			{
				playerAppliedGuild.Applications.Remove(player);
				return SaveGuild(playerAppliedGuild);
			}
			return true;
		}

		public static void RegisterCustomData(Type type)
		{
		}

		public static T? GetCustomData<T>(Guild guild) where T : class
		{
			return null;
		}

		public static void SetCustomData<T>(Guild guild, T customData) where T : class
		{
		}

		public static void IncreaseAchievementProgress(Guild guild, string achievement, float increment = 1f)
		{
		}

		public static void RegisterOnAchievementCompleted(AchievementCompleted callback)
		{
		}

		public static void RegisterAchievement(string name, AchievementConfig config)
		{
		}

		internal static AchievementConfig? GetAchievementConfig(string achievement)
		{
			return null;
		}

		internal static IEnumerable<KeyValuePair<string, AchievementConfig>> AllAchievementConfigs()
		{
			return Array.Empty<KeyValuePair<string, AchievementConfig>>();
		}

		public static Sprite? GetGuildIcon(Guild guild)
		{
			return null;
		}

		public static Sprite? GetGuildIconById(int iconId)
		{
			return null;
		}

		public static int GetAchievementStage(Guild guild, AchievementConfig achievement)
		{
			return 0;
		}

		public static void RegisterOnGuildJoined(GuildJoined callback)
		{
		}

		public static void RegisterOnGuildLeft(GuildLeft callback)
		{
		}

		public static void RegisterOnGuildCreated(GuildCreated callback)
		{
		}

		public static void RegisterOnGuildDeleted(GuildDeleted callback)
		{
		}
	}
	[PublicAPI]
	internal class Guild
	{
		public string Name = "";

		public GuildGeneral General = new GuildGeneral();

		public Dictionary<PlayerReference, GuildMember> Members = new Dictionary<PlayerReference, GuildMember>();

		public Dictionary<PlayerReference, Application> Applications = new Dictionary<PlayerReference, Application>();

		public Dictionary<string, AchievementData> Achievements = new Dictionary<string, AchievementData>();

		public CustomData customData = new CustomData();

		public string GUID = Guid.NewGuid().ToString();
	}
	[PublicAPI]
	internal class GuildMember
	{
		public Ranks rank = Ranks.Member;

		public DateTime lastOnline = DateTime.Now;

		public Dictionary<int, Dictionary<string, int>> contribution = new Dictionary<int, Dictionary<string, int>>();
	}
	[PublicAPI]
	internal class GuildGeneral
	{
		public int id = 0;

		public string description = "";

		public int icon = 1;

		public int level = 0;

		public string color = "";
	}
	[PublicAPI]
	internal class Application
	{
		public DateTime applied = DateTime.Now;

		public string description = "";
	}
	[PublicAPI]
	internal class AchievementData
	{
		public float? progress = 0f;

		public List<DateTime> completed = new List<DateTime>();
	}
	[PublicAPI]
	internal class CustomData
	{
		internal Dictionary<Type, object> data = new Dictionary<Type, object>();

		internal Dictionary<string, object> unknown = new Dictionary<string, object>();
	}
	[PublicAPI]
	internal class AchievementConfig
	{
		public string name = "";

		public string description = "";

		public List<float> progress = new List<float> { 1f };

		public List<int>? guild = null;

		public List<int> level = new List<int>();

		public string icon = "";

		public bool first;

		public Dictionary<string, string> config = new Dictionary<string, string>();

		public T getConfigValue<T>(string name, T defaultValue = default(T))
		{
			return defaultValue;
		}
	}
	[PublicAPI]
	[TypeConverter(typeof(PlayerReferenceTypeConverter))]
	internal struct PlayerReference
	{
		public string id;

		public string name;

		public static PlayerReference fromPlayerInfo(PlayerInfo playerInfo)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			PlayerReference result = default(PlayerReference);
			result.id = (Utility.IsNullOrWhiteSpace(playerInfo.m_host) ? PrivilegeManager.GetNetworkUserId() : (playerInfo.m_host.Contains("_") ? playerInfo.m_host : ("Steam_" + playerInfo.m_host)));
			result.name = playerInfo.m_name ?? "";
			return result;
		}

		public static PlayerReference fromPlayer(Player player)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Player player2 = player;
			return ((Object)(object)player2 == (Object)(object)Player.m_localPlayer) ? forOwnPlayer() : fromPlayerInfo(((IEnumerable<PlayerInfo>)ZNet.instance.m_players).FirstOrDefault((Func<PlayerInfo, bool>)((PlayerInfo info) => info.m_characterID == ((Character)player2).GetZDOID())));
		}

		public static PlayerReference forOwnPlayer()
		{
			PlayerReference result = default(PlayerReference);
			result.id = PrivilegeManager.GetNetworkUserId();
			result.name = Game.instance.GetPlayerProfile().GetName();
			return result;
		}

		public static bool operator !=(PlayerReference a, PlayerReference b)
		{
			return !(a == b);
		}

		public static bool operator ==(PlayerReference a, PlayerReference b)
		{
			return a.id == b.id && a.name == b.name;
		}

		public bool Equals(PlayerReference other)
		{
			return this == other;
		}

		public override bool Equals(object? obj)
		{
			return obj is PlayerReference other && Equals(other);
		}

		public override int GetHashCode()
		{
			return (id.GetHashCode() * 397) ^ name.GetHashCode();
		}

		public override string ToString()
		{
			return id + ":" + name;
		}

		public static PlayerReference fromString(string str)
		{
			string[] array = str.Split(new char[1] { ':' });
			PlayerReference result = default(PlayerReference);
			result.id = array[0];
			result.name = array[1];
			return result;
		}
	}
	internal class PlayerReferenceTypeConverter : TypeConverter
	{
		public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object? value)
		{
			return PlayerReference.fromString(value?.ToString() ?? ":");
		}
	}
	internal enum Toggle
	{
		On = 1,
		Off = 0
	}
	internal enum Ranks
	{
		Leader,
		Coleader,
		Officer,
		Member
	}
}