コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public void OnKeyDown(object o, KeyEventArgs k)
        {
//            Logger.WriteLine("VisionExport OnKeyDown called.");
            switch (k.KeyCode)
            {
            case Keys.PageUp:
                postgresTask?.Wait();
                postgresTask = StartSession();
                runTask?.Wait();
                runTask = StartRun();
                UINotify("GTA Vision Enabled");
//                there is set weather, just for testing
                World.Weather = wantedWeather;
                break;

            case Keys.PageDown:
                if (staticCamera)
                {
                    CamerasList.Deactivate();
                }
                StopRun();
                StopSession();
                UINotify("GTA Vision Disabled");
                break;

            // temp modification
            case Keys.H:
                EnterVehicle();
                UINotify("Trying to enter vehicle");
                ToggleNavigation();
                break;

            // temp modification
            case Keys.Y:
                ReloadGame();
                break;

            // temp modification
            case Keys.X:
                notificationsAllowed = !notificationsAllowed;
                if (notificationsAllowed)
                {
                    UI.Notify("Notifications Enabled");
                }
                else
                {
                    UI.Notify("Notifications Disabled");
                }

                break;

            // temp modification
            case Keys.U:
                var settings = ScriptSettings.Load("GTAVisionExport.xml");
                var loc      = AppDomain.CurrentDomain.BaseDirectory;

                //UINotify(ConfigurationManager.AppSettings["database_connection"]);
                var str = settings.GetValue("", "ConnectionString");
                UINotify("BaseDirectory: " + loc);
                UINotify("ConnectionString: " + str);
                break;

            // temp modification
            case Keys.G:
                /*
                 * IsGamePaused = true;
                 * Game.Pause(true);
                 * Script.Wait(500);
                 * TraverseWeather();
                 * Script.Wait(500);
                 * IsGamePaused = false;
                 * Game.Pause(false);
                 */
                GTAData data;
                if (multipleWeathers)
                {
                    data = GTAData.DumpData(Game.GameTime + ".tiff", wantedWeathers.ToList());
                }
                else
                {
                    Weather weather = currentWeather ? GTA.World.Weather : wantedWeather;
                    data = GTAData.DumpData(Game.GameTime + ".tiff", weather);
                }

                string path = @"D:\GTAV_extraction_output\trymatrix.txt";
                // This text is added only once to the file.
                if (!File.Exists(path))
                {
                    // Create a file to write to.
                    using (StreamWriter file = File.CreateText(path)) {
                        file.WriteLine("cam direction file");
                        file.WriteLine("direction:");
                        file.WriteLine(
                            $"{World.RenderingCamera.Direction.X} {World.RenderingCamera.Direction.Y} {World.RenderingCamera.Direction.Z}");
                        file.WriteLine("Dot Product:");
                        file.WriteLine(Vector3.Dot(World.RenderingCamera.Direction, World.RenderingCamera.Rotation));
                        file.WriteLine("position:");
                        file.WriteLine(
                            $"{World.RenderingCamera.Position.X} {World.RenderingCamera.Position.Y} {World.RenderingCamera.Position.Z}");
                        file.WriteLine("rotation:");
                        file.WriteLine(
                            $"{World.RenderingCamera.Rotation.X} {World.RenderingCamera.Rotation.Y} {World.RenderingCamera.Rotation.Z}");
                        file.WriteLine("relative heading:");
                        file.WriteLine(GameplayCamera.RelativeHeading.ToString());
                        file.WriteLine("relative pitch:");
                        file.WriteLine(GameplayCamera.RelativePitch.ToString());
                        file.WriteLine("fov:");
                        file.WriteLine(GameplayCamera.FieldOfView.ToString());
                    }
                }

                break;

            // temp modification
            case Keys.T:
                World.Weather = Weather.Raining;
                /* set it between 0 = stop, 1 = heavy rain. set it too high will lead to sloppy ground */
                Function.Call(Hash._SET_RAIN_FX_INTENSITY, 0.5f);
                var test = Function.Call <float>(Hash.GET_RAIN_LEVEL);
                UINotify("" + test);
                World.CurrentDayTime = new TimeSpan(12, 0, 0);
                //Script.Wait(5000);
                break;

            case Keys.N:
                UINotify("N pressed, going to take screenshots");

                startRunAndSessionManual();
                postgresTask?.Wait();
                runTask?.Wait();
                UINotify("starting screenshots");
                for (int i = 0; i < 2; i++)
                {
                    GamePause(true);
                    gatherData(100);
                    GamePause(false);
                    Script.Wait(200);     // hoping game will go on during this wait
                }

                if (staticCamera)
                {
                    CamerasList.Deactivate();
                }

                StopRun();
                StopSession();
                break;

            case Keys.OemMinus:     //to tlačítko vlevo od pravého shiftu, -
                UINotify("- pressed, going to rotate cameras");

                Game.Pause(true);
                for (int i = 0; i < CamerasList.cameras.Count; i++)
                {
                    Logger.WriteLine($"activating camera {i}");
                    CamerasList.ActivateCamera(i);
                    Script.Wait(1000);
                }
                CamerasList.Deactivate();
                Game.Pause(false);
                break;

            case Keys.I:
                var info = new GTAVisionUtils.InstanceData();
                UINotify(info.type);
                UINotify(info.publichostname);
                break;

            case Keys.Divide:
                Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position.");
                var startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea());
                var start     = OffroadPlanning.GetRandomPoint(startRect);
                var startZ    = World.GetGroundHeight(new Vector2(start.X, start.Y));
                Logger.WriteLine($"{startZ} is the ground position of {start}.");
//                    OffroadPlanning.setNextStart();
                startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea());
                start     = OffroadPlanning.GetRandomPoint(startRect);
                somePos   = start;
                startZ    = World.GetGroundHeight(new Vector2(start.X, start.Y));
                Logger.WriteLine($"{startZ} is the ground position of {start}.");
//                    when I use the same position, the GetGroundHeight call takes coordinates of player as ground height
                Game.Player.Character.Position = new Vector3(start.X + 5, start.Y + 5, 800);
                Logger.WriteLine($"teleporting player above teh position.");
                Script.Wait(50);
                startZ = World.GetGroundHeight(new Vector2(start.X, start.Y));
                Logger.WriteLine($"{startZ} is the ground position of {start}.");
                Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position.");
                Logger.ForceFlush();
                break;

            case Keys.F12:
                Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position.");
                Logger.WriteLine($"{World.GetGroundHeight(somePos)} is the {somePos} ground position.");
                break;

            case Keys.F11:
                Model mod     = new Model(GTAConst.OffroadVehicleHash);
                var   player  = Game.Player;
                var   vehicle = World.CreateVehicle(mod, player.Character.Position);
                player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver);
                break;

            case Keys.F10:
                startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea());
                start     = OffroadPlanning.GetRandomPoint(startRect);
                somePos   = start;
                startZ    = World.GetGroundHeight(new Vector2(start.X, start.Y));
                Logger.WriteLine($"{startZ} is the ground position of {start}.");
                for (int i = 900; i > 100; i -= 50)
                {
//                    when I use the same position, the GetGroundHeight call takes coordinates of player as ground height
                    Game.Player.Character.Position = new Vector3(start.X + 5, start.Y + 5, i);
                    Logger.WriteLine($"teleporting player above teh position to height {i}.");
                    Script.Wait(500);
                    startZ = World.GetGroundHeight(new Vector2(start.X, start.Y));
                    Logger.WriteLine($"{startZ} is the ground position of {start}.");
                }
                break;

            case Keys.F9:
                //turn on and off for datagathering during driving, mostly for testing offroad
                gatheringData = !gatheringData;
                if (gatheringData)
                {
                    UI.Notify("will be gathering data");
                }
                else
                {
                    UI.Notify("won't be gathering data");
                }

                break;
            }
        }
コード例 #3
0
        public void OnKeyDown(object o, KeyEventArgs k)
        {
            if (k.KeyCode == Keys.PageUp)
            {
                postgresTask?.Wait();
                postgresTask = StartSession();
                runTask?.Wait();
                runTask = StartRun();
                UI.Notify("GTA Vision Enabled");
            }
            if (k.KeyCode == Keys.PageDown)
            {
                StopRun();
                StopSession();
                UI.Notify("GTA Vision Disabled");
            }
            if (k.KeyCode == Keys.H) // temp modification
            {
                EnterVehicle();
                UI.Notify("Trying to enter vehicle");
                ToggleNavigation();
            }
            if (k.KeyCode == Keys.Y) // temp modification
            {
                ReloadGame();
            }
            if (k.KeyCode == Keys.U) // temp modification
            {
                var settings = ScriptSettings.Load("GTAVisionExport.xml");
                var loc      = AppDomain.CurrentDomain.BaseDirectory;

                //UI.Notify(ConfigurationManager.AppSettings["database_connection"]);
                var str = settings.GetValue("", "ConnectionString");
                UI.Notify(loc);
            }
            if (k.KeyCode == Keys.G) // temp modification
            {
                /*
                 * IsGamePaused = true;
                 * Game.Pause(true);
                 * Script.Wait(500);
                 * TraverseWeather();
                 * Script.Wait(500);
                 * IsGamePaused = false;
                 * Game.Pause(false);
                 */
                var data = GTAData.DumpData(Game.GameTime + ".tiff", new List <Weather>(wantedWeather));

                string path = @"C:\Users\NGV-02\Documents\Data\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(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("rotation:");
                        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:");
                        file.WriteLine(GameplayCamera.RelativePitch.ToString());
                        file.WriteLine("fov:");
                        file.WriteLine(GameplayCamera.FieldOfView.ToString());
                    }
                }
            }

            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 <float>(GTA.Native.Hash.GET_RAIN_LEVEL);
                UI.Notify("" + test);
                World.CurrentDayTime = new TimeSpan(12, 0, 0);
                //Script.Wait(5000);
            }

            if (k.KeyCode == Keys.N)
            {
                /*
                 * //var color = VisionNative.GetColorBuffer();
                 *
                 * List<byte[]> colors = new List<byte[]>();
                 * 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 = VisionNative.GetColorBuffer();
                for (int i = 0; i < 100; i++)
                {
                    List <byte[]> colors = new List <byte[]>();
                    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(GameplayCamera.FieldOfView.ToString());
                    //UI.Notify((connection != null && connection.Connected).ToString());


                    var data = GTAData.DumpData(Game.GameTime + ".dat", new List <Weather>(wantedWeather));

                    string path = @"C:\Users\NGV-02\Documents\Data\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("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());
                        }
                    }

                    Script.Wait(200);
                }
            }
            if (k.KeyCode == Keys.I)
            {
                var info = new GTAVisionUtils.InstanceData();
                UI.Notify(info.type);
                UI.Notify(info.publichostname);
            }
        }