From 89f104782e673cfacec0eab016dc22a51533f113 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 9 Dec 2017 17:59:57 +0100 Subject: proto/freetrack: cleanup - set zeros in shm, for NPClient.dll tracking detection - remove tirviews support - remove registry cleanup on exit support --- proto-ft/ftnoir_ftcontrols.ui | 142 +++++---------------------------- proto-ft/ftnoir_protocol_ft.cpp | 60 +++----------- proto-ft/ftnoir_protocol_ft.h | 40 +++------- proto-ft/ftnoir_protocol_ft_dialog.cpp | 14 +--- proto-ft/mutex.cpp | 60 -------------- proto-ft/mutex.hpp | 16 ---- 6 files changed, 45 insertions(+), 287 deletions(-) delete mode 100644 proto-ft/mutex.cpp delete mode 100644 proto-ft/mutex.hpp (limited to 'proto-ft') 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 @@ true - - - 0 - 0 - 515 - 429 - - - + 0 0 - 0 + 571 0 @@ -42,97 +34,14 @@ false - - - - - 0 - 0 - - - - Select interface - - - Qt::AlignJustify|Qt::AlignTop - - - false - - - - 9 - - - - - - - - Disable one of the protocols if game is confused by presence of both at the same time. - - - true - - - - - - - - - - - 0 - 0 - - - - TIRViews - - - Qt::AlignJustify|Qt::AlignTop - - - false + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - 9 - - - - - - 0 - 0 - - - - Memory hacks - - - - - - - Only for very old and buggy old games such as CFS3. - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - true - - - - - + @@ -181,15 +90,8 @@ Starting tracking will again overwrite the DLL locations. - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - + + 0 @@ -197,29 +99,25 @@ Starting tracking will again overwrite the DLL locations. - Disable tracking for games on exit + Select interface - + + Qt::AlignJustify|Qt::AlignTop + + + false + + 9 - - - - 0 - 0 - - - - Disable on program exit - - + - + - 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. + Disable one of the protocols if game is confused by presence of both at the same time. true 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 #include -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(&value::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 -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "freetrackclient/fttypes.h" #include "compat/shm.h" #include "options/options.hpp" -#include "mutex.hpp" +#include "api/plugin-api.hpp" +#include +#include +#include + +#include #include using namespace options; struct settings : opts { value intUsedInterface; - value 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 + #include +#include 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 -#include - -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(); -}; -- cgit v1.2.3