Skip to content

Commit

Permalink
Merge pull request #12 from 0xvpr/dev
Browse files Browse the repository at this point in the history
hacks functions exported to asm
  • Loading branch information
0xvpr authored Feb 11, 2024
2 parents 91aac95 + db8d3da commit 95abc70
Show file tree
Hide file tree
Showing 8 changed files with 637 additions and 95 deletions.
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@
</p>
<br>

### Timeline
- Project started: 08/18/2021
- Switch from C to CPP: 08/18/2021
- Project completed: 08/19/2021
- Switch from CPP to C: 08/20/2021
- Project revisited: 12/09/2021
- Project revisited: 12/07/2022
- Project revisited: 05/26/2023

## Overview & Demonstration
The main purpose of this project was to get familiar with the C language while also
familiarizing myself with the Directx9c API.
The main purpose of this repository was to see if I could write cheats
in pure assembly.

<img src="./resources/demo.gif"/>
Demonstration of God Mode, Disable Alarms, and Disable Enemies.
Expand Down
3 changes: 0 additions & 3 deletions compile_flags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
-std=c99
--target=i686-pc-windows-gnu
-I/usr/lib/gcc/i686-w64-mingw32/9.3-win32/include
-I/usr/lib/gcc/i686-w64-mingw32/9.3-win32/include-fixed
-I/usr/lib/gcc/i686-w64-mingw32/9.3-win32/../../../../i686-w64-mingw32/include
-Iinclude
-Wall
-Wextra
Expand Down
242 changes: 242 additions & 0 deletions src/events.asm.bak

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,51 @@ extern HackMenu g_hack_menu[MAX_MENU_ITEMS];

int events_handle_keyboard(void)
{
/* Toggle GodMode */
/*[> Toggle GodMode <]*/
if (GetAsyncKeyState(VK_NUMPAD1) & 1)
{
g_hack_menu[GOD_MODE].bEnabled = !g_hack_menu[GOD_MODE].bEnabled;
hack_god_mode(g_hack_menu[GOD_MODE].bEnabled);
}

/* Toggle GhostMode */
/*[> Toggle GhostMode <]*/
if (GetAsyncKeyState(VK_NUMPAD2) & 1)
{
g_hack_menu[GHOST_MODE].bEnabled = !g_hack_menu[GHOST_MODE].bEnabled;
hack_ghost_mode(g_hack_menu[GHOST_MODE].bEnabled);
}

/* Toggle Super Weapons */
/*[> Toggle Super Weapons <]*/
if (GetAsyncKeyState(VK_NUMPAD3) & 1)
{
g_hack_menu[SUPER_WEAPONS].bEnabled = !g_hack_menu[SUPER_WEAPONS].bEnabled;
hack_super_weapons(g_hack_menu[SUPER_WEAPONS].bEnabled);
}

/* Disable All Alarms */
/*[> Disable All Alarms <]*/
if (GetAsyncKeyState(VK_NUMPAD4) & 1)
{
g_hack_menu[DISABLE_ALARMS].bEnabled = !g_hack_menu[DISABLE_ALARMS].bEnabled;
hack_disable_alarms(g_hack_menu[DISABLE_ALARMS].bEnabled);
}

/* Toggle DisableEnemies */
/*[> Toggle DisableEnemies <]*/
if (GetAsyncKeyState(VK_NUMPAD5) & 1)
{
g_hack_menu[DISABLE_ENEMIES].bEnabled = !g_hack_menu[DISABLE_ENEMIES].bEnabled;
/*n_entities_changed = */
/*[>n_entities_changed = <]*/
hack_disable_enemies(g_hack_menu[DISABLE_ENEMIES].bEnabled);
}

/* Unlock All Doors */
/*[> Unlock All Doors <]*/
if (GetAsyncKeyState(VK_NUMPAD6) & 1)
{
//g_hack_menu[UNLOCK_ALL_DOORS].bEnabled = !g_hack_menu[UNLOCK_ALL_DOORS].bEnabled;
/*total_doors_unlocked = */
/*[>total_doors_unlocked = <]*/
hack_unlock_all_doors();
}

/* Unlock All Doors */
/*[> Unlock All Doors <]*/
if (GetAsyncKeyState(VK_NUMPAD7) & 1)
{
hack_test();
Expand Down
Empty file removed src/hack_god_mode.asm
Empty file.
384 changes: 384 additions & 0 deletions src/hacks.asm

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions src/hacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,6 @@

extern uintptr_t g_module_base_addr;

__attribute__((always_inline))
void hack_god_mode(int bEnabled)
{
void* const health_addr = (void *)(g_module_base_addr + offsets_health_base);

if (bEnabled)
{
memory_detour(health_addr, health_detour, sizeof(patch_health_original));
}
else
{
memory_patch(health_addr, patch_health_original, sizeof(patch_health_original));
}
}

__attribute__((always_inline))
void hack_ghost_mode(int bEnabled)
{
void* const visibility_addr = (void *)(g_module_base_addr + offsets_invisibility_base);
void* const noise_addr = (void *)(g_module_base_addr + offsets_noise_base);

// TODO: Add third op for slider

if (bEnabled)
{
DWORD old_protect = 0;
VirtualProtect(visibility_addr, sizeof(patch_visibility_original), PAGE_EXECUTE_WRITECOPY, &old_protect);
*((uint64_t *)visibility_addr) = 0x05D9909090909090;
VirtualProtect(visibility_addr, sizeof(patch_visibility_original), old_protect, &old_protect);

/*memory_nop(visibility_addr, sizeof(patch_visibility_original));*/
memory_patch(noise_addr, patch_noise_patch, sizeof(patch_noise_patch));
}
else
{
memory_patch(visibility_addr, patch_visibility_original, sizeof(patch_visibility_original));
memory_patch(noise_addr, patch_noise_original, sizeof(patch_noise_original));
}

}

void hack_super_weapons(int bEnabled)
{
void* const main_ammo_addr = (void *)(g_module_base_addr + offsets_main_ammo_base);
Expand Down Expand Up @@ -99,20 +58,6 @@ void hack_super_weapons(int bEnabled)

}

void hack_disable_alarms(int bEnabled)
{
void* const alarm_addr = (char *)(g_module_base_addr + offsets_alarm_base);

if (bEnabled)
{
memory_patch(alarm_addr, patch_alarm_patch, sizeof(patch_alarm_patch));
}
else
{
memory_patch(alarm_addr, patch_alarm_original, sizeof(patch_alarm_original));
}
}

unsigned int hack_disable_enemies(int bEnabled)
{
GameWorld* gameWorld = (GameWorld *)memory_find_dynamic_address(g_module_base_addr + offsets_game_world_base,
Expand Down
17 changes: 0 additions & 17 deletions src/health_detour.asm

This file was deleted.

0 comments on commit 95abc70

Please sign in to comment.