public int ImportPreset(WaymarkPreset preset)
        {
            WaymarkPreset importedPreset = new WaymarkPreset(preset);

            Presets.Add(importedPreset);
            return(Presets.Count - 1);
        }
Exemple #2
0
        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.");
            }
        }
Exemple #3
0
        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.");
            }
        }
Exemple #4
0
        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}");
                    }
                }
            }
        }
 public int ImportPreset(GamePreset gamePresetData)
 {
     try
     {
         WaymarkPreset importedPreset = WaymarkPreset.Parse(gamePresetData);
         importedPreset.Name = "Imported";
         Presets.Add(importedPreset);
         return(Presets.Count - 1);
     }
     catch
     {
         return(-1);
     }
 }
 public int ImportPreset(string importStr)
 {
     try
     {
         WaymarkPreset importedPreset = JsonConvert.DeserializeObject <WaymarkPreset>(importStr);
         if (importedPreset != null)
         {
             Presets.Add(importedPreset);
             return(Presets.Count - 1);
         }
         else
         {
             return(-1);
         }
     }
     catch
     {
         return(-1);
     }
 }
 public WaymarkPresetExport(WaymarkPreset objToCopy) : base(objToCopy)
 {
 }
 public static string GetExportString(WaymarkPreset preset)
 {
     return(JsonConvert.SerializeObject(new WaymarkPresetExport(preset)));
 }
Exemple #9
0
        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.");
            }
        }