using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PiUtils.Util;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("pi_utils")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0+a912d6e1dd94c2c53ba6e48bdfe6661b81fb9348")]
[assembly: AssemblyProduct("Pi Utils")]
[assembly: AssemblyTitle("pi_utils")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace PiUtils
{
public class ModConfig
{
private static ConfigEntry<bool> modEnabled;
private static ConfigEntry<bool> debugMode;
private static ConfigEntry<bool> gizmoEnabled;
private static ConfigEntry<bool> debugLineEnabled;
private static ConfigEntry<bool> traceLogEnabled;
public static void Init(ConfigFile config)
{
modEnabled = config.Bind<bool>("General", "Enabled", true, "Enable mod");
debugMode = config.Bind<bool>("Debug", "Debug Mode", false, "Enable debug mode");
gizmoEnabled = config.Bind<bool>("Debug", "Gizmo Enabled", false, "Enable gizmos");
debugLineEnabled = config.Bind<bool>("Debug", "Debug Line Enabled", false, "Enable debug lines");
traceLogEnabled = config.Bind<bool>("Debug", "Trace Log Enabled", false, "Enable trace logs");
}
public static bool ModEnabled()
{
return modEnabled.Value;
}
public static bool GizmoEnabled()
{
if (debugMode.Value)
{
return gizmoEnabled.Value;
}
return false;
}
public static bool DebugEnabled()
{
return debugMode.Value;
}
public static bool DebugLineEnabled()
{
if (debugMode.Value)
{
return debugLineEnabled.Value;
}
return false;
}
public static bool TraceLogEnabled()
{
if (debugMode.Value)
{
return traceLogEnabled.Value;
}
return false;
}
}
[BepInPlugin("de.xenira.pi_utils", "Pi Utils", "0.4.0")]
public class PiUtils : BaseUnityPlugin
{
public static string gameExePath = Process.GetCurrentProcess().MainModule.FileName;
public static string gamePath = Path.GetDirectoryName(gameExePath);
private void Awake()
{
PluginLogger logger = PluginLogger.GetLogger<PiUtils>();
logger.LogInfo("Loading plugin pi_utils version 0.4.0...");
License.LogLicense(logger, "Xenira", "pi_utils", "0.4.0");
ModConfig.Init(((BaseUnityPlugin)this).Config);
if (!ModConfig.ModEnabled())
{
logger.LogInfo("Mod is disabled, skipping...");
return;
}
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
logger.LogInfo("Plugin pi_utils is loaded!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "pi_utils";
public const string PLUGIN_NAME = "Pi Utils";
public const string PLUGIN_VERSION = "0.4.0";
}
}
namespace PiUtils.Input
{
public class BitState
{
public long state;
private long initialState;
private long nextNewFlag = 1L;
public long GetNextFlag()
{
long result = nextNewFlag;
nextNewFlag <<= 1;
return result;
}
internal void reset()
{
state = initialState;
}
public void setState(long newState)
{
state = newState;
}
public void addState(long newState)
{
state |= newState;
}
public void removeState(long newState)
{
state &= ~newState;
}
public void toggleState(long newState)
{
state ^= newState;
}
public bool hasState(long newState)
{
return (state & newState) != 0;
}
public bool isState(long newState)
{
return state == newState;
}
}
}
namespace PiUtils.Util
{
public class Async
{
public static IEnumerator Timeout(Action callback, float seconds)
{
yield return (object)new WaitForSeconds(seconds);
callback();
}
public static IEnumerator TimeoutFrames(Action callback, int frames)
{
for (int i = 0; i < frames; i++)
{
yield return (object)new WaitForEndOfFrame();
}
callback();
}
public static IEnumerator Interval(Action callback, float seconds, float startInSeconds, int? cnt = null)
{
yield return (object)new WaitForSeconds((startInSeconds < 0f) ? seconds : startInSeconds);
while (true)
{
callback();
if (cnt.HasValue)
{
int? num = cnt - 1;
cnt = num;
if (num <= 0)
{
break;
}
}
yield return (object)new WaitForSeconds(seconds);
}
}
public static IEnumerator IntervalFrames(Action callback, int frames, int startInFrames, int? cnt = null)
{
for (int j = 0; j < startInFrames; j++)
{
yield return (object)new WaitForEndOfFrame();
}
while (true)
{
callback();
if (cnt.HasValue)
{
int? num = cnt - 1;
cnt = num;
if (num <= 0)
{
break;
}
}
for (int j = 0; j < frames; j++)
{
yield return (object)new WaitForEndOfFrame();
}
}
}
public static IEnumerator DelayUntilSet<T>(Action callback, T value)
{
yield return (object)new WaitUntil((Func<bool>)(() => value != null));
callback();
}
public static IEnumerator DelayUntil(IEnumerator condition, Action callback)
{
while (!condition.MoveNext())
{
yield return null;
}
callback();
}
public static IEnumerator DelayUntil(Action callback, Func<bool> condition)
{
yield return (object)new WaitUntil(condition);
callback();
}
}
public class AsyncGameObject : MonoBehaviour
{
private static PluginLogger Logger = PluginLogger.GetLogger<AsyncGameObject>();
private static AsyncGameObject instance;
private static AsyncGameObject Instance
{
get
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)instance == (Object)null)
{
instance = new GameObject("AsyncGameObject").AddComponent<AsyncGameObject>();
}
return instance;
}
}
private void Awake()
{
if ((Object)(object)instance != (Object)null)
{
Logger.LogError("AsyncGameObject already exists, destroying this one");
Object.Destroy((Object)(object)this);
}
else
{
instance = this;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
}
}
public static Coroutine Timeout(Action callback, float seconds)
{
return Instance.timeout(callback, seconds);
}
private Coroutine timeout(Action callback, float seconds)
{
return ((MonoBehaviour)this).StartCoroutine(Async.Timeout(callback, seconds));
}
public static Coroutine TimeoutFrames(Action callback, int frames)
{
return Instance.timeoutFrames(callback, frames);
}
public static Coroutine NextFrame(Action callback)
{
return Instance.timeoutFrames(callback, 1);
}
private Coroutine timeoutFrames(Action callback, int frames)
{
return ((MonoBehaviour)this).StartCoroutine(Async.TimeoutFrames(callback, frames));
}
public static Coroutine Interval(Action callback, float seconds, float startInSeconds, int? cnt = null)
{
return Instance.interval(callback, seconds, startInSeconds, cnt);
}
private Coroutine interval(Action callback, float seconds, float startInSeconds, int? cnt = null)
{
return ((MonoBehaviour)this).StartCoroutine(Async.Interval(callback, seconds, startInSeconds, cnt));
}
public static Coroutine DelayUntilSet<T>(Action callback, T value)
{
return Instance.delayUntilSet(callback, value);
}
private Coroutine delayUntilSet<T>(Action callback, T value)
{
return ((MonoBehaviour)this).StartCoroutine(Async.DelayUntilSet(callback, value));
}
public static Coroutine DelayUntil(Action callback, Func<bool> condition)
{
return Instance.delayUntil(callback, condition);
}
private Coroutine delayUntil(Action callback, Func<bool> condition)
{
return ((MonoBehaviour)this).StartCoroutine(Async.DelayUntil(callback, condition));
}
public static void Cancel(Coroutine coroutine)
{
Instance.cancel(coroutine);
}
private void cancel(Coroutine coroutine)
{
if (coroutine != null)
{
((MonoBehaviour)this).StopCoroutine(coroutine);
}
}
}
public class Callbacks
{
public static Action<T> Debounce<T>(Action<T> callback, float seconds)
{
Coroutine timeout = null;
T lastValue;
return delegate(T arg)
{
lastValue = arg;
if (timeout == null)
{
timeout = AsyncGameObject.Timeout(delegate
{
timeout = null;
callback(lastValue);
}, seconds);
}
};
}
public static Action<T> Unique<T>(Action<T> callback)
{
Option<T> lastValue = Option<T>.None();
return delegate(T arg)
{
if (!lastValue.Contains(arg))
{
lastValue = Option<T>.Some(arg);
callback(arg);
}
};
}
}
public static class Enumeration
{
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (T item in source)
{
action(item);
}
}
public static IEnumerable<T> Inspect<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (T item in source)
{
action(item);
yield return item;
}
}
}
public class License
{
public static void LogLicense(PluginLogger logger, string author, string name, string version)
{
logger.LogInfo(string.Format("{0} {1} Copyright (C) {2} {3}", name, "v" + version, DateTime.Now.Year, author));
logger.LogInfo("This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.");
logger.LogInfo("This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.");
logger.LogInfo("You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.");
}
}
public class PluginLogger
{
public static Dictionary<string, ManualLogSource> loggers = new Dictionary<string, ManualLogSource>();
private string prefix;
private ManualLogSource logger
{
get
{
if (loggers.ContainsKey(prefix))
{
return loggers[prefix];
}
ManualLogSource val = Logger.CreateLogSource(prefix);
loggers.Add(prefix, val);
return val;
}
}
public PluginLogger(string prefix)
{
this.prefix = prefix;
}
public PluginLogger(Type type)
: this(type.FullName)
{
}
public static PluginLogger GetLogger<T>()
{
return new PluginLogger(typeof(T));
}
public void LogInfo(string message)
{
logger.LogInfo((object)$"<{Time.frameCount}> {message}");
}
public void LogDebug(string message)
{
logger.LogDebug((object)$"<{Time.frameCount}> {message}");
}
public void LogWarning(string message)
{
logger.LogWarning((object)$"<{Time.frameCount}> {message}");
}
public void LogError(string message)
{
logger.LogError((object)$"<{Time.frameCount}> {message}");
}
public void LogError(string message, Exception e)
{
LogError(message + "\n" + e.ToString());
}
public void LogTrace(string v)
{
if (ModConfig.TraceLogEnabled())
{
logger.LogDebug((object)$"<{Time.frameCount}> {v}");
}
}
}
public class MathyStuff
{
public static void PositionCanvasInWorld(GameObject tlc, Camera cam, Vector3 point, Vector3 lookAt = default(Vector3))
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: 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_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: 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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
Canvas componentInParent = ((Component)tlc.transform).GetComponentInParent<Canvas>();
Vector3 val = cam.WorldToScreenPoint(point);
Vector3 position = componentInParent.worldCamera.ScreenToWorldPoint(val);
tlc.transform.position = position;
if (lookAt != Vector3.zero)
{
Quaternion val2 = Quaternion.LookRotation(point - lookAt);
tlc.transform.rotation = Quaternion.Inverse(((Component)cam).transform.rotation) * val2;
}
}
}
public class GameObjectFinder
{
private static Dictionary<string, GameObject> cache = new Dictionary<string, GameObject>();
public static GameObject FindObjectByName(string name)
{
if (cache.ContainsKey(name))
{
return cache[name];
}
Transform? obj = ((IEnumerable<Transform>)Resources.FindObjectsOfTypeAll<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform o) => ((Object)((Component)o).gameObject).name == name));
GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
if ((Object)(object)val != (Object)null)
{
cache[name] = val;
}
return val;
}
public static IEnumerable<GameObject> FindParentObjectsByName(string name, GameObject child)
{
return from o in child.GetComponentsInParent<Transform>()
where ((Object)((Component)o).gameObject).name == name
select ((Component)o).gameObject;
}
public static GameObject FindParentObjectByName(string name, GameObject child)
{
Transform? obj = ((IEnumerable<Transform>)child.GetComponentsInParent<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform o) => ((Object)((Component)o).gameObject).name == name));
if (obj == null)
{
return null;
}
return ((Component)obj).gameObject;
}
public static IEnumerable<GameObject> FindChildObjectsByName(string name, GameObject parent)
{
return from o in parent.GetComponentsInChildren<Transform>()
where ((Object)((Component)o).gameObject).name == name
select ((Component)o).gameObject;
}
public static GameObject FindChildObjectByName(string name, GameObject parent)
{
Transform? obj = ((IEnumerable<Transform>)parent.GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform o) => ((Object)((Component)o).gameObject).name == name));
if (obj == null)
{
return null;
}
return ((Component)obj).gameObject;
}
public static GameObject FindChildObjectByName(string name, Transform parent)
{
return FindChildObjectByName(name, ((Component)parent).gameObject);
}
public static IEnumerable<GameObject> FindSiblingChildObjectsByName(string name, GameObject sibling)
{
if ((Object)(object)sibling.transform.parent == (Object)null)
{
yield break;
}
for (int i = 0; i < sibling.transform.parent.childCount; i++)
{
Transform child = sibling.transform.parent.GetChild(i);
if (((Object)((Component)child).gameObject).name == name)
{
yield return ((Component)child).gameObject;
}
}
}
}
public class ObjectPosition
{
private static PluginLogger Logger = PluginLogger.GetLogger<ObjectPosition>();
public static Vector3 addLocalPositions(Transform transform, Transform stopAt = null)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: 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_0043: 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)
Vector3 val = transform.localPosition;
while ((Object)(object)transform.parent != (Object)null && (Object)(object)transform.parent != (Object)(object)stopAt)
{
transform = transform.parent;
Logger.LogTrace($"Adding {transform.localPosition} from {((Object)((Component)transform).gameObject).name} to {val}");
val += transform.localPosition;
}
return val;
}
public static Vector3 addLocalPositions(Transform transform, int stopAt)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: 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_0031: 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_0043: 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)
Vector3 val = transform.localPosition;
while ((Object)(object)((Component)transform).transform.parent != (Object)null && stopAt > 0)
{
transform = transform.parent;
Logger.LogTrace($"Adding {transform.localPosition} from {((Object)((Component)transform).gameObject).name} to {val}");
val += transform.localPosition;
stopAt--;
}
if (stopAt > 0)
{
Logger.LogWarning($"Ran out of parents to add to {((Object)((Component)transform).gameObject).name} ({stopAt} remaining)");
}
return val;
}
}
public class Option<T> : IEnumerable<T>, IEnumerable
{
private readonly T[] data;
private Option(T[] data)
{
this.data = data;
}
public static Option<T> New(T value)
{
if (value == null)
{
return None();
}
return Some(value);
}
public static Option<T> Some(T value)
{
return new Option<T>(new T[1] { value });
}
public static Option<T> None()
{
return new Option<T>(Array.Empty<T>());
}
public bool IsSome()
{
return data.Length != 0;
}
public IEnumerator<T> GetEnumerator()
{
return ((IEnumerable<T>)data).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return data.GetEnumerator();
}
}
public static class TransformUtils
{
public static void DestroyAllChildren(this Transform transform)
{
for (int num = transform.childCount - 1; num >= 0; num--)
{
Object.Destroy((Object)(object)((Component)transform.GetChild(num)).gameObject);
}
}
}
}
namespace PiUtils.UI
{
public class BehaviourMenu : Menu
{
public bool open { private get; set; }
public bool isOpen()
{
return open;
}
}
public interface Menu
{
bool isOpen();
}
}
namespace PiUtils.Patches
{
public class AtLeastOnePatch : IPatch
{
private bool applied;
private IPatch[] patches;
public AtLeastOnePatch(IPatch[] patches)
{
this.patches = patches;
}
public bool Apply()
{
IPatch[] array = patches;
for (int i = 0; i < array.Length; i++)
{
array[i].Apply();
}
applied = patches.Select((IPatch p) => p.IsApplied()).Any((bool applied) => applied);
return applied;
}
public bool IsApplied()
{
return applied;
}
}
public class ExecuteAfterPatch : IPatch
{
private bool applied;
private IPatch patch;
private IPatch[] dependsOn;
public ExecuteAfterPatch(IPatch patch, IPatch[] dependsOn)
{
this.patch = patch;
this.dependsOn = dependsOn;
}
public bool Apply()
{
if (dependsOn.Any((IPatch p) => !p.IsApplied()))
{
return false;
}
applied = patch.Apply();
return applied;
}
public bool IsApplied()
{
return applied;
}
}
public abstract class GameComponentPatch<T> : IPatch where T : Object
{
private bool applied;
public bool Apply()
{
T val = Object.FindObjectOfType<T>();
if ((Object)(object)val == (Object)null)
{
return false;
}
applied = Apply(val);
return applied;
}
public bool IsApplied()
{
return applied;
}
protected abstract bool Apply(T component);
}
public abstract class GameObjectPatch : IPatch
{
private string gameObjectName;
private bool applied;
public GameObjectPatch(string gameObjectName)
{
this.gameObjectName = gameObjectName;
}
public bool Apply()
{
GameObject val = GameObject.Find(gameObjectName) ?? GameObjectFinder.FindObjectByName(gameObjectName);
if ((Object)(object)val == (Object)null)
{
return false;
}
applied = Apply(val);
return applied;
}
public bool IsApplied()
{
return applied;
}
protected abstract bool Apply(GameObject gameObject);
}
public interface IPatch
{
bool Apply();
bool IsApplied();
}
}
namespace PiUtils.Patches.Universal
{
public class DisableByNamePatch : GameObjectPatch
{
public DisableByNamePatch(string gameObjectName)
: base(gameObjectName)
{
}
protected override bool Apply(GameObject component)
{
component.gameObject.SetActive(false);
return true;
}
}
public class DisableComponentPatch<T> : GameComponentPatch<T> where T : MonoBehaviour
{
protected override bool Apply(T component)
{
((Behaviour)(object)component).enabled = false;
return true;
}
}
public class DisableOnComponentPatch<T> : GameComponentPatch<T> where T : MonoBehaviour
{
protected override bool Apply(T component)
{
((Component)(object)component).gameObject.SetActive(false);
return true;
}
}
[HarmonyPatch]
public class SetDefaultLayerPatch : GameObjectPatch
{
private bool applyToChildren;
public SetDefaultLayerPatch(string gameObjectName, bool applyToChildren)
: base(gameObjectName)
{
this.applyToChildren = applyToChildren;
}
protected override bool Apply(GameObject gameObject)
{
if (applyToChildren)
{
SetChildLayer(gameObject, 0);
}
else
{
gameObject.layer = 0;
}
return true;
}
public static void SetChildLayer(GameObject gameObject, int layer)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
gameObject.layer = layer;
foreach (Transform item in gameObject.transform)
{
SetChildLayer(((Component)item).gameObject, layer);
}
}
}
}
namespace PiUtils.Objects.Behaviours
{
public class Grabable : MonoBehaviour
{
private static readonly PluginLogger Logger = PluginLogger.GetLogger<Grabable>();
public float grabDistance = 0.2f;
public bool snapToHand;
public Option<Vector3> grabOffset = Option<Vector3>.None();
public Option<Quaternion> grabRotation = Option<Quaternion>.None();
public bool IsGrabbed { get; private set; }
public bool IsHovered { get; private set; }
public Transform originalParent { get; private set; }
public Grabable()
{
}
public Grabable(float? grabDistance, bool snapToHand, Option<Vector3> grabOffset, Option<Quaternion> grabRotation)
{
this.grabDistance = grabDistance ?? this.grabDistance;
this.snapToHand = snapToHand;
this.grabOffset = grabOffset;
this.grabRotation = grabRotation;
}
public bool TryGrab(Transform grabbingTransform)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (IsGrabbed)
{
Logger.LogDebug("Object already grabbed: " + ((Object)((Component)this).gameObject).name);
return false;
}
float num = Vector3.Distance(((Component)this).transform.position, grabbingTransform.position);
if (grabDistance >= 0f && num >= grabDistance)
{
Logger.LogDebug($"Object too far to grab: {((Object)((Component)this).gameObject).name} ({num} > {grabDistance})");
return false;
}
Grab(grabbingTransform);
return IsGrabbed;
}
public void Grab(Transform grabbingTransform)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: 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_0080: Unknown result type (might be due to invalid IL or missing references)
if (!IsGrabbed)
{
Logger.LogDebug("Grabbing object: " + ((Object)((Component)this).gameObject).name);
IsGrabbed = true;
originalParent = ((Component)this).transform.parent;
if (snapToHand)
{
((Component)this).transform.position = grabbingTransform.position + grabOffset.FirstOrDefault();
((Component)this).transform.rotation = grabbingTransform.rotation * grabRotation.FirstOrDefault();
}
((Component)this).transform.SetParent(grabbingTransform, true);
}
}
public void Release()
{
if (IsGrabbed)
{
IsGrabbed = false;
((Component)this).transform.SetParent(originalParent, true);
originalParent = null;
}
}
}
public class Interactable : MonoBehaviour
{
private static PluginLogger Logger = PluginLogger.GetLogger<Interactable>();
public Transform interactionTransform;
public float radius = 0.1f;
public bool isHovered { get; private set; }
public event Action OnEnter;
public event Action OnExit;
private void Update()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)interactionTransform == (Object)null))
{
float num = Vector3.Distance(interactionTransform.position, ((Component)this).transform.position);
if (num <= radius && !isHovered)
{
Logger.LogDebug("Hovered " + ((Object)((Component)this).gameObject).name);
isHovered = true;
this.OnEnter?.Invoke();
}
else if (num > radius && isHovered)
{
Logger.LogDebug("Unhovered " + ((Object)((Component)this).gameObject).name);
isHovered = false;
this.OnExit?.Invoke();
}
}
}
}
}
namespace PiUtils.Debug
{
public class DebugLine : MonoBehaviour
{
public Transform start;
public Transform end;
private LineRenderer line;
private void Start()
{
if (!ModConfig.DebugLineEnabled())
{
Object.Destroy((Object)(object)this);
return;
}
line = ((Component)this).gameObject.AddComponent<LineRenderer>();
line.startWidth = 0.01f;
line.endWidth = 0.01f;
line.positionCount = 2;
}
private void Update()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)start) && Object.op_Implicit((Object)(object)end))
{
line.SetPosition(0, start.position);
line.SetPosition(1, end.position);
}
}
public void DrawLine(Vector3 end)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
Transform obj = start;
DrawLine((obj != null) ? obj.position : ((Component)this).transform.position, end);
}
public void DrawLine(Vector3 start, Vector3 end)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
line.SetPosition(0, start);
line.SetPosition(1, end);
}
}
public class DebugPlane : MonoBehaviour
{
private GameObject plane;
private void Start()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
if (!ModConfig.DebugEnabled())
{
Object.Destroy((Object)(object)this);
return;
}
plane = GameObject.CreatePrimitive((PrimitiveType)4);
((Collider)plane.GetComponent<MeshCollider>()).enabled = false;
MeshRenderer obj = plane.AddComponent<MeshRenderer>();
Material val = new Material(Shader.Find("Unlit/Color"));
val.SetColor("_Color", Color.red);
((Renderer)obj).material = val;
plane.AddComponent<Gizmo>();
}
public void DrawPlane(Vector3 position, Vector3 normal, float size = 1f)
{
//IL_000b: 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_0034: Unknown result type (might be due to invalid IL or missing references)
plane.transform.position = position;
plane.transform.up = normal;
plane.transform.localScale = new Vector3(size, 1f, size);
}
}
public class Gizmo : MonoBehaviour
{
public Color colorUp = Color.green;
public Color colorForward = Color.blue;
public Color colorRight = Color.red;
private LineRenderer lineUp;
private LineRenderer lineForward;
private LineRenderer lineRight;
public float radius = 0.5f;
private void Start()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected O, but got Unknown
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected O, but got Unknown
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Expected O, but got Unknown
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Expected O, but got Unknown
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Expected O, but got Unknown
if (!ModConfig.GizmoEnabled())
{
Object.Destroy((Object)(object)this);
return;
}
GameObject val = new GameObject("Up");
val.transform.parent = ((Component)this).transform;
lineUp = val.AddComponent<LineRenderer>();
lineUp.startWidth = 0.01f;
lineUp.endWidth = 0.01f;
lineUp.positionCount = 2;
((Renderer)lineUp).material = new Material(Shader.Find("Unlit/Color"))
{
color = colorUp
};
GameObject val2 = new GameObject("Forward");
val2.transform.parent = ((Component)this).transform;
lineForward = val2.AddComponent<LineRenderer>();
lineForward.startWidth = 0.01f;
lineForward.endWidth = 0.01f;
lineForward.positionCount = 2;
((Renderer)lineForward).material = new Material(Shader.Find("Unlit/Color"))
{
color = colorForward
};
GameObject val3 = new GameObject("Right");
val3.transform.parent = ((Component)this).transform;
lineRight = val3.AddComponent<LineRenderer>();
lineRight.startWidth = 0.01f;
lineRight.endWidth = 0.01f;
lineRight.positionCount = 2;
((Renderer)lineRight).material = new Material(Shader.Find("Unlit/Color"))
{
color = colorRight
};
}
private void Update()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: 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_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
lineUp.SetPosition(0, ((Component)this).transform.position);
lineUp.SetPosition(1, ((Component)this).transform.position + ((Component)this).transform.up * radius);
lineForward.SetPosition(0, ((Component)this).transform.position);
lineForward.SetPosition(1, ((Component)this).transform.position + ((Component)this).transform.forward * radius);
lineRight.SetPosition(0, ((Component)this).transform.position);
lineRight.SetPosition(1, ((Component)this).transform.position + ((Component)this).transform.right * radius);
}
}
}
namespace PiUtils.Assets
{
public class AssetLoader
{
private static PluginLogger Logger = PluginLogger.GetLogger<AssetLoader>();
private string assetPath = "assets";
public AssetLoader()
{
}
public AssetLoader(string assetPath)
{
this.assetPath = assetPath;
}
public IEnumerator Load<T>(AssetBundle bundle, string prefabName) where T : Object
{
T val = LoadAsset<T>(bundle, prefabName);
if (Object.op_Implicit((Object)(object)val))
{
yield return val;
yield break;
}
Logger.LogError("Failed to load asset " + prefabName);
yield return null;
}
public T LoadAsset<T>(AssetBundle bundle, string prefabName) where T : Object
{
T val = bundle.LoadAsset<T>("Assets/" + prefabName);
if (Object.op_Implicit((Object)(object)val))
{
return val;
}
Logger.LogError("Failed to load asset " + prefabName);
return default(T);
}
public AssetBundle LoadBundle(string assetName)
{
AssetBundle val = AssetBundle.LoadFromFile(GetAssetPath(assetName));
if ((Object)(object)val == (Object)null)
{
Logger.LogError("Failed to load AssetBundle " + assetName);
return null;
}
return val;
}
private string GetAssetPath(string assetName)
{
return Path.Combine(Paths.PluginPath, Path.Combine(assetPath, assetName));
}
}
public class DependencyLoader
{
private static PluginLogger Logger = PluginLogger.GetLogger<DependencyLoader>();
public static void LoadDirectory(string path)
{
string[] files = Directory.GetFiles(path, "*.dll");
foreach (string text in files)
{
try
{
Assembly.LoadFile(text);
}
catch (Exception e)
{
Logger.LogError("Failed to load assembly " + text, e);
}
}
}
}
}