// Cleanup public void Dispose() { MemoryHandler.Uninit(); mUI.Dispose(); mPluginInterface.CommandManager.RemoveHandler(mTextCommandName); mPluginInterface.Dispose(); }
// Initialization public void Initialize(DalamudPluginInterface pluginInterface) { // Configuration mPluginInterface = pluginInterface; mConfiguration = mPluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); mConfiguration.Initialize(mPluginInterface); MemoryHandler.Init(mPluginInterface); ZoneInfoHandler.Init(mPluginInterface); // Text Command Initialization mPluginInterface.CommandManager.AddHandler(mTextCommandName, new CommandInfo(ProcessTextCommand) { HelpMessage = "Performs waymark preset commands. Use \"/pwaymark help\" for detailed usage information." }); // UI Initialization mUI = new PluginUI(mConfiguration, mPluginInterface); mPluginInterface.UiBuilder.OnBuildUi += DrawUI; mPluginInterface.UiBuilder.OnOpenConfigUi += (sender, args) => DrawConfigUI(); mUI.SetCurrentTerritoryTypeID(mPluginInterface.ClientState.TerritoryType); mUI.Initialize(); // Event Subscription mPluginInterface.ClientState.TerritoryChanged += OnTerritoryChanged; // Tell the user if there's something out of the ordinary. if (!MemoryHandler.FoundSavedPresetSigs()) { mPluginInterface.Framework.Gui.Chat.Print("Error initializing WaymarkPresetPlugin: Cannot write to or read from game."); } }
protected string ProcessTextCommand_Place(string args) { if (mConfiguration.AllowDirectPlacePreset) { int slotNum = -1; bool validSlot = int.TryParse(args.Trim(), out slotNum) && slotNum >= 0 && slotNum < mConfiguration.PresetLibrary.Presets.Count; if (validSlot) { try { MemoryHandler.DirectPlacePreset(mConfiguration.PresetLibrary.Presets[slotNum].ConstructGamePreset()); return(""); } catch (Exception e) { PluginLog.Log($"An unknown error occured while attempting to place preset {slotNum} : {e}"); return($"An unknown error occured placing preset {slotNum}."); } } else { return($"Invalid preset number \"{slotNum}\""); } } else { return("Direct placement from the library is not currently allowed; see the plugin settings for more information."); } }
protected string ProcessTextCommand_SlotInfo(string args) { uint gameSlotToCopy; if (args.Length == 1 && uint.TryParse(args, out gameSlotToCopy) && gameSlotToCopy >= 1 && gameSlotToCopy <= 5) { if (MemoryHandler.FoundSavedPresetSigs()) { byte[] gamePreset = new byte[104]; try { WaymarkPreset tempPreset = WaymarkPreset.Parse(MemoryHandler.ReadSlot(gameSlotToCopy)); return("Slot " + gameSlotToCopy.ToString() + " Contents:\r\n" + tempPreset.GetPresetDataString(mConfiguration.GetZoneNameDelegate, mConfiguration.ShowIDNumberNextToZoneNames)); } catch (Exception e) { PluginLog.Log($"An unknown error occured while trying to read the game's waymark data: {e}"); return("An unknown error occured while trying to read the game's waymark data."); } } else { return("Unable to read game's waymark data."); } } else { return("An invalid game slot number was provided."); } }
protected string ProcessTextCommand_Import(string args) { uint gameSlotToCopy; if (args.Length == 1 && uint.TryParse(args, out gameSlotToCopy) && gameSlotToCopy >= 1 && gameSlotToCopy <= MemoryHandler.MaxPresetSlotNum) { if (MemoryHandler.FoundSavedPresetSigs()) { try { WaymarkPreset tempPreset = WaymarkPreset.Parse(MemoryHandler.ReadSlot(gameSlotToCopy)); int importedIndex = mConfiguration.PresetLibrary.ImportPreset(tempPreset); mConfiguration.Save(); return($"Imported game preset {gameSlotToCopy} as library preset {importedIndex}."); } catch (Exception e) { PluginLog.Log($"An unknown error occured while trying to read the game's waymark data: {e}"); return("An unknown error occured while trying to read the game's waymark data."); } } else { return("Unable to read game's waymark data."); } } else { return($"An invalid game slot number was provided."); } }
protected string ProcessTextCommand_Place(string args) { if (mConfiguration.AllowDirectPlacePreset) { int libraryIndex = -1; bool validIndex = int.TryParse(args.Trim(), out libraryIndex) && libraryIndex >= 0 && libraryIndex < mConfiguration.PresetLibrary.Presets.Count; if (validIndex) { try { MemoryHandler.PlacePreset(mConfiguration.PresetLibrary.Presets[libraryIndex].GetAsGamePreset() /*, mConfiguration.AllowClientSidePlacementInOverworldZones*/); return(""); } catch (Exception e) { PluginLog.Log($"An unknown error occured while attempting to place preset {libraryIndex} : {e}"); return($"An unknown error occured placing preset {libraryIndex}."); } } else { return($"Invalid preset number \"{libraryIndex}\""); } } else { return("Direct placement from the library is not currently allowed; see the plugin settings for more information."); } }
protected void OnTerritoryChanged(object sender, UInt16 ID) { ZoneInfo prevTerritoryTypeInfo = ZoneInfoHandler.GetZoneInfoFromTerritoryTypeID(CurrentTerritoryTypeID); ZoneInfo newTerritoryTypeInfo = ZoneInfoHandler.GetZoneInfoFromTerritoryTypeID(ID); CurrentTerritoryTypeID = ID; mUI.SetCurrentTerritoryTypeID(ID); // Auto-save presets on leaving instance. if (mConfiguration.AutoSavePresetsOnInstanceLeave && ZoneInfoHandler.IsKnownContentFinderID(prevTerritoryTypeInfo.ContentFinderConditionID)) { for (uint i = 1; i <= MemoryHandler.MaxPresetSlotNum; ++i) { try { var preset = WaymarkPreset.Parse(MemoryHandler.ReadSlot(i)); if (preset.MapID == prevTerritoryTypeInfo.ContentFinderConditionID && !mConfiguration.PresetLibrary.Presets.Any(x => x.Equals(preset))) { preset.Name = prevTerritoryTypeInfo.DutyName.ToString() + " - AutoImported"; mConfiguration.PresetLibrary.ImportPreset(preset); } } catch (Exception e) { PluginLog.Log($"Error while attempting to auto-import game slot {i}: {e}"); } } mConfiguration.Save(); } // Auto-load presets on entering instance. if (mConfiguration.AutoPopulatePresetsOnEnterInstance && ZoneInfoHandler.IsKnownContentFinderID(newTerritoryTypeInfo.ContentFinderConditionID)) { //*****TODO: Eventually maybe have this check for a "preferred" flag on the presets and use that to help select which five to use, rather than just the first five from the zone. var presetsToAutoLoad = mConfiguration.PresetLibrary.Presets.Where(x => x.MapID == newTerritoryTypeInfo.ContentFinderConditionID).Take(MemoryHandler.MaxPresetSlotNum).ToList(); for (int i = 0; i < MemoryHandler.MaxPresetSlotNum; ++i) { GamePreset gamePresetData = new GamePreset(); if (i < presetsToAutoLoad.Count) { var preset = presetsToAutoLoad[i]; gamePresetData = preset.GetAsGamePreset(); } try { MemoryHandler.WriteSlot((uint)i + 1, gamePresetData); } catch (Exception e) { PluginLog.Log($"Error while auto copying preset data to game slot {i}: {e}"); } } } }
protected string ProcessTextCommand_Export(string args) { var parameters = args.Split(); bool includeTimestamp = parameters.Contains("-t"); bool useGameSlot = parameters.Contains("-g"); int scratchVal; var slotIndexNumbers = parameters.Where(x => int.TryParse(x, out scratchVal)).ToList(); WaymarkPreset presetToExport = null; try { if (slotIndexNumbers.Count < 1) { return("No slot or index numbers were provided."); } else if (slotIndexNumbers.Count == 1) { int indexToExport = int.Parse(slotIndexNumbers[0]); if (useGameSlot) { if (indexToExport >= 1 && indexToExport <= MemoryHandler.MaxPresetSlotNum) { presetToExport = WaymarkPreset.Parse(MemoryHandler.ReadSlot((uint)indexToExport)); } else { return($"An invalid game slot number ({indexToExport}) was provided."); } } else { if (indexToExport >= 0 && indexToExport < mConfiguration.PresetLibrary.Presets.Count) { presetToExport = mConfiguration.PresetLibrary.Presets[indexToExport]; } else { return($"An invalid library index ({indexToExport}) was provided."); } } string exportStr = ""; if (includeTimestamp) { exportStr = JsonConvert.SerializeObject(presetToExport); } else { exportStr = WaymarkPresetExport.GetExportString(presetToExport); } Win32Clipboard.CopyTextToClipboard(exportStr); return("Copied to clipboard."); } else { int indexToExport = int.Parse(slotIndexNumbers[0]); int exportTargetIndex = int.Parse(slotIndexNumbers[1]); if (useGameSlot) { if (indexToExport >= 1 && indexToExport <= MemoryHandler.MaxPresetSlotNum) { presetToExport = WaymarkPreset.Parse(MemoryHandler.ReadSlot((uint)indexToExport)); } else { return($"An invalid game slot number to export ({indexToExport}) was provided."); } } else { if (indexToExport >= 0 && indexToExport < mConfiguration.PresetLibrary.Presets.Count) { presetToExport = mConfiguration.PresetLibrary.Presets[indexToExport]; } else { return($"An invalid library index ({indexToExport}) was provided."); } } if (exportTargetIndex >= 1 && exportTargetIndex <= MemoryHandler.MaxPresetSlotNum) { MemoryHandler.WriteSlot((uint)exportTargetIndex, presetToExport.GetAsGamePreset()); return($"Preset exported to game slot."); } else { return($"An invalid game slot number({exportTargetIndex}) was provided as the target."); } } } catch (Exception e) { PluginLog.Log($"Unknown error occured while export the preset: {e}"); return("Unknown error occured while trying to export the preset."); } }