public static Level Read(ProcessMemory memory, uint baseAddress) { var level = new Level(); level.Floor = memory.ReadS32(baseAddress + OffsetLevel); level.Width = memory.ReadS32(baseAddress + OffsetWidth); level.Height = memory.ReadS32(baseAddress + OffsetHeight); var roomNamesStartAddress = memory.ReadU32(baseAddress + OffsetRoomNamesStart); var roomNamesEndAddress = memory.ReadU32(baseAddress + OffsetRoomNamesEnd); var roomNameCount = (roomNamesEndAddress - roomNamesStartAddress) / 28; var roomNameData = new byte[0x1C * roomNameCount]; if (memory.Read(roomNamesStartAddress, ref roomNameData) != roomNameData.Length) { throw new InvalidOperationException(); } level.RoomNames.Clear(); for (int i = 0; i < roomNameData.Length; i += 0x1C) { var roomNameLength = BitConverter.ToInt32(roomNameData, i + 0x14); if (roomNameLength < 16) { level.RoomNames.Add(Encoding.ASCII.GetString(roomNameData, i + 4, roomNameLength)); } else { var roomName = new byte[roomNameLength]; if (memory.Read(BitConverter.ToUInt32(roomNameData, i + 0x04), ref roomName) != roomName.Length) { throw new InvalidOperationException(); } level.RoomNames.Add(Encoding.ASCII.GetString(roomName, 0, roomNameLength)); } } var tileAddress = memory.ReadU32(baseAddress + OffsetSquares); // read all tile data at once instead of one tile at a time (speed!) var tileData = new byte[level.Width * level.Height * 0x5C]; if (memory.Read(tileAddress, ref tileData) != tileData.Length) { throw new InvalidOperationException(); } level.Squares = new Square[level.Width, level.Height]; for (int y = 0; y < level.Height; y++) { for (int x = 0; x < level.Width; x++) { level.Squares[x, y] = Square.Read(tileData, ((y * level.Width) + x) * 0x5C, memory); } } return(level); }
static void SearchEntryPoint() { if (process.Read(memory, 0, memory.Length) > 0 && DosBox.GetExeEntryPoint(memory, out entryPoint)) { //check if CDROM/floppy version byte[] cdPattern = Encoding.ASCII.GetBytes("CD Not Found"); var gameVersion = Shared.Tools.IndexOf(memory, cdPattern) != -1 ? GameVersion.AITD1 : GameVersion.AITD1_FLOPPY; if (gameVersion == GameVersion.AITD1_FLOPPY) { if (Shared.Tools.IndexOf(memory, Encoding.ASCII.GetBytes("USA.PAK")) != -1) { gameVersion = GameVersion.AITD1_DEMO; } } gameConfig = gameConfigs[gameVersion]; switch (gameVersion) { case GameVersion.AITD1: cache = cacheConfig.Where(x => x.Section != VarEnum.MUSIC).ToArray(); break; default: cache = cacheConfig; break; } } else { CloseReader(); } }
public WinningPlayerData(IntPtr baseAddr, ProcessMemory MemInstance, GameOffsets CurrentOffsets) { unsafe { var baseAddrCopy = baseAddr; int last = MemInstance.OffsetAddress(ref baseAddrCopy, 0, 0); int size = ((int)Math.Ceiling((decimal)((8 + CurrentOffsets.WinningPlayerDataStructOffsets.IsDeadOffset) / 8))) * 8; //Find the nearest multiple of 8 byte[] buffer = MemInstance.Read(baseAddrCopy + last, size); PlayerOutfitStructOffsets oOf = CurrentOffsets.PlayerOutfitStructOffsets; WinningPlayerDataStructOffsets pOf = CurrentOffsets.WinningPlayerDataStructOffsets; fixed(byte *ptr = buffer) { var buffptr = (IntPtr)ptr; Name = MemInstance.ReadString(MemInstance.Read <IntPtr>(baseAddrCopy, oOf.PlayerNameOffset), CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]); ColorId = (int)Marshal.ReadInt32(buffptr, oOf.ColorIDOffset); // TODO: Since IDs are changed from enum to string like "hat_police", renaming or mapping existing svgs to string is required // TODO: As a workaround just fill with 0 as IDs HatId = 0; PetId = 0; SkinId = 0; IsImpostor = Marshal.ReadByte(buffptr, pOf.IsImposterOffset) == 1; IsDead = Marshal.ReadByte(buffptr, pOf.IsDeadOffset) > 0; IsYou = Marshal.ReadByte(buffptr, pOf.IsYouOffset) == 1; } } }
public static float GetHealth(ProcessMemory processMemory) { long baseAddress = processMemory.BaseToLong() + BaseAddress; float health = processMemory.Read(baseAddress, offsetsHealth); return(health * 100); }
public static string Read(ProcessMemory memory, uint baseAddress) { var length = memory.ReadU32(baseAddress + 0x10); uint valueAddress; if (length < 16) { valueAddress = baseAddress + 0x00; } else { valueAddress = memory.ReadU32(baseAddress + 0x00); } var valueBytes = new byte[length]; if (memory.Read(valueAddress, ref valueBytes) != valueBytes.Length) { throw new InvalidOperationException(); } return(Encoding.ASCII.GetString(valueBytes, 0, valueBytes.Length)); }
public WinningPlayerData(IntPtr baseAddr, ProcessMemory MemInstance, GameOffsets CurrentOffsets) { unsafe { var baseAddrCopy = baseAddr; int last = MemInstance.OffsetAddress(ref baseAddrCopy, 0, 0); int size = ((int)Math.Ceiling((decimal)((1 + CurrentOffsets.WinningPlayerDataStructOffsets.IsYouOffset) / 8))) * 8; //Find the nearest multiple of 8 byte[] buffer = MemInstance.Read(baseAddrCopy + last, size); WinningPlayerDataStructOffsets pOf = CurrentOffsets.WinningPlayerDataStructOffsets; fixed(byte *ptr = buffer) { var buffptr = (IntPtr)ptr; var NamePTR = MemInstance.is64Bit ? (IntPtr)Marshal.ReadInt64(buffptr, pOf.NameOffset) : (IntPtr)Marshal.ReadInt32(buffptr, pOf.NameOffset); Name = NamePTR == IntPtr.Zero ? "" : MemInstance.ReadString(NamePTR, CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]); ColorId = (int)Marshal.ReadInt32(buffptr, pOf.ColorOffset); HatId = (uint)Marshal.ReadInt32(buffptr, pOf.HatOffset); PetId = (uint)Marshal.ReadInt32(buffptr, pOf.PetOffset); SkinId = (uint)Marshal.ReadInt32(buffptr, pOf.SkinOffset); IsImpostor = Marshal.ReadByte(buffptr, pOf.ImposterOffset) == 1; IsDead = Marshal.ReadByte(buffptr, pOf.DeadOffset) > 0; IsYou = Marshal.ReadByte(buffptr, pOf.IsYouOffset) == 1; } } }
/// <summary> /// Create new instance of the <see cref="WowMemory"/>. /// </summary> /// <param name="process">Wow process.</param> public WowMemory(Process process) { if (process == null) throw new ArgumentNullException(nameof(process)); Memory = new ProcessMemory(process); Settings.Load(Build); if (Settings.PlayerName == 0U) throw new NullReferenceException($"Current game version ({Build}) not supported!"); KeyBoardProck = new KeyBoardProc(HookCallback); keyboardHook = SetWindowsHookEx(13, KeyBoardProck, Process.GetCurrentProcess().MainModule.BaseAddress, 0); mTimer.Tick += (o, e) => { if (CheckProcess()) { Settings.Load(Build);// reload offsets IsInGame = Memory.Read<bool>(Memory.Rebase(Settings.IsInGame)); if (IsInGame && Settings.FishEnbl != 0L) { var isBotEnable = Memory.Read<float>(Memory.Rebase(Settings.FishEnbl)); if (Math.Abs(isBotEnable - 12.01f) < float.Epsilon) TestBoober(); } } }; mTimer.Start(); }
/// <summary> /// Инициализирует новый экземпляр класса <see cref="Yanitta.WowMemory"/>. /// </summary> /// <param name="process">Процесс WoW.</param> public WowMemory(Process process) { if (process == null) throw new ArgumentNullException(nameof(process)); var section = $"{process.ProcessName}_{process.MainModule.FileVersionInfo.FilePrivatePart}"; Offsets = new Offsets(section); if (Offsets == null) throw new NullReferenceException($"Current game version ({section}) not supported!"); Memory = new ProcessMemory(process); // Мы должны сохранить ссылку на делегат, чтобы его не трогал сборщик мусора KeyBoardProck = new KeyBoardProc(HookCallback); keyboardHook = SetWindowsHookEx(13, KeyBoardProck, Process.GetCurrentProcess().MainModule.BaseAddress, 0); mTimer.Tick += (o, e) => { if (CheckProcess()) { var ingame = Memory.Read<byte>(Memory.Rebase(Offsets.IsInGame)); IsInGame = ingame != 0; } }; mTimer.Start(); }
public bool Update() { if (process == null) { int processId = DosBox.SearchProcess(); if (processId != -1) { process = new ProcessMemory(processId); process.BaseAddress = process.SearchFor16MRegion(); if (process.BaseAddress == -1) { CloseReader(); } } } if (process != null && entryPoint == -1) { if (process.Read(memory, 0, memory.Length) > 0 && DosBox.GetExeEntryPoint(memory, out entryPoint)) { //check if CDROM/floppy version byte[] cdPattern = Encoding.ASCII.GetBytes("CD Not Found"); gameVersion = Tools.IndexOf(memory, cdPattern) != -1 ? GameVersion.AITD1 : GameVersion.AITD1_FLOPPY; if (gameVersion == GameVersion.AITD1_FLOPPY) { if (Tools.IndexOf(memory, Encoding.ASCII.GetBytes("USA.PAK")) != -1) { gameVersion = GameVersion.AITD1_DEMO; } } gameConfig = gameConfigs[gameVersion]; } else { CloseReader(); } } if (process != null && !Freeze) { bool needRefresh = false; int time = Environment.TickCount; bool result = true; if (result &= (process.Read(memory, gameConfig.VarsAddress + entryPoint, 4) > 0)) { varsPointer = memory.ReadFarPointer(0); if (varsPointer == 0) { InitVars(vars, 0, VarEnum.VARS); } else { InitVars(vars, gameVersion == GameVersion.AITD1_DEMO ? 22 : 207, VarEnum.VARS); if (result &= (process.Read(memory, varsPointer, vars.Count * 2) > 0)) { needRefresh |= CheckDifferences(vars, time); } } } InitVars(cvars, 16, VarEnum.CVARS); if (result &= (process.Read(memory, gameConfig.CvarAddress + entryPoint, cvars.Count * 2) > 0)) { needRefresh |= CheckDifferences(cvars, time); } if (!result) { CloseReader(); } IgnoreDifferences = false; return(needRefresh); } return(false); }
public static T Read <T>(IntPtr address) where T : struct { return(Reader.Read <T>(address)); }