private void timer_Tick(object sender, EventArgs e) { GameState newGameState = new GameState(); ProcessMemoryReader pmr = new ProcessMemoryReader(); if(pmr.OpenProcess()) { newGameState.zone = pmr.GetZoneShort(); newGameState.spawnList = pmr.GetSpawnList(); newGameState.groundSpawnList = pmr.GetGroundSpawnList(); newGameState.self = pmr.GetSelf(); newGameState.target = pmr.GetTarget(); newGameState.account = pmr.GetAccount(); newGameState.server = pmr.GetServer(); newGameState.installDir = pmr.GetInstallDir(); //DateTime gameTime = pmr.GetGameTime(); // broke. add in when offsets are figured out pmr.CloseHandle(); if (newGameState.zone != "") { analyze(newGameState); } this.oldGameState = newGameState; } }
private void analyze(GameState newGameState) { //ontick always goes off if(OnTick != null) { OnTick(this); } //see if we zoned if (newGameState.zone != "" && oldGameState.zone != newGameState.zone) { oldGameState.spawnList.Clear(); StringEventArgs zoneArgs = new StringEventArgs(); zoneArgs.value = newGameState.zone; if (OnZone != null) { OnZone(this, zoneArgs); } } //spawnlistUpdate events //add new spawns foreach (Spawn s in newGameState.spawnList.Except(oldGameState.spawnList, new SpawnComparer()).ToArray()) { SpawnEventArgs args = new SpawnEventArgs(); args.spawn = s; if(OnSpawnAdd != null) { OnSpawnAdd(this, args); } } //update position on existing spawns foreach (Spawn s in newGameState.spawnList.Intersect(oldGameState.spawnList, new SpawnComparer()).ToArray()) { Spawn tmpSpawn = oldGameState.spawnList.Find(x => x.id == s.id); if (s.xLoc != tmpSpawn.xLoc || s.yLoc != tmpSpawn.yLoc || s.heading != tmpSpawn.heading) { SpawnEventArgs args = new SpawnEventArgs(); args.spawn = s; if (OnSpawnUpdate != null) { OnSpawnUpdate(this, args); } } if (s.type != tmpSpawn.type) { //something died so the spawn poofs and corpse is spawned SpawnEventArgs args = new SpawnEventArgs(); args.spawn = s; if (OnSpawnDelete != null) { OnSpawnDelete(this, args); } if (OnSpawnAdd != null) { OnSpawnAdd(this, args); } } } //remove missing spawns foreach (Spawn s in oldGameState.spawnList.Except(newGameState.spawnList, new SpawnComparer()).ToArray()) { SpawnEventArgs args = new SpawnEventArgs(); args.spawn = s; if (OnSpawnDelete != null) { OnSpawnDelete(this, args); } } //ToDo: groundSpawnListUpdate events //check for new target if (newGameState.spawnList.Count > 0 && oldGameState.target != newGameState.target) { SpawnEventArgs args = new SpawnEventArgs(); args.spawn = newGameState.target; if (OnTargetChange != null) { OnTargetChange(this, args); } } //check if target moved if(oldGameState.target.xLoc != newGameState.target.xLoc || oldGameState.target.yLoc != newGameState.target.yLoc || oldGameState.target.zLoc != newGameState.target.zLoc) { CoordinatesEventArgs OnTargetMoveArgs = new CoordinatesEventArgs(); OnTargetMoveArgs.point.X = newGameState.target.xLoc; OnTargetMoveArgs.point.Y = newGameState.target.yLoc; OnTargetMoveArgs.point.Z = newGameState.target.zLoc; if(OnTargetMove != null) { OnTargetMove(this, OnTargetMoveArgs); } } //check if we moved if (oldGameState.self.xLoc != newGameState.self.xLoc || oldGameState.self.yLoc != newGameState.self.yLoc || oldGameState.self.zLoc != newGameState.self.zLoc) { CoordinatesEventArgs playerMoveArgs = new CoordinatesEventArgs(); playerMoveArgs.point.X = newGameState.self.xLoc; playerMoveArgs.point.Y = newGameState.self.yLoc; playerMoveArgs.point.Z = newGameState.self.zLoc; if (OnPlayerMove != null) { OnPlayerMove(this, playerMoveArgs); } } //check if we changed level if (oldGameState.self.level != newGameState.self.level) { IntEventArgs intEventArgs = new IntEventArgs(); intEventArgs.value = newGameState.self.level; if (OnPlayerLevelChange != null) { OnPlayerLevelChange(this, intEventArgs); } } }