diff options
author | Imre Botos <zokny@users.sourceforge.net> | 2010-04-18 17:05:52 +0400 |
---|---|---|
committer | Stefan Hacker <dd0t@users.sourceforge.net> | 2010-04-18 20:20:56 +0400 |
commit | 7b77dea279744b39bda8431f4ef3adc4dd56a67c (patch) | |
tree | 64c47407a989d1ab56e56b751c8cc79ac3754708 /plugins/cs | |
parent | 3c345144b2b46fca5713492320d165416cb7d4e7 (diff) |
Counter-Strike 1.6 Positional Audio support
Diffstat (limited to 'plugins/cs')
-rw-r--r-- | plugins/cs/cs.cpp | 245 |
1 files changed, 76 insertions, 169 deletions
diff --git a/plugins/cs/cs.cpp b/plugins/cs/cs.cpp index 9bec292e4..2ea8e0e2f 100644 --- a/plugins/cs/cs.cpp +++ b/plugins/cs/cs.cpp @@ -30,117 +30,30 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <stdio.h> -#include <stdlib.h> -#include <windows.h> -#include <tlhelp32.h> -#include <string> -#include <sstream> - -#define _USE_MATH_DEFINES -#include <math.h> - -#include "mumble_plugin.h" +#include "mumble_plugin_win32.h" using namespace std; -HANDLE h; -BYTE *pClient; BYTE *pEngine; -/* DESCRIPTION ADDRESS TYPE VALUE - - * Client based addresses - Connected to server: client.dll+0xFC228 byte (0 - not; 1 - connected) - Position tuple: client.dll+0x11D470 float (x, y, z in inches) - Orientation tuple: client.dll+0x11D47C float (v, h in degrees) - Check string: client.dll+0xE46F5 char ("CSSpectatorGUI@@" | 16 bytes) - Player state: client.dll+0xFBC2C byte (0 - died; 1 - stand; 2 - duck; 3 - walk; 4 - run; 5 - crouchmove; 6 - fall) - Team state: client.dll+0xFC94C byte (0 - Spectator; 1 - Terrorist; 2 - Counter-Terrorist) - ALT+TAB: client.dll+0xFD05C byte (0 - tabbed; 1 - ingame) - Map string: client.dll+0x11DCE4 str ("maps/de_nuke.bsp") - - * Engine based addresses - IP:Port string hw.dll+0x697E60 str (ip:port) - ALT+TAB: hw.dll+0x7486B4 byte (0 - tabbed; 1 - ingame) +/* DESCRIPTION ADDRESS TYPE VALUE + + * Client based addresses + Connected to server: client.dll+0xFC228 byte (0 - not; 1 - connected) + Position tuple: client.dll+0x11D470 float (x, y, z in inches) + Orientation tuple: client.dll+0x11D47C float (v, h in degrees) + Check string: client.dll+0xE46F5 char ("CSSpectatorGUI@@" | 16 bytes) + Player state: client.dll+0xFBC2C byte (0 - died; 1 - stand; 2 - duck; 3 - walk; 4 - run; 5 - crouchmove; 6 - fall) + Team state: client.dll+0xFC94C byte (0 - Spectator; 1 - Terrorist; 2 - Counter-Terrorist) + ALT+TAB: client.dll+0xFD05C byte (0 - tabbed; 1 - ingame) + Map string: client.dll+0x11DCE4 str ("maps/de_nuke.bsp") + + * Engine based addresses + IP:Port string hw.dll+0x697E60 str (ip:port) + ALT+TAB: hw.dll+0x7486B4 byte (0 - tabbed; 1 - ingame) */ -void __cdecl ods(const char *format, ...) { - char buf[4096], *p = buf; - va_list args; - - va_start(args, format); - int len = _vsnprintf_s(p, sizeof(buf) - 1, _TRUNCATE, format, args); - va_end(args); - - if (len <= 0) - return; - - p += len; - - while (p > buf && isspace(p[-1])) - *--p = '\0'; - - *p++ = '\r'; - *p++ = '\n'; - *p = '\0'; - - OutputDebugStringA(buf); -} - -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 Counter-Strike 1.6. IP:Port context support.", L"Mumble CS Plugin", MB_OK); -} - -static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, float *camera_pos, float *camera_front, float *camera_top, std::string &context, std::wstring &identity) { +static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, float *camera_pos, float *camera_front, float *camera_top, string &context, wstring &identity) { for (int i=0;i<3;i++) avatar_pos[i] = avatar_front[i] = avatar_top[i] = camera_pos[i] = camera_front[i] = camera_top[i] = 0.0f; @@ -150,23 +63,25 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa char cHostAddr[40]; float fViewHor, fViewVer; - /* Dust2 - INC DEC | Ver Hor - X - hosszú fele B fele | 0 közép 0/360 hosszú fele - Y - CT kezdő fele T kezdő fele | -89 felnéz 90 CT kezdő fele - Z - felfele lefele | 89 lenéz 180 B fele - | 270 T kezdő fele - */ - - ok = peekProc((BYTE*) pClient + 0x11D470, avatar_pos, 12) && - peekProc((BYTE*) pClient + 0x11D47C, &fViewHor, 4) && - peekProc((BYTE*) pClient + 0x11D480, &fViewVer, 4) && - peekProc((BYTE*) pClient + 0xFC228, &bConnected, 1) && - peekProc((BYTE*) pClient + 0xFBC2C, &cPlayerState, 1) && - peekProc((BYTE*) pEngine + 0x697E60, cHostAddr, 40); - if(!ok){ - //ods("MUMBLECSPLUGIN Error: peekProc failed\n"); - return false;} + /* Dust2 + INC DEC | Ver Hor + X - long B | 0 center 0/360 long + Y - CT spawn T spawn | -89 lookup 90 CT spawn + Z - up down | 89 lookdown 180 B + | 270 T spawn + */ + + ok = peekProc((BYTE*) pModule + 0x11D470, avatar_pos, 12) && + peekProc((BYTE*) pModule + 0x11D47C, &fViewHor, 4) && + peekProc((BYTE*) pModule + 0x11D480, &fViewVer, 4) && + peekProc((BYTE*) pModule + 0xFC228, &bConnected, 1) && + peekProc((BYTE*) pModule + 0xFBC2C, &cPlayerState, 1) && + peekProc((BYTE*) pEngine + 0x697E60, cHostAddr, 40); + if (!ok) + return false; + + if (!bConnected) + return true; /* // FOR TEST ONLY - constant position (d2 CT middle, looking T spawn through doorgap) avatar_pos[0] = -380.359375f; @@ -175,29 +90,28 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa fViewHor = 269,703369140625; fViewVer = -4,45587635040283; */ - if(!bConnected){ - //ods("MUMBLECSPLUGIN: Not connected!\n"); - return true;} context = cHostAddr; - if(!cPlayerState){ - //ods("MUMBLECSPLUGIN: Player dead!\n"); - return true;} - - //ods("MUMBLECSPLUGIN Active: %d, %s, %d", bConnected, cHostAddr, cPlayerState); + if(!cPlayerState) + return true; - for (int i=0;i<3;i++) - avatar_pos[i] /= 39.37f; + if ((fViewHor < -360.0f) || (fViewVer > 360.0f) || (fViewHor < -360.0f) || (fViewHor > 360.0f)) + return false; fViewHor *= static_cast<float>(M_PI / 180.0f); fViewVer *= static_cast<float>(M_PI / 180.0f); + avatar_pos[0] = avatar_pos[0] / 39.37f; + avatar_pos[1] = avatar_pos[2] / 39.37f; + avatar_pos[2] = avatar_pos[1] / 39.37f; + avatar_front[0] = cos(fViewVer) * cos(fViewHor); avatar_front[1] = -sin(fViewHor); avatar_front[2] = sin(fViewVer) * cos(fViewHor); fViewHor -= static_cast<float>(M_PI / 2.0f); + avatar_top[0] = cos(fViewVer) * cos(fViewHor); avatar_top[1] = -sin(fViewHor); avatar_top[2] = sin(fViewVer) * cos(fViewHor); @@ -211,53 +125,32 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa return true; } -static int trylock() { - - h = NULL; +static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids) { - DWORD pid = getProcess(L"hl.exe"); - if (!pid){ - //ods("MUMBLECSPLUGIN: GetProcess(\"hl.exe\") failed!\n"); - return false;} + if (! initialize(pids, L"hl.exe", L"client.dll")) + return false; - pClient = getModuleAddr(pid, L"client.dll"); - if (!pClient){ - //ods("MUMBLECSPLUGIN: GetModule(\"client.dll\") failed!\n"); - return false;} - pEngine = getModuleAddr(pid, L"hw.dll"); - if (!pEngine){ - //ods("MUMBLECSPLUGIN: GetModule(\"hw.dll\") failed!\n"); - return false;} + pEngine = getModuleAddr(L"hw.dll"); + if (!pEngine) + return false; - h = OpenProcess(PROCESS_VM_READ, false, pid); - if (!h){ - //ods("MUMBLECSPLUGIN: OpenProccess() failed!\n"); - return false;} + // Gamecheck + char sMagic[16]; + if (!peekProc(pModule + 0xE46F5, sMagic, 16) || strncmp("CSSpectatorGUI@@", sMagic, 16)!=0) + return false; float apos[3], afront[3], atop[3], cpos[3], cfront[3], ctop[3]; std::string context; std::wstring identity; - if (fetch(apos, afront, atop, cpos, cfront, ctop, context, identity)) + if (fetch(apos, afront, atop, cpos, cfront, ctop, context, identity)){ return true; - - //ods("MUMBLECSPLUGIN: fetch() failed!\n"); - - CloseHandle(h); - h = NULL; - return false; -} - -static void unlock() { - //ods("MUMBLECSPLUGIN: unlock()\n"); - if (h) { - CloseHandle(h); - h = NULL; + } else { + generic_unlock(); + return false; } - return; } - static const std::wstring longdesc() { return std::wstring(L"Supports Counter-Strike 1.6 (Steam). Context support based on server address. No identity support."); } @@ -265,18 +158,32 @@ static const std::wstring longdesc() { static std::wstring description(L"Counter-Strike 1.6"); static std::wstring shortname(L"Counter-Strike"); +static int trylock1(){ + return trylock(std::multimap<std::wstring, unsigned long long int>()); +} + static MumblePlugin csplug = { MUMBLE_PLUGIN_MAGIC, description, shortname, - about, NULL, - trylock, - unlock, + NULL, + trylock1, + generic_unlock, longdesc, fetch }; +static MumblePlugin2 csplug2 = { + MUMBLE_PLUGIN_MAGIC_2, + MUMBLE_PLUGIN_VERSION, + trylock +}; + extern "C" __declspec(dllexport) MumblePlugin *getMumblePlugin() { return &csplug; } + +extern "C" __declspec(dllexport) MumblePlugin2 *getMumblePlugin2() { + return &csplug2; +} |