using System;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using REPOPortalsMod;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[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]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.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;
}
}
}
[BepInPlugin("com.ZeroTails.PortalGun", "Portal Gun", "0.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class PortalGun : BaseUnityPlugin
{
internal static bool nextPortalIsPortal1 = true;
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("com.ZeroTails.PortalGun");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Portal Gun Mod initialized!");
}
}
[HarmonyPatch(typeof(ItemGun), "ShootRPC")]
public class ItemGunShootPatch
{
private static void Postfix(ItemGun __instance)
{
ItemAttributes component = ((Component)__instance).GetComponent<ItemAttributes>();
if (!((Object)(object)component != (Object)null) || !(component.itemAssetName == "PortalGun"))
{
return;
}
REPOPortalsMod instance = REPOPortalsMod.Instance;
if ((Object)(object)instance == (Object)null)
{
Debug.LogError((object)"REPOPortals mod instance not found.");
return;
}
Type nestedType = typeof(REPOPortalsMod).GetNestedType("PlayerControllerPatches", BindingFlags.NonPublic);
if (nestedType == null)
{
Debug.LogError((object)"PlayerControllerPatches class not found in REPOPortals mod.");
return;
}
MethodInfo method = nestedType.GetMethod("PlacePortal", BindingFlags.Static | BindingFlags.NonPublic);
if (method == null)
{
Debug.LogError((object)"PlacePortal method not found in PlayerControllerPatches.");
return;
}
PlayerController val = Object.FindObjectOfType<PlayerController>();
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)"PlayerController not found in the scene.");
return;
}
int num = (PortalGun.nextPortalIsPortal1 ? 1 : 2);
method.Invoke(null, new object[4] { num, val, 0.4f, 3f });
PortalGun.nextPortalIsPortal1 = !PortalGun.nextPortalIsPortal1;
}
}
[HarmonyPatch(typeof(ItemGunBullet), "ActivateAll")]
public class ItemGunBulletActivateAllPatch
{
private static void Postfix(ItemGunBullet __instance)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: 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_0049: Unknown result type (might be due to invalid IL or missing references)
ItemAttributes componentInParent = ((Component)__instance).GetComponentInParent<ItemAttributes>();
if ((Object)(object)componentInParent != (Object)null && componentInParent.itemAssetName == "PortalGun")
{
Vector3 hitPosition = __instance.hitPosition;
Vector3 forward = ((Component)__instance).transform.forward;
if (PortalGun.nextPortalIsPortal1)
{
CreatePortal1(hitPosition, forward);
}
else
{
CreatePortal2(hitPosition, forward);
}
PortalGun.nextPortalIsPortal1 = !PortalGun.nextPortalIsPortal1;
}
}
private static void CreatePortal1(Vector3 position, Vector3 normal)
{
//IL_0045: 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_0047: Unknown result type (might be due to invalid IL or missing references)
GameObject memberValue = ReflectionUtils.GetMemberValue<GameObject>("portal1Instance");
GameObject memberValue2 = ReflectionUtils.GetMemberValue<GameObject>("portalPrefab");
if ((Object)(object)memberValue != (Object)null)
{
Object.Destroy((Object)(object)memberValue);
}
if ((Object)(object)memberValue2 == (Object)null)
{
throw new NullReferenceException("Portal prefab is null. Ensure the REPOPortals mod is properly loaded.");
}
GameObject val = Object.Instantiate<GameObject>(memberValue2, position, Quaternion.LookRotation(normal));
ReflectionUtils.SetMemberValue<GameObject>("portal1Instance", val);
ReflectionUtils.SetMemberValue("portal1Placed", value: true);
ReflectionUtils.SetMemberValue<BoxCollider>("portal1Collider", val.GetComponentInChildren<BoxCollider>(true));
}
private static void CreatePortal2(Vector3 position, Vector3 normal)
{
//IL_0045: 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_0047: Unknown result type (might be due to invalid IL or missing references)
GameObject memberValue = ReflectionUtils.GetMemberValue<GameObject>("portal2Instance");
GameObject memberValue2 = ReflectionUtils.GetMemberValue<GameObject>("portalPrefab");
if ((Object)(object)memberValue != (Object)null)
{
Object.Destroy((Object)(object)memberValue);
}
if ((Object)(object)memberValue2 == (Object)null)
{
throw new NullReferenceException("Portal prefab is null. Ensure the REPOPortals mod is properly loaded.");
}
GameObject val = Object.Instantiate<GameObject>(memberValue2, position, Quaternion.LookRotation(normal));
ReflectionUtils.SetMemberValue<GameObject>("portal2Instance", val);
ReflectionUtils.SetMemberValue("portal2Placed", value: true);
ReflectionUtils.SetMemberValue<BoxCollider>("portal2Collider", val.GetComponentInChildren<BoxCollider>(true));
}
}
public static class ReflectionUtils
{
private static readonly Dictionary<string, MemberInfo> MemberCache = new Dictionary<string, MemberInfo>();
public static T GetMemberValue<T>(string memberName)
{
if (!IsAllowedMember(memberName))
{
Debug.LogWarning((object)("ReflectionUtils: Access to member '" + memberName + "' is not allowed."));
throw new ArgumentException("Access to member '" + memberName + "' is not allowed.");
}
if (!MemberCache.TryGetValue(memberName, out MemberInfo value))
{
value = (MemberInfo)(((object)typeof(REPOPortalsMod).GetField(memberName, BindingFlags.Static | BindingFlags.NonPublic)) ?? ((object)typeof(REPOPortalsMod).GetProperty(memberName, BindingFlags.Static | BindingFlags.Public)));
if (value == null)
{
Debug.LogError((object)("ReflectionUtils: Member '" + memberName + "' not found in REPOPortalsMod.REPOPortalsMod."));
throw new MissingMemberException("Member '" + memberName + "' not found in REPOPortalsMod.REPOPortalsMod.");
}
MemberCache[memberName] = value;
}
try
{
if (1 == 0)
{
}
T result;
if (!(value is FieldInfo fieldInfo))
{
if (!(value is PropertyInfo propertyInfo))
{
throw new InvalidOperationException("ReflectionUtils: Unsupported member type for '" + memberName + "'.");
}
result = (T)propertyInfo.GetValue(null);
}
else
{
result = (T)fieldInfo.GetValue(null);
}
if (1 == 0)
{
}
return result;
}
catch (InvalidCastException)
{
Debug.LogError((object)$"ReflectionUtils: Failed to cast member '{memberName}' to type '{typeof(T)}'.");
throw;
}
}
public static void SetMemberValue<T>(string memberName, T value)
{
if (!IsAllowedMember(memberName))
{
Debug.LogWarning((object)("ReflectionUtils: Access to member '" + memberName + "' is not allowed."));
return;
}
if (!MemberCache.TryGetValue(memberName, out MemberInfo value2))
{
value2 = (MemberInfo)(((object)typeof(REPOPortalsMod).GetField(memberName, BindingFlags.Static | BindingFlags.NonPublic)) ?? ((object)typeof(REPOPortalsMod).GetProperty(memberName, BindingFlags.Static | BindingFlags.Public)));
if (value2 == null)
{
Debug.LogError((object)("ReflectionUtils: Member '" + memberName + "' not found in REPOPortalsMod.REPOPortalsMod."));
return;
}
MemberCache[memberName] = value2;
}
MemberInfo memberInfo = value2;
MemberInfo memberInfo2 = memberInfo;
if (!(memberInfo2 is FieldInfo fieldInfo))
{
if (memberInfo2 is PropertyInfo propertyInfo && propertyInfo.CanWrite)
{
propertyInfo.SetValue(null, value);
}
else
{
Debug.LogError((object)("ReflectionUtils: Cannot set value for member '" + memberName + "'."));
}
}
else
{
fieldInfo.SetValue(null, value);
}
}
private static bool IsAllowedMember(string memberName)
{
HashSet<string> hashSet = new HashSet<string> { "portal1Instance", "portal2Instance", "portalPrefab", "portal1Placed", "portal2Placed", "portal1Collider", "portal2Collider" };
return hashSet.Contains(memberName);
}
}