diff options
Diffstat (limited to 'proto-ft')
-rw-r--r-- | proto-ft/ftnoir_ftcontrols.ui | 142 | ||||
-rw-r--r-- | proto-ft/ftnoir_protocol_ft.cpp | 60 | ||||
-rw-r--r-- | proto-ft/ftnoir_protocol_ft.h | 40 | ||||
-rw-r--r-- | proto-ft/ftnoir_protocol_ft_dialog.cpp | 14 | ||||
-rw-r--r-- | proto-ft/mutex.cpp | 60 | ||||
-rw-r--r-- | proto-ft/mutex.hpp | 16 |
6 files changed, 45 insertions, 287 deletions
diff --git a/proto-ft/ftnoir_ftcontrols.ui b/proto-ft/ftnoir_ftcontrols.ui index e8098505..4ad00514 100644 --- a/proto-ft/ftnoir_ftcontrols.ui +++ b/proto-ft/ftnoir_ftcontrols.ui @@ -8,23 +8,15 @@ <property name="enabled"> <bool>true</bool> </property> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>515</width> - <height>429</height> - </rect> - </property> <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <sizepolicy hsizetype="Maximum" vsizetype="Maximum"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="minimumSize"> <size> - <width>0</width> + <width>571</width> <height>0</height> </size> </property> @@ -42,97 +34,14 @@ <bool>false</bool> </property> <layout class="QGridLayout" name="gridLayout_2"> - <item row="1" column="0"> - <widget class="QGroupBox" name="groupBox_3"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="title"> - <string>Select interface</string> - </property> - <property name="alignment"> - <set>Qt::AlignJustify|Qt::AlignTop</set> - </property> - <property name="flat"> - <bool>false</bool> - </property> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <property name="spacing"> - <number>9</number> - </property> - <item> - <widget class="QComboBox" name="cbxSelectInterface"/> - </item> - <item> - <widget class="QLabel" name="label_8"> - <property name="text"> - <string>Disable one of the protocols if game is confused by presence of both at the same time.</string> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="0" column="0"> - <widget class="QGroupBox" name="groupBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="title"> - <string>TIRViews</string> - </property> - <property name="alignment"> - <set>Qt::AlignJustify|Qt::AlignTop</set> - </property> - <property name="flat"> - <bool>false</bool> + <item row="2" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> </property> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <property name="spacing"> - <number>9</number> - </property> - <item> - <widget class="QCheckBox" name="chkTIRViews"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Memory hacks</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Only for very old and buggy old games such as CFS3.</string> - </property> - <property name="scaledContents"> - <bool>false</bool> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> </widget> </item> - <item row="2" column="0"> + <item row="1" column="0"> <widget class="QGroupBox" name="groupBox_4"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> @@ -181,15 +90,8 @@ Starting tracking will again overwrite the DLL locations.</string> </layout> </widget> </item> - <item row="4" column="0"> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QGroupBox" name="groupBox_2"> + <item row="0" column="0"> + <widget class="QGroupBox" name="groupBox_3"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> @@ -197,29 +99,25 @@ Starting tracking will again overwrite the DLL locations.</string> </sizepolicy> </property> <property name="title"> - <string>Disable tracking for games on exit</string> + <string>Select interface</string> </property> - <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="alignment"> + <set>Qt::AlignJustify|Qt::AlignTop</set> + </property> + <property name="flat"> + <bool>false</bool> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_3"> <property name="spacing"> <number>9</number> </property> <item> - <widget class="QCheckBox" name="close_on_exit"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Disable on program exit</string> - </property> - </widget> + <widget class="QComboBox" name="cbxSelectInterface"/> </item> <item> - <widget class="QLabel" name="label"> + <widget class="QLabel" name="label_8"> <property name="text"> - <string>Use this for games that disable mouselook when opentrack isn't running, and you're not running opentrack that much. To use opentrack with this option you need to start it before the games to have it work at all.</string> + <string>Disable one of the protocols if game is confused by presence of both at the same time.</string> </property> <property name="wordWrap"> <bool>true</bool> diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp index d03ca59a..a0272115 100644 --- a/proto-ft/ftnoir_protocol_ft.cpp +++ b/proto-ft/ftnoir_protocol_ft.cpp @@ -17,28 +17,18 @@ #include <cmath> #include <windows.h> -check_for_first_run freetrack::runonce_check = check_for_first_run(); - -freetrack::freetrack() : - shm(FREETRACK_HEAP, FREETRACK_MUTEX, sizeof(FTHeap)), - pMemData((FTHeap*) shm.ptr()), - viewsStart(nullptr), - viewsStop(nullptr), - intGameID(-1) +freetrack::freetrack() { - runonce_check.set_enabled(s.close_protocols_on_exit); - QObject::connect(&s.close_protocols_on_exit, - static_cast<void (base_value::*)(bool) const>(&value<bool>::valueChanged), - [] (bool flag) -> void { runonce_check.set_enabled(flag); }); - runonce_check.try_runonce(); } freetrack::~freetrack() { - if (viewsStop != NULL) { - viewsStop(); - FTIRViewsLib.unload(); + if (shm.success()) + { + const double tmp[6] {}; + pose(tmp); } + dummyTrackIR.close(); } @@ -81,7 +71,7 @@ void freetrack::pose(const double* headpose) // HACK: Falcon BMS makes a "bump" if pitch is over the value -sh 20170615 const bool is_crossing_90 = std::fabs(headpose[Pitch] - 90) < 1e-4; - const float pitch = -degrees_to_rads(is_crossing_90 ? 89.86 : headpose[Pitch]); + const float pitch = -degrees_to_rads(is_crossing_90 ? 89.85 : headpose[Pitch]); FTHeap volatile* ft = pMemData; FTData volatile* data = &ft->data; @@ -112,14 +102,14 @@ void freetrack::pose(const double* headpose) const std::uintptr_t addr = (std::uintptr_t)(void*)&pMemData->table[0]; const std::uintptr_t addr_ = addr & ~(sizeof(LONG)-1u); + static_assert(sizeof(LONG) == 4, ""); + // the data `happens' to be aligned by virtue of element ordering // inside FTHeap. there's no deeper reason behind it. - if (addr != addr_) assert(!"unaligned access"); - static_assert(sizeof(LONG) == 4, ""); - + // no unaligned atomic access for `char' for (unsigned k = 0; k < 2; k++) store(*(std::int32_t volatile*)&pMemData->table_ints[k], t.ints[k]); } @@ -141,33 +131,8 @@ float freetrack::degrees_to_rads(double degrees) return float(degrees*M_PI/180); } -void freetrack::start_tirviews() +void freetrack::start_dummy() { - QString aFileName = OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH "TIRViews.dll"; - if ( QFile::exists( aFileName )) { - FTIRViewsLib.setFileName(aFileName); - FTIRViewsLib.load(); - - viewsStart = (importTIRViewsStart) FTIRViewsLib.resolve("TIRViewsStart"); - if (viewsStart == NULL) { - qDebug() << "FTServer::run() says: TIRViewsStart function not found in DLL!"; - } - else { - qDebug() << "FTServer::run() says: TIRViewsStart executed!"; - viewsStart(); - } - - // - // Load the Stop function from TIRViews.dll. Call it when terminating the thread. - // - viewsStop = (importTIRViewsStop) FTIRViewsLib.resolve("TIRViewsStop"); - if (viewsStop == NULL) { - qDebug() << "FTServer::run() says: TIRViewsStop function not found in DLL!"; - } - } -} - -void freetrack::start_dummy() { static const QString program = OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH "TrackIR.exe"; dummyTrackIR.setProgram("\"" + program + "\""); dummyTrackIR.start(); @@ -216,9 +181,6 @@ module_status freetrack::check_status() set_protocols(use_ft, use_npclient); - if (s.useTIRViews && use_npclient) - start_tirviews(); - pMemData->data.DataID = 1; pMemData->data.CamWidth = 100; pMemData->data.CamHeight = 250; diff --git a/proto-ft/ftnoir_protocol_ft.h b/proto-ft/ftnoir_protocol_ft.h index e2faacf3..e01c08e2 100644 --- a/proto-ft/ftnoir_protocol_ft.h +++ b/proto-ft/ftnoir_protocol_ft.h @@ -7,43 +7,32 @@ */ #pragma once + #include "ui_ftnoir_ftcontrols.h" -#include "api/plugin-api.hpp" -#include <QMessageBox> -#include <QSettings> -#include <QLibrary> -#include <QProcess> -#include <QDebug> -#include <QFile> -#include <QString> -#include <QMutex> -#include <QMutexLocker> -#include <cinttypes> #include "freetrackclient/fttypes.h" #include "compat/shm.h" #include "options/options.hpp" -#include "mutex.hpp" +#include "api/plugin-api.hpp" +#include <QProcess> +#include <QString> +#include <QMutex> + +#include <cinttypes> #include <memory> using namespace options; struct settings : opts { value<int> intUsedInterface; - value<bool> useTIRViews, close_protocols_on_exit; settings() : opts("proto-freetrack"), - intUsedInterface(b, "used-interfaces", 0), - useTIRViews(b, "use-memory-hacks", false), - close_protocols_on_exit(b, "close-protocols-on-exit", false) + intUsedInterface(b, "used-interfaces", 0) {} }; -typedef void (__stdcall *importTIRViewsStart)(void); -typedef void (__stdcall *importTIRViewsStop)(void); - class freetrack : public IProtocol { public: @@ -57,20 +46,15 @@ public: } private: settings s; - shm_wrapper shm; - FTHeap volatile *pMemData; + shm_wrapper shm { FREETRACK_HEAP, FREETRACK_MUTEX, sizeof(FTHeap) }; + FTHeap volatile *pMemData { (FTHeap*) shm.ptr() }; - QLibrary FTIRViewsLib; QProcess dummyTrackIR; - importTIRViewsStart viewsStart; - importTIRViewsStop viewsStop; - int intGameID; + int intGameID = -1; QString connected_game; QMutex game_name_mutex; - static check_for_first_run runonce_check; - void start_tirviews(); void start_dummy(); static float degrees_to_rads(double degrees); @@ -97,6 +81,6 @@ private slots: class freetrackDll : public Metadata { public: - QString name() { return QString(QCoreApplication::translate("freetrackDll", "freetrack 2.0 Enhanced")); } + QString name() { return otr_tr("freetrack 2.0 Enhanced"); } QIcon icon() { return QIcon(":/images/freetrack.png"); } }; diff --git a/proto-ft/ftnoir_protocol_ft_dialog.cpp b/proto-ft/ftnoir_protocol_ft_dialog.cpp index 5b3ad3b2..35f03586 100644 --- a/proto-ft/ftnoir_protocol_ft_dialog.cpp +++ b/proto-ft/ftnoir_protocol_ft_dialog.cpp @@ -10,8 +10,9 @@ */ #include "ftnoir_protocol_ft.h" #include "opentrack-library-path.h" -#include <QDebug> + #include <QFileDialog> +#include <QFileInfo> FTControls::FTControls() { @@ -21,22 +22,11 @@ FTControls::FTControls() connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); connect(ui.bntLocateNPClient, SIGNAL(clicked()), this, SLOT(selectDLL())); - tie_setting(s.useTIRViews, ui.chkTIRViews); - tie_setting(s.close_protocols_on_exit, ui.close_on_exit); - ui.cbxSelectInterface->addItem("Enable both"); ui.cbxSelectInterface->addItem("Use FreeTrack, hide TrackIR"); ui.cbxSelectInterface->addItem("Use TrackIR, hide FreeTrack"); tie_setting(s.intUsedInterface, ui.cbxSelectInterface); - - static const QFile memhacks_pathname(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH "TIRViews.dll"); - if (!memhacks_pathname.exists()) { - ui.chkTIRViews->setEnabled(false); - } - else { - ui.chkTIRViews->setEnabled(true); - } } void FTControls::doOK() diff --git a/proto-ft/mutex.cpp b/proto-ft/mutex.cpp deleted file mode 100644 index a012ba90..00000000 --- a/proto-ft/mutex.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "ftnoir_protocol_ft.h" -#include "mutex.hpp" -#include <windows.h> -#include <QDebug> - -check_for_first_run::check_for_first_run() : checked_for_first_run(false), is_first_instance(false), enabled(false) -{ -} - -bool check_for_first_run::is_first_run() -{ - return checked_for_first_run && is_first_instance; -} - -void check_for_first_run::set_enabled(bool flag) -{ - enabled = flag; -} - -void check_for_first_run::try_runonce() -{ - constexpr const char* name = "opentrack-freetrack-runonce"; - - if (checked_for_first_run) - return; - - // just leak it, no issue - HANDLE h = CreateMutexA(nullptr, false, name); - - switch (WaitForSingleObject(h, 0)) - { - case WAIT_OBJECT_0: - is_first_instance = true; - checked_for_first_run = true; - break; - case WAIT_TIMEOUT: - checked_for_first_run = true; - break; - default: - checked_for_first_run = false; - break; - } - - if (checked_for_first_run && !is_first_instance) - CloseHandle(h); -} - -check_for_first_run::~check_for_first_run() -{ - try_exit(); -} - -void check_for_first_run::try_exit() -{ - if (is_first_instance && enabled) - { - qDebug() << "ft runonce: removing registry keys"; - freetrack::set_protocols(false, false); - } -} diff --git a/proto-ft/mutex.hpp b/proto-ft/mutex.hpp deleted file mode 100644 index f92a14bf..00000000 --- a/proto-ft/mutex.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -class check_for_first_run final -{ - bool checked_for_first_run; - bool is_first_instance; - bool enabled; - - void try_exit(); -public: - check_for_first_run(); - bool is_first_run(); - void set_enabled(bool flag); - void try_runonce(); - ~check_for_first_run(); -}; |