private ChatLine[] ReadChatLines(ChatLogHeader clh) { byte[][] linesRaw = ReadChatLinesRaw(clh); List <ChatLine> lines = new List <ChatLine>(); foreach (byte[] b in linesRaw) { ChatLine c = new ChatLine(); if (b.Length > 0) { c.Stuff = BitConverter.ToInt32(b, 0); c.Mode = BitConverter.ToInt32(b, 4); c.Line = CleanString(Encoding.Default.GetString(b, 8, b.Length - 8)); c.Raw = b; c.RawLine = Encoding.ASCII.GetString(b, 8, b.Length - 8); //string[] parts = c.Line.Split(''); //if(parts.Length > 1 && parts[0] == parts[1]) //{ // c.Line = c.Line.Replace(parts[0] + "" + parts[1], parts[0]); //} lines.Add(c); } } return(lines.ToArray()); }
private uint[] ReadChatLogOffsets(ChatLogHeader header) { IntPtr offsetPtr = header.offsetsPtr; uint[] offsets = new uint[header.count]; for (uint i = 0; i < header.count; i++) { offsets[i] = MemTools.ReadProcessMemory <uint>(_process.Handle, (IntPtr)((ulong)offsetPtr + (i * 4))); } return(offsets); }
//public int GlobalCount //{ // get // { // return ReadChatLogHeader().count; // } //} private uint GetCount(ChatLogHeader clh) { uint[] offsets = ReadChatLogOffsets(clh); uint i = 0; while (((ulong)clh.startOfLogPtr + offsets[i]) < (ulong)clh.endofLogPtr) { i++; } return(i); }
//public byte[][] GetChatLinesRaw() //{ // return ReadChatLinesRaw(ReadChatLogHeader()); //} private byte[][] ReadChatLinesRaw(ChatLogHeader clh) { uint[] offsets = ReadChatLogOffsets(clh); uint chatlogSize = (uint)((ulong)clh.endofLogPtr - (ulong)clh.startOfLogPtr); uint count = GetCount(clh); List <byte[]> rawstrings = new List <byte[]>(); byte[] chatLogRaw = new byte[chatlogSize]; MemTools.ReadProcessMemory(_process.Handle, clh.startOfLogPtr, chatLogRaw, chatlogSize, 0); if (count > 0) { uint chunkSize = count > 1 ? offsets[0] : (uint)((ulong)clh.endofLogPtr - (ulong)clh.startOfLogPtr); byte[] raw = new byte[chunkSize]; Buffer.BlockCopy(chatLogRaw, 0, raw, 0, (int)chunkSize); rawstrings.Add(raw); } for (int i = 0; i < count; i++) { uint chunkSize = i < count - 1 ? (offsets[i + 1] - offsets[i]) : (uint)((ulong)clh.endofLogPtr - ((ulong)clh.startOfLogPtr + offsets[i])); byte[] raw = new byte[chunkSize]; Buffer.BlockCopy(chatLogRaw, (int)offsets[i], raw, 0, (int)chunkSize); rawstrings.Add(raw); } return(rawstrings.ToArray()); }