Skip to content

Commit

Permalink
feat: speedhack functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Micrologist committed Feb 16, 2022
1 parent c3edace commit 0876794
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 7 deletions.
1 change: 1 addition & 0 deletions DeathloopTrainer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Injector.cs" />
<Compile Include="SignatureScanner.cs" />
<Compile Include="WinAPI.cs" />
<Page Include="MainWindow.xaml">
Expand Down
93 changes: 93 additions & 0 deletions Injector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace DeathloopTrainer
{
public static class Injector
{

[Flags]
public enum AllocationType : uint
{
Commit = 0x1000,
Reserve = 0x2000,
Decommit = 0x4000,
Release = 0x8000,
Reset = 0x80000,
Physical = 0x400000,
TopDown = 0x100000,
WriteWatch = 0x200000,
LargePages = 0x20000000
}

[Flags]
public enum MemoryProtection : uint
{
Execute = 0x10,
ExecuteRead = 0x20,
ExecuteReadWrite = 0x40,
ExecuteWriteCopy = 0x80,
NoAccess = 0x01,
ReadOnly = 0x02,
ReadWrite = 0x04,
WriteCopy = 0x08,
GuardModifierflag = 0x100,
NoCacheModifierflag = 0x200,
WriteCombineModifierflag = 0x400
}

[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, AllocationType flAllocationType, MemoryProtection flProtect);

[DllImport("kernel32.dll")]
static extern bool WriteProcessMemory(
IntPtr hProcess,
IntPtr lpBaseAddress,
byte[] lpBuffer,
Int32 nSize,
out IntPtr lpNumberOfBytesWritten
);

[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr GetModuleHandle(string moduleName);

[DllImport("kernel32.dll")]
static extern IntPtr CreateRemoteThread(IntPtr hProcess,
IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress,
IntPtr lpParameter, uint dwCreationFlags, out IntPtr lpThreadId);

public static bool InjectDLL(string dllpath, Process proc)
{
if (proc.Handle == IntPtr.Zero)
return false;


IntPtr loc = VirtualAllocEx(proc.Handle, IntPtr.Zero, (uint)dllpath.Length, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ReadWrite);

if (loc.Equals(0))
{
return false;
}

bool result = WriteProcessMemory(proc.Handle, loc, Encoding.ASCII.GetBytes(dllpath), dllpath.Length, out IntPtr bytesRead);

if (!result || bytesRead.Equals(0))
{
return false;
}

IntPtr loadLibAdr = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");

IntPtr hThread = CreateRemoteThread(proc.Handle, IntPtr.Zero, 0, loadLibAdr, loc, 0, out _);

return !hThread.Equals(0);

}
}

}
13 changes: 8 additions & 5 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DeathloopTrainer"
mc:Ignorable="d"
Title="Deathloop Trainer" Height="266" Width="485" ResizeMode="CanMinimize">
Title="Deathloop Trainer" Height="312.751" Width="485" ResizeMode="CanMinimize">
<Grid Background="#FF292929">
<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"/>
<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"/>
<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" />
<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" />
<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"/>
<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"/>
<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"/>
<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"/>
<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"/>
<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>
<TextBlock x:Name="positionBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="78,41,0,0" Height="85" Width="116" FontSize="20" Foreground="White" TextAlignment="Right"/>
<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" />
<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" />
<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" />
<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" />
<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" />
<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" />
<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"/>
<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"/>
<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"/>

</Grid>

Expand Down
118 changes: 116 additions & 2 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
Expand All @@ -19,12 +20,16 @@ public partial class MainWindow : Window
DeepPointer characterDP = new DeepPointer(0x02D5F688, 0x8, 0x8, 0x98, 0xA0, 0x1F0, 0x0);
DeepPointer rotationDP = new DeepPointer(0x810, 0x0);
DeepPointer statusDP = new DeepPointer(0x900);
DeepPointer gameSpeedDP = new DeepPointer("timewizardry.dll", 0x63F8);

IntPtr xVelPtr, yVelPtr, zVelPtr, xPosPtr, yPosPtr, zPosPtr, godPtr, ammoPtr, rotAPtr, rotBPtr;
IntPtr xVelPtr, yVelPtr, zVelPtr, xPosPtr, yPosPtr, zPosPtr, godPtr, ammoPtr, rotAPtr, rotBPtr, gameSpeedPtr;

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

double gameSpeed, prefGameSpeed = 1.0;

bool speedhackActivated = false;

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

Expand Down Expand Up @@ -57,12 +62,25 @@ private void teleUpBtn_Click(object sender, RoutedEventArgs e)
TeleportUpward();
}

private void activateGameSpeedBtn_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
ActivateSpeedhack();
}


private void saveBtn_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
StorePosition();
}

private void gameSpeedBtn_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
SwitchPrefSpeed();
}

private void teleBtn_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
Expand All @@ -80,6 +98,8 @@ public MainWindow()
kbHook.HookedKeys.Add(System.Windows.Forms.Keys.F4);
kbHook.HookedKeys.Add(System.Windows.Forms.Keys.F5);
kbHook.HookedKeys.Add(System.Windows.Forms.Keys.F6);
kbHook.HookedKeys.Add(System.Windows.Forms.Keys.F7);


updateTimer = new Timer
{
Expand Down Expand Up @@ -109,7 +129,6 @@ private void Update(object sender, EventArgs e)
return;
}


game.ReadValue<float>(xPosPtr, out xPos);
game.ReadValue<float>(yPosPtr, out yPos);
game.ReadValue<float>(zPosPtr, out zPos);
Expand Down Expand Up @@ -140,6 +159,63 @@ private void Update(object sender, EventArgs e)
{
TeleportUpward();
}



if(speedhackActivated)
{
activateGameSpeedBtn.Visibility = Visibility.Hidden;
gameSpeedBtn.Visibility = Visibility.Visible;
gameSpeedLabel.Visibility = Visibility.Visible;

game.ReadValue<double>(gameSpeedPtr, out gameSpeed);
if(gameSpeed != prefGameSpeed)
{
game.WriteBytes(gameSpeedPtr, BitConverter.GetBytes(prefGameSpeed));
}

gameSpeedLabel.Content = prefGameSpeed.ToString("0.0") + "x";
}
else
{
activateGameSpeedBtn.Visibility = Visibility.Visible;
gameSpeedBtn.Visibility = Visibility.Hidden;
gameSpeedLabel.Visibility = Visibility.Hidden;
}
}

private bool CheckSpeedhack()
{
foreach (ProcessModule module in game.Modules)
{
if (module.ModuleName == "timewizardry.dll")
return true;
}
return false;
}
private void SwitchPrefSpeed()
{
switch (prefGameSpeed)
{
case 1.0f:
prefGameSpeed = 2.0;
break;
case 2.0f:
prefGameSpeed = 4.0;
break;
case 4.0f:
prefGameSpeed = 8.0;
break;
case 8.0f:
prefGameSpeed = 0.5;
break;
case 0.5f:
prefGameSpeed = 1.0;
break;
default:
prefGameSpeed = 1.0;
break;
}
}

private bool Hook()
Expand Down Expand Up @@ -186,6 +262,7 @@ private bool Hook()

private void DerefPointers()
{

characterDP.DerefOffsets(game, out IntPtr basePtr);
xPosPtr = basePtr + 0x80;
yPosPtr = basePtr + 0x84;
Expand All @@ -202,6 +279,16 @@ private void DerefPointers()
rotAPtr = basePtr + 0x1B4;
rotBPtr = basePtr + 0x1B8;

speedhackActivated = CheckSpeedhack();


gameSpeedDP.DerefOffsets(game, out gameSpeedPtr);
speedhackActivated = gameSpeedPtr != IntPtr.Zero;
if (speedhackActivated)
{
WinAPI.VirtualProtectEx(game.Handle, gameSpeedPtr, (UIntPtr)0x8, MemPageProtect.PAGE_READWRITE, out _);
}

}

private void InputKeyDown(object sender, KeyEventArgs e)
Expand All @@ -226,6 +313,12 @@ private void InputKeyDown(object sender, KeyEventArgs e)
case Keys.F6:
Teleport();
break;
case Keys.F7:
if (speedhackActivated)
SwitchPrefSpeed();
else
ActivateSpeedhack();
break;
default:
break;
}
Expand Down Expand Up @@ -496,5 +589,26 @@ void TestFunction()
game.WriteBytes(newRotPtr, BitConverter.GetBytes(ptr.ToInt64()));
}


private void ActivateSpeedhack()
{
if (!hooked || speedhackActivated) return;


string dllPath = System.Windows.Forms.Application.StartupPath + "\\timewizardry.dll";

if (!File.Exists(dllPath))
{
System.Windows.MessageBox.Show("Could not find \"timewizardry.dll\".", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

bool result = Injector.InjectDLL(dllPath, game);
if(!result)
{
System.Windows.MessageBox.Show("Injection Failed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

}
}

0 comments on commit 0876794

Please sign in to comment.