Пример #1
0
 // New app is running, distribute new app ID
 private void UpdateAppId()
 {
     StopRegisteringKeys();
     _currentApplicationId = _ovr.GetRunningApplicationId();
     if (_currentApplicationId == string.Empty)
     {
         _currentApplicationId = MainModel.CONFIG_DEFAULT;
     }
     AppUpdateAction.Invoke(_currentApplicationId);
     LoadConfig();
 }
Пример #2
0
        public void Init()
        {
            StatusUpdateAction.Invoke(false);
            AppUpdateAction.Invoke("");

            _mediaPlayer = new MediaPlayer();

            _workerThread = new Thread(WorkerThread);
            _workerThread.Start();

            if (_settings.EnableServer && _settings.ServerPort != 0)
            {
                _server.StartOrRestart(_settings.ServerPort);
            }
            _server.MessageReceievedAction = (session, message) =>
            {
                var msg = new Remote.ScreenshotMessage();
                try
                {
                    msg = JsonConvert.DeserializeObject <Remote.ScreenshotMessage>(message);
                } catch (JsonReaderException e)
                {
                    Debug.WriteLine(e.Message);
                    _server.SendMessage(session, "Could not parse JSON");
                }
                if (_initComplete && !OpenVR.Overlay.IsDashboardVisible())
                {
                    if (msg.nonce != string.Empty)
                    {
                        msg.session = session;
                        if (msg.delay > 0)
                        {
                            TakeDelayedScreenshot(true, msg);
                        }
                        else
                        {
                            TakeScreenshot(true, msg);                                                       // byUser is true as this should show viewfinder etc.
                        }
                    }
                }
            };
            _server.StatusMessageAction = (session, connected, status) =>
            {
                Debug.WriteLine($"Session: {session}, connected: {connected}, status: {status}");
            };
            _server.StatusAction = (status, count) =>
            {
            };
        }
Пример #3
0
        public void Init(string[] actionKeys)
        {
            _actionKeys = actionKeys;

            // Sets default values for status labels
            StatusUpdateAction.Invoke(false);
            AppUpdateAction.Invoke(MainModel.CONFIG_DEFAULT);
            KeyActivatedAction.Invoke(string.Empty, false);

            // Loads default config
            LoadConfig(true);

            // Start background thread
            var workerThread = new Thread(WorkerThread);

            workerThread.Start();
        }
Пример #4
0
        private void WorkerThread()
        {
            Thread.CurrentThread.IsBackground = true;
            while (true)
            {
                Thread.Sleep(1000 / (int)_displayFrequency);
                if (!_ovr.IsInitialized())
                {
                    _ovr.Init();
                    StatusUpdateAction(_ovr.IsInitialized());
                    Thread.Sleep(1000);
                }
                else
                {
                    if (!_initComplete)
                    { // Initialization
                        _initComplete = true;

                        // Screenshots
                        UpdateScreenshotHook();
                        PlayScreenshotSound(true);
                        _currentAppId = _ovr.GetRunningApplicationId();
                        AppUpdateAction.Invoke(_currentAppId);
                        // ToggleViewfinder(true); // DEBUG
                        UpdateTrackedDeviceIndex();
                        UpdateDisplayFrequency();

                        // App
                        _ovr.AddApplicationManifest("./app.vrmanifest", "boll7708.superscreenshottervr", true);

                        // Input
                        _ovr.LoadActionManifest("./actions.json");
                        _ovr.RegisterActionSet("/actions/screenshots");

                        Action <InputDigitalActionData_t, InputActionInfo> takeScreenshotAction = (data, info) =>
                        {
                            var ok = data.bState && !OpenVR.Overlay.IsDashboardVisible();
                            if (_settings.DelayCapture)
                            {
                                TakeDelayedScreenshot(ok);
                            }
                            else if (ok)
                            {
                                TakeScreenshot();
                            }
                        };
                        Action <InputDigitalActionData_t, InputActionInfo> showViewfinderAction = (data, info) =>
                        {
                            var ok = data.bState && !OpenVR.Overlay.IsDashboardVisible();
                            ToggleViewfinder(ok);
                        };
                        Action <InputDigitalActionData_t, InputActionInfo> takeDelayedScreenshotAction = (data, info) =>
                        {
                            var ok = data.bState && !OpenVR.Overlay.IsDashboardVisible();
                            TakeDelayedScreenshot(ok);
                        };
                        _ovr.RegisterDigitalAction("/actions/screenshots/in/take_screenshot", takeScreenshotAction);
                        _ovr.RegisterDigitalAction("/actions/screenshots/in/show_viewfinder", showViewfinderAction);
                        _ovr.RegisterDigitalAction("/actions/screenshots/in/take_delayed_screenshot", takeDelayedScreenshotAction);
                        _ovr.RegisterDigitalAction("/actions/screenshots/in/take_screenshot_chord", takeScreenshotAction, true);
                        _ovr.RegisterDigitalAction("/actions/screenshots/in/show_viewfinder_chord", showViewfinderAction, true);
                        _ovr.RegisterDigitalAction("/actions/screenshots/in/take_delayed_screenshot_chord", takeDelayedScreenshotAction, true);

                        _notificationOverlayHandle = _ovr.InitNotificationOverlay("SuperScreenShotterVR");
                        _currentAppId = _ovr.GetRunningApplicationId();

                        // Events
                        _ovr.RegisterEvent(EVREventType.VREvent_RequestScreenshot, (data) => {
                            Debug.WriteLine("OBS! Screenshot request.");
                            // This happens after running TakeScreenshot() with no application running
                            // It leaves us with an error akin to ScreenshotAlreadyInProgress until
                            // we submit an empty result to Steam, we do that in ScreenShotTriggered().
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_ScreenshotTriggered, (data) => {
                            Debug.WriteLine($"Screenshot triggered, handle: {data.data.screenshot.handle}");
                            if (_isHookedForScreenshots)
                            {
                                if (_settings.DelayCapture)
                                {
                                    TakeDelayedScreenshot();
                                }
                                else
                                {
                                    TakeScreenshot();
                                }
                            }
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_ScreenshotTaken, (data) => {
                            Debug.WriteLine($"Screenshot taken, handle: {data.data.screenshot.handle}");
                            ScreenShotTaken(data.data);
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_ScreenshotFailed, (data) => {
                            _screenshotQueue.Remove(data.data.screenshot.handle);
                            Debug.WriteLine("Screenshot failed");
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_ScreenshotProgressToDashboard, (data) => {
                            Debug.WriteLine("Screenshot progress to dashboard");
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_SceneApplicationChanged, (data) => {
                            _currentAppId = _ovr.GetRunningApplicationId();
                            AppUpdateAction.Invoke(_currentAppId);
                            _isHookedForScreenshots = false; // To enable rehooking
                            UpdateScreenshotHook();          // Hook at new application as it seems to occasionally get dropped
                            UpdateOutputFolder();
                            _screenshotQueue.Clear();        // To not have left-overs
                            Debug.WriteLine($"New application running: {_currentAppId}");
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_Quit, (data) =>
                        {
                            _ovr.AcknowledgeShutdown();
                            _shouldShutDown = true;
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_TrackedDeviceActivated, (data) =>
                        {
                            UpdateTrackedDeviceIndex();
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_SteamVRSectionSettingChanged, (data) =>
                        {
                            // This is triggered when someone changes their headset display frequency in SteamVR
                            // (as well as other settings)
                            UpdateDisplayFrequency();
                        });
                        _ovr.RegisterEvent(EVREventType.VREvent_DashboardActivated, (data) =>
                        {
                            ToggleViewfinder(false);
                        });
                        Debug.WriteLine("Init complete.");
                    }
                    else
                    { // Per frame loop
                        _ovr.UpdateActionStates();
                        _ovr.UpdateEvents();

                        if (_settings.CaptureTimer)
                        {
                            if (!_stopWatch.IsRunning)
                            {
                                _stopWatch.Start();
                            }
                            if (_stopWatch.Elapsed.TotalSeconds >= _settings.TimerSeconds)
                            {
                                TakeScreenshot(false);
                                _stopWatch.Restart();
                            }
                        }
                        else if (_stopWatch.IsRunning)
                        {
                            _stopWatch.Stop();
                        }

                        if (_overlayIsVisible)
                        {
                            UpdateOverlays();
                        }

                        ShutdownIfWeShould();
                    }
                }
            }
        }