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 pos0ptr, pos1ptr, pos2ptr, faceptr, topptr;
11 //BYTE *stateptr;
12 
fetch(float * avatar_pos,float * avatar_front,float * avatar_top,float * camera_pos,float * camera_front,float * camera_top,std::string &,std::wstring &)13 static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, float *camera_pos, float *camera_front, float *camera_top, std::string &, std::wstring &) {
14 	char state;
15 	//char ccontext[128];
16 	bool ok;
17 
18 	float face_corrector[3];
19 	float top_corrector[3];
20 
21 	for (int i=0;i<3;i++)
22 		avatar_pos[i] = avatar_front[i] = avatar_top[i] = camera_pos[i] = camera_front[i] = camera_top[i] = 0.0f;
23 
24 	ok = peekProc(0x01DEAFD9, &state, 1);
25 	if (! ok)
26 		return false;
27 
28 	if (state == 1)
29 		return true;
30 
31 	/*
32 	   Z-Value is increasing when heading north
33 				  decreasing when heading south
34 	   X-Value is increasing when heading east
35 				  decreasing when heading west
36 	   Y-Value is increasing when going up
37 				  decreasing when going down
38 	*/
39 
40 	//Convert to left-handed coordinate system
41 
42 	ok = peekProc(pos2ptr, avatar_pos, 4) &&	//X
43 	     peekProc(pos1ptr, avatar_pos+1, 4) &&	//Y
44 	     peekProc(pos0ptr, avatar_pos+2, 4) &&  //Z
45 	     peekProc(faceptr, &face_corrector, 12) &&
46 	     peekProc(topptr, &top_corrector, 12);
47 
48 	//peekProc((BYTE *) 0x0122E0B8, ccontext, 128);
49 
50 	if (! ok)
51 		return false;
52 
53 	if (face_corrector[1] <= -0.98) {
54 		top_corrector[1] = -top_corrector[1];
55 	}
56 	if (face_corrector[1] >= 0.98) {
57 		top_corrector[1] = -top_corrector[1];
58 	}
59 
60 	//Find north by playing on a Warfare game type - center view on the up arrow on the mini map
61 	avatar_front[0] = face_corrector[2];
62 	avatar_front[1] = face_corrector[1];
63 	avatar_front[2] = face_corrector[0];
64 
65 	avatar_top[0] = top_corrector[2];
66 	avatar_top[1] = top_corrector[1];
67 	avatar_top[2] = top_corrector[0];
68 
69 	//avatar_top[0] = top_corrector[2];
70 	//avatar_top[1] = top_corrector[1];
71 
72 	//ccontext[127] = 0;
73 	//context = std::string(ccontext);
74 
75 	//if (context.find(':')==string::npos)
76 	//	context.append(":UT3PORT");
77 
78 	for (int i=0;i<3;i++) {
79 		camera_pos[i] = avatar_pos[i];
80 		camera_front[i] = avatar_front[i];
81 		camera_top[i] = avatar_top[i];
82 	}
83 
84 	return true;
85 }
86 
trylock(const std::multimap<std::wstring,unsigned long long int> & pids)87 static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids) {
88 	pos0ptr = pos1ptr = pos2ptr = faceptr = 0;
89 
90 	if (! initialize(pids, L"UT3.exe", L"wrap_oal.dll"))
91 		return false;
92 
93 	procptr_t ptraddress = pModule + 0x8A740;
94 	procptr_t baseptr = peekProcPtr(ptraddress);
95 
96 	pos0ptr = baseptr;
97 	pos1ptr = baseptr + 0x4;
98 	pos2ptr = baseptr + 0x8;
99 	faceptr = baseptr + 0x18;
100 	topptr = baseptr + 0x24;
101 
102 	//stateptr = pModule + 0xC4;
103 
104 	float apos[3], afront[3], atop[3], cpos[3], cfront[3], ctop[3];
105 	std::string context;
106 	std::wstring identity;
107 
108 	if (fetch(apos, afront, atop, cpos, cfront, ctop, context, identity)) {
109 		return true;
110 	} else {
111 		generic_unlock();
112 		return false;
113 	}
114 }
115 
longdesc()116 static const std::wstring longdesc() {
117 	return std::wstring(L"Supports Unreal Tournament 3 (v2.1). No context or identity support yet.");
118 }
119 
120 static std::wstring description(L"Unreal Tournament 3 (v2.1)");
121 static std::wstring shortname(L"Unreal Tournament 3");
122 
trylock1()123 static int trylock1() {
124 	return trylock(std::multimap<std::wstring, unsigned long long int>());
125 }
126 
127 static MumblePlugin ut3plug = {
128 	MUMBLE_PLUGIN_MAGIC,
129 	description,
130 	shortname,
131 	NULL,
132 	NULL,
133 	trylock1,
134 	generic_unlock,
135 	longdesc,
136 	fetch
137 };
138 
139 static MumblePlugin2 ut3plug2 = {
140 	MUMBLE_PLUGIN_MAGIC_2,
141 	MUMBLE_PLUGIN_VERSION,
142 	trylock
143 };
144 
getMumblePlugin()145 extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin *getMumblePlugin() {
146 	return &ut3plug;
147 }
148 
getMumblePlugin2()149 extern "C" MUMBLE_PLUGIN_EXPORT MumblePlugin2 *getMumblePlugin2() {
150 	return &ut3plug2;
151 }
152