using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ValheimMoreIngots")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ValheimMoreIngots")]
[assembly: AssemblyTitle("ValheimMoreIngots")]
[assembly: AssemblyVersion("1.0.0.0")]
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 ValheimMoreIngots
{
[BepInPlugin("com.dryzler.valheim.moreingots", "Dryzler's More Ingots", "1.0.4")]
public class Mod : BaseUnityPlugin
{
private class Lib
{
public static void initMod(Mod mod)
{
instance = mod;
mod.dateTimeAwaked = DateTime.UtcNow;
mod.harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), mod.PLUGIN_ID);
try
{
X509Certificate2 serverCert = new X509Certificate2(Encoding.ASCII.GetBytes(mod.CERT));
byte[] bytes = Encoding.ASCII.GetBytes(apiKey.Value.Substring(0, 6));
string signature = apiKey.Value.Substring(6);
byte[] signature2 = (from i in Enumerable.Range(0, signature.Length / 2)
select Convert.ToByte(signature.Substring(i * 2, 2), 16)).ToArray();
mod.active = VerifySignature(bytes, signature2, serverCert);
}
catch (Exception ex)
{
ex.ToString();
}
}
public static bool VerifySignature(byte[] data, byte[] signature, X509Certificate2 serverCert)
{
using (SHA256.Create())
{
using RSA rSA = serverCert.GetRSAPublicKey();
return rSA.VerifyData(data, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}
}
public static bool isDemoFinished()
{
if ((DateTime.UtcNow - instance.dateTimeAwaked).TotalMinutes >= (double)instance.MINUTES)
{
return true;
}
return false;
}
public static bool modIsActivated()
{
return instance.active;
}
}
[HarmonyPatch(typeof(Smelter), "Spawn")]
private class Smelter_Patch
{
private static void Prefix(string ore, ref int stack)
{
if (!(ore == "Wood"))
{
if (Lib.isDemoFinished() && !Lib.modIsActivated())
{
MessageHud.instance.ShowMessage((MessageType)2, "The test period for the Mod 'Dryzler's More Ingots' is over." + Environment.NewLine + "Visit https://dryzlers-mods.com for more information.", 0, (Sprite)null);
}
else if (fixedIngotMultiplier.Value > 0)
{
stack *= fixedIngotMultiplier.Value;
}
else
{
stack += ZNet.instance.GetNrOfPlayers() - 1;
}
}
}
}
private Harmony harmony;
private bool active;
private DateTime dateTimeAwaked;
private static Mod instance;
public static ConfigEntry<string> apiKey { get; private set; }
private string PLUGIN_ID => "com.dryzler.valheim.moreingots";
public string CERT => "-----BEGIN CERTIFICATE-----\r\nMIIB4TCCAYugAwIBAgIUXQJpDzY3TvKHl/GNfcpykCAq5SYwDQYJKoZIhvcNAQEL\r\nBQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM\r\nGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDA2MjAwNjIyNTJaFw00NDA2\r\nMTUwNjIyNTJaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw\r\nHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwXDANBgkqhkiG9w0BAQEF\r\nAANLADBIAkEA1uX7eMY71hwX3AWAcSi8SGiIRnlKEjzqaNEXCo4H5dLPWttHvmP2\r\nXdzFQf/UX78njP+jejL5dPbEqQ0HfsdPAQIDAQABo1MwUTAdBgNVHQ4EFgQUThhx\r\nogoLkFxvkSlne7ePVD/EqY8wHwYDVR0jBBgwFoAUThhxogoLkFxvkSlne7ePVD/E\r\nqY8wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAANBAEXK6FO/kCdaBsfy\r\nR91zWAtQLtT1dLt+CW1UfWBgEzWMS1DJME7lMc+XoUr3J61ThUKFbw7LhNXtKx1E\r\nxMZgMRM=\r\n-----END CERTIFICATE-----\r\n";
private int MINUTES => 10;
public static ConfigEntry<int> fixedIngotMultiplier { get; private set; }
private void Awake()
{
apiKey = ((BaseUnityPlugin)this).Config.Bind<string>("Dryzlers More Ingots", "Dryzlers-Mods-Key", "Get your mod key at https://dryzlers-mods.com", "The mod works for " + MINUTES + " minutes. After that you need a key which you enter here.");
fixedIngotMultiplier = ((BaseUnityPlugin)this).Config.Bind<int>("Dryzlers More Ingots", "Fixed Multiplier", 0, "If you enter a value here, this value will be used instead of number of players.");
Lib.initMod(this);
}
}
}