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.Bootstrap;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Hook;
using DropServer.VanityItems;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.Runtime;
using Il2CppSystem.Collections.Generic;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AllVanity")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyProduct("AllVanity")]
[assembly: AssemblyTitle("AllVanity")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace AllVanity;
[BepInPlugin("dev.aurirex.gtfo.allvanity", "All Vanity", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInIncompatibility("com.mccad00.AmongDrip")]
public class EntryPoint : BasePlugin
{
public const string GUID = "dev.aurirex.gtfo.allvanity";
public const string NAME = "All Vanity";
public const string VERSION = "1.1.0";
public const string DEVIOUSLICK_GUID = "com.mccad00.AmongDrip";
public const string NOBOOSTERS_GUID = "dev.aurirex.gtfo.noboosters";
private Harmony _harmonyInstance;
internal static ManualLogSource L;
internal static bool noboostersLoaded = false;
internal static string hexColorUnlocked = "faa";
public override void Load()
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
L = ((BasePlugin)this).Log;
noboostersLoaded = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.Any((KeyValuePair<string, PluginInfo> kvp) => kvp.Key == "dev.aurirex.gtfo.noboosters");
if (noboostersLoaded)
{
((BasePlugin)this).Log.LogInfo((object)"NoBoosters is installed, harmony patching ...");
_harmonyInstance = new Harmony("dev.aurirex.gtfo.allvanity");
_harmonyInstance.PatchAll(typeof(Patches.PersistentInventoryManager_CommitPendingTransactions_Patch));
}
else
{
((BasePlugin)this).Log.LogInfo((object)"NoBoosters is NOT installed, native patching ...");
NativePatches.ApplyNative();
}
}
}
internal class NativePatches
{
public unsafe delegate void UpdateItems(IntPtr _this, IntPtr data, Il2CppMethodInfo* methodInfo);
private static readonly List<INativeDetour> _detours = new List<INativeDetour>();
private static UpdateItems _originalUpdateItems;
public unsafe static void* GetIl2CppMethod<T>(string methodName, string returnTypeName, bool isGeneric, params string[] argTypes) where T : Il2CppObjectBase
{
void** ptr = (void**)IL2CPP.GetIl2CppMethod(Il2CppClassPointerStore<T>.NativeClassPtr, isGeneric, methodName, returnTypeName, argTypes).ToPointer();
if (ptr == null)
{
return ptr;
}
return *ptr;
}
internal unsafe static void ApplyNative()
{
_detours.Add(INativeDetour.CreateAndApply<UpdateItems>((IntPtr)(nint)NativePatches.GetIl2CppMethod<VanityItemInventory>("UpdateItems", "System.Void", isGeneric: false, new string[1] { "VanityItemPlayerData" }), (UpdateItems)UpdateItemsPatch, ref _originalUpdateItems));
}
public unsafe static void UpdateItemsPatch(IntPtr self, IntPtr vanityItemPlayerData, Il2CppMethodInfo* methodInfo)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
VanityItemInventory val = new VanityItemInventory(self);
_originalUpdateItems(self, vanityItemPlayerData, methodInfo);
List<uint> list = new List<uint>();
if (val.m_backednItems == null)
{
val.m_backednItems = new List<VanityItem>(0);
}
Enumerator<VanityItem> enumerator = val.m_backednItems.GetEnumerator();
while (enumerator.MoveNext())
{
VanityItem current = enumerator.Current;
list.Add(current.id);
}
foreach (VanityItemsTemplateDataBlock allBlock in GameDataBlockBase<VanityItemsTemplateDataBlock>.GetAllBlocks())
{
if (allBlock != null && !list.Contains(((GameDataBlockBase<VanityItemsTemplateDataBlock>)(object)allBlock).persistentID))
{
VanityItem val2 = new VanityItem(ClassInjector.DerivedConstructorPointer<VanityItem>());
val2.publicName = $"<#{EntryPoint.hexColorUnlocked}>{allBlock.publicName}</color>";
val2.type = allBlock.type;
val2.prefab = allBlock.prefab;
val2.flags = (VanityItemFlags)3;
val2.id = ((GameDataBlockBase<VanityItemsTemplateDataBlock>)(object)allBlock).persistentID;
val.m_backednItems.Add(val2);
}
}
}
}
internal class Patches
{
[HarmonyPriority(500)]
[HarmonyPatch(typeof(PersistentInventoryManager), "CommitPendingTransactions")]
internal static class PersistentInventoryManager_CommitPendingTransactions_Patch
{
public static bool Prefix()
{
if (PersistentInventoryManager.m_dirty)
{
Unlock.SetupVanityInventory();
PersistentInventoryManager.m_dirty = false;
return false;
}
return true;
}
}
}
public class Unlock
{
public static void SetupVanityInventory()
{
EntryPoint.L.LogWarning((object)"Setting up Vanity Item Inventory!");
PersistentInventoryManager.Current.m_vanityItemsInventory.UpdateItems(CreateVanityPlayerData());
}
internal static VanityItemPlayerData CreateVanityPlayerData()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
VanityItemPlayerData val = new VanityItemPlayerData(ClassInjector.DerivedConstructorPointer<VanityItemPlayerData>());
Il2CppArrayBase<VanityItemsTemplateDataBlock> allBlocks = GameDataBlockBase<VanityItemsTemplateDataBlock>.GetAllBlocks();
Il2CppReferenceArray<VanityItem> val2 = new Il2CppReferenceArray<VanityItem>((long)allBlocks.Count);
int num = 0;
foreach (VanityItemsTemplateDataBlock item in allBlocks)
{
VanityItem val3 = new VanityItem(ClassInjector.DerivedConstructorPointer<VanityItem>())
{
Flags = (InventoryItemFlags)3,
ItemId = ((GameDataBlockBase<VanityItemsTemplateDataBlock>)(object)item).persistentID
};
((Il2CppArrayBase<VanityItem>)(object)val2)[num] = val3;
num++;
}
val.Items = val2;
return val;
}
}