diff options
author | Davide Beatrici <davidebeatrici@gmail.com> | 2017-01-22 19:09:18 +0300 |
---|---|---|
committer | Jan Klass <kissaki@posteo.de> | 2017-01-29 15:02:58 +0300 |
commit | 474b3700aeef869ca2df37227e9e27aea982e6fe (patch) | |
tree | 8e863342e2ba16fbe8d62aef98ecbc7f03311760 /plugins/bf4 | |
parent | 82d385f6bdd6de8d80b3aa28c87947eb0df12d57 (diff) |
plugins: Fix indentation and whitespace
* Use tabs for indentation
* Remove trailing whitespace
* Space indentation for alignment
Diffstat (limited to 'plugins/bf4')
-rw-r--r-- | plugins/bf4/bf4.cpp | 384 |
1 files changed, 192 insertions, 192 deletions
diff --git a/plugins/bf4/bf4.cpp b/plugins/bf4/bf4.cpp index 07785a23f..b8ac453fe 100644 --- a/plugins/bf4/bf4.cpp +++ b/plugins/bf4/bf4.cpp @@ -7,209 +7,209 @@ #include "../mumble_plugin_utils.h" // Include plugin header for special functions, like "escape". 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] = camera_pos[i] = camera_front[i] = camera_top[i] = 0.0f; - } - - bool ok, state; - char serverid[37], host[22], team[3]; - BYTE squad, squad_leader, squad_state; - - // Server ID pointers - procptr64_t serverid_base = peekProc<procptr64_t>(pModule + 0x02210658); - if (!serverid_base) return false; - procptr64_t serverid_offset_0 = peekProc<procptr64_t>(serverid_base + 0x18); - if (!serverid_offset_0) return false; - procptr64_t serverid_offset_1 = peekProc<procptr64_t>(serverid_offset_0 + 0x28); - if (!serverid_offset_1) return false; - procptr64_t serverid_offset = peekProc<procptr64_t>(serverid_offset_1 + 0x350); - if (!serverid_offset) return false; - - // Squad pointers - procptr64_t squad_base = peekProc<procptr64_t>(pModule + 0x02210718); - if (!squad_base) return false; - procptr64_t squad_offset_0 = peekProc<procptr64_t>(squad_base + 0xD8); - if (!squad_offset_0) return false; - procptr64_t squad_offset_1 = peekProc<procptr64_t>(squad_offset_0 + 0x100); - if (!squad_offset_1) return false; - procptr64_t squad_offset_2 = peekProc<procptr64_t>(squad_offset_1 + 0x58); - if (!squad_offset_2) return false; - - // Peekproc and assign game addresses to our containers, so we can retrieve positional data - ok = peekProc(pModule + 0x21CAFF0, &state, 1) && // Magical state value: 0 when in-game and 1 when in menu/dead. - peekProc(pModule + 0x21C6D40, avatar_pos, 12) && // Avatar Position values (X, Y and Z). - peekProc(pModule + 0x21CAF80, camera_pos, 12) && // Camera Position values (X, Y and Z). - peekProc(pModule + 0x21CAF60, avatar_top, 12) && // Avatar Top Vector values (X, Y and Z). - peekProc(pModule + 0x21CAF70, avatar_front, 12) && // Avatar Front Vector values (X, Y and Z). - peekProc(serverid_offset, serverid) && // Server ID (36 characters). - peekProc(pModule + 0x21B80C0, host) && // Host value: "IP:Port" when in a server, "bot" when loading and empty when it's hidden. - peekProc(pModule + 0x24AFAE5, team) && // Team value: US (United States); RU (Russia); CH (China). - peekProc(squad_offset_2 + 0x230, squad) && // Squad value: 0 (not in a squad); 1 (Alpha); 2 (Bravo); 3 (Charlie)... 26 (Zulu). - peekProc(squad_offset_2 + 0x234, squad_leader) && // Squad leader value: 0 (False); 1 (True). - peekProc(squad_offset_2 + 0x235, squad_state); // Squad state value: 0 (Public); 1 (Private). - - // This prevents the plugin from linking to the game in case something goes wrong during values retrieval from memory addresses. - if (! ok) { - return false; - } - - if (state) { // If not in-game - context.clear(); // Clear context - identity.clear(); // Clear identity - // Set vectors values to 0. - 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; - } - - return true; // This tells Mumble to ignore all vectors. - } - - escape(serverid, sizeof(serverid)); - std::ostringstream ocontext; - ocontext << " {\"Server ID\": \"" << serverid << "\"}"; // Set context with server ID - context = ocontext.str(); - - std::wostringstream oidentity; - oidentity << "{"; - escape(host, sizeof(host)); - // Only include host (IP:port) if it is not empty and does not include the string "bot" (which means it's a local server). - if (strcmp(host, "") != 0 && strstr(host, "bot") == NULL) { - oidentity << std::endl << "\"Host\": \"" << host << "\","; - } - - std::string Team(team); - if (!Team.empty()) { - oidentity << std::endl; - if (Team == "US") - oidentity << "\"Team\": \"United States\","; // If team value is US, set "United States" as team in identity. - else if (Team == "CH") - oidentity << "\"Team\": \"China\","; // If team value is CH, set "China" as team in identity. - else if (Team == "RU") - oidentity << "\"Team\": \"Russia\","; // If team value is RU, set "Russia" as team in identity. - } - - // If squad value is in a value between 1 and 26, set squad name in identity using NATO Phonetic alphabet. - if (squad > 0 && squad < 27) { - if (squad == 1) - oidentity << std::endl << "\"Squad\": \"Alpha\","; - else if (squad == 2) - oidentity << std::endl << "\"Squad\": \"Bravo\","; - else if (squad == 3) - oidentity << std::endl << "\"Squad\": \"Charlie\","; - else if (squad == 4) - oidentity << std::endl << "\"Squad\": \"Delta\","; - else if (squad == 5) - oidentity << std::endl << "\"Squad\": \"Echo\","; - else if (squad == 6) - oidentity << std::endl << "\"Squad\": \"Foxtrot\","; - else if (squad == 7) - oidentity << std::endl << "\"Squad\": \"Golf\","; - else if (squad == 8) - oidentity << std::endl << "\"Squad\": \"Hotel\","; - else if (squad == 9) - oidentity << std::endl << "\"Squad\": \"India\","; - else if (squad == 10) - oidentity << std::endl << "\"Squad\": \"Juliet\","; - else if (squad == 11) - oidentity << std::endl << "\"Squad\": \"Kilo\","; - else if (squad == 12) - oidentity << std::endl << "\"Squad\": \"Lima\","; - else if (squad == 13) - oidentity << std::endl << "\"Squad\": \"Mike\","; - else if (squad == 14) - oidentity << std::endl << "\"Squad\": \"November\","; - else if (squad == 15) - oidentity << std::endl << "\"Squad\": \"Oscar\","; - else if (squad == 16) - oidentity << std::endl << "\"Squad\": \"Papa\","; - else if (squad == 17) - oidentity << std::endl << "\"Squad\": \"Quebec\","; - else if (squad == 18) - oidentity << std::endl << "\"Squad\": \"Romeo\","; - else if (squad == 19) - oidentity << std::endl << "\"Squad\": \"Sierra\","; - else if (squad == 20) - oidentity << std::endl << "\"Squad\": \"Tango\","; - else if (squad == 21) - oidentity << std::endl << "\"Squad\": \"Uniform\","; - else if (squad == 22) - oidentity << std::endl << "\"Squad\": \"Victor\","; - else if (squad == 23) - oidentity << std::endl << "\"Squad\": \"Whiskey\","; - else if (squad == 24) - oidentity << std::endl << "\"Squad\": \"X-ray\","; - else if (squad == 25) - oidentity << std::endl << "\"Squad\": \"Yankee\","; - else if (squad == 26) - oidentity << std::endl << "\"Squad\": \"Zulu\","; - // Squad leader - if (squad_leader == 1) - oidentity << std::endl << "\"Squad leader\": true,"; // If squad leader value is true, set squad leader state to "True" in identity. - else - oidentity << std::endl << "\"Squad leader\": false,"; // If squad leader value is false, set squad leader state to "False" in identity. - // Squad state - if (squad_state == 1) - oidentity << std::endl << "\"Squad state\": \"Private\""; // If squad state value is true, set squad state to "Private" in identity. - else - oidentity << std::endl << "\"Squad state\": \"Public\""; // If squad state value is false, set squad state to "Public" in identity. - // When not in a squad - } else { - oidentity << std::endl << "\"Squad\": null,"; // If squad value isn't between 1 and 26, set squad to "null" in identity. - oidentity << std::endl << "\"Squad leader\": null,"; // If not in a squad, set squad leader state to "null" in identity. - oidentity << std::endl << "\"Squad state\": null"; // If not in a squad, set squad state to "null" in identity. - } - - oidentity << std::endl << "}"; - identity = oidentity.str(); - - // Flip the front vector - for (int i=0;i<3;i++) { - avatar_front[i] = -avatar_front[i]; - } - - // Convert from right to left handed - avatar_pos[0] = -avatar_pos[0]; - camera_pos[0] = -camera_pos[0]; - avatar_front[0] = -avatar_front[0]; - avatar_top[0] = -avatar_top[0]; - - // Sync camera front and top vectors with avatar ones - for (int i=0;i<3;i++) { - camera_front[i] = avatar_front[i]; - camera_top[i] = avatar_top[i]; - } - - return true; + 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; + } + + bool ok, state; + char serverid[37], host[22], team[3]; + BYTE squad, squad_leader, squad_state; + + // Server ID pointers + procptr64_t serverid_base = peekProc<procptr64_t>(pModule + 0x02210658); + if (!serverid_base) return false; + procptr64_t serverid_offset_0 = peekProc<procptr64_t>(serverid_base + 0x18); + if (!serverid_offset_0) return false; + procptr64_t serverid_offset_1 = peekProc<procptr64_t>(serverid_offset_0 + 0x28); + if (!serverid_offset_1) return false; + procptr64_t serverid_offset = peekProc<procptr64_t>(serverid_offset_1 + 0x350); + if (!serverid_offset) return false; + + // Squad pointers + procptr64_t squad_base = peekProc<procptr64_t>(pModule + 0x02210718); + if (!squad_base) return false; + procptr64_t squad_offset_0 = peekProc<procptr64_t>(squad_base + 0xD8); + if (!squad_offset_0) return false; + procptr64_t squad_offset_1 = peekProc<procptr64_t>(squad_offset_0 + 0x100); + if (!squad_offset_1) return false; + procptr64_t squad_offset_2 = peekProc<procptr64_t>(squad_offset_1 + 0x58); + if (!squad_offset_2) return false; + + // Peekproc and assign game addresses to our containers, so we can retrieve positional data + ok = peekProc(pModule + 0x21CAFF0, &state, 1) && // Magical state value: 0 when in-game and 1 when in menu/dead. + peekProc(pModule + 0x21C6D40, avatar_pos, 12) && // Avatar Position values (X, Y and Z). + peekProc(pModule + 0x21CAF80, camera_pos, 12) && // Camera Position values (X, Y and Z). + peekProc(pModule + 0x21CAF60, avatar_top, 12) && // Avatar Top Vector values (X, Y and Z). + peekProc(pModule + 0x21CAF70, avatar_front, 12) && // Avatar Front Vector values (X, Y and Z). + peekProc(serverid_offset, serverid) && // Server ID (36 characters). + peekProc(pModule + 0x21B80C0, host) && // Host value: "IP:Port" when in a server, "bot" when loading and empty when it's hidden. + peekProc(pModule + 0x24AFAE5, team) && // Team value: US (United States); RU (Russia); CH (China). + peekProc(squad_offset_2 + 0x230, squad) && // Squad value: 0 (not in a squad); 1 (Alpha); 2 (Bravo); 3 (Charlie)... 26 (Zulu). + peekProc(squad_offset_2 + 0x234, squad_leader) && // Squad leader value: 0 (False); 1 (True). + peekProc(squad_offset_2 + 0x235, squad_state); // Squad state value: 0 (Public); 1 (Private). + + // This prevents the plugin from linking to the game in case something goes wrong during values retrieval from memory addresses. + if (! ok) { + return false; + } + + if (state) { // If not in-game + context.clear(); // Clear context + identity.clear(); // Clear identity + // Set vectors values to 0. + 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; + } + + return true; // This tells Mumble to ignore all vectors. + } + + escape(serverid, sizeof(serverid)); + std::ostringstream ocontext; + ocontext << " {\"Server ID\": \"" << serverid << "\"}"; // Set context with server ID + context = ocontext.str(); + + std::wostringstream oidentity; + oidentity << "{"; + escape(host, sizeof(host)); + // Only include host (IP:port) if it is not empty and does not include the string "bot" (which means it's a local server). + if (strcmp(host, "") != 0 && strstr(host, "bot") == NULL) { + oidentity << std::endl << "\"Host\": \"" << host << "\","; + } + + std::string Team(team); + if (!Team.empty()) { + oidentity << std::endl; + if (Team == "US") + oidentity << "\"Team\": \"United States\","; // If team value is US, set "United States" as team in identity. + else if (Team == "CH") + oidentity << "\"Team\": \"China\","; // If team value is CH, set "China" as team in identity. + else if (Team == "RU") + oidentity << "\"Team\": \"Russia\","; // If team value is RU, set "Russia" as team in identity. + } + + // If squad value is in a value between 1 and 26, set squad name in identity using NATO Phonetic alphabet. + if (squad > 0 && squad < 27) { + if (squad == 1) + oidentity << std::endl << "\"Squad\": \"Alpha\","; + else if (squad == 2) + oidentity << std::endl << "\"Squad\": \"Bravo\","; + else if (squad == 3) + oidentity << std::endl << "\"Squad\": \"Charlie\","; + else if (squad == 4) + oidentity << std::endl << "\"Squad\": \"Delta\","; + else if (squad == 5) + oidentity << std::endl << "\"Squad\": \"Echo\","; + else if (squad == 6) + oidentity << std::endl << "\"Squad\": \"Foxtrot\","; + else if (squad == 7) + oidentity << std::endl << "\"Squad\": \"Golf\","; + else if (squad == 8) + oidentity << std::endl << "\"Squad\": \"Hotel\","; + else if (squad == 9) + oidentity << std::endl << "\"Squad\": \"India\","; + else if (squad == 10) + oidentity << std::endl << "\"Squad\": \"Juliet\","; + else if (squad == 11) + oidentity << std::endl << "\"Squad\": \"Kilo\","; + else if (squad == 12) + oidentity << std::endl << "\"Squad\": \"Lima\","; + else if (squad == 13) + oidentity << std::endl << "\"Squad\": \"Mike\","; + else if (squad == 14) + oidentity << std::endl << "\"Squad\": \"November\","; + else if (squad == 15) + oidentity << std::endl << "\"Squad\": \"Oscar\","; + else if (squad == 16) + oidentity << std::endl << "\"Squad\": \"Papa\","; + else if (squad == 17) + oidentity << std::endl << "\"Squad\": \"Quebec\","; + else if (squad == 18) + oidentity << std::endl << "\"Squad\": \"Romeo\","; + else if (squad == 19) + oidentity << std::endl << "\"Squad\": \"Sierra\","; + else if (squad == 20) + oidentity << std::endl << "\"Squad\": \"Tango\","; + else if (squad == 21) + oidentity << std::endl << "\"Squad\": \"Uniform\","; + else if (squad == 22) + oidentity << std::endl << "\"Squad\": \"Victor\","; + else if (squad == 23) + oidentity << std::endl << "\"Squad\": \"Whiskey\","; + else if (squad == 24) + oidentity << std::endl << "\"Squad\": \"X-ray\","; + else if (squad == 25) + oidentity << std::endl << "\"Squad\": \"Yankee\","; + else if (squad == 26) + oidentity << std::endl << "\"Squad\": \"Zulu\","; + // Squad leader + if (squad_leader == 1) + oidentity << std::endl << "\"Squad leader\": true,"; // If squad leader value is true, set squad leader state to "True" in identity. + else + oidentity << std::endl << "\"Squad leader\": false,"; // If squad leader value is false, set squad leader state to "False" in identity. + // Squad state + if (squad_state == 1) + oidentity << std::endl << "\"Squad state\": \"Private\""; // If squad state value is true, set squad state to "Private" in identity. + else + oidentity << std::endl << "\"Squad state\": \"Public\""; // If squad state value is false, set squad state to "Public" in identity. + // When not in a squad + } else { + oidentity << std::endl << "\"Squad\": null,"; // If squad value isn't between 1 and 26, set squad to "null" in identity. + oidentity << std::endl << "\"Squad leader\": null,"; // If not in a squad, set squad leader state to "null" in identity. + oidentity << std::endl << "\"Squad state\": null"; // If not in a squad, set squad state to "null" in identity. + } + + oidentity << std::endl << "}"; + identity = oidentity.str(); + + // Flip the front vector + for (int i=0;i<3;i++) { + avatar_front[i] = -avatar_front[i]; + } + + // Convert from right to left handed + avatar_pos[0] = -avatar_pos[0]; + camera_pos[0] = -camera_pos[0]; + avatar_front[0] = -avatar_front[0]; + avatar_top[0] = -avatar_top[0]; + + // Sync camera front and top vectors with avatar ones + for (int i=0;i<3;i++) { + camera_front[i] = avatar_front[i]; + camera_top[i] = avatar_top[i]; + } + + return true; } static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids) { - if (! initialize(pids, L"bf4.exe")) { // Link the game executable - return false; - } - - // 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; - std::string scontext; - - if (fetch(apos, afront, atop, cpos, cfront, ctop, scontext, sidentity)) { - return true; - } else { - generic_unlock(); - return false; - } + if (! initialize(pids, L"bf4.exe")) { // Link the game executable + return false; + } + + // 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; + std::string scontext; + + if (fetch(apos, afront, atop, cpos, cfront, ctop, scontext, sidentity)) { + return true; + } else { + generic_unlock(); + return false; + } } static const std::wstring longdesc() { - return std::wstring(L"Supports Battlefield 4 with context and identity support."); // Plugin long description + return std::wstring(L"Supports Battlefield 4 with context and identity support."); // Plugin long description } static std::wstring description(L"Battlefield 4 (x64) version 1.7.2.45672"); // Plugin short description static std::wstring shortname(L"Battlefield 4"); // Plugin short name static int trylock1() { - return trylock(std::multimap<std::wstring, unsigned long long int>()); + return trylock(std::multimap<std::wstring, unsigned long long int>()); } static MumblePlugin bf4plug = { @@ -231,9 +231,9 @@ static MumblePlugin2 bf4plug2 = { }; extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin *getMumblePlugin() { - return &bf4plug; + return &bf4plug; } extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin2 *getMumblePlugin2() { - return &bf4plug2; + return &bf4plug2; } |