static void ModAV(string av, string value) { object convertedValue = TypeUtils.StringToNumericAuto(value); //we *should* now have the correct type in the box //DevConsole.singleton.Log(convertedValue.GetType().Name); try { if (convertedValue.GetType() == typeof(float)) { GameState.Instance.PlayerRpgState.ModAV(av, (float)convertedValue); } else if (convertedValue.GetType() == typeof(int)) { GameState.Instance.PlayerRpgState.ModAV(av, (int)convertedValue); } else if (convertedValue.GetType() == typeof(string)) { GameState.Instance.PlayerRpgState.ModAV(av, (string)convertedValue); } else { GameState.Instance.PlayerRpgState.ModAV(av, convertedValue); } } catch (Exception e) { ConsoleModule.WriteLine(e.ToString(), LogLevel.Error); } }
static void Prbt(string tag) { var objs = WorldUtils.FindEntitiesWithTag(tag); if (objs == null || objs.Count < 1) { ConsoleModule.WriteLine("No refs found with tag!"); return; } if (objs.Count > 1) { ConsoleModule.WriteLine("More than one ref with tag!"); } var obj = objs[0]; if (obj != null && obj.GetComponent <BaseController>()) { SelectedTID = obj.gameObject.name; SelectedObject = obj.gameObject; } else { ConsoleModule.WriteLine("Ref null or invalid!"); } ConsoleModule.WriteLine("Found TID: " + SelectedTID); }
static void GetInfo() { if (SelectedObject != null) { StringBuilder sb = new StringBuilder(256); //name, form id sb.AppendFormat("TID: {0} | FID: {1} \n", SelectedObject.name, SelectedObject.GetComponent <BaseController>().Ref()?.FormID ?? "N/A"); //tags etc sb.AppendFormat("Unity Tag: {0} | Unity Layer: {1} | Entity tags: {2} \n", SelectedObject.tag, SelectedObject.layer, SelectedObject.GetComponent <BaseController>().Ref()?.Tags?.ToNiceString() ?? "N/A"); //coords sb.AppendFormat("Location: ({0:f2},{1:f2},{2:f2})\n", SelectedObject.transform.position.x, SelectedObject.transform.position.y, SelectedObject.transform.position.z); //enabled? active? sb.AppendFormat("Active: {0} | Visible: {1}", SelectedObject.activeSelf, SelectedObject.GetComponent <BaseController>().Ref()?.GetVisibility().ToString() ?? "N/A"); ConsoleModule.WriteLine(sb.ToString()); } else { ConsoleModule.WriteLine("No object selected!"); } }
/// <summary> /// Executes a command from a command string /// </summary> internal void ExecuteCommand(string commandLine) { string[] splitCommand = SplitCommandLine(commandLine); //Debug.Log(splitCommand.ToNiceString()); if (Commands.ContainsKey(splitCommand[0])) { int numArgs = splitCommand.Length - 1; List <MethodInfo> commandMethodsList = Commands[splitCommand[0]]; //dependency resolution is pretty stupid: we look at the number of arguments var matchingCommandMethods = commandMethodsList.Where(m => m.GetParameters().Length == numArgs).ToArray(); if (matchingCommandMethods.Length == 0) { Debug.LogError($"Failed to run command '{splitCommand[0]}' because no methods with matching parameter count were found!"); ConsoleModule.WriteLine("Did you mean:\n" + string.Join("\n", FindSimilarCommands(splitCommand[0], splitCommand.Length - 1))); } else { if (matchingCommandMethods.Length > 1) { Debug.LogWarning($"Command '{splitCommand[0]}' has {matchingCommandMethods.Length} possible methods!\n" + matchingCommandMethods.Select(m => m.ReflectedType.Name + "." + m.Name).ToNiceString()); } MethodInfo commandMethod = matchingCommandMethods[0]; ParameterInfo[] parameterInfos = commandMethod.GetParameters(); //coerce the arguments into fitting object[] coercedArgs = new object[numArgs]; for (int argNum = 0; argNum < numArgs; argNum++) { var parameterInfo = parameterInfos[argNum]; if (parameterInfo.ParameterType == typeof(string)) { coercedArgs[argNum] = splitCommand[argNum + 1]; } else { coercedArgs[argNum] = Convert.ChangeType(splitCommand[argNum + 1], parameterInfo.ParameterType); } } try { commandMethod.Invoke(null, coercedArgs); } catch (Exception e) { Debug.LogError($"Command {splitCommand[0]} failed: {(e.InnerException ?? e).GetType().Name}"); Debug.LogException(e); } } } else { Debug.LogError($"Failed to run command '{splitCommand[0]}' because no methods with matching name were found!"); ConsoleModule.WriteLine("Did you mean:\n" + string.Join("\n", FindSimilarCommands(splitCommand[0], splitCommand.Length - 1))); } }
static void ListItems() { var items = GameState.Instance.PlayerRpgState.Inventory.GetItemsListActual(); foreach (var item in items) { ConsoleModule.WriteLine(item.ToString()); } }
static void ListAllMonologues() { StringBuilder sb = new StringBuilder(Instance.LoadedMonologues.Count * 80); foreach (var monologue in Instance.LoadedMonologues.Keys) { sb.AppendLine(monologue); } ConsoleModule.WriteLine(sb.ToString()); }
static void RemoveItem(string item, string quantity) { try { GameState.Instance.PlayerRpgState.Inventory.UseItem(item, int.Parse(quantity)); } catch (Exception e) { ConsoleModule.WriteLine(e.ToString(), LogLevel.Error); } }
public static void CommandListMacros() { StringBuilder sb = new StringBuilder(80 * Instance.SubMap.Count); foreach (var key in Instance.SubMap.Keys) { sb.AppendLine($"<{key}>"); } ConsoleModule.WriteLine(sb.ToString()); }
static void ListAllMonologues() { var dialogueModule = CCBase.GetModule <DialogueModule>(); StringBuilder sb = new StringBuilder(dialogueModule.LoadedMonologues.Count * 80); foreach (var monologue in dialogueModule.LoadedMonologues.Keys) { sb.AppendLine(monologue); } ConsoleModule.WriteLine(sb.ToString()); }
static void ListAllEffects() { var effects = CoreUtils.LoadResources <GameObject>("Effects/"); StringBuilder sb = new StringBuilder(effects.Length * 32); foreach (var effect in effects) { sb.AppendLine(effect.name); } ConsoleModule.WriteLine(sb.ToString()); }
private static void CallHooked(string hook) { if (Enum.TryParse <ScriptHook>(hook, out ScriptHook parsedHook)) { ScriptingModule.CallHooked(parsedHook, null, new object[] { }); } else { ConsoleModule.WriteLine($"Failed to call hooked scripts because \"{hook}\" is not a valid built-in hook (were you looking for CallNamedHooked instead?)"); } }
public static void CommandReplace(string baseString, string listName) { try { ConsoleModule.WriteLine(Instance.GetString(baseString, listName, false, false)); } catch (Exception e) { ConsoleModule.WriteLine(e.ToString(), LogLevel.Error); } }
static void ListAllEntities() { var entities = CoreUtils.LoadResources <GameObject>("Entities/"); StringBuilder sb = new StringBuilder(entities.Length * 32); foreach (var entity in entities) { sb.AppendLine(entity.name); } ConsoleModule.WriteLine(sb.ToString()); }
private static void ListAll() { var scripts = ScriptingModule.GetCallableMethods(); StringBuilder sb = new StringBuilder(scripts.Count * 64); foreach (var s in scripts) { sb.AppendLine(string.Format("{0} : {1}", s.Key, s.Value.ToString())); } ConsoleModule.WriteLine(sb.ToString()); }
public static void CommandMacro(string baseString) { try { ConsoleModule.WriteLine(Instance.SubstituteMacros(baseString)); } catch (Exception e) { ConsoleModule.WriteLine(e.ToString(), LogLevel.Error); } }
protected override void OnCreate(Bundle savedInstanceState) { #region Android Stuff base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab); fab.Click += FabOnClick; #endregion consoleOutput = FindViewById <TextView>(Resource.Id.ConsoleOutput); titleLabel = FindViewById <TextView>(Resource.Id.titleLabel); CommandBar = FindViewById <EditText>(Resource.Id.CommandBar); // Sets up the base console system ClientServer = new ModuleServer(ref CommQueue); int id = ClientServer.ID; ConsoleClient = new ConsoleModule(ref CommQueue); id = ConsoleClient.ID; ConsoleClient.ConsolePostEvent += ConsoleClient_MessageRxEvent; ClientServer.Subscribe(ConsoleClient); // Sets up the networking and port system TCPClient = new NetworkingTCPClient(ref CommQueue); ClientServer.Subscribe(TCPClient); CommandBar.KeyPress += (object sender, View.KeyEventArgs e) => { e.Handled = false; if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter) { Toast.MakeText(this, "Message Transmitting!", ToastLength.Short).Show(); e.Handled = true; ClientServer.SendMessage("Post", new List <string>() { "Command: " + CommandBar.Text }, ConsoleClient.ID); // Updates the console List <string> arguments = CommandSyntaxInterpreter.ParseMessageBySpace(CommandBar.Text); // Finds the arguments based on the location of spaces string command = arguments[0]; // Extracts the actual command arguments.RemoveAt(0); // Removes the command from the list of arguments ClientServer.SendMessage(command, arguments); // Sends the command CommandBar.Text = ""; } }; }
static void DisplayTime() { string timeStr = string.Format("Real Time: {0:F1}s\nGame Time: {1:F1}s\nWorld Time: {2:F1}d, {3}s\n\nUnity Timescale: {4}\nWorld Timescale: {5}", GameState.Instance.WorldState.RealTimeElapsed, GameState.Instance.WorldState.GameTimeElapsed, GameState.Instance.WorldState.WorldDaysElapsed, GameState.Instance.WorldState.WorldSecondsElapsed, Time.timeScale, GameState.Instance.WorldState.WorldTimeScale); ConsoleModule.WriteLine(timeStr); }
static void CountItem(string item) { try { var quantity = GameState.Instance.PlayerRpgState.Inventory.CountItem(item); ConsoleModule.WriteLine(string.Format("{0}:{1}", item, quantity)); } catch (Exception e) { ConsoleModule.WriteLine(e.ToString(), LogLevel.Error); } }
static void ListSharedContainers() { var containersDict = GameState.Instance.ContainerState; StringBuilder sb = new StringBuilder(containersDict.Count * 64); foreach (var kvp in containersDict) { sb.AppendFormat("{0} ({1} items) \n", kvp.Key, kvp.Value.ListItems().Length); } ConsoleModule.WriteLine(sb.ToString()); }
static void PrintCoreParams() { Dictionary <string, object> coreParams = new Dictionary <string, object>(); var props = typeof(CoreParams).GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var prop in props) { coreParams.Add(prop.Name, prop.GetValue(null)); } ConsoleModule.WriteLine(DebugUtils.JsonStringify(coreParams)); }
static void GetAV(string av) { try { var value = GameState.Instance.PlayerRpgState.GetAV <object>(av); ConsoleModule.WriteLine(string.Format("{0} : {1}", av, value)); } catch (Exception e) { ConsoleModule.WriteLine(e.ToString(), LogLevel.Error); } }
static void ListEntitiesInScene() { StringBuilder sb = new StringBuilder(); var entities = CoreUtils.GetWorldRoot().GetComponentsInChildren <BaseController>(true); foreach (var entity in entities) { sb.AppendLine($"{entity.gameObject.name} ({entity.FormID ?? entity.EditorFormID} : {entity.GetType().Name}) [{entity.transform.position.ToString("F2")}] {(entity.isActiveAndEnabled ? "" : "(disabled)")} {(entity is ITakeDamage && WorldUtils.IsAlive(entity) ? "" : "(dead)")}"); } ConsoleModule.WriteLine(sb.ToString()); }
static void God() { if (MetaState.Instance.SessionFlags.Contains("GodMode")) { ConsoleModule.WriteLine("Degreelessness mode off"); MetaState.Instance.SessionFlags.Remove("GodMode"); } else { ConsoleModule.WriteLine("Degreelessness mode on"); MetaState.Instance.SessionFlags.Add("GodMode"); } }
private static void Call(string script, string arg0, string arg1, string arg2) { try { ScriptingModule.Call(script, new ScriptExecutionContext { Activator = null, Caller = null }, arg0, arg1, arg2); } catch (Exception e) { ConsoleModule.WriteLine(string.Format("Error in script {0}\n{1}\n{2}", script, e.ToString(), e.StackTrace)); } }
private static void SetConfig(string configOption, string newValue) { var property = ConfigState.Instance.GetType().GetProperty(configOption, BindingFlags.Instance | BindingFlags.Public); if (property != null) { property.SetValue(ConfigState.Instance, TypeUtils.Parse(newValue, property.PropertyType)); //TODO handle enums } else { ConsoleModule.WriteLine("not found"); } }
private static void CallForResult(string script, string arg0) { try { var result = ScriptingModule.CallForResult(script, new ScriptExecutionContext { Activator = null, Caller = null }, arg0); ConsoleModule.WriteLine($"Returned '{result?.ToString() ?? "null"}' [{result?.GetType().Name}]"); } catch (Exception e) { ConsoleModule.WriteLine(string.Format("Error in script {0}\n{1}\n{2}", script, e.ToString(), e.StackTrace)); } }
private static void SetCustomVar(string customVar, string newValue) { if (ConfigState.Instance.CustomConfigVars.ContainsKey(customVar)) { //value exists: coerce the value object value = ConfigState.Instance.CustomConfigVars[customVar]; object newValueParsed = TypeUtils.Parse(newValue, value.GetType()); ConfigState.Instance.CustomConfigVars[customVar] = newValueParsed; } else { //value doesn't exist: warn and exit ConsoleModule.WriteLine("Value doesn't already exist; can't determine type to set. Use SetCustomVarTyped instead."); } }
private static void SetCurrentTheme(string theme) { var uiModule = CCBase.GetModule <UIModule>(); var uiTheme = uiModule.GetThemeByName(theme); if (uiTheme == null) { ConsoleModule.WriteLine($"Couldn't find theme \"{theme}\""); return; } uiModule.CurrentTheme = uiTheme; ConsoleModule.WriteLine($"Set theme to \"{theme}\". You will need to reload the UI to apply changes (usually can be done with Reload)"); }
public static void CommandListSubstitutions() { StringBuilder sb = new StringBuilder(80 * Instance.Strings.Count); foreach (var list in Instance.Strings) { sb.AppendLine(list.Key); foreach (var item in list.Value) { sb.AppendFormat("\t{0} : \"{1}\"\n", item.Key, item.Value); } sb.AppendLine(); } ConsoleModule.WriteLine(sb.ToString()); }
private static void ListConfig() { StringBuilder sb = new StringBuilder(256); var properties = ConfigState.Instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var property in properties) { string key = property.Name; string value = property.GetValue(ConfigState.Instance)?.ToString(); sb.AppendLine($"{key}={value}"); } ConsoleModule.WriteLine(sb.ToString()); }