using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2Cpp;
using Il2CppFriendlyFoe.Debug;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using PitOfGoblinSpawner;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(SpawnerMod), "POG Item Spawner", "1.0.0", "YourName", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PitOfGoblinSpawner")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PitOfGoblinSpawner")]
[assembly: AssemblyTitle("PitOfGoblinSpawner")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PitOfGoblinSpawner;
public class SpawnerMod : MelonMod
{
private class SpawnableEntry
{
public string Name;
public int DbIndex = -1;
public GameObject Prefab = null;
}
private bool showMenu = false;
private string searchQuery = "";
private Vector2 scrollPos = Vector2.zero;
private SpawnerPickups pickupSpawner = null;
private SpawnerDatabase database = null;
private List<SpawnableEntry> itemList = new List<SpawnableEntry>();
public override void OnUpdate()
{
if (Input.GetKeyDown((KeyCode)286))
{
showMenu = !showMenu;
if (showMenu)
{
RefreshItems();
}
}
if (!showMenu)
{
return;
}
Cursor.visible = true;
Cursor.lockState = (CursorLockMode)0;
string inputString = Input.inputString;
for (int i = 0; i < inputString.Length; i++)
{
char c = inputString[i];
switch (c)
{
case '\b':
if (searchQuery.Length > 0)
{
searchQuery = searchQuery.Substring(0, searchQuery.Length - 1);
}
break;
default:
if (c != '\r')
{
searchQuery += c;
}
break;
case '\n':
break;
}
}
}
private void RefreshItems()
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected O, but got Unknown
itemList.Clear();
if ((Object)(object)database == (Object)null)
{
Il2CppArrayBase<SpawnerDatabase> val = Resources.FindObjectsOfTypeAll<SpawnerDatabase>();
if (val != null && val.Length > 0)
{
database = val[0];
}
}
if ((Object)(object)pickupSpawner == (Object)null)
{
Il2CppArrayBase<SpawnerPickups> val2 = Resources.FindObjectsOfTypeAll<SpawnerPickups>();
if (val2 != null && val2.Length > 0)
{
pickupSpawner = val2[0];
}
else
{
GameObject val3 = new GameObject("CustomPOGSpawner");
Object.DontDestroyOnLoad((Object)(object)val3);
pickupSpawner = val3.AddComponent<SpawnerPickups>();
if ((Object)(object)database != (Object)null)
{
((SpawnerCreator)pickupSpawner).m_database = database;
}
}
}
if ((Object)(object)database != (Object)null && database.m_pickups != null && database.m_pickups.Count > 0)
{
for (int i = 0; i < database.m_pickups.Count; i++)
{
AssetInfo<GameObject> val4 = database.m_pickups[i];
if (val4 != null)
{
string text = ((SpawnerCreator)pickupSpawner).GetCellTitle(val4);
if (string.IsNullOrEmpty(text))
{
text = $"Item #{i}";
}
itemList.Add(new SpawnableEntry
{
Name = text,
DbIndex = i
});
}
}
MelonLogger.Msg($"Loaded {itemList.Count} items from SpawnerDatabase.");
}
else if ((Object)(object)NetworkManager.Singleton != (Object)null && NetworkManager.Singleton.NetworkConfig != null)
{
IReadOnlyList<NetworkPrefab> prefabs = NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs;
int count = ((Il2CppObjectBase)prefabs).Cast<IReadOnlyCollection<NetworkPrefab>>().Count;
for (int j = 0; j < count; j++)
{
NetworkPrefab val5 = prefabs[j];
if (val5 != null && !((Object)(object)val5.Prefab == (Object)null))
{
InventoryItem component = val5.Prefab.GetComponent<InventoryItem>();
if ((Object)(object)component != (Object)null)
{
itemList.Add(new SpawnableEntry
{
Name = ((Object)val5.Prefab).name,
Prefab = val5.Prefab
});
}
}
}
MelonLogger.Msg($"Loaded {itemList.Count} items from NetworkManager prefabs.");
}
else
{
MelonLogger.Warning("NetworkManager not ready yet! Load into a match first.");
}
}
private void SpawnEntry(SpawnableEntry entry, bool onPlayer)
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: 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_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
if (entry.DbIndex >= 0 && (Object)(object)pickupSpawner != (Object)null)
{
if (onPlayer)
{
((SpawnerCreator)pickupSpawner).OnSpawnOnPlayer(entry.DbIndex);
}
else
{
((SpawnerCreator)pickupSpawner).OnSpawnInWorld(entry.DbIndex);
}
}
else
{
if (!((Object)(object)entry.Prefab != (Object)null))
{
return;
}
if ((Object)(object)NetworkManager.Singleton == (Object)null || !NetworkManager.Singleton.IsServer)
{
MelonLogger.Warning("You must be the host/server to spawn networked items!");
return;
}
Vector3 val = Vector3.zero;
Il2CppArrayBase<SpawnedObjectsService> val2 = Resources.FindObjectsOfTypeAll<SpawnedObjectsService>();
if (val2 != null && val2.Length > 0 && (Object)(object)val2[0].LocalPlayer != (Object)null)
{
Transform transform = ((Component)val2[0].LocalPlayer).transform;
val = (onPlayer ? (transform.position + Vector3.up * 1.2f) : (transform.position + transform.forward * 1.5f + Vector3.up * 0.5f));
}
else if ((Object)(object)Camera.main != (Object)null)
{
Transform transform2 = ((Component)Camera.main).transform;
val = transform2.position + transform2.forward * 2f;
}
GameObject val3 = Object.Instantiate<GameObject>(entry.Prefab, val, Quaternion.identity);
NetworkObject component = val3.GetComponent<NetworkObject>();
if ((Object)(object)component != (Object)null)
{
component.Spawn(true);
MelonLogger.Msg($"Spawned {entry.Name} at {val}");
}
}
}
public override void OnGUI()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: 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_0093: 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_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
if (!showMenu)
{
return;
}
GUI.Box(new Rect(20f, 20f, 360f, 520f), "Pit of Goblin - Item Spawner (F5)");
GUI.Label(new Rect(35f, 50f, 60f, 25f), "Search:");
GUI.Box(new Rect(95f, 50f, 205f, 25f), "");
GUI.Label(new Rect(100f, 52f, 195f, 22f), string.IsNullOrEmpty(searchQuery) ? "<Type to filter...>" : searchQuery);
if (GUI.Button(new Rect(305f, 50f, 60f, 25f), "Clear"))
{
searchQuery = "";
}
if (itemList.Count == 0)
{
if (GUI.Button(new Rect(35f, 90f, 330f, 30f), "Reload Items"))
{
RefreshItems();
}
GUI.Label(new Rect(35f, 130f, 330f, 40f), "No items loaded yet. Enter a match and click Reload.");
return;
}
List<SpawnableEntry> list = new List<SpawnableEntry>();
foreach (SpawnableEntry item in itemList)
{
if (string.IsNullOrEmpty(searchQuery) || item.Name.IndexOf(searchQuery, StringComparison.OrdinalIgnoreCase) >= 0)
{
list.Add(item);
}
}
scrollPos = GUI.BeginScrollView(new Rect(30f, 85f, 340f, 440f), scrollPos, new Rect(0f, 0f, 315f, (float)(list.Count * 32)));
int num = 0;
foreach (SpawnableEntry item2 in list)
{
GUI.Label(new Rect(5f, (float)(num + 4), 185f, 25f), item2.Name);
if (GUI.Button(new Rect(190f, (float)num, 60f, 26f), "World"))
{
SpawnEntry(item2, onPlayer: false);
}
if (GUI.Button(new Rect(255f, (float)num, 60f, 26f), "Player"))
{
SpawnEntry(item2, onPlayer: true);
}
num += 32;
}
GUI.EndScrollView();
}
}