public static void ReadGame() { if (hProcess == IntPtr.Zero) throw new SystemException("Failed to read structs from the game"); ViewOrigin = ProcessMemory.Read<Vector>(hProcess, Address.ViewOrigin); RefDef = ProcessMemory.Read<RefDef>(hProcess, Address.RefDef); Entities = ProcessMemory.ReadArray<Entity>(hProcess, Address.Entity, Entity.LENGTH, Entity.SIZE); Clients = ProcessMemory.ReadArray<ClientInfo>(hProcess, Address.ClientInfo, ClientInfo.LENGTH, ClientInfo.SIZE); Camera = ProcessMemory.Read<Camera>(hProcess, Address.Camera); CG = ProcessMemory.Read<ClientGame>(hProcess, Address.ClientGame); CGS = ProcessMemory.Read<ClientGameState>(hProcess, Address.ClientGameState); Players.Clear(); Turrets.Clear(); Helis.Clear(); Planes.Clear(); Explosives.Clear(); for (int i = 0; i < Entities.Length; i++) { bool isEntityValid = (Entities[i].isValid & 1) == 1; switch (Entities[i].type) { case EntityType.Player: var player = new Player(); player.IsValid = isEntityValid; player.ClientNum = Clients[i].clientNum; player.Origin = Entities[i].origin; player.Angles = Clients[i].angles; player.Flag = Entities[i].flags; player.IsAlive = isEntityValid; player.Name = Clients[i].name; player.Team = Clients[i].team1 == Clients[CG.clientNum].team1 && Clients[CG.clientNum].team2 != 0 ? PlayerTeam.Friendly : PlayerTeam.Hostile; player.Rank = Clients[i].rank + 1; player.Score = Clients[i].score; if (player.ClientNum == CG.clientNum) LocalPlayer = player; Players.Add(player); break; case EntityType.Turret: var turret = new Turret(); turret.IsValid = isEntityValid; turret.ClientNum = Entities[i].clientNum; turret.Origin = Entities[i].origin; Turrets.Add(turret); break; case EntityType.Helicopter: var heli = new Helicopter(); heli.IsValid = isEntityValid; heli.ClientNum = Entities[i].clientNum; heli.Origin = Entities[i].origin; Helis.Add(heli); break; case EntityType.Plane: var plane = new Plane(); plane.IsValid = isEntityValid; plane.ClientNum = Entities[i].clientNum; plane.Origin = Entities[i].origin; Planes.Add(plane); break; case EntityType.Explosive: var explosive = new Explosive(); explosive.IsValid = isEntityValid; explosive.ClientNum = Entities[i].clientNum; explosive.Origin = Entities[i].origin; Explosives.Add(explosive); break; } } }
public static void ReadGame() { if (hProcess == IntPtr.Zero) { throw new SystemException("Failed to read structs from the game"); } ViewOrigin = ProcessMemory.Read <Vector>(hProcess, Address.ViewOrigin); RefDef = ProcessMemory.Read <RefDef>(hProcess, Address.RefDef); Entities = ProcessMemory.ReadArray <Entity>(hProcess, Address.Entity, Entity.LENGTH, Entity.SIZE); Clients = ProcessMemory.ReadArray <ClientInfo>(hProcess, Address.ClientInfo, ClientInfo.LENGTH, ClientInfo.SIZE); Camera = ProcessMemory.Read <Camera>(hProcess, Address.Camera); CG = ProcessMemory.Read <ClientGame>(hProcess, Address.ClientGame); CGS = ProcessMemory.Read <ClientGameState>(hProcess, Address.ClientGameState); Players.Clear(); Turrets.Clear(); Helis.Clear(); Planes.Clear(); Explosives.Clear(); for (int i = 0; i < Entities.Length; i++) { bool isEntityValid = (Entities[i].isValid & 1) == 1; switch (Entities[i].type) { case EntityType.Player: var player = new Player(); player.IsValid = isEntityValid; player.ClientNum = Clients[i].clientNum; player.Origin = Entities[i].origin; player.Angles = Clients[i].angles; player.Flag = Entities[i].flags; player.IsAlive = isEntityValid; player.Name = Clients[i].name; player.Team = Clients[i].team1 == Clients[CG.clientNum].team1 && Clients[CG.clientNum].team2 != 0 ? PlayerTeam.Friendly : PlayerTeam.Hostile; player.Rank = Clients[i].rank + 1; player.Score = Clients[i].score; if (player.ClientNum == CG.clientNum) { LocalPlayer = player; } Players.Add(player); break; case EntityType.Turret: var turret = new Turret(); turret.IsValid = isEntityValid; turret.ClientNum = Entities[i].clientNum; turret.Origin = Entities[i].origin; Turrets.Add(turret); break; case EntityType.Helicopter: var heli = new Helicopter(); heli.IsValid = isEntityValid; heli.ClientNum = Entities[i].clientNum; heli.Origin = Entities[i].origin; Helis.Add(heli); break; case EntityType.Plane: var plane = new Plane(); plane.IsValid = isEntityValid; plane.ClientNum = Entities[i].clientNum; plane.Origin = Entities[i].origin; Planes.Add(plane); break; case EntityType.Explosive: var explosive = new Explosive(); explosive.IsValid = isEntityValid; explosive.ClientNum = Entities[i].clientNum; explosive.Origin = Entities[i].origin; Explosives.Add(explosive); break; } } }