Пример #1
0
        internal static void TTS(string text, string localization = "zh")
        {
            string tts = System.Web.HttpUtility.UrlEncode(text, System.Text.Encoding.UTF8);
            string tmp = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Global.APPNAME, "tts_cache", $"{localization}_{tts}.mp3");

            if (File.Exists(tmp) && Settings.TTSCache == "0")
            {
                WebApi.Download($"https://fanyi.baidu.com/gettts?lan={localization}&text={tts}&spd={Settings.TTSSpeed}&source=web", tmp, true);
            }
            else if (!File.Exists(tmp))
            {
                WebApi.Download($"https://fanyi.baidu.com/gettts?lan={localization}&text={tts}&spd={Settings.TTSSpeed}&source=web", tmp);
            }
            Play(tmp, "TTS", Settings.TTSVol * 10);
        }
Пример #2
0
        internal void SetDutyAsMatched(Instance instance)
        {
            isMatched = false;
            tryHide();
            this.Invoke(() =>
            {
                label_DutyCount.SetLocalizedText("overlay-queue-waiting-confirm");
                label_DutyName.Text = instance.Name;
                label_DutyStatus.SetLocalizedText("overlay-queue-matched");
                if (Settings.TTS)
                {
                    Sound_Helper.TTS($"{label_DutyName.Text} {label_DutyStatus.Text}", Localization.GetText("tts-langset"));
                }

                if (Settings.FlashWindow)
                {
                    WinApi.FlashWindow(mainForm.FFXIVProcess);
                }

                if (Settings.PlaySound && Settings.SoundLocation != "" && System.IO.File.Exists(Settings.SoundLocation))
                {
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer(Settings.SoundLocation);
                    player.Play();
                }

                if (!Settings.ShowOverlay)
                {
                    mainForm.ShowNotification("notification-queue-matched", instance.Name);
                }

                if (Settings.TwitterEnabled)
                {
                    WebApi.Tweet("tweet-queue-matched", instance.Name);
                }

                Log.S("l-queue-matched", instance.Name);
                accentColor = Color.Red;
                StartBlink();
            });
        }
Пример #3
0
        internal void SetFATEAsOccured(FATE fate)
        {
            isMatched = false;
            tryHide();
            this.Invoke(() =>
            {
                label_DutyCount.Text = fate.Area.Name;
                label_DutyName.Text  = fate.Name;
                label_DutyStatus.SetLocalizedText("overlay-fate-occured");
                if (Settings.TTS)
                {
                    Sound_Helper.TTS($"{label_DutyName.Text} {label_DutyStatus.Text}", Localization.GetText("tts-langset"));
                }

                if (Settings.FlashWindow)
                {
                    WinApi.FlashWindow(mainForm.FFXIVProcess);
                }

                if (Settings.PlaySound && Settings.SoundLocation != "" && System.IO.File.Exists(Settings.SoundLocation))
                {
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer(Settings.SoundLocation);
                    player.Play();
                }

                if (!Settings.ShowOverlay)
                {
                    mainForm.ShowNotification("tweet-fate-occured", fate.Name);
                }

                if (Settings.TwitterEnabled)
                {
                    WebApi.Tweet("tweet-fate-occured", fate.Name);
                }
                accentColor = Color.DarkOrange;
                StartBlink();
                Log.I("l-fate-occured-info", fate.Name);
            });
        }
Пример #4
0
 internal void new_tracker(int type)
 {
     Task.Factory.StartNew(() =>
     {
         this.Invoke(() =>
         {
             Show();
             var resp = WebApi.Post($@"{_TrackerHost()}api/instances", "{\"data\":{\"attributes\":{\"copy-from\":null,\"data-center-id\":null,\"instance-id\":null,\"created-at\":null,\"updated-at\":null,\"zone-id\":\"" + type.ToString() + "\"},\"type\":\"instances\"}}");
             var json = JsonConvert.DeserializeObject <dynamic>(resp);
             if (json.data.id != null)
             {
                 Tracker_Load(json.data.id.ToString());
                 ext_js = $"localStorage.setItem('instancepw:{json.data.id.ToString()}','{json.data.attributes.password.ToString()}')";
                 Log.Debug($"Debug:New Tracker[Tracker_Id:{json.data.id.ToString()},Password:{json.data.attributes.password.ToString()}]");
             }
             else
             {
                 LMessageBox.E("ui-new-tracker-error");
             }
         });
     });
 }
Пример #5
0
        private void HandleMessage(byte[] message)
        {
            try
            {
                if (message.Length < 32)
                {
                    // type == 0x0000 이였던 메시지는 여기서 걸러짐
                    return;
                }

                mainForm.overlayForm.SetStatus(true);

                var opcode = BitConverter.ToUInt16(message, 18);

#if !DEBUG
                if (opcode != 0x0078 &&
                    opcode != 0x0079 &&
                    opcode != 0x0080 &&
                    opcode != 0x006C &&
                    opcode != 0x006F &&
                    opcode != 0x0121 &&
                    opcode != 0x0143 &&
                    opcode != 0x022F)
                {
                    return;
                }
#endif

                var data = message.Skip(32).ToArray();

                if (opcode == 0x022F)
                {
                    var code = BitConverter.ToInt16(data, 4);
                    var type = data[8];

                    if (type == 0x0B)
                    {
                        Log.I("l-field-instance-entered", Data.GetInstance(code).Name);
                    }
                    else if (type == 0x0C)
                    {
                        Log.I("l-field-instance-left");
                    }

                    /*if (Settings.ShowOverlay && Settings.AutoOverlayHide)
                     * {
                     *  mainForm.overlayForm.Invoke(() =>
                     *  {
                     *      if (type == 0x0B)
                     *      {
                     *          mainForm.overlayForm.Hide();
                     *      }
                     *      else if (type == 0x0C)
                     *      {
                     *          mainForm.overlayForm.Show();
                     *      }
                     *  });
                     * }*/
                }
                else if (opcode == 0x0143)
                {
                    var type = data[0];

                    if (type == 0x9B)
                    {
                        /*
                         * var code = BitConverter.ToUInt16(data, 4);
                         * var progress = data[8];
                         *
                         * var fate = Data.GetFATE(code);
                         *
                         * //Log.D("\"{0}\" 돌발 진행도 {1}%", fate.Name, progress);
                         */
                    }
                    else if (type == 0x79)
                    {
                        /*
                         * // 돌발 임무 종료 (지역 이동시 발생할 수 있는 모든 임무에 대해 전부 옴)
                         *
                         * var code = BitConverter.ToUInt16(data, 4);
                         * var status = BitConverter.ToUInt16(data, 28);
                         *
                         * var fate = Data.GetFATE(code);
                         *
                         * //Log.D("\"{0}\" 돌발 종료!", fate.Name);
                         */
                    }
                    else if (type == 0x74)
                    {
                        // 돌발 임무 발생 (지역 이동시에도 기존 돌발 목록이 옴)

                        var code = BitConverter.ToUInt16(data, 4);

                        var fate = Data.GetFATE(code);

                        if (Settings.FATEs.Contains(code))
                        {
                            mainForm.overlayForm.SetFATEAsOccured(fate);
                            Log.I("l-fate-occured-info", fate.Name);

                            if (!Settings.ShowOverlay)
                            {
                                mainForm.ShowNotification("notification-fate-occured", fate.Name);
                            }

                            if (Settings.FlashWindow)
                            {
                                WinApi.FlashWindow(mainForm.FFXIVProcess);
                            }

                            if (Settings.TwitterEnabled)
                            {
                                WebApi.Tweet("tweet-fate-occured", fate.Name);
                            }
                        }
                    }
                }

                /*else if (opcode == 0x006C) // 3.5 cross-world 파티 참가하면 문제가 발생하는 부분.
                 * {
                 *  var code = BitConverter.ToUInt16(data, 192);
                 *
                 *  var instance = Data.GetInstance(code);
                 *
                 *  state = State.QUEUED;
                 *  mainForm.overlayForm.SetDutyCount(1);
                 *
                 *  Log.I("l-queue-started-general", instance.Name);
                 * }*/
                else if (opcode == 0x0078)
                {
                    var status = data[0];
                    var reason = data[4];

                    if (status == 0)
                    {
                        state = State.QUEUED;

                        var rouletteCode = data[20];

                        if (rouletteCode != 0 && (data[15] == 0 || data[15] == 64)) //무작위 임무 신청, 한국서버/글로벌 서버
                        {
                            var roulette = Data.GetRoulette(rouletteCode);
                            mainForm.overlayForm.SetRoulleteDuty(roulette);
                            Log.I("l-queue-started-roulette", roulette.Name);
                        }
                        else //특정 임무 신청
                        {
                            var instances = new List <Instance>();

                            for (int i = 0; i < 5; i++)
                            {
                                var code = BitConverter.ToUInt16(data, 22 + (i * 2));
                                if (code == 0)
                                {
                                    break;
                                }
                                instances.Add(Data.GetInstance(code));
                            }

                            if (!instances.Any())
                            {
                                return;
                            }

                            mainForm.overlayForm.SetDutyCount(instances.Count);

                            Log.I("l-queue-started-general",
                                  string.Join(", ", instances.Select(x => x.Name).ToArray()));
                        }
                    }
                    else if (status == 3)
                    {
                        state = reason == 8 ? State.QUEUED : State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.E("l-queue-stopped");
                    }
                    else if (status == 6)
                    {
                        state = State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.I("l-queue-entered");
                    }
                    else if (status == 4) //글섭에서 매칭 잡혔을 때 출력
                    {
                        var roulette = data[20];
                        var code     = BitConverter.ToUInt16(data, 22);

                        Instance instance;

                        if (!Settings.CheatRoulette && roulette != 0)
                        {
                            instance = new Instance {
                                Name = Data.GetRoulette(roulette).Name
                            };
                        }
                        else
                        {
                            instance = Data.GetInstance(code);
                        }

                        state = State.MATCHED;
                        mainForm.overlayForm.SetDutyAsMatched(instance);

                        if (Settings.FlashWindow)
                        {
                            WinApi.FlashWindow(mainForm.FFXIVProcess);
                        }

                        if (!Settings.ShowOverlay)
                        {
                            mainForm.ShowNotification("notification-queue-matched", instance.Name);
                        }

                        if (Settings.TwitterEnabled)
                        {
                            WebApi.Tweet("tweet-queue-matched", instance.Name);
                        }

                        Log.S("l-queue-matched", instance.Name);
                    }
                }
                else if (opcode == 0x006F)
                {
                    var status = data[0];

                    if (status == 0)
                    {
                        // 플레이어가 매칭 참가 확인 창에서 취소를 누르거나 참가 확인 제한 시간이 초과됨
                        // 매칭 중단을 알리기 위해 상단 2DB status 3 패킷이 연이어 옴
                    }
                    if (status == 1)
                    {
                        // 플레이어가 매칭 참가 확인 창에서 확인을 누름
                        // 다른 매칭 인원들도 전부 확인을 눌렀을 경우 입장을 위해 상단 2DB status 6 패킷이 옴
                        mainForm.overlayForm.StopBlink();
                    }
                }
                else if (opcode == 0x0121) //글로벌 서버
                {
                    var status = data[5];

                    if (status == 128)
                    {
                        // 매칭 참가 신청 확인 창에서 확인을 누름
                        mainForm.overlayForm.StopBlink();
                    }
                }
                else if (opcode == 0x0079)
                {
                    var code   = BitConverter.ToUInt16(data, 0);
                    var status = data[4];
                    var tank   = data[5];
                    var dps    = data[6];
                    var healer = data[7];

                    var instance = Data.GetInstance(code);

                    if (status == 1)
                    {
                        // 인원 현황 패킷
                        var member = tank * 10000 + dps * 100 + healer;

                        if (state == State.MATCHED && lastMember != member)
                        {
                            // 매칭도중일 때 인원 현황 패킷이 오고 마지막 인원 정보와 다른 경우에 누군가에 의해 큐가 취소된 경우.
                            state = State.QUEUED;
                            mainForm.overlayForm.CancelDutyFinder();
                        }
                        else if (state == State.IDLE)
                        {
                            // 프로그램이 매칭 중간에 켜짐
                            state = State.QUEUED;
                            mainForm.overlayForm.SetDutyCount(-1); // 알 수 없음으로 설정함 (TODO: 알아낼 방법 있으면 정확히 나오게 수정하기)
                            mainForm.overlayForm.SetDutyStatus(instance, tank, dps, healer);
                        }
                        else if (state == State.QUEUED)
                        {
                            mainForm.overlayForm.SetDutyStatus(instance, tank, dps, healer);
                        }

                        lastMember = member;
                    }
                    else if (status == 2)
                    {
                        // 현재 매칭된 파티의 역할별 인원 수 정보
                        // 조율 해제 상태여도 역할별로 정확히 날아옴
                        mainForm.overlayForm.SetMemberCount(tank, dps, healer);
                        return;
                    }
                    else if (status == 4)
                    {
                        // 매칭 뒤 참가자 확인 현황 패킷
                        mainForm.overlayForm.SetConfirmStatus(instance, tank, dps, healer);
                    }
                    Log.I("l-queue-updated", instance.Name, status, tank, instance.Tank, healer, instance.Healer, dps,
                          instance.DPS);
                }
                else if (opcode == 0x0080)
                {
                    var roulette = data[2];
                    var code     = BitConverter.ToUInt16(data, 4);

                    Instance instance;

                    if (!Settings.CheatRoulette && roulette != 0)
                    {
                        instance = new Instance {
                            Name = Data.GetRoulette(roulette).Name
                        };
                    }
                    else
                    {
                        instance = Data.GetInstance(code);
                    }

                    state = State.MATCHED;
                    mainForm.overlayForm.SetDutyAsMatched(instance);

                    if (Settings.FlashWindow)
                    {
                        WinApi.FlashWindow(mainForm.FFXIVProcess);
                    }

                    if (!Settings.ShowOverlay)
                    {
                        mainForm.ShowNotification("notification-queue-matched", instance.Name);
                    }

                    if (Settings.TwitterEnabled)
                    {
                        WebApi.Tweet("tweet-queue-matched", instance.Name);
                    }

                    Log.S("l-queue-matched", instance.Name);
                }
            }
            catch (Exception ex)
            {
                Log.Ex(ex, "l-analyze-error-general");
            }
        }
Пример #6
0
        private void HandleMessage(byte[] message)
        {
            try
            {
                if (message.Length < 32)
                {
                    // type == 0x0000 이였던 메시지는 여기서 걸러짐
                    return;
                }

                mainForm.overlayForm.SetStatus(true);

                var opcode = BitConverter.ToUInt16(message, 18);

#if !DEBUG
                if (opcode != 0x0078 &&
                    opcode != 0x0079 &&
                    opcode != 0x0080 &&
                    opcode != 0x006C &&
                    opcode != 0x006F &&
                    opcode != 0x0121 &&
                    opcode != 0x0143 &&
                    opcode != 0x022F &&
                    // v5.1
                    opcode != 0x008F &&
                    opcode != 0x00AE &&
                    opcode != 0x00B3 &&
                    opcode != 0x015E &&
                    opcode != 0x0121 &&
                    opcode != 0x0304 &&
                    // v5.11
                    opcode != 0x0164 &&
                    opcode != 0x032D &&
                    opcode != 0x03CF &&
                    opcode != 0x02A8 &&
                    opcode != 0x032F &&
                    opcode != 0x0339 &&
                    opcode != 0x0002)
                {
                    return;
                }
#endif

                var data = message.Skip(32).ToArray();

                if (opcode == 0x022F)
                {
                    var code = BitConverter.ToInt16(data, 4);
                    var type = data[8];

                    if (type == 0x0B)
                    {
                        Log.I("l-field-instance-entered", Data.GetInstance(code).Name);
                    }
                    else if (type == 0x0C)
                    {
                        Log.I("l-field-instance-left");
                    }

                    /*if (Settings.ShowOverlay && Settings.AutoOverlayHide)
                     * {
                     *  mainForm.overlayForm.Invoke(() =>
                     *  {
                     *      if (type == 0x0B)
                     *      {
                     *          mainForm.overlayForm.Hide();
                     *      }
                     *      else if (type == 0x0C)
                     *      {
                     *          mainForm.overlayForm.Show();
                     *      }
                     *  });
                     * }*/
                }
                else if (opcode == 0x0143)
                {
                    var type = data[0];

                    if (type == 0x9B)
                    {
                        /*
                         * var code = BitConverter.ToUInt16(data, 4);
                         * var progress = data[8];
                         *
                         * var fate = Data.GetFATE(code);
                         *
                         * //Log.D("\"{0}\" 돌발 진행도 {1}%", fate.Name, progress);
                         */
                    }
                    else if (type == 0x79)
                    {
                        /*
                         * // 돌발 임무 종료 (지역 이동시 발생할 수 있는 모든 임무에 대해 전부 옴)
                         *
                         * var code = BitConverter.ToUInt16(data, 4);
                         * var status = BitConverter.ToUInt16(data, 28);
                         *
                         * var fate = Data.GetFATE(code);
                         *
                         * //Log.D("\"{0}\" 돌발 종료!", fate.Name);
                         */
                    }
                    else if (type == 0x74)
                    {
                        // 돌발 임무 발생 (지역 이동시에도 기존 돌발 목록이 옴)

                        var code = BitConverter.ToUInt16(data, 4);

                        var fate = Data.GetFATE(code);

                        if (Settings.FATEs.Contains(code))
                        {
                            mainForm.overlayForm.SetFATEAsOccured(fate);
                            if (Settings.ShowOverlay)
                            {
                                mainForm.overlayForm.Show();
                            }
                            Log.I("l-fate-occured-info", fate.Name);

                            if (Settings.FateSound)
                            {
                                fatePlayer = new SoundPlayer(str);
                                fatePlayer.Stream.Position = 0; // fatePlayer가 Play()를 끝내기 전에 다시 Play()를 할 때 (한 번에 여러 돌발이 나타날 때) 버그 방지를 위해 필요한 코드
                                fatePlayer.Play();
                            }
                            else if (Settings.CustomSound)
                            {
                                notificationPlayer.Play();
                            }
                            if (!Settings.ShowOverlay)
                            {
                                mainForm.ShowNotification("notification-fate-occured", fate.Name);
                            }

                            if (Settings.FlashWindow)
                            {
                                WinApi.FlashWindow(mainForm.FFXIVProcess);
                            }

                            if (Settings.TelegramEnabled)
                            {
                                WebApi.Request("telegram", "fate-occured", fate.Name);
                            }

                            if (Settings.DiscordEnabled)
                            {
                                WebApi.Request("discord", "fate-occured", fate.Name);
                            }

                            if (Settings.customHttpRequest && Settings.requestOnFateOccured)
                            {
                                WebApi.customHttpRequest("fate-occured", fate.Name);
                            }
                        }
                    }
                }
                else if (opcode == 0x0078)
                {
                    var status = data[0];
                    var reason = data[4];

                    if (status == 0)
                    {
                        state = State.QUEUED;

                        rouletteCode = data[20];

                        if (Settings.ShowOverlay)
                        {
                            mainForm.overlayForm.Show();
                        }

                        if (rouletteCode != 0 && (data[15] == 0 || data[15] == 64)) //무작위 임무 신청, 한국서버/글로벌 서버
                        {
                            var roulette = Data.GetRoulette(rouletteCode);
                            mainForm.overlayForm.SetRoulleteDuty(roulette);
                            Log.I("l-queue-started-roulette", roulette.Name);
                        }
                        else //특정 임무 신청
                        {
                            rouletteCode = 0;
                            var instances = new List <Instance>();

                            for (int i = 0; i < 5; i++)
                            {
                                var code = BitConverter.ToUInt16(data, 22 + (i * 2));
                                if (code == 0)
                                {
                                    break;
                                }
                                instances.Add(Data.GetInstance(code));
                            }

                            if (!instances.Any())
                            {
                                return;
                            }

                            mainForm.overlayForm.SetDutyCount(instances.Count);

                            Log.I("l-queue-started-general",
                                  string.Join(", ", instances.Select(x => x.Name).ToArray()));
                        }
                    }
                    else if (status == 3)
                    {
                        state = reason == 8 ? State.QUEUED : State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.E("l-queue-stopped");
                    }
                    else if (status == 6)
                    {
                        state = State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.I("l-queue-entered");
                        mainForm.overlayForm.instances_callback(lastCode);
                    }
                    else if (status == 4) //글섭에서 매칭 잡혔을 때 출력
                    {
                        var roulette = data[20];
                        var code     = BitConverter.ToUInt16(data, 22);

                        Instance instance;
                        if (Settings.CustomSound)
                        {
                            notificationPlayer.Play();
                        }
                        if (!Settings.CheatRoulette && roulette != 0)
                        {
                            instance = new Instance {
                                Name = Data.GetRoulette(roulette).Name
                            };
                        }
                        else
                        {
                            instance = Data.GetInstance(code);
                        }

                        state = State.MATCHED;
                        mainForm.overlayForm.SetDutyAsMatched(instance);

                        if (Settings.FlashWindow)
                        {
                            WinApi.FlashWindow(mainForm.FFXIVProcess);
                        }

                        if (!Settings.ShowOverlay)
                        {
                            mainForm.ShowNotification("notification-queue-matched", instance.Name);
                        }

                        if (Settings.TelegramEnabled)
                        {
                            WebApi.Request("telegram", "duty-matched", instance.Name);
                        }

                        if (Settings.DiscordEnabled)
                        {
                            WebApi.Request("discord", "duty-matched", instance.Name);
                        }

                        if (Settings.customHttpRequest && Settings.requestOnDutyMatched)
                        {
                            WebApi.customHttpRequest("duty-matched", instance.Name);
                        }

                        Log.S("l-queue-matched", instance.Name);
                    }
                }
                else if (opcode == 0x008F || opcode == 0x0164) // v5.1, v5.11 (enroll duty)
                {
                    var status = data[0];
                    var reason = data[4];

                    state = State.QUEUED;

                    // rouletteCode = data[20];
                    rouletteCode = data[8];

                    if (Settings.ShowOverlay)
                    {
                        mainForm.overlayForm.Show();
                    }
                    if (rouletteCode != 0 && (data[15] == 0 || data[15] == 64)) //무작위 임무 신청, 한국서버/글로벌 서버
                    {
                        var roulette = Data.GetRoulette(rouletteCode);
                        mainForm.overlayForm.SetRoulleteDuty(roulette);
                        Log.I("l-queue-started-roulette", roulette.Name);
                    }
                    else //특정 임무 신청
                    {
                        rouletteCode = 0;
                        var instances = new List <Instance>();

                        for (int i = 0; i < 5; i++)
                        {
                            var code = BitConverter.ToUInt16(data, 12 + (i * 4));
                            if (code == 0)
                            {
                                break;
                            }
                            instances.Add(Data.GetInstance(code));
                        }
                        if (!instances.Any())
                        {
                            return;
                        }
                        mainForm.overlayForm.SetDutyCount(instances.Count);
                        mainForm.overlayForm.SetDutyAsMatching();
                        Log.I("l-queue-started-general",
                              string.Join(", ", instances.Select(x => x.Name).ToArray()));
                    }
                }
                else if (opcode == 0x00B3 || opcode == 0x032D) // v5.1, v5.11 (duty matched)
                {
                    var roulette = rouletteCode;
                    var code     = BitConverter.ToUInt16(data, 20);

                    Instance instance;
                    if (Settings.CustomSound)
                    {
                        notificationPlayer.Play();
                    }
                    if (!Settings.CheatRoulette && roulette != 0)
                    {
                        instance = new Instance {
                            Name = Data.GetRoulette(roulette).Name
                        };
                    }
                    else
                    {
                        instance = Data.GetInstance(code);
                    }

                    state = State.MATCHED;
                    mainForm.overlayForm.SetDutyAsMatched(instance);

                    if (Settings.FlashWindow)
                    {
                        WinApi.FlashWindow(mainForm.FFXIVProcess);
                    }

                    if (!Settings.ShowOverlay)
                    {
                        mainForm.ShowNotification("notification-queue-matched", instance.Name);
                    }

                    if (Settings.TelegramEnabled)
                    {
                        WebApi.Request("telegram", "duty-matched", instance.Name);
                    }

                    if (Settings.DiscordEnabled)
                    {
                        WebApi.Request("discord", "duty-matched", instance.Name);
                    }

                    if (Settings.customHttpRequest && Settings.requestOnDutyMatched)
                    {
                        WebApi.customHttpRequest("duty-matched", instance.Name);
                    }

                    Log.S("l-queue-matched", instance.Name);
                }
                else if (opcode == 0x006F)
                {
                    var status = data[0];

                    if (status == 0)
                    {
                        // 플레이어가 매칭 참가 확인 창에서 취소를 누르거나 참가 확인 제한 시간이 초과됨
                        // 매칭 중단을 알리기 위해 상단 2DB status 3 패킷이 연이어 옴
                    }
                    if (status == 1)
                    {
                        // 플레이어가 매칭 참가 확인 창에서 확인을 누름
                        // 다른 매칭 인원들도 전부 확인을 눌렀을 경우 입장을 위해 상단 2DB status 6 패킷이 옴
                        mainForm.overlayForm.StopBlink();
                    }
                }
                else if (opcode == 0x015E)            // cancel duty
                {
                    if (data[3] == 0 || data[3] == 8) // v5.1에서 8로 바뀌었다고 들음
                    {
                        state = State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.E("l-queue-stopped");
                    }
                }
                else if (opcode == 0x0121) // v5.1 commence duty
                {
                    var status = data[5];

                    if (status == 128)
                    {
                        // 매칭 참가 신청 확인 창에서 확인을 누름
                        mainForm.overlayForm.StopBlink();
                    }
                }
                else if (opcode == 0x03CF) // v5.11 cancel duty
                {
                    var status = data[0];

                    if (status == 0x73) // 매칭 취소
                    {
                        state = State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.E("l-queue-stopped");
                    }
                }
                else if (opcode == 0x0079)
                {
                    var code   = BitConverter.ToUInt16(data, 0);
                    var status = data[8];
                    var tank   = data[9];
                    var dps    = data[10];
                    var healer = data[11];
                    var order  = data[4];

                    var instance = Data.GetInstance(code);

                    if (status == 1)
                    {
                        // 인원 현황 패킷
                        var member = tank * 10000 + dps * 100 + healer;

                        if (state == State.MATCHED && lastMember != member)
                        {
                            // 매칭도중일 때 인원 현황 패킷이 오고 마지막 인원 정보와 다른 경우에 누군가에 의해 큐가 취소된 경우.
                            state = State.QUEUED;
                            mainForm.overlayForm.CancelDutyFinder();
                        }
                        else if (state == State.IDLE)
                        {
                            // 프로그램이 매칭 중간에 켜짐
                            state = State.QUEUED;
                            mainForm.overlayForm.SetDutyCount(-1); // 알 수 없음으로 설정함 (TODO: 알아낼 방법 있으면 정확히 나오게 수정하기)
                            if (rouletteCode > 0 || (tank == 0 && dps == 0 && healer == 0))
                            {
                                mainForm.overlayForm.SetDutyStatus(order);
                            }
                            else
                            {
                                mainForm.overlayForm.SetDutyStatus(instance, tank, dps, healer);
                            }
                        }
                        else if (state == State.QUEUED)
                        {
                            if (rouletteCode > 0 || (tank == 0 && dps == 0 && healer == 0))
                            {
                                mainForm.overlayForm.SetDutyStatus(order);
                            }
                            else
                            {
                                mainForm.overlayForm.SetDutyStatus(instance, tank, dps, healer);
                            }
                        }

                        // 직전 맴버 구성과 같은 상황이면 알림주지 않음
                        if (Settings.TelegramEnabled && Settings.TelegramQueueStatusEnabled)
                        {
                            if (rouletteCode == 0 && lastMember != member || !(tank == 0 && dps == 0 && healer == 0)) // 무작위 임무가 아님 (Not roulette duty)
                            {
                                WebApi.Request("telegram", "duty-status", $"{instance.Name}, {tank}/{instance.Tank}, {healer}/{instance.Healer}, {dps}/{instance.DPS}");
                            }
                            else if (order != 0 && lastOrder != order) // 매칭 현황을 받아오는 중이면 제외 (except 'retrieving information')
                            {
                                var roulette = Data.GetRoulette(rouletteCode);
                                WebApi.Request("telegram", "duty-status-roulette", $"{roulette.Name} - #{order}");
                            }
                        }

                        lastMember = member;
                        lastOrder  = order;
                    }
                    else if (status == 2)
                    {
                        // 현재 매칭된 파티의 역할별 인원 수 정보
                        // 조율 해제 상태여도 역할별로 정확히 날아옴
                        mainForm.overlayForm.SetMemberCount(tank, dps, healer);
                        return;
                    }
                    else if (status == 4)
                    {
                        // 매칭 뒤 참가자 확인 현황 패킷
                        mainForm.overlayForm.SetConfirmStatus(instance, tank, dps, healer);
                    }
                    lastCode = code;
                    Log.I("l-queue-updated", instance.Name, status, tank, instance.Tank, healer, instance.Healer, dps,
                          instance.DPS);
                }
                else if (opcode == 0x0304)
                {
                    //var code = BitConverter.ToUInt16(data, 0); // 이제 던전 안알려줌. 대신 max 인원 알려줌.
                    //var status = data[8];
                    var order     = data[6];
                    var waitTime  = data[7];
                    var tank      = data[8];
                    var tankMax   = data[9];
                    var healer    = data[10];
                    var healerMax = data[11];
                    var dps       = data[12];
                    var dpsMax    = data[13];

                    //var instance = Data.GetInstance(code);

                    //if (status == 1)
                    //{
                    // 인원 현황 패킷
                    var member = tank * 10000 + dps * 100 + healer;

                    if (state == State.MATCHED && lastMember != member)
                    {
                        // 매칭도중일 때 인원 현황 패킷이 오고 마지막 인원 정보와 다른 경우에 누군가에 의해 큐가 취소된 경우.
                        state = State.QUEUED;
                        mainForm.overlayForm.CancelDutyFinder();
                    }
                    else if (state == State.IDLE)
                    {
                        // 프로그램이 매칭 중간에 켜짐
                        state = State.QUEUED;
                        mainForm.overlayForm.SetDutyCount(-1); // 알 수 없음으로 설정함 (TODO: 알아낼 방법 있으면 정확히 나오게 수정하기)
                        if (rouletteCode > 0)
                        {
                            mainForm.overlayForm.SetDutyStatus(order);
                        }
                        else
                        {
                            mainForm.overlayForm.SetDutyStatus(tank, tankMax, dps, dpsMax, healer, healerMax);
                        }
                    }
                    else if (state == State.QUEUED)
                    {
                        if (rouletteCode > 0)
                        {
                            mainForm.overlayForm.SetDutyStatus(order);
                        }
                        else
                        {
                            mainForm.overlayForm.SetDutyStatus(tank, tankMax, dps, dpsMax, healer, healerMax);
                        }
                    }

                    // 직전 맴버 구성과 같은 상황이면 알림주지 않음
                    if (Settings.TelegramEnabled && Settings.TelegramQueueStatusEnabled)
                    {
                        if (rouletteCode == 0 && lastMember != member || !(tank == 0 && dps == 0 && healer == 0)) // 무작위 임무가 아님 (Not roulette duty)
                        {
                            WebApi.Request("telegram", "duty-status", $"{tank}/{tankMax}, {healer}/{healerMax}, {dps}/{dpsMax}");
                        }
                        else if (order != 0 && lastOrder != order) // 매칭 현황을 받아오는 중이면 제외 (except 'retrieving information')
                        {
                            var roulette = Data.GetRoulette(rouletteCode);
                            WebApi.Request("telegram", "duty-status-roulette", $"{roulette.Name} - #{order}");
                        }
                    }

                    lastMember = member;
                    lastOrder  = order;
                    //}

                    /*else if (status == 2)
                     * {
                     *  // 현재 매칭된 파티의 역할별 인원 수 정보
                     *  // 조율 해제 상태여도 역할별로 정확히 날아옴
                     *  mainForm.overlayForm.SetMemberCount(tank, dps, healer);
                     *  return;
                     * }*/
                    Log.I("l-queue-updated", "", /*status*/ 1, tank, tankMax, healer, healerMax, dps, dpsMax);
                }
                else if (opcode == 0x00AE || opcode == 0x032F) // v5.1, v5.11 매칭 뒤 참가자 확인 현황 패킷
                {
                    var code   = BitConverter.ToUInt16(data, 8);
                    var tank   = data[12];
                    var healer = data[14];
                    var dps    = data[16];

                    var instance = Data.GetInstance(code);

                    mainForm.overlayForm.SetConfirmStatus(instance, tank, dps, healer);

                    lastCode = code;
                    Log.I("l-queue-updated", instance.Name, 4, tank, instance.Tank, healer, instance.Healer, dps,
                          instance.DPS);
                }
                else if (opcode == 0x0080)
                {
                    var roulette = data[2];
                    var code     = BitConverter.ToUInt16(data, 4);

                    Instance instance;
                    if (Settings.CustomSound)
                    {
                        notificationPlayer.Play();
                    }
                    if (!Settings.CheatRoulette && roulette != 0)
                    {
                        instance = new Instance {
                            Name = Data.GetRoulette(roulette).Name
                        };
                    }
                    else
                    {
                        instance = Data.GetInstance(code);
                    }

                    state = State.MATCHED;
                    mainForm.overlayForm.SetDutyAsMatched(instance);

                    if (Settings.FlashWindow)
                    {
                        WinApi.FlashWindow(mainForm.FFXIVProcess);
                    }

                    if (!Settings.ShowOverlay)
                    {
                        mainForm.ShowNotification("notification-queue-matched", instance.Name);
                    }

                    if (Settings.TelegramEnabled)
                    {
                        WebApi.Request("telegram", "duty-matched", instance.Name);
                    }

                    if (Settings.DiscordEnabled)
                    {
                        WebApi.Request("discord", "duty-matched", instance.Name);
                    }

                    if (Settings.customHttpRequest && Settings.requestOnDutyMatched)
                    {
                        WebApi.customHttpRequest("duty-matched", instance.Name);
                    }

                    Log.S("l-queue-matched", instance.Name);
                }
            }
            catch (Exception ex)
            {
                Log.Ex(ex, "l-analyze-error-general");
            }
        }
Пример #7
0
        private void HandleMessage(byte[] message)
        {
            try
            {
                if (message.Length < 32)
                {
                    // type == 0x0000 이였던 메시지는 여기서 걸러짐
                    return;
                }

                mainForm.overlayForm.SetStatus(true);

                var opcode = BitConverter.ToUInt16(message, 18);
                if (opcode != 0x0142 &&
                    opcode != 0x0143 &&
                    opcode != 0x006C &&
                    opcode != 0x0074 &&
                    opcode != 0x0076 &&
                    opcode != 0x02DB &&
                    opcode != 0x006F &&
                    opcode != 0x02DE &&
                    opcode != 0x0339)
                {
                    return;
                }

                var data = message.Skip(32).ToArray();

                if (opcode == 0x0142)
                {
                    var type = data[0];

                    if (type == 0xCF)
                    {
                        var selfkey = BitConverter.ToInt32(message, 8);
                        var charkey = BitConverter.ToInt32(message, 40);

                        var code = BitConverter.ToUInt16(data, 16);
                        var zone = Data.GetArea(code);

                        byte teleMeasure = message[36];

                        if (selfkey == charkey) // isSelf
                        {
                            ushort lastCode = (BitConverter.ToUInt16(System.Text.Encoding.Unicode.GetBytes(new char[] { Data.GetAreaName(code).Last() }), 0));
                            string lastChar = ((lastCode - 0xAC00U) % 28 == 0 || lastCode - 0xAC00U == 8 ? "로" : "으로");

                            if (teleMeasure != 0x0C)
                            {
                                Log.D("{1}{2} 지역으로 이동했습니다. ({0})", code, Data.GetAreaName(code), lastChar);
                            }
                            else
                            {
                                Log.D("임무에서 퇴장했습니다. ({0})", teleMeasure);
                            }

                            mainForm.overlayForm.currentArea = code;
                        }
                    }
                }
                else if (opcode == 0x0143)
                {
                    var type = data[0];

                    if (type == 0x9B)
                    {
                        /*
                         * var code = BitConverter.ToUInt16(data, 4);
                         * var progress = data[8];
                         *
                         * var fate = Data.GetFATE(code);
                         *
                         * //Log.D("\"{0}\" 돌발 진행도 {1}%", fate.Name, progress);
                         */
                    }
                    else if (type == 0x79)
                    {
                        /*
                         * // 돌발 임무 종료 (지역 이동시 발생할 수 있는 모든 임무에 대해 전부 옴)
                         *
                         * var code = BitConverter.ToUInt16(data, 4);
                         * var status = BitConverter.ToUInt16(data, 28);
                         *
                         * var fate = Data.GetFATE(code);
                         *
                         * //Log.D("\"{0}\" 돌발 종료!", fate.Name);
                         */
                    }
                    else if (type == 0x74)
                    {
                        // 돌발 임무 발생 (지역 이동시에도 기존 돌발 목록이 옴)

                        var code = BitConverter.ToUInt16(data, 4);

                        var fate = Data.GetFATE(code);

                        if (Settings.FATEs.Contains(code))
                        {
                            mainForm.overlayForm.SetFATEAsAppeared(fate);

                            if (Settings.FlashWindow)
                            {
                                WinApi.FlashWindow(mainForm.FFXIVProcess);
                            }

                            if (Settings.TwitterEnabled)
                            {
                                WebApi.Tweet("< {0} > 돌발 발생!", fate.Name);
                            }
                        }

                        Log.D("\"{0}\" 돌발 발생!", fate.Name);
                    }
                }
                else if (opcode == 0x006C)
                {
                    var code = BitConverter.ToUInt16(data, 192);

                    var instance = Data.GetInstance(code);

                    state = State.QUEUED;
                    mainForm.overlayForm.SetDutyCount(1);

                    Log.I("DFAN: 매칭 시작됨 (6C) [{0}]", instance.Name);
                }
                else if (opcode == 0x0074)
                {
                    var instances = new List <Instance>();

                    for (int i = 0; i < 5; i++)
                    {
                        var code = BitConverter.ToUInt16(data, 192 + (i * 2));
                        if (code == 0)
                        {
                            break;
                        }
                        instances.Add(Data.GetInstance(code));
                    }

                    if (!instances.Any())
                    {
                        return;
                    }

                    state = State.QUEUED;
                    mainForm.overlayForm.SetDutyCount(instances.Count);

                    Log.I("DFAN: 매칭 시작됨 (74) [{0}]", string.Join(", ", instances.Select(x => x.Name).ToArray()));
                }
                else if (opcode == 0x0076)
                {
                    var code     = data[192];
                    var roulette = Data.GetRoulette(code);

                    state = State.QUEUED;
                    mainForm.overlayForm.SetRoulleteDuty(roulette);

                    Log.I("DFAN: 무작위 임무 매칭 시작됨 [{0}]", roulette.Name);
                }
                else if (opcode == 0x02DB)
                {
                    var status = data[0];

                    if (status == 3)
                    {
                        state = State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.E("DFAN: 매칭 중지됨 (2DB)");
                    }
                    else if (status == 6)
                    {
                        state = State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.I("DFAN: 입장함");
                    }
                }
                else if (opcode == 0x006F)
                {
                    var status = data[0];

                    if (status == 0)
                    {
                        // 플레이어가 매칭 참가 확인 창에서 취소를 누르거나 참가 확인 제한 시간이 초과됨
                        // 매칭 중단을 알리기 위해 상단 2DB status 3 패킷이 연이어 옴
                    }
                    if (status == 1)
                    {
                        // 플레이어가 매칭 참가 확인 창에서 확인을 누름
                        // 다른 매칭 인원들도 전부 확인을 눌렀을 경우 입장을 위해 상단 2DB status 6 패킷이 옴
                        mainForm.overlayForm.StopBlink();
                    }
                }
                else if (opcode == 0x02DE)
                {
                    var code   = BitConverter.ToUInt16(data, 0);
                    var status = data[4];
                    var tank   = data[5];
                    var dps    = data[6];
                    var healer = data[7];

                    var instance = Data.GetInstance(code);

                    if (status == 1)
                    {
                        // 인원 현황 패킷
                        var member = tank * 10000 + dps * 100 + healer;

                        if (state == State.MATCHED && lastMember != member)
                        {
                            // 매칭도중일 때 인원 현황 패킷이 오고 마지막 인원 정보와 다른 경우에 누군가에 의해 큐가 취소된 경우.
                            state = State.QUEUED;
                            mainForm.overlayForm.CancelDutyFinder();
                        }
                        else if (state == State.IDLE)
                        {
                            // 프로그램이 매칭 중간에 켜짐
                            state = State.QUEUED;
                            mainForm.overlayForm.SetDutyCount(-1); // 알 수 없음으로 설정함 (TODO: 알아낼 방법 있으면 정확히 나오게 수정하기)
                            mainForm.overlayForm.SetDutyStatus(instance, tank, dps, healer);
                        }
                        else if (state == State.QUEUED)
                        {
                            mainForm.overlayForm.SetDutyStatus(instance, tank, dps, healer);
                        }

                        lastMember = member;
                    }
                    else if (status == 2)
                    {
                        // 현재 매칭된 파티의 역할별 인원 수 정보
                        // 조율 해제 상태여도 역할별로 정확히 날아옴
                        mainForm.overlayForm.SetMemberCount(tank, dps, healer);
                        return;
                    }
                    else if (status == 4)
                    {
                        // 매칭 뒤 참가자 확인 현황 패킷
                        mainForm.overlayForm.SetConfirmStatus(instance, tank, dps, healer);
                    }

                    Log.I("DFAN: 매칭 상태 업데이트됨 [{0}, {1}, {2}/{3}, {4}/{5}, {6}/{7}]",
                          instance.Name, status, tank, instance.Tank, healer, instance.Healer, dps, instance.DPS);
                }
                else if (opcode == 0x0339)
                {
                    var roulette = data[3];
                    var code     = BitConverter.ToUInt16(data, 4);

                    Instance instance;

                    if (!Settings.CheatRoulette && roulette != 0)
                    {
                        instance = new Instance(Data.GetRoulette(roulette).Name, 0, 0, 0);
                    }
                    else
                    {
                        instance = Data.GetInstance(code);
                    }

                    state = State.MATCHED;
                    mainForm.overlayForm.SetDutyAsMatched(instance);

                    if (Settings.FlashWindow)
                    {
                        WinApi.FlashWindow(mainForm.FFXIVProcess);
                    }

                    if (!Settings.ShowOverlay)
                    {
                        mainForm.ShowNotification("< {0} > 매칭!", instance.Name);
                    }

                    if (Settings.TwitterEnabled)
                    {
                        WebApi.Tweet("< {0} > 매칭!", instance.Name);
                    }

                    Log.S("DFAN: 매칭됨 [{0}]", instance.Name);
                }
            }
            catch (Exception ex)
            {
                Log.Ex(ex, "메시지 처리중 에러 발생함");
            }
        }
Пример #8
0
        internal static void CheckNewVersion(MainForm mainForm)
        {
            Task.Factory.StartNew(() =>
            {
                var tempdir   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Global.APPNAME, Global.UPDATE_TEMP_DIRPATH);
                var batchpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Global.APPNAME, "update.bat");

                if (Directory.Exists(tempdir))
                {
                    Directory.Delete(tempdir, true);
                }
                Directory.CreateDirectory(tempdir);

                var resp = WebApi.Request("http://ffxiv.diemoe.net/DFA/check_update.php");
                if (resp == null)
                {
                    Log.E("l-updater-error-check");
                    return;
                }

                try {
                    var api = JsonConvert.DeserializeObject <dynamic>(resp);

                    var latest = api.tag_name.ToObject <string>();
                    Log.I("l-updater-current-version", Global.VERSION);
                    Log.I("l-updater-latest-version", latest);

                    var ci = new CultureInfo("en-us");
                    if (decimal.Parse(Global.VERSION.Substring(1), ci) >= decimal.Parse(latest.Substring(1), ci))
                    {
                        Log.S("l-updater-is-latest");
                    }
                    else
                    {
                        Log.S("l-updater-new-version");

                        string url = "http://ffxiv.diemoe.net/download/DFAssist?loc=cn";

                        if (url == null)
                        {
                            Log.E("l-updater-error-no-url");
                            return;
                        }

                        mainForm.Invoke(() =>
                        {
                            mainForm.Hide();
                            mainForm.overlayForm.Hide();
                        });

                        Task.Factory.StartNew(() =>
                        {
                            var updaterForm = new UpdaterForm();
                            updaterForm.SetVersion(latest);
                            updaterForm.ShowDialog();
                        });

                        //Sentry.Report("Update started");

                        var exepath = Process.GetCurrentProcess().MainModule.FileName;

                        var stream = GetDownloadStreamByUrl(url);
                        using (var zip = ZipStorer.Open(stream, FileAccess.Read))
                        {
                            var dir = zip.ReadCentralDir();
                            foreach (var entry in dir)
                            {
                                /*
                                 * if (entry.FilenameInZip == "README.txt")
                                 * {
                                 *  continue;
                                 * }
                                 */

                                var filename = entry.FilenameInZip;
                                if (filename == "DFAssist.exe")
                                {
                                    filename = Path.GetFileName(exepath);
                                }

                                zip.ExtractFile(entry, Path.Combine(tempdir, filename));
                            }
                        }

                        var currentdir = Path.GetDirectoryName(exepath);

                        File.WriteAllText(batchpath,
                                          "@echo off\r\n" +
                                          "title DFAssist Updater\r\n" +
                                          "echo Updating DFAssist...\r\n" +
                                          "ping 127.0.0.1 -n 3 > nul\r\n" +
                                          $"move /y \"{tempdir}*\" \"{currentdir}\" > nul\r\n" +
                                          $"\"{exepath}\"\r\n" +
                                          "echo Running DFAssist...\r\n",
                                          Encoding.Default);

                        var si             = new ProcessStartInfo();
                        si.FileName        = batchpath;
                        si.CreateNoWindow  = true;
                        si.UseShellExecute = false;
                        si.WindowStyle     = ProcessWindowStyle.Hidden;

                        Process.Start(si);
                        Settings.Updated = true;
                        Settings.Save();
                        Application.Exit();
                    }
                }
                catch (Exception ex)
                {
                    Log.Ex(ex, "l-updater-error-general");
                }

                try
                {
                    var json = WebApi.Request($"http://ffxiv.diemoe.net/DFA/Data/{Settings.Language}.json");
                    Data.Fill(json);
                }
                catch (Exception ex)
                {
                    Log.Ex(ex, "l-updater-error-data");
                }
            });
        }
Пример #9
0
        internal static void CheckNewVersion(MainForm mainForm)
        {
            Task.Factory.StartNew(() =>
            {
                var tempdir   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Global.APPNAME, Global.UPDATE_TEMP_DIRPATH);
                var batchpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Global.APPNAME, "update.bat");

                if (Directory.Exists(tempdir))
                {
                    Directory.Delete(tempdir, true);
                }
                Directory.CreateDirectory(tempdir);

                var resp = WebApi.Request($"https://api.github.com/repos/{Global.GITHUB_REPO}/releases/latest");
                if (resp == null)
                {
                    Log.E("l-updater-error-check");
                    return;
                }

                try {
                    var api = JsonConvert.DeserializeObject <dynamic>(resp);

                    var latest = api.tag_name.ToObject <string>();
                    Log.I("l-updater-current-version", Global.VERSION);
                    Log.I("l-updater-latest-version", latest);

                    if (decimal.Parse(Global.VERSION.Substring(1)) >= decimal.Parse(latest.Substring(1)))
                    {
                        Log.S("l-updater-is-latest");
                    }
                    else
                    {
                        Log.S("l-updater-new-version");

                        string url = null;
                        foreach (var asset in api.assets)
                        {
                            if (asset.name == string.Format("DFAssist.{0}.zip", latest))
                            {
                                url = asset.browser_download_url;
                                break;
                            }
                        }

                        if (url == null)
                        {
                            Log.E("l-updater-error-no-url");
                            return;
                        }

                        mainForm.Invoke(() =>
                        {
                            mainForm.Hide();
                            mainForm.overlayForm.Hide();
                        });

                        Task.Factory.StartNew(() =>
                        {
                            var updaterForm = new UpdaterForm();
                            updaterForm.SetVersion(latest);
                            updaterForm.ShowDialog();
                        });

                        Sentry.Report("Update started");

                        var stream = GetDownloadStreamByUrl(url);
                        using (var zip = ZipStorer.Open(stream, FileAccess.Read))
                        {
                            var dir = zip.ReadCentralDir();
                            foreach (var entry in dir)
                            {
                                if (entry.FilenameInZip == "README.txt")
                                {
                                    continue;
                                }
                                zip.ExtractFile(entry, Path.Combine(tempdir, entry.FilenameInZip));
                            }
                        }

                        var exepath    = Process.GetCurrentProcess().MainModule.FileName;
                        var currentdir = Path.GetDirectoryName(exepath);

                        File.WriteAllText(batchpath,
                                          "@echo off\r\n" +
                                          "title DFAssist Updater\r\n" +
                                          "echo Updating DFAssist...\r\n" +
                                          "ping 127.0.0.1 -n 3 > nul\r\n" +
                                          $"move /y \"{tempdir}\\*\" \"{currentdir}\" > nul\r\n" +
                                          $"\"{exepath}\"\r\n" +
                                          "echo Running DFAssist...\r\n",
                                          Encoding.Default);

                        var si             = new ProcessStartInfo();
                        si.FileName        = batchpath;
                        si.CreateNoWindow  = true;
                        si.UseShellExecute = false;
                        si.WindowStyle     = ProcessWindowStyle.Hidden;

                        Process.Start(si);
                        Settings.Updated = true;
                        Settings.Save();
                        Application.Exit();
                    }
                }
                catch (Exception ex)
                {
                    Log.Ex(ex, "l-updater-error-general");
                }

                try
                {
                    var json = WebApi.Request($"https://raw.githubusercontent.com/{Global.GITHUB_REPO}/master/App/Resources/Data/{Settings.Language}.json");
                    Data.Fill(json);
                }
                catch (Exception ex)
                {
                    Log.Ex(ex, "l-updater-error-data");
                }
            });
        }
Пример #10
0
        private async System.Threading.Tasks.Task HandleMessageAsync(byte[] message)
        {
            try
            {
                if (message.Length < 32)
                {
                    // type == 0x0000 이였던 메시지는 여기서 걸러짐
                    // Messages with type == 0x0000 are filtered out here
                    return;
                }

                mainForm.overlayForm.SetStatus(true);

                var opcode = BitConverter.ToUInt16(message, 18);

#if !DEBUG
                if (opcode != 0x0078 &&
                    opcode != 0x0079 &&
                    opcode != 0x0080 &&
                    opcode != 0x006C &&
                    opcode != 0x006F &&
                    opcode != 0x0121 &&
                    opcode != 0x0143 &&
                    opcode != 0x022F)
                {
                    return;
                }
#endif

                var data = message.Skip(32).ToArray();

                if (!seenPackets.Contains(opcode))
                {
                    Log.I(string.Format("Saw packet type {0:x4}.", opcode));
                    seenPackets.Add(opcode);
                }

                if (opcode == 0x022F)
                {
                    var code = BitConverter.ToInt16(data, 4);
                    var type = data[8];

                    Log.B(data);

                    if (type == 0x0B)
                    {
                        Log.I("l-field-instance-entered", Data.GetInstance(code).Name);
                    }
                    else if (type == 0x0C)
                    {
                        Log.I("l-field-instance-left");
                    }

                    if (Settings.ShowOverlay && Settings.AutoOverlayHide)
                    {
                        mainForm.overlayForm.Invoke(() =>
                        {
                            if (type == 0x0B)
                            {
                                mainForm.overlayForm.Hide();
                            }
                            else if (type == 0x0C)
                            {
                                mainForm.overlayForm.Show();
                            }
                        });
                    }
                }
                else if (opcode == 0x0143)
                {
                    var type = data[0];

                    if (type == 0x9B)
                    {
                        /*
                         * var code = BitConverter.ToUInt16(data, 4);
                         * var progress = data[8];
                         *
                         * var fate = Data.GetFATE(code);
                         *
                         * //Log.D("\"{0}\" 돌발 진행도 {1}%", fate.Name, progress);
                         */
                    }
                    else if (type == 0x79)
                    {
                        /*
                         * // 돌발 임무 종료 (지역 이동시 발생할 수 있는 모든 임무에 대해 전부 옴)
                         *
                         * var code = BitConverter.ToUInt16(data, 4);
                         * var status = BitConverter.ToUInt16(data, 28);
                         *
                         * var fate = Data.GetFATE(code);
                         *
                         * //Log.D("\"{0}\" 돌발 종료!", fate.Name);
                         */
                    }
                    else if (type == 0x74)
                    {
                        // 돌발 임무 발생 (지역 이동시에도 기존 돌발 목록이 옴)

                        var code = BitConverter.ToUInt16(data, 4);

                        var fate = Data.GetFATE(code);

                        if (Settings.FATEs.Contains(code))
                        {
                            mainForm.overlayForm.SetFATEAsOccured(fate);
                            Log.I("l-fate-occured-info", fate.Name);

                            if (Settings.FlashWindow)
                            {
                                WinApi.FlashWindow(mainForm.FFXIVProcess);
                            }

                            if (Settings.TwitterEnabled)
                            {
                                WebApi.Tweet("tweet-fate-occured", fate.Name);
                            }
                        }
                    }
                }

                /*else if (opcode == 0x006C) // 3.5 cross-world 파티 참가하면 문제가 발생하는 부분.
                 * {
                 *  var code = BitConverter.ToUInt16(data, 192);
                 *
                 *  var instance = Data.GetInstance(code);
                 *
                 *  state = State.QUEUED;
                 *  mainForm.overlayForm.SetDutyCount(1);
                 *
                 *  Log.I("l-queue-started-general", instance.Name);
                 * }*/
                else if (opcode == 0x0078)
                {
                    var status = data[0];
                    var reason = data[4];

                    if (status == 0)
                    {
                        state = State.QUEUED;

                        var rouletteCode = data[20];

                        // Random assignment, Korea server / global server
                        if (rouletteCode != 0 && (data[15] == 0 || data[15] == 64)) //무작위 임무 신청, 한국서버/글로벌 서버
                        {
                            var roulette = Data.GetRoulette(rouletteCode);
                            mainForm.overlayForm.SetRoulleteDuty(roulette);
                            Log.I("l-queue-started-roulette", roulette.Name);
                        }
                        else //특정 임무 신청
                        // Apply for a specific mission
                        {
                            var instances = new List <Instance>();

                            for (int i = 0; i < 5; i++)
                            {
                                var code = BitConverter.ToUInt16(data, 22 + (i * 2));
                                if (code == 0)
                                {
                                    break;
                                }
                                instances.Add(Data.GetInstance(code));
                            }

                            if (!instances.Any())
                            {
                                return;
                            }

                            mainForm.overlayForm.SetDutyCount(instances.Count);

                            Log.I("l-queue-started-general",
                                  string.Join(", ", instances.Select(x => x.Name).ToArray()));
                        }
                    }
                    else if (status == 3)
                    {
                        state = reason == 8 ? State.QUEUED : State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.E("l-queue-stopped");
                    }
                    else if (status == 6)
                    {
                        state = State.IDLE;
                        mainForm.overlayForm.CancelDutyFinder();

                        Log.I("l-queue-entered");
                    }
                    else if (status == 4) //글섭에서 매칭 잡혔을 때 출력
                                          // Output when matched in Gap
                    {
                        var roulette = data[20];
                        var code     = BitConverter.ToUInt16(data, 22);

                        Instance instance;

                        if (!Settings.CheatRoulette && roulette != 0)
                        {
                            instance = new Instance {
                                Name = Data.GetRoulette(roulette).Name
                            };
                        }
                        else
                        {
                            instance = Data.GetInstance(code);
                        }

                        state = State.MATCHED;
                        mainForm.overlayForm.SetDutyAsMatched(instance);

                        if (Settings.FlashWindow)
                        {
                            WinApi.FlashWindow(mainForm.FFXIVProcess);
                        }

                        if (!Settings.ShowOverlay)
                        {
                            mainForm.ShowNotification("notification-queue-matched", instance.Name);
                        }

                        if (Settings.TwitterEnabled)
                        {
                            WebApi.Tweet("tweet-queue-matched", instance.Name);
                        }

                        Log.S("l-queue-matched", instance.Name);
                    }
                }
                else if (opcode == 0x006F)
                {
                    var status = data[0];

                    if (status == 0)
                    {
                        // 플레이어가 매칭 참가 확인 창에서 취소를 누르거나 참가 확인 제한 시간이 초과됨
                        // 매칭 중단을 알리기 위해 상단 2DB status 3 패킷이 연이어 옴

                        // Player clicks Cancel in the Match Participation Confirmation window or the Participation Confirmation Timeout is exceeded
                        // Upper 2DB status 3 packets in succession
                    }
                    if (status == 1)
                    {
                        // 플레이어가 매칭 참가 확인 창에서 확인을 누름
                        // 다른 매칭 인원들도 전부 확인을 눌렀을 경우 입장을 위해 상단 2DB status 6 패킷이 옴

                        // Player clicks OK in the matching entry confirmation window
                        // If all other matching personnel have clicked OK, the top 2DB status 6 packets for admission
                        mainForm.overlayForm.StopBlink();
                    }
                }
                else if (opcode == 0x0121)
                // Global server
                {
                    var status = data[5];

                    if (status == 128)
                    {
                        // 매칭 참가 신청 확인 창에서 확인을 누름
                        // Click OK on Confirmation of Matching Application
                        mainForm.overlayForm.StopBlink();
                    }
                }
                else if (opcode == 0x0079)
                {
                    var code   = BitConverter.ToUInt16(data, 0);
                    var status = data[4];
                    var tank   = data[5];
                    var dps    = data[6];
                    var healer = data[7];

                    var instance = Data.GetInstance(code);

                    if (status == 1)
                    {
                        // 인원 현황 패킷
                        // Personnel Status Packet
                        var member = tank * 10000 + dps * 100 + healer;

                        if (state == State.MATCHED && lastMember != member)
                        {
                            // 매칭도중일 때 인원 현황 패킷이 오고 마지막 인원 정보와 다른 경우에 누군가에 의해 큐가 취소된 경우.
                            // If the queue status is canceled by somebody when the status packet arrives when it is in the
                            // middle of matching and is different from the last passer's information.
                            state = State.QUEUED;
                            mainForm.overlayForm.CancelDutyFinder();
                        }
                        else if (state == State.IDLE)
                        {
                            // 프로그램이 매칭 중간에 켜짐
                            // program is on in the middle of matching
                            state = State.QUEUED;
                            mainForm.overlayForm.SetDutyCount(-1); // 알 수 없음으로 설정함 (TODO: 알아낼 방법 있으면 정확히 나오게 수정하기)
                                                                   // Set to unknown (TODO: if there is a way to find out, fix it to be correct)
                            mainForm.overlayForm.SetDutyStatus(instance, tank, dps, healer);
                        }
                        else if (state == State.QUEUED)
                        {
                            mainForm.overlayForm.SetDutyStatus(instance, tank, dps, healer);
                        }

                        lastMember = member;
                    }
                    else if (status == 2)
                    {
                        // 현재 매칭된 파티의 역할별 인원 수 정보
                        // 조율 해제 상태여도 역할별로 정확히 날아옴
                        // Information on the number of people by role of the currently matched party
                        // Even if it is in un-tuned state,
                        mainForm.overlayForm.SetMemberCount(tank, dps, healer);
                        return;
                    }
                    else if (status == 4)
                    {
                        // 매칭 뒤 참가자 확인 현황 패킷
                        // Participant check status packet after matching
                        mainForm.overlayForm.SetConfirmStatus(instance, tank, dps, healer);
                    }
                    Log.I("l-queue-updated", instance.Name, status, tank, instance.Tank, healer, instance.Healer, dps,
                          instance.DPS);
                }
                else if (opcode == 0x0080)
                {
                    var roulette = data[2];
                    var code     = BitConverter.ToUInt16(data, 4);

                    Instance instance;

                    if (!Settings.CheatRoulette && roulette != 0)
                    {
                        instance = new Instance {
                            Name = Data.GetRoulette(roulette).Name
                        };
                    }
                    else
                    {
                        instance = Data.GetInstance(code);
                    }

                    state = State.MATCHED;
                    mainForm.overlayForm.SetDutyAsMatched(instance);

                    if (Settings.FlashWindow)
                    {
                        WinApi.FlashWindow(mainForm.FFXIVProcess);
                    }

                    if (!Settings.ShowOverlay)
                    {
                        mainForm.ShowNotification("notification-queue-matched", instance.Name);
                    }

                    if (Settings.TwitterEnabled)
                    {
                        WebApi.Tweet("tweet-queue-matched", instance.Name);
                    }

                    Log.S("l-queue-matched", instance.Name);
                }
                else if (opcode == 0x00e6)
                {
                    var itemId = BitConverter.ToUInt32(data, 0);
                    int offset = 4;

                    while (offset < data.Length)
                    {
                        var resp = await HandleSaleMessageAsync(itemId, data, offset);

                        if (resp < 0)
                        {
                            break;
                        }
                        offset += resp;
                    }
                    //Log.Bu(data);
                }
                else if (opcode == 0x00e1 || opcode == 0xe2 || opcode == 0xe6)
                {
                    var itemId = BitConverter.ToUInt32(data, 0);
                    // Log.I(string.Format("packet {0:x4} {0}", itemId));
                    //Log.Bu(data);
                }
            }
            catch (Exception ex)
            {
                Log.Ex(ex, "l-analyze-error-general");
            }
        }