diff options
author | Tuck Therebelos <snares@users.sourceforge.net> | 2009-03-11 00:46:02 +0300 |
---|---|---|
committer | Tuck Therebelos <snares@users.sourceforge.net> | 2009-03-11 00:46:02 +0300 |
commit | 67ac3356eef7634f4941200460e810fd466c7376 (patch) | |
tree | 210260239d1e233707d2223509642154c7072a2f /plugins/dys | |
parent | 8034ec1b54dd2cbe9014f96e3a47b9adc36355bf (diff) |
Added Dystopia plugin
Diffstat (limited to 'plugins/dys')
-rw-r--r-- | plugins/dys/dys.cpp | 184 | ||||
-rw-r--r-- | plugins/dys/dys.pro | 5 |
2 files changed, 189 insertions, 0 deletions
diff --git a/plugins/dys/dys.cpp b/plugins/dys/dys.cpp new file mode 100644 index 000000000..62060f337 --- /dev/null +++ b/plugins/dys/dys.cpp @@ -0,0 +1,184 @@ +#include <stdio.h>
+#include <stdlib.h>
+#include <windows.h>
+#include <tlhelp32.h>
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+
+#include "../mumble_plugin.h"
+
+HANDLE h;
+BYTE *posptr;
+BYTE *rotptr;
+BYTE *stateptr;
+
+static DWORD getProcess(const wchar_t *exename) {
+ PROCESSENTRY32 pe;
+ DWORD pid = 0;
+
+ pe.dwSize = sizeof(pe);
+ HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+ if (hSnap != INVALID_HANDLE_VALUE) {
+ BOOL ok = Process32First(hSnap, &pe);
+
+ while (ok) {
+ if (wcscmp(pe.szExeFile, exename)==0) {
+ pid = pe.th32ProcessID;
+ break;
+ }
+ ok = Process32Next(hSnap, &pe);
+ }
+ CloseHandle(hSnap);
+ }
+ return pid;
+}
+
+static BYTE *getModuleAddr(DWORD pid, const wchar_t *modname) {
+ MODULEENTRY32 me;
+ BYTE *addr = NULL;
+ me.dwSize = sizeof(me);
+ HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
+ if (hSnap != INVALID_HANDLE_VALUE) {
+ BOOL ok = Module32First(hSnap, &me);
+
+ while (ok) {
+ if (wcscmp(me.szModule, modname)==0) {
+ addr = me.modBaseAddr;
+ break;
+ }
+ ok = Module32Next(hSnap, &me);
+ }
+ CloseHandle(hSnap);
+ }
+ return addr;
+}
+
+
+static bool peekProc(VOID *base, VOID *dest, SIZE_T len) {
+ SIZE_T r;
+ BOOL ok=ReadProcessMemory(h, base, dest, len, &r);
+ return (ok && (r == len));
+}
+
+static void about(HWND h) {
+ ::MessageBox(h, L"Reads audio position information from Dystopia (Build 3698)", L"Mumble Dystopia Plugin", MB_OK);
+}
+
+static bool calcout(float *pos, float *rot, float *opos, float *front, float *top) {
+ float h = rot[0];
+ float v = rot[1];
+
+ if ((v < -360.0f) || (v > 360.0f) || (h < -360.0f) || (h > 360.0f))
+ return false;
+
+ h *= static_cast<float>(M_PI / 180.0f);
+ v *= static_cast<float>(M_PI / 180.0f);
+
+ // Seems Dystopia is in inches. INCHES?!?
+ opos[0] = pos[0] / 39.37f;
+ opos[1] = pos[2] / 39.37f;
+ opos[2] = pos[1] / 39.37f;
+
+ front[0] = cos(v) * cos(h);
+ front[1] = -sin(h);
+ front[2] = sin(v) * cos(h);
+
+ h -= static_cast<float>(M_PI / 2.0f);
+
+ top[0] = cos(v) * cos(h);
+ top[1] = -sin(h);
+ top[2] = sin(v) * cos(h);
+
+ return true;
+}
+
+static int trylock() {
+
+ h = NULL;
+ posptr = rotptr = NULL;
+
+ DWORD pid=getProcess(L"hl2.exe");
+ if (!pid)
+ return false;
+ BYTE *mod=getModuleAddr(pid, L"client.dll");
+ if (!mod)
+ return false;
+ h=OpenProcess(PROCESS_VM_READ, false, pid);
+ if (!h)
+ return false;
+
+ // Check if we really have Dystopia running
+ /*
+ position tuple: client.dll+0x4238a0 (x,y,z, float)
+ orientation tuple: client.dll+0x423930 (v,h float)
+ ID string: client.dll+0x3c947e = "DysObjective@@" (14 characters, text)
+ spawn state: client.dll+0x3c6260 (0 when at main menu, 2 when not spawned, 6 when spawned, byte)
+ */
+ char sMagic[14];
+ if (!peekProc(mod + 0x3c947e, sMagic, 14) || strncmp("DysObjective@@", sMagic, 14)!=0)
+ return false;
+
+ // Remember addresses for later
+ posptr = mod + 0x4238a0;
+ rotptr = mod + 0x423930;
+ stateptr = mod + 0x3c6260;
+
+ float pos[3];
+ float rot[3];
+ float opos[3], top[3], front[3];
+
+ bool ok = peekProc(posptr, pos, 12) &&
+ peekProc(rotptr, rot, 12);
+
+ if (ok)
+ return calcout(pos, rot, opos, top, front);
+ // If it failed clean up
+ CloseHandle(h);
+ h = NULL;
+ return false;
+}
+
+static void unlock() {
+ if (h) {
+ CloseHandle(h);
+ h = NULL;
+ }
+ return;
+}
+
+static int fetch(float *pos, float *front, float *top) {
+ for (int i=0;i<3;i++)
+ pos[i] = front[i] = top[i] = 0;
+
+ float ipos[3], rot[3];
+ bool ok;
+ char state;
+
+ ok = peekProc(posptr, ipos, 12) &&
+ peekProc(rotptr, rot, 12) &&
+ peekProc(stateptr, &state, 1);
+ if (!ok)
+ return false;
+
+ // Check to see if you are spawned
+ if (state == 0 || state == 2)
+ return true; // Deactivate plugin
+
+ return calcout(ipos, rot, pos, front, top);
+}
+
+static MumblePlugin dysplug = {
+ MUMBLE_PLUGIN_MAGIC,
+ L"Dystopia (Build 3698)",
+ L"Dystopia",
+ about,
+ NULL,
+ trylock,
+ unlock,
+ fetch
+};
+
+extern "C" __declspec(dllexport) MumblePlugin *getMumblePlugin() {
+ return &dysplug;
+}
diff --git a/plugins/dys/dys.pro b/plugins/dys/dys.pro new file mode 100644 index 000000000..f5d61ee49 --- /dev/null +++ b/plugins/dys/dys.pro @@ -0,0 +1,5 @@ +include(../plugins.pri)
+
+TARGET = dys
+SOURCES = dys.cpp
+LIBS += -luser32
\ No newline at end of file |