using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace OmniConsole;
public static class Commands
{
private class Info
{
public string name;
public string group;
public string usage;
}
private static readonly List<Info> registered = new List<Info>();
private static readonly Dictionary<string, Vector3> savedPositions = new Dictionary<string, Vector3>(StringComparer.OrdinalIgnoreCase);
private static readonly Dictionary<Behaviour, bool> frozenBehaviours = new Dictionary<Behaviour, bool>();
private static readonly Dictionary<Rigidbody, bool> frozenBodies = new Dictionary<Rigidbody, bool>();
private static bool denizensFrozen;
private static float registryBuildAt = -1f;
private static ENT_Player tunedPlayer;
private static float baseSpeed;
private static float baseSprint;
private static float baseCrouch;
private static float baseSwim;
private static float baseJump;
private static float baseGravity;
private static float baseInteract;
private static readonly CultureInfo Inv = CultureInfo.InvariantCulture;
public static void RegisterAll()
{
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
registered.Clear();
Cmd("spawn", Spawn(null), "Spawning", "[name] (count) ...: spawn ANY denizen/item/prop/object at your crosshair", NameAc(null));
Cmd("spawndenizen", Spawn(Category.Denizen), "Spawning", "[denizen] (count): spawn any denizen (rat king, teeth, everything)", NameAc(Category.Denizen));
Cmd("spawnprop", Spawn(Category.Prop), "Spawning", "[prop] (count): spawn any physics prop", NameAc(Category.Prop));
Cmd("spawnobject", Spawn(Category.Object), "Spawning", "[object] (count): spawn any other prefab (fx, hazards, machines...)", NameAc(Category.Object));
Cmd("spawnhere", SpawnHere, "Spawning", "[name] (count): spawn in front of you instead of at the crosshair", NameAc(null));
Cmd("spawnaround", SpawnAround, "Spawning", "[name] [count] (radius=6): spawn a ring of things around you", NameAc(null));
Cmd("give", Give, "Spawning", "[item] (count): put ANY item in your inventory, including locked/hidden ones", NameAc(Category.Item));
Cmd("giveall", GiveAll, "Spawning", "(filter): give every item (optionally only names containing filter)", null);
Cmd("dropitem", Spawn(Category.Item), "Spawning", "[item] (count): drop an item into the world at your crosshair", NameAc(Category.Item));
Cmd("clonelook", CloneLook, "Spawning", "(count): duplicate whatever you're looking at", null);
Cmd("undo", Undo, "Spawning", "(count=1): delete the last thing(s) you spawned", null);
Cmd("clearspawned", ClearSpawned, "Spawning", "Delete everything spawned with OmniConsole this run", null);
Cmd("spawnmenu", delegate
{
SpawnMenu.Toggle();
}, "Spawning", "Open the clickable spawn browser (also " + ((object)Plugin.SpawnMenuKey.Value/*cast due to .constrained prefix*/).ToString() + ")", null);
Cmd("omni", Help, "Info", "(group): list every OmniConsole command", null, cheat: false);
Cmd("find", Find, "Info", "[text]: search everything spawnable", null, cheat: false);
Cmd("listdenizens", List(Category.Denizen), "Info", "(filter): list every spawnable denizen", null, cheat: false);
Cmd("listitems", List(Category.Item), "Info", "(filter): list every item, locked ones included", null, cheat: false);
Cmd("listprops", List(Category.Prop), "Info", "(filter): list every prop", null, cheat: false);
Cmd("listobjects", List(Category.Object), "Info", "(filter): list other spawnable prefabs", null, cheat: false);
Cmd("listentities", List(Category.Entity), "Info", "(filter): list other game entities", null, cheat: false);
Cmd("listspawnables", List(null), "Info", "(filter): list absolutely everything", null, cheat: false);
Cmd("dumpspawnables", delegate
{
CommandConsole.Log("Wrote full list to: " + Registry.Dump());
}, "Info", "Write every spawnable name to BepInEx/config/OmniConsole_Spawnables.txt", null, cheat: false);
Cmd("rescan", delegate
{
Registry.Build();
CommandConsole.Log("Rescanned: " + Registry.Summary());
}, "Info", "Rebuild the spawn list (e.g. after new levels load)", null, cheat: false);
Cmd("listevents", ListEvents, "Info", "(filter): list every session event, hidden ones included", null, cheat: false);
Cmd("listlive", ListLive, "Info", "(filter): list every live entity in the world", null, cheat: false);
Cmd("listnearby", ListNearby, "Info", "(radius=30): list entities near you with distance", null, cheat: false);
Cmd("pos", Pos, "Info", "Print your position", null, cheat: false);
Cmd("lookinfo", LookInfo, "Info", "Print info about what you're looking at", null, cheat: false);
Cmd("killall", KillAll, "Entities", "(filter): kill every denizen/entity (optionally matching filter)", null);
Cmd("killlook", KillLook, "Entities", "Kill what you're looking at", null);
Cmd("deletelook", DeleteLook, "Entities", "Delete what you're looking at (entities, props, items, anything)", null);
Cmd("deleteall", DeleteAll, "Entities", "[filter]: delete every live entity whose name contains filter", null);
Cmd("bring", Bring, "Entities", "[filter]: teleport the nearest matching entity to your crosshair", null);
Cmd("bringall", BringAll, "Entities", "(filter): teleport every denizen to your crosshair", null);
Cmd("freezedenizens", FreezeDenizens, "Entities", "(true/false=toggle): pause all denizen AI", BoolAc());
Cmd("despawnteeth", delegate
{
if ((Object)(object)DEN_Teeth.instance != (Object)null)
{
DEN_Teeth.instance.Despawn();
CommandConsole.Log("Teeth despawned.");
}
else
{
CommandConsole.Log("No Teeth active.");
}
}, "Entities", "Despawn the Teeth", null);
Cmd("heal", Heal, "Player", "Fully heal", null);
Cmd("sethealth", SetHealth, "Player", "[amount]: set current health", null);
Cmd("setmaxhealth", SetMaxHealth, "Player", "[amount]: set max health (and heal to it)", null);
Cmd("setspeed", SetSpeed, "Player", "[multiplier=1]: movement speed multiplier", null);
Cmd("setjump", SetJump, "Player", "[multiplier=1]: jump height multiplier", null);
Cmd("setgravity", SetGravity, "Player", "[multiplier=1]: player gravity multiplier (0 = float)", null);
Cmd("extrajumps", ExtraJumps, "Player", "[count]: number of mid-air jumps", null);
Cmd("reach", Reach, "Player", "[multiplier=1]: grab/interact distance multiplier", null);
Cmd("launch", Launch, "Player", "(force=20): launch yourself where you're looking", null);
Cmd("tplook", TpLook, "Player", "Teleport to your crosshair", null);
Cmd("tpup", TpUp, "Player", "[meters]: teleport straight up (negative = down)", null);
Cmd("tpto", TpTo, "Player", "[filter]: teleport to the nearest entity matching filter", null);
Cmd("savepos", SavePos, "Player", "(name=default): remember your position", null);
Cmd("loadpos", LoadPos, "Player", "(name=default): teleport to a saved position", SavedPosAc());
Cmd("removeperk", RemovePerk, "Player", "[perk id | all]: remove a perk", PerkAc());
Cmd("clearinventory", ClearInventory, "Player", "Remove every item you're carrying", null);
Cmd("startevent", StartEvent, "World", "[event]: start any session event, hidden ones included", EventAc());
Cmd("stopevents", delegate
{
CL_EventManager.StopAllEvents();
CommandConsole.Log("Stopped all events.");
}, "World", "Stop every running session event", null);
Cmd("setflag", SetFlag, "World", "[flag] (true/false=true) (data): set a game flag", null);
Cmd("worldgravity", WorldGravity, "World", "[y=-9.81]: gravity for physics objects", null);
Cmd("repeat", Repeat, "Console", "[times] [command...]: run a command several times", null, cheat: false);
Cmd("echo", delegate(string[] a)
{
CommandConsole.Log(string.Join(" ", a));
}, "Console", "[text]: print text", null, cheat: false);
}
public static void Tick()
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
if (registryBuildAt < 0f && (Object)(object)CL_GameManager.gMan != (Object)null && (Object)(object)ENT_Player.GetPlayer() != (Object)null)
{
registryBuildAt = Time.unscaledTime + 2f;
}
if (registryBuildAt > 0f && Time.unscaledTime >= registryBuildAt)
{
registryBuildAt = 0f;
try
{
Registry.Build();
CommandConsole.Log("<color=#9cf>OmniConsole ready</color> - " + Registry.Summary() + ". Type <color=#9f9>omni</color> for commands, " + ((object)Plugin.SpawnMenuKey.Value/*cast due to .constrained prefix*/).ToString() + " for the spawn browser.");
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("Registry build failed: " + ex));
}
}
}
internal static void NewRunReset()
{
registryBuildAt = -1f;
frozenBehaviours.Clear();
frozenBodies.Clear();
denizensFrozen = false;
tunedPlayer = null;
}
private static void Cmd(string name, Action<string[]> cb, string group, string desc, Action<CommandAutocomplete> ac, bool cheat = true)
{
CommandConsole.RemoveCommand(name);
Action<string[]> action = delegate(string[] args)
{
try
{
cb(args ?? new string[0]);
}
catch (Exception ex)
{
CommandConsole.LogError(name + " failed: " + ex.Message);
Plugin.Log.LogError((object)(name + ": " + ex));
}
};
CommandBuilder val = CommandConsole.BuildCommand(name, action).Description(desc + " <color=#888>[Omni]</color>");
if (!cheat)
{
val.NotCheat();
}
if (ac != null)
{
val.AutocompleteCustom(ac);
}
registered.Add(new Info
{
name = name,
group = group,
usage = desc
});
}
private static Action<CommandAutocomplete> NameAc(Category? cat)
{
return delegate(CommandAutocomplete ac)
{
string text = ac.ArgumentAt(ac.activeArg);
if (ac.activeArg <= 0 || !int.TryParse(text, out var _))
{
if (ac.activeArg > 0 && text.Length == 0)
{
ac.FromArray((IReadOnlyList<string>)new string[3] { "1", "5", "10" });
}
ac.FromArrayWithDesc((IReadOnlyList<ValueTuple<string, string>>)Registry.AutocompleteFor(text, cat));
}
};
}
private static Action<CommandAutocomplete> BoolAc()
{
return delegate(CommandAutocomplete ac)
{
if (ac.activeArg == 0)
{
ac.FromArray((IReadOnlyList<string>)new string[2] { "true", "false" });
}
else
{
ac.Reject();
}
};
}
private static Action<CommandAutocomplete> SavedPosAc()
{
return delegate(CommandAutocomplete ac)
{
if (ac.activeArg == 0)
{
ac.FromArray((IReadOnlyList<string>)savedPositions.Keys.ToArray());
}
else
{
ac.Reject();
}
};
}
private static Action<CommandAutocomplete> PerkAc()
{
return delegate(CommandAutocomplete ac)
{
if (ac.activeArg != 0)
{
ac.Reject();
}
else
{
List<(string, string)> list = new List<(string, string)> { ("all", "remove every perk") };
ENT_Player player = ENT_Player.GetPlayer();
if ((Object)(object)player != (Object)null && player.perks != null)
{
foreach (Perk perk in player.perks)
{
if ((Object)(object)perk != (Object)null)
{
list.Add((perk.id, perk.title));
}
}
}
ac.FromArrayWithDesc((IReadOnlyList<ValueTuple<string, string>>)list);
}
};
}
private static Action<CommandAutocomplete> EventAc()
{
return delegate(CommandAutocomplete ac)
{
if (ac.activeArg != 0)
{
ac.Reject();
}
else
{
string text = ac.ArgumentAt(0).ToLowerInvariant();
List<(string, string)> list = new List<(string, string)>();
foreach (SessionEvent item in AllEvents())
{
if (text.Length == 0 || ((Object)item).name.ToLowerInvariant().Contains(text))
{
list.Add((((Object)item).name, item.showInList ? "" : "(hidden)"));
}
if (list.Count >= 80)
{
break;
}
}
ac.FromArrayWithDesc((IReadOnlyList<ValueTuple<string, string>>)list);
}
};
}
private static ENT_Player Player()
{
ENT_Player player = ENT_Player.GetPlayer();
if ((Object)(object)player == (Object)null)
{
throw new Exception("no player right now (start a run first)");
}
return player;
}
private static float ParseF(string s, float def)
{
if (!float.TryParse(s, NumberStyles.Float, Inv, out var result))
{
return def;
}
return result;
}
private static float ArgF(string[] a, int i, float def)
{
if (a.Length <= i)
{
return def;
}
return ParseF(a[i], def);
}
private static int ArgI(string[] a, int i, int def)
{
if (a.Length <= i || !int.TryParse(a[i], out var result))
{
return def;
}
return result;
}
private static string Joined(string[] a, int from = 0)
{
if (a.Length <= from)
{
return "";
}
return string.Join(" ", a.Skip(from).ToArray());
}
private static List<KeyValuePair<string, int>> NameCounts(string[] args)
{
List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();
for (int i = 0; i < args.Length; i++)
{
if (!int.TryParse(args[i], out var result))
{
int value = 1;
if (i + 1 < args.Length && int.TryParse(args[i + 1], out result))
{
value = Mathf.Clamp(result, 1, 500);
}
list.Add(new KeyValuePair<string, int>(args[i], value));
}
}
return list;
}
private static SpawnEntry Resolve(string name, Category? cat)
{
int alternatives;
SpawnEntry spawnEntry = Registry.Find(name, cat, out alternatives);
if (spawnEntry == null)
{
CommandConsole.Log("<color=orange>Nothing called '" + name + "'" + (cat.HasValue ? (" in " + cat.Value) : "") + ". Try: find " + name + "</color>");
return null;
}
if ((Object)(object)spawnEntry.prefab == (Object)null)
{
CommandConsole.Log("<color=orange>'" + spawnEntry.key + "' was unloaded by the game. Run 'rescan' and try again.</color>");
return null;
}
if (alternatives > 0 && Registry.MakeKey(name) != spawnEntry.key)
{
CommandConsole.Log("Using '" + spawnEntry.key + "' (" + alternatives + " other match" + ((alternatives == 1) ? "" : "es") + ", see: find " + name + ")");
}
return spawnEntry;
}
private static IEnumerable<GameEntity> LiveEntities()
{
return GameEntity.entities.Where((GameEntity g) => (Object)(object)g != (Object)null && !(g is ENT_Player) && ((Component)g).gameObject.activeInHierarchy).ToList();
}
private static bool IsDenizenObject(GameEntity g)
{
MonoBehaviour[] components = ((Component)g).GetComponents<MonoBehaviour>();
foreach (MonoBehaviour val in components)
{
if ((Object)(object)val != (Object)null && Registry.IsDenizenType(((object)val).GetType()))
{
return true;
}
}
return false;
}
private static bool NameMatch(GameObject g, string filter)
{
if (string.IsNullOrEmpty(filter))
{
return true;
}
return Registry.MakeKey(((Object)g).name).Contains(Registry.MakeKey(filter));
}
private static GameObject LookTarget(out RaycastHit hit)
{
if (!Spawner.Aim(out hit))
{
return null;
}
GameEntity componentInParent = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<GameEntity>();
if ((Object)(object)componentInParent != (Object)null && !(componentInParent is ENT_Player))
{
return ((Component)componentInParent).gameObject;
}
Item_Object componentInParent2 = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<Item_Object>();
if ((Object)(object)componentInParent2 != (Object)null)
{
return ((Component)componentInParent2).gameObject;
}
if ((Object)(object)((RaycastHit)(ref hit)).rigidbody != (Object)null)
{
return ((Component)((RaycastHit)(ref hit)).rigidbody).gameObject;
}
return ((Component)((RaycastHit)(ref hit)).collider).gameObject;
}
private static IEnumerable<SessionEvent> AllEvents()
{
WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
if (!((Object)(object)fullCombinedAssetDatabase == (Object)null))
{
return fullCombinedAssetDatabase.sessionEvents.Where((SessionEvent e) => (Object)(object)e != (Object)null);
}
return Enumerable.Empty<SessionEvent>();
}
private static void TunePlayerBase()
{
ENT_Player val = Player();
if (!((Object)(object)tunedPlayer == (Object)(object)val))
{
tunedPlayer = val;
baseSpeed = val.speed;
baseSprint = val.sprintSpeed;
baseCrouch = val.crouchSpeed;
baseSwim = val.swimSpeed;
baseJump = val.jumpHeight;
baseGravity = val.gravity;
baseInteract = val.interactDistance;
}
}
private static Action<string[]> Spawn(Category? cat)
{
return delegate(string[] args)
{
if (args.Length == 0)
{
CommandConsole.Log("Usage: name (count). Example: spawn teeth | spawn ratking 3");
return;
}
foreach (KeyValuePair<string, int> item in NameCounts(args))
{
SpawnEntry spawnEntry = Resolve(item.Key, cat);
if (spawnEntry != null)
{
int num = 0;
for (int i = 0; i < item.Value; i++)
{
if ((Object)(object)Spawner.SpawnAtAim(spawnEntry) != (Object)null)
{
num++;
}
}
CommandConsole.Log("Spawned " + num + "x <color=#9f9>" + spawnEntry.key + "</color> " + spawnEntry.Describe());
}
}
};
}
private static void SpawnHere(string[] args)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
ENT_Player val = Player();
Camera cam = Spawner.Cam;
Vector3 val2 = (((Object)(object)cam != (Object)null) ? ((Component)cam).transform.forward : ((Component)val).transform.forward);
val2.y = 0f;
if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
{
val2 = ((Component)val).transform.forward;
}
((Vector3)(ref val2)).Normalize();
foreach (KeyValuePair<string, int> item in NameCounts(args))
{
SpawnEntry spawnEntry = Resolve(item.Key, null);
if (spawnEntry != null)
{
for (int i = 0; i < item.Value; i++)
{
Vector3 pos = ((Component)val).transform.position + val2 * 2.5f + Vector3.up * 0.5f + Random.insideUnitSphere * 0.3f * (float)i;
Spawner.SpawnAt(spawnEntry, pos, Vector3.up, pushOutOfSurface: false);
}
CommandConsole.Log("Spawned " + item.Value + "x " + spawnEntry.key + " in front of you.");
}
}
}
private static void SpawnAround(string[] args)
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
if (args.Length == 0)
{
CommandConsole.Log("Usage: spawnaround [name] [count] (radius)");
return;
}
ENT_Player val = Player();
SpawnEntry spawnEntry = Resolve(args[0], null);
if (spawnEntry == null)
{
return;
}
int num = Mathf.Clamp(ArgI(args, 1, 8), 1, 200);
float num2 = ArgF(args, 2, 6f);
RaycastHit val3 = default(RaycastHit);
for (int i = 0; i < num; i++)
{
float num3 = (float)i * (float)Math.PI * 2f / (float)num;
Vector3 val2 = ((Component)val).transform.position + new Vector3(Mathf.Cos(num3), 0f, Mathf.Sin(num3)) * num2 + Vector3.up * 2f;
if (Physics.Raycast(val2, Vector3.down, ref val3, 20f, -1, (QueryTriggerInteraction)1))
{
Spawner.SpawnAt(spawnEntry, ((RaycastHit)(ref val3)).point, ((RaycastHit)(ref val3)).normal);
}
else
{
Spawner.SpawnAt(spawnEntry, val2, Vector3.up, pushOutOfSurface: false);
}
}
CommandConsole.Log("Spawned " + num + "x " + spawnEntry.key + " around you.");
}
private static void Give(string[] args)
{
if (args.Length == 0)
{
CommandConsole.Log("Usage: give [item] (count)");
return;
}
Player();
List<KeyValuePair<string, int>> list = NameCounts(args);
for (int i = 0; i < list.Count; i++)
{
SpawnEntry spawnEntry = Resolve(list[i].Key, Category.Item);
if (spawnEntry == null)
{
continue;
}
int num = 0;
for (int j = 0; j < list[i].Value; j++)
{
if (Spawner.GiveItem(spawnEntry, i == list.Count - 1 && j == list[i].Value - 1))
{
num++;
}
}
CommandConsole.Log("Gave " + num + "x <color=#9f9>" + spawnEntry.key + "</color>");
}
}
private static void GiveAll(string[] args)
{
Player();
List<SpawnEntry> list = (from e in Registry.Search(Joined(args), Category.Item)
where (Object)(object)e.item != (Object)null && (Object)(object)e.prefab != (Object)null
select e).ToList();
int value = Plugin.GiveAllLimit.Value;
int num = 0;
for (int num2 = 0; num2 < list.Count; num2++)
{
if (num >= value)
{
break;
}
try
{
if (Spawner.GiveItem(list[num2], num2 == list.Count - 1 || num == value - 1))
{
num++;
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("giveall skipped " + list[num2].key + ": " + ex.Message));
}
}
CommandConsole.Log("Gave " + num + " items" + ((list.Count > value) ? (" (capped at " + value + ", change GiveAllLimit in config)") : "") + ".");
}
private static void CloneLook(string[] args)
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: 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_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
RaycastHit hit;
GameObject val = LookTarget(out hit);
if ((Object)(object)val == (Object)null)
{
CommandConsole.Log("Not looking at anything.");
return;
}
if ((Object)(object)val.GetComponent<GameEntity>() == (Object)null && (Object)(object)val.GetComponent<Item_Object>() == (Object)null && (Object)(object)val.GetComponent<Rigidbody>() == (Object)null)
{
CommandConsole.Log("That's level geometry - aim at a denizen, prop or item.");
return;
}
int num = Mathf.Clamp(ArgI(args, 0, 1), 1, 100);
Camera cam = Spawner.Cam;
for (int i = 0; i < num; i++)
{
Vector3 pos = val.transform.position + (((Object)(object)cam != (Object)null) ? (-((Component)cam).transform.forward) : Vector3.up) * (1f + (float)i * 0.5f) + Vector3.up * 0.5f;
Spawner.Clone(val, pos);
}
CommandConsole.Log("Cloned " + ((Object)val).name + " x" + num);
}
private static void Undo(string[] args)
{
int num = Mathf.Max(1, ArgI(args, 0, 1));
int num2 = 0;
for (int i = 0; i < num; i++)
{
if (!Spawner.Undo(out var what))
{
break;
}
num2++;
if (num == 1)
{
CommandConsole.Log("Removed " + what);
}
}
if (num2 == 0)
{
CommandConsole.Log("Nothing to undo.");
}
else if (num > 1)
{
CommandConsole.Log("Removed " + num2 + " spawned things.");
}
}
private static void ClearSpawned(string[] args)
{
CommandConsole.Log("Removed " + Spawner.ClearAll() + " spawned things.");
}
private static void Help(string[] args)
{
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
string text = ((args.Length != 0) ? args[0].ToLowerInvariant() : null);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("<color=#9cf>==== OmniConsole 1.0.0 ====</color> (" + Registry.Summary() + ")");
if (!CommandConsole.cheatsEnabled)
{
stringBuilder.AppendLine("<color=yellow>Most commands are cheats: type 'cheats' first (disables stat saving, like vanilla).</color>");
}
foreach (IGrouping<string, Info> item in from r in registered
group r by r.@group)
{
if (text != null && item.Key.ToLowerInvariant() != text)
{
continue;
}
stringBuilder.AppendLine("<color=#fc6>-- " + item.Key + " --</color>");
foreach (Info item2 in item)
{
stringBuilder.AppendLine("<color=#9f9>" + item2.name + "</color> " + item2.usage);
}
}
stringBuilder.Append("Spawn browser: " + ((object)Plugin.SpawnMenuKey.Value/*cast due to .constrained prefix*/).ToString() + " | Names autocomplete with Tab.");
CommandConsole.Log(stringBuilder.ToString());
}
private static void Find(string[] args)
{
string text = Joined(args);
PrintEntries(Registry.Search(text, null), "matches for '" + text + "'");
}
private static Action<string[]> List(Category? cat)
{
return delegate(string[] args)
{
PrintEntries(Registry.Search(Joined(args), cat), (cat.HasValue ? cat.Value.ToString().ToLower() : "spawnable") + "s");
};
}
private static void PrintEntries(List<SpawnEntry> res, string label)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine(res.Count + " " + label + ":");
foreach (SpawnEntry item in res.Take(150))
{
stringBuilder.AppendLine("<color=#9f9>" + item.key + "</color> <color=#888>" + item.category.ToString() + (item.embedded ? " / level " : " / ") + item.source + "</color>");
}
if (res.Count > 150)
{
stringBuilder.AppendLine("... " + (res.Count - 150) + " more. Add a filter, or run dumpspawnables for the full list.");
}
CommandConsole.Log(stringBuilder.ToString().TrimEnd());
}
private static void ListEvents(string[] args)
{
string text = Joined(args).ToLowerInvariant();
StringBuilder stringBuilder = new StringBuilder();
int num = 0;
foreach (SessionEvent item in AllEvents())
{
if (text.Length <= 0 || ((Object)item).name.ToLowerInvariant().Contains(text))
{
stringBuilder.AppendLine("<color=#9f9>" + ((Object)item).name + "</color>" + (item.showInList ? "" : " <color=#888>(hidden)</color>"));
num++;
}
}
CommandConsole.Log(num + " events:\n" + stringBuilder.ToString().TrimEnd());
}
private static void ListLive(string[] args)
{
string f = Joined(args);
List<GameEntity> list = (from g in LiveEntities()
where NameMatch(((Component)g).gameObject, f)
select g).ToList();
StringBuilder stringBuilder = new StringBuilder(list.Count + " live entities:\n");
foreach (IGrouping<string, GameEntity> item in from g in list
group g by ((Object)((Component)g).gameObject).name into g
orderby g.Count() descending
select g)
{
stringBuilder.AppendLine(item.Key + " x" + item.Count());
}
CommandConsole.Log(stringBuilder.ToString().TrimEnd());
}
private static void ListNearby(string[] args)
{
ENT_Player p = Player();
float r = ArgF(args, 0, 30f);
var list = (from g in LiveEntities()
select new
{
g = g,
d = Vector3.Distance(((Component)g).transform.position, ((Component)p).transform.position)
} into x
where x.d <= r
orderby x.d
select x).Take(60).ToList();
StringBuilder stringBuilder = new StringBuilder(list.Count + " entities within " + r + "m:\n");
foreach (var item in list)
{
stringBuilder.AppendLine(item.d.ToString("0.0", Inv) + "m " + ((Object)((Component)item.g).gameObject).name + " hp " + item.g.health.ToString("0", Inv));
}
CommandConsole.Log(stringBuilder.ToString().TrimEnd());
}
private static void Pos(string[] args)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((Component)Player()).transform.position;
CommandConsole.Log("Position: " + position.x.ToString("0.00", Inv) + " " + position.y.ToString("0.00", Inv) + " " + position.z.ToString("0.00", Inv));
}
private static void LookInfo(string[] args)
{
RaycastHit hit;
GameObject val = LookTarget(out hit);
if ((Object)(object)val == (Object)null)
{
CommandConsole.Log("Not looking at anything.");
return;
}
GameEntity component = val.GetComponent<GameEntity>();
string text = string.Join(", ", (from m in val.GetComponents<MonoBehaviour>()
where (Object)(object)m != (Object)null
select ((object)m).GetType().Name).ToArray());
CommandConsole.Log("<color=#9f9>" + ((Object)val).name + "</color> dist " + ((RaycastHit)(ref hit)).distance.ToString("0.0", Inv) + "m" + (((Object)(object)component != (Object)null) ? (" hp " + component.health.ToString("0.#", Inv) + "/" + component.maxHealth.ToString("0.#", Inv)) : "") + "\ncomponents: " + text);
}
private static void KillAll(string[] args)
{
string text = Joined(args);
int num = 0;
foreach (GameEntity item in LiveEntities())
{
if (!item.dead && !((Object)(object)((Component)item).GetComponent<Item_Object>() != (Object)null) && (text.Length != 0 || IsDenizenObject(item)) && NameMatch(((Component)item).gameObject, text))
{
try
{
item.Kill("");
num++;
}
catch
{
}
}
}
CommandConsole.Log("Killed " + num + ".");
}
private static void KillLook(string[] args)
{
RaycastHit hit;
GameObject val = LookTarget(out hit);
GameEntity val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<GameEntity>() : null);
if ((Object)(object)val2 == (Object)null)
{
CommandConsole.Log("Not looking at an entity.");
return;
}
val2.Kill("");
CommandConsole.Log("Killed " + ((Object)val).name);
}
private static void DeleteLook(string[] args)
{
RaycastHit hit;
GameObject val = LookTarget(out hit);
if ((Object)(object)val == (Object)null)
{
CommandConsole.Log("Not looking at anything.");
return;
}
if ((Object)(object)val.GetComponent<M_Level>() != (Object)null)
{
CommandConsole.Log("Refusing to delete a whole level.");
return;
}
CommandConsole.Log("Deleted " + ((Object)val).name);
Object.Destroy((Object)(object)val);
}
private static void DeleteAll(string[] args)
{
string text = Joined(args);
if (text.Length == 0)
{
CommandConsole.Log("Give a filter, e.g. deleteall roach");
return;
}
int num = 0;
foreach (GameEntity item in LiveEntities())
{
if (NameMatch(((Component)item).gameObject, text))
{
Object.Destroy((Object)(object)((Component)item).gameObject);
num++;
}
}
CommandConsole.Log("Deleted " + num + ".");
}
private static void Bring(string[] args)
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
ENT_Player p = Player();
string f = Joined(args);
GameEntity val = (from g in LiveEntities()
where NameMatch(((Component)g).gameObject, f)
orderby Vector3.Distance(((Component)g).transform.position, ((Component)p).transform.position)
select g).FirstOrDefault();
if ((Object)(object)val == (Object)null)
{
CommandConsole.Log("No live entity matching '" + f + "'.");
return;
}
Spawner.GetSpawnPoint(out var pos, out var normal, out var _);
val.Teleport(pos + normal * 1f);
CommandConsole.Log("Brought " + ((Object)((Component)val).gameObject).name);
}
private static void BringAll(string[] args)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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_0060: 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_006f: Unknown result type (might be due to invalid IL or missing references)
string text = Joined(args);
Spawner.GetSpawnPoint(out var pos, out var normal, out var _);
int num = 0;
foreach (GameEntity item in LiveEntities())
{
if ((text.Length != 0 || IsDenizenObject(item)) && NameMatch(((Component)item).gameObject, text))
{
item.Teleport(pos + normal * 1f + Random.insideUnitSphere * 1.5f);
num++;
}
}
CommandConsole.Log("Brought " + num + ".");
}
private static void FreezeDenizens(string[] args)
{
bool flag = !denizensFrozen;
if (args.Length != 0 && bool.TryParse(args[0], out var result))
{
flag = result;
}
if (flag)
{
int num = 0;
MonoBehaviour[] array = Object.FindObjectsByType<MonoBehaviour>((FindObjectsSortMode)0);
foreach (MonoBehaviour val in array)
{
if ((Object)(object)val == (Object)null || !Registry.IsDenizenType(((object)val).GetType()) || frozenBehaviours.ContainsKey((Behaviour)(object)val))
{
continue;
}
frozenBehaviours[(Behaviour)(object)val] = ((Behaviour)val).enabled;
((Behaviour)val).enabled = false;
Rigidbody[] componentsInChildren = ((Component)val).GetComponentsInChildren<Rigidbody>();
foreach (Rigidbody val2 in componentsInChildren)
{
if (!frozenBodies.ContainsKey(val2))
{
frozenBodies[val2] = val2.isKinematic;
val2.isKinematic = true;
}
}
num++;
}
Animator[] array2 = Object.FindObjectsByType<Animator>((FindObjectsSortMode)0);
foreach (Animator val3 in array2)
{
if ((!((Object)(object)((Component)val3).GetComponentInParent<Denizen>() == (Object)null) || !((Object)(object)((Component)val3).GetComponentInParent<AIGameEntity>() == (Object)null)) && !frozenBehaviours.ContainsKey((Behaviour)(object)val3))
{
frozenBehaviours[(Behaviour)(object)val3] = ((Behaviour)val3).enabled;
((Behaviour)val3).enabled = false;
}
}
denizensFrozen = true;
CommandConsole.Log("Froze " + num + " denizens. Run freezedenizens again to unfreeze.");
return;
}
foreach (KeyValuePair<Behaviour, bool> frozenBehaviour in frozenBehaviours)
{
if ((Object)(object)frozenBehaviour.Key != (Object)null)
{
frozenBehaviour.Key.enabled = frozenBehaviour.Value;
}
}
foreach (KeyValuePair<Rigidbody, bool> frozenBody in frozenBodies)
{
if ((Object)(object)frozenBody.Key != (Object)null)
{
frozenBody.Key.isKinematic = frozenBody.Value;
}
}
frozenBehaviours.Clear();
frozenBodies.Clear();
denizensFrozen = false;
CommandConsole.Log("Denizens unfrozen.");
}
private static void Heal(string[] args)
{
ENT_Player val = Player();
((GameEntity)val).health = ((GameEntity)val).maxHealth;
CommandConsole.Log("Healed to " + ((GameEntity)val).maxHealth.ToString("0.#", Inv));
}
private static void SetHealth(string[] args)
{
ENT_Player val = Player();
((GameEntity)val).health = Mathf.Max(0.1f, ArgF(args, 0, ((GameEntity)val).maxHealth));
CommandConsole.Log("Health = " + ((GameEntity)val).health.ToString("0.#", Inv));
}
private static void SetMaxHealth(string[] args)
{
ENT_Player val = Player();
((GameEntity)val).maxHealth = Mathf.Max(1f, ArgF(args, 0, ((GameEntity)val).maxHealth));
((GameEntity)val).health = ((GameEntity)val).maxHealth;
CommandConsole.Log("Max health = " + ((GameEntity)val).maxHealth.ToString("0.#", Inv));
}
private static void SetSpeed(string[] args)
{
TunePlayerBase();
ENT_Player obj = Player();
float num = ArgF(args, 0, 1f);
obj.speed = baseSpeed * num;
obj.sprintSpeed = baseSprint * num;
obj.crouchSpeed = baseCrouch * num;
obj.swimSpeed = baseSwim * num;
CommandConsole.Log("Speed x" + num.ToString("0.##", Inv));
}
private static void SetJump(string[] args)
{
TunePlayerBase();
float num = ArgF(args, 0, 1f);
Player().jumpHeight = baseJump * num;
CommandConsole.Log("Jump x" + num.ToString("0.##", Inv));
}
private static void SetGravity(string[] args)
{
TunePlayerBase();
float num = ArgF(args, 0, 1f);
Player().gravity = baseGravity * num;
CommandConsole.Log("Player gravity x" + num.ToString("0.##", Inv));
}
private static void ExtraJumps(string[] args)
{
ENT_Player val = Player();
val.extraJumps = Mathf.Max(0, ArgI(args, 0, 1));
CommandConsole.Log("Extra jumps = " + val.extraJumps);
}
private static void Reach(string[] args)
{
TunePlayerBase();
float num = ArgF(args, 0, 1f);
Player().interactDistance = baseInteract * num;
CommandConsole.Log("Reach x" + num.ToString("0.##", Inv));
}
private static void Launch(string[] args)
{
//IL_0021: 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)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: 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)
ENT_Player obj = Player();
Camera cam = Spawner.Cam;
Vector3 val = (((Object)(object)cam != (Object)null) ? ((Component)cam).transform.forward : Vector3.up);
((GameEntity)obj).AddForce(val * ArgF(args, 0, 20f), "omni");
}
private static void TpLook(string[] args)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: 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_003d: 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)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
ENT_Player val = Player();
if (!Spawner.Aim(out var hit))
{
CommandConsole.Log("Not looking at anything.");
}
else
{
((GameEntity)val).Teleport(((RaycastHit)(ref hit)).point + ((RaycastHit)(ref hit)).normal * 1.2f + Vector3.up * 0.5f);
}
}
private static void TpUp(string[] args)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: 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)
ENT_Player obj = Player();
((GameEntity)obj).Teleport(((Component)obj).transform.position + Vector3.up * ArgF(args, 0, 10f));
}
private static void TpTo(string[] args)
{
//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)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
ENT_Player p = Player();
string f = Joined(args);
GameEntity val = (from g in LiveEntities()
where NameMatch(((Component)g).gameObject, f)
orderby Vector3.Distance(((Component)g).transform.position, ((Component)p).transform.position)
select g).FirstOrDefault();
if ((Object)(object)val == (Object)null)
{
CommandConsole.Log("No live entity matching '" + f + "'.");
return;
}
((GameEntity)p).Teleport(((Component)val).transform.position + Vector3.up * 2f);
CommandConsole.Log("Teleported to " + ((Object)((Component)val).gameObject).name);
}
private static void SavePos(string[] args)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
string text = ((args.Length != 0) ? args[0] : "default");
savedPositions[text] = ((Component)Player()).transform.position;
CommandConsole.Log("Saved position '" + text + "'.");
}
private static void LoadPos(string[] args)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
string text = ((args.Length != 0) ? args[0] : "default");
if (!savedPositions.TryGetValue(text, out var value))
{
CommandConsole.Log("No saved position '" + text + "'.");
}
else
{
((GameEntity)Player()).Teleport(value);
}
}
private static void RemovePerk(string[] args)
{
ENT_Player val = Player();
if (args.Length == 0)
{
CommandConsole.Log("Usage: removeperk [id|all]");
}
else if (args[0].Equals("all", StringComparison.OrdinalIgnoreCase))
{
val.RemoveAllPerks(true);
CommandConsole.Log("Removed all perks.");
}
else
{
val.RemovePerk(args[0], true);
CommandConsole.Log("Removed perk " + args[0]);
}
}
private static void ClearInventory(string[] args)
{
Inventory instance = Inventory.instance;
if ((Object)(object)instance == (Object)null)
{
CommandConsole.Log("No inventory.");
return;
}
MethodInfo method = typeof(Inventory).GetMethod("ClearInventory", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method == null)
{
CommandConsole.LogError("ClearInventory not found in this game version.");
return;
}
method.Invoke(instance, null);
CommandConsole.Log("Inventory cleared.");
}
private static void StartEvent(string[] args)
{
string q = Joined(args).ToLowerInvariant();
if (q.Length == 0)
{
CommandConsole.Log("Usage: startevent [name] (see listevents)");
return;
}
List<SessionEvent> source = AllEvents().ToList();
SessionEvent val = ((IEnumerable<SessionEvent>)source).FirstOrDefault((Func<SessionEvent, bool>)((SessionEvent e) => ((Object)e).name.ToLowerInvariant() == q)) ?? ((IEnumerable<SessionEvent>)source).FirstOrDefault((Func<SessionEvent, bool>)((SessionEvent e) => ((Object)e).name.ToLowerInvariant().StartsWith(q))) ?? ((IEnumerable<SessionEvent>)source).FirstOrDefault((Func<SessionEvent, bool>)((SessionEvent e) => ((Object)e).name.ToLowerInvariant().Contains(q)));
if ((Object)(object)val == (Object)null)
{
CommandConsole.Log("No event matching '" + q + "'.");
return;
}
CL_EventManager.StartEvent(val);
CommandConsole.Log("Started event " + ((Object)val).name);
}
private static void SetFlag(string[] args)
{
if (args.Length == 0)
{
CommandConsole.Log("Usage: setflag [flag] (true/false) (data)");
return;
}
bool result = true;
if (args.Length > 1)
{
bool.TryParse(args[1], out result);
}
string text = ((args.Length > 2) ? Joined(args, 2) : "");
CL_GameManager.SetGameFlag(args[0], result, text, false, false);
CommandConsole.Log("Flag " + args[0] + " = " + result);
}
private static void WorldGravity(string[] args)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
float num = ArgF(args, 0, -9.81f);
Physics.gravity = new Vector3(0f, num, 0f);
CommandConsole.Log("Physics gravity = " + num.ToString("0.##", Inv));
}
private static void Repeat(string[] args)
{
if (args.Length < 2 || !int.TryParse(args[0], out var result))
{
CommandConsole.Log("Usage: repeat [times] [command...]");
return;
}
result = Mathf.Clamp(result, 1, 200);
string text = Joined(args, 1);
for (int i = 0; i < result; i++)
{
CommandConsole.instance.ExecuteCommand(text, false);
}
}
}
[BepInPlugin("com.wkmods.omniconsole", "OmniConsole", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "com.wkmods.omniconsole";
public const string NAME = "OmniConsole";
public const string VERSION = "1.0.0";
internal static Plugin Instance;
internal static ManualLogSource Log;
internal static ConfigEntry<KeyCode> SpawnMenuKey;
internal static ConfigEntry<bool> AutoEnableCheats;
internal static ConfigEntry<int> GiveAllLimit;
internal static ConfigEntry<bool> SpawnFacesPlayer;
internal static ConfigEntry<KeyCode> ExtraConsoleKey;
private static MethodInfo toggleConsole;
private CommandConsole lastConsole;
private CL_GameManager lastGameManager;
private float nextCheck;
private void Awake()
{
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
SpawnMenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "SpawnMenuKey", (KeyCode)288, "Key that opens/closes the OmniConsole spawn browser.");
AutoEnableCheats = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AutoEnableCheats", false, "Automatically run 'cheats true' at the start of every run (cheats still disable stats saving, like vanilla).");
GiveAllLimit = ((BaseUnityPlugin)this).Config.Bind<int>("General", "GiveAllLimit", 300, "Safety cap for how many items 'giveall' will put into your inventory at once.");
ExtraConsoleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ExtraConsoleKey", (KeyCode)289, "Extra one-key shortcut to open/close the console (vanilla Shift + ` still works). Set to None to disable.");
SpawnFacesPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "SpawnFacesPlayer", true, "When spawning on a floor, rotate the spawned thing to face you. Walls/ceilings always use the surface normal like vanilla spawnentity.");
((Component)this).gameObject.AddComponent<SpawnMenu>();
((BaseUnityPlugin)this).Logger.LogInfo((object)"OmniConsole 1.0.0 loaded. Open the console with Shift + ` and type 'omni' for the command list.");
}
private void Update()
{
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
if (Time.unscaledTime >= nextCheck)
{
nextCheck = Time.unscaledTime + 0.5f;
try
{
CommandConsole instance = CommandConsole.instance;
CL_GameManager gMan = CL_GameManager.gMan;
if ((Object)(object)instance != (Object)null && ((Object)(object)instance != (Object)(object)lastConsole || (Object)(object)gMan != (Object)(object)lastGameManager))
{
bool num = (Object)(object)gMan != (Object)null && (Object)(object)gMan != (Object)(object)lastGameManager;
lastConsole = instance;
lastGameManager = gMan;
Commands.RegisterAll();
if (num)
{
Spawner.OnNewRun();
Commands.NewRunReset();
if (AutoEnableCheats.Value && !CommandConsole.cheatsEnabled)
{
instance.ExecuteCommand("cheats true", false);
}
}
}
}
catch (Exception ex)
{
Log.LogError((object)("Registration check failed: " + ex));
}
}
try
{
Commands.Tick();
}
catch (Exception ex2)
{
Log.LogError((object)ex2);
}
try
{
KeyCode value = ExtraConsoleKey.Value;
if ((int)value != 0 && Input.GetKeyDown(value) && (Object)(object)CommandConsole.instance != (Object)null && (Object)(object)CL_GameManager.gMan != (Object)null)
{
if (toggleConsole == null)
{
toggleConsole = typeof(CommandConsole).GetMethod("ToggleConsole", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
if (toggleConsole != null)
{
toggleConsole.Invoke(CommandConsole.instance, null);
}
}
}
catch (Exception ex3)
{
Log.LogWarning((object)("Console toggle failed: " + ex3.Message));
}
}
}
public enum Category
{
Denizen,
Item,
Prop,
Entity,
Object
}
public class SpawnEntry
{
public string key;
public string displayName;
public Category category;
public string source;
public GameObject prefab;
public bool embedded;
public Item_Object item;
public string Describe()
{
return "[" + category.ToString() + "] " + displayName + (embedded ? (" (from level " + source + ")") : (" (" + source + ")"));
}
}
public static class Registry
{
public static readonly List<SpawnEntry> All = new List<SpawnEntry>();
private static readonly Dictionary<string, SpawnEntry> byKey = new Dictionary<string, SpawnEntry>(StringComparer.OrdinalIgnoreCase);
private static readonly HashSet<string> partTypes = new HashSet<string> { "DEN_Hunter_Arm", "DEN_HadalDiver_Segment", "DEN_Teeth_Animator" };
private static readonly Type[] forbiddenRootTypes = new Type[7]
{
typeof(ENT_Player),
typeof(CL_GameManager),
typeof(CommandConsole),
typeof(WorldLoader),
typeof(CL_UIManager),
typeof(MenuManager),
typeof(Inventory)
};
public static bool Built { get; private set; }
public static void EnsureBuilt()
{
if (!Built)
{
Build();
}
}
public static void Build()
{
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
Stopwatch stopwatch = Stopwatch.StartNew();
All.Clear();
byKey.Clear();
try
{
if ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.gameEntityPrefabs != null)
{
foreach (GameEntity gameEntityPrefab in CL_GameManager.gMan.gameEntityPrefabs)
{
if ((Object)(object)gameEntityPrefab != (Object)null)
{
AddRoot(((Component)gameEntityPrefab).gameObject, "game entity list");
}
}
}
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("gameEntityPrefabs scan failed: " + ex.Message));
}
List<GameObject> list = new List<GameObject>();
try
{
WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
if ((Object)(object)fullCombinedAssetDatabase != (Object)null)
{
foreach (GameObject denizenPrefab in fullCombinedAssetDatabase.denizenPrefabs)
{
if ((Object)(object)denizenPrefab != (Object)null)
{
AddRoot(denizenPrefab, "asset database");
}
}
foreach (GameObject itemPrefab in fullCombinedAssetDatabase.itemPrefabs)
{
if ((Object)(object)itemPrefab != (Object)null)
{
AddRoot(itemPrefab, "asset database");
}
}
foreach (GameObject entityPrefab in fullCombinedAssetDatabase.entityPrefabs)
{
if ((Object)(object)entityPrefab != (Object)null)
{
AddRoot(entityPrefab, "asset database");
}
}
foreach (LevelAssetHolder levelAsset in fullCombinedAssetDatabase.levelAssets)
{
try
{
if (levelAsset != null && (Object)(object)levelAsset.level != (Object)null)
{
list.Add(((Component)levelAsset.level).gameObject);
}
}
catch
{
}
}
}
}
catch (Exception ex2)
{
Plugin.Log.LogWarning((object)("asset database scan failed: " + ex2.Message));
}
try
{
GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
foreach (GameObject val in array)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Scene scene = val.scene;
if (!((Scene)(ref scene)).IsValid() && !((Object)(object)val.transform.parent != (Object)null))
{
if ((Object)(object)val.GetComponent<M_Level>() != (Object)null)
{
list.Add(val);
}
else
{
AddRoot(val, "prefab");
}
}
}
}
catch (Exception ex3)
{
Plugin.Log.LogWarning((object)("prefab scan failed: " + ex3.Message));
}
HashSet<GameObject> hashSet = new HashSet<GameObject>();
foreach (GameObject item in list)
{
if (!((Object)(object)item == (Object)null) && hashSet.Add(item))
{
try
{
ScanEmbedded(item);
}
catch (Exception ex4)
{
Plugin.Log.LogWarning((object)("level scan failed for " + ((Object)item).name + ": " + ex4.Message));
}
}
}
All.Sort(delegate(SpawnEntry a, SpawnEntry b)
{
int num = a.category.CompareTo(b.category);
return (num == 0) ? string.Compare(a.key, b.key, StringComparison.OrdinalIgnoreCase) : num;
});
Built = true;
stopwatch.Stop();
Plugin.Log.LogInfo((object)("Registry built: " + All.Count + " spawnables in " + stopwatch.ElapsedMilliseconds + "ms"));
}
public static string Summary()
{
IEnumerable<string> source = from Category c in Enum.GetValues(typeof(Category))
select c.ToString() + ": " + All.Count((SpawnEntry e) => e.category == c);
return string.Join(", ", source.ToArray());
}
internal static bool IsDenizenType(Type t)
{
if (t == null)
{
return false;
}
if (partTypes.Contains(t.Name))
{
return false;
}
if (typeof(ENT_Player).IsAssignableFrom(t))
{
return false;
}
if (typeof(Denizen).IsAssignableFrom(t))
{
return true;
}
if (typeof(AIGameEntity).IsAssignableFrom(t))
{
return true;
}
return t.Name.StartsWith("DEN_", StringComparison.Ordinal);
}
private static bool HasDenizen(GameObject root)
{
MonoBehaviour[] componentsInChildren = root.GetComponentsInChildren<MonoBehaviour>(true);
foreach (MonoBehaviour val in componentsInChildren)
{
if ((Object)(object)val != (Object)null && IsDenizenType(((object)val).GetType()))
{
return true;
}
}
return false;
}
private static bool IsForbidden(GameObject root)
{
Type[] array = forbiddenRootTypes;
foreach (Type type in array)
{
if ((Object)(object)root.GetComponentInChildren(type, true) != (Object)null)
{
return true;
}
}
if ((Object)(object)root.GetComponent<RectTransform>() != (Object)null)
{
return true;
}
if ((Object)(object)root.GetComponent<Camera>() != (Object)null)
{
return true;
}
return false;
}
private static void AddRoot(GameObject go, string source)
{
if (!((Object)(object)go == (Object)null) && !((Object)(object)go.GetComponent<M_Level>() != (Object)null) && !IsForbidden(go))
{
Item_Object component = go.GetComponent<Item_Object>();
Category category = (((Object)(object)component != (Object)null) ? Category.Item : ((!HasDenizen(go)) ? (((Object)(object)go.GetComponentInChildren<CL_Prop>(true) != (Object)null) ? Category.Prop : ((!((Object)(object)go.GetComponentInChildren<GameEntity>(true) != (Object)null)) ? Category.Object : Category.Entity)) : Category.Denizen));
Add(new SpawnEntry
{
displayName = ((Object)go).name,
category = category,
source = source,
prefab = go,
item = component
});
}
}
private static void ScanEmbedded(GameObject levelRoot)
{
string name = ((Object)levelRoot).name;
Transform transform = levelRoot.transform;
HashSet<Transform> hashSet = new HashSet<Transform>();
MonoBehaviour[] componentsInChildren = levelRoot.GetComponentsInChildren<MonoBehaviour>(true);
foreach (MonoBehaviour val in componentsInChildren)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Category category;
if (IsDenizenType(((object)val).GetType()))
{
category = Category.Denizen;
}
else
{
if (!(val is CL_Prop))
{
continue;
}
category = Category.Prop;
}
Transform transform2 = ((Component)val).transform;
if (!hashSet.Contains(transform2) && !HasAncestorEntity(transform2, transform))
{
Transform val2 = transform2;
while ((Object)(object)val2.parent != (Object)null && (Object)(object)val2.parent != (Object)(object)transform && val2.parent.childCount == 1 && (Object)(object)((Component)val2.parent).GetComponent<M_Level>() == (Object)null)
{
val2 = val2.parent;
}
hashSet.Add(transform2);
Add(new SpawnEntry
{
displayName = ((Object)((Component)transform2).gameObject).name,
category = category,
source = name,
prefab = ((Component)val2).gameObject,
embedded = true
});
}
}
}
private static bool HasAncestorEntity(Transform t, Transform stopAt)
{
Transform parent = t.parent;
while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)stopAt)
{
MonoBehaviour[] components = ((Component)parent).GetComponents<MonoBehaviour>();
foreach (MonoBehaviour val in components)
{
if (!((Object)(object)val == (Object)null) && (IsDenizenType(((object)val).GetType()) || val is CL_Prop))
{
return true;
}
}
parent = parent.parent;
}
return false;
}
private static void Add(SpawnEntry e)
{
string text = MakeKey(e.displayName);
if (string.IsNullOrEmpty(text))
{
return;
}
if (byKey.TryGetValue(text, out var value))
{
if ((Object)(object)value.prefab == (Object)(object)e.prefab || e.embedded || (value.category == e.category && !value.embedded))
{
return;
}
int num = 2;
string text2;
do
{
text2 = text + "#" + num++;
}
while (byKey.ContainsKey(text2));
text = text2;
}
e.key = text;
byKey[text] = e;
All.Add(e);
}
public static string MakeKey(string name)
{
if (name == null)
{
return "";
}
StringBuilder stringBuilder = new StringBuilder(name.Length);
string text = name.Trim();
foreach (char c in text)
{
if (char.IsWhiteSpace(c))
{
stringBuilder.Append('_');
}
else if (c != '"' && c != ';')
{
stringBuilder.Append(char.ToLowerInvariant(c));
}
}
return stringBuilder.ToString();
}
public static IEnumerable<SpawnEntry> Filter(Category? cat)
{
EnsureBuilt();
if (!cat.HasValue)
{
return All;
}
return All.Where((SpawnEntry e) => e.category == cat.Value);
}
public static List<SpawnEntry> Search(string text, Category? cat)
{
IEnumerable<SpawnEntry> source = Filter(cat);
text = MakeKey(text ?? "");
if (text.Length == 0)
{
return source.ToList();
}
return (from e in source
where e.key.Contains(text) || MakeKey(e.source).Contains(text)
orderby (!(e.key == text)) ? (e.key.StartsWith(text) ? 1 : 2) : 0, e.key.Length
select e).ToList();
}
public static SpawnEntry Find(string text, Category? cat, out int alternatives)
{
alternatives = 0;
EnsureBuilt();
string k = MakeKey(text);
if (byKey.TryGetValue(k, out var value) && (!cat.HasValue || value.category == cat.Value))
{
return value;
}
List<SpawnEntry> list = (from e in Filter(cat)
where e.key.Contains(k)
orderby (!e.key.StartsWith(k)) ? 1 : 0, e.key.Length
select e).ToList();
if (list.Count == 0)
{
return null;
}
alternatives = list.Count - 1;
return list[0];
}
public static List<(string, string)> AutocompleteFor(string typed, Category? cat, int max = 80)
{
List<(string, string)> list = new List<(string, string)>();
foreach (SpawnEntry item in Search(typed, cat))
{
list.Add((item.key, item.Describe()));
if (list.Count >= max)
{
break;
}
}
return list;
}
public static string Dump()
{
EnsureBuilt();
string text = Path.Combine(Paths.ConfigPath, "OmniConsole_Spawnables.txt");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("OmniConsole spawnables (" + All.Count + ") - " + Summary());
stringBuilder.AppendLine("Use: spawn <name> [count] | give <item> [count]");
foreach (Category c in Enum.GetValues(typeof(Category)))
{
stringBuilder.AppendLine();
stringBuilder.AppendLine("==== " + c.ToString() + " ====");
foreach (SpawnEntry item in All.Where((SpawnEntry x) => x.category == c))
{
stringBuilder.AppendLine(item.key.PadRight(48) + (item.embedded ? "level: " : "") + item.source);
}
}
File.WriteAllText(text, stringBuilder.ToString());
return text;
}
}
public class SpawnMenu : MonoBehaviour
{
private static SpawnMenu inst;
private bool open;
private Rect win = new Rect(80f, 60f, 760f, 600f);
private string search = "";
private string lastSearch;
private int tab;
private int lastTab = -1;
private string countText = "1";
private bool giveItems = true;
private Vector2 scroll;
private List<SpawnEntry> results = new List<SpawnEntry>();
private int lastRegistryCount = -1;
private static readonly string[] tabs = new string[6] { "All", "Denizens", "Items", "Props", "Entities", "Objects" };
private static readonly Category?[] tabCats = new Category?[6]
{
null,
Category.Denizen,
Category.Item,
Category.Prop,
Category.Entity,
Category.Object
};
private GUIStyle rowStyle;
private GUIStyle srcStyle;
private GUIStyle headerStyle;
private GUIStyle warnStyle;
private Texture2D bg;
private void Awake()
{
inst = this;
}
public static void Toggle()
{
if ((Object)(object)inst != (Object)null)
{
inst.SetOpen(!inst.open);
}
}
private void SetOpen(bool o)
{
if (o && (Object)(object)ENT_Player.GetPlayer() == (Object)null)
{
CommandConsole.Log("Start a run first - the spawn menu needs a player.");
return;
}
open = o;
if (open)
{
Registry.EnsureBuilt();
lastSearch = null;
}
else if ((Object)(object)CL_GameManager.gMan != (Object)null && !CommandConsole.IsConsoleVisible())
{
CL_GameManager.gMan.lockPlayerInput = false;
if (!CL_GameManager.isDead() && !CL_GameManager.gMan.isPaused)
{
Cursor.lockState = (CursorLockMode)1;
Cursor.visible = false;
}
}
}
private void Update()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(Plugin.SpawnMenuKey.Value) && !CommandConsole.IsConsoleVisible())
{
SetOpen(!open);
}
if (open && Input.GetKeyDown((KeyCode)27))
{
SetOpen(o: false);
}
if (open && (Object)(object)ENT_Player.GetPlayer() == (Object)null)
{
SetOpen(o: false);
}
}
private void LateUpdate()
{
if (open)
{
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = true;
if ((Object)(object)CL_GameManager.gMan != (Object)null)
{
CL_GameManager.gMan.lockPlayerInput = true;
}
}
}
private void InitStyles()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
//IL_008e: 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_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Expected O, but got Unknown
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Expected O, but got Unknown
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
if (rowStyle == null)
{
bg = new Texture2D(1, 1);
bg.SetPixel(0, 0, new Color(0.06f, 0.06f, 0.07f, 0.96f));
bg.Apply();
rowStyle = new GUIStyle(GUI.skin.button)
{
alignment = (TextAnchor)3,
fontSize = 14,
richText = true
};
rowStyle.padding.left = 8;
srcStyle = new GUIStyle(GUI.skin.label)
{
alignment = (TextAnchor)5,
fontSize = 11
};
srcStyle.normal.textColor = new Color(0.6f, 0.6f, 0.6f);
headerStyle = new GUIStyle(GUI.skin.label)
{
fontSize = 12,
richText = true
};
warnStyle = new GUIStyle(GUI.skin.label)
{
fontSize = 13,
richText = true,
wordWrap = true
};
warnStyle.normal.textColor = new Color(1f, 0.8f, 0.3f);
}
}
private void OnGUI()
{
//IL_001a: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: 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_006e: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
if (open)
{
InitStyles();
GUI.depth = -1000;
GUI.DrawTexture(win, (Texture)(object)bg);
win = GUI.Window(12648430, win, new WindowFunction(DrawWindow), "OmniConsole - Spawn Everything (" + ((object)Plugin.SpawnMenuKey.Value/*cast due to .constrained prefix*/).ToString() + " / Esc to close)");
}
}
private void Run(string cmd)
{
if (!((Object)(object)CommandConsole.instance == (Object)null))
{
CommandConsole.instance.ExecuteCommand(cmd, true);
}
}
private void DrawWindow(int id)
{
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: Unknown result type (might be due to invalid IL or missing references)
//IL_0312: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
//IL_03da: Unknown result type (might be due to invalid IL or missing references)
//IL_0445: Unknown result type (might be due to invalid IL or missing references)
//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
if (Registry.All.Count != lastRegistryCount)
{
lastRegistryCount = Registry.All.Count;
lastSearch = null;
}
GUILayout.Space(4f);
tab = GUILayout.Toolbar(tab, tabs, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Label("Search", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
GUI.SetNextControlName("omni_search");
search = GUILayout.TextField(search ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(250f) });
GUILayout.Label("Count", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(42f) });
countText = GUILayout.TextField(countText ?? "1", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
if (tabCats[tab] == Category.Item || !tabCats[tab].HasValue)
{
giveItems = GUILayout.Toggle(giveItems, giveItems ? " Items -> inventory" : " Items -> drop in world", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(170f) });
}
GUILayout.EndHorizontal();
if (search != lastSearch || tab != lastTab)
{
lastSearch = search;
lastTab = tab;
results = Registry.Search(search, tabCats[tab]);
scroll = Vector2.zero;
}
if (!CommandConsole.cheatsEnabled)
{
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Label("Cheats are off, so spawning won't work yet. Enabling cheats disables stat saving for this run (vanilla rule).", warnStyle, Array.Empty<GUILayoutOption>());
if (GUILayout.Button("Enable cheats", (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(120f),
GUILayout.Height(30f)
}))
{
Run("cheats true");
}
GUILayout.EndHorizontal();
}
GUILayout.Label("<b>" + results.Count + "</b> results <color=#888>" + Registry.Summary() + "</color>", headerStyle, Array.Empty<GUILayoutOption>());
Rect rect = GUILayoutUtility.GetRect(10f, 10000f, 200f, 10000f, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.ExpandHeight(true),
GUILayout.ExpandWidth(true)
});
Rect val = default(Rect);
((Rect)(ref val))..ctor(0f, 0f, ((Rect)(ref rect)).width - 20f, Mathf.Max(((Rect)(ref rect)).height, (float)results.Count * 26f));
scroll = GUI.BeginScrollView(rect, scroll, val);
int num = Mathf.Max(0, (int)(scroll.y / 26f));
int num2 = Mathf.Min(results.Count, num + (int)(((Rect)(ref rect)).height / 26f) + 2);
Rect val2 = default(Rect);
for (int i = num; i < num2; i++)
{
SpawnEntry spawnEntry = results[i];
((Rect)(ref val2))..ctor(0f, (float)i * 26f, ((Rect)(ref val)).width, 24f);
string text = ((spawnEntry.category == Category.Denizen) ? "#ff8a80" : ((spawnEntry.category == Category.Item) ? "#9fe39f" : ((spawnEntry.category == Category.Prop) ? "#90caf9" : ((spawnEntry.category == Category.Entity) ? "#ffd180" : "#cccccc"))));
if (GUI.Button(val2, "<color=" + text + ">" + spawnEntry.key + "</color>", rowStyle))
{
OnClick(spawnEntry);
}
GUI.Label(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width - 8f, ((Rect)(ref val2)).height), spawnEntry.category.ToString() + (spawnEntry.embedded ? " · level " : " · ") + spawnEntry.source, srcStyle);
}
GUI.EndScrollView();
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
if (GUILayout.Button("Undo", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
Run("undo");
}
if (GUILayout.Button("Clear my spawns", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
Run("clearspawned");
}
if (GUILayout.Button("Kill all denizens", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
Run("killall");
}
if (GUILayout.Button("Freeze/unfreeze AI", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
Run("freezedenizens");
}
if (GUILayout.Button("Rescan", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
Run("rescan");
lastSearch = null;
}
if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
SetOpen(o: false);
}
GUILayout.EndHorizontal();
GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
}
private void OnClick(SpawnEntry e)
{
if (!int.TryParse(countText, out var result) || result < 1)
{
result = 1;
}
string text = "\"" + e.key + "\" " + result;
if (e.category == Category.Item && giveItems)
{
Run("give " + text);
}
else if (e.category == Category.Item)
{
Run("dropitem " + text);
}
else
{
Run("spawn " + text);
}
}
}
public static class Spawner
{
private static readonly List<GameObject> spawned = new List<GameObject>();
public static int SpawnedCount
{
get
{
spawned.RemoveAll((GameObject g) => (Object)(object)g == (Object)null);
return spawned.Count;
}
}
public static Camera Cam
{
get
{
Camera val = Camera.main;
if ((Object)(object)val == (Object)null)
{
ENT_Player player = ENT_Player.GetPlayer();
if ((Object)(object)player != (Object)null)
{
val = player.cam;
}
}
return val;
}
}
public static void OnNewRun()
{
spawned.Clear();
}
public static bool Aim(out RaycastHit hit, float maxDistance = 1000f)
{
//IL_0001: 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_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: 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_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
hit = default(RaycastHit);
Camera cam = Cam;
if ((Object)(object)cam == (Object)null)
{
return false;
}
RaycastHit[] array = Physics.RaycastAll(new Ray(((Component)cam).transform.position, ((Component)cam).transform.forward), maxDistance, -1, (QueryTriggerInteraction)1);
Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
ENT_Player player = ENT_Player.GetPlayer();
RaycastHit[] array2 = array;
for (int num = 0; num < array2.Length; num++)
{
RaycastHit val = array2[num];
if (!((Object)(object)player != (Object)null) || !((Component)((RaycastHit)(ref val)).collider).transform.IsChildOf(((Component)player).transform))
{
hit = val;
return true;
}
}
return false;
}
public static void GetSpawnPoint(out Vector3 pos, out Vector3 normal, out bool hitSomething)
{
//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_0017: 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_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
Camera cam = Cam;
if (Aim(out var hit))
{
pos = ((RaycastHit)(ref hit)).point;
normal = ((RaycastHit)(ref hit)).normal;
hitSomething = true;
}
else
{
hitSomething = false;
normal = Vector3.up;
pos = (((Object)(object)cam != (Object)null) ? (((Component)cam).transform.position + ((Component)cam).transform.forward * 3f) : Vector3.zero);
}
}
public static GameObject SpawnAtAim(SpawnEntry e)
{
//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)
GetSpawnPoint(out var pos, out var normal, out var hitSomething);
return SpawnAt(e, pos, normal, hitSomething);
}
public static GameObject SpawnAt(SpawnEntry e, Vector3 pos, Vector3 normal, bool pushOutOfSurface = true)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: 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_007d: 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_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Expected O, but got Unknown
//IL_00ed: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: 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_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0229: 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_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0281: 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_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
if (e == null || (Object)(object)e.prefab == (Object)null)
{
return null;
}
Camera cam = Cam;
Quaternion val;
if (!(normal.y > 0.7f) || !Plugin.SpawnFacesPlayer.Value || !((Object)(object)cam != (Object)null))
{
val = ((e.category != Category.Item && e.category != Category.Prop) ? Quaternion.LookRotation(normal) : Quaternion.identity);
}
else
{
Vector3 val2 = ((Component)cam).transform.position - pos;
val2.y = 0f;
val = ((((Vector3)(ref val2)).sqrMagnitude > 0.001f) ? Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up) : Quaternion.identity);
}
GameObject val3 = null;
Transform val4 = null;
bool activeSelf = e.prefab.activeSelf;
if (activeSelf)
{
e.prefab.SetActive(false);
}
GameObject val5;
try
{
if (e.embedded)
{
val3 = new GameObject("OmniSpawn_" + e.key);
val3.transform.SetPositionAndRotation(pos, val);
val4 = new GameObject("OmniSpawnInner").transform;
val4.SetParent(val3.transform, false);
val5 = Object.Instantiate<GameObject>(e.prefab, val4);
val5.transform.localPosition = Vector3.zero;
val5.transform.localRotation = Quaternion.identity;
}
else
{
val5 = Object.Instantiate<GameObject>(e.prefab, pos, val);
}
}
finally
{
if (activeSelf)
{
e.prefab.SetActive(true);
}
}
((Object)val5).name = ((Object)e.prefab).name;
val5.SetActive(true);
if ((Object)(object)val3 != (Object)null)
{
spawned.Add(val3);
if ((Object)(object)val5 != (Object)null && (Object)(object)val5.transform.parent != (Object)(object)val4)
{
spawned.Add(val5);
}
}
else
{
spawned.Add(val5);
}
if (pushOutOfSurface && (Object)(object)val5 != (Object)null)
{
Physics.SyncTransforms();
Bounds? bounds = GetBounds(val5);
if (bounds.HasValue)
{
Bounds value = bounds.Value;
Vector3 extents = ((Bounds)(ref value)).extents;
float num = Mathf.Abs(extents.x * normal.x) + Mathf.Abs(extents.y * normal.y) + Mathf.Abs(extents.z * normal.z);
value = bounds.Value;
float num2 = Vector3.Dot(((Bounds)(ref value)).center - pos, normal);
float num3 = Mathf.Clamp(num - num2, 0f, 6f) + 0.02f;
Transform root = val5.transform.root;
root.position += normal * num3;
}
}
return val5;
}
private static Bounds? GetBounds(GameObject g)
{
//IL_0054: 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)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
Bounds? result = null;
Collider[] componentsInChildren = g.GetComponentsInChildren<Collider>();
foreach (Collider val in componentsInChildren)
{
if (!val.isTrigger && val.enabled)
{
if (result.HasValue)
{
Bounds value = result.Value;
((Bounds)(ref value)).Encapsulate(val.bounds);
result = value;
}
else
{
result = val.bounds;
}
}
}
if (!result.HasValue)
{
Renderer[] componentsInChildren2 = g.GetComponentsInChildren<Renderer>();
foreach (Renderer val2 in componentsInChildren2)
{
if (val2.enabled)
{
if (result.HasValue)
{
Bounds value2 = result.Value;
((Bounds)(ref value2)).Encapsulate(val2.bounds);
result = value2;
}
else
{
result = val2.bounds;
}
}
}
}
return result;
}
public static GameObject Clone(GameObject source, Vector3 pos)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
GameObject val = Object.Instantiate<GameObject>(source, pos, source.transform.rotation);
((Object)val).name = ((Object)source).name;
if (!val.activeSelf)
{
val.SetActive(true);
}
spawned.Add(val);
return val;
}
public static bool GiveItem(SpawnEntry e, bool last)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_0075: Unknown result type (might be due to invalid IL or missing references)
if (e == null || (Object)(object)e.item == (Object)null || e.item.itemData == null)
{
return false;
}
Inventory instance = Inventory.instance;
if ((Object)(object)instance == (Object)null || (Object)(object)ENT_Player.GetPlayer() == (Object)null)
{
return false;
}
Item clone = e.item.itemData.GetClone((Item)null, false);
instance.AddItemToInventoryScreen(new Vector3(0f, 0f, 1f) + Random.insideUnitSphere * 0.01f, clone, true, false, last);
return true;
}
public static bool Undo(out string what)
{
what = null;
for (int num = spawned.Count - 1; num >= 0; num--)
{
GameObject val = spawned[num];
spawned.RemoveAt(num);
if (!((Object)(object)val == (Object)null))
{
what = ((Object)val).name;
Object.Destroy((Object)(object)val);
return true;
}
}
return false;
}
public static int ClearAll()
{
int num = 0;
foreach (GameObject item in spawned)
{
if (!((Object)(object)item == (Object)null))
{
Object.Destroy((Object)(object)item);
num++;
}
}
spawned.Clear();
return num;
}
}