Skip to content
Permalink
Browse files

Merge PR #2650: L4d2 Plugin Simplification

  • Loading branch information...
mkrautz committed Nov 25, 2016
2 parents 64d730a + 8494361 commit db12479e5b39096e502f45503fb75234df281415
Showing with 68 additions and 255 deletions.
  1. +65 −23 plugins/l4d2/{l4d2_win32.cpp → l4d2.cpp}
  2. +3 −9 plugins/l4d2/l4d2.pro
  3. +0 −223 plugins/l4d2/l4d2_linux.cpp
@@ -3,10 +3,58 @@
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#ifdef WIN32
#include "../mumble_plugin_win32_32bit.h" // Include standard plugin header.
#else
#include "../mumble_plugin_linux_32bit.h" // Include standard plugin header.
#endif

#include "../mumble_plugin_utils.h" // Include plugin header for special functions, like "escape".

procptr32_t serverid_steamclient, playerid_engine, player_server; // Variables to contain modules addresses
// Variables to contain modules addresses
procptr32_t steamclient = 0;
procptr32_t server = 0;
procptr32_t engine = 0;

#ifdef WIN32
// Memory offsets
const procptr32_t state_offset = 0x6ACBD5;
const procptr32_t avatar_pos_offset = 0x6B9E1C;
const procptr32_t camera_pos_offset = 0x774B98;
const procptr32_t avatar_front_offset = 0x774BF8;
const procptr32_t avatar_top_offset = 0x774C28;
const procptr32_t host_offset = 0x772B24;
const procptr32_t servername_offset = 0x772D2C;
const procptr32_t map_offset = 0x772C28;
const procptr32_t serverid_steamclient_offset = 0x95E56D;
const procptr32_t player_server_offset = 0x7F87BC;
const procptr32_t playerid_engine_offset = 0x4EBF88;
// Module names
const wchar_t *exe_name = L"left4dead2.exe";
const wchar_t *client_name = L"client.dll";
const wchar_t *steamclient_name = L"steamclient.dll";
const wchar_t *server_name = L"server.dll";
const wchar_t *engine_name = L"engine.dll";
#else
// Memory offsets
const procptr32_t state_offset = 0xE0A24C;
const procptr32_t avatar_pos_offset = 0xE773FC;
const procptr32_t camera_pos_offset = 0xED8700;
const procptr32_t avatar_front_offset = 0xE3C138;
const procptr32_t avatar_top_offset = 0xE3C150;
const procptr32_t host_offset = 0xE356D0;
const procptr32_t servername_offset = 0xE358D8;
const procptr32_t map_offset = 0xE09E9D;
const procptr32_t serverid_steamclient_offset = 0x1216CA5;
const procptr32_t player_server_offset = 0xF340E4;
const procptr32_t playerid_engine_offset = 0xA62C60;
// Module names
const wchar_t *exe_name = L"hl2_linux";
const wchar_t *client_name = L"client.so";
const wchar_t *steamclient_name = L"steamclient.so";
const wchar_t *server_name = L"server.so";
const wchar_t *engine_name = L"engine.so";
#endif

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++) {
@@ -20,20 +68,20 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa
// Char values for extra features
char serverid[22], host[22], servername[50], map[30], player[33], playerid[22];
// State
BYTE state;
unsigned char state;

// Peekproc and assign game addresses to our containers, so we can retrieve positional data
ok = peekProc(pModule + 0x6ACBD5, &state, 1) && // Magical state value: 0 or 255 when in main menu and 1 when in-game.
peekProc(pModule + 0x6B9E1C, avatar_pos_corrector, 12) && // Avatar Position values (X, Z and Y).
peekProc(pModule + 0x774B98, camera_pos_corrector, 12) && // Camera Position values (X, Z and Y).
peekProc(pModule + 0x774BF8, avatar_front_corrector, 12) && // Front vector values (X, Z and Y).
peekProc(pModule + 0x774C28, avatar_top_corrector, 12) && // Top vector values (Z, X and Y).
peekProc(serverid_steamclient, serverid) && // Unique server Steam ID.
peekProc(pModule + 0x772B24, host) && // Server value: "IP:Port" (xxx.xxx.xxx.xxx:yyyyy) when in a remote server, "loopback:0" when on a local server and empty when not playing.
peekProc(pModule + 0x772D2C, servername) && // Server name.
peekProc(pModule + 0x772C28, map) && // Map name.
peekProc(player_server, player) && // Player nickname.
peekProc(playerid_engine, playerid); // Unique player Steam ID.
ok = peekProc(pModule + state_offset, &state, 1) && // Magical state value: 0 or 255 when in main menu and 1 when in-game.
peekProc(pModule + avatar_pos_offset, avatar_pos_corrector, 12) && // Avatar Position values (X, Z and Y).
peekProc(pModule + camera_pos_offset, camera_pos_corrector, 12) && // Camera Position values (X, Z and Y).
peekProc(pModule + avatar_front_offset, avatar_front_corrector, 12) && // Front vector values (X, Z and Y).
peekProc(pModule + avatar_top_offset, avatar_top_corrector, 12) && // Top vector values (Z, X and Y).
peekProc(steamclient + serverid_steamclient_offset, serverid) && // Unique server Steam ID.
peekProc(pModule + host_offset, host) && // Server value: "IP:Port" (xxx.xxx.xxx.xxx:yyyyy) when in a remote server, "loopback:0" when on a local server and empty when not playing.
peekProc(pModule + servername_offset, servername) && // Server name.
peekProc(pModule + map_offset, map) && // Map name.
peekProc(server + player_server_offset, player) && // Player nickname.
peekProc(engine + playerid_engine_offset, playerid); // Unique player Steam ID.

// This prevents the plugin from linking to the game in case something goes wrong during values retrieval from memory addresses.
if (! ok)
@@ -144,34 +192,28 @@ static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, floa

static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids) {

if (! initialize(pids, L"left4dead2.exe", L"client.dll")) { // Retrieve "client.dll" module's memory address
if (! initialize(pids, exe_name, client_name)) { // Retrieve "client_name" module's memory address
return false;
}

// Server ID
procptr32_t steamclient = getModuleAddr(L"steamclient.dll"); // Retrieve "steamclient.dll" module's memory address
steamclient = getModuleAddr(steamclient_name); // Retrieve "steamclient_name" module's memory address
// This prevents the plugin from linking to the game in case something goes wrong during module's memory address retrieval.
if (!steamclient)
return false;

serverid_steamclient = steamclient + 0x95E56D; // Module + Server ID offset

// Player name
procptr32_t server = getModuleAddr(L"server.dll"); // Retrieve "server.dll" module's memory address
server = getModuleAddr(server_name); // Retrieve "server_name" module's memory address
// This prevents the plugin from linking to the game in case something goes wrong during module's memory address retrieval.
if (!server)
return false;

player_server = server + 0x7F87BC; // Module + Player offset

// Player ID
procptr32_t engine = getModuleAddr(L"engine.dll"); // Retrieve "engine.dll" module's memory address
engine = getModuleAddr(engine_name); // Retrieve "engine_name" module's memory address
// This prevents the plugin from linking to the game in case something goes wrong during module's memory address retrieval.
if (!engine)
return false;

playerid_engine = engine + 0x4EBF88; // Module + Player ID offset

// Check if we can get meaningful data from it
float apos[3], afront[3], atop[3], cpos[3], cfront[3], ctop[3];
std::wstring sidentity;
@@ -5,13 +5,7 @@

include(../plugins.pri)

TARGET = l4d2
TARGET = l4d2
SOURCES = l4d2.cpp

win32 {
SOURCES = l4d2_win32.cpp
LIBS += -luser32
}

linux {
SOURCES = l4d2_linux.cpp
}
win32:LIBS += -luser32

This file was deleted.

0 comments on commit db12479

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