From 0739d5b595be9492c1e574192eba12174111e52c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 30 Oct 2015 09:16:32 +0100 Subject: also rename protocol -> proto --- proto-ft/CMakeLists.txt | 4 + proto-ft/ft-protocol.qrc | 5 + proto-ft/ftnoir_ftcontrols.ui | 182 +++++++++++++++++++++++++++++++++ proto-ft/ftnoir_protocol_ft.cpp | 166 ++++++++++++++++++++++++++++++ proto-ft/ftnoir_protocol_ft.h | 90 ++++++++++++++++ proto-ft/ftnoir_protocol_ft_dialog.cpp | 60 +++++++++++ proto-ft/images/freetrack.png | Bin 0 -> 1773 bytes 7 files changed, 507 insertions(+) create mode 100644 proto-ft/CMakeLists.txt create mode 100644 proto-ft/ft-protocol.qrc create mode 100644 proto-ft/ftnoir_ftcontrols.ui create mode 100644 proto-ft/ftnoir_protocol_ft.cpp create mode 100644 proto-ft/ftnoir_protocol_ft.h create mode 100644 proto-ft/ftnoir_protocol_ft_dialog.cpp create mode 100644 proto-ft/images/freetrack.png (limited to 'proto-ft') diff --git a/proto-ft/CMakeLists.txt b/proto-ft/CMakeLists.txt new file mode 100644 index 00000000..44f95ba3 --- /dev/null +++ b/proto-ft/CMakeLists.txt @@ -0,0 +1,4 @@ +if(WIN32) + opentrack_boilerplate(opentrack-proto-freetrack) + target_link_libraries(opentrack-proto-freetrack opentrack-csv opentrack-compat) +endif() diff --git a/proto-ft/ft-protocol.qrc b/proto-ft/ft-protocol.qrc new file mode 100644 index 00000000..c04959f0 --- /dev/null +++ b/proto-ft/ft-protocol.qrc @@ -0,0 +1,5 @@ + + + images/freetrack.png + + diff --git a/proto-ft/ftnoir_ftcontrols.ui b/proto-ft/ftnoir_ftcontrols.ui new file mode 100644 index 00000000..5356d2e5 --- /dev/null +++ b/proto-ft/ftnoir_ftcontrols.ui @@ -0,0 +1,182 @@ + + + UICFTControls + + + Qt::NonModal + + + true + + + + 0 + 0 + 422 + 305 + + + + + 0 + 0 + + + + + 0 + 0 + + + + freetrack protocol settings + + + + :/images/freetrack.png:/images/freetrack.png + + + Qt::LeftToRight + + + false + + + + + + + 0 + 0 + + + + TIRViews + + + Qt::AlignJustify|Qt::AlignTop + + + false + + + + + + Qt::RightToLeft + + + Memory hacks + + + + + + + Only for very old and buggy old games such as CFS3. + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + true + + + + + + + + + + + 0 + 0 + + + + Repair NPClient location + + + Qt::AlignJustify|Qt::AlignTop + + + false + + + + + + Locate DLL + + + + + + + Replace the registry entry if you want to use other software with the NPClient protocol and it doesn't work automatically. + + + true + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 0 + + + + Select interface + + + Qt::AlignJustify|Qt::AlignTop + + + false + + + + + + + + + Disable one of the protocols if game is confused by presence of both at the same time. + + + true + + + + + + + + + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp new file mode 100644 index 00000000..05253174 --- /dev/null +++ b/proto-ft/ftnoir_protocol_ft.cpp @@ -0,0 +1,166 @@ +/* Copyright (c) 2013-2015 Stanislaw Halik + * Copyright (c) 2015 Wim Vriend + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#include "ftnoir_protocol_ft.h" +#include "csv/csv.h" + +FTNoIR_Protocol::FTNoIR_Protocol() : + shm(FREETRACK_HEAP, FREETRACK_MUTEX, sizeof(FTHeap)), + pMemData((FTHeap*) shm.ptr()), + viewsStart(nullptr), + viewsStop(nullptr), + intGameID(0) +{ +} + +FTNoIR_Protocol::~FTNoIR_Protocol() +{ + if (viewsStop != NULL) { + viewsStop(); + FTIRViewsLib.unload(); + } + dummyTrackIR.terminate(); + dummyTrackIR.kill(); + dummyTrackIR.waitForFinished(50); +} + +void FTNoIR_Protocol::pose(const double* headpose) { + float yaw = -getRadsFromDegrees(headpose[Yaw]); + float pitch = -getRadsFromDegrees(headpose[Pitch]); + float roll = getRadsFromDegrees(headpose[Roll]); + float tx = headpose[TX] * 10.f; + float ty = headpose[TY] * 10.f; + float tz = headpose[TZ] * 10.f; + + FTHeap* ft = pMemData; + FTData* data = &ft->data; + + data->RawX = 0; + data->RawY = 0; + data->RawZ = 0; + data->RawPitch = 0; + data->RawYaw = 0; + data->RawRoll = 0; + + data->X = tx; + data->Y = ty; + data->Z = tz; + data->Yaw = yaw; + data->Pitch = pitch; + data->Roll = roll; + + data->X1 = data->DataID; + data->X2 = 0; + data->X3 = 0; + data->X4 = 0; + data->Y1 = 0; + data->Y2 = 0; + data->Y3 = 0; + data->Y4 = 0; + + int32_t id = ft->GameID; + + if (intGameID != id) + { + QString gamename; + { + unsigned char table[8]; + if (CSV::getGameData(id, table, gamename)) + for (int i = 0; i < 8; i++) pMemData->table[i] = table[i]; + } + ft->GameID2 = id; + intGameID = id; + QMutexLocker foo(&this->game_name_mutex); + connected_game = gamename; + } + + data->DataID += 1; +} + +void FTNoIR_Protocol::start_tirviews() { + QString aFileName = QCoreApplication::applicationDirPath() + "/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 FTNoIR_Protocol::start_dummy() { + + + QString program = QCoreApplication::applicationDirPath() + "/TrackIR.exe"; + dummyTrackIR.setProgram("\"" + program + "\""); + dummyTrackIR.start(); +} + +bool FTNoIR_Protocol::correct() +{ + // Registry settings (in HK_USER) + QSettings settings("Freetrack", "FreetrackClient"); + QSettings settingsTIR("NaturalPoint", "NATURALPOINT\\NPClient Location"); + + if (!shm.success()) + return false; + + QString aLocation = QCoreApplication::applicationDirPath() + "/"; + + switch (s.intUsedInterface) { + case 0: + // Use both interfaces + settings.setValue( "Path" , aLocation ); + settingsTIR.setValue( "Path" , aLocation ); + break; + case 1: + // Use FreeTrack, disable TrackIR + settings.setValue( "Path" , aLocation ); + settingsTIR.setValue( "Path" , "" ); + break; + case 2: + // Use TrackIR, disable FreeTrack + settings.setValue( "Path" , "" ); + settingsTIR.setValue( "Path" , aLocation ); + break; + default: + break; + } + + if (s.useTIRViews) { + start_tirviews(); + } + + // more games need the dummy executable than previously thought + start_dummy(); + + pMemData->data.DataID = 1; + pMemData->data.CamWidth = 100; + pMemData->data.CamHeight = 250; + pMemData->GameID2 = 0; + for (int i = 0; i < 8; i++) + pMemData->table[i] = 0; + + return true; +} + +OPENTRACK_DECLARE_PROTOCOL(FTNoIR_Protocol, FTControls, FTNoIR_ProtocolDll) diff --git a/proto-ft/ftnoir_protocol_ft.h b/proto-ft/ftnoir_protocol_ft.h new file mode 100644 index 00000000..8e50f1cb --- /dev/null +++ b/proto-ft/ftnoir_protocol_ft.h @@ -0,0 +1,90 @@ +/* Copyright (c) 2013-2015 Stanislaw Halik + * Copyright (c) 2015 Wim Vriend + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#pragma once +#include "ui_ftnoir_ftcontrols.h" +#include "opentrack/plugin-api.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "opentrack-compat/shm.h" +#include "opentrack/options.hpp" +#include "freetrackclient/fttypes.h" +using namespace options; + +struct settings : opts { + value intUsedInterface; + value useTIRViews; + settings() : + opts("proto-freetrack"), + intUsedInterface(b, "used-interfaces", 0), + useTIRViews(b, "use-memory-hacks", false) + {} +}; + +typedef void (__stdcall *importTIRViewsStart)(void); +typedef void (__stdcall *importTIRViewsStop)(void); + +class FTNoIR_Protocol : public IProtocol +{ +public: + FTNoIR_Protocol(); + ~FTNoIR_Protocol() override; + bool correct(); + void pose( const double *headpose ); + QString game_name() override { + QMutexLocker foo(&game_name_mutex); + return connected_game; + } +private: + settings s; + PortableLockedShm shm; + FTHeap *pMemData; + + QLibrary FTIRViewsLib; + QProcess dummyTrackIR; + importTIRViewsStart viewsStart; + importTIRViewsStop viewsStop; + + int intGameID; + QString connected_game; + QMutex game_name_mutex; + + static inline double getRadsFromDegrees(double degrees) { return degrees * 0.017453; } + void start_tirviews(); + void start_dummy(); +}; + +class FTControls: public IProtocolDialog +{ + Q_OBJECT +public: + FTControls(); + void register_protocol(IProtocol *) {} + void unregister_protocol() {} +private: + Ui::UICFTControls ui; + settings s; +private slots: + void selectDLL(); + void doOK(); + void doCancel(); +}; + +class FTNoIR_ProtocolDll : public Metadata +{ +public: + QString name() { return QString("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 new file mode 100644 index 00000000..25f3a4cb --- /dev/null +++ b/proto-ft/ftnoir_protocol_ft_dialog.cpp @@ -0,0 +1,60 @@ +/* Homepage http://facetracknoir.sourceforge.net/home/default.htm * + * * + * ISC License (ISC) * + * * + * Copyright (c) 2015, Wim Vriend * + * * + * Permission to use, copy, modify, and/or distribute this software for any * + * purpose with or without fee is hereby granted, provided that the above * + * copyright notice and this permission notice appear in all copies. * + */ +#include "ftnoir_protocol_ft.h" +#include +#include + +FTControls::FTControls() +{ + ui.setupUi( this ); + + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + connect(ui.bntLocateNPClient, SIGNAL(clicked()), this, SLOT(selectDLL())); + + tie_setting(s.useTIRViews, ui.chkTIRViews); + + 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); + + QFile memhacks_pathname(QCoreApplication::applicationDirPath() + "/TIRViews.dll"); + if (!memhacks_pathname.exists()) { + ui.chkTIRViews->setChecked( false ); + ui.chkTIRViews->setEnabled ( false ); + } + else { + ui.chkTIRViews->setEnabled ( true ); + } +} + +void FTControls::doOK() { + s.b->save(); + this->close(); +} + +void FTControls::doCancel() { + s.b->reload(); + this->close(); +} + +void FTControls::selectDLL() { + QString filename = QFileDialog::getOpenFileName( this, tr("Select the desired NPClient DLL"), QCoreApplication::applicationDirPath() + "/NPClient.dll", tr("Dll file (*.dll);;All Files (*)")); + + if (! filename.isEmpty() ) { + QSettings node("NaturalPoint", "NATURALPOINT\\NPClient Location"); + QFileInfo dllname(filename); + node.setValue( "Path" , dllname.dir().path() ); + } +} + diff --git a/proto-ft/images/freetrack.png b/proto-ft/images/freetrack.png new file mode 100644 index 00000000..c184dc88 Binary files /dev/null and b/proto-ft/images/freetrack.png differ -- cgit v1.2.3