public void ToggleNavigation() { if (drivingOffroad) { //offroad driving script should handle that separately OffroadPlanning.setNextTarget(); triedRestartingAutodrive = false; } else { MethodInfo inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); inf.Invoke(kh, new object[] { new KeyEventArgs(Keys.J) }); } }
public void ReloadGame() { if (staticCamera) { return; } clearStuckCheckers(); /* * Process p = Process.GetProcessesByName("Grand Theft Auto V").FirstOrDefault(); * if (p != null) * { * IntPtr h = p.MainWindowHandle; * SetForegroundWindow(h); * SendKeys.SendWait("{ESC}"); * //Script.Wait(200); * } */ // or use CLEAR_AREA_OF_VEHICLES Ped player = Game.Player.Character; //UINotify("x = " + player.Position.X + "y = " + player.Position.Y + "z = " + player.Position.Z); // no need to release the autodrive here // delete all surrounding vehicles & the driver's car // ClearSurroundingVehicles(player.Position, 1000f); player.LastVehicle.Delete(); // teleport to the spawning position, defined in GameUtils.cs, subject to changes // player.Position = GTAConst.OriginalStartPos; if (drivingOffroad) { OffroadPlanning.setNextStart(); OffroadPlanning.setNextTarget(); } else { player.Position = GTAConst.HighwayStartPos; } // ClearSurroundingVehicles(player.Position, 100f); // ClearSurroundingVehicles(player.Position, 50f); ClearSurroundingVehicles(player.Position, 20f); // start a new run EnterVehicle(); //Script.Wait(2000); ToggleNavigation(); lowSpeedTime.clear(); }
public void OnKeyDown(object o, KeyEventArgs k) { // Logger.WriteLine("VisionExport OnKeyDown called."); switch (k.KeyCode) { case Keys.PageUp: postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); UINotify("GTA Vision Enabled"); // there is set weather, just for testing World.Weather = wantedWeather; break; case Keys.PageDown: if (staticCamera) { CamerasList.Deactivate(); } StopRun(); StopSession(); UINotify("GTA Vision Disabled"); break; // temp modification case Keys.H: EnterVehicle(); UINotify("Trying to enter vehicle"); ToggleNavigation(); break; // temp modification case Keys.Y: ReloadGame(); break; // temp modification case Keys.X: notificationsAllowed = !notificationsAllowed; if (notificationsAllowed) { UI.Notify("Notifications Enabled"); } else { UI.Notify("Notifications Disabled"); } break; // temp modification case Keys.U: var settings = ScriptSettings.Load("GTAVisionExport.xml"); var loc = AppDomain.CurrentDomain.BaseDirectory; //UINotify(ConfigurationManager.AppSettings["database_connection"]); var str = settings.GetValue("", "ConnectionString"); UINotify("BaseDirectory: " + loc); UINotify("ConnectionString: " + str); break; // temp modification case Keys.G: /* * IsGamePaused = true; * Game.Pause(true); * Script.Wait(500); * TraverseWeather(); * Script.Wait(500); * IsGamePaused = false; * Game.Pause(false); */ GTAData data; if (multipleWeathers) { data = GTAData.DumpData(Game.GameTime + ".tiff", wantedWeathers.ToList()); } else { Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; data = GTAData.DumpData(Game.GameTime + ".tiff", weather); } string path = @"D:\GTAV_extraction_output\trymatrix.txt"; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter file = File.CreateText(path)) { file.WriteLine("cam direction file"); file.WriteLine("direction:"); file.WriteLine( $"{World.RenderingCamera.Direction.X} {World.RenderingCamera.Direction.Y} {World.RenderingCamera.Direction.Z}"); file.WriteLine("Dot Product:"); file.WriteLine(Vector3.Dot(World.RenderingCamera.Direction, World.RenderingCamera.Rotation)); file.WriteLine("position:"); file.WriteLine( $"{World.RenderingCamera.Position.X} {World.RenderingCamera.Position.Y} {World.RenderingCamera.Position.Z}"); file.WriteLine("rotation:"); file.WriteLine( $"{World.RenderingCamera.Rotation.X} {World.RenderingCamera.Rotation.Y} {World.RenderingCamera.Rotation.Z}"); file.WriteLine("relative heading:"); file.WriteLine(GameplayCamera.RelativeHeading.ToString()); file.WriteLine("relative pitch:"); file.WriteLine(GameplayCamera.RelativePitch.ToString()); file.WriteLine("fov:"); file.WriteLine(GameplayCamera.FieldOfView.ToString()); } } break; // temp modification case Keys.T: World.Weather = Weather.Raining; /* set it between 0 = stop, 1 = heavy rain. set it too high will lead to sloppy ground */ Function.Call(Hash._SET_RAIN_FX_INTENSITY, 0.5f); var test = Function.Call <float>(Hash.GET_RAIN_LEVEL); UINotify("" + test); World.CurrentDayTime = new TimeSpan(12, 0, 0); //Script.Wait(5000); break; case Keys.N: UINotify("N pressed, going to take screenshots"); startRunAndSessionManual(); postgresTask?.Wait(); runTask?.Wait(); UINotify("starting screenshots"); for (int i = 0; i < 2; i++) { GamePause(true); gatherData(100); GamePause(false); Script.Wait(200); // hoping game will go on during this wait } if (staticCamera) { CamerasList.Deactivate(); } StopRun(); StopSession(); break; case Keys.OemMinus: //to tlačítko vlevo od pravého shiftu, - UINotify("- pressed, going to rotate cameras"); Game.Pause(true); for (int i = 0; i < CamerasList.cameras.Count; i++) { Logger.WriteLine($"activating camera {i}"); CamerasList.ActivateCamera(i); Script.Wait(1000); } CamerasList.Deactivate(); Game.Pause(false); break; case Keys.I: var info = new GTAVisionUtils.InstanceData(); UINotify(info.type); UINotify(info.publichostname); break; case Keys.Divide: Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position."); var startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea()); var start = OffroadPlanning.GetRandomPoint(startRect); var startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); // OffroadPlanning.setNextStart(); startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea()); start = OffroadPlanning.GetRandomPoint(startRect); somePos = start; startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); // when I use the same position, the GetGroundHeight call takes coordinates of player as ground height Game.Player.Character.Position = new Vector3(start.X + 5, start.Y + 5, 800); Logger.WriteLine($"teleporting player above teh position."); Script.Wait(50); startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position."); Logger.ForceFlush(); break; case Keys.F12: Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position."); Logger.WriteLine($"{World.GetGroundHeight(somePos)} is the {somePos} ground position."); break; case Keys.F11: Model mod = new Model(GTAConst.OffroadVehicleHash); var player = Game.Player; var vehicle = World.CreateVehicle(mod, player.Character.Position); player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); break; case Keys.F10: startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea()); start = OffroadPlanning.GetRandomPoint(startRect); somePos = start; startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); for (int i = 900; i > 100; i -= 50) { // when I use the same position, the GetGroundHeight call takes coordinates of player as ground height Game.Player.Character.Position = new Vector3(start.X + 5, start.Y + 5, i); Logger.WriteLine($"teleporting player above teh position to height {i}."); Script.Wait(500); startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); } break; case Keys.F9: //turn on and off for datagathering during driving, mostly for testing offroad gatheringData = !gatheringData; if (gatheringData) { UI.Notify("will be gathering data"); } else { UI.Notify("won't be gathering data"); } break; } }
/* -1 = need restart, 0 = normal, 1 = need to enter vehicle */ public GameStatus checkStatus() { var player = Game.Player.Character; if (player.IsDead) { return(GameStatus.NeedReload); } if (player.IsInVehicle()) { var vehicle = player.CurrentVehicle; // here checking the time in low or no speed if (vehicle.Speed < 1.0f) //speed is in mph { if (lowSpeedTime.isPassed(Game.GameTime)) { Logger.WriteLine("needed reload by low speed for 2 minutes"); UINotify("needed reload by low speed for 2 minutes"); return(GameStatus.NeedReload); } } else { lowSpeedTime.clear(); } if (vehicle.Speed < 0.01f) { if (notMovingTime.isPassed(Game.GameTime)) { Logger.WriteLine("needed reload by staying in place 30 seconds"); UINotify("needed reload by staying in place 30 seconds"); return(GameStatus.NeedReload); } // if (notMovingNorDrivingTime.isPassed(Game.GameTime) && !triedRestartingAutodrive) { if (notMovingNorDrivingTime.isPassed(Game.GameTime)) { Logger.WriteLine("starting driving from 6s inactivity"); UINotify("starting driving from 6s inactivity"); if (drivingOffroad) { OffroadPlanning.DriveToCurrentTarget(); triedRestartingAutodrive = true; } } } else { notMovingTime.clear(); notMovingNorDrivingTime.clear(); } // here checking the movement from previous position on some time if (NearPointFromStart.isPassed(Game.GameTime, vehicle.Position)) { Logger.WriteLine("vehicle hasn't moved for 10 meters after 1 minute"); return(GameStatus.NeedReload); } if (LongFarFromTarget.isPassed(Game.GameTime, vehicle.Position)) { Logger.WriteLine("hasn't been any nearer to goal after 90 seconds"); return(GameStatus.NeedReload); } return(GameStatus.NoActionNeeded); } else { return(GameStatus.NeedReload); } }
public void OnTick(object o, EventArgs e) { if (server.Poll(10, SelectMode.SelectRead) && connection == null) { connection = server.Accept(); UINotify("CONNECTED"); connection.Blocking = false; } HandlePipeInput(); if (!enabled) { return; } //Array values = Enum.GetValues(typeof(Weather)); switch (checkStatus()) { case GameStatus.NeedReload: Logger.WriteLine("Status is NeedReload"); StopRun(); runTask?.Wait(); runTask = StartRun(); //StopSession(); //Autostart(); UINotify("need reload game"); Wait(100); ReloadGame(); break; case GameStatus.NeedStart: Logger.WriteLine("Status is NeedStart"); //Autostart(); // use reloading temporarily StopRun(); ReloadGame(); Wait(100); runTask?.Wait(); runTask = StartRun(); //Autostart(); break; case GameStatus.NoActionNeeded: break; } // UINotify("runTask.IsCompleted: " + runTask.IsCompleted.ToString()); // UINotify("postgresTask.IsCompleted: " + postgresTask.IsCompleted.ToString()); if (!runTask.IsCompleted) { return; } if (!postgresTask.IsCompleted) { return; } if (drivingOffroad && OffroadPlanning.offroadDrivingStarted) { OffroadPlanning.checkDrivingToTarget(); OffroadPlanning.setNextTarget(); } // UINotify("going to save images and save to postgres"); if (gatheringData) { try { GamePause(true); gatherData(); GamePause(false); } catch (Exception exception) { GamePause(false); Logger.WriteLine("exception occured, logging and continuing"); Logger.WriteLine(exception); } } // if time interval is enabled, checkes game time and sets it to timeFrom, it current time is after timeTo if (timeIntervalEnabled) { var currentTime = World.CurrentDayTime; if (currentTime > timeTo) { World.CurrentDayTime = timeFrom; } } }