using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 DSPInfiniteMetadata
{
[BepInPlugin("godvector.dysonsphereprogram.infinitemetadata", "Infinite Metadata", "1.0.1")]
[BepInProcess("DSPGAME.exe")]
public sealed class InfiniteMetadataPlugin : BaseUnityPlugin
{
public const string PluginGuid = "godvector.dysonsphereprogram.infinitemetadata";
public const string PluginName = "Infinite Metadata";
public const string PluginVersion = "1.0.1";
public const long DefaultMetadataAmount = 8000000000000000000L;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<long> MetadataAmount;
private Harmony _harmony;
private void Awake()
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Expected O, but got Unknown
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable effectively unlimited Metadata.");
MetadataAmount = ((BaseUnityPlugin)this).Config.Bind<long>("General", "MetadataAmount", 8000000000000000000L, "Virtual amount returned for Metadata item IDs 6001-6006.");
try
{
_harmony = new Harmony("godvector.dysonsphereprogram.infinitemetadata");
_harmony.PatchAll(typeof(InfiniteMetadataPlugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Infinite Metadata 1.0.1 loaded. MetadataAmount=" + GetMetadataAmount()));
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)"Infinite Metadata could not patch the current DSP build.");
((BaseUnityPlugin)this).Logger.LogError((object)ex);
}
}
private void OnDestroy()
{
if (_harmony != null)
{
_harmony.UnpatchSelf();
}
}
internal static bool IsEnabled()
{
if (Enabled != null)
{
return Enabled.Value;
}
return true;
}
internal static bool IsMetadata(int itemId)
{
if (itemId >= 6001)
{
return itemId <= 6006;
}
return false;
}
internal static long GetMetadataAmount()
{
if (MetadataAmount == null || MetadataAmount.Value <= 0)
{
return 8000000000000000000L;
}
return MetadataAmount.Value;
}
}
[HarmonyPatch]
internal static class GetItemTotalPropertyPatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("PropertySystem");
if (type == null)
{
throw new MissingMemberException("DSP PropertySystem type was not found.");
}
MethodInfo methodInfo = AccessTools.Method(type, "GetItemTotalProperty", new Type[1] { typeof(int) }, (Type[])null);
if (methodInfo == null)
{
throw new MissingMethodException("PropertySystem.GetItemTotalProperty(int) was not found.");
}
if (methodInfo.ReturnType != typeof(long))
{
throw new InvalidOperationException("GetItemTotalProperty return type changed. Expected System.Int64 but found " + methodInfo.ReturnType.FullName + ".");
}
return methodInfo;
}
private static bool Prefix(int __0, ref long __result)
{
if (!InfiniteMetadataPlugin.IsEnabled())
{
return true;
}
if (!InfiniteMetadataPlugin.IsMetadata(__0))
{
return true;
}
__result = InfiniteMetadataPlugin.GetMetadataAmount();
return false;
}
}
[HarmonyPatch]
internal static class GetItemAvaliablePropertyPatch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("PropertySystem");
if (type == null)
{
throw new MissingMemberException("DSP PropertySystem type was not found.");
}
MethodInfo methodInfo = AccessTools.Method(type, "GetItemAvaliableProperty", new Type[2]
{
typeof(long),
typeof(int)
}, (Type[])null);
if (methodInfo == null)
{
throw new MissingMethodException("PropertySystem.GetItemAvaliableProperty(long, int) was not found.");
}
if (methodInfo.ReturnType != typeof(long))
{
throw new InvalidOperationException("GetItemAvaliableProperty return type changed. Expected System.Int64 but found " + methodInfo.ReturnType.FullName + ".");
}
return methodInfo;
}
private static bool Prefix(long __0, int __1, ref long __result)
{
if (!InfiniteMetadataPlugin.IsEnabled())
{
return true;
}
if (!InfiniteMetadataPlugin.IsMetadata(__1))
{
return true;
}
__result = InfiniteMetadataPlugin.GetMetadataAmount();
return false;
}
}
}