"Fossies" - the Fresh Open Source Software Archive

Member "mumble-1.3.2/plugins/aoc/aoc.cpp" (9 Jul 2020, 4589 Bytes) of package /linux/misc/mumble-1.3.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "aoc.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.2.19_vs_1.3.0.

    1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license
    3 // that can be found in the LICENSE file at the root of the
    4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
    5 
    6 #include "../mumble_plugin_win32.h"
    7 
    8 using namespace std;
    9 
   10 procptr_t posptr, rotptr, stateptr, hostptr;
   11 
   12 static bool calcout(float *pos, float *rot, float *opos, float *front, float *top) {
   13     float h = rot[0];
   14     float v = rot[1];
   15 
   16     if ((v < -360.0f) || (v > 360.0f) || (h < -360.0f) || (h > 360.0f))
   17         return false;
   18 
   19     h *= static_cast<float>(M_PI / 180.0f);
   20     v *= static_cast<float>(M_PI / 180.0f);
   21 
   22     // Seems AOC is in inches. INCHES?!?
   23     opos[0] = pos[0] / 39.37f;
   24     opos[1] = pos[2] / 39.37f;
   25     opos[2] = pos[1] / 39.37f;
   26 
   27     front[0] = cos(v) * cos(h);
   28     front[1] = -sin(h);
   29     front[2] = sin(v) * cos(h);
   30 
   31     h -= static_cast<float>(M_PI / 2.0f);
   32 
   33     top[0] = cos(v) * cos(h);
   34     top[1] = -sin(h);
   35     top[2] = sin(v) * cos(h);
   36 
   37     return true;
   38 }
   39 
   40 static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, float *camera_pos, float *camera_front, float *camera_top, string &context, wstring &) {
   41     for (int i=0;i<3;i++)
   42         avatar_pos[i] = avatar_front[i] = avatar_top[i] = camera_pos[i] = camera_front[i] = camera_top[i] = 0.0f;
   43 
   44     float ipos[3], rot[3];
   45     bool ok;
   46     char state;
   47     char chHostStr[40];
   48     string sHost;
   49     wostringstream new_identity;
   50     ostringstream new_context;
   51 
   52     ok = peekProc(posptr, ipos, 12) &&
   53          peekProc(rotptr, rot, 12) &&
   54          peekProc(stateptr, &state, 1) &&
   55          peekProc(hostptr, chHostStr, 40);
   56     if (!ok)
   57         return false;
   58 
   59     chHostStr[39] = 0;
   60 
   61     sHost.assign(chHostStr);
   62     if (sHost.find(':')==string::npos)
   63         sHost.append(":27015");
   64 
   65     new_context << "<context>"
   66                 << "<game>aoc</game>"
   67                 << "<hostport>" << sHost << "</hostport>"
   68                 << "</context>";
   69     context = new_context.str();
   70 
   71     /* TODO
   72     new_identity << "<identity>"
   73                  << "<name>" << "SAS" << "</name>"
   74                  << "</identity>";
   75     identity = new_identity.str(); */
   76 
   77     // Check to see if you are spawned
   78     if (state == 0 || state == 1 || state == 2)
   79         return true; // Deactivate plugin
   80 
   81     ok = calcout(ipos, rot, avatar_pos, avatar_front, avatar_top);
   82     if (ok) {
   83         for (int i=0;i<3;++i) {
   84             camera_pos[i] = avatar_pos[i];
   85             camera_front[i] = avatar_front[i];
   86             camera_top[i] = avatar_top[i];
   87         }
   88         return true;
   89     }
   90 
   91     return false;
   92 }
   93 
   94 static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids) {
   95     posptr = rotptr = 0;
   96 
   97     if (! initialize(pids, L"hl2.exe", L"client.dll"))
   98         return false;
   99 
  100     procptr_t mod_engine=getModuleAddr(L"engine.dll");
  101     if (!mod_engine)
  102         return false;
  103 
  104     // Check if we really have AOC running
  105     /*
  106         position tuple:     client.dll+0x748e14  (x,y,z, float)
  107         orientation tuple:  client.dll+0x73dc9c  (v,h float)
  108         ID string:          client.dll+0x7071e8 = "ageofchivalry" (13 characters, text)
  109         spawn state:        client.dll+0x6d4334  (0 when at main menu, 1 when at team selection, 2 when not spawned,
  110                                                   between 6 and 7 when spawned)
  111         context offsets:    engine.dll + 0x3bf69f = (ip:port)
  112                             server.dll + 0x71a0a4 = (team info, 3 Mason, 1 Agathia)
  113     */
  114 
  115     // Remember addresses for later
  116     posptr = pModule + 0x748e14;
  117     rotptr = pModule + 0x73dc9c;
  118     stateptr = pModule + 0x6d4334;
  119     hostptr = mod_engine + 0x3C2A84;
  120 
  121     //Gamecheck
  122     char sMagic[13];
  123     if (!peekProc(pModule + 0x7071e8, sMagic, 13) || strncmp("ageofchivalry", sMagic, 13)!=0)
  124         return false;
  125 
  126     // Check if we can get meaningful data from it
  127     float apos[3], afront[3], atop[3];
  128     float cpos[3], cfront[3], ctop[3];
  129     wstring sidentity;
  130     string scontext;
  131 
  132     if (fetch(apos, afront, atop, cpos, cfront, ctop, scontext, sidentity)) {
  133         return true;
  134     } else {
  135         generic_unlock();
  136         return false;
  137     }
  138 }
  139 
  140 static const std::wstring longdesc() {
  141     return std::wstring(L"Supports AOC Build 4104. No identity support yet.");
  142 }
  143 
  144 static std::wstring description(L"Age of Chivalry (Build 4104)");
  145 static std::wstring shortname(L"Age of Chivalry");
  146 
  147 static int trylock1() {
  148     return trylock(std::multimap<std::wstring, unsigned long long int>());
  149 }
  150 
  151 static MumblePlugin aocplug = {
  152     MUMBLE_PLUGIN_MAGIC,
  153     description,
  154     shortname,
  155     NULL,
  156     NULL,
  157     trylock1,
  158     generic_unlock,
  159     longdesc,
  160     fetch
  161 };
  162 
  163 static MumblePlugin2 aocplug2 = {
  164     MUMBLE_PLUGIN_MAGIC_2,
  165     MUMBLE_PLUGIN_VERSION,
  166     trylock
  167 };
  168 
  169 extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin *getMumblePlugin() {
  170     return &aocplug;
  171 }
  172 
  173 extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin2 *getMumblePlugin2() {
  174     return &aocplug2;
  175 }