1
1
using System ;
2
2
using System . Diagnostics ;
3
+ using System . Reflection ;
4
+ using System . IO ;
3
5
using System . Collections . Generic ;
4
6
using System . Linq ;
5
7
using System . Text ;
@@ -12,9 +14,12 @@ class GameHack
12
14
{
13
15
int LithTechBaseAdress = 0x00400000 ;
14
16
int cshellBaseAdress = 0x0000000 ; //Is changed later, when the app starts running.
17
+ int d3dren = 0x0000000 ; //Is changed later, when the app starts running.
15
18
int hookedDllAddress = 0x0 ;
16
19
Process [ ] myProcess ;
17
20
21
+ string path = Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) ;
22
+
18
23
static int threadDelay = 500 ;
19
24
private volatile bool _shouldStop = false ;
20
25
string processName = "lithtech" ;
@@ -44,8 +49,8 @@ public void DoWork()
44
49
fovX = VerticalRadiansToHorizontalFor4By3Monitor ( fovY ) ;
45
50
bgCorrectedValue = correntMenuBGWithAspect ( 1.308997035f ) ;
46
51
47
-
48
- Trace . WriteLine ( "Display FOV calculated to: " + fovX + " horizontal, " + fovY + " vertical" ) ;
52
+ LogHandler . WriteLine ( "Launcher directory is: " + path ) ;
53
+ LogHandler . WriteLine ( "Display FOV calculated to: " + fovX + " horizontal, " + fovY + " vertical" ) ;
49
54
System . Threading . Thread . Sleep ( 5000 ) ;
50
55
51
56
while ( ! _shouldStop )
@@ -58,20 +63,23 @@ public void DoWork()
58
63
{
59
64
if ( foundProcess == false )
60
65
System . Threading . Thread . Sleep ( 2000 ) ;
61
- if ( cshellBaseAdress == 0x0 || LithTechBaseAdress == 0x0 )
66
+ if ( cshellBaseAdress == 0x0 || LithTechBaseAdress == 0x0 || d3dren == 0x0 )
62
67
{
63
68
String appToHookTo = processName ;
64
69
Process [ ] foundProcesses = Process . GetProcessesByName ( appToHookTo ) ;
65
70
ProcessModuleCollection modules = foundProcesses [ 0 ] . Modules ;
66
- ProcessModule dllBaseAdressIWant = null ;
67
71
foreach ( ProcessModule i in modules )
68
72
{
69
73
if ( i . ModuleName == "cshell.dll" )
70
74
{
71
- dllBaseAdressIWant = i ;
75
+ cshellBaseAdress = i . BaseAddress . ToInt32 ( ) ;
72
76
}
77
+ else if ( i . ModuleName == "d3d.ren" )
78
+ {
79
+ d3dren = i . BaseAddress . ToInt32 ( ) ;
80
+ }
81
+
73
82
}
74
- cshellBaseAdress = dllBaseAdressIWant . BaseAddress . ToInt32 ( ) ;
75
83
}
76
84
77
85
foundProcess = true ;
@@ -92,14 +100,51 @@ public void DoWork()
92
100
if ( readBgValue != bgCorrectedValue && readBgValue != 0x0000000 )
93
101
Trainer . WritePointerFloat ( myProcess , cshellBaseAdress + bgScalingAddress , bgScalingOffsets , bgCorrectedValue ) ;
94
102
95
- if ( ! dllInjected && LithTechBaseAdress != 0x0 && cshellBaseAdress != 0x0 )
103
+ if ( ! dllInjected && LithTechBaseAdress != 0x0 && cshellBaseAdress != 0x0 && d3dren != 0x0 )
96
104
{
97
- DllInjectionResult result = DllInjector . GetInstance . Inject ( myProcess , "widescreenfix.dll" ) ;
98
- Debug . WriteLine ( "DLL Injection: " + result ) ;
105
+ #region LogAssemblyBytes
106
+ {
107
+ string strByte = "" ;
108
+ for ( int i = 0 ; i < 5 ; i ++ )
109
+ {
110
+ strByte += ( Trainer . ReadByte ( myProcess , cshellBaseAdress + 0xEF79 + i ) ) . ToString ( "X2" ) ;
111
+ }
112
+
113
+ LogHandler . WriteLine ( "Bytes at injection point cshellBaseAdress + 0xEF79 (resolution hack):" + strByte ) ;
114
+ }
115
+
116
+ {
117
+ string strByte = "" ;
118
+ for ( int i = 0 ; i < 6 ; i ++ )
119
+ {
120
+ strByte += ( Trainer . ReadByte ( myProcess , LithTechBaseAdress + 0xC370 + i ) ) . ToString ( "X2" ) ;
121
+ }
122
+
123
+ LogHandler . WriteLine ( "Bytes at injection point LithTechBaseAdress + 0xC370 (fov hack):" + strByte ) ;
124
+ }
125
+
126
+ {
127
+ string strByte = "" ;
128
+ for ( int i = 0 ; i < 9 ; i ++ )
129
+ {
130
+ strByte += ( Trainer . ReadByte ( myProcess , d3dren + 0x107F2 + i ) ) . ToString ( "X2" ) ;
131
+ }
132
+
133
+ LogHandler . WriteLine ( "Bytes at injection point d3dren + 0x107F2 (viewmodel hack):" + strByte ) ;
134
+ }
135
+ #endregion
136
+
137
+ DllInjectionResult result = DllInjector . GetInstance . Inject ( myProcess , Path . Combine ( path , "widescreenfix.dll" ) ) ;
138
+ LogHandler . WriteLine ( "DLL Injection: " + result ) ;
99
139
if ( result == DllInjectionResult . Success )
100
140
{
101
141
dllInjected = true ;
102
142
}
143
+ else
144
+ {
145
+ LogHandler . WriteLine ( "Error when injecting DLL: " + result . ToString ( ) ) ;
146
+ MessageBox . Show ( "Error when injecting DLL: " + result . ToString ( ) ) ;
147
+ }
103
148
104
149
105
150
System . Threading . Thread . Sleep ( 500 ) ;
@@ -117,16 +162,18 @@ public void DoWork()
117
162
118
163
#if DEBUG
119
164
{
120
- Debug . WriteLine ( "DLL Injected at: 0x" + hookedDllAddress . ToString ( "X4" ) ) ;
165
+ LogHandler . WriteLine ( "DLL Injected at: 0x" + hookedDllAddress . ToString ( "X4" ) ) ;
121
166
Trainer . WriteInteger ( myProcess , hookedDllAddress + 0x19008 , ResolutionX ) ;
122
167
Trainer . WriteInteger ( myProcess , hookedDllAddress + 0x1900C , ResolutionY ) ;
123
- Debug . WriteLine ( "Written to dllHook: " + ResolutionX + "x" + ResolutionY + " at address " + ( hookedDllAddress + 0x19008 ) . ToString ( "X4" ) ) ;
168
+ LogHandler . WriteLine ( "Written to dllHook: " + ResolutionX + "x" + ResolutionY + " at address " + ( hookedDllAddress + 0x19008 ) . ToString ( "X4" ) ) ;
124
169
}
125
170
#else
126
171
{
127
172
//And HOPE NOTHING MOVED
173
+ LogHandler . WriteLine ( "DLL Injected at: 0x" + hookedDllAddress . ToString ( "X4" ) ) ;
128
174
Trainer . WriteInteger ( myProcess , hookedDllAddress + 0x4008 , ResolutionX ) ;
129
175
Trainer . WriteInteger ( myProcess , hookedDllAddress + 0x400C , ResolutionY ) ;
176
+ LogHandler . WriteLine ( "Written to dllHook: " + ResolutionX + "x" + ResolutionY + " at address " + ( hookedDllAddress + 0x4008 ) . ToString ( "X4" ) ) ;
130
177
}
131
178
#endif
132
179
}
@@ -135,7 +182,7 @@ public void DoWork()
135
182
}
136
183
catch ( Exception ex )
137
184
{
138
- Trace . WriteLine ( ex . ToString ( ) ) ;
185
+ LogHandler . WriteLine ( "Exception in GameHack.cs" + ex . ToString ( ) ) ;
139
186
}
140
187
141
188
}
@@ -146,7 +193,7 @@ public void SendValues(float value, int ResX, int ResY)
146
193
desiredfov = value ;
147
194
ResolutionX = ResX ;
148
195
ResolutionY = ResY ;
149
- Debug . WriteLine ( "Thread received values: " + ResolutionX + "x" + ResolutionY + " @ " + desiredfov ) ;
196
+ LogHandler . WriteLine ( "Thread received values: " + ResolutionX + "x" + ResolutionY + " @ " + desiredfov ) ;
150
197
}
151
198
152
199
public void RequestStop ( )
0 commit comments