diff --git a/database_schema.sql b/database_schema.sql new file mode 100644 index 0000000..2e4e44a --- /dev/null +++ b/database_schema.sql @@ -0,0 +1,200 @@ +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/managed/GTAVisionExport/GTAVisionExport.csproj b/managed/GTAVisionExport/GTAVisionExport.csproj index 3f425f4..40d7973 100644 --- a/managed/GTAVisionExport/GTAVisionExport.csproj +++ b/managed/GTAVisionExport/GTAVisionExport.csproj @@ -74,9 +74,8 @@ ..\packages\Microsoft.Extensions.Logging.Abstractions.1.1.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll - - False - G:\games\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\NativeUI.dll + + C:\Program Files\Rockstar Games\Grand Theft Auto V\Scripts\NativeUI.dll ..\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll @@ -84,10 +83,7 @@ - ..\..\..\..\..\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 + C:\Program Files\Rockstar Games\Grand Theft Auto V\ScriptHookVDotNet2.dll @@ -113,10 +109,10 @@ - G:\games\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + C:\Program Files\Rockstar Games\Grand Theft Auto V\Scripts\VAutodrive.dll - G:\games\SteamLibrary\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + C:\Program Files\Rockstar Games\Grand Theft Auto V\Scripts\VCommonFunctions.dll diff --git a/managed/GTAVisionExport/VisionExport.cs b/managed/GTAVisionExport/VisionExport.cs index e94b456..9eb2bbd 100644 --- a/managed/GTAVisionExport/VisionExport.cs +++ b/managed/GTAVisionExport/VisionExport.cs @@ -67,6 +67,7 @@ class VisionExport : Script private speedAndTime lowSpeedTime = new speedAndTime(); private bool IsGamePaused = false; private StereoCamera cams; + private bool notificationsEnabled = true; public VisionExport() { // loading ini file @@ -105,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()); + if(notificationsEnabled) UI.Notify("handlePipeInput called"); + if (notificationsEnabled) UI.Notify("server connected:" + server.Connected.ToString()); + if (notificationsEnabled) UI.Notify(connection == null ? "connection is null" : "connection:" + connection.ToString()); if (connection == null) return; byte[] inBuffer = new byte[1024]; @@ -133,7 +134,7 @@ private void handlePipeInput() connection = null; return; } - UI.Notify(str.Length.ToString()); + if (notificationsEnabled) UI.Notify(str.Length.ToString()); switch (str) { case "START_SESSION": @@ -150,7 +151,7 @@ private void handlePipeInput() ToggleNavigation(); break; case "ENTER_VEHICLE": - UI.Notify("Trying to enter vehicle"); + if (notificationsEnabled) UI.Notify("Trying to enter vehicle"); EnterVehicle(); break; case "AUTOSTART": @@ -219,7 +220,7 @@ public void OnTick(object o, EventArgs e) if (server.Poll(10, SelectMode.SelectRead) && connection == null) { connection = server.Accept(); - UI.Notify("CONNECTED"); + if (notificationsEnabled) UI.Notify("CONNECTED"); connection.Blocking = false; } handlePipeInput(); @@ -234,9 +235,9 @@ public void OnTick(object o, EventArgs e) StopRun(); runTask?.Wait(); runTask = StartRun(); - //StopSession(); - //Autostart(); - UI.Notify("need reload game"); + //StopSession(); + //Autostart(); + if (notificationsEnabled) UI.Notify("need reload game"); Script.Wait(100); ReloadGame(); break; @@ -284,11 +285,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[0].Length.ToString()); + //UI.Notify("DIFF: " + (colorframe - depthframe) + " FRAMETIME: " + (1 / Game.FPS) * 1000); + if (notificationsEnabled) UI.Notify(colors[0].Length.ToString()); if (depth == null || stencil == null) { - UI.Notify("No DEPTH"); + if (notificationsEnabled) UI.Notify("No DEPTH"); return; } @@ -499,24 +500,39 @@ public void TraverseWeather() public void OnKeyDown(object o, KeyEventArgs k) { System.IO.File.AppendAllText(logFilePath, "VisionExport OnKeyDown called.\n"); + + if (k.KeyCode == Keys.Z) + { + if (notificationsEnabled) + { + UI.Notify("Notifications Disabled"); + notificationsEnabled = false; + } + else + { + UI.Notify("Notifications Enabled"); + notificationsEnabled = true; + + } + } if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); - UI.Notify("GTA Vision Enabled"); + if (notificationsEnabled) UI.Notify("GTA Vision Enabled"); } if (k.KeyCode == Keys.PageDown) { StopRun(); StopSession(); - UI.Notify("GTA Vision Disabled"); + if (notificationsEnabled) UI.Notify("GTA Vision Disabled"); } if (k.KeyCode == Keys.H) // temp modification { EnterVehicle(); - UI.Notify("Trying to enter vehicle"); + if (notificationsEnabled) UI.Notify("Trying to enter vehicle"); ToggleNavigation(); } if (k.KeyCode == Keys.Y) // temp modification @@ -530,7 +546,7 @@ public void OnKeyDown(object o, KeyEventArgs k) //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); var str = settings.GetValue("", "ConnectionString"); - UI.Notify(loc); + if (notificationsEnabled) UI.Notify(loc); } if (k.KeyCode == Keys.G) // temp modification @@ -580,7 +596,7 @@ 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); + if (notificationsEnabled) UI.Notify("" + test); World.CurrentDayTime = new TimeSpan(12, 0, 0); //Script.Wait(5000); } @@ -634,7 +650,7 @@ 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()); + if (notificationsEnabled) UI.Notify(GameplayCamera.FieldOfView.ToString()); //UI.Notify((connection != null && connection.Connected).ToString()); @@ -681,8 +697,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); + if (notificationsEnabled) UI.Notify(info.type); + if (notificationsEnabled) UI.Notify(info.publichostname); } } } diff --git a/managed/GTAVisionUtils/GTAVisionUtils.csproj b/managed/GTAVisionUtils/GTAVisionUtils.csproj index da3620b..28fca82 100644 --- a/managed/GTAVisionUtils/GTAVisionUtils.csproj +++ b/managed/GTAVisionUtils/GTAVisionUtils.csproj @@ -66,7 +66,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 + C:\Program Files\Rockstar Games\Grand Theft Auto V\Scripts\NativeUI.dll ..\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll @@ -80,10 +80,7 @@ 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 + C:\Program Files\Rockstar Games\Grand Theft Auto V\ScriptHookVDotNet2.dll ..\packages\SharpDX.3.1.1\lib\net45\SharpDX.dll @@ -114,10 +111,10 @@ - ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Grand Theft Auto V\scripts\VAutodrive.dll + C:\Program Files\Rockstar Games\Grand Theft Auto V\Scripts\VAutodrive.dll - ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Grand Theft Auto V\scripts\VCommonFunctions.dll + C:\Program Files\Rockstar Games\Grand Theft Auto V\Scripts\VCommonFunctions.dll diff --git a/native/src/export.cpp b/native/src/export.cpp index b71cefe..2542a4a 100644 --- a/native/src/export.cpp +++ b/native/src/export.cpp @@ -44,8 +44,10 @@ static time_point last_constant_time; static void unpack_depth(ID3D11Device* dev, ID3D11DeviceContext* ctx, ID3D11Resource* src, vector& dst, vector& stencil) { HRESULT hr = S_OK; - + int screenResX; + int screenResY; ComPtr src_tex; + GRAPHICS::GET_SCREEN_RESOLUTION(&screenResX, &screenResY); hr = src->QueryInterface(__uuidof(ID3D11Texture2D), &src_tex); if (hr != S_OK) throw std::system_error(hr, std::system_category()); @@ -57,17 +59,43 @@ static void unpack_depth(ID3D11Device* dev, ID3D11DeviceContext* ctx, ID3D11Reso if (hr != S_OK) throw std::system_error(hr, std::system_category()); if (dst.size() != src_desc.Height * src_desc.Width * 4) dst = vector(src_desc.Height * src_desc.Width * 4); if (stencil.size() != src_desc.Height * src_desc.Width) stencil = vector(src_desc.Height * src_desc.Width); - for (int x = 0; x < src_desc.Width; ++x) + + if (screenResX >= src_desc.Width) { - for (int y = 0; y < src_desc.Height; ++y) + for (int x = 0; x < src_desc.Width; ++x) + { + for (int y = 0; y < src_desc.Height; ++y) + { + const float* src_f = (const float*)((const char*)src_map.pData + src_map.RowPitch*y + (x * 8)); + unsigned char* dst_p = &dst[src_desc.Width * 4 * y + (x * 4)]; + unsigned char* stencil_p = &stencil[src_desc.Width * y + x]; + memmove(dst_p, src_f, 4); + memmove(stencil_p, src_f + 1, 1); + } + } + } + else + { + // resample, for when depth map is bigger than screen image. + float scale = ((float) src_desc.Width) / ((float) screenResX); + dst = vector(screenResY * screenResX * 4); + + for (int x = 0; x < screenResX; ++x) // screenResX { - const float* src_f = (const float*)((const char*)src_map.pData + src_map.RowPitch*y + (x * 8)); - unsigned char* dst_p = &dst[src_desc.Width * 4 * y + (x * 4)]; - unsigned char* stencil_p = &stencil[src_desc.Width * y + x]; - memmove(dst_p, src_f, 4); - memmove(stencil_p, src_f + 1, 1); + int scaledX = int(x*scale); + + for (int y = 0; y < screenResY; ++y) //screenResY + { + int scaledY = int(y*scale); + const float* src_f = (const float*)((const char*)src_map.pData + int(src_map.RowPitch*scaledY + (scaledX * 8))); + unsigned char* dst_p = &dst[screenResX * 4 * y + (x * 4)]; + unsigned char* stencil_p = &stencil[screenResX * y + x]; + memmove(dst_p, src_f, 4); + memmove(stencil_p, src_f + 1, 1); + } } } + ctx->Unmap(src, 0); } static ComPtr CreateTexHelper(ID3D11Device* dev, DXGI_FORMAT fmt, int width, int height, int samples) @@ -255,4 +283,4 @@ extern "C" { __declspec(dllexport) long long int export_get_current_time() { return duration_cast(high_resolution_clock::now().time_since_epoch()).count(); } -} \ No newline at end of file +}