using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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 BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ScaleTheseNuts.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ScaleTheseNuts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("ScaleTheseNuts")]
[assembly: AssemblyTitle("ScaleTheseNuts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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.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;
}
}
}
namespace ScaleTheseNuts
{
internal class Conf
{
private static ConfigEntry<bool> _enableUpgradeCostMultiplier;
public static bool EnableUpgradeCostMultiplier
{
get
{
return _enableUpgradeCostMultiplier.Value;
}
set
{
_enableUpgradeCostMultiplier.Value = value;
}
}
public static void Initialize(ConfigFile _Config)
{
_enableUpgradeCostMultiplier = _Config.Bind<bool>("General", "Enable Upgrade Cost Multiplier", true, "Sets the costs of upgrades to be multiplied by the number of players in the game.");
}
}
[Flags]
public enum LogLevel
{
None = 0,
Fatal = 1,
Error = 2,
Warning = 4,
Message = 8,
Info = 0x10,
Debug = 0x20,
All = 0x3F
}
[StructLayout(LayoutKind.Sequential, Size = 1)]
public struct Log
{
public static void Fatal(string message)
{
LogInternal(LogLevel.Fatal, message);
}
public static void Error(string message)
{
LogInternal(LogLevel.Error, message);
}
public static void Error(Exception exception)
{
LogInternal(LogLevel.Error, exception.ToString());
}
public static void Warning(string message)
{
LogInternal(LogLevel.Warning, message);
}
public static void Message(string message)
{
LogInternal(LogLevel.Message, message);
}
public static void Info(string message)
{
LogInternal(LogLevel.Info, message);
}
public static void Debug(string message)
{
LogInternal(LogLevel.Debug, message);
}
private static void LogInternal(LogLevel level, string message)
{
string message2 = DateTime.Now.ToString(CultureInfo.InvariantCulture) + ": " + message;
BepInExLog(level, message2);
}
private static void BepInExLog(LogLevel level, string message)
{
switch (level)
{
case LogLevel.Debug:
ScaleTheseNuts.logger.Log((LogLevel)32, (object)message);
break;
case LogLevel.Message:
ScaleTheseNuts.logger.Log((LogLevel)8, (object)message);
break;
case LogLevel.Warning:
ScaleTheseNuts.logger.Log((LogLevel)4, (object)message);
break;
case LogLevel.Error:
ScaleTheseNuts.logger.Log((LogLevel)2, (object)message);
break;
case LogLevel.Fatal:
ScaleTheseNuts.logger.Log((LogLevel)1, (object)message);
break;
default:
ScaleTheseNuts.logger.Log((LogLevel)16, (object)message);
break;
}
}
}
[BepInPlugin("com.stoopwaffle.repo.scalethesenuts", "ScaleTheseNuts", "1.0.2")]
internal sealed class ScaleTheseNuts : BaseUnityPlugin
{
private const string Guid = "com.stoopwaffle.repo.scalethesenuts";
public const string Name = "ScaleTheseNuts";
public const string Version = "1.0.2";
private const string LogName = "ScaleTheseNuts";
private Harmony harmony = new Harmony("com.stoopwaffle.repo.scalethesenuts");
internal static readonly ManualLogSource logger = Logger.CreateLogSource("ScaleTheseNuts");
private void Awake()
{
Conf.Initialize(((BaseUnityPlugin)this).Config);
harmony.PatchAll(typeof(PatchUpgradeCost));
Log.Info("ScaleTheseNuts initialized.");
}
}
}
namespace ScaleTheseNuts.Patches
{
[HarmonyPatch]
public class PatchUpgradeCost
{
private static readonly FieldInfo ItemAttributesValueField = AccessTools.Field(typeof(ItemAttributes), "value");
[HarmonyTranspiler]
[HarmonyPatch(typeof(ItemAttributes), "GetValue")]
private static IEnumerable<CodeInstruction> ItemAttributes_GetValue_Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Stfld, (object)ItemAttributesValueField, (string)null)
}).Repeat((Action<CodeMatcher>)delegate(CodeMatcher matcher)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
matcher.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null)
}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Action<ItemAttributes>>((Action<ItemAttributes>)HandleMultiplyUpgradeCost) });
}, (Action<string>)null).InstructionEnumeration();
}
private static void HandleMultiplyUpgradeCost(ItemAttributes attributes)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
if ((int)attributes.itemType == 3 && Conf.EnableUpgradeCostMultiplier)
{
int count = SemiFunc.PlayerGetAll().Count;
if (count > 1)
{
int value = attributes.value;
attributes.value *= count;
Log.Info($"Multiplied cost of ({attributes.itemName}) from {value} to {attributes.value}");
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(StatsManager), "AddItemsUpgradesPurchased")]
private static bool StatsManager_AddItemsUpgradesPurchased_Postfix(StatsManager __instance, string itemName)
{
if (!Conf.EnableUpgradeCostMultiplier)
{
return true;
}
int count = SemiFunc.PlayerGetAll().Count;
if (count > 1)
{
Dictionary<string, int> itemsUpgradesPurchased = __instance.itemsUpgradesPurchased;
int num = itemsUpgradesPurchased[itemName];
itemsUpgradesPurchased[itemName] = num + count;
Log.Info($"Adding {count} to itemsUpgradesPurchased for {itemName} (instead of the default 1).");
return false;
}
return true;
}
}
}