public static bool SetProcess(Process process) { if (ffxivProcess != null) { ffxivProcess.Dispose(); ffxivProcess = null; } try { ffxivProcess = process; ffxivProcess.EnableRaisingEvents = true; ffxivModulePtr = ffxivProcess.MainModule.BaseAddress; ffxivHandle = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.All, false, ffxivProcess.Id); if (NativeMethods.IsX86Process(ffxivHandle)) { return(false); } GameWindowHandle = process.MainWindowHandle; running = true; taskWorker = Task.Factory.StartNew(WorkerThread); } catch (Exception ex) { Sentry.Error(ex); return(false); } return(true); }
private static bool ReadIconPos(Stream stream) { try { using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4096, true)) { using (var csv = new CsvReader(reader)) { csv.Configuration.HasHeaderRecord = true; csv.Configuration.RegisterClassMap(typeof(PosRecord.Map)); foreach (var r in csv.GetRecords <PosRecord>()) { IconPosition.Add(r.StatusId, new Int32Rect(r.X, r.Y, 24, 32)); IconPosition2x.Add(r.StatusId, new Int32Rect(r.X * 2, r.Y * 2, 24 * 2, 32 * 2)); } } } return(true); } catch (Exception ex) { Sentry.Error(ex); return(false); } }
private static ResourceResult DownloadResource() { try { using (var wc = new WebClientEx()) { wc.DownloadProgressChanged += (ls, le) => DownloadProgressChanged?.Invoke(le.ProgressPercentage); wc.DownloadFileAsync(new Uri(ResourceUrl), ResourcePath); while (wc.IsBusy) { Thread.Sleep(100); } } return(ResourceResult.Success); } catch (WebException ex) { Sentry.Error(ex); return(ResourceResult.NetworkError); } catch (Exception ex) { Sentry.Error(ex); return(ResourceResult.UnknownError); } }
private static string GetStr(byte[] rawData, int index, int endIndex, out bool hasTag) { hasTag = false; int nextIndex; byte[] bytes; int completionId; using (var mem = new MemoryStream(rawData.Length)) { byte v; while (index < endIndex) { v = rawData[index++]; if (v == 2 && index < endIndex) { v = rawData[index]; nextIndex = index + rawData[index + 1] + 2; if (v == 0x2E || v == 0x27 || v == 0x13) { hasTag = true; if (v == 0x2E) { v = rawData[index + 2]; if (v != 0xC9) { try { completionId = GetValue(rawData, index + 3); bytes = FFData.Completion.Table[v][completionId]; } catch (Exception ex) { bytes = UnknownCommand; Sentry.Error(ex, rawData); } mem.Write(bytes, 0, bytes.Length); } } index = nextIndex; continue; } } mem.WriteByte(v); } return(mem.Length > 0 ? Encoding.UTF8.GetString(mem.ToArray()) : null); } }
private static ResourceResult CheckResource() { var fileInfo = new FileInfo(ResourcePath); if (!fileInfo.Exists) { return(ResourceResult.NeedToDownload); } try { using (var wc = new WebClientEx()) { // 파일 사이즈 비교 wc.Method = "HEAD"; wc.DownloadData(ResourceUrl); if (fileInfo.Length != wc.ContentLength) { return(ResourceResult.NeedToDownload); } if (fileInfo.Exists) { // 파일 해싱 비교 string hashCurrent, hashRemote; using (var md5 = MD5.Create()) using (var file = File.OpenRead(ResourcePath)) hashCurrent = BitConverter.ToString(md5.ComputeHash(file)).Replace("-", "").ToLower(); wc.Method = null; hashRemote = wc.DownloadString(ResourceHash).ToLower(); if (!string.IsNullOrWhiteSpace(hashRemote) && hashRemote.StartsWith(hashCurrent)) { return(ResourceResult.Success); } } } } catch (WebException ex) { Sentry.Error(ex); return(ResourceResult.NetworkError); } catch (Exception ex) { Sentry.Error(ex); return(ResourceResult.UnknownError); } return(ResourceResult.NeedToDownload); }
private void SendChatWorker() { Chat?chat; while (this.m_sendChat.WaitOne(TimeSpan.Zero)) { if (!this.m_sendChatWait.WaitOne(100)) { continue; } chat = null; lock (this.m_toClient) { if (this.m_toClient.Count > 0) { chat = this.m_toClient.Dequeue(); } else { this.m_sendChatWait.Reset(); continue; } } if (chat.HasValue) { try { WriteChat(chat.Value); } catch (Exception ex) { Sentry.Error(ex, chat); } Thread.Sleep(500); } else { Thread.Sleep(100); } } }
private static bool ReadStatus(Stream stream) { FStatus status = new FStatus(); StatusList.Add(status); StatusListDic.Add(0, status); try { using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4096, true)) { using (var csv = new CsvReader(reader)) { csv.Configuration.HasHeaderRecord = true; csv.Configuration.RegisterClassMap(typeof(FStatus.Map)); foreach (var r in csv.GetRecords <FStatus>()) { if (string.IsNullOrEmpty(r.Name) || string.IsNullOrEmpty(r.Desc)) { continue; } StatusList.Add(r); StatusListDic.Add(r.Id, r); } } } return(true); } catch (Exception ex) { Sentry.Error(ex); return(false); } }
private static bool ReadIcon(Stream stream, bool waifu2x) { try { using (var bitmap = Image.FromStream(stream) as Bitmap) { if (waifu2x) { IconBitmap2x = CreateBitmapSource(bitmap); } else { IconBitmap = CreateBitmapSource(bitmap); } } return(true); } catch (Exception ex) { Sentry.Error(ex); return(false); } }
private static ResourceResult ReadResourceFromDat() { try { using (var memory = new MemoryStream()) using (var file = new FileStream(ResourcePath, FileMode.Open, FileAccess.ReadWrite)) using (var tar = new TarInputStream(file)) { TarEntry entry; while ((entry = tar.GetNextEntry()) != null) { if (entry.IsDirectory) { continue; } if (entry.Name.EndsWith("icons.png") || entry.Name.EndsWith("*****@*****.**")) { memory.SetLength(0); tar.CopyEntryContents(memory); memory.Position = 0; if (!ReadIcon(memory, entry.Name.EndsWith("*****@*****.**"))) { return(ResourceResult.DataError); } } else if (entry.Name.EndsWith("offset.json")) { memory.SetLength(0); tar.CopyEntryContents(memory); memory.Position = 0; if (!Worker.SetOffset(memory)) { return(ResourceResult.DataError); } } else if (entry.Name.EndsWith("icons-pos.csv")) { memory.SetLength(0); tar.CopyEntryContents(memory); memory.Position = 0; if (!ReadIconPos(memory)) { return(ResourceResult.DataError); } } else if (entry.Name.EndsWith("status.exh_ko.csv")) { memory.SetLength(0); tar.CopyEntryContents(memory); memory.Position = 0; if (!ReadStatus(memory)) { return(ResourceResult.DataError); } } } } return(ResourceResult.Success); } catch (Exception ex) { Sentry.Error(ex); return(ResourceResult.UnknownError); } }
private void ReadChatWorker() { long start; long end; long lenStart; long lenEnd; int[] buff = new int[0xfa0]; int num = 0; bool flag = true; long zero = 0; long ptr2 = 0; int j; int i; int len; while (this.m_readChat.WaitOne(TimeSpan.Zero)) { if (NativeMethods.ReadInt8(this.m_ffxivHandle, this.m_baseModulePtr + this.m_pattern.LoginStatusStatus) != this.m_pattern.LoginStatusValue) { this.Clear(true); return; } start = NativeMethods.ReadPointer(this.m_ffxivHandle, this.m_isX64, m_chatLog, m_pattern.ChatStart).ToInt64(); end = NativeMethods.ReadPointer(this.m_ffxivHandle, this.m_isX64, m_chatLog, m_pattern.ChatEnd).ToInt64(); lenStart = NativeMethods.ReadPointer(this.m_ffxivHandle, this.m_isX64, m_chatLog, m_pattern.ChatLenStart).ToInt64(); lenEnd = NativeMethods.ReadPointer(this.m_ffxivHandle, this.m_isX64, m_chatLog, m_pattern.ChatLenEnd).ToInt64(); if ((start == 0 || end == 0) || (lenStart == 0 || lenEnd == 0)) { Sentry.Error(new ApplicationException("error with chat log - cannot read chat pointer."), null); this.Clear(true); return; } else if (lenStart + num * 4 == lenEnd) { flag = false; Thread.Sleep(10); } else { if (lenEnd < lenStart) { Sentry.Error(new ApplicationException("error with chat log - end len pointer is before beginning len pointer."), null); this.Clear(true); return; } if (lenEnd < (lenStart + num * 4)) { if ((zero != 0) && (zero != 0)) { for (j = num; j < 0x3e8; j++) { buff[j] = NativeMethods.ReadInt32(this.m_ffxivHandle, new IntPtr(ptr2 + j * 4)); if (buff[j] > 0x100000) { zero = 0; ptr2 = 0; Sentry.Error(new ApplicationException("Error with chat log - message length too long."), null); this.Clear(true); return; } int length = buff[j] - ((j == 0) ? 0 : buff[j - 1]); if (length != 0) { ReadChat(this.m_ffxivHandle, new IntPtr(start + (j == 0 ? 0 : buff[j - 1])), length); } } } buff = new int[0xfa0]; num = 0; } zero = start; ptr2 = lenStart; if ((lenEnd - lenStart) > 0x100000L) { Sentry.Error(new ApplicationException("Error with chat log - too much unread Len data (>100kb)."), null); this.Clear(true); return; } if (((lenEnd - lenStart) % 4) != 0) { Sentry.Error(new ApplicationException("Error with chat log - Log length array is invalid."), null); this.Clear(true); return; } if ((lenEnd - lenStart) > 0xfa0L) { Sentry.Error(new ApplicationException("Error with chat log - Log length array is too small."), null); this.Clear(true); return; } len = (int)(lenEnd - lenStart) / 4; for (i = num; i < len; i++) { buff[i] = NativeMethods.ReadInt32(this.m_ffxivHandle, new IntPtr(lenStart + i * 4)); num++; if (!flag) { ReadChat(this.m_ffxivHandle, new IntPtr(start + (i == 0 ? 0 : buff[i - 1])), buff[i] - (i == 0 ? 0 : buff[i - 1])); } } flag = false; Thread.Sleep(10); } } }