Пример #1
0
        //	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.");
            }
        }
Пример #2
0
        protected string GetZoneNameHelperFunc(UInt16 ID, bool showID)
        {
            string str = ShowDutyNames ? ZoneInfoHandler.GetZoneInfoFromContentFinderID(ID).DutyName : ZoneInfoHandler.GetZoneInfoFromContentFinderID(ID).ZoneName;

            str += showID ? $" ({ID})" : "";
            return(str);
        }
Пример #3
0
        public static bool GetCurrentWaymarksAsPresetData(ref byte[] presetData)
        {
            if (mPluginInterface != null && true /*TODO: found the right sigs*/)
            {
                byte currentContentLinkType = mdGetCurrentContentFinderLinkType.Invoke();
                if (currentContentLinkType > 0 && currentContentLinkType < 4)
                {
                    byte[] rawWaymarkData = new byte[104];
                    unsafe
                    {
                        fixed(byte *pRawWaymarkData = rawWaymarkData)
                        {
                            mdGetCurrentWaymarkData.Invoke(mpWaymarksObj, new IntPtr(pRawWaymarkData));
                        }
                    }

                    presetData = ConvertWaymarkObjDataToSavedPresetFormat(rawWaymarkData);

                    UInt16 currentZone      = ZoneInfoHandler.GetContentFinderIDFromTerritoryTypeID(mPluginInterface.ClientState.TerritoryType);
                    UInt32 currentTimestamp = (UInt32)DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    Array.Copy(BitConverter.GetBytes(currentZone), 0, presetData, 98, 2);
                    Array.Copy(BitConverter.GetBytes(currentTimestamp), 0, presetData, 100, 4);
                    return(true);
                }
            }

            return(false);
        }
Пример #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}");
                    }
                }
            }
        }
Пример #5
0
 protected void RebuildFoundZonesList(string searchString)
 {
     FoundZones.Clear();
     foreach (var zone in ZoneInfoHandler.GetAllZoneInfo())
     {
         if (!FoundZones.Contains(zone.Key) &&
             (LastSearchString.Length < 1 ||
              zone.Value.DutyName.ToLower().Contains(LastSearchString) ||
              zone.Value.ZoneName.ToLower().Contains(LastSearchString) ||
              zone.Value.ContentFinderConditionID.ToString().Contains(LastSearchString) ||
              zone.Value.TerritoryTypeID.ToString().Contains(LastSearchString)))
         {
             FoundZones.Add(zone.Key);
         }
     }
 }
Пример #6
0
        public static bool GetCurrentWaymarksAsPresetData(ref GamePreset rPresetData)
        {
            if (mPluginInterface != null && FoundDirectSaveSigs())
            {
                byte currentContentLinkType = mdGetCurrentContentFinderLinkType.Invoke();
                if (currentContentLinkType >= 0 && currentContentLinkType < 4)                  //	Same as the game check, but let it do overworld maps too.
                {
                    GamePreset_Placement rawWaymarkData = new GamePreset_Placement();
                    unsafe
                    {
                        mdGetCurrentWaymarkData.Invoke(mpWaymarksObj, new IntPtr(&rawWaymarkData));
                    }

                    rPresetData = new GamePreset(rawWaymarkData);
                    rPresetData.ContentFinderConditionID = ZoneInfoHandler.GetContentFinderIDFromTerritoryTypeID(mPluginInterface.ClientState.TerritoryType);                           //*****TODO: How do we get this as a territory type for non-instanced zones? The return type might need to be changed, or pass in another ref paramter or something. *****
                    rPresetData.UnixTime = (Int32)DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    return(true);
                }
            }

            return(false);
        }