private void Awake() { // Load all hotkey data hotkeyData = FileManager.GetDataFromJson <HotkeyData.HotkeyJson>(FileManager.GetModDirectoryPath() + "/Hotkeys.json").hotkeys; // Convert json key value from string to KeyCode for (int i = 0; i < hotkeyData.Count; i++) { HotkeyData.HotkeyJson.Data hotkey = hotkeyData[i]; // If keycode name is valid try { KeyCode key = (KeyCode)Enum.Parse(typeof(KeyCode), hotkey.key); DebugCommandHandler.CommandInfo command = GetCommandMethod(hotkey.name); string[] args = GetCommandArgs(hotkey.name); hotkeyHolder.hotkeys.Add(new HotkeyData.Hotkey(hotkey.name, key, command, args)); } // If keycode name is invalid catch { DebugManager.LogToFile("Hotkey '" + hotkey.name + "' does not have a key assigned and will never run.", LogType.Warning, false, false); } } EventListener.OnPlayerUpdate += PlayerUpdate; DebugManager.LogToFile("Hotkeys initialized!"); }
private void PlayerUpdate() { HotkeyData.Hotkey hotkey = IsUsingHotkey(); if (hotkey != null) { // If hotkey is for OpenDebugMenu if (hotkey.name == "OpenDebugMenu") { return; } DebugManager.LogToFile("Hotkey '" + hotkey.name + "' triggered from pressing '" + hotkey.key.ToString() + "'!", LogType.Log, false, false); if (textAnimation != null) { StopCoroutine(textAnimation); Destroy(textObj); } textAnimation = commandHandler.StartCoroutine(ShowText(hotkey.name, hotkey.key.ToString())); // Start animation of showing text EventListener.OnSceneUnload += OnSceneUnload; // If command is active if (commandHandler.IsCommandActive(hotkey.commandToRun)) { // Deactivate command commandHandler.DeactivateCommand(hotkey.commandToRun); } // If command inactive else { // Activate command commandHandler.ActivateCommand(hotkey.commandToRun, hotkey.commandArgs); } } }
private void Awake() { // Create commands allCommands = new List <CommandInfo> { // Do not put dev commands at bottom of list, as this will add extra comma in help command and // is more performant to just not list dev command last rather than remove that trailing comma { new CommandInfo("Test", new ActivationMethod(testCommand.Activate), null, null, true) }, { new CommandInfo("Goto", new ActivationMethod(gotoCommand.Activate), null, new string[] { "warpto" }) }, { new CommandInfo("Speed", new ActivationMethod(speedCommand.Activate), new DeactivationMethod(speedCommand.Deactivate), new string[] { "setspeed" }) }, { new CommandInfo("God", new ActivationMethod(godCommand.Activate), new DeactivationMethod(godCommand.Deactivate)) }, { new CommandInfo("Help", new ActivationMethod(helpCommand.Activate)) }, { new CommandInfo("LikeABoss", new ActivationMethod(likeABossCommand.Activate), new DeactivationMethod(likeABossCommand.Deactivate)) }, { new CommandInfo("NoClip", new ActivationMethod(noClipCommand.Activate), new DeactivationMethod(noClipCommand.Deactivate)) }, { new CommandInfo("Find", new ActivationMethod(findCommand.Activate)) }, { new CommandInfo("SaveState", new ActivationMethod(saveStateCommand.Activate), null, new string[] { "save", "ss" }) }, { new CommandInfo("LoadState", new ActivationMethod(loadStateCommand.Activate), null, new string[] { "load", "ls" }) }, { new CommandInfo("SetItems", new ActivationMethod(setItemsCommand.Activate), null, new string[] { "setitem", "items", "item" }) }, { new CommandInfo("SetHp", new ActivationMethod(setHpCommand.Activate), null, new string[] { "hp" }) }, { new CommandInfo("Stopwatch", new ActivationMethod(stopwatchCommand.Activate), new DeactivationMethod(stopwatchCommand.Deactivate), new string[] { "sw" }) }, }; keyToOpenDebugMenu = HotkeyHelper.Instance.GetHotkey("OpenDebugMenu").key; DebugManager.LogToFile("DebugCommandHandler initialized"); }
// Returns true if file exists, false if not public static bool DoesFileExist(string path) { bool fileExists = File.Exists(path); if (!fileExists) { DebugManager.LogToFile("File at path '" + path + "' does not exist. Typo?", LogType.Warning); } return(fileExists); }
public static int LoadFromEnt(string path) { Entity fromEnt = GameObject.Find("PlayerEnt").GetComponent <Entity>(); if (fromEnt != null) { return(fromEnt.GetStateVariable(path)); } DebugManager.LogToFile("'PlayerEnt' was not found. Returning 0.", LogType.Warning); return(0); }
// Returns the primary SaverOwner public static SaverOwner GetSaverOwner() { foreach (SaverOwner owner in Resources.FindObjectsOfTypeAll <SaverOwner>()) { if (owner.name == "MainSaver") { return(owner); } } DebugManager.LogToFile("SaverOwner named 'MainSaver' was not found. Returning null.", LogType.Warning); return(null); }
public static string LoadFromSaveFile(string path) { IDataSaver saver = GetSaver(path); if (saver != null) { string key = GetSaveKey(path); return(saver.LoadData(key)); } DebugManager.LogToFile("[Save Data] Path " + path + " could not be loaded. Returning empty string.", LogType.Warning); return(string.Empty); }
// Moves a file from one location to another (allows renaming destination file) public static void MoveFile(string sourcePath, string destinationPath) { // If source file exists if (File.Exists(sourcePath)) { File.Move(sourcePath, destinationPath); } // If source file does not exist else { // Output warning DebugManager.LogToFile("Attempted to move missing file `" + sourcePath + "`", LogType.Warning); } }
// Deletes a file public static void DeleteFile(string path) { // If file exists if (File.Exists(path)) { // Delete file File.Delete(path); } // If file does not exist else { // Output warning DebugManager.LogToFile("Attempted to delete missing file `" + path + "`", LogType.Warning); } }
public static void DeleteSaveData(string path, bool doSave = true) { IDataSaver saver = GetSaver(path); if (saver != null) { saver.ClearValue(GetSaveKey(path)); if (doSave) { GetSaverOwner().SaveAll(); } return; } DebugManager.LogToFile("[Save Data] Path " + path + " could not be loaded. Cannot delete save data that was not found.", LogType.Warning); }
public static void SaveToSaveFile(string path, string value, bool doSave = true) { IDataSaver saver = GetSaver(path); if (saver != null) { string key = GetSaveKey(path); saver.SaveData(key, value); if (doSave) { GetSaverOwner().SaveAll(); } } else { DebugManager.LogToFile("[Save Data] Path " + path + " could not be loaded. Unable to save the requested data.", LogType.Warning); } }
public static object LoadFromPrefs <T>(string prefName) { TypeCode type = Type.GetTypeCode(typeof(T)); switch (type) { case TypeCode.Int32: return(PlayerPrefs.GetInt(prefName)); case TypeCode.Decimal: return(PlayerPrefs.GetFloat(prefName)); case TypeCode.String: return(PlayerPrefs.GetString(prefName)); default: DebugManager.LogToFile(type.ToString() + " is not a valid t ype for PlayerPrefs. Type must be of type `int`, `float`, or `string`. Returning null.", LogType.Error); return(null); } }
public static void SaveToPrefs(string prefName, object value) { switch (value) { case int _value: PlayerPrefs.SetInt(prefName, _value); break; case float _value: PlayerPrefs.SetFloat(prefName, _value); break; case string _value: PlayerPrefs.SetString(prefName, _value); break; default: DebugManager.LogToFile(value.GetType().ToString() + " is not a valid type for PlayerPrefs. Value must be of type `int`, `float`, or `string`.", LogType.Error); break; } }
// Copies a file from one location to another (allows renaming & overwriting destination file) public static void CopyFile(string sourcePath, string destinationPath, bool doOverwrite = false) { destinationPath = destinationPath.Replace('/', '\\'); // If source file exists if (File.Exists(sourcePath)) { // If not overwriting, check if destination file exists if (!doOverwrite && File.Exists(destinationPath)) { // Output warning DebugManager.LogToFile("Attempted to copy file `" + sourcePath + "` to destination `" + destinationPath + "` which already exists. File not copied.", LogType.Warning); } // If overwriting or destination file does not exist else { // Remove filename from destination path string directoryPath = destinationPath.Remove(destinationPath.LastIndexOf('\\')); // If directory does not exist if (!Directory.Exists(directoryPath)) { // Create directory Directory.CreateDirectory(directoryPath); } // Copy source file to destination File.Copy(sourcePath, destinationPath, doOverwrite); } } // If source file does not exist else { // Output warning DebugManager.LogToFile("Attempted to copy missing file `" + sourcePath + "`", LogType.Warning); } }