From cfcd63684ca36f0681f0a007f3257d5ee6472d9f Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 22 Oct 2024 17:22:41 +0200 Subject: [PATCH 1/5] tr2: port Lift_Initialise --- docs/tr2/progress.svg | 32 ++++++++++++++--------------- docs/tr2/progress.txt | 15 +++++++++----- src/tr2/game/objects/general/lift.c | 15 ++++++++++++++ src/tr2/game/objects/general/lift.h | 10 +++++++++ src/tr2/global/funcs.h | 9 ++++---- src/tr2/inject_exec.c | 2 ++ src/tr2/meson.build | 1 + 7 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 src/tr2/game/objects/general/lift.c create mode 100644 src/tr2/game/objects/general/lift.h diff --git a/docs/tr2/progress.svg b/docs/tr2/progress.svg index 90aa91d38..5e4b9f9d2 100644 --- a/docs/tr2/progress.svg +++ b/docs/tr2/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -67.36% (838) · 30.23% (376) · 0% (0) · 2.41% (30) +67.44% (839) · 30.14% (375) · 0% (0) · 2.41% (30) - - + + @@ -715,11 +715,11 @@ void __cdecl DrawBridgeFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl DrawBridgeCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl DrawBridgeCollision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll); -void __cdecl InitialiseLift(int16_t item_num); -void __cdecl LiftControl(int16_t item_num); -void __cdecl LiftFloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); -void __cdecl LiftFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); -void __cdecl LiftCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +void __cdecl Lift_Initialise(int16_t item_num); +void __cdecl Lift_Control(int16_t item_num); +void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); +void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeFlatFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeFlatCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); int32_t __cdecl GetOffset(ITEM *item, int32_t x, int32_t z); @@ -1324,10 +1324,10 @@ Tomb2.exe progress according to the function sizes: -72.69% · 26.98% · 0% · 0.33% +72.71% · 26.96% · 0% · 0.33% - - + + @@ -1578,7 +1578,7 @@ void __cdecl S_Audio_Sample_Init2(HWND hwnd); void __cdecl SE_GraphicsDlgInit(HWND hwndDlg); void __cdecl SpinningBlade(int16_t item_num); -void __cdecl LiftFloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); +void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); void __cdecl Lara_Col_Run(ITEM *item, COLL_INFO *coll); void __cdecl Output_InsertPoly_Gouraud(int32_t vtx_count, float z, int32_t red, int32_t green, int32_t blue, int16_t poly_type); void __cdecl Boat_DoWakeEffect(ITEM *boat); @@ -1755,7 +1755,7 @@ bool __cdecl SE_GraphicsTestStart(void); int16_t __cdecl Creature_Turn(ITEM *item, int16_t maximum_turn); void __cdecl WinVidSetDisplayAdapter(DISPLAY_ADAPTER *disp_adapter); -void __cdecl LiftControl(int16_t item_num); +void __cdecl Lift_Control(int16_t item_num); void __cdecl Output_InsertTransQuad(int32_t x, int32_t y, int32_t width, int32_t height, int32_t z); void __cdecl Lara_State_ForwardJump(ITEM *item, COLL_INFO *coll); void __cdecl Flare_DoInHand(int32_t flare_age); @@ -2269,9 +2269,9 @@ void __cdecl Lara_State_HangRight(ITEM *item, COLL_INFO *coll); void __cdecl Lara_State_ClimbLeft(ITEM *item, COLL_INFO *coll); void __cdecl Lara_State_ClimbRight(ITEM *item, COLL_INFO *coll); -void __cdecl InitialiseLift(int16_t item_num); -void __cdecl LiftFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); -void __cdecl LiftCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +void __cdecl Lift_Initialise(int16_t item_num); +void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeTilt1Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl ReadSG(void *pointer, int32_t size); void __cdecl WinVidSetGameWindowSize(int32_t width, int32_t height); diff --git a/docs/tr2/progress.txt b/docs/tr2/progress.txt index 40b263fe5..7f5e802e1 100644 --- a/docs/tr2/progress.txt +++ b/docs/tr2/progress.txt @@ -2653,6 +2653,11 @@ typedef struct __unaligned { int32_t pitch; } SKIDOO_INFO; +typedef struct __unaligned { // decompiled + int32_t start_height; + int32_t wait_time; +} LIFT_INFO; + typedef struct __unaligned { struct { XYZ_16 min; @@ -3580,11 +3585,11 @@ typedef enum { 0x00435650 0x0036 -R void __cdecl DrawBridgeFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435690 0x003B -R void __cdecl DrawBridgeCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x004356D0 0x002C -R void __cdecl DrawBridgeCollision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll); -0x00435700 0x0035 -R void __cdecl InitialiseLift(int16_t item_num); -0x00435740 0x00D4 -R void __cdecl LiftControl(int16_t item_num); -0x00435820 0x0179 -R void __cdecl LiftFloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); -0x004359A0 0x0035 -R void __cdecl LiftFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); -0x004359E0 0x0035 -R void __cdecl LiftCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +0x00435700 0x0035 + void __cdecl Lift_Initialise(int16_t item_num); +0x00435740 0x00D4 - void __cdecl Lift_Control(int16_t item_num); +0x00435820 0x0179 - void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); +0x004359A0 0x0035 - void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +0x004359E0 0x0035 - void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A20 0x0016 -R void __cdecl BridgeFlatFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A40 0x001B -R void __cdecl BridgeFlatCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A60 0x003B -R int32_t __cdecl GetOffset(ITEM *item, int32_t x, int32_t z); diff --git a/src/tr2/game/objects/general/lift.c b/src/tr2/game/objects/general/lift.c new file mode 100644 index 000000000..fabebc4e3 --- /dev/null +++ b/src/tr2/game/objects/general/lift.c @@ -0,0 +1,15 @@ +#include "game/objects/general/lift.h" + +#include "global/funcs.h" + +void __cdecl Lift_Initialise(const int16_t item_num) +{ + ITEM *const item = Item_Get(item_num); + + LIFT_INFO *const lift_data = + game_malloc(sizeof(LIFT_INFO), GBUF_TEMP_ALLOC); + lift_data->start_height = item->pos.y; + lift_data->wait_time = 0; + + item->data = lift_data; +} diff --git a/src/tr2/game/objects/general/lift.h b/src/tr2/game/objects/general/lift.h new file mode 100644 index 000000000..89f10ebf3 --- /dev/null +++ b/src/tr2/game/objects/general/lift.h @@ -0,0 +1,10 @@ +#pragma once + +#include "global/types.h" + +typedef struct __PACKING { + int32_t start_height; + int32_t wait_time; +} LIFT_INFO; + +void __cdecl Lift_Initialise(int16_t item_num); diff --git a/src/tr2/global/funcs.h b/src/tr2/global/funcs.h index b199212d7..ee438a20c 100644 --- a/src/tr2/global/funcs.h +++ b/src/tr2/global/funcs.h @@ -121,11 +121,10 @@ #define DrawBridgeFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435650) #define DrawBridgeCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435690) #define DrawBridgeCollision ((void __cdecl (*)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll))0x004356D0) -#define InitialiseLift ((void __cdecl (*)(int16_t item_num))0x00435700) -#define LiftControl ((void __cdecl (*)(int16_t item_num))0x00435740) -#define LiftFloorCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling))0x00435820) -#define LiftFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359A0) -#define LiftCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359E0) +#define Lift_Control ((void __cdecl (*)(int16_t item_num))0x00435740) +#define Lift_FloorCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling))0x00435820) +#define Lift_Floor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359A0) +#define Lift_Ceiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359E0) #define BridgeFlatFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435A20) #define BridgeFlatCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435A40) #define GetOffset ((int32_t __cdecl (*)(ITEM *item, int32_t x, int32_t z))0x00435A60) diff --git a/src/tr2/inject_exec.c b/src/tr2/inject_exec.c index a56577060..2adcea8f1 100644 --- a/src/tr2/inject_exec.c +++ b/src/tr2/inject_exec.c @@ -53,6 +53,7 @@ #include "game/objects/general/final_level_counter.h" #include "game/objects/general/gong_bonger.h" #include "game/objects/general/keyhole.h" +#include "game/objects/general/lift.h" #include "game/objects/general/movable_block.h" #include "game/objects/general/pickup.h" #include "game/objects/general/puzzle_hole.h" @@ -1016,6 +1017,7 @@ static void M_Objects(const bool enable) INJECT(enable, 0x00434800, GongBonger_Control); INJECT(enable, 0x004348C0, Zipline_Collision); INJECT(enable, 0x00434980, Zipline_Control); + INJECT(enable, 0x00435700, Lift_Initialise); INJECT(enable, 0x00435D70, Detonator_Control); INJECT(enable, 0x00437E70, Pickup_Collision); INJECT(enable, 0x004382F0, Switch_Collision); diff --git a/src/tr2/meson.build b/src/tr2/meson.build index 0b93084d6..fd38e2cc4 100644 --- a/src/tr2/meson.build +++ b/src/tr2/meson.build @@ -168,6 +168,7 @@ dll_sources = [ 'game/objects/general/final_level_counter.c', 'game/objects/general/gong_bonger.c', 'game/objects/general/keyhole.c', + 'game/objects/general/lift.c', 'game/objects/general/movable_block.c', 'game/objects/general/pickup.c', 'game/objects/general/puzzle_hole.c', From 317f37d9a4fe086ed6e0d01c055886e658545106 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 22 Oct 2024 20:44:32 +0200 Subject: [PATCH 2/5] tr2: port Lift_Control --- docs/tr2/progress.svg | 16 ++++----- docs/tr2/progress.txt | 2 +- src/tr2/game/objects/general/lift.c | 54 +++++++++++++++++++++++++++++ src/tr2/game/objects/general/lift.h | 1 + src/tr2/global/funcs.h | 1 - src/tr2/inject_exec.c | 1 + 6 files changed, 65 insertions(+), 10 deletions(-) diff --git a/docs/tr2/progress.svg b/docs/tr2/progress.svg index 5e4b9f9d2..c55fb2ff8 100644 --- a/docs/tr2/progress.svg +++ b/docs/tr2/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -67.44% (839) · 30.14% (375) · 0% (0) · 2.41% (30) +67.52% (840) · 30.06% (374) · 0% (0) · 2.41% (30) - - + + @@ -716,7 +716,7 @@ void __cdecl DrawBridgeCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl DrawBridgeCollision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll); void __cdecl Lift_Initialise(int16_t item_num); -void __cdecl Lift_Control(int16_t item_num); +void __cdecl Lift_Control(int16_t item_num); void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); @@ -1324,10 +1324,10 @@ Tomb2.exe progress according to the function sizes: -72.71% · 26.96% · 0% · 0.33% +72.77% · 26.90% · 0% · 0.33% - - + + @@ -1755,7 +1755,7 @@ bool __cdecl SE_GraphicsTestStart(void); int16_t __cdecl Creature_Turn(ITEM *item, int16_t maximum_turn); void __cdecl WinVidSetDisplayAdapter(DISPLAY_ADAPTER *disp_adapter); -void __cdecl Lift_Control(int16_t item_num); +void __cdecl Lift_Control(int16_t item_num); void __cdecl Output_InsertTransQuad(int32_t x, int32_t y, int32_t width, int32_t height, int32_t z); void __cdecl Lara_State_ForwardJump(ITEM *item, COLL_INFO *coll); void __cdecl Flare_DoInHand(int32_t flare_age); diff --git a/docs/tr2/progress.txt b/docs/tr2/progress.txt index 7f5e802e1..7bb46b618 100644 --- a/docs/tr2/progress.txt +++ b/docs/tr2/progress.txt @@ -3586,7 +3586,7 @@ typedef enum { 0x00435690 0x003B -R void __cdecl DrawBridgeCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x004356D0 0x002C -R void __cdecl DrawBridgeCollision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll); 0x00435700 0x0035 + void __cdecl Lift_Initialise(int16_t item_num); -0x00435740 0x00D4 - void __cdecl Lift_Control(int16_t item_num); +0x00435740 0x00D4 + void __cdecl Lift_Control(int16_t item_num); 0x00435820 0x0179 - void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); 0x004359A0 0x0035 - void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x004359E0 0x0035 - void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); diff --git a/src/tr2/game/objects/general/lift.c b/src/tr2/game/objects/general/lift.c index fabebc4e3..4adaf6150 100644 --- a/src/tr2/game/objects/general/lift.c +++ b/src/tr2/game/objects/general/lift.c @@ -1,7 +1,18 @@ #include "game/objects/general/lift.h" +#include "game/items.h" +#include "game/room.h" #include "global/funcs.h" +#define LIFT_WAIT_TIME (3 * FRAMES_PER_SECOND) // = 90 +#define LIFT_SHIFT 16 +#define LIFT_TRAVEL_DIST (STEP_L * 22) + +typedef enum { + LIFT_STATE_DOOR_CLOSED = 0, + LIFT_STATE_DOOR_OPEN = 1, +} LIFT_STATE; + void __cdecl Lift_Initialise(const int16_t item_num) { ITEM *const item = Item_Get(item_num); @@ -13,3 +24,46 @@ void __cdecl Lift_Initialise(const int16_t item_num) item->data = lift_data; } + +void __cdecl Lift_Control(const int16_t item_num) +{ + ITEM *const item = Item_Get(item_num); + LIFT_INFO *const lift_data = item->data; + + if (Item_IsTriggerActive(item)) { + if (item->pos.y + < lift_data->start_height + LIFT_TRAVEL_DIST - LIFT_SHIFT) { + if (lift_data->wait_time < LIFT_WAIT_TIME) { + item->goal_anim_state = LIFT_STATE_DOOR_OPEN; + lift_data->wait_time++; + } else { + item->goal_anim_state = LIFT_STATE_DOOR_CLOSED; + item->pos.y += LIFT_SHIFT; + } + } else { + item->goal_anim_state = LIFT_STATE_DOOR_OPEN; + lift_data->wait_time = 0; + } + } else { + if (item->pos.y > lift_data->start_height + LIFT_SHIFT) { + if (lift_data->wait_time < LIFT_WAIT_TIME) { + item->goal_anim_state = LIFT_STATE_DOOR_OPEN; + lift_data->wait_time++; + } else { + item->goal_anim_state = LIFT_STATE_DOOR_CLOSED; + item->pos.y -= LIFT_SHIFT; + } + } else { + item->goal_anim_state = LIFT_STATE_DOOR_OPEN; + lift_data->wait_time = 0; + } + } + + Item_Animate(item); + + int16_t room_num = item->room_num; + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); + if (item->room_num != room_num) { + Item_NewRoom(item_num, room_num); + } +} diff --git a/src/tr2/game/objects/general/lift.h b/src/tr2/game/objects/general/lift.h index 89f10ebf3..bf482c1ad 100644 --- a/src/tr2/game/objects/general/lift.h +++ b/src/tr2/game/objects/general/lift.h @@ -8,3 +8,4 @@ typedef struct __PACKING { } LIFT_INFO; void __cdecl Lift_Initialise(int16_t item_num); +void __cdecl Lift_Control(int16_t item_num); diff --git a/src/tr2/global/funcs.h b/src/tr2/global/funcs.h index ee438a20c..4f705c1e8 100644 --- a/src/tr2/global/funcs.h +++ b/src/tr2/global/funcs.h @@ -121,7 +121,6 @@ #define DrawBridgeFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435650) #define DrawBridgeCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435690) #define DrawBridgeCollision ((void __cdecl (*)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll))0x004356D0) -#define Lift_Control ((void __cdecl (*)(int16_t item_num))0x00435740) #define Lift_FloorCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling))0x00435820) #define Lift_Floor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359A0) #define Lift_Ceiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359E0) diff --git a/src/tr2/inject_exec.c b/src/tr2/inject_exec.c index 2adcea8f1..bfaf31699 100644 --- a/src/tr2/inject_exec.c +++ b/src/tr2/inject_exec.c @@ -1018,6 +1018,7 @@ static void M_Objects(const bool enable) INJECT(enable, 0x004348C0, Zipline_Collision); INJECT(enable, 0x00434980, Zipline_Control); INJECT(enable, 0x00435700, Lift_Initialise); + INJECT(enable, 0x00435740, Lift_Control); INJECT(enable, 0x00435D70, Detonator_Control); INJECT(enable, 0x00437E70, Pickup_Collision); INJECT(enable, 0x004382F0, Switch_Collision); From caeb329cac37025b74da91532d215fdb4a8cfe2c Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 22 Oct 2024 21:03:02 +0200 Subject: [PATCH 3/5] tr2: port Lift_FloorCeiling --- docs/tr2/progress.svg | 16 +++--- docs/tr2/progress.txt | 2 +- src/libtrx/include/libtrx/game/math.h | 10 ++++ src/tr2/game/objects/general/lift.c | 73 +++++++++++++++++++++++++++ src/tr2/game/objects/general/lift.h | 3 ++ src/tr2/global/funcs.h | 1 - src/tr2/inject_exec.c | 1 + 7 files changed, 96 insertions(+), 10 deletions(-) diff --git a/docs/tr2/progress.svg b/docs/tr2/progress.svg index c55fb2ff8..afaa3b4e6 100644 --- a/docs/tr2/progress.svg +++ b/docs/tr2/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -67.52% (840) · 30.06% (374) · 0% (0) · 2.41% (30) +67.60% (841) · 29.98% (373) · 0% (0) · 2.41% (30) - - + + @@ -717,7 +717,7 @@ void __cdecl DrawBridgeCollision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll); void __cdecl Lift_Initialise(int16_t item_num); void __cdecl Lift_Control(int16_t item_num); -void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); +void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeFlatFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); @@ -1324,10 +1324,10 @@ Tomb2.exe progress according to the function sizes: -72.77% · 26.90% · 0% · 0.33% +72.88% · 26.79% · 0% · 0.33% - - + + @@ -1578,7 +1578,7 @@ void __cdecl S_Audio_Sample_Init2(HWND hwnd); void __cdecl SE_GraphicsDlgInit(HWND hwndDlg); void __cdecl SpinningBlade(int16_t item_num); -void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); +void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); void __cdecl Lara_Col_Run(ITEM *item, COLL_INFO *coll); void __cdecl Output_InsertPoly_Gouraud(int32_t vtx_count, float z, int32_t red, int32_t green, int32_t blue, int16_t poly_type); void __cdecl Boat_DoWakeEffect(ITEM *boat); diff --git a/docs/tr2/progress.txt b/docs/tr2/progress.txt index 7bb46b618..b2ee632ea 100644 --- a/docs/tr2/progress.txt +++ b/docs/tr2/progress.txt @@ -3587,7 +3587,7 @@ typedef enum { 0x004356D0 0x002C -R void __cdecl DrawBridgeCollision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll); 0x00435700 0x0035 + void __cdecl Lift_Initialise(int16_t item_num); 0x00435740 0x00D4 + void __cdecl Lift_Control(int16_t item_num); -0x00435820 0x0179 - void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); +0x00435820 0x0179 + void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); 0x004359A0 0x0035 - void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x004359E0 0x0035 - void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A20 0x0016 -R void __cdecl BridgeFlatFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); diff --git a/src/libtrx/include/libtrx/game/math.h b/src/libtrx/include/libtrx/game/math.h index 79c51ad49..e532eb235 100644 --- a/src/libtrx/include/libtrx/game/math.h +++ b/src/libtrx/include/libtrx/game/math.h @@ -6,6 +6,16 @@ #pragma pack(push, 1) +typedef struct __PACKING { + int32_t x; + int32_t z; +} XZ_32; + +typedef struct __PACKING { + int16_t x; + int16_t z; +} XZ_16; + typedef struct __PACKING { int32_t x; int32_t y; diff --git a/src/tr2/game/objects/general/lift.c b/src/tr2/game/objects/general/lift.c index 4adaf6150..bfcc8aec8 100644 --- a/src/tr2/game/objects/general/lift.c +++ b/src/tr2/game/objects/general/lift.c @@ -3,9 +3,11 @@ #include "game/items.h" #include "game/room.h" #include "global/funcs.h" +#include "global/vars.h" #define LIFT_WAIT_TIME (3 * FRAMES_PER_SECOND) // = 90 #define LIFT_SHIFT 16 +#define LIFT_HEIGHT (STEP_L * 5) // = 1280 #define LIFT_TRAVEL_DIST (STEP_L * 22) typedef enum { @@ -67,3 +69,74 @@ void __cdecl Lift_Control(const int16_t item_num) Item_NewRoom(item_num, room_num); } } + +void __cdecl Lift_FloorCeiling( + const ITEM *const item, const int32_t x, const int32_t y, const int32_t z, + int32_t *const out_floor, int32_t *const out_ceiling) +{ + const XZ_32 lift_tile = { + .x = item->pos.x >> WALL_SHIFT, + .z = item->pos.z >> WALL_SHIFT, + }; + + const XZ_32 lara_tile = { + .x = g_LaraItem->pos.x >> WALL_SHIFT, + .z = g_LaraItem->pos.z >> WALL_SHIFT, + }; + + const XZ_32 test_tile = { + .x = x >> WALL_SHIFT, + .z = z >> WALL_SHIFT, + }; + + // clang-format off + const bool point_in_shaft = + (test_tile.x == lift_tile.x || test_tile.x + 1 == lift_tile.x) && + (test_tile.z == lift_tile.z || test_tile.z - 1 == lift_tile.z); + + const bool lara_in_shaft = + (lara_tile.x == lift_tile.x || lara_tile.x + 1 == lift_tile.x) && + (lara_tile.z == lift_tile.z || lara_tile.z - 1 == lift_tile.z); + // clang-format on + + const int32_t lift_floor = item->pos.y; + const int32_t lift_ceiling = item->pos.y - LIFT_HEIGHT; + + *out_floor = 0x7FFF; + *out_ceiling = -0x7FFF; + + if (lara_in_shaft) { + if (item->current_anim_state == LIFT_STATE_DOOR_CLOSED + && g_LaraItem->pos.y < lift_floor + STEP_L + && g_LaraItem->pos.y > lift_ceiling + STEP_L) { + if (point_in_shaft) { + *out_floor = lift_floor; + *out_ceiling = lift_ceiling + STEP_L; + } else { + *out_floor = NO_HEIGHT; + *out_ceiling = 0x7FFF; + } + } else if (point_in_shaft) { + if (g_LaraItem->pos.y < lift_ceiling + STEP_L) { + *out_floor = lift_ceiling; + } else if (g_LaraItem->pos.y < lift_floor + STEP_L) { + *out_floor = lift_floor; + *out_ceiling = lift_ceiling + STEP_L; + } else { + *out_ceiling = lift_floor + STEP_L; + } + } + } else if (point_in_shaft) { + if (y <= lift_ceiling) { + *out_floor = lift_ceiling; + } else if (y >= lift_floor + STEP_L) { + *out_ceiling = lift_floor + STEP_L; + } else if (item->current_anim_state == LIFT_STATE_DOOR_OPEN) { + *out_floor = lift_floor; + *out_ceiling = lift_ceiling + STEP_L; + } else { + *out_floor = NO_HEIGHT; + *out_ceiling = 0x7FFF; + } + } +} diff --git a/src/tr2/game/objects/general/lift.h b/src/tr2/game/objects/general/lift.h index bf482c1ad..7123a0667 100644 --- a/src/tr2/game/objects/general/lift.h +++ b/src/tr2/game/objects/general/lift.h @@ -9,3 +9,6 @@ typedef struct __PACKING { void __cdecl Lift_Initialise(int16_t item_num); void __cdecl Lift_Control(int16_t item_num); +void __cdecl Lift_FloorCeiling( + const ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *out_floor, + int32_t *out_ceiling); diff --git a/src/tr2/global/funcs.h b/src/tr2/global/funcs.h index 4f705c1e8..26c7a2f72 100644 --- a/src/tr2/global/funcs.h +++ b/src/tr2/global/funcs.h @@ -121,7 +121,6 @@ #define DrawBridgeFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435650) #define DrawBridgeCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435690) #define DrawBridgeCollision ((void __cdecl (*)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll))0x004356D0) -#define Lift_FloorCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling))0x00435820) #define Lift_Floor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359A0) #define Lift_Ceiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359E0) #define BridgeFlatFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435A20) diff --git a/src/tr2/inject_exec.c b/src/tr2/inject_exec.c index bfaf31699..c2080fde7 100644 --- a/src/tr2/inject_exec.c +++ b/src/tr2/inject_exec.c @@ -1019,6 +1019,7 @@ static void M_Objects(const bool enable) INJECT(enable, 0x00434980, Zipline_Control); INJECT(enable, 0x00435700, Lift_Initialise); INJECT(enable, 0x00435740, Lift_Control); + INJECT(enable, 0x00435820, Lift_FloorCeiling); INJECT(enable, 0x00435D70, Detonator_Control); INJECT(enable, 0x00437E70, Pickup_Collision); INJECT(enable, 0x004382F0, Switch_Collision); From 2e2eb1f7e852242e010c115af54cfa329225b6cf Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 22 Oct 2024 21:05:03 +0200 Subject: [PATCH 4/5] tr2: port Lift_Floor --- docs/tr2/progress.svg | 16 ++++++++-------- docs/tr2/progress.txt | 2 +- src/tr2/game/objects/general/lift.c | 12 ++++++++++++ src/tr2/game/objects/general/lift.h | 2 ++ src/tr2/global/funcs.h | 1 - src/tr2/inject_exec.c | 1 + 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/docs/tr2/progress.svg b/docs/tr2/progress.svg index afaa3b4e6..c94457fdc 100644 --- a/docs/tr2/progress.svg +++ b/docs/tr2/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -67.60% (841) · 29.98% (373) · 0% (0) · 2.41% (30) +67.68% (842) · 29.90% (372) · 0% (0) · 2.41% (30) - - + + @@ -718,7 +718,7 @@ void __cdecl Lift_Initialise(int16_t item_num); void __cdecl Lift_Control(int16_t item_num); void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); -void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeFlatFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeFlatCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); @@ -1324,10 +1324,10 @@ Tomb2.exe progress according to the function sizes: -72.88% · 26.79% · 0% · 0.33% +72.90% · 26.78% · 0% · 0.33% - - + + @@ -2270,7 +2270,7 @@ void __cdecl Lara_State_ClimbLeft(ITEM *item, COLL_INFO *coll); void __cdecl Lara_State_ClimbRight(ITEM *item, COLL_INFO *coll); void __cdecl Lift_Initialise(int16_t item_num); -void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeTilt1Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl ReadSG(void *pointer, int32_t size); diff --git a/docs/tr2/progress.txt b/docs/tr2/progress.txt index b2ee632ea..e00730eda 100644 --- a/docs/tr2/progress.txt +++ b/docs/tr2/progress.txt @@ -3588,7 +3588,7 @@ typedef enum { 0x00435700 0x0035 + void __cdecl Lift_Initialise(int16_t item_num); 0x00435740 0x00D4 + void __cdecl Lift_Control(int16_t item_num); 0x00435820 0x0179 + void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); -0x004359A0 0x0035 - void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +0x004359A0 0x0035 + void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x004359E0 0x0035 - void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A20 0x0016 -R void __cdecl BridgeFlatFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A40 0x001B -R void __cdecl BridgeFlatCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); diff --git a/src/tr2/game/objects/general/lift.c b/src/tr2/game/objects/general/lift.c index bfcc8aec8..542a47897 100644 --- a/src/tr2/game/objects/general/lift.c +++ b/src/tr2/game/objects/general/lift.c @@ -140,3 +140,15 @@ void __cdecl Lift_FloorCeiling( } } } + +void __cdecl Lift_Floor( + const ITEM *const item, const int32_t x, const int32_t y, const int32_t z, + int32_t *const out_height) +{ + int32_t floor; + int32_t height; + Lift_FloorCeiling(item, x, y, z, &floor, &height); + if (floor < *out_height) { + *out_height = floor; + } +} diff --git a/src/tr2/game/objects/general/lift.h b/src/tr2/game/objects/general/lift.h index 7123a0667..58dec6d36 100644 --- a/src/tr2/game/objects/general/lift.h +++ b/src/tr2/game/objects/general/lift.h @@ -12,3 +12,5 @@ void __cdecl Lift_Control(int16_t item_num); void __cdecl Lift_FloorCeiling( const ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *out_floor, int32_t *out_ceiling); +void __cdecl Lift_Floor( + const ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *out_height); diff --git a/src/tr2/global/funcs.h b/src/tr2/global/funcs.h index 26c7a2f72..3c47bc1f0 100644 --- a/src/tr2/global/funcs.h +++ b/src/tr2/global/funcs.h @@ -121,7 +121,6 @@ #define DrawBridgeFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435650) #define DrawBridgeCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435690) #define DrawBridgeCollision ((void __cdecl (*)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll))0x004356D0) -#define Lift_Floor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359A0) #define Lift_Ceiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359E0) #define BridgeFlatFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435A20) #define BridgeFlatCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435A40) diff --git a/src/tr2/inject_exec.c b/src/tr2/inject_exec.c index c2080fde7..01e5414c9 100644 --- a/src/tr2/inject_exec.c +++ b/src/tr2/inject_exec.c @@ -1020,6 +1020,7 @@ static void M_Objects(const bool enable) INJECT(enable, 0x00435700, Lift_Initialise); INJECT(enable, 0x00435740, Lift_Control); INJECT(enable, 0x00435820, Lift_FloorCeiling); + INJECT(enable, 0x004359A0, Lift_Floor); INJECT(enable, 0x00435D70, Detonator_Control); INJECT(enable, 0x00437E70, Pickup_Collision); INJECT(enable, 0x004382F0, Switch_Collision); From 05dc05eeb1034a862053872b8a83574b4380b40c Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 22 Oct 2024 21:06:12 +0200 Subject: [PATCH 5/5] tr2: port Lift_Ceiling --- docs/tr2/progress.svg | 16 ++++++++-------- docs/tr2/progress.txt | 2 +- src/tr2/game/objects/general/lift.c | 12 ++++++++++++ src/tr2/game/objects/general/lift.h | 2 ++ src/tr2/global/funcs.h | 1 - src/tr2/inject_exec.c | 1 + 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/docs/tr2/progress.svg b/docs/tr2/progress.svg index c94457fdc..5802384ca 100644 --- a/docs/tr2/progress.svg +++ b/docs/tr2/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -67.68% (842) · 29.90% (372) · 0% (0) · 2.41% (30) +67.77% (843) · 29.82% (371) · 0% (0) · 2.41% (30) - - + + @@ -719,7 +719,7 @@ void __cdecl Lift_Control(int16_t item_num); void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); -void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeFlatFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeFlatCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); int32_t __cdecl GetOffset(ITEM *item, int32_t x, int32_t z); @@ -1324,10 +1324,10 @@ Tomb2.exe progress according to the function sizes: -72.90% · 26.78% · 0% · 0.33% +72.91% · 26.76% · 0% · 0.33% - - + + @@ -2271,7 +2271,7 @@ void __cdecl Lara_State_ClimbRight(ITEM *item, COLL_INFO *coll); void __cdecl Lift_Initialise(int16_t item_num); void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); -void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl BridgeTilt1Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); void __cdecl ReadSG(void *pointer, int32_t size); void __cdecl WinVidSetGameWindowSize(int32_t width, int32_t height); diff --git a/docs/tr2/progress.txt b/docs/tr2/progress.txt index e00730eda..35782ea20 100644 --- a/docs/tr2/progress.txt +++ b/docs/tr2/progress.txt @@ -3589,7 +3589,7 @@ typedef enum { 0x00435740 0x00D4 + void __cdecl Lift_Control(int16_t item_num); 0x00435820 0x0179 + void __cdecl Lift_FloorCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *floor, int32_t *ceiling); 0x004359A0 0x0035 + void __cdecl Lift_Floor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); -0x004359E0 0x0035 - void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); +0x004359E0 0x0035 + void __cdecl Lift_Ceiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A20 0x0016 -R void __cdecl BridgeFlatFloor(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A40 0x001B -R void __cdecl BridgeFlatCeiling(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height); 0x00435A60 0x003B -R int32_t __cdecl GetOffset(ITEM *item, int32_t x, int32_t z); diff --git a/src/tr2/game/objects/general/lift.c b/src/tr2/game/objects/general/lift.c index 542a47897..da92646a9 100644 --- a/src/tr2/game/objects/general/lift.c +++ b/src/tr2/game/objects/general/lift.c @@ -152,3 +152,15 @@ void __cdecl Lift_Floor( *out_height = floor; } } + +void __cdecl Lift_Ceiling( + const ITEM *const item, const int32_t x, const int32_t y, const int32_t z, + int32_t *const out_height) +{ + int32_t floor; + int32_t height; + Lift_FloorCeiling(item, x, y, z, &floor, &height); + if (height > *out_height) { + *out_height = height; + } +} diff --git a/src/tr2/game/objects/general/lift.h b/src/tr2/game/objects/general/lift.h index 58dec6d36..9856a2586 100644 --- a/src/tr2/game/objects/general/lift.h +++ b/src/tr2/game/objects/general/lift.h @@ -14,3 +14,5 @@ void __cdecl Lift_FloorCeiling( int32_t *out_ceiling); void __cdecl Lift_Floor( const ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *out_height); +void __cdecl Lift_Ceiling( + const ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *out_height); diff --git a/src/tr2/global/funcs.h b/src/tr2/global/funcs.h index 3c47bc1f0..e4ec8f5d8 100644 --- a/src/tr2/global/funcs.h +++ b/src/tr2/global/funcs.h @@ -121,7 +121,6 @@ #define DrawBridgeFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435650) #define DrawBridgeCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435690) #define DrawBridgeCollision ((void __cdecl (*)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll))0x004356D0) -#define Lift_Ceiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x004359E0) #define BridgeFlatFloor ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435A20) #define BridgeFlatCeiling ((void __cdecl (*)(ITEM *item, int32_t x, int32_t y, int32_t z, int32_t *height))0x00435A40) #define GetOffset ((int32_t __cdecl (*)(ITEM *item, int32_t x, int32_t z))0x00435A60) diff --git a/src/tr2/inject_exec.c b/src/tr2/inject_exec.c index 01e5414c9..76378cf61 100644 --- a/src/tr2/inject_exec.c +++ b/src/tr2/inject_exec.c @@ -1021,6 +1021,7 @@ static void M_Objects(const bool enable) INJECT(enable, 0x00435740, Lift_Control); INJECT(enable, 0x00435820, Lift_FloorCeiling); INJECT(enable, 0x004359A0, Lift_Floor); + INJECT(enable, 0x004359E0, Lift_Ceiling); INJECT(enable, 0x00435D70, Detonator_Control); INJECT(enable, 0x00437E70, Pickup_Collision); INJECT(enable, 0x004382F0, Switch_Collision);