using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FreeInfusion")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreeInfusion")]
[assembly: AssemblyTitle("FreeInfusion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace FreeInfusion
{
[HarmonyPatch(typeof(InfusionInventoryGenerator), "Generate")]
public static class GeneratePatch
{
private static void Postfix(InfusionInventoryGenerator __instance, ref List<StoreItem> __result)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Expected O, but got Unknown
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
try
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(26, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Generate: game gave ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(__result.Count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" items");
}
logger.LogInfo(val);
Describe(" original", __result);
for (int i = 0; i < 8; i++)
{
StoreItem singleStoreItem = ((StoreInventoryGenerator)__instance).GetSingleStoreItem(__result);
if (singleStoreItem == null)
{
Plugin.Logger.LogInfo((object)" GetSingleStoreItem returned null, stopping");
break;
}
SpellInfusionItem val2 = ((Il2CppObjectBase)singleStoreItem).TryCast<SpellInfusionItem>();
if (val2 != null && AlreadyHas(__result, val2.Element))
{
Plugin.Logger.LogInfo((object)" duplicate element, stopping");
break;
}
__result.Add(singleStoreItem);
ManualLogSource logger2 = Plugin.Logger;
val = new BepInExInfoLogInterpolatedStringHandler(20, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" added extra item #");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(i + 1);
}
logger2.LogInfo(val);
}
ManualLogSource logger3 = Plugin.Logger;
val = new BepInExInfoLogInterpolatedStringHandler(20, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Generate: now ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(__result.Count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" items");
}
logger3.LogInfo(val);
Describe(" final", __result);
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)ex);
}
}
private static bool AlreadyHas(List<StoreItem> list, ElementType element)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < list.Count; i++)
{
SpellInfusionItem val = ((Il2CppObjectBase)list[i]).TryCast<SpellInfusionItem>();
if (val != null && val.Element == element)
{
return true;
}
}
return false;
}
private static void Describe(string label, List<StoreItem> list)
{
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < list.Count; i++)
{
SpellInfusionItem val = ((Il2CppObjectBase)list[i]).TryCast<SpellInfusionItem>();
Plugin.Logger.LogInfo((object)($"{label} [{i}]: " + ((val == null) ? "not a SpellInfusionItem" : $"Element={val.Element}, ConfigNull={(Object)(object)val.Configuration == (Object)null}")));
}
}
}
[BepInPlugin("you.spellbrigade.freeinfusion", "Free Infusion Choice", "1.0.0")]
public class Plugin : BasePlugin
{
internal static ManualLogSource Logger;
public override void Load()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BasePlugin)this).Log;
new Harmony("you.spellbrigade.freeinfusion").PatchAll();
((BasePlugin)this).Log.LogInfo((object)"Free Infusion Choice loaded");
}
}
[HarmonyPatch(typeof(PlayerSeatUpdater), "UpdateSeats")]
public static class SeatUpdatePatch
{
private static void Postfix(PlayerSeatUpdater __instance)
{
SeatLayout.Apply(__instance);
}
}
[HarmonyPatch(typeof(PlayerSeatUpdater), "Start")]
public static class SeatStartPatch
{
private static void Postfix(PlayerSeatUpdater __instance)
{
SeatLayout.Apply(__instance);
}
}
public static class SeatLayout
{
private static readonly Dictionary<int, (Vector3 pos, Vector3 scale)> originals = new Dictionary<int, (Vector3, Vector3)>();
public static void Apply(PlayerSeatUpdater updater)
{
//IL_00ff: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_0230: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_0286: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
//IL_02f3: Expected O, but got Unknown
//IL_031e: Unknown result type (might be due to invalid IL or missing references)
try
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type typeFromHandle = typeof(PlayerSeatUpdater);
if (!((typeFromHandle.GetProperty("seats", bindingAttr)?.GetValue(updater) ?? typeFromHandle.GetField("seats", bindingAttr)?.GetValue(updater)) is IEnumerable enumerable))
{
Plugin.Logger.LogWarning((object)"seats array not found");
return;
}
List<PlayerSeat> list = new List<PlayerSeat>();
foreach (object item in enumerable)
{
PlayerSeat val = (PlayerSeat)((item is PlayerSeat) ? item : null);
if (val != null && (Object)(object)val != (Object)null)
{
list.Add(val);
}
}
if (list.Count == 0)
{
return;
}
foreach (PlayerSeat item2 in list)
{
int instanceID = ((Object)((Component)item2).gameObject).GetInstanceID();
if (!originals.ContainsKey(instanceID))
{
originals[instanceID] = (((Component)item2).transform.position, ((Component)item2).transform.localScale);
}
}
bool num = (Object)(object)SingletonPersistent<NetworkStateMachine>.Instance != (Object)null && SingletonPersistent<NetworkStateMachine>.Instance.IsSolo();
PlayerSeat localPlayerSeat = updater.GetLocalPlayerSeat();
if (!num || (Object)(object)localPlayerSeat == (Object)null)
{
foreach (PlayerSeat item3 in list)
{
(Vector3, Vector3) tuple = originals[((Object)((Component)item3).gameObject).GetInstanceID()];
((Component)item3).transform.position = tuple.Item1;
((Component)item3).transform.localScale = tuple.Item2;
}
return;
}
Vector3 val2 = Vector3.zero;
foreach (PlayerSeat item4 in list)
{
val2 += originals[((Object)((Component)item4).gameObject).GetInstanceID()].pos;
}
val2 /= (float)list.Count;
foreach (PlayerSeat item5 in list)
{
(Vector3, Vector3) tuple2 = originals[((Object)((Component)item5).gameObject).GetInstanceID()];
if (((Object)((Component)item5).gameObject).GetInstanceID() == ((Object)((Component)localPlayerSeat).gameObject).GetInstanceID())
{
((Component)item5).transform.position = val2;
((Component)item5).transform.localScale = tuple2.Item2;
}
else
{
((Component)item5).transform.position = tuple2.Item1;
((Component)item5).transform.localScale = Vector3.zero;
}
}
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(52, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Solo layout applied: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(list.Count);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" seats, centered local seat at ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Vector3>(val2);
}
logger.LogInfo(val3);
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)ex);
}
}
}
}