Skip to content

Commit 858b594

Browse files
author
Sui
committed
Stuff
1 parent a50d159 commit 858b594

10 files changed

+193
-58
lines changed

AVP_CustomLauncher.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
</Compile>
9090
<Compile Include="DLLInjector.cs" />
9191
<Compile Include="GameHack.cs" />
92+
<Compile Include="LogHandler.cs" />
9293
<Compile Include="Settings.cs" />
9394
<Compile Include="SettingsForms\GameSettingsForm.cs">
9495
<SubType>Form</SubType>

AVP_CustomLauncher.sdf

0 Bytes
Binary file not shown.

GameHack.cs

+60-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Reflection;
4+
using System.IO;
35
using System.Collections.Generic;
46
using System.Linq;
57
using System.Text;
@@ -12,9 +14,12 @@ class GameHack
1214
{
1315
int LithTechBaseAdress = 0x00400000;
1416
int cshellBaseAdress = 0x0000000; //Is changed later, when the app starts running.
17+
int d3dren = 0x0000000; //Is changed later, when the app starts running.
1518
int hookedDllAddress = 0x0;
1619
Process[] myProcess;
1720

21+
string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
22+
1823
static int threadDelay = 500;
1924
private volatile bool _shouldStop = false;
2025
string processName = "lithtech";
@@ -44,8 +49,8 @@ public void DoWork()
4449
fovX = VerticalRadiansToHorizontalFor4By3Monitor(fovY);
4550
bgCorrectedValue = correntMenuBGWithAspect(1.308997035f);
4651

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");
4954
System.Threading.Thread.Sleep(5000);
5055

5156
while (!_shouldStop)
@@ -58,20 +63,23 @@ public void DoWork()
5863
{
5964
if (foundProcess == false)
6065
System.Threading.Thread.Sleep(2000);
61-
if (cshellBaseAdress == 0x0 || LithTechBaseAdress == 0x0)
66+
if (cshellBaseAdress == 0x0 || LithTechBaseAdress == 0x0 || d3dren == 0x0)
6267
{
6368
String appToHookTo = processName;
6469
Process[] foundProcesses = Process.GetProcessesByName(appToHookTo);
6570
ProcessModuleCollection modules = foundProcesses[0].Modules;
66-
ProcessModule dllBaseAdressIWant = null;
6771
foreach (ProcessModule i in modules)
6872
{
6973
if (i.ModuleName == "cshell.dll")
7074
{
71-
dllBaseAdressIWant = i;
75+
cshellBaseAdress = i.BaseAddress.ToInt32();
7276
}
77+
else if (i.ModuleName == "d3d.ren")
78+
{
79+
d3dren = i.BaseAddress.ToInt32();
80+
}
81+
7382
}
74-
cshellBaseAdress = dllBaseAdressIWant.BaseAddress.ToInt32();
7583
}
7684

7785
foundProcess = true;
@@ -92,14 +100,51 @@ public void DoWork()
92100
if (readBgValue != bgCorrectedValue && readBgValue != 0x0000000)
93101
Trainer.WritePointerFloat(myProcess, cshellBaseAdress + bgScalingAddress, bgScalingOffsets, bgCorrectedValue);
94102

95-
if (!dllInjected && LithTechBaseAdress != 0x0 && cshellBaseAdress != 0x0)
103+
if (!dllInjected && LithTechBaseAdress != 0x0 && cshellBaseAdress != 0x0 && d3dren != 0x0)
96104
{
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);
99139
if(result == DllInjectionResult.Success)
100140
{
101141
dllInjected = true;
102142
}
143+
else
144+
{
145+
LogHandler.WriteLine("Error when injecting DLL: " + result.ToString());
146+
MessageBox.Show("Error when injecting DLL: " + result.ToString());
147+
}
103148

104149

105150
System.Threading.Thread.Sleep(500);
@@ -117,16 +162,18 @@ public void DoWork()
117162

118163
#if DEBUG
119164
{
120-
Debug.WriteLine("DLL Injected at: 0x" + hookedDllAddress.ToString("X4"));
165+
LogHandler.WriteLine("DLL Injected at: 0x" + hookedDllAddress.ToString("X4"));
121166
Trainer.WriteInteger(myProcess, hookedDllAddress + 0x19008, ResolutionX);
122167
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"));
124169
}
125170
#else
126171
{
127172
//And HOPE NOTHING MOVED
173+
LogHandler.WriteLine("DLL Injected at: 0x" + hookedDllAddress.ToString("X4"));
128174
Trainer.WriteInteger(myProcess, hookedDllAddress + 0x4008, ResolutionX);
129175
Trainer.WriteInteger(myProcess, hookedDllAddress + 0x400C, ResolutionY);
176+
LogHandler.WriteLine("Written to dllHook: " + ResolutionX + "x" + ResolutionY + " at address " + (hookedDllAddress + 0x4008).ToString("X4"));
130177
}
131178
#endif
132179
}
@@ -135,7 +182,7 @@ public void DoWork()
135182
}
136183
catch(Exception ex)
137184
{
138-
Trace.WriteLine(ex.ToString());
185+
LogHandler.WriteLine("Exception in GameHack.cs" + ex.ToString());
139186
}
140187

141188
}
@@ -146,7 +193,7 @@ public void SendValues(float value, int ResX, int ResY)
146193
desiredfov = value;
147194
ResolutionX = ResX;
148195
ResolutionY = ResY;
149-
Debug.WriteLine("Thread received values: " + ResolutionX + "x" + ResolutionY + " @ " + desiredfov);
196+
LogHandler.WriteLine("Thread received values: " + ResolutionX + "x" + ResolutionY + " @ " + desiredfov);
150197
}
151198

152199
public void RequestStop()

LogHandler.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.IO;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Diagnostics;
8+
9+
namespace AVP_CustomLauncher
10+
{
11+
static class LogHandler
12+
{
13+
static StreamWriter SR = new StreamWriter("avp2_customlauncher.log");
14+
static DateTime time = DateTime.Now;
15+
16+
17+
public static void Open()
18+
{
19+
SR.Flush();
20+
SR.WriteLine("This log is created each time, you start a launcher and writes down exceptions, errors etc.");
21+
}
22+
23+
public static void WriteLine(string text)
24+
{
25+
#if DEBUG
26+
Debug.WriteLine(text);
27+
#endif
28+
29+
string tString = (DateTime.Now - time).ToString();
30+
SR.WriteLine(tString + ": " + text);
31+
}
32+
33+
public static void Close()
34+
{
35+
string tString = (DateTime.Now - time).ToString();
36+
SR.WriteLine(tString + ": Closing");
37+
SR.Close();
38+
}
39+
}
40+
}

MainForm.cs

+77-34
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public partial class mainform : Form
2323

2424
public mainform()
2525
{
26+
LogHandler.WriteLine("LogFile created.");
2627
InitializeComponent();
2728
if (File.Exists("autoexecextended.cfg"))
2829
{
@@ -110,6 +111,7 @@ private void B_StartGame_Click(object sender, EventArgs e)
110111
StreamReader SR = new StreamReader("avp2cmds.txt");
111112
string cmdlineparamters = "";
112113
cmdlineparamters = SR.ReadToEnd();
114+
cmdlineparamters = stripResolutionParameters(cmdlineparamters);
113115

114116
if (_GraphicsSettings.windowed)
115117
cmdlineparamters = cmdlineparamters + " +windowed 1";
@@ -148,8 +150,7 @@ private void B_StartGame_Click(object sender, EventArgs e)
148150

149151
cmdlineparamters = cmdlineparamters + " " + _GraphicsSettings.T_CommandLine.Text;
150152

151-
152-
153+
LogHandler.WriteLine("Launch parameters are: " + cmdlineparamters);
153154

154155
Thread GameHackThread = new Thread(_gamehack.DoWork);
155156
if (_GraphicsSettings.aspectratiohack)
@@ -173,11 +174,50 @@ private void B_StartGame_Click(object sender, EventArgs e)
173174
}
174175
catch (Exception ex)
175176
{
176-
Console.WriteLine("An error occurred!: " + ex.Message);
177+
LogHandler.WriteLine("An error occurred when creating new process: " + ex.Message);
177178
return;
178179
}
179180
}
180181

182+
private string stripResolutionParameters(string cmdlineparamters)
183+
{
184+
string[] words = cmdlineparamters.Split(' ');
185+
for (int i = 0; i < words.Length - 1; i++)
186+
{
187+
if (words[i].ToLower() == "++gamescreenwidth" || words[i].ToLower() == "++screenwidth")
188+
{
189+
uint num;
190+
if (uint.TryParse(words[i + 1], out num))
191+
{
192+
words[i + 1] = _GraphicsSettings.ResolutionX.ToString();
193+
i++;
194+
}
195+
}
196+
else if (words[i].ToLower() == "++gamescreenheight" || words[i].ToLower() == "++screenheight")
197+
{
198+
uint num;
199+
if (uint.TryParse(words[i + 1], out num))
200+
{
201+
words[i + 1] = _GraphicsSettings.ResolutionY.ToString();
202+
i++;
203+
}
204+
}
205+
else if (words[i].ToLower() == "++gamebitdepth" || words[i].ToLower() == "++bitdepth")
206+
{
207+
uint num;
208+
if (uint.TryParse(words[i + 1], out num))
209+
{
210+
if (_GraphicsSettings.GameBitDepth)
211+
words[i + 1] = "32";
212+
else
213+
words[i + 1] = "16";
214+
i++;
215+
}
216+
}
217+
}
218+
return string.Join(" ", words);
219+
}
220+
181221
private void B_DisplaySettings_Click(object sender, EventArgs e)
182222
{
183223
_GraphicsSettings.SetDesktopLocation(this.DesktopLocation.X + 10, this.DesktopLocation.Y + 10);
@@ -189,6 +229,39 @@ private void B_Exit_Click(object sender, EventArgs e)
189229
_gamehack.RequestStop();
190230
this.Close();
191231
}
232+
233+
private void mainform_FormClosing(object sender, FormClosingEventArgs e)
234+
{
235+
if (File.Exists("autoexecextended.cfg")) //well should have thought about this earlier... whatever
236+
{
237+
bool flagX = false;
238+
bool flagY = false;
239+
string[] settings = File.ReadAllLines("autoexecextended.cfg");
240+
for (int i = 0; i < settings.Length; i++)
241+
{
242+
if (settings[i].StartsWith("PositionX:"))
243+
{
244+
settings[i] = "PositionX:" + _posX.ToString();
245+
flagX = true;
246+
}
247+
else if (settings[i].StartsWith("PositionY:"))
248+
{
249+
settings[i] = "PositionY:" + _posY.ToString();
250+
flagY = true;
251+
}
252+
}
253+
254+
string output = string.Join("\n", settings);
255+
256+
if (!flagX)
257+
output += "\nPositionX:" + this._posX.ToString();
258+
if (!flagY)
259+
output += "\nPositionY:" + this._posY.ToString();
260+
261+
File.WriteAllText("autoexecextended.cfg", output);
262+
}
263+
LogHandler.Close();
264+
}
192265
#endregion
193266

194267
#region ParseFunctions
@@ -223,41 +296,11 @@ private bool checkIfPosIsCorrect(uint PosX, uint PosY)
223296
}
224297
#endregion
225298

226-
private void mainform_FormClosing(object sender, FormClosingEventArgs e)
227-
{
228-
if (File.Exists("autoexecextended.cfg")) //well should have thought about this earlier... whatever
229-
{
230-
bool flagX = false;
231-
bool flagY = false;
232-
string[] settings = File.ReadAllLines("autoexecextended.cfg");
233-
for (int i = 0; i < settings.Length; i++)
234-
{
235-
if (settings[i].StartsWith("PositionX:"))
236-
{
237-
settings[i] = "PositionX:" + _posX.ToString();
238-
flagX = true;
239-
}
240-
else if (settings[i].StartsWith("PositionY:"))
241-
{
242-
settings[i] = "PositionY:" + _posY.ToString();
243-
flagY = true;
244-
}
245-
}
246-
247-
string output = string.Join("\n", settings);
248-
249-
if (!flagX)
250-
output += "\nPositionX:" + this._posX.ToString();
251-
if (!flagY)
252-
output += "\nPositionY:" + this._posY.ToString();
253299

254-
File.WriteAllText("autoexecextended.cfg", output);
255-
}
256-
}
257300

258301
private void mainform_LocationChanged(object sender, EventArgs e)
259302
{
260-
if (this.WindowState == FormWindowState.Normal)
303+
if (this.WindowState == FormWindowState.Normal && this.DesktopLocation.X > -1 && this.DesktopLocation.Y>-1)
261304
{
262305
_posX = this.DesktopLocation.X;
263306
_posY = this.DesktopLocation.Y;

Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.6.3.0")]
36-
[assembly: AssemblyFileVersion("0.6.3.0")]
35+
[assembly: AssemblyVersion("0.6.4.0")]
36+
[assembly: AssemblyFileVersion("0.6.4.0")]

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Patch the game if you haven't already. Download the program from [releases page]
2323

2424
**Note**: For the program to work properly, Administrator rights may be required (especially for Widescreen hack). You can set it in Compatibility Options.
2525

26+
**Note 2**: For running the game on resolutions wider than 2048px you'll need "special" D3DIM700.DLL by jackfuste. It can be found [here](http://www.wsgf.org/forums/viewtopic.php?p=155982#p155982).
27+
2628
Credits
2729
-------
2830
* [SuicideMachine](http://www.twitch.tv/suicidemachine/)

Release/AVP_CustomLauncher.exe

3.5 KB
Binary file not shown.

Release/widescreenfix.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)