public float DotProduct(Vector v) { return x * v.x + y * v.y + z * v.z; }
public static bool WorldToScreen(Vector location, out PointF point) { point = new PointF(); Vector local = location - Game.ViewOrigin; var transform = new Vector(); transform.x = local.DotProduct(Game.RefDef.viewAxis2); transform.y = local.DotProduct(Game.RefDef.viewAxis3); transform.z = local.DotProduct(Game.RefDef.viewAxis1); if (transform.z < 0.1f) return false; PointF center = Game.ScreenCenter(); point.X = center.X * (1.0f - (transform.x / Game.RefDef.fovX / transform.z)); point.Y = center.Y * (1.0f - (transform.y / Game.RefDef.fovY / transform.z)); return true; }
public static float Distance(Vector u, Vector v) { return (u - v).Length; }
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; } } }