using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.Store;
using FrooxEngine.UIX;
using HarmonyLib;
using SkyFrost.Base;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v10.0", FrameworkDisplayName = ".NET 10.0")]
[assembly: AssemblyCompany("art0007i")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.3.0")]
[assembly: AssemblyInformationalVersion("2.0.3+03688bde11730e3a6abe53130ec0fbd91cb20f1d")]
[assembly: AssemblyProduct("SpecialItemsLib")]
[assembly: AssemblyTitle("SpecialItemsLib")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/art0007i/SpecialItemsLib")]
[assembly: AssemblyVersion("2.0.3.0")]
[module: RefSafetyRules(11)]
namespace SpecialItemsLib;
public class CustomSpecialItem
{
private Uri? Uri;
internal ConfigEntry<string?> UriConfig;
[field: CompilerGenerated]
public SpecialItemType ItemType
{
[CompilerGenerated]
get;
}
[field: CompilerGenerated]
public string ReadableName
{
[CompilerGenerated]
get;
[CompilerGenerated]
set;
}
public Uri? ItemUri
{
get
{
return Uri;
}
set
{
Uri = value;
UriConfig.Value = ((object)value)?.ToString();
}
}
internal CustomSpecialItem(int type, string readableName, ConfigEntry<string?> config)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
UriConfig = config;
ReadableName = readableName;
ItemType = (SpecialItemType)type;
Uri uri = default(Uri);
if (Uri.TryCreate(UriConfig.Value, (UriKind)1, ref uri))
{
Uri = uri;
}
else
{
Uri = null;
}
}
}
[ResonitePlugin("art0007i.SpecialItemsLib", "SpecialItemsLib", "2.0.3", "art0007i", "https://github.com/art0007i/SpecialItemsLib")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class SpecialItemsLib : BasePlugin
{
[HarmonyPatch(typeof(InventoryBrowser))]
private class InventoryBrowser_ChangeEvents_Patch
{
[HarmonyPostfix]
[HarmonyPatch("ProcessItem")]
public static void PostProcess(InventoryItemUI item)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
Record val = (Record)AccessTools.Field(((object)item).GetType(), "Item").GetValue((object)item);
if (val == null)
{
return;
}
Uri url = val.GetUrl(((SkyFrostInterface)((Worker)item).Cloud).Platform);
if (url == (Uri)null)
{
return;
}
SpecialItemType val2 = InventoryBrowser.ClassifyItem(item);
Enumerator<string, CustomSpecialItem> enumerator = CustomItems.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
KeyValuePair<string, CustomSpecialItem> current = enumerator.Current;
if ((int)current.Value.ItemType != 0 && val2 == current.Value.ItemType && url == current.Value.ItemUri)
{
((SyncField<colorX>)(object)((BrowserItem)item).NormalColor).Value = InventoryBrowser.FAVORITE_COLOR;
Sync<colorX> selectedColor = ((BrowserItem)item).SelectedColor;
colorX fAVORITE_COLOR = InventoryBrowser.FAVORITE_COLOR;
((SyncField<colorX>)(object)selectedColor).Value = ((colorX)(ref fAVORITE_COLOR)).MulA(2f);
break;
}
}
}
finally
{
((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
}
}
[HarmonyPostfix]
[HarmonyPatch("OnAwake")]
public static void PostAwake(InventoryBrowser __instance)
{
ActiveBrowsers.Add(__instance);
}
[HarmonyPostfix]
[HarmonyPatch("OnDispose")]
public static void PostDispose(InventoryBrowser __instance)
{
ActiveBrowsers.Remove(__instance);
}
}
[HarmonyPatch(typeof(InventoryBrowser), "ClassifyItem")]
private class InventoryBrowser_ClassifyItem_Patch
{
public static void Postfix(InventoryItemUI? itemui, ref SpecialItemType __result)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Expected I4, but got Unknown
if (__result || itemui == null)
{
return;
}
Record val = (Record)AccessTools.Field(((object)itemui).GetType(), "Item").GetValue((object)itemui);
if (val == null || val.Tags == null)
{
return;
}
Enumerator<string, CustomSpecialItem> enumerator = CustomItems.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
KeyValuePair<string, CustomSpecialItem> current = enumerator.Current;
if ((int)current.Value.ItemType != 0 && val.Tags.Contains(current.Key))
{
__result = (SpecialItemType)(int)current.Value.ItemType;
}
}
}
finally
{
((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
}
}
}
[HarmonyPatch(typeof(InventoryBrowser), "OnItemSelected")]
private class InventoryBrowser_OnItemSelected_Patch
{
public static void Prefix(InventoryBrowser __instance, out SpecialItemType __state)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected I4, but got Unknown
__state = (SpecialItemType)(int)((SyncField<SpecialItemType>)(object)(AccessTools.Field(typeof(InventoryBrowser), "_lastSpecialItemType").GetValue((object)__instance) as Sync<SpecialItemType>)).Value;
}
public unsafe static void Postfix(InventoryBrowser __instance, BrowserItem currentItem, SpecialItemType __state)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Expected O, but got Unknown
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Expected O, but got Unknown
SpecialItemType val = InventoryBrowser.ClassifyItem((InventoryItemUI)(object)((currentItem is InventoryItemUI) ? currentItem : null));
Slot val2 = (AccessTools.Field(typeof(InventoryBrowser), "_buttonsRoot").GetValue((object)__instance) as SyncRef<Slot>).Target[0];
Log.LogDebug((object)("Classified item is " + ((object)(*(SpecialItemType*)(&val))/*cast due to .constrained prefix*/).ToString()));
if (__state == val)
{
return;
}
Dictionary<string, CustomSpecialItem> customItems = CustomItems;
Log.LogDebug((object)customItems.Count);
Enumerator<string, CustomSpecialItem> enumerator = customItems.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
KeyValuePair<string, CustomSpecialItem> item = enumerator.Current;
Log.LogDebug((object)("checking against " + ((object)item.Value.ItemType/*cast due to .constrained prefix*/).ToString()));
if ((int)item.Value.ItemType == 0 || val != item.Value.ItemType)
{
continue;
}
UIBuilder val3 = new UIBuilder(val2, (Slot)null);
val3.Style.PreferredWidth = BrowserDialog.DEFAULT_ITEM_SIZE * 3;
RadiantUI_Constants.SetupDefaultStyle(val3, false);
colorX purple = colorX.Purple;
colorX white = colorX.White;
MathX.Lerp(ref purple, ref white, 0.5f, (ColorProfileAwareOperation)0);
Button but = val3.Button(Inspector.Pin, LocaleString.op_Implicit("Set " + item.Value.ReadableName));
((Component)but).Slot.OrderOffset = -1L;
but.LocalPressed += (ButtonEventHandler)delegate
{
object value = AccessTools.Field(typeof(InventoryItemUI), "Item").GetValue((object)__instance.SelectedInventoryItem);
Uri val4 = ((Record)((value is Record) ? value : null)).GetUrl(((SkyFrostInterface)((Worker)but).Cloud).Platform);
if (item.Value.ItemUri == val4)
{
val4 = null;
}
item.Value.ItemUri = val4;
config.Save();
RefreshItems();
};
break;
}
}
finally
{
((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
}
}
}
internal static ManualLogSource Log;
internal static ConfigFile config;
internal static Dictionary<string, CustomSpecialItem> customItems = new Dictionary<string, CustomSpecialItem>();
private static int CurrentSpecialItem = 20;
private static readonly List<InventoryBrowser> ActiveBrowsers = new List<InventoryBrowser>();
public static Dictionary<string, CustomSpecialItem> CustomItems => customItems;
public override void Load()
{
Log = ((BasePlugin)this).Log;
config = ((BasePlugin)this).Config;
((BasePlugin)this).HarmonyInstance.PatchAll();
}
public static void RefreshItems()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
Enumerator<InventoryBrowser> enumerator = ActiveBrowsers.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
InventoryBrowser browser = enumerator.Current;
if (((BrowserDialog)browser).CanInteract(((Worker)browser).LocalUser))
{
((ComponentBase<Component>)(object)browser).RunSynchronously((Action)delegate
{
((MethodBase)AccessTools.Method(typeof(InventoryBrowser), "ReprocessItems", (global::System.Type[])null, (global::System.Type[])null)).Invoke((object)browser, (object[])null);
}, false);
}
}
}
finally
{
((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
}
}
public static CustomSpecialItem RegisterItem(string item_tag, string readable_name)
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Expected O, but got Unknown
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Expected O, but got Unknown
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Expected O, but got Unknown
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Expected O, but got Unknown
if (config == null)
{
throw new global::System.Exception("Tried to register special item before SpecialItemsLib was initialized. Make sure you've specified the correct BepInDependency attribute on your mod.");
}
Dictionary<string, CustomSpecialItem> val = CustomItems;
bool flag = default(bool);
CustomSpecialItem result = default(CustomSpecialItem);
if (val.TryGetValue(item_tag, ref result))
{
ManualLogSource log = Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(64, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Tried to register '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item_tag);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' special item twice, this should not happen.");
}
log.LogWarning(val2);
return result;
}
Enumerator<ConfigDefinition, string> enumerator = Traverse.Create((object)config).Property<Dictionary<ConfigDefinition, string>>("OrphanedEntries", (object[])null).Value.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
KeyValuePair<ConfigDefinition, string> current = enumerator.Current;
ManualLogSource log2 = Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(16, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("PRphan -> $");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<ConfigDefinition>(current.Key);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" == $");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(current.Value);
}
log2.LogWarning(val2);
}
}
finally
{
((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
}
ConfigEntry<string> val3 = config.Bind<string>("Items", item_tag, (string)null, "The uri for your custom " + readable_name);
Uri val4 = default(Uri);
if (val3.Value != null && !Uri.TryCreate(val3.Value, (UriKind)1, ref val4))
{
ManualLogSource log3 = Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(47, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Config for ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item_tag);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" contains invalid uri '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val3.Value);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("', resetting.");
}
log3.LogWarning(val2);
val3.Value = null;
}
ManualLogSource log4 = Log;
BepInExDebugLogInterpolatedStringHandler val5 = new BepInExDebugLogInterpolatedStringHandler(20, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Config value for ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(item_tag);
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" = ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(val3.Value);
}
log4.LogDebug(val5);
result = new CustomSpecialItem(CurrentSpecialItem++, readable_name, val3);
val.Add(item_tag, result);
ManualLogSource log5 = Log;
val5 = new BepInExDebugLogInterpolatedStringHandler(41, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("adding new item ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(readable_name);
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" (");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(item_tag);
((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(") with special item id ");
((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(CurrentSpecialItem - 1);
}
log5.LogDebug(val5);
Log.LogDebug((object)("Special items count " + CustomItems.Count));
return result;
}
}
public static class PluginMetadata
{
public const string GUID = "art0007i.SpecialItemsLib";
public const string NAME = "SpecialItemsLib";
public const string VERSION = "2.0.3";
public const string AUTHORS = "art0007i";
public const string REPOSITORY_URL = "https://github.com/art0007i/SpecialItemsLib";
}