Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bf3.cpp « bf3 « plugins - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 015ad321320d77660ffdf0e05ab9f322077e4464 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// Copyright 2005-2016 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

/* Copyright (C) 2010-2011, Snares <snares@users.sourceforge.net>
   Copyright (C) 2005-2011, Thorvald Natvig <thorvald@natvig.com>
   Copyright (C) 2011, Ryan Austin <ryan@gameforcecenters.com>
   Copyright (C) 2012, Bojan Hartmann <bogie@bawki.de>

   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_32bit.h"
static bool ptr_chain_valid = false;

// Magic ptrs
static procptr32_t const state_ptr = 0x238ABDC;

// Vector ptrs
static procptr32_t const avatar_pos_ptr = 0x0238AB70;
static procptr32_t const avatar_front_ptr = 0x0238ABA0;
static procptr32_t const avatar_top_ptr = 0x0238AB90;

// Context ptrs
static procptr32_t const ipport_ptr = 0x0235DB90;

// Identity ptrs
static procptr32_t team_state_ptr, squad_state_ptr, squad_lead_state_ptr;

// Offsets
static const int base_offset = 0x01EF25C4;
static const int identity_offset1 = 0x1C;
static const int identity_offset2 = 0xBC;
static const int identity_offset3 = 0x36C;
static const int identity_offset4 = 0x8;
static const int squad_state_offset = 0x104;
static const int squad_lead_state_offset = 0x108;
static const int team_state_offset = 0x31C;

enum state_values {
    STATE_UNKN = 0,
    STATE_LOADING = 1,
    STATE_IN_GAME = 2,
    STATE_IN_MENU = 3
};

inline bool resolve_ptrs() {
    team_state_ptr = squad_state_ptr = squad_lead_state_ptr = NULL;

    /*
      Analysis for future patches:

      - state_ptr is always 0x6C after avatar_pos_ptr
      - avatar_front_ptr is always 0x30 after avatar_pos_ptr
      - avatar_top_ptr is always 0x20 after avatar_pos_ptr
      - you can find avatar_pos_ptr easily by jumping in a jet/heli and look at the altitude indicator

      - for squad/team/squad lead pointers, search for your name
      - name address - 0x20 = squad lead(1=yes/0=no)
      - squad lead - 0x4 = squad number(1=alpha etc)
      - squad number - 0x150 = team number(1=US,2=RU)
      */
    /*
    Magic:
        state : 0x238ABDC                                                        BYTE        1 when playing
                                                                                             2 while in menu/dead

    Context:
        IP:Port of server: 0x0235DB90                                            char[128]   ip:port of the server

    Identity:
        Squad state: BF3.exe+0x01EF25C4 + 0x1C + 0xBC + 0x36C + 0x8 + 0x104      BYTE        0 is not in squad; 1 is in Alpha squad, 2 Bravo, ... , 9 India
        SLead state: BF3.exe+0x01EF25C4 + 0x1C + 0xBC + 0x36C + 0x8 + 0x108      BYTE        0 is not lead; 1 is lead
        Team state:  BF3.exe+0x01EF25C4 + 0x1C + 0xBC + 0x31C                    BYTE        1 is blufor (US team, for example), 2 is opfor (RU), 0 is probably upcoming spec mode
    */

    procptr32_t base_bf3 = peekProc<procptr32_t>(pModule + base_offset);
    if (!base_bf3)
        return false;

    procptr32_t offset_ptr1 = peekProc<procptr32_t>(base_bf3 + identity_offset1);
    if (!offset_ptr1) return false;
    procptr32_t offset_ptr2 = peekProc<procptr32_t>(offset_ptr1 + identity_offset2);
    if (!offset_ptr2) return false;
    procptr32_t offset_ptr3 = peekProc<procptr32_t>(offset_ptr2 + identity_offset3);
    if (!offset_ptr3) return false;
    procptr32_t offset_ptr4 = peekProc<procptr32_t>(offset_ptr3 + identity_offset4);
    if (!offset_ptr4) return false;

    squad_state_ptr = offset_ptr4 + squad_state_offset;
    squad_lead_state_ptr = offset_ptr4 + squad_lead_state_offset;
    team_state_ptr = offset_ptr2 + team_state_offset;

    return true;
}

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;

    char ccontext[128];
    char state;
    BYTE squad_state;
    BYTE is_squadleader;
    BYTE team_state;
    bool ok;

    ok = peekProc(state_ptr, &state, 1); // State value
    if (! ok)
        return false;

    if (state != STATE_IN_GAME && state != STATE_IN_MENU) {
        ptr_chain_valid = false;
        context.clear();
        identity.clear();
        return true;
    } else if (!ptr_chain_valid) {
        if (!resolve_ptrs())
            return false;
        ptr_chain_valid = true;
    }

    ok = peekProc(avatar_pos_ptr, avatar_pos, 12) &&
        peekProc(avatar_front_ptr, avatar_front, 12) &&
        peekProc(avatar_top_ptr, avatar_top, 12) &&
        peekProc(squad_state_ptr,&squad_state,1) &&
        peekProc(squad_lead_state_ptr, &is_squadleader,1) &&
        peekProc(team_state_ptr,&team_state,1) &&
        peekProc(ipport_ptr,ccontext,128);

    if (! ok)
        return false;

    ccontext[sizeof(ccontext) - 1] = 0;
    if (ccontext[0] != '0') {
        std::ostringstream ocontext;
        ocontext << "{ \"ipport\": \"" << ccontext << "\" }";

        context = ocontext.str();

        /*
            Get identity string.
        */
        std::wostringstream oidentity;
        oidentity << "{"
        << "\"squad\":" << static_cast<unsigned int>(squad_state) << ","
        << "\"squad_leader\":" << (is_squadleader ? "true" : "false") << ",";
        if (team_state == 0)
            oidentity << "\"team\": \"SPEC\"";
        else if (team_state == 1)
            oidentity << "\"team\": \"US\"";
        else if (team_state == 2)
            oidentity << "\"team\": \"RU\"";
        oidentity << "}";
        identity = oidentity.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];
    }

    return ok;
}

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

    if (! initialize(pids, L"bf3.exe"))
        return false;

    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 3 with context and identity support.");
}

static std::wstring description(L"Battlefield 3 v1147186 - Endgame");
static std::wstring shortname(L"Battlefield 3");

static int trylock1() {
    return trylock(std::multimap<std::wstring, unsigned long long int>());
}

static MumblePlugin bf3plug = {
    MUMBLE_PLUGIN_MAGIC,
    description,
    shortname,
    NULL,
    NULL,
    trylock1,
    generic_unlock,
    longdesc,
    fetch
};

static MumblePlugin2 bf3plug2 = {
    MUMBLE_PLUGIN_MAGIC_2,
    MUMBLE_PLUGIN_VERSION,
    trylock
};

extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin *getMumblePlugin() {
    return &bf3plug;
}

extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin2 *getMumblePlugin2() {
    return &bf3plug2;
}