SHARE
TWEET

Untitled

a guest Nov 14th, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9.  
  10. namespace SR_GameServer_Reader
  11. {
  12.     static public class Main
  13.     {
  14.        
  15.  
  16.         static public List<Character> ConnectedCharacters = new List<Character>();
  17.         static public Dictionary<UInt32, UInt32> SpawnedNPCs = new Dictionary<UInt32, UInt32>();
  18.  
  19.         public delegate UInt32 GetLobbyEntryByJID(UInt32 CLobby, UInt32 JID);
  20.  
  21.         const int PROCESS_WM_READ = 0x0010;
  22.  
  23.         [DllImport("kernel32.dll")]
  24.         public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  25.  
  26.         [DllImport("kernel32.dll")]
  27.         public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
  28.  
  29.         public static void ReadMemory()
  30.         {
  31.             ConnectedCharacters.Clear();
  32.             Program.MainWindow.connectedCharacters.Items.Clear();
  33.  
  34.             Process process = Process.GetProcessesByName("SR_GameServer_nolag2")[0];
  35.             IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
  36.  
  37.             IntPtr baseAddress = process.MainModule.BaseAddress;
  38.  
  39.             IntPtr ppListChar = IntPtr.Add(baseAddress, 0x8D3A3C);
  40.  
  41.             IntPtr pListChar = ReadPointer(processHandle, ppListChar);
  42.  
  43.             IntPtr ListChar = ReadPointer(processHandle, pListChar);
  44.             int ListCharOffset = 0x00;
  45.  
  46.             IntPtr vftable = IntPtr.Zero;
  47.  
  48.             do
  49.             {
  50.                 IntPtr ListCharNext = IntPtr.Add(ListChar, ListCharOffset);
  51.                 IntPtr CurrentChar = ReadPointer(processHandle, ListCharNext);      //this.value = 8e8e3024
  52.  
  53.                 vftable = ReadPointer(processHandle, CurrentChar);      //this.value = 8e8e3024
  54.  
  55.                 if (IntPtr.Equals(vftable, new IntPtr(0x00AF59FC)))
  56.                 {
  57.                     UInt32 UniqueID = ReadUInt32(processHandle, IntPtr.Add(CurrentChar, 0x08));
  58.  
  59.                     IntPtr CharacterData = ReadPointer(processHandle, IntPtr.Add(CurrentChar, 0x34));
  60.  
  61.                     UInt32 RefObjID = ReadUInt32(processHandle, IntPtr.Add(CharacterData, 0x28));
  62.  
  63.                     String Name = ReadAscii(processHandle, IntPtr.Add(CharacterData, 0x30), 16);
  64.  
  65.                     UInt32 CurrentHP = ReadUInt32(processHandle, IntPtr.Add(CharacterData, 0x8C));
  66.                     UInt32 CurrentMP = ReadUInt32(processHandle, IntPtr.Add(CharacterData, 0x90));
  67.  
  68.                     Byte RegionX = ReadByte(processHandle, IntPtr.Add(CurrentChar, 0x84));
  69.                     Byte RegionZ = ReadByte(processHandle, IntPtr.Add(CurrentChar, 0x86));
  70.  
  71.                     Single posX = ReadSingle(processHandle, IntPtr.Add(CurrentChar, 0x88));
  72.                     Single posZ = ReadSingle(processHandle, IntPtr.Add(CurrentChar, 0x8C));
  73.                     Single posY = ReadSingle(processHandle, IntPtr.Add(CurrentChar, 0x90));
  74.  
  75.                     Position CurrentPosition = new Position(RegionX, RegionZ, posX, posY, posZ);
  76.                     Character CurrentCharacter = new Character(UniqueID, RefObjID, Name, CurrentPosition);
  77.  
  78.                     if(UniqueID != 0x00000000)
  79.                         ConnectedCharacters.Add(CurrentCharacter);
  80.                 }
  81.  
  82.                 ListCharOffset += 0x04;
  83.             }
  84.             while (vftable.Equals(new IntPtr(0x00AF59FC)));
  85.  
  86.             foreach(Character CurrentChararcter in ConnectedCharacters)
  87.                 Program.MainWindow.connectedCharacters.Items.Add(CurrentChararcter);
  88.         }
  89.         public static void GetSpawnedNPCs()
  90.         {
  91.             SpawnedNPCs.Clear();
  92.             Program.MainWindow.spawnedNPCs.Items.Clear();
  93.  
  94.             Process process = Process.GetProcessesByName("SR_GameServer_nolag2")[0];
  95.             IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
  96.  
  97.             IntPtr baseAddress = process.MainModule.BaseAddress;
  98.  
  99.             IntPtr pListSpawnedNPCs = IntPtr.Add(baseAddress, 0x9322EC);
  100.  
  101.             IntPtr ListSpawnedNPCs = ReadPointer(processHandle, pListSpawnedNPCs);
  102.  
  103.             int ListCharOffset = 0x00;
  104.  
  105.             IntPtr vftable = IntPtr.Zero;
  106.  
  107.             do
  108.             {
  109.                 IntPtr NextSpawnedNPC = IntPtr.Add(ListSpawnedNPCs, ListCharOffset);
  110.  
  111.                 vftable = ReadPointer(processHandle, NextSpawnedNPC);      //vftable -> 0x00AEf674
  112.  
  113.                 if (IntPtr.Equals(vftable, new IntPtr(0x00AEF674)))
  114.                 {
  115.                     IntPtr NPCData = ReadPointer(processHandle, IntPtr.Add(NextSpawnedNPC, 0x34));
  116.  
  117.                     UInt32 UniqueID = ReadUInt32(processHandle, IntPtr.Add(NextSpawnedNPC, 0x08));
  118.  
  119.                     UInt32 RefObjID = ReadUInt32(processHandle, IntPtr.Add(NPCData, 0x28));
  120.  
  121.                     if (UniqueID != 0x00000000 && !SpawnedNPCs.ContainsKey(UniqueID))
  122.                         SpawnedNPCs.Add(UniqueID, RefObjID);
  123.                 }
  124.  
  125.                 ListCharOffset += 0x1D38;
  126.             }
  127.             while (vftable.Equals(new IntPtr(0x00AEF674)));
  128.  
  129.             foreach (KeyValuePair<UInt32, UInt32> CurretNPC in SpawnedNPCs)
  130.                 Program.MainWindow.spawnedNPCs.Items.Add(CurretNPC.Key.ToString("X") + " - " + CurretNPC.Value.ToString());
  131.         }
  132.  
  133.         public static void Test1()
  134.         {
  135.             Process process = Process.GetProcessesByName("SR_GameServer_nolag2")[0];
  136.             IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
  137.  
  138.             IntPtr baseAddress = process.MainModule.BaseAddress;
  139.         }
  140.  
  141.  
  142.         static public IntPtr ReadPointer(IntPtr processHandle, IntPtr address)
  143.         {
  144.             int bytesRead = 0;
  145.             byte[] buffer = new byte[4];
  146.  
  147.             ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
  148.  
  149.             return new IntPtr(BitConverter.ToInt32(buffer, 0));
  150.         }
  151.  
  152.         static public Byte ReadByte(IntPtr processHandle, IntPtr address)
  153.         {
  154.             int bytesRead = 0;
  155.             byte[] buffer = new byte[1];
  156.  
  157.             ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
  158.  
  159.             return buffer[0];
  160.         }
  161.  
  162.         static public Int32 ReadInt32(IntPtr processHandle, IntPtr address)
  163.         {
  164.             int bytesRead = 0;
  165.             byte[] buffer = new byte[4];
  166.  
  167.             ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
  168.  
  169.             return BitConverter.ToInt32(buffer, 0);
  170.         }
  171.  
  172.         static public UInt32 ReadUInt32(IntPtr processHandle, IntPtr address)
  173.         {
  174.             int bytesRead = 0;
  175.             byte[] buffer = new byte[4];
  176.  
  177.             ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
  178.  
  179.             return BitConverter.ToUInt32(buffer, 0);
  180.         }
  181.  
  182.         static public Single ReadSingle(IntPtr processHandle, IntPtr address)
  183.         {
  184.             int bytesRead = 0;
  185.             byte[] buffer = new byte[4];
  186.  
  187.             ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
  188.  
  189.             return BitConverter.ToSingle(buffer, 0);
  190.         }
  191.  
  192.         static public String ReadAscii(IntPtr processHandle, IntPtr address, int Length)
  193.         {
  194.             int bytesRead = 0;
  195.             byte[] buffer = new byte[Length];
  196.  
  197.             ReadProcessMemory((int)processHandle, (int)address, buffer, buffer.Length, ref bytesRead);
  198.  
  199.             return Encoding.ASCII.GetString(buffer);
  200.         }
  201.  
  202.     }
  203. }
RAW Paste Data
Top