1+ //========================================================================== 
2+ // Mouse Injector for Dolphin 
3+ //========================================================================== 
4+ // Copyright (C) 2019-2020 Carnivorous 
5+ // All rights reserved. 
6+ // 
7+ // Mouse Injector is free software; you can redistribute it and/or modify it 
8+ // under the terms of the GNU General Public License as published by the Free 
9+ // Software Foundation; either version 2 of the License, or (at your option) 
10+ // any later version. 
11+ // 
12+ // This program is distributed in the hope that it will be useful, but 
13+ // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
14+ // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
15+ // for more details. 
16+ // 
17+ // You should have received a copy of the GNU General Public License 
18+ // along with this program; if not, visit http://www.gnu.org/licenses/gpl-2.0.html 
19+ //========================================================================== 
20+ #include  <stdint.h> 
21+ #include  "../main.h" 
22+ #include  "../memory.h" 
23+ #include  "../mouse.h" 
24+ #include  "game.h" 
25+ 
26+ #define  PI  3.14159265f // 0x40490FDB
27+ #define  TAU  6.2831853f // 0x40C90FDB
28+ 
29+ #define  TE_IS_PAUSED  0x80310A8C
30+ #define  TE_IS_PAUSED_TRUE  0x00000002
31+ 
32+ #define  TE_IS_IN_GAME_CUTSCENE  0x8070C834
33+ #define  TE_IS_IN_GAME_CUTSCENE_TRUE  0x00000001
34+ 
35+ #define  TE_ONFOOT_CAMBASE  0x803113AC
36+ #define  TE_ONFOOT_CAMBASE_SANITY_1_VALUE  0xFFA284BF
37+ // offsets from camBase 
38+ #define  TE_ONFOOT_CAMBASE_SANITY_1  0x2C
39+ #define  TE_ONFOOT_CAMX  0xF0
40+ #define  TE_ONFOOT_CAMY  0x41C
41+ #define  TE_ONFOOT_FOV  0x8D8
42+ #define  TE_CLIMB_CAMX  0x420
43+ #define  TE_IS_NOT_CLIMBING  0x400
44+ #define  TE_IN_WATER  0x1888
45+ #define  TE_TURRET_BASE  0x19FC
46+ // offsets from turret base 
47+ #define  TE_TURRET_CAMY  0x448
48+ #define  TE_TURRET_CAMX  0x44C
49+ #define  TE_TURRET_CAMY_BOUND  0x498
50+ #define  TE_TURRET_CAMX_BOUND  0x49C
51+ 
52+ #define  TE_IS_CLIMBING  0x807DDF28
53+ #define  TE_IS_CLIMBING_TRUE  0xBF000000
54+ 
55+ #define  TE_FLYING_BASE  0x803113AC
56+ #define  TE_FLYING_BASE_SANITY_1_VALUE  0x3F7B1D3C
57+ #define  TE_FLYING_BASE_SANITY_2_VALUE  0xFFA284FF
58+ // offsets from flying camBase 
59+ #define  TE_FLYING_BASE_SANITY_1  0x40
60+ #define  TE_FLYING_BASE_SANITY_2  0x2C
61+ #define  TE_FLYING_ROLL_SPEED  0xB4C
62+ #define  TE_FLYING_PITCH_SPEED  0xB50
63+ 
64+ #define  TE_CLIMBING_CAMY_REBOUND_OP  0x801CBEBC
65+ 
66+ 
67+ static  uint8_t  GC_TE_Status (void );
68+ static  uint8_t  GC_TE_DetectCamBase (void );
69+ static  uint8_t  GC_TE_DetectFlyingBase (void );
70+ static  void  GC_TE_Inject (void );
71+ 
72+ static  const  GAMEDRIVER  GAMEDRIVER_INTERFACE  = 
73+ {
74+ 	"Turok: Evolution" ,
75+ 	GC_TE_Status ,
76+ 	GC_TE_Inject ,
77+ 	1 , // if tickrate is any lower, mouse input will get sluggish 
78+ 	0  // crosshair sway not supported for driver 
79+ };
80+ 
81+ const  GAMEDRIVER  * GAME_GC_TUROKEVOLUTION  =  & GAMEDRIVER_INTERFACE ;
82+ 
83+ static  uint32_t  camBase  =  0 ;
84+ static  uint32_t  flyingCamBase  =  0 ;
85+ static  float  scale  =  300.f ;
86+ static  float  lastRoll  =  0.f ;
87+ 
88+ //========================================================================== 
89+ // Purpose: return 1 if game is detected 
90+ //========================================================================== 
91+ static  uint8_t  GC_TE_Status (void )
92+ {
93+ 	// GTKE51 
94+ 	return  (MEM_ReadUInt (0x80000000 ) ==  0x47544B45U  &&  
95+ 			MEM_ReadUInt (0x80000004 ) ==  0x35310000U );
96+ }
97+ 
98+ static  uint8_t  GC_TE_DetectCamBase (void )
99+ {
100+ 	uint32_t  tempCamBase  =  MEM_ReadUInt (TE_ONFOOT_CAMBASE );
101+ 	if  (tempCamBase  && 
102+ 		MEM_ReadUInt (tempCamBase  +  TE_ONFOOT_CAMBASE_SANITY_1 ) ==  TE_ONFOOT_CAMBASE_SANITY_1_VALUE ) // && 
103+ 		// MEM_ReadUInt(tempCamBase + TE_ONFOOT_CAMBASE_SANITY_2) == TE_ONFOOT_CAMBASE_SANITY_2_VALUE) 
104+ 	{
105+ 		camBase  =  tempCamBase ;
106+ 		return  1 ;
107+ 	}
108+ 	return  0 ;
109+ }
110+ 
111+ static  uint8_t  GC_TE_DetectFlyingBase (void )
112+ {
113+ 	uint32_t  tempCamBase  =  MEM_ReadUInt (TE_FLYING_BASE );
114+ 	if  (tempCamBase  && 
115+ 		MEM_ReadUInt (tempCamBase  +  TE_FLYING_BASE_SANITY_1 ) ==  TE_FLYING_BASE_SANITY_1_VALUE  && 
116+ 		MEM_ReadUInt (tempCamBase  +  TE_FLYING_BASE_SANITY_2 ) ==  TE_FLYING_BASE_SANITY_2_VALUE )
117+ 	{
118+ 		flyingCamBase  =  tempCamBase ;
119+ 		return  1 ;
120+ 	}
121+ 	return  0 ;
122+ }
123+ 
124+ //========================================================================== 
125+ // Purpose: calculate mouse look and inject into current game 
126+ //========================================================================== 
127+ static  void  GC_TE_Inject (void )
128+ {
129+ 	if (xmouse  ==  0  &&  ymouse  ==  0 ) // if mouse is idle 
130+ 		return ;
131+ 	
132+ 	if  (MEM_ReadUInt (TE_IS_PAUSED ) ==  TE_IS_PAUSED_TRUE )
133+ 		return ;
134+ 
135+ 	if  (MEM_ReadUInt (TE_IS_IN_GAME_CUTSCENE ) ==  TE_IS_IN_GAME_CUTSCENE_TRUE )
136+ 		return ;
137+ 
138+ 	const  float  looksensitivity  =  (float )sensitivity  / 40.f ;
139+ 
140+ 	if  (GC_TE_DetectFlyingBase ())
141+ 	{
142+ 		float  flyingPitchSpeed  =  MEM_ReadFloat (flyingCamBase  +  TE_FLYING_PITCH_SPEED );
143+ 		flyingPitchSpeed  +=  (float )ymouse  *  looksensitivity  / 100.f ;
144+ 		flyingPitchSpeed  =  ClampFloat (flyingPitchSpeed , -1.33f , 1.33f );
145+ 		MEM_WriteFloat (flyingCamBase  +  TE_FLYING_PITCH_SPEED , flyingPitchSpeed );
146+ 
147+ 		float  flyingRollSpeed  =  MEM_ReadFloat (flyingCamBase  +  TE_FLYING_ROLL_SPEED );
148+ 		flyingRollSpeed  +=  (float )xmouse  *  looksensitivity  / scale ;
149+ 		// flyingRollSpeed = ClampFloat(flyingRollSpeed, -0.83f, 0.83f); 
150+ 		flyingRollSpeed  =  ClampFloat (flyingRollSpeed , -1.2f , 1.2f );
151+ 		MEM_WriteFloat (flyingCamBase  +  TE_FLYING_ROLL_SPEED , flyingRollSpeed );
152+ 		lastRoll  =  flyingRollSpeed ;
153+ 
154+ 		return ;
155+ 	}
156+ 
157+ 	if  (!GC_TE_DetectCamBase ())
158+ 		return ;
159+ 	
160+ 	uint32_t  turretBase  =  MEM_ReadUInt (camBase  +  TE_TURRET_BASE );
161+ 	
162+ 	if  (turretBase )
163+ 	{
164+ 		float  camX  =  MEM_ReadFloat (turretBase  +  TE_TURRET_CAMX );
165+ 		camX  -=  (float )xmouse  *  looksensitivity  / scale ;
166+ 		float  camXBound  =  MEM_ReadFloat (turretBase  +  TE_TURRET_CAMX_BOUND );
167+ 		camX  =  ClampFloat (camX , - camXBound , camXBound );
168+ 
169+ 		float  camY  =  MEM_ReadFloat (turretBase  +  TE_TURRET_CAMY );
170+ 		camY  -=  (float )(invertpitch  ? - ymouse  : ymouse ) *  looksensitivity  / scale ;
171+ 		float  camYBound  =  MEM_ReadFloat (turretBase  +  TE_TURRET_CAMY_BOUND );
172+ 		camY  =  ClampFloat (camY , - camYBound , camYBound );
173+ 
174+ 		MEM_WriteFloat (turretBase  +  TE_TURRET_CAMX , camX );
175+ 		MEM_WriteFloat (turretBase  +  TE_TURRET_CAMY , camY );
176+ 	}
177+ 	else  if  (!MEM_ReadUInt (camBase  +  TE_IS_NOT_CLIMBING ) &&  !MEM_ReadUInt (camBase  +  TE_IN_WATER ))
178+ 	{
179+ 		// if climbing and not in water 
180+ 
181+ 		if  (MEM_ReadUInt (TE_CLIMBING_CAMY_REBOUND_OP ) ==  0x60000000 ) // if patch is enabled 
182+ 		{
183+ 			float  camX  =  MEM_ReadFloat (camBase  +  TE_CLIMB_CAMX );
184+ 			camX  -=  (float )xmouse  *  looksensitivity  *  (360.f  / TAU ) / scale ;
185+ 			camX  =  ClampFloat (camX , -110.f , 110.f );
186+ 
187+ 			float  camY  =  MEM_ReadFloat (camBase  +  TE_ONFOOT_CAMY );
188+ 			camY  -=  (float )(invertpitch  ? - ymouse  : ymouse ) *  looksensitivity  *  (360.f  / TAU ) / scale ;
189+ 			camY  =  ClampFloat (camY , -75.f , 225.f );
190+ 
191+ 			MEM_WriteFloat (camBase  +  TE_CLIMB_CAMX , camX );
192+ 			MEM_WriteFloat (camBase  +  TE_ONFOOT_CAMY , camY );
193+ 		}
194+ 
195+ 		return ;
196+ 	}
197+ 	else 
198+ 	{
199+ 		float  fov  =  MEM_ReadFloat (camBase  +  TE_ONFOOT_FOV ) / 90.f ;
200+ 		
201+ 		float  camX  =  MEM_ReadFloat (camBase  +  TE_ONFOOT_CAMX );
202+ 		camX  -=  (float )xmouse  *  looksensitivity  / scale  *  fov ;
203+ 		while  (camX  >= TAU )
204+ 			camX  -=  TAU ;
205+ 		while  (camX  <  0 )
206+ 			camX  +=  TAU ;
207+ 
208+ 		float  camY  =  MEM_ReadFloat (camBase  +  TE_ONFOOT_CAMY );
209+ 		camY  -=  (float )(invertpitch  ? - ymouse  : ymouse ) *  looksensitivity  *  (360.f  / TAU ) / scale  *  fov ;
210+ 		camY  =  ClampFloat (camY , -70.f , 70.f );
211+ 
212+ 		MEM_WriteFloat (camBase  +  TE_ONFOOT_CAMX , camX );
213+ 		MEM_WriteFloat (camBase  +  TE_ONFOOT_CAMY , camY );
214+ 	}
215+ }
0 commit comments