summaryrefslogtreecommitdiffhomepage
path: root/protocol-ft
diff options
context:
space:
mode:
Diffstat (limited to 'protocol-ft')
-rw-r--r--protocol-ft/CMakeLists.txt4
-rw-r--r--protocol-ft/ft-protocol.qrc5
-rw-r--r--protocol-ft/ftnoir_ftcontrols.ui182
-rw-r--r--protocol-ft/ftnoir_protocol_ft.cpp166
-rw-r--r--protocol-ft/ftnoir_protocol_ft.h90
-rw-r--r--protocol-ft/ftnoir_protocol_ft_dialog.cpp60
-rw-r--r--protocol-ft/images/freetrack.pngbin0 -> 1773 bytes
7 files changed, 507 insertions, 0 deletions
diff --git a/protocol-ft/CMakeLists.txt b/protocol-ft/CMakeLists.txt
new file mode 100644
index 00000000..44f95ba3
--- /dev/null
+++ b/protocol-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/protocol-ft/ft-protocol.qrc b/protocol-ft/ft-protocol.qrc
new file mode 100644
index 00000000..c04959f0
--- /dev/null
+++ b/protocol-ft/ft-protocol.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>images/freetrack.png</file>
+ </qresource>
+</RCC>
diff --git a/protocol-ft/ftnoir_ftcontrols.ui b/protocol-ft/ftnoir_ftcontrols.ui
new file mode 100644
index 00000000..5356d2e5
--- /dev/null
+++ b/protocol-ft/ftnoir_ftcontrols.ui
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UICFTControls</class>
+ <widget class="QWidget" name="UICFTControls">
+ <property name="windowModality">
+ <enum>Qt::NonModal</enum>
+ </property>
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>422</width>
+ <height>305</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="windowTitle">
+ <string>freetrack protocol settings</string>
+ </property>
+ <property name="windowIcon">
+ <iconset resource="ft-protocol.qrc">
+ <normaloff>:/images/freetrack.png</normaloff>:/images/freetrack.png</iconset>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <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>
+ </property>
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="0" column="0">
+ <widget class="QCheckBox" name="chkTIRViews">
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string>Memory hacks</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <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">
+ <widget class="QGroupBox" name="groupBox_4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Repair NPClient location</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignJustify|Qt::AlignTop</set>
+ </property>
+ <property name="flat">
+ <bool>false</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QPushButton" name="bntLocateNPClient">
+ <property name="text">
+ <string>Locate DLL</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLabel" name="label_10">
+ <property name="text">
+ <string>Replace the registry entry if you want to use other software with the NPClient protocol and it doesn't work automatically.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QGroupBox" name="groupBox_3">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <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="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <widget class="QComboBox" name="cbxSelectInterface"/>
+ </item>
+ <item row="0" column="1">
+ <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>
+ </layout>
+ </widget>
+ <resources>
+ <include location="ft-protocol.qrc"/>
+ </resources>
+ <connections/>
+ <slots>
+ <slot>startEngineClicked()</slot>
+ <slot>stopEngineClicked()</slot>
+ <slot>cameraSettingsClicked()</slot>
+ </slots>
+</ui>
diff --git a/protocol-ft/ftnoir_protocol_ft.cpp b/protocol-ft/ftnoir_protocol_ft.cpp
new file mode 100644
index 00000000..05253174
--- /dev/null
+++ b/protocol-ft/ftnoir_protocol_ft.cpp
@@ -0,0 +1,166 @@
+/* Copyright (c) 2013-2015 Stanislaw Halik <sthalik@misaki.pl>
+ * 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/protocol-ft/ftnoir_protocol_ft.h b/protocol-ft/ftnoir_protocol_ft.h
new file mode 100644
index 00000000..8e50f1cb
--- /dev/null
+++ b/protocol-ft/ftnoir_protocol_ft.h
@@ -0,0 +1,90 @@
+/* Copyright (c) 2013-2015 Stanislaw Halik <sthalik@misaki.pl>
+ * 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 <QMessageBox>
+#include <QSettings>
+#include <QLibrary>
+#include <QProcess>
+#include <QDebug>
+#include <QFile>
+#include <QString>
+#include <QMutex>
+#include <QMutexLocker>
+#include "opentrack-compat/shm.h"
+#include "opentrack/options.hpp"
+#include "freetrackclient/fttypes.h"
+using namespace options;
+
+struct settings : opts {
+ value<int> intUsedInterface;
+ value<bool> 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/protocol-ft/ftnoir_protocol_ft_dialog.cpp b/protocol-ft/ftnoir_protocol_ft_dialog.cpp
new file mode 100644
index 00000000..25f3a4cb
--- /dev/null
+++ b/protocol-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 <QDebug>
+#include <QFileDialog>
+
+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/protocol-ft/images/freetrack.png b/protocol-ft/images/freetrack.png
new file mode 100644
index 00000000..c184dc88
--- /dev/null
+++ b/protocol-ft/images/freetrack.png
Binary files differ