Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Copyright (C) 2014, Hattiwatti
- Copyright (C) 2010-2011, Snares <[email protected]>
- Copyright (C) 2005-2011, Thorvald Natvig <[email protected]>
- Copyright (C) 2011, Ryan Austin <[email protected]>
- Copyright (C) 2012, Bojan Hartmann <[email protected]>
- All rights reserved.
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- - Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- - Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- - Neither the name of the Mumble Developers nor the names of its
- contributors may be used to endorse or promote products derived from this
- software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include "../mumble_plugin_win32.h"
- #include <tchar.h>
- #include <vector>
- // Pipe stuff
- #define BUF_SIZE 256
- TCHAR szName[]=TEXT("Global\\BFmumble");
- 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;
- BYTE state;
- BYTE squad_state;
- BYTE is_squadleader;
- BYTE team_state;
- bool ok;
- char* pBuf;
- // Get values from the mapped memory file
- HANDLE hMapFile = OpenFileMapping(
- FILE_MAP_ALL_ACCESS, // read/write access
- FALSE, // do not inherit the name
- szName); // name of mapping object
- if(hMapFile == NULL)
- return false;
- pBuf = (char*)MapViewOfFile(hMapFile, // handle to map object
- FILE_MAP_ALL_ACCESS, // read/write permission
- 0,
- 0,
- BUF_SIZE);
- if(pBuf == NULL)
- return false;
- std::string csMsg = "";
- std::vector<std::string> args;
- //Parse the message
- for(int i=0;i<strlen(pBuf);i++)
- {
- if(pBuf[i] != ' ' )
- {
- csMsg += pBuf[i];
- if(i == strlen(pBuf)-1)
- args.push_back(csMsg);
- }
- else
- {
- args.push_back(csMsg);
- csMsg = "";
- }
- }
- UnmapViewOfFile(pBuf);
- CloseHandle(hMapFile);
- context = "{ \"ipport\": \"" + args[0] + "\" }";
- /*
- Get identity string.
- */
- std::string oidentity = "{\"squad\":" + args[2] + "," + "\"squad_leader\":" + (atoi(args[3].c_str()) ? "true" : "false") + ",\"team\":" + args[1].c_str() + "}";
- identity = std::wstring(oidentity.begin(), oidentity.end());
- avatar_top[0] = atof(args[4].c_str());
- avatar_top[1] = atof(args[5].c_str());
- avatar_top[2] = atof(args[6].c_str());
- avatar_front[0] = atof(args[7].c_str());
- avatar_front[1] = atof(args[8].c_str());
- avatar_front[2] = atof(args[9].c_str());
- avatar_pos[0] = atof(args[10].c_str());
- avatar_pos[1] = atof(args[11].c_str());
- avatar_pos[2] = atof(args[12].c_str());
- // Flip our 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];
- avatar_front[0] = -avatar_front[0];
- avatar_top[0] = -avatar_top[0];
- 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];
- }
- printf("Returning true\n");
- return true;
- }
- static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids)
- {
- 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)) {
- generic_unlock();
- return false;
- }
- return true;
- }
- static const std::wstring longdesc() {
- return std::wstring(L"Supports Battlefield 4 with context and identity support.");
- }
- static std::wstring description(L"Battlefield 4 64-bit v1147186");
- static std::wstring shortname(L"Battlefield 4 64-bit");
- static int trylock1() {
- return trylock(std::multimap<std::wstring, unsigned long long int>());
- }
- static MumblePlugin bf4plug = {
- MUMBLE_PLUGIN_MAGIC,
- description,
- shortname,
- NULL,
- NULL,
- trylock1,
- generic_unlock,
- longdesc,
- fetch
- };
- static MumblePlugin2 bf4plug2 = {
- MUMBLE_PLUGIN_MAGIC_2,
- MUMBLE_PLUGIN_VERSION,
- trylock
- };
- extern "C" __declspec(dllexport) MumblePlugin *getMumblePlugin() {
- return &bf4plug;
- }
- extern "C" __declspec(dllexport) MumblePlugin2 *getMumblePlugin2() {
- return &bf4plug2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement