From 27f52368835c4ea5d6f19daf53276740f5fb8294 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 11 Oct 2017 22:32:13 +0200 Subject: [PATCH 001/158] Updated README of native driver. --- native/README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/native/README.md b/native/README.md index 53baf47..f6f23c2 100644 --- a/native/README.md +++ b/native/README.md @@ -8,9 +8,16 @@ GTX770, Windows 10 64bit, Visual Studio 2017 (community edition), cmake 3.9.0, G Needed tools and libraries -------------------------- -AsiLoader and ScriptHookV : http://www.dev-c.com/files/ScriptHookV_1.0.1103.2.zip -cmake : https://cmake.org/download/ -Eigen3 : http://bitbucket.org/eigen/eigen/get/3.3.1.tar.bz2 +AsiLoader and ScriptHookV : http://www.dev-c.com/files/ScriptHookV_1.0.1180.2.zip + +cmake : https://cmake.org/download/ + +Eigen3 : http://bitbucket.org/eigen/eigen/get/3.3.1.tar.bz2 + +MS Visual Studio 2017 : https://www.visualstudio.com/cs/downloads/ + +MSBuild.exe in `PATH` variable, version 141. + Build steps ----------- From 81b1d83f5bbd1e0104fb29614f6d35d791721036 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 11 Oct 2017 22:34:18 +0200 Subject: [PATCH 002/158] indentation --- native/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/README.md b/native/README.md index f6f23c2..1e6bac6 100644 --- a/native/README.md +++ b/native/README.md @@ -10,9 +10,9 @@ Needed tools and libraries -------------------------- AsiLoader and ScriptHookV : http://www.dev-c.com/files/ScriptHookV_1.0.1180.2.zip -cmake : https://cmake.org/download/ +cmake : https://cmake.org/download/ -Eigen3 : http://bitbucket.org/eigen/eigen/get/3.3.1.tar.bz2 +Eigen3 : http://bitbucket.org/eigen/eigen/get/3.3.1.tar.bz2 MS Visual Studio 2017 : https://www.visualstudio.com/cs/downloads/ From 37de58de0bf0cb194ee56e297b28216a1cb345f7 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 11 Oct 2017 23:20:24 +0200 Subject: [PATCH 003/158] Little clarified install instructions. --- native/README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/native/README.md b/native/README.md index 1e6bac6..8795185 100644 --- a/native/README.md +++ b/native/README.md @@ -26,19 +26,20 @@ Build steps 3. Extract ScriptHookV archive and drop the files in 'bin' into your GTAV exe folder. 4. Run cmake (cmake-gui) from your Windows start menu. 5. Hit 'Browse Source' and select your GTAVisionExport/native folder. -6. Hit 'configure' (first time around it will fail but dont worry). -7. Choose project generator 'Visual Studio 15 2017 Win64' and keep the option 'use default native compilers' -8. After the fail dialog, modify the EIGEN3_INCLUDE_DIR to point to your Eigen3 folder. -9. Run 'configure' followed by 'generate'. -10. cmake should now have generated the Visual Studio solution into GTAVisionExport/build. -11. Open 'GTANativePlugin.sln' in Visual Studio. -12. Select 'release' from the 'Solution Configurations' drop down. -13. Edit GTAVisionNative project properties/configuration properties/c/c++/additional include dirs in VS to add the GTAVisionExport/src folder (this allows VS to find MinHook.h) -14. Edit GTAVisionNative project properties/configuration properties/linker/input/additional dependencies to add : +6. Hit 'Browse Build', create GTAVisionExport/native/build folder and select it. +7. Hit 'configure' (first time around it will fail but dont worry). +8. Choose project generator 'Visual Studio 15 2017 Win64' and keep the option 'use default native compilers' +9. After the fail dialog, modify the EIGEN3_INCLUDE_DIR to point to your Eigen3 folder. +10. Run 'configure' followed by 'generate'. +11. cmake should now have generated the Visual Studio solution into GTAVisionExport/build. +12. Open 'GTANativePlugin.sln' in Visual Studio. +13. Select 'release' from the 'Solution Configurations' drop down. +14. Edit GTAVisionNative project properties/configuration properties/c/c++/additional include dirs in VS to add the GTAVisionExport/native/src folder (this allows VS to find MinHook.h) +15. Edit GTAVisionNative project properties/configuration properties/linker/input/additional dependencies to add : `"..\..\deps\libMinHook.x64.lib"` -15. Press F6 to build the solution. it should now succeed and the products should be in 'GTAVisionExport\native\build\src\Release' -16. Copy GTAVisionNative.asi & GTAVisionNative.lib to your GTAV exe folder. -17. Run GTAV. -18. Get to a place where you want to grab frames and press 'l' (lowercase 'L') to grab a frame. GTAVisionExport should now create color.raw, stencil.raw and depth.raw files in your GTAV exe folder. +16. Press F6 to build the solution. it should now succeed and the products should be in 'GTAVisionExport\native\build\src\Release' +17. Copy GTAVisionNative.asi & GTAVisionNative.lib to your GTAV exe folder. +18. Run GTAV. +19. Get to a place where you want to grab frames and press 'l' (lowercase 'L') to grab a frame. GTAVisionExport should now create color.raw, stencil.raw and depth.raw files in your GTAV exe folder. HTH From dadb6b7b97f504120d3513bad4fe9aad91048495 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 12 Oct 2017 13:27:09 +0200 Subject: [PATCH 004/158] Added some notes to fix crashing game during screenshot. --- native/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/native/README.md b/native/README.md index 8795185..4bc20eb 100644 --- a/native/README.md +++ b/native/README.md @@ -43,3 +43,14 @@ Build steps 19. Get to a place where you want to grab frames and press 'l' (lowercase 'L') to grab a frame. GTAVisionExport should now create color.raw, stencil.raw and depth.raw files in your GTAV exe folder. HTH + +FAQ +--- + +The game crashes after pressing 'L': + +If you are using steam, be sure to disable the steam overlay for this game. + +If steam overlay is disabled and game still crashes, be sure to have resolution same or higher as constants in source code of this project. +Default is 1000 x 1000, as can be seen [here](https://github.com/umautobots/GTAVisionExport/blob/4f2bf90997df056764605076c0c95b885c424c43/native/src/main.cpp#L235) and [here](https://github.com/umautobots/GTAVisionExport/blob/4f2bf90997df056764605076c0c95b885c424c43/native/src/main.cpp#L212). +If you want to use lower resolution, change these numbers and recompile. From bc5271e2ba0bb7b83adacc4b1a575802e30466c7 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sat, 14 Oct 2017 19:54:36 +0200 Subject: [PATCH 005/158] Fixed postgres schema for managed plugin. --- managed/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/managed/README.md b/managed/README.md index 18b428f..b95eadb 100644 --- a/managed/README.md +++ b/managed/README.md @@ -25,6 +25,13 @@ The format of the conenction can be found at http://www.npgsql.org/doc/connectio ## database schema ```sql + +create type detection_type AS ENUM ('background', 'person', 'car', 'bicycle'); + +create type detection_class AS ENUM ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Train'); + +create type weather AS ENUM ('Unknown', 'ExtraSunny', 'Clear', 'Clouds', 'Smog', 'Foggy', 'Overcast', 'Raining', 'ThunderStorm', 'Clearing', 'Neutral', 'Snowing', 'Blizzard', 'Snowlight', 'Christmas', 'Halloween'); + create table detections ( detection_id serial not null @@ -38,7 +45,6 @@ create table detections handle integer default '-1'::integer, best_bbox box, best_bbox_old box, - method detection_method default 'gtagame'::detection_method, bbox3d box3d, rot geometry, coverage real default 0.0 @@ -94,7 +100,6 @@ create table snapshots timeofday time, currentweather weather, camera_pos geometry(PointZ), - datasource data_source_type, camera_direction geometry, camera_fov real, view_matrix double precision[], From 6d02a9f8f7054b4a6a51d92247b64bf7d2598c0b Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 31 Oct 2017 12:57:28 +0100 Subject: [PATCH 006/158] Fully working dumping to files. --- managed/GTAVisionExport.sln | 10 ++ .../GTAVisionExport/GTAVisionExport.csproj | 17 ++- managed/GTAVisionExport/VisionExport.cs | 104 +++++++++++------- managed/GTAVisionUtils/GTAVisionUtils.csproj | 14 ++- managed/GTAVisionUtils/PostgresExport.cs | 2 + native/src/main.cpp | 4 +- 6 files changed, 95 insertions(+), 56 deletions(-) diff --git a/managed/GTAVisionExport.sln b/managed/GTAVisionExport.sln index 7126d34..dfa10f3 100644 --- a/managed/GTAVisionExport.sln +++ b/managed/GTAVisionExport.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GTAVisionUtils", "GTAVision EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageViewer", "ImageViewer\ImageViewer.csproj", "{30284E7F-F081-42AA-AC6A-6D4267E87024}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox", "Sandbox\Sandbox.csproj", "{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,6 +43,14 @@ Global {30284E7F-F081-42AA-AC6A-6D4267E87024}.Release|Any CPU.Build.0 = Release|Any CPU {30284E7F-F081-42AA-AC6A-6D4267E87024}.Release|x64.ActiveCfg = Release|Any CPU {30284E7F-F081-42AA-AC6A-6D4267E87024}.Release|x64.Build.0 = Release|Any CPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Debug|x64.ActiveCfg = Debug|Any CPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Debug|x64.Build.0 = Debug|Any CPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Release|Any CPU.Build.0 = Release|Any CPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Release|x64.ActiveCfg = Release|Any CPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index 9f0302d..e749b9b 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -62,6 +62,9 @@ ..\packages\ini-parser.2.4.0\lib\net20\INIFileParser.dll + + ..\packages\MathNet.Numerics.3.17.0\lib\net40\MathNet.Numerics.dll + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.0\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll @@ -73,16 +76,15 @@ False - G:\games\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll ..\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll - - D:\Games\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet.dll - False + + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll @@ -108,10 +110,10 @@ - G:\games\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll - G:\games\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll @@ -130,9 +132,6 @@ GTAVisionUtils - - - diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 5360848..4e3e764 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -47,7 +47,7 @@ class VisionExport : Script #endif //private readonly string dataPath = // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Data"); - private readonly string dataPath = @"Z:\archives\"; + private readonly string dataPath = @"D:\projekty\GTA-V-extractors\output\"; private readonly Weather[] wantedWeather = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; private Player player; private string outputPath; @@ -68,6 +68,7 @@ class VisionExport : Script private StereoCamera cams; public VisionExport() { + System.IO.File.WriteAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport constructor called.\n"); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); PostgresExport.InitSQLTypes(); player = Game.Player; @@ -78,8 +79,8 @@ public VisionExport() var parser = new FileIniDataParser(); var location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); - var access_key = data["aws"]["access_key"]; - var secret_key = data["aws"]["secret_key"]; + //var access_key = data["aws"]["access_key"]; + //var secret_key = data["aws"]["secret_key"]; //client = new AmazonS3Client(new BasicAWSCredentials(access_key, secret_key), RegionEndpoint.USEast1); //outputPath = @"D:\Datasets\GTA\"; //outputPath = Path.Combine(outputPath, "testData.yaml"); @@ -99,7 +100,10 @@ public VisionExport() private void handlePipeInput() { - //UI.Notify(server.Available.ToString()); + System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport handlePipeInput called.\n"); + UI.Notify("handlePipeInput called"); + UI.Notify("server available:" + server.Available.ToString()); + UI.Notify(connection == null ? "connection is null" : "connection:" + connection.ToString()); if (connection == null) return; byte[] inBuffer = new byte[1024]; @@ -125,7 +129,7 @@ private void handlePipeInput() connection = null; return; } - UI.Notify(str.Length.ToString()); + UI.Notify("str length: " + str.Length.ToString()); switch (str) { case "START_SESSION": @@ -171,7 +175,9 @@ private void handlePipeInput() private void UploadFile() { - + System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport UploadFile called.\n"); + UI.Notify("UploadFile called"); + archive.Dispose(); var oldOutput = outputPath; if (oldOutput != null) @@ -206,7 +212,6 @@ private void UploadFile() public void OnTick(object o, EventArgs e) { - if (server.Poll(10, SelectMode.SelectRead) && connection == null) { @@ -247,9 +252,13 @@ public void OnTick(object o, EventArgs e) case GameStatus.NoActionNeeded: break; } + UI.Notify("runTask.IsCompleted: " + runTask.IsCompleted.ToString()); + UI.Notify("postgresTask.IsCompleted: " + postgresTask.IsCompleted.ToString()); if (!runTask.IsCompleted) return; if (!postgresTask.IsCompleted) return; - + + UI.Notify("going to upload tiff"); + List colors = new List(); Game.Pause(true); Script.Wait(500); @@ -277,7 +286,7 @@ public void OnTick(object o, EventArgs e) var depthframe = VisionNative.GetLastConstantTime(); var constantframe = VisionNative.GetLastConstantTime(); //UI.Notify("DIFF: " + (colorframe - depthframe) + " FRAMETIME: " + (1 / Game.FPS) * 1000); - UI.Notify(colors[0].Length.ToString()); + UI.Notify("colors length: " + colors[0].Length.ToString()); if (depth == null || stencil == null) { UI.Notify("No DEPTH"); @@ -300,6 +309,7 @@ public void OnTick(object o, EventArgs e) PostgresExport.SaveSnapshot(dat, run.guid); } */ + UI.Notify("going to upload and save to postgres"); ImageUtils.WaitForProcessing(); ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, Game.ScreenResolution.Height, colors, depth, stencil); @@ -344,6 +354,7 @@ public GameStatus checkStatus() public Bitmap CaptureScreen() { + UI.Notify("CaptureScreen called"); var cap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); var gfx = Graphics.FromImage(cap); //var dat = GTAData.DumpData(Game.GameTime + ".jpg"); @@ -490,6 +501,7 @@ public void TraverseWeather() public void OnKeyDown(object o, KeyEventArgs k) { + System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport OnKeyDown called.\n"); if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); @@ -521,7 +533,8 @@ public void OnKeyDown(object o, KeyEventArgs k) //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); var str = settings.GetValue("", "ConnectionString"); - UI.Notify(loc); + UI.Notify("BaseDirectory: " + loc); + UI.Notify("ConnectionString: " + str); } if (k.KeyCode == Keys.G) // temp modification @@ -537,7 +550,7 @@ public void OnKeyDown(object o, KeyEventArgs k) */ var data = GTAData.DumpData(Game.GameTime + ".tiff", new List(wantedWeather)); - string path = @"C:\Users\NGV-02\Documents\Data\trymatrix.txt"; + string path = @"D:\projekty\GTA-V-extractors\output\trymatrix.txt"; // This text is added only once to the file. if (!File.Exists(path)) { @@ -578,34 +591,12 @@ public void OnKeyDown(object o, KeyEventArgs k) if (k.KeyCode == Keys.N) { - /* - //var color = VisionNative.GetColorBuffer(); + UI.Notify("N pressed, going to print stats to file or what?"); - List colors = new List(); - Game.Pause(true); - Script.Wait(1); - var depth = VisionNative.GetDepthBuffer(); - var stencil = VisionNative.GetStencilBuffer(); - foreach (var wea in wantedWeather) { - World.TransitionToWeather(wea, 0.0f); - Script.Wait(1); - colors.Add(VisionNative.GetColorBuffer()); - } - Game.Pause(false); - if (depth != null) - { - var res = Game.ScreenResolution; - var t = Tiff.Open(Path.Combine(dataPath, "test.tiff"), "w"); - ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); - t.Close(); - UI.Notify(GameplayCamera.FieldOfView.ToString()); - } - else - { - UI.Notify("No Depth Data quite yet"); - } - //UI.Notify((connection != null && connection.Connected).ToString()); - */ + //var color = VisionNatGetColorBuffer(); + + dumpTest(); + //var color = VisionNative.GetColorBuffer(); for (int i = 0; i < 100; i++) { @@ -625,13 +616,13 @@ public void OnKeyDown(object o, KeyEventArgs k) var t = Tiff.Open(Path.Combine(dataPath, "info" + i.ToString() + ".tiff"), "w"); ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); t.Close(); - UI.Notify(GameplayCamera.FieldOfView.ToString()); + UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); //UI.Notify((connection != null && connection.Connected).ToString()); var data = GTAData.DumpData(Game.GameTime + ".dat", new List(wantedWeather)); - string path = @"C:\Users\NGV-02\Documents\Data\info.txt"; + string path = @"D:\projekty\GTA-V-extractors\output\info.txt"; // This text is added only once to the file. if (!File.Exists(path)) { @@ -653,6 +644,10 @@ public void OnKeyDown(object o, KeyEventArgs k) file.WriteLine(GameplayCamera.Direction.X.ToString()); file.WriteLine(GameplayCamera.Direction.Y.ToString()); file.WriteLine(GameplayCamera.Direction.Z.ToString()); + file.WriteLine("projection matrix"); + file.WriteLine(data.ProjectionMatrix.Values.ToString()); + file.WriteLine("view matrix"); + file.WriteLine(data.ViewMatrix.Values.ToString()); file.WriteLine("character"); file.WriteLine(data.Pos.X.ToString()); file.WriteLine(data.Pos.Y.ToString()); @@ -676,5 +671,34 @@ public void OnKeyDown(object o, KeyEventArgs k) UI.Notify(info.publichostname); } } + + private void dumpTest() + { + List colors = new List(); + Game.Pause(true); + Script.Wait(1); + var depth = VisionNative.GetDepthBuffer(); + var stencil = VisionNative.GetStencilBuffer(); + foreach (var wea in wantedWeather) + { + World.TransitionToWeather(wea, 0.0f); + Script.Wait(1); + colors.Add(VisionNative.GetColorBuffer()); + } + Game.Pause(false); + if (depth != null) + { + var res = Game.ScreenResolution; + var t = Tiff.Open(Path.Combine(dataPath, "test.tiff"), "w"); + ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); + t.Close(); + UI.Notify(GameplayCamera.FieldOfView.ToString()); + } + else + { + UI.Notify("No Depth Data quite yet"); + } + UI.Notify((connection != null && connection.Connected).ToString()); + } } } diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index b1ca021..db7920b 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -65,7 +65,7 @@ ..\packages\Microsoft.Extensions.Logging.Abstractions.1.1.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll - ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll ..\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll @@ -78,8 +78,8 @@ ..\packages\GDAL.1.11.1\lib\net40\osr_csharp.dll True - - G:\games\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet.dll + + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll ..\packages\SharpDX.3.1.1\lib\net45\SharpDX.dll @@ -94,6 +94,7 @@ + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll @@ -109,10 +110,10 @@ - ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll - ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll @@ -136,6 +137,9 @@ + + + diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index d371154..16d74ea 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -24,6 +24,7 @@ public static void InitSQLTypes() NpgsqlConnection.MapEnumGlobally(); NpgsqlConnection.MapEnumGlobally(pgName: "detection_class", nameTranslator: new NpgsqlNullNameTranslator()); } + public static NpgsqlConnection OpenConnection() { var parser = new FileIniDataParser(); @@ -171,6 +172,7 @@ public static async void SaveSnapshot(GTAData data, Guid runId) { await Task.Run(() => SaveSnapshotImpl(data, runId)); } + public static void SaveSnapshotImpl(GTAData data, Guid runId) { var conn = OpenConnection(); diff --git a/native/src/main.cpp b/native/src/main.cpp index a34fcd1..a0c8ff5 100644 --- a/native/src/main.cpp +++ b/native/src/main.cpp @@ -209,7 +209,7 @@ void clear_render_target_view_hook(ID3D11DeviceContext* self, ID3D11RenderTarget hr = res.As(&tex); if (hr != S_OK) return; tex->GetDesc(&desc); - if (desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM && desc.Width > 1000 && desc.Height > 1000) { + if (desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM && desc.Width > 600 && desc.Height > 600) { lastRtv = curRTV; } } @@ -232,7 +232,7 @@ void clear_depth_stencil_view_hook(ID3D11DeviceContext* self, ID3D11DepthStencil if (hr != S_OK) return; tex->GetDesc(&desc); - if (lastDsv == nullptr && desc.Format == DXGI_FORMAT_R32G8X24_TYPELESS && desc.Width > 1000 && desc.Height > 1000) { + if (lastDsv == nullptr && desc.Format == DXGI_FORMAT_R32G8X24_TYPELESS && desc.Width > 600 && desc.Height > 600) { lastDsv = curDSV; ExtractDepthBuffer(dev.Get(), self, res.Get()); last_capture_depth = system_clock::now(); From fcc4b8b8bc7a83361dfd9c1092d70a6b2ae49159 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 31 Oct 2017 16:06:05 +0100 Subject: [PATCH 007/158] Added ini information. --- managed/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/managed/README.md b/managed/README.md index b95eadb..fd49611 100644 --- a/managed/README.md +++ b/managed/README.md @@ -14,7 +14,9 @@ This is the managed portion of the gta vision export code. This gets information First go through the refereces in visual studio and update the paths for the non-nuget dependencies. These dependencies will usually live in your GTAV ddirectory. Then simply build the GTAVisionExport project and copy the resulting files into {gtav directory}/Scripts. ## database config -In order the connect to the database the managed plugins needs to know your database information. This is provided in an ini file that looks like the following: +In order the connect to the database the managed plugins needs to know your database information. + +For that, create `GTAVision.ini` file in your scripts directory with following content: ```ini [Database] ConnectionString= @@ -22,6 +24,12 @@ ConnectionString= The format of the conenction can be found at http://www.npgsql.org/doc/connection-string-parameters.html +Example config for localhost: +```ini +[Database] +ConnectionString=Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=postgres; +``` + ## database schema ```sql From 8d625e7f93b3d6313d11be4448236621e0ebd6ab Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 31 Oct 2017 16:23:27 +0100 Subject: [PATCH 008/158] Added scripts info. --- managed/README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/managed/README.md b/managed/README.md index fd49611..982fe0d 100644 --- a/managed/README.md +++ b/managed/README.md @@ -10,10 +10,14 @@ This is the managed portion of the gta vision export code. This gets information * NativeUI * others managed by nuget -## building +## Building First go through the refereces in visual studio and update the paths for the non-nuget dependencies. These dependencies will usually live in your GTAV ddirectory. Then simply build the GTAVisionExport project and copy the resulting files into {gtav directory}/Scripts. -## database config +There is ScriptHookVDotNet in references, but it is deprecated. Use ScriptHookVDotNet2 instead of ScriptHookVDotNet. + +Probably, you will need to add the System.Management dependency for it to work. + +## Database config In order the connect to the database the managed plugins needs to know your database information. For that, create `GTAVision.ini` file in your scripts directory with following content: @@ -30,7 +34,7 @@ Example config for localhost: ConnectionString=Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=postgres; ``` -## database schema +## Database schema ```sql @@ -227,4 +231,61 @@ create table system_graphics ; -``` \ No newline at end of file +``` + +## Copying compiled files to GTA V +After you compile the GTAVisionExport, copy compiled files from the `path to GTAVisionExport/managed/GTAVisionExport/bin/Release` to `path to GTA V/scripts`. +Content of `scripts` directory should be following: +- AWSSDK.dll +- BitMiracle.LibTiff.NET.dll +- BitMiracle.LibTiff.NET.xml +- gdal_csharp.dll +- GTAVision.ini +- GTAVisionExport.dll +- GTAVisionUtils.dll +- GTAVisionUtils.dll.config +- INIFileParser.dll +- INIFileParser.xml +- MathNet.Numerics.dll +- MathNet.Numerics.xml +- Microsoft.Extensions.DependencyInjection.Abstractions.dll +- Microsoft.Extensions.DependencyInjection.Abstractions.xml +- Microsoft.Extensions.Logging.Abstractions.dll +- Microsoft.Extensions.Logging.Abstractions.xml +- Microsoft.Extensions.Logging.dll +- Microsoft.Extensions.Logging.xml +- NativeUI.dll +- Npgsql.dll +- Npgsql.xml +- ogr_csharp.dll +- osr_csharp.dll +- SharpDX.dll +- SharpDX.Mathematics.dll +- SharpDX.Mathematics.xml +- SharpDX.xml +- System.Runtime.InteropServices.RuntimeInformation.dll +- System.Threading.Tasks.Extensions.dll +- System.Threading.Tasks.Extensions.xml +- VAutodrive.dll +- VAutodriveConfig.xml +- VCommonFunctions.dll +- YamlDotNet.dll +- YamlDotNet.xml + + +## Verifying it loaded correctly + +To verify all plugins loaded, see the `ScriptHookVDotNet2.log` and search for this line: +``` +[23:02:26] [DEBUG] Starting 10 script(s) ... +``` + +If less than 10 scripts loaded, you have problem. + +## Usage + +In the game, turn off the HUD, MSAA and Radar. + +Turn the plugin on by "Page Up" in the game. + +Then, collect data by pressing "N" key. \ No newline at end of file From f0844cf7ded67ee201c8f2fd892a934edd070618 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sat, 11 Nov 2017 16:25:07 +0100 Subject: [PATCH 009/158] Added docker compose and some printing. --- managed/.gitignore | 5 ++++- managed/GTAVisionExport/VisionExport.cs | 1 + managed/docker-compose.yml | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 managed/docker-compose.yml diff --git a/managed/.gitignore b/managed/.gitignore index 3a2238d..b5deaf6 100644 --- a/managed/.gitignore +++ b/managed/.gitignore @@ -242,4 +242,7 @@ ModelManifest.xml .paket/paket.exe # FAKE - F# Make -.fake/ \ No newline at end of file +.fake/ + +# Intellij Idea IDE config files +.idea/ \ No newline at end of file diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 4e3e764..5a98b0a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -130,6 +130,7 @@ private void handlePipeInput() return; } UI.Notify("str length: " + str.Length.ToString()); + UI.Notify("str: " + str.ToString()); switch (str) { case "START_SESSION": diff --git a/managed/docker-compose.yml b/managed/docker-compose.yml new file mode 100644 index 0000000..a406e00 --- /dev/null +++ b/managed/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' +services: + db: + image: mdillon/postgis:9.6-alpine + ports: + - 5432:5432 + volumes: + - gtav-postgresql:/var/lib/postgresql/data + adminer: + image: adminer + ports: + - 8081:8080 + +volumes: + gtav-postgresql: + external: true From 33192075705c4b7515348e39a2d6bacd93981028 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sat, 11 Nov 2017 20:28:48 +0100 Subject: [PATCH 010/158] Added sandbox to test things. --- managed/GTAVisionUtils/WMIInformation.cs | 4 +- managed/Sandbox/MainClass.cs | 123 ++++++++++++++ managed/Sandbox/Sandbox.csproj | 68 ++++++++ managed/Sandbox/sandbox.sql | 199 +++++++++++++++++++++++ 4 files changed, 392 insertions(+), 2 deletions(-) create mode 100644 managed/Sandbox/MainClass.cs create mode 100644 managed/Sandbox/Sandbox.csproj create mode 100644 managed/Sandbox/sandbox.sql diff --git a/managed/GTAVisionUtils/WMIInformation.cs b/managed/GTAVisionUtils/WMIInformation.cs index ba6642f..7b98eee 100644 --- a/managed/GTAVisionUtils/WMIInformation.cs +++ b/managed/GTAVisionUtils/WMIInformation.cs @@ -10,7 +10,7 @@ namespace GTAVisionUtils { - class WMIGraphicsInformation + public class WMIGraphicsInformation { public string deviceId; public string AdapterCompat; @@ -50,7 +50,7 @@ public WMIGraphicsInformation(ManagementBaseObject from) } } - class WMIInformation + public class WMIInformation { public Guid system_uuid; public string vendor; diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs new file mode 100644 index 0000000..7f252d6 --- /dev/null +++ b/managed/Sandbox/MainClass.cs @@ -0,0 +1,123 @@ +using System; +using System.IO; +using GTAVisionUtils; +using IniParser; +using Npgsql; +using Npgsql.NameTranslation; +using NpgsqlTypes; + +namespace Sandbox +{ + public enum DetectionType + { + background, + person, + car, + bicycle + } + + public enum DetectionClass + { + Unknown = -1, + Compacts = 0, + Sedans = 1, + SUVs = 2, + Coupes = 3, + Muscle = 4, + SportsClassics = 5, + Sports = 6, + Super = 7, + Motorcycles = 8, + OffRoad = 9, + Industrial = 10, + Utility = 11, + Vans = 12, + Cycles = 13, + Boats = 14, + Helicopters = 15, + Planes = 16, + Service = 17, + Emergency = 18, + Military = 19, + Commercial = 20, + Trains = 21 + } + + public enum Weather + { + Unknown = -1, + ExtraSunny = 0, + Clear = 1, + Clouds = 2, + Smog = 3, + Foggy = 4, + Overcast = 5, + Raining = 6, + ThunderStorm = 7, + Clearing = 8, + Neutral = 9, + Snowing = 10, + Blizzard = 11, + Snowlight = 12, + Christmas = 13, + Halloween = 14, + } + + public class MainClass + { + public static void InitSQLTypes() + { + NpgsqlConnection.MapEnumGlobally("weather", new NpgsqlNullNameTranslator()); + NpgsqlConnection.MapEnumGlobally(); + NpgsqlConnection.MapEnumGlobally(pgName: "detection_class", + nameTranslator: new NpgsqlNullNameTranslator()); + } + + public static NpgsqlConnection OpenConnection() + { + var parser = new FileIniDataParser(); + var location = AppDomain.CurrentDomain.BaseDirectory; + var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); + + //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); + var str = data["Database"]["ConnectionString"]; + + var conn = new NpgsqlConnection(str); + conn.Open(); + return conn; + } + + public static void InsertEnum() + { + var conn = OpenConnection(); + var trans = conn.BeginTransaction(); + using (NpgsqlCommand cmd = new NpgsqlCommand()) + { + + cmd.Connection = conn; + cmd.Transaction = trans; + //UI.Notify(data.CurrentWeather.ToString()); + cmd.Parameters.Clear(); + cmd.CommandText = + "INSERT INTO test_enums (detection_type, weather_type, detection_class) VALUES (@type, @weather, @class);"; +// cmd.CommandText = +// "INSERT INTO test_enums (detection_type) VALUES (@type);"; + cmd.Parameters.AddWithValue("@weather", NpgsqlDbType.Enum, Weather.Foggy); +// cmd.Parameters.AddWithValue("@type", NpgsqlDbType.Enum, DetectionType.background); + cmd.Parameters.AddWithValue("@type", NpgsqlDbType.Enum, DetectionType.bicycle); + cmd.Parameters.AddWithValue("@class", NpgsqlDbType.Enum, DetectionClass.Commercial); + cmd.Prepare(); + cmd.ExecuteNonQuery(); + trans.Commit(); + conn.Close(); + } + } + + public static void Main(string[] args) + { + var systemInfo = new GTAVisionUtils.WMIInformation(); + InitSQLTypes(); +// InsertEnum(); + } + } +} \ No newline at end of file diff --git a/managed/Sandbox/Sandbox.csproj b/managed/Sandbox/Sandbox.csproj new file mode 100644 index 0000000..3805e55 --- /dev/null +++ b/managed/Sandbox/Sandbox.csproj @@ -0,0 +1,68 @@ + + + + + Debug + AnyCPU + {35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Exe + Properties + Sandbox + Sandbox + v4.5.2 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\GTAVisionUtils.dll + + + ..\packages\ini-parser.2.4.0\lib\net20\INIFileParser.dll + + + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\Npgsql.dll + + + + + + + {D3C3EAE5-CFDD-454A-BD26-9D6FD5D6C239} + GTAVisionUtils + + + + + + + + \ No newline at end of file diff --git a/managed/Sandbox/sandbox.sql b/managed/Sandbox/sandbox.sql new file mode 100644 index 0000000..8a62713 --- /dev/null +++ b/managed/Sandbox/sandbox.sql @@ -0,0 +1,199 @@ +-- CREATE EXTENSION postgis; + +CREATE TYPE detection_type AS ENUM ('background', 'person', 'car', 'bicycle'); + +CREATE TYPE detection_class AS ENUM ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Train'); + +CREATE TYPE weather AS ENUM ('Unknown', 'ExtraSunny', 'Clear', 'Clouds', 'Smog', 'Foggy', 'Overcast', 'Raining', 'ThunderStorm', 'Clearing', 'Neutral', 'Snowing', 'Blizzard', 'Snowlight', 'Christmas', 'Halloween'); + +CREATE TABLE test_enums ( + detection_type detection_type, + weather_type weather, + detection_class detection_class +); + +create table detections +( + detection_id serial not null + constraint detections_pkey + primary key, + snapshot_id integer, + type detection_type, + pos geometry(PointZ), + bbox box, + class detection_class default 'Unknown'::detection_class, + handle integer default '-1'::integer, + best_bbox box, + best_bbox_old box, + bbox3d box3d, + rot geometry, + coverage real default 0.0 +) +; + + +create table runs +( + run_id serial not null + constraint runs_pkey + primary key, + runguid uuid, + archivepath text, + localpath text, + session_id integer default 1, + instance_id integer default 0 +) +; + + +create table sessions +( + session_id serial not null + constraint sessions_pkey + primary key, + name text + constraint sessions_name_key + unique, + start timestamp with time zone, + "end" timestamp with time zone +) +; + +alter table runs + add constraint runs_session_fkey +foreign key (session_id) references sessions +on delete cascade +; + +create table snapshots +( + snapshot_id serial not null + constraint snapshots_pkey + primary key, + run_id integer + constraint snapshots_run_fkey + references runs + on delete cascade, + version integer, + imagepath text, + timestamp timestamp with time zone, + timeofday time, + currentweather weather, + camera_pos geometry(PointZ), + camera_direction geometry, + camera_fov real, + view_matrix double precision[], + proj_matrix double precision[], + processed boolean default false not null, + width integer, + height integer +) +; + + +alter table detections + add constraint detections_snapshot_fkey +foreign key (snapshot_id) references snapshots +on delete cascade +; + +create table instances +( + instance_id serial not null + constraint isntances_pkey + primary key, + hostname text, + instanceid text + constraint instanceid_uniq + unique, + instancetype text, + publichostname text, + amiid text, + constraint instance_info_uniq + unique (hostname, instanceid, instancetype, publichostname, amiid) +) +; + +alter table runs + add constraint runs_instance_fkey +foreign key (instance_id) references instances +; + +create table snapshot_weathers +( + weather_id serial not null + constraint snapshot_weathers_pkey + primary key, + snapshot_id integer + constraint snapshot_weathers_snapshot_id_fkey + references snapshots + on delete cascade, + weather_type weather, + snapshot_page integer +) +; + +create table uploads +( + id serial not null + constraint uploads_pkey + primary key, + bucket text, + key text, + uploadid text +) +; + +create table datasets +( + dataset_id serial not null + constraint datasets_pkey + primary key, + dataset_name text, + view_name text +) +; + +create table systems +( + system_uuid uuid not null + constraint systems_pkey + primary key, + vendor text, + dnshostname text, + username text, + systemtype text, + totalmem integer +) +; + +create table system_graphics +( + system_graphic_id serial not null + constraint system_graphics_pkey + primary key, + deviceid text, + adaptercompatibility text, + adapterdactype text, + adapterram integer, + availability integer, + caption text, + description text, + driverdate timestamp with time zone, + driverversion text, + pnpdeviceid text, + name text, + videoarch integer, + memtype integer, + videoprocessor text, + bpp integer, + hrez integer, + vrez integer, + num_colors integer, + cols integer, + rows integer, + refresh integer, + scanmode integer, + videomodedesc text +) +; From b4ef112a99773b06f547273cb2f2b3c5212feae0 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sat, 11 Nov 2017 21:39:40 +0100 Subject: [PATCH 011/158] Fixed fucking typo --- managed/GTAVisionUtils/WMIInformation.cs | 2 +- managed/Sandbox/MainClass.cs | 84 +++++++++++++++++++++++- managed/Sandbox/Sandbox.csproj | 1 + 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/managed/GTAVisionUtils/WMIInformation.cs b/managed/GTAVisionUtils/WMIInformation.cs index 7b98eee..32fd636 100644 --- a/managed/GTAVisionUtils/WMIInformation.cs +++ b/managed/GTAVisionUtils/WMIInformation.cs @@ -38,7 +38,7 @@ public class WMIGraphicsInformation public WMIGraphicsInformation(ManagementBaseObject from) { - deviceId = from.GetPropertyValue("DeivceID") as string; + deviceId = from.GetPropertyValue("DeviceID") as string; AdapterCompat = from.GetPropertyValue("AdapterCompatibility") as string; AdapterDACType = from.GetPropertyValue("AdapterDACType") as string; AdapterRAM = from.GetPropertyValue("AdapterRAM") as string; diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 7f252d6..8b33503 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Management; using GTAVisionUtils; using IniParser; using Npgsql; @@ -8,6 +11,83 @@ namespace Sandbox { + public class WMIGraphicsInformation + { + public string deviceId; + public string AdapterCompat; + public string AdapterDACType; + public string AdapterRAM; + public int Availability; + public string Caption; + public string Description; + public DateTime DriverDate; + public string DriverVersion; + public string PnPDeviceId; + public string name; + public string VideoArch; + public string MemType; + public string VideoProcessor; + public string bpp; + public string hrez; + public string vrez; + public string num_colors; + public string cols; + public string rows; + public string refresh; + public string scanMode; + public string videoModeDesc; + + public WMIGraphicsInformation(ManagementBaseObject from) + { + deviceId = from.GetPropertyValue("DeviceID") as string; + AdapterCompat = from.GetPropertyValue("AdapterCompatibility") as string; + AdapterDACType = from.GetPropertyValue("AdapterDACType") as string; + AdapterRAM = from.GetPropertyValue("AdapterRAM") as string; + Caption = from.GetPropertyValue("Caption") as string; + DriverVersion = from.GetPropertyValue("DriverVersion") as string; + DriverDate = ManagementDateTimeConverter.ToDateTime( from.GetPropertyValue("DriverDate") as string); + VideoProcessor = from.GetPropertyValue("VideoProcessor") as string; + name = from.GetPropertyValue("Name") as string; + + } + } + public class WMIInformation + { + public Guid system_uuid; + public string vendor; + public string dnshostname; + public string username; + public string systemtype; + public UInt64 totalmem; + public List gfxCards; + /// + /// gets wmi info for the current computer + /// + public WMIInformation() + { + var scope = new ManagementScope("ROOT\\CIMV2"); + var genQuery = new ObjectQuery("SELECT * FROM Win32_ComputerSystem"); + var result = new ManagementObjectSearcher(scope, genQuery).Get().Cast(); + dnshostname = result.First().GetPropertyValue("DNSHostName") as string; + username = result.First().GetPropertyValue("UserName") as string; + systemtype = result.First().GetPropertyValue("SystemType") as string; + totalmem = (UInt64) result.First().GetPropertyValue("TotalPhysicalMemory"); + var prodQuery = new ObjectQuery("SELECT * FROM Win32_ComputerSystemProduct"); + result = new ManagementObjectSearcher(scope, prodQuery).Get().Cast(); + system_uuid = Guid.Parse( result.First().GetPropertyValue("UUID") as string); + vendor = result.First().GetPropertyValue("Vendor") as string; + + var videoQuery = new ObjectQuery("SELECT * FROM Win32_VideoController"); + result = new ManagementObjectSearcher(scope, videoQuery).Get().Cast(); + gfxCards = new List(); + foreach (var obj in result) + { + gfxCards.Add(new WMIGraphicsInformation(obj)); + } + + } + } + public enum DetectionType { background, @@ -115,8 +195,8 @@ public static void InsertEnum() public static void Main(string[] args) { - var systemInfo = new GTAVisionUtils.WMIInformation(); - InitSQLTypes(); + var systemInfo = new WMIInformation(); +// InitSQLTypes(); // InsertEnum(); } } diff --git a/managed/Sandbox/Sandbox.csproj b/managed/Sandbox/Sandbox.csproj index 3805e55..d96fffa 100644 --- a/managed/Sandbox/Sandbox.csproj +++ b/managed/Sandbox/Sandbox.csproj @@ -47,6 +47,7 @@ + From a0ed51bf1fa3b308ef997e4f364b8af3fd0f7f42 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sat, 11 Nov 2017 21:50:26 +0100 Subject: [PATCH 012/158] Added infor about the database in docker. --- managed/README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/managed/README.md b/managed/README.md index 982fe0d..71805b2 100644 --- a/managed/README.md +++ b/managed/README.md @@ -284,8 +284,14 @@ If less than 10 scripts loaded, you have problem. ## Usage -In the game, turn off the HUD, MSAA and Radar. +Make sure your PostgreSQL database is up. -Turn the plugin on by "Page Up" in the game. +If you don't want to install one, you can use the one in docker. +Start the database in docker by `docker-compose up`. +Default credentials are: +- username: `postgres` +- password: `postgres` +In the game, turn off the HUD, MSAA and Radar. +Turn the plugin on by "Page Up" in the game. Then, collect data by pressing "N" key. \ No newline at end of file From 31b4e901f127a48eb5763aa8a99c3c8223867cac Mon Sep 17 00:00:00 2001 From: racinmat Date: Sat, 11 Nov 2017 22:47:33 +0100 Subject: [PATCH 013/158] added created --- managed/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/managed/README.md b/managed/README.md index 982fe0d..34b8789 100644 --- a/managed/README.md +++ b/managed/README.md @@ -141,6 +141,7 @@ create table instances instancetype text, publichostname text, amiid text, + created timestamp without time zone default (now() at time zone 'utc'), constraint instance_info_uniq unique (hostname, instanceid, instancetype, publichostname, amiid) ) From a4b046945eff80889781508e87721f00e5e1c74c Mon Sep 17 00:00:00 2001 From: racinmat Date: Sat, 11 Nov 2017 23:07:16 +0100 Subject: [PATCH 014/158] copied not working system inserts --- managed/GTAVisionUtils/PostgresExport.cs | 2 + managed/Sandbox/MainClass.cs | 63 +++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 16d74ea..33919bf 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -44,6 +44,7 @@ public static Guid InsertSystemData(NpgsqlConnection conn) var systemInfo = new WMIInformation(); using (var cmd = new NpgsqlCommand()) { + cmd.Connection = conn; cmd.Parameters.AddWithValue("@system_uuid", systemInfo.system_uuid); cmd.Parameters.AddWithValue("@vendor", systemInfo.vendor); cmd.Parameters.AddWithValue("@dnshostname", systemInfo.dnshostname); @@ -56,6 +57,7 @@ public static Guid InsertSystemData(NpgsqlConnection conn) return Guid.Parse(cmd.ExecuteScalar() as string); } } + public static int InsertInstanceData(NpgsqlConnection conn) { diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 8b33503..7a949c2 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -156,7 +156,7 @@ public static void InitSQLTypes() public static NpgsqlConnection OpenConnection() { var parser = new FileIniDataParser(); - var location = AppDomain.CurrentDomain.BaseDirectory; + var location = @"D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts"; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); @@ -192,10 +192,71 @@ public static void InsertEnum() conn.Close(); } } + + public static int InsertInstanceData(NpgsqlConnection conn) + { + + var instanceinfo = new InstanceData(); + using (var cmd = new NpgsqlCommand()) + { + cmd.Connection = conn; + + cmd.Parameters.AddWithValue("@host", System.Environment.MachineName); + cmd.Parameters.AddWithValue("@iid", DBNull.Value); + cmd.Parameters.AddWithValue("@typ", instanceinfo.type); + cmd.Parameters.AddWithValue("@pubhost", DBNull.Value); + cmd.Parameters.AddWithValue("@amiid", DBNull.Value); + + if (instanceinfo.type != "LOCALHOST") + { + cmd.Parameters.AddWithValue("@host", instanceinfo.hostname); + cmd.Parameters.AddWithValue("@iid", instanceinfo.instanceid); + cmd.Parameters.AddWithValue("@typ", instanceinfo.type); + cmd.Parameters.AddWithValue("@pubhost", instanceinfo.publichostname); + cmd.Parameters.AddWithValue("@amiid", instanceinfo.amiid); + } + cmd.CommandText = + "SELECT instance_id FROM instances WHERE hostname=@host AND instancetype=@typ AND instanceid=@iid AND amiid=@amiid AND publichostname=@pubhost"; + var id = cmd.ExecuteScalar(); + if (id == null) + { + cmd.CommandText = + "INSERT INTO instances (hostname, instanceid, instancetype, publichostname, amiid) VALUES (@host, @iid, @typ, @pubhost, @amiid) " + + "RETURNING instance_id"; + return (int) cmd.ExecuteScalar(); + } + + return (int) id; + + } + } + + public static Guid InsertSystemData(NpgsqlConnection conn) + { + var systemInfo = new WMIInformation(); + using (var cmd = new NpgsqlCommand()) + { + cmd.Connection = conn; + cmd.Parameters.AddWithValue("@system_uuid", systemInfo.system_uuid); + cmd.Parameters.AddWithValue("@vendor", systemInfo.vendor); + cmd.Parameters.AddWithValue("@dnshostname", systemInfo.dnshostname); + cmd.Parameters.AddWithValue("@username", systemInfo.username); + cmd.Parameters.AddWithValue("@systemtype", systemInfo.systemtype); + cmd.Parameters.AddWithValue("@totalmem", systemInfo.totalmem); + cmd.CommandText = + "INSERT INTO systems (system_uuid, vendor, dnshostname, username, systemtype, totalmem) VALUES " + + "(@system_uuid, @vendor, @dnshostname, @username, @systemtype, @totalmem) ON CONFLICT DO NOTHING RETURNING system_uuid"; + return Guid.Parse(cmd.ExecuteScalar() as string); + } + } public static void Main(string[] args) { var systemInfo = new WMIInformation(); + var conn = OpenConnection(); + int instanceid = InsertInstanceData(conn); + InsertSystemData(conn); + // InitSQLTypes(); // InsertEnum(); } From 1d6c51672db7efa86ba725152786e1684b1c2c58 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 00:31:59 +0100 Subject: [PATCH 015/158] Fixed fucking insert to db with duplicate and casting to string. --- managed/GTAVisionUtils/PostgresExport.cs | 5 +++-- managed/Sandbox/MainClass.cs | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 33919bf..4b35b2e 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -53,8 +53,9 @@ public static Guid InsertSystemData(NpgsqlConnection conn) cmd.Parameters.AddWithValue("@totalmem", systemInfo.totalmem); cmd.CommandText = "INSERT INTO systems (system_uuid, vendor, dnshostname, username, systemtype, totalmem) VALUES " + - "(@system_uuid, @vendor, @dnshostname, @username, @systemtype, @totalmem) ON CONFLICT DO NOTHING RETURNING system_uuid"; - return Guid.Parse(cmd.ExecuteScalar() as string); + "(@system_uuid, @vendor, @dnshostname, @username, @systemtype, @totalmem) ON CONFLICT(system_uuid) " + + "DO UPDATE SET system_uuid = EXCLUDED.system_uuid RETURNING system_uuid"; + return Guid.Parse(cmd.ExecuteScalar().ToString()); } } diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 7a949c2..a7535c8 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -242,11 +242,14 @@ public static Guid InsertSystemData(NpgsqlConnection conn) cmd.Parameters.AddWithValue("@dnshostname", systemInfo.dnshostname); cmd.Parameters.AddWithValue("@username", systemInfo.username); cmd.Parameters.AddWithValue("@systemtype", systemInfo.systemtype); - cmd.Parameters.AddWithValue("@totalmem", systemInfo.totalmem); + cmd.Parameters.AddWithValue("@totalmem", NpgsqlDbType.Bigint, systemInfo.totalmem); +// cmd.CommandText = +// "INSERT INTO systems (system_uuid, vendor, dnshostname, username, systemtype, totalmem) VALUES " + +// "(@system_uuid, @vendor, @dnshostname, @username, @systemtype, @totalmem) ON CONFLICT DO NOTHING RETURNING system_uuid"; cmd.CommandText = "INSERT INTO systems (system_uuid, vendor, dnshostname, username, systemtype, totalmem) VALUES " + - "(@system_uuid, @vendor, @dnshostname, @username, @systemtype, @totalmem) ON CONFLICT DO NOTHING RETURNING system_uuid"; - return Guid.Parse(cmd.ExecuteScalar() as string); + "(@system_uuid, @vendor, @dnshostname, @username, @systemtype, @totalmem) ON CONFLICT(system_uuid) DO UPDATE SET system_uuid = EXCLUDED.system_uuid RETURNING system_uuid"; + return Guid.Parse(cmd.ExecuteScalar().ToString()); } } From d42c2b7c0da1208c6a14be70e65b172923ab07ef Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 00:42:13 +0100 Subject: [PATCH 016/158] fixed bigint --- managed/GTAVisionUtils/PostgresExport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 4b35b2e..a71e8ac 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -50,7 +50,7 @@ public static Guid InsertSystemData(NpgsqlConnection conn) cmd.Parameters.AddWithValue("@dnshostname", systemInfo.dnshostname); cmd.Parameters.AddWithValue("@username", systemInfo.username); cmd.Parameters.AddWithValue("@systemtype", systemInfo.systemtype); - cmd.Parameters.AddWithValue("@totalmem", systemInfo.totalmem); + cmd.Parameters.AddWithValue("@totalmem", NpgsqlDbType.Bigint, systemInfo.totalmem); cmd.CommandText = "INSERT INTO systems (system_uuid, vendor, dnshostname, username, systemtype, totalmem) VALUES " + "(@system_uuid, @vendor, @dnshostname, @username, @systemtype, @totalmem) ON CONFLICT(system_uuid) " + From 9f2b93c495dba786354922c57ab799757d770e25 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 00:55:00 +0100 Subject: [PATCH 017/158] added created everywhere --- managed/README.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/managed/README.md b/managed/README.md index 34b8789..8fa9b1c 100644 --- a/managed/README.md +++ b/managed/README.md @@ -59,7 +59,8 @@ create table detections best_bbox_old box, bbox3d box3d, rot geometry, - coverage real default 0.0 + coverage real default 0.0, + created timestamp without time zone default (now() at time zone 'utc') ) ; @@ -73,7 +74,8 @@ create table runs archivepath text, localpath text, session_id integer default 1, - instance_id integer default 0 + instance_id integer default 0, + created timestamp without time zone default (now() at time zone 'utc') ) ; @@ -87,7 +89,8 @@ create table sessions constraint sessions_name_key unique, start timestamp with time zone, - "end" timestamp with time zone + "end" timestamp with time zone, + created timestamp without time zone default (now() at time zone 'utc') ) ; @@ -162,7 +165,8 @@ create table snapshot_weathers references snapshots on delete cascade, weather_type weather, - snapshot_page integer + snapshot_page integer, + created timestamp without time zone default (now() at time zone 'utc') ) ; @@ -173,7 +177,8 @@ create table uploads primary key, bucket text, key text, - uploadid text + uploadid text, + created timestamp without time zone default (now() at time zone 'utc') ) ; @@ -183,7 +188,8 @@ create table datasets constraint datasets_pkey primary key, dataset_name text, - view_name text + view_name text, + created timestamp without time zone default (now() at time zone 'utc') ) ; @@ -196,7 +202,8 @@ create table systems dnshostname text, username text, systemtype text, - totalmem integer + totalmem bigint, + created timestamp without time zone default (now() at time zone 'utc') ) ; @@ -227,7 +234,8 @@ create table system_graphics rows integer, refresh integer, scanmode integer, - videomodedesc text + videomodedesc text, + created timestamp without time zone default (now() at time zone 'utc') ) ; From 451e678e8f3800012ea44c372a107333263a4e2e Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 17:05:00 +0100 Subject: [PATCH 018/158] added null prints, just to see what is wrong --- managed/GTAVisionExport/VisionExport.cs | 11 ++++------- managed/Sandbox/MainClass.cs | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 5a98b0a..1824c61 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -59,7 +59,6 @@ class VisionExport : Script private KeyHandling kh = new KeyHandling(); private ZipArchive archive; private Stream S3Stream; - private AmazonS3Client client; private Task postgresTask; private Task runTask; private int curSessionId = -1; @@ -79,9 +78,6 @@ public VisionExport() var parser = new FileIniDataParser(); var location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); - //var access_key = data["aws"]["access_key"]; - //var secret_key = data["aws"]["secret_key"]; - //client = new AmazonS3Client(new BasicAWSCredentials(access_key, secret_key), RegionEndpoint.USEast1); //outputPath = @"D:\Datasets\GTA\"; //outputPath = Path.Combine(outputPath, "testData.yaml"); //outStream = File.CreateText(outputPath); @@ -102,7 +98,7 @@ private void handlePipeInput() { System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport handlePipeInput called.\n"); UI.Notify("handlePipeInput called"); - UI.Notify("server available:" + server.Available.ToString()); + UI.Notify("server connected:" + server.Connected.ToString()); UI.Notify(connection == null ? "connection is null" : "connection:" + connection.ToString()); if (connection == null) return; @@ -129,7 +125,6 @@ private void handlePipeInput() connection = null; return; } - UI.Notify("str length: " + str.Length.ToString()); UI.Notify("str: " + str.ToString()); switch (str) { @@ -176,7 +171,7 @@ private void handlePipeInput() private void UploadFile() { - System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport UploadFile called.\n"); + System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); UI.Notify("UploadFile called"); archive.Dispose(); @@ -447,6 +442,8 @@ public void EnterVehicle() */ Model mod = new Model(GTA.Native.VehicleHash.Asea); var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); + if (player == null) {UI.Notify("player is null");} + if (player.Character == null) {UI.Notify("player.Character is null");} player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); //vehicle.Alpha = 0; //transparent //player.Character.Alpha = 0; diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index a7535c8..114e96a 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -257,6 +257,7 @@ public static void Main(string[] args) { var systemInfo = new WMIInformation(); var conn = OpenConnection(); + conn = null; int instanceid = InsertInstanceData(conn); InsertSystemData(conn); From dbcd2280172906bcc191e8d53e1cd9063760c7fe Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 17:25:43 +0100 Subject: [PATCH 019/158] Added some debug information. --- managed/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/managed/README.md b/managed/README.md index 6030239..ebd0a62 100644 --- a/managed/README.md +++ b/managed/README.md @@ -251,8 +251,10 @@ Content of `scripts` directory should be following: - gdal_csharp.dll - GTAVision.ini - GTAVisionExport.dll +- GTAVisionExport.pdb - GTAVisionUtils.dll - GTAVisionUtils.dll.config +- GTAVisionUtils.pdb - INIFileParser.dll - INIFileParser.xml - MathNet.Numerics.dll @@ -281,6 +283,7 @@ Content of `scripts` directory should be following: - YamlDotNet.dll - YamlDotNet.xml +PDB files enable you to see line number in the stacktrace, which is useful for debugging. ## Verifying it loaded correctly From 571ccc30ca13bbe549143dce7b742f36efccc858 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 17:26:06 +0100 Subject: [PATCH 020/158] added null check --- managed/GTAVisionExport/VisionExport.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 1824c61..ba367d2 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -444,6 +444,7 @@ public void EnterVehicle() var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); if (player == null) {UI.Notify("player is null");} if (player.Character == null) {UI.Notify("player.Character is null");} + if (vehicle == null) {UI.Notify("vehicle is null");} player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); //vehicle.Alpha = 0; //transparent //player.Character.Alpha = 0; From a382d5badceea80680221dd4555d92baa9ad6279 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 17:44:05 +0100 Subject: [PATCH 021/158] added position showing --- managed/GTAVisionExport/VisionExport.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index ba367d2..8841f61 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -441,9 +441,11 @@ public void EnterVehicle() player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); */ Model mod = new Model(GTA.Native.VehicleHash.Asea); - var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); + if (mod == null) {UI.Notify("mod is null");} if (player == null) {UI.Notify("player is null");} if (player.Character == null) {UI.Notify("player.Character is null");} + UI.Notify("player position: " + player.Character.Position.ToString()); + var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); if (vehicle == null) {UI.Notify("vehicle is null");} player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); //vehicle.Alpha = 0; //transparent From 5e68cbd1671714dabfb95c9bc865ef10f3e368df Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 18:24:48 +0100 Subject: [PATCH 022/158] added null check --- managed/GTAVisionExport/VisionExport.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 8841f61..4d6d958 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -446,8 +446,14 @@ public void EnterVehicle() if (player.Character == null) {UI.Notify("player.Character is null");} UI.Notify("player position: " + player.Character.Position.ToString()); var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); - if (vehicle == null) {UI.Notify("vehicle is null");} - player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); + if (vehicle == null) + { + UI.Notify("vehicle is null. Something is fucked up"); + } + else + { + player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); + } //vehicle.Alpha = 0; //transparent //player.Character.Alpha = 0; } From b150e63219e385dd368ee08dd9d12823945601ee Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 19:22:06 +0100 Subject: [PATCH 023/158] Fixed enum. Added some more prints. --- managed/GTAVisionExport/VisionExport.cs | 19 ++++++++++--------- managed/GTAVisionUtils/PostgresExport.cs | 6 ++++-- managed/README.md | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 4d6d958..5aba3a4 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -58,7 +58,7 @@ class VisionExport : Script private UTF8Encoding encoding = new UTF8Encoding(false); private KeyHandling kh = new KeyHandling(); private ZipArchive archive; - private Stream S3Stream; + private Stream outStream; private Task postgresTask; private Task runTask; private int curSessionId = -1; @@ -161,6 +161,7 @@ private void handlePipeInput() case "GET_SCREEN": var last = ImageUtils.getLastCapturedFrame(); Int64 size = last.Length; + UI.Notify("last size: " + size.ToString()); size = IPAddress.HostToNetworkOrder(size); connection.Send(BitConverter.GetBytes(size)); connection.Send(last); @@ -185,8 +186,8 @@ private void UploadFile() } outputPath = Path.GetTempFileName(); - S3Stream = File.Open(outputPath, FileMode.Truncate); - archive = new ZipArchive(S3Stream, ZipArchiveMode.Update); + outStream = File.Open(outputPath, FileMode.Truncate); + archive = new ZipArchive(outStream, ZipArchiveMode.Update); //File.Delete(oldOutput); /* @@ -311,8 +312,8 @@ public void OnTick(object o, EventArgs e) Game.ScreenResolution.Height, colors, depth, stencil); PostgresExport.SaveSnapshot(dat, run.guid); - S3Stream.Flush(); - if ((Int64)S3Stream.Length > (Int64)2048 * (Int64)1024 * (Int64)1024) { + outStream.Flush(); + if ((Int64)outStream.Length > (Int64)2048 * (Int64)1024 * (Int64)1024) { ImageUtils.WaitForProcessing(); StopRun(); runTask?.Wait(); @@ -406,8 +407,8 @@ public async Task StartRun() //S3Stream = s3Info.Create(); outputPath = Path.GetTempFileName(); - S3Stream = File.Open(outputPath, FileMode.Truncate); - archive = new ZipArchive(S3Stream, ZipArchiveMode.Create); + outStream = File.Open(outputPath, FileMode.Truncate); + archive = new ZipArchive(outStream, ZipArchiveMode.Create); //archive = new ZipArchive(, ZipArchiveMode.Create); @@ -422,9 +423,9 @@ public void StopRun() { runTask?.Wait(); ImageUtils.WaitForProcessing(); - if (S3Stream.CanWrite) + if (outStream.CanWrite) { - S3Stream.Flush(); + outStream.Flush(); } enabled = false; PostgresExport.StopRun(run); diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index a71e8ac..4ed531b 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -178,6 +178,7 @@ public static async void SaveSnapshot(GTAData data, Guid runId) public static void SaveSnapshotImpl(GTAData data, Guid runId) { + UI.Notify("going to save snapshot"); var conn = OpenConnection(); var trans = conn.BeginTransaction(); using (NpgsqlCommand cmd = new NpgsqlCommand()) @@ -185,7 +186,7 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Connection = conn; cmd.Transaction = trans; - //UI.Notify(data.CurrentWeather.ToString()); + UI.Notify("current weather: " + data.CurrentWeather.ToString()); cmd.CommandText = "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_direction, camera_fov, view_matrix, proj_matrix, width, height) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + @@ -242,7 +243,8 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters.AddWithValue("@class", NpgsqlDbType.Enum, DetectionClass.Unknown); cmd.Parameters.Add("@handle", NpgsqlDbType.Integer); cmd.CommandText = - "INSERT INTO detections (snapshot_id, type, pos, rot, bbox, class, handle, bbox3d) VALUES (@snapshot, @type, ST_MakePoint(@x,@y,@z), ST_MakePoint(@xrot, @yrot, @zrot), @bbox, @class, @handle," + + "INSERT INTO detections (snapshot_id, type, pos, rot, bbox, class, handle, bbox3d) VALUES " + + "(@snapshot, @type, ST_MakePoint(@x,@y,@z), ST_MakePoint(@xrot, @yrot, @zrot), @bbox, @class, @handle," + "ST_3DMakeBox(ST_MakePoint(@minx,@miny,@minz), ST_MakePoint(@maxx, @maxy, @maxz)));"; cmd.Prepare(); diff --git a/managed/README.md b/managed/README.md index ebd0a62..70d6f19 100644 --- a/managed/README.md +++ b/managed/README.md @@ -40,7 +40,7 @@ ConnectionString=Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;P create type detection_type AS ENUM ('background', 'person', 'car', 'bicycle'); -create type detection_class AS ENUM ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Train'); +create type detection_class AS ENUM ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Trains'); create type weather AS ENUM ('Unknown', 'ExtraSunny', 'Clear', 'Clouds', 'Smog', 'Foggy', 'Overcast', 'Raining', 'ThunderStorm', 'Clearing', 'Neutral', 'Snowing', 'Blizzard', 'Snowlight', 'Christmas', 'Halloween'); From 3580934e5fc4d921d862d3079f83bddeda681f5c Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 19:25:01 +0100 Subject: [PATCH 024/158] Moved UI Notify outside the postgres export --- managed/GTAVisionExport/VisionExport.cs | 2 ++ managed/GTAVisionUtils/PostgresExport.cs | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 5aba3a4..67e5573 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -311,6 +311,8 @@ public void OnTick(object o, EventArgs e) ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, Game.ScreenResolution.Height, colors, depth, stencil); + UI.Notify("going to save snapshot"); + UI.Notify("current weather: " + dat.CurrentWeather.ToString()); PostgresExport.SaveSnapshot(dat, run.guid); outStream.Flush(); if ((Int64)outStream.Length > (Int64)2048 * (Int64)1024 * (Int64)1024) { diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 4ed531b..d450911 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -178,7 +178,6 @@ public static async void SaveSnapshot(GTAData data, Guid runId) public static void SaveSnapshotImpl(GTAData data, Guid runId) { - UI.Notify("going to save snapshot"); var conn = OpenConnection(); var trans = conn.BeginTransaction(); using (NpgsqlCommand cmd = new NpgsqlCommand()) @@ -186,7 +185,6 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Connection = conn; cmd.Transaction = trans; - UI.Notify("current weather: " + data.CurrentWeather.ToString()); cmd.CommandText = "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_direction, camera_fov, view_matrix, proj_matrix, width, height) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + From 22bc07433c83cc37b4164aaa89903f965a1ab98f Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 20:28:16 +0100 Subject: [PATCH 025/158] Drastically changed uploading procedure. Now it saved to local disk instead of zipping data. Now it should hopefully work. Get screen commented because it breaks client. --- managed/GTAVisionExport/VisionExport.cs | 197 ++++++++++++------------ 1 file changed, 102 insertions(+), 95 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 67e5573..578391a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -158,14 +158,15 @@ private void handlePipeInput() .GetMethod("DoKeyboardMessage", BindingFlags.Instance | BindingFlags.Public); m.Invoke(domain, new object[] {Keys.Insert, true, false, false, false}); break; - case "GET_SCREEN": - var last = ImageUtils.getLastCapturedFrame(); - Int64 size = last.Length; - UI.Notify("last size: " + size.ToString()); - size = IPAddress.HostToNetworkOrder(size); - connection.Send(BitConverter.GetBytes(size)); - connection.Send(last); - break; +// uncomment when resolving, how the hell should I get image by socket correctly +// case "GET_SCREEN": +// var last = ImageUtils.getLastCapturedFrame(); +// Int64 size = last.Length; +// UI.Notify("last size: " + size.ToString()); +// size = IPAddress.HostToNetworkOrder(size); +// connection.Send(BitConverter.GetBytes(size)); +// connection.Send(last); +// break; } } @@ -256,22 +257,22 @@ public void OnTick(object o, EventArgs e) UI.Notify("going to upload tiff"); - List colors = new List(); +// List colors = new List(); Game.Pause(true); - Script.Wait(500); + Script.Wait(200); GTAData dat = GTAData.DumpData(Game.GameTime + ".tiff", new List()); if (dat == null) return; - var thisframe = VisionNative.GetCurrentTime(); - var depth = VisionNative.GetDepthBuffer(); - var stencil = VisionNative.GetStencilBuffer(); - colors.Add(VisionNative.GetColorBuffer()); +// var thisframe = VisionNative.GetCurrentTime(); +// var depth = VisionNative.GetDepthBuffer(); +// var stencil = VisionNative.GetStencilBuffer(); +// colors.Add(VisionNative.GetColorBuffer()); /* foreach (var wea in wantedWeather) { World.TransitionToWeather(wea, 0.0f); Script.Wait(1); colors.Add(VisionNative.GetColorBuffer()); }*/ - Game.Pause(false); +// Game.Pause(false); /* if (World.Weather != Weather.Snowing) @@ -279,16 +280,16 @@ public void OnTick(object o, EventArgs e) World.TransitionToWeather(Weather.Snowing, 1); }*/ - var colorframe = VisionNative.GetLastColorTime(); - var depthframe = VisionNative.GetLastConstantTime(); - var constantframe = VisionNative.GetLastConstantTime(); +// var colorframe = VisionNative.GetLastColorTime(); +// var depthframe = VisionNative.GetLastConstantTime(); +// var constantframe = VisionNative.GetLastConstantTime(); //UI.Notify("DIFF: " + (colorframe - depthframe) + " FRAMETIME: " + (1 / Game.FPS) * 1000); - UI.Notify("colors length: " + colors[0].Length.ToString()); - if (depth == null || stencil == null) - { - UI.Notify("No DEPTH"); - return; - } +// UI.Notify("colors length: " + colors[0].Length.ToString()); +// if (depth == null || stencil == null) +// { +// UI.Notify("No DEPTH"); +// return; +// } /* * this code checks to see if there's drift @@ -306,21 +307,22 @@ public void OnTick(object o, EventArgs e) PostgresExport.SaveSnapshot(dat, run.guid); } */ - UI.Notify("going to upload and save to postgres"); - ImageUtils.WaitForProcessing(); - ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, - Game.ScreenResolution.Height, colors, depth, stencil); + UI.Notify("going to save images and save to postgres"); +// ImageUtils.WaitForProcessing(); + saveSnapshotToFile(dat.ImageName); +// ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, +// Game.ScreenResolution.Height, colors, depth, stencil); UI.Notify("going to save snapshot"); UI.Notify("current weather: " + dat.CurrentWeather.ToString()); PostgresExport.SaveSnapshot(dat, run.guid); - outStream.Flush(); - if ((Int64)outStream.Length > (Int64)2048 * (Int64)1024 * (Int64)1024) { - ImageUtils.WaitForProcessing(); - StopRun(); - runTask?.Wait(); - runTask = StartRun(); - } +// outStream.Flush(); +// if ((Int64)outStream.Length > (Int64)2048 * (Int64)1024 * (Int64)1024) { +// ImageUtils.WaitForProcessing(); +// StopRun(); +// runTask?.Wait(); +// runTask = StartRun(); +// } } /* -1 = need restart, 0 = normal, 1 = need to enter vehicle */ @@ -610,66 +612,7 @@ public void OnKeyDown(object o, KeyEventArgs k) //var color = VisionNative.GetColorBuffer(); for (int i = 0; i < 100; i++) { - List colors = new List(); - Game.Pause(true); - var depth = VisionNative.GetDepthBuffer(); - var stencil = VisionNative.GetStencilBuffer(); - foreach (var wea in wantedWeather) - { - World.TransitionToWeather(wea, 0.0f); - Script.Wait(1); - colors.Add(VisionNative.GetColorBuffer()); - } - - Game.Pause(false); - var res = Game.ScreenResolution; - var t = Tiff.Open(Path.Combine(dataPath, "info" + i.ToString() + ".tiff"), "w"); - ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); - t.Close(); - UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); - //UI.Notify((connection != null && connection.Connected).ToString()); - - - var data = GTAData.DumpData(Game.GameTime + ".dat", new List(wantedWeather)); - - string path = @"D:\projekty\GTA-V-extractors\output\info.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 & Ped pos file"); - } - } - - using (StreamWriter file = File.AppendText(path)) - { - file.WriteLine("==============info" + i.ToString() + ".tiff 's metadata======================="); - file.WriteLine("cam pos"); - file.WriteLine(GameplayCamera.Position.X.ToString()); - file.WriteLine(GameplayCamera.Position.Y.ToString()); - file.WriteLine(GameplayCamera.Position.Z.ToString()); - file.WriteLine("cam direction"); - file.WriteLine(GameplayCamera.Direction.X.ToString()); - file.WriteLine(GameplayCamera.Direction.Y.ToString()); - file.WriteLine(GameplayCamera.Direction.Z.ToString()); - file.WriteLine("projection matrix"); - file.WriteLine(data.ProjectionMatrix.Values.ToString()); - file.WriteLine("view matrix"); - file.WriteLine(data.ViewMatrix.Values.ToString()); - file.WriteLine("character"); - file.WriteLine(data.Pos.X.ToString()); - file.WriteLine(data.Pos.Y.ToString()); - file.WriteLine(data.Pos.Z.ToString()); - foreach (var detection in data.Detections) - { - file.WriteLine(detection.Type.ToString()); - file.WriteLine(detection.Pos.X.ToString()); - file.WriteLine(detection.Pos.Y.ToString()); - file.WriteLine(detection.Pos.Z.ToString()); - } - } + saveSnapshotToFile(i.ToString() + ".tiff"); Script.Wait(200); } @@ -682,6 +625,70 @@ public void OnKeyDown(object o, KeyEventArgs k) } } + private void saveSnapshotToFile(String name) + { + List colors = new List(); + Game.Pause(true); + var depth = VisionNative.GetDepthBuffer(); + var stencil = VisionNative.GetStencilBuffer(); + foreach (var wea in wantedWeather) + { + World.TransitionToWeather(wea, 0.0f); + Script.Wait(1); + colors.Add(VisionNative.GetColorBuffer()); + } + + Game.Pause(false); + var res = Game.ScreenResolution; + var t = Tiff.Open(Path.Combine(dataPath, "info" + name), "w"); + ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); + t.Close(); + UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); + //UI.Notify((connection != null && connection.Connected).ToString()); + + + var data = GTAData.DumpData(Game.GameTime + ".dat", new List(wantedWeather)); + + string path = @"D:\projekty\GTA-V-extractors\output\info.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 & Ped pos file"); + } + } + + using (StreamWriter file = File.AppendText(path)) + { + file.WriteLine("==============info" + i.ToString() + ".tiff 's metadata======================="); + file.WriteLine("cam pos"); + file.WriteLine(GameplayCamera.Position.X.ToString()); + file.WriteLine(GameplayCamera.Position.Y.ToString()); + file.WriteLine(GameplayCamera.Position.Z.ToString()); + file.WriteLine("cam direction"); + file.WriteLine(GameplayCamera.Direction.X.ToString()); + file.WriteLine(GameplayCamera.Direction.Y.ToString()); + file.WriteLine(GameplayCamera.Direction.Z.ToString()); + file.WriteLine("projection matrix"); + file.WriteLine(data.ProjectionMatrix.Values.ToString()); + file.WriteLine("view matrix"); + file.WriteLine(data.ViewMatrix.Values.ToString()); + file.WriteLine("character"); + file.WriteLine(data.Pos.X.ToString()); + file.WriteLine(data.Pos.Y.ToString()); + file.WriteLine(data.Pos.Z.ToString()); + foreach (var detection in data.Detections) + { + file.WriteLine(detection.Type.ToString()); + file.WriteLine(detection.Pos.X.ToString()); + file.WriteLine(detection.Pos.Y.ToString()); + file.WriteLine(detection.Pos.Z.ToString()); + } + } + } + private void dumpTest() { List colors = new List(); From c135b8f6149fa1b572848fef2564c4356be58fa6 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 22:13:12 +0100 Subject: [PATCH 026/158] commented all archive related garbage --- managed/GTAVisionExport/VisionExport.cs | 177 ++++++++++++------------ 1 file changed, 90 insertions(+), 87 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 578391a..f69b56b 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -57,8 +57,8 @@ class VisionExport : Script private Socket connection; private UTF8Encoding encoding = new UTF8Encoding(false); private KeyHandling kh = new KeyHandling(); - private ZipArchive archive; - private Stream outStream; +// private ZipArchive archive; +// private Stream outStream; private Task postgresTask; private Task runTask; private int curSessionId = -1; @@ -171,42 +171,43 @@ private void handlePipeInput() } } - private void UploadFile() - { - System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); - UI.Notify("UploadFile called"); - - archive.Dispose(); - var oldOutput = outputPath; - if (oldOutput != null) - { - new Thread(() => - { - File.Move(oldOutput, Path.Combine(dataPath, run.guid + ".zip")); - }).Start(); - } - - outputPath = Path.GetTempFileName(); - outStream = File.Open(outputPath, FileMode.Truncate); - archive = new ZipArchive(outStream, ZipArchiveMode.Update); - //File.Delete(oldOutput); - - /* - archive.Dispose(); - var req = new PutObjectRequest { - BucketName = "gtadata", - Key = "images/" + run.guid + ".zip", - FilePath = outputPath - }; - var resp = client.PutObjectAsync(req); - outputPath = Path.GetTempFileName(); - S3Stream = File.Open(outputPath, FileMode.Truncate); - archive = new ZipArchive(S3Stream, ZipArchiveMode.Update); - - await resp; - File.Delete(req.FilePath); - */ - } +// private void UploadFile() +// { +// System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); +// UI.Notify("UploadFile called"); +// +//// archive.Dispose(); +// var oldOutput = outputPath; +// if (oldOutput != null) +// { +// new Thread(() => +// { +// File.Move(oldOutput, Path.Combine(dataPath, run.guid + ".zip")); +// }).Start(); +// } +// +// outputPath = Path.GetTempFileName(); +// outStream = File.Open(outputPath, FileMode.Truncate); +//// archive = new ZipArchive(outStream, ZipArchiveMode.Update); +// //File.Delete(oldOutput); +// +// /* +// archive.Dispose(); +// var req = new PutObjectRequest { +// BucketName = "gtadata", +// Key = "images/" + run.guid + ".zip", +// FilePath = outputPath +// }; +// var resp = client.PutObjectAsync(req); +// outputPath = Path.GetTempFileName(); +// S3Stream = File.Open(outputPath, FileMode.Truncate); +// archive = new ZipArchive(S3Stream, ZipArchiveMode.Update); +// +// await resp; +// File.Delete(req.FilePath); +// */ +// } + public void OnTick(object o, EventArgs e) { @@ -313,7 +314,7 @@ public void OnTick(object o, EventArgs e) // ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, // Game.ScreenResolution.Height, colors, depth, stencil); - UI.Notify("going to save snapshot"); + UI.Notify("going to save snapshot to db"); UI.Notify("current weather: " + dat.CurrentWeather.ToString()); PostgresExport.SaveSnapshot(dat, run.guid); // outStream.Flush(); @@ -410,9 +411,9 @@ public async Task StartRun() //var s3Info = new S3FileInfo(client, "gtadata", run.archiveKey); //S3Stream = s3Info.Create(); - outputPath = Path.GetTempFileName(); - outStream = File.Open(outputPath, FileMode.Truncate); - archive = new ZipArchive(outStream, ZipArchiveMode.Create); +// outputPath = Path.GetTempFileName(); +// outStream = File.Open(outputPath, FileMode.Truncate); +// archive = new ZipArchive(outStream, ZipArchiveMode.Create); //archive = new ZipArchive(, ZipArchiveMode.Create); @@ -427,13 +428,13 @@ public void StopRun() { runTask?.Wait(); ImageUtils.WaitForProcessing(); - if (outStream.CanWrite) - { - outStream.Flush(); - } +// if (outStream.CanWrite) +// { +// outStream.Flush(); +// } enabled = false; PostgresExport.StopRun(run); - UploadFile(); +// UploadFile(); run = null; Game.Player.LastVehicle.Alpha = int.MaxValue; @@ -640,53 +641,55 @@ private void saveSnapshotToFile(String name) Game.Pause(false); var res = Game.ScreenResolution; - var t = Tiff.Open(Path.Combine(dataPath, "info" + name), "w"); + var fileName = Path.Combine(dataPath, "info-" + name); + var t = Tiff.Open(fileName, "w"); ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); t.Close(); + UI.Notify("file saved to: " + fileName); UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); //UI.Notify((connection != null && connection.Connected).ToString()); - var data = GTAData.DumpData(Game.GameTime + ".dat", new List(wantedWeather)); - - string path = @"D:\projekty\GTA-V-extractors\output\info.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 & Ped pos file"); - } - } +// var data = GTAData.DumpData(Game.GameTime + ".dat", new List(wantedWeather)); - using (StreamWriter file = File.AppendText(path)) - { - file.WriteLine("==============info" + i.ToString() + ".tiff 's metadata======================="); - file.WriteLine("cam pos"); - file.WriteLine(GameplayCamera.Position.X.ToString()); - file.WriteLine(GameplayCamera.Position.Y.ToString()); - file.WriteLine(GameplayCamera.Position.Z.ToString()); - file.WriteLine("cam direction"); - file.WriteLine(GameplayCamera.Direction.X.ToString()); - file.WriteLine(GameplayCamera.Direction.Y.ToString()); - file.WriteLine(GameplayCamera.Direction.Z.ToString()); - file.WriteLine("projection matrix"); - file.WriteLine(data.ProjectionMatrix.Values.ToString()); - file.WriteLine("view matrix"); - file.WriteLine(data.ViewMatrix.Values.ToString()); - file.WriteLine("character"); - file.WriteLine(data.Pos.X.ToString()); - file.WriteLine(data.Pos.Y.ToString()); - file.WriteLine(data.Pos.Z.ToString()); - foreach (var detection in data.Detections) - { - file.WriteLine(detection.Type.ToString()); - file.WriteLine(detection.Pos.X.ToString()); - file.WriteLine(detection.Pos.Y.ToString()); - file.WriteLine(detection.Pos.Z.ToString()); - } - } +// string path = @"D:\projekty\GTA-V-extractors\output\info.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 & Ped pos file"); +// } +// } +// +// using (StreamWriter file = File.AppendText(path)) +// { +// file.WriteLine("==============info" + i.ToString() + ".tiff 's metadata======================="); +// file.WriteLine("cam pos"); +// file.WriteLine(GameplayCamera.Position.X.ToString()); +// file.WriteLine(GameplayCamera.Position.Y.ToString()); +// file.WriteLine(GameplayCamera.Position.Z.ToString()); +// file.WriteLine("cam direction"); +// file.WriteLine(GameplayCamera.Direction.X.ToString()); +// file.WriteLine(GameplayCamera.Direction.Y.ToString()); +// file.WriteLine(GameplayCamera.Direction.Z.ToString()); +// file.WriteLine("projection matrix"); +// file.WriteLine(data.ProjectionMatrix.Values.ToString()); +// file.WriteLine("view matrix"); +// file.WriteLine(data.ViewMatrix.Values.ToString()); +// file.WriteLine("character"); +// file.WriteLine(data.Pos.X.ToString()); +// file.WriteLine(data.Pos.Y.ToString()); +// file.WriteLine(data.Pos.Z.ToString()); +// foreach (var detection in data.Detections) +// { +// file.WriteLine(detection.Type.ToString()); +// file.WriteLine(detection.Pos.X.ToString()); +// file.WriteLine(detection.Pos.Y.ToString()); +// file.WriteLine(detection.Pos.Z.ToString()); +// } +// } } private void dumpTest() From e719b5db94dacc0e3825ad1b18f7c129d0c35d48 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 22:47:58 +0100 Subject: [PATCH 027/158] more meaningful file names. Based on real datetime. --- managed/GTAVisionExport/VisionExport.cs | 5 +++-- managed/Sandbox/MainClass.cs | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index f69b56b..0f01a19 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -256,12 +256,13 @@ public void OnTick(object o, EventArgs e) if (!runTask.IsCompleted) return; if (!postgresTask.IsCompleted) return; - UI.Notify("going to upload tiff"); + UI.Notify("going to save tiff"); // List colors = new List(); Game.Pause(true); Script.Wait(200); - GTAData dat = GTAData.DumpData(Game.GameTime + ".tiff", new List()); + var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; + GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff", new List()); if (dat == null) return; // var thisframe = VisionNative.GetCurrentTime(); // var depth = VisionNative.GetDepthBuffer(); diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 114e96a..e3df8d3 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -255,11 +255,14 @@ public static Guid InsertSystemData(NpgsqlConnection conn) public static void Main(string[] args) { - var systemInfo = new WMIInformation(); - var conn = OpenConnection(); - conn = null; - int instanceid = InsertInstanceData(conn); - InsertSystemData(conn); + var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; + var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; + Console.WriteLine(fileName); +// var systemInfo = new WMIInformation(); +// var conn = OpenConnection(); +// conn = null; +// int instanceid = InsertInstanceData(conn); +// InsertSystemData(conn); // InitSQLTypes(); // InsertEnum(); From 84f71fb0a18127485431875c21023e5157913fb9 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 22:48:33 +0100 Subject: [PATCH 028/158] lower time wait. --- managed/GTAVisionExport/VisionExport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 0f01a19..d4f21e3 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -260,7 +260,7 @@ public void OnTick(object o, EventArgs e) // List colors = new List(); Game.Pause(true); - Script.Wait(200); + Script.Wait(100); var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff", new List()); if (dat == null) return; From 5fb80c3c8060c688a2ccf4a06448406de3aaf6f6 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 22:49:13 +0100 Subject: [PATCH 029/158] better printscreens name --- managed/GTAVisionExport/VisionExport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index d4f21e3..14827d6 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -261,7 +261,7 @@ public void OnTick(object o, EventArgs e) // List colors = new List(); Game.Pause(true); Script.Wait(100); - var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff", new List()); if (dat == null) return; // var thisframe = VisionNative.GetCurrentTime(); From 06c0d0c95c2bf81277a50cad39259e294b34d3c8 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 12 Nov 2017 23:07:36 +0100 Subject: [PATCH 030/158] Added some more description. --- managed/README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/managed/README.md b/managed/README.md index 70d6f19..ccaf2bd 100644 --- a/managed/README.md +++ b/managed/README.md @@ -296,6 +296,7 @@ If less than 10 scripts loaded, you have problem. ## Usage +### Dependencies setup Make sure your PostgreSQL database is up. If you don't want to install one, you can use the one in docker. @@ -306,4 +307,12 @@ Default credentials are: In the game, turn off the HUD, MSAA and Radar. Turn the plugin on by "Page Up" in the game. -Then, collect data by pressing "N" key. \ No newline at end of file + +### Gathering screenshots +There is either manual or automatic way. +- Collect data manually by pressing "N" key. +- Or you can use https://github.com/racinmat/GTAVisionExport-Server. + It contains python HTTP server with buttons to control the managed plugin. + It connects to the socket server inside the managed plugin. + When the main script starts, you can click the "START_SESSION" button and then it creates new car and starts + driving autonomously and grabbing screenshots automatically. \ No newline at end of file From 72596052c9d84c4b2e4bb2b9af62433b5f56dd5a Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 13 Nov 2017 01:06:09 +0100 Subject: [PATCH 031/158] Tiff file is now created inside tiff --- managed/GTAVisionExport/VisionExport.cs | 8 ++------ managed/GTAVisionUtils/ImageUtils.cs | 10 ++++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 14827d6..c8a5db3 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -643,9 +643,7 @@ private void saveSnapshotToFile(String name) Game.Pause(false); var res = Game.ScreenResolution; var fileName = Path.Combine(dataPath, "info-" + name); - var t = Tiff.Open(fileName, "w"); - ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); - t.Close(); + ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil); UI.Notify("file saved to: " + fileName); UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); //UI.Notify((connection != null && connection.Connected).ToString()); @@ -710,9 +708,7 @@ private void dumpTest() if (depth != null) { var res = Game.ScreenResolution; - var t = Tiff.Open(Path.Combine(dataPath, "test.tiff"), "w"); - ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); - t.Close(); + ImageUtils.WriteToTiff(Path.Combine(dataPath, "test.tiff"), res.Width, res.Height, colors, depth, stencil); UI.Notify(GameplayCamera.FieldOfView.ToString()); } else diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index 5eb0546..f7235d1 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -35,22 +35,19 @@ public static void UploadToArchive(ZipArchive archive, string name, int w, int h List colors, byte[] depth, byte[] stencil) { var memstream = new MemoryStream(); - var tiff = Tiff.ClientOpen(name, "w", memstream, new TiffStream()); - WriteToTiff(tiff, w, h, colors, depth, stencil); - tiff.Flush(); - tiff.Close(); + WriteToTiff(name, w, h, colors, depth, stencil); var entry = archive.CreateEntry(name + ".tiff", CompressionLevel.NoCompression); var entryStream = entry.Open(); lastCapturedBytes = memstream.ToArray(); entryStream.Write(lastCapturedBytes, 0, lastCapturedBytes.Length); entryStream.Close(); - //tiff.Close(); memstream.Close(); } - public static void WriteToTiff(Tiff t, int width, int height, List colors, byte[] depth, byte[] stencil) + public static void WriteToTiff(string name, int width, int height, List colors, byte[] depth, byte[] stencil) { + var t = Tiff.Open(name, "w"); var pages = colors.Count + 2; var page = 0; foreach (var color in colors) @@ -107,6 +104,7 @@ public static void WriteToTiff(Tiff t, int width, int height, List color t.WriteEncodedStrip(0, stencil, stencil.Length); t.WriteDirectory(); t.Flush(); + t.Close(); } } From 67d48826e6e00c07c6bc5ca06ce826ac27cab3ee Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 13 Nov 2017 01:14:18 +0100 Subject: [PATCH 032/158] Unified compression. --- managed/GTAVisionUtils/ImageUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index f7235d1..4769190 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -61,7 +61,7 @@ public static void WriteToTiff(string name, int width, int height, List t.SetField(TiffTag.BITSPERSAMPLE, 8); t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); t.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB); - t.SetField(TiffTag.COMPRESSION, Compression.JPEG); + t.SetField(TiffTag.COMPRESSION, Compression.LZW); t.SetField(TiffTag.JPEGQUALITY, 60); t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); From b5acb1ed992fb3725f0e9a555ce134cd3b7d2604 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 14 Nov 2017 12:44:29 +0100 Subject: [PATCH 033/158] Removed directories from single page tiff. --- managed/GTAVisionExport/VisionExport.cs | 14 +++++++------- managed/GTAVisionUtils/ImageUtils.cs | 23 ++++++++++++----------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index c8a5db3..59d0857 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -262,7 +262,7 @@ public void OnTick(object o, EventArgs e) Game.Pause(true); Script.Wait(100); var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; - GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff", new List()); + GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather.ToList()); if (dat == null) return; // var thisframe = VisionNative.GetCurrentTime(); // var depth = VisionNative.GetDepthBuffer(); @@ -311,7 +311,7 @@ public void OnTick(object o, EventArgs e) */ UI.Notify("going to save images and save to postgres"); // ImageUtils.WaitForProcessing(); - saveSnapshotToFile(dat.ImageName); + saveSnapshotToFile(dat.ImageName, wantedWeather); // ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, // Game.ScreenResolution.Height, colors, depth, stencil); @@ -614,7 +614,7 @@ public void OnKeyDown(object o, KeyEventArgs k) //var color = VisionNative.GetColorBuffer(); for (int i = 0; i < 100; i++) { - saveSnapshotToFile(i.ToString() + ".tiff"); + saveSnapshotToFile(i.ToString(), wantedWeather); Script.Wait(200); } @@ -627,13 +627,13 @@ public void OnKeyDown(object o, KeyEventArgs k) } } - private void saveSnapshotToFile(String name) + private void saveSnapshotToFile(String name, Weather[] weathers) { List colors = new List(); Game.Pause(true); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); - foreach (var wea in wantedWeather) + foreach (var wea in weathers) { World.TransitionToWeather(wea, 0.0f); Script.Wait(1); @@ -645,7 +645,7 @@ private void saveSnapshotToFile(String name) var fileName = Path.Combine(dataPath, "info-" + name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil); UI.Notify("file saved to: " + fileName); - UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); +// UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); //UI.Notify((connection != null && connection.Connected).ToString()); @@ -708,7 +708,7 @@ private void dumpTest() if (depth != null) { var res = Game.ScreenResolution; - ImageUtils.WriteToTiff(Path.Combine(dataPath, "test.tiff"), res.Width, res.Height, colors, depth, stencil); + ImageUtils.WriteToTiff(Path.Combine(dataPath, "test"), res.Width, res.Height, colors, depth, stencil); UI.Notify(GameplayCamera.FieldOfView.ToString()); } else diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index 4769190..505de0a 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -47,8 +47,8 @@ public static void UploadToArchive(ZipArchive archive, string name, int w, int h public static void WriteToTiff(string name, int width, int height, List colors, byte[] depth, byte[] stencil) { - var t = Tiff.Open(name, "w"); - var pages = colors.Count + 2; + var t = Tiff.Open(name + ".tiff", "w"); + var pages = colors.Count; var page = 0; foreach (var color in colors) { @@ -62,7 +62,7 @@ public static void WriteToTiff(string name, int width, int height, List t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); t.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB); t.SetField(TiffTag.COMPRESSION, Compression.LZW); - t.SetField(TiffTag.JPEGQUALITY, 60); +// t.SetField(TiffTag.JPEGQUALITY, 60); t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); t.SetField(TiffTag.PAGENUMBER, page, pages); @@ -70,9 +70,11 @@ public static void WriteToTiff(string name, int width, int height, List page++; t.WriteDirectory(); } - - t.CreateDirectory(); - //page 2 + + t.Flush(); + t.Close(); + + t = Tiff.Open(name + "-depth.tiff", "w"); t.SetField(TiffTag.IMAGEWIDTH, width); t.SetField(TiffTag.IMAGELENGTH, height); t.SetField(TiffTag.ROWSPERSTRIP, height); @@ -84,11 +86,12 @@ public static void WriteToTiff(string name, int width, int height, List t.SetField(TiffTag.COMPRESSION, Compression.LZW); t.SetField(TiffTag.PREDICTOR, Predictor.FLOATINGPOINT); t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.IEEEFP); - t.SetField(TiffTag.PAGENUMBER, page, pages); t.WriteEncodedStrip(0, depth, depth.Length); - page++; - t.WriteDirectory(); + + t.Flush(); + t.Close(); + t = Tiff.Open(name + "-stencil.tiff", "w"); t.SetField(TiffTag.IMAGEWIDTH, width); t.SetField(TiffTag.IMAGELENGTH, height); t.SetField(TiffTag.ROWSPERSTRIP, height); @@ -100,9 +103,7 @@ public static void WriteToTiff(string name, int width, int height, List t.SetField(TiffTag.COMPRESSION, Compression.LZW); t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); - t.SetField(TiffTag.PAGENUMBER, page, pages); t.WriteEncodedStrip(0, stencil, stencil.Length); - t.WriteDirectory(); t.Flush(); t.Close(); } From de7d10aa028cb5c3cce9cea05b76fd81b0bc7906 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 14 Nov 2017 18:36:26 +0100 Subject: [PATCH 034/158] Async saving data to files. --- managed/GTAVisionExport/VisionExport.cs | 13 ++++++----- managed/GTAVisionUtils/ImageUtils.cs | 8 +++++-- managed/Sandbox/MainClass.cs | 30 ++++++++++++------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 59d0857..b6e4492 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -251,12 +251,12 @@ public void OnTick(object o, EventArgs e) case GameStatus.NoActionNeeded: break; } - UI.Notify("runTask.IsCompleted: " + runTask.IsCompleted.ToString()); - UI.Notify("postgresTask.IsCompleted: " + postgresTask.IsCompleted.ToString()); +// UI.Notify("runTask.IsCompleted: " + runTask.IsCompleted.ToString()); +// UI.Notify("postgresTask.IsCompleted: " + postgresTask.IsCompleted.ToString()); if (!runTask.IsCompleted) return; if (!postgresTask.IsCompleted) return; - UI.Notify("going to save tiff"); +// UI.Notify("going to save tiff"); // List colors = new List(); Game.Pause(true); @@ -315,8 +315,8 @@ public void OnTick(object o, EventArgs e) // ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, // Game.ScreenResolution.Height, colors, depth, stencil); - UI.Notify("going to save snapshot to db"); - UI.Notify("current weather: " + dat.CurrentWeather.ToString()); +// UI.Notify("going to save snapshot to db"); +// UI.Notify("current weather: " + dat.CurrentWeather.ToString()); PostgresExport.SaveSnapshot(dat, run.guid); // outStream.Flush(); // if ((Int64)outStream.Length > (Int64)2048 * (Int64)1024 * (Int64)1024) { @@ -644,7 +644,8 @@ private void saveSnapshotToFile(String name, Weather[] weathers) var res = Game.ScreenResolution; var fileName = Path.Combine(dataPath, "info-" + name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil); - UI.Notify("file saved to: " + fileName); +// UI.Notify("file saved to: " + fileName); + // UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); //UI.Notify((connection != null && connection.Connected).ToString()); diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index 505de0a..31f46d7 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -45,7 +45,12 @@ public static void UploadToArchive(ZipArchive archive, string name, int w, int h } - public static void WriteToTiff(string name, int width, int height, List colors, byte[] depth, byte[] stencil) + public static async void WriteToTiff(string name, int width, int height, List colors, byte[] depth, byte[] stencil) + { + await Task.Run(() => WriteToTiffImpl(name, width, height, colors, depth, stencil)); + } + + public static void WriteToTiffImpl(string name, int width, int height, List colors, byte[] depth, byte[] stencil) { var t = Tiff.Open(name + ".tiff", "w"); var pages = colors.Count; @@ -62,7 +67,6 @@ public static void WriteToTiff(string name, int width, int height, List t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); t.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB); t.SetField(TiffTag.COMPRESSION, Compression.LZW); -// t.SetField(TiffTag.JPEGQUALITY, 60); t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); t.SetField(TiffTag.PAGENUMBER, page, pages); diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index e3df8d3..8645474 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -196,25 +196,25 @@ public static void InsertEnum() public static int InsertInstanceData(NpgsqlConnection conn) { - var instanceinfo = new InstanceData(); +// var instanceinfo = new InstanceData(); using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; - cmd.Parameters.AddWithValue("@host", System.Environment.MachineName); - cmd.Parameters.AddWithValue("@iid", DBNull.Value); - cmd.Parameters.AddWithValue("@typ", instanceinfo.type); - cmd.Parameters.AddWithValue("@pubhost", DBNull.Value); - cmd.Parameters.AddWithValue("@amiid", DBNull.Value); - - if (instanceinfo.type != "LOCALHOST") - { - cmd.Parameters.AddWithValue("@host", instanceinfo.hostname); - cmd.Parameters.AddWithValue("@iid", instanceinfo.instanceid); - cmd.Parameters.AddWithValue("@typ", instanceinfo.type); - cmd.Parameters.AddWithValue("@pubhost", instanceinfo.publichostname); - cmd.Parameters.AddWithValue("@amiid", instanceinfo.amiid); - } +// cmd.Parameters.AddWithValue("@host", System.Environment.MachineName); +// cmd.Parameters.AddWithValue("@iid", DBNull.Value); +// cmd.Parameters.AddWithValue("@typ", instanceinfo.type); +// cmd.Parameters.AddWithValue("@pubhost", DBNull.Value); +// cmd.Parameters.AddWithValue("@amiid", DBNull.Value); +// +// if (instanceinfo.type != "LOCALHOST") +// { +// cmd.Parameters.AddWithValue("@host", instanceinfo.hostname); +// cmd.Parameters.AddWithValue("@iid", instanceinfo.instanceid); +// cmd.Parameters.AddWithValue("@typ", instanceinfo.type); +// cmd.Parameters.AddWithValue("@pubhost", instanceinfo.publichostname); +// cmd.Parameters.AddWithValue("@amiid", instanceinfo.amiid); +// } cmd.CommandText = "SELECT instance_id FROM instances WHERE hostname=@host AND instancetype=@typ AND instanceid=@iid AND amiid=@amiid AND publichostname=@pubhost"; var id = cmd.ExecuteScalar(); From 9426f151d23f37fdfbdbb1d2b6b1aaa49b297c54 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 15 Nov 2017 11:04:07 +0100 Subject: [PATCH 035/158] Commented 2D bounding box visualization --- managed/GTAVisionExport/VisionExport.cs | 3 +-- managed/GTAVisionUtils/GTADataStructures.cs | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index b6e4492..24d2cfe 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -256,7 +256,7 @@ public void OnTick(object o, EventArgs e) if (!runTask.IsCompleted) return; if (!postgresTask.IsCompleted) return; -// UI.Notify("going to save tiff"); +// UI.Notify("going to save images and save to postgres"); // List colors = new List(); Game.Pause(true); @@ -309,7 +309,6 @@ public void OnTick(object o, EventArgs e) PostgresExport.SaveSnapshot(dat, run.guid); } */ - UI.Notify("going to save images and save to postgres"); // ImageUtils.WaitForProcessing(); saveSnapshotToFile(dat.ImageName, wantedWeather); // ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 4a0a2e8..69b96a1 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -252,15 +252,17 @@ public static GTABoundingBox2 ComputeBoundingBox(Entity e, Vector3 offset, float rv.Max.X = Math.Max(rv.Max.X, s.X); rv.Max.Y = Math.Max(rv.Max.Y, s.Y); } - /* - int x = (int)(rv.Min.X * 1920); - int y = (int)(rv.Min.Y * 1080); - int x2 = (int)(rv.Max.X); - int y2 = (int)(rv.Max.Y * 1080); - float w = rv.Max.X - rv.Min.X; - float h = rv.Max.Y - rv.Min.Y; - HashFunctions.DrawRect(rv.Min.X + w/2, rv.Min.Y + h/2, rv.Max.X - rv.Min.X, rv.Max.Y - rv.Min.Y, 255, 255, 255, 100);*/ - //new UIRectangle(new Point((int)(rv.Min.X * 1920), (int)(rv.Min.Y * 1080)), rv.) + +// int width = 1280; +// int height = 960; +// int x = (int)(rv.Min.X * width); +// int y = (int)(rv.Min.Y * height); +// int x2 = (int)(rv.Max.X * width); +// int y2 = (int)(rv.Max.Y * height); +// float w = rv.Max.X - rv.Min.X; +// float h = rv.Max.Y - rv.Min.Y; +// HashFunctions.DrawRect(rv.Min.X + w/2, rv.Min.Y + h/2, rv.Max.X - rv.Min.X, rv.Max.Y - rv.Min.Y, 255, 255, 255, 100); +// new UIRectangle(new Point((int)(rv.Min.X * 1920), (int)(rv.Min.Y * 1080)), rv.) return rv; } public static bool CheckVisible(Entity e) { From 3bf97dfeb7c2821bd27d06657964626ef5d3784c Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 16 Nov 2017 16:34:35 +0100 Subject: [PATCH 036/158] Added setting time. --- managed/GTAVisionExport/VisionExport.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 24d2cfe..bdbe27a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -158,6 +158,18 @@ private void handlePipeInput() .GetMethod("DoKeyboardMessage", BindingFlags.Instance | BindingFlags.Public); m.Invoke(domain, new object[] {Keys.Insert, true, false, false, false}); break; + case "SET_TIME": + num = connection.Receive(inBuffer); + var dataLen = int.Parse(encoding.GetString(inBuffer, 0, num)); + connection.Send(BitConverter.GetBytes(dataLen)); + num = connection.Receive(inBuffer); + var time = encoding.GetString(inBuffer, 0, num); + UI.Notify("set time, obtained: " + time); + var hoursAndMinutes = time.Split(':'); + var hours = int.Parse(hoursAndMinutes[0]); + var minutes = int.Parse(hoursAndMinutes[1]); + GTA.World.CurrentDayTime = new TimeSpan(hours, minutes, 0); + break; // uncomment when resolving, how the hell should I get image by socket correctly // case "GET_SCREEN": // var last = ImageUtils.getLastCapturedFrame(); From 925898934efcd951cc31755714a5e50431c27d6c Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 16 Nov 2017 17:45:23 +0100 Subject: [PATCH 037/158] Migrated to json. --- managed/GTAVisionExport/GTAVisionExport.csproj | 3 +++ managed/GTAVisionExport/VisionExport.cs | 14 +++++++------- managed/GTAVisionExport/packages.config | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index e749b9b..6d45e99 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -78,6 +78,9 @@ False ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + ..\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index bdbe27a..d882a88 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -35,6 +35,7 @@ using System.Configuration; using System.Threading; using IniParser; +using Newtonsoft.Json; namespace GTAVisionExport { @@ -126,7 +127,9 @@ private void handlePipeInput() return; } UI.Notify("str: " + str.ToString()); - switch (str) + dynamic parameters = JsonConvert.DeserializeObject(str); + string commandName = parameters.name; + switch (commandName) { case "START_SESSION": postgresTask?.Wait(); @@ -159,16 +162,13 @@ private void handlePipeInput() m.Invoke(domain, new object[] {Keys.Insert, true, false, false, false}); break; case "SET_TIME": - num = connection.Receive(inBuffer); - var dataLen = int.Parse(encoding.GetString(inBuffer, 0, num)); - connection.Send(BitConverter.GetBytes(dataLen)); - num = connection.Receive(inBuffer); - var time = encoding.GetString(inBuffer, 0, num); - UI.Notify("set time, obtained: " + time); + var time = parameters.time; + UI.Notify("starting set time, obtained: " + time); var hoursAndMinutes = time.Split(':'); var hours = int.Parse(hoursAndMinutes[0]); var minutes = int.Parse(hoursAndMinutes[1]); GTA.World.CurrentDayTime = new TimeSpan(hours, minutes, 0); + UI.Notify("Time Set"); break; // uncomment when resolving, how the hell should I get image by socket correctly // case "GET_SCREEN": diff --git a/managed/GTAVisionExport/packages.config b/managed/GTAVisionExport/packages.config index 1dea3ec..cc24a5e 100644 --- a/managed/GTAVisionExport/packages.config +++ b/managed/GTAVisionExport/packages.config @@ -9,6 +9,7 @@ + From a4f4a32b281755f28441840c67792f4d6dbe8165 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 19 Nov 2017 23:37:39 +0100 Subject: [PATCH 038/158] Fixed json reading values. --- managed/GTAVisionExport/VisionExport.cs | 4 ++-- managed/Sandbox/MainClass.cs | 16 +++++++++++++--- managed/Sandbox/Sandbox.csproj | 5 +++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index d882a88..b8ee866 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -128,7 +128,7 @@ private void handlePipeInput() } UI.Notify("str: " + str.ToString()); dynamic parameters = JsonConvert.DeserializeObject(str); - string commandName = parameters.name; + string commandName = parameters.name.Value(); switch (commandName) { case "START_SESSION": @@ -162,7 +162,7 @@ private void handlePipeInput() m.Invoke(domain, new object[] {Keys.Insert, true, false, false, false}); break; case "SET_TIME": - var time = parameters.time; + var time = parameters.time.Value(); UI.Notify("starting set time, obtained: " + time); var hoursAndMinutes = time.Split(':'); var hours = int.Parse(hoursAndMinutes[0]); diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 8645474..ec88dad 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -5,6 +5,7 @@ using System.Management; using GTAVisionUtils; using IniParser; +using Newtonsoft.Json; using Npgsql; using Npgsql.NameTranslation; using NpgsqlTypes; @@ -255,9 +256,9 @@ public static Guid InsertSystemData(NpgsqlConnection conn) public static void Main(string[] args) { - var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; - var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; - Console.WriteLine(fileName); +// var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; +// var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; +// Console.WriteLine(fileName); // var systemInfo = new WMIInformation(); // var conn = OpenConnection(); // conn = null; @@ -266,6 +267,15 @@ public static void Main(string[] args) // InitSQLTypes(); // InsertEnum(); + var str = "{\"name\": \"SET_TIME\", \"time\": \"05:20\"}"; + dynamic parameters = JsonConvert.DeserializeObject(str); + var time = parameters.time.Value(); + var hoursAndMinutes = time.Split(':'); + var hours = int.Parse(hoursAndMinutes[0]); + var minutes = int.Parse(hoursAndMinutes[1]); + var timeSpan = new TimeSpan(hours, minutes, 0); + + } } } \ No newline at end of file diff --git a/managed/Sandbox/Sandbox.csproj b/managed/Sandbox/Sandbox.csproj index d96fffa..bc06b73 100644 --- a/managed/Sandbox/Sandbox.csproj +++ b/managed/Sandbox/Sandbox.csproj @@ -42,10 +42,15 @@ ..\packages\ini-parser.2.4.0\lib\net20\INIFileParser.dll + + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\Npgsql.dll + From 2fbec2aac4aba1efba26492724bf80ea3c663490 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 19 Nov 2017 23:44:38 +0100 Subject: [PATCH 039/158] Fixed json types. --- managed/GTAVisionExport/VisionExport.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index b8ee866..98a1e44 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -128,7 +128,7 @@ private void handlePipeInput() } UI.Notify("str: " + str.ToString()); dynamic parameters = JsonConvert.DeserializeObject(str); - string commandName = parameters.name.Value(); + string commandName = parameters.name; switch (commandName) { case "START_SESSION": @@ -162,7 +162,7 @@ private void handlePipeInput() m.Invoke(domain, new object[] {Keys.Insert, true, false, false, false}); break; case "SET_TIME": - var time = parameters.time.Value(); + string time = parameters.time; UI.Notify("starting set time, obtained: " + time); var hoursAndMinutes = time.Split(':'); var hours = int.Parse(hoursAndMinutes[0]); From e194f5c118aec756630e3f9e841caec6fdfd1ddc Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 20 Nov 2017 23:40:44 +0100 Subject: [PATCH 040/158] Fixed null username. Added some dependencies. Added some info to readme. --- .../GTAVisionExport/GTAVisionExport.csproj | 12 +++ managed/GTAVisionExport/VisionExport.cs | 14 +-- managed/GTAVisionUtils/GTAVisionUtils.csproj | 12 +++ managed/GTAVisionUtils/WMIInformation.cs | 4 + managed/README.md | 7 +- managed/Sandbox/MainClass.cs | 96 ++++++++++--------- managed/Sandbox/Sandbox.csproj | 19 +++- 7 files changed, 107 insertions(+), 57 deletions(-) diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index 6d45e99..c534a41 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -78,6 +78,9 @@ False ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + + D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll @@ -89,6 +92,9 @@ ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll + + D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll + @@ -115,9 +121,15 @@ ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + + D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + + D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + ..\packages\YamlDotNet.4.1.0\lib\net35\YamlDotNet.dll diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 98a1e44..6d34425 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -48,7 +48,7 @@ class VisionExport : Script #endif //private readonly string dataPath = // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Data"); - private readonly string dataPath = @"D:\projekty\GTA-V-extractors\output\"; + private readonly string dataPath = @"D:\GTAV_extraction_output\"; private readonly Weather[] wantedWeather = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; private Player player; private string outputPath; @@ -68,7 +68,7 @@ class VisionExport : Script private StereoCamera cams; public VisionExport() { - System.IO.File.WriteAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport constructor called.\n"); + System.IO.File.WriteAllText(@"D:\GTAV_extraction_output\log.txt", "VisionExport constructor called.\n"); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); PostgresExport.InitSQLTypes(); player = Game.Player; @@ -97,7 +97,7 @@ public VisionExport() private void handlePipeInput() { - System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport handlePipeInput called.\n"); + System.IO.File.AppendAllText(@"D:\GTAV_extraction_output\log.txt", "VisionExport handlePipeInput called.\n"); UI.Notify("handlePipeInput called"); UI.Notify("server connected:" + server.Connected.ToString()); UI.Notify(connection == null ? "connection is null" : "connection:" + connection.ToString()); @@ -185,7 +185,7 @@ private void handlePipeInput() // private void UploadFile() // { -// System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); +// System.IO.File.AppendAllText(@"D:\GTAV_extraction_output\log.txt", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); // UI.Notify("UploadFile called"); // //// archive.Dispose(); @@ -526,7 +526,7 @@ public void TraverseWeather() public void OnKeyDown(object o, KeyEventArgs k) { - System.IO.File.AppendAllText(@"D:\projekty\GTA-V-extractors\output\log.txt", "VisionExport OnKeyDown called.\n"); + System.IO.File.AppendAllText(@"D:\GTAV_extraction_output\log.txt", "VisionExport OnKeyDown called.\n"); if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); @@ -575,7 +575,7 @@ public void OnKeyDown(object o, KeyEventArgs k) */ var data = GTAData.DumpData(Game.GameTime + ".tiff", new List(wantedWeather)); - string path = @"D:\projekty\GTA-V-extractors\output\trymatrix.txt"; + string path = @"D:\GTAV_extraction_output\trymatrix.txt"; // This text is added only once to the file. if (!File.Exists(path)) { @@ -663,7 +663,7 @@ private void saveSnapshotToFile(String name, Weather[] weathers) // var data = GTAData.DumpData(Game.GameTime + ".dat", new List(wantedWeather)); -// string path = @"D:\projekty\GTA-V-extractors\output\info.txt"; +// string path = @"D:\GTAV_extraction_output\info.txt"; // // This text is added only once to the file. // if (!File.Exists(path)) // { diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index db7920b..36f79cb 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -67,6 +67,9 @@ ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + + D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + ..\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll @@ -81,6 +84,9 @@ ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll + + D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll + ..\packages\SharpDX.3.1.1\lib\net45\SharpDX.dll @@ -112,9 +118,15 @@ ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + + D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + + D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + diff --git a/managed/GTAVisionUtils/WMIInformation.cs b/managed/GTAVisionUtils/WMIInformation.cs index 32fd636..166810a 100644 --- a/managed/GTAVisionUtils/WMIInformation.cs +++ b/managed/GTAVisionUtils/WMIInformation.cs @@ -69,6 +69,10 @@ public WMIInformation() var result = new ManagementObjectSearcher(scope, genQuery).Get().Cast(); dnshostname = result.First().GetPropertyValue("DNSHostName") as string; username = result.First().GetPropertyValue("UserName") as string; + if (username == null) + { + username = Environment.UserName; + } systemtype = result.First().GetPropertyValue("SystemType") as string; totalmem = (UInt64) result.First().GetPropertyValue("TotalPhysicalMemory"); var prodQuery = new ObjectQuery("SELECT * FROM Win32_ComputerSystemProduct"); diff --git a/managed/README.md b/managed/README.md index ccaf2bd..05ff75e 100644 --- a/managed/README.md +++ b/managed/README.md @@ -299,7 +299,12 @@ If less than 10 scripts loaded, you have problem. ### Dependencies setup Make sure your PostgreSQL database is up. -If you don't want to install one, you can use the one in docker. +If you don't want to install one, you can use the one in docker. + +Before starting it, if you want the data persistent (hint: you want the data persitent), +create external volume. This is the only way to create volume in docker which is ok for postgresql. +Create it by `docker volume create gtav-postgresql`. + Start the database in docker by `docker-compose up`. Default credentials are: - username: `postgres` diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index ec88dad..825da21 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.PerformanceData; using System.IO; using System.Linq; using System.Management; @@ -52,42 +53,42 @@ public WMIGraphicsInformation(ManagementBaseObject from) } } - public class WMIInformation - { - public Guid system_uuid; - public string vendor; - public string dnshostname; - public string username; - public string systemtype; - public UInt64 totalmem; - public List gfxCards; - /// - /// gets wmi info for the current computer - /// - public WMIInformation() - { - var scope = new ManagementScope("ROOT\\CIMV2"); - var genQuery = new ObjectQuery("SELECT * FROM Win32_ComputerSystem"); - var result = new ManagementObjectSearcher(scope, genQuery).Get().Cast(); - dnshostname = result.First().GetPropertyValue("DNSHostName") as string; - username = result.First().GetPropertyValue("UserName") as string; - systemtype = result.First().GetPropertyValue("SystemType") as string; - totalmem = (UInt64) result.First().GetPropertyValue("TotalPhysicalMemory"); - var prodQuery = new ObjectQuery("SELECT * FROM Win32_ComputerSystemProduct"); - result = new ManagementObjectSearcher(scope, prodQuery).Get().Cast(); - system_uuid = Guid.Parse( result.First().GetPropertyValue("UUID") as string); - vendor = result.First().GetPropertyValue("Vendor") as string; - - var videoQuery = new ObjectQuery("SELECT * FROM Win32_VideoController"); - result = new ManagementObjectSearcher(scope, videoQuery).Get().Cast(); - gfxCards = new List(); - foreach (var obj in result) - { - gfxCards.Add(new WMIGraphicsInformation(obj)); - } - - } - } +// public class WMIInformation +// { +// public Guid system_uuid; +// public string vendor; +// public string dnshostname; +// public string username; +// public string systemtype; +// public UInt64 totalmem; +// public List gfxCards; +// /// +// /// gets wmi info for the current computer +// /// +// public WMIInformation() +// { +// var scope = new ManagementScope("ROOT\\CIMV2"); +// var genQuery = new ObjectQuery("SELECT * FROM Win32_ComputerSystem"); +// var result = new ManagementObjectSearcher(scope, genQuery).Get().Cast(); +// dnshostname = result.First().GetPropertyValue("DNSHostName") as string; +// username = result.First().GetPropertyValue("UserName") as string; +// systemtype = result.First().GetPropertyValue("SystemType") as string; +// totalmem = (UInt64) result.First().GetPropertyValue("TotalPhysicalMemory"); +// var prodQuery = new ObjectQuery("SELECT * FROM Win32_ComputerSystemProduct"); +// result = new ManagementObjectSearcher(scope, prodQuery).Get().Cast(); +// system_uuid = Guid.Parse( result.First().GetPropertyValue("UUID") as string); +// vendor = result.First().GetPropertyValue("Vendor") as string; +// +// var videoQuery = new ObjectQuery("SELECT * FROM Win32_VideoController"); +// result = new ManagementObjectSearcher(scope, videoQuery).Get().Cast(); +// gfxCards = new List(); +// foreach (var obj in result) +// { +// gfxCards.Add(new WMIGraphicsInformation(obj)); +// } +// +// } +// } public enum DetectionType { @@ -157,7 +158,7 @@ public static void InitSQLTypes() public static NpgsqlConnection OpenConnection() { var parser = new FileIniDataParser(); - var location = @"D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts"; + var location = @"D:\Program Files\Rockstar Games\Grand Theft Auto V\scripts"; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); @@ -259,22 +260,25 @@ public static void Main(string[] args) // var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; // var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; // Console.WriteLine(fileName); -// var systemInfo = new WMIInformation(); -// var conn = OpenConnection(); + var systemInfo = new WMIInformation(); + Console.WriteLine(systemInfo.dnshostname); + Console.WriteLine(systemInfo.username); + var conn = OpenConnection(); // conn = null; // int instanceid = InsertInstanceData(conn); // InsertSystemData(conn); // InitSQLTypes(); // InsertEnum(); - var str = "{\"name\": \"SET_TIME\", \"time\": \"05:20\"}"; - dynamic parameters = JsonConvert.DeserializeObject(str); - var time = parameters.time.Value(); - var hoursAndMinutes = time.Split(':'); - var hours = int.Parse(hoursAndMinutes[0]); - var minutes = int.Parse(hoursAndMinutes[1]); - var timeSpan = new TimeSpan(hours, minutes, 0); +// var str = "{\"name\": \"SET_TIME\", \"time\": \"05:20\"}"; +// dynamic parameters = JsonConvert.DeserializeObject(str); +// var time = parameters.time.Value(); +// var hoursAndMinutes = time.Split(':'); +// var hours = int.Parse(hoursAndMinutes[0]); +// var minutes = int.Parse(hoursAndMinutes[1]); +// var timeSpan = new TimeSpan(hours, minutes, 0); + Console.WriteLine("the end"); } } diff --git a/managed/Sandbox/Sandbox.csproj b/managed/Sandbox/Sandbox.csproj index bc06b73..514d3c5 100644 --- a/managed/Sandbox/Sandbox.csproj +++ b/managed/Sandbox/Sandbox.csproj @@ -36,29 +36,42 @@ - - ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\GTAVisionUtils.dll - ..\packages\ini-parser.2.4.0\lib\net20\INIFileParser.dll + + ..\packages\Microsoft.Extensions.Logging.1.1.0\lib\netstandard1.1\Microsoft.Extensions.Logging.dll + + + ..\packages\Microsoft.Extensions.Logging.Abstractions.1.1.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\Npgsql.dll + + ..\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll + {D3C3EAE5-CFDD-454A-BD26-9D6FD5D6C239} GTAVisionUtils + + {d3c3eae5-cfdd-454a-bd26-9d6fd5d6c239} + GTAVisionUtils + From 940a241eba4114ad9e3fc8ab6e72b942559709c6 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 22 Nov 2017 16:07:09 +0100 Subject: [PATCH 041/158] dded original postprocessing script. --- native/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/native/README.md b/native/README.md index 4bc20eb..9524453 100644 --- a/native/README.md +++ b/native/README.md @@ -47,6 +47,11 @@ HTH FAQ --- +Can not configure in CMake, `gdi32.lib` is missing: +This is probably due to incorrect Visual Studio SDK, can be solved by installing Windows 10 SDK (10.0.15063.0) for Desktop C++ x86 and x64 in the VS Installer. + +Source: https://stackoverflow.com/questions/33599723/fatal-error-lnk1104-cannot-open-file-gdi32-lib + The game crashes after pressing 'L': If you are using steam, be sure to disable the steam overlay for this game. From 711b969650c2b008610016fb6f7d2aaef4aaa944 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 22 Nov 2017 20:27:55 +0100 Subject: [PATCH 042/158] Reading output from ini file. Added sample ini file. --- managed/GTAVision.ini | 5 +++++ managed/GTAVisionExport/VisionExport.cs | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 managed/GTAVision.ini diff --git a/managed/GTAVision.ini b/managed/GTAVision.ini new file mode 100644 index 0000000..9fdee4b --- /dev/null +++ b/managed/GTAVision.ini @@ -0,0 +1,5 @@ +[Database] +ConnectionString=Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=postgres; +[Snapshots] +OutputDir=D:\GTAV_extraction_output\ +LogFile=D:\GTAV_extraction_output\log.txt diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 6d34425..a587cde 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -49,6 +49,7 @@ class VisionExport : Script //private readonly string dataPath = // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Data"); private readonly string dataPath = @"D:\GTAV_extraction_output\"; + private readonly string logFilePath = @"D:\GTAV_extraction_output\log.txt"; private readonly Weather[] wantedWeather = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; private Player player; private string outputPath; @@ -68,7 +69,16 @@ class VisionExport : Script private StereoCamera cams; public VisionExport() { - System.IO.File.WriteAllText(@"D:\GTAV_extraction_output\log.txt", "VisionExport constructor called.\n"); + // loading ini file + var parser = new FileIniDataParser(); + var location = AppDomain.CurrentDomain.BaseDirectory; + var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); + + //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); + dataPath = data["Snapshots"]["OutputDir"]; + logFilePath = data["Snapshots"]["LogFile"]; + + System.IO.File.WriteAllText(logFilePath, "VisionExport constructor called.\n"); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); PostgresExport.InitSQLTypes(); player = Game.Player; @@ -76,9 +86,6 @@ public VisionExport() server.Bind(new IPEndPoint(IPAddress.Loopback, 5555)); server.Listen(5); //server = new UdpClient(5555); - var parser = new FileIniDataParser(); - var location = AppDomain.CurrentDomain.BaseDirectory; - var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); //outputPath = @"D:\Datasets\GTA\"; //outputPath = Path.Combine(outputPath, "testData.yaml"); //outStream = File.CreateText(outputPath); @@ -97,7 +104,7 @@ public VisionExport() private void handlePipeInput() { - System.IO.File.AppendAllText(@"D:\GTAV_extraction_output\log.txt", "VisionExport handlePipeInput called.\n"); + System.IO.File.AppendAllText(logFilePath, "VisionExport handlePipeInput called.\n"); UI.Notify("handlePipeInput called"); UI.Notify("server connected:" + server.Connected.ToString()); UI.Notify(connection == null ? "connection is null" : "connection:" + connection.ToString()); @@ -185,7 +192,7 @@ private void handlePipeInput() // private void UploadFile() // { -// System.IO.File.AppendAllText(@"D:\GTAV_extraction_output\log.txt", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); +// System.IO.File.AppendAllText(logFilePath, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); // UI.Notify("UploadFile called"); // //// archive.Dispose(); @@ -526,7 +533,7 @@ public void TraverseWeather() public void OnKeyDown(object o, KeyEventArgs k) { - System.IO.File.AppendAllText(@"D:\GTAV_extraction_output\log.txt", "VisionExport OnKeyDown called.\n"); + System.IO.File.AppendAllText(logFilePath, "VisionExport OnKeyDown called.\n"); if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); From cec909566386edb8b1f13b38f3878140d22faf7f Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 23 Nov 2017 01:49:15 +0100 Subject: [PATCH 043/158] Added key for turning notifications on and off. --- managed/GTAVisionExport/VisionExport.cs | 42 +++++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index a587cde..78e4c84 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -66,6 +66,7 @@ class VisionExport : Script private int curSessionId = -1; private speedAndTime lowSpeedTime = new speedAndTime(); private bool IsGamePaused = false; + private bool notificationsAllowed = true; private StereoCamera cams; public VisionExport() { @@ -459,6 +460,15 @@ public void StopRun() Game.Player.LastVehicle.Alpha = int.MaxValue; } + public void UINotify(string message) + { + //just wrapper for UI.Notify, but lets us disable showing notifications ar all + if (notificationsAllowed) + { + UI.Notify(message); + } + } + public void EnterVehicle() { /* @@ -466,14 +476,14 @@ public void EnterVehicle() player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); */ Model mod = new Model(GTA.Native.VehicleHash.Asea); - if (mod == null) {UI.Notify("mod is null");} - if (player == null) {UI.Notify("player is null");} - if (player.Character == null) {UI.Notify("player.Character is null");} - UI.Notify("player position: " + player.Character.Position.ToString()); + if (mod == null) {UINotify("mod is null");} + if (player == null) {UINotify("player is null");} + if (player.Character == null) {UINotify("player.Character is null");} + UINotify("player position: " + player.Character.Position.ToString()); var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); if (vehicle == null) { - UI.Notify("vehicle is null. Something is fucked up"); + UINotify("vehicle is null. Something is fucked up"); } else { @@ -540,24 +550,36 @@ public void OnKeyDown(object o, KeyEventArgs k) postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); - UI.Notify("GTA Vision Enabled"); + UINotify("GTA Vision Enabled"); } if (k.KeyCode == Keys.PageDown) { StopRun(); StopSession(); - UI.Notify("GTA Vision Disabled"); + UINotify("GTA Vision Disabled"); } if (k.KeyCode == Keys.H) // temp modification { EnterVehicle(); - UI.Notify("Trying to enter vehicle"); + UINotify("Trying to enter vehicle"); ToggleNavigation(); } if (k.KeyCode == Keys.Y) // temp modification { ReloadGame(); } + if (k.KeyCode == Keys.X) // temp modification + { + notificationsAllowed = !notificationsAllowed; + if (notificationsAllowed) + { + UI.Notify("Notifications Enabled"); + } + else + { + UI.Notify("Notifications Disabled"); + } + } if (k.KeyCode == Keys.U) // temp modification { var settings = ScriptSettings.Load("GTAVisionExport.xml"); @@ -565,8 +587,8 @@ public void OnKeyDown(object o, KeyEventArgs k) //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); var str = settings.GetValue("", "ConnectionString"); - UI.Notify("BaseDirectory: " + loc); - UI.Notify("ConnectionString: " + str); + UINotify("BaseDirectory: " + loc); + UINotify("ConnectionString: " + str); } if (k.KeyCode == Keys.G) // temp modification From 6da3a467bbdecfcdc9f1701a458881cc7970a319 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 23 Nov 2017 01:52:49 +0100 Subject: [PATCH 044/158] All UI notify calls are wrapped now. --- managed/GTAVisionExport/VisionExport.cs | 68 ++++++++++++------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 78e4c84..7c02ccd 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -75,7 +75,7 @@ public VisionExport() var location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); - //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); + //UINotify(ConfigurationManager.AppSettings["database_connection"]); dataPath = data["Snapshots"]["OutputDir"]; logFilePath = data["Snapshots"]["LogFile"]; @@ -106,9 +106,9 @@ public VisionExport() private void handlePipeInput() { System.IO.File.AppendAllText(logFilePath, "VisionExport handlePipeInput called.\n"); - UI.Notify("handlePipeInput called"); - UI.Notify("server connected:" + server.Connected.ToString()); - UI.Notify(connection == null ? "connection is null" : "connection:" + connection.ToString()); + UINotify("handlePipeInput called"); + UINotify("server connected:" + server.Connected.ToString()); + UINotify(connection == null ? "connection is null" : "connection:" + connection.ToString()); if (connection == null) return; byte[] inBuffer = new byte[1024]; @@ -134,7 +134,7 @@ private void handlePipeInput() connection = null; return; } - UI.Notify("str: " + str.ToString()); + UINotify("str: " + str.ToString()); dynamic parameters = JsonConvert.DeserializeObject(str); string commandName = parameters.name; switch (commandName) @@ -153,7 +153,7 @@ private void handlePipeInput() ToggleNavigation(); break; case "ENTER_VEHICLE": - UI.Notify("Trying to enter vehicle"); + UINotify("Trying to enter vehicle"); EnterVehicle(); break; case "AUTOSTART": @@ -171,18 +171,18 @@ private void handlePipeInput() break; case "SET_TIME": string time = parameters.time; - UI.Notify("starting set time, obtained: " + time); + UINotify("starting set time, obtained: " + time); var hoursAndMinutes = time.Split(':'); var hours = int.Parse(hoursAndMinutes[0]); var minutes = int.Parse(hoursAndMinutes[1]); GTA.World.CurrentDayTime = new TimeSpan(hours, minutes, 0); - UI.Notify("Time Set"); + UINotify("Time Set"); break; // uncomment when resolving, how the hell should I get image by socket correctly // case "GET_SCREEN": // var last = ImageUtils.getLastCapturedFrame(); // Int64 size = last.Length; -// UI.Notify("last size: " + size.ToString()); +// UINotify("last size: " + size.ToString()); // size = IPAddress.HostToNetworkOrder(size); // connection.Send(BitConverter.GetBytes(size)); // connection.Send(last); @@ -194,7 +194,7 @@ private void handlePipeInput() // private void UploadFile() // { // System.IO.File.AppendAllText(logFilePath, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); -// UI.Notify("UploadFile called"); +// UINotify("UploadFile called"); // //// archive.Dispose(); // var oldOutput = outputPath; @@ -235,7 +235,7 @@ public void OnTick(object o, EventArgs e) if (server.Poll(10, SelectMode.SelectRead) && connection == null) { connection = server.Accept(); - UI.Notify("CONNECTED"); + UINotify("CONNECTED"); connection.Blocking = false; } handlePipeInput(); @@ -252,7 +252,7 @@ public void OnTick(object o, EventArgs e) runTask = StartRun(); //StopSession(); //Autostart(); - UI.Notify("need reload game"); + UINotify("need reload game"); Script.Wait(100); ReloadGame(); break; @@ -271,12 +271,12 @@ public void OnTick(object o, EventArgs e) case GameStatus.NoActionNeeded: break; } -// UI.Notify("runTask.IsCompleted: " + runTask.IsCompleted.ToString()); -// UI.Notify("postgresTask.IsCompleted: " + postgresTask.IsCompleted.ToString()); +// UINotify("runTask.IsCompleted: " + runTask.IsCompleted.ToString()); +// UINotify("postgresTask.IsCompleted: " + postgresTask.IsCompleted.ToString()); if (!runTask.IsCompleted) return; if (!postgresTask.IsCompleted) return; -// UI.Notify("going to save images and save to postgres"); +// UINotify("going to save images and save to postgres"); // List colors = new List(); Game.Pause(true); @@ -305,11 +305,11 @@ public void OnTick(object o, EventArgs e) // var colorframe = VisionNative.GetLastColorTime(); // var depthframe = VisionNative.GetLastConstantTime(); // var constantframe = VisionNative.GetLastConstantTime(); - //UI.Notify("DIFF: " + (colorframe - depthframe) + " FRAMETIME: " + (1 / Game.FPS) * 1000); -// UI.Notify("colors length: " + colors[0].Length.ToString()); + //UINotify("DIFF: " + (colorframe - depthframe) + " FRAMETIME: " + (1 / Game.FPS) * 1000); +// UINotify("colors length: " + colors[0].Length.ToString()); // if (depth == null || stencil == null) // { -// UI.Notify("No DEPTH"); +// UINotify("No DEPTH"); // return; // } @@ -334,8 +334,8 @@ public void OnTick(object o, EventArgs e) // ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, // Game.ScreenResolution.Height, colors, depth, stencil); -// UI.Notify("going to save snapshot to db"); -// UI.Notify("current weather: " + dat.CurrentWeather.ToString()); +// UINotify("going to save snapshot to db"); +// UINotify("current weather: " + dat.CurrentWeather.ToString()); PostgresExport.SaveSnapshot(dat, run.guid); // outStream.Flush(); // if ((Int64)outStream.Length > (Int64)2048 * (Int64)1024 * (Int64)1024) { @@ -354,7 +354,7 @@ public GameStatus checkStatus() if (player.IsInVehicle()) { Vehicle vehicle = player.CurrentVehicle; - //UI.Notify("T:" + Game.GameTime.ToString() + " S: " + vehicle.Speed.ToString()); + //UINotify("T:" + Game.GameTime.ToString() + " S: " + vehicle.Speed.ToString()); if (vehicle.Speed < 1.0f) //speed is in mph { if (lowSpeedTime.checkTrafficJam(Game.GameTime, vehicle.Speed)) @@ -376,7 +376,7 @@ public GameStatus checkStatus() public Bitmap CaptureScreen() { - UI.Notify("CaptureScreen called"); + UINotify("CaptureScreen called"); var cap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); var gfx = Graphics.FromImage(cap); //var dat = GTAData.DumpData(Game.GameTime + ".jpg"); @@ -514,7 +514,7 @@ public void ReloadGame() */ // or use CLEAR_AREA_OF_VEHICLES Ped player = Game.Player.Character; - //UI.Notify("x = " + player.Position.X + "y = " + player.Position.Y + "z = " + player.Position.Z); + //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 Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, player.Position.Z, 1000f, false, false, false, false); @@ -585,7 +585,7 @@ public void OnKeyDown(object o, KeyEventArgs k) var settings = ScriptSettings.Load("GTAVisionExport.xml"); var loc = AppDomain.CurrentDomain.BaseDirectory; - //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); + //UINotify(ConfigurationManager.AppSettings["database_connection"]); var str = settings.GetValue("", "ConnectionString"); UINotify("BaseDirectory: " + loc); UINotify("ConnectionString: " + str); @@ -638,14 +638,14 @@ public void OnKeyDown(object o, KeyEventArgs k) /* set it between 0 = stop, 1 = heavy rain. set it too high will lead to sloppy ground */ Function.Call(GTA.Native.Hash._SET_RAIN_FX_INTENSITY, 0.5f); var test = Function.Call(GTA.Native.Hash.GET_RAIN_LEVEL); - UI.Notify("" + test); + UINotify("" + test); World.CurrentDayTime = new TimeSpan(12, 0, 0); //Script.Wait(5000); } if (k.KeyCode == Keys.N) { - UI.Notify("N pressed, going to print stats to file or what?"); + UINotify("N pressed, going to print stats to file or what?"); //var color = VisionNatGetColorBuffer(); @@ -662,8 +662,8 @@ public void OnKeyDown(object o, KeyEventArgs k) if (k.KeyCode == Keys.I) { var info = new GTAVisionUtils.InstanceData(); - UI.Notify(info.type); - UI.Notify(info.publichostname); + UINotify(info.type); + UINotify(info.publichostname); } } @@ -684,10 +684,10 @@ private void saveSnapshotToFile(String name, Weather[] weathers) var res = Game.ScreenResolution; var fileName = Path.Combine(dataPath, "info-" + name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil); -// UI.Notify("file saved to: " + fileName); +// UINotify("file saved to: " + fileName); -// UI.Notify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); - //UI.Notify((connection != null && connection.Connected).ToString()); +// UINotify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); + //UINotify((connection != null && connection.Connected).ToString()); // var data = GTAData.DumpData(Game.GameTime + ".dat", new List(wantedWeather)); @@ -750,13 +750,13 @@ private void dumpTest() { var res = Game.ScreenResolution; ImageUtils.WriteToTiff(Path.Combine(dataPath, "test"), res.Width, res.Height, colors, depth, stencil); - UI.Notify(GameplayCamera.FieldOfView.ToString()); + UINotify(GameplayCamera.FieldOfView.ToString()); } else { - UI.Notify("No Depth Data quite yet"); + UINotify("No Depth Data quite yet"); } - UI.Notify((connection != null && connection.Connected).ToString()); + UINotify((connection != null && connection.Connected).ToString()); } } } From 26d3f3c19af21d640d4a0af7b4fee8e2e0533525 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 23 Nov 2017 16:32:12 +0100 Subject: [PATCH 045/158] Added comment. --- managed/GTAVisionExport/VisionExport.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 6d34425..230307a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -478,6 +478,8 @@ public void EnterVehicle() public void ToggleNavigation() { + //todo: probably here try to set camera, maybe by SET_FOLLOW_VEHICLE_CAM_VIEW_MODE(int viewMode), or by SET_FOLLOW_VEHICLE_CAM_ZOOM_LEVEL(int zoomLevel) + // or just something with the GTA.GameplayCamera //YOLO MethodInfo inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); From 12abd0c36bf686b36b9cde479b0fc899f7ec08d6 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 24 Nov 2017 00:13:17 +0100 Subject: [PATCH 046/158] Added milliseconds to the tiff name. --- managed/GTAVisionExport/VisionExport.cs | 2 +- managed/Sandbox/MainClass.cs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 7c02ccd..99899b6 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -281,7 +281,7 @@ public void OnTick(object o, EventArgs e) // List colors = new List(); Game.Pause(true); Script.Wait(100); - var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--ffff"; GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather.ToList()); if (dat == null) return; // var thisframe = VisionNative.GetCurrentTime(); diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 825da21..082e50e 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -258,12 +258,16 @@ public static Guid InsertSystemData(NpgsqlConnection conn) public static void Main(string[] args) { // var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; -// var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; -// Console.WriteLine(fileName); - var systemInfo = new WMIInformation(); - Console.WriteLine(systemInfo.dnshostname); - Console.WriteLine(systemInfo.username); - var conn = OpenConnection(); + for (int i = 0; i < 100; i++) + { + var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss-ffff"; + var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; + Console.WriteLine(fileName); + } +// var systemInfo = new WMIInformation(); +// Console.WriteLine(systemInfo.dnshostname); +// Console.WriteLine(systemInfo.username); +// var conn = OpenConnection(); // conn = null; // int instanceid = InsertInstanceData(conn); // InsertSystemData(conn); From 23d9abb7f3a3ffd77606b1686525be3b4ce45102 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 24 Nov 2017 00:16:57 +0100 Subject: [PATCH 047/158] only milliseconds used. Useless when trying to set bigger precission. --- managed/GTAVisionExport/VisionExport.cs | 2 +- managed/Sandbox/MainClass.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 99899b6..007c9ba 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -281,7 +281,7 @@ public void OnTick(object o, EventArgs e) // List colors = new List(); Game.Pause(true); Script.Wait(100); - var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--ffff"; + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather.ToList()); if (dat == null) return; // var thisframe = VisionNative.GetCurrentTime(); diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 082e50e..00211a5 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -258,9 +258,9 @@ public static Guid InsertSystemData(NpgsqlConnection conn) public static void Main(string[] args) { // var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; + var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss-fff"; for (int i = 0; i < 100; i++) { - var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss-ffff"; var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; Console.WriteLine(fileName); } From 236863412c565fc5df5f7460501aa7a5e2cca6f9 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 24 Nov 2017 16:24:45 +0100 Subject: [PATCH 048/158] Added info about correct ingame settings. --- managed/README.md | 18 ++++++++++++++++-- managed/Sandbox/MainClass.cs | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/managed/README.md b/managed/README.md index 05ff75e..5d2fc7b 100644 --- a/managed/README.md +++ b/managed/README.md @@ -310,8 +310,22 @@ Default credentials are: - username: `postgres` - password: `postgres` -In the game, turn off the HUD, MSAA and Radar. -Turn the plugin on by "Page Up" in the game. +### In-game settings +Turn the plugin on by pressing "Page Up" in the game. +Turn NativeUI notifications off by pressing "X" in the game. + +In settings, set up these things: +- In Camera + - set First Person Velicle Hood to On +- In Display + - set Radar to Off + - set HUD to Off +- In Graphics + - set MSAA to Off +- In Notifications + - set all notifications to Off + +Set the camera to be on the hood of the car by pressing "V" repeatedly, until camera is on desired position. ### Gathering screenshots There is either manual or automatic way. diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 00211a5..4473bf7 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -259,7 +259,7 @@ public static void Main(string[] args) { // var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss-fff"; - for (int i = 0; i < 100; i++) + for (int i = 0; i < 1000; i++) { var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; Console.WriteLine(fileName); From 83ef8639987750c803646a5dc0ce869a3bdc7a6e Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 24 Nov 2017 18:27:00 +0100 Subject: [PATCH 049/158] Changed interval. --- managed/GTAVisionExport/VisionExport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 007c9ba..9278259 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -93,7 +93,7 @@ public VisionExport() this.Tick += new EventHandler(this.OnTick); this.KeyDown += OnKeyDown; - Interval = 1000; + Interval = 100; if (enabled) { postgresTask?.Wait(); From d721484178092c9c0d45acad03189d3e6c9ab459 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 24 Nov 2017 18:30:56 +0100 Subject: [PATCH 050/158] Removed default path params. --- managed/GTAVisionExport/VisionExport.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 9278259..f705301 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -48,8 +48,8 @@ class VisionExport : Script #endif //private readonly string dataPath = // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Data"); - private readonly string dataPath = @"D:\GTAV_extraction_output\"; - private readonly string logFilePath = @"D:\GTAV_extraction_output\log.txt"; + private readonly string dataPath; + private readonly string logFilePath; private readonly Weather[] wantedWeather = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; private Player player; private string outputPath; From 4765e0822a29ea3316d649ac778b3c800aa16a6b Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 24 Nov 2017 18:37:15 +0100 Subject: [PATCH 051/158] Added saving to one tiff, for BC. --- managed/GTAVisionExport/VisionExport.cs | 2 +- managed/GTAVisionUtils/ImageUtils.cs | 166 +++++++++++++++++------- 2 files changed, 117 insertions(+), 51 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index f705301..095bd49 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -683,7 +683,7 @@ private void saveSnapshotToFile(String name, Weather[] weathers) Game.Pause(false); var res = Game.ScreenResolution; var fileName = Path.Combine(dataPath, "info-" + name); - ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil); + ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil, false); // UINotify("file saved to: " + fileName); // UINotify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index 31f46d7..c4ed974 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -7,8 +7,8 @@ using System.Threading.Tasks; using BitMiracle.LibTiff.Classic; -namespace GTAVisionUtils { - +namespace GTAVisionUtils +{ public class ImageUtils { private static Task imageTask; @@ -19,6 +19,7 @@ public static byte[] getLastCapturedFrame() WaitForProcessing(); return lastCapturedBytes; } + public static void WaitForProcessing() { if (imageTask == null) return; @@ -30,7 +31,8 @@ public static void StartUploadTask(ZipArchive archive, string name, int w, int h { WaitForProcessing(); imageTask = Task.Run(() => UploadToArchive(archive, name, w, h, colors, depth, stencil)); - } + } + public static void UploadToArchive(ZipArchive archive, string name, int w, int h, List colors, byte[] depth, byte[] stencil) { @@ -42,75 +44,139 @@ public static void UploadToArchive(ZipArchive archive, string name, int w, int h entryStream.Write(lastCapturedBytes, 0, lastCapturedBytes.Length); entryStream.Close(); memstream.Close(); - } - public static async void WriteToTiff(string name, int width, int height, List colors, byte[] depth, byte[] stencil) + public static async void WriteToTiff(string name, int width, int height, List colors, byte[] depth, + byte[] stencil, bool oneFile = true) { - await Task.Run(() => WriteToTiffImpl(name, width, height, colors, depth, stencil)); + await Task.Run(() => WriteToTiffImpl(name, width, height, colors, depth, stencil, oneFile)); } - public static void WriteToTiffImpl(string name, int width, int height, List colors, byte[] depth, byte[] stencil) + public static void WriteToTiffImpl(string name, int width, int height, List colors, byte[] depth, + byte[] stencil, bool oneFile = true) { - var t = Tiff.Open(name + ".tiff", "w"); - var pages = colors.Count; - var page = 0; - foreach (var color in colors) + if (oneFile) { + var t = Tiff.Open(name + ".tiff", "w"); + var pages = colors.Count + 2; + var page = 0; + foreach (var color in colors) + { + t.CreateDirectory(); + t.SetField(TiffTag.IMAGEWIDTH, width); + t.SetField(TiffTag.IMAGELENGTH, height); + t.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG); + t.SetField(TiffTag.SAMPLESPERPIXEL, 4); + t.SetField(TiffTag.ROWSPERSTRIP, height); + t.SetField(TiffTag.BITSPERSAMPLE, 8); + t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); + t.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB); + t.SetField(TiffTag.COMPRESSION, Compression.JPEG); + t.SetField(TiffTag.JPEGQUALITY, 60); + t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); + t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); + t.SetField(TiffTag.PAGENUMBER, page, pages); + t.WriteEncodedStrip(0, color, color.Length); + page++; + t.WriteDirectory(); + } + t.CreateDirectory(); + //page 2 t.SetField(TiffTag.IMAGEWIDTH, width); t.SetField(TiffTag.IMAGELENGTH, height); + t.SetField(TiffTag.ROWSPERSTRIP, height); t.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG); - t.SetField(TiffTag.SAMPLESPERPIXEL, 4); + t.SetField(TiffTag.SAMPLESPERPIXEL, 1); + t.SetField(TiffTag.BITSPERSAMPLE, 32); + t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); + t.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK); + t.SetField(TiffTag.COMPRESSION, Compression.LZW); + t.SetField(TiffTag.PREDICTOR, Predictor.FLOATINGPOINT); + t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.IEEEFP); + t.SetField(TiffTag.PAGENUMBER, page, pages); + t.WriteEncodedStrip(0, depth, depth.Length); + page++; + t.WriteDirectory(); + + t.SetField(TiffTag.IMAGEWIDTH, width); + t.SetField(TiffTag.IMAGELENGTH, height); t.SetField(TiffTag.ROWSPERSTRIP, height); + t.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG); + t.SetField(TiffTag.SAMPLESPERPIXEL, 1); t.SetField(TiffTag.BITSPERSAMPLE, 8); t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); - t.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB); + t.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK); t.SetField(TiffTag.COMPRESSION, Compression.LZW); t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); t.SetField(TiffTag.PAGENUMBER, page, pages); - t.WriteEncodedStrip(0, color, color.Length); - page++; + t.WriteEncodedStrip(0, stencil, stencil.Length); t.WriteDirectory(); + t.Flush(); + t.Close(); } + else + { + var t = Tiff.Open(name + ".tiff", "w"); + var pages = colors.Count; + var page = 0; + foreach (var color in colors) + { + t.CreateDirectory(); + t.SetField(TiffTag.IMAGEWIDTH, width); + t.SetField(TiffTag.IMAGELENGTH, height); + t.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG); + t.SetField(TiffTag.SAMPLESPERPIXEL, 4); + t.SetField(TiffTag.ROWSPERSTRIP, height); + t.SetField(TiffTag.BITSPERSAMPLE, 8); + t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); + t.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB); + t.SetField(TiffTag.COMPRESSION, Compression.LZW); + t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); + t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); + t.SetField(TiffTag.PAGENUMBER, page, pages); + t.WriteEncodedStrip(0, color, color.Length); + page++; + t.WriteDirectory(); + } - t.Flush(); - t.Close(); + t.Flush(); + t.Close(); - t = Tiff.Open(name + "-depth.tiff", "w"); - t.SetField(TiffTag.IMAGEWIDTH, width); - t.SetField(TiffTag.IMAGELENGTH, height); - t.SetField(TiffTag.ROWSPERSTRIP, height); - t.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG); - t.SetField(TiffTag.SAMPLESPERPIXEL, 1); - t.SetField(TiffTag.BITSPERSAMPLE, 32); - t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); - t.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK); - t.SetField(TiffTag.COMPRESSION, Compression.LZW); - t.SetField(TiffTag.PREDICTOR, Predictor.FLOATINGPOINT); - t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.IEEEFP); - t.WriteEncodedStrip(0, depth, depth.Length); - - t.Flush(); - t.Close(); + t = Tiff.Open(name + "-depth.tiff", "w"); + t.SetField(TiffTag.IMAGEWIDTH, width); + t.SetField(TiffTag.IMAGELENGTH, height); + t.SetField(TiffTag.ROWSPERSTRIP, height); + t.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG); + t.SetField(TiffTag.SAMPLESPERPIXEL, 1); + t.SetField(TiffTag.BITSPERSAMPLE, 32); + t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); + t.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK); + t.SetField(TiffTag.COMPRESSION, Compression.LZW); + t.SetField(TiffTag.PREDICTOR, Predictor.FLOATINGPOINT); + t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.IEEEFP); + t.WriteEncodedStrip(0, depth, depth.Length); + + t.Flush(); + t.Close(); - t = Tiff.Open(name + "-stencil.tiff", "w"); - t.SetField(TiffTag.IMAGEWIDTH, width); - t.SetField(TiffTag.IMAGELENGTH, height); - t.SetField(TiffTag.ROWSPERSTRIP, height); - t.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG); - t.SetField(TiffTag.SAMPLESPERPIXEL, 1); - t.SetField(TiffTag.BITSPERSAMPLE, 8); - t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); - t.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK); - t.SetField(TiffTag.COMPRESSION, Compression.LZW); - t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); - t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); - t.WriteEncodedStrip(0, stencil, stencil.Length); - t.Flush(); - t.Close(); + t = Tiff.Open(name + "-stencil.tiff", "w"); + t.SetField(TiffTag.IMAGEWIDTH, width); + t.SetField(TiffTag.IMAGELENGTH, height); + t.SetField(TiffTag.ROWSPERSTRIP, height); + t.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG); + t.SetField(TiffTag.SAMPLESPERPIXEL, 1); + t.SetField(TiffTag.BITSPERSAMPLE, 8); + t.SetField(TiffTag.SUBFILETYPE, FileType.PAGE); + t.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK); + t.SetField(TiffTag.COMPRESSION, Compression.LZW); + t.SetField(TiffTag.PREDICTOR, Predictor.HORIZONTAL); + t.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.UINT); + t.WriteEncodedStrip(0, stencil, stencil.Length); + t.Flush(); + t.Close(); + } } - } -} +} \ No newline at end of file From 4c7a863220ad74e8821a00d45dbe4df6454e25c1 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sat, 25 Nov 2017 12:49:36 +0100 Subject: [PATCH 052/158] fixed output name for jpeg conversion. Added some more info. --- managed/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/managed/README.md b/managed/README.md index 5d2fc7b..96fffcb 100644 --- a/managed/README.md +++ b/managed/README.md @@ -322,6 +322,7 @@ In settings, set up these things: - set HUD to Off - In Graphics - set MSAA to Off + - set Pause Game on Focus Loss to Off - In Notifications - set all notifications to Off From e1bb0efa22186c9428233a8399c9c5b9ddfb3367 Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 27 Nov 2017 10:08:37 +0100 Subject: [PATCH 053/158] Used JPEG compression for RGB images --- managed/GTAVisionUtils/ImageUtils.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index c4ed974..6c2ca5c 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -132,7 +132,8 @@ public static void WriteToTiffImpl(string name, int width, int height, List Date: Thu, 7 Dec 2017 17:09:42 +0100 Subject: [PATCH 054/158] Added weather setting. Added persisting to trycatch --- managed/GTAVisionExport/VisionExport.cs | 82 ++++++------------------- 1 file changed, 20 insertions(+), 62 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 1b06393..eef5e92 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -178,6 +178,13 @@ private void handlePipeInput() GTA.World.CurrentDayTime = new TimeSpan(hours, minutes, 0); UINotify("Time Set"); break; + case "SET_WEATHER": + string weather = parameters.weather; + UINotify("starting set time, obtained: " + weather); + Enum.TryParse(weather, out Weather weatherEnum); + GTA.World.Weather = weatherEnum; + UINotify("Weather Set"); + break; // uncomment when resolving, how the hell should I get image by socket correctly // case "GET_SCREEN": // var last = ImageUtils.getLastCapturedFrame(); @@ -278,72 +285,23 @@ public void OnTick(object o, EventArgs e) // UINotify("going to save images and save to postgres"); -// List colors = new List(); - Game.Pause(true); - Script.Wait(100); - var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; - GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather.ToList()); - if (dat == null) return; -// var thisframe = VisionNative.GetCurrentTime(); -// var depth = VisionNative.GetDepthBuffer(); -// var stencil = VisionNative.GetStencilBuffer(); -// colors.Add(VisionNative.GetColorBuffer()); - /* - foreach (var wea in wantedWeather) { - World.TransitionToWeather(wea, 0.0f); - Script.Wait(1); - colors.Add(VisionNative.GetColorBuffer()); - }*/ -// Game.Pause(false); - - /* - if (World.Weather != Weather.Snowing) - { - World.TransitionToWeather(Weather.Snowing, 1); - - }*/ -// var colorframe = VisionNative.GetLastColorTime(); -// var depthframe = VisionNative.GetLastConstantTime(); -// var constantframe = VisionNative.GetLastConstantTime(); - //UINotify("DIFF: " + (colorframe - depthframe) + " FRAMETIME: " + (1 / Game.FPS) * 1000); -// UINotify("colors length: " + colors[0].Length.ToString()); -// if (depth == null || stencil == null) -// { -// UINotify("No DEPTH"); -// return; -// } - - /* - * this code checks to see if there's drift - * it's kinda pointless because we end up "straddling" a present call, - * so the capture time difference can be ~1/4th of a frame but still the - * depth/stencil and color buffers are one frame offset from each other - if (Math.Abs(thisframe - colorframe) < 60 && Math.Abs(colorframe - depthframe) < 60 && - Math.Abs(colorframe - constantframe) < 60) + try { - - - + Game.Pause(true); + Script.Wait(100); + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; + GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather.ToList()); + if (dat == null) return; - + saveSnapshotToFile(dat.ImageName, wantedWeather); PostgresExport.SaveSnapshot(dat, run.guid); } - */ -// ImageUtils.WaitForProcessing(); - saveSnapshotToFile(dat.ImageName, wantedWeather); -// ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, -// Game.ScreenResolution.Height, colors, depth, stencil); - -// UINotify("going to save snapshot to db"); -// UINotify("current weather: " + dat.CurrentWeather.ToString()); - PostgresExport.SaveSnapshot(dat, run.guid); -// outStream.Flush(); -// if ((Int64)outStream.Length > (Int64)2048 * (Int64)1024 * (Int64)1024) { -// ImageUtils.WaitForProcessing(); -// StopRun(); -// runTask?.Wait(); -// runTask = StartRun(); -// } + catch (Exception exception) + { + Console.WriteLine("exception occured, logging and continuing"); + Console.WriteLine(exception); + throw; + } } /* -1 = need restart, 0 = normal, 1 = need to enter vehicle */ From c8a502c1c3deb26ac4aa5c36881003f8a9b3acfe Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 7 Dec 2017 17:12:33 +0100 Subject: [PATCH 055/158] N now saves to database --- managed/GTAVisionExport/VisionExport.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index eef5e92..fb4e337 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -300,7 +300,6 @@ public void OnTick(object o, EventArgs e) { Console.WriteLine("exception occured, logging and continuing"); Console.WriteLine(exception); - throw; } } @@ -614,8 +613,11 @@ public void OnKeyDown(object o, KeyEventArgs k) //var color = VisionNative.GetColorBuffer(); for (int i = 0; i < 100; i++) { - saveSnapshotToFile(i.ToString(), wantedWeather); + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; + GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather.ToList()); + saveSnapshotToFile(dat.ImageName, wantedWeather); + PostgresExport.SaveSnapshot(dat, run.guid); Script.Wait(200); } } From eadaee9745308cf8ee8ac0be8a97ba60d7b73086 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 7 Dec 2017 18:02:16 +0100 Subject: [PATCH 056/158] added some thread testing things --- managed/Sandbox/MainClass.cs | 66 ++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 4473bf7..7ebadc4 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Management; +using System.Threading.Tasks; using GTAVisionUtils; using IniParser; using Newtonsoft.Json; @@ -255,15 +256,68 @@ public static Guid InsertSystemData(NpgsqlConnection conn) } } + public static async void Printing(int i) + { + await Task.Run(() => PrintingImpl(i)); + } + + public static void PrintingImpl(int i) + { + System.Threading.Thread.Sleep(1000); // wait 1 second + Console.WriteLine(i); + } + + public static async void Printing(string i) + { + await Task.Run(() => PrintingImpl(i)); + } + + public static void PrintingImpl(string i) + { + System.Threading.Thread.Sleep(1000); // wait 1 second + Console.WriteLine(i); + } + + public static async void Printing(byte[] i) + { + await Task.Run(() => PrintingImpl(i)); + } + + public static void PrintingImpl(byte[] i) + { + System.Threading.Thread.Sleep(1000); // wait 1 second + Console.WriteLine(BitConverter.ToString(i)); + } + + public static void tryThreads() + { +// var i = 1; +// var i = "h"; + var i = new byte[] { 0x20, 0x20, 0x20, 0x20}; + Printing(i); + System.Threading.Thread.Sleep(500); +// i = 2; +// i = "he"; + i = new byte[] { 0x30, 0x30, 0x30, 0x30}; + Printing(i); + System.Threading.Thread.Sleep(500); +// i = 3; +// i = "hello"; + i = new byte[] { 0x40, 0x40, 0x40, 0x40}; + Printing(i); + System.Threading.Thread.Sleep(3000); + } + public static void Main(string[] args) { + tryThreads(); // var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; - var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss-fff"; - for (int i = 0; i < 1000; i++) - { - var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; - Console.WriteLine(fileName); - } +// var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss-fff"; +// for (int i = 0; i < 1000; i++) +// { +// var fileName = DateTime.UtcNow.ToString(dateTimeFormat) + ".tiff"; +// Console.WriteLine(fileName); +// } // var systemInfo = new WMIInformation(); // Console.WriteLine(systemInfo.dnshostname); // Console.WriteLine(systemInfo.username); From 5c1cd93cfd9044b28403ad43e066c3de570738df Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 7 Dec 2017 18:15:48 +0100 Subject: [PATCH 057/158] Weather parsing throws exception (thich is caught, but incorrectly parsed enum is not set) --- managed/GTAVisionExport/VisionExport.cs | 19 +++++++++++++------ managed/Sandbox/MainClass.cs | 7 ++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index fb4e337..8c33ed5 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -179,12 +179,19 @@ private void handlePipeInput() UINotify("Time Set"); break; case "SET_WEATHER": - string weather = parameters.weather; - UINotify("starting set time, obtained: " + weather); - Enum.TryParse(weather, out Weather weatherEnum); - GTA.World.Weather = weatherEnum; - UINotify("Weather Set"); - break; + try + { + string weather = parameters.weather; + UINotify("starting set time, obtained: " + weather); + Weather weatherEnum = (Weather) Enum.Parse(typeof(Weather), weather); + GTA.World.Weather = weatherEnum; + UINotify("Weather Set"); + break; + } + catch (Exception e) + { + Console.WriteLine(e); + } // uncomment when resolving, how the hell should I get image by socket correctly // case "GET_SCREEN": // var last = ImageUtils.getLastCapturedFrame(); diff --git a/managed/Sandbox/MainClass.cs b/managed/Sandbox/MainClass.cs index 7ebadc4..752cc57 100644 --- a/managed/Sandbox/MainClass.cs +++ b/managed/Sandbox/MainClass.cs @@ -310,7 +310,12 @@ public static void tryThreads() public static void Main(string[] args) { - tryThreads(); +// tryThreads(); + + string weather = "Clear"; +// string weather = "Overcast"; + var weatherEnum = Enum.Parse(typeof(Weather), weather); + Console.WriteLine(weatherEnum); // var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss"; // var dateTimeFormat = @"dd-MM-yyyy--HH-mm-ss-fff"; // for (int i = 0; i < 1000; i++) From cdf3f48dba1c4813f8ce0fb662f51790b62aa845 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 7 Dec 2017 18:16:17 +0100 Subject: [PATCH 058/158] added new weather to UINotify --- managed/GTAVisionExport/VisionExport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 8c33ed5..edda865 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -185,7 +185,7 @@ private void handlePipeInput() UINotify("starting set time, obtained: " + weather); Weather weatherEnum = (Weather) Enum.Parse(typeof(Weather), weather); GTA.World.Weather = weatherEnum; - UINotify("Weather Set"); + UINotify("Weather Set to " + weatherEnum.ToString()); break; } catch (Exception e) From c08e7f54668071b74fe83c5421639a738c529ee1 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 7 Dec 2017 19:28:31 +0100 Subject: [PATCH 059/158] Added time interval constraint. --- managed/GTAVisionExport/VisionExport.cs | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index edda865..e409d22 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -68,6 +68,9 @@ class VisionExport : Script private bool IsGamePaused = false; private bool notificationsAllowed = true; private StereoCamera cams; + private bool timeIntervalEnabled = false; + private TimeSpan timeFrom; + private TimeSpan timeTo; public VisionExport() { // loading ini file @@ -186,12 +189,27 @@ private void handlePipeInput() Weather weatherEnum = (Weather) Enum.Parse(typeof(Weather), weather); GTA.World.Weather = weatherEnum; UINotify("Weather Set to " + weatherEnum.ToString()); - break; } catch (Exception e) { Console.WriteLine(e); } + break; + case "SET_TIME_INTERVAL": + string timeFrom = parameters.timeFrom; + string timeTo = parameters.timeTo; + UINotify("starting set time, obtained from: " + timeFrom + ", to: " + timeTo); + var hoursAndMinutesFrom = timeFrom.Split(':'); + var hoursAndMinutesTo = timeTo.Split(':'); + var hoursFrom = int.Parse(hoursAndMinutesFrom[0]); + var minutesFrom = int.Parse(hoursAndMinutesFrom[1]); + var hoursTo = int.Parse(hoursAndMinutesTo[0]); + var minutesTo = int.Parse(hoursAndMinutesTo[1]); + this.timeIntervalEnabled = true; + this.timeFrom = new TimeSpan(hoursFrom, minutesFrom, 0); + this.timeTo = new TimeSpan(hoursTo, minutesTo, 0); + UINotify("Time Interval Set"); + break; // uncomment when resolving, how the hell should I get image by socket correctly // case "GET_SCREEN": // var last = ImageUtils.getLastCapturedFrame(); @@ -308,6 +326,16 @@ public void OnTick(object o, EventArgs e) Console.WriteLine("exception occured, logging and continuing"); Console.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 = GTA.World.CurrentDayTime; + if (currentTime > timeTo) + { + GTA.World.CurrentDayTime = timeFrom; + } + } } /* -1 = need restart, 0 = normal, 1 = need to enter vehicle */ From df6e9e3874d40c64aa2bcf8bbc3d8ce7296be142 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 03:01:19 +0100 Subject: [PATCH 060/158] Added support for one weather. --- managed/GTAVisionExport/VisionExport.cs | 115 +++++++++++--------- managed/GTAVisionUtils/GTADataStructures.cs | 6 + 2 files changed, 67 insertions(+), 54 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index e409d22..a567ee6 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -50,7 +50,9 @@ class VisionExport : Script // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Data"); private readonly string dataPath; private readonly string logFilePath; - private readonly Weather[] wantedWeather = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; + private readonly Weather[] wantedWeathers = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; + private readonly Weather wantedWeather = Weather.Clear; + private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one private Player player; private string outputPath; private GTARun run; @@ -315,10 +317,21 @@ public void OnTick(object o, EventArgs e) Game.Pause(true); Script.Wait(100); var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; - GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather.ToList()); - if (dat == null) return; - - saveSnapshotToFile(dat.ImageName, wantedWeather); + GTAData dat; + if (multipleWeathers) + { + dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); + if (dat == null) return; + saveSnapshotToFile(dat.ImageName, wantedWeathers); + } + else + { + dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather); + if (dat == null) return; + saveSnapshotToFile(dat.ImageName, wantedWeather); + } + + Game.Pause(false); PostgresExport.SaveSnapshot(dat, run.guid); } catch (Exception exception) @@ -596,7 +609,17 @@ public void OnKeyDown(object o, KeyEventArgs k) IsGamePaused = false; Game.Pause(false); */ - var data = GTAData.DumpData(Game.GameTime + ".tiff", new List(wantedWeather)); + Weather[] weathers; + if (multipleWeathers) + { + weathers = wantedWeathers; + } + else + { + weathers = new Weather[] {wantedWeather}; + } + + var data = GTAData.DumpData(Game.GameTime + ".tiff", weathers.ToList()); string path = @"D:\GTAV_extraction_output\trymatrix.txt"; // This text is added only once to the file. @@ -646,14 +669,27 @@ public void OnKeyDown(object o, KeyEventArgs k) dumpTest(); //var color = VisionNative.GetColorBuffer(); - for (int i = 0; i < 100; i++) + for (int i = 0; i < 10; i++) { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; - GTAData dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather.ToList()); - saveSnapshotToFile(dat.ImageName, wantedWeather); + Game.Pause(true); + Script.Wait(100); + + GTAData dat; + if (multipleWeathers) + { + dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); + saveSnapshotToFile(dat.ImageName, wantedWeathers); + } + else + { + dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather); + saveSnapshotToFile(dat.ImageName, wantedWeather); + } + PostgresExport.SaveSnapshot(dat, run.guid); - Script.Wait(200); + Game.Pause(false); } } if (k.KeyCode == Keys.I) @@ -682,51 +718,22 @@ private void saveSnapshotToFile(String name, Weather[] weathers) var fileName = Path.Combine(dataPath, "info-" + name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil, false); // UINotify("file saved to: " + fileName); - -// UINotify("FieldOfView: " + GameplayCamera.FieldOfView.ToString()); - //UINotify((connection != null && connection.Connected).ToString()); - + } -// var data = GTAData.DumpData(Game.GameTime + ".dat", new List(wantedWeather)); + private void saveSnapshotToFile(String name, Weather weather) + { + Game.Pause(true); + World.TransitionToWeather(weather, 0.0f); + Script.Wait(1); + var depth = VisionNative.GetDepthBuffer(); + var stencil = VisionNative.GetStencilBuffer(); + var color = VisionNative.GetColorBuffer(); -// string path = @"D:\GTAV_extraction_output\info.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 & Ped pos file"); -// } -// } -// -// using (StreamWriter file = File.AppendText(path)) -// { -// file.WriteLine("==============info" + i.ToString() + ".tiff 's metadata======================="); -// file.WriteLine("cam pos"); -// file.WriteLine(GameplayCamera.Position.X.ToString()); -// file.WriteLine(GameplayCamera.Position.Y.ToString()); -// file.WriteLine(GameplayCamera.Position.Z.ToString()); -// file.WriteLine("cam direction"); -// file.WriteLine(GameplayCamera.Direction.X.ToString()); -// file.WriteLine(GameplayCamera.Direction.Y.ToString()); -// file.WriteLine(GameplayCamera.Direction.Z.ToString()); -// file.WriteLine("projection matrix"); -// file.WriteLine(data.ProjectionMatrix.Values.ToString()); -// file.WriteLine("view matrix"); -// file.WriteLine(data.ViewMatrix.Values.ToString()); -// file.WriteLine("character"); -// file.WriteLine(data.Pos.X.ToString()); -// file.WriteLine(data.Pos.Y.ToString()); -// file.WriteLine(data.Pos.Z.ToString()); -// foreach (var detection in data.Detections) -// { -// file.WriteLine(detection.Type.ToString()); -// file.WriteLine(detection.Pos.X.ToString()); -// file.WriteLine(detection.Pos.Y.ToString()); -// file.WriteLine(detection.Pos.Z.ToString()); -// } -// } + Game.Pause(false); + var res = Game.ScreenResolution; + var fileName = Path.Combine(dataPath, "info-" + name); + ImageUtils.WriteToTiff(fileName, res.Width, res.Height, new List() {color}, depth, stencil, false); +// UINotify("file saved to: " + fileName); } private void dumpTest() @@ -736,7 +743,7 @@ private void dumpTest() Script.Wait(1); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); - foreach (var wea in wantedWeather) + foreach (var wea in wantedWeathers) { World.TransitionToWeather(wea, 0.0f); Script.Wait(1); diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 69b96a1..61e9332 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -283,6 +283,12 @@ public static bool CheckVisible(Entity e) { //return e.IsInRangeOf(res.HitCoords, 10); //return res.HitEntity == e; } + + public static GTAData DumpData(string imageName, Weather capturedWeather) + { + return DumpData(imageName, new List() {capturedWeather}); + } + public static GTAData DumpData(string imageName, List capturedWeathers) { var ret = new GTAData(); From 4dd2f85bdf0a143779958cbce6a749ce8a577ad8 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 03:58:57 +0100 Subject: [PATCH 061/158] added multiple weather options --- managed/GTAVisionExport/VisionExport.cs | 32 +++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index a567ee6..9c3bf41 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -53,6 +53,7 @@ class VisionExport : Script private readonly Weather[] wantedWeathers = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; private readonly Weather wantedWeather = Weather.Clear; private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one + private readonly bool currentWeather = true; private Player player; private string outputPath; private GTARun run; @@ -187,10 +188,9 @@ private void handlePipeInput() try { string weather = parameters.weather; - UINotify("starting set time, obtained: " + weather); + UINotify("Weather Set to " + weather.ToString()); Weather weatherEnum = (Weather) Enum.Parse(typeof(Weather), weather); GTA.World.Weather = weatherEnum; - UINotify("Weather Set to " + weatherEnum.ToString()); } catch (Exception e) { @@ -326,9 +326,10 @@ public void OnTick(object o, EventArgs e) } else { - dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather); + Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; + dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); if (dat == null) return; - saveSnapshotToFile(dat.ImageName, wantedWeather); + saveSnapshotToFile(dat.ImageName, weather); } Game.Pause(false); @@ -609,17 +610,16 @@ public void OnKeyDown(object o, KeyEventArgs k) IsGamePaused = false; Game.Pause(false); */ - Weather[] weathers; + GTAData data; if (multipleWeathers) { - weathers = wantedWeathers; + data = GTAData.DumpData(Game.GameTime + ".tiff", wantedWeathers.ToList()); } else { - weathers = new Weather[] {wantedWeather}; + Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; + data = GTAData.DumpData(Game.GameTime + ".tiff", weather); } - - var data = GTAData.DumpData(Game.GameTime + ".tiff", weathers.ToList()); string path = @"D:\GTAV_extraction_output\trymatrix.txt"; // This text is added only once to the file. @@ -662,11 +662,11 @@ public void OnKeyDown(object o, KeyEventArgs k) if (k.KeyCode == Keys.N) { - UINotify("N pressed, going to print stats to file or what?"); + UINotify("N pressed, going to print stats to file"); //var color = VisionNatGetColorBuffer(); - dumpTest(); +// dumpTest(); //var color = VisionNative.GetColorBuffer(); for (int i = 0; i < 10; i++) @@ -683,12 +683,14 @@ public void OnKeyDown(object o, KeyEventArgs k) } else { - dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeather); - saveSnapshotToFile(dat.ImageName, wantedWeather); + Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; + dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); + saveSnapshotToFile(dat.ImageName, weather); } - - PostgresExport.SaveSnapshot(dat, run.guid); +// tady dát nějaký "manual" id, na tom to padá +// ToolStripDropDown: fixnout +// PostgresExport.SaveSnapshot(dat, -1); Game.Pause(false); } } From cf1445926c3b6923ba2f5dff486f230a801c6884 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 13:26:40 +0100 Subject: [PATCH 062/158] Added check for manual printscreen. --- managed/GTAVisionExport/VisionExport.cs | 165 ++++++++++++------------ 1 file changed, 81 insertions(+), 84 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 9c3bf41..eb94263 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -37,8 +37,8 @@ using IniParser; using Newtonsoft.Json; -namespace GTAVisionExport { - +namespace GTAVisionExport +{ class VisionExport : Script { #if DEBUG @@ -50,7 +50,10 @@ class VisionExport : Script // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Data"); private readonly string dataPath; private readonly string logFilePath; - private readonly Weather[] wantedWeathers = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; + + private readonly Weather[] wantedWeathers = new Weather[] + {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; + private readonly Weather wantedWeather = Weather.Clear; private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one private readonly bool currentWeather = true; @@ -61,10 +64,13 @@ class VisionExport : Script private Socket server; private Socket connection; private UTF8Encoding encoding = new UTF8Encoding(false); + private KeyHandling kh = new KeyHandling(); + // private ZipArchive archive; // private Stream outStream; private Task postgresTask; + private Task runTask; private int curSessionId = -1; private speedAndTime lowSpeedTime = new speedAndTime(); @@ -74,6 +80,7 @@ class VisionExport : Script private bool timeIntervalEnabled = false; private TimeSpan timeFrom; private TimeSpan timeTo; + public VisionExport() { // loading ini file @@ -98,7 +105,7 @@ public VisionExport() //outStream = File.CreateText(outputPath); this.Tick += new EventHandler(this.OnTick); this.KeyDown += OnKeyDown; - + Interval = 100; if (enabled) { @@ -116,7 +123,7 @@ private void handlePipeInput() UINotify("server connected:" + server.Connected.ToString()); UINotify(connection == null ? "connection is null" : "connection:" + connection.ToString()); if (connection == null) return; - + byte[] inBuffer = new byte[1024]; string str = ""; int num = 0; @@ -146,10 +153,7 @@ private void handlePipeInput() switch (commandName) { case "START_SESSION": - postgresTask?.Wait(); - postgresTask = StartSession(); - runTask?.Wait(); - runTask = StartRun(); + startRunAndSession(); break; case "STOP_SESSION": StopRun(); @@ -169,7 +173,8 @@ private void handlePipeInput() ReloadGame(); break; case "RELOAD": - FieldInfo f = this.GetType().GetField("_scriptdomain", BindingFlags.NonPublic | BindingFlags.Instance); + FieldInfo f = this.GetType() + .GetField("_scriptdomain", BindingFlags.NonPublic | BindingFlags.Instance); object domain = f.GetValue(this); MethodInfo m = domain.GetType() .GetMethod("DoKeyboardMessage", BindingFlags.Instance | BindingFlags.Public); @@ -221,51 +226,19 @@ private void handlePipeInput() // connection.Send(BitConverter.GetBytes(size)); // connection.Send(last); // break; - } } -// private void UploadFile() -// { -// System.IO.File.AppendAllText(logFilePath, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ": VisionExport UploadFile called.\n"); -// UINotify("UploadFile called"); -// -//// archive.Dispose(); -// var oldOutput = outputPath; -// if (oldOutput != null) -// { -// new Thread(() => -// { -// File.Move(oldOutput, Path.Combine(dataPath, run.guid + ".zip")); -// }).Start(); -// } -// -// outputPath = Path.GetTempFileName(); -// outStream = File.Open(outputPath, FileMode.Truncate); -//// archive = new ZipArchive(outStream, ZipArchiveMode.Update); -// //File.Delete(oldOutput); -// -// /* -// archive.Dispose(); -// var req = new PutObjectRequest { -// BucketName = "gtadata", -// Key = "images/" + run.guid + ".zip", -// FilePath = outputPath -// }; -// var resp = client.PutObjectAsync(req); -// outputPath = Path.GetTempFileName(); -// S3Stream = File.Open(outputPath, FileMode.Truncate); -// archive = new ZipArchive(S3Stream, ZipArchiveMode.Update); -// -// await resp; -// File.Delete(req.FilePath); -// */ -// } - - public void OnTick(object o, EventArgs e) + public void startRunAndSession() { - + postgresTask?.Wait(); + postgresTask = StartSession(); + runTask?.Wait(); + runTask = StartRun(); + } + public void OnTick(object o, EventArgs e) + { if (server.Poll(10, SelectMode.SelectRead) && connection == null) { connection = server.Accept(); @@ -274,11 +247,12 @@ public void OnTick(object o, EventArgs e) } handlePipeInput(); if (!enabled) return; - + //Array values = Enum.GetValues(typeof(Weather)); - switch (checkStatus()) { + switch (checkStatus()) + { case GameStatus.NeedReload: //TODO: need to get a new session and run? StopRun(); @@ -295,7 +269,7 @@ public void OnTick(object o, EventArgs e) //Autostart(); // use reloading temporarily StopRun(); - + ReloadGame(); Script.Wait(100); runTask?.Wait(); @@ -331,7 +305,7 @@ public void OnTick(object o, EventArgs e) if (dat == null) return; saveSnapshotToFile(dat.ImageName, weather); } - + Game.Pause(false); PostgresExport.SaveSnapshot(dat, run.guid); } @@ -340,7 +314,7 @@ public void OnTick(object o, EventArgs e) Console.WriteLine("exception occured, logging and continuing"); Console.WriteLine(exception); } - + // if time interval is enabled, checkes game time and sets it to timeFrom, it current time is after timeTo if (timeIntervalEnabled) { @@ -401,7 +375,6 @@ public Bitmap CaptureScreen() } */ return cap; //cap.Save(GetFileName(".png"), ImageFormat.Png); - } public void Autostart() @@ -428,23 +401,24 @@ public void StopSession() PostgresExport.StopSession(curSessionId); curSessionId = -1; } + public async Task StartRun() { await postgresTask; - if(run != null) PostgresExport.StopRun(run); + if (run != null) PostgresExport.StopRun(run); var runid = await PostgresExport.StartRun(curSessionId); //var s3Info = new S3FileInfo(client, "gtadata", run.archiveKey); //S3Stream = s3Info.Create(); - + // outputPath = Path.GetTempFileName(); // outStream = File.Open(outputPath, FileMode.Truncate); // archive = new ZipArchive(outStream, ZipArchiveMode.Create); - + //archive = new ZipArchive(, ZipArchiveMode.Create); - + //archive = ZipFile.Open(Path.Combine(dataPath, run.guid + ".zip"), ZipArchiveMode.Create); - + run = runid; enabled = true; @@ -462,7 +436,7 @@ public void StopRun() PostgresExport.StopRun(run); // UploadFile(); run = null; - + Game.Player.LastVehicle.Alpha = int.MaxValue; } @@ -471,10 +445,10 @@ public void UINotify(string message) //just wrapper for UI.Notify, but lets us disable showing notifications ar all if (notificationsAllowed) { - UI.Notify(message); + UI.Notify(message); } } - + public void EnterVehicle() { /* @@ -482,9 +456,18 @@ public void EnterVehicle() player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); */ Model mod = new Model(GTA.Native.VehicleHash.Asea); - if (mod == null) {UINotify("mod is null");} - if (player == null) {UINotify("player is null");} - if (player.Character == null) {UINotify("player.Character is null");} + if (mod == null) + { + UINotify("mod is null"); + } + if (player == null) + { + UINotify("player is null"); + } + if (player.Character == null) + { + UINotify("player.Character is null"); + } UINotify("player position: " + player.Character.Position.ToString()); var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); if (vehicle == null) @@ -493,7 +476,7 @@ public void EnterVehicle() } else { - player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); + player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); } //vehicle.Alpha = 0; //transparent //player.Character.Alpha = 0; @@ -504,7 +487,8 @@ public void ToggleNavigation() //todo: probably here try to set camera, maybe by SET_FOLLOW_VEHICLE_CAM_VIEW_MODE(int viewMode), or by SET_FOLLOW_VEHICLE_CAM_ZOOM_LEVEL(int zoomLevel) // or just something with the GTA.GameplayCamera //YOLO - MethodInfo inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); + MethodInfo inf = + kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } @@ -525,18 +509,19 @@ public void ReloadGame() //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 - Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, player.Position.Z, 1000f, false, false, false, false); + Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, + player.Position.Z, 1000f, false, false, false, false); player.LastVehicle.Delete(); // teleport to the spawning position, defined in GameUtils.cs, subject to changes player.Position = GTAConst.StartPos; - Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, player.Position.Z, 100f, false, false, false, false); + Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, + player.Position.Z, 100f, false, false, false, false); // start a new run EnterVehicle(); //Script.Wait(2000); ToggleNavigation(); lowSpeedTime.clearTime(); - } public void TraverseWeather() @@ -544,7 +529,7 @@ public void TraverseWeather() for (int i = 1; i < 14; i++) { //World.Weather = (Weather)i; - World.TransitionToWeather((Weather)i, 0.0f); + World.TransitionToWeather((Weather) i, 0.0f); //Script.Wait(1000); } } @@ -597,7 +582,6 @@ public void OnKeyDown(object o, KeyEventArgs k) var str = settings.GetValue("", "ConnectionString"); UINotify("BaseDirectory: " + loc); UINotify("ConnectionString: " + str); - } if (k.KeyCode == Keys.G) // temp modification { @@ -628,17 +612,21 @@ public void OnKeyDown(object o, KeyEventArgs k) // Create a file to write to. using (StreamWriter file = File.CreateText(path)) { - - file.WriteLine("cam direction file"); file.WriteLine("direction:"); - file.WriteLine(GameplayCamera.Direction.X.ToString() + ' ' + GameplayCamera.Direction.Y.ToString() + ' ' + GameplayCamera.Direction.Z.ToString()); + file.WriteLine(GameplayCamera.Direction.X.ToString() + ' ' + + GameplayCamera.Direction.Y.ToString() + ' ' + + GameplayCamera.Direction.Z.ToString()); file.WriteLine("Dot Product:"); file.WriteLine(Vector3.Dot(GameplayCamera.Direction, GameplayCamera.Rotation)); file.WriteLine("position:"); - file.WriteLine(GameplayCamera.Position.X.ToString() + ' ' + GameplayCamera.Position.Y.ToString() + ' ' + GameplayCamera.Position.Z.ToString()); + file.WriteLine(GameplayCamera.Position.X.ToString() + ' ' + + GameplayCamera.Position.Y.ToString() + ' ' + + GameplayCamera.Position.Z.ToString()); file.WriteLine("rotation:"); - file.WriteLine(GameplayCamera.Rotation.X.ToString() + ' ' + GameplayCamera.Rotation.Y.ToString() + ' ' + GameplayCamera.Rotation.Z.ToString()); + file.WriteLine(GameplayCamera.Rotation.X.ToString() + ' ' + + GameplayCamera.Rotation.Y.ToString() + ' ' + + GameplayCamera.Rotation.Z.ToString()); file.WriteLine("relative heading:"); file.WriteLine(GameplayCamera.RelativeHeading.ToString()); file.WriteLine("relative pitch:"); @@ -662,13 +650,20 @@ public void OnKeyDown(object o, KeyEventArgs k) if (k.KeyCode == Keys.N) { - UINotify("N pressed, going to print stats to file"); + UINotify("N pressed, going to dump to file"); + + if (curSessionId == -1 || run == null) + { + UINotify("Please, enable plugin by PageUp"); + } //var color = VisionNatGetColorBuffer(); - + // dumpTest(); //var color = VisionNative.GetColorBuffer(); + + startRunAndSession(); for (int i = 0; i < 10; i++) { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; @@ -690,10 +685,12 @@ public void OnKeyDown(object o, KeyEventArgs k) // tady dát nějaký "manual" id, na tom to padá // ToolStripDropDown: fixnout -// PostgresExport.SaveSnapshot(dat, -1); + PostgresExport.SaveSnapshot(dat, run.guid); Game.Pause(false); + Script.Wait(200); // hoping game will go on during this wait } - } + + } if (k.KeyCode == Keys.I) { var info = new GTAVisionUtils.InstanceData(); @@ -765,4 +762,4 @@ private void dumpTest() UINotify((connection != null && connection.Connected).ToString()); } } -} +} \ No newline at end of file From 7fcc22d9f9140563d4d3bc978128b99f819e94ab Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 14:29:34 +0100 Subject: [PATCH 063/158] Added manual starting. --- managed/GTAVisionExport/VisionExport.cs | 41 +++++++------------------ managed/GTAVisionUtils/ImageUtils.cs | 16 +++++++++- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index eb94263..a1d1b2e 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -153,7 +153,10 @@ private void handlePipeInput() switch (commandName) { case "START_SESSION": - startRunAndSession(); + postgresTask?.Wait(); + postgresTask = StartSession(); + runTask?.Wait(); + runTask = StartRun(); break; case "STOP_SESSION": StopRun(); @@ -229,12 +232,13 @@ private void handlePipeInput() } } - public void startRunAndSession() + public void startRunAndSessionManual() { +// this method does not enable mod (used for manual data gathering) postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); - runTask = StartRun(); + runTask = StartRun(false); } public void OnTick(object o, EventArgs e) @@ -402,24 +406,11 @@ public void StopSession() curSessionId = -1; } - public async Task StartRun() + public async Task StartRun(bool enable = true) { await postgresTask; if (run != null) PostgresExport.StopRun(run); var runid = await PostgresExport.StartRun(curSessionId); - - //var s3Info = new S3FileInfo(client, "gtadata", run.archiveKey); - //S3Stream = s3Info.Create(); - -// outputPath = Path.GetTempFileName(); -// outStream = File.Open(outputPath, FileMode.Truncate); -// archive = new ZipArchive(outStream, ZipArchiveMode.Create); - - //archive = new ZipArchive(, ZipArchiveMode.Create); - - //archive = ZipFile.Open(Path.Combine(dataPath, run.guid + ".zip"), ZipArchiveMode.Create); - - run = runid; enabled = true; } @@ -652,18 +643,7 @@ public void OnKeyDown(object o, KeyEventArgs k) { UINotify("N pressed, going to dump to file"); - if (curSessionId == -1 || run == null) - { - UINotify("Please, enable plugin by PageUp"); - } - - //var color = VisionNatGetColorBuffer(); - -// dumpTest(); - - //var color = VisionNative.GetColorBuffer(); - - startRunAndSession(); + startRunAndSessionManual(); for (int i = 0; i < 10; i++) { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; @@ -689,7 +669,8 @@ public void OnKeyDown(object o, KeyEventArgs k) Game.Pause(false); Script.Wait(200); // hoping game will go on during this wait } - + StopRun(); + StopSession(); } if (k.KeyCode == Keys.I) { diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index 6c2ca5c..aa5c924 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -49,7 +49,21 @@ public static void UploadToArchive(ZipArchive archive, string name, int w, int h public static async void WriteToTiff(string name, int width, int height, List colors, byte[] depth, byte[] stencil, bool oneFile = true) { - await Task.Run(() => WriteToTiffImpl(name, width, height, colors, depth, stencil, oneFile)); + await Task.Run(() => + { + try + { + WriteToTiffImpl(name, width, height, colors, depth, stencil, oneFile); + } + catch (Exception e) + { + Console.WriteLine(e); + Console.WriteLine("width: " + width.ToString()); + Console.WriteLine("height: " + height.ToString()); + Console.WriteLine("oneFile: " + oneFile.ToString()); + throw; + } + }); } public static void WriteToTiffImpl(string name, int width, int height, List colors, byte[] depth, From f82ceb3841998c4254907c53f06120b7da518cac Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 14:56:45 +0100 Subject: [PATCH 064/158] waiting for run and session to properly start --- managed/GTAVisionExport/VisionExport.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index a1d1b2e..e282e15 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -412,17 +412,16 @@ public async Task StartRun(bool enable = true) if (run != null) PostgresExport.StopRun(run); var runid = await PostgresExport.StartRun(curSessionId); run = runid; - enabled = true; + if (enable) + { + enabled = true; + } } public void StopRun() { runTask?.Wait(); ImageUtils.WaitForProcessing(); -// if (outStream.CanWrite) -// { -// outStream.Flush(); -// } enabled = false; PostgresExport.StopRun(run); // UploadFile(); @@ -644,6 +643,8 @@ public void OnKeyDown(object o, KeyEventArgs k) UINotify("N pressed, going to dump to file"); startRunAndSessionManual(); + postgresTask?.Wait(); + runTask?.Wait(); for (int i = 0; i < 10; i++) { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; @@ -663,8 +664,6 @@ public void OnKeyDown(object o, KeyEventArgs k) saveSnapshotToFile(dat.ImageName, weather); } -// tady dát nějaký "manual" id, na tom to padá -// ToolStripDropDown: fixnout PostgresExport.SaveSnapshot(dat, run.guid); Game.Pause(false); Script.Wait(200); // hoping game will go on during this wait From 08a8bb335b949e62e24c0f2735dd2c26d84c8134 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 15:17:24 +0100 Subject: [PATCH 065/158] Logger moved to utils --- managed/GTAVisionExport/VisionExport.cs | 15 ++++--- managed/GTAVisionUtils/GTAVisionUtils.csproj | 1 + managed/GTAVisionUtils/ImageUtils.cs | 9 +++-- managed/GTAVisionUtils/Logger.cs | 41 ++++++++++++++++++++ 4 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 managed/GTAVisionUtils/Logger.cs diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index e282e15..3983522 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -49,7 +49,7 @@ class VisionExport : Script //private readonly string dataPath = // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Data"); private readonly string dataPath; - private readonly string logFilePath; + public static string logFilePath; private readonly Weather[] wantedWeathers = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; @@ -91,6 +91,7 @@ public VisionExport() //UINotify(ConfigurationManager.AppSettings["database_connection"]); dataPath = data["Snapshots"]["OutputDir"]; logFilePath = data["Snapshots"]["LogFile"]; + Logger.setLogFilePath(logFilePath); System.IO.File.WriteAllText(logFilePath, "VisionExport constructor called.\n"); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); @@ -202,7 +203,7 @@ private void handlePipeInput() } catch (Exception e) { - Console.WriteLine(e); + Logger.writeLine(e); } break; case "SET_TIME_INTERVAL": @@ -315,8 +316,8 @@ public void OnTick(object o, EventArgs e) } catch (Exception exception) { - Console.WriteLine("exception occured, logging and continuing"); - Console.WriteLine(exception); + 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 @@ -526,7 +527,7 @@ public void TraverseWeather() public void OnKeyDown(object o, KeyEventArgs k) { - System.IO.File.AppendAllText(logFilePath, "VisionExport OnKeyDown called.\n"); + Logger.writeLine("VisionExport OnKeyDown called."); if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); @@ -640,11 +641,12 @@ public void OnKeyDown(object o, KeyEventArgs k) if (k.KeyCode == Keys.N) { - UINotify("N pressed, going to dump to file"); + UINotify("N pressed, going to take screenshots"); startRunAndSessionManual(); postgresTask?.Wait(); runTask?.Wait(); + UINotify("starting screenshots"); for (int i = 0; i < 10; i++) { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; @@ -671,6 +673,7 @@ public void OnKeyDown(object o, KeyEventArgs k) StopRun(); StopSession(); } + if (k.KeyCode == Keys.I) { var info = new GTAVisionUtils.InstanceData(); diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index 36f79cb..cb957c8 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -135,6 +135,7 @@ + diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index aa5c924..e5f309b 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -57,10 +57,11 @@ await Task.Run(() => } catch (Exception e) { - Console.WriteLine(e); - Console.WriteLine("width: " + width.ToString()); - Console.WriteLine("height: " + height.ToString()); - Console.WriteLine("oneFile: " + oneFile.ToString()); + + Logger.writeLine(e); + Logger.writeLine("width: " + width.ToString()); + Logger.writeLine("height: " + height.ToString()); + Logger.writeLine("oneFile: " + oneFile.ToString()); throw; } }); diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs new file mode 100644 index 0000000..8941b93 --- /dev/null +++ b/managed/GTAVisionUtils/Logger.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BitMiracle.LibTiff.Classic; + +namespace GTAVisionUtils +{ + public class Logger + { + private static string logFilePath; + + public static void setLogFilePath(string path) + { + logFilePath = path; + } + + + public static void writeLine(string line) + { + System.IO.File.AppendAllText(logFilePath, line + "\n"); + } + + public static void writeLine(Exception e) + { + writeLine(e.StackTrace); + } + + public static void writeLine(object value) + { + if (value == null) + { + return; + } + writeLine(value.ToString()); + } + } +} \ No newline at end of file From cbc4392d15f89dabd7437b86cd4dda689574066f Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 15:31:39 +0100 Subject: [PATCH 066/158] datetime in logs --- managed/GTAVisionExport/VisionExport.cs | 6 +++--- managed/GTAVisionUtils/ImageUtils.cs | 1 - managed/GTAVisionUtils/Logger.cs | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 3983522..f735ced 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -646,12 +646,12 @@ public void OnKeyDown(object o, KeyEventArgs k) startRunAndSessionManual(); postgresTask?.Wait(); runTask?.Wait(); + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; UINotify("starting screenshots"); - for (int i = 0; i < 10; i++) + for (int i = 0; i < 5; i++) { - var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; Game.Pause(true); - Script.Wait(100); + Script.Wait(200); GTAData dat; if (multipleWeathers) diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index e5f309b..f9be3f3 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -57,7 +57,6 @@ await Task.Run(() => } catch (Exception e) { - Logger.writeLine(e); Logger.writeLine("width: " + width.ToString()); Logger.writeLine("height: " + height.ToString()); diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs index 8941b93..92870d4 100644 --- a/managed/GTAVisionUtils/Logger.cs +++ b/managed/GTAVisionUtils/Logger.cs @@ -21,7 +21,8 @@ public static void setLogFilePath(string path) public static void writeLine(string line) { - System.IO.File.AppendAllText(logFilePath, line + "\n"); + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; + System.IO.File.AppendAllText(logFilePath, DateTime.UtcNow.ToString(dateTimeFormat) + ": " + line + "\n"); } public static void writeLine(Exception e) From 3515aaa6eee74cafac67e8dc608dd62810d77982 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 15:33:49 +0100 Subject: [PATCH 067/158] added nam --- managed/GTAVisionUtils/ImageUtils.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index f9be3f3..b82cfb9 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -58,6 +58,7 @@ await Task.Run(() => catch (Exception e) { Logger.writeLine(e); + Logger.writeLine("name: " + name); Logger.writeLine("width: " + width.ToString()); Logger.writeLine("height: " + height.ToString()); Logger.writeLine("oneFile: " + oneFile.ToString()); From d63201e380c208f37ccf36cf1ea787f8c93abdc5 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 8 Dec 2017 16:23:54 +0100 Subject: [PATCH 068/158] fixed inconsistent logging --- managed/GTAVisionExport/VisionExport.cs | 2 +- managed/GTAVisionUtils/ImageUtils.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index f735ced..886730c 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -119,7 +119,7 @@ public VisionExport() private void handlePipeInput() { - System.IO.File.AppendAllText(logFilePath, "VisionExport handlePipeInput called.\n"); + Logger.writeLine("VisionExport handlePipeInput called."); UINotify("handlePipeInput called"); UINotify("server connected:" + server.Connected.ToString()); UINotify(connection == null ? "connection is null" : "connection:" + connection.ToString()); diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index b82cfb9..f6aca88 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -53,6 +53,8 @@ await Task.Run(() => { try { + Logger.writeLine("writing to tiff"); + Logger.writeLine("name: " + name); WriteToTiffImpl(name, width, height, colors, depth, stencil, oneFile); } catch (Exception e) From 9c931d51a70ff794fcd9a1ff751ec0d0af25df34 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 13 Dec 2017 12:00:40 +0100 Subject: [PATCH 069/158] removed on delete cascade from snapshot to run --- managed/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/managed/README.md b/managed/README.md index 96fffcb..e4db084 100644 --- a/managed/README.md +++ b/managed/README.md @@ -107,8 +107,7 @@ create table snapshots primary key, run_id integer constraint snapshots_run_fkey - references runs - on delete cascade, + references runs, version integer, imagepath text, timestamp timestamp with time zone, From a744ba8b76d6916bba6ccccbdd9fc409a8555554 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 13 Dec 2017 14:23:43 +0100 Subject: [PATCH 070/158] adding bounding box only for visible entities --- managed/GTAVisionUtils/GTADataStructures.cs | 30 +++++++++------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 61e9332..c184628 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -253,32 +253,25 @@ public static GTABoundingBox2 ComputeBoundingBox(Entity e, Vector3 offset, float rv.Max.Y = Math.Max(rv.Max.Y, s.Y); } -// int width = 1280; -// int height = 960; -// int x = (int)(rv.Min.X * width); -// int y = (int)(rv.Min.Y * height); -// int x2 = (int)(rv.Max.X * width); -// int y2 = (int)(rv.Max.Y * height); -// float w = rv.Max.X - rv.Min.X; -// float h = rv.Max.Y - rv.Min.Y; -// HashFunctions.DrawRect(rv.Min.X + w/2, rv.Min.Y + h/2, rv.Max.X - rv.Min.X, rv.Max.Y - rv.Min.Y, 255, 255, 255, 100); -// new UIRectangle(new Point((int)(rv.Min.X * 1920), (int)(rv.Min.Y * 1080)), rv.) + float w = rv.Max.X - rv.Min.X; + float h = rv.Max.Y - rv.Min.Y; + HashFunctions.DrawRect(rv.Min.X + w/2, rv.Min.Y + h/2, rv.Max.X - rv.Min.X, rv.Max.Y - rv.Min.Y, 255, 255, 255, 100); return rv; } public static bool CheckVisible(Entity e) { - return true; +// return true; //var p = Game.Player.LastVehicle; var ppos = GameplayCamera.Position; var isLOS = Function.Call((GTA.Native.Hash) 0x0267D00AF114F17A, Game.Player.Character, e); return isLOS; - //var ppos = GameplayCamera.Position; +// var ppos = GameplayCamera.Position; - //var res = World.Raycast(ppos, e.Position, IntersectOptions.Everything, Game.Player.Character.CurrentVehicle); - //HashFunctions.Draw3DLine(ppos, e.Position); - //UI.Notify("Camera: " + ppos.X + " Ent: " + e.Position.X); +// var res = World.Raycast(ppos, e.Position, IntersectOptions.Everything, Game.Player.Character.CurrentVehicle); +// HashFunctions.Draw3DLine(ppos, e.Position); +// UI.Notify("Camera: " + ppos.X + " Ent: " + e.Position.X); //World.DrawMarker(MarkerType.HorizontalCircleSkinny_Arrow, p.Position, (e.Position - p.Position).Normalized, Vector3.Zero, new Vector3(1, 1, 1), System.Drawing.Color.Red); - //return res.HitEntity == e; +// return res.HitEntity == e; //if (res.HitCoords == null) return false; //return e.IsInRangeOf(res.HitCoords, 10); //return res.HitEntity == e; @@ -326,13 +319,14 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.ViewMatrix = V as DenseMatrix; var pedList = from ped in peds - where ped.IsHuman && ped.IsOnFoot + where ped.IsHuman && ped.IsOnFoot && CheckVisible(ped) select new GTADetection(ped); var cycles = from ped in peds - where ped.IsOnBike + where ped.IsOnBike && CheckVisible(ped) select new GTADetection(ped, DetectionType.bicycle); var vehicleList = from car in cars + where CheckVisible(car) select new GTADetection(car); ret.Detections = new List(); ret.Detections.AddRange(pedList); From 9059e2db726250ad53c3c677fac8e8e3d7993719 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 13 Dec 2017 15:42:29 +0100 Subject: [PATCH 071/158] added null checking for data from native plugin --- managed/GTAVisionExport/VisionExport.cs | 33 ++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 886730c..14e51c0 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -297,21 +297,26 @@ public void OnTick(object o, EventArgs e) Script.Wait(100); var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; GTAData dat; + bool success; if (multipleWeathers) { dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); if (dat == null) return; - saveSnapshotToFile(dat.ImageName, wantedWeathers); + success = saveSnapshotToFile(dat.ImageName, wantedWeathers); } else { Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); if (dat == null) return; - saveSnapshotToFile(dat.ImageName, weather); + success = saveSnapshotToFile(dat.ImageName, weather); } - Game.Pause(false); + if (!success) + { +// when getting data and saving to file failed, saving to db is skipped + return; + } PostgresExport.SaveSnapshot(dat, run.guid); } catch (Exception exception) @@ -682,17 +687,27 @@ public void OnKeyDown(object o, KeyEventArgs k) } } - private void saveSnapshotToFile(String name, Weather[] weathers) + private bool saveSnapshotToFile(String name, Weather[] weathers) { +// returns true on success, and false on failure List colors = new List(); Game.Pause(true); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); + if (depth == null || stencil == null) + { + return false; + } foreach (var wea in weathers) { World.TransitionToWeather(wea, 0.0f); Script.Wait(1); - colors.Add(VisionNative.GetColorBuffer()); + var color = VisionNative.GetColorBuffer(); + if (color == null) + { + return false; + } + colors.Add(color); } Game.Pause(false); @@ -700,16 +715,22 @@ private void saveSnapshotToFile(String name, Weather[] weathers) var fileName = Path.Combine(dataPath, "info-" + name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil, false); // UINotify("file saved to: " + fileName); + return true; } - private void saveSnapshotToFile(String name, Weather weather) + private bool saveSnapshotToFile(String name, Weather weather) { +// returns true on success, and false on failure Game.Pause(true); World.TransitionToWeather(weather, 0.0f); Script.Wait(1); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); var color = VisionNative.GetColorBuffer(); + if (depth == null || stencil == null || color == null) + { + return false; + } Game.Pause(false); var res = Game.ScreenResolution; From 3de1dcfb44fa0b7659434cef1450cf35ca3079c3 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 13 Dec 2017 18:10:56 +0100 Subject: [PATCH 072/158] from debug to data collecting --- managed/GTAVisionExport/VisionExport.cs | 1 + managed/GTAVisionUtils/GTADataStructures.cs | 37 +++++++++++++++++---- managed/GTAVisionUtils/HashFunctions.cs | 37 +++++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 14e51c0..972a83e 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -737,6 +737,7 @@ private bool saveSnapshotToFile(String name, Weather weather) var fileName = Path.Combine(dataPath, "info-" + name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, new List() {color}, depth, stencil, false); // UINotify("file saved to: " + fileName); + return true; } private void dumpTest() diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index c184628..38a85cd 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -16,6 +16,7 @@ using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics; +using Color = System.Drawing.Color; using Vector2 = GTA.Math.Vector2; using Vector3 = GTA.Math.Vector3; using Point = System.Drawing.Point; @@ -255,25 +256,45 @@ public static GTABoundingBox2 ComputeBoundingBox(Entity e, Vector3 offset, float float w = rv.Max.X - rv.Min.X; float h = rv.Max.Y - rv.Min.Y; - HashFunctions.DrawRect(rv.Min.X + w/2, rv.Min.Y + h/2, rv.Max.X - rv.Min.X, rv.Max.Y - rv.Min.Y, 255, 255, 255, 100); +// just for debug purposes, show visible and not visible entities in other color +// if (CheckVisible(e)) +// { +// HashFunctions.DrawRect(rv.Min.X + w / 2, rv.Min.Y + h / 2, rv.Max.X - rv.Min.X, rv.Max.Y - rv.Min.Y, +// Color.White, 100); +// } +// else +// { +// HashFunctions.DrawRect(rv.Min.X + w / 2, rv.Min.Y + h / 2, rv.Max.X - rv.Min.X, rv.Max.Y - rv.Min.Y, +// Color.Red, 100); +// } +// HashFunctions.DrawRect(rv.Min.X + w/2, rv.Min.Y + h/2, rv.Max.X - rv.Min.X, rv.Max.Y - rv.Min.Y, 255, 255, 255, 100); return rv; } public static bool CheckVisible(Entity e) { // return true; - //var p = Game.Player.LastVehicle; var ppos = GameplayCamera.Position; var isLOS = Function.Call((GTA.Native.Hash) 0x0267D00AF114F17A, Game.Player.Character, e); - return isLOS; + if (isLOS) return true; +// return isLOS; // var ppos = GameplayCamera.Position; -// var res = World.Raycast(ppos, e.Position, IntersectOptions.Everything, Game.Player.Character.CurrentVehicle); + var res = World.Raycast(ppos, e.Position, IntersectOptions.Everything, Game.Player.Character.CurrentVehicle); // HashFunctions.Draw3DLine(ppos, e.Position); // UI.Notify("Camera: " + ppos.X + " Ent: " + e.Position.X); - //World.DrawMarker(MarkerType.HorizontalCircleSkinny_Arrow, p.Position, (e.Position - p.Position).Normalized, Vector3.Zero, new Vector3(1, 1, 1), System.Drawing.Color.Red); +// World.DrawMarker(MarkerType.HorizontalCircleSkinny_Arrow, ppos, (e.Position - ppos).Normalized, Vector3.Zero, new Vector3(1, 1, 1), System.Drawing.Color.Green); + +// debugging visualization for visible or invisible vehicles +// var p = Game.Player.LastVehicle; +// HashFunctions.Draw3DLine(p.Position, e.Position, System.Drawing.Color.Green); +// var s = HashFunctions.Convert3dTo2d(e.Position); +// HashFunctions.Draw2DText("Just Monika", s.X, s.Y, 255, 255, 255, 255); + +// World.DrawMarker(MarkerType.HorizontalCircleSkinny_Arrow, p.Position, (e.Position - p.Position).Normalized, Vector3.Zero, new Vector3(1, 1, 1), System.Drawing.Color.Green); // return res.HitEntity == e; - //if (res.HitCoords == null) return false; - //return e.IsInRangeOf(res.HitCoords, 10); + if (res.HitEntity == e) return true; + if (res.HitCoords == null) return false; + return e.IsInRangeOf(res.HitCoords, 10); //return res.HitEntity == e; } @@ -319,9 +340,11 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.ViewMatrix = V as DenseMatrix; var pedList = from ped in peds +// where ped.IsHuman && ped.IsOnFoot where ped.IsHuman && ped.IsOnFoot && CheckVisible(ped) select new GTADetection(ped); var cycles = from ped in peds +// where ped.IsOnBike where ped.IsOnBike && CheckVisible(ped) select new GTADetection(ped, DetectionType.bicycle); diff --git a/managed/GTAVisionUtils/HashFunctions.cs b/managed/GTAVisionUtils/HashFunctions.cs index c188860..1657cf3 100644 --- a/managed/GTAVisionUtils/HashFunctions.cs +++ b/managed/GTAVisionUtils/HashFunctions.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; +using GTA; using GTA.Math; using GTA.Native; @@ -40,6 +42,15 @@ public static void Draw3DLine(Vector3 iniPos, Vector3 finPos, byte col_r = 255, (int)col_a }); } + + public static void Draw3DLine(Vector3 iniPos, Vector3 finPos, Color color) { + Draw3DLine(iniPos, finPos, color.R, color.G, color.B, color.A); + } + + public static void Draw3DLine(Vector3 iniPos, Vector3 finPos, Color color, byte a) { + Draw3DLine(iniPos, finPos, color.R, color.G, color.B, a); + } + public static void DrawRect(float x, float y, float w, float h, byte r = 255, byte g = 255, byte b = 255, byte a = 255) { Function.Call(Hash.DRAW_RECT, new InputArgument[] { x, y, @@ -47,6 +58,32 @@ public static void DrawRect(float x, float y, float w, float h, byte r = 255, by (int)r, (int)g, (int)b, (int)a }); } + + public static void DrawRect(float x, float y, float w, float h, Color color) { + DrawRect(x, y, w, h, color.R, color.G, color.B, color.A); + } + + public static void DrawRect(float x, float y, float w, float h, Color color, byte a) { + DrawRect(x, y, w, h, color.R, color.G, color.B, a); + } + public static void Draw2DText(string text, float x, float y, Color color) { + Draw2DText(text, x, y, color.R, color.G, color.B, color.A); + } + + public static void Draw2DText(string text, float x, float y, byte r = 255, byte g = 255, byte b = 255, byte a = 255) { + Function.Call(Hash.SET_TEXT_FONT, 0); + Function.Call(Hash.SET_TEXT_SCALE, 0.3f, 0.3f); + Function.Call(Hash.SET_TEXT_COLOUR, (int)r, (int)g, (int)b, (int)a); + Function.Call(Hash.SET_TEXT_CENTRE, 1); + Function.Call(Hash._SET_TEXT_ENTRY, "STRING"); + Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text); + Function.Call(Hash._DRAW_TEXT, x, y); + } + + public static void Draw2DText(string text, float x, float y, Color color, byte a) { + Draw2DText(text, x, y, color.R, color.G, color.B, a); + } + } } From 9f49a2f125b2c322da3af790bb193042b7c420f8 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 13 Dec 2017 18:27:19 +0100 Subject: [PATCH 073/158] Added trycatch --- managed/GTAVisionUtils/Logger.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs index 92870d4..45c7cb1 100644 --- a/managed/GTAVisionUtils/Logger.cs +++ b/managed/GTAVisionUtils/Logger.cs @@ -22,7 +22,14 @@ public static void setLogFilePath(string path) public static void writeLine(string line) { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; - System.IO.File.AppendAllText(logFilePath, DateTime.UtcNow.ToString(dateTimeFormat) + ": " + line + "\n"); + try + { + System.IO.File.AppendAllText(logFilePath, DateTime.UtcNow.ToString(dateTimeFormat) + ": " + line + "\n"); + } + catch (System.IO.IOException e) + { +// just silently fail, better than throwing + } } public static void writeLine(Exception e) From a9073f1e3dcd5496feee6cb7cdc4db51b38110c2 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 3 Jan 2018 16:01:54 +0100 Subject: [PATCH 074/158] added additional attributes, used for 3D to 2D projection in the postprocessing --- managed/GTAVisionUtils/GTADataStructures.cs | 13 ++++++++++++- managed/GTAVisionUtils/PostgresExport.cs | 12 ++++++++++-- managed/README.md | 7 ++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 38a85cd..091b4bf 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -186,6 +186,13 @@ public class GTAData public DenseMatrix ViewMatrix { get; set; } public DenseMatrix ProjectionMatrix { get; set; } public double CamFOV { get; set; } + + public double CamNearClip { get; set; } + public double CamFarClip { get; set; } + public GTAVector playerPos { get; set; } + public int UIHeight { get; set; } + public int UIWidth { get; set; } + public List Detections { get; set; } public static SharpDX.Vector3 CvtVec(GTA.Math.Vector3 inp) { return (SharpDX.Vector3)new GTAVector(inp); @@ -318,7 +325,11 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.CamFOV = GameplayCamera.FieldOfView; ret.ImageWidth = Game.ScreenResolution.Width; ret.ImageHeight = Game.ScreenResolution.Height; - //ret.Pos = new GTAVector(Game.Player.Character.Position); + ret.UIWidth = UI.WIDTH; + ret.UIHeight = UI.HEIGHT; + ret.playerPos = new GTAVector(Game.Player.Character.Position); + ret.CamNearClip = World.RenderingCamera.NearClip; + ret.CamFarClip = World.RenderingCamera.FarClip; var peds = World.GetNearbyPeds(Game.Player.Character, 150.0f); var cars = World.GetNearbyVehicles(Game.Player.Character, 150.0f); diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index d450911..78602c8 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -186,9 +186,9 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Connection = conn; cmd.Transaction = trans; cmd.CommandText = - "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_direction, camera_fov, view_matrix, proj_matrix, width, height) " + + "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, cam_near_clip, cam_far_clip) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + - "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height ) " + + "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip) " + "RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); @@ -206,6 +206,14 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters.AddWithValue("@proj_matrix", data.ProjectionMatrix.ToArray()); cmd.Parameters.AddWithValue("@width", data.ImageWidth); cmd.Parameters.AddWithValue("@height", data.ImageHeight); +// @ui_width, @ui_height, @player_pos, @cam_near_clip, @cam_far_clip + cmd.Parameters.AddWithValue("@ui_width", data.UIWidth); + cmd.Parameters.AddWithValue("@ui_height", data.UIHeight); + cmd.Parameters.AddWithValue("@player_x", data.playerPos.X); + cmd.Parameters.AddWithValue("@player_y", data.playerPos.Y); + cmd.Parameters.AddWithValue("@player_z", data.playerPos.Z); + cmd.Parameters.AddWithValue("@cam_near_clip", data.CamNearClip); + cmd.Parameters.AddWithValue("@cam_far_clip", data.CamFarClip); cmd.Parameters.Add(new NpgsqlParameter("@guid", runId)); int snapshotid = (int)cmd.ExecuteScalar(); cmd.Parameters.Clear(); diff --git a/managed/README.md b/managed/README.md index e4db084..9804cc9 100644 --- a/managed/README.md +++ b/managed/README.md @@ -120,7 +120,12 @@ create table snapshots proj_matrix double precision[], processed boolean default false not null, width integer, - height integer + height integer, + ui_width integer, + ui_height integer, + cam_near_clip real, + cam_far_clip real, + player_pos GEOMETRY(PointZ) ) ; From 77bfc1fb81dff1e8cb4b3988cc8af1fcf3fb1609 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 3 Jan 2018 16:24:49 +0100 Subject: [PATCH 075/158] Addeed new class, for testing the scripted camera. --- .../GTAVisionExport/GTAVisionExport.csproj | 1 + managed/GTAVisionExport/TestVehicle.cs | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 managed/GTAVisionExport/TestVehicle.cs diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index c534a41..6a358fd 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -139,6 +139,7 @@ + diff --git a/managed/GTAVisionExport/TestVehicle.cs b/managed/GTAVisionExport/TestVehicle.cs new file mode 100644 index 0000000..25967cd --- /dev/null +++ b/managed/GTAVisionExport/TestVehicle.cs @@ -0,0 +1,88 @@ +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Collections.Generic; +using GTA; +using GTA.Native; +using GTA.Math; + +namespace GTAVisionExport +{ + +// Controls: +// P - mounts rendering camera on vehicle +// O - restores the rendering camera to original control + + public class TestVehicle : Script + { + // camera used on the vehicle + Camera camera = null; + + public TestVehicle() + { + UI.Notify("Loaded TestVehicle.cs"); + + // create a new camera + World.DestroyAllCameras(); + camera = World.CreateCamera(new Vector3(), new Vector3(), 50); + camera.IsActive = true; + GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, false, true, camera.Handle, true, true); + + // attach time methods + Tick += OnTick; + KeyUp += onKeyUp; + } + + // Function used to take control of the world rendering camera. + public void mountCameraOnVehicle() + { + if (Game.Player.Character.IsInVehicle()) + { + GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, true, true, camera.Handle, true, true); + } + else + { + UI.Notify("Please enter a vehicle."); + } + } + + // Function used to allows the user original control of the camera. + public void restoreCamera() + { + UI.Notify("Relinquishing control"); + GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, false, false, camera.Handle, true, true); + } + + // Function used to keep camera on vehicle and facing forward on each tick step. + public void keepCameraOnVehicle() + { + if (Game.Player.Character.IsInVehicle()) + { + // keep the camera in the same position relative to the car + camera.AttachTo(Game.Player.Character.CurrentVehicle, new Vector3(0f, 2f, 0.4f)); + + // rotate the camera to face the same direction as the car + camera.Rotation = Game.Player.Character.CurrentVehicle.Rotation; + } + } + + // Test vehicle controls + private void onKeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.P) + { + mountCameraOnVehicle(); + } + + if (e.KeyCode == Keys.O) + { + restoreCamera(); + } + } + + void OnTick(object sender, EventArgs e) + { + keepCameraOnVehicle(); + } + } +} \ No newline at end of file From 4e1c315ec0532f55ad0d147614820247ee2ba5f0 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 18 Jan 2018 01:27:09 +0100 Subject: [PATCH 076/158] added original postprocessing, with modification for samples, added functions to sql schema --- managed/README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/managed/README.md b/managed/README.md index 9804cc9..f86a416 100644 --- a/managed/README.md +++ b/managed/README.md @@ -244,6 +244,79 @@ create table system_graphics ; +-- +-- Name: ngv_box3dmultipoint(box3d); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION ngv_box3dmultipoint(box3d) RETURNS geometry + LANGUAGE sql + AS $_$ select ST_Multi(ST_Collect(ST_MakePoint(ST_XMin($1), ST_YMin($1), ST_ZMin($1)), ST_MakePoint(ST_XMax($1), ST_YMax($1), ST_ZMax($1)))) $_$; + + +-- +-- Name: ngv_box3dpolygon(box3d); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION ngv_box3dpolygon(box3d) RETURNS geometry + LANGUAGE sql + AS $_$ +SELECT ST_Collect(ARRAY[ + ST_MakePoint(ST_XMin($1), ST_YMin($1), ST_ZMin($1)), + ST_MakePoint(ST_XMax($1), ST_YMin($1), ST_ZMin($1)), + ST_MakePoint(ST_XMax($1), ST_YMax($1), ST_ZMin($1)), + ST_MakePoint(ST_XMin($1), ST_YMax($1), ST_ZMin($1)), + ST_MakePoint(ST_XMin($1), ST_YMin($1), ST_ZMax($1)), + ST_MakePoint(ST_XMax($1), ST_YMin($1), ST_ZMax($1)), + ST_MakePoint(ST_XMax($1), ST_YMax($1), ST_ZMax($1)), + ST_MakePoint(ST_XMin($1), ST_YMax($1), ST_ZMax($1))]) +$_$; + + +-- +-- Name: ngv_contract(box, integer, integer); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION ngv_contract(bbox box, width integer, height integer) RETURNS box + LANGUAGE sql + AS $$ + select box(point((bbox[0])[0] / width, (bbox[0])[1] / height), point((bbox[1])[0] / width, (bbox[1])[1] / height)); +$$; + + +-- +-- Name: ngv_expand(box, integer, integer); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION ngv_expand(bbox box, width integer, height integer) RETURNS box + LANGUAGE sql + AS $$ + select box(point((bbox[0])[0] * width, (bbox[0])[1] * height), point((bbox[1])[0] * width, (bbox[1])[1] * height)); +$$; + + +-- +-- Name: ngv_get_bytes(integer); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION ngv_get_bytes(id integer) RETURNS bytea + LANGUAGE sql + AS $$ +SELECT ngv_get_bytes(localpath, imagepath) FROM snapshots JOIN runs USING(run_id) where snapshot_id=id +$$; + + +-- +-- Name: ngv_get_raster(text, text); Type: FUNCTION; Schema: public; Owner: - +-- + +CREATE FUNCTION ngv_get_raster(archive text, image text) RETURNS raster + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN ST_FromGDALRaster(ngv_get_bytes(archive, image)); +END; +$$; + ``` ## Copying compiled files to GTA V From 6ea4c5e83a2cb02da172186ddda032dedf5e9a09 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 21 Jan 2018 20:00:37 +0100 Subject: [PATCH 077/158] wrapper for game pausing. No "info-" prefix for files, should result in easier handling. --- managed/GTAVisionExport/VisionExport.cs | 43 +++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 972a83e..9c61735 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -67,14 +67,12 @@ class VisionExport : Script private KeyHandling kh = new KeyHandling(); -// private ZipArchive archive; -// private Stream outStream; private Task postgresTask; private Task runTask; private int curSessionId = -1; private speedAndTime lowSpeedTime = new speedAndTime(); - private bool IsGamePaused = false; + private bool isGamePaused = false; // this is for external pause, not for internal pause inside the script private bool notificationsAllowed = true; private StereoCamera cams; private bool timeIntervalEnabled = false; @@ -221,6 +219,16 @@ private void handlePipeInput() this.timeTo = new TimeSpan(hoursTo, minutesTo, 0); UINotify("Time Interval Set"); break; + case "PAUSE": + UINotify("game paused"); + isGamePaused = true; + Game.Pause(true); + break; + case "UNPAUSE": + UINotify("game unpaused"); + isGamePaused = false; + Game.Pause(false); + break; // uncomment when resolving, how the hell should I get image by socket correctly // case "GET_SCREEN": // var last = ImageUtils.getLastCapturedFrame(); @@ -293,7 +301,7 @@ public void OnTick(object o, EventArgs e) try { - Game.Pause(true); + GamePause(true); Script.Wait(100); var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; GTAData dat; @@ -311,7 +319,7 @@ public void OnTick(object o, EventArgs e) if (dat == null) return; success = saveSnapshotToFile(dat.ImageName, weather); } - Game.Pause(false); + GamePause(false); if (!success) { // when getting data and saving to file failed, saving to db is skipped @@ -445,6 +453,15 @@ public void UINotify(string message) } } + public void GamePause(bool value) + { + //wraper for pausing and unpausing game, because if its paused, I don't want to pause it again and unpause it. + if (!isGamePaused) + { + Game.Pause(value); + } + } + public void EnterVehicle() { /* @@ -655,7 +672,7 @@ public void OnKeyDown(object o, KeyEventArgs k) UINotify("starting screenshots"); for (int i = 0; i < 5; i++) { - Game.Pause(true); + GamePause(true); Script.Wait(200); GTAData dat; @@ -672,7 +689,7 @@ public void OnKeyDown(object o, KeyEventArgs k) } PostgresExport.SaveSnapshot(dat, run.guid); - Game.Pause(false); + GamePause(false); Script.Wait(200); // hoping game will go on during this wait } StopRun(); @@ -691,7 +708,7 @@ private bool saveSnapshotToFile(String name, Weather[] weathers) { // returns true on success, and false on failure List colors = new List(); - Game.Pause(true); + GamePause(true); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); if (depth == null || stencil == null) @@ -710,9 +727,9 @@ private bool saveSnapshotToFile(String name, Weather[] weathers) colors.Add(color); } - Game.Pause(false); + GamePause(false); var res = Game.ScreenResolution; - var fileName = Path.Combine(dataPath, "info-" + name); + var fileName = Path.Combine(dataPath, name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil, false); // UINotify("file saved to: " + fileName); return true; @@ -721,7 +738,7 @@ private bool saveSnapshotToFile(String name, Weather[] weathers) private bool saveSnapshotToFile(String name, Weather weather) { // returns true on success, and false on failure - Game.Pause(true); + GamePause(true); World.TransitionToWeather(weather, 0.0f); Script.Wait(1); var depth = VisionNative.GetDepthBuffer(); @@ -732,9 +749,9 @@ private bool saveSnapshotToFile(String name, Weather weather) return false; } - Game.Pause(false); + GamePause(false); var res = Game.ScreenResolution; - var fileName = Path.Combine(dataPath, "info-" + name); + var fileName = Path.Combine(dataPath, name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, new List() {color}, depth, stencil, false); // UINotify("file saved to: " + fileName); return true; From e1363f3efe0da0a301442372f0f241a838fdecb4 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 25 Jan 2018 15:14:47 +0100 Subject: [PATCH 078/158] added velocity to both player and all detected entities --- managed/GTAVisionUtils/GTADataStructures.cs | 4 ++++ managed/GTAVisionUtils/PostgresExport.cs | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 091b4bf..3fdd2a8 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -102,6 +102,7 @@ public class GTADetection public GTABoundingBox2 BBox { get; set; } public BoundingBox BBox3D { get; set; } public int Handle { get; set; } + public GTAVector velocity { get; set; } public GTADetection(Entity e, DetectionType type) { Type = type; @@ -111,6 +112,7 @@ public GTADetection(Entity e, DetectionType type) Handle = e.Handle; Rot = new GTAVector(e.Rotation); + velocity = new GTAVector(e.Velocity); cls = DetectionClass.Unknown; Vector3 gmin; Vector3 gmax; @@ -190,6 +192,7 @@ public class GTAData public double CamNearClip { get; set; } public double CamFarClip { get; set; } public GTAVector playerPos { get; set; } + public GTAVector velocity { get; set; } public int UIHeight { get; set; } public int UIWidth { get; set; } @@ -328,6 +331,7 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.UIWidth = UI.WIDTH; ret.UIHeight = UI.HEIGHT; ret.playerPos = new GTAVector(Game.Player.Character.Position); + ret.velocity = new GTAVector(Game.Player.Character.Velocity); ret.CamNearClip = World.RenderingCamera.NearClip; ret.CamFarClip = World.RenderingCamera.FarClip; diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 78602c8..9c20ef3 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -186,9 +186,13 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Connection = conn; cmd.Transaction = trans; cmd.CommandText = - "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, cam_near_clip, cam_far_clip) " + + "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, " + + "camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, " + + "cam_near_clip, cam_far_clip, velocity) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + - "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip) " + + "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), " + + "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + + "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z)) " + "RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); @@ -212,6 +216,9 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters.AddWithValue("@player_x", data.playerPos.X); cmd.Parameters.AddWithValue("@player_y", data.playerPos.Y); cmd.Parameters.AddWithValue("@player_z", data.playerPos.Z); + cmd.Parameters.AddWithValue("@vel_x", data.velocity.X); + cmd.Parameters.AddWithValue("@vel_y", data.velocity.Y); + cmd.Parameters.AddWithValue("@vel_z", data.velocity.Z); cmd.Parameters.AddWithValue("@cam_near_clip", data.CamNearClip); cmd.Parameters.AddWithValue("@cam_far_clip", data.CamFarClip); cmd.Parameters.Add(new NpgsqlParameter("@guid", runId)); @@ -249,9 +256,9 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters.AddWithValue("@class", NpgsqlDbType.Enum, DetectionClass.Unknown); cmd.Parameters.Add("@handle", NpgsqlDbType.Integer); cmd.CommandText = - "INSERT INTO detections (snapshot_id, type, pos, rot, bbox, class, handle, bbox3d) VALUES " + + "INSERT INTO detections (snapshot_id, type, pos, rot, bbox, class, handle, bbox3d, velocity) VALUES " + "(@snapshot, @type, ST_MakePoint(@x,@y,@z), ST_MakePoint(@xrot, @yrot, @zrot), @bbox, @class, @handle," + - "ST_3DMakeBox(ST_MakePoint(@minx,@miny,@minz), ST_MakePoint(@maxx, @maxy, @maxz)));"; + "ST_3DMakeBox(ST_MakePoint(@minx,@miny,@minz), ST_MakePoint(@maxx, @maxy, @maxz), ST_MakePoint(@vel_x, @vel_y, @vel_z)));"; cmd.Prepare(); @@ -277,6 +284,10 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters["@maxy"].Value = detection.BBox3D.Maximum.Y; cmd.Parameters["@maxz"].Value = detection.BBox3D.Maximum.Z; + cmd.Parameters["@vel_x"].Value = detection.velocity.X; + cmd.Parameters["@vel_y"].Value = detection.velocity.Y; + cmd.Parameters["@vel_z"].Value = detection.velocity.Z; + cmd.ExecuteNonQuery(); } } From 0c789c7cf3efc6eec80c5145084471839924f5a9 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 25 Jan 2018 15:22:08 +0100 Subject: [PATCH 079/158] added new columns to database in readme --- managed/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/managed/README.md b/managed/README.md index f86a416..30c8ae0 100644 --- a/managed/README.md +++ b/managed/README.md @@ -60,7 +60,8 @@ create table detections bbox3d box3d, rot geometry, coverage real default 0.0, - created timestamp without time zone default (now() at time zone 'utc') + created timestamp without time zone default (now() at time zone 'utc'), + velocity GEOMETRY(PointZ) ) ; @@ -125,7 +126,8 @@ create table snapshots ui_height integer, cam_near_clip real, cam_far_clip real, - player_pos GEOMETRY(PointZ) + player_pos GEOMETRY(PointZ), + velocity GEOMETRY(PointZ) ) ; From a757d940238021e2668fe3ad26f9f675da3e8d55 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 26 Jan 2018 14:20:26 +0100 Subject: [PATCH 080/158] changed database --- managed/GTAVision.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVision.ini b/managed/GTAVision.ini index 9fdee4b..359c869 100644 --- a/managed/GTAVision.ini +++ b/managed/GTAVision.ini @@ -1,5 +1,5 @@ [Database] -ConnectionString=Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=postgres; +ConnectionString=Server=127.0.0.1;Port=5432;Database=gta_v;User Id=postgres;Password=postgres; [Snapshots] OutputDir=D:\GTAV_extraction_output\ LogFile=D:\GTAV_extraction_output\log.txt From 2c1bc9bb1902fc10745a6858bd057b70186561e3 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 26 Jan 2018 14:52:34 +0100 Subject: [PATCH 081/158] added other script for camera handling. Using correct camera, hopefully --- .../{TestVehicle.cs => CameraHandling.cs} | 4 +- .../GTAVisionExport/GTAVisionExport.csproj | 2 +- managed/GTAVisionExport/VisionExport.cs | 47 ++++++------------- managed/GTAVisionUtils/GTADataStructures.cs | 12 +++-- managed/GTAVisionUtils/PostgresExport.cs | 13 +++-- managed/README.md | 1 + 6 files changed, 33 insertions(+), 46 deletions(-) rename managed/GTAVisionExport/{TestVehicle.cs => CameraHandling.cs} (97%) diff --git a/managed/GTAVisionExport/TestVehicle.cs b/managed/GTAVisionExport/CameraHandling.cs similarity index 97% rename from managed/GTAVisionExport/TestVehicle.cs rename to managed/GTAVisionExport/CameraHandling.cs index 25967cd..e7a1927 100644 --- a/managed/GTAVisionExport/TestVehicle.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -13,12 +13,12 @@ namespace GTAVisionExport // P - mounts rendering camera on vehicle // O - restores the rendering camera to original control - public class TestVehicle : Script + public class CameraHandling : Script { // camera used on the vehicle Camera camera = null; - public TestVehicle() + public CameraHandling() { UI.Notify("Loaded TestVehicle.cs"); diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index 6a358fd..50afd0e 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -139,7 +139,7 @@ - + diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 5e15768..fb66f74 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -49,7 +49,6 @@ class VisionExport : Script //private readonly string dataPath = // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Data"); private readonly string dataPath; -<<<<<<< HEAD public static string logFilePath; private readonly Weather[] wantedWeathers = new Weather[] @@ -58,10 +57,6 @@ class VisionExport : Script private readonly Weather wantedWeather = Weather.Clear; private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one private readonly bool currentWeather = true; -======= - private readonly string logFilePath; - private readonly Weather[] wantedWeather = new Weather[] {Weather.Clear, Weather.Clouds, Weather.Overcast, Weather.Raining, Weather.Christmas}; ->>>>>>> origin/master private Player player; private string outputPath; private GTARun run; @@ -94,10 +89,7 @@ public VisionExport() //UINotify(ConfigurationManager.AppSettings["database_connection"]); dataPath = data["Snapshots"]["OutputDir"]; logFilePath = data["Snapshots"]["LogFile"]; -<<<<<<< HEAD Logger.setLogFilePath(logFilePath); -======= ->>>>>>> origin/master System.IO.File.WriteAllText(logFilePath, "VisionExport constructor called.\n"); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); @@ -113,7 +105,7 @@ public VisionExport() this.Tick += new EventHandler(this.OnTick); this.KeyDown += OnKeyDown; - Interval = 100; + Interval = 50; if (enabled) { postgresTask?.Wait(); @@ -125,17 +117,10 @@ public VisionExport() private void handlePipeInput() { -<<<<<<< HEAD Logger.writeLine("VisionExport handlePipeInput called."); UINotify("handlePipeInput called"); UINotify("server connected:" + server.Connected.ToString()); UINotify(connection == null ? "connection is null" : "connection:" + connection.ToString()); -======= - System.IO.File.AppendAllText(logFilePath, "VisionExport handlePipeInput called.\n"); - UI.Notify("handlePipeInput called"); - UI.Notify("server connected:" + server.Connected.ToString()); - UI.Notify(connection == null ? "connection is null" : "connection:" + connection.ToString()); ->>>>>>> origin/master if (connection == null) return; byte[] inBuffer = new byte[1024]; @@ -564,11 +549,7 @@ public void TraverseWeather() public void OnKeyDown(object o, KeyEventArgs k) { -<<<<<<< HEAD Logger.writeLine("VisionExport OnKeyDown called."); -======= - System.IO.File.AppendAllText(logFilePath, "VisionExport OnKeyDown called.\n"); ->>>>>>> origin/master if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); @@ -646,19 +627,19 @@ public void OnKeyDown(object o, KeyEventArgs k) { file.WriteLine("cam direction file"); file.WriteLine("direction:"); - file.WriteLine(GameplayCamera.Direction.X.ToString() + ' ' + - GameplayCamera.Direction.Y.ToString() + ' ' + - GameplayCamera.Direction.Z.ToString()); + file.WriteLine(World.RenderingCamera.Direction.X.ToString() + ' ' + + World.RenderingCamera.Direction.Y.ToString() + ' ' + + World.RenderingCamera.Direction.Z.ToString()); file.WriteLine("Dot Product:"); - file.WriteLine(Vector3.Dot(GameplayCamera.Direction, GameplayCamera.Rotation)); + file.WriteLine(Vector3.Dot(World.RenderingCamera.Direction, World.RenderingCamera.Rotation)); file.WriteLine("position:"); - file.WriteLine(GameplayCamera.Position.X.ToString() + ' ' + - GameplayCamera.Position.Y.ToString() + ' ' + - GameplayCamera.Position.Z.ToString()); + file.WriteLine(World.RenderingCamera.Position.X.ToString() + ' ' + + World.RenderingCamera.Position.Y.ToString() + ' ' + + World.RenderingCamera.Position.Z.ToString()); file.WriteLine("rotation:"); - file.WriteLine(GameplayCamera.Rotation.X.ToString() + ' ' + - GameplayCamera.Rotation.Y.ToString() + ' ' + - GameplayCamera.Rotation.Z.ToString()); + file.WriteLine(World.RenderingCamera.Rotation.X.ToString() + ' ' + + World.RenderingCamera.Rotation.Y.ToString() + ' ' + + World.RenderingCamera.Rotation.Z.ToString()); file.WriteLine("relative heading:"); file.WriteLine(GameplayCamera.RelativeHeading.ToString()); file.WriteLine("relative pitch:"); @@ -794,7 +775,7 @@ private void dumpTest() { var res = Game.ScreenResolution; ImageUtils.WriteToTiff(Path.Combine(dataPath, "test"), res.Width, res.Height, colors, depth, stencil); - UINotify(GameplayCamera.FieldOfView.ToString()); + UINotify(World.RenderingCamera.FieldOfView.ToString()); } else { @@ -803,4 +784,4 @@ private void dumpTest() UINotify((connection != null && connection.Connected).ToString()); } } -} \ No newline at end of file +} diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 3fdd2a8..435c85d 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -180,7 +180,8 @@ public class GTAData public TimeSpan LocalTime { get; set; } public Weather CurrentWeather { get; set; } public List CapturedWeathers; - public GTAVector Pos { get; set; } + public GTAVector CamPos { get; set; } + public GTAVector CamRot { get; set; } public GTAVector CamDirection { get; set; } //mathnet's matrices are in heap storage, which is super annoying, //but we want to use double matrices to avoid numerical issues as we @@ -283,7 +284,7 @@ public static GTABoundingBox2 ComputeBoundingBox(Entity e, Vector3 offset, float public static bool CheckVisible(Entity e) { // return true; - var ppos = GameplayCamera.Position; + var ppos = World.RenderingCamera.Position; var isLOS = Function.Call((GTA.Native.Hash) 0x0267D00AF114F17A, Game.Player.Character, e); if (isLOS) return true; // return isLOS; @@ -323,9 +324,10 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.Timestamp = DateTime.UtcNow; ret.LocalTime = World.CurrentDayTime; - ret.Pos = new GTAVector(GameplayCamera.Position); - ret.CamDirection = new GTAVector(GameplayCamera.Direction); - ret.CamFOV = GameplayCamera.FieldOfView; + ret.CamPos = new GTAVector(World.RenderingCamera.Position); + ret.CamRot = new GTAVector(World.RenderingCamera.Rotation); + ret.CamDirection = new GTAVector(World.RenderingCamera.Direction); + ret.CamFOV = World.RenderingCamera.FieldOfView; ret.ImageWidth = Game.ScreenResolution.Width; ret.ImageHeight = Game.ScreenResolution.Height; ret.UIWidth = UI.WIDTH; diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 9c20ef3..b977c0e 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -186,11 +186,11 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Connection = conn; cmd.Transaction = trans; cmd.CommandText = - "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, " + + "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_rot, " + "camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, " + "cam_near_clip, cam_far_clip, velocity) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + - "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), " + + "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@rotx, @roty, @rotz), " + "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z)) " + "RETURNING snapshot_id;"; @@ -199,9 +199,12 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters.Add(new NpgsqlParameter("@timestamp", data.Timestamp)); cmd.Parameters.Add(new NpgsqlParameter("@timeofday", data.LocalTime)); cmd.Parameters.Add(new NpgsqlParameter("@currentweather", data.CurrentWeather)); - cmd.Parameters.Add(new NpgsqlParameter("@x", data.Pos.X)); - cmd.Parameters.Add(new NpgsqlParameter("@y", data.Pos.Y)); - cmd.Parameters.Add(new NpgsqlParameter("@z", data.Pos.Z)); + cmd.Parameters.Add(new NpgsqlParameter("@x", data.CamPos.X)); + cmd.Parameters.Add(new NpgsqlParameter("@y", data.CamPos.Y)); + cmd.Parameters.Add(new NpgsqlParameter("@z", data.CamPos.Z)); + cmd.Parameters.Add(new NpgsqlParameter("@rotx", data.CamRot.X)); + cmd.Parameters.Add(new NpgsqlParameter("@roty", data.CamRot.Y)); + cmd.Parameters.Add(new NpgsqlParameter("@rotz", data.CamRot.Z)); cmd.Parameters.AddWithValue("@dirx", data.CamDirection.X); cmd.Parameters.AddWithValue("@diry", data.CamDirection.Y); cmd.Parameters.AddWithValue("@dirz", data.CamDirection.Z); diff --git a/managed/README.md b/managed/README.md index 30c8ae0..13fb591 100644 --- a/managed/README.md +++ b/managed/README.md @@ -115,6 +115,7 @@ create table snapshots timeofday time, currentweather weather, camera_pos geometry(PointZ), + camera_rot geometry(PointZ), camera_direction geometry, camera_fov real, view_matrix double precision[], From 733d54b4dbccef65041825028393f5e012822928 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 26 Jan 2018 15:09:27 +0100 Subject: [PATCH 082/158] detection sql bugfix --- managed/GTAVisionUtils/PostgresExport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index b977c0e..010fd26 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -261,7 +261,7 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.CommandText = "INSERT INTO detections (snapshot_id, type, pos, rot, bbox, class, handle, bbox3d, velocity) VALUES " + "(@snapshot, @type, ST_MakePoint(@x,@y,@z), ST_MakePoint(@xrot, @yrot, @zrot), @bbox, @class, @handle," + - "ST_3DMakeBox(ST_MakePoint(@minx,@miny,@minz), ST_MakePoint(@maxx, @maxy, @maxz), ST_MakePoint(@vel_x, @vel_y, @vel_z)));"; + "ST_3DMakeBox(ST_MakePoint(@minx,@miny,@minz), ST_MakePoint(@maxx, @maxy, @maxz)), ST_MakePoint(@vel_x, @vel_y, @vel_z))"; cmd.Prepare(); From 3bb8540318eb01988f8b7d3c8099cabe7e0760d8 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 26 Jan 2018 15:20:36 +0100 Subject: [PATCH 083/158] added values for velocity --- managed/GTAVisionUtils/PostgresExport.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 010fd26..ece900f 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -256,6 +256,9 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters.Add("@maxx", NpgsqlDbType.Real); cmd.Parameters.Add("@maxy", NpgsqlDbType.Real); cmd.Parameters.Add("@maxz", NpgsqlDbType.Real); + cmd.Parameters.Add("@vel_x", NpgsqlDbType.Real); + cmd.Parameters.Add("@vel_y", NpgsqlDbType.Real); + cmd.Parameters.Add("@vel_z", NpgsqlDbType.Real); cmd.Parameters.AddWithValue("@class", NpgsqlDbType.Enum, DetectionClass.Unknown); cmd.Parameters.Add("@handle", NpgsqlDbType.Integer); cmd.CommandText = From d140c29a6ed8b4cd3fcdf45f63b7e7099394d00c Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 29 Jan 2018 17:11:30 +0100 Subject: [PATCH 084/158] all entities are put to db, not only visible ones. Increased range for entities --- managed/GTAVisionUtils/GTADataStructures.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 435c85d..dbd0767 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -337,8 +337,8 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.CamNearClip = World.RenderingCamera.NearClip; ret.CamFarClip = World.RenderingCamera.FarClip; - var peds = World.GetNearbyPeds(Game.Player.Character, 150.0f); - var cars = World.GetNearbyVehicles(Game.Player.Character, 150.0f); + var peds = World.GetNearbyPeds(Game.Player.Character, 500.0f); + var cars = World.GetNearbyVehicles(Game.Player.Character, 500.0f); //var props = World.GetNearbyProps(Game.Player.Character.Position, 300.0f); var constants = VisionNative.GetConstants(); @@ -357,16 +357,16 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.ViewMatrix = V as DenseMatrix; var pedList = from ped in peds -// where ped.IsHuman && ped.IsOnFoot - where ped.IsHuman && ped.IsOnFoot && CheckVisible(ped) + where ped.IsHuman && ped.IsOnFoot +// where ped.IsHuman && ped.IsOnFoot && CheckVisible(ped) select new GTADetection(ped); var cycles = from ped in peds -// where ped.IsOnBike - where ped.IsOnBike && CheckVisible(ped) + where ped.IsOnBike +// where ped.IsOnBike && CheckVisible(ped) select new GTADetection(ped, DetectionType.bicycle); var vehicleList = from car in cars - where CheckVisible(car) +// where CheckVisible(car) select new GTADetection(car); ret.Detections = new List(); ret.Detections.AddRange(pedList); From 7be1f0b137924100aeea1d4e4e82f0b54cc866d2 Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 29 Jan 2018 17:25:32 +0100 Subject: [PATCH 085/158] added some modifications --- managed/GTAVisionExport/VisionExport.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index fb66f74..4d01002 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -505,6 +505,16 @@ public void ToggleNavigation() inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } + private void ClearSurroundingVehicles(float x, float y, float z, float radius) + { + Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, x, y, z, radius, false, false, false, false); + } + + private void ClearSurroundingEverything(float x, float y, float z, float radius) + { + Function.Call(GTA.Native.Hash.CLEAR_AREA, x, y, z, radius, false, false, false, false); + } + public void ReloadGame() { /* @@ -522,13 +532,13 @@ public void ReloadGame() //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.X, player.Position.Y, player.Position.Z, 1000f); Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, player.Position.Z, 1000f, false, false, false, false); player.LastVehicle.Delete(); // teleport to the spawning position, defined in GameUtils.cs, subject to changes player.Position = GTAConst.StartPos; - Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, - player.Position.Z, 100f, false, false, false, false); + ClearSurroundingVehicles(player.Position.X, player.Position.Y, player.Position.Z, 100f); // start a new run EnterVehicle(); //Script.Wait(2000); @@ -557,6 +567,8 @@ public void OnKeyDown(object o, KeyEventArgs k) runTask?.Wait(); runTask = StartRun(); UINotify("GTA Vision Enabled"); +// there is set weather, just for testing + World.Weather = wantedWeather; } if (k.KeyCode == Keys.PageDown) { @@ -739,7 +751,7 @@ private bool saveSnapshotToFile(String name, Weather weather) { // returns true on success, and false on failure GamePause(true); - World.TransitionToWeather(weather, 0.0f); +// World.TransitionToWeather(weather, 0.0f); //trying to set weather only in the beginning, because of depth =/= RGB Script.Wait(1); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); From cee1f90f688e6253fae9fb052bac34d87176eef8 Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 29 Jan 2018 17:28:42 +0100 Subject: [PATCH 086/158] added posibility of clearing everything --- managed/GTAVisionExport/VisionExport.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 4d01002..4bc6d82 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -57,6 +57,7 @@ class VisionExport : Script private readonly Weather wantedWeather = Weather.Clear; private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one private readonly bool currentWeather = true; + private readonly bool clearEverything = false; private Player player; private string outputPath; private GTARun run; @@ -303,6 +304,10 @@ public void OnTick(object o, EventArgs e) { GamePause(true); Script.Wait(100); + if (clearEverything) + { + ClearSurroundingEverything(Game.Player.Character.Position, 1000f); + } var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; GTAData dat; bool success; @@ -505,10 +510,20 @@ public void ToggleNavigation() inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } + private void ClearSurroundingVehicles(Vector3 pos, float radius) + { + ClearSurroundingVehicles(pos.X, pos.Y, pos.Z, radius); + } + private void ClearSurroundingVehicles(float x, float y, float z, float radius) { Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, x, y, z, radius, false, false, false, false); } + + private void ClearSurroundingEverything(Vector3 pos, float radius) + { + ClearSurroundingEverything(pos.X, pos.Y, pos.Z, radius); + } private void ClearSurroundingEverything(float x, float y, float z, float radius) { @@ -532,13 +547,13 @@ public void ReloadGame() //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.X, player.Position.Y, player.Position.Z, 1000f); + ClearSurroundingVehicles(player.Position, 1000f); Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, player.Position.Z, 1000f, false, false, false, false); player.LastVehicle.Delete(); // teleport to the spawning position, defined in GameUtils.cs, subject to changes player.Position = GTAConst.StartPos; - ClearSurroundingVehicles(player.Position.X, player.Position.Y, player.Position.Z, 100f); + ClearSurroundingVehicles(player.Position, 100f); // start a new run EnterVehicle(); //Script.Wait(2000); From 5b8b898cee7e8112c18cfd06102c33254237a0b5 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 6 Feb 2018 15:04:18 +0100 Subject: [PATCH 087/158] added new cameras --- managed/GTAVisionExport/CameraHandling.cs | 74 ++++++++++++++++--- managed/GTAVisionExport/CamerasList.cs | 48 ++++++++++++ .../GTAVisionExport/GTAVisionExport.csproj | 1 + managed/GTAVisionExport/VisionExport.cs | 13 +++- 4 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 managed/GTAVisionExport/CamerasList.cs diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index e7a1927..32ac897 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.Windows.Forms; using System.Collections.Generic; +using System.Linq; using GTA; using GTA.Native; using GTA.Math; @@ -16,7 +17,10 @@ namespace GTAVisionExport public class CameraHandling : Script { // camera used on the vehicle - Camera camera = null; + Camera mainCamera = null; + Camera[] cameras = null; + private bool enabled = false; + private int activeCameraIndex = -1; public CameraHandling() { @@ -24,9 +28,9 @@ public CameraHandling() // create a new camera World.DestroyAllCameras(); - camera = World.CreateCamera(new Vector3(), new Vector3(), 50); - camera.IsActive = true; - GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, false, true, camera.Handle, true, true); + mainCamera = World.CreateCamera(new Vector3(), new Vector3(), 50); + mainCamera.IsActive = true; + World.RenderingCamera = mainCamera; // attach time methods Tick += OnTick; @@ -38,7 +42,16 @@ public void mountCameraOnVehicle() { if (Game.Player.Character.IsInVehicle()) { - GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, true, true, camera.Handle, true, true); +// void RENDER_SCRIPT_CAMS(BOOL render, BOOL ease, int easeTime, BOOL p3, +// BOOL p4) // 0x07E5B515DB0636FC 0x74337969 + if (activeCameraIndex == -1) + { + World.RenderingCamera = mainCamera; + } + else + { + World.RenderingCamera = cameras[activeCameraIndex]; + } } else { @@ -50,19 +63,28 @@ public void mountCameraOnVehicle() public void restoreCamera() { UI.Notify("Relinquishing control"); - GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, false, false, camera.Handle, true, true); + mainCamera.IsActive = false; + World.RenderingCamera = mainCamera; } // Function used to keep camera on vehicle and facing forward on each tick step. public void keepCameraOnVehicle() { - if (Game.Player.Character.IsInVehicle()) + if (Game.Player.Character.IsInVehicle() && enabled) { // keep the camera in the same position relative to the car - camera.AttachTo(Game.Player.Character.CurrentVehicle, new Vector3(0f, 2f, 0.4f)); + mainCamera.AttachTo(Game.Player.Character.CurrentVehicle, CamerasList.mainCamera.Value); // rotate the camera to face the same direction as the car - camera.Rotation = Game.Player.Character.CurrentVehicle.Rotation; + mainCamera.Rotation = Game.Player.Character.CurrentVehicle.Rotation; + } + + if (Game.Player.Character.IsInVehicle() && enabled) + { + for (int i = 0; i < cameras.Length; i++) + { + CamerasList.ActivateCamera(i); + } } } @@ -71,13 +93,47 @@ private void onKeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.P) { + activeCameraIndex = -1; mountCameraOnVehicle(); + enabled = true; } if (e.KeyCode == Keys.O) { restoreCamera(); + enabled = false; } + + if (e.KeyCode == Keys.NumPad0) + { + activeCameraIndex = 0; + mountCameraOnVehicle(); + } + + if (e.KeyCode == Keys.NumPad1) + { + activeCameraIndex = 0; + mountCameraOnVehicle(); + } + + if (e.KeyCode == Keys.NumPad2) + { + activeCameraIndex = 0; + mountCameraOnVehicle(); + } + + if (e.KeyCode == Keys.NumPad3) + { + activeCameraIndex = 0; + mountCameraOnVehicle(); + } + + if (e.KeyCode == Keys.Decimal) + { + activeCameraIndex = -1; + mountCameraOnVehicle(); + } + } void OnTick(object sender, EventArgs e) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs new file mode 100644 index 0000000..a154de6 --- /dev/null +++ b/managed/GTAVisionExport/CamerasList.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GTA; +using GTA.Math; + +namespace GTAVisionExport { + public static class CamerasList + { + public static Vector3? mainCamera { get; set; } = null; + public static List cameras { get; set; } = new List(); + public static List camerasPositions { get; set; } = new List(); + public static List camerasRotations { get; set; } = new List(); + private static Camera gameCam; + + static CamerasList() + { + gameCam = World.RenderingCamera; + } + + public static void addCamera(Vector3 position, Vector3 rotation) + { + var newCamera = World.CreateCamera(new Vector3(), new Vector3(), GameplayCamera.FieldOfView); + cameras.Add(newCamera); + camerasPositions.Add(position); + camerasRotations.Add(rotation); + } + + public static void ActivateCamera(int i) + { + cameras[i].IsActive = true; + World.RenderingCamera = cameras[i]; + cameras[i].AttachTo(Game.Player.Character.CurrentVehicle, camerasPositions[i]); + cameras[i].Rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; + } + + public static void Deactivate() + { + foreach (var camera in cameras) + { + camera.IsActive = false; + } + World.RenderingCamera = gameCam; + } + } +} diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index 50afd0e..7c47e80 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -136,6 +136,7 @@ + diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 4bc6d82..fb4bc59 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -58,6 +58,7 @@ class VisionExport : Script private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one private readonly bool currentWeather = true; private readonly bool clearEverything = false; + private readonly bool useMultipleCameras = true; private Player player; private string outputPath; private GTARun run; @@ -114,6 +115,14 @@ public VisionExport() runTask?.Wait(); runTask = StartRun(); } + +// cameras initialization: + float r = 5f; //radius of circle with 4 cameras + CamerasList.mainCamera = new Vector3(0f, 2f, 0.4f); + CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f)); + CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f)); + CamerasList.addCamera(new Vector3(2*r, 2f, 0.4f), new Vector3(0f, 0f, 180f)); + CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f)); } private void handlePipeInput() @@ -766,8 +775,8 @@ private bool saveSnapshotToFile(String name, Weather weather) { // returns true on success, and false on failure GamePause(true); -// World.TransitionToWeather(weather, 0.0f); //trying to set weather only in the beginning, because of depth =/= RGB - Script.Wait(1); + World.TransitionToWeather(weather, 0.0f); //trying to set weather only in the beginning, because of depth =/= RGB + Script.Wait(10); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); var color = VisionNative.GetColorBuffer(); From a55447978a2b118408f40544907129c5c9ff9fc1 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 6 Feb 2018 16:38:05 +0100 Subject: [PATCH 088/158] created setup for multiple cameras --- managed/GTAVisionExport/VisionExport.cs | 355 +++++++++----------- managed/GTAVisionUtils/GTADataStructures.cs | 1 + managed/GTAVisionUtils/PostgresExport.cs | 125 +++---- managed/README.md | 1 + 4 files changed, 222 insertions(+), 260 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index fb4bc59..570e03a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -37,10 +37,8 @@ using IniParser; using Newtonsoft.Json; -namespace GTAVisionExport -{ - class VisionExport : Script - { +namespace GTAVisionExport { + class VisionExport : Script { #if DEBUG const string session_name = "NEW_DATA_CAPTURE_NATURAL_V4_3"; #else @@ -74,15 +72,14 @@ class VisionExport : Script private Task runTask; private int curSessionId = -1; private speedAndTime lowSpeedTime = new speedAndTime(); - private bool isGamePaused = false; // this is for external pause, not for internal pause inside the script + private bool isGamePaused = false; // this is for external pause, not for internal pause inside the script private bool notificationsAllowed = true; private StereoCamera cams; private bool timeIntervalEnabled = false; private TimeSpan timeFrom; private TimeSpan timeTo; - public VisionExport() - { + public VisionExport() { // loading ini file var parser = new FileIniDataParser(); var location = AppDomain.CurrentDomain.BaseDirectory; @@ -108,25 +105,23 @@ public VisionExport() this.KeyDown += OnKeyDown; Interval = 50; - if (enabled) - { + if (enabled) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); } - + // cameras initialization: - float r = 5f; //radius of circle with 4 cameras + float r = 5f; //radius of circle with 4 cameras CamerasList.mainCamera = new Vector3(0f, 2f, 0.4f); CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f)); CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f)); - CamerasList.addCamera(new Vector3(2*r, 2f, 0.4f), new Vector3(0f, 0f, 180f)); + CamerasList.addCamera(new Vector3(2 * r, 2f, 0.4f), new Vector3(0f, 0f, 180f)); CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f)); } - private void handlePipeInput() - { + private void handlePipeInput() { Logger.writeLine("VisionExport handlePipeInput called."); UINotify("handlePipeInput called"); UINotify("server connected:" + server.Connected.ToString()); @@ -136,31 +131,29 @@ private void handlePipeInput() byte[] inBuffer = new byte[1024]; string str = ""; int num = 0; - try - { + try { num = connection.Receive(inBuffer); str = encoding.GetString(inBuffer, 0, num); } - catch (SocketException e) - { - if (e.SocketErrorCode == SocketError.WouldBlock) - { + catch (SocketException e) { + if (e.SocketErrorCode == SocketError.WouldBlock) { return; } + throw; } - if (num == 0) - { + + if (num == 0) { connection.Shutdown(SocketShutdown.Both); connection.Close(); connection = null; return; } + UINotify("str: " + str.ToString()); dynamic parameters = JsonConvert.DeserializeObject(str); string commandName = parameters.name; - switch (commandName) - { + switch (commandName) { case "START_SESSION": postgresTask?.Wait(); postgresTask = StartSession(); @@ -202,17 +195,16 @@ private void handlePipeInput() UINotify("Time Set"); break; case "SET_WEATHER": - try - { + try { string weather = parameters.weather; UINotify("Weather Set to " + weather.ToString()); Weather weatherEnum = (Weather) Enum.Parse(typeof(Weather), weather); GTA.World.Weather = weatherEnum; } - catch (Exception e) - { + catch (Exception e) { Logger.writeLine(e); } + break; case "SET_TIME_INTERVAL": string timeFrom = parameters.timeFrom; @@ -251,8 +243,7 @@ private void handlePipeInput() } } - public void startRunAndSessionManual() - { + public void startRunAndSessionManual() { // this method does not enable mod (used for manual data gathering) postgresTask?.Wait(); postgresTask = StartSession(); @@ -260,22 +251,20 @@ public void startRunAndSessionManual() runTask = StartRun(false); } - public void OnTick(object o, EventArgs e) - { - if (server.Poll(10, SelectMode.SelectRead) && connection == null) - { + 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()) - { + switch (checkStatus()) { case GameStatus.NeedReload: //TODO: need to get a new session and run? StopRun(); @@ -302,6 +291,7 @@ public void OnTick(object o, EventArgs e) case GameStatus.NoActionNeeded: break; } + // UINotify("runTask.IsCompleted: " + runTask.IsCompleted.ToString()); // UINotify("postgresTask.IsCompleted: " + postgresTask.IsCompleted.ToString()); if (!runTask.IsCompleted) return; @@ -309,85 +299,104 @@ public void OnTick(object o, EventArgs e) // UINotify("going to save images and save to postgres"); - try - { + try { GamePause(true); - Script.Wait(100); - if (clearEverything) - { - ClearSurroundingEverything(Game.Player.Character.Position, 1000f); - } - var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; - GTAData dat; - bool success; - if (multipleWeathers) - { - dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); - if (dat == null) return; - success = saveSnapshotToFile(dat.ImageName, wantedWeathers); - } - else - { - Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; - dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); - if (dat == null) return; - success = saveSnapshotToFile(dat.ImageName, weather); - } + gatherData(); GamePause(false); - if (!success) - { -// when getting data and saving to file failed, saving to db is skipped - return; - } - PostgresExport.SaveSnapshot(dat, run.guid); } - catch (Exception exception) - { + 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) - { + if (timeIntervalEnabled) { var currentTime = GTA.World.CurrentDayTime; - if (currentTime > timeTo) - { + if (currentTime > timeTo) { GTA.World.CurrentDayTime = timeFrom; } } } + private void gatherData() { + if (clearEverything) { + ClearSurroundingEverything(Game.Player.Character.Position, 1000f); + } + + Script.Wait(100); + + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; + var guid = Guid.NewGuid(); + + if (useMultipleCameras) { + for (int i = 0; i < CamerasList.cameras.Count; i++) { + CamerasList.ActivateCamera(i); + gatherDatForOneCamera(dateTimeFormat, guid); + Script.Wait(5); + } + } + else { + gatherDatForOneCamera(dateTimeFormat, guid); + } + } + + private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { + GTAData dat; + bool success; + if (multipleWeathers) { + dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); + } + else { + Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; + dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); + } + + if (dat == null) { + return; + } + + if (multipleWeathers) { + success = saveSnapshotToFile(dat.ImageName, wantedWeathers); + } + else { + Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; + success = saveSnapshotToFile(dat.ImageName, weather); + } + + if (!success) { +// when getting data and saving to file failed, saving to db is skipped + return; + } + + PostgresExport.SaveSnapshot(dat, run.guid); + } + /* -1 = need restart, 0 = normal, 1 = need to enter vehicle */ - public GameStatus checkStatus() - { + public GameStatus checkStatus() { Ped player = Game.Player.Character; if (player.IsDead) return GameStatus.NeedReload; - if (player.IsInVehicle()) - { + if (player.IsInVehicle()) { Vehicle vehicle = player.CurrentVehicle; //UINotify("T:" + Game.GameTime.ToString() + " S: " + vehicle.Speed.ToString()); if (vehicle.Speed < 1.0f) //speed is in mph { - if (lowSpeedTime.checkTrafficJam(Game.GameTime, vehicle.Speed)) - { + if (lowSpeedTime.checkTrafficJam(Game.GameTime, vehicle.Speed)) { return GameStatus.NeedReload; } } - else - { + else { lowSpeedTime.clearTime(); } + return GameStatus.NoActionNeeded; } - else - { + else { return GameStatus.NeedReload; } } - public Bitmap CaptureScreen() - { + public Bitmap CaptureScreen() { UINotify("CaptureScreen called"); var cap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); var gfx = Graphics.FromImage(cap); @@ -409,8 +418,7 @@ public Bitmap CaptureScreen() //cap.Save(GetFileName(".png"), ImageFormat.Png); } - public void Autostart() - { + public void Autostart() { EnterVehicle(); Script.Wait(200); ToggleNavigation(); @@ -419,35 +427,30 @@ public void Autostart() postgresTask = StartSession(); } - public async Task StartSession(string name = session_name) - { + public async Task StartSession(string name = session_name) { if (name == null) name = Guid.NewGuid().ToString(); if (curSessionId != -1) StopSession(); int id = await PostgresExport.StartSession(name); curSessionId = id; } - public void StopSession() - { + public void StopSession() { if (curSessionId == -1) return; PostgresExport.StopSession(curSessionId); curSessionId = -1; } - public async Task StartRun(bool enable = true) - { + public async Task StartRun(bool enable = true) { await postgresTask; if (run != null) PostgresExport.StopRun(run); var runid = await PostgresExport.StartRun(curSessionId); run = runid; - if (enable) - { - enabled = true; + if (enable) { + enabled = true; } } - public void StopRun() - { + public void StopRun() { runTask?.Wait(); ImageUtils.WaitForProcessing(); enabled = false; @@ -458,59 +461,52 @@ public void StopRun() Game.Player.LastVehicle.Alpha = int.MaxValue; } - public void UINotify(string message) - { + public void UINotify(string message) { //just wrapper for UI.Notify, but lets us disable showing notifications ar all - if (notificationsAllowed) - { + if (notificationsAllowed) { UI.Notify(message); } } - public void GamePause(bool value) - { + public void GamePause(bool value) { //wraper for pausing and unpausing game, because if its paused, I don't want to pause it again and unpause it. - if (!isGamePaused) - { + if (!isGamePaused) { Game.Pause(value); } } - public void EnterVehicle() - { + public void EnterVehicle() { /* var vehicle = World.GetClosestVehicle(player.Character.Position, 30f); player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); */ Model mod = new Model(GTA.Native.VehicleHash.Asea); - if (mod == null) - { + if (mod == null) { UINotify("mod is null"); } - if (player == null) - { + + if (player == null) { UINotify("player is null"); } - if (player.Character == null) - { + + if (player.Character == null) { UINotify("player.Character is null"); } + UINotify("player position: " + player.Character.Position.ToString()); var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); - if (vehicle == null) - { + if (vehicle == null) { UINotify("vehicle is null. Something is fucked up"); } - else - { + else { player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); } + //vehicle.Alpha = 0; //transparent //player.Character.Alpha = 0; } - public void ToggleNavigation() - { + public void ToggleNavigation() { //todo: probably here try to set camera, maybe by SET_FOLLOW_VEHICLE_CAM_VIEW_MODE(int viewMode), or by SET_FOLLOW_VEHICLE_CAM_ZOOM_LEVEL(int zoomLevel) // or just something with the GTA.GameplayCamera //YOLO @@ -519,28 +515,23 @@ public void ToggleNavigation() inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } - private void ClearSurroundingVehicles(Vector3 pos, float radius) - { + private void ClearSurroundingVehicles(Vector3 pos, float radius) { ClearSurroundingVehicles(pos.X, pos.Y, pos.Z, radius); } - - private void ClearSurroundingVehicles(float x, float y, float z, float radius) - { - Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, x, y, z, radius, false, false, false, false); + + private void ClearSurroundingVehicles(float x, float y, float z, float radius) { + Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, x, y, z, radius, false, false, false, false); } - private void ClearSurroundingEverything(Vector3 pos, float radius) - { + private void ClearSurroundingEverything(Vector3 pos, float radius) { ClearSurroundingEverything(pos.X, pos.Y, pos.Z, radius); } - - private void ClearSurroundingEverything(float x, float y, float z, float radius) - { - Function.Call(GTA.Native.Hash.CLEAR_AREA, x, y, z, radius, false, false, false, false); + + private void ClearSurroundingEverything(float x, float y, float z, float radius) { + Function.Call(GTA.Native.Hash.CLEAR_AREA, x, y, z, radius, false, false, false, false); } - - public void ReloadGame() - { + + public void ReloadGame() { /* Process p = Process.GetProcessesByName("Grand Theft Auto V").FirstOrDefault(); if (p != null) @@ -571,21 +562,17 @@ public void ReloadGame() lowSpeedTime.clearTime(); } - public void TraverseWeather() - { - for (int i = 1; i < 14; i++) - { + public void TraverseWeather() { + for (int i = 1; i < 14; i++) { //World.Weather = (Weather)i; World.TransitionToWeather((Weather) i, 0.0f); //Script.Wait(1000); } } - public void OnKeyDown(object o, KeyEventArgs k) - { + public void OnKeyDown(object o, KeyEventArgs k) { Logger.writeLine("VisionExport OnKeyDown called."); - if (k.KeyCode == Keys.PageUp) - { + if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); @@ -594,34 +581,36 @@ public void OnKeyDown(object o, KeyEventArgs k) // there is set weather, just for testing World.Weather = wantedWeather; } - if (k.KeyCode == Keys.PageDown) - { + + if (k.KeyCode == Keys.PageDown) { StopRun(); StopSession(); UINotify("GTA Vision Disabled"); } + if (k.KeyCode == Keys.H) // temp modification { EnterVehicle(); UINotify("Trying to enter vehicle"); ToggleNavigation(); } + if (k.KeyCode == Keys.Y) // temp modification { ReloadGame(); } + if (k.KeyCode == Keys.X) // temp modification { notificationsAllowed = !notificationsAllowed; - if (notificationsAllowed) - { + if (notificationsAllowed) { UI.Notify("Notifications Enabled"); } - else - { + else { UI.Notify("Notifications Disabled"); } } + if (k.KeyCode == Keys.U) // temp modification { var settings = ScriptSettings.Load("GTAVisionExport.xml"); @@ -632,6 +621,7 @@ public void OnKeyDown(object o, KeyEventArgs k) UINotify("BaseDirectory: " + loc); UINotify("ConnectionString: " + str); } + if (k.KeyCode == Keys.G) // temp modification { /* @@ -644,23 +634,19 @@ public void OnKeyDown(object o, KeyEventArgs k) Game.Pause(false); */ GTAData data; - if (multipleWeathers) - { + if (multipleWeathers) { data = GTAData.DumpData(Game.GameTime + ".tiff", wantedWeathers.ToList()); } - else - { + 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)) - { + if (!File.Exists(path)) { // Create a file to write to. - using (StreamWriter file = File.CreateText(path)) - { + using (StreamWriter file = File.CreateText(path)) { file.WriteLine("cam direction file"); file.WriteLine("direction:"); file.WriteLine(World.RenderingCamera.Direction.X.ToString() + ' ' + @@ -697,8 +683,7 @@ public void OnKeyDown(object o, KeyEventArgs k) //Script.Wait(5000); } - if (k.KeyCode == Keys.N) - { + if (k.KeyCode == Keys.N) { UINotify("N pressed, going to take screenshots"); startRunAndSessionManual(); @@ -706,19 +691,16 @@ public void OnKeyDown(object o, KeyEventArgs k) runTask?.Wait(); var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; UINotify("starting screenshots"); - for (int i = 0; i < 5; i++) - { + for (int i = 0; i < 5; i++) { GamePause(true); Script.Wait(200); GTAData dat; - if (multipleWeathers) - { + if (multipleWeathers) { dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); saveSnapshotToFile(dat.ImageName, wantedWeathers); } - else - { + else { Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); saveSnapshotToFile(dat.ImageName, weather); @@ -728,38 +710,36 @@ public void OnKeyDown(object o, KeyEventArgs k) GamePause(false); Script.Wait(200); // hoping game will go on during this wait } + StopRun(); StopSession(); } - - if (k.KeyCode == Keys.I) - { + + if (k.KeyCode == Keys.I) { var info = new GTAVisionUtils.InstanceData(); UINotify(info.type); UINotify(info.publichostname); } } - private bool saveSnapshotToFile(String name, Weather[] weathers) - { + private bool saveSnapshotToFile(String name, Weather[] weathers) { // returns true on success, and false on failure List colors = new List(); GamePause(true); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); - if (depth == null || stencil == null) - { + if (depth == null || stencil == null) { return false; } - foreach (var wea in weathers) - { + + foreach (var wea in weathers) { World.TransitionToWeather(wea, 0.0f); Script.Wait(1); var color = VisionNative.GetColorBuffer(); - if (color == null) - { + if (color == null) { return false; } + colors.Add(color); } @@ -771,17 +751,16 @@ private bool saveSnapshotToFile(String name, Weather[] weathers) return true; } - private bool saveSnapshotToFile(String name, Weather weather) - { + private bool saveSnapshotToFile(String name, Weather weather) { // returns true on success, and false on failure GamePause(true); - World.TransitionToWeather(weather, 0.0f); //trying to set weather only in the beginning, because of depth =/= RGB + World.TransitionToWeather(weather, + 0.0f); //trying to set weather only in the beginning, because of depth =/= RGB Script.Wait(10); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); var color = VisionNative.GetColorBuffer(); - if (depth == null || stencil == null || color == null) - { + if (depth == null || stencil == null || color == null) { return false; } @@ -793,31 +772,29 @@ private bool saveSnapshotToFile(String name, Weather weather) return true; } - private void dumpTest() - { + private void dumpTest() { List colors = new List(); Game.Pause(true); Script.Wait(1); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); - foreach (var wea in wantedWeathers) - { + foreach (var wea in wantedWeathers) { World.TransitionToWeather(wea, 0.0f); Script.Wait(1); colors.Add(VisionNative.GetColorBuffer()); } + Game.Pause(false); - if (depth != null) - { + if (depth != null) { var res = Game.ScreenResolution; ImageUtils.WriteToTiff(Path.Combine(dataPath, "test"), res.Width, res.Height, colors, depth, stencil); UINotify(World.RenderingCamera.FieldOfView.ToString()); } - else - { + else { UINotify("No Depth Data quite yet"); } + UINotify((connection != null && connection.Connected).ToString()); } } -} +} \ No newline at end of file diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index dbd0767..7d16851 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -196,6 +196,7 @@ public class GTAData public GTAVector velocity { get; set; } public int UIHeight { get; set; } public int UIWidth { get; set; } + public Guid sceneGuid { get; set; } public List Detections { get; set; } public static SharpDX.Vector3 CvtVec(GTA.Math.Vector3 inp) { diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index ece900f..8dc72ec 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -14,36 +14,32 @@ using NpgsqlTypes; using System.Reflection; using IniParser; + namespace GTAVisionUtils { - public class PostgresExport { - - public static void InitSQLTypes() - { + public static void InitSQLTypes() { NpgsqlConnection.MapEnumGlobally("weather", new NpgsqlNullNameTranslator()); NpgsqlConnection.MapEnumGlobally(); - NpgsqlConnection.MapEnumGlobally(pgName: "detection_class", nameTranslator: new NpgsqlNullNameTranslator()); + NpgsqlConnection.MapEnumGlobally(pgName: "detection_class", + nameTranslator: new NpgsqlNullNameTranslator()); } - - public static NpgsqlConnection OpenConnection() - { + + public static NpgsqlConnection OpenConnection() { var parser = new FileIniDataParser(); var location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); var str = data["Database"]["ConnectionString"]; - + var conn = new NpgsqlConnection(str); conn.Open(); return conn; } - public static Guid InsertSystemData(NpgsqlConnection conn) - { + public static Guid InsertSystemData(NpgsqlConnection conn) { var systemInfo = new WMIInformation(); - using (var cmd = new NpgsqlCommand()) - { + using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.Parameters.AddWithValue("@system_uuid", systemInfo.system_uuid); cmd.Parameters.AddWithValue("@vendor", systemInfo.vendor); @@ -58,141 +54,128 @@ public static Guid InsertSystemData(NpgsqlConnection conn) return Guid.Parse(cmd.ExecuteScalar().ToString()); } } - - public static int InsertInstanceData(NpgsqlConnection conn) - { - + + public static int InsertInstanceData(NpgsqlConnection conn) { var instanceinfo = new InstanceData(); - using (var cmd = new NpgsqlCommand()) - { + using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; - + cmd.Parameters.AddWithValue("@host", System.Environment.MachineName); cmd.Parameters.AddWithValue("@iid", DBNull.Value); cmd.Parameters.AddWithValue("@typ", instanceinfo.type); cmd.Parameters.AddWithValue("@pubhost", DBNull.Value); cmd.Parameters.AddWithValue("@amiid", DBNull.Value); - - if (instanceinfo.type != "LOCALHOST") - { + + if (instanceinfo.type != "LOCALHOST") { cmd.Parameters.AddWithValue("@host", instanceinfo.hostname); cmd.Parameters.AddWithValue("@iid", instanceinfo.instanceid); cmd.Parameters.AddWithValue("@typ", instanceinfo.type); cmd.Parameters.AddWithValue("@pubhost", instanceinfo.publichostname); cmd.Parameters.AddWithValue("@amiid", instanceinfo.amiid); } + cmd.CommandText = "SELECT instance_id FROM instances WHERE hostname=@host AND instancetype=@typ AND instanceid=@iid AND amiid=@amiid AND publichostname=@pubhost"; var id = cmd.ExecuteScalar(); - if (id == null) - { + if (id == null) { cmd.CommandText = - "INSERT INTO instances (hostname, instanceid, instancetype, publichostname, amiid) VALUES (@host, @iid, @typ, @pubhost, @amiid) " + - "RETURNING instance_id"; + "INSERT INTO instances (hostname, instanceid, instancetype, publichostname, amiid) VALUES (@host, @iid, @typ, @pubhost, @amiid) " + + "RETURNING instance_id"; return (int) cmd.ExecuteScalar(); } return (int) id; - } } - public static async Task StartSession(string name) - { + public static async Task StartSession(string name) { return await Task.Run(() => StartSessionImpl(name)); } - public static int StartSessionImpl(string name) - { + + public static int StartSessionImpl(string name) { var conn = OpenConnection(); int result = 0; //int instance = InsertInstanceData(conn); - using (var cmd = new NpgsqlCommand()) - { - + using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.CommandText = "INSERT INTO sessions (name, start) VALUES (@name, @start) ON CONFLICT DO NOTHING"; cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@start", DateTime.UtcNow); cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT session_id FROM sessions WHERE name = @name"; - result = (int)cmd.ExecuteScalar(); + result = (int) cmd.ExecuteScalar(); } + conn.Close(); return result; } - public static async Task StopSession(int sessionid) - { + public static async Task StopSession(int sessionid) { await Task.Run(() => StopSessionImpl(sessionid)); } - public static void StopSessionImpl(int sessionid) - { + + public static void StopSessionImpl(int sessionid) { var conn = OpenConnection(); - using (var cmd = new NpgsqlCommand()) - { + using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.CommandText = @"UPDATE sessions SET ""end"" = @endtime WHERE session_id = @sessionid"; cmd.Parameters.AddWithValue("@endtime", DateTime.UtcNow); cmd.Parameters.AddWithValue("@sessionid", sessionid); cmd.ExecuteNonQuery(); } + conn.Close(); } - public static async Task StartRun(int sessionid) - { + public static async Task StartRun(int sessionid) { var t = Task.Run(() => StartRunImpl(sessionid)); return await t; } - public static GTARun StartRunImpl(int sessionid) - { + + public static GTARun StartRunImpl(int sessionid) { var run = new GTARun(); run.guid = Guid.NewGuid(); run.archiveKey = Path.Combine("images", run.guid + ".zip"); var conn = OpenConnection(); int instanceid = InsertInstanceData(conn); InsertSystemData(conn); - using (var cmd = new NpgsqlCommand()) - { + using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; - cmd.CommandText = "INSERT INTO runs (runguid, archivepath, session_id, instance_id) VALUES (@guid, @archivekey, @session, @instance);"; + cmd.CommandText = + "INSERT INTO runs (runguid, archivepath, session_id, instance_id) VALUES (@guid, @archivekey, @session, @instance);"; cmd.Parameters.AddWithValue("@guid", run.guid); cmd.Parameters.AddWithValue("@archivekey", run.archiveKey); cmd.Parameters.AddWithValue("@session", sessionid); cmd.Parameters.AddWithValue("@instance", instanceid); cmd.ExecuteNonQuery(); } + conn.Close(); - + return run; } - public static void StopRun(GTARun run) - { + public static void StopRun(GTARun run) { } - public static async void SaveSnapshot(GTAData data, Guid runId) - { + public static async void SaveSnapshot(GTAData data, Guid runId) { await Task.Run(() => SaveSnapshotImpl(data, runId)); } - - public static void SaveSnapshotImpl(GTAData data, Guid runId) - { + + public static void SaveSnapshotImpl(GTAData data, Guid runId) { var conn = OpenConnection(); var trans = conn.BeginTransaction(); - using (NpgsqlCommand cmd = new NpgsqlCommand()) - { - + using (NpgsqlCommand cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.Transaction = trans; cmd.CommandText = "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_rot, " + "camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, " + - "cam_near_clip, cam_far_clip, velocity) " + + "cam_near_clip, cam_far_clip, velocity, scene_id) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@rotx, @roty, @rotz), " + "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + - "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z)) " + + "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id) " + "RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); @@ -224,8 +207,9 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters.AddWithValue("@vel_z", data.velocity.Z); cmd.Parameters.AddWithValue("@cam_near_clip", data.CamNearClip); cmd.Parameters.AddWithValue("@cam_far_clip", data.CamFarClip); + cmd.Parameters.AddWithValue("@scene_id", data.sceneGuid); cmd.Parameters.Add(new NpgsqlParameter("@guid", runId)); - int snapshotid = (int)cmd.ExecuteScalar(); + int snapshotid = (int) cmd.ExecuteScalar(); cmd.Parameters.Clear(); cmd.CommandText = "INSERT INTO snapshot_weathers (snapshot_id, weather_type, snapshot_page) VALUES (@snapshot, @weather, @page);"; @@ -233,8 +217,7 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters.AddWithValue("@weather", NpgsqlDbType.Enum, Weather.Unknown); cmd.Parameters.Add("@page", NpgsqlDbType.Integer); cmd.Prepare(); - for (int i = 0; i < data.CapturedWeathers.Count; ++i) - { + for (int i = 0; i < data.CapturedWeathers.Count; ++i) { cmd.Parameters["@weather"].Value = data.CapturedWeathers[i]; cmd.Parameters["@page"].Value = i; cmd.ExecuteNonQuery(); @@ -266,10 +249,9 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) "(@snapshot, @type, ST_MakePoint(@x,@y,@z), ST_MakePoint(@xrot, @yrot, @zrot), @bbox, @class, @handle," + "ST_3DMakeBox(ST_MakePoint(@minx,@miny,@minz), ST_MakePoint(@maxx, @maxy, @maxz)), ST_MakePoint(@vel_x, @vel_y, @vel_z))"; cmd.Prepare(); - - + + foreach (var detection in data.Detections) { - cmd.Parameters["@snapshot"].Value = snapshotid; cmd.Parameters["@type"].Value = detection.Type; cmd.Parameters["@x"].Value = detection.Pos.X; @@ -279,7 +261,8 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.Parameters["@yrot"].Value = detection.Rot.Y; cmd.Parameters["@zrot"].Value = detection.Rot.Z; cmd.Parameters["@bbox"].Value = - new NpgsqlBox(detection.BBox.Max.Y, detection.BBox.Max.X, detection.BBox.Min.Y, detection.BBox.Min.X); + new NpgsqlBox(detection.BBox.Max.Y, detection.BBox.Max.X, detection.BBox.Min.Y, + detection.BBox.Min.X); cmd.Parameters["@class"].Value = detection.cls; cmd.Parameters["@handle"].Value = detection.Handle; cmd.Parameters["@minx"].Value = detection.BBox3D.Minimum.X; @@ -297,9 +280,9 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) cmd.ExecuteNonQuery(); } } + trans.Commit(); conn.Close(); } } - -} +} \ No newline at end of file diff --git a/managed/README.md b/managed/README.md index 13fb591..93ebb14 100644 --- a/managed/README.md +++ b/managed/README.md @@ -110,6 +110,7 @@ create table snapshots constraint snapshots_run_fkey references runs, version integer, + scene_id uuid, imagepath text, timestamp timestamp with time zone, timeofday time, From 090804f805c95ed8beedbcdf3d43042b0b969bf2 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 6 Feb 2018 21:51:21 +0100 Subject: [PATCH 089/158] fixed cameras. Added description for downgrading --- managed/GTAVisionExport/CameraHandling.cs | 11 +++++------ managed/README.md | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 32ac897..a2812a1 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -27,10 +27,9 @@ public CameraHandling() UI.Notify("Loaded TestVehicle.cs"); // create a new camera - World.DestroyAllCameras(); +// World.DestroyAllCameras(); mainCamera = World.CreateCamera(new Vector3(), new Vector3(), 50); - mainCamera.IsActive = true; - World.RenderingCamera = mainCamera; + mainCamera.IsActive = false; // attach time methods Tick += OnTick; @@ -112,19 +111,19 @@ private void onKeyUp(object sender, KeyEventArgs e) if (e.KeyCode == Keys.NumPad1) { - activeCameraIndex = 0; + activeCameraIndex = 1; mountCameraOnVehicle(); } if (e.KeyCode == Keys.NumPad2) { - activeCameraIndex = 0; + activeCameraIndex = 2; mountCameraOnVehicle(); } if (e.KeyCode == Keys.NumPad3) { - activeCameraIndex = 0; + activeCameraIndex = 3; mountCameraOnVehicle(); } diff --git a/managed/README.md b/managed/README.md index 93ebb14..701ca80 100644 --- a/managed/README.md +++ b/managed/README.md @@ -416,4 +416,22 @@ There is either manual or automatic way. It contains python HTTP server with buttons to control the managed plugin. It connects to the socket server inside the managed plugin. When the main script starts, you can click the "START_SESSION" button and then it creates new car and starts - driving autonomously and grabbing screenshots automatically. \ No newline at end of file + driving autonomously and grabbing screenshots automatically. + + +### Downgrading the GTA V Steam version +Your version of GTA V can be higher than your shvdn can manage, and in that case, this error pops up and game crashes: +Here is tutorial for it: +https://www.youtube.com/watch?v=7HWOGLtV7Ig +Link for files needed to download is: +https://mega.nz/#!Z7RVUDzb!jtWcn0sQxM7Er4pR83mDG3jFDJ49QkA_7SO9aFckawY +if the link is dead, just write me and I'll upload files somewhere and share them with you. + +Basically: +setup the update frequency in steam to updating before launch (all other options are automatic updates, which you don't want) +The only files being changed during updates are: +GTA5.exe +GTAVLauncher.exe +update/update.rpf + +So simply backup these files, just to be sure, and replace them by their older versions. From b38092ba493ad2d0153d0b3f122ce109b0f5ac06 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 6 Feb 2018 21:58:51 +0100 Subject: [PATCH 090/158] changed log location --- managed/GTAVision.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVision.ini b/managed/GTAVision.ini index 359c869..6031450 100644 --- a/managed/GTAVision.ini +++ b/managed/GTAVision.ini @@ -2,4 +2,4 @@ ConnectionString=Server=127.0.0.1;Port=5432;Database=gta_v;User Id=postgres;Password=postgres; [Snapshots] OutputDir=D:\GTAV_extraction_output\ -LogFile=D:\GTAV_extraction_output\log.txt +LogFile=D:\Program Files\Rockstar Games\Grand Theft Auto V\my_log.txt From a19658fe0732c5d5f6e9644545ce2e73fcc00dac Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 6 Feb 2018 22:01:47 +0100 Subject: [PATCH 091/158] added logging of obtained json --- managed/GTAVisionExport/VisionExport.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 570e03a..7a18536 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -151,6 +151,7 @@ private void handlePipeInput() { } UINotify("str: " + str.ToString()); + Logger.writeLine("obtained json: " + str.ToString()); dynamic parameters = JsonConvert.DeserializeObject(str); string commandName = parameters.name; switch (commandName) { From 1b9d8e4945e1fb4742ca3a57dda28795ce340062 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 6 Feb 2018 22:35:48 +0100 Subject: [PATCH 092/158] fixed camera trainer stuff. Added som debug printing. --- managed/GTAVisionExport/CameraHandling.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index a2812a1..8d75164 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -19,12 +19,14 @@ public class CameraHandling : Script // camera used on the vehicle Camera mainCamera = null; Camera[] cameras = null; + private Camera gameCam; private bool enabled = false; private int activeCameraIndex = -1; public CameraHandling() { UI.Notify("Loaded TestVehicle.cs"); + gameCam = World.RenderingCamera; // create a new camera // World.DestroyAllCameras(); @@ -63,7 +65,7 @@ public void restoreCamera() { UI.Notify("Relinquishing control"); mainCamera.IsActive = false; - World.RenderingCamera = mainCamera; + World.RenderingCamera = gameCam; } // Function used to keep camera on vehicle and facing forward on each tick step. @@ -77,14 +79,6 @@ public void keepCameraOnVehicle() // rotate the camera to face the same direction as the car mainCamera.Rotation = Game.Player.Character.CurrentVehicle.Rotation; } - - if (Game.Player.Character.IsInVehicle() && enabled) - { - for (int i = 0; i < cameras.Length; i++) - { - CamerasList.ActivateCamera(i); - } - } } // Test vehicle controls @@ -105,30 +99,35 @@ private void onKeyUp(object sender, KeyEventArgs e) if (e.KeyCode == Keys.NumPad0) { + UI.Notify("Pressed numpad 0"); activeCameraIndex = 0; mountCameraOnVehicle(); } if (e.KeyCode == Keys.NumPad1) { + UI.Notify("Pressed numpad 1"); activeCameraIndex = 1; mountCameraOnVehicle(); } if (e.KeyCode == Keys.NumPad2) { + UI.Notify("Pressed numpad 2"); activeCameraIndex = 2; mountCameraOnVehicle(); } if (e.KeyCode == Keys.NumPad3) { + UI.Notify("Pressed numpad 3"); activeCameraIndex = 3; mountCameraOnVehicle(); } if (e.KeyCode == Keys.Decimal) { + UI.Notify("Pressed numpad ,"); activeCameraIndex = -1; mountCameraOnVehicle(); } From d38f2e79720570521eeda0da86cab2290879f1c6 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 15:54:35 +0100 Subject: [PATCH 093/158] added possibility to specify field of view, logger uses windows newlines --- managed/GTAVisionExport/CameraHandling.cs | 74 ++++++++--------------- managed/GTAVisionExport/CamerasList.cs | 22 +++++-- managed/GTAVisionExport/VisionExport.cs | 12 ++-- managed/GTAVisionUtils/Logger.cs | 2 +- 4 files changed, 51 insertions(+), 59 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 8d75164..269ba64 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -6,27 +6,23 @@ using GTA; using GTA.Native; using GTA.Math; +using GTAVisionUtils; -namespace GTAVisionExport -{ - +namespace GTAVisionExport { // Controls: // P - mounts rendering camera on vehicle // O - restores the rendering camera to original control - public class CameraHandling : Script - { + public class CameraHandling : Script { // camera used on the vehicle Camera mainCamera = null; - Camera[] cameras = null; private Camera gameCam; private bool enabled = false; private int activeCameraIndex = -1; - public CameraHandling() - { + public CameraHandling() { UI.Notify("Loaded TestVehicle.cs"); - gameCam = World.RenderingCamera; + gameCam = CamerasList.gameCam; // create a new camera // World.DestroyAllCameras(); @@ -39,40 +35,32 @@ public CameraHandling() } // Function used to take control of the world rendering camera. - public void mountCameraOnVehicle() - { - if (Game.Player.Character.IsInVehicle()) - { -// void RENDER_SCRIPT_CAMS(BOOL render, BOOL ease, int easeTime, BOOL p3, -// BOOL p4) // 0x07E5B515DB0636FC 0x74337969 - if (activeCameraIndex == -1) - { - World.RenderingCamera = mainCamera; + public void mountCameraOnVehicle() { + if (Game.Player.Character.IsInVehicle()) { + if (activeCameraIndex == -1) { + World.RenderingCamera = mainCamera; } - else - { - World.RenderingCamera = cameras[activeCameraIndex]; + else { + UI.Notify("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation.ToString()); + Logger.writeLine("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation.ToString()); + CamerasList.ActivateCamera(activeCameraIndex); } } - else - { + else { UI.Notify("Please enter a vehicle."); } } // Function used to allows the user original control of the camera. - public void restoreCamera() - { + public void restoreCamera() { UI.Notify("Relinquishing control"); mainCamera.IsActive = false; World.RenderingCamera = gameCam; } // Function used to keep camera on vehicle and facing forward on each tick step. - public void keepCameraOnVehicle() - { - if (Game.Player.Character.IsInVehicle() && enabled) - { + public void keepCameraOnVehicle() { + if (Game.Player.Character.IsInVehicle() && enabled) { // keep the camera in the same position relative to the car mainCamera.AttachTo(Game.Player.Character.CurrentVehicle, CamerasList.mainCamera.Value); @@ -82,60 +70,50 @@ public void keepCameraOnVehicle() } // Test vehicle controls - private void onKeyUp(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.P) - { + private void onKeyUp(object sender, KeyEventArgs e) { + if (e.KeyCode == Keys.P) { activeCameraIndex = -1; mountCameraOnVehicle(); enabled = true; } - if (e.KeyCode == Keys.O) - { + if (e.KeyCode == Keys.O) { restoreCamera(); enabled = false; } - if (e.KeyCode == Keys.NumPad0) - { + if (e.KeyCode == Keys.NumPad0) { UI.Notify("Pressed numpad 0"); activeCameraIndex = 0; mountCameraOnVehicle(); } - if (e.KeyCode == Keys.NumPad1) - { + if (e.KeyCode == Keys.NumPad1) { UI.Notify("Pressed numpad 1"); activeCameraIndex = 1; mountCameraOnVehicle(); } - if (e.KeyCode == Keys.NumPad2) - { + if (e.KeyCode == Keys.NumPad2) { UI.Notify("Pressed numpad 2"); activeCameraIndex = 2; mountCameraOnVehicle(); } - if (e.KeyCode == Keys.NumPad3) - { + if (e.KeyCode == Keys.NumPad3) { UI.Notify("Pressed numpad 3"); activeCameraIndex = 3; mountCameraOnVehicle(); } - if (e.KeyCode == Keys.Decimal) - { + if (e.KeyCode == Keys.Decimal) { UI.Notify("Pressed numpad ,"); activeCameraIndex = -1; mountCameraOnVehicle(); } - } - void OnTick(object sender, EventArgs e) - { + void OnTick(object sender, EventArgs e) { keepCameraOnVehicle(); } } diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index a154de6..d7e4443 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using GTA; using GTA.Math; +using GTAVisionUtils; namespace GTAVisionExport { public static class CamerasList @@ -13,16 +14,22 @@ public static class CamerasList public static List cameras { get; set; } = new List(); public static List camerasPositions { get; set; } = new List(); public static List camerasRotations { get; set; } = new List(); - private static Camera gameCam; + public static Camera gameCam; static CamerasList() { + World.DestroyAllCameras(); gameCam = World.RenderingCamera; } - public static void addCamera(Vector3 position, Vector3 rotation) + public static void addCamera(Vector3 position, Vector3 rotation, float? fov = null) { - var newCamera = World.CreateCamera(new Vector3(), new Vector3(), GameplayCamera.FieldOfView); + if (!fov.HasValue) + { + fov = GameplayCamera.FieldOfView; + } + + var newCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value); cameras.Add(newCamera); camerasPositions.Add(position); camerasRotations.Add(rotation); @@ -33,7 +40,14 @@ public static void ActivateCamera(int i) cameras[i].IsActive = true; World.RenderingCamera = cameras[i]; cameras[i].AttachTo(Game.Player.Character.CurrentVehicle, camerasPositions[i]); - cameras[i].Rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; + var rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; +// rotation.Z %= 360; + cameras[i].Rotation = rotation; + UI.Notify("new camera rotation is: " + rotation.ToString()); + Logger.writeLine("new camera position is: " + cameras[i].Position.ToString()); + Logger.writeLine("new camera rotation is: " + cameras[i].Rotation.ToString()); + Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); + Logger.writeLine("new camera rotation offset is: " + camerasRotations[i].ToString()); } public static void Deactivate() diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 7a18536..14d5068 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -113,16 +113,16 @@ public VisionExport() { } // cameras initialization: - float r = 5f; //radius of circle with 4 cameras + float r = 8f; //radius of circle with 4 cameras CamerasList.mainCamera = new Vector3(0f, 2f, 0.4f); - CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f)); - CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f)); - CamerasList.addCamera(new Vector3(2 * r, 2f, 0.4f), new Vector3(0f, 0f, 180f)); - CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f)); + CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 100); + CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 100); + CamerasList.addCamera(new Vector3(2 * r, 2f, 0.4f), new Vector3(0f, 0f, 180f), 100); + CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 100); } private void handlePipeInput() { - Logger.writeLine("VisionExport handlePipeInput called."); +// Logger.writeLine("VisionExport handlePipeInput called."); UINotify("handlePipeInput called"); UINotify("server connected:" + server.Connected.ToString()); UINotify(connection == null ? "connection is null" : "connection:" + connection.ToString()); diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs index 45c7cb1..da75476 100644 --- a/managed/GTAVisionUtils/Logger.cs +++ b/managed/GTAVisionUtils/Logger.cs @@ -24,7 +24,7 @@ public static void writeLine(string line) var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; try { - System.IO.File.AppendAllText(logFilePath, DateTime.UtcNow.ToString(dateTimeFormat) + ": " + line + "\n"); + System.IO.File.AppendAllText(logFilePath, DateTime.UtcNow.ToString(dateTimeFormat) + ": " + line + "\r\n"); } catch (System.IO.IOException e) { From ee456580097370fe7d36e41642b6ca19960c86aa Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 17:15:13 +0100 Subject: [PATCH 094/158] fully working screenshots taking from 4 camers --- managed/GTAVisionExport/CameraHandling.cs | 2 +- managed/GTAVisionExport/CamerasList.cs | 6 +++--- managed/GTAVisionExport/VisionExport.cs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 269ba64..2736054 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -55,7 +55,7 @@ public void mountCameraOnVehicle() { public void restoreCamera() { UI.Notify("Relinquishing control"); mainCamera.IsActive = false; - World.RenderingCamera = gameCam; + World.RenderingCamera = mainCamera; } // Function used to keep camera on vehicle and facing forward on each tick step. diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index d7e4443..32af9b5 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -43,9 +43,9 @@ public static void ActivateCamera(int i) var rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; // rotation.Z %= 360; cameras[i].Rotation = rotation; - UI.Notify("new camera rotation is: " + rotation.ToString()); - Logger.writeLine("new camera position is: " + cameras[i].Position.ToString()); - Logger.writeLine("new camera rotation is: " + cameras[i].Rotation.ToString()); +// UI.Notify("new camera rotation is: " + rotation.ToString()); + Logger.writeLine("new camera position is: " + World.RenderingCamera.Position.ToString()); + Logger.writeLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); Logger.writeLine("new camera rotation offset is: " + camerasRotations[i].ToString()); } diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 14d5068..efd7968 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -115,10 +115,10 @@ public VisionExport() { // cameras initialization: float r = 8f; //radius of circle with 4 cameras CamerasList.mainCamera = new Vector3(0f, 2f, 0.4f); - CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 100); - CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 100); - CamerasList.addCamera(new Vector3(2 * r, 2f, 0.4f), new Vector3(0f, 0f, 180f), 100); - CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 100); + CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f)); + CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f)); + CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f)); + CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f)); } private void handlePipeInput() { From 15533793ecbbf1bc85e13c51f07f94559a9d0505 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 17:31:32 +0100 Subject: [PATCH 095/158] more logging --- managed/GTAVisionExport/VisionExport.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index efd7968..b669228 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -332,10 +332,12 @@ private void gatherData() { if (useMultipleCameras) { for (int i = 0; i < CamerasList.cameras.Count; i++) { + Logger.writeLine("activating camera " + i.ToString()); CamerasList.ActivateCamera(i); gatherDatForOneCamera(dateTimeFormat, guid); Script.Wait(5); } + CamerasList.Deactivate(); } else { gatherDatForOneCamera(dateTimeFormat, guid); From 457602124a3f5906009e10bbd2bf09b889d04252 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 20:28:19 +0100 Subject: [PATCH 096/158] scene id persisten to db --- managed/GTAVisionExport/VisionExport.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index b669228..15a369a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -355,6 +355,8 @@ private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); } + dat.sceneGuid = guid; + if (dat == null) { return; } From 2653abc9521d2e628b5963d83a4ec89a702ec5c2 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 20:48:49 +0100 Subject: [PATCH 097/158] added loggin scene guid --- managed/GTAVisionExport/VisionExport.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 15a369a..4ba7a14 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -329,6 +329,7 @@ private void gatherData() { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; var guid = Guid.NewGuid(); + Logger.writeLine("generated scene guid: " + guid.ToString()); if (useMultipleCameras) { for (int i = 0; i < CamerasList.cameras.Count; i++) { From 8c592d41ea04160950dd8c8a8002e2063387d131 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 21:11:17 +0100 Subject: [PATCH 098/158] added initialization --- managed/GTAVisionExport/CamerasList.cs | 26 ++++++++++++++++++++++++- managed/GTAVisionExport/VisionExport.cs | 13 ++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 32af9b5..9dcea9f 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -15,15 +16,26 @@ public static class CamerasList public static List camerasPositions { get; set; } = new List(); public static List camerasRotations { get; set; } = new List(); public static Camera gameCam; + private static bool initialized = false; static CamerasList() { + } + + public static void initialize() { World.DestroyAllCameras(); + Logger.writeLine("destroying all cameras at the beginning, to be clear"); gameCam = World.RenderingCamera; + initialized = true; } - + public static void addCamera(Vector3 position, Vector3 rotation, float? fov = null) { + if (!initialized) { + throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); + } + + Logger.writeLine("adding new camera"); if (!fov.HasValue) { fov = GameplayCamera.FieldOfView; @@ -37,6 +49,14 @@ public static void addCamera(Vector3 position, Vector3 rotation, float? fov = nu public static void ActivateCamera(int i) { + if (!initialized) { + throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); + } + + if (i >= cameras.Count) { + throw new Exception("there is no camera with index " + i); + } + cameras[i].IsActive = true; World.RenderingCamera = cameras[i]; cameras[i].AttachTo(Game.Player.Character.CurrentVehicle, camerasPositions[i]); @@ -52,6 +72,10 @@ public static void ActivateCamera(int i) public static void Deactivate() { + if (!initialized) { + throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); + } + foreach (var camera in cameras) { camera.IsActive = false; diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 4ba7a14..1ca1a7a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -112,15 +112,20 @@ public VisionExport() { runTask = StartRun(); } + CamerasList.in + initialize4cameras(); + } + + private void initialize4cameras() { // cameras initialization: float r = 8f; //radius of circle with 4 cameras CamerasList.mainCamera = new Vector3(0f, 2f, 0.4f); CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f)); CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f)); CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f)); - CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f)); + CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f)); } - + private void handlePipeInput() { // Logger.writeLine("VisionExport handlePipeInput called."); UINotify("handlePipeInput called"); @@ -308,7 +313,9 @@ public void OnTick(object o, EventArgs e) { catch (Exception exception) { GamePause(false); Logger.writeLine("exception occured, logging and continuing"); - Logger.writeLine(exception); + Logger.writeLine(exception.Message); + Logger.writeLine(exception.Source); + Logger.writeLine(exception.StackTrace); } // if time interval is enabled, checkes game time and sets it to timeFrom, it current time is after timeTo From f3ecb5ae1075fdd2fe962d61379ba8dd4a9a451b Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 21:11:47 +0100 Subject: [PATCH 099/158] typo --- managed/GTAVisionExport/CamerasList.cs | 4 ---- managed/GTAVisionExport/VisionExport.cs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 9dcea9f..865ee0d 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -1,9 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using GTA; using GTA.Math; using GTAVisionUtils; diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 1ca1a7a..4950972 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -112,7 +112,7 @@ public VisionExport() { runTask = StartRun(); } - CamerasList.in + CamerasList.initialize(); initialize4cameras(); } From 0989d4bde8423cb238f3ca48a6b71c2399a8abd8 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 21:24:18 +0100 Subject: [PATCH 100/158] better managing of game pauses. Added more time between camera activation and values reading. --- managed/GTAVisionExport/CamerasList.cs | 1 + managed/GTAVisionExport/VisionExport.cs | 34 +++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 865ee0d..29eb9f9 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -60,6 +60,7 @@ public static void ActivateCamera(int i) // rotation.Z %= 360; cameras[i].Rotation = rotation; // UI.Notify("new camera rotation is: " + rotation.ToString()); + Script.Wait(4); Logger.writeLine("new camera position is: " + World.RenderingCamera.Position.ToString()); Logger.writeLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 4950972..f8b1c1d 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -90,7 +90,7 @@ public VisionExport() { logFilePath = data["Snapshots"]["LogFile"]; Logger.setLogFilePath(logFilePath); - System.IO.File.WriteAllText(logFilePath, "VisionExport constructor called.\n"); + System.IO.File.WriteAllText(logFilePath, "VisionExport constructor called.\r\n"); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); PostgresExport.InitSQLTypes(); player = Game.Player; @@ -711,12 +711,12 @@ public void OnKeyDown(object o, KeyEventArgs k) { GTAData dat; if (multipleWeathers) { dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); - saveSnapshotToFile(dat.ImageName, wantedWeathers); + saveSnapshotToFile(dat.ImageName, wantedWeathers, false); } else { Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); - saveSnapshotToFile(dat.ImageName, weather); + saveSnapshotToFile(dat.ImageName, weather, false); } PostgresExport.SaveSnapshot(dat, run.guid); @@ -735,10 +735,14 @@ public void OnKeyDown(object o, KeyEventArgs k) { } } - private bool saveSnapshotToFile(String name, Weather[] weathers) { + private bool saveSnapshotToFile(String name, Weather[] weathers, bool manageGamePauses = true) { // returns true on success, and false on failure List colors = new List(); - GamePause(true); + + if (manageGamePauses) { + GamePause(true); + } + var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); if (depth == null || stencil == null) { @@ -756,7 +760,10 @@ private bool saveSnapshotToFile(String name, Weather[] weathers) { colors.Add(color); } - GamePause(false); + if (manageGamePauses) { + GamePause(false); + } + var res = Game.ScreenResolution; var fileName = Path.Combine(dataPath, name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, colors, depth, stencil, false); @@ -764,11 +771,14 @@ private bool saveSnapshotToFile(String name, Weather[] weathers) { return true; } - private bool saveSnapshotToFile(String name, Weather weather) { + private bool saveSnapshotToFile(String name, Weather weather, bool manageGamePauses = true) { // returns true on success, and false on failure - GamePause(true); + if (manageGamePauses) { + GamePause(true); + } + World.TransitionToWeather(weather, - 0.0f); //trying to set weather only in the beginning, because of depth =/= RGB + 0.0f); Script.Wait(10); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); @@ -777,7 +787,11 @@ private bool saveSnapshotToFile(String name, Weather weather) { return false; } - GamePause(false); + + if (manageGamePauses) { + GamePause(false); + } + var res = Game.ScreenResolution; var fileName = Path.Combine(dataPath, name); ImageUtils.WriteToTiff(fileName, res.Width, res.Height, new List() {color}, depth, stencil, false); From 848996ccfe030d5fc70bcee8f4a1be7550da2b03 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 21:34:16 +0100 Subject: [PATCH 101/158] increased waiting time after camera is set --- managed/GTAVisionExport/CamerasList.cs | 2 +- managed/GTAVisionExport/VisionExport.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 29eb9f9..cb51d98 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -60,7 +60,7 @@ public static void ActivateCamera(int i) // rotation.Z %= 360; cameras[i].Rotation = rotation; // UI.Notify("new camera rotation is: " + rotation.ToString()); - Script.Wait(4); + Script.Wait(10); Logger.writeLine("new camera position is: " + World.RenderingCamera.Position.ToString()); Logger.writeLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index f8b1c1d..a61fd76 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -58,7 +58,6 @@ class VisionExport : Script { private readonly bool clearEverything = false; private readonly bool useMultipleCameras = true; private Player player; - private string outputPath; private GTARun run; private bool enabled = false; private Socket server; From 7624a2d25722c17777aa2d683c40869380250604 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 21:40:57 +0100 Subject: [PATCH 102/158] correct game pauses management --- managed/GTAVisionExport/VisionExport.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index a61fd76..86a5f9a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -369,11 +369,11 @@ private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { } if (multipleWeathers) { - success = saveSnapshotToFile(dat.ImageName, wantedWeathers); + success = saveSnapshotToFile(dat.ImageName, wantedWeathers, false); } else { Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; - success = saveSnapshotToFile(dat.ImageName, weather); + success = saveSnapshotToFile(dat.ImageName, weather, false); } if (!success) { From 345818f77d1e6fe43aca1877045dbb151e40a3bd Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 21:44:41 +0100 Subject: [PATCH 103/158] unified manual and automatic data gathering --- managed/GTAVisionExport/VisionExport.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 86a5f9a..b2a7ed8 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -701,24 +701,10 @@ public void OnKeyDown(object o, KeyEventArgs k) { startRunAndSessionManual(); postgresTask?.Wait(); runTask?.Wait(); - var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; UINotify("starting screenshots"); for (int i = 0; i < 5; i++) { GamePause(true); - Script.Wait(200); - - GTAData dat; - if (multipleWeathers) { - dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); - saveSnapshotToFile(dat.ImageName, wantedWeathers, false); - } - else { - Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; - dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); - saveSnapshotToFile(dat.ImageName, weather, false); - } - - PostgresExport.SaveSnapshot(dat, run.guid); + gatherData(); GamePause(false); Script.Wait(200); // hoping game will go on during this wait } From 33605f9fe02d9f6b3387e74d935cb20477c31aa5 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Feb 2018 23:19:21 +0100 Subject: [PATCH 104/158] fixed cameras manual handling --- managed/GTAVisionExport/CameraHandling.cs | 18 +++++++++++++++--- managed/GTAVisionExport/CamerasList.cs | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 2736054..71cd11c 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -17,12 +17,14 @@ public class CameraHandling : Script { // camera used on the vehicle Camera mainCamera = null; private Camera gameCam; + private Camera activeCamera; private bool enabled = false; private int activeCameraIndex = -1; public CameraHandling() { UI.Notify("Loaded TestVehicle.cs"); gameCam = CamerasList.gameCam; + activeCamera = null; // create a new camera // World.DestroyAllCameras(); @@ -36,14 +38,19 @@ public CameraHandling() { // Function used to take control of the world rendering camera. public void mountCameraOnVehicle() { + UI.Notify("Mounting camera to the vehicle."); if (Game.Player.Character.IsInVehicle()) { if (activeCameraIndex == -1) { + mainCamera.IsActive = true; + activeCamera = mainCamera; World.RenderingCamera = mainCamera; + mainCamera.AttachTo(Game.Player.Character.CurrentVehicle, CamerasList.mainCamera.Value); + mainCamera.Rotation = Game.Player.Character.CurrentVehicle.Rotation; } else { UI.Notify("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation.ToString()); Logger.writeLine("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation.ToString()); - CamerasList.ActivateCamera(activeCameraIndex); + activeCamera = CamerasList.ActivateCamera(activeCameraIndex); } } else { @@ -54,8 +61,13 @@ public void mountCameraOnVehicle() { // Function used to allows the user original control of the camera. public void restoreCamera() { UI.Notify("Relinquishing control"); - mainCamera.IsActive = false; - World.RenderingCamera = mainCamera; + if (activeCameraIndex == -1) { + activeCamera.IsActive = false; + World.RenderingCamera = activeCamera; + } + else { + CamerasList.Deactivate(); + } } // Function used to keep camera on vehicle and facing forward on each tick step. diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index cb51d98..cf7f9a8 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -43,7 +43,7 @@ public static void addCamera(Vector3 position, Vector3 rotation, float? fov = nu camerasRotations.Add(rotation); } - public static void ActivateCamera(int i) + public static Camera ActivateCamera(int i) { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); @@ -65,6 +65,7 @@ public static void ActivateCamera(int i) Logger.writeLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); Logger.writeLine("new camera rotation offset is: " + camerasRotations[i].ToString()); + return cameras[i]; } public static void Deactivate() From 7e1ea11b3825d75489e06b13c875d9ccd4b71f9c Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 8 Feb 2018 00:13:30 +0100 Subject: [PATCH 105/158] unified main camera handling with multiple cameras --- managed/GTAVisionExport/CameraHandling.cs | 22 +++++------ managed/GTAVisionExport/CamerasList.cs | 47 ++++++++++++++++++++--- managed/GTAVisionExport/VisionExport.cs | 2 +- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 71cd11c..ea7c0ba 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -15,7 +15,6 @@ namespace GTAVisionExport { public class CameraHandling : Script { // camera used on the vehicle - Camera mainCamera = null; private Camera gameCam; private Camera activeCamera; private bool enabled = false; @@ -28,9 +27,8 @@ public CameraHandling() { // create a new camera // World.DestroyAllCameras(); - mainCamera = World.CreateCamera(new Vector3(), new Vector3(), 50); - mainCamera.IsActive = false; - + CamerasList.initialize(); + // attach time methods Tick += OnTick; KeyUp += onKeyUp; @@ -41,15 +39,13 @@ public void mountCameraOnVehicle() { UI.Notify("Mounting camera to the vehicle."); if (Game.Player.Character.IsInVehicle()) { if (activeCameraIndex == -1) { - mainCamera.IsActive = true; - activeCamera = mainCamera; - World.RenderingCamera = mainCamera; - mainCamera.AttachTo(Game.Player.Character.CurrentVehicle, CamerasList.mainCamera.Value); - mainCamera.Rotation = Game.Player.Character.CurrentVehicle.Rotation; + UI.Notify("Mounting main camera"); + CamerasList.ActivateMainCamera(); } else { - UI.Notify("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation.ToString()); - Logger.writeLine("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation.ToString()); + UI.Notify("Mounting camera from list"); + UI.Notify("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation); + Logger.writeLine("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation); activeCamera = CamerasList.ActivateCamera(activeCameraIndex); } } @@ -74,10 +70,10 @@ public void restoreCamera() { public void keepCameraOnVehicle() { if (Game.Player.Character.IsInVehicle() && enabled) { // keep the camera in the same position relative to the car - mainCamera.AttachTo(Game.Player.Character.CurrentVehicle, CamerasList.mainCamera.Value); + CamerasList.mainCamera.AttachTo(Game.Player.Character.CurrentVehicle, CamerasList.mainCameraPosition); // rotate the camera to face the same direction as the car - mainCamera.Rotation = Game.Player.Character.CurrentVehicle.Rotation; + CamerasList.mainCamera.Rotation = Game.Player.Character.CurrentVehicle.Rotation; } } diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index cf7f9a8..60c3969 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -2,15 +2,18 @@ using System.Collections.Generic; using GTA; using GTA.Math; +using GTA.Native; using GTAVisionUtils; namespace GTAVisionExport { public static class CamerasList { - public static Vector3? mainCamera { get; set; } = null; - public static List cameras { get; set; } = new List(); - public static List camerasPositions { get; set; } = new List(); - public static List camerasRotations { get; set; } = new List(); + public static Camera mainCamera { get; set; } + public static Vector3 mainCameraPosition { get; set; } + + public static List cameras { get; } = new List(); + public static List camerasPositions { get; } = new List(); + public static List camerasRotations { get; } = new List(); public static Camera gameCam; private static bool initialized = false; @@ -19,12 +22,37 @@ static CamerasList() } public static void initialize() { + if (initialized) { + return; + } + World.DestroyAllCameras(); Logger.writeLine("destroying all cameras at the beginning, to be clear"); gameCam = World.RenderingCamera; + +// mainCamera.IsActive = false; + mainCamera.IsActive = true; + GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, false, true, mainCamera.Handle, true, true); + initialized = true; } + public static void setMainCamera(Vector3 position, float? fov = null) + { + if (!initialized) { + throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); + } + + Logger.writeLine("setting main camera"); + if (!fov.HasValue) + { + fov = GameplayCamera.FieldOfView; + } + + mainCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value); + mainCameraPosition = position; + } + public static void addCamera(Vector3 position, Vector3 rotation, float? fov = null) { if (!initialized) { @@ -42,7 +70,16 @@ public static void addCamera(Vector3 position, Vector3 rotation, float? fov = nu camerasPositions.Add(position); camerasRotations.Add(rotation); } - + + public static void ActivateMainCamera() + { + if (!initialized) { + throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); + } + + GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, true, true, mainCamera.Handle, true, true); + } + public static Camera ActivateCamera(int i) { if (!initialized) { diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index b2a7ed8..a42b9a1 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -118,7 +118,7 @@ public VisionExport() { private void initialize4cameras() { // cameras initialization: float r = 8f; //radius of circle with 4 cameras - CamerasList.mainCamera = new Vector3(0f, 2f, 0.4f); + CamerasList.setMainCamera(new Vector3(0f, 2f, 0.4f)); CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f)); CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f)); CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f)); From 06d1015c73784c9a42b7322aaa73f4c0f84ee68e Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 8 Feb 2018 01:15:06 +0100 Subject: [PATCH 106/158] finally working cameras with the new setup and without native calls --- managed/GTAVisionExport/CameraHandling.cs | 12 +------ managed/GTAVisionExport/CamerasList.cs | 29 ++++++++-------- managed/GTAVisionExport/VisionExport.cs | 9 ++--- managed/GTAVisionUtils/Logger.cs | 40 +++++++++-------------- 4 files changed, 37 insertions(+), 53 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index ea7c0ba..d1e5470 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -15,19 +15,15 @@ namespace GTAVisionExport { public class CameraHandling : Script { // camera used on the vehicle - private Camera gameCam; private Camera activeCamera; private bool enabled = false; private int activeCameraIndex = -1; public CameraHandling() { UI.Notify("Loaded TestVehicle.cs"); - gameCam = CamerasList.gameCam; - activeCamera = null; // create a new camera // World.DestroyAllCameras(); - CamerasList.initialize(); // attach time methods Tick += OnTick; @@ -57,13 +53,7 @@ public void mountCameraOnVehicle() { // Function used to allows the user original control of the camera. public void restoreCamera() { UI.Notify("Relinquishing control"); - if (activeCameraIndex == -1) { - activeCamera.IsActive = false; - World.RenderingCamera = activeCamera; - } - else { - CamerasList.Deactivate(); - } + CamerasList.Deactivate(); } // Function used to keep camera on vehicle and facing forward on each tick step. diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 60c3969..e8c39e3 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -8,18 +8,14 @@ namespace GTAVisionExport { public static class CamerasList { - public static Camera mainCamera { get; set; } - public static Vector3 mainCameraPosition { get; set; } + public static Camera mainCamera { get; private set; } + public static Vector3 mainCameraPosition { get; private set; } public static List cameras { get; } = new List(); public static List camerasPositions { get; } = new List(); public static List camerasRotations { get; } = new List(); - public static Camera gameCam; +// public static Camera gameCam; private static bool initialized = false; - - static CamerasList() - { - } public static void initialize() { if (initialized) { @@ -28,11 +24,9 @@ public static void initialize() { World.DestroyAllCameras(); Logger.writeLine("destroying all cameras at the beginning, to be clear"); - gameCam = World.RenderingCamera; +// gameCam = World.RenderingCamera; // mainCamera.IsActive = false; - mainCamera.IsActive = true; - GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, false, true, mainCamera.Handle, true, true); initialized = true; } @@ -50,7 +44,11 @@ public static void setMainCamera(Vector3 position, float? fov = null) } mainCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value); +// mainCamera.IsActive = true; mainCameraPosition = position; + + mainCamera.IsActive = false; + World.RenderingCamera = null; } public static void addCamera(Vector3 position, Vector3 rotation, float? fov = null) @@ -77,7 +75,12 @@ public static void ActivateMainCamera() throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } - GTA.Native.Function.Call(Hash.RENDER_SCRIPT_CAMS, true, true, mainCamera.Handle, true, true); + if (mainCamera == null) { + throw new Exception("please, set main camera"); + } + + mainCamera.IsActive = true; + World.RenderingCamera = mainCamera; } public static Camera ActivateCamera(int i) @@ -94,7 +97,6 @@ public static Camera ActivateCamera(int i) World.RenderingCamera = cameras[i]; cameras[i].AttachTo(Game.Player.Character.CurrentVehicle, camerasPositions[i]); var rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; -// rotation.Z %= 360; cameras[i].Rotation = rotation; // UI.Notify("new camera rotation is: " + rotation.ToString()); Script.Wait(10); @@ -111,11 +113,12 @@ public static void Deactivate() throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } + mainCamera.IsActive = false; foreach (var camera in cameras) { camera.IsActive = false; } - World.RenderingCamera = gameCam; + World.RenderingCamera = null; } } } diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index a42b9a1..aa0f1bd 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -87,7 +87,7 @@ public VisionExport() { //UINotify(ConfigurationManager.AppSettings["database_connection"]); dataPath = data["Snapshots"]["OutputDir"]; logFilePath = data["Snapshots"]["LogFile"]; - Logger.setLogFilePath(logFilePath); + Logger.logFilePath = logFilePath; System.IO.File.WriteAllText(logFilePath, "VisionExport constructor called.\r\n"); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); @@ -111,8 +111,11 @@ public VisionExport() { runTask = StartRun(); } + Logger.writeLine("Logger prepared"); + UINotify("Logger initialized. Going to initialize cameras."); CamerasList.initialize(); initialize4cameras(); + UINotify("VisionExport plugin initialized."); } private void initialize4cameras() { @@ -312,9 +315,7 @@ public void OnTick(object o, EventArgs e) { catch (Exception exception) { GamePause(false); Logger.writeLine("exception occured, logging and continuing"); - Logger.writeLine(exception.Message); - Logger.writeLine(exception.Source); - Logger.writeLine(exception.StackTrace); + Logger.writeLine(exception); } // if time interval is enabled, checkes game time and sets it to timeFrom, it current time is after timeTo diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs index da75476..a4ac7aa 100644 --- a/managed/GTAVisionUtils/Logger.cs +++ b/managed/GTAVisionUtils/Logger.cs @@ -7,42 +7,32 @@ using System.Threading.Tasks; using BitMiracle.LibTiff.Classic; -namespace GTAVisionUtils -{ - public class Logger - { - private static string logFilePath; +namespace GTAVisionUtils { + public class Logger { + public static string logFilePath { private get; set; } - public static void setLogFilePath(string path) - { - logFilePath = path; - } - - - public static void writeLine(string line) - { + public static void writeLine(string line) { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; - try - { - System.IO.File.AppendAllText(logFilePath, DateTime.UtcNow.ToString(dateTimeFormat) + ": " + line + "\r\n"); + try { + System.IO.File.AppendAllText(logFilePath, + DateTime.UtcNow.ToString(dateTimeFormat) + ": " + line + "\r\n"); } - catch (System.IO.IOException e) - { -// just silently fail, better than throwing + catch (System.IO.IOException e) { +// just silently fail, better than throwing } } - public static void writeLine(Exception e) - { + public static void writeLine(Exception e) { + writeLine(e.Message); + writeLine(e.Source); writeLine(e.StackTrace); } - public static void writeLine(object value) - { - if (value == null) - { + public static void writeLine(object value) { + if (value == null) { return; } + writeLine(value.ToString()); } } From 887759e949dcc6be388d504d42dd5bedba50af62 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 8 Feb 2018 02:14:07 +0100 Subject: [PATCH 107/158] finally fully working multiple cameras data gathering! --- managed/GTAVisionExport/CamerasList.cs | 9 ++++++--- managed/GTAVisionExport/VisionExport.cs | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index e8c39e3..8f12aef 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -93,13 +93,16 @@ public static Camera ActivateCamera(int i) throw new Exception("there is no camera with index " + i); } + Game.Pause(false); cameras[i].IsActive = true; World.RenderingCamera = cameras[i]; cameras[i].AttachTo(Game.Player.Character.CurrentVehicle, camerasPositions[i]); - var rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; - cameras[i].Rotation = rotation; + cameras[i].Rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; +// WARNING: CAMERAS SETTING DO NOT WORK WHEN GAME IS PAUSED, SO WE NEED TO UNPAUSE THE GAME, SET THINGS UP, AND THEN PAUSE GAME AGAIN + Script.Wait(1); + Game.Pause(true); // UI.Notify("new camera rotation is: " + rotation.ToString()); - Script.Wait(10); + Script.Wait(20); Logger.writeLine("new camera position is: " + World.RenderingCamera.Position.ToString()); Logger.writeLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index aa0f1bd..6d09529 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -327,7 +327,7 @@ public void OnTick(object o, EventArgs e) { } } - private void gatherData() { + private void gatherData(int delay = 5) { if (clearEverything) { ClearSurroundingEverything(Game.Player.Character.Position, 1000f); } @@ -343,7 +343,7 @@ private void gatherData() { Logger.writeLine("activating camera " + i.ToString()); CamerasList.ActivateCamera(i); gatherDatForOneCamera(dateTimeFormat, guid); - Script.Wait(5); + Script.Wait(delay); } CamerasList.Deactivate(); } @@ -705,7 +705,7 @@ public void OnKeyDown(object o, KeyEventArgs k) { UINotify("starting screenshots"); for (int i = 0; i < 5; i++) { GamePause(true); - gatherData(); + gatherData(100); GamePause(false); Script.Wait(200); // hoping game will go on during this wait } @@ -714,6 +714,19 @@ public void OnKeyDown(object o, KeyEventArgs k) { StopSession(); } + if (k.KeyCode == 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.ToString()); + CamerasList.ActivateCamera(i); + Script.Wait(1000); + } + CamerasList.Deactivate(); + Game.Pause(false); + } + if (k.KeyCode == Keys.I) { var info = new GTAVisionUtils.InstanceData(); UINotify(info.type); From 8cd33a912cf4c6d17f51122c8cb788e31d760c94 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 11 Feb 2018 19:01:41 +0100 Subject: [PATCH 108/158] added relative rotation saving to database --- managed/GTAVisionExport/CamerasList.cs | 5 +++++ managed/GTAVisionExport/VisionExport.cs | 8 ++++++++ managed/GTAVisionUtils/GTADataStructures.cs | 1 + managed/GTAVisionUtils/PostgresExport.cs | 19 +++++++++++++++++-- managed/README.md | 1 + 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 8f12aef..7baa80f 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -14,6 +14,9 @@ public static class CamerasList public static List cameras { get; } = new List(); public static List camerasPositions { get; } = new List(); public static List camerasRotations { get; } = new List(); + + public static Vector3? activeCameraRotation { get; private set; } = null; + // public static Camera gameCam; private static bool initialized = false; @@ -81,6 +84,7 @@ public static void ActivateMainCamera() mainCamera.IsActive = true; World.RenderingCamera = mainCamera; + activeCameraRotation = new Vector3(); } public static Camera ActivateCamera(int i) @@ -107,6 +111,7 @@ public static Camera ActivateCamera(int i) Logger.writeLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); Logger.writeLine("new camera rotation offset is: " + camerasRotations[i].ToString()); + activeCameraRotation = camerasRotations[i]; return cameras[i]; } diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 6d09529..3291dac 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -34,6 +34,7 @@ using Color = System.Windows.Media.Color; using System.Configuration; using System.Threading; +using Amazon.ElasticLoadBalancing.Model; using IniParser; using Newtonsoft.Json; @@ -363,6 +364,13 @@ private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); } + if (CamerasList.activeCameraRotation.HasValue) { + dat.CamRelativeRot = new GTAVector(CamerasList.activeCameraRotation.Value); + } + else { + dat.CamRelativeRot = null; + } + dat.sceneGuid = guid; if (dat == null) { diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 7d16851..ae81647 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -197,6 +197,7 @@ public class GTAData public int UIHeight { get; set; } public int UIWidth { get; set; } public Guid sceneGuid { get; set; } + public GTAVector CamRelativeRot { get; set; } public List Detections { get; set; } public static SharpDX.Vector3 CvtVec(GTA.Math.Vector3 inp) { diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 8dc72ec..aaea065 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -165,17 +165,25 @@ public static async void SaveSnapshot(GTAData data, Guid runId) { public static void SaveSnapshotImpl(GTAData data, Guid runId) { var conn = OpenConnection(); var trans = conn.BeginTransaction(); + + var camRelativeRotString = "NULL"; + + if (data.CamRelativeRot != null) { + camRelativeRotString = "ST_MakePoint(@relative_rot_x, @relative_rot_y, @relative_rot_z)"; + } + using (NpgsqlCommand cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.Transaction = trans; cmd.CommandText = "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_rot, " + "camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, " + - "cam_near_clip, cam_far_clip, velocity, scene_id) " + + "cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@rotx, @roty, @rotz), " + "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + - "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id) " + + "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id, " + + camRelativeRotString + ") " + "RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); @@ -208,6 +216,13 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { cmd.Parameters.AddWithValue("@cam_near_clip", data.CamNearClip); cmd.Parameters.AddWithValue("@cam_far_clip", data.CamFarClip); cmd.Parameters.AddWithValue("@scene_id", data.sceneGuid); + + if (data.CamRelativeRot != null) { + cmd.Parameters.AddWithValue("@relative_rot_x", data.velocity.X); + cmd.Parameters.AddWithValue("@relative_rot_y", data.velocity.Y); + cmd.Parameters.AddWithValue("@relative_rot_z", data.velocity.Z); + } + cmd.Parameters.Add(new NpgsqlParameter("@guid", runId)); int snapshotid = (int) cmd.ExecuteScalar(); cmd.Parameters.Clear(); diff --git a/managed/README.md b/managed/README.md index 701ca80..b6df697 100644 --- a/managed/README.md +++ b/managed/README.md @@ -117,6 +117,7 @@ create table snapshots currentweather weather, camera_pos geometry(PointZ), camera_rot geometry(PointZ), + camera_relative_rotation geometry(PointZ), camera_direction geometry, camera_fov real, view_matrix double precision[], From 2de37ee3a9a7702c829f6f9014494a762a478a71 Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 19 Feb 2018 01:52:53 +0100 Subject: [PATCH 109/158] fixed relative rotation persisting --- managed/GTAVisionExport/CamerasList.cs | 6 +++++- managed/GTAVisionExport/VisionExport.cs | 5 ++--- managed/GTAVisionUtils/PostgresExport.cs | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 7baa80f..6d0d472 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -103,7 +103,11 @@ public static Camera ActivateCamera(int i) cameras[i].AttachTo(Game.Player.Character.CurrentVehicle, camerasPositions[i]); cameras[i].Rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; // WARNING: CAMERAS SETTING DO NOT WORK WHEN GAME IS PAUSED, SO WE NEED TO UNPAUSE THE GAME, SET THINGS UP, AND THEN PAUSE GAME AGAIN - Script.Wait(1); +// Script.Wait(1); +// //with time 1, sometimes depth does not correspond, and bounding boxes dont correspond by 3 frames +// //with time 2, depth does correspond, but bounding boxes dont correspond by 2 frames +// //with time 3, sometimes depth does not correspond, but bounding boxes dont correspond by 1 frames + Script.Wait(4);//tried 4 milliseconds instead of one, so screenshots correspond to their data Game.Pause(true); // UI.Notify("new camera rotation is: " + rotation.ToString()); Script.Wait(20); diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 3291dac..c1a00a0 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -569,12 +569,11 @@ public void ReloadGame() { // no need to release the autodrive here // delete all surrounding vehicles & the driver's car ClearSurroundingVehicles(player.Position, 1000f); - Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, player.Position.X, player.Position.Y, - player.Position.Z, 1000f, false, false, false, false); player.LastVehicle.Delete(); // teleport to the spawning position, defined in GameUtils.cs, subject to changes player.Position = GTAConst.StartPos; - ClearSurroundingVehicles(player.Position, 100f); +// ClearSurroundingVehicles(player.Position, 100f); + ClearSurroundingVehicles(player.Position, 50f); // start a new run EnterVehicle(); //Script.Wait(2000); diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index aaea065..1f925b3 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -218,9 +218,9 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { cmd.Parameters.AddWithValue("@scene_id", data.sceneGuid); if (data.CamRelativeRot != null) { - cmd.Parameters.AddWithValue("@relative_rot_x", data.velocity.X); - cmd.Parameters.AddWithValue("@relative_rot_y", data.velocity.Y); - cmd.Parameters.AddWithValue("@relative_rot_z", data.velocity.Z); + cmd.Parameters.AddWithValue("@relative_rot_x", data.CamRelativeRot.X); + cmd.Parameters.AddWithValue("@relative_rot_y", data.CamRelativeRot.Y); + cmd.Parameters.AddWithValue("@relative_rot_z", data.CamRelativeRot.Z); } cmd.Parameters.Add(new NpgsqlParameter("@guid", runId)); From c89bfe3a7d0630d84e21a5b9a5c9dec05712a7cb Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 20 Feb 2018 21:49:45 +0100 Subject: [PATCH 110/158] parameterized wait after camera switch --- managed/GTAVision.ini | 2 ++ managed/GTAVisionExport/CamerasList.cs | 9 ++++++++- managed/GTAVisionExport/VisionExport.cs | 5 +++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/managed/GTAVision.ini b/managed/GTAVision.ini index 6031450..a295d31 100644 --- a/managed/GTAVision.ini +++ b/managed/GTAVision.ini @@ -3,3 +3,5 @@ ConnectionString=Server=127.0.0.1;Port=5432;Database=gta_v;User Id=postgres;Pass [Snapshots] OutputDir=D:\GTAV_extraction_output\ LogFile=D:\Program Files\Rockstar Games\Grand Theft Auto V\my_log.txt +[MultiCamera] +GameplayTimeAfterSwitch=2000 \ No newline at end of file diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 6d0d472..74e3ef6 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.IO; using GTA; using GTA.Math; using GTA.Native; using GTAVisionUtils; +using IniParser; namespace GTAVisionExport { public static class CamerasList @@ -17,6 +19,7 @@ public static class CamerasList public static Vector3? activeCameraRotation { get; private set; } = null; + private static int? gameplayInterval = null; // public static Camera gameCam; private static bool initialized = false; @@ -27,6 +30,9 @@ public static void initialize() { World.DestroyAllCameras(); Logger.writeLine("destroying all cameras at the beginning, to be clear"); + var parser = new FileIniDataParser(); + var data = parser.ReadFile(Path.Combine(VisionExport.location, "GTAVision.ini")); + gameplayInterval = Convert.ToInt32(data["MultiCamera"]["GameplayTimeAfterSwitch"]); // gameCam = World.RenderingCamera; // mainCamera.IsActive = false; @@ -107,7 +113,8 @@ public static Camera ActivateCamera(int i) // //with time 1, sometimes depth does not correspond, and bounding boxes dont correspond by 3 frames // //with time 2, depth does correspond, but bounding boxes dont correspond by 2 frames // //with time 3, sometimes depth does not correspond, but bounding boxes dont correspond by 1 frames - Script.Wait(4);//tried 4 milliseconds instead of one, so screenshots correspond to their data +// Script.Wait(4);//tried 4 milliseconds instead of one, so screenshots correspond to their data + Script.Wait(gameplayInterval.Value); Game.Pause(true); // UI.Notify("new camera rotation is: " + rotation.ToString()); Script.Wait(20); diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index c1a00a0..cf21245 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -78,11 +78,12 @@ class VisionExport : Script { private bool timeIntervalEnabled = false; private TimeSpan timeFrom; private TimeSpan timeTo; + public static string location; public VisionExport() { // loading ini file var parser = new FileIniDataParser(); - var location = AppDomain.CurrentDomain.BaseDirectory; + location = AppDomain.CurrentDomain.BaseDirectory; var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini")); //UINotify(ConfigurationManager.AppSettings["database_connection"]); @@ -710,7 +711,7 @@ public void OnKeyDown(object o, KeyEventArgs k) { postgresTask?.Wait(); runTask?.Wait(); UINotify("starting screenshots"); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 3; i++) { GamePause(true); gatherData(100); GamePause(false); From b9dab2a6749b893463d802448a1ce7ec65d6ca05 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 22 Feb 2018 00:35:34 +0100 Subject: [PATCH 111/158] optional setting near clip, persisting model matrix --- managed/GTAVisionExport/CamerasList.cs | 55 +++++++++++---------- managed/GTAVisionUtils/GTADataStructures.cs | 2 + managed/GTAVisionUtils/PostgresExport.cs | 5 +- managed/README.md | 1 + 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 74e3ef6..24da401 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -8,18 +8,18 @@ using IniParser; namespace GTAVisionExport { - public static class CamerasList - { + public static class CamerasList { public static Camera mainCamera { get; private set; } public static Vector3 mainCameraPosition { get; private set; } - + public static List cameras { get; } = new List(); public static List camerasPositions { get; } = new List(); public static List camerasRotations { get; } = new List(); - - public static Vector3? activeCameraRotation { get; private set; } = null; - + + public static Vector3? activeCameraRotation { get; private set; } = null; + private static int? gameplayInterval = null; + // public static Camera gameCam; private static bool initialized = false; @@ -27,59 +27,62 @@ public static void initialize() { if (initialized) { return; } - + World.DestroyAllCameras(); Logger.writeLine("destroying all cameras at the beginning, to be clear"); var parser = new FileIniDataParser(); var data = parser.ReadFile(Path.Combine(VisionExport.location, "GTAVision.ini")); - gameplayInterval = Convert.ToInt32(data["MultiCamera"]["GameplayTimeAfterSwitch"]); + gameplayInterval = Convert.ToInt32(data["MultiCamera"]["GameplayTimeAfterSwitch"]); // gameCam = World.RenderingCamera; // mainCamera.IsActive = false; initialized = true; } - - public static void setMainCamera(Vector3 position, float? fov = null) - { + + public static void setMainCamera(Vector3 position, float? fov = null, float? nearClip = null) { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } Logger.writeLine("setting main camera"); - if (!fov.HasValue) - { + if (!fov.HasValue) { fov = GameplayCamera.FieldOfView; } + if (!nearClip.HasValue) { + nearClip = World.RenderingCamera.NearClip; + } mainCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value); + mainCamera.NearClip = nearClip.Value; // mainCamera.IsActive = true; mainCameraPosition = position; mainCamera.IsActive = false; World.RenderingCamera = null; } - - public static void addCamera(Vector3 position, Vector3 rotation, float? fov = null) - { + + public static void addCamera(Vector3 position, Vector3 rotation, float? fov = null, float? nearClip = null) { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } Logger.writeLine("adding new camera"); - if (!fov.HasValue) - { + if (!fov.HasValue) { fov = GameplayCamera.FieldOfView; } + if (!nearClip.HasValue) { + nearClip = World.RenderingCamera.NearClip; + } var newCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value); + newCamera.NearClip = nearClip.Value; cameras.Add(newCamera); camerasPositions.Add(position); camerasRotations.Add(rotation); } - public static void ActivateMainCamera() - { + public static void ActivateMainCamera() { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } @@ -93,8 +96,7 @@ public static void ActivateMainCamera() activeCameraRotation = new Vector3(); } - public static Camera ActivateCamera(int i) - { + public static Camera ActivateCamera(int i) { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } @@ -126,18 +128,17 @@ public static Camera ActivateCamera(int i) return cameras[i]; } - public static void Deactivate() - { + public static void Deactivate() { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } mainCamera.IsActive = false; - foreach (var camera in cameras) - { + foreach (var camera in cameras) { camera.IsActive = false; } + World.RenderingCamera = null; } } -} +} \ No newline at end of file diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index ae81647..d5469a7 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -186,6 +186,7 @@ public class GTAData //mathnet's matrices are in heap storage, which is super annoying, //but we want to use double matrices to avoid numerical issues as we //decompose the MVP matrix into seperate M,V and P matrices + public DenseMatrix WorldMatrix { get; set; } public DenseMatrix ViewMatrix { get; set; } public DenseMatrix ProjectionMatrix { get; set; } public double CamFOV { get; set; } @@ -357,6 +358,7 @@ public static GTAData DumpData(string imageName, List capturedWeathers) var P = WVP*WV.Inverse(); ret.ProjectionMatrix = P as DenseMatrix; ret.ViewMatrix = V as DenseMatrix; + ret.WorldMatrix = W as DenseMatrix; var pedList = from ped in peds where ped.IsHuman && ped.IsOnFoot diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 1f925b3..7dd48f7 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -178,12 +178,12 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { cmd.CommandText = "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_rot, " + "camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, " + - "cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation) " + + "cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation, world_matrix) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@rotx, @roty, @rotz), " + "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id, " + - camRelativeRotString + ") " + + camRelativeRotString + ", @world_matrix) " + "RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); @@ -202,6 +202,7 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { cmd.Parameters.AddWithValue("@fov", data.CamFOV); cmd.Parameters.AddWithValue("@view_matrix", data.ViewMatrix.ToArray()); cmd.Parameters.AddWithValue("@proj_matrix", data.ProjectionMatrix.ToArray()); + cmd.Parameters.AddWithValue("@world_matrix", data.WorldMatrix.ToArray()); cmd.Parameters.AddWithValue("@width", data.ImageWidth); cmd.Parameters.AddWithValue("@height", data.ImageHeight); // @ui_width, @ui_height, @player_pos, @cam_near_clip, @cam_far_clip diff --git a/managed/README.md b/managed/README.md index b6df697..e6abe5e 100644 --- a/managed/README.md +++ b/managed/README.md @@ -120,6 +120,7 @@ create table snapshots camera_relative_rotation geometry(PointZ), camera_direction geometry, camera_fov real, + world_matrix double precision[], view_matrix double precision[], proj_matrix double precision[], processed boolean default false not null, From 57605a5d76e0f4470323731a4c1ef2d67a9b7771 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 22 Feb 2018 01:06:17 +0100 Subject: [PATCH 112/158] specified near clip and fov for scripted camera --- managed/GTAVisionExport/VisionExport.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index cf21245..e9e6f1f 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -124,10 +124,10 @@ private void initialize4cameras() { // cameras initialization: float r = 8f; //radius of circle with 4 cameras CamerasList.setMainCamera(new Vector3(0f, 2f, 0.4f)); - CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f)); - CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f)); - CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f)); - CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f)); + CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); + CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); + CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); + CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); } private void handlePipeInput() { From 078086498e44c7878495da070fc7b0a081dd0d3b Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 26 Feb 2018 00:15:28 +0100 Subject: [PATCH 113/158] used SHVDN2 as a nuget package added script for showing pointcloud --- managed/GTAVisionExport/GTAVisionExport.csproj | 3 --- managed/GTAVisionExport/packages.config | 1 + managed/GTAVisionUtils/GTAVisionUtils.csproj | 7 ++----- managed/GTAVisionUtils/packages.config | 1 + 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index 7c47e80..d9d6dd5 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -89,9 +89,6 @@ - - ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll - D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll diff --git a/managed/GTAVisionExport/packages.config b/managed/GTAVisionExport/packages.config index cc24a5e..91fe7a0 100644 --- a/managed/GTAVisionExport/packages.config +++ b/managed/GTAVisionExport/packages.config @@ -11,6 +11,7 @@ + diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index 5c7eb8c..7bbc4a2 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -82,11 +82,8 @@ ..\packages\GDAL.1.11.1\lib\net40\osr_csharp.dll True - - ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll - - - D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll + + ..\packages\ScriptHookVDotNet2.2.10.3\lib\net452\ScriptHookVDotNet2.dll ..\packages\SharpDX.3.1.1\lib\net45\SharpDX.dll diff --git a/managed/GTAVisionUtils/packages.config b/managed/GTAVisionUtils/packages.config index fdbd910..a3ffc26 100644 --- a/managed/GTAVisionUtils/packages.config +++ b/managed/GTAVisionUtils/packages.config @@ -12,6 +12,7 @@ + From 3d2b6ec886d7d6215509ba0e8bdd16d118527745 Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 26 Feb 2018 16:57:30 +0100 Subject: [PATCH 114/158] added multiple cameras inspection scripts, added more inspections for multiple cameras. Added database schema as sql --- managed/README.md | 2 +- managed/structure_dump.sql | 791 +++++++++++++++++++++++++++++++++++++ 2 files changed, 792 insertions(+), 1 deletion(-) create mode 100644 managed/structure_dump.sql diff --git a/managed/README.md b/managed/README.md index e6abe5e..cedb7e6 100644 --- a/managed/README.md +++ b/managed/README.md @@ -399,7 +399,7 @@ Turn NativeUI notifications off by pressing "X" in the game. In settings, set up these things: - In Camera - - set First Person Velicle Hood to On + - set First Person Vehicle Hood to On - In Display - set Radar to Off - set HUD to Off diff --git a/managed/structure_dump.sql b/managed/structure_dump.sql new file mode 100644 index 0000000..a271c6c --- /dev/null +++ b/managed/structure_dump.sql @@ -0,0 +1,791 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 9.6.5 +-- Dumped by pg_dump version 9.6.5 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: postgres; Type: COMMENT; Schema: -; Owner: postgres +-- + +COMMENT ON DATABASE postgres IS 'default administrative connection database'; + + +-- +-- Name: tiger; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA tiger; + + +ALTER SCHEMA tiger OWNER TO postgres; + +-- +-- Name: tiger_data; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA tiger_data; + + +ALTER SCHEMA tiger_data OWNER TO postgres; + +-- +-- Name: topology; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA topology; + + +ALTER SCHEMA topology OWNER TO postgres; + +-- +-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; + + +-- +-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; + + +-- +-- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA public; + + +-- +-- Name: EXTENSION fuzzystrmatch; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION fuzzystrmatch IS 'determine similarities and distance between strings'; + + +-- +-- Name: postgis; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; + + +-- +-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions'; + + +-- +-- Name: postgis_tiger_geocoder; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder WITH SCHEMA tiger; + + +-- +-- Name: EXTENSION postgis_tiger_geocoder; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION postgis_tiger_geocoder IS 'PostGIS tiger geocoder and reverse geocoder'; + + +-- +-- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology; + + +-- +-- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions'; + + +SET search_path = public, pg_catalog; + +-- +-- Name: detection_class; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE detection_class AS ENUM ( + 'Unknown', + 'Compacts', + 'Sedans', + 'SUVs', + 'Coupes', + 'Muscle', + 'SportsClassics', + 'Sports', + 'Super', + 'Motorcycles', + 'OffRoad', + 'Industrial', + 'Utility', + 'Vans', + 'Cycles', + 'Boats', + 'Helicopters', + 'Planes', + 'Service', + 'Emergency', + 'Military', + 'Commercial', + 'Trains' +); + + +ALTER TYPE detection_class OWNER TO postgres; + +-- +-- Name: detection_type; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE detection_type AS ENUM ( + 'background', + 'person', + 'car', + 'bicycle' +); + + +ALTER TYPE detection_type OWNER TO postgres; + +-- +-- Name: weather; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE weather AS ENUM ( + 'Unknown', + 'ExtraSunny', + 'Clear', + 'Clouds', + 'Smog', + 'Foggy', + 'Overcast', + 'Raining', + 'ThunderStorm', + 'Clearing', + 'Neutral', + 'Snowing', + 'Blizzard', + 'Snowlight', + 'Christmas', + 'Halloween' +); + + +ALTER TYPE weather OWNER TO postgres; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: datasets; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE datasets ( + dataset_id integer NOT NULL, + dataset_name text, + view_name text, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE datasets OWNER TO postgres; + +-- +-- Name: datasets_dataset_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE datasets_dataset_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE datasets_dataset_id_seq OWNER TO postgres; + +-- +-- Name: datasets_dataset_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE datasets_dataset_id_seq OWNED BY datasets.dataset_id; + + +-- +-- Name: detections; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE detections ( + detection_id integer NOT NULL, + snapshot_id integer, + type detection_type, + pos geometry(PointZ), + bbox box, + class detection_class DEFAULT 'Unknown'::detection_class, + handle integer DEFAULT '-1'::integer, + best_bbox box, + best_bbox_old box, + bbox3d box3d, + rot geometry, + coverage real DEFAULT 0.0, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE detections OWNER TO postgres; + +-- +-- Name: detections_detection_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE detections_detection_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE detections_detection_id_seq OWNER TO postgres; + +-- +-- Name: detections_detection_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE detections_detection_id_seq OWNED BY detections.detection_id; + + +-- +-- Name: instances; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE instances ( + instance_id integer NOT NULL, + hostname text, + instanceid text, + instancetype text, + publichostname text, + amiid text, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE instances OWNER TO postgres; + +-- +-- Name: instances_instance_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE instances_instance_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE instances_instance_id_seq OWNER TO postgres; + +-- +-- Name: instances_instance_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE instances_instance_id_seq OWNED BY instances.instance_id; + + +-- +-- Name: runs; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE runs ( + run_id integer NOT NULL, + runguid uuid, + archivepath text, + localpath text, + session_id integer DEFAULT 1, + instance_id integer DEFAULT 0, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE runs OWNER TO postgres; + +-- +-- Name: runs_run_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE runs_run_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE runs_run_id_seq OWNER TO postgres; + +-- +-- Name: runs_run_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE runs_run_id_seq OWNED BY runs.run_id; + + +-- +-- Name: sessions; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE sessions ( + session_id integer NOT NULL, + name text, + start timestamp with time zone, + "end" timestamp with time zone, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE sessions OWNER TO postgres; + +-- +-- Name: sessions_session_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE sessions_session_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE sessions_session_id_seq OWNER TO postgres; + +-- +-- Name: sessions_session_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE sessions_session_id_seq OWNED BY sessions.session_id; + + +-- +-- Name: snapshot_weathers; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE snapshot_weathers ( + weather_id integer NOT NULL, + snapshot_id integer, + weather_type weather, + snapshot_page integer, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE snapshot_weathers OWNER TO postgres; + +-- +-- Name: snapshot_weathers_weather_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE snapshot_weathers_weather_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE snapshot_weathers_weather_id_seq OWNER TO postgres; + +-- +-- Name: snapshot_weathers_weather_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE snapshot_weathers_weather_id_seq OWNED BY snapshot_weathers.weather_id; + + +-- +-- Name: snapshots; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE snapshots ( + snapshot_id integer NOT NULL, + run_id integer, + version integer, + imagepath text, + "timestamp" timestamp with time zone, + timeofday time without time zone, + currentweather weather, + camera_pos geometry(PointZ), + camera_direction geometry, + camera_fov real, + view_matrix double precision[], + proj_matrix double precision[], + processed boolean DEFAULT false NOT NULL, + width integer, + height integer +); + + +ALTER TABLE snapshots OWNER TO postgres; + +-- +-- Name: snapshots_snapshot_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE snapshots_snapshot_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE snapshots_snapshot_id_seq OWNER TO postgres; + +-- +-- Name: snapshots_snapshot_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE snapshots_snapshot_id_seq OWNED BY snapshots.snapshot_id; + + +-- +-- Name: system_graphics; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE system_graphics ( + system_graphic_id integer NOT NULL, + deviceid text, + adaptercompatibility text, + adapterdactype text, + adapterram integer, + availability integer, + caption text, + description text, + driverdate timestamp with time zone, + driverversion text, + pnpdeviceid text, + name text, + videoarch integer, + memtype integer, + videoprocessor text, + bpp integer, + hrez integer, + vrez integer, + num_colors integer, + cols integer, + rows integer, + refresh integer, + scanmode integer, + videomodedesc text, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE system_graphics OWNER TO postgres; + +-- +-- Name: system_graphics_system_graphic_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE system_graphics_system_graphic_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE system_graphics_system_graphic_id_seq OWNER TO postgres; + +-- +-- Name: system_graphics_system_graphic_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE system_graphics_system_graphic_id_seq OWNED BY system_graphics.system_graphic_id; + + +-- +-- Name: systems; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE systems ( + system_uuid uuid NOT NULL, + vendor text, + dnshostname text, + username text, + systemtype text, + totalmem bigint, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE systems OWNER TO postgres; + +-- +-- Name: uploads; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE uploads ( + id integer NOT NULL, + bucket text, + key text, + uploadid text, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE uploads OWNER TO postgres; + +-- +-- Name: uploads_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE uploads_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE uploads_id_seq OWNER TO postgres; + +-- +-- Name: uploads_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE uploads_id_seq OWNED BY uploads.id; + + +-- +-- Name: datasets dataset_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY datasets ALTER COLUMN dataset_id SET DEFAULT nextval('datasets_dataset_id_seq'::regclass); + + +-- +-- Name: detections detection_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY detections ALTER COLUMN detection_id SET DEFAULT nextval('detections_detection_id_seq'::regclass); + + +-- +-- Name: instances instance_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY instances ALTER COLUMN instance_id SET DEFAULT nextval('instances_instance_id_seq'::regclass); + + +-- +-- Name: runs run_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY runs ALTER COLUMN run_id SET DEFAULT nextval('runs_run_id_seq'::regclass); + + +-- +-- Name: sessions session_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY sessions ALTER COLUMN session_id SET DEFAULT nextval('sessions_session_id_seq'::regclass); + + +-- +-- Name: snapshot_weathers weather_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY snapshot_weathers ALTER COLUMN weather_id SET DEFAULT nextval('snapshot_weathers_weather_id_seq'::regclass); + + +-- +-- Name: snapshots snapshot_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY snapshots ALTER COLUMN snapshot_id SET DEFAULT nextval('snapshots_snapshot_id_seq'::regclass); + + +-- +-- Name: system_graphics system_graphic_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY system_graphics ALTER COLUMN system_graphic_id SET DEFAULT nextval('system_graphics_system_graphic_id_seq'::regclass); + + +-- +-- Name: uploads id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY uploads ALTER COLUMN id SET DEFAULT nextval('uploads_id_seq'::regclass); + +-- +-- Name: datasets datasets_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY datasets + ADD CONSTRAINT datasets_pkey PRIMARY KEY (dataset_id); + + +-- +-- Name: detections detections_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY detections + ADD CONSTRAINT detections_pkey PRIMARY KEY (detection_id); + + +-- +-- Name: instances instance_info_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY instances + ADD CONSTRAINT instance_info_uniq UNIQUE (hostname, instanceid, instancetype, publichostname, amiid); + + +-- +-- Name: instances instanceid_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY instances + ADD CONSTRAINT instanceid_uniq UNIQUE (instanceid); + + +-- +-- Name: instances isntances_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY instances + ADD CONSTRAINT isntances_pkey PRIMARY KEY (instance_id); + + +-- +-- Name: runs runs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY runs + ADD CONSTRAINT runs_pkey PRIMARY KEY (run_id); + + +-- +-- Name: sessions sessions_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY sessions + ADD CONSTRAINT sessions_name_key UNIQUE (name); + + +-- +-- Name: sessions sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY sessions + ADD CONSTRAINT sessions_pkey PRIMARY KEY (session_id); + + +-- +-- Name: snapshot_weathers snapshot_weathers_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY snapshot_weathers + ADD CONSTRAINT snapshot_weathers_pkey PRIMARY KEY (weather_id); + + +-- +-- Name: snapshots snapshots_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY snapshots + ADD CONSTRAINT snapshots_pkey PRIMARY KEY (snapshot_id); + + +-- +-- Name: system_graphics system_graphics_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY system_graphics + ADD CONSTRAINT system_graphics_pkey PRIMARY KEY (system_graphic_id); + + +-- +-- Name: systems systems_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY systems + ADD CONSTRAINT systems_pkey PRIMARY KEY (system_uuid); + + +-- +-- Name: uploads uploads_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY uploads + ADD CONSTRAINT uploads_pkey PRIMARY KEY (id); + + +-- +-- Name: detections detections_snapshot_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY detections + ADD CONSTRAINT detections_snapshot_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots(snapshot_id) ON DELETE CASCADE; + + +-- +-- Name: runs runs_instance_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY runs + ADD CONSTRAINT runs_instance_fkey FOREIGN KEY (instance_id) REFERENCES instances(instance_id); + + +-- +-- Name: runs runs_session_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY runs + ADD CONSTRAINT runs_session_fkey FOREIGN KEY (session_id) REFERENCES sessions(session_id) ON DELETE CASCADE; + + +-- +-- Name: snapshot_weathers snapshot_weathers_snapshot_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY snapshot_weathers + ADD CONSTRAINT snapshot_weathers_snapshot_id_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots(snapshot_id) ON DELETE CASCADE; + + +-- +-- Name: snapshots snapshots_run_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY snapshots + ADD CONSTRAINT snapshots_run_fkey FOREIGN KEY (run_id) REFERENCES runs(run_id) ON DELETE CASCADE; + + +-- +-- PostgreSQL database dump complete +-- + From afdcdbe054a88e8a1d962403fc6aaab40ccd389a Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 6 Mar 2018 18:36:20 +0100 Subject: [PATCH 115/158] added infor about path and not seeing msbuild --- native/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/native/README.md b/native/README.md index 9524453..b9b3906 100644 --- a/native/README.md +++ b/native/README.md @@ -47,6 +47,18 @@ HTH FAQ --- +Can not configure in CMake, this message shows up: +``` +CMake Error at CMakeLists.txt:3 (project): + Failed to run MSBuild command: + + MSBuild.exe + + to get the value of VCTargetsPath: +``` + +This means your visual studio MSBuild is not in your PATH variable. + Can not configure in CMake, `gdi32.lib` is missing: This is probably due to incorrect Visual Studio SDK, can be solved by installing Windows 10 SDK (10.0.15063.0) for Desktop C++ x86 and x64 in the VS Installer. From 58504814dcad31ef272dba2e50039c12251cba12 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Mar 2018 12:58:36 +0100 Subject: [PATCH 116/158] formatted and updated structure dump. --- managed/structure_dump.sql | 620 +++++++++++++++++++------------------ 1 file changed, 316 insertions(+), 304 deletions(-) diff --git a/managed/structure_dump.sql b/managed/structure_dump.sql index a271c6c..b460765 100644 --- a/managed/structure_dump.sql +++ b/managed/structure_dump.sql @@ -9,10 +9,10 @@ SET statement_timeout = 0; SET lock_timeout = 0; SET idle_in_transaction_session_timeout = 0; SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SET check_function_bodies = false; -SET client_min_messages = warning; -SET row_security = off; +SET standard_conforming_strings = ON; +SET check_function_bodies = FALSE; +SET client_min_messages = WARNING; +SET row_security = OFF; -- -- Name: postgres; Type: COMMENT; Schema: -; Owner: postgres @@ -20,7 +20,6 @@ SET row_security = off; COMMENT ON DATABASE postgres IS 'default administrative connection database'; - -- -- Name: tiger; Type: SCHEMA; Schema: -; Owner: postgres -- @@ -28,7 +27,8 @@ COMMENT ON DATABASE postgres IS 'default administrative connection database'; CREATE SCHEMA tiger; -ALTER SCHEMA tiger OWNER TO postgres; +ALTER SCHEMA tiger +OWNER TO postgres; -- -- Name: tiger_data; Type: SCHEMA; Schema: -; Owner: postgres @@ -37,7 +37,8 @@ ALTER SCHEMA tiger OWNER TO postgres; CREATE SCHEMA tiger_data; -ALTER SCHEMA tiger_data OWNER TO postgres; +ALTER SCHEMA tiger_data +OWNER TO postgres; -- -- Name: topology; Type: SCHEMA; Schema: -; Owner: postgres @@ -46,7 +47,8 @@ ALTER SCHEMA tiger_data OWNER TO postgres; CREATE SCHEMA topology; -ALTER SCHEMA topology OWNER TO postgres; +ALTER SCHEMA topology +OWNER TO postgres; -- -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: @@ -54,63 +56,54 @@ ALTER SCHEMA topology OWNER TO postgres; CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - -- -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -- COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - -- -- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: -- CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA public; - -- -- Name: EXTENSION fuzzystrmatch; Type: COMMENT; Schema: -; Owner: -- COMMENT ON EXTENSION fuzzystrmatch IS 'determine similarities and distance between strings'; - -- -- Name: postgis; Type: EXTENSION; Schema: -; Owner: -- CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; - -- -- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: -- COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions'; - -- -- Name: postgis_tiger_geocoder; Type: EXTENSION; Schema: -; Owner: -- CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder WITH SCHEMA tiger; - -- -- Name: EXTENSION postgis_tiger_geocoder; Type: COMMENT; Schema: -; Owner: -- COMMENT ON EXTENSION postgis_tiger_geocoder IS 'PostGIS tiger geocoder and reverse geocoder'; - -- -- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: -- CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology; - -- -- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner: -- @@ -124,666 +117,685 @@ SET search_path = public, pg_catalog; -- Name: detection_class; Type: TYPE; Schema: public; Owner: postgres -- -CREATE TYPE detection_class AS ENUM ( - 'Unknown', - 'Compacts', - 'Sedans', - 'SUVs', - 'Coupes', - 'Muscle', - 'SportsClassics', - 'Sports', - 'Super', - 'Motorcycles', - 'OffRoad', - 'Industrial', - 'Utility', - 'Vans', - 'Cycles', - 'Boats', - 'Helicopters', - 'Planes', - 'Service', - 'Emergency', - 'Military', - 'Commercial', - 'Trains' +CREATE TYPE DETECTION_CLASS AS ENUM ( + 'Unknown', + 'Compacts', + 'Sedans', + 'SUVs', + 'Coupes', + 'Muscle', + 'SportsClassics', + 'Sports', + 'Super', + 'Motorcycles', + 'OffRoad', + 'Industrial', + 'Utility', + 'Vans', + 'Cycles', + 'Boats', + 'Helicopters', + 'Planes', + 'Service', + 'Emergency', + 'Military', + 'Commercial', + 'Trains' ); -ALTER TYPE detection_class OWNER TO postgres; +ALTER TYPE DETECTION_CLASS + OWNER TO postgres; -- -- Name: detection_type; Type: TYPE; Schema: public; Owner: postgres -- -CREATE TYPE detection_type AS ENUM ( - 'background', - 'person', - 'car', - 'bicycle' +CREATE TYPE DETECTION_TYPE AS ENUM ( + 'background', + 'person', + 'car', + 'bicycle' ); -ALTER TYPE detection_type OWNER TO postgres; +ALTER TYPE DETECTION_TYPE + OWNER TO postgres; -- -- Name: weather; Type: TYPE; Schema: public; Owner: postgres -- -CREATE TYPE weather AS ENUM ( - 'Unknown', - 'ExtraSunny', - 'Clear', - 'Clouds', - 'Smog', - 'Foggy', - 'Overcast', - 'Raining', - 'ThunderStorm', - 'Clearing', - 'Neutral', - 'Snowing', - 'Blizzard', - 'Snowlight', - 'Christmas', - 'Halloween' +CREATE TYPE WEATHER AS ENUM ( + 'Unknown', + 'ExtraSunny', + 'Clear', + 'Clouds', + 'Smog', + 'Foggy', + 'Overcast', + 'Raining', + 'ThunderStorm', + 'Clearing', + 'Neutral', + 'Snowing', + 'Blizzard', + 'Snowlight', + 'Christmas', + 'Halloween' ); -ALTER TYPE weather OWNER TO postgres; +ALTER TYPE WEATHER + OWNER TO postgres; SET default_tablespace = ''; -SET default_with_oids = false; +SET default_with_oids = FALSE; -- -- Name: datasets; Type: TABLE; Schema: public; Owner: postgres -- CREATE TABLE datasets ( - dataset_id integer NOT NULL, - dataset_name text, - view_name text, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) + dataset_id INTEGER NOT NULL, + dataset_name TEXT, + view_name TEXT, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) ); -ALTER TABLE datasets OWNER TO postgres; +ALTER TABLE datasets + OWNER TO postgres; -- -- Name: datasets_dataset_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE datasets_dataset_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE datasets_dataset_id_seq OWNER TO postgres; +ALTER TABLE datasets_dataset_id_seq + OWNER TO postgres; -- -- Name: datasets_dataset_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE datasets_dataset_id_seq OWNED BY datasets.dataset_id; - +ALTER SEQUENCE datasets_dataset_id_seq +OWNED BY datasets.dataset_id; -- -- Name: detections; Type: TABLE; Schema: public; Owner: postgres -- -CREATE TABLE detections ( - detection_id integer NOT NULL, - snapshot_id integer, - type detection_type, - pos geometry(PointZ), - bbox box, - class detection_class DEFAULT 'Unknown'::detection_class, - handle integer DEFAULT '-1'::integer, - best_bbox box, - best_bbox_old box, - bbox3d box3d, - rot geometry, - coverage real DEFAULT 0.0, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) +CREATE TABLE detections +( + detection_id SERIAL NOT NULL + CONSTRAINT detections_pkey + PRIMARY KEY, + snapshot_id INTEGER, + type DETECTION_TYPE, + pos GEOMETRY(PointZ), + bbox BOX, + class DETECTION_CLASS DEFAULT 'Unknown' :: DETECTION_CLASS, + handle INTEGER DEFAULT '-1' :: INTEGER, + best_bbox BOX, + best_bbox_old BOX, + bbox3d BOX3D, + rot GEOMETRY, + coverage REAL DEFAULT 0.0, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'utc'), + velocity GEOMETRY(PointZ) ); - - -ALTER TABLE detections OWNER TO postgres; +ALTER TABLE detections + OWNER TO postgres; -- -- Name: detections_detection_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE detections_detection_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE detections_detection_id_seq OWNER TO postgres; +ALTER TABLE detections_detection_id_seq + OWNER TO postgres; -- -- Name: detections_detection_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE detections_detection_id_seq OWNED BY detections.detection_id; - +ALTER SEQUENCE detections_detection_id_seq +OWNED BY detections.detection_id; -- -- Name: instances; Type: TABLE; Schema: public; Owner: postgres -- CREATE TABLE instances ( - instance_id integer NOT NULL, - hostname text, - instanceid text, - instancetype text, - publichostname text, - amiid text, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) + instance_id INTEGER NOT NULL, + hostname TEXT, + instanceid TEXT, + instancetype TEXT, + publichostname TEXT, + amiid TEXT, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) ); -ALTER TABLE instances OWNER TO postgres; +ALTER TABLE instances + OWNER TO postgres; -- -- Name: instances_instance_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE instances_instance_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE instances_instance_id_seq OWNER TO postgres; +ALTER TABLE instances_instance_id_seq + OWNER TO postgres; -- -- Name: instances_instance_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE instances_instance_id_seq OWNED BY instances.instance_id; - +ALTER SEQUENCE instances_instance_id_seq +OWNED BY instances.instance_id; -- -- Name: runs; Type: TABLE; Schema: public; Owner: postgres -- CREATE TABLE runs ( - run_id integer NOT NULL, - runguid uuid, - archivepath text, - localpath text, - session_id integer DEFAULT 1, - instance_id integer DEFAULT 0, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) + run_id INTEGER NOT NULL, + runguid UUID, + archivepath TEXT, + localpath TEXT, + session_id INTEGER DEFAULT 1, + instance_id INTEGER DEFAULT 0, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) ); -ALTER TABLE runs OWNER TO postgres; +ALTER TABLE runs + OWNER TO postgres; -- -- Name: runs_run_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE runs_run_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE runs_run_id_seq OWNER TO postgres; +ALTER TABLE runs_run_id_seq + OWNER TO postgres; -- -- Name: runs_run_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE runs_run_id_seq OWNED BY runs.run_id; - +ALTER SEQUENCE runs_run_id_seq +OWNED BY runs.run_id; -- -- Name: sessions; Type: TABLE; Schema: public; Owner: postgres -- CREATE TABLE sessions ( - session_id integer NOT NULL, - name text, - start timestamp with time zone, - "end" timestamp with time zone, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) + session_id INTEGER NOT NULL, + name TEXT, + start TIMESTAMP WITH TIME ZONE, + "end" TIMESTAMP WITH TIME ZONE, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) ); -ALTER TABLE sessions OWNER TO postgres; +ALTER TABLE sessions + OWNER TO postgres; -- -- Name: sessions_session_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE sessions_session_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE sessions_session_id_seq OWNER TO postgres; +ALTER TABLE sessions_session_id_seq + OWNER TO postgres; -- -- Name: sessions_session_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE sessions_session_id_seq OWNED BY sessions.session_id; - +ALTER SEQUENCE sessions_session_id_seq +OWNED BY sessions.session_id; -- -- Name: snapshot_weathers; Type: TABLE; Schema: public; Owner: postgres -- CREATE TABLE snapshot_weathers ( - weather_id integer NOT NULL, - snapshot_id integer, - weather_type weather, - snapshot_page integer, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) + weather_id INTEGER NOT NULL, + snapshot_id INTEGER, + weather_type WEATHER, + snapshot_page INTEGER, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) ); -ALTER TABLE snapshot_weathers OWNER TO postgres; +ALTER TABLE snapshot_weathers + OWNER TO postgres; -- -- Name: snapshot_weathers_weather_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE snapshot_weathers_weather_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE snapshot_weathers_weather_id_seq OWNER TO postgres; +ALTER TABLE snapshot_weathers_weather_id_seq + OWNER TO postgres; -- -- Name: snapshot_weathers_weather_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE snapshot_weathers_weather_id_seq OWNED BY snapshot_weathers.weather_id; - - --- --- Name: snapshots; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE snapshots ( - snapshot_id integer NOT NULL, - run_id integer, - version integer, - imagepath text, - "timestamp" timestamp with time zone, - timeofday time without time zone, - currentweather weather, - camera_pos geometry(PointZ), - camera_direction geometry, - camera_fov real, - view_matrix double precision[], - proj_matrix double precision[], - processed boolean DEFAULT false NOT NULL, - width integer, - height integer +ALTER SEQUENCE snapshot_weathers_weather_id_seq +OWNED BY snapshot_weathers.weather_id; + + +CREATE TABLE snapshots +( + snapshot_id SERIAL NOT NULL + CONSTRAINT snapshots_pkey + PRIMARY KEY, + run_id INTEGER + CONSTRAINT snapshots_run_fkey + REFERENCES runs, + version INTEGER, + scene_id UUID, + imagepath TEXT, + timestamp TIMESTAMP WITH TIME ZONE, + timeofday TIME, + currentweather WEATHER, + camera_pos GEOMETRY(PointZ), + camera_rot GEOMETRY(PointZ), + camera_relative_rotation GEOMETRY(PointZ), + camera_direction GEOMETRY, + camera_fov REAL, + world_matrix DOUBLE PRECISION [], + view_matrix DOUBLE PRECISION [], + proj_matrix DOUBLE PRECISION [], + processed BOOLEAN DEFAULT FALSE NOT NULL, + width INTEGER, + height INTEGER, + ui_width INTEGER, + ui_height INTEGER, + cam_near_clip REAL, + cam_far_clip REAL, + player_pos GEOMETRY(PointZ), + velocity GEOMETRY(PointZ) ); -ALTER TABLE snapshots OWNER TO postgres; +ALTER TABLE snapshots + OWNER TO postgres; -- -- Name: snapshots_snapshot_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE snapshots_snapshot_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE snapshots_snapshot_id_seq OWNER TO postgres; +ALTER TABLE snapshots_snapshot_id_seq + OWNER TO postgres; -- -- Name: snapshots_snapshot_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE snapshots_snapshot_id_seq OWNED BY snapshots.snapshot_id; - +ALTER SEQUENCE snapshots_snapshot_id_seq +OWNED BY snapshots.snapshot_id; -- -- Name: system_graphics; Type: TABLE; Schema: public; Owner: postgres -- CREATE TABLE system_graphics ( - system_graphic_id integer NOT NULL, - deviceid text, - adaptercompatibility text, - adapterdactype text, - adapterram integer, - availability integer, - caption text, - description text, - driverdate timestamp with time zone, - driverversion text, - pnpdeviceid text, - name text, - videoarch integer, - memtype integer, - videoprocessor text, - bpp integer, - hrez integer, - vrez integer, - num_colors integer, - cols integer, - rows integer, - refresh integer, - scanmode integer, - videomodedesc text, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) + system_graphic_id INTEGER NOT NULL, + deviceid TEXT, + adaptercompatibility TEXT, + adapterdactype TEXT, + adapterram INTEGER, + availability INTEGER, + caption TEXT, + description TEXT, + driverdate TIMESTAMP WITH TIME ZONE, + driverversion TEXT, + pnpdeviceid TEXT, + name TEXT, + videoarch INTEGER, + memtype INTEGER, + videoprocessor TEXT, + bpp INTEGER, + hrez INTEGER, + vrez INTEGER, + num_colors INTEGER, + cols INTEGER, + rows INTEGER, + refresh INTEGER, + scanmode INTEGER, + videomodedesc TEXT, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) ); -ALTER TABLE system_graphics OWNER TO postgres; +ALTER TABLE system_graphics + OWNER TO postgres; -- -- Name: system_graphics_system_graphic_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE system_graphics_system_graphic_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE system_graphics_system_graphic_id_seq OWNER TO postgres; +ALTER TABLE system_graphics_system_graphic_id_seq + OWNER TO postgres; -- -- Name: system_graphics_system_graphic_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE system_graphics_system_graphic_id_seq OWNED BY system_graphics.system_graphic_id; - +ALTER SEQUENCE system_graphics_system_graphic_id_seq +OWNED BY system_graphics.system_graphic_id; -- -- Name: systems; Type: TABLE; Schema: public; Owner: postgres -- CREATE TABLE systems ( - system_uuid uuid NOT NULL, - vendor text, - dnshostname text, - username text, - systemtype text, - totalmem bigint, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) + system_uuid UUID NOT NULL, + vendor TEXT, + dnshostname TEXT, + username TEXT, + systemtype TEXT, + totalmem BIGINT, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) ); -ALTER TABLE systems OWNER TO postgres; +ALTER TABLE systems + OWNER TO postgres; -- -- Name: uploads; Type: TABLE; Schema: public; Owner: postgres -- CREATE TABLE uploads ( - id integer NOT NULL, - bucket text, - key text, - uploadid text, - created timestamp without time zone DEFAULT timezone('utc'::text, now()) + id INTEGER NOT NULL, + bucket TEXT, + key TEXT, + uploadid TEXT, + created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) ); -ALTER TABLE uploads OWNER TO postgres; +ALTER TABLE uploads + OWNER TO postgres; -- -- Name: uploads_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres -- CREATE SEQUENCE uploads_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE uploads_id_seq OWNER TO postgres; +ALTER TABLE uploads_id_seq + OWNER TO postgres; -- -- Name: uploads_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres -- -ALTER SEQUENCE uploads_id_seq OWNED BY uploads.id; - +ALTER SEQUENCE uploads_id_seq +OWNED BY uploads.id; -- -- Name: datasets dataset_id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY datasets ALTER COLUMN dataset_id SET DEFAULT nextval('datasets_dataset_id_seq'::regclass); - +ALTER TABLE ONLY datasets + ALTER COLUMN dataset_id SET DEFAULT nextval('datasets_dataset_id_seq' :: REGCLASS); -- -- Name: detections detection_id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY detections ALTER COLUMN detection_id SET DEFAULT nextval('detections_detection_id_seq'::regclass); - +ALTER TABLE ONLY detections + ALTER COLUMN detection_id SET DEFAULT nextval('detections_detection_id_seq' :: REGCLASS); -- -- Name: instances instance_id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY instances ALTER COLUMN instance_id SET DEFAULT nextval('instances_instance_id_seq'::regclass); - +ALTER TABLE ONLY instances + ALTER COLUMN instance_id SET DEFAULT nextval('instances_instance_id_seq' :: REGCLASS); -- -- Name: runs run_id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY runs ALTER COLUMN run_id SET DEFAULT nextval('runs_run_id_seq'::regclass); - +ALTER TABLE ONLY runs + ALTER COLUMN run_id SET DEFAULT nextval('runs_run_id_seq' :: REGCLASS); -- -- Name: sessions session_id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY sessions ALTER COLUMN session_id SET DEFAULT nextval('sessions_session_id_seq'::regclass); - +ALTER TABLE ONLY sessions + ALTER COLUMN session_id SET DEFAULT nextval('sessions_session_id_seq' :: REGCLASS); -- -- Name: snapshot_weathers weather_id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY snapshot_weathers ALTER COLUMN weather_id SET DEFAULT nextval('snapshot_weathers_weather_id_seq'::regclass); - +ALTER TABLE ONLY snapshot_weathers + ALTER COLUMN weather_id SET DEFAULT nextval('snapshot_weathers_weather_id_seq' :: REGCLASS); -- -- Name: snapshots snapshot_id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY snapshots ALTER COLUMN snapshot_id SET DEFAULT nextval('snapshots_snapshot_id_seq'::regclass); - +ALTER TABLE ONLY snapshots + ALTER COLUMN snapshot_id SET DEFAULT nextval('snapshots_snapshot_id_seq' :: REGCLASS); -- -- Name: system_graphics system_graphic_id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY system_graphics ALTER COLUMN system_graphic_id SET DEFAULT nextval('system_graphics_system_graphic_id_seq'::regclass); - +ALTER TABLE ONLY system_graphics + ALTER COLUMN system_graphic_id SET DEFAULT nextval('system_graphics_system_graphic_id_seq' :: REGCLASS); -- -- Name: uploads id; Type: DEFAULT; Schema: public; Owner: postgres -- -ALTER TABLE ONLY uploads ALTER COLUMN id SET DEFAULT nextval('uploads_id_seq'::regclass); +ALTER TABLE ONLY uploads + ALTER COLUMN id SET DEFAULT nextval('uploads_id_seq' :: REGCLASS); -- -- Name: datasets datasets_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY datasets - ADD CONSTRAINT datasets_pkey PRIMARY KEY (dataset_id); - + ADD CONSTRAINT datasets_pkey PRIMARY KEY (dataset_id); -- -- Name: detections detections_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY detections - ADD CONSTRAINT detections_pkey PRIMARY KEY (detection_id); - + ADD CONSTRAINT detections_pkey PRIMARY KEY (detection_id); -- -- Name: instances instance_info_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY instances - ADD CONSTRAINT instance_info_uniq UNIQUE (hostname, instanceid, instancetype, publichostname, amiid); - + ADD CONSTRAINT instance_info_uniq UNIQUE (hostname, instanceid, instancetype, publichostname, amiid); -- -- Name: instances instanceid_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY instances - ADD CONSTRAINT instanceid_uniq UNIQUE (instanceid); - + ADD CONSTRAINT instanceid_uniq UNIQUE (instanceid); -- -- Name: instances isntances_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY instances - ADD CONSTRAINT isntances_pkey PRIMARY KEY (instance_id); - + ADD CONSTRAINT isntances_pkey PRIMARY KEY (instance_id); -- -- Name: runs runs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY runs - ADD CONSTRAINT runs_pkey PRIMARY KEY (run_id); - + ADD CONSTRAINT runs_pkey PRIMARY KEY (run_id); -- -- Name: sessions sessions_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY sessions - ADD CONSTRAINT sessions_name_key UNIQUE (name); - + ADD CONSTRAINT sessions_name_key UNIQUE (name); -- -- Name: sessions sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY sessions - ADD CONSTRAINT sessions_pkey PRIMARY KEY (session_id); - + ADD CONSTRAINT sessions_pkey PRIMARY KEY (session_id); -- -- Name: snapshot_weathers snapshot_weathers_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY snapshot_weathers - ADD CONSTRAINT snapshot_weathers_pkey PRIMARY KEY (weather_id); - + ADD CONSTRAINT snapshot_weathers_pkey PRIMARY KEY (weather_id); -- -- Name: snapshots snapshots_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY snapshots - ADD CONSTRAINT snapshots_pkey PRIMARY KEY (snapshot_id); - + ADD CONSTRAINT snapshots_pkey PRIMARY KEY (snapshot_id); -- -- Name: system_graphics system_graphics_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY system_graphics - ADD CONSTRAINT system_graphics_pkey PRIMARY KEY (system_graphic_id); - + ADD CONSTRAINT system_graphics_pkey PRIMARY KEY (system_graphic_id); -- -- Name: systems systems_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY systems - ADD CONSTRAINT systems_pkey PRIMARY KEY (system_uuid); - + ADD CONSTRAINT systems_pkey PRIMARY KEY (system_uuid); -- -- Name: uploads uploads_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY uploads - ADD CONSTRAINT uploads_pkey PRIMARY KEY (id); - + ADD CONSTRAINT uploads_pkey PRIMARY KEY (id); -- -- Name: detections detections_snapshot_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY detections - ADD CONSTRAINT detections_snapshot_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots(snapshot_id) ON DELETE CASCADE; - + ADD CONSTRAINT detections_snapshot_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots (snapshot_id) ON DELETE CASCADE; -- -- Name: runs runs_instance_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY runs - ADD CONSTRAINT runs_instance_fkey FOREIGN KEY (instance_id) REFERENCES instances(instance_id); - + ADD CONSTRAINT runs_instance_fkey FOREIGN KEY (instance_id) REFERENCES instances (instance_id); -- -- Name: runs runs_session_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY runs - ADD CONSTRAINT runs_session_fkey FOREIGN KEY (session_id) REFERENCES sessions(session_id) ON DELETE CASCADE; - + ADD CONSTRAINT runs_session_fkey FOREIGN KEY (session_id) REFERENCES sessions (session_id) ON DELETE CASCADE; -- -- Name: snapshot_weathers snapshot_weathers_snapshot_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY snapshot_weathers - ADD CONSTRAINT snapshot_weathers_snapshot_id_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots(snapshot_id) ON DELETE CASCADE; - + ADD CONSTRAINT snapshot_weathers_snapshot_id_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots (snapshot_id) ON DELETE CASCADE; -- -- Name: snapshots snapshots_run_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres -- ALTER TABLE ONLY snapshots - ADD CONSTRAINT snapshots_run_fkey FOREIGN KEY (run_id) REFERENCES runs(run_id) ON DELETE CASCADE; - + ADD CONSTRAINT snapshots_run_fkey FOREIGN KEY (run_id) REFERENCES runs (run_id) ON DELETE CASCADE; -- -- PostgreSQL database dump complete From 513d4a1444af9b8dc4112aded4b6e3812635a486 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Mar 2018 13:06:06 +0100 Subject: [PATCH 117/158] fixed db dump --- managed/structure_dump.sql | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/managed/structure_dump.sql b/managed/structure_dump.sql index b460765..3bf23e1 100644 --- a/managed/structure_dump.sql +++ b/managed/structure_dump.sql @@ -236,9 +236,7 @@ OWNED BY datasets.dataset_id; CREATE TABLE detections ( - detection_id SERIAL NOT NULL - CONSTRAINT detections_pkey - PRIMARY KEY, + detection_id SERIAL NOT NULL, snapshot_id INTEGER, type DETECTION_TYPE, pos GEOMETRY(PointZ), @@ -437,12 +435,8 @@ OWNED BY snapshot_weathers.weather_id; CREATE TABLE snapshots ( - snapshot_id SERIAL NOT NULL - CONSTRAINT snapshots_pkey - PRIMARY KEY, - run_id INTEGER - CONSTRAINT snapshots_run_fkey - REFERENCES runs, + snapshot_id SERIAL NOT NULL, + run_id INTEGER, version INTEGER, scene_id UUID, imagepath TEXT, From 768cbe384d07b4bcdd3e0917f0abc5d55058dfe3 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Mar 2018 14:33:47 +0100 Subject: [PATCH 118/158] update readme, removed aws library, fixed libraries --- managed/GTAVisionExport/GTAVisionExport.csproj | 17 +++++++++++------ managed/GTAVisionExport/VisionExport.cs | 6 ------ managed/GTAVisionExport/packages.config | 1 - managed/GTAVisionUtils/GTAVisionUtils.csproj | 3 +++ managed/README.md | 4 ++++ 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index d9d6dd5..28eed07 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -51,10 +51,6 @@ true - - ..\packages\AWSSDK.2.3.55.2\lib\net45\AWSSDK.dll - True - ..\packages\BitMiracle.LibTiff.NET.2.4.571\lib\net20\BitMiracle.LibTiff.NET.dll True @@ -81,6 +77,9 @@ D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + + ..\NativeUI.dll + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll @@ -89,8 +88,8 @@ - - D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\ScriptHookVDotNet2.dll + + ..\packages\ScriptHookVDotNet2.2.10.3\lib\net452\ScriptHookVDotNet2.dll @@ -121,12 +120,18 @@ D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + + ..\376923-VAutodrive V8.0.3\Scripts\VAutodrive.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + + ..\376923-VAutodrive V8.0.3\Scripts\VCommonFunctions.dll + ..\packages\YamlDotNet.4.1.0\lib\net35\YamlDotNet.dll diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index e9e6f1f..565f7d8 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -15,12 +15,7 @@ using BitMiracle.LibTiff.Classic; using System.Drawing; using System.Drawing.Imaging; -using Amazon; -using Amazon.Runtime; using YamlDotNet.RepresentationModel; -using Amazon.S3; -using Amazon.S3.IO; -using Amazon.S3.Model; using System.IO.Pipes; using System.Net; using VAutodrive; @@ -34,7 +29,6 @@ using Color = System.Windows.Media.Color; using System.Configuration; using System.Threading; -using Amazon.ElasticLoadBalancing.Model; using IniParser; using Newtonsoft.Json; diff --git a/managed/GTAVisionExport/packages.config b/managed/GTAVisionExport/packages.config index 91fe7a0..1186e2f 100644 --- a/managed/GTAVisionExport/packages.config +++ b/managed/GTAVisionExport/packages.config @@ -1,6 +1,5 @@  - diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index 7bbc4a2..ba88c4f 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -71,6 +71,9 @@ D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + + ..\NativeUI.dll + ..\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll diff --git a/managed/README.md b/managed/README.md index cedb7e6..44eccdc 100644 --- a/managed/README.md +++ b/managed/README.md @@ -377,6 +377,10 @@ To verify all plugins loaded, see the `ScriptHookVDotNet2.log` and search for th If less than 10 scripts loaded, you have problem. +If you have `ScriptHookVDotNet2.dll` in the scripts directory, you need to remove it. + +If only 1 script is loaded (NativeUI), it can be solved by + ## Usage ### Dependencies setup From d08608cbf613b5c5c84a3f32876547878f4273d7 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 7 Mar 2018 14:38:13 +0100 Subject: [PATCH 119/158] updated advice when scripts dont load --- managed/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/managed/README.md b/managed/README.md index 44eccdc..82d709c 100644 --- a/managed/README.md +++ b/managed/README.md @@ -328,7 +328,6 @@ $$; ## Copying compiled files to GTA V After you compile the GTAVisionExport, copy compiled files from the `path to GTAVisionExport/managed/GTAVisionExport/bin/Release` to `path to GTA V/scripts`. Content of `scripts` directory should be following: -- AWSSDK.dll - BitMiracle.LibTiff.NET.dll - BitMiracle.LibTiff.NET.xml - gdal_csharp.dll @@ -379,7 +378,8 @@ If less than 10 scripts loaded, you have problem. If you have `ScriptHookVDotNet2.dll` in the scripts directory, you need to remove it. -If only 1 script is loaded (NativeUI), it can be solved by +If only 1 script is loaded (NativeUI), it can be solved by removing `YamlDotNet.pdb` from your scripts dir. +You should not have any .pdb files except of your own dlls (`GTAVisionExport.pdb` and `GTAVisionUtils.pdb`) ## Usage From e8a0ba3a503e5751d18d73d9d9032b7a3c8b8328 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 29 Mar 2018 18:52:50 +0200 Subject: [PATCH 120/158] set 4 cameras on the car, back to 0.15 near clip. Added debug function for 3D boxes diaplying --- managed/GTAVisionExport/CameraHandling.cs | 49 ++++++++++++++++++- .../GTAVisionExport/GTAVisionExport.csproj | 7 ++- managed/GTAVisionExport/VisionExport.cs | 20 ++++++-- managed/GTAVisionExport/packages.config | 2 + managed/GTAVisionUtils/HashFunctions.cs | 15 ++++++ 5 files changed, 85 insertions(+), 8 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index d1e5470..5106503 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -7,6 +7,8 @@ using GTA.Native; using GTA.Math; using GTAVisionUtils; +using MathNet.Spatial.Euclidean; +using MathNet.Spatial.Units; namespace GTAVisionExport { // Controls: @@ -18,9 +20,10 @@ public class CameraHandling : Script { private Camera activeCamera; private bool enabled = false; private int activeCameraIndex = -1; + private bool showCameras = false; public CameraHandling() { - UI.Notify("Loaded TestVehicle.cs"); + UI.Notify("Loaded CameraHandling.cs"); // create a new camera // World.DestroyAllCameras(); @@ -80,6 +83,21 @@ private void onKeyUp(object sender, KeyEventArgs e) { enabled = false; } +// UI.Notify("keycode is:" + e.KeyCode); + + if (e.KeyCode == Keys.Add) { + UI.Notify("Pressed numpad +"); + showCameras = !showCameras; + UI.Notify("there are " + CamerasList.camerasPositions.Count + " cameras"); + if (showCameras) { + UI.Notify("enabled cameras showing"); + } + else { + UI.Notify("disabled cameras showing"); + } + + } + if (e.KeyCode == Keys.NumPad0) { UI.Notify("Pressed numpad 0"); activeCameraIndex = 0; @@ -113,6 +131,35 @@ private void onKeyUp(object sender, KeyEventArgs e) { void OnTick(object sender, EventArgs e) { keepCameraOnVehicle(); + if (showCameras) { + drawCamerasBoxes(); + } + } + + void drawCamerasBoxes() { +// this shows white boxes where cameras are + foreach (var camPos in CamerasList.camerasPositions) { + var curVehicle = Game.Player.Character.CurrentVehicle; +// Logger.writeLine("rotation"); +// Logger.writeLine(curVehicle.Rotation); +// Logger.writeLine("forward vector"); +// Logger.writeLine(curVehicle.ForwardVector); +// Logger.writeLine("right vector"); +// Logger.writeLine(curVehicle.RightVector); +// Logger.writeLine("up vector"); +// Logger.writeLine(curVehicle.UpVector); +// var camPosToCar = Vector3.Modulate(curVehicle.ForwardVector, cameraPosition); +// camPosToCar += Vector3.Modulate(curVehicle.RightVector, cameraPosition); +// camPosToCar += Vector3.Modulate(curVehicle.UpVector, cameraPosition); + var rot = curVehicle.Rotation; + var rotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(rot.X)); + var rotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(rot.Y)); + var rotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(rot.Z)); + var rotMat = rotX * rotY * rotZ; + var camPosToCar = rotMat * new Vector3D(camPos.X, camPos.Y, camPos.Z); + var absolutePosition = curVehicle.Position + new Vector3((float) camPosToCar[0], (float) camPosToCar[1], (float) camPosToCar[2]); + HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f)); + } } } } \ No newline at end of file diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index 28eed07..ec7dd08 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -58,8 +58,11 @@ ..\packages\ini-parser.2.4.0\lib\net20\INIFileParser.dll - - ..\packages\MathNet.Numerics.3.17.0\lib\net40\MathNet.Numerics.dll + + ..\packages\MathNet.Numerics.3.8.0\lib\net40\MathNet.Numerics.dll + + + ..\packages\MathNet.Spatial.0.4.0\lib\net40\MathNet.Spatial.dll ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.0\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 565f7d8..9177e45 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -116,12 +116,22 @@ public VisionExport() { private void initialize4cameras() { // cameras initialization: - float r = 8f; //radius of circle with 4 cameras + +// for cameras mapping area before the car +// float r = 8f; //radius of circle with 4 cameras +// CamerasList.setMainCamera(new Vector3(0f, 2f, 0.4f)); +// CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); +// CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); +// CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); +// CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); + +// for 4 cameras of different sides of the car CamerasList.setMainCamera(new Vector3(0f, 2f, 0.4f)); - CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); - CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); - CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); - CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); + CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 0.15f); + CamerasList.addCamera(new Vector3(-0.6f, 0f, 0.8f), new Vector3(0f, 0f, 90f), 50, 0.15f); + CamerasList.addCamera(new Vector3(0f, -2f, 0.6f), new Vector3(0f, 0f, 180f), 50, 0.15f); + CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); + } private void handlePipeInput() { diff --git a/managed/GTAVisionExport/packages.config b/managed/GTAVisionExport/packages.config index 1186e2f..c8bb455 100644 --- a/managed/GTAVisionExport/packages.config +++ b/managed/GTAVisionExport/packages.config @@ -2,6 +2,8 @@ + + diff --git a/managed/GTAVisionUtils/HashFunctions.cs b/managed/GTAVisionUtils/HashFunctions.cs index 1657cf3..bad6fbc 100644 --- a/managed/GTAVisionUtils/HashFunctions.cs +++ b/managed/GTAVisionUtils/HashFunctions.cs @@ -42,6 +42,21 @@ public static void Draw3DLine(Vector3 iniPos, Vector3 finPos, byte col_r = 255, (int)col_a }); } + + public static void Draw3DBox(Vector3 pos, Vector3 size, byte col_r = 255, byte col_g = 255, byte col_b = 255, byte col_a = 255) { + Function.Call(Hash.DRAW_BOX, new InputArgument[] { + pos.X - size.X / 2, + pos.Y - size.Y / 2, + pos.Z - size.Z / 2, + pos.X + size.X / 2, + pos.Y + size.Y / 2, + pos.Z + size.Z / 2, + (int)col_r, + (int)col_g, + (int)col_b, + (int)col_a + }); + } public static void Draw3DLine(Vector3 iniPos, Vector3 finPos, Color color) { Draw3DLine(iniPos, finPos, color.R, color.G, color.B, color.A); From e299f7f443451db3bb532e3e865bc80c551a6548 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 30 Mar 2018 14:32:27 +0200 Subject: [PATCH 121/158] camera relative position is persisted into db along with relative rotation --- managed/GTAVisionExport/CamerasList.cs | 3 +++ managed/GTAVisionExport/VisionExport.cs | 9 ++++++++- managed/GTAVisionUtils/GTADataStructures.cs | 1 + managed/GTAVisionUtils/PostgresExport.cs | 15 ++++++++++++--- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 24da401..5588573 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -17,6 +17,7 @@ public static class CamerasList { public static List camerasRotations { get; } = new List(); public static Vector3? activeCameraRotation { get; private set; } = null; + public static Vector3? activeCameraPosition { get; private set; } = null; private static int? gameplayInterval = null; @@ -94,6 +95,7 @@ public static void ActivateMainCamera() { mainCamera.IsActive = true; World.RenderingCamera = mainCamera; activeCameraRotation = new Vector3(); + activeCameraPosition = new Vector3(); } public static Camera ActivateCamera(int i) { @@ -125,6 +127,7 @@ public static Camera ActivateCamera(int i) { Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); Logger.writeLine("new camera rotation offset is: " + camerasRotations[i].ToString()); activeCameraRotation = camerasRotations[i]; + activeCameraPosition = camerasPositions[i]; return cameras[i]; } diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 9177e45..0f94460 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -136,7 +136,7 @@ private void initialize4cameras() { private void handlePipeInput() { // Logger.writeLine("VisionExport handlePipeInput called."); - UINotify("handlePipeInput called"); +// UINotify("handlePipeInput called"); UINotify("server connected:" + server.Connected.ToString()); UINotify(connection == null ? "connection is null" : "connection:" + connection.ToString()); if (connection == null) return; @@ -375,6 +375,13 @@ private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { else { dat.CamRelativeRot = null; } + + if (CamerasList.activeCameraPosition.HasValue) { + dat.CamRelativePos = new GTAVector(CamerasList.activeCameraPosition.Value); + } + else { + dat.CamRelativePos = null; + } dat.sceneGuid = guid; diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index d5469a7..02d77c6 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -199,6 +199,7 @@ public class GTAData public int UIWidth { get; set; } public Guid sceneGuid { get; set; } public GTAVector CamRelativeRot { get; set; } + public GTAVector CamRelativePos { get; set; } public List Detections { get; set; } public static SharpDX.Vector3 CvtVec(GTA.Math.Vector3 inp) { diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 7dd48f7..6f80212 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -167,23 +167,27 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { var trans = conn.BeginTransaction(); var camRelativeRotString = "NULL"; - if (data.CamRelativeRot != null) { camRelativeRotString = "ST_MakePoint(@relative_rot_x, @relative_rot_y, @relative_rot_z)"; } + var camRelativePosString = "NULL"; + if (data.CamRelativePos != null) { + camRelativePosString = "ST_MakePoint(@relative_pos_x, @relative_pos_y, @relative_pos_z)"; + } + using (NpgsqlCommand cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.Transaction = trans; cmd.CommandText = "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_rot, " + "camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, " + - "cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation, world_matrix) " + + "cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation, camera_relative_position, world_matrix) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@rotx, @roty, @rotz), " + "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id, " + - camRelativeRotString + ", @world_matrix) " + + camRelativeRotString + ", " + ", @world_matrix) " + "RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); @@ -223,6 +227,11 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { cmd.Parameters.AddWithValue("@relative_rot_y", data.CamRelativeRot.Y); cmd.Parameters.AddWithValue("@relative_rot_z", data.CamRelativeRot.Z); } + if (data.CamRelativePos != null) { + cmd.Parameters.AddWithValue("@relative_pos_x", data.CamRelativePos.X); + cmd.Parameters.AddWithValue("@relative_pos_y", data.CamRelativePos.Y); + cmd.Parameters.AddWithValue("@relative_pos_z", data.CamRelativePos.Z); + } cmd.Parameters.Add(new NpgsqlParameter("@guid", runId)); int snapshotid = (int) cmd.ExecuteScalar(); From b50dca5b37eb3ee19e9252f3ac48f0779d2bc296 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 5 Apr 2018 20:40:04 +0200 Subject: [PATCH 122/158] upgraded hookversion, some playing with static camera --- managed/GTAVisionExport/CameraHandling.cs | 23 ++++++++ managed/GTAVisionExport/CamerasList.cs | 11 ++-- .../GTAVisionExport/GTAVisionExport.csproj | 4 +- managed/GTAVisionExport/VisionExport.cs | 56 +++++++++++++++---- managed/GTAVisionExport/packages.config | 2 +- managed/GTAVisionUtils/GTAVisionUtils.csproj | 10 +++- managed/GTAVisionUtils/HashFunctions.cs | 15 +++++ managed/GTAVisionUtils/PostgresExport.cs | 2 +- managed/GTAVisionUtils/packages.config | 2 +- managed/README.md | 15 +++++ 10 files changed, 118 insertions(+), 22 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 5106503..5592ef1 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -6,6 +6,7 @@ using GTA; using GTA.Native; using GTA.Math; +using GTA.NaturalMotion; using GTAVisionUtils; using MathNet.Spatial.Euclidean; using MathNet.Spatial.Units; @@ -134,6 +135,7 @@ void OnTick(object sender, EventArgs e) { if (showCameras) { drawCamerasBoxes(); } +// drawAxesBoxesAround(new Vector3(-1078f, -216f, 200f)); } void drawCamerasBoxes() { @@ -161,5 +163,26 @@ void drawCamerasBoxes() { HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f)); } } + + void drawAxesBoxesAround(Vector3 position) { + var dist = 10; + var vectors = new[] { + new Vector3(dist, 0, 0), new Vector3(-dist, 0, 0), // x, pos and neg + new Vector3(0, dist, 0), new Vector3(0, -dist, 0), // y, pos and neg + new Vector3(0, 0, dist), new Vector3(0, 0, -dist), // z, pos and neg + }; + var colors = new[] { + new Vector3(255, 0, 0), new Vector3(255, 180, 180), // x, pos and neg + new Vector3(0, 255, 0), new Vector3(180, 255, 180), // y, pos and neg + new Vector3(0, 0, 255), new Vector3(180, 180, 255), // z, pos and neg + }; + for (int i = 0; i < vectors.Length; i++) { + var relativePos = vectors[i]; + var color = colors[i]; + var absolutePosition = position + new Vector3((float) relativePos[0], (float) relativePos[1], (float) relativePos[2]); + HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f), + (byte) colors[i][0], (byte) colors[i][1], (byte) colors[i][2]); + } + } } } \ No newline at end of file diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 5588573..9407885 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -11,6 +11,7 @@ namespace GTAVisionExport { public static class CamerasList { public static Camera mainCamera { get; private set; } public static Vector3 mainCameraPosition { get; private set; } + public static Vector3 mainCameraRotation { get; private set; } public static List cameras { get; } = new List(); public static List camerasPositions { get; } = new List(); @@ -41,7 +42,7 @@ public static void initialize() { initialized = true; } - public static void setMainCamera(Vector3 position, float? fov = null, float? nearClip = null) { + public static void setMainCamera(Vector3 position = new Vector3(), Vector3 rotation = new Vector3(), float? fov = null, float? nearClip = null) { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } @@ -54,10 +55,12 @@ public static void setMainCamera(Vector3 position, float? fov = null, float? nea nearClip = World.RenderingCamera.NearClip; } - mainCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value); + mainCamera = World.CreateCamera(position, rotation, fov.Value); +// mainCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value); mainCamera.NearClip = nearClip.Value; // mainCamera.IsActive = true; mainCameraPosition = position; + mainCameraRotation = rotation; mainCamera.IsActive = false; World.RenderingCamera = null; @@ -94,8 +97,8 @@ public static void ActivateMainCamera() { mainCamera.IsActive = true; World.RenderingCamera = mainCamera; - activeCameraRotation = new Vector3(); - activeCameraPosition = new Vector3(); + activeCameraRotation = mainCameraRotation; + activeCameraPosition = mainCameraPosition; } public static Camera ActivateCamera(int i) { diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index ec7dd08..f159912 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -91,8 +91,8 @@ - - ..\packages\ScriptHookVDotNet2.2.10.3\lib\net452\ScriptHookVDotNet2.dll + + ..\packages\ScriptHookVDotNet2.2.10.4\lib\net452\ScriptHookVDotNet2.dll diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 0f94460..1d684dc 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -51,7 +51,8 @@ class VisionExport : Script { private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one private readonly bool currentWeather = true; private readonly bool clearEverything = false; - private readonly bool useMultipleCameras = true; + private readonly bool useMultipleCameras = false; // when false, cameras handling script is not used at all + private readonly bool staticCamera = true; // this turns off whole car spawning, teleportation and autodriving procedure private Player player; private GTARun run; private bool enabled = false; @@ -111,6 +112,18 @@ public VisionExport() { UINotify("Logger initialized. Going to initialize cameras."); CamerasList.initialize(); initialize4cameras(); + +// var newCamera = World.CreateCamera(new Vector3(), new Vector3(), 50); +// newCamera.NearClip = 0.15f; +// newCamera.IsActive = true; +// newCamera.Position = new Vector3(-1078f, -216f, 37f); +//// newCamera.Rotation = new Vector3(270f, 0f, 0f); // x and y rotation seem to be switched. Can be fixed by setting the last parameter to 2 +// newCamera.Rotation = new Vector3(0f, 270f, 0f); // x and y rotation seem to be switched. Can be fixed by setting the last parameter to 2 +// World.RenderingCamera = newCamera; + +// {-1078,-216,37} +// CamerasList.setMainCamera(new Vector3(358f, -1308f, 52f), new Vector3(0f, 90f, 0f), 150, 0.15f); + UINotify("VisionExport plugin initialized."); } @@ -119,18 +132,21 @@ private void initialize4cameras() { // for cameras mapping area before the car // float r = 8f; //radius of circle with 4 cameras -// CamerasList.setMainCamera(new Vector3(0f, 2f, 0.4f)); +// CamerasList.setMainCamera(new Vector3()); // CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); // CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); // CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); // CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); // for 4 cameras of different sides of the car - CamerasList.setMainCamera(new Vector3(0f, 2f, 0.4f)); - CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 0.15f); - CamerasList.addCamera(new Vector3(-0.6f, 0f, 0.8f), new Vector3(0f, 0f, 90f), 50, 0.15f); - CamerasList.addCamera(new Vector3(0f, -2f, 0.6f), new Vector3(0f, 0f, 180f), 50, 0.15f); - CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); +// CamerasList.setMainCamera(new Vector3()); +// CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(-0.6f, 0f, 0.8f), new Vector3(0f, 0f, 90f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(0f, -2f, 0.6f), new Vector3(0f, 0f, 180f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); + +// set only main camera for static traffic camera + CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(270f, 0f, 0f), 50, 0.15f); } @@ -354,6 +370,11 @@ private void gatherData(int delay = 5) { CamerasList.Deactivate(); } else { +// when multiple cameras are not used, only main camera is being used. +// now it checks if it is active or not, and sets it + if (!CamerasList.mainCamera.IsActive) { + CamerasList.ActivateMainCamera(); + } gatherDatForOneCamera(dateTimeFormat, guid); } } @@ -452,10 +473,12 @@ public Bitmap CaptureScreen() { } public void Autostart() { - EnterVehicle(); - Script.Wait(200); - ToggleNavigation(); - Script.Wait(200); + if (! staticCamera) { + EnterVehicle(); + Script.Wait(200); + ToggleNavigation(); + Script.Wait(200); + } postgresTask?.Wait(); postgresTask = StartSession(); } @@ -565,6 +588,10 @@ private void ClearSurroundingEverything(float x, float y, float z, float radius) } public void ReloadGame() { + if (staticCamera) { + return; + } + /* Process p = Process.GetProcessesByName("Grand Theft Auto V").FirstOrDefault(); if (p != null) @@ -615,6 +642,9 @@ public void OnKeyDown(object o, KeyEventArgs k) { } if (k.KeyCode == Keys.PageDown) { + if (staticCamera) { + CamerasList.Deactivate(); + } StopRun(); StopSession(); UINotify("GTA Vision Disabled"); @@ -729,6 +759,10 @@ public void OnKeyDown(object o, KeyEventArgs k) { Script.Wait(200); // hoping game will go on during this wait } + if (staticCamera) { + CamerasList.Deactivate(); + } + StopRun(); StopSession(); } diff --git a/managed/GTAVisionExport/packages.config b/managed/GTAVisionExport/packages.config index c8bb455..bdcb313 100644 --- a/managed/GTAVisionExport/packages.config +++ b/managed/GTAVisionExport/packages.config @@ -12,7 +12,7 @@ - + diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index ba88c4f..8a8b608 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -85,8 +85,8 @@ ..\packages\GDAL.1.11.1\lib\net40\osr_csharp.dll True - - ..\packages\ScriptHookVDotNet2.2.10.3\lib\net452\ScriptHookVDotNet2.dll + + ..\packages\ScriptHookVDotNet2.2.10.4\lib\net452\ScriptHookVDotNet2.dll ..\packages\SharpDX.3.1.1\lib\net45\SharpDX.dll @@ -122,12 +122,18 @@ D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + + ..\376923-VAutodrive V8.0.3\Scripts\VAutodrive.dll + ..\..\..\..\..\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll D:\Program Files (x86)\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + + ..\376923-VAutodrive V8.0.3\Scripts\VCommonFunctions.dll + diff --git a/managed/GTAVisionUtils/HashFunctions.cs b/managed/GTAVisionUtils/HashFunctions.cs index bad6fbc..0bd13dd 100644 --- a/managed/GTAVisionUtils/HashFunctions.cs +++ b/managed/GTAVisionUtils/HashFunctions.cs @@ -100,5 +100,20 @@ public static void Draw2DText(string text, float x, float y, Color color, byte a Draw2DText(text, x, y, color.R, color.G, color.B, a); } + public static void SetCameraRotation(Camera camera, Vector3 value) { + InputArgument[] inputArgumentArray = new InputArgument[5]; + InputArgument inputArgument1 = new InputArgument(camera.Handle); + inputArgumentArray[0] = inputArgument1; + InputArgument inputArgument2 = new InputArgument(value.X); + inputArgumentArray[1] = inputArgument2; + InputArgument inputArgument3 = new InputArgument(value.Y); + inputArgumentArray[2] = inputArgument3; + InputArgument inputArgument4 = new InputArgument(value.Z); + inputArgumentArray[3] = inputArgument4; + InputArgument inputArgument5 = new InputArgument(2); + inputArgumentArray[4] = inputArgument5; + Function.Call(Hash._0x85973643155D0B07, inputArgumentArray); + } + } } diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 6f80212..bb5d071 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -187,7 +187,7 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@rotx, @roty, @rotz), " + "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id, " + - camRelativeRotString + ", " + ", @world_matrix) " + + camRelativeRotString + ", " + camRelativePosString + ", @world_matrix) " + "RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); diff --git a/managed/GTAVisionUtils/packages.config b/managed/GTAVisionUtils/packages.config index a3ffc26..0965904 100644 --- a/managed/GTAVisionUtils/packages.config +++ b/managed/GTAVisionUtils/packages.config @@ -12,7 +12,7 @@ - + diff --git a/managed/README.md b/managed/README.md index 82d709c..3728b05 100644 --- a/managed/README.md +++ b/managed/README.md @@ -323,6 +323,21 @@ BEGIN END; $$; +-- we often ask for all entities for single snapshot, this index makes querying like 20x faster +CREATE INDEX snapshot_index ON detections (snapshot_id); + +-- so we see nicely even postgis objects +CREATE VIEW snapshots_view AS + SELECT snapshot_id, run_id, version, scene_id, imagepath, timestamp, timeofday, currentweather, + ARRAY[st_x(camera_pos), st_y(camera_pos), st_z(camera_pos)] AS camera_pos, + ARRAY[st_x(camera_rot), st_y(camera_rot), st_z(camera_rot)] AS camera_rot, + ARRAY[st_x(camera_relative_rotation), st_y(camera_relative_rotation), st_z(camera_relative_rotation)] AS camera_relative_rotation, + ARRAY[st_x(camera_relative_position), st_y(camera_relative_position), st_z(camera_relative_position)] AS camera_relative_position, + ARRAY[st_x(camera_direction), st_y(camera_direction), st_z(camera_direction)] AS camera_direction, + camera_fov, world_matrix, view_matrix, proj_matrix, processed, width, height, ui_width, ui_height, cam_near_clip, cam_far_clip, + ARRAY[st_x(player_pos), st_y(player_pos), st_z(player_pos)] AS player_pos, + ARRAY[st_x(velocity), st_y(velocity), st_z(velocity)] AS velocity + FROM snapshots; ``` ## Copying compiled files to GTA V From a6fefd937df99c7f0f2d8ca3e43c79e1b13647bf Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 10 Apr 2018 18:40:57 +0200 Subject: [PATCH 123/158] upgraded to 1.10.5 version of scripthookvdotnet2 --- .../GTAVisionExport/GTAVisionExport.csproj | 2 +- managed/GTAVisionExport/VisionExport.cs | 16 ++++++----- managed/GTAVisionExport/packages.config | 2 +- managed/GTAVisionUtils/GTADataStructures.cs | 1 + managed/GTAVisionUtils/GTAVisionUtils.csproj | 2 +- managed/GTAVisionUtils/HashFunctions.cs | 28 +++++++++---------- managed/GTAVisionUtils/ImageUtils.cs | 3 +- managed/GTAVisionUtils/packages.config | 2 +- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index f159912..c8d044b 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -92,7 +92,7 @@ - ..\packages\ScriptHookVDotNet2.2.10.4\lib\net452\ScriptHookVDotNet2.dll + ..\packages\ScriptHookVDotNet2.2.10.5\lib\net452\ScriptHookVDotNet2.dll diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 1d684dc..4b9a764 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -51,7 +51,8 @@ class VisionExport : Script { private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one private readonly bool currentWeather = true; private readonly bool clearEverything = false; - private readonly bool useMultipleCameras = false; // when false, cameras handling script is not used at all +// private readonly bool useMultipleCameras = false; // when false, cameras handling script is not used at all + private readonly bool useMultipleCameras = true; // when false, cameras handling script is not used at all private readonly bool staticCamera = true; // this turns off whole car spawning, teleportation and autodriving procedure private Player player; private GTARun run; @@ -139,14 +140,15 @@ private void initialize4cameras() { // CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); // for 4 cameras of different sides of the car -// CamerasList.setMainCamera(new Vector3()); -// CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 0.15f); -// CamerasList.addCamera(new Vector3(-0.6f, 0f, 0.8f), new Vector3(0f, 0f, 90f), 50, 0.15f); -// CamerasList.addCamera(new Vector3(0f, -2f, 0.6f), new Vector3(0f, 0f, 180f), 50, 0.15f); -// CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); + CamerasList.setMainCamera(); + CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 0.15f); + CamerasList.addCamera(new Vector3(-0.6f, 0f, 0.8f), new Vector3(0f, 0f, 90f), 50, 0.15f); + CamerasList.addCamera(new Vector3(0f, -2f, 0.6f), new Vector3(0f, 0f, 180f), 50, 0.15f); + CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); // set only main camera for static traffic camera - CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(270f, 0f, 0f), 50, 0.15f); +// CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(270f, 0f, 0f), 50, 0.15f); +// CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(0f, 270f, 0f), 50, 0.15f); } diff --git a/managed/GTAVisionExport/packages.config b/managed/GTAVisionExport/packages.config index bdcb313..a3c59ab 100644 --- a/managed/GTAVisionExport/packages.config +++ b/managed/GTAVisionExport/packages.config @@ -12,7 +12,7 @@ - + diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 02d77c6..6eedea0 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -341,6 +341,7 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.CamNearClip = World.RenderingCamera.NearClip; ret.CamFarClip = World.RenderingCamera.FarClip; + Logger.writeLine(Game.Player.Character.ToString()); var peds = World.GetNearbyPeds(Game.Player.Character, 500.0f); var cars = World.GetNearbyVehicles(Game.Player.Character, 500.0f); //var props = World.GetNearbyProps(Game.Player.Character.Position, 300.0f); diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index 8a8b608..c119d5c 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -86,7 +86,7 @@ True - ..\packages\ScriptHookVDotNet2.2.10.4\lib\net452\ScriptHookVDotNet2.dll + ..\packages\ScriptHookVDotNet2.2.10.5\lib\net452\ScriptHookVDotNet2.dll ..\packages\SharpDX.3.1.1\lib\net45\SharpDX.dll diff --git a/managed/GTAVisionUtils/HashFunctions.cs b/managed/GTAVisionUtils/HashFunctions.cs index 0bd13dd..a880b54 100644 --- a/managed/GTAVisionUtils/HashFunctions.cs +++ b/managed/GTAVisionUtils/HashFunctions.cs @@ -100,20 +100,20 @@ public static void Draw2DText(string text, float x, float y, Color color, byte a Draw2DText(text, x, y, color.R, color.G, color.B, a); } - public static void SetCameraRotation(Camera camera, Vector3 value) { - InputArgument[] inputArgumentArray = new InputArgument[5]; - InputArgument inputArgument1 = new InputArgument(camera.Handle); - inputArgumentArray[0] = inputArgument1; - InputArgument inputArgument2 = new InputArgument(value.X); - inputArgumentArray[1] = inputArgument2; - InputArgument inputArgument3 = new InputArgument(value.Y); - inputArgumentArray[2] = inputArgument3; - InputArgument inputArgument4 = new InputArgument(value.Z); - inputArgumentArray[3] = inputArgument4; - InputArgument inputArgument5 = new InputArgument(2); - inputArgumentArray[4] = inputArgument5; - Function.Call(Hash._0x85973643155D0B07, inputArgumentArray); - } +// public static void SetCameraRotation(Camera camera, Vector3 value) { +// InputArgument[] inputArgumentArray = new InputArgument[5]; +// InputArgument inputArgument1 = new InputArgument(camera.Handle); +// inputArgumentArray[0] = inputArgument1; +// InputArgument inputArgument2 = new InputArgument(value.X); +// inputArgumentArray[1] = inputArgument2; +// InputArgument inputArgument3 = new InputArgument(value.Y); +// inputArgumentArray[2] = inputArgument3; +// InputArgument inputArgument4 = new InputArgument(value.Z); +// inputArgumentArray[3] = inputArgument4; +// InputArgument inputArgument5 = new InputArgument(3); +// inputArgumentArray[4] = inputArgument5; +// Function.Call(Hash.SET_CAM_ROT, inputArgumentArray); +// } } } diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index f6aca88..d29bb75 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -149,7 +149,8 @@ public static void WriteToTiffImpl(string name, int width, int height, List - + From 658f6ea28ea26ade9fea94b8298c25d175d2e0b3 Mon Sep 17 00:00:00 2001 From: racinmat Date: Sun, 22 Apr 2018 04:10:47 +0200 Subject: [PATCH 124/158] fixing dimensions for voxelmap depth image metrics --- native/src/GTAVisionNative.vcxproj | 328 +++++++++++++++++++++ native/src/GTAVisionNative.vcxproj.filters | 42 +++ native/src/cmake_install.cmake | 34 +++ 3 files changed, 404 insertions(+) create mode 100644 native/src/GTAVisionNative.vcxproj create mode 100644 native/src/GTAVisionNative.vcxproj.filters create mode 100644 native/src/cmake_install.cmake diff --git a/native/src/GTAVisionNative.vcxproj b/native/src/GTAVisionNative.vcxproj new file mode 100644 index 0000000..ad35c90 --- /dev/null +++ b/native/src/GTAVisionNative.vcxproj @@ -0,0 +1,328 @@ + + + + + Debug + x64 + + + Release + x64 + + + MinSizeRel + x64 + + + RelWithDebInfo + x64 + + + + {D7A05F9F-7920-3AC9-A553-47920A761D8A} + 10.0.16299.0 + Win32Proj + x64 + GTAVisionNative + NoUpgrade + + + + DynamicLibrary + MultiByte + v141 + + + DynamicLibrary + MultiByte + v141 + + + DynamicLibrary + MultiByte + v141 + + + DynamicLibrary + MultiByte + v141 + + + + + + + + + + <_ProjectFileVersion>10.0.20506.1 + D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\Debug\ + GTAVisionNative.dir\Debug\ + GTAVisionNative + .asi + true + true + D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\Release\ + GTAVisionNative.dir\Release\ + GTAVisionNative + .asi + false + true + D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\MinSizeRel\ + GTAVisionNative.dir\MinSizeRel\ + GTAVisionNative + .asi + false + true + D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\RelWithDebInfo\ + GTAVisionNative.dir\RelWithDebInfo\ + GTAVisionNative + .asi + true + true + + + + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + Debug/ + EnableFastChecks + CompileAsCpp + ProgramDatabase + Sync + Disabled + Disabled + NotUsing + MultiThreadedDebugDLL + true + Level3 + WIN32;_WINDOWS;CMAKE_INTDIR="Debug";GTAVisionNative_EXPORTS;%(PreprocessorDefinitions) + $(IntDir) + + + WIN32;_DEBUG;_WINDOWS;CMAKE_INTDIR=\"Debug\";GTAVisionNative_EXPORTS;%(PreprocessorDefinitions) + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + + + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + $(ProjectDir)/$(IntDir) + %(Filename).h + %(Filename).tlb + %(Filename)_i.c + %(Filename)_p.c + + + ..\deps\ScriptHookV.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib + %(AdditionalLibraryDirectories) + %(AdditionalOptions) /machine:x64 + true + %(IgnoreSpecificDefaultLibraries) + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/Debug/GTAVisionNative.lib + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/Debug/GTAVisionNative.pdb + Console + + + false + + + + + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + Release/ + CompileAsCpp + Sync + AnySuitable + MaxSpeed + NotUsing + MultiThreadedDLL + true + Level3 + WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";GTAVisionNative_EXPORTS;%(PreprocessorDefinitions) + $(IntDir) + + + + WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";GTAVisionNative_EXPORTS;%(PreprocessorDefinitions) + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + + + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + $(ProjectDir)/$(IntDir) + %(Filename).h + %(Filename).tlb + %(Filename)_i.c + %(Filename)_p.c + + + ..\deps\ScriptHookV.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib + %(AdditionalLibraryDirectories) + %(AdditionalOptions) /machine:x64 + false + %(IgnoreSpecificDefaultLibraries) + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/Release/GTAVisionNative.lib + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/Release/GTAVisionNative.pdb + Console + + + false + + + + + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + MinSizeRel/ + CompileAsCpp + Sync + OnlyExplicitInline + MinSpace + NotUsing + MultiThreadedDLL + true + Level3 + WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="MinSizeRel";GTAVisionNative_EXPORTS;%(PreprocessorDefinitions) + $(IntDir) + + + + WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"MinSizeRel\";GTAVisionNative_EXPORTS;%(PreprocessorDefinitions) + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + + + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + $(ProjectDir)/$(IntDir) + %(Filename).h + %(Filename).tlb + %(Filename)_i.c + %(Filename)_p.c + + + ..\deps\ScriptHookV.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib + %(AdditionalLibraryDirectories) + %(AdditionalOptions) /machine:x64 + false + %(IgnoreSpecificDefaultLibraries) + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/MinSizeRel/GTAVisionNative.lib + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/MinSizeRel/GTAVisionNative.pdb + Console + + + false + + + + + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + RelWithDebInfo/ + CompileAsCpp + ProgramDatabase + Sync + OnlyExplicitInline + MaxSpeed + NotUsing + MultiThreadedDLL + true + Level3 + WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="RelWithDebInfo";GTAVisionNative_EXPORTS;%(PreprocessorDefinitions) + $(IntDir) + + + WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"RelWithDebInfo\";GTAVisionNative_EXPORTS;%(PreprocessorDefinitions) + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + + + D:\projekty\GTA-V-extractors\GTAVisionExport\eigen-eigen-f562a193118d;%(AdditionalIncludeDirectories) + $(ProjectDir)/$(IntDir) + %(Filename).h + %(Filename).tlb + %(Filename)_i.c + %(Filename)_p.c + + + ..\deps\ScriptHookV.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib + %(AdditionalLibraryDirectories) + %(AdditionalOptions) /machine:x64 + true + %(IgnoreSpecificDefaultLibraries) + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/RelWithDebInfo/GTAVisionNative.lib + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/RelWithDebInfo/GTAVisionNative.pdb + Console + + + false + + + + + Building Custom Rule D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeLists.txt + setlocal +"C:\Program Files\CMake\bin\cmake.exe" -HD:/projekty/GTA-V-extractors/GTAVisionExport/native -BD:/projekty/GTA-V-extractors/GTAVisionExport/native --check-stamp-file D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeFiles/generate.stamp +if %errorlevel% neq 0 goto :cmEnd +:cmEnd +endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone +:cmErrorLevel +exit /b %1 +:cmDone +if %errorlevel% neq 0 goto :VCEnd + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeLists.txt;D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeLists.txt;D:\projekty\GTA-V-extractors\GTAVisionExport\native\cmake\FindEigen3.cmake;D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeLists.txt;%(AdditionalInputs) + D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeFiles\generate.stamp + false + Building Custom Rule D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeLists.txt + setlocal +"C:\Program Files\CMake\bin\cmake.exe" -HD:/projekty/GTA-V-extractors/GTAVisionExport/native -BD:/projekty/GTA-V-extractors/GTAVisionExport/native --check-stamp-file D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeFiles/generate.stamp +if %errorlevel% neq 0 goto :cmEnd +:cmEnd +endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone +:cmErrorLevel +exit /b %1 +:cmDone +if %errorlevel% neq 0 goto :VCEnd + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeLists.txt;D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeLists.txt;D:\projekty\GTA-V-extractors\GTAVisionExport\native\cmake\FindEigen3.cmake;D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeLists.txt;%(AdditionalInputs) + D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeFiles\generate.stamp + false + Building Custom Rule D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeLists.txt + setlocal +"C:\Program Files\CMake\bin\cmake.exe" -HD:/projekty/GTA-V-extractors/GTAVisionExport/native -BD:/projekty/GTA-V-extractors/GTAVisionExport/native --check-stamp-file D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeFiles/generate.stamp +if %errorlevel% neq 0 goto :cmEnd +:cmEnd +endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone +:cmErrorLevel +exit /b %1 +:cmDone +if %errorlevel% neq 0 goto :VCEnd + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeLists.txt;D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeLists.txt;D:\projekty\GTA-V-extractors\GTAVisionExport\native\cmake\FindEigen3.cmake;D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeLists.txt;%(AdditionalInputs) + D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeFiles\generate.stamp + false + Building Custom Rule D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeLists.txt + setlocal +"C:\Program Files\CMake\bin\cmake.exe" -HD:/projekty/GTA-V-extractors/GTAVisionExport/native -BD:/projekty/GTA-V-extractors/GTAVisionExport/native --check-stamp-file D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeFiles/generate.stamp +if %errorlevel% neq 0 goto :cmEnd +:cmEnd +endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone +:cmErrorLevel +exit /b %1 +:cmDone +if %errorlevel% neq 0 goto :VCEnd + D:/projekty/GTA-V-extractors/GTAVisionExport/native/src/CMakeLists.txt;D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeLists.txt;D:\projekty\GTA-V-extractors\GTAVisionExport\native\cmake\FindEigen3.cmake;D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeLists.txt;%(AdditionalInputs) + D:\projekty\GTA-V-extractors\GTAVisionExport\native\src\CMakeFiles\generate.stamp + false + + + + + + + + + + + + + + + {1772903C-DA00-382E-B43A-8939865BD425} + ZERO_CHECK + + + + + + \ No newline at end of file diff --git a/native/src/GTAVisionNative.vcxproj.filters b/native/src/GTAVisionNative.vcxproj.filters new file mode 100644 index 0000000..3b19c7a --- /dev/null +++ b/native/src/GTAVisionNative.vcxproj.filters @@ -0,0 +1,42 @@ + + + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + + + + {2B7382E6-CEB9-3073-B77E-CC34D4F475C0} + + + {5F5C3B6C-34F1-38F0-8718-BF4C7F6B0B00} + + + diff --git a/native/src/cmake_install.cmake b/native/src/cmake_install.cmake new file mode 100644 index 0000000..78b5f6e --- /dev/null +++ b/native/src/cmake_install.cmake @@ -0,0 +1,34 @@ +# Install script for directory: D:/projekty/GTA-V-extractors/GTAVisionExport/native/src + +# Set the install prefix +if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "C:/Program Files/GTANativePlugin") +endif() +string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") + +# Set the install configuration name. +if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) + if(BUILD_TYPE) + string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" + CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") + else() + set(CMAKE_INSTALL_CONFIG_NAME "Release") + endif() + message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") +endif() + +# Set the component getting installed. +if(NOT CMAKE_INSTALL_COMPONENT) + if(COMPONENT) + message(STATUS "Install component: \"${COMPONENT}\"") + set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") + else() + set(CMAKE_INSTALL_COMPONENT) + endif() +endif() + +# Is this installation the result of a crosscompile? +if(NOT DEFINED CMAKE_CROSSCOMPILING) + set(CMAKE_CROSSCOMPILING "FALSE") +endif() + From d0cf4befbd2183c0b12d4932232ec8a29146987c Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 27 Jun 2018 11:38:27 +0200 Subject: [PATCH 125/158] added notes on managed plusing dependencies --- managed/GTAVisionExport/VisionExport.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 1d684dc..76b3b72 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -131,12 +131,12 @@ private void initialize4cameras() { // cameras initialization: // for cameras mapping area before the car -// float r = 8f; //radius of circle with 4 cameras -// CamerasList.setMainCamera(new Vector3()); -// CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); -// CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); -// CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); -// CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); + float r = 8f; //radius of circle with 4 cameras + CamerasList.setMainCamera(new Vector3()); + CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); + CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); + CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); + CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); // for 4 cameras of different sides of the car // CamerasList.setMainCamera(new Vector3()); From 8b90d83b608ac08cc67eeedc8e95624851adda84 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 27 Jun 2018 14:42:08 +0200 Subject: [PATCH 126/158] new schema with added columns --- db_schema.sql | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 db_schema.sql diff --git a/db_schema.sql b/db_schema.sql new file mode 100644 index 0000000..ad00d38 --- /dev/null +++ b/db_schema.sql @@ -0,0 +1,204 @@ + +create table datasets +( + dataset_id serial not null + constraint datasets_pkey + primary key, + dataset_name text, + view_name text, + created timestamp default timezone('utc'::text, now()) +) +; + +create table instances +( + instance_id serial not null + constraint isntances_pkey + primary key, + hostname text, + instanceid text + constraint instanceid_uniq + unique, + instancetype text, + publichostname text, + amiid text, + created timestamp default timezone('utc'::text, now()), + constraint instance_info_uniq + unique (hostname, instanceid, instancetype, publichostname, amiid) +) +; + +create table sessions +( + session_id serial not null + constraint sessions_pkey + primary key, + name text + constraint sessions_name_key + unique, + start timestamp with time zone, + "end" timestamp with time zone, + created timestamp default timezone('utc'::text, now()) +) +; + +create table runs +( + run_id serial not null + constraint runs_pkey + primary key, + runguid uuid, + archivepath text, + localpath text, + session_id integer default 1 + constraint runs_session_fkey + references sessions + on delete cascade, + instance_id integer default 0 + constraint runs_instance_fkey + references instances, + created timestamp default timezone('utc'::text, now()) +) +; + +create table snapshots +( + snapshot_id serial not null + constraint snapshots_pkey + primary key, + run_id integer + constraint snapshots_run_fkey + references runs + on delete cascade, + version integer, + scene_id uuid, + imagepath text, + timestamp timestamp with time zone, + timeofday time, + currentweather weather, + camera_pos geometry(PointZ), + camera_rot geometry(PointZ), + camera_relative_rotation geometry(PointZ), + camera_direction geometry, + camera_fov real, + world_matrix double precision[], + view_matrix double precision[], + proj_matrix double precision[], + processed boolean default false not null, + width integer, + height integer, + ui_width integer, + ui_height integer, + cam_near_clip real, + cam_far_clip real, + player_pos geometry(PointZ), + velocity geometry(PointZ), + camera_relative_position geometry(PointZ) +) +; + +create table detections +( + detection_id serial not null + constraint detections_pkey + primary key, + snapshot_id integer + constraint detections_snapshot_fkey + references snapshots + on delete cascade, + type detection_type, + pos geometry(PointZ), + bbox box, + class detection_class default 'Unknown'::detection_class, + handle integer default '-1'::integer, + best_bbox box, + best_bbox_old box, + bbox3d box3d, + rot geometry, + coverage real default 0.0, + created timestamp default timezone('utc'::text, now()), + velocity geometry(PointZ) +) +; + +create index snapshot_index + on detections (snapshot_id) +; + +create index handle_index + on detections (handle) +; + +create table snapshot_weathers +( + weather_id serial not null + constraint snapshot_weathers_pkey + primary key, + snapshot_id integer + constraint snapshot_weathers_snapshot_id_fkey + references snapshots + on delete cascade, + weather_type weather, + snapshot_page integer, + created timestamp default timezone('utc'::text, now()) +) +; + +create table system_graphics +( + system_graphic_id serial not null + constraint system_graphics_pkey + primary key, + deviceid text, + adaptercompatibility text, + adapterdactype text, + adapterram integer, + availability integer, + caption text, + description text, + driverdate timestamp with time zone, + driverversion text, + pnpdeviceid text, + name text, + videoarch integer, + memtype integer, + videoprocessor text, + bpp integer, + hrez integer, + vrez integer, + num_colors integer, + cols integer, + rows integer, + refresh integer, + scanmode integer, + videomodedesc text, + created timestamp default timezone('utc'::text, now()) +) +; + +create table systems +( + system_uuid uuid not null + constraint systems_pkey + primary key, + vendor text, + dnshostname text, + username text, + systemtype text, + totalmem bigint, + created timestamp default timezone('utc'::text, now()) +) +; + +create table uploads +( + id serial not null + constraint uploads_pkey + primary key, + bucket text, + key text, + uploadid text, + created timestamp default timezone('utc'::text, now()) +) +; + From aea6e85263fa62c9e84dffbc8dd69920d6ed56af Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 27 Jun 2018 14:45:15 +0200 Subject: [PATCH 127/158] added schema --- db_schema.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db_schema.sql b/db_schema.sql index ad00d38..e6c1bad 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -1,4 +1,6 @@ +set schema 'public'; + create table datasets ( dataset_id serial not null From e79ae78abadbde7510d5244ef18cfdc317305861 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 27 Jun 2018 14:51:02 +0200 Subject: [PATCH 128/158] specified schema, added types --- db_schema.sql | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/db_schema.sql b/db_schema.sql index e6c1bad..b3a31a4 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -1,5 +1,15 @@ +SET search_path = public, pg_catalog; + + +create type detection_class as enum ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Trains') +; + +create type detection_type as enum ('background', 'person', 'car', 'bicycle') +; + +create type weather as enum ('Unknown', 'ExtraSunny', 'Clear', 'Clouds', 'Smog', 'Foggy', 'Overcast', 'Raining', 'ThunderStorm', 'Clearing', 'Neutral', 'Snowing', 'Blizzard', 'Snowlight', 'Christmas', 'Halloween') +; -set schema 'public'; create table datasets ( From 309cf4695dea7d6ecd28f36658ae8b9ca7853cad Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 27 Jun 2018 15:10:21 +0200 Subject: [PATCH 129/158] new db schema --- ...base_schema.sql => database_schema_old.sql | 0 db_schema.sql | 1270 ++++++++++++++--- db_schema_old.sql | 216 +++ 3 files changed, 1271 insertions(+), 215 deletions(-) rename database_schema.sql => database_schema_old.sql (100%) create mode 100644 db_schema_old.sql diff --git a/database_schema.sql b/database_schema_old.sql similarity index 100% rename from database_schema.sql rename to database_schema_old.sql diff --git a/db_schema.sql b/db_schema.sql index b3a31a4..4603e64 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -1,216 +1,1056 @@ -SET search_path = public, pg_catalog; - - -create type detection_class as enum ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Trains') -; - -create type detection_type as enum ('background', 'person', 'car', 'bicycle') -; - -create type weather as enum ('Unknown', 'ExtraSunny', 'Clear', 'Clouds', 'Smog', 'Foggy', 'Overcast', 'Raining', 'ThunderStorm', 'Clearing', 'Neutral', 'Snowing', 'Blizzard', 'Snowlight', 'Christmas', 'Halloween') -; - - -create table datasets -( - dataset_id serial not null - constraint datasets_pkey - primary key, - dataset_name text, - view_name text, - created timestamp default timezone('utc'::text, now()) -) -; - -create table instances -( - instance_id serial not null - constraint isntances_pkey - primary key, - hostname text, - instanceid text - constraint instanceid_uniq - unique, - instancetype text, - publichostname text, - amiid text, - created timestamp default timezone('utc'::text, now()), - constraint instance_info_uniq - unique (hostname, instanceid, instancetype, publichostname, amiid) -) -; - -create table sessions -( - session_id serial not null - constraint sessions_pkey - primary key, - name text - constraint sessions_name_key - unique, - start timestamp with time zone, - "end" timestamp with time zone, - created timestamp default timezone('utc'::text, now()) -) -; - -create table runs -( - run_id serial not null - constraint runs_pkey - primary key, - runguid uuid, - archivepath text, - localpath text, - session_id integer default 1 - constraint runs_session_fkey - references sessions - on delete cascade, - instance_id integer default 0 - constraint runs_instance_fkey - references instances, - created timestamp default timezone('utc'::text, now()) -) -; - -create table snapshots -( - snapshot_id serial not null - constraint snapshots_pkey - primary key, - run_id integer - constraint snapshots_run_fkey - references runs - on delete cascade, - version integer, - scene_id uuid, - imagepath text, - timestamp timestamp with time zone, - timeofday time, - currentweather weather, - camera_pos geometry(PointZ), - camera_rot geometry(PointZ), - camera_relative_rotation geometry(PointZ), - camera_direction geometry, - camera_fov real, - world_matrix double precision[], - view_matrix double precision[], - proj_matrix double precision[], - processed boolean default false not null, - width integer, - height integer, - ui_width integer, - ui_height integer, - cam_near_clip real, - cam_far_clip real, - player_pos geometry(PointZ), - velocity geometry(PointZ), - camera_relative_position geometry(PointZ) -) -; - -create table detections -( - detection_id serial not null - constraint detections_pkey - primary key, - snapshot_id integer - constraint detections_snapshot_fkey - references snapshots - on delete cascade, - type detection_type, - pos geometry(PointZ), - bbox box, - class detection_class default 'Unknown'::detection_class, - handle integer default '-1'::integer, - best_bbox box, - best_bbox_old box, - bbox3d box3d, - rot geometry, - coverage real default 0.0, - created timestamp default timezone('utc'::text, now()), - velocity geometry(PointZ) -) -; - -create index snapshot_index - on detections (snapshot_id) -; - -create index handle_index - on detections (handle) -; - -create table snapshot_weathers -( - weather_id serial not null - constraint snapshot_weathers_pkey - primary key, - snapshot_id integer - constraint snapshot_weathers_snapshot_id_fkey - references snapshots - on delete cascade, - weather_type weather, - snapshot_page integer, - created timestamp default timezone('utc'::text, now()) -) -; - -create table system_graphics -( - system_graphic_id serial not null - constraint system_graphics_pkey - primary key, - deviceid text, - adaptercompatibility text, - adapterdactype text, - adapterram integer, - availability integer, - caption text, - description text, - driverdate timestamp with time zone, - driverversion text, - pnpdeviceid text, - name text, - videoarch integer, - memtype integer, - videoprocessor text, - bpp integer, - hrez integer, - vrez integer, - num_colors integer, - cols integer, - rows integer, - refresh integer, - scanmode integer, - videomodedesc text, - created timestamp default timezone('utc'::text, now()) -) -; - -create table systems -( - system_uuid uuid not null - constraint systems_pkey - primary key, - vendor text, - dnshostname text, - username text, - systemtype text, - totalmem bigint, - created timestamp default timezone('utc'::text, now()) -) -; - -create table uploads -( - id serial not null - constraint uploads_pkey - primary key, - bucket text, - key text, - uploadid text, - created timestamp default timezone('utc'::text, now()) -) -; +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 9.6.8 +-- Dumped by pg_dump version 9.6.8 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: DATABASE postgres; Type: COMMENT; Schema: -; Owner: postgres +-- + +COMMENT ON DATABASE postgres IS 'default administrative connection database'; + + +-- +-- Name: tiger; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA tiger; + + +ALTER SCHEMA tiger OWNER TO postgres; + +-- +-- Name: tiger_data; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA tiger_data; + + +ALTER SCHEMA tiger_data OWNER TO postgres; + +-- +-- Name: topology; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA topology; + + +ALTER SCHEMA topology OWNER TO postgres; + +-- +-- Name: SCHEMA topology; Type: COMMENT; Schema: -; Owner: postgres +-- + +COMMENT ON SCHEMA topology IS 'PostGIS Topology schema'; + + +-- +-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; + + +-- +-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; + + +-- +-- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA public; + + +-- +-- Name: EXTENSION fuzzystrmatch; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION fuzzystrmatch IS 'determine similarities and distance between strings'; + + +-- +-- Name: postgis; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; + + +-- +-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions'; + + +-- +-- Name: postgis_tiger_geocoder; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder WITH SCHEMA tiger; + + +-- +-- Name: EXTENSION postgis_tiger_geocoder; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION postgis_tiger_geocoder IS 'PostGIS tiger geocoder and reverse geocoder'; + + +-- +-- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology; + + +-- +-- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions'; + + +-- +-- Name: detection_class; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.detection_class AS ENUM ( + 'Unknown', + 'Compacts', + 'Sedans', + 'SUVs', + 'Coupes', + 'Muscle', + 'SportsClassics', + 'Sports', + 'Super', + 'Motorcycles', + 'OffRoad', + 'Industrial', + 'Utility', + 'Vans', + 'Cycles', + 'Boats', + 'Helicopters', + 'Planes', + 'Service', + 'Emergency', + 'Military', + 'Commercial', + 'Trains' +); + + +ALTER TYPE public.detection_class OWNER TO postgres; + +-- +-- Name: detection_type; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.detection_type AS ENUM ( + 'background', + 'person', + 'car', + 'bicycle' +); + + +ALTER TYPE public.detection_type OWNER TO postgres; + +-- +-- Name: weather; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.weather AS ENUM ( + 'Unknown', + 'ExtraSunny', + 'Clear', + 'Clouds', + 'Smog', + 'Foggy', + 'Overcast', + 'Raining', + 'ThunderStorm', + 'Clearing', + 'Neutral', + 'Snowing', + 'Blizzard', + 'Snowlight', + 'Christmas', + 'Halloween' +); + + +ALTER TYPE public.weather OWNER TO postgres; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: datasets; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.datasets ( + dataset_id integer NOT NULL, + dataset_name text, + view_name text, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE public.datasets OWNER TO postgres; + +-- +-- Name: datasets_dataset_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.datasets_dataset_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.datasets_dataset_id_seq OWNER TO postgres; + +-- +-- Name: datasets_dataset_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.datasets_dataset_id_seq OWNED BY public.datasets.dataset_id; + + +-- +-- Name: detections; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.detections ( + detection_id integer NOT NULL, + snapshot_id integer, + type public.detection_type, + pos public.geometry(PointZ), + bbox box, + class public.detection_class DEFAULT 'Unknown'::public.detection_class, + handle integer DEFAULT '-1'::integer, + best_bbox box, + best_bbox_old box, + bbox3d public.box3d, + rot public.geometry, + coverage real DEFAULT 0.0, + created timestamp without time zone DEFAULT timezone('utc'::text, now()), + velocity public.geometry(PointZ) +); + + +ALTER TABLE public.detections OWNER TO postgres; + +-- +-- Name: detections_detection_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.detections_detection_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.detections_detection_id_seq OWNER TO postgres; + +-- +-- Name: detections_detection_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.detections_detection_id_seq OWNED BY public.detections.detection_id; + + +-- +-- Name: instances; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.instances ( + instance_id integer NOT NULL, + hostname text, + instanceid text, + instancetype text, + publichostname text, + amiid text, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE public.instances OWNER TO postgres; + +-- +-- Name: instances_instance_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.instances_instance_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.instances_instance_id_seq OWNER TO postgres; + +-- +-- Name: instances_instance_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.instances_instance_id_seq OWNED BY public.instances.instance_id; + + +-- +-- Name: runs; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.runs ( + run_id integer NOT NULL, + runguid uuid, + archivepath text, + localpath text, + session_id integer DEFAULT 1, + instance_id integer DEFAULT 0, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE public.runs OWNER TO postgres; + +-- +-- Name: runs_run_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.runs_run_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.runs_run_id_seq OWNER TO postgres; + +-- +-- Name: runs_run_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.runs_run_id_seq OWNED BY public.runs.run_id; + + +-- +-- Name: sessions; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.sessions ( + session_id integer NOT NULL, + name text, + start timestamp with time zone, + "end" timestamp with time zone, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE public.sessions OWNER TO postgres; + +-- +-- Name: sessions_session_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.sessions_session_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.sessions_session_id_seq OWNER TO postgres; + +-- +-- Name: sessions_session_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.sessions_session_id_seq OWNED BY public.sessions.session_id; + + +-- +-- Name: snapshot_weathers; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.snapshot_weathers ( + weather_id integer NOT NULL, + snapshot_id integer, + weather_type public.weather, + snapshot_page integer, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE public.snapshot_weathers OWNER TO postgres; + +-- +-- Name: snapshot_weathers_weather_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.snapshot_weathers_weather_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.snapshot_weathers_weather_id_seq OWNER TO postgres; + +-- +-- Name: snapshot_weathers_weather_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.snapshot_weathers_weather_id_seq OWNED BY public.snapshot_weathers.weather_id; + + +-- +-- Name: snapshots; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.snapshots ( + snapshot_id integer NOT NULL, + run_id integer, + version integer, + scene_id uuid, + imagepath text, + "timestamp" timestamp with time zone, + timeofday time without time zone, + currentweather public.weather, + camera_pos public.geometry(PointZ), + camera_rot public.geometry(PointZ), + camera_relative_rotation public.geometry(PointZ), + camera_direction public.geometry, + camera_fov real, + world_matrix double precision[], + view_matrix double precision[], + proj_matrix double precision[], + processed boolean DEFAULT false NOT NULL, + width integer, + height integer, + ui_width integer, + ui_height integer, + cam_near_clip real, + cam_far_clip real, + player_pos public.geometry(PointZ), + velocity public.geometry(PointZ), + camera_relative_position public.geometry(PointZ) +); + + +ALTER TABLE public.snapshots OWNER TO postgres; + +-- +-- Name: snapshots_snapshot_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.snapshots_snapshot_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.snapshots_snapshot_id_seq OWNER TO postgres; + +-- +-- Name: snapshots_snapshot_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.snapshots_snapshot_id_seq OWNED BY public.snapshots.snapshot_id; + + +-- +-- Name: snapshots_snapshot_id_seq1; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.snapshots_snapshot_id_seq1 + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.snapshots_snapshot_id_seq1 OWNER TO postgres; + +-- +-- Name: snapshots_snapshot_id_seq1; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.snapshots_snapshot_id_seq1 OWNED BY public.snapshots.snapshot_id; + + +-- +-- Name: snapshots_view; Type: VIEW; Schema: public; Owner: gta_v +-- + +CREATE VIEW public.snapshots_view AS + SELECT snapshots.snapshot_id, + snapshots.run_id, + snapshots.version, + snapshots.scene_id, + snapshots.imagepath, + snapshots."timestamp", + snapshots.timeofday, + snapshots.currentweather, + ARRAY[public.st_x(snapshots.camera_pos), public.st_y(snapshots.camera_pos), public.st_z(snapshots.camera_pos)] AS camera_pos, + ARRAY[public.st_x(snapshots.camera_rot), public.st_y(snapshots.camera_rot), public.st_z(snapshots.camera_rot)] AS camera_rot, + ARRAY[public.st_x(snapshots.camera_relative_rotation), public.st_y(snapshots.camera_relative_rotation), public.st_z(snapshots.camera_relative_rotation)] AS camera_relative_rotation, + ARRAY[public.st_x(snapshots.camera_relative_position), public.st_y(snapshots.camera_relative_position), public.st_z(snapshots.camera_relative_position)] AS camera_relative_position, + ARRAY[public.st_x(snapshots.camera_direction), public.st_y(snapshots.camera_direction), public.st_z(snapshots.camera_direction)] AS camera_direction, + snapshots.camera_fov, + snapshots.world_matrix, + snapshots.view_matrix, + snapshots.proj_matrix, + snapshots.processed, + snapshots.width, + snapshots.height, + snapshots.ui_width, + snapshots.ui_height, + snapshots.cam_near_clip, + snapshots.cam_far_clip, + ARRAY[public.st_x(snapshots.player_pos), public.st_y(snapshots.player_pos), public.st_z(snapshots.player_pos)] AS player_pos, + ARRAY[public.st_x(snapshots.velocity), public.st_y(snapshots.velocity), public.st_z(snapshots.velocity)] AS velocity + FROM public.snapshots; + + +ALTER TABLE public.snapshots_view OWNER TO gta_v; + +-- +-- Name: system_graphics; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.system_graphics ( + system_graphic_id integer NOT NULL, + deviceid text, + adaptercompatibility text, + adapterdactype text, + adapterram integer, + availability integer, + caption text, + description text, + driverdate timestamp with time zone, + driverversion text, + pnpdeviceid text, + name text, + videoarch integer, + memtype integer, + videoprocessor text, + bpp integer, + hrez integer, + vrez integer, + num_colors integer, + cols integer, + rows integer, + refresh integer, + scanmode integer, + videomodedesc text, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE public.system_graphics OWNER TO postgres; + +-- +-- Name: system_graphics_system_graphic_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.system_graphics_system_graphic_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.system_graphics_system_graphic_id_seq OWNER TO postgres; + +-- +-- Name: system_graphics_system_graphic_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.system_graphics_system_graphic_id_seq OWNED BY public.system_graphics.system_graphic_id; + + +-- +-- Name: systems; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.systems ( + system_uuid uuid NOT NULL, + vendor text, + dnshostname text, + username text, + systemtype text, + totalmem bigint, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE public.systems OWNER TO postgres; + +-- +-- Name: uploads; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.uploads ( + id integer NOT NULL, + bucket text, + key text, + uploadid text, + created timestamp without time zone DEFAULT timezone('utc'::text, now()) +); + + +ALTER TABLE public.uploads OWNER TO postgres; + +-- +-- Name: uploads_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres +-- + +CREATE SEQUENCE public.uploads_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.uploads_id_seq OWNER TO postgres; + +-- +-- Name: uploads_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres +-- + +ALTER SEQUENCE public.uploads_id_seq OWNED BY public.uploads.id; + + +-- +-- Name: datasets dataset_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.datasets ALTER COLUMN dataset_id SET DEFAULT nextval('public.datasets_dataset_id_seq'::regclass); + + +-- +-- Name: detections detection_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.detections ALTER COLUMN detection_id SET DEFAULT nextval('public.detections_detection_id_seq'::regclass); + + +-- +-- Name: instances instance_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.instances ALTER COLUMN instance_id SET DEFAULT nextval('public.instances_instance_id_seq'::regclass); + + +-- +-- Name: runs run_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.runs ALTER COLUMN run_id SET DEFAULT nextval('public.runs_run_id_seq'::regclass); + + +-- +-- Name: sessions session_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.sessions ALTER COLUMN session_id SET DEFAULT nextval('public.sessions_session_id_seq'::regclass); + + +-- +-- Name: snapshot_weathers weather_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.snapshot_weathers ALTER COLUMN weather_id SET DEFAULT nextval('public.snapshot_weathers_weather_id_seq'::regclass); + + +-- +-- Name: snapshots snapshot_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.snapshots ALTER COLUMN snapshot_id SET DEFAULT nextval('public.snapshots_snapshot_id_seq'::regclass); + + +-- +-- Name: system_graphics system_graphic_id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.system_graphics ALTER COLUMN system_graphic_id SET DEFAULT nextval('public.system_graphics_system_graphic_id_seq'::regclass); + + +-- +-- Name: uploads id; Type: DEFAULT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.uploads ALTER COLUMN id SET DEFAULT nextval('public.uploads_id_seq'::regclass); + + +-- +-- Name: datasets datasets_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.datasets + ADD CONSTRAINT datasets_pkey PRIMARY KEY (dataset_id); + + +-- +-- Name: detections detections_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.detections + ADD CONSTRAINT detections_pkey PRIMARY KEY (detection_id); + + +-- +-- Name: instances instance_info_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.instances + ADD CONSTRAINT instance_info_uniq UNIQUE (hostname, instanceid, instancetype, publichostname, amiid); + + +-- +-- Name: instances instanceid_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.instances + ADD CONSTRAINT instanceid_uniq UNIQUE (instanceid); + + +-- +-- Name: instances isntances_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.instances + ADD CONSTRAINT isntances_pkey PRIMARY KEY (instance_id); + + +-- +-- Name: runs runs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.runs + ADD CONSTRAINT runs_pkey PRIMARY KEY (run_id); + + +-- +-- Name: sessions sessions_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.sessions + ADD CONSTRAINT sessions_name_key UNIQUE (name); + + +-- +-- Name: sessions sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.sessions + ADD CONSTRAINT sessions_pkey PRIMARY KEY (session_id); + + +-- +-- Name: snapshot_weathers snapshot_weathers_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.snapshot_weathers + ADD CONSTRAINT snapshot_weathers_pkey PRIMARY KEY (weather_id); + + +-- +-- Name: snapshots snapshots_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.snapshots + ADD CONSTRAINT snapshots_pkey PRIMARY KEY (snapshot_id); + + +-- +-- Name: system_graphics system_graphics_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.system_graphics + ADD CONSTRAINT system_graphics_pkey PRIMARY KEY (system_graphic_id); + + +-- +-- Name: systems systems_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.systems + ADD CONSTRAINT systems_pkey PRIMARY KEY (system_uuid); + + +-- +-- Name: uploads uploads_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.uploads + ADD CONSTRAINT uploads_pkey PRIMARY KEY (id); + + +-- +-- Name: handle_index; Type: INDEX; Schema: public; Owner: postgres +-- + +CREATE INDEX handle_index ON public.detections USING btree (handle); + + +-- +-- Name: snapshot_index; Type: INDEX; Schema: public; Owner: postgres +-- + +CREATE INDEX snapshot_index ON public.detections USING btree (snapshot_id); + + +-- +-- Name: detections detections_snapshot_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.detections + ADD CONSTRAINT detections_snapshot_fkey FOREIGN KEY (snapshot_id) REFERENCES public.snapshots(snapshot_id) ON DELETE CASCADE; + + +-- +-- Name: runs runs_instance_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.runs + ADD CONSTRAINT runs_instance_fkey FOREIGN KEY (instance_id) REFERENCES public.instances(instance_id); + + +-- +-- Name: runs runs_session_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.runs + ADD CONSTRAINT runs_session_fkey FOREIGN KEY (session_id) REFERENCES public.sessions(session_id) ON DELETE CASCADE; + + +-- +-- Name: snapshot_weathers snapshot_weathers_snapshot_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.snapshot_weathers + ADD CONSTRAINT snapshot_weathers_snapshot_id_fkey FOREIGN KEY (snapshot_id) REFERENCES public.snapshots(snapshot_id) ON DELETE CASCADE; + + +-- +-- Name: snapshots snapshots_run_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.snapshots + ADD CONSTRAINT snapshots_run_fkey FOREIGN KEY (run_id) REFERENCES public.runs(run_id) ON DELETE CASCADE; + + +-- +-- Name: TABLE datasets; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.datasets TO gta_v; + + +-- +-- Name: SEQUENCE datasets_dataset_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.datasets_dataset_id_seq TO gta_v; + + +-- +-- Name: TABLE detections; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.detections TO gta_v; + + +-- +-- Name: SEQUENCE detections_detection_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.detections_detection_id_seq TO gta_v; + + +-- +-- Name: TABLE geography_columns; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.geography_columns TO gta_v; + + +-- +-- Name: TABLE geometry_columns; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.geometry_columns TO gta_v; + + +-- +-- Name: TABLE instances; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.instances TO gta_v; + + +-- +-- Name: SEQUENCE instances_instance_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.instances_instance_id_seq TO gta_v; + + +-- +-- Name: TABLE raster_columns; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.raster_columns TO gta_v; + + +-- +-- Name: TABLE raster_overviews; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.raster_overviews TO gta_v; + + +-- +-- Name: TABLE runs; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.runs TO gta_v; + + +-- +-- Name: SEQUENCE runs_run_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.runs_run_id_seq TO gta_v; + + +-- +-- Name: TABLE sessions; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.sessions TO gta_v; + + +-- +-- Name: SEQUENCE sessions_session_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.sessions_session_id_seq TO gta_v; + + +-- +-- Name: TABLE snapshot_weathers; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.snapshot_weathers TO gta_v; + + +-- +-- Name: SEQUENCE snapshot_weathers_weather_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.snapshot_weathers_weather_id_seq TO gta_v; + + +-- +-- Name: TABLE snapshots; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.snapshots TO gta_v; + + +-- +-- Name: SEQUENCE snapshots_snapshot_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.snapshots_snapshot_id_seq TO gta_v; + + +-- +-- Name: SEQUENCE snapshots_snapshot_id_seq1; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.snapshots_snapshot_id_seq1 TO gta_v; + + +-- +-- Name: TABLE spatial_ref_sys; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.spatial_ref_sys TO gta_v; + + +-- +-- Name: TABLE system_graphics; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.system_graphics TO gta_v; + + +-- +-- Name: SEQUENCE system_graphics_system_graphic_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.system_graphics_system_graphic_id_seq TO gta_v; + + +-- +-- Name: TABLE systems; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.systems TO gta_v; + + +-- +-- Name: TABLE uploads; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON TABLE public.uploads TO gta_v; + + +-- +-- Name: SEQUENCE uploads_id_seq; Type: ACL; Schema: public; Owner: postgres +-- + +GRANT ALL ON SEQUENCE public.uploads_id_seq TO gta_v; + + +-- +-- PostgreSQL database dump complete +-- diff --git a/db_schema_old.sql b/db_schema_old.sql new file mode 100644 index 0000000..b3a31a4 --- /dev/null +++ b/db_schema_old.sql @@ -0,0 +1,216 @@ +SET search_path = public, pg_catalog; + + +create type detection_class as enum ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Trains') +; + +create type detection_type as enum ('background', 'person', 'car', 'bicycle') +; + +create type weather as enum ('Unknown', 'ExtraSunny', 'Clear', 'Clouds', 'Smog', 'Foggy', 'Overcast', 'Raining', 'ThunderStorm', 'Clearing', 'Neutral', 'Snowing', 'Blizzard', 'Snowlight', 'Christmas', 'Halloween') +; + + +create table datasets +( + dataset_id serial not null + constraint datasets_pkey + primary key, + dataset_name text, + view_name text, + created timestamp default timezone('utc'::text, now()) +) +; + +create table instances +( + instance_id serial not null + constraint isntances_pkey + primary key, + hostname text, + instanceid text + constraint instanceid_uniq + unique, + instancetype text, + publichostname text, + amiid text, + created timestamp default timezone('utc'::text, now()), + constraint instance_info_uniq + unique (hostname, instanceid, instancetype, publichostname, amiid) +) +; + +create table sessions +( + session_id serial not null + constraint sessions_pkey + primary key, + name text + constraint sessions_name_key + unique, + start timestamp with time zone, + "end" timestamp with time zone, + created timestamp default timezone('utc'::text, now()) +) +; + +create table runs +( + run_id serial not null + constraint runs_pkey + primary key, + runguid uuid, + archivepath text, + localpath text, + session_id integer default 1 + constraint runs_session_fkey + references sessions + on delete cascade, + instance_id integer default 0 + constraint runs_instance_fkey + references instances, + created timestamp default timezone('utc'::text, now()) +) +; + +create table snapshots +( + snapshot_id serial not null + constraint snapshots_pkey + primary key, + run_id integer + constraint snapshots_run_fkey + references runs + on delete cascade, + version integer, + scene_id uuid, + imagepath text, + timestamp timestamp with time zone, + timeofday time, + currentweather weather, + camera_pos geometry(PointZ), + camera_rot geometry(PointZ), + camera_relative_rotation geometry(PointZ), + camera_direction geometry, + camera_fov real, + world_matrix double precision[], + view_matrix double precision[], + proj_matrix double precision[], + processed boolean default false not null, + width integer, + height integer, + ui_width integer, + ui_height integer, + cam_near_clip real, + cam_far_clip real, + player_pos geometry(PointZ), + velocity geometry(PointZ), + camera_relative_position geometry(PointZ) +) +; + +create table detections +( + detection_id serial not null + constraint detections_pkey + primary key, + snapshot_id integer + constraint detections_snapshot_fkey + references snapshots + on delete cascade, + type detection_type, + pos geometry(PointZ), + bbox box, + class detection_class default 'Unknown'::detection_class, + handle integer default '-1'::integer, + best_bbox box, + best_bbox_old box, + bbox3d box3d, + rot geometry, + coverage real default 0.0, + created timestamp default timezone('utc'::text, now()), + velocity geometry(PointZ) +) +; + +create index snapshot_index + on detections (snapshot_id) +; + +create index handle_index + on detections (handle) +; + +create table snapshot_weathers +( + weather_id serial not null + constraint snapshot_weathers_pkey + primary key, + snapshot_id integer + constraint snapshot_weathers_snapshot_id_fkey + references snapshots + on delete cascade, + weather_type weather, + snapshot_page integer, + created timestamp default timezone('utc'::text, now()) +) +; + +create table system_graphics +( + system_graphic_id serial not null + constraint system_graphics_pkey + primary key, + deviceid text, + adaptercompatibility text, + adapterdactype text, + adapterram integer, + availability integer, + caption text, + description text, + driverdate timestamp with time zone, + driverversion text, + pnpdeviceid text, + name text, + videoarch integer, + memtype integer, + videoprocessor text, + bpp integer, + hrez integer, + vrez integer, + num_colors integer, + cols integer, + rows integer, + refresh integer, + scanmode integer, + videomodedesc text, + created timestamp default timezone('utc'::text, now()) +) +; + +create table systems +( + system_uuid uuid not null + constraint systems_pkey + primary key, + vendor text, + dnshostname text, + username text, + systemtype text, + totalmem bigint, + created timestamp default timezone('utc'::text, now()) +) +; + +create table uploads +( + id serial not null + constraint uploads_pkey + primary key, + bucket text, + key text, + uploadid text, + created timestamp default timezone('utc'::text, now()) +) +; + From dfd6915195a3722e9191b3a6ed01dd7b121b9d59 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 27 Jun 2018 15:13:28 +0200 Subject: [PATCH 130/158] removed user gta_v from dump --- db_schema.sql | 184 +------------------------------------------------- 1 file changed, 1 insertion(+), 183 deletions(-) diff --git a/db_schema.sql b/db_schema.sql index 4603e64..bc62c11 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -510,7 +510,7 @@ ALTER SEQUENCE public.snapshots_snapshot_id_seq1 OWNED BY public.snapshots.snaps -- --- Name: snapshots_view; Type: VIEW; Schema: public; Owner: gta_v +-- Name: snapshots_view; Type: VIEW; Schema: public; -- CREATE VIEW public.snapshots_view AS @@ -543,8 +543,6 @@ CREATE VIEW public.snapshots_view AS FROM public.snapshots; -ALTER TABLE public.snapshots_view OWNER TO gta_v; - -- -- Name: system_graphics; Type: TABLE; Schema: public; Owner: postgres -- @@ -874,183 +872,3 @@ ALTER TABLE ONLY public.snapshot_weathers ALTER TABLE ONLY public.snapshots ADD CONSTRAINT snapshots_run_fkey FOREIGN KEY (run_id) REFERENCES public.runs(run_id) ON DELETE CASCADE; - --- --- Name: TABLE datasets; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.datasets TO gta_v; - - --- --- Name: SEQUENCE datasets_dataset_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.datasets_dataset_id_seq TO gta_v; - - --- --- Name: TABLE detections; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.detections TO gta_v; - - --- --- Name: SEQUENCE detections_detection_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.detections_detection_id_seq TO gta_v; - - --- --- Name: TABLE geography_columns; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.geography_columns TO gta_v; - - --- --- Name: TABLE geometry_columns; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.geometry_columns TO gta_v; - - --- --- Name: TABLE instances; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.instances TO gta_v; - - --- --- Name: SEQUENCE instances_instance_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.instances_instance_id_seq TO gta_v; - - --- --- Name: TABLE raster_columns; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.raster_columns TO gta_v; - - --- --- Name: TABLE raster_overviews; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.raster_overviews TO gta_v; - - --- --- Name: TABLE runs; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.runs TO gta_v; - - --- --- Name: SEQUENCE runs_run_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.runs_run_id_seq TO gta_v; - - --- --- Name: TABLE sessions; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.sessions TO gta_v; - - --- --- Name: SEQUENCE sessions_session_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.sessions_session_id_seq TO gta_v; - - --- --- Name: TABLE snapshot_weathers; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.snapshot_weathers TO gta_v; - - --- --- Name: SEQUENCE snapshot_weathers_weather_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.snapshot_weathers_weather_id_seq TO gta_v; - - --- --- Name: TABLE snapshots; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.snapshots TO gta_v; - - --- --- Name: SEQUENCE snapshots_snapshot_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.snapshots_snapshot_id_seq TO gta_v; - - --- --- Name: SEQUENCE snapshots_snapshot_id_seq1; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.snapshots_snapshot_id_seq1 TO gta_v; - - --- --- Name: TABLE spatial_ref_sys; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.spatial_ref_sys TO gta_v; - - --- --- Name: TABLE system_graphics; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.system_graphics TO gta_v; - - --- --- Name: SEQUENCE system_graphics_system_graphic_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.system_graphics_system_graphic_id_seq TO gta_v; - - --- --- Name: TABLE systems; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.systems TO gta_v; - - --- --- Name: TABLE uploads; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON TABLE public.uploads TO gta_v; - - --- --- Name: SEQUENCE uploads_id_seq; Type: ACL; Schema: public; Owner: postgres --- - -GRANT ALL ON SEQUENCE public.uploads_id_seq TO gta_v; - - --- --- PostgreSQL database dump complete --- - From ea88c1f370e5d72ebcb122ec84bb385e55cbbae2 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 17 Jul 2018 19:08:58 +0200 Subject: [PATCH 131/158] added saving of ego vehicle model size, good for estimation of car middle position above ground --- managed/GTAVisionExport/VisionExport.cs | 30 ++++++++---- managed/GTAVisionUtils/GTADataStructures.cs | 8 +++- managed/GTAVisionUtils/PostgresExport.cs | 53 ++++++++++++--------- managed/structure_dump.sql | 1 + 4 files changed, 60 insertions(+), 32 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 76b3b72..bd02f69 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -131,12 +131,12 @@ private void initialize4cameras() { // cameras initialization: // for cameras mapping area before the car - float r = 8f; //radius of circle with 4 cameras - CamerasList.setMainCamera(new Vector3()); - CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); - CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); - CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); - CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); +// float r = 8f; //radius of circle with 4 cameras +// CamerasList.setMainCamera(new Vector3()); +// CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); +// CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); +// CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); +// CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); // for 4 cameras of different sides of the car // CamerasList.setMainCamera(new Vector3()); @@ -146,8 +146,22 @@ private void initialize4cameras() { // CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); // set only main camera for static traffic camera - CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(270f, 0f, 0f), 50, 0.15f); - +// CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(270f, 0f, 0f), 50, 0.15f); + +// two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo +// for cameras mapping area before the car + CamerasList.setMainCamera(new Vector3()); + float r = 8f; //radius of circle with 4 cameras + var camOne = new Vector3(-0.06f, 0.27f, 1.65f); + var camTwo = new Vector3(-0.06f+0.54f, 0.27f, 1.65f); + CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 1.5f); + CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 1.5f); + CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 1.5f); + CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 1.5f); + CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 1.5f); + CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 1.5f); + CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 1.5f); + CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 1.5f); } private void handlePipeInput() { diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 02d77c6..fd81935 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -117,7 +117,7 @@ public GTADetection(Entity e, DetectionType type) Vector3 gmin; Vector3 gmax; e.Model.GetDimensions(out gmin, out gmax); - BBox3D = new SharpDX.BoundingBox((SharpDX.Vector3)new GTAVector(gmin), (SharpDX.Vector3)new GTAVector(gmax)); + BBox3D = new BoundingBox((SharpDX.Vector3) new GTAVector(gmin), (SharpDX.Vector3)new GTAVector(gmax)); } public GTADetection(Ped p) : this(p, DetectionType.person) @@ -182,6 +182,7 @@ public class GTAData public List CapturedWeathers; public GTAVector CamPos { get; set; } public GTAVector CamRot { get; set; } + public BoundingBox CarModelBox { get; set; } public GTAVector CamDirection { get; set; } //mathnet's matrices are in heap storage, which is super annoying, //but we want to use double matrices to avoid numerical issues as we @@ -330,6 +331,11 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.LocalTime = World.CurrentDayTime; ret.CamPos = new GTAVector(World.RenderingCamera.Position); ret.CamRot = new GTAVector(World.RenderingCamera.Rotation); + //getting information about currently driving vehicle model size + Vector3 gmin; + Vector3 gmax; + Game.Player.Character.CurrentVehicle.Model.GetDimensions(out gmin, out gmax); + ret.CarModelBox = new BoundingBox((SharpDX.Vector3) new GTAVector(gmin), (SharpDX.Vector3) new GTAVector(gmax)); ret.CamDirection = new GTAVector(World.RenderingCamera.Direction); ret.CamFOV = World.RenderingCamera.FieldOfView; ret.ImageWidth = Game.ScreenResolution.Width; diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index bb5d071..8e7a7be 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -166,28 +166,46 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { var conn = OpenConnection(); var trans = conn.BeginTransaction(); - var camRelativeRotString = "NULL"; - if (data.CamRelativeRot != null) { - camRelativeRotString = "ST_MakePoint(@relative_rot_x, @relative_rot_y, @relative_rot_z)"; - } - - var camRelativePosString = "NULL"; - if (data.CamRelativePos != null) { - camRelativePosString = "ST_MakePoint(@relative_pos_x, @relative_pos_y, @relative_pos_z)"; - } - using (NpgsqlCommand cmd = new NpgsqlCommand()) { + var camRelativeRotString = "NULL"; + if (data.CamRelativeRot != null) { + camRelativeRotString = "ST_MakePoint(@relative_rot_x, @relative_rot_y, @relative_rot_z)"; + cmd.Parameters.AddWithValue("@relative_rot_x", data.CamRelativeRot.X); + cmd.Parameters.AddWithValue("@relative_rot_y", data.CamRelativeRot.Y); + cmd.Parameters.AddWithValue("@relative_rot_z", data.CamRelativeRot.Z); + } + + var camRelativePosString = "NULL"; + if (data.CamRelativePos != null) { + camRelativePosString = "ST_MakePoint(@relative_pos_x, @relative_pos_y, @relative_pos_z)"; + cmd.Parameters.AddWithValue("@relative_pos_x", data.CamRelativePos.X); + cmd.Parameters.AddWithValue("@relative_pos_y", data.CamRelativePos.Y); + cmd.Parameters.AddWithValue("@relative_pos_z", data.CamRelativePos.Z); + } + + var carModelBoxString = "NULL"; + if (data.CarModelBox != null) { + carModelBoxString = "ST_3DMakeBox(ST_MakePoint(@cam_box_min_x, @cam_box_min_y, @cam_box_min_z), " + + "ST_MakePoint(@cam_box_max_x, @cam_box_max_y, @cam_box_max_z))"; + cmd.Parameters.AddWithValue("@cam_box_min_x", data.CarModelBox.Minimum.X); + cmd.Parameters.AddWithValue("@cam_box_min_y", data.CarModelBox.Minimum.Y); + cmd.Parameters.AddWithValue("@cam_box_min_z", data.CarModelBox.Minimum.Z); + cmd.Parameters.AddWithValue("@cam_box_max_x", data.CarModelBox.Maximum.X); + cmd.Parameters.AddWithValue("@cam_box_max_y", data.CarModelBox.Maximum.Y); + cmd.Parameters.AddWithValue("@cam_box_max_z", data.CarModelBox.Maximum.Z); + } + cmd.Connection = conn; cmd.Transaction = trans; cmd.CommandText = "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_rot, " + "camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, " + - "cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation, camera_relative_position, world_matrix) " + + "cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation, camera_relative_position, car_model_box, world_matrix) " + "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@rotx, @roty, @rotz), " + "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id, " + - camRelativeRotString + ", " + camRelativePosString + ", @world_matrix) " + + camRelativeRotString + ", " + camRelativePosString + ", " + carModelBoxString + ", @world_matrix) " + "RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); @@ -222,17 +240,6 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { cmd.Parameters.AddWithValue("@cam_far_clip", data.CamFarClip); cmd.Parameters.AddWithValue("@scene_id", data.sceneGuid); - if (data.CamRelativeRot != null) { - cmd.Parameters.AddWithValue("@relative_rot_x", data.CamRelativeRot.X); - cmd.Parameters.AddWithValue("@relative_rot_y", data.CamRelativeRot.Y); - cmd.Parameters.AddWithValue("@relative_rot_z", data.CamRelativeRot.Z); - } - if (data.CamRelativePos != null) { - cmd.Parameters.AddWithValue("@relative_pos_x", data.CamRelativePos.X); - cmd.Parameters.AddWithValue("@relative_pos_y", data.CamRelativePos.Y); - cmd.Parameters.AddWithValue("@relative_pos_z", data.CamRelativePos.Z); - } - cmd.Parameters.Add(new NpgsqlParameter("@guid", runId)); int snapshotid = (int) cmd.ExecuteScalar(); cmd.Parameters.Clear(); diff --git a/managed/structure_dump.sql b/managed/structure_dump.sql index 3bf23e1..e7a2fcf 100644 --- a/managed/structure_dump.sql +++ b/managed/structure_dump.sql @@ -447,6 +447,7 @@ CREATE TABLE snapshots camera_rot GEOMETRY(PointZ), camera_relative_rotation GEOMETRY(PointZ), camera_direction GEOMETRY, + car_model_box box3d, camera_fov REAL, world_matrix DOUBLE PRECISION [], view_matrix DOUBLE PRECISION [], From 60172864c14b995480cc4628943f2b75a1dcd557 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 17 Jul 2018 19:19:14 +0200 Subject: [PATCH 132/158] updated db schema --- db_schema.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db_schema.sql b/db_schema.sql index bc62c11..41df09e 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -449,6 +449,7 @@ CREATE TABLE public.snapshots ( camera_relative_rotation public.geometry(PointZ), camera_direction public.geometry, camera_fov real, + car_model_box box3d, world_matrix double precision[], view_matrix double precision[], proj_matrix double precision[], From 246f2f35a171067228711a1450a3083cba123608 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 19 Jul 2018 01:06:37 +0200 Subject: [PATCH 133/158] finally found parameters for multi-camera KITTI-like setup --- managed/GTAVisionExport/CamerasList.cs | 7 ++++-- managed/GTAVisionExport/VisionExport.cs | 31 +++++++++++++++---------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 9407885..e77a2a7 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -117,9 +117,12 @@ public static Camera ActivateCamera(int i) { cameras[i].Rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; // WARNING: CAMERAS SETTING DO NOT WORK WHEN GAME IS PAUSED, SO WE NEED TO UNPAUSE THE GAME, SET THINGS UP, AND THEN PAUSE GAME AGAIN // Script.Wait(1); -// //with time 1, sometimes depth does not correspond, and bounding boxes dont correspond by 3 frames +// //with time 1, sometimes depth does not correspond, and bounding boxes dont correspond by 1 frames // //with time 2, depth does correspond, but bounding boxes dont correspond by 2 frames -// //with time 3, sometimes depth does not correspond, but bounding boxes dont correspond by 1 frames +// //with time 3, depth does correspond, but bounding boxes dont correspond by 3 frames +// //with time 4, depth does NOT correspond sometimes, but bounding boxes dont correspond by 3 frames +// //with time 5, depth is OK +// todo: pair detections with scene id, not with snapshot id, and gather them once per scene, not per snapshot // Script.Wait(4);//tried 4 milliseconds instead of one, so screenshots correspond to their data Script.Wait(gameplayInterval.Value); Game.Pause(true); diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index bd02f69..dcfa9a0 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -51,8 +51,10 @@ class VisionExport : Script { private readonly bool multipleWeathers = false; // decides whether to use multiple weathers or just one private readonly bool currentWeather = true; private readonly bool clearEverything = false; - private readonly bool useMultipleCameras = false; // when false, cameras handling script is not used at all - private readonly bool staticCamera = true; // this turns off whole car spawning, teleportation and autodriving procedure +// private readonly bool useMultipleCameras = false; // when false, cameras handling script is not used at all + private readonly bool useMultipleCameras = true; // when false, cameras handling script is not used at all +// private readonly bool staticCamera = true; // this turns off whole car spawning, teleportation and autodriving procedure + private readonly bool staticCamera = false; // this turns off whole car spawning, teleportation and autodriving procedure private Player player; private GTARun run; private bool enabled = false; @@ -152,16 +154,21 @@ private void initialize4cameras() { // for cameras mapping area before the car CamerasList.setMainCamera(new Vector3()); float r = 8f; //radius of circle with 4 cameras - var camOne = new Vector3(-0.06f, 0.27f, 1.65f); - var camTwo = new Vector3(-0.06f+0.54f, 0.27f, 1.65f); - CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 1.5f); - CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 1.5f); - CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 1.5f); - CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 1.5f); - CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 1.5f); - CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 1.5f); - CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 1.5f); - CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 1.5f); + // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground + var car_center = 0.5735f; + var camOne = new Vector3(-0.06f, 0.27f, 1.65f - car_center); + var camTwo = new Vector3(-0.06f+0.54f, 0.27f, 1.65f - car_center); + CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); + CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); + CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); + CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); +// 4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras + CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); +// CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); +// CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); +// CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); +// and now, one camera from birds-eye view, with this configuration, it sees all other cameras + CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); } private void handlePipeInput() { From 83a74b0b1bb9d37b2a075f3e418e886b4f20efb4 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 24 Jul 2018 16:21:16 +0200 Subject: [PATCH 134/158] less frames during manual capturing --- managed/GTAVisionExport/VisionExport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index dcfa9a0..5477b88 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -773,7 +773,7 @@ public void OnKeyDown(object o, KeyEventArgs k) { postgresTask?.Wait(); runTask?.Wait(); UINotify("starting screenshots"); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 2; i++) { GamePause(true); gatherData(100); GamePause(false); From 805d9cf64061a04e1aa165b0cb1ba4bf356660b7 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 24 Jul 2018 16:40:08 +0200 Subject: [PATCH 135/158] some other examples of using GTA api, minor modifications --- managed/GTAVisionExport/CameraHandling.cs | 18 +++++++++ managed/GTAVisionExport/VisionExport.cs | 42 +++++++++++++-------- managed/GTAVisionUtils/GTADataStructures.cs | 1 - managed/GTAVisionUtils/ImageUtils.cs | 2 +- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 5592ef1..bd367d5 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -71,8 +71,26 @@ public void keepCameraOnVehicle() { } } + public void doRayCasting() { + var result = GTA.World.Raycast(Game.Player.Character.Position, + Game.Player.Character.Position + (Vector3.RelativeLeft * 100), IntersectOptions.Everything); + UI.Notify("raycast result:"); + Logger.writeLine("raycast result:"); + UI.Notify(result.DitHitAnything.ToString()); + Logger.writeLine(result.DitHitAnything.ToString()); + if (result.DitHitAnything) { + UI.Notify(result.HitCoords.ToString()); + Logger.writeLine(result.HitCoords.ToString()); + GTA.World.DrawMarker(MarkerType.CheckeredFlagCircle, result.HitCoords, Vector3.RelativeRight, Vector3.WorldUp, new Vector3(10, 10, 10), Color.Chartreuse); + } + } + // Test vehicle controls private void onKeyUp(object sender, KeyEventArgs e) { + if (e.KeyCode == Keys.B) { + doRayCasting(); + } + if (e.KeyCode == Keys.P) { activeCameraIndex = -1; mountCameraOnVehicle(); diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 4b9a764..127df1f 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -53,7 +53,7 @@ class VisionExport : Script { private readonly bool clearEverything = false; // private readonly bool useMultipleCameras = false; // when false, cameras handling script is not used at all private readonly bool useMultipleCameras = true; // when false, cameras handling script is not used at all - private readonly bool staticCamera = true; // this turns off whole car spawning, teleportation and autodriving procedure + private readonly bool staticCamera = false; // this turns off whole car spawning, teleportation and autodriving procedure private Player player; private GTARun run; private bool enabled = false; @@ -132,23 +132,31 @@ private void initialize4cameras() { // cameras initialization: // for cameras mapping area before the car -// float r = 8f; //radius of circle with 4 cameras -// CamerasList.setMainCamera(new Vector3()); -// CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); -// CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); -// CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); -// CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); - -// for 4 cameras of different sides of the car - CamerasList.setMainCamera(); - CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 0.15f); - CamerasList.addCamera(new Vector3(-0.6f, 0f, 0.8f), new Vector3(0f, 0f, 90f), 50, 0.15f); - CamerasList.addCamera(new Vector3(0f, -2f, 0.6f), new Vector3(0f, 0f, 180f), 50, 0.15f); - CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); + float r = 8f; //radius of circle with 4 cameras + CamerasList.setMainCamera(new Vector3()); + CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); + CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); + CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); + CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); + +// for 4 cameras on different sides of the car +// CamerasList.setMainCamera(); +// CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(-0.6f, 0f, 0.8f), new Vector3(0f, 0f, 90f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(0f, -2f, 0.6f), new Vector3(0f, 0f, 180f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); + +// for 4 cameras on top of car, heading 4 directions +// CamerasList.setMainCamera(); +// CamerasList.addCamera(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 0f), 58, 0.15f); +// CamerasList.addCamera(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 90f), 58, 0.15f); +// CamerasList.addCamera(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 180f), 58, 0.15f); +// CamerasList.addCamera(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 270f), 58, 0.15f); // set only main camera for static traffic camera -// CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(270f, 0f, 0f), 50, 0.15f); -// CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(0f, 270f, 0f), 50, 0.15f); +// CamerasList.setMainCamera(new Vector3(-1078f, -216f, 67f), new Vector3(270f, 0f, 0f), 50, 0.15f); +// CamerasList.setMainCamera(new Vector3(-908.5f, 238f, 100f), new Vector3(270f, 0f, 0f), 50, 0.15f); +// CamerasList.setMainCamera(new Vector3(-908.5f, 238f, 80f), new Vector3(270f, 0f, 0f), 100, 0.15f); // very big field of view } @@ -299,6 +307,7 @@ public void OnTick(object o, EventArgs e) { switch (checkStatus()) { case GameStatus.NeedReload: //TODO: need to get a new session and run? + Logger.writeLine("Status is NeedReload"); StopRun(); runTask?.Wait(); runTask = StartRun(); @@ -310,6 +319,7 @@ public void OnTick(object o, EventArgs e) { break; case GameStatus.NeedStart: //TODO do the autostart manually or automatically? + Logger.writeLine("Status is NeedStart"); //Autostart(); // use reloading temporarily StopRun(); diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index 6eedea0..02d77c6 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -341,7 +341,6 @@ public static GTAData DumpData(string imageName, List capturedWeathers) ret.CamNearClip = World.RenderingCamera.NearClip; ret.CamFarClip = World.RenderingCamera.FarClip; - Logger.writeLine(Game.Player.Character.ToString()); var peds = World.GetNearbyPeds(Game.Player.Character, 500.0f); var cars = World.GetNearbyVehicles(Game.Player.Character, 500.0f); //var props = World.GetNearbyProps(Game.Player.Character.Position, 300.0f); diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index d29bb75..87a3eaf 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -151,7 +151,7 @@ public static void WriteToTiffImpl(string name, int width, int height, List Date: Tue, 24 Jul 2018 16:52:26 +0200 Subject: [PATCH 136/158] some small refactoring, code cleanup --- managed/GTAVisionExport/CameraHandling.cs | 110 ++++++++++------------ managed/GTAVisionExport/VisionExport.cs | 50 +++++----- 2 files changed, 77 insertions(+), 83 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index bd367d5..389dd20 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -87,68 +87,62 @@ public void doRayCasting() { // Test vehicle controls private void onKeyUp(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.B) { - doRayCasting(); - } - - if (e.KeyCode == Keys.P) { - activeCameraIndex = -1; - mountCameraOnVehicle(); - enabled = true; - } - - if (e.KeyCode == Keys.O) { - restoreCamera(); - enabled = false; - } + switch (e.KeyCode) { + case Keys.B: + doRayCasting(); + break; + case Keys.P: + activeCameraIndex = -1; + mountCameraOnVehicle(); + enabled = true; + break; + case Keys.O: + restoreCamera(); + enabled = false; + break; // UI.Notify("keycode is:" + e.KeyCode); - - if (e.KeyCode == Keys.Add) { - UI.Notify("Pressed numpad +"); - showCameras = !showCameras; - UI.Notify("there are " + CamerasList.camerasPositions.Count + " cameras"); - if (showCameras) { - UI.Notify("enabled cameras showing"); - } - else { - UI.Notify("disabled cameras showing"); - } - - } - - if (e.KeyCode == Keys.NumPad0) { - UI.Notify("Pressed numpad 0"); - activeCameraIndex = 0; - mountCameraOnVehicle(); - } - - if (e.KeyCode == Keys.NumPad1) { - UI.Notify("Pressed numpad 1"); - activeCameraIndex = 1; - mountCameraOnVehicle(); - } - - if (e.KeyCode == Keys.NumPad2) { - UI.Notify("Pressed numpad 2"); - activeCameraIndex = 2; - mountCameraOnVehicle(); - } - - if (e.KeyCode == Keys.NumPad3) { - UI.Notify("Pressed numpad 3"); - activeCameraIndex = 3; - mountCameraOnVehicle(); - } - - if (e.KeyCode == Keys.Decimal) { - UI.Notify("Pressed numpad ,"); - activeCameraIndex = -1; - mountCameraOnVehicle(); + case Keys.Add: + UI.Notify("Pressed numpad +"); + showCameras = !showCameras; + UI.Notify("there are " + CamerasList.camerasPositions.Count + " cameras"); + if (showCameras) { + UI.Notify("enabled cameras showing"); + } + else { + UI.Notify("disabled cameras showing"); + } + + break; + case Keys.NumPad0: + UI.Notify("Pressed numpad 0"); + activeCameraIndex = 0; + mountCameraOnVehicle(); + break; + case Keys.NumPad1: + UI.Notify("Pressed numpad 1"); + activeCameraIndex = 1; + mountCameraOnVehicle(); + break; + case Keys.NumPad2: + UI.Notify("Pressed numpad 2"); + activeCameraIndex = 2; + mountCameraOnVehicle(); + break; + case Keys.NumPad3: + UI.Notify("Pressed numpad 3"); + activeCameraIndex = 3; + mountCameraOnVehicle(); + break; + case Keys.Decimal: + UI.Notify("Pressed numpad ,"); + activeCameraIndex = -1; + mountCameraOnVehicle(); + break; } } - void OnTick(object sender, EventArgs e) { + public void OnTick(object sender, EventArgs e) { keepCameraOnVehicle(); if (showCameras) { drawCamerasBoxes(); @@ -156,7 +150,7 @@ void OnTick(object sender, EventArgs e) { // drawAxesBoxesAround(new Vector3(-1078f, -216f, 200f)); } - void drawCamerasBoxes() { + public void drawCamerasBoxes() { // this shows white boxes where cameras are foreach (var camPos in CamerasList.camerasPositions) { var curVehicle = Game.Player.Character.CurrentVehicle; diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 2e5d762..3a4ecb5 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -159,12 +159,12 @@ private void initialize4cameras() { // two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo // for cameras mapping area before the car - CamerasList.setMainCamera(new Vector3()); - float r = 8f; //radius of circle with 4 cameras + CamerasList.setMainCamera(); + const float r = 8f; //radius of circle with 4 cameras // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground - var car_center = 0.5735f; - var camOne = new Vector3(-0.06f, 0.27f, 1.65f - car_center); - var camTwo = new Vector3(-0.06f+0.54f, 0.27f, 1.65f - car_center); + var carCenter = 0.5735f; + var camOne = new Vector3(-0.06f, 0.27f, 1.65f - carCenter); + var camTwo = new Vector3(-0.06f+0.54f, 0.27f, 1.65f - carCenter); CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); @@ -178,16 +178,16 @@ private void initialize4cameras() { CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); } - private void handlePipeInput() { + private void HandlePipeInput() { // Logger.writeLine("VisionExport handlePipeInput called."); // UINotify("handlePipeInput called"); UINotify("server connected:" + server.Connected.ToString()); - UINotify(connection == null ? "connection is null" : "connection:" + connection.ToString()); + UINotify(connection == null ? "connection is null" : "connection:" + connection); if (connection == null) return; - byte[] inBuffer = new byte[1024]; - string str = ""; - int num = 0; + var inBuffer = new byte[1024]; + var str = ""; + var num = 0; try { num = connection.Receive(inBuffer); str = encoding.GetString(inBuffer, 0, num); @@ -207,8 +207,8 @@ private void handlePipeInput() { return; } - UINotify("str: " + str.ToString()); - Logger.writeLine("obtained json: " + str.ToString()); + UINotify("str: " + str); + Logger.writeLine("obtained json: " + str); dynamic parameters = JsonConvert.DeserializeObject(str); string commandName = parameters.name; switch (commandName) { @@ -236,10 +236,10 @@ private void handlePipeInput() { ReloadGame(); break; case "RELOAD": - FieldInfo f = this.GetType() + var f = GetType() .GetField("_scriptdomain", BindingFlags.NonPublic | BindingFlags.Instance); - object domain = f.GetValue(this); - MethodInfo m = domain.GetType() + var domain = f.GetValue(this); + var m = domain.GetType() .GetMethod("DoKeyboardMessage", BindingFlags.Instance | BindingFlags.Public); m.Invoke(domain, new object[] {Keys.Insert, true, false, false, false}); break; @@ -256,7 +256,7 @@ private void handlePipeInput() { try { string weather = parameters.weather; UINotify("Weather Set to " + weather.ToString()); - Weather weatherEnum = (Weather) Enum.Parse(typeof(Weather), weather); + var weatherEnum = (Weather) Enum.Parse(typeof(Weather), weather); GTA.World.Weather = weatherEnum; } catch (Exception e) { @@ -316,7 +316,7 @@ public void OnTick(object o, EventArgs e) { connection.Blocking = false; } - handlePipeInput(); + HandlePipeInput(); if (!enabled) return; //Array values = Enum.GetValues(typeof(Weather)); @@ -332,7 +332,7 @@ public void OnTick(object o, EventArgs e) { //StopSession(); //Autostart(); UINotify("need reload game"); - Script.Wait(100); + Wait(100); ReloadGame(); break; case GameStatus.NeedStart: @@ -343,7 +343,7 @@ public void OnTick(object o, EventArgs e) { StopRun(); ReloadGame(); - Script.Wait(100); + Wait(100); runTask?.Wait(); runTask = StartRun(); //Autostart(); @@ -384,18 +384,18 @@ private void gatherData(int delay = 5) { ClearSurroundingEverything(Game.Player.Character.Position, 1000f); } - Script.Wait(100); + Wait(100); var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; var guid = Guid.NewGuid(); Logger.writeLine("generated scene guid: " + guid.ToString()); if (useMultipleCameras) { - for (int i = 0; i < CamerasList.cameras.Count; i++) { + for (var i = 0; i < CamerasList.cameras.Count; i++) { Logger.writeLine("activating camera " + i.ToString()); CamerasList.ActivateCamera(i); gatherDatForOneCamera(dateTimeFormat, guid); - Script.Wait(delay); + Wait(delay); } CamerasList.Deactivate(); } @@ -458,10 +458,10 @@ private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { /* -1 = need restart, 0 = normal, 1 = need to enter vehicle */ public GameStatus checkStatus() { - Ped player = Game.Player.Character; + var player = Game.Player.Character; if (player.IsDead) return GameStatus.NeedReload; if (player.IsInVehicle()) { - Vehicle vehicle = player.CurrentVehicle; + var vehicle = player.CurrentVehicle; //UINotify("T:" + Game.GameTime.ToString() + " S: " + vehicle.Speed.ToString()); if (vehicle.Speed < 1.0f) //speed is in mph { @@ -566,7 +566,7 @@ public void EnterVehicle() { var vehicle = World.GetClosestVehicle(player.Character.Position, 30f); player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); */ - Model mod = new Model(GTA.Native.VehicleHash.Asea); + var mod = new Model(GTA.Native.VehicleHash.Asea); if (mod == null) { UINotify("mod is null"); } From a0009ecc449a695e8590a530a087d4141f721738 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 25 Jul 2018 14:49:51 +0200 Subject: [PATCH 137/158] implemented threadsafe logging, more detailed logging of tiff-related exceptions --- managed/GTAVisionExport/VisionExport.cs | 50 +++++++++--------- managed/GTAVisionUtils/ImageUtils.cs | 32 +++++++++--- managed/GTAVisionUtils/Logger.cs | 67 ++++++++++++++++++++++--- 3 files changed, 109 insertions(+), 40 deletions(-) diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 3a4ecb5..95f16e1 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -134,18 +134,18 @@ private void initialize4cameras() { // for cameras mapping area before the car // float r = 8f; //radius of circle with 4 cameras -// CamerasList.setMainCamera(new Vector3()); +// CamerasList.setMainCamera(); // CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f); // CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f); // CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); // CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); // for 4 cameras of different sides of the car -// CamerasList.setMainCamera(new Vector3()); -// CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 0.15f); -// CamerasList.addCamera(new Vector3(-0.6f, 0f, 0.8f), new Vector3(0f, 0f, 90f), 50, 0.15f); -// CamerasList.addCamera(new Vector3(0f, -2f, 0.6f), new Vector3(0f, 0f, 180f), 50, 0.15f); -// CamerasList.addCamera(new Vector3(0.6f, 0f, 0.8f), new Vector3(0f, 0f, 270f), 50, 0.15f); + CamerasList.setMainCamera(); + CamerasList.addCamera(new Vector3(0f, 2f, 0.3f), new Vector3(0f, 0f, 0f), 50, 0.15f); + CamerasList.addCamera(new Vector3(-0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 90f), 50, 0.15f); + CamerasList.addCamera(new Vector3(0f, -2.3f, 0.3f), new Vector3(0f, 0f, 180f), 50, 0.15f); + CamerasList.addCamera(new Vector3(0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 270f), 50, 0.15f); // for 4 cameras on top of car, heading 4 directions // CamerasList.setMainCamera(); @@ -157,25 +157,25 @@ private void initialize4cameras() { // set only main camera for static traffic camera // CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(270f, 0f, 0f), 50, 0.15f); -// two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo -// for cameras mapping area before the car - CamerasList.setMainCamera(); - const float r = 8f; //radius of circle with 4 cameras - // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground - var carCenter = 0.5735f; - var camOne = new Vector3(-0.06f, 0.27f, 1.65f - carCenter); - var camTwo = new Vector3(-0.06f+0.54f, 0.27f, 1.65f - carCenter); - CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); - CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); - CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); - CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); -// 4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras - CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); -// CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); -// CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); -// CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); -// and now, one camera from birds-eye view, with this configuration, it sees all other cameras - CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); +//// two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo +//// for cameras mapping area before the car +// CamerasList.setMainCamera(); +// const float r = 8f; //radius of circle with 4 cameras +// // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground +// var carCenter = 0.5735f; +// var camOne = new Vector3(-0.06f, 0.27f, 1.65f - carCenter); +// var camTwo = new Vector3(-0.06f+0.54f, 0.27f, 1.65f - carCenter); +// CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); +// CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); +// CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); +// CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); +//// 4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras +// CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); +//// CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); +//// CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); +//// CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); +//// and now, one camera from birds-eye view, with this configuration, it sees all other cameras +// CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); } private void HandlePipeInput() { diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index 87a3eaf..5f8f723 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -54,16 +54,32 @@ await Task.Run(() => try { Logger.writeLine("writing to tiff"); - Logger.writeLine("name: " + name); + Logger.writeLine($"name: {name}"); WriteToTiffImpl(name, width, height, colors, depth, stencil, oneFile); } catch (Exception e) { Logger.writeLine(e); - Logger.writeLine("name: " + name); - Logger.writeLine("width: " + width.ToString()); - Logger.writeLine("height: " + height.ToString()); - Logger.writeLine("oneFile: " + oneFile.ToString()); + Logger.writeLine($"name: {name}"); + Logger.writeLine($"width: {width}"); + Logger.writeLine($"height: {height}"); + Logger.writeLine($"oneFile: {oneFile}"); + + if (e is ArgumentException) { +// probably some problem with tiff, logging info avout images + if (colors.Count == 1) { + Logger.writeLine($"color size: {colors[0].Length}"); + } + else { + for (int i = 0; i < colors.Count; i++) { + Logger.writeLine($"{i}-th color size: {colors[i].Length}"); + } + } + Logger.writeLine($"depth size: {depth.Length}"); + Logger.writeLine($"stencil size: {stencil.Length}"); + + } + Logger.ForceFlush(); throw; } }); @@ -149,9 +165,9 @@ public static void WriteToTiffImpl(string name, int width, int height, List LogQueue; public static string logFilePath { private get; set; } + public static int FlushAfterSeconds = 5; + public static int FlushAtQty = 10; + private static DateTime FlushedAt; + private Logger() { } - public static void writeLine(string line) { - var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; - try { - System.IO.File.AppendAllText(logFilePath, - DateTime.UtcNow.ToString(dateTimeFormat) + ": " + line + "\r\n"); + public static void ForceFlush() + { + FlushLogToFile(); + } + + private static bool CheckTimeToFlush() + { + TimeSpan time = DateTime.Now - FlushedAt; + if (time.TotalSeconds >= FlushAfterSeconds) + { + FlushedAt = DateTime.Now; + return true; + } + return false; + } + + private static void FlushLogToFile() + { + while (LogQueue.Count > 0) + { + + // Get entry to log + string entry = LogQueue.Dequeue(); + + // Crete filestream + FileStream stream = new FileStream(logFilePath, FileMode.Append, FileAccess.Write); + using (var writer = new StreamWriter(stream)) + { + // Log to file + writer.WriteLine(entry); + stream.Close(); + } } - catch (System.IO.IOException e) { -// just silently fail, better than throwing + } + + private static string wrapLogMessage(string message) { + var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; + return $"{DateTime.UtcNow.ToString(dateTimeFormat)}: {message}\r\n"; + } + + public static void writeLine(string line) { + lock (LogQueue) + { + + // Create log + LogQueue.Enqueue(wrapLogMessage(line)); + + // Check if should flush + if (LogQueue.Count >= FlushAtQty || CheckTimeToFlush()) + { + FlushLogToFile(); + } + } } From d2433cea939027c437469f5bc0a5e0c0eed5cc81 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 25 Jul 2018 15:13:54 +0200 Subject: [PATCH 138/158] fixed bug in logger initialization --- managed/GTAVisionExport/CameraHandling.cs | 8 +++---- managed/GTAVisionExport/CamerasList.cs | 14 ++++++------ managed/GTAVisionExport/VisionExport.cs | 24 +++++++++---------- managed/GTAVisionUtils/ImageUtils.cs | 22 +++++++++--------- managed/GTAVisionUtils/Logger.cs | 28 +++++++++++------------ 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 389dd20..3d41bb4 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -45,7 +45,7 @@ public void mountCameraOnVehicle() { else { UI.Notify("Mounting camera from list"); UI.Notify("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation); - Logger.writeLine("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation); + Logger.WriteLine("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation); activeCamera = CamerasList.ActivateCamera(activeCameraIndex); } } @@ -75,12 +75,12 @@ public void doRayCasting() { var result = GTA.World.Raycast(Game.Player.Character.Position, Game.Player.Character.Position + (Vector3.RelativeLeft * 100), IntersectOptions.Everything); UI.Notify("raycast result:"); - Logger.writeLine("raycast result:"); + Logger.WriteLine("raycast result:"); UI.Notify(result.DitHitAnything.ToString()); - Logger.writeLine(result.DitHitAnything.ToString()); + Logger.WriteLine(result.DitHitAnything.ToString()); if (result.DitHitAnything) { UI.Notify(result.HitCoords.ToString()); - Logger.writeLine(result.HitCoords.ToString()); + Logger.WriteLine(result.HitCoords.ToString()); GTA.World.DrawMarker(MarkerType.CheckeredFlagCircle, result.HitCoords, Vector3.RelativeRight, Vector3.WorldUp, new Vector3(10, 10, 10), Color.Chartreuse); } } diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index e77a2a7..3ba8c87 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -31,7 +31,7 @@ public static void initialize() { } World.DestroyAllCameras(); - Logger.writeLine("destroying all cameras at the beginning, to be clear"); + Logger.WriteLine("destroying all cameras at the beginning, to be clear"); var parser = new FileIniDataParser(); var data = parser.ReadFile(Path.Combine(VisionExport.location, "GTAVision.ini")); gameplayInterval = Convert.ToInt32(data["MultiCamera"]["GameplayTimeAfterSwitch"]); @@ -47,7 +47,7 @@ public static void initialize() { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } - Logger.writeLine("setting main camera"); + Logger.WriteLine("setting main camera"); if (!fov.HasValue) { fov = GameplayCamera.FieldOfView; } @@ -71,7 +71,7 @@ public static void addCamera(Vector3 position, Vector3 rotation, float? fov = nu throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); } - Logger.writeLine("adding new camera"); + Logger.WriteLine("adding new camera"); if (!fov.HasValue) { fov = GameplayCamera.FieldOfView; } @@ -128,10 +128,10 @@ public static Camera ActivateCamera(int i) { Game.Pause(true); // UI.Notify("new camera rotation is: " + rotation.ToString()); Script.Wait(20); - Logger.writeLine("new camera position is: " + World.RenderingCamera.Position.ToString()); - Logger.writeLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); - Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString()); - Logger.writeLine("new camera rotation offset is: " + camerasRotations[i].ToString()); + Logger.WriteLine("new camera position is: " + World.RenderingCamera.Position.ToString()); + Logger.WriteLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); + Logger.WriteLine("new camera position offset is: " + camerasPositions[i].ToString()); + Logger.WriteLine("new camera rotation offset is: " + camerasRotations[i].ToString()); activeCameraRotation = camerasRotations[i]; activeCameraPosition = camerasPositions[i]; return cameras[i]; diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 95f16e1..54c19a5 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -88,7 +88,7 @@ public VisionExport() { logFilePath = data["Snapshots"]["LogFile"]; Logger.logFilePath = logFilePath; - System.IO.File.WriteAllText(logFilePath, "VisionExport constructor called.\r\n"); + Logger.WriteLine("VisionExport constructor called."); if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath); PostgresExport.InitSQLTypes(); player = Game.Player; @@ -110,7 +110,7 @@ public VisionExport() { runTask = StartRun(); } - Logger.writeLine("Logger prepared"); + Logger.WriteLine("Logger prepared"); UINotify("Logger initialized. Going to initialize cameras."); CamerasList.initialize(); initialize4cameras(); @@ -208,7 +208,7 @@ private void HandlePipeInput() { } UINotify("str: " + str); - Logger.writeLine("obtained json: " + str); + Logger.WriteLine("obtained json: " + str); dynamic parameters = JsonConvert.DeserializeObject(str); string commandName = parameters.name; switch (commandName) { @@ -260,7 +260,7 @@ private void HandlePipeInput() { GTA.World.Weather = weatherEnum; } catch (Exception e) { - Logger.writeLine(e); + Logger.WriteLine(e); } break; @@ -325,7 +325,7 @@ public void OnTick(object o, EventArgs e) { switch (checkStatus()) { case GameStatus.NeedReload: //TODO: need to get a new session and run? - Logger.writeLine("Status is NeedReload"); + Logger.WriteLine("Status is NeedReload"); StopRun(); runTask?.Wait(); runTask = StartRun(); @@ -337,7 +337,7 @@ public void OnTick(object o, EventArgs e) { break; case GameStatus.NeedStart: //TODO do the autostart manually or automatically? - Logger.writeLine("Status is NeedStart"); + Logger.WriteLine("Status is NeedStart"); //Autostart(); // use reloading temporarily StopRun(); @@ -366,8 +366,8 @@ public void OnTick(object o, EventArgs e) { } catch (Exception exception) { GamePause(false); - Logger.writeLine("exception occured, logging and continuing"); - Logger.writeLine(exception); + 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 @@ -388,11 +388,11 @@ private void gatherData(int delay = 5) { var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff"; var guid = Guid.NewGuid(); - Logger.writeLine("generated scene guid: " + guid.ToString()); + Logger.WriteLine("generated scene guid: " + guid.ToString()); if (useMultipleCameras) { for (var i = 0; i < CamerasList.cameras.Count; i++) { - Logger.writeLine("activating camera " + i.ToString()); + Logger.WriteLine("activating camera " + i.ToString()); CamerasList.ActivateCamera(i); gatherDatForOneCamera(dateTimeFormat, guid); Wait(delay); @@ -660,7 +660,7 @@ public void TraverseWeather() { } public void OnKeyDown(object o, KeyEventArgs k) { - Logger.writeLine("VisionExport OnKeyDown called."); + Logger.WriteLine("VisionExport OnKeyDown called."); if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); postgresTask = StartSession(); @@ -802,7 +802,7 @@ public void OnKeyDown(object o, KeyEventArgs k) { Game.Pause(true); for (int i = 0; i < CamerasList.cameras.Count; i++) { - Logger.writeLine("activating camera " + i.ToString()); + Logger.WriteLine("activating camera " + i.ToString()); CamerasList.ActivateCamera(i); Script.Wait(1000); } diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index 5f8f723..3e05ae5 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -53,30 +53,30 @@ await Task.Run(() => { try { - Logger.writeLine("writing to tiff"); - Logger.writeLine($"name: {name}"); + Logger.WriteLine("writing to tiff"); + Logger.WriteLine($"name: {name}"); WriteToTiffImpl(name, width, height, colors, depth, stencil, oneFile); } catch (Exception e) { - Logger.writeLine(e); - Logger.writeLine($"name: {name}"); - Logger.writeLine($"width: {width}"); - Logger.writeLine($"height: {height}"); - Logger.writeLine($"oneFile: {oneFile}"); + Logger.WriteLine(e); + Logger.WriteLine($"name: {name}"); + Logger.WriteLine($"width: {width}"); + Logger.WriteLine($"height: {height}"); + Logger.WriteLine($"oneFile: {oneFile}"); if (e is ArgumentException) { // probably some problem with tiff, logging info avout images if (colors.Count == 1) { - Logger.writeLine($"color size: {colors[0].Length}"); + Logger.WriteLine($"color size: {colors[0].Length}"); } else { for (int i = 0; i < colors.Count; i++) { - Logger.writeLine($"{i}-th color size: {colors[i].Length}"); + Logger.WriteLine($"{i}-th color size: {colors[i].Length}"); } } - Logger.writeLine($"depth size: {depth.Length}"); - Logger.writeLine($"stencil size: {stencil.Length}"); + Logger.WriteLine($"depth size: {depth.Length}"); + Logger.WriteLine($"stencil size: {stencil.Length}"); } Logger.ForceFlush(); diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs index f58b70e..00dbeb8 100644 --- a/managed/GTAVisionUtils/Logger.cs +++ b/managed/GTAVisionUtils/Logger.cs @@ -12,11 +12,11 @@ namespace GTAVisionUtils { public class Logger { //most code taken from https://github.com/dbaaron/log-writer - private static Queue LogQueue; + private static Queue LogQueue = new Queue(); public static string logFilePath { private get; set; } public static int FlushAfterSeconds = 5; public static int FlushAtQty = 10; - private static DateTime FlushedAt; + private static DateTime FlushedAt = DateTime.Now; private Logger() { } public static void ForceFlush() @@ -26,7 +26,7 @@ public static void ForceFlush() private static bool CheckTimeToFlush() { - TimeSpan time = DateTime.Now - FlushedAt; + var time = DateTime.Now - FlushedAt; if (time.TotalSeconds >= FlushAfterSeconds) { FlushedAt = DateTime.Now; @@ -54,17 +54,17 @@ private static void FlushLogToFile() } } - private static string wrapLogMessage(string message) { - var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; - return $"{DateTime.UtcNow.ToString(dateTimeFormat)}: {message}\r\n"; + private static string WrapLogMessage(string message) { + const string dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss"; + return $"{DateTime.UtcNow.ToString(dateTimeFormat)}: {message}\r\n"; } - public static void writeLine(string line) { + public static void WriteLine(string line) { lock (LogQueue) { // Create log - LogQueue.Enqueue(wrapLogMessage(line)); + LogQueue.Enqueue(WrapLogMessage(line)); // Check if should flush if (LogQueue.Count >= FlushAtQty || CheckTimeToFlush()) @@ -75,18 +75,18 @@ public static void writeLine(string line) { } } - public static void writeLine(Exception e) { - writeLine(e.Message); - writeLine(e.Source); - writeLine(e.StackTrace); + public static void WriteLine(Exception e) { + WriteLine(e.Message); + WriteLine(e.Source); + WriteLine(e.StackTrace); } - public static void writeLine(object value) { + public static void WriteLine(object value) { if (value == null) { return; } - writeLine(value.ToString()); + WriteLine(value.ToString()); } } } \ No newline at end of file From c8c6c406315139b21a38fb7de412bf3af498c87d Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 25 Jul 2018 15:20:52 +0200 Subject: [PATCH 139/158] fixed another bug in logger initialization --- managed/GTAVisionUtils/Logger.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs index 00dbeb8..b3089a2 100644 --- a/managed/GTAVisionUtils/Logger.cs +++ b/managed/GTAVisionUtils/Logger.cs @@ -41,15 +41,14 @@ private static void FlushLogToFile() { // Get entry to log - string entry = LogQueue.Dequeue(); + var entry = LogQueue.Dequeue(); // Crete filestream - FileStream stream = new FileStream(logFilePath, FileMode.Append, FileAccess.Write); + var stream = new FileStream(logFilePath, FileMode.Append, FileAccess.Write); using (var writer = new StreamWriter(stream)) { // Log to file writer.WriteLine(entry); - stream.Close(); } } } From 8b23ea2a3797627bda536563c675d04b4362066f Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 26 Jul 2018 14:47:11 +0200 Subject: [PATCH 140/158] fixed fucking cameras visualization --- managed/GTAVisionExport/CameraHandling.cs | 14 +++++++++----- managed/GTAVisionExport/CamerasList.cs | 23 +++++++++++++++++++---- managed/GTAVisionUtils/Logger.cs | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 3d41bb4..6c08065 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -39,9 +39,13 @@ public void mountCameraOnVehicle() { UI.Notify("Mounting camera to the vehicle."); if (Game.Player.Character.IsInVehicle()) { if (activeCameraIndex == -1) { - UI.Notify("Mounting main camera"); + UI.Notify("Mounting free camera"); CamerasList.ActivateMainCamera(); } + else if (activeCameraIndex == -2) { + UI.Notify("Mounting free camera"); + CamerasList.ActivateGameplayCamera(); + } else { UI.Notify("Mounting camera from list"); UI.Notify("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation); @@ -72,7 +76,7 @@ public void keepCameraOnVehicle() { } public void doRayCasting() { - var result = GTA.World.Raycast(Game.Player.Character.Position, + var result = World.Raycast(Game.Player.Character.Position, Game.Player.Character.Position + (Vector3.RelativeLeft * 100), IntersectOptions.Everything); UI.Notify("raycast result:"); Logger.WriteLine("raycast result:"); @@ -81,7 +85,7 @@ public void doRayCasting() { if (result.DitHitAnything) { UI.Notify(result.HitCoords.ToString()); Logger.WriteLine(result.HitCoords.ToString()); - GTA.World.DrawMarker(MarkerType.CheckeredFlagCircle, result.HitCoords, Vector3.RelativeRight, Vector3.WorldUp, new Vector3(10, 10, 10), Color.Chartreuse); + World.DrawMarker(MarkerType.CheckeredFlagCircle, result.HitCoords, Vector3.RelativeRight, Vector3.WorldUp, new Vector3(10, 10, 10), Color.Chartreuse); } } @@ -136,7 +140,7 @@ private void onKeyUp(object sender, KeyEventArgs e) { break; case Keys.Decimal: UI.Notify("Pressed numpad ,"); - activeCameraIndex = -1; + activeCameraIndex = -2; mountCameraOnVehicle(); break; } @@ -169,7 +173,7 @@ public void drawCamerasBoxes() { var rotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(rot.X)); var rotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(rot.Y)); var rotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(rot.Z)); - var rotMat = rotX * rotY * rotZ; + var rotMat = rotZ * rotY * rotX; var camPosToCar = rotMat * new Vector3D(camPos.X, camPos.Y, camPos.Z); var absolutePosition = curVehicle.Position + new Vector3((float) camPosToCar[0], (float) camPosToCar[1], (float) camPosToCar[2]); HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f)); diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index 3ba8c87..a3adf5d 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -101,6 +101,21 @@ public static void ActivateMainCamera() { activeCameraPosition = mainCameraPosition; } + public static void ActivateGameplayCamera() { + if (!initialized) { + throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); + } + + if (mainCamera == null) { + throw new Exception("please, set main camera"); + } + + mainCamera.IsActive = false; + World.RenderingCamera = null; + activeCameraRotation = GameplayCamera.Rotation; + activeCameraPosition = GameplayCamera.Position; + } + public static Camera ActivateCamera(int i) { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); @@ -128,10 +143,10 @@ public static Camera ActivateCamera(int i) { Game.Pause(true); // UI.Notify("new camera rotation is: " + rotation.ToString()); Script.Wait(20); - Logger.WriteLine("new camera position is: " + World.RenderingCamera.Position.ToString()); - Logger.WriteLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString()); - Logger.WriteLine("new camera position offset is: " + camerasPositions[i].ToString()); - Logger.WriteLine("new camera rotation offset is: " + camerasRotations[i].ToString()); + Logger.WriteLine("new camera position is: " + World.RenderingCamera.Position); + Logger.WriteLine("new camera rotation is: " + World.RenderingCamera.Rotation); + Logger.WriteLine("new camera position offset is: " + camerasPositions[i]); + Logger.WriteLine("new camera rotation offset is: " + camerasRotations[i]); activeCameraRotation = camerasRotations[i]; activeCameraPosition = camerasPositions[i]; return cameras[i]; diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs index b3089a2..bf7caca 100644 --- a/managed/GTAVisionUtils/Logger.cs +++ b/managed/GTAVisionUtils/Logger.cs @@ -48,7 +48,7 @@ private static void FlushLogToFile() using (var writer = new StreamWriter(stream)) { // Log to file - writer.WriteLine(entry); + writer.Write(entry); } } } From af0f266e23d6b50e1ec256d115c8386dc78409e1 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 26 Jul 2018 17:22:30 +0200 Subject: [PATCH 141/158] finally fucking working rotation of cameras relatively to the car --- managed/GTAVisionExport/CameraHandling.cs | 44 ++++++++++++++++------- managed/GTAVisionExport/CamerasList.cs | 39 +++++++++++++++++++- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 6c08065..cb3bf92 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -8,6 +8,8 @@ using GTA.Math; using GTA.NaturalMotion; using GTAVisionUtils; +using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Spatial.Euclidean; using MathNet.Spatial.Units; @@ -156,28 +158,44 @@ public void OnTick(object sender, EventArgs e) { public void drawCamerasBoxes() { // this shows white boxes where cameras are - foreach (var camPos in CamerasList.camerasPositions) { + for (var i = 0; i < CamerasList.cameras.Count; i++) { + var camPos = CamerasList.camerasPositions[i]; + var camRot = CamerasList.camerasRotations[i]; var curVehicle = Game.Player.Character.CurrentVehicle; -// Logger.writeLine("rotation"); -// Logger.writeLine(curVehicle.Rotation); -// Logger.writeLine("forward vector"); -// Logger.writeLine(curVehicle.ForwardVector); -// Logger.writeLine("right vector"); -// Logger.writeLine(curVehicle.RightVector); -// Logger.writeLine("up vector"); -// Logger.writeLine(curVehicle.UpVector); -// var camPosToCar = Vector3.Modulate(curVehicle.ForwardVector, cameraPosition); -// camPosToCar += Vector3.Modulate(curVehicle.RightVector, cameraPosition); -// camPosToCar += Vector3.Modulate(curVehicle.UpVector, cameraPosition); + var rot = curVehicle.Rotation; var rotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(rot.X)); var rotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(rot.Y)); var rotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(rot.Z)); var rotMat = rotZ * rotY * rotX; + + var relRotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(camRot.X)); + var relRotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(camRot.Y)); + var relRotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(camRot.Z)); + var relRotMat = relRotZ * relRotY * relRotX; + var camPosToCar = rotMat * new Vector3D(camPos.X, camPos.Y, camPos.Z); +// var camDirection = new Vector3D(rotMat * relRotMat * new Vector3D(0f, 0f, -1f)); +// var camDirection = new Vector3D(relRotMat * new Vector3D(0f, 0f, -1f)); +// var camDirection = new Vector3D(0f, 0f, -1f); + var camDirection = new Vector3D(0, 0, 0); +// var camRotation = new Vector3D(0, 0, 0); + var camRotation = CamerasList.rotationMatrixToDegrees(rotMat * relRotMat); +// var camRotation = CamerasList.rotationMatrixToDegrees(relRotMat * rotMat); +// var camRotation = rotationMatrixToDegrees(Matrix3D.RotationAroundXAxis(Angle.FromDegrees(-90)) * rotMat * relRotMat); +// var camRotation = rotationMatrixToDegrees(Matrix3D.RotationAroundXAxis(Angle.FromDegrees(-90))); var absolutePosition = curVehicle.Position + new Vector3((float) camPosToCar[0], (float) camPosToCar[1], (float) camPosToCar[2]); - HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f)); +// HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f)); +// Logger.WriteLine($"{i}-th cam vector rotation"); +// Logger.WriteLine(camRotation); + + World.DrawMarker(MarkerType.HorizontalCircleSkinny_Arrow, absolutePosition, + new Vector3((float) camDirection.X, (float) camDirection.Y, (float) camDirection.Z), + new Vector3((float) camRotation.X, (float) camRotation.Y, (float) camRotation.Z), + new Vector3(1, 1, 1), Color.White); } +// Logger.WriteLine("car vector rotation"); +// Logger.WriteLine(Game.Player.Character.CurrentVehicle.Rotation); } void drawAxesBoxesAround(Vector3 position) { diff --git a/managed/GTAVisionExport/CamerasList.cs b/managed/GTAVisionExport/CamerasList.cs index a3adf5d..5044b53 100644 --- a/managed/GTAVisionExport/CamerasList.cs +++ b/managed/GTAVisionExport/CamerasList.cs @@ -6,6 +6,9 @@ using GTA.Native; using GTAVisionUtils; using IniParser; +using MathNet.Numerics.LinearAlgebra; +using MathNet.Spatial.Euclidean; +using MathNet.Spatial.Units; namespace GTAVisionExport { public static class CamerasList { @@ -116,6 +119,27 @@ public static void ActivateGameplayCamera() { activeCameraPosition = GameplayCamera.Position; } + public static Vector3 rotationMatrixToDegrees(Matrix r) { + var sy = Math.Sqrt(r[0, 0] * r[0, 0] + r[1, 0] * r[1, 0]); + + var singular = sy < 1e-6; + + var x = 0d; + var y = 0d; + var z = 0d; + if (!singular) { + x = Math.Atan2(r[2, 1], r[2, 2]); + y = Math.Atan2(-r[2, 0], sy); + z = Math.Atan2(r[1, 0], r[0, 0]); + } else { + x = Math.Atan2(-r[1, 2], r[1, 1]); + y = Math.Atan2(-r[2, 0], sy); + z = 0; + } + + return new Vector3((float) Angle.FromRadians(x).Degrees, (float) Angle.FromRadians(y).Degrees, (float) Angle.FromRadians(z).Degrees); + } + public static Camera ActivateCamera(int i) { if (!initialized) { throw new Exception("not initialized, please, call CamerasList.initialize() method before this one"); @@ -129,7 +153,20 @@ public static Camera ActivateCamera(int i) { cameras[i].IsActive = true; World.RenderingCamera = cameras[i]; cameras[i].AttachTo(Game.Player.Character.CurrentVehicle, camerasPositions[i]); - cameras[i].Rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; +// if we want to rotate camera relatively to the car, we must do through rotation matrix multiplication, not addition +// cameras[i].Rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i]; // this row is wrong + var rot = Game.Player.Character.CurrentVehicle.Rotation; + var rotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(rot.X)); + var rotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(rot.Y)); + var rotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(rot.Z)); + var rotMat = rotZ * rotY * rotX; + var relRotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(camerasRotations[i].X)); + var relRotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(camerasRotations[i].Y)); + var relRotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(camerasRotations[i].Z)); + var relRotMat = relRotZ * relRotY * relRotX; + +// cameras[i].Rotation = rotationMatrixToDegrees(relRotMat * rotMat); + cameras[i].Rotation = rotationMatrixToDegrees(rotMat * relRotMat); // WARNING: CAMERAS SETTING DO NOT WORK WHEN GAME IS PAUSED, SO WE NEED TO UNPAUSE THE GAME, SET THINGS UP, AND THEN PAUSE GAME AGAIN // Script.Wait(1); // //with time 1, sometimes depth does not correspond, and bounding boxes dont correspond by 1 frames From c398c6f035f2ab16b91bba92dcd15b287756cf67 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 26 Jul 2018 17:34:02 +0200 Subject: [PATCH 142/158] slight refactoring, added more starting positions --- managed/GTAVisionExport/GameUtils.cs | 3 +- managed/GTAVisionExport/VisionExport.cs | 268 ++++++++++++------------ 2 files changed, 132 insertions(+), 139 deletions(-) diff --git a/managed/GTAVisionExport/GameUtils.cs b/managed/GTAVisionExport/GameUtils.cs index 86466ba..3ffe7cf 100644 --- a/managed/GTAVisionExport/GameUtils.cs +++ b/managed/GTAVisionExport/GameUtils.cs @@ -59,6 +59,7 @@ public enum GameStatus public class GTAConst { - public static Vector3 StartPos = new Vector3(311.7819f, -1372.574f, 31.84874f); + public static Vector3 OriginalStartPos = new Vector3(311.7819f, -1372.574f, 31.84874f); + public static Vector3 HighwayStartPos = new Vector3(1209.5412f,-1936.0394f,38.3709f); } } diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 54c19a5..d726f33 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -579,7 +579,7 @@ public void EnterVehicle() { UINotify("player.Character is null"); } - UINotify("player position: " + player.Character.Position.ToString()); + UINotify("player position: " + player.Character.Position); var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); if (vehicle == null) { UINotify("vehicle is null. Something is fucked up"); @@ -640,7 +640,8 @@ public void ReloadGame() { ClearSurroundingVehicles(player.Position, 1000f); player.LastVehicle.Delete(); // teleport to the spawning position, defined in GameUtils.cs, subject to changes - player.Position = GTAConst.StartPos; +// player.Position = GTAConst.OriginalStartPos; + player.Position = GTAConst.HighwayStartPos; // ClearSurroundingVehicles(player.Position, 100f); ClearSurroundingVehicles(player.Position, 50f); // start a new run @@ -661,62 +662,58 @@ public void TraverseWeather() { public void OnKeyDown(object o, KeyEventArgs k) { Logger.WriteLine("VisionExport OnKeyDown called."); - if (k.KeyCode == Keys.PageUp) { - postgresTask?.Wait(); - postgresTask = StartSession(); - runTask?.Wait(); - runTask = StartRun(); - UINotify("GTA Vision Enabled"); + 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; - } - - if (k.KeyCode == Keys.PageDown) { - if (staticCamera) { - CamerasList.Deactivate(); - } - StopRun(); - StopSession(); - UINotify("GTA Vision Disabled"); - } - - if (k.KeyCode == Keys.H) // temp modification - { - EnterVehicle(); - UINotify("Trying to enter vehicle"); - ToggleNavigation(); - } - - if (k.KeyCode == Keys.Y) // temp modification - { - ReloadGame(); - } - - if (k.KeyCode == Keys.X) // temp modification - { - notificationsAllowed = !notificationsAllowed; - if (notificationsAllowed) { - UI.Notify("Notifications Enabled"); - } - else { - UI.Notify("Notifications Disabled"); - } - } - - if (k.KeyCode == Keys.U) // temp modification - { - 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); - } + 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"); + } - if (k.KeyCode == Keys.G) // temp modification - { - /* + 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); @@ -725,95 +722,90 @@ public void OnKeyDown(object o, KeyEventArgs k) { 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.ToString() + ' ' + - World.RenderingCamera.Direction.Y.ToString() + ' ' + - World.RenderingCamera.Direction.Z.ToString()); - file.WriteLine("Dot Product:"); - file.WriteLine(Vector3.Dot(World.RenderingCamera.Direction, World.RenderingCamera.Rotation)); - file.WriteLine("position:"); - file.WriteLine(World.RenderingCamera.Position.X.ToString() + ' ' + - World.RenderingCamera.Position.Y.ToString() + ' ' + - World.RenderingCamera.Position.Z.ToString()); - file.WriteLine("rotation:"); - file.WriteLine(World.RenderingCamera.Rotation.X.ToString() + ' ' + - World.RenderingCamera.Rotation.Y.ToString() + ' ' + - World.RenderingCamera.Rotation.Z.ToString()); - 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()); + 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); } - } - } - - if (k.KeyCode == Keys.T) // temp modification - { - World.Weather = Weather.Raining; - /* set it between 0 = stop, 1 = heavy rain. set it too high will lead to sloppy ground */ - Function.Call(GTA.Native.Hash._SET_RAIN_FX_INTENSITY, 0.5f); - var test = Function.Call(GTA.Native.Hash.GET_RAIN_LEVEL); - UINotify("" + test); - World.CurrentDayTime = new TimeSpan(12, 0, 0); - //Script.Wait(5000); - } - if (k.KeyCode == Keys.N) { - UINotify("N pressed, going to take screenshots"); + 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()); + } + } - 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 - } + 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(GTA.Native.Hash._SET_RAIN_FX_INTENSITY, 0.5f); + var test = Function.Call(GTA.Native.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"); - if (staticCamera) { - CamerasList.Deactivate(); - } + 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 + } - StopRun(); - StopSession(); - } + if (staticCamera) { + CamerasList.Deactivate(); + } - if (k.KeyCode == Keys.OemMinus) { //to tlačítko vlevo od pravého shiftu, - - UINotify("- pressed, going to rotate cameras"); + 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.ToString()); - CamerasList.ActivateCamera(i); - Script.Wait(1000); - } - CamerasList.Deactivate(); - Game.Pause(false); - } - - if (k.KeyCode == Keys.I) { - var info = new GTAVisionUtils.InstanceData(); - UINotify(info.type); - UINotify(info.publichostname); + Game.Pause(true); + for (int i = 0; i < CamerasList.cameras.Count; i++) { + Logger.WriteLine("activating camera " + i.ToString()); + 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; } } From b7478e1a3585a1432dadb64cad358358e0df8279 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 27 Jul 2018 20:56:45 +0200 Subject: [PATCH 143/158] added some utilities for offroad preparation --- managed/GTAVisionExport/CameraHandling.cs | 116 +++++++++++------- .../GTAVisionExport/GTAVisionExport.csproj | 1 + managed/GTAVisionExport/OffroadPlanning.cs | 72 +++++++++++ managed/GTAVisionExport/VisionExport.cs | 2 +- managed/GTAVisionUtils/HashFunctions.cs | 8 ++ 5 files changed, 157 insertions(+), 42 deletions(-) create mode 100644 managed/GTAVisionExport/OffroadPlanning.cs diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index cb3bf92..3e45558 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -24,6 +24,7 @@ public class CameraHandling : Script { private bool enabled = false; private int activeCameraIndex = -1; private bool showCameras = false; + private bool showPosition = false; public CameraHandling() { UI.Notify("Loaded CameraHandling.cs"); @@ -118,28 +119,37 @@ private void onKeyUp(object sender, KeyEventArgs e) { else { UI.Notify("disabled cameras showing"); } - - break; - case Keys.NumPad0: - UI.Notify("Pressed numpad 0"); - activeCameraIndex = 0; - mountCameraOnVehicle(); - break; - case Keys.NumPad1: - UI.Notify("Pressed numpad 1"); - activeCameraIndex = 1; - mountCameraOnVehicle(); - break; - case Keys.NumPad2: - UI.Notify("Pressed numpad 2"); - activeCameraIndex = 2; - mountCameraOnVehicle(); break; - case Keys.NumPad3: - UI.Notify("Pressed numpad 3"); - activeCameraIndex = 3; - mountCameraOnVehicle(); + case Keys.Multiply: + UI.Notify("Pressed numpad *"); + showPosition = !showPosition; + if (showPosition) { + UI.Notify("enabled position showing"); + } + else { + UI.Notify("disabled position showing"); + } break; +// case Keys.NumPad0: +// UI.Notify("Pressed numpad 0"); +// activeCameraIndex = 0; +// mountCameraOnVehicle(); +// break; +// case Keys.NumPad1: +// UI.Notify("Pressed numpad 1"); +// activeCameraIndex = 1; +// mountCameraOnVehicle(); +// break; +// case Keys.NumPad2: +// UI.Notify("Pressed numpad 2"); +// activeCameraIndex = 2; +// mountCameraOnVehicle(); +// break; +// case Keys.NumPad3: +// UI.Notify("Pressed numpad 3"); +// activeCameraIndex = 3; +// mountCameraOnVehicle(); +// break; case Keys.Decimal: UI.Notify("Pressed numpad ,"); activeCameraIndex = -2; @@ -153,47 +163,71 @@ public void OnTick(object sender, EventArgs e) { if (showCameras) { drawCamerasBoxes(); } + if (showPosition) { + drawPosition(); + } // drawAxesBoxesAround(new Vector3(-1078f, -216f, 200f)); } + public void drawPosition() { + var pos = Game.Player.Character.Position; + HashFunctions.Draw2DText($"X:{ pos.X:.##} Y:{pos.Y:.##} Z:{pos.Z:.##}", pos, Color.Red); + } + public void drawCamerasBoxes() { +// WARNING, do not attempt to draw cameras as markes in their correct rotation. It does not work. +// I spent lots of time trying to show cameras in their direction, but shit just doesn't work. +// 3D boxes are enough I guess + // this shows white boxes where cameras are + var curVehicle = Game.Player.Character.CurrentVehicle; + var rot = curVehicle.Rotation; + var rotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(rot.X)); + var rotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(rot.Y)); + var rotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(rot.Z)); + var rotMat = rotZ * rotY * rotX; + for (var i = 0; i < CamerasList.cameras.Count; i++) { var camPos = CamerasList.camerasPositions[i]; - var camRot = CamerasList.camerasRotations[i]; - var curVehicle = Game.Player.Character.CurrentVehicle; +// var camRot = CamerasList.camerasRotations[i]; - var rot = curVehicle.Rotation; - var rotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(rot.X)); - var rotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(rot.Y)); - var rotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(rot.Z)); - var rotMat = rotZ * rotY * rotX; - - var relRotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(camRot.X)); - var relRotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(camRot.Y)); - var relRotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(camRot.Z)); - var relRotMat = relRotZ * relRotY * relRotX; +// var relRotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(camRot.X)); +// var relRotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(camRot.Y)); +// var relRotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(camRot.Z)); +// var relRotMat = relRotZ * relRotY * relRotX; +// var relRotMat = relRotX * relRotY * relRotZ; var camPosToCar = rotMat * new Vector3D(camPos.X, camPos.Y, camPos.Z); // var camDirection = new Vector3D(rotMat * relRotMat * new Vector3D(0f, 0f, -1f)); // var camDirection = new Vector3D(relRotMat * new Vector3D(0f, 0f, -1f)); // var camDirection = new Vector3D(0f, 0f, -1f); - var camDirection = new Vector3D(0, 0, 0); +// var camDirection = new Vector3D(0, 0, 0); // var camRotation = new Vector3D(0, 0, 0); - var camRotation = CamerasList.rotationMatrixToDegrees(rotMat * relRotMat); +// var camRotation = CamerasList.rotationMatrixToDegrees(rotMat * relRotMat); +// var camRotation = Game.Player.Character.CurrentVehicle.Rotation; +// camRotation.X *= -1; +// camRotation.Y = - Game.Player.Character.CurrentVehicle.Rotation.X; +// camRotation.X = Game.Player.Character.CurrentVehicle.Rotation.Y; // var camRotation = CamerasList.rotationMatrixToDegrees(relRotMat * rotMat); -// var camRotation = rotationMatrixToDegrees(Matrix3D.RotationAroundXAxis(Angle.FromDegrees(-90)) * rotMat * relRotMat); -// var camRotation = rotationMatrixToDegrees(Matrix3D.RotationAroundXAxis(Angle.FromDegrees(-90))); +// var camRotation = CamerasList.rotationMatrixToDegrees(Matrix3D.RotationAroundZAxis(Angle.FromDegrees(90)) * rotMat); +// var camRotation = new Vector3D(Matrix3D.RotationAroundZAxis(Angle.FromDegrees(90)) * +// new Vector3D(rot.X, rot.Y, rot.Z)); +// var camRotation = CamerasList.rotationMatrixToDegrees(Matrix3D.RotationAroundXAxis(Angle.FromDegrees(-90))); var absolutePosition = curVehicle.Position + new Vector3((float) camPosToCar[0], (float) camPosToCar[1], (float) camPosToCar[2]); -// HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f)); + HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f)); // Logger.WriteLine($"{i}-th cam vector rotation"); // Logger.WriteLine(camRotation); +// Logger.WriteLine($"{i}-th cam rotation matrix"); +// Logger.WriteLine(relRotMat * rotMat); - World.DrawMarker(MarkerType.HorizontalCircleSkinny_Arrow, absolutePosition, - new Vector3((float) camDirection.X, (float) camDirection.Y, (float) camDirection.Z), - new Vector3((float) camRotation.X, (float) camRotation.Y, (float) camRotation.Z), - new Vector3(1, 1, 1), Color.White); +// World.DrawMarker(MarkerType.ChevronUpx1, absolutePosition, +// new Vector3((float) camDirection.X, (float) camDirection.Y, (float) camDirection.Z), +// new Vector3((float) camRotation.X, (float) camRotation.Y, (float) camRotation.Z), +// new Vector3(1, 1, 1), Color.White); +// +// HashFunctions.Draw2DText($"X:{camRotation.X:.##} Y:{camRotation.Y:.##} Z:{camRotation.Z:.##}", absolutePosition, Color.Red); } + HashFunctions.Draw2DText($"X:{rot.X:.##} Y:{rot.Y:.##} Z:{rot.Z:.##}", curVehicle.Position, Color.Red); // Logger.WriteLine("car vector rotation"); // Logger.WriteLine(Game.Player.Character.CurrentVehicle.Rotation); } diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index c8d044b..a438602 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -143,6 +143,7 @@ + diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs new file mode 100644 index 0000000..8f19dcc --- /dev/null +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Forms; +using GTA; +using GTA.Math; +using GTA.Native; +using GTAVisionUtils; + +namespace GTAVisionExport { + public class OffroadPlanning : Script { +// constant for tried and sufficient offroad model + public static VehicleHash OffroadModel = VehicleHash.Contender; + private bool showOffroadAreas = false; + + public List> areas; + + public OffroadPlanning() { + UI.Notify("Loaded OffroadPlanning.cs"); + + // attach time methods + Tick += OnTick; + KeyUp += OnKeyUp; + areas = new List>(); + createOffroadAreas(); + } + + private void createOffroadAreas() { + var area1 = new List(); + area1.Add(new Rect(1400, -2650, 800, 1750)); + var area2 = new List(); + area2.Add(new Rect(1624, -418, 770, 1410)); + areas.Add(area1); + areas.Add(area2); + } + // Test vehicle controls + private void OnKeyUp(object sender, KeyEventArgs e) { + switch (e.KeyCode) { + case Keys.Subtract: + UI.Notify("Pressed numpad -"); + showOffroadAreas = !showOffroadAreas; + if (showOffroadAreas) { + UI.Notify("enabled offroad areas showing"); + } + else { + UI.Notify("disabled offroad areas showing"); + } + + break; + } + } + + public void OnTick(object sender, EventArgs e) { + if (showOffroadAreas) { + DrawOffroadAreas(); + } +// drawAxesBoxesAround(new Vector3(-1078f, -216f, 200f)); + } + + public void DrawOffroadAreas() { + foreach (var area in areas) { + foreach (var rect in area) { + HashFunctions.Draw3DBox( + new Vector3((float) (rect.X + rect.Width/2), (float) (rect.Y + rect.Height/2), 0), + new Vector3((float) rect.Width, (float) rect.Height, 400), + 255, 255, 255, 50); + } + } + } + + } +} diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index d726f33..32c8351 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -566,7 +566,7 @@ public void EnterVehicle() { var vehicle = World.GetClosestVehicle(player.Character.Position, 30f); player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); */ - var mod = new Model(GTA.Native.VehicleHash.Asea); + var mod = new Model(VehicleHash.Asea); if (mod == null) { UINotify("mod is null"); } diff --git a/managed/GTAVisionUtils/HashFunctions.cs b/managed/GTAVisionUtils/HashFunctions.cs index a880b54..6468db2 100644 --- a/managed/GTAVisionUtils/HashFunctions.cs +++ b/managed/GTAVisionUtils/HashFunctions.cs @@ -82,6 +82,14 @@ public static void DrawRect(float x, float y, float w, float h, Color color, byt DrawRect(x, y, w, h, color.R, color.G, color.B, a); } + public static void Draw2DText(string text, Vector2 pos, Color color) { + Draw2DText(text, pos.X, pos.Y, color.R, color.G, color.B, color.A); + } + + public static void Draw2DText(string text, Vector3 pos, Color color) { + Draw2DText(text, Convert3dTo2d(pos), color); + } + public static void Draw2DText(string text, float x, float y, Color color) { Draw2DText(text, x, y, color.R, color.G, color.B, color.A); } From ea3c2edf41b6ed47b7502f1a2ed99e0436baa366 Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 30 Jul 2018 18:28:08 +0200 Subject: [PATCH 144/158] added more offroad areas --- managed/GTAVisionExport/OffroadPlanning.cs | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index 8f19dcc..fa31e0e 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -30,8 +30,33 @@ private void createOffroadAreas() { area1.Add(new Rect(1400, -2650, 800, 1750)); var area2 = new List(); area2.Add(new Rect(1624, -418, 770, 1410)); + area2.Add(new Rect(1750, 992, 300, 410)); + var area3 = new List(); + area3.Add(new Rect(2180, 1300, 300, 1410)); + area3.Add(new Rect(1980, 1700, 200, 770)); + area3.Add(new Rect(2060, 1500, 120, 200)); + area3.Add(new Rect(2060, 2470, 120, 100)); + var area4 = new List(); + area4.Add(new Rect(2620, 1800, 350, 780)); + area4.Add(new Rect(2970, 2180, 250, 400)); + area4.Add(new Rect(2600, 2580, 750, 450)); + area4.Add(new Rect(3350, 2850, 220, 300)); + var area5 = new List(); + area5.Add(new Rect(150, 1400, 1500, 980)); + area5.Add(new Rect(150, 2380, 1300, 220)); + var area6 = new List(); + area6.Add(new Rect(300, 2720, 1200, 700)); + area6.Add(new Rect(1500, 2950, 230, 470)); + var area7 = new List(); +// todo: dodělat + area7.Add(new Rect(2300, 3100, 300, 500)); areas.Add(area1); areas.Add(area2); + areas.Add(area3); + areas.Add(area4); + areas.Add(area5); + areas.Add(area6); + areas.Add(area7); } // Test vehicle controls private void OnKeyUp(object sender, KeyEventArgs e) { From 0b7e01fca7c602668c0bd7ba710b1a32b92a2c44 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 31 Jul 2018 14:01:45 +0200 Subject: [PATCH 145/158] 8 offroad areas, for some time that should suffice --- managed/GTAVisionExport/OffroadPlanning.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index fa31e0e..52bd3b3 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -44,12 +44,22 @@ private void createOffroadAreas() { var area5 = new List(); area5.Add(new Rect(150, 1400, 1500, 980)); area5.Add(new Rect(150, 2380, 1300, 220)); + area5.Add(new Rect(-540, 2120, 690, 500)); var area6 = new List(); area6.Add(new Rect(300, 2720, 1200, 700)); area6.Add(new Rect(1500, 2950, 230, 470)); var area7 = new List(); -// todo: dodělat - area7.Add(new Rect(2300, 3100, 300, 500)); + area7.Add(new Rect(2300, 3100, 300, 700)); + var area8 = new List(); + area8.Add(new Rect(-570, 4700, 410, 950)); + area8.Add(new Rect(-820, 4700, 250, 740)); + area8.Add(new Rect(-690, 5440, 120, 80)); + area8.Add(new Rect(-1100, 4700, 280, 600)); + area8.Add(new Rect(-1270, 4700, 170, 520)); + area8.Add(new Rect(-1470, 4700, 200, 300)); + area8.Add(new Rect(-1600, 4700, 130, 170)); + area8.Add(new Rect(-1700, 4700, 100, 90)); + area8.Add(new Rect(-1700, 4550, 300, 150)); areas.Add(area1); areas.Add(area2); areas.Add(area3); @@ -57,6 +67,7 @@ private void createOffroadAreas() { areas.Add(area5); areas.Add(area6); areas.Add(area7); + areas.Add(area8); } // Test vehicle controls private void OnKeyUp(object sender, KeyEventArgs e) { @@ -87,7 +98,7 @@ public void DrawOffroadAreas() { foreach (var rect in area) { HashFunctions.Draw3DBox( new Vector3((float) (rect.X + rect.Width/2), (float) (rect.Y + rect.Height/2), 0), - new Vector3((float) rect.Width, (float) rect.Height, 400), + new Vector3((float) rect.Width, (float) rect.Height, 500), 255, 255, 255, 50); } } From a855cafbd96c1e9681ac093dd60d0c9b9ca41d9a Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 31 Jul 2018 18:08:59 +0200 Subject: [PATCH 146/158] added the basic logic for offroad --- managed/GTAVisionExport/OffroadPlanning.cs | 96 +++++++++++++++++++- managed/GTAVisionExport/VisionExport.cs | 4 + managed/GTAVisionUtils/GTAVisionUtils.csproj | 1 + managed/GTAVisionUtils/HashFunctions.cs | 4 + managed/GTAVisionUtils/MathUtils.cs | 54 +++++++++++ 5 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 managed/GTAVisionUtils/MathUtils.cs diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index 52bd3b3..f8e7c62 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -1,19 +1,29 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Reflection; using System.Windows; using System.Windows.Forms; using GTA; using GTA.Math; using GTA.Native; using GTAVisionUtils; +using VAutodrive; namespace GTAVisionExport { public class OffroadPlanning : Script { // constant for tried and sufficient offroad model public static VehicleHash OffroadModel = VehicleHash.Contender; - private bool showOffroadAreas = false; + private bool showOffroadAreas; public List> areas; + private Random rnd; + + private bool offroadDrivingStarted; + private bool currentlyDrivingToTarget; + private Vector2 currentTarget; + private int targetsFromSameStart = 0; + private List currentArea = null; public OffroadPlanning() { UI.Notify("Loaded OffroadPlanning.cs"); @@ -22,10 +32,11 @@ public OffroadPlanning() { Tick += OnTick; KeyUp += OnKeyUp; areas = new List>(); - createOffroadAreas(); + rnd = new Random(); + CreateOffroadAreas(); } - private void createOffroadAreas() { + private void CreateOffroadAreas() { var area1 = new List(); area1.Add(new Rect(1400, -2650, 800, 1750)); var area2 = new List(); @@ -69,6 +80,7 @@ private void createOffroadAreas() { areas.Add(area7); areas.Add(area8); } + // Test vehicle controls private void OnKeyUp(object sender, KeyEventArgs e) { switch (e.KeyCode) { @@ -82,15 +94,91 @@ private void OnKeyUp(object sender, KeyEventArgs e) { UI.Notify("disabled offroad areas showing"); } + break; + case Keys.Pause: + UI.Notify("Pressed Pause/Break"); + offroadDrivingStarted = !offroadDrivingStarted; + if (offroadDrivingStarted) { + UI.Notify("offroad driving enabled"); + } + else { + UI.Notify("offroad driving disabled"); + } + break; } } + public void checkDrivingToTarget() { + if (Game.Player.Character.CurrentVehicle.Position.DistanceTo2D(new Vector3(currentTarget.X, currentTarget.Y, 0)) < 2) { + currentlyDrivingToTarget = false; + } + } + + public void setNextTarget() { + if (currentlyDrivingToTarget) { + return; + } + +// setting the new start in new area + var targetsPerArea = 10; + if (targetsPerArea < targetsFromSameStart || currentArea == null) { + currentArea = GetRandomArea(); + var startRect = GetRandomRect(currentArea); + var start = GetRandomPoint(startRect); + var startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); + Game.Player.Character.CurrentVehicle.Position = new Vector3(start.X, start.Y, startZ); + targetsFromSameStart = 0; + } + +// firstly, select some area and for a while, perform random walk in that area, then randomly selct other area +// at first, I'll randomly sample rectangle from area, then randomly sample point from that rectangle +// sampling rectangles is in ratio corresponsing to their sizes, so smaller rectangle is not sampled more often + + var targetRect = GetRandomRect(currentArea); + var target = GetRandomPoint(targetRect); + DriveToPoint(target); + + currentlyDrivingToTarget = true; + currentTarget = target; + targetsFromSameStart += 1; + } + + private void SetTargetAsWaypoint(Vector2 target) { + HashFunctions.SetNewWaypoint(target); + } + + private void DriveToPoint(Vector2 target) { + SetTargetAsWaypoint(target); + var kh = new KeyHandling(); + var inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); + inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); + } + + private List GetRandomArea() { + return areas[rnd.Next(areas.Count)]; + } + + private Rect GetRandomRect(List area) { + var volumes = (List) (from rect in area select rect.Width * rect.Height); //calculating volumes + var sum = 0; + var rectIdx = MathUtils.digitize(rnd.Next(volumes.Sum()), MathUtils.cumsum(volumes)); + return area[rectIdx]; + } + + private Vector2 GetRandomPoint(Rect rect) { + return new Vector2(rnd.Next((int) (rect.Width)), rnd.Next((int) rect.Height)); + } + public void OnTick(object sender, EventArgs e) { if (showOffroadAreas) { DrawOffroadAreas(); } -// drawAxesBoxesAround(new Vector3(-1078f, -216f, 200f)); + + if (offroadDrivingStarted) { + checkDrivingToTarget(); + setNextTarget(); + } } public void DrawOffroadAreas() { diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 32c8351..9252636 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -62,6 +62,7 @@ class VisionExport : Script { private Socket connection; private UTF8Encoding encoding = new UTF8Encoding(false); +// this is the vaustodrive keyhandling private KeyHandling kh = new KeyHandling(); private Task postgresTask; @@ -77,6 +78,9 @@ class VisionExport : Script { private TimeSpan timeTo; public static string location; + //this variable, when true, should be disabling car spawning and autodrive starting here, because offroad has different settings + public static bool drivingOffroad; + public VisionExport() { // loading ini file var parser = new FileIniDataParser(); diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index c119d5c..6a99a20 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -143,6 +143,7 @@ + diff --git a/managed/GTAVisionUtils/HashFunctions.cs b/managed/GTAVisionUtils/HashFunctions.cs index 6468db2..7481129 100644 --- a/managed/GTAVisionUtils/HashFunctions.cs +++ b/managed/GTAVisionUtils/HashFunctions.cs @@ -7,6 +7,7 @@ using GTA; using GTA.Math; using GTA.Native; +using Point = System.Windows.Markup; namespace GTAVisionUtils { @@ -123,5 +124,8 @@ public static void Draw2DText(string text, float x, float y, Color color, byte a // Function.Call(Hash.SET_CAM_ROT, inputArgumentArray); // } + public static void SetNewWaypoint(Vector2 point) { + Function.Call(Hash.SET_NEW_WAYPOINT, point.X, point.Y); + } } } diff --git a/managed/GTAVisionUtils/MathUtils.cs b/managed/GTAVisionUtils/MathUtils.cs new file mode 100644 index 0000000..1e8af51 --- /dev/null +++ b/managed/GTAVisionUtils/MathUtils.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; + +namespace GTAVisionUtils { + public class MathUtils { + public static List cumsum(List arr) { + var cumsumArr = new List(arr.Count); + double sum = 0; + for (int i = 0; i < arr.Count; i++) { + sum += arr[i]; + cumsumArr[i] = sum; + } + + return cumsumArr; + } + + public static List cumsum(List arr) { + var cumsumArr = new List(arr.Count); + float sum = 0; + for (int i = 0; i < arr.Count; i++) { + sum += arr[i]; + cumsumArr[i] = sum; + } + + return cumsumArr; + } + + public static List cumsum(List arr) { + var cumsumArr = new List(arr.Count); + int sum = 0; + for (int i = 0; i < arr.Count; i++) { + sum += arr[i]; + cumsumArr[i] = sum; + } + + return cumsumArr; + } + + /// + /// Returns index of bin from cumulative sum array, same functionality as in numpy.digitize + /// + /// + public static int digitize(int number, List cumsumArr) { + for (int i = 0; i < cumsumArr.Count; i++) { + if (number < cumsumArr[i]) { + return i; + } + } + + throw new Exception("number is out of range of cumcum array"); + } + + } +} \ No newline at end of file From 6f3c794c02e1c21b82f6b826e6dd43b23dafaa0c Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 31 Jul 2018 18:35:42 +0200 Subject: [PATCH 147/158] refactored, now should be consistent with onread driving --- managed/GTAVisionExport/GameUtils.cs | 4 +++ managed/GTAVisionExport/OffroadPlanning.cs | 39 +++++++++++----------- managed/GTAVisionExport/VisionExport.cs | 31 ++++++++++++----- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/managed/GTAVisionExport/GameUtils.cs b/managed/GTAVisionExport/GameUtils.cs index 3ffe7cf..9564e36 100644 --- a/managed/GTAVisionExport/GameUtils.cs +++ b/managed/GTAVisionExport/GameUtils.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using GTA; using GTA.Math; +using GTA.Native; namespace GTAVisionExport { @@ -61,5 +62,8 @@ public class GTAConst { public static Vector3 OriginalStartPos = new Vector3(311.7819f, -1372.574f, 31.84874f); public static Vector3 HighwayStartPos = new Vector3(1209.5412f,-1936.0394f,38.3709f); + + public static VehicleHash OnroadVehicleHash = VehicleHash.Asea; + public static VehicleHash OffroadVehicleHash = OffroadPlanning.OffroadModel; } } diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index f8e7c62..a9626f7 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -11,19 +11,21 @@ using VAutodrive; namespace GTAVisionExport { + // all driving and path planning related things are static and called from VisionExport script which behaves as controlling point + // it makes coordination and switching between onroad and offroad easier public class OffroadPlanning : Script { // constant for tried and sufficient offroad model public static VehicleHash OffroadModel = VehicleHash.Contender; private bool showOffroadAreas; - public List> areas; - private Random rnd; + public static List> areas; + private static Random rnd; - private bool offroadDrivingStarted; - private bool currentlyDrivingToTarget; - private Vector2 currentTarget; - private int targetsFromSameStart = 0; - private List currentArea = null; + public static bool offroadDrivingStarted; + private static bool currentlyDrivingToTarget; + private static Vector2 currentTarget; + private static int targetsFromSameStart = 0; + private static List currentArea = null; public OffroadPlanning() { UI.Notify("Loaded OffroadPlanning.cs"); @@ -100,27 +102,29 @@ private void OnKeyUp(object sender, KeyEventArgs e) { offroadDrivingStarted = !offroadDrivingStarted; if (offroadDrivingStarted) { UI.Notify("offroad driving enabled"); + VisionExport.drivingOffroad = true; } else { UI.Notify("offroad driving disabled"); + VisionExport.drivingOffroad = false; } break; } } - public void checkDrivingToTarget() { + public static void checkDrivingToTarget() { if (Game.Player.Character.CurrentVehicle.Position.DistanceTo2D(new Vector3(currentTarget.X, currentTarget.Y, 0)) < 2) { currentlyDrivingToTarget = false; } } - public void setNextTarget() { + public static void setNextTarget() { if (currentlyDrivingToTarget) { return; } -// setting the new start in new area +// setting the new start in new area after some number of targets from same start var targetsPerArea = 10; if (targetsPerArea < targetsFromSameStart || currentArea == null) { currentArea = GetRandomArea(); @@ -144,29 +148,29 @@ public void setNextTarget() { targetsFromSameStart += 1; } - private void SetTargetAsWaypoint(Vector2 target) { + private static void SetTargetAsWaypoint(Vector2 target) { HashFunctions.SetNewWaypoint(target); } - private void DriveToPoint(Vector2 target) { + private static void DriveToPoint(Vector2 target) { SetTargetAsWaypoint(target); var kh = new KeyHandling(); var inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } - private List GetRandomArea() { + private static List GetRandomArea() { return areas[rnd.Next(areas.Count)]; } - private Rect GetRandomRect(List area) { + private static Rect GetRandomRect(List area) { var volumes = (List) (from rect in area select rect.Width * rect.Height); //calculating volumes var sum = 0; var rectIdx = MathUtils.digitize(rnd.Next(volumes.Sum()), MathUtils.cumsum(volumes)); return area[rectIdx]; } - private Vector2 GetRandomPoint(Rect rect) { + private static Vector2 GetRandomPoint(Rect rect) { return new Vector2(rnd.Next((int) (rect.Width)), rnd.Next((int) rect.Height)); } @@ -175,10 +179,7 @@ public void OnTick(object sender, EventArgs e) { DrawOffroadAreas(); } - if (offroadDrivingStarted) { - checkDrivingToTarget(); - setNextTarget(); - } + // driving and planning related things are in VisionExport } public void DrawOffroadAreas() { diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 9252636..fb51cf8 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -71,7 +71,7 @@ class VisionExport : Script { private int curSessionId = -1; private speedAndTime lowSpeedTime = new speedAndTime(); private bool isGamePaused = false; // this is for external pause, not for internal pause inside the script - private bool notificationsAllowed = true; + private static bool notificationsAllowed = true; private StereoCamera cams; private bool timeIntervalEnabled = false; private TimeSpan timeFrom; @@ -360,6 +360,11 @@ public void OnTick(object o, EventArgs e) { // UINotify("postgresTask.IsCompleted: " + postgresTask.IsCompleted.ToString()); if (!runTask.IsCompleted) return; if (!postgresTask.IsCompleted) return; + + if (OffroadPlanning.offroadDrivingStarted) { + OffroadPlanning.checkDrivingToTarget(); + OffroadPlanning.setNextTarget(); + } // UINotify("going to save images and save to postgres"); @@ -551,7 +556,7 @@ public void StopRun() { Game.Player.LastVehicle.Alpha = int.MaxValue; } - public void UINotify(string message) { + public static void UINotify(string message) { //just wrapper for UI.Notify, but lets us disable showing notifications ar all if (notificationsAllowed) { UI.Notify(message); @@ -565,12 +570,19 @@ public void GamePause(bool value) { } } - public void EnterVehicle() { + public static void EnterVehicle() { /* var vehicle = World.GetClosestVehicle(player.Character.Position, 30f); player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); */ - var mod = new Model(VehicleHash.Asea); + Model mod = null; + if (drivingOffroad) { + mod = new Model(GTAConst.OffroadVehicleHash); + } else { + mod = new Model(GTAConst.OnroadVehicleHash); + } + + var player = Game.Player; if (mod == null) { UINotify("mod is null"); } @@ -597,11 +609,12 @@ public void EnterVehicle() { } public void ToggleNavigation() { - //todo: probably here try to set camera, maybe by SET_FOLLOW_VEHICLE_CAM_VIEW_MODE(int viewMode), or by SET_FOLLOW_VEHICLE_CAM_ZOOM_LEVEL(int zoomLevel) - // or just something with the GTA.GameplayCamera - //YOLO - MethodInfo inf = - kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); + if (drivingOffroad) { + //offroad driving script should handle that separately + return; + } + + MethodInfo inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } From 433e2f3def944e33afad69d5e346f0968890b142 Mon Sep 17 00:00:00 2001 From: racinmat Date: Tue, 31 Jul 2018 19:20:44 +0200 Subject: [PATCH 148/158] fixed some bugs, but still needs some more work to function --- managed/GTAVisionExport/OffroadPlanning.cs | 17 +++++++++++++++-- managed/GTAVisionExport/VisionExport.cs | 4 ++-- managed/GTAVisionUtils/Logger.cs | 3 +-- managed/GTAVisionUtils/MathUtils.cs | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index a9626f7..4bd45a2 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -160,12 +160,25 @@ private static void DriveToPoint(Vector2 target) { } private static List GetRandomArea() { - return areas[rnd.Next(areas.Count)]; + var areaIdx = rnd.Next(areas.Count); + Logger.WriteLine($"randomly selected area index {areaIdx} from {areas.Count} areas"); + var area = areas[areaIdx]; + Logger.WriteLine($"selected area: {string.Join(", ", area)}, with size {area.Count}"); + return area; } private static Rect GetRandomRect(List area) { - var volumes = (List) (from rect in area select rect.Width * rect.Height); //calculating volumes + Logger.WriteLine($"selecting random rect for area with size {area.Count}"); + Logger.ForceFlush(); + var volumes = new List(area.Count); + for (var i = 0; i < area.Count; i++) { + Logger.WriteLine($"to {i}-th index, setting volume {area[i].Width * area[i].Height}"); + Logger.ForceFlush(); + volumes.Add((int) (area[i].Width * area[i].Height)); + } var sum = 0; + Logger.WriteLine($"calculated volumes"); + Logger.ForceFlush(); var rectIdx = MathUtils.digitize(rnd.Next(volumes.Sum()), MathUtils.cumsum(volumes)); return area[rectIdx]; } diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index fb51cf8..2bb511a 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -361,7 +361,7 @@ public void OnTick(object o, EventArgs e) { if (!runTask.IsCompleted) return; if (!postgresTask.IsCompleted) return; - if (OffroadPlanning.offroadDrivingStarted) { + if (drivingOffroad && OffroadPlanning.offroadDrivingStarted) { OffroadPlanning.checkDrivingToTarget(); OffroadPlanning.setNextTarget(); } @@ -596,7 +596,7 @@ public static void EnterVehicle() { } UINotify("player position: " + player.Character.Position); - var vehicle = GTA.World.CreateVehicle(mod, player.Character.Position); + var vehicle = World.CreateVehicle(mod, player.Character.Position); if (vehicle == null) { UINotify("vehicle is null. Something is fucked up"); } diff --git a/managed/GTAVisionUtils/Logger.cs b/managed/GTAVisionUtils/Logger.cs index bf7caca..b39c226 100644 --- a/managed/GTAVisionUtils/Logger.cs +++ b/managed/GTAVisionUtils/Logger.cs @@ -17,8 +17,7 @@ public class Logger { public static int FlushAfterSeconds = 5; public static int FlushAtQty = 10; private static DateTime FlushedAt = DateTime.Now; - private Logger() { } - + public static void ForceFlush() { FlushLogToFile(); diff --git a/managed/GTAVisionUtils/MathUtils.cs b/managed/GTAVisionUtils/MathUtils.cs index 1e8af51..f6507b5 100644 --- a/managed/GTAVisionUtils/MathUtils.cs +++ b/managed/GTAVisionUtils/MathUtils.cs @@ -30,7 +30,7 @@ public static List cumsum(List arr) { int sum = 0; for (int i = 0; i < arr.Count; i++) { sum += arr[i]; - cumsumArr[i] = sum; + cumsumArr.Add(sum); } return cumsumArr; From ec20e5afc579bd3c8cfcac8a70cc27a615f481ab Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 1 Aug 2018 19:57:12 +0200 Subject: [PATCH 149/158] hopefully finally working the magic behind getting the z ground coord --- .../GTAVisionExport/GTAVisionExport.csproj | 4 ++ managed/GTAVisionExport/OffroadPlanning.cs | 67 +++++++++++++++---- managed/GTAVisionExport/VisionExport.cs | 64 ++++++++++++++++-- managed/GTAVisionUtils/GTAVisionUtils.csproj | 2 + managed/GTAVisionUtils/HashFunctions.cs | 4 ++ 5 files changed, 121 insertions(+), 20 deletions(-) diff --git a/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index a438602..fe6589f 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -21,6 +21,7 @@ prompt 4 x64 + false pdbonly @@ -29,6 +30,7 @@ TRACE prompt 4 + false true @@ -39,6 +41,7 @@ prompt MinimumRecommendedRules.ruleset false + false bin\Release\ @@ -49,6 +52,7 @@ prompt MinimumRecommendedRules.ruleset true + false diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index 4bd45a2..0da7423 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -119,6 +119,53 @@ public static void checkDrivingToTarget() { } } + /// + /// behold, this function wraps most of fuckups that GetGroundHeight causes, + /// teleports player multiple times and perform waiting, call only when you know what your're doing + /// + /// + /// + public static float GetGroundHeightMagic(Vector2 position) { +// for distant position from player, which are not bufferent, function returns 0, so we need to teleport +// above that position and let player fall, in the meantime texture loads properly and getting ground height starts +// working. Raycasting returns exactly same results, so it seems that it's used as an implementation of this function +// when the player is falling on the exact same x,y location, this returns player's position as ground +// that is heavy evidence for thinking raycasting from above is used in that function. That's why here is +5, +5 +// for player position. For each position, height in which it starts working, differs, so that's why I tryit in cycle +// and check when it returns nonzero, and thus correct result + 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(position.X + 5, position.Y + 5, i); + //just some more waiting for textures to load + Script.Wait(500); + var startZ = World.GetGroundHeight(new Vector2(position.X, position.Y)); + if (startZ != 0) { + return startZ; + } + } + + throw new Exception("height measurement is fucked up somehow, aborting"); + } + + public static void setNextStart() { + Logger.WriteLine($"setting the next start"); + currentArea = GetRandomArea(); + var startRect = GetRandomRect(currentArea); + var start = GetRandomPoint(startRect); + var startZ = GetGroundHeightMagic(start); + Game.Player.Character.IsInvincible = true; + Logger.WriteLine($"{startZ} is ground height of {start}"); + var newPosition = new Vector3(start.X, start.Y, startZ + 2); // so we have some reserve, when setting to ground z coord, it falls through + if (Game.Player.Character.IsInVehicle()) { + Game.Player.Character.CurrentVehicle.Position = newPosition; + } + else { + Game.Player.Character.Position = newPosition; + } + targetsFromSameStart = 0; + Logger.WriteLine($"setting next start in {newPosition}"); + } + public static void setNextTarget() { if (currentlyDrivingToTarget) { return; @@ -127,12 +174,7 @@ public static void setNextTarget() { // setting the new start in new area after some number of targets from same start var targetsPerArea = 10; if (targetsPerArea < targetsFromSameStart || currentArea == null) { - currentArea = GetRandomArea(); - var startRect = GetRandomRect(currentArea); - var start = GetRandomPoint(startRect); - var startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); - Game.Player.Character.CurrentVehicle.Position = new Vector3(start.X, start.Y, startZ); - targetsFromSameStart = 0; + setNextStart(); } // firstly, select some area and for a while, perform random walk in that area, then randomly selct other area @@ -141,6 +183,7 @@ public static void setNextTarget() { var targetRect = GetRandomRect(currentArea); var target = GetRandomPoint(targetRect); + Logger.WriteLine($"setting next target in {target}"); DriveToPoint(target); currentlyDrivingToTarget = true; @@ -159,7 +202,7 @@ private static void DriveToPoint(Vector2 target) { inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } - private static List GetRandomArea() { + public static List GetRandomArea() { var areaIdx = rnd.Next(areas.Count); Logger.WriteLine($"randomly selected area index {areaIdx} from {areas.Count} areas"); var area = areas[areaIdx]; @@ -167,24 +210,20 @@ private static List GetRandomArea() { return area; } - private static Rect GetRandomRect(List area) { + public static Rect GetRandomRect(List area) { Logger.WriteLine($"selecting random rect for area with size {area.Count}"); Logger.ForceFlush(); var volumes = new List(area.Count); for (var i = 0; i < area.Count; i++) { - Logger.WriteLine($"to {i}-th index, setting volume {area[i].Width * area[i].Height}"); - Logger.ForceFlush(); volumes.Add((int) (area[i].Width * area[i].Height)); } var sum = 0; - Logger.WriteLine($"calculated volumes"); - Logger.ForceFlush(); var rectIdx = MathUtils.digitize(rnd.Next(volumes.Sum()), MathUtils.cumsum(volumes)); return area[rectIdx]; } - private static Vector2 GetRandomPoint(Rect rect) { - return new Vector2(rnd.Next((int) (rect.Width)), rnd.Next((int) rect.Height)); + public static Vector2 GetRandomPoint(Rect rect) { + return new Vector2((float) (rect.X + rnd.Next((int) (rect.Width))), (float) (rect.Y + rnd.Next((int) rect.Height))); } public void OnTick(object sender, EventArgs e) { diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 2bb511a..c8e51f6 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -77,6 +77,7 @@ class VisionExport : Script { private TimeSpan timeFrom; private TimeSpan timeTo; public static string location; + private static Vector2 somePos; //this variable, when true, should be disabling car spawning and autodrive starting here, because offroad has different settings public static bool drivingOffroad; @@ -654,13 +655,19 @@ public void ReloadGame() { //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); +// ClearSurroundingVehicles(player.Position, 1000f); player.LastVehicle.Delete(); // teleport to the spawning position, defined in GameUtils.cs, subject to changes // player.Position = GTAConst.OriginalStartPos; - player.Position = GTAConst.HighwayStartPos; + if (drivingOffroad) { + OffroadPlanning.setNextStart(); + } + else { + player.Position = GTAConst.HighwayStartPos; + } // ClearSurroundingVehicles(player.Position, 100f); - ClearSurroundingVehicles(player.Position, 50f); +// ClearSurroundingVehicles(player.Position, 50f); + ClearSurroundingVehicles(player.Position, 20f); // start a new run EnterVehicle(); //Script.Wait(2000); @@ -779,8 +786,8 @@ public void OnKeyDown(object o, KeyEventArgs k) { 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(GTA.Native.Hash._SET_RAIN_FX_INTENSITY, 0.5f); - var test = Function.Call(GTA.Native.Hash.GET_RAIN_LEVEL); + Function.Call(Hash._SET_RAIN_FX_INTENSITY, 0.5f); + var test = Function.Call(Hash.GET_RAIN_LEVEL); UINotify("" + test); World.CurrentDayTime = new TimeSpan(12, 0, 0); //Script.Wait(5000); @@ -811,7 +818,7 @@ public void OnKeyDown(object o, KeyEventArgs k) { Game.Pause(true); for (int i = 0; i < CamerasList.cameras.Count; i++) { - Logger.WriteLine("activating camera " + i.ToString()); + Logger.WriteLine($"activating camera {i}"); CamerasList.ActivateCamera(i); Script.Wait(1000); } @@ -823,6 +830,51 @@ public void OnKeyDown(object o, KeyEventArgs k) { 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: + var res = World.Raycast(new Vector3(somePos.X, somePos.Y, 800), new Vector3(somePos.X, somePos.Y, -100), IntersectOptions.Everything, Game.Player.Character); + Logger.WriteLine($"{res.DitHitAnything} is raycast did hit result."); + Logger.WriteLine($"{res.HitCoords.Z} is the {somePos} raycasted ground position."); + 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; } } diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index 6a99a20..406c9b8 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -23,6 +23,7 @@ prompt 4 x64 + true pdbonly @@ -31,6 +32,7 @@ TRACE prompt 4 + true diff --git a/managed/GTAVisionUtils/HashFunctions.cs b/managed/GTAVisionUtils/HashFunctions.cs index 7481129..a515d4f 100644 --- a/managed/GTAVisionUtils/HashFunctions.cs +++ b/managed/GTAVisionUtils/HashFunctions.cs @@ -127,5 +127,9 @@ public static void Draw2DText(string text, float x, float y, Color color, byte a public static void SetNewWaypoint(Vector2 point) { Function.Call(Hash.SET_NEW_WAYPOINT, point.X, point.Y); } + + public static void PlaceObjectOnGroundProperly(Entity entity) { + Function.Call(Hash.PLACE_OBJECT_ON_GROUND_PROPERLY, entity); + } } } From 1995f9efcb555b145ebcb15e1202e7896f960fa4 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 1 Aug 2018 20:40:44 +0200 Subject: [PATCH 150/158] other car, tried and is working in single player --- managed/GTAVisionExport/OffroadPlanning.cs | 3 +- managed/GTAVisionExport/VisionExport.cs | 40 +++++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index 0da7423..6b26dc5 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -15,7 +15,8 @@ namespace GTAVisionExport { // it makes coordination and switching between onroad and offroad easier public class OffroadPlanning : Script { // constant for tried and sufficient offroad model - public static VehicleHash OffroadModel = VehicleHash.Contender; +// it is single player car. Some cars here are multiplayer and disappear at most few seconds after spawning + public static VehicleHash OffroadModel = VehicleHash.Mesa; private bool showOffroadAreas; public static List> areas; diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index c8e51f6..c5ed4f5 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -145,12 +145,12 @@ private void initialize4cameras() { // CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); // CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); -// for 4 cameras of different sides of the car - CamerasList.setMainCamera(); - CamerasList.addCamera(new Vector3(0f, 2f, 0.3f), new Vector3(0f, 0f, 0f), 50, 0.15f); - CamerasList.addCamera(new Vector3(-0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 90f), 50, 0.15f); - CamerasList.addCamera(new Vector3(0f, -2.3f, 0.3f), new Vector3(0f, 0f, 180f), 50, 0.15f); - CamerasList.addCamera(new Vector3(0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 270f), 50, 0.15f); +//// for 4 cameras of different sides of the car +// CamerasList.setMainCamera(); +// CamerasList.addCamera(new Vector3(0f, 2f, 0.3f), new Vector3(0f, 0f, 0f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(-0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 90f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(0f, -2.3f, 0.3f), new Vector3(0f, 0f, 180f), 50, 0.15f); +// CamerasList.addCamera(new Vector3(0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 270f), 50, 0.15f); // for 4 cameras on top of car, heading 4 directions // CamerasList.setMainCamera(); @@ -181,6 +181,27 @@ private void initialize4cameras() { //// CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); //// and now, one camera from birds-eye view, with this configuration, it sees all other cameras // CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); + +// two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo, but for offroad car, specifically, for Mesa +// for cameras mapping area before the car + CamerasList.setMainCamera(); + const float r = 8f; //radius of circle with 4 cameras + // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground + var carCenter = 0.5735f; + var camOne = new Vector3(-0.06f, 0.47f, 1.65f - carCenter); + var camTwo = new Vector3(-0.06f+0.54f, 0.47f, 1.65f - carCenter); + CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); + CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); + CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); + CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); +// 4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras + CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); +// CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); +// CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); +// CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); +// and now, one camera from birds-eye view, with this configuration, it sees all other cameras + CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); + } private void HandlePipeInput() { @@ -856,9 +877,10 @@ public void OnKeyDown(object o, KeyEventArgs k) { Logger.WriteLine($"{World.GetGroundHeight(somePos)} is the {somePos} ground position."); break; case Keys.F11: - var res = World.Raycast(new Vector3(somePos.X, somePos.Y, 800), new Vector3(somePos.X, somePos.Y, -100), IntersectOptions.Everything, Game.Player.Character); - Logger.WriteLine($"{res.DitHitAnything} is raycast did hit result."); - Logger.WriteLine($"{res.HitCoords.Z} is the {somePos} raycasted ground position."); + 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()); From 09dedf8dc0ad351a01fc12211d39e0b19a58a9ec Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 2 Aug 2018 16:23:22 +0200 Subject: [PATCH 151/158] hopefully correctly set cameras fov for being like kitti --- managed/GTAVisionExport/CameraHandling.cs | 40 +++++++++++------------ managed/GTAVisionExport/VisionExport.cs | 14 ++++---- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/managed/GTAVisionExport/CameraHandling.cs b/managed/GTAVisionExport/CameraHandling.cs index 3e45558..32bdf6b 100644 --- a/managed/GTAVisionExport/CameraHandling.cs +++ b/managed/GTAVisionExport/CameraHandling.cs @@ -130,26 +130,26 @@ private void onKeyUp(object sender, KeyEventArgs e) { UI.Notify("disabled position showing"); } break; -// case Keys.NumPad0: -// UI.Notify("Pressed numpad 0"); -// activeCameraIndex = 0; -// mountCameraOnVehicle(); -// break; -// case Keys.NumPad1: -// UI.Notify("Pressed numpad 1"); -// activeCameraIndex = 1; -// mountCameraOnVehicle(); -// break; -// case Keys.NumPad2: -// UI.Notify("Pressed numpad 2"); -// activeCameraIndex = 2; -// mountCameraOnVehicle(); -// break; -// case Keys.NumPad3: -// UI.Notify("Pressed numpad 3"); -// activeCameraIndex = 3; -// mountCameraOnVehicle(); -// break; + case Keys.NumPad0: + UI.Notify("Pressed numpad 0"); + activeCameraIndex = 0; + mountCameraOnVehicle(); + break; + case Keys.NumPad1: + UI.Notify("Pressed numpad 1"); + activeCameraIndex = 1; + mountCameraOnVehicle(); + break; + case Keys.NumPad2: + UI.Notify("Pressed numpad 2"); + activeCameraIndex = 2; + mountCameraOnVehicle(); + break; + case Keys.NumPad3: + UI.Notify("Pressed numpad 3"); + activeCameraIndex = 3; + mountCameraOnVehicle(); + break; case Keys.Decimal: UI.Notify("Pressed numpad ,"); activeCameraIndex = -2; diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index c5ed4f5..7553ace 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -145,7 +145,7 @@ private void initialize4cameras() { // CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f); // CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f); -//// for 4 cameras of different sides of the car +//// for 4 cameras of different sides of the car, for šochman // CamerasList.setMainCamera(); // CamerasList.addCamera(new Vector3(0f, 2f, 0.3f), new Vector3(0f, 0f, 0f), 50, 0.15f); // CamerasList.addCamera(new Vector3(-0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 90f), 50, 0.15f); @@ -184,18 +184,20 @@ private void initialize4cameras() { // two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo, but for offroad car, specifically, for Mesa // for cameras mapping area before the car +// KITTI images have ratio of 3.32, they are very large and thus have large horizontal fov. This ratio can not be obtained here +// so I set higher vertical fov and image may be then cropped into KITTI-like one CamerasList.setMainCamera(); const float r = 8f; //radius of circle with 4 cameras // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground var carCenter = 0.5735f; var camOne = new Vector3(-0.06f, 0.47f, 1.65f - carCenter); var camTwo = new Vector3(-0.06f+0.54f, 0.47f, 1.65f - carCenter); - CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); - CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); - CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); - CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); + CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f); + CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 90, 0.15f); + CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 90, 0.15f); + CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 90, 0.15f); // 4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras - CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f); + CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f); // CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); // CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); // CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); From 3210342c622792b014fdfe5dd4b67e1695f69c54 Mon Sep 17 00:00:00 2001 From: racinmat Date: Wed, 8 Aug 2018 19:59:28 +0200 Subject: [PATCH 152/158] added and refactored failsafe mechanisms for car stuck in offroad --- managed/GTAVisionExport/GameUtils.cs | 92 ++++++++------ managed/GTAVisionExport/OffroadPlanning.cs | 17 ++- managed/GTAVisionExport/VisionExport.cs | 132 +++++++++++++++------ managed/GTAVisionUtils/ImageUtils.cs | 2 +- managed/README.md | 4 +- 5 files changed, 170 insertions(+), 77 deletions(-) diff --git a/managed/GTAVisionExport/GameUtils.cs b/managed/GTAVisionExport/GameUtils.cs index 9564e36..9d78be4 100644 --- a/managed/GTAVisionExport/GameUtils.cs +++ b/managed/GTAVisionExport/GameUtils.cs @@ -7,59 +7,85 @@ using GTA.Math; using GTA.Native; -namespace GTAVisionExport -{ +namespace GTAVisionExport { - public class speedAndTime - { - public int gameTime { get; set; } - public float speed { get; set; } + public class TimeChecker { + public int startTime { get; set; } public bool initialized { get; set; } - public speedAndTime() - { - gameTime = 0; - speed = 0; + public TimeSpan interval { get; set; } + + public TimeChecker(TimeSpan interval) { + /* Game.Gametime is in ms, so 1000000 ms = 16.6 min*/ + startTime = 0; initialized = false; + this.interval = interval; } - public void setTime(int time, float speed) - { - this.gameTime = time; - this.speed = speed; - this.initialized = true; - } - public void clearTime() - { + + public void clear() { this.initialized = false; } - public Boolean checkTrafficJam(int time, float speed) - { + + public bool isPassed(int time) { //UI.Notify("last time" + this.gameTime); //UI.Notify("time now" + time); - if (!initialized) - { - this.gameTime = time; - this.speed = speed; - this.initialized = true; + if (!initialized) { + startTime = time; + initialized = true; return false; } + + return time >= startTime + interval.TotalMilliseconds; + } + } + + /// + /// Use to check if vehicle is stuck in some area for some time (e.g. has not moved 1 meter or more from position in last minute) + /// + /// + public class TimeDistanceChecker { + public int startTime { get; set; } + public bool initialized { get; set; } + public TimeSpan interval { get; set; } + public Vector3 center; + public int distance; + + public TimeDistanceChecker(TimeSpan interval, int distance, Vector3 center) { /* Game.Gametime is in ms, so 1000000 ms = 16.6 min*/ - else if (time >= this.gameTime + 200000) - { - return true; + startTime = 0; + initialized = false; + this.interval = interval; + this.center = center; + this.distance = distance; + } + + public void clear() { + this.initialized = false; + } + + public bool isPassed(int time, Vector3 position) { + //UI.Notify("last time" + this.gameTime); + //UI.Notify("time now" + time); + if (!initialized) { + startTime = time; + initialized = true; + center = position; + return false; + } + + if (time >= startTime + interval.TotalMilliseconds) { + return position.DistanceTo(center) < distance; } - else return false; + return false; } } - public enum GameStatus - { + public enum GameStatus { NeedReload, NeedStart, NoActionNeeded } - public class GTAConst - { + public class GTAConst { public static Vector3 OriginalStartPos = new Vector3(311.7819f, -1372.574f, 31.84874f); public static Vector3 HighwayStartPos = new Vector3(1209.5412f,-1936.0394f,38.3709f); diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index 6b26dc5..6e70b13 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -115,9 +115,15 @@ private void OnKeyUp(object sender, KeyEventArgs e) { } public static void checkDrivingToTarget() { - if (Game.Player.Character.CurrentVehicle.Position.DistanceTo2D(new Vector3(currentTarget.X, currentTarget.Y, 0)) < 2) { + if (Game.Player.Character.CurrentVehicle.Position.DistanceTo2D(new Vector3(currentTarget.X, currentTarget.Y, 0)) < 3) { currentlyDrivingToTarget = false; } + + if (! Game.IsWaypointActive) { + currentlyDrivingToTarget = false; + } + + } /// @@ -182,8 +188,13 @@ public static void setNextTarget() { // at first, I'll randomly sample rectangle from area, then randomly sample point from that rectangle // sampling rectangles is in ratio corresponsing to their sizes, so smaller rectangle is not sampled more often - var targetRect = GetRandomRect(currentArea); - var target = GetRandomPoint(targetRect); +// because vehicle is driving onroad for longer routes, generated target shall be max. 200 meters from start, behaving as a "waypoint" on randomly sampled route + Vector2 target; + var playerPos = Game.Player.Character.Position; + do { + var targetRect = GetRandomRect(currentArea); + target = GetRandomPoint(targetRect); + } while (target.DistanceTo(new Vector2(playerPos.X, playerPos.Y)) > 200); Logger.WriteLine($"setting next target in {target}"); DriveToPoint(target); diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 7553ace..3a7b8ef 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -69,7 +69,9 @@ class VisionExport : Script { private Task runTask; private int curSessionId = -1; - private speedAndTime lowSpeedTime = new speedAndTime(); + private TimeChecker lowSpeedTime = new TimeChecker(TimeSpan.FromSeconds(200)); + private TimeChecker notMovingTime = new TimeChecker(TimeSpan.FromSeconds(30)); + private TimeDistanceChecker distanceFromStart = new TimeDistanceChecker(TimeSpan.FromSeconds(30), 2, new Vector3()); private bool isGamePaused = false; // this is for external pause, not for internal pause inside the script private static bool notificationsAllowed = true; private StereoCamera cams; @@ -81,6 +83,7 @@ class VisionExport : Script { //this variable, when true, should be disabling car spawning and autodrive starting here, because offroad has different settings public static bool drivingOffroad; + public static bool gatheringData = true; public VisionExport() { // loading ini file @@ -182,34 +185,54 @@ private void initialize4cameras() { //// and now, one camera from birds-eye view, with this configuration, it sees all other cameras // CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); +//// two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo, but for offroad car, specifically, for Mesa +//// for cameras mapping area before the car +//// KITTI images have ratio of 3.32, they are very large and thus have large horizontal fov. This ratio can not be obtained here +//// so I set higher vertical fov and image may be then cropped into KITTI-like one +// CamerasList.setMainCamera(); +// const float r = 8f; //radius of circle with 4 cameras +// // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground +// var carCenter = 0.5735f; +// var camOne = new Vector3(-0.06f, 1.5f, 1.65f - carCenter); +// var camTwo = new Vector3(-0.06f+0.54f, 1.5f, 1.65f - carCenter); +// CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f); +// CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 90, 0.15f); +// CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 90, 0.15f); +// CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 90, 0.15f); +//// 4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras +// CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f); +//// CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); +//// CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); +//// CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); +//// and now, one camera from birds-eye view, with this configuration, it sees all other cameras +// CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); + +// na 32 metrů průměr, výš a natočit dolů // two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo, but for offroad car, specifically, for Mesa // for cameras mapping area before the car // KITTI images have ratio of 3.32, they are very large and thus have large horizontal fov. This ratio can not be obtained here // so I set higher vertical fov and image may be then cropped into KITTI-like one CamerasList.setMainCamera(); - const float r = 8f; //radius of circle with 4 cameras + const float r = 16f; //radius of circle with 4 cameras // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground var carCenter = 0.5735f; - var camOne = new Vector3(-0.06f, 0.47f, 1.65f - carCenter); - var camTwo = new Vector3(-0.06f+0.54f, 0.47f, 1.65f - carCenter); + var camOne = new Vector3(-0.06f, 1.5f, 1.65f - carCenter); + var camTwo = new Vector3(-0.06f+0.54f, 1.5f, 1.65f - carCenter); CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f); - CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 90, 0.15f); - CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 90, 0.15f); - CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 90, 0.15f); + + CamerasList.addCamera(camOne + new Vector3(r, r, 5f), new Vector3(-30f, 0f, 90f), 90, 0.15f); + CamerasList.addCamera(camOne + new Vector3(0, 2*r, 5f), new Vector3(-30f, 0f, 180f), 90, 0.15f); + CamerasList.addCamera(camOne + new Vector3(-r, r, 5f), new Vector3(-30f, 0f, 270f), 90, 0.15f); // 4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f); -// CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f); -// CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f); -// CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f); // and now, one camera from birds-eye view, with this configuration, it sees all other cameras - CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f); - + CamerasList.addCamera(camOne + new Vector3(0, r, r + 8), new Vector3(270f, 0f, 90f), 70, 0.15f); //to have bigger view of area in front of and behind car } private void HandlePipeInput() { // Logger.writeLine("VisionExport handlePipeInput called."); // UINotify("handlePipeInput called"); - UINotify("server connected:" + server.Connected.ToString()); + UINotify("server connected:" + server.Connected); UINotify(connection == null ? "connection is null" : "connection:" + connection); if (connection == null) return; @@ -392,22 +415,24 @@ public void OnTick(object o, EventArgs e) { // UINotify("going to save images and save to postgres"); - try { - GamePause(true); - gatherData(); - GamePause(false); - } - catch (Exception exception) { - GamePause(false); - Logger.WriteLine("exception occured, logging and continuing"); - Logger.WriteLine(exception); + 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 = GTA.World.CurrentDayTime; + var currentTime = World.CurrentDayTime; if (currentTime > timeTo) { - GTA.World.CurrentDayTime = timeFrom; + World.CurrentDayTime = timeFrom; } } } @@ -495,15 +520,26 @@ public GameStatus checkStatus() { if (player.IsDead) return GameStatus.NeedReload; if (player.IsInVehicle()) { var vehicle = player.CurrentVehicle; - //UINotify("T:" + Game.GameTime.ToString() + " S: " + vehicle.Speed.ToString()); - if (vehicle.Speed < 1.0f) //speed is in mph - { - if (lowSpeedTime.checkTrafficJam(Game.GameTime, vehicle.Speed)) { +// here checking the time in low or no speed + if (vehicle.Speed < 1.0f) { //speed is in mph + if (lowSpeedTime.isPassed(Game.GameTime)) { return GameStatus.NeedReload; } + } else { + lowSpeedTime.clear(); } - else { - lowSpeedTime.clearTime(); + + if (vehicle.Speed < 0.001f) { + if (notMovingTime.isPassed(Game.GameTime)) { + return GameStatus.NeedReload; + } + } else { + notMovingTime.clear(); + } + +// here checking the movement from previous position on some time + if (distanceFromStart.isPassed(Game.GameTime, vehicle.Position)) { + return GameStatus.NeedReload; } return GameStatus.NoActionNeeded; @@ -538,9 +574,9 @@ public Bitmap CaptureScreen() { public void Autostart() { if (! staticCamera) { EnterVehicle(); - Script.Wait(200); + Wait(200); ToggleNavigation(); - Script.Wait(200); + Wait(200); } postgresTask?.Wait(); postgresTask = StartSession(); @@ -628,14 +664,16 @@ public static void EnterVehicle() { player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); } - //vehicle.Alpha = 0; //transparent - //player.Character.Alpha = 0; +// vehicle.Alpha = 0; //transparent +// player.Character.Alpha = 0; + vehicle.Alpha = int.MaxValue; //back to visible, not sure what the exact value means in terms of transparency + player.Character.Alpha = int.MaxValue; } public void ToggleNavigation() { if (drivingOffroad) { //offroad driving script should handle that separately - return; + OffroadPlanning.setNextTarget(); } MethodInfo inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); @@ -647,7 +685,7 @@ private void ClearSurroundingVehicles(Vector3 pos, float radius) { } private void ClearSurroundingVehicles(float x, float y, float z, float radius) { - Function.Call(GTA.Native.Hash.CLEAR_AREA_OF_VEHICLES, x, y, z, radius, false, false, false, false); + Function.Call(Hash.CLEAR_AREA_OF_VEHICLES, x, y, z, radius, false, false, false, false); } private void ClearSurroundingEverything(Vector3 pos, float radius) { @@ -655,14 +693,17 @@ private void ClearSurroundingEverything(Vector3 pos, float radius) { } private void ClearSurroundingEverything(float x, float y, float z, float radius) { - Function.Call(GTA.Native.Hash.CLEAR_AREA, x, y, z, radius, false, false, false, false); + Function.Call(Hash.CLEAR_AREA, x, y, z, radius, false, false, false, false); } public void ReloadGame() { if (staticCamera) { return; } - + + lowSpeedTime.clear(); + notMovingTime.clear(); + distanceFromStart.clear(); /* Process p = Process.GetProcessesByName("Grand Theft Auto V").FirstOrDefault(); if (p != null) @@ -684,6 +725,7 @@ public void ReloadGame() { // player.Position = GTAConst.OriginalStartPos; if (drivingOffroad) { OffroadPlanning.setNextStart(); + OffroadPlanning.setNextTarget(); } else { player.Position = GTAConst.HighwayStartPos; @@ -696,7 +738,7 @@ public void ReloadGame() { //Script.Wait(2000); ToggleNavigation(); - lowSpeedTime.clearTime(); + lowSpeedTime.clear(); } public void TraverseWeather() { @@ -899,6 +941,18 @@ public void OnKeyDown(object o, KeyEventArgs k) { 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; + } } diff --git a/managed/GTAVisionUtils/ImageUtils.cs b/managed/GTAVisionUtils/ImageUtils.cs index 3e05ae5..e9a9342 100644 --- a/managed/GTAVisionUtils/ImageUtils.cs +++ b/managed/GTAVisionUtils/ImageUtils.cs @@ -105,7 +105,7 @@ public static void WriteToTiffImpl(string name, int width, int height, List Date: Thu, 9 Aug 2018 16:59:24 +0200 Subject: [PATCH 153/158] better failsafe mechanisms --- managed/GTAVisionExport/GameUtils.cs | 90 ++++++++++++++++++++-- managed/GTAVisionExport/OffroadPlanning.cs | 30 ++++++-- managed/GTAVisionExport/VisionExport.cs | 58 ++++++++++---- 3 files changed, 150 insertions(+), 28 deletions(-) diff --git a/managed/GTAVisionExport/GameUtils.cs b/managed/GTAVisionExport/GameUtils.cs index 9d78be4..7038138 100644 --- a/managed/GTAVisionExport/GameUtils.cs +++ b/managed/GTAVisionExport/GameUtils.cs @@ -37,12 +37,8 @@ public bool isPassed(int time) { return time >= startTime + interval.TotalMilliseconds; } } - - /// - /// Use to check if vehicle is stuck in some area for some time (e.g. has not moved 1 meter or more from position in last minute) - /// - /// - public class TimeDistanceChecker { + + public abstract class TimeDistanceChecker { public int startTime { get; set; } public bool initialized { get; set; } public TimeSpan interval { get; set; } @@ -59,8 +55,10 @@ public TimeDistanceChecker(TimeSpan interval, int distance, Vector3 center) { } public void clear() { - this.initialized = false; + initialized = false; } + + public abstract bool isDistanceSatisfied(Vector3 position); public bool isPassed(int time, Vector3 position) { //UI.Notify("last time" + this.gameTime); @@ -73,12 +71,88 @@ public bool isPassed(int time, Vector3 position) { } if (time >= startTime + interval.TotalMilliseconds) { - return position.DistanceTo(center) < distance; + return isDistanceSatisfied(position); } return false; } } + /// + /// Use to check if vehicle is stuck in some area for some time (e.g. has not moved 1 meter or more from position in last minute) + /// + /// + public class TimeNearPointChecker : TimeDistanceChecker { + + public TimeNearPointChecker(TimeSpan interval, int distance, Vector3 center) : base(interval, distance, center) { + } + + public override bool isDistanceSatisfied(Vector3 position) { + return position.DistanceTo(center) < distance; + } + } + + /// + /// Use to check if vehicle is stuck in some area for some time (e.g. has not come nearer to a location (not moving to a target)) + /// + public class TimeDistantFromPointChecker : TimeDistanceChecker { + + public TimeDistantFromPointChecker(TimeSpan interval, int distance, Vector3 center) : base(interval, distance, center) { + } + + public override bool isDistanceSatisfied(Vector3 position) { + return position.DistanceTo(center) > distance; + } + + } + + /// + /// Use to check if vehicle is stuck in some area for some time (e.g. has not come nearer to a location (not moving to a target)) + /// Updates distance, checks if min distance is changing or not after some time. + /// + public class TimeNotMovingTowardsPointChecker { + public int startTime { get; set; } + public bool initialized { get; set; } + public TimeSpan interval { get; set; } + public Vector2 center { get; set; } + public float distance; + public float minDistance; + + public TimeNotMovingTowardsPointChecker(TimeSpan interval, Vector2 center) { + /* Game.Gametime is in ms, so 1000000 ms = 16.6 min*/ + startTime = 0; + initialized = false; + this.interval = interval; + this.center = center; + } + + public void clear() { + this.initialized = false; + } + + public bool isPassed(int time, Vector3 position) { + //UI.Notify("last time" + this.gameTime); + //UI.Notify("time now" + time); + if (!initialized) { + startTime = time; + initialized = true; + return false; + } + + distance = center.DistanceTo(new Vector2(position.X, position.Y)); + if (distance < minDistance) { + minDistance = distance; + startTime = time; + } + + if (time >= startTime + interval.TotalMilliseconds) { + return distance > minDistance; + } + return false; + } + + + } + public enum GameStatus { NeedReload, NeedStart, diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index 6e70b13..1e8ec0c 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -27,6 +27,8 @@ public class OffroadPlanning : Script { private static Vector2 currentTarget; private static int targetsFromSameStart = 0; private static List currentArea = null; + static KeyHandling kh = new KeyHandling(); + public OffroadPlanning() { UI.Notify("Loaded OffroadPlanning.cs"); @@ -155,7 +157,7 @@ public static float GetGroundHeightMagic(Vector2 position) { } public static void setNextStart() { - Logger.WriteLine($"setting the next start"); +// Logger.WriteLine($"setting the next start"); currentArea = GetRandomArea(); var startRect = GetRandomRect(currentArea); var start = GetRandomPoint(startRect); @@ -171,6 +173,7 @@ public static void setNextStart() { } targetsFromSameStart = 0; Logger.WriteLine($"setting next start in {newPosition}"); + VisionExport.UINotify($"setting next start in {newPosition}"); } public static void setNextTarget() { @@ -179,7 +182,8 @@ public static void setNextTarget() { } // setting the new start in new area after some number of targets from same start - var targetsPerArea = 10; +// var targetsPerArea = 10; + var targetsPerArea = 5; //5 for testing purpose if (targetsPerArea < targetsFromSameStart || currentArea == null) { setNextStart(); } @@ -196,34 +200,46 @@ public static void setNextTarget() { target = GetRandomPoint(targetRect); } while (target.DistanceTo(new Vector2(playerPos.X, playerPos.Y)) > 200); Logger.WriteLine($"setting next target in {target}"); + VisionExport.UINotify($"setting next target in {target}"); DriveToPoint(target); currentlyDrivingToTarget = true; currentTarget = target; targetsFromSameStart += 1; + VisionExport.clearStuckCheckers(); + VisionExport.LongFarFromTarget.center = currentTarget; } private static void SetTargetAsWaypoint(Vector2 target) { HashFunctions.SetNewWaypoint(target); } + private static Autopilot getAutopilot() { + var field = kh.GetType().GetField("_autopilot", BindingFlags.NonPublic | BindingFlags.Instance); + return (Autopilot) field.GetValue(kh); + } + private static void DriveToPoint(Vector2 target) { SetTargetAsWaypoint(target); - var kh = new KeyHandling(); + Wait(10); //just wait until target is set var inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } - + + public static void DriveToCurrentTarget() { + DriveToPoint(currentTarget); + } + public static List GetRandomArea() { var areaIdx = rnd.Next(areas.Count); - Logger.WriteLine($"randomly selected area index {areaIdx} from {areas.Count} areas"); +// Logger.WriteLine($"randomly selected area index {areaIdx} from {areas.Count} areas"); var area = areas[areaIdx]; - Logger.WriteLine($"selected area: {string.Join(", ", area)}, with size {area.Count}"); +// Logger.WriteLine($"selected area: {string.Join(", ", area)}, with size {area.Count}"); return area; } public static Rect GetRandomRect(List area) { - Logger.WriteLine($"selecting random rect for area with size {area.Count}"); +// Logger.WriteLine($"selecting random rect for area with size {area.Count}"); Logger.ForceFlush(); var volumes = new List(area.Count); for (var i = 0; i < area.Count; i++) { diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 3a7b8ef..1d51919 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -69,9 +69,11 @@ class VisionExport : Script { private Task runTask; private int curSessionId = -1; - private TimeChecker lowSpeedTime = new TimeChecker(TimeSpan.FromSeconds(200)); - private TimeChecker notMovingTime = new TimeChecker(TimeSpan.FromSeconds(30)); - private TimeDistanceChecker distanceFromStart = new TimeDistanceChecker(TimeSpan.FromSeconds(30), 2, new Vector3()); + public static TimeChecker lowSpeedTime = new TimeChecker(TimeSpan.FromMinutes(2)); + public static TimeChecker notMovingTime = new TimeChecker(TimeSpan.FromSeconds(30)); + public static TimeChecker notMovingNorDrivingTime = new TimeChecker(TimeSpan.FromSeconds(6)); + public static TimeNearPointChecker NearPointFromStart = new TimeNearPointChecker(TimeSpan.FromSeconds(60), 10, new Vector3()); + public static TimeNotMovingTowardsPointChecker LongFarFromTarget = new TimeNotMovingTowardsPointChecker(TimeSpan.FromSeconds(90), new Vector2()); private bool isGamePaused = false; // this is for external pause, not for internal pause inside the script private static bool notificationsAllowed = true; private StereoCamera cams; @@ -84,6 +86,7 @@ class VisionExport : Script { //this variable, when true, should be disabling car spawning and autodrive starting here, because offroad has different settings public static bool drivingOffroad; public static bool gatheringData = true; + public static bool triedRestartingAutodrive; public VisionExport() { // loading ini file @@ -375,7 +378,6 @@ public void OnTick(object o, EventArgs e) { switch (checkStatus()) { case GameStatus.NeedReload: - //TODO: need to get a new session and run? Logger.WriteLine("Status is NeedReload"); StopRun(); runTask?.Wait(); @@ -387,7 +389,6 @@ public void OnTick(object o, EventArgs e) { ReloadGame(); break; case GameStatus.NeedStart: - //TODO do the autostart manually or automatically? Logger.WriteLine("Status is NeedStart"); //Autostart(); // use reloading temporarily @@ -523,22 +524,41 @@ public GameStatus checkStatus() { // 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.001f) { + 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) { + 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 (distanceFromStart.isPassed(Game.GameTime, vehicle.Position)) { + 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; } @@ -668,16 +688,20 @@ public static void EnterVehicle() { // player.Character.Alpha = 0; vehicle.Alpha = int.MaxValue; //back to visible, not sure what the exact value means in terms of transparency player.Character.Alpha = int.MaxValue; + vehicle.IsInvincible = true; //very important for offroad } 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)}); } - MethodInfo inf = kh.GetType().GetMethod("AtToggleAutopilot", BindingFlags.NonPublic | BindingFlags.Instance); - inf.Invoke(kh, new object[] {new KeyEventArgs(Keys.J)}); } private void ClearSurroundingVehicles(Vector3 pos, float radius) { @@ -696,14 +720,22 @@ private void ClearSurroundingEverything(float x, float y, float z, float radius) Function.Call(Hash.CLEAR_AREA, x, y, z, radius, false, false, false, false); } + public static void clearStuckCheckers() { + lowSpeedTime.clear(); + notMovingTime.clear(); + notMovingNorDrivingTime.clear(); + NearPointFromStart.clear(); + LongFarFromTarget.clear(); + triedRestartingAutodrive = false; + } + public void ReloadGame() { if (staticCamera) { return; } - lowSpeedTime.clear(); - notMovingTime.clear(); - distanceFromStart.clear(); + clearStuckCheckers(); + /* Process p = Process.GetProcessesByName("Grand Theft Auto V").FirstOrDefault(); if (p != null) @@ -750,7 +782,7 @@ public void TraverseWeather() { } public void OnKeyDown(object o, KeyEventArgs k) { - Logger.WriteLine("VisionExport OnKeyDown called."); +// Logger.WriteLine("VisionExport OnKeyDown called."); switch (k.KeyCode) { case Keys.PageUp: postgresTask?.Wait(); From 6a4d24ada7d7a2bb437a8026bd0516a840a23e01 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 9 Aug 2018 17:30:16 +0200 Subject: [PATCH 154/158] done fixing failsafe mechanisms, sometimes false positives, but much better than before --- managed/GTAVisionExport/GameUtils.cs | 2 ++ managed/GTAVisionExport/OffroadPlanning.cs | 5 +++-- managed/GTAVisionExport/VisionExport.cs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/managed/GTAVisionExport/GameUtils.cs b/managed/GTAVisionExport/GameUtils.cs index 7038138..96de3f3 100644 --- a/managed/GTAVisionExport/GameUtils.cs +++ b/managed/GTAVisionExport/GameUtils.cs @@ -123,6 +123,7 @@ public TimeNotMovingTowardsPointChecker(TimeSpan interval, Vector2 center) { initialized = false; this.interval = interval; this.center = center; + minDistance = float.MaxValue; } public void clear() { @@ -135,6 +136,7 @@ public bool isPassed(int time, Vector3 position) { if (!initialized) { startTime = time; initialized = true; + minDistance = float.MaxValue; return false; } diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index 1e8ec0c..2bb6a14 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -122,7 +122,7 @@ public static void checkDrivingToTarget() { } if (! Game.IsWaypointActive) { - currentlyDrivingToTarget = false; + currentlyDrivingToTarget = false; } @@ -171,7 +171,8 @@ public static void setNextStart() { else { Game.Player.Character.Position = newPosition; } - targetsFromSameStart = 0; + targetsFromSameStart = 0; + currentlyDrivingToTarget = false; Logger.WriteLine($"setting next start in {newPosition}"); VisionExport.UINotify($"setting next start in {newPosition}"); } diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index 1d51919..f92e450 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -726,7 +726,8 @@ public static void clearStuckCheckers() { notMovingNorDrivingTime.clear(); NearPointFromStart.clear(); LongFarFromTarget.clear(); - triedRestartingAutodrive = false; + triedRestartingAutodrive = false; + Logger.WriteLine("clearing checkers"); } public void ReloadGame() { From 308fc7c31951d7ee69861017e7f0d742a8a8d740 Mon Sep 17 00:00:00 2001 From: racinmat Date: Thu, 9 Aug 2018 18:36:56 +0200 Subject: [PATCH 155/158] cleaned db structure sql file, updated --- database_schema_old.sql | 200 ---------- db_schema.sql | 3 +- db_schema_old.sql | 216 ---------- managed/structure_dump.sql | 798 ------------------------------------- 4 files changed, 2 insertions(+), 1215 deletions(-) delete mode 100644 database_schema_old.sql delete mode 100644 db_schema_old.sql delete mode 100644 managed/structure_dump.sql diff --git a/database_schema_old.sql b/database_schema_old.sql deleted file mode 100644 index 2e4e44a..0000000 --- a/database_schema_old.sql +++ /dev/null @@ -1,200 +0,0 @@ -create type detection_type AS ENUM ('background', 'person', 'car', 'bicycle'); - -create type detection_class AS ENUM ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Trains'); - -create type weather AS ENUM ('Unknown', 'ExtraSunny', 'Clear', 'Clouds', 'Smog', 'Foggy', 'Overcast', 'Raining', 'ThunderStorm', 'Clearing', 'Neutral', 'Snowing', 'Blizzard', 'Snowlight', 'Christmas', 'Halloween'); - -create table detections -( - detection_id serial not null - constraint detections_pkey - primary key, - snapshot_id integer, - type detection_type, - pos geometry(PointZ), - bbox box, - class detection_class default 'Unknown'::detection_class, - handle integer default '-1'::integer, - best_bbox box, - best_bbox_old box, - bbox3d box3d, - rot geometry, - coverage real default 0.0, - created timestamp without time zone default (now() at time zone 'utc') -) -; - - -create table runs -( - run_id serial not null - constraint runs_pkey - primary key, - runguid uuid, - archivepath text, - localpath text, - session_id integer default 1, - instance_id integer default 0, - created timestamp without time zone default (now() at time zone 'utc') -) -; - - -create table sessions -( - session_id serial not null - constraint sessions_pkey - primary key, - name text - constraint sessions_name_key - unique, - start timestamp with time zone, - "end" timestamp with time zone, - created timestamp without time zone default (now() at time zone 'utc') -) -; - -alter table runs - add constraint runs_session_fkey - foreign key (session_id) references sessions - on delete cascade -; - -create table snapshots -( - snapshot_id serial not null - constraint snapshots_pkey - primary key, - run_id integer - constraint snapshots_run_fkey - references runs - on delete cascade, - version integer, - imagepath text, - timestamp timestamp with time zone, - timeofday time, - currentweather weather, - camera_pos geometry(PointZ), - camera_direction geometry, - camera_fov real, - view_matrix double precision[], - proj_matrix double precision[], - processed boolean default false not null, - width integer, - height integer -) -; - - -alter table detections - add constraint detections_snapshot_fkey - foreign key (snapshot_id) references snapshots - on delete cascade -; - -create table instances -( - instance_id serial not null - constraint isntances_pkey - primary key, - hostname text, - instanceid text - constraint instanceid_uniq - unique, - instancetype text, - publichostname text, - amiid text, - created timestamp without time zone default (now() at time zone 'utc'), - constraint instance_info_uniq - unique (hostname, instanceid, instancetype, publichostname, amiid) -) -; - -alter table runs - add constraint runs_instance_fkey - foreign key (instance_id) references instances -; - -create table snapshot_weathers -( - weather_id serial not null - constraint snapshot_weathers_pkey - primary key, - snapshot_id integer - constraint snapshot_weathers_snapshot_id_fkey - references snapshots - on delete cascade, - weather_type weather, - snapshot_page integer, - created timestamp without time zone default (now() at time zone 'utc') -) -; - -create table uploads -( - id serial not null - constraint uploads_pkey - primary key, - bucket text, - key text, - uploadid text, - created timestamp without time zone default (now() at time zone 'utc') -) -; - -create table datasets -( - dataset_id serial not null - constraint datasets_pkey - primary key, - dataset_name text, - view_name text, - created timestamp without time zone default (now() at time zone 'utc') -) -; - -create table systems -( - system_uuid uuid not null - constraint systems_pkey - primary key, - vendor text, - dnshostname text, - username text, - systemtype text, - totalmem bigint, - created timestamp without time zone default (now() at time zone 'utc') -) -; - -create table system_graphics -( - system_graphic_id serial not null - constraint system_graphics_pkey - primary key, - deviceid text, - adaptercompatibility text, - adapterdactype text, - adapterram integer, - availability integer, - caption text, - description text, - driverdate timestamp with time zone, - driverversion text, - pnpdeviceid text, - name text, - videoarch integer, - memtype integer, - videoprocessor text, - bpp integer, - hrez integer, - vrez integer, - num_colors integer, - cols integer, - rows integer, - refresh integer, - scanmode integer, - videomodedesc text, - created timestamp without time zone default (now() at time zone 'utc') -) -; \ No newline at end of file diff --git a/db_schema.sql b/db_schema.sql index 41df09e..54272d2 100644 --- a/db_schema.sql +++ b/db_schema.sql @@ -462,7 +462,8 @@ CREATE TABLE public.snapshots ( cam_far_clip real, player_pos public.geometry(PointZ), velocity public.geometry(PointZ), - camera_relative_position public.geometry(PointZ) + camera_relative_position public.geometry(PointZ), + current_target public.geometry(Point) ); diff --git a/db_schema_old.sql b/db_schema_old.sql deleted file mode 100644 index b3a31a4..0000000 --- a/db_schema_old.sql +++ /dev/null @@ -1,216 +0,0 @@ -SET search_path = public, pg_catalog; - - -create type detection_class as enum ('Unknown', 'Compacts', 'Sedans', 'SUVs', 'Coupes', 'Muscle', 'SportsClassics', 'Sports', 'Super', 'Motorcycles', 'OffRoad', 'Industrial', 'Utility', 'Vans', 'Cycles', 'Boats', 'Helicopters', 'Planes', 'Service', 'Emergency', 'Military', 'Commercial', 'Trains') -; - -create type detection_type as enum ('background', 'person', 'car', 'bicycle') -; - -create type weather as enum ('Unknown', 'ExtraSunny', 'Clear', 'Clouds', 'Smog', 'Foggy', 'Overcast', 'Raining', 'ThunderStorm', 'Clearing', 'Neutral', 'Snowing', 'Blizzard', 'Snowlight', 'Christmas', 'Halloween') -; - - -create table datasets -( - dataset_id serial not null - constraint datasets_pkey - primary key, - dataset_name text, - view_name text, - created timestamp default timezone('utc'::text, now()) -) -; - -create table instances -( - instance_id serial not null - constraint isntances_pkey - primary key, - hostname text, - instanceid text - constraint instanceid_uniq - unique, - instancetype text, - publichostname text, - amiid text, - created timestamp default timezone('utc'::text, now()), - constraint instance_info_uniq - unique (hostname, instanceid, instancetype, publichostname, amiid) -) -; - -create table sessions -( - session_id serial not null - constraint sessions_pkey - primary key, - name text - constraint sessions_name_key - unique, - start timestamp with time zone, - "end" timestamp with time zone, - created timestamp default timezone('utc'::text, now()) -) -; - -create table runs -( - run_id serial not null - constraint runs_pkey - primary key, - runguid uuid, - archivepath text, - localpath text, - session_id integer default 1 - constraint runs_session_fkey - references sessions - on delete cascade, - instance_id integer default 0 - constraint runs_instance_fkey - references instances, - created timestamp default timezone('utc'::text, now()) -) -; - -create table snapshots -( - snapshot_id serial not null - constraint snapshots_pkey - primary key, - run_id integer - constraint snapshots_run_fkey - references runs - on delete cascade, - version integer, - scene_id uuid, - imagepath text, - timestamp timestamp with time zone, - timeofday time, - currentweather weather, - camera_pos geometry(PointZ), - camera_rot geometry(PointZ), - camera_relative_rotation geometry(PointZ), - camera_direction geometry, - camera_fov real, - world_matrix double precision[], - view_matrix double precision[], - proj_matrix double precision[], - processed boolean default false not null, - width integer, - height integer, - ui_width integer, - ui_height integer, - cam_near_clip real, - cam_far_clip real, - player_pos geometry(PointZ), - velocity geometry(PointZ), - camera_relative_position geometry(PointZ) -) -; - -create table detections -( - detection_id serial not null - constraint detections_pkey - primary key, - snapshot_id integer - constraint detections_snapshot_fkey - references snapshots - on delete cascade, - type detection_type, - pos geometry(PointZ), - bbox box, - class detection_class default 'Unknown'::detection_class, - handle integer default '-1'::integer, - best_bbox box, - best_bbox_old box, - bbox3d box3d, - rot geometry, - coverage real default 0.0, - created timestamp default timezone('utc'::text, now()), - velocity geometry(PointZ) -) -; - -create index snapshot_index - on detections (snapshot_id) -; - -create index handle_index - on detections (handle) -; - -create table snapshot_weathers -( - weather_id serial not null - constraint snapshot_weathers_pkey - primary key, - snapshot_id integer - constraint snapshot_weathers_snapshot_id_fkey - references snapshots - on delete cascade, - weather_type weather, - snapshot_page integer, - created timestamp default timezone('utc'::text, now()) -) -; - -create table system_graphics -( - system_graphic_id serial not null - constraint system_graphics_pkey - primary key, - deviceid text, - adaptercompatibility text, - adapterdactype text, - adapterram integer, - availability integer, - caption text, - description text, - driverdate timestamp with time zone, - driverversion text, - pnpdeviceid text, - name text, - videoarch integer, - memtype integer, - videoprocessor text, - bpp integer, - hrez integer, - vrez integer, - num_colors integer, - cols integer, - rows integer, - refresh integer, - scanmode integer, - videomodedesc text, - created timestamp default timezone('utc'::text, now()) -) -; - -create table systems -( - system_uuid uuid not null - constraint systems_pkey - primary key, - vendor text, - dnshostname text, - username text, - systemtype text, - totalmem bigint, - created timestamp default timezone('utc'::text, now()) -) -; - -create table uploads -( - id serial not null - constraint uploads_pkey - primary key, - bucket text, - key text, - uploadid text, - created timestamp default timezone('utc'::text, now()) -) -; - diff --git a/managed/structure_dump.sql b/managed/structure_dump.sql deleted file mode 100644 index e7a2fcf..0000000 --- a/managed/structure_dump.sql +++ /dev/null @@ -1,798 +0,0 @@ --- --- PostgreSQL database dump --- - --- Dumped from database version 9.6.5 --- Dumped by pg_dump version 9.6.5 - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = ON; -SET check_function_bodies = FALSE; -SET client_min_messages = WARNING; -SET row_security = OFF; - --- --- Name: postgres; Type: COMMENT; Schema: -; Owner: postgres --- - -COMMENT ON DATABASE postgres IS 'default administrative connection database'; - --- --- Name: tiger; Type: SCHEMA; Schema: -; Owner: postgres --- - -CREATE SCHEMA tiger; - - -ALTER SCHEMA tiger -OWNER TO postgres; - --- --- Name: tiger_data; Type: SCHEMA; Schema: -; Owner: postgres --- - -CREATE SCHEMA tiger_data; - - -ALTER SCHEMA tiger_data -OWNER TO postgres; - --- --- Name: topology; Type: SCHEMA; Schema: -; Owner: postgres --- - -CREATE SCHEMA topology; - - -ALTER SCHEMA topology -OWNER TO postgres; - --- --- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: --- - -CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - --- --- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: --- - -COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - --- --- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: --- - -CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA public; - --- --- Name: EXTENSION fuzzystrmatch; Type: COMMENT; Schema: -; Owner: --- - -COMMENT ON EXTENSION fuzzystrmatch IS 'determine similarities and distance between strings'; - --- --- Name: postgis; Type: EXTENSION; Schema: -; Owner: --- - -CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; - --- --- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: --- - -COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions'; - --- --- Name: postgis_tiger_geocoder; Type: EXTENSION; Schema: -; Owner: --- - -CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder WITH SCHEMA tiger; - --- --- Name: EXTENSION postgis_tiger_geocoder; Type: COMMENT; Schema: -; Owner: --- - -COMMENT ON EXTENSION postgis_tiger_geocoder IS 'PostGIS tiger geocoder and reverse geocoder'; - --- --- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: --- - -CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology; - --- --- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner: --- - -COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions'; - - -SET search_path = public, pg_catalog; - --- --- Name: detection_class; Type: TYPE; Schema: public; Owner: postgres --- - -CREATE TYPE DETECTION_CLASS AS ENUM ( - 'Unknown', - 'Compacts', - 'Sedans', - 'SUVs', - 'Coupes', - 'Muscle', - 'SportsClassics', - 'Sports', - 'Super', - 'Motorcycles', - 'OffRoad', - 'Industrial', - 'Utility', - 'Vans', - 'Cycles', - 'Boats', - 'Helicopters', - 'Planes', - 'Service', - 'Emergency', - 'Military', - 'Commercial', - 'Trains' -); - - -ALTER TYPE DETECTION_CLASS - OWNER TO postgres; - --- --- Name: detection_type; Type: TYPE; Schema: public; Owner: postgres --- - -CREATE TYPE DETECTION_TYPE AS ENUM ( - 'background', - 'person', - 'car', - 'bicycle' -); - - -ALTER TYPE DETECTION_TYPE - OWNER TO postgres; - --- --- Name: weather; Type: TYPE; Schema: public; Owner: postgres --- - -CREATE TYPE WEATHER AS ENUM ( - 'Unknown', - 'ExtraSunny', - 'Clear', - 'Clouds', - 'Smog', - 'Foggy', - 'Overcast', - 'Raining', - 'ThunderStorm', - 'Clearing', - 'Neutral', - 'Snowing', - 'Blizzard', - 'Snowlight', - 'Christmas', - 'Halloween' -); - - -ALTER TYPE WEATHER - OWNER TO postgres; - -SET default_tablespace = ''; - -SET default_with_oids = FALSE; - --- --- Name: datasets; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE datasets ( - dataset_id INTEGER NOT NULL, - dataset_name TEXT, - view_name TEXT, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) -); - - -ALTER TABLE datasets - OWNER TO postgres; - --- --- Name: datasets_dataset_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE datasets_dataset_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE datasets_dataset_id_seq - OWNER TO postgres; - --- --- Name: datasets_dataset_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE datasets_dataset_id_seq -OWNED BY datasets.dataset_id; - --- --- Name: detections; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE detections -( - detection_id SERIAL NOT NULL, - snapshot_id INTEGER, - type DETECTION_TYPE, - pos GEOMETRY(PointZ), - bbox BOX, - class DETECTION_CLASS DEFAULT 'Unknown' :: DETECTION_CLASS, - handle INTEGER DEFAULT '-1' :: INTEGER, - best_bbox BOX, - best_bbox_old BOX, - bbox3d BOX3D, - rot GEOMETRY, - coverage REAL DEFAULT 0.0, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'utc'), - velocity GEOMETRY(PointZ) -); -ALTER TABLE detections - OWNER TO postgres; - --- --- Name: detections_detection_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE detections_detection_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE detections_detection_id_seq - OWNER TO postgres; - --- --- Name: detections_detection_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE detections_detection_id_seq -OWNED BY detections.detection_id; - --- --- Name: instances; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE instances ( - instance_id INTEGER NOT NULL, - hostname TEXT, - instanceid TEXT, - instancetype TEXT, - publichostname TEXT, - amiid TEXT, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) -); - - -ALTER TABLE instances - OWNER TO postgres; - --- --- Name: instances_instance_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE instances_instance_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE instances_instance_id_seq - OWNER TO postgres; - --- --- Name: instances_instance_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE instances_instance_id_seq -OWNED BY instances.instance_id; - --- --- Name: runs; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE runs ( - run_id INTEGER NOT NULL, - runguid UUID, - archivepath TEXT, - localpath TEXT, - session_id INTEGER DEFAULT 1, - instance_id INTEGER DEFAULT 0, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) -); - - -ALTER TABLE runs - OWNER TO postgres; - --- --- Name: runs_run_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE runs_run_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE runs_run_id_seq - OWNER TO postgres; - --- --- Name: runs_run_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE runs_run_id_seq -OWNED BY runs.run_id; - --- --- Name: sessions; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE sessions ( - session_id INTEGER NOT NULL, - name TEXT, - start TIMESTAMP WITH TIME ZONE, - "end" TIMESTAMP WITH TIME ZONE, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) -); - - -ALTER TABLE sessions - OWNER TO postgres; - --- --- Name: sessions_session_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE sessions_session_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE sessions_session_id_seq - OWNER TO postgres; - --- --- Name: sessions_session_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE sessions_session_id_seq -OWNED BY sessions.session_id; - --- --- Name: snapshot_weathers; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE snapshot_weathers ( - weather_id INTEGER NOT NULL, - snapshot_id INTEGER, - weather_type WEATHER, - snapshot_page INTEGER, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) -); - - -ALTER TABLE snapshot_weathers - OWNER TO postgres; - --- --- Name: snapshot_weathers_weather_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE snapshot_weathers_weather_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE snapshot_weathers_weather_id_seq - OWNER TO postgres; - --- --- Name: snapshot_weathers_weather_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE snapshot_weathers_weather_id_seq -OWNED BY snapshot_weathers.weather_id; - - -CREATE TABLE snapshots -( - snapshot_id SERIAL NOT NULL, - run_id INTEGER, - version INTEGER, - scene_id UUID, - imagepath TEXT, - timestamp TIMESTAMP WITH TIME ZONE, - timeofday TIME, - currentweather WEATHER, - camera_pos GEOMETRY(PointZ), - camera_rot GEOMETRY(PointZ), - camera_relative_rotation GEOMETRY(PointZ), - camera_direction GEOMETRY, - car_model_box box3d, - camera_fov REAL, - world_matrix DOUBLE PRECISION [], - view_matrix DOUBLE PRECISION [], - proj_matrix DOUBLE PRECISION [], - processed BOOLEAN DEFAULT FALSE NOT NULL, - width INTEGER, - height INTEGER, - ui_width INTEGER, - ui_height INTEGER, - cam_near_clip REAL, - cam_far_clip REAL, - player_pos GEOMETRY(PointZ), - velocity GEOMETRY(PointZ) -); - - -ALTER TABLE snapshots - OWNER TO postgres; - --- --- Name: snapshots_snapshot_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE snapshots_snapshot_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE snapshots_snapshot_id_seq - OWNER TO postgres; - --- --- Name: snapshots_snapshot_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE snapshots_snapshot_id_seq -OWNED BY snapshots.snapshot_id; - --- --- Name: system_graphics; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE system_graphics ( - system_graphic_id INTEGER NOT NULL, - deviceid TEXT, - adaptercompatibility TEXT, - adapterdactype TEXT, - adapterram INTEGER, - availability INTEGER, - caption TEXT, - description TEXT, - driverdate TIMESTAMP WITH TIME ZONE, - driverversion TEXT, - pnpdeviceid TEXT, - name TEXT, - videoarch INTEGER, - memtype INTEGER, - videoprocessor TEXT, - bpp INTEGER, - hrez INTEGER, - vrez INTEGER, - num_colors INTEGER, - cols INTEGER, - rows INTEGER, - refresh INTEGER, - scanmode INTEGER, - videomodedesc TEXT, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) -); - - -ALTER TABLE system_graphics - OWNER TO postgres; - --- --- Name: system_graphics_system_graphic_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE system_graphics_system_graphic_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE system_graphics_system_graphic_id_seq - OWNER TO postgres; - --- --- Name: system_graphics_system_graphic_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE system_graphics_system_graphic_id_seq -OWNED BY system_graphics.system_graphic_id; - --- --- Name: systems; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE systems ( - system_uuid UUID NOT NULL, - vendor TEXT, - dnshostname TEXT, - username TEXT, - systemtype TEXT, - totalmem BIGINT, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) -); - - -ALTER TABLE systems - OWNER TO postgres; - --- --- Name: uploads; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE uploads ( - id INTEGER NOT NULL, - bucket TEXT, - key TEXT, - uploadid TEXT, - created TIMESTAMP WITHOUT TIME ZONE DEFAULT timezone('utc' :: TEXT, now()) -); - - -ALTER TABLE uploads - OWNER TO postgres; - --- --- Name: uploads_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE uploads_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE uploads_id_seq - OWNER TO postgres; - --- --- Name: uploads_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE uploads_id_seq -OWNED BY uploads.id; - --- --- Name: datasets dataset_id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY datasets - ALTER COLUMN dataset_id SET DEFAULT nextval('datasets_dataset_id_seq' :: REGCLASS); - --- --- Name: detections detection_id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY detections - ALTER COLUMN detection_id SET DEFAULT nextval('detections_detection_id_seq' :: REGCLASS); - --- --- Name: instances instance_id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY instances - ALTER COLUMN instance_id SET DEFAULT nextval('instances_instance_id_seq' :: REGCLASS); - --- --- Name: runs run_id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY runs - ALTER COLUMN run_id SET DEFAULT nextval('runs_run_id_seq' :: REGCLASS); - --- --- Name: sessions session_id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY sessions - ALTER COLUMN session_id SET DEFAULT nextval('sessions_session_id_seq' :: REGCLASS); - --- --- Name: snapshot_weathers weather_id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY snapshot_weathers - ALTER COLUMN weather_id SET DEFAULT nextval('snapshot_weathers_weather_id_seq' :: REGCLASS); - --- --- Name: snapshots snapshot_id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY snapshots - ALTER COLUMN snapshot_id SET DEFAULT nextval('snapshots_snapshot_id_seq' :: REGCLASS); - --- --- Name: system_graphics system_graphic_id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY system_graphics - ALTER COLUMN system_graphic_id SET DEFAULT nextval('system_graphics_system_graphic_id_seq' :: REGCLASS); - --- --- Name: uploads id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY uploads - ALTER COLUMN id SET DEFAULT nextval('uploads_id_seq' :: REGCLASS); - --- --- Name: datasets datasets_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY datasets - ADD CONSTRAINT datasets_pkey PRIMARY KEY (dataset_id); - --- --- Name: detections detections_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY detections - ADD CONSTRAINT detections_pkey PRIMARY KEY (detection_id); - --- --- Name: instances instance_info_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY instances - ADD CONSTRAINT instance_info_uniq UNIQUE (hostname, instanceid, instancetype, publichostname, amiid); - --- --- Name: instances instanceid_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY instances - ADD CONSTRAINT instanceid_uniq UNIQUE (instanceid); - --- --- Name: instances isntances_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY instances - ADD CONSTRAINT isntances_pkey PRIMARY KEY (instance_id); - --- --- Name: runs runs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY runs - ADD CONSTRAINT runs_pkey PRIMARY KEY (run_id); - --- --- Name: sessions sessions_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY sessions - ADD CONSTRAINT sessions_name_key UNIQUE (name); - --- --- Name: sessions sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY sessions - ADD CONSTRAINT sessions_pkey PRIMARY KEY (session_id); - --- --- Name: snapshot_weathers snapshot_weathers_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY snapshot_weathers - ADD CONSTRAINT snapshot_weathers_pkey PRIMARY KEY (weather_id); - --- --- Name: snapshots snapshots_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY snapshots - ADD CONSTRAINT snapshots_pkey PRIMARY KEY (snapshot_id); - --- --- Name: system_graphics system_graphics_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY system_graphics - ADD CONSTRAINT system_graphics_pkey PRIMARY KEY (system_graphic_id); - --- --- Name: systems systems_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY systems - ADD CONSTRAINT systems_pkey PRIMARY KEY (system_uuid); - --- --- Name: uploads uploads_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY uploads - ADD CONSTRAINT uploads_pkey PRIMARY KEY (id); - --- --- Name: detections detections_snapshot_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY detections - ADD CONSTRAINT detections_snapshot_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots (snapshot_id) ON DELETE CASCADE; - --- --- Name: runs runs_instance_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY runs - ADD CONSTRAINT runs_instance_fkey FOREIGN KEY (instance_id) REFERENCES instances (instance_id); - --- --- Name: runs runs_session_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY runs - ADD CONSTRAINT runs_session_fkey FOREIGN KEY (session_id) REFERENCES sessions (session_id) ON DELETE CASCADE; - --- --- Name: snapshot_weathers snapshot_weathers_snapshot_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY snapshot_weathers - ADD CONSTRAINT snapshot_weathers_snapshot_id_fkey FOREIGN KEY (snapshot_id) REFERENCES snapshots (snapshot_id) ON DELETE CASCADE; - --- --- Name: snapshots snapshots_run_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY snapshots - ADD CONSTRAINT snapshots_run_fkey FOREIGN KEY (run_id) REFERENCES runs (run_id) ON DELETE CASCADE; - --- --- PostgreSQL database dump complete --- - From e0ed3c3502301e6f6792d632b69225aaca0869e1 Mon Sep 17 00:00:00 2001 From: racinmat Date: Fri, 10 Aug 2018 10:03:46 +0200 Subject: [PATCH 156/158] fixed sql for current target --- managed/GTAVisionExport/OffroadPlanning.cs | 8 +++--- managed/GTAVisionExport/VisionExport.cs | 14 ++++++++--- managed/GTAVisionUtils/GTADataStructures.cs | 6 +++++ managed/GTAVisionUtils/PostgresExport.cs | 27 +++++++++++++-------- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/managed/GTAVisionExport/OffroadPlanning.cs b/managed/GTAVisionExport/OffroadPlanning.cs index 2bb6a14..c228da3 100644 --- a/managed/GTAVisionExport/OffroadPlanning.cs +++ b/managed/GTAVisionExport/OffroadPlanning.cs @@ -24,7 +24,7 @@ public class OffroadPlanning : Script { public static bool offroadDrivingStarted; private static bool currentlyDrivingToTarget; - private static Vector2 currentTarget; + public static Vector2? currentTarget = null; private static int targetsFromSameStart = 0; private static List currentArea = null; static KeyHandling kh = new KeyHandling(); @@ -117,7 +117,7 @@ private void OnKeyUp(object sender, KeyEventArgs e) { } public static void checkDrivingToTarget() { - if (Game.Player.Character.CurrentVehicle.Position.DistanceTo2D(new Vector3(currentTarget.X, currentTarget.Y, 0)) < 3) { + if (Game.Player.Character.CurrentVehicle.Position.DistanceTo2D(new Vector3(currentTarget.Value.X, currentTarget.Value.Y, 0)) < 3) { currentlyDrivingToTarget = false; } @@ -208,7 +208,7 @@ public static void setNextTarget() { currentTarget = target; targetsFromSameStart += 1; VisionExport.clearStuckCheckers(); - VisionExport.LongFarFromTarget.center = currentTarget; + VisionExport.LongFarFromTarget.center = currentTarget.Value; } private static void SetTargetAsWaypoint(Vector2 target) { @@ -228,7 +228,7 @@ private static void DriveToPoint(Vector2 target) { } public static void DriveToCurrentTarget() { - DriveToPoint(currentTarget); + DriveToPoint(currentTarget.Value); } public static List GetRandomArea() { diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index f92e450..2347572 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -73,7 +73,7 @@ class VisionExport : Script { public static TimeChecker notMovingTime = new TimeChecker(TimeSpan.FromSeconds(30)); public static TimeChecker notMovingNorDrivingTime = new TimeChecker(TimeSpan.FromSeconds(6)); public static TimeNearPointChecker NearPointFromStart = new TimeNearPointChecker(TimeSpan.FromSeconds(60), 10, new Vector3()); - public static TimeNotMovingTowardsPointChecker LongFarFromTarget = new TimeNotMovingTowardsPointChecker(TimeSpan.FromSeconds(90), new Vector2()); + public static TimeNotMovingTowardsPointChecker LongFarFromTarget = new TimeNotMovingTowardsPointChecker(TimeSpan.FromMinutes(2.5), new Vector2()); private bool isGamePaused = false; // this is for external pause, not for internal pause inside the script private static bool notificationsAllowed = true; private StereoCamera cams; @@ -492,6 +492,13 @@ private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { else { dat.CamRelativePos = null; } + + if (drivingOffroad && OffroadPlanning.currentTarget != null) { + dat.CurrentTarget =GTAVector2.fromVector2(OffroadPlanning.currentTarget.Value); + } + else { + dat.CurrentTarget = null; + } dat.sceneGuid = guid; @@ -503,7 +510,7 @@ private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { success = saveSnapshotToFile(dat.ImageName, wantedWeathers, false); } else { - Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; + Weather weather = currentWeather ? World.Weather : wantedWeather; success = saveSnapshotToFile(dat.ImageName, weather, false); } @@ -538,7 +545,8 @@ public GameStatus checkStatus() { UINotify("needed reload by staying in place 30 seconds"); return GameStatus.NeedReload; } - if (notMovingNorDrivingTime.isPassed(Game.GameTime) && !triedRestartingAutodrive) { +// 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) { diff --git a/managed/GTAVisionUtils/GTADataStructures.cs b/managed/GTAVisionUtils/GTADataStructures.cs index fd81935..bcdda84 100644 --- a/managed/GTAVisionUtils/GTADataStructures.cs +++ b/managed/GTAVisionUtils/GTADataStructures.cs @@ -13,6 +13,7 @@ using SharpDX.Mathematics; using NativeUI; using System.Drawing; +using Amazon.KeyManagementService.Model.Internal.MarshallTransformations; using MathNet.Numerics.LinearAlgebra.Double; using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics; @@ -153,6 +154,10 @@ public class GTAVector2 public float X { get; set; } public float Y { get; set; } + public static GTAVector2 fromVector2(Vector2 vector2) { + return new GTAVector2(vector2.X, vector2.Y); + } + public GTAVector2(float x, float y) { X = x; @@ -201,6 +206,7 @@ public class GTAData public Guid sceneGuid { get; set; } public GTAVector CamRelativeRot { get; set; } public GTAVector CamRelativePos { get; set; } + public GTAVector2 CurrentTarget { get; set; } public List Detections { get; set; } public static SharpDX.Vector3 CvtVec(GTA.Math.Vector3 inp) { diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 8e7a7be..3934ee2 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -174,7 +174,7 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { cmd.Parameters.AddWithValue("@relative_rot_y", data.CamRelativeRot.Y); cmd.Parameters.AddWithValue("@relative_rot_z", data.CamRelativeRot.Z); } - + var camRelativePosString = "NULL"; if (data.CamRelativePos != null) { camRelativePosString = "ST_MakePoint(@relative_pos_x, @relative_pos_y, @relative_pos_z)"; @@ -195,18 +195,25 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { cmd.Parameters.AddWithValue("@cam_box_max_z", data.CarModelBox.Maximum.Z); } + var currentTarget = "NULL"; + if (data.CurrentTarget != null) { + carModelBoxString = "ST_MakePoint(@target_x, @target_y)"; + cmd.Parameters.AddWithValue("@target_x", data.CurrentTarget.X); + cmd.Parameters.AddWithValue("@target_y", data.CurrentTarget.Y); + } + cmd.Connection = conn; cmd.Transaction = trans; cmd.CommandText = - "INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, camera_rot, " + - "camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, player_pos, " + - "cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation, camera_relative_position, car_model_box, world_matrix) " + - "VALUES ( (SELECT run_id FROM runs WHERE runguid=@guid), " + - "@Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), ST_MakePoint(@rotx, @roty, @rotz), " + - "ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, @width, @height, @ui_width, @ui_height, " + - "ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, @cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id, " + - camRelativeRotString + ", " + camRelativePosString + ", " + carModelBoxString + ", @world_matrix) " + - "RETURNING snapshot_id;"; + $"INSERT INTO snapshots (run_id, version, imagepath, timestamp, timeofday, currentweather, camera_pos, " + + $"camera_rot, camera_direction, camera_fov, view_matrix, proj_matrix, width, height, ui_width, ui_height, " + + $"player_pos, cam_near_clip, cam_far_clip, velocity, scene_id, camera_relative_rotation, " + + $"camera_relative_position, car_model_box, world_matrix, current_target) VALUES ( (SELECT run_id FROM runs WHERE " + + $"runguid=@guid), @Version, @Imagepath, @Timestamp, @Timeofday, @currentweather, ST_MakePoint(@x, @y, @z), " + + $"ST_MakePoint(@rotx, @roty, @rotz), ST_MakePoint(@dirx, @diry, @dirz), @fov, @view_matrix, @proj_matrix, " + + $"@width, @height, @ui_width, @ui_height, ST_MakePoint(@player_x, @player_y, @player_z), @cam_near_clip, " + + $"@cam_far_clip, ST_MakePoint(@vel_x, @vel_y, @vel_z), @scene_id, {camRelativeRotString}, " + + $"{camRelativePosString}, {carModelBoxString}, @world_matrix, {currentTarget}) RETURNING snapshot_id;"; cmd.Parameters.Add(new NpgsqlParameter("@version", data.Version)); cmd.Parameters.Add(new NpgsqlParameter("@imagepath", data.ImageName)); cmd.Parameters.Add(new NpgsqlParameter("@timestamp", data.Timestamp)); From 1f87aadf4cf18caf5688bb567b3f8a2288851961 Mon Sep 17 00:00:00 2001 From: racinmat Date: Mon, 13 Aug 2018 12:54:09 +0200 Subject: [PATCH 157/158] fixed sql for inserting current target --- managed/GTAVisionUtils/PostgresExport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/managed/GTAVisionUtils/PostgresExport.cs b/managed/GTAVisionUtils/PostgresExport.cs index 3934ee2..5bb501d 100644 --- a/managed/GTAVisionUtils/PostgresExport.cs +++ b/managed/GTAVisionUtils/PostgresExport.cs @@ -197,7 +197,7 @@ public static void SaveSnapshotImpl(GTAData data, Guid runId) { var currentTarget = "NULL"; if (data.CurrentTarget != null) { - carModelBoxString = "ST_MakePoint(@target_x, @target_y)"; + currentTarget = "ST_MakePoint(@target_x, @target_y)"; cmd.Parameters.AddWithValue("@target_x", data.CurrentTarget.X); cmd.Parameters.AddWithValue("@target_y", data.CurrentTarget.Y); } From d841d9d7f3de7fefdf534da07cb8d9d7330605f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Ra=C4=8Dinsk=C3=BD?= Date: Tue, 28 Jan 2020 00:00:31 +0100 Subject: [PATCH 158/158] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 51a0819..fd1f5dd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # GTAVisionExport -Code to export full segmentations from GTA +Code to export full segmentations and depth data from GTA V, used for Matěj Račinský's master thesis, available [here](https://dspace.cvut.cz/handle/10467/76430), heavily modified from the original paper using the repo.