public Form1() { rand = new Random(); InitializeComponent(); TH155Addr.TH155AddrStartup(1, this.Handle, TH155Addr.TH155CALLBACK); fsw = new FileSystemWatcher(); fsw.Created += OnFileCreated; fsw.Filter = "*.rep"; fsw.IncludeSubdirectories = true; fsw.EnableRaisingEvents = false; _client2 = new HttpClient(); _client = new HttpClient(); _client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A356 Safari/604.1"); //client.DefaultRequestHeaders.Add("Content-Type", "application /x-www-form-urlencoded"); _client.DefaultRequestHeaders.Add("Referer", "https://tenco.info/game/7/account/nanashi/"); _client.DefaultRequestHeaders.Add("Origin", "https://tenco.info/game/7/account/nanashi/"); _client.DefaultRequestHeaders.Add("Host", "tenco.info"); _client.DefaultRequestHeaders.Add("Accept", "*/*"); _client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate"); _client.DefaultRequestHeaders.Add("Accept-Language", "zh-CN,zh;q=0.8"); _currentDate = DateTime.Now; _records = new ReplayRecord("repRecord.db"); _records.Database.EnsureCreated(); _records.Database.Migrate(); }
private async void LaunchTH155() { if (executing) { return; } executing = true; Log($"Exec: Launch TH155"); for (;;) { Process proc = new Process(); proc.StartInfo.FileName = "steam://run/716710"; proc.StartInfo.UseShellExecute = true; proc.StartInfo.RedirectStandardOutput = false; proc.StartInfo.RedirectStandardError = false; proc.Start(); Thread.Sleep(13000); if (TH155Addr.TH155AddrGetState() > 0) { break; } } //await WaitingUntil(() => TH155Addr.TH155AddrGetState() > 0); SetTH155Foreground(); //TH155Addr.VirtualPress(90); //Thread.Sleep(6000); await SwitchTo(512); Thread.Sleep(200); TH155Addr.VirtualPress(90); Thread.Sleep(300); Log($"Exec Finish:LaunchTH155"); executing = false; }
private Task SwitchTo(int loc, Func <bool> predice = null) { return(Task.Run(() => { if (TH155Addr.TH155AddrGetState() < 1) { return; } for (; ;) { if (TH155Addr.TH155AddrGetState() == 0) { return; } var cursorstat_y = TH155Addr.TH155GetRTChildInt("menu/cursor/target_y"); SetTH155Foreground(); if (predice != null && predice()) { return; } if (loc == cursorstat_y) { break; } TH155Addr.VirtualPressEx(0x28);//Down Thread.Sleep(100); } })); }
private void TerminateTH155() { var hwnd = TH155Addr.FindWindow(); try { SendMessage(hwnd, 0x0010, 0, 0); // WM_CLOSE } catch (Exception e) { Log(e.ToString()); } }
private Task WaitingUntil(Func <bool> predice) { return(Task.Run(() => { for (;;) { if (predice() || TH155Addr.TH155AddrGetState() == 0) { return; } Thread.Sleep(1000); } })); }
private bool IsMainMenu() { /* * 424:network * 512:replay * * 396:watch * * 72-88:main menu * 310:network * 350:replay * * * 0,0 开始界面 * * * -1,-1 输入ip地址 */ var cursorstat_x = TH155Addr.TH155GetRTChildInt("menu/cursor/target_x"); return(cursorstat_x >= 72 && cursorstat_x <= 88); }
private Task ReturnToGameMenu() { return(Task.Run(() => { if (TH155Addr.TH155AddrGetState() < 1) { return; } for (; ;) { if (TH155Addr.TH155AddrGetState() == 0) { return; } SetTH155Foreground(); if (IsMainMenu()) { break; } var replay_state = TH155Addr.TH155GetRTChildInt("replay/state"); var current_y = TH155Addr.TH155GetRTChildInt("menu/cursor/target_y"); if (IsReplaying() && current_y == 216) { TH155Addr.VirtualPress(88);//x Thread.Sleep(1000); SwitchTo(306, () => { return !CheckCursor(-1); }).Wait(); Thread.Sleep(100); TH155Addr.VirtualPress(90); Thread.Sleep(100); } TH155Addr.VirtualPress(88);//x Thread.Sleep(1000); } })); }
private void button6_Click(object sender, EventArgs e) { TH155Addr.TH155EnumRTCHild(); }
private async void ToNetwork(string IPAddress) { if (executing) { return; } if (TH155Addr.TH155AddrGetState() < 1) { return; } executing = true; Log($"Exec: Network Match"); File.WriteAllText("P1.txt", "***"); File.WriteAllText("P2.txt", "***"); File.Copy($"Avatar/Default.png", "P1.png", true); File.Copy($"Avatar/Default.png", "P2.png", true); Clipboard.SetText(IPAddress); SetTH155Foreground(); await ReturnToGameMenu(); await SwitchTo(424); TH155Addr.VirtualPress(90); await WaitingUntil(IsNetwork); await SwitchTo(396, () => !IsNetwork());// 观战 if (IsNetwork()) { TH155Addr.VirtualPress(90); Thread.Sleep(200); TH155Addr.VirtualPress(0x43); Thread.Sleep(200); TH155Addr.VirtualPress(90); Thread.Sleep(5000); if (TH155Addr.TH155IsConnect()) { //network/player_name/0 try { var P1 = TH155Addr.TH155GetRTChildStr("network/player_name/0"); var P2 = TH155Addr.TH155GetRTChildStr("network/player_name/1"); File.WriteAllText("P1.txt", P1); File.WriteAllText("P2.txt", P2); ApplyAvatar(P1, "P1.png"); ApplyAvatar(P2, "P2.png"); } catch (Exception ex) { File.AppendAllText("exception.txt", ex.ToString()); } } await WaitingUntil(() => { //var is_watch = TH155Addr.TH155GetRTChildInt("network/is_watch"); //var is_disconnect = TH155Addr.TH155GetRTChildInt("network/is_disconnect"); return(!TH155Addr.TH155IsConnect()); }); } //Return to replay await ReturnToGameMenu(); //Thread.Sleep(200); //await SwitchTo(512); //TH155Addr.VirtualPress(90); //Thread.Sleep(300); Log($"Exec Finish:Network Match"); executing = false; }
private void SetTH155Foreground() { var hwnd = TH155Addr.FindWindow(); SetForegroundWindow(hwnd); }
private bool CheckCursor(int value) { var cursorstat_x = TH155Addr.TH155GetRTChildInt("menu/cursor/target_x"); return(cursorstat_x == value); }
private bool IsReplaying() { var cursorstat_x = TH155Addr.TH155GetRTChildInt("menu/cursor/target_x"); return(cursorstat_x == -100); }
private bool IsNetwork() { var cursorstat_x = TH155Addr.TH155GetRTChildInt("menu/cursor/target_x"); return(cursorstat_x == 310 || cursorstat_x == -1); }
private void timer1_Tick_1(object sender, EventArgs e) { label6.Text = (executing ? "Executing" : "Idleing") + (tencoFetch ? "Fetching" : ""); int state = TH155Addr.TH155AddrGetState(); string str; label1.Text = "State : " + state; if (_currentDate.Day != DateTime.Now.Day) //日替 { FetchTenco(); } if (state >= 1) { var cursorstat_y = TH155Addr.TH155GetRTChildInt("menu/cursor/target_y"); var cursorstat_x = TH155Addr.TH155GetRTChildInt("menu/cursor/target_x"); label5.Text = "cursor:" + cursorstat_x + "," + cursorstat_y; var replay_state = TH155Addr.TH155GetRTChildInt("replay/state"); var play_state = TH155Addr.TH155GetRTChildInt("replay/game_mode"); label2.Text = "replayStat : " + play_state; if (play_state == -1 && TH155Addr.TH155AddrGetState() != 0) { //无法获取到信息,重启游戏 TerminateTH155(); } if (!IsReplaying() && (checkBox1.Checked || _LoadReplay) && !executing) { executing = true; Log($"Exec:SwitchReplay"); Task.Run(() => { //Thread.Sleep(2500); if (CheckCursor(-1)) //暂停中 { SetTH155Foreground(); TH155Addr.VirtualPress(88);//x Log($"Exec Finish:SwitchReplay(Pause)"); executing = false; return; } string selectedReplay = ""; try { if (_current != null && _current.Count > 0) { selectedReplay = _current.Last().FileName; _current.RemoveAt(_current.Count - 1); StatusLog($"正在播放满足条件的Rep,还剩{_current.Count}个:{_filterStr}"); } else { selectedReplay = _records.Replays.OrderBy(x => Guid.NewGuid()).Take(1).First().FileName; StatusLog("正在随机播放所有rep"); } var info = ReplayReader.Open(selectedReplay); Func <string, string> processStr = input => { string ret = input.Replace("\\", "").Trim(); return(ret.Length == 0 ? "无名黑幕" : ret); }; var P1Name = processStr(info[14]); var P2Name = processStr(info[16]); File.WriteAllText("P1.txt", P1Name); ApplyAvatar(P1Name, "P1.png"); File.WriteAllText("P2.txt", P2Name); ApplyAvatar(P2Name, "P2.png"); File.Copy(selectedReplay, textBox1.Text, true); } catch (Exception ex) { File.AppendAllText("exception.txt", ex.ToString()); } SetTH155Foreground(); Thread.Sleep(500); if (IsMainMenu()) { SwitchTo(512).Wait(); TH155Addr.VirtualPress(90); Thread.Sleep(300); TH155Addr.VirtualPress(90); Thread.Sleep(300); } TH155Addr.VirtualPress(90); //SendKeys.SendWait("z"); Thread.Sleep(2000); Log($"Exec Finish:SwitchReplay"); _LoadReplay = false; executing = false; }); } } else if (checkBox2.Checked) { LaunchTH155(); } }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { TH155Addr.TH155AddrCleanup(); }