Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuck Therebelos <snares@users.sourceforge.net>2009-12-10 11:46:37 +0300
committerTuck Therebelos <snares@users.sourceforge.net>2009-12-10 11:46:37 +0300
commita4ea89c1cf467fd5d1ab1cb96aee959416d4fa59 (patch)
treec88098d13b3ac1de6c7017998d0c8de57d9241c6 /plugins/bf2142
parente9f7e0a732f9a0841e3d72d1ae22f7ddf218d61f (diff)
Added BFHeroes plugin; updated BF2 and BF2142 with IP contexts and improved linkstates
Diffstat (limited to 'plugins/bf2142')
-rw-r--r--plugins/bf2142/bf2142.cpp126
1 files changed, 46 insertions, 80 deletions
diff --git a/plugins/bf2142/bf2142.cpp b/plugins/bf2142/bf2142.cpp
index 8a67043e7..48d75a338 100644
--- a/plugins/bf2142/bf2142.cpp
+++ b/plugins/bf2142/bf2142.cpp
@@ -7,11 +7,10 @@
#include "../mumble_plugin.h"
HANDLE h;
+
BYTE *posptr;
BYTE *faceptr;
BYTE *topptr;
-BYTE *velptr;
-
static DWORD getProcess(const wchar_t *exename) {
PROCESSENTRY32 pe;
@@ -61,8 +60,6 @@ static bool peekProc(VOID *base, VOID *dest, SIZE_T len) {
return (ok && (r == len));
}
-static BYTE scratchbuffer[128];
-
static DWORD peekProc(VOID *base) {
DWORD v = 0;
peekProc(base, reinterpret_cast<BYTE *>(&v), sizeof(DWORD));
@@ -75,59 +72,59 @@ static BYTE *peekProcPtr(VOID *base) {
}
static void about(HWND h) {
- ::MessageBox(h, L"Reads audio position information from BF2142 (v1.50)", L"Mumble BF2142 Plugin", MB_OK);
+ ::MessageBox(h, L"Reads audio position information from BF2142 (v1.50). IP:Port context support.", L"Mumble BF2142 Plugin", MB_OK);
}
-static bool sane(float *avatar_pos, float *vel, float *avatar_face, float *avatar_top, bool initial = false) {
- int i;
- bool ok = true;
+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) {
+ for (int i=0;i<3;i++)
+ avatar_pos[i]=avatar_front[i]=avatar_top[i]=0.0f;
- float min = (initial) ? 0.1f : 0.00001f;
+ char ccontext[128];
+ char state;
- // Sanity check #1: Position should be from -2000 to +2000, and not 0.
- for (i=0;i<3;i++) {
- ok = ok && (fabs(avatar_pos[i]) > min);
- ok = ok && (fabs(avatar_pos[i]) < 2000.0);
- }
- if (! ok) {
- return false;
- }
+ bool ok;
- // Sanity check #2: Directional vectors should have length 1. (and 1 * 1 == 1, so no sqrt)
- double sqdist;
- sqdist=avatar_face[0] * avatar_face[0] + avatar_face[1] * avatar_face[1] + avatar_face[2] * avatar_face[2];
- if (fabs(sqdist - 1.0) > 0.1) {
+ /*
+ state value is:
+ 0 while not in game
+ usually 1, never 0 if you create your own server ingame; this value will switch to 1 the instant you click "Join Game"
+ usually 3, never 0 if you load into a server; this value will switch to 3 the instant you click "Join Game"
+ */
+ ok = peekProc((BYTE *) 0x00B47968, &state, 1); // Magical state value
+ if (! ok)
return false;
- }
+ ok = peekProc(posptr, avatar_pos, 12) &&
+ peekProc(faceptr, avatar_front, 12) &&
+ peekProc(topptr, avatar_top, 12);
+ peekProc((BYTE *) 0x00B527B8, ccontext, 128);
- sqdist=avatar_top[0] * avatar_top[0] + avatar_top[1] * avatar_top[1] + avatar_top[2] * avatar_top[2];
- if (fabs(sqdist - 1.0) > 0.1) {
+ if (! ok)
return false;
- }
- if (! initial)
- return true;
+ /*
+ Get context string; in this plugin this will be an
+ ip:port (char 256 bytes) string
+ */
+ ccontext[127] = 0;
+ context = std::string(ccontext);
- // .. and it's not looking STRAIGHT ahead...
- if (avatar_face[2] == 1.0)
- return false;
- if (avatar_top[1] == 1.0)
- return false;
+ if (state == 0)
+ return true; // This results in all vectors beeing zero which tells Mumble to ignore them.
- // Sanity check #3: Initial speed vector should be >0.2 (BF2142 gravity) and < 1.0
- sqdist=vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2];
- if ((sqdist < 0.2) || (sqdist > 1.0))
- return false;
+ for (int i=0;i<3;i++) {
+ camera_pos[i] = avatar_pos[i];
+ camera_front[i] = avatar_front[i];
+ camera_top[i] = avatar_top[i];
+ }
- // We're good!
- return true;
+ return ok;
}
static int trylock() {
h = NULL;
- posptr = faceptr = topptr = velptr = NULL;
+ posptr = faceptr = topptr = NULL;
DWORD pid=getProcess(L"BF2142.exe");
if (!pid)
@@ -140,30 +137,20 @@ static int trylock() {
if (!h)
return false;
- BYTE *cacheaddr= mod + 0x4745c;
+ BYTE *cacheaddr = mod + 0x4745c;
BYTE *cache = peekProcPtr(cacheaddr);
posptr = peekProcPtr(cache + 0xc0);
faceptr = peekProcPtr(cache + 0xc4);
topptr = peekProcPtr(cache + 0xc8);
- velptr = peekProcPtr(cache + 0xcc);
- if (cache && posptr && faceptr && topptr && velptr) {
- float avatar_pos[3];
- float vel[3];
- float avatar_face[3];
- float avatar_top[3];
-
- bool ok = peekProc(posptr, avatar_pos, 12) &&
- peekProc(velptr, vel, 12) &&
- peekProc(faceptr, avatar_face, 12) &&
- peekProc(topptr, avatar_top, 12);
-
- if (ok)
- ok = sane(avatar_pos, vel, avatar_face, avatar_top, true);
-
- if (ok)
- return true;
- }
+
+ 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))
+ return true;
+
CloseHandle(h);
h = NULL;
return false;
@@ -177,29 +164,8 @@ static void unlock() {
return;
}
-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) {
- float vel[3];
- bool ok;
- ok = peekProc(posptr, avatar_pos, 12) &&
- peekProc(velptr, vel, 12) &&
- peekProc(faceptr, avatar_front, 12) &&
- peekProc(topptr, avatar_top, 12);
-
- for (int i=0;i<3;i++) {
- camera_pos[i] = avatar_pos[i];
- camera_front[i] = avatar_front[i];
- camera_top[i] = avatar_top[i];
- }
-
- if (ok) {
- ok = sane(avatar_pos, vel, avatar_front, avatar_top);
- }
-
- return ok;
-}
-
static const std::wstring longdesc() {
- return std::wstring(L"Supports Battlefield 2142 v1.50. No context or identity support yet.");
+ return std::wstring(L"Supports Battlefield 2142 v1.50. No identity support yet.");
}
static std::wstring description(L"Battlefield 2142 v1.50");