Skip to content

Commit

Permalink
fixes for tm
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjosack committed Feb 16, 2023
1 parent c7e00d0 commit 25e6d4b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.0.33] - 2023-02-16

### Fixed

- Crash on shutdown related to entity hooking
- Tunnel Man Mod now works with crysknife
- Tunnal Man Mod no longer plays audio when you press whip in the air

## [0.0.32] - 2023-02-15

### Added
Expand Down
63 changes: 58 additions & 5 deletions specs/specs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,42 @@ void __declspec(naked) hookUnlockCoffins() {
}
}

DWORD hookWhipJmpBackAddr = NULL;
DWORD hookWhipSkipWhippingAddr = NULL;
void __declspec(naked) hookWhip() {

// 0x569a5
// 83 bf 34 01 00 00 1d

__asm {
; Save all registers
pushad
}

// Player off ground
if (gGlobalState->player1 && gGlobalState->player1_data.has_crysknife == 0 &&
gGlobalState->player1->field68_0x200 == 0) {
__asm {
; Restore all registers
popad

; Jump back to previous location
jmp [hookWhipSkipWhippingAddr]
}
}
else {
__asm {
; Restore all registers
popad

CMP dword ptr [EDI + 0x134],0x1d

; Jump back to previous location
jmp [hookWhipJmpBackAddr]
}
}
}

DWORD hookPostSpawnEntityJmpBackAddr = NULL;
void __declspec(naked) hookPostSpawnEntity() {

Expand All @@ -593,6 +629,8 @@ void __declspec(naked) hookPostSpawnEntity() {
popad

mov esi, spawned_entity
mov spawned_entity, 0

; Jump back to previous location
jmp [hookPostSpawnEntityJmpBackAddr]
}
Expand Down Expand Up @@ -2835,6 +2873,11 @@ std::vector<Patch> gFullSpelunkyPatches = {

};

std::vector<Patch> gTunnelManPatches = {
// Put back stolen bytes
{0x569a5, {}, {0x83, 0xbf, 0x34, 0x01, 0x00, 0x00, 0x1d}},
};

void resetTunnelManState() {
gGlobalState->player1_data.health = 2;
gGlobalState->player1_data.health2 = 2;
Expand Down Expand Up @@ -3040,12 +3083,7 @@ Entity *postSpawnEntityTunnelMan(Entity *ent) {
if (ent && ent->entity_type == 109) {
ent->alpha = 0.0;
ent->flag_deletion = 1;

auto new_ent = gGlobalState->SpawnEntity(ent->x, ent->y, 510, true);
if (gGlobalState->player1 && gGlobalState->player1->field68_0x200 == 0) {
new_ent->alpha = 0.0;
gGlobalState->player1->field27_0x198 = 0;
}

return new_ent;
}
Expand Down Expand Up @@ -3591,6 +3629,21 @@ void drawModsTab() {
if (ImGui::Checkbox("Tunnel Man", &gModsState.TunnelMan)) {
if (gModsState.TunnelMan) {
resetTunnelManState();

if (!hookWhipJmpBackAddr) {

int hookLen = 7;
DWORD hookAddr = gBaseAddress + 0x569a5;
hookWhipJmpBackAddr = hookAddr + hookLen;
hookWhipSkipWhippingAddr = gBaseAddress + 0x56a80;
hook((void *)hookAddr, hookWhip, hookLen);
}
} else {
if (hookWhipJmpBackAddr) {
applyPatches(gTunnelManPatches, true);
hookWhipJmpBackAddr = NULL;
hookWhipSkipWhippingAddr = NULL;
}
}
};
}
Expand Down

0 comments on commit 25e6d4b

Please sign in to comment.