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" // Include standard plugin header.
7 #include "../mumble_plugin_utils.h" // Include plugin header for special functions, like "escape".
8
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)9 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) {
10 for (int i=0;i<3;i++) {
11 avatar_pos[i] = avatar_front[i] = avatar_top[i] = camera_pos[i] = camera_front[i] = camera_top[i] = 0.0f;
12 }
13
14 // To update visit http://www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-bots-programs/wow-memory-editing
15 // and look for a thread called "[WoW] [Version] Release Info Dump Thread".
16 // http://www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-bots-programs/wow-memory-editing/585582-wow-7-0-3-22624-release-info-dump-thread.html#post3615091
17
18 // Avatar pointer
19 procptr_t avatar_offset = peekProcPtr(pModule + 0xDE565C); // "LocalPlayer" in the thread.
20 if (!avatar_offset) return false;
21
22 // Camera pointer
23 procptr_t camera_base = peekProcPtr(pModule + 0xEBA11C); // "CameraStruct" in the thread.
24 if (!camera_base) return false;
25 procptr_t camera_offset = peekProcPtr(camera_base + 0x3264); // "CameraOffset" in the thread.
26 if (!camera_offset) return false;
27
28 // Realm pointer
29 procptr_t realm_offset = peekProcPtr(pModule + 0xF3AF7C); // Not available in the thread.
30 if (!realm_offset) return false;
31
32 // Memory addresses
33 procptr_t state_address = 0xE5BD19; // "GameState" in the thread.
34 procptr_t avatar_pos_address = 0xAF8; // "UnitOrigin" in the thread.
35 procptr_t camera_pos_address = 0x08; // "CameraOrigin" in the thread.
36 procptr_t camera_front_address = 0x14; // "CameraMatrix" in the thread.
37 procptr_t camera_top_address = 0x2C; // "CameraMatrix" + 0x18.
38 procptr_t avatar_heading_address = 0xB08; // "UnitAngle" in the thread.
39 procptr_t realm_address = 0x384; // Not available in the thread.
40 procptr_t player_address = 0xF3B288; // Not available in the thread.
41
42 // Boolean value to check if game addresses retrieval is successful
43 bool ok;
44 // Create containers to stuff our raw data into, so we can convert it to Mumble's coordinate system
45 float avatar_pos_corrector[3], camera_pos_corrector[3], avatar_heading, camera_front_corrector[3], camera_top_corrector[3];
46 // Char values for extra features
47 char state, player[50], realm[50];
48
49 // Peekproc and assign game addresses to our containers, so we can retrieve positional data
50 ok = peekProc(pModule + state_address, &state, 1) && // Magical state value: 1 when in-game, 0 when not.
51 peekProc(avatar_offset + avatar_pos_address, avatar_pos_corrector, 12) && // Avatar Position values (Z, -X and Y).
52 peekProc(camera_offset + camera_pos_address, camera_pos_corrector, 12) && // Camera Position values (Z, -X and Y).
53 peekProc(avatar_offset + avatar_heading_address, avatar_heading) && // Avatar heading.
54 peekProc(camera_offset + camera_front_address, camera_front_corrector, 12) && // Camera Front Vector values (Z, -X and Y).
55 peekProc(camera_offset + camera_top_address, camera_top_corrector, 12) && // Camera Top Vector values (Z, -X and Y).
56 peekProc(realm_offset + realm_address, realm) && // Realm name.
57 peekProc(pModule + player_address, player); // Player nickname.
58
59 // This prevents the plugin from linking to the game in case something goes wrong during values retrieval from memory addresses.
60 if (! ok)
61 return false;
62
63 // State
64 if (state != 1) { // If not in-game
65 context.clear(); // Clear context
66 identity.clear(); // Clear identity
67 // Set vectors values to 0.
68 for (int i=0;i<3;i++)
69 avatar_pos[i] = avatar_front[i] = avatar_top[i] = camera_pos[i] = camera_front[i] = camera_top[i] = 0.0f;
70
71 return true; // This tells Mumble to ignore all vectors.
72 }
73
74 // Begin context
75 std::ostringstream ocontext;
76
77 // Realm
78 escape(realm, sizeof(realm));
79 if (strcmp(realm, "") != 0) { // Set Realm string only if not empty
80 ocontext << " {\"Realm\": \"" << realm << "\"}"; // Set context with Realm's name
81 }
82
83 context = ocontext.str();
84 // End context
85
86 // Begin identity
87 std::wostringstream oidentity;
88 oidentity << "{";
89
90 // Player
91 escape(player, sizeof(player));
92 if (strcmp(player, "") != 0) {
93 oidentity << std::endl;
94 oidentity << "\"Player\": \"" << player << "\""; // Set player nickname in identity.
95 } else {
96 oidentity << std::endl << "\"Player\": null";
97 }
98
99 oidentity << std::endl << "}";
100 identity = oidentity.str();
101 // End identity
102
103 /*
104 Mumble | Game
105 X | Z
106 Y | -X
107 Z | Y
108 */
109 avatar_pos[0] = -avatar_pos_corrector[1];
110 avatar_pos[1] = avatar_pos_corrector[2];
111 avatar_pos[2] = avatar_pos_corrector[0];
112
113 camera_pos[0] = -camera_pos_corrector[1];
114 camera_pos[1] = camera_pos_corrector[2];
115 camera_pos[2] = camera_pos_corrector[0];
116
117 avatar_front[0] = -sin(avatar_heading);
118 avatar_front[1] = 0.0f;
119 avatar_front[2] = cos(avatar_heading);
120
121 avatar_top[2] = -1; // Dummy top vector, you can't tilt your head sideways in WoW.
122
123 camera_front[0] = -camera_front_corrector[1];
124 camera_front[1] = camera_front_corrector[2];
125 camera_front[2] = camera_front_corrector[0];
126
127 camera_top[0] = -camera_top_corrector[1];
128 camera_top[1] = camera_top_corrector[2];
129 camera_top[2] = camera_top_corrector[0];
130
131 return true;
132 }
133
trylock(const std::multimap<std::wstring,unsigned long long int> & pids)134 static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids) {
135
136 if (! initialize(pids, L"Wow.exe")) { // Retrieve game executable's memory address
137 return false;
138 }
139
140 // Check if we can get meaningful data from it
141 float apos[3], afront[3], atop[3], cpos[3], cfront[3], ctop[3];
142 std::wstring sidentity;
143 std::string scontext;
144
145 if (fetch(apos, afront, atop, cpos, cfront, ctop, scontext, sidentity)) {
146 return true;
147 } else {
148 generic_unlock();
149 return false;
150 }
151 }
152
longdesc()153 static const std::wstring longdesc() {
154 return std::wstring(L"Supports World of Warcraft (x86) with context and identity support."); // Plugin long description
155 }
156
157 static std::wstring description(L"World of Warcraft (x86) version 7.0.3.22810"); // Plugin short description
158 static std::wstring shortname(L"World of Warcraft"); // Plugin short name
159
trylock1()160 static int trylock1() {
161 return trylock(std::multimap<std::wstring, unsigned long long int>());
162 }
163
164 static MumblePlugin wowplug = {
165 MUMBLE_PLUGIN_MAGIC,
166 description,
167 shortname,
168 NULL,
169 NULL,
170 trylock1,
171 generic_unlock,
172 longdesc,
173 fetch
174 };
175
176 static MumblePlugin2 wowplug2 = {
177 MUMBLE_PLUGIN_MAGIC_2,
178 MUMBLE_PLUGIN_VERSION,
179 trylock
180 };
181
getMumblePlugin()182 extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin *getMumblePlugin() {
183 return &wowplug;
184 }
185
getMumblePlugin2()186 extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin2 *getMumblePlugin2() {
187 return &wowplug2;
188 }
189