Advertisement
Hattiwatti

BF4 x64 Positional Audio - Mumble plugin file

May 29th, 2014
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.63 KB | None | 0 0
  1. /*
  2.    Copyright (C) 2014, Hattiwatti
  3.    Copyright (C) 2010-2011, Snares <[email protected]>
  4.    Copyright (C) 2005-2011, Thorvald Natvig <[email protected]>
  5.    Copyright (C) 2011, Ryan Austin <[email protected]>
  6.    Copyright (C) 2012, Bojan Hartmann <[email protected]>
  7.  
  8.    All rights reserved.
  9.  
  10.    Redistribution and use in source and binary forms, with or without
  11.    modification, are permitted provided that the following conditions
  12.    are met:
  13.  
  14.    - Redistributions of source code must retain the above copyright notice,
  15.      this list of conditions and the following disclaimer.
  16.    - Redistributions in binary form must reproduce the above copyright notice,
  17.      this list of conditions and the following disclaimer in the documentation
  18.      and/or other materials provided with the distribution.
  19.    - Neither the name of the Mumble Developers nor the names of its
  20.      contributors may be used to endorse or promote products derived from this
  21.      software without specific prior written permission.
  22.  
  23.    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24.    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25.    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26.    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
  27.    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28.    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29.    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30.    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31.    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32.    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33.    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35.  
  36. #include "../mumble_plugin_win32.h"
  37. #include <tchar.h>
  38. #include <vector>
  39.  
  40.  
  41. // Pipe stuff
  42. #define BUF_SIZE 256
  43. TCHAR szName[]=TEXT("Global\\BFmumble");
  44.  
  45. 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) {
  46.     for (int i=0;i<3;i++)
  47.         avatar_pos[i] = avatar_front[i] = avatar_top[i] = camera_pos[i] = camera_front[i] = camera_top[i] = 0.0f;
  48.  
  49.     BYTE state;
  50.     BYTE squad_state;
  51.     BYTE is_squadleader;
  52.     BYTE team_state;
  53.     bool ok;
  54.  
  55.     char* pBuf;
  56.  
  57.     // Get values from the mapped memory file
  58.  
  59.     HANDLE hMapFile = OpenFileMapping(
  60.                     FILE_MAP_ALL_ACCESS,   // read/write access
  61.                     FALSE,                 // do not inherit the name
  62.                     szName);               // name of mapping object
  63.  
  64.     if(hMapFile == NULL)
  65.         return false;
  66.  
  67.     pBuf = (char*)MapViewOfFile(hMapFile, // handle to map object
  68.                FILE_MAP_ALL_ACCESS,  // read/write permission
  69.                0,
  70.                0,
  71.                BUF_SIZE);
  72.  
  73.     if(pBuf == NULL)
  74.         return false;
  75.  
  76.     std::string csMsg = "";
  77.     std::vector<std::string> args;
  78.  
  79.     //Parse the message
  80.     for(int i=0;i<strlen(pBuf);i++)
  81.     {
  82.         if(pBuf[i] != ' ' )
  83.         {
  84.             csMsg += pBuf[i];
  85.             if(i == strlen(pBuf)-1)
  86.                 args.push_back(csMsg);
  87.         }
  88.         else
  89.         {
  90.             args.push_back(csMsg);
  91.             csMsg = "";
  92.         }
  93.     }
  94.  
  95.     UnmapViewOfFile(pBuf);
  96.     CloseHandle(hMapFile);
  97.  
  98.     context = "{ \"ipport\": \"" + args[0] +  "\" }";
  99.  
  100.     /*
  101.         Get identity string.
  102.     */
  103.  
  104.     std::string oidentity = "{\"squad\":" + args[2] + "," + "\"squad_leader\":" + (atoi(args[3].c_str()) ? "true" : "false") + ",\"team\":" + args[1].c_str() + "}";
  105.     identity = std::wstring(oidentity.begin(), oidentity.end());
  106.  
  107.     avatar_top[0] = atof(args[4].c_str());
  108.     avatar_top[1] = atof(args[5].c_str());
  109.     avatar_top[2] = atof(args[6].c_str());
  110.  
  111.     avatar_front[0] = atof(args[7].c_str());
  112.     avatar_front[1] = atof(args[8].c_str());
  113.     avatar_front[2] = atof(args[9].c_str());
  114.  
  115.     avatar_pos[0] = atof(args[10].c_str());
  116.     avatar_pos[1] = atof(args[11].c_str());
  117.     avatar_pos[2] = atof(args[12].c_str());
  118.  
  119.     // Flip our front vector
  120.     for (int i=0;i<3;i++) {
  121.         avatar_front[i] = -avatar_front[i];
  122.     }
  123.  
  124.  
  125.     // Convert from right to left handed
  126.     avatar_pos[0] = -avatar_pos[0];
  127.     avatar_front[0] = -avatar_front[0];
  128.     avatar_top[0] = -avatar_top[0];
  129.  
  130.     for (int i=0;i<3;i++) {
  131.         camera_pos[i] = avatar_pos[i];
  132.         camera_front[i] = avatar_front[i];
  133.         camera_top[i] = avatar_top[i];
  134.     }
  135.     printf("Returning true\n");
  136.     return true;
  137. }
  138.  
  139.  
  140. static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids)
  141. {
  142.  
  143.     float apos[3], afront[3], atop[3], cpos[3], cfront[3], ctop[3];
  144.     std::string context;
  145.     std::wstring identity;
  146.  
  147.     if (!fetch(apos, afront, atop, cpos, cfront, ctop, context, identity)) {
  148.         generic_unlock();
  149.         return false;
  150.     }
  151.     return true;
  152. }
  153.  
  154. static const std::wstring longdesc() {
  155.     return std::wstring(L"Supports Battlefield 4 with context and identity support.");
  156. }
  157.  
  158. static std::wstring description(L"Battlefield 4 64-bit v1147186");
  159. static std::wstring shortname(L"Battlefield 4 64-bit");
  160.  
  161. static int trylock1() {
  162.     return trylock(std::multimap<std::wstring, unsigned long long int>());
  163. }
  164.  
  165. static MumblePlugin bf4plug = {
  166.     MUMBLE_PLUGIN_MAGIC,
  167.     description,
  168.     shortname,
  169.     NULL,
  170.     NULL,
  171.     trylock1,
  172.     generic_unlock,
  173.     longdesc,
  174.     fetch
  175. };
  176.  
  177. static MumblePlugin2 bf4plug2 = {
  178.     MUMBLE_PLUGIN_MAGIC_2,
  179.     MUMBLE_PLUGIN_VERSION,
  180.     trylock
  181. };
  182.  
  183. extern "C" __declspec(dllexport) MumblePlugin *getMumblePlugin() {
  184.     return &bf4plug;
  185. }
  186.  
  187. extern "C" __declspec(dllexport) MumblePlugin2 *getMumblePlugin2() {
  188.     return &bf4plug2;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement