Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace SR_GameServer_Reader
- {
- static public class Main
- {
- static public List<Character> ConnectedCharacters = new List<Character>();
- static public Dictionary<UInt32, UInt32> SpawnedNPCs = new Dictionary<UInt32, UInt32>();
- public delegate UInt32 GetLobbyEntryByJID(UInt32 CLobby, UInt32 JID);
- const int PROCESS_WM_READ = 0x0010;
- [DllImport("kernel32.dll")]
- public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
- [DllImport("kernel32.dll")]
- public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
- public static void ReadMemory()
- {
- ConnectedCharacters.Clear();
- Program.MainWindow.connectedCharacters.Items.Clear();
- Process process = Process.GetProcessesByName("SR_GameServer_nolag2")[0];
- IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
- IntPtr baseAddress = process.MainModule.BaseAddress;
- IntPtr ppListChar = IntPtr.Add(baseAddress, 0x8D3A3C);
- IntPtr pListChar = ReadPointer(processHandle, ppListChar);
- IntPtr ListChar = ReadPointer(processHandle, pListChar);
- int ListCharOffset = 0x00;
- IntPtr vftable = IntPtr.Zero;
- do
- {
- IntPtr ListCharNext = IntPtr.Add(ListChar, ListCharOffset);
- IntPtr CurrentChar = ReadPointer(processHandle, ListCharNext); //this.value = 8e8e3024
- vftable = ReadPointer(processHandle, CurrentChar); //this.value = 8e8e3024
- if (IntPtr.Equals(vftable, new IntPtr(0x00AF59FC)))
- {
- UInt32 UniqueID = ReadUInt32(processHandle, IntPtr.Add(CurrentChar, 0x08));
- IntPtr CharacterData = ReadPointer(processHandle, IntPtr.Add(CurrentChar, 0x34));
- UInt32 RefObjID = ReadUInt32(processHandle, IntPtr.Add(CharacterData, 0x28));
- String Name = ReadAscii(processHandle, IntPtr.Add(CharacterData, 0x30), 16);
- UInt32 CurrentHP = ReadUInt32(processHandle, IntPtr.Add(CharacterData, 0x8C));
- UInt32 CurrentMP = ReadUInt32(processHandle, IntPtr.Add(CharacterData, 0x90));
- Byte RegionX = ReadByte(processHandle, IntPtr.Add(CurrentChar, 0x84));
- Byte RegionZ = ReadByte(processHandle, IntPtr.Add(CurrentChar, 0x86));
- Single posX = ReadSingle(processHandle, IntPtr.Add(CurrentChar, 0x88));
- Single posZ = ReadSingle(processHandle, IntPtr.Add(CurrentChar, 0x8C));
- Single posY = ReadSingle(processHandle, IntPtr.Add(CurrentChar, 0x90));
- Position CurrentPosition = new Position(RegionX, RegionZ, posX, posY, posZ);
- Character CurrentCharacter = new Character(UniqueID, RefObjID, Name, CurrentPosition);
- if(UniqueID != 0x00000000)
- ConnectedCharacters.Add(CurrentCharacter);
- }
- ListCharOffset += 0x04;
- }
- while (vftable.Equals(new IntPtr(0x00AF59FC)));
- foreach(Character CurrentChararcter in ConnectedCharacters)
- Program.MainWindow.connectedCharacters.Items.Add(CurrentChararcter);
- }
- public static void GetSpawnedNPCs()
- {
- SpawnedNPCs.Clear();
- Program.MainWindow.spawnedNPCs.Items.Clear();
- Process process = Process.GetProcessesByName("SR_GameServer_nolag2")[0];
- IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
- IntPtr baseAddress = process.MainModule.BaseAddress;
- IntPtr pListSpawnedNPCs = IntPtr.Add(baseAddress, 0x9322EC);
- IntPtr ListSpawnedNPCs = ReadPointer(processHandle, pListSpawnedNPCs);
- int ListCharOffset = 0x00;
- IntPtr vftable = IntPtr.Zero;
- do
- {
- IntPtr NextSpawnedNPC = IntPtr.Add(ListSpawnedNPCs, ListCharOffset);
- vftable = ReadPointer(processHandle, NextSpawnedNPC); //vftable -> 0x00AEf674
- if (IntPtr.Equals(vftable, new IntPtr(0x00AEF674)))
- {
- IntPtr NPCData = ReadPointer(processHandle, IntPtr.Add(NextSpawnedNPC, 0x34));
- UInt32 UniqueID = ReadUInt32(processHandle, IntPtr.Add(NextSpawnedNPC, 0x08));
- UInt32 RefObjID = ReadUInt32(processHandle, IntPtr.Add(NPCData, 0x28));
- if (UniqueID != 0x00000000 && !SpawnedNPCs.ContainsKey(UniqueID))
- SpawnedNPCs.Add(UniqueID, RefObjID);
- }
- ListCharOffset += 0x1D38;
- }
- while (vftable.Equals(new IntPtr(0x00AEF674)));
- foreach (KeyValuePair<UInt32, UInt32> CurretNPC in SpawnedNPCs)
- Program.MainWindow.spawnedNPCs.Items.Add(CurretNPC.Key.ToString("X") + " - " + CurretNPC.Value.ToString());
- }
- public static void Test1()
- {
- Process process = Process.GetProcessesByName("SR_GameServer_nolag2")[0];
- IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
- IntPtr baseAddress = process.MainModule.BaseAddress;
- }
- static public IntPtr ReadPointer(IntPtr processHandle, IntPtr address)
- {
- int bytesRead = 0;
- byte[] buffer = new byte[4];
- ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
- return new IntPtr(BitConverter.ToInt32(buffer, 0));
- }
- static public Byte ReadByte(IntPtr processHandle, IntPtr address)
- {
- int bytesRead = 0;
- byte[] buffer = new byte[1];
- ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
- return buffer[0];
- }
- static public Int32 ReadInt32(IntPtr processHandle, IntPtr address)
- {
- int bytesRead = 0;
- byte[] buffer = new byte[4];
- ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
- return BitConverter.ToInt32(buffer, 0);
- }
- static public UInt32 ReadUInt32(IntPtr processHandle, IntPtr address)
- {
- int bytesRead = 0;
- byte[] buffer = new byte[4];
- ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
- return BitConverter.ToUInt32(buffer, 0);
- }
- static public Single ReadSingle(IntPtr processHandle, IntPtr address)
- {
- int bytesRead = 0;
- byte[] buffer = new byte[4];
- ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
- return BitConverter.ToSingle(buffer, 0);
- }
- static public String ReadAscii(IntPtr processHandle, IntPtr address, int Length)
- {
- int bytesRead = 0;
- byte[] buffer = new byte[Length];
- ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
- return Encoding.ASCII.GetString(buffer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement