using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using DefaultNamespace.ContentEvents;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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]
[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 ArtifactIdFix
{
[ContentWarningPlugin("ElfDevelop.ArtifactIdFix", "1.0.0", false)]
[BepInPlugin("ElfDevelop.ArtifactIdFix", "ArtifactIdFix", "1.0.0")]
public class ArtifactIdFixPlugin : BaseUnityPlugin
{
private const ushort FirstFreeId = 1900;
private static readonly Dictionary<ushort, PropContent> modded = new Dictionary<ushort, PropContent>();
private static int checkedItems = -1;
internal static ManualLogSource Logger { get; private set; } = null;
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
new Harmony("ElfDevelop.ArtifactIdFix").PatchAll(typeof(ArtifactIdFixPlugin));
Logger.LogInfo((object)"ArtifactIdFix 1.0.0 has loaded!");
}
private static void EnsureFixed()
{
List<Item> list = ((DatabaseAsset<ItemDatabase, Item>)(object)SingletonAsset<ItemDatabase>.Instance).Objects.Where((Item i) => (Object)(object)i != (Object)null).ToList();
if (list.Count == checkedItems)
{
return;
}
checkedItems = list.Count;
modded.Clear();
HashSet<PropContent> hashSet = new HashSet<PropContent>(((DatabaseAsset<PropContentDatabase, PropContent>)(object)SingletonAsset<PropContentDatabase>.Instance).Objects.Where((PropContent c) => (Object)(object)c != (Object)null));
HashSet<ushort> hashSet2 = new HashSet<ushort>(hashSet.Select((PropContent c) => c.id));
foreach (Item item in from i in list
where (Object)(object)i.content != (Object)null
orderby i.id
select i)
{
PropContent content = item.content;
if (hashSet.Contains(content) || !content.isArtifact)
{
continue;
}
ushort num = content.id;
if (hashSet2.Contains(num) || num >= 2000 || ContentEventIDMapper.GetContentEventGenerated(num) != null)
{
num = 1900;
while (hashSet2.Contains(num) || ContentEventIDMapper.GetContentEventGenerated(num) != null)
{
num++;
}
Logger.LogInfo((object)$"{item.displayName}: content id {content.id} belongs to another prop, using {num}");
content.id = num;
}
hashSet2.Add(num);
modded[num] = content;
}
}
[HarmonyPatch(typeof(ArtifactContentEvent), "GetID")]
[HarmonyPrefix]
private static void BeforeWritingArtifact()
{
EnsureFixed();
}
[HarmonyPatch(typeof(ContentEventIDMapper), "GetContentEvent")]
[HarmonyPrefix]
[HarmonyPriority(600)]
private static bool ReadModdedArtifact(ushort id, ref ContentEvent __result)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
EnsureFixed();
if (!modded.TryGetValue(id, out PropContent value))
{
return true;
}
__result = (ContentEvent)new ArtifactContentEvent
{
content = value
};
return false;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}