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

bf2142.cpp « bf2142 « plugins - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 30c87893813b4f2413383aa51d7dcf9851157932 (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
// Copyright 2005-2017 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>.

#include "../mumble_plugin_win32_32bit.h" // Include standard plugin header.
#include "../mumble_plugin_utils.h" // Include plugin header for special functions, like "escape".

// Variable to contain module's addresses
procptr32_t RendDX9 = 0;


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) {
	bool ok;
	char server_name[100], soldier_name[100];
	BYTE team_id, squad_id, is_commander, is_squad_leader, target_squad_id, on_voip, on_voip_com;

	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;


	// Server name pointers
	// Doubles as an in-server state variable (NULL if not in a game)
	procptr32_t server_offset_0 = peekProc<procptr32_t>(pModule + 0x61B5D8);
	if (!server_offset_0) {
		context.clear(); // Clear context
		identity.clear(); // Clear identity

		return true; // This tells Mumble to ignore all vectors.
	}

	procptr32_t server_offset_1 = peekProc<procptr32_t>(server_offset_0 + 0x108);
	if (!server_offset_1) return false;

	// Team ID pointers
	procptr32_t team_offset_0 = peekProc<procptr32_t>(pModule + 0x624430);
	if (!team_offset_0) return false;
	procptr32_t team_offset_1 = peekProc<procptr32_t>(team_offset_0 + 0x1B4);
	if (!team_offset_1) return false;

	// Commander, SquadLeader, SquadID base pointers
	procptr32_t role_offset_0 = peekProc<procptr32_t>(pModule + 0x685228);
	if (!role_offset_0) return false;
	procptr32_t role_offset_1 = peekProc<procptr32_t>(role_offset_0 + 0x6C);
	if (!role_offset_1) return false;

	// Tactical pointers
	procptr32_t tactical_offset_0 = peekProc<procptr32_t>(pModule + 0x72D148);
	if (!tactical_offset_0) return false;
	procptr32_t tactical_offset_1 = peekProc<procptr32_t>(tactical_offset_0 + 0xE4);
	if (!tactical_offset_1) return false;

	// VoiP pointers
	procptr32_t voip_offset_0 = peekProc<procptr32_t>(pModule + 0x620D30);
	if (!voip_offset_0) return false;

	// Peekproc and assign game addresses to our containers, so we can retrieve positional data
	ok = peekProc(pModule + 0x6697C8      , avatar_pos, 12) &&   // Avatar position values (X, Y and Z).
	     peekProc(RendDX9 + 0x20E9F4      , camera_pos, 12) &&   // Camera position values (X, Y and Z).
	     peekProc(RendDX9 + 0x2139D4      , camera_front, 12) && // Avatar front vector values (X, Y and Z).
	     peekProc(RendDX9 + 0x2139C4      , camera_top, 12) &&   // Avatar top vector values (X, Y and Z).
	     peekProc(server_offset_1         , server_name) &&      // Server name.
	     peekProc(pModule + 0x6228B9      , soldier_name) &&     // Soldier name.
	     peekProc(team_offset_1 + 0xA0    , team_id) &&          // Team ID (0 for PAC, 1 for EU).
	     peekProc(role_offset_1 + 0x108   , squad_id);           // Squad ID (0 for none, 1-9 for squads).
	     peekProc(role_offset_1 + 0x10C   , is_commander) &&     // Whether Commander.
	     peekProc(role_offset_1 + 0x10D   , is_squad_leader) &&  // Whether Squad Leader.
	     peekProc(tactical_offset_1 + 0xCC, target_squad_id) &&  // Commander's selected squad.
	     peekProc(voip_offset_0 + 0xA1    , on_voip) &&          // Whether VoiP is active.
	     peekProc(voip_offset_0 + 0xA0    , on_voip_com);        // Whether VoiP to/from commander is active.

	// This prevents the plugin from linking to the game in case something goes wrong during values retrieval from memory addresses.
	if (!ok)
		return false;


	// Begin context
	std::ostringstream ocontext;

	// Server name
	escape(server_name, sizeof(server_name));

	if (strcmp(server_name, "") != 0)
		ocontext << " {\"ipport\": \"" << server_name << "\"}";

	context = ocontext.str();
	// End context

	// Begin identity
	std::wostringstream oidentity;

	// Soldier name
	escape(soldier_name, sizeof(soldier_name));

	oidentity << "{"
	          << "\"ipport\": \"" << server_name << "\", "
	          << "\"team_id\": " << team_id << ", "
	          << "\"squad_id\": " << squad_id << ", "
	          << "\"is_commander\": " << (is_commander ? "true" : "false") << ", "
	          << "\"is_squad_leader\": " << (is_squad_leader ? "true" : "false") << ", "
	          << "\"target_squad_id\": " << target_squad_id << ", "
	          << "\"on_voip\": " << (on_voip ? "true" : "false") << ", "
	          << "\"on_voip_com\": " << (on_voip_com ? "true" : "false") << ", "
	          << "\"name\": \"" << soldier_name << "\""
	          << "}";

	identity = oidentity.str();
	// End identity

	// Copy camera direction vectors to avatar
	for (int i=0; i<3; i++) {
		avatar_front[i] = camera_front[i];
		avatar_top[i] = camera_top[i];
	}

	return true;
}

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

	if (!initialize(pids, L"BF2142.exe")) // Retrieve game executable's memory address
		return false;

	RendDX9 = getModuleAddr(L"RendDX9.dll"); // Retrieve "RendDX9.dll" module's memory address
	// This prevents the plugin from linking to the game in case something goes wrong during module's memory address retrieval.
	if (!RendDX9)
		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 2142 version 1.51."); // Plugin long description
}

static std::wstring description(L"Battlefield 2142 1.51"); // Plugin short description
static std::wstring shortname(L"Battlefield 2142"); // Plugin short name

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

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

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

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

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