using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.BoneMenu.Elements;
using MelonLoader;
using MelonLoader.Preferences;
using SLZ.Marrow.Pool;
using SLZ.Marrow.SceneStreaming;
using SLZ.Marrow.Warehouse;
using SLZ.Rig;
using SLZ.SFX;
using TMPro;
using UnityEngine;
using WarehouseScanner;
using WarehouseScanner.Melon;
using WarehouseScanner.Menu;
using WarehouseScanner.Resources;
using WarehouseScanner.Scripts;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Scan crates, get barcodes.")]
[assembly: AssemblyDescription("Scan crates, get barcodes.")]
[assembly: AssemblyCompany("Weather Electric")]
[assembly: AssemblyProduct("WarehouseScanner")]
[assembly: AssemblyCopyright("Developed by SoulWithMae")]
[assembly: AssemblyTrademark("Weather Electric")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: MelonInfo(typeof(Main), "WarehouseScanner", "1.2.0", "SoulWithMae", "https://bonelab.thunderstore.io/package/SoulWithMae/WarehouseScanner/")]
[assembly: MelonColor(ConsoleColor.Magenta)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace WarehouseScanner
{
public class Main : MelonMod
{
internal const string Name = "WarehouseScanner";
internal const string Description = "Scan crates, get barcodes.";
internal const string Author = "SoulWithMae";
internal const string Company = "Weather Electric";
internal const string Version = "1.2.0";
internal const string DownloadLink = "https://bonelab.thunderstore.io/package/SoulWithMae/WarehouseScanner/";
internal static Assembly CurrAsm => Assembly.GetExecutingAssembly();
public override void OnInitializeMelon()
{
ModConsole.Setup(((MelonBase)this).LoggerInstance);
Preferences.Setup();
Assets.Load();
BoneMenu.Setup();
Hooking.OnLevelUnloaded += OnLevelUnload;
}
private static void OnLevelUnload()
{
Scanner.PostDestroy();
BoneMenu.IsSpawned = false;
}
}
}
namespace WarehouseScanner.Scripts
{
[RegisterTypeInIl2Cpp]
public class Scanner : MonoBehaviour
{
private Transform _firePoint;
private AudioSource _successSound;
private ImpactSFX _impactSfx;
private TextMeshPro _titleText;
private TextMeshPro _barcodeText;
public static Scanner Instance { get; private set; }
internal static void PostDestroy()
{
Instance = null;
}
private void Awake()
{
Instance = this;
}
private void Start()
{
_firePoint = ((Component)this).transform.Find("FirePoint");
_titleText = ((Component)((Component)this).transform.Find("Text/Title")).GetComponent<TextMeshPro>();
_barcodeText = ((Component)((Component)this).transform.Find("Text/Barcode")).GetComponent<TextMeshPro>();
_successSound = ((Component)((Component)this).transform).GetComponent<AudioSource>();
_successSound.outputAudioMixerGroup = Audio.SFXMixer;
_impactSfx = ((Component)((Component)this).transform.Find("ImpactSFX")).GetComponent<ImpactSFX>();
_impactSfx.outputMixer = Audio.SFXMixer;
}
public void Scan()
{
//IL_0006: 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_004f: Unknown result type (might be due to invalid IL or missing references)
RaycastHit hit = default(RaycastHit);
Physics.Raycast(_firePoint.position, _firePoint.forward, ref hit, 100f);
if (!((Object)(object)((RaycastHit)(ref hit)).rigidbody == (Object)null))
{
AssetPoolee component = ((Component)((RaycastHit)(ref hit)).rigidbody).gameObject.GetComponent<AssetPoolee>();
if ((Object)(object)component == (Object)null)
{
ScanNPC(hit);
return;
}
_successSound.Play();
Barcode barcode = ((Scannable)component.spawnableCrate).Barcode;
string title = ((Scannable)component.spawnableCrate).Title;
((TMP_Text)_titleText).text = title;
((TMP_Text)_barcodeText).text = Barcode.op_Implicit(barcode);
((MonoBehaviour)this).CancelInvoke("HideText");
((MonoBehaviour)this).Invoke("HideText", 2f);
ModConsole.Msg($"{((Object)((Component)component).gameObject).name}'s barcode: {barcode}, title: {title}");
}
}
public void ScanMap()
{
LevelCrate level = SceneStreamer.Session.Level;
if (!((Object)(object)level == (Object)null))
{
_successSound.Play();
Barcode barcode = ((Scannable)level).Barcode;
string title = ((Scannable)level).Title;
((TMP_Text)_titleText).text = title;
((TMP_Text)_barcodeText).text = Barcode.op_Implicit(barcode);
((MonoBehaviour)this).CancelInvoke("HideText");
((MonoBehaviour)this).Invoke("HideText", 2f);
ModConsole.Msg($"Map barcode: {barcode}, title: {title}");
}
}
private void ScanNPC(RaycastHit hit)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
AssetPoolee componentInParent = ((Component)((RaycastHit)(ref hit)).rigidbody).gameObject.GetComponentInParent<AssetPoolee>();
if ((Object)(object)componentInParent == (Object)null)
{
ScanAvatar(hit);
return;
}
Barcode barcode = ((Scannable)componentInParent.spawnableCrate).Barcode;
string title = ((Scannable)componentInParent.spawnableCrate).Title;
((TMP_Text)_titleText).text = title;
((TMP_Text)_barcodeText).text = Barcode.op_Implicit(barcode);
((MonoBehaviour)this).CancelInvoke("HideText");
((MonoBehaviour)this).Invoke("HideText", 2f);
ModConsole.Msg($"{((Object)((Component)componentInParent).gameObject).name}'s barcode: {barcode}, title: {title}");
}
private void ScanAvatar(RaycastHit hit)
{
RigManager componentInParent = ((Component)((RaycastHit)(ref hit)).rigidbody).gameObject.GetComponentInParent<RigManager>();
if (!((Object)(object)componentInParent == (Object)null))
{
_successSound.Play();
Barcode barcode = ((Scannable)((CrateReferenceT<AvatarCrate>)(object)componentInParent.AvatarCrate).Crate).Barcode;
string title = ((Scannable)((CrateReferenceT<AvatarCrate>)(object)componentInParent.AvatarCrate).Crate).Title;
((TMP_Text)_titleText).text = title;
((TMP_Text)_barcodeText).text = Barcode.op_Implicit(barcode);
((MonoBehaviour)this).CancelInvoke("HideText");
((MonoBehaviour)this).Invoke("HideText", 2f);
ModConsole.Msg($"Avatar's barcode: {barcode}, title: {title}");
}
}
private void HideText()
{
((TMP_Text)_titleText).text = "";
((TMP_Text)_barcodeText).text = "";
}
private void OnDestroy()
{
Instance = null;
}
public Scanner(IntPtr ptr)
: base(ptr)
{
}
}
}
namespace WarehouseScanner.Resources
{
internal static class Assets
{
private static AssetBundle _bundle;
public static GameObject Scanner { get; private set; }
public static void Load()
{
_bundle = HelperMethods.LoadEmbeddedAssetBundle(Main.CurrAsm, HelperMethods.IsAndroid() ? "WarehouseScanner.Resources.Android.bundle" : "WarehouseScanner.Resources.Windows.bundle");
Scanner = HelperMethods.LoadPersistentAsset<GameObject>(_bundle, "Assets/Dickweed.prefab");
}
}
}
namespace WarehouseScanner.Melon
{
internal static class ModConsole
{
private static Instance _logger;
public static void Setup(Instance loggerInstance)
{
_logger = loggerInstance;
}
public static void Msg(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text);
}
}
public static void Msg(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text);
}
}
public static void Msg(ConsoleColor txtcolor, object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text);
}
}
public static void Msg(ConsoleColor txtcolor, string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text);
}
}
public static void Msg(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
ConsoleColor consoleColor = ((loggingMode == 1) ? ConsoleColor.Yellow : ConsoleColor.Gray);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(consoleColor, text, args);
}
}
public static void Msg(ConsoleColor txtcolor, string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Msg(txtcolor, text, args);
}
}
public static void Error(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text);
}
}
public static void Error(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text);
}
}
public static void Error(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Error(text, args);
}
}
public static void Warning(object obj, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? $"[DEBUG] {obj}" : obj.ToString());
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text);
}
}
public static void Warning(string txt, int loggingMode = 0)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text);
}
}
public static void Warning(string txt, int loggingMode = 0, params object[] args)
{
string text = ((loggingMode == 1) ? ("[DEBUG] " + txt) : txt);
if (Preferences.LoggingMode.Value >= loggingMode)
{
_logger.Warning(text, args);
}
}
}
internal static class Preferences
{
public static readonly MelonPreferences_Category GlobalCategory = MelonPreferences.CreateCategory("Global");
public static MelonPreferences_Entry<int> LoggingMode { get; set; }
public static void Setup()
{
LoggingMode = GlobalCategory.GetEntry<int>("LoggingMode") ?? GlobalCategory.CreateEntry<int>("LoggingMode", 0, "Logging Mode", "The level of logging to use. 0 = Important Only, 1 = All", false, false, (ValueValidator)null, (string)null);
GlobalCategory.SetFilePath(MelonUtils.UserDataDirectory + "/WeatherElectric.cfg");
GlobalCategory.SaveToFile(false);
ModConsole.Msg("Finished preferences setup for WarehouseScanner", 1);
}
}
}
namespace WarehouseScanner.Menu
{
internal static class BoneMenu
{
public static bool IsSpawned;
public static void Setup()
{
//IL_0014: 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_0040: Unknown result type (might be due to invalid IL or missing references)
MenuCategory obj = MenuManager.CreateCategory("Weather Electric", "#6FBDFF").CreateCategory("Warehouse Scanner", Color.magenta);
obj.CreateFunctionElement("Spawn", Color.green, (Action)Spawn);
obj.CreateFunctionElement("Despawn", Color.red, (Action)Despawn);
}
private static void Spawn()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: 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_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (!IsSpawned)
{
Vector3 val = Player.playerHead.position + Player.playerHead.forward * 2f;
Object.Instantiate<GameObject>(Assets.Scanner, val, Quaternion.identity);
IsSpawned = true;
}
}
private static void Despawn()
{
if (IsSpawned)
{
Object.Destroy((Object)(object)((Component)Scanner.Instance).gameObject);
IsSpawned = false;
}
}
}
}