Skip to content

Commit 0876794

Browse files
committed
feat: speedhack functionality
1 parent c3edace commit 0876794

File tree

4 files changed

+218
-7
lines changed

4 files changed

+218
-7
lines changed

DeathloopTrainer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Generator>MSBuild:Compile</Generator>
8080
<SubType>Designer</SubType>
8181
</ApplicationDefinition>
82+
<Compile Include="Injector.cs" />
8283
<Compile Include="SignatureScanner.cs" />
8384
<Compile Include="WinAPI.cs" />
8485
<Page Include="MainWindow.xaml">

Injector.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Text;
3+
using System.Runtime.InteropServices;
4+
using System.Diagnostics;
5+
6+
namespace DeathloopTrainer
7+
{
8+
public static class Injector
9+
{
10+
11+
[Flags]
12+
public enum AllocationType : uint
13+
{
14+
Commit = 0x1000,
15+
Reserve = 0x2000,
16+
Decommit = 0x4000,
17+
Release = 0x8000,
18+
Reset = 0x80000,
19+
Physical = 0x400000,
20+
TopDown = 0x100000,
21+
WriteWatch = 0x200000,
22+
LargePages = 0x20000000
23+
}
24+
25+
[Flags]
26+
public enum MemoryProtection : uint
27+
{
28+
Execute = 0x10,
29+
ExecuteRead = 0x20,
30+
ExecuteReadWrite = 0x40,
31+
ExecuteWriteCopy = 0x80,
32+
NoAccess = 0x01,
33+
ReadOnly = 0x02,
34+
ReadWrite = 0x04,
35+
WriteCopy = 0x08,
36+
GuardModifierflag = 0x100,
37+
NoCacheModifierflag = 0x200,
38+
WriteCombineModifierflag = 0x400
39+
}
40+
41+
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
42+
static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect);
43+
44+
[DllImport("kernel32.dll")]
45+
static extern bool WriteProcessMemory(
46+
IntPtr hProcess,
47+
IntPtr lpBaseAddress,
48+
byte[] lpBuffer,
49+
Int32 nSize,
50+
out IntPtr lpNumberOfBytesWritten
51+
);
52+
53+
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
54+
static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
55+
56+
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
57+
public static extern IntPtr GetModuleHandle(string moduleName);
58+
59+
[DllImport("kernel32.dll")]
60+
static extern IntPtr CreateRemoteThread(IntPtr hProcess,
61+
IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress,
62+
IntPtr lpParameter, uint dwCreationFlags, out IntPtr lpThreadId);
63+
64+
public static bool InjectDLL(string dllpath, Process proc)
65+
{
66+
if (proc.Handle == IntPtr.Zero)
67+
return false;
68+
69+
70+
IntPtr loc = VirtualAllocEx(proc.Handle, IntPtr.Zero, (uint)dllpath.Length, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ReadWrite);
71+
72+
if (loc.Equals(0))
73+
{
74+
return false;
75+
}
76+
77+
bool result = WriteProcessMemory(proc.Handle, loc, Encoding.ASCII.GetBytes(dllpath), dllpath.Length, out IntPtr bytesRead);
78+
79+
if (!result || bytesRead.Equals(0))
80+
{
81+
return false;
82+
}
83+
84+
IntPtr loadLibAdr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
85+
86+
IntPtr hThread = CreateRemoteThread(proc.Handle, IntPtr.Zero, 0, loadLibAdr, loc, 0, out _);
87+
88+
return !hThread.Equals(0);
89+
90+
}
91+
}
92+
93+
}

MainWindow.xaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:DeathloopTrainer"
77
mc:Ignorable="d"
8-
Title="Deathloop Trainer" Height="266" Width="485" ResizeMode="CanMinimize">
8+
Title="Deathloop Trainer" Height="312.751" Width="485" ResizeMode="CanMinimize">
99
<Grid Background="#FF292929">
10-
<Button x:Name="teleportFwBtn" Content="[F1] Teleport Forwards" HorizontalAlignment="Left" Height="28" Margin="218,12,0,0" VerticalAlignment="Top" Width="200" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Click="teleportFwBtn_Click"/>
10+
<Button x:Name="teleportFwBtn" Content="[F1] Teleport Forwards" HorizontalAlignment="Left" Height="28" Margin="218,12,0,0" VerticalAlignment="Top" Width="240" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Click="teleportFwBtn_Click"/>
1111
<Button x:Name="saveBtn" Content="[F5] Save Position" HorizontalAlignment="Left" Height="27" Margin="218,150,0,0" VerticalAlignment="Top" Width="240" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Click="saveBtn_Click" />
1212
<Button x:Name="teleBtn" Content="[F6] Teleport" HorizontalAlignment="Left" Height="28" Margin="218,182,0,0" VerticalAlignment="Top" Width="240" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Click="teleBtn_Click" />
13-
<Label x:Name="speedLabel" Content="Speed" HorizontalAlignment="Left" Height="35" Margin="10,177,0,0" VerticalAlignment="Top" Width="68" FontSize="20" Foreground="White" FontWeight="Bold"/>
14-
<TextBlock x:Name="speedBlock" HorizontalAlignment="Left" Text="10.99 m/s" VerticalAlignment="Top" Margin="86,182,0,0" Height="31" Width="108" FontSize="20" Foreground="White" TextAlignment="Right"/>
13+
<Label x:Name="speedLabel" Content="Speed" HorizontalAlignment="Left" Height="35" Margin="10,217,0,0" VerticalAlignment="Top" Width="68" FontSize="20" Foreground="White" FontWeight="Bold"/>
14+
<TextBlock x:Name="speedBlock" HorizontalAlignment="Left" Text="10.99 m/s" VerticalAlignment="Top" Margin="86,222,0,0" Height="31" Width="108" FontSize="20" Foreground="White" TextAlignment="Right"/>
1515
<Label x:Name="positionLabel" Content="Position" HorizontalAlignment="Left" Height="35" Margin="10,3,0,0" VerticalAlignment="Top" Width="196" FontSize="20" Foreground="White" FontWeight="Bold"/>
1616
<TextBlock x:Name="positionLabelBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="17,41,0,0" Height="85" Width="61" FontSize="20" Foreground="White" TextAlignment="Left"><Run Text="x"/><LineBreak/><Run Text="y"/><LineBreak/><Run Text="z"/></TextBlock>
1717
<TextBlock x:Name="positionBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="78,41,0,0" Height="85" Width="116" FontSize="20" Foreground="White" TextAlignment="Right"/>
1818
<Button x:Name="godModeBtn" Content="[F3] God Mode" HorizontalAlignment="Left" Height="28" Margin="218,78,0,0" VerticalAlignment="Top" Width="200" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Click="godModeBtn_Click" />
1919
<Label x:Name="godModeLabel" Content="OFF" HorizontalAlignment="Left" Height="35" Margin="423,77,0,0" VerticalAlignment="Top" Width="46" FontSize="16" FontWeight="Bold" Foreground="Red" RenderTransformOrigin="0.571,-1.489" />
2020
<Button x:Name="ammoBtn" Content="[F4] Infinite Ammo" HorizontalAlignment="Left" Height="28" Margin="218,111,0,0" VerticalAlignment="Top" Width="200" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Click="ammoBtn_Click" />
2121
<Label x:Name="ammoLabel" Content="OFF" HorizontalAlignment="Left" Height="35" Margin="423,110,0,0" VerticalAlignment="Top" Width="46" FontSize="16" FontWeight="Bold" Foreground="Red" RenderTransformOrigin="0.571,-1.489" />
22-
<Button x:Name="teleUpBtn" Content="[F2] Teleport Up" HorizontalAlignment="Left" Height="28" Margin="218,45,0,0" VerticalAlignment="Top" Width="200" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Click="teleUpBtn_Click" />
22+
<Button x:Name="teleUpBtn" Content="[F2] Teleport Up" HorizontalAlignment="Left" Height="28" Margin="218,45,0,0" VerticalAlignment="Top" Width="240" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Click="teleUpBtn_Click" />
23+
<Button x:Name="gameSpeedBtn" Content="[F7] Game Speed" HorizontalAlignment="Left" Height="28" Margin="218,223,0,0" VerticalAlignment="Top" Width="194" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Visibility="HIdden" Click="gameSpeedBtn_Click"/>
24+
<Label x:Name="gameSpeedLabel" Content="1.0x" HorizontalAlignment="Left" Height="35" Margin="412,221,0,0" VerticalAlignment="Top" Width="46" FontSize="16" FontWeight="Bold" Foreground="White" RenderTransformOrigin="0.478,0.543" Background="#00000000" Visibility="HIdden"/>
25+
<Button x:Name="activateGameSpeedBtn" Content="[F7] Activate Speedhack" HorizontalAlignment="Left" Height="28" Margin="218,223,0,0" VerticalAlignment="Top" Width="240" FontSize="16" Background="#FF666666" Foreground="White" BorderBrush="#FF040404" Visibility="Visible" Click="activateGameSpeedBtn_Click"/>
2326

2427
</Grid>
2528

MainWindow.xaml.cs

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
45
using System.Linq;
56
using System.Windows;
67
using System.Windows.Forms;
@@ -19,12 +20,16 @@ public partial class MainWindow : Window
1920
DeepPointer characterDP = new DeepPointer(0x02D5F688, 0x8, 0x8, 0x98, 0xA0, 0x1F0, 0x0);
2021
DeepPointer rotationDP = new DeepPointer(0x810, 0x0);
2122
DeepPointer statusDP = new DeepPointer(0x900);
23+
DeepPointer gameSpeedDP = new DeepPointer("timewizardry.dll", 0x63F8);
2224

23-
IntPtr xVelPtr, yVelPtr, zVelPtr, xPosPtr, yPosPtr, zPosPtr, godPtr, ammoPtr, rotAPtr, rotBPtr;
25+
IntPtr xVelPtr, yVelPtr, zVelPtr, xPosPtr, yPosPtr, zPosPtr, godPtr, ammoPtr, rotAPtr, rotBPtr, gameSpeedPtr;
2426

2527
bool god, ammo, teleFw, teleUp = false;
2628
float[] storedPos = new float[5] { 0f, 0f, 0f, 0f, 0f };
2729

30+
double gameSpeed, prefGameSpeed = 1.0;
31+
32+
bool speedhackActivated = false;
2833

2934
float xVel, yVel, zVel, xPos, yPos, zPos, rotA, rotB;
3035

@@ -57,12 +62,25 @@ private void teleUpBtn_Click(object sender, RoutedEventArgs e)
5762
TeleportUpward();
5863
}
5964

65+
private void activateGameSpeedBtn_Click(object sender, RoutedEventArgs e)
66+
{
67+
e.Handled = true;
68+
ActivateSpeedhack();
69+
}
70+
71+
6072
private void saveBtn_Click(object sender, RoutedEventArgs e)
6173
{
6274
e.Handled = true;
6375
StorePosition();
6476
}
6577

78+
private void gameSpeedBtn_Click(object sender, RoutedEventArgs e)
79+
{
80+
e.Handled = true;
81+
SwitchPrefSpeed();
82+
}
83+
6684
private void teleBtn_Click(object sender, RoutedEventArgs e)
6785
{
6886
e.Handled = true;
@@ -80,6 +98,8 @@ public MainWindow()
8098
kbHook.HookedKeys.Add(System.Windows.Forms.Keys.F4);
8199
kbHook.HookedKeys.Add(System.Windows.Forms.Keys.F5);
82100
kbHook.HookedKeys.Add(System.Windows.Forms.Keys.F6);
101+
kbHook.HookedKeys.Add(System.Windows.Forms.Keys.F7);
102+
83103

84104
updateTimer = new Timer
85105
{
@@ -109,7 +129,6 @@ private void Update(object sender, EventArgs e)
109129
return;
110130
}
111131

112-
113132
game.ReadValue<float>(xPosPtr, out xPos);
114133
game.ReadValue<float>(yPosPtr, out yPos);
115134
game.ReadValue<float>(zPosPtr, out zPos);
@@ -140,6 +159,63 @@ private void Update(object sender, EventArgs e)
140159
{
141160
TeleportUpward();
142161
}
162+
163+
164+
165+
if(speedhackActivated)
166+
{
167+
activateGameSpeedBtn.Visibility = Visibility.Hidden;
168+
gameSpeedBtn.Visibility = Visibility.Visible;
169+
gameSpeedLabel.Visibility = Visibility.Visible;
170+
171+
game.ReadValue<double>(gameSpeedPtr, out gameSpeed);
172+
if(gameSpeed != prefGameSpeed)
173+
{
174+
game.WriteBytes(gameSpeedPtr, BitConverter.GetBytes(prefGameSpeed));
175+
}
176+
177+
gameSpeedLabel.Content = prefGameSpeed.ToString("0.0") + "x";
178+
}
179+
else
180+
{
181+
activateGameSpeedBtn.Visibility = Visibility.Visible;
182+
gameSpeedBtn.Visibility = Visibility.Hidden;
183+
gameSpeedLabel.Visibility = Visibility.Hidden;
184+
}
185+
}
186+
187+
private bool CheckSpeedhack()
188+
{
189+
foreach (ProcessModule module in game.Modules)
190+
{
191+
if (module.ModuleName == "timewizardry.dll")
192+
return true;
193+
}
194+
return false;
195+
}
196+
private void SwitchPrefSpeed()
197+
{
198+
switch (prefGameSpeed)
199+
{
200+
case 1.0f:
201+
prefGameSpeed = 2.0;
202+
break;
203+
case 2.0f:
204+
prefGameSpeed = 4.0;
205+
break;
206+
case 4.0f:
207+
prefGameSpeed = 8.0;
208+
break;
209+
case 8.0f:
210+
prefGameSpeed = 0.5;
211+
break;
212+
case 0.5f:
213+
prefGameSpeed = 1.0;
214+
break;
215+
default:
216+
prefGameSpeed = 1.0;
217+
break;
218+
}
143219
}
144220

145221
private bool Hook()
@@ -186,6 +262,7 @@ private bool Hook()
186262

187263
private void DerefPointers()
188264
{
265+
189266
characterDP.DerefOffsets(game, out IntPtr basePtr);
190267
xPosPtr = basePtr + 0x80;
191268
yPosPtr = basePtr + 0x84;
@@ -202,6 +279,16 @@ private void DerefPointers()
202279
rotAPtr = basePtr + 0x1B4;
203280
rotBPtr = basePtr + 0x1B8;
204281

282+
speedhackActivated = CheckSpeedhack();
283+
284+
285+
gameSpeedDP.DerefOffsets(game, out gameSpeedPtr);
286+
speedhackActivated = gameSpeedPtr != IntPtr.Zero;
287+
if (speedhackActivated)
288+
{
289+
WinAPI.VirtualProtectEx(game.Handle, gameSpeedPtr, (UIntPtr)0x8, MemPageProtect.PAGE_READWRITE, out _);
290+
}
291+
205292
}
206293

207294
private void InputKeyDown(object sender, KeyEventArgs e)
@@ -226,6 +313,12 @@ private void InputKeyDown(object sender, KeyEventArgs e)
226313
case Keys.F6:
227314
Teleport();
228315
break;
316+
case Keys.F7:
317+
if (speedhackActivated)
318+
SwitchPrefSpeed();
319+
else
320+
ActivateSpeedhack();
321+
break;
229322
default:
230323
break;
231324
}
@@ -496,5 +589,26 @@ void TestFunction()
496589
game.WriteBytes(newRotPtr, BitConverter.GetBytes(ptr.ToInt64()));
497590
}
498591

592+
593+
private void ActivateSpeedhack()
594+
{
595+
if (!hooked || speedhackActivated) return;
596+
597+
598+
string dllPath = System.Windows.Forms.Application.StartupPath + "\\timewizardry.dll";
599+
600+
if (!File.Exists(dllPath))
601+
{
602+
System.Windows.MessageBox.Show("Could not find \"timewizardry.dll\".", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
603+
return;
604+
}
605+
606+
bool result = Injector.InjectDLL(dllPath, game);
607+
if(!result)
608+
{
609+
System.Windows.MessageBox.Show("Injection Failed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
610+
}
611+
}
612+
499613
}
500614
}

0 commit comments

Comments
 (0)