Example #1
0
 public static void Debug(object message)
 {
     foreach (var m in SplitMessage(message))
     {
         PluginLog.LogDebug($"{m}");
     }
 }
Example #2
0
        private void ProcessBestResult(string bestTracker)
        {
            var trackerInfo = this.trackerInfos[bestTracker];

            if (trackerInfo.Ticked)
            {
                // Process result
                NextRTTCalculation(trackerInfo.LastRTT);
                trackerInfo.Ticked = false;

                if (this.currentTracker != bestTracker)
                {
                    // Swap logging priorities
                    trackerInfo.Tracker.Verbose = true;
                    if (!string.IsNullOrEmpty(this.currentTracker))
                    {
                        this.trackerInfos[this.currentTracker].Tracker.Verbose = false;
                    }

                    // Update the current tracker
                    this.currentTracker = bestTracker;

                    if (Verbose)
                    {
                        PluginLog.LogDebug("Retrieving ping from tracker {PingTrackerKey}", bestTracker);
                    }
                }
            }
        }
Example #3
0
        private void CalculatePing(IntPtr dataPtr, ushort opcode, NetworkMessageDirection direction)
        {
            if (direction == NetworkMessageDirection.ZoneDown && opcode == this.predictedDownOpcode)
            {
                // The response packet has the same timestamp as the request packet, so we can just
                // take it from here instead of keeping state.
                var prevMs = (uint)Marshal.ReadInt32(dataPtr);

                if (QueryPerformanceCounter(out var nextNs))
                {
                    var nextMs = nextNs / 10000;
                    this.pingMs  = nextMs - prevMs;
                    this.gotPing = true;

                    if (Verbose)
                    {
                        PluginLog.LogDebug("Packet ping: {LastPing}ms", this.pingMs);
                    }
                }
                else
                {
                    PluginLog.LogError("Failed to call QueryPerformanceCounter! (How can this happen?)");
                }
            }
        }
Example #4
0
 public static void Debug(object message, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerName = "", [CallerLineNumber] int lineNumber = -1)
 {
     foreach (var m in SplitMessage(message))
     {
         PluginLog.LogDebug($"[{callerPath.Substring(_subStrIndex)}::{callerName}:{lineNumber}] {m}");
     }
 }
 private Dictionary <string, LocalizationEntry> ReadFileWithLangCode(string langCode)
 {
     try
     {
         PluginLog.LogDebug($"Reading localization file with language code {langCode}...");
         return(JsonConvert.DeserializeObject <Dictionary <string, LocalizationEntry> >(
                    File.ReadAllText(Path.Combine(
                                         RichPresencePlugin.DalamudPluginInterface.AssemblyLocation.DirectoryName,
                                         "Resources",
                                         "loc",
                                         $"{PREFIX}{langCode}.json"
                                         ))
                    ));
     }
     catch (Exception ex)
     {
         PluginLog.LogError(ex, $"File with language code {langCode} not loaded, using fallbacks...");
         return(JsonConvert.DeserializeObject <Dictionary <string, LocalizationEntry> >(
                    File.ReadAllText(Path.Combine(
                                         RichPresencePlugin.DalamudPluginInterface.AssemblyLocation.DirectoryName,
                                         "Resources",
                                         "loc",
                                         $"{PREFIX}{DEFAULT_DICT_LANGCODE}.json"
                                         ))
                    ));
     }
 }
 private void ReadClientLanguageLocFile(string langCode)
 {
     PluginLog.LogDebug("Loading client localization file...");
     clientLocalizationDictonary = this.ReadFileWithLangCode(langCode);
     clientCultureInfo           = new CultureInfo(langCode);
     PluginLog.LogDebug("Client localization file loaded.");
 }
Example #7
0
        private void OnHousingWardInfo(IntPtr dataPtr)
        {
            HousingWardInfo wardInfo = HousingWardInfo.Read(dataPtr);

            PluginLog.LogDebug($"Got HousingWardInfo for ward: {wardInfo.LandIdent.WardNumber} territory: {wardInfo.LandIdent.TerritoryTypeId}");

            // if the current wardinfo is for a different district than the last swept one, print the header\
            // or if the last sweep was > 10m ago
            if (wardInfo.LandIdent.WorldId != lastSweptDistrictWorldId ||
                wardInfo.LandIdent.TerritoryTypeId != lastSweptDistrictTerritoryTypeId ||
                lastSweepTime < (DateTime.Now - TimeSpan.FromMinutes(10)))
            {
                // reset last sweep info to the current sweep
                lastSweptDistrictWorldId         = wardInfo.LandIdent.WorldId;
                lastSweptDistrictTerritoryTypeId = wardInfo.LandIdent.TerritoryTypeId;
                lastSweptDistrictSeenWardNumbers.Clear();
                lastSweepTime = DateTime.Now;

                var districtName = this.territories.GetRow((uint)wardInfo.LandIdent.TerritoryTypeId).PlaceName.Value.Name;
                var worldName    = this.worlds.GetRow((uint)wardInfo.LandIdent.WorldId).Name;
                this.pi.Framework.Gui.Chat.Print($"Began sweep for {districtName} ({worldName})");
            }

            // if we've seen this ward already, ignore it
            if (lastSweptDistrictSeenWardNumbers.Contains(wardInfo.LandIdent.WardNumber))
            {
                PluginLog.LogDebug($"Skipped processing HousingWardInfo for ward: {wardInfo.LandIdent.WardNumber} because we have seen it already");
                return;
            }

            // add the ward number to this sweep's seen numbers
            lastSweptDistrictSeenWardNumbers.Add(wardInfo.LandIdent.WardNumber);
            // if that's all the wards, give the user a cookie
            if (lastSweptDistrictSeenWardNumbers.Count == numWardsPerDistrict)
            {
                this.pi.Framework.Gui.Chat.Print($"Swept all {numWardsPerDistrict} wards. Thank you!");
            }

            // iterate over houses to find open houses
            for (int i = 0; i < wardInfo.HouseInfoEntries.Length; i++)
            {
                HouseInfoEntry houseInfoEntry = wardInfo.HouseInfoEntries[i];
                PluginLog.LogVerbose(
                    $"Got {wardInfo.LandIdent.WardNumber + 1}-{i + 1}: owned by {houseInfoEntry.EstateOwnerName}, flags {houseInfoEntry.InfoFlags}, price {houseInfoEntry.HousePrice}");
                if ((houseInfoEntry.InfoFlags & HousingFlags.PlotOwned) == 0)
                {
                    this.OnFoundOpenHouse(wardInfo, houseInfoEntry, i);
                }
            }
            PluginLog.LogDebug($"Done processing HousingWardInfo for ward: {wardInfo.LandIdent.WardNumber}");
        }
Example #8
0
        /*
         * private Int64 AdjustActionIdFuncDetour(Int64 a1, int a2)
         * {
         *  Int64 result = this.AdjustActionIdFuncHook.Original(a1, a2);
         *  if(a2 != (int)result && a2 != 21)
         *      PluginLog.LogDebug($"AdjustActionId a1:{a1} a2:{a2} result:{result}");
         *  return result;
         * }
         */


        private char ActionEffectFuncDetour(Int64 a1, int sourceActorId, Int16 a3, IntPtr a4, int size)
        {
            try
            {
                if (((size == 0x78) || (size == 0x278) ||
                     (size == 0x4B8) || (size == 0x6F8) || (size == 0x938)) &&
                    (int)sourceActorId == this.pi.ClientState.LocalPlayer?.ActorId)
                {
                    var actionId = Marshal.ReadInt32(a4 + 8);
                    actionRequestTime.TryGetValue((uint)actionId, out Stopwatch stopwatch);
                    stopwatch?.Stop();
                    var actionEffect = (ActionEffect)Marshal.PtrToStructure(a4, typeof(ActionEffect));
                    if (actionEffect.SourceSequence > 0 && actionEffect.AnimationLockDuration > 0.5)
                    {
                        long elapsedTime = 0;
                        long laggingTime = 0;
                        if (actionRequestTime.ContainsKey(actionEffect.ActionId))
                        {
                            actionRequestTime.Remove(actionEffect.ActionId);
                            elapsedTime = Math.Max(stopwatch.ElapsedMilliseconds / 2, elapsedTime);
                            laggingTime = Math.Min(Math.Min(elapsedTime, LastRTT), 500);
                        }
                        else
                        {
                            laggingTime = Math.Min(LastRTT, 500);
                        }
                        var    serverAnimationLock = actionEffect.AnimationLockDuration * 1000;
                        float  animationLock       = Math.Max(serverAnimationLock - laggingTime, 100);
                        byte[] bytes = BitConverter.GetBytes(animationLock / 1000);
                        Marshal.Copy(bytes, 0, a4 + 16, bytes.Length);
                        string logLine = $"Status ActionId:{actionEffect.ActionId} Sequence:{actionEffect.SourceSequence} " +
                                         $"Elapsed:{elapsedTime}ms RTT:{RTT}ms Lagging:{laggingTime}ms " +
                                         $"AnimationLockDuration:{serverAnimationLock}ms -> {animationLock}ms";
                        PluginLog.LogDebug(logLine);
                    }
                }
            }
            catch (Exception e)
            {
                PluginLog.Log($"Exception: {e}");
                PluginLog.Log("Don't crash the game");
            }
            var result = ActionEffectFuncHook.Original(a1, sourceActorId, a3, a4, size);

            return(result);
        }
Example #9
0
        private Int64 ActionRequestFuncDetour(Int64 a1, uint a2, uint a3)
        {
            Stopwatch stopwatch = new Stopwatch();

            try
            {
                string logLine = $"Request ActionId:{a3}";
                if (actionRequestTime.ContainsKey(a3))
                {
                    actionRequestTime.Remove(a3);
                }
                actionRequestTime.Add(a3, stopwatch);
                PluginLog.LogDebug(logLine);
            }
            catch
            {
                PluginLog.Log("Don't crash the game");
            }
            var result = ActionRequestFuncHook.Original(a1, a2, a3);

            stopwatch.Start();
            return(result);
        }
Example #10
0
        public void Initialize(DalamudPluginInterface pluginInterface)
        {
            this.pi = pluginInterface;

            // setup
            this.configuration = this.pi.GetPluginConfig() as Configuration ?? new Configuration();
            this.configuration.Initialize(this.pi);
            this.ui              = new PluginUI(this.configuration);
            this.territories     = pi.Data.GetExcelSheet <TerritoryType>();
            this.worlds          = pi.Data.GetExcelSheet <World>();
            this.housingLandSets = pi.Data.GetExcelSheet <HousingLandSet>();

            this.pi.CommandManager.AddHandler(commandName, new CommandInfo(OnCommand)
            {
                HelpMessage = $"Configure PaissaHouse settings.\n\"{commandName} reset\" to reset a sweep if sweeping the same district multiple times in a row."
            });

            // event hooks
            this.pi.Framework.Network.OnNetworkMessage += OnNetworkEvent;
            this.pi.UiBuilder.OnBuildUi      += DrawUI;
            this.pi.UiBuilder.OnOpenConfigUi += (sender, args) => DrawConfigUI();

            PluginLog.LogDebug($"Initialization complete: configVersion={this.configuration.Version}");
        }
Example #11
0
 private void UpdateRTTDetour(dynamic expando)
 {
     PluginLog.LogDebug($"LastRTT:{expando.LastRTT} AverageRTT:{expando.AverageRTT}");
     RTT     = (long)expando.AverageRTT;
     LastRTT = (long)expando.LastRTT;
 }
Example #12
0
 /// <summary>
 /// Log debug message.
 /// </summary>
 /// <param name="messageTemplate">message to log.</param>
 public static void LogDebug(string messageTemplate)
 {
     PluginLog.LogDebug(messageTemplate);
 }
 private void ReadPluginLanguageLocFile(string langCode)
 {
     PluginLog.LogDebug("Loading plugin localization file...");
     pluginLocalizationDictionary = ReadFileWithLangCode(langCode);
     PluginLog.LogDebug("Plugin localization file loaded.");
 }