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