Skip to content
Permalink
Browse files

Merge PR #2361: plugins/ql: Native front and top vectors

  • Loading branch information...
mkrautz committed Jun 23, 2016
2 parents ea372de + c1b91cf commit d21de05d240f73d14f4e07d07239375c15666865
Showing with 24 additions and 23 deletions.
  1. +24 −23 plugins/ql/ql.cpp
@@ -14,20 +14,21 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa
// Boolean values to check if game addresses retrieval is successful and if player is in-game
bool ok, state, spec;
// Create containers to stuff our raw data into, so we can convert it to Mumble's coordinate system
float avatar_pos_corrector[3], camera_pos_corrector[3], viewHor, viewVer;
float avatar_pos_corrector[3], camera_pos_corrector[3], avatar_front_corrector[3], avatar_top_corrector[3];
// Char values for extra features
char host[22], map[30];
char host[22], servername[50], map[30];
// Team
BYTE team;

// Peekproc and assign game addresses to our containers, so we can retrieve positional data
ok = peekProc(pModule + 0x0188248, &state, 1) && // Magical state value: 1 when in-game and 0 when in main menu.
peekProc(pModule + 0x1041C68, &spec, 1) && // Spectator state value: 1 when spectating and 0 when playing.
peekProc(pModule + 0x0EB8950, avatar_pos_corrector, 12) && // Avatar Position values (Z, X and Y, respectively).
peekProc(pModule + 0x0E6093C, camera_pos_corrector, 12) && // Camera Position values (Z, X and Y, respectively).
peekProc(pModule + 0x106CE04, &viewHor, 4) && // Changes in a range from 180 to -180 when moving the view to left/right.
peekProc(pModule + 0x106CE00, &viewVer, 4) && // Changes in a range from 87.890625 (looking down) to -87.890625 (looking up).
peekProc(pModule + 0x0EB8950, avatar_pos_corrector, 12) && // Avatar Position values (X, Z and Y, respectively).
peekProc(pModule + 0x0E6093C, camera_pos_corrector, 12) && // Camera Position values (X, Z and Y, respectively).
peekProc(pModule + 0x0EC5B50, avatar_front_corrector, 12) && // Avatar front values (X, Z and Y, respectively).
peekProc(pModule + 0x0EC5B68, avatar_top_corrector, 12) && // Avatar top values (X, Z and Y, respectively).
peekProc(pModule + 0x0E4A638, host) && // Server value: "IP:Port" when in a remote server, "loopback" when on a local server.
peekProc(pModule + 0x106E24B, servername) && // Server name.
peekProc(pModule + 0x12DE8D8, map) && // Map name.
peekProc(pModule + 0x106CE6C, team); // Team value: 0 when in a FFA game (no team); 1 when in Red team; 2 when in Blue team; 3 when in Spectators.

@@ -88,11 +89,11 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa
if (team >= 0 && team <= 3) {
if (team == 0)
oidentity << std::endl << "\"Team\": \"FFA\""; // If team value is 0, set "FFA" as team in identity.
else if (team == 1)
if (team == 1)
oidentity << std::endl << "\"Team\": \"Red\""; // If team value is 1, set "Red" as team in identity.
else if (team == 2)
if (team == 2)
oidentity << std::endl << "\"Team\": \"Blue\""; // If team value is 2, set "Blue" as team in identity.
else if (team == 3)
if (team == 3)
oidentity << std::endl << "\"Team\": \"Spectators\""; // If team value is 3, set "Spectators" as team in identity.
} else {
oidentity << std::endl << "\"Team\": null";
@@ -104,30 +105,30 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa

/*
Mumble | Game
X | Y
X | X
Y | Z
Z | X
Z | Y
*/
avatar_pos[0] = avatar_pos_corrector[1];
avatar_pos[0] = avatar_pos_corrector[0];
avatar_pos[1] = avatar_pos_corrector[2];
avatar_pos[2] = avatar_pos_corrector[0];
avatar_pos[2] = avatar_pos_corrector[1];

camera_pos[0] = camera_pos_corrector[1];
camera_pos[0] = camera_pos_corrector[0];
camera_pos[1] = camera_pos_corrector[2];
camera_pos[2] = camera_pos_corrector[0];
camera_pos[2] = camera_pos_corrector[1];

// Calculate view unit vector
viewVer *= static_cast<float>(M_PI / 180.0f);
viewHor *= static_cast<float>(M_PI / 180.0f);
avatar_front[0] = avatar_front_corrector[0];
avatar_front[1] = avatar_front_corrector[2];
avatar_front[2] = avatar_front_corrector[1];

avatar_front[0] = camera_front[0] = cos(viewVer) * cos(viewHor);
avatar_front[1] = camera_front[1] = -sin(viewVer);
avatar_front[2] = camera_front[2] = cos(viewVer) * sin(viewHor);

avatar_top[2] = camera_top[2] = -1; // This tells Mumble to automatically calculate top vector using front vector.
avatar_top[0] = avatar_top_corrector[0];
avatar_top[1] = avatar_top_corrector[2];
avatar_top[2] = avatar_top_corrector[1];

// Scale to meters
for (int i=0;i<3;i++) {
camera_front[i] = avatar_front[i];
camera_top[i] = avatar_top[i];
avatar_pos[i]/=70.0f;
camera_pos[i]/=70.0f;
}

0 comments on commit d21de05

Please sign in to comment.
You can’t perform that action at this time.