public static void UpdateClient(GameWindow window) { var buffer = new byte[32]; var bytesRead = 0; if(!window.IsInitialized) { return; } var windowHandle = window.OpenHandle.ToInt32(); ReadProcessMemory(windowHandle, window.ServerAddress, buffer, buffer.Length, ref bytesRead); window.Character.Server = Encoding.UTF8.GetString(buffer).TrimEnd('\0'); ReadProcessMemory(windowHandle, window.CharacterAddress, buffer, buffer.Length, ref bytesRead); window.Character.Name = Encoding.UTF8.GetString(buffer).TrimEnd('\0'); var nullIndex = window.Character.Name.IndexOf('\0'); window.Character.Name = window.Character.Name.Substring(0, nullIndex); ReadProcessMemory(windowHandle, window.PositionAddress, buffer, buffer.Length, ref bytesRead); window.Character.Z = BitConverter.ToInt32(buffer, 0); window.Character.Y = BitConverter.ToInt32(buffer, 4); window.Character.X = BitConverter.ToInt32(buffer, 8); window.Character.F = BitConverter.ToInt32(buffer, 12); var foreground = GetForegroundWindow(); if(foreground.ToInt32() == windowHandle) { window.IsActiveWindow = true; } else { window.IsActiveWindow = false; } }
public static int Initialize(GameWindow window) { uint processId; GetWindowThreadProcessId(window.Handle, out processId); if(processId == 0) { return -1; } const int access = ProcessQueryInformation|ProcessVmRead; window.OpenHandle = OpenProcess(access, true, (int)processId); var process = Process.GetProcessById((int)processId); string path = process.MainModule.FileName; var reader = new PeHeaderReader(path); var processHandle = window.OpenHandle.ToInt32(); for (int i = 0; i < reader.ImageSectionHeaders.Length; i++ ) { var currentSection = reader.ImageSectionHeaders[i]; if(!currentSection.HasFlag(PeHeaderReader.DataSectionFlags.MemoryExecute)) { continue; } var address = currentSection.VirtualAddress + reader.OptionalHeader32.ImageBase; if (window.PositionAddress == 0) { short[] pattern = { 0x8B, 0x15, -1, -1, -1, -1, 0x8B, 0x01, 0x8B, 0x40, 0x54, 0x52, 0x8B, 0x15 }; // ~6.0.14.4 - 7.x (Stygian Abyss to High Seas+) if (Pattern.PatternSearch(processHandle, address, currentSection.VirtualSize, pattern) > 0) { window.PositionAddress = ((pattern[5] << 24) + (pattern[4] << 16) + (pattern[3] << 8) + pattern[2]) - 4; } } if (window.CharacterAddress == 0) { short[] pattern = { 0xE8, -1, -1, -1, -1, 0x68, -1, -1, -1, -1, 0x68, -1, -1, -1, -1, 0x57, 0xE8, -1, -1, -1, -1, 0x83, 0xC4, -1, 0x68, -1, -1, -1, -1 }; if (Pattern.PatternSearch(processHandle, address, currentSection.VirtualSize, pattern) > 0) { window.ServerAddress = ((pattern[9] << 24) + (pattern[8] << 16) + (pattern[7] << 8) + pattern[6]); window.CharacterAddress = ((pattern[28] << 24) + (pattern[27] << 16) + (pattern[26] << 8) + pattern[25]); } } // 4.0.11d - ~6.0.9.x (Mondain's Legacy to Kingdom Reborn+) if (window.PositionAddress == 0) { short[] pattern = { 0x8B, 0x0D, -1, -1, -1, -1, 0x53, 0x55, 0x56, 0x8B, 0x35 }; // ~6.0.14.4 - 7.x (Stygian Abyss to High Seas+) if (Pattern.PatternSearch(processHandle, address, currentSection.VirtualSize, pattern) > 0) { window.PositionAddress = ((pattern[5] << 24) + (pattern[4] << 16) + (pattern[3] << 8) + pattern[2]) - 4; } } if (window.CharacterAddress == 0) { short[] pattern = { 0x83, 0xC4, -1, 0x68, -1, -1, -1, -1, 0x68, -1, -1, -1, -1, 0x57, 0xE8, -1, -1, -1, -1, 0x83, 0xC4, -1, 0x68, -1, -1, -1, -1, 0x68, -1, -1, -1, -1, 0x57, 0xE8, -1, -1, -1, -1, 0x8B, 0x54, 0x24 }; if (Pattern.PatternSearch(processHandle, address, currentSection.VirtualSize, pattern) > 0) { window.ServerAddress = ((pattern[7] << 24) + (pattern[6] << 16) + (pattern[5] << 8) + pattern[4]); window.CharacterAddress = ((pattern[26] << 24) + (pattern[25] << 16) + (pattern[24] << 8) + pattern[23]); } } } return 0; }
public static void UpdateClient(GameWindow window) { var buffer = new byte[32]; var bytesRead = 0; if(!window.IsInitialized) { return; } var windowHandle = window.OpenHandle.ToInt32(); try { ReadProcessMemory(windowHandle, window.ServerAddress, buffer, buffer.Length, ref bytesRead); window.Server = Encoding.UTF8.GetString(buffer).TrimEnd('\0'); ReadProcessMemory(windowHandle, window.CharacterAddress, buffer, buffer.Length, ref bytesRead); window.Name = Encoding.UTF8.GetString(buffer).TrimEnd('\0'); // remove everything from the string up to the first null character // if you dont do this, the json will be invalid var nullIndex = window.Name.IndexOf('\0'); window.Name = window.Name.Substring(0, nullIndex); ReadProcessMemory(windowHandle, window.PositionAddress, buffer, buffer.Length, ref bytesRead); var Z = BitConverter.ToInt32(buffer, 0); var Y = BitConverter.ToInt32(buffer, 4); var X = BitConverter.ToInt32(buffer, 8); var F = BitConverter.ToInt32(buffer, 12); var IsActive = GetForegroundWindow().ToInt32() == window.Handle.ToInt32(); window.Moved = (Z != window.Z || Y != window.Y || X != window.X || F != window.F || window.IsActive != IsActive); window.Z = Z; window.Y = Y; window.X = X; window.F = F; window.IsActive = IsActive; } catch(Exception ex) { // The client has closed window.ClientClosed = true; } }