Decompiled source of NewCharacterLocks v1.0.2

NewCharactersLocks.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NewCharactersLocks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7183f9d55c6f87a79e5e952e1a7b69bc43ed8395")]
[assembly: AssemblyProduct("NewCharactersLocks")]
[assembly: AssemblyTitle("NewCharactersLocks")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.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;
		}
	}
	[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;
		}
	}
}
[BepInPlugin("com.altair.valheim.newcharacterlock", "New Character Lock", "1.0.2")]
public class NewCharacterLock : BaseUnityPlugin
{
	[HarmonyPatch(typeof(PlayerProfile), "Load")]
	public class CharacterLoadPatch
	{
		private static bool Prefix(PlayerProfile __instance)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!SteamManager.Initialized)
			{
				PluginLogger.LogError((object)"Steam no está inicializado.");
				return false;
			}
			ulong steamID = SteamUser.GetSteamID().m_SteamID;
			string name = __instance.GetName();
			return RequestServerAccess(steamID.ToString(), name);
		}
	}

	public static readonly string filePath = Path.Combine(Paths.ConfigPath, "CharacterSteamIDs.txt");

	public static ManualLogSource PluginLogger = Logger.CreateLogSource("NewCharacterLock");

	private void Awake()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		if (!SteamManager.Initialized && !SteamAPI.Init())
		{
			PluginLogger.LogError((object)"Steam API no inicializado.");
			return;
		}
		CSteamID steamID = SteamUser.GetSteamID();
		PluginLogger.LogInfo((object)$"SteamID obtenido: {steamID.m_SteamID}");
		Harmony val = new Harmony("com.altair.valheim.newcharacterlock");
		val.PatchAll(Assembly.GetExecutingAssembly());
		PluginLogger.LogInfo((object)"Nuevo personaje Lock mod ha sido cargado!");
		EnsureFileExists(filePath);
	}

	private void EnsureFileExists(string path)
	{
		if (!File.Exists(path))
		{
			File.Create(path).Close();
			PluginLogger.LogInfo((object)("Archivo creado en: " + path));
		}
	}

	private static bool RequestServerAccess(string steamID, string characterName)
	{
		bool flag = VerifyCharacterOnServer(steamID, characterName);
		if (!flag)
		{
			PluginLogger.LogError((object)"Acceso denegado: debes entrar con un personaje nuevo.");
		}
		return flag;
	}

	private static bool VerifyCharacterOnServer(string steamID, string characterName)
	{
		string[] array = File.ReadAllLines(filePath);
		bool flag = false;
		bool flag2 = false;
		string[] array2 = array;
		foreach (string text in array2)
		{
			string[] array3 = text.Split(':');
			if (array3[1] == steamID)
			{
				flag = true;
				if (array3[0] == characterName)
				{
					flag2 = true;
					break;
				}
			}
		}
		if (!flag)
		{
			File.AppendAllText(filePath, characterName + ":" + steamID + "\n");
			PluginLogger.LogInfo((object)("Nuevo personaje " + characterName + " registrado con SteamID: " + steamID));
			return true;
		}
		if (flag && !flag2)
		{
			PluginLogger.LogError((object)("Acceso denegado para " + characterName + " con el ID " + steamID + ": el personaje no está registrado."));
			return false;
		}
		PluginLogger.LogInfo((object)("Acceso concedido para " + characterName + " con el ID " + steamID));
		return true;
	}
}