From e0fbe19afbdb46280375c03e0ddf56bc2b1d12a5 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 2 Oct 2023 11:13:31 +0200 Subject: [PATCH] port Camera_Initialise --- docs/progress.svg | 44 +++++++------- docs/progress.txt | 139 ++++++++++++++++++++++++++++++++++++++++++--- meson.build | 1 + src/game/camera.c | 37 ++++++++++++ src/game/camera.h | 5 ++ src/global/const.h | 2 + src/global/funcs.h | 13 ++--- src/global/types.h | 120 ++++++++++++++++++++++++++++++++++++++ src/global/vars.h | 5 ++ src/inject_exec.c | 10 ++++ 10 files changed, 338 insertions(+), 38 deletions(-) create mode 100644 src/game/camera.c create mode 100644 src/game/camera.h diff --git a/docs/progress.svg b/docs/progress.svg index bade4bd0..82da4b19 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -1.17% (14) · 96.42% (1157) · 0.67% (8) · 1.75% (21) +1.25% (15) · 96.33% (1156) · 0.67% (8) · 1.75% (21) - - + + @@ -200,7 +200,7 @@ int32_t __cdecl Creature_Vault(int16_t item_num, int16_t angle, int32_t vault, int32_t shift); void __cdecl Creature_Kill(struct ITEM_INFO *item, int32_t kill_anim, int32_t kill_state, int32_t lara_kill_state); void __cdecl Creature_GetBaddieTarget(int16_t item_num, int32_t goody); -void __cdecl Camera_Initialise(void); +void __cdecl Camera_Initialise(void); void __cdecl Camera_Move(struct GAME_VECTOR *ideal, int32_t speed); void __cdecl Camera_Clip(int32_t *x, int32_t *y, int32_t *h, int32_t target_x, int32_t target_y, int32_t target_h, int32_t left, int32_t top, int32_t right, int32_t bottom); void __cdecl Camera_Shift(int32_t *x, int32_t *y, int32_t *h, int32_t target_x, int32_t target_y, int32_t target_h, int32_t left, int32_t top, int32_t right, int32_t bottom); @@ -1064,8 +1064,8 @@ void __cdecl GetSavedGamesList(REQUEST_INFO *req); void __cdecl DisplayCredits(void); BOOL __cdecl S_FrontEndCheck(void); -BOOL __cdecl S_SaveGame(LPCVOID saveData, DWORD saveSize, int32_t slotNumber); -BOOL __cdecl S_LoadGame(LPVOID saveData, DWORD saveSize, int32_t slotNumber); +int32_t __cdecl S_SaveGame(const void *save_data, uint32_t save_size, int32_t slot_num); +int32_t __cdecl S_LoadGame(void *save_data, uint32_t save_size, int32_t slot_num); void __cdecl HWR_InitState(void); void __cdecl HWR_ResetTexSource(void); void __cdecl HWR_ResetColorKey(void); @@ -1098,7 +1098,7 @@ void __cdecl Shell_Shutdown(void); sub_44E860 sub_44E880 -void __cdecl Shell_ExitSystem(LPCTSTR message); +void __cdecl Shell_ExitSystem(const char *message); void __cdecl ScreenShotPCX(void); DWORD __cdecl CompPCX(BYTE *bitmap, DWORD width, DWORD height, RGB888 *palette, BYTE **pcxData); DWORD __cdecl EncodeLinePCX(BYTE *src, DWORD width, BYTE *dst); @@ -1125,7 +1125,7 @@ int32_t __cdecl S_GetObjectBounds(int16_t *bPtr); void __cdecl S_InsertBackPolygon(int32_t x0, int32_t y0, int32_t x1, int32_t y1); void __cdecl S_PrintShadow(int16_t radius, int16_t *bPtr, ITEM_INFO *item); -void __cdecl S_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t roomNumber); +void __cdecl S_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t room_num); void __cdecl S_CalculateStaticLight(int16_t adder); void __cdecl S_CalculateStaticMeshLight(int32_t x, int32_t y, int32_t z, int32_t shade1, int32_t shade2, ROOM_INFO *room); void __cdecl S_LightRoom(ROOM_INFO *room); @@ -1183,13 +1183,13 @@ void __cdecl SE_AdvancedDlgInit(HWND hwndDlg); HWND __cdecl SE_FindSetupDialog(void); BOOL __cdecl GameMain(void); -__int16 __cdecl TitleSequence(void); +int16_t __cdecl TitleSequence(void); void __cdecl CheckCheatMode(void); void __cdecl S_SaveSettings(void); void __cdecl S_LoadSettings(void); int32_t __cdecl S_SoundPlaySample(int32_t channel, UINT16 volume, int32_t pitch, int32_t pan); int32_t __cdecl S_Sound_CalculateSampleVolume(DWORD volume); -int32_t __cdecl S_Sound_CalculateSamplePan(__int16 pan); +int32_t __cdecl S_Sound_CalculateSamplePan(int16_t pan); int32_t __cdecl S_SoundPlaySampleLooped(int32_t channel, UINT16 volume, DWORD pitch, int32_t pan); void __cdecl S_SoundSetPanAndVolume(int32_t channel, int32_t pan, UINT16 volume); void __cdecl S_SoundSetPitch(int32_t channel, DWORD pitch); @@ -1199,7 +1199,7 @@ BOOL __cdecl S_SoundSampleIsPlaying(int32_t channel); bool __cdecl CD_Init(void); void __cdecl CD_Cleanup(void); -void __cdecl S_CDPlay(__int16 trackID, BOOL isLooped); +void __cdecl S_CDPlay(int16_t trackID, BOOL isLooped); void __cdecl S_CDStop(void); BOOL __cdecl StartSyncedAudio(int32_t trackID); DWORD __cdecl S_CDGetLoc(void); @@ -1281,10 +1281,10 @@ Tomb2.exe progress according to the function sizes: -0.73% · 98.94% · 0.02% · 0.31% +0.78% · 98.89% · 0.02% · 0.31% - - + + @@ -1395,7 +1395,7 @@ void __cdecl Lara_Push(struct ITEM_INFO *item, struct ITEM_INFO *lara_item, struct COLL_INFO *coll, int32_t spaz_on, int32_t big_push); int32_t __cdecl LOS_ObjectOnLOS(struct GAME_VECTOR *start, struct GAME_VECTOR *target); void __fastcall gtmapA(int32_t y0, int32_t y1, BYTE *texPage); -void __cdecl S_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t roomNumber); +void __cdecl S_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t room_num); void __cdecl DragonCollision(int16_t item_num, struct ITEM_INFO *laraitem, struct COLL_INFO *coll); int32_t __cdecl LOS_CheckX(struct GAME_VECTOR *start, struct GAME_VECTOR *target); int32_t __cdecl LOS_CheckZ(struct GAME_VECTOR *start, struct GAME_VECTOR *target); @@ -1618,11 +1618,11 @@ void __cdecl S_DrawScreenBox(int32_t sx, int32_t sy, int32_t z, int32_t width, int32_t height, BYTE colorIdx, GOURAUD_OUTLINE *gour, uint16_t flags); void __cdecl ControlCeilingSpikes(int16_t item_num); void __cdecl InitialiseBartoli(int16_t item_num); -BOOL __cdecl S_SaveGame(LPCVOID saveData, DWORD saveSize, int32_t slotNumber); +int32_t __cdecl S_SaveGame(const void *save_data, uint32_t save_size, int32_t slot_num); int32_t __cdecl GameStats(int32_t levelID); int32_t __cdecl Game_Cutscene_Start(int32_t level_num); int32_t __cdecl Inv_RemoveItem(int32_t itemNum); -__int16 __cdecl TitleSequence(void); +int16_t __cdecl TitleSequence(void); void __cdecl Inv_RingInit(struct RING_INFO *ring, int16_t type, struct INVENTORY_ITEM **list, int16_t qty, int16_t current, struct IMOTION_INFO *imo); void __cdecl ScreenShotPCX(void); bool __cdecl WinSndMakeSample(DWORD sampleIdx, LPWAVEFORMATEX format, const LPVOID data, DWORD dataSize); @@ -1774,7 +1774,7 @@ int32_t __cdecl TestHangSwingIn(struct ITEM_INFO *item, PHD_ANGLE angle); int32_t __cdecl OnDrawBridge(struct ITEM_INFO *item, int32_t x, int32_t y); void __cdecl S_AnimateTextures(int32_t nTicks); -void __cdecl Camera_Initialise(void); +void __cdecl Camera_Initialise(void); bool __cdecl WinVidGetDisplayAdapters(void); void __cdecl ControlWaterSprite(int16_t fx_num); DWORD __cdecl CompPCX(BYTE *bitmap, DWORD width, DWORD height, RGB888 *palette, BYTE **pcxData); @@ -1842,7 +1842,7 @@ void __cdecl lara_col_back( ITEM_INFO *item, COLL_INFO *coll ); void __cdecl HitTarget(struct ITEM_INFO *item, struct GAME_VECTOR *hitpos, int32_t damage); void __cdecl WindowControl(int16_t item_num); -BOOL __cdecl S_LoadGame(LPVOID saveData, DWORD saveSize, int32_t slotNumber); +int32_t __cdecl S_LoadGame(void *save_data, uint32_t save_size, int32_t slot_num); void __cdecl S_ChangeCtrlText(void); void __cdecl Output_SetNearZ(int32_t near_z); void __cdecl Box_TargetBox(struct LOT_INFO *lot, int16_t box_num); @@ -1958,7 +1958,7 @@ void __cdecl CreatePictureBuffer(void); int32_t __cdecl Box_UpdateLOT(struct LOT_INFO *lot, int32_t expansion); void __cdecl RemoveDrawnItem(int16_t item_num); -void __cdecl S_CDPlay(__int16 trackID, BOOL isLooped); +void __cdecl S_CDPlay(int16_t trackID, BOOL isLooped); BOOL __cdecl UT_CenterWindow(HWND hWnd); void __cdecl UT_MemBlt(BYTE *dstBuf, DWORD dstX, DWORD dstY, DWORD width, DWORD height, DWORD dstPitch, BYTE *srcBuf, DWORD srcX, DWORD srcY, DWORD srcPitch); bool __cdecl Output_VisibleZClip(struct PHD_VBUF *vtx0, struct PHD_VBUF *vtx1, struct PHD_VBUF *vtx2); @@ -2158,7 +2158,7 @@ void __cdecl ControlCutShotgun(int16_t item_num); void __cdecl InitialiseRollingBall(int16_t item_num); int32_t __cdecl RenderErrorBox(int32_t errorCode); -void __cdecl Shell_ExitSystem(LPCTSTR message); +void __cdecl Shell_ExitSystem(const char *message); void __cdecl S_SoundStopAllSamples(void); int32_t __cdecl CheckForHoldingState(int32_t state); int32_t __cdecl WeaponObject(int32_t weapon_type); @@ -2306,7 +2306,7 @@ void __cdecl Inv_RingMotionRadius(struct RING_INFO *ring, int16_t target); LPCTSTR __cdecl GetFullPath(LPCTSTR fileName); void __cdecl ScreenClear(bool isPhdWinSize); -int32_t __cdecl S_Sound_CalculateSamplePan(__int16 pan); +int32_t __cdecl S_Sound_CalculateSamplePan(int16_t pan); void __cdecl FreeTexturePages(void); void __cdecl SE_PassMessageToImage(HWND hWnd, UINT uMsg, WPARAM wParam); void __cdecl Inv_RingMotionCameraPos(struct RING_INFO *ring, int16_t target); diff --git a/docs/progress.txt b/docs/progress.txt index 44796c18..54444c46 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -705,6 +705,122 @@ typedef struct CREATURE_INFO { struct ITEM_INFO *enemy; } CREATURE_INFO; +typedef enum CAMERA_TYPE { + CAM_CHASE = 0, + CAM_FIXED = 1, + CAM_LOOK = 2, + CAM_COMBAT = 3, + CAM_CINEMATIC = 4, + CAM_HEAVY = 5, +} CAMERA_TYPE; + +typedef struct GAME_VECTOR { + int32_t x; + int32_t y; + int32_t z; + int16_t room_num; + int16_t box_num; +} GAME_VECTOR; + +typedef struct __unaligned CAMERA_INFO { + struct GAME_VECTOR pos; + struct GAME_VECTOR target; + enum CAMERA_TYPE type; + int32_t shift; + uint32_t flags; + int32_t fixed_camera; + int32_t num_frames; + int32_t bounce; + int32_t underwater; + int32_t target_distance; + int32_t target_square; + int16_t target_angle; + int16_t actual_angle; + int16_t target_elevation; + int16_t box; + int16_t num; + int16_t last; + int16_t timer; + int16_t speed; + struct ITEM_INFO *item; + struct ITEM_INFO *last_item; + struct OBJECT_VECTOR *fixed; + bool is_lara_mic; + struct PHD_VECTOR mic_pos; +} CAMERA_INFO; + +typedef struct __unaligned LARA_ARM { + int16_t *frame_base; + int16_t frame_num; + int16_t anim_num; + int16_t lock; + int16_t y_rot; + int16_t x_rot; + int16_t z_rot; + int16_t flash_gun; +} LARA_ARM; + +typedef struct __unaligned AMMO_INFO { + int32_t ammo; +} AMMO_INFO; + +typedef struct __unaligned LARA_INFO { + int16_t item_num; + int16_t gun_status; + int16_t gun_type; + int16_t request_gun_type; + int16_t last_gun_type; + int16_t calc_fallspeed; + int16_t water_status; + int16_t climb_status; + int16_t pose_count; + int16_t hit_frame; + int16_t hit_direction; + int16_t air; + int16_t dive_count; + int16_t death_count; + int16_t current_active; + int16_t spaz_effect_count; + int16_t flare_age; + int16_t skidoo; + int16_t weapon_item; + int16_t back_gun; + int16_t flare_frame; + uint16_t flare_control_left : 1; + uint16_t flare_control_right : 1; + uint16_t extra_anim : 1; + uint16_t look : 1; + uint16_t burn : 1; + uint16_t keep_ducked : 1; + uint16_t can_monkey_swing : 1; + uint16_t pad : 9; + int32_t water_surface_dist; + struct PHD_VECTOR last_pos; + struct FX_INFO *spaz_effect; + uint32_t mesh_effects; + int16_t *mesh_ptrs[15]; + struct ITEM_INFO *target; + int16_t target_angles[2]; + int16_t turn_rate; + int16_t move_angle; + int16_t head_y_rot; + int16_t head_x_rot; + int16_t head_z_rot; + int16_t torso_y_rot; + int16_t torso_x_rot; + int16_t torso_z_rot; + struct LARA_ARM left_arm; + struct LARA_ARM right_arm; + struct AMMO_INFO pistol_ammo; + struct AMMO_INFO magnum_ammo; + struct AMMO_INFO uzi_ammo; + struct AMMO_INFO shotgun_ammo; + struct AMMO_INFO harpoon_ammo; + struct AMMO_INFO grenade_ammo; + struct AMMO_INFO m16_ammo; + struct CREATURE_INFO *creature; +} LARA_INFO; + # FUNCTIONS # Flags: # - to do @@ -737,7 +853,7 @@ typedef struct CREATURE_INFO { 00402430 00000033 - void __cdecl Output_SortPolyList(void); 00402470 000000C5 - void __cdecl Output_QuickSort(int32_t left, int32_t right); 00402540 00000036 - void __cdecl Output_PrintPolyList(uint8_t *surface_ptr); -00402580 000000A1 - void __cdecl Viewport_AlterFOV(int16_t fov); +00402580 000000A1 * void __cdecl Viewport_AlterFOV(int16_t fov); 00402690 00000095 - void __cdecl Output_SetNearZ(int32_t near_z); 004026E0 0000006B - void __cdecl Output_SetFarZ(int32_t far_z); 00402700 00000266 - void __cdecl Viewport_Init(int16_t x, int16_t y, int32_t width, int32_t height, int32_t near_z, int32_t far_z, int16_t view_angle, int32_t screen_width, int32_t screen_height); @@ -851,7 +967,7 @@ typedef struct CREATURE_INFO { 004103C0 000001DB - void __cdecl Creature_GetBaddieTarget(int16_t item_num, int32_t goody); # game/camera.c -004105A0 000000B0 - void __cdecl Camera_Initialise(void); +004105A0 000000B0 + void __cdecl Camera_Initialise(void); 00410650 00000372 - void __cdecl Camera_Move(struct GAME_VECTOR *ideal, int32_t speed); 004109D0 000000D7 - void __cdecl Camera_Clip(int32_t *x, int32_t *y, int32_t *h, int32_t target_x, int32_t target_y, int32_t target_h, int32_t left, int32_t top, int32_t right, int32_t bottom); 00410AB0 00000154 - void __cdecl Camera_Shift(int32_t *x, int32_t *y, int32_t *h, int32_t target_x, int32_t target_y, int32_t target_h, int32_t left, int32_t top, int32_t right, int32_t bottom); @@ -862,7 +978,7 @@ typedef struct CREATURE_INFO { 00411680 0000018E - void __cdecl Camera_Combat(struct ITEM_INFO *item); 00411810 000001E2 - void __cdecl Camera_Look(struct ITEM_INFO *item); 00411A00 00000099 - void __cdecl Camera_Fixed(void); -00411AA0 000004A9 - void __cdecl Camera_Update(void); +00411AA0 000004A9 * void __cdecl Camera_Update(void); 00411F50 0000000A - void __cdecl Camera_SetCutsceneTrack(int32_t track); 00411F60 00000112 - int32_t __cdecl Game_Cutscene_Start(int32_t level_num); 00412080 00000093 -R void __cdecl Misc_InitCinematicRooms(void); @@ -1802,8 +1918,8 @@ typedef struct CREATURE_INFO { 0044CA20 0000004C -R void __cdecl GetSavedGamesList(REQUEST_INFO *req); 0044CA70 00000233 -R void __cdecl DisplayCredits(void); 0044CCB0 00000165 -R BOOL __cdecl S_FrontEndCheck(void); -0044CE20 00000114 -R BOOL __cdecl S_SaveGame(LPCVOID saveData, DWORD saveSize, int32_t slotNumber); -0044CF40 00000096 -R BOOL __cdecl S_LoadGame(LPVOID saveData, DWORD saveSize, int32_t slotNumber); +0044CE20 00000114 -R int32_t __cdecl S_SaveGame(const void *save_data, uint32_t save_size, int32_t slot_num); +0044CF40 00000096 -R int32_t __cdecl S_LoadGame(void *save_data, uint32_t save_size, int32_t slot_num); 0044CFE0 00000128 -R void __cdecl HWR_InitState(void); 0044D110 00000029 -R void __cdecl HWR_ResetTexSource(void); 0044D140 0000002B -R void __cdecl HWR_ResetColorKey(void); @@ -1863,7 +1979,7 @@ typedef struct CREATURE_INFO { 00450CC0 00000270 -R int32_t __cdecl S_GetObjectBounds(int16_t *bPtr); 00450F30 00000046 -R void __cdecl S_InsertBackPolygon(int32_t x0, int32_t y0, int32_t x1, int32_t y1); 00450F80 000001F1 -R void __cdecl S_PrintShadow(int16_t radius, int16_t *bPtr, ITEM_INFO *item); -00451180 000002F6 -R void __cdecl S_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t roomNumber); +00451180 000002F6 -R void __cdecl S_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t room_num); 00451480 00000031 -R void __cdecl S_CalculateStaticLight(int16_t adder); 004514C0 00000124 -R void __cdecl S_CalculateStaticMeshLight(int32_t x, int32_t y, int32_t z, int32_t shade1, int32_t shade2, ROOM_INFO *room); 004515F0 00000206 -R void __cdecl S_LightRoom(ROOM_INFO *room); @@ -1921,13 +2037,13 @@ typedef struct CREATURE_INFO { 00454950 0000000E -R void __cdecl SE_AdvancedDlgInit(HWND hwndDlg); 00454960 00000011 -R HWND __cdecl SE_FindSetupDialog(void); 00454980 000002D0 -R BOOL __cdecl GameMain(void); -00454C50 00000110 -R __int16 __cdecl TitleSequence(void); +00454C50 00000110 -R int16_t __cdecl TitleSequence(void); 00454D60 0000032D -R void __cdecl CheckCheatMode(void); 004550C0 0000007D -R void __cdecl S_SaveSettings(void); 00455140 000000DB -R void __cdecl S_LoadSettings(void); 00455220 00000046 -R int32_t __cdecl S_SoundPlaySample(int32_t channel, UINT16 volume, int32_t pitch, int32_t pan); 00455270 0000002A -R int32_t __cdecl S_Sound_CalculateSampleVolume(DWORD volume); -004552A0 00000026 -R int32_t __cdecl S_Sound_CalculateSamplePan(__int16 pan); +004552A0 00000026 -R int32_t __cdecl S_Sound_CalculateSamplePan(int16_t pan); 004552D0 00000046 -R int32_t __cdecl S_SoundPlaySampleLooped(int32_t channel, UINT16 volume, DWORD pitch, int32_t pan); 00455320 00000039 -R void __cdecl S_SoundSetPanAndVolume(int32_t channel, int32_t pan, UINT16 volume); 00455360 0000001C -R void __cdecl S_SoundSetPitch(int32_t channel, DWORD pitch); @@ -1937,7 +2053,7 @@ typedef struct CREATURE_INFO { 004553C0 0000001F -R BOOL __cdecl S_SoundSampleIsPlaying(int32_t channel); 004553E0 00000077 -R bool __cdecl CD_Init(void); 00455460 00000051 -R void __cdecl CD_Cleanup(void); -00455500 0000006F -R void __cdecl S_CDPlay(__int16 trackID, BOOL isLooped); +00455500 0000006F -R void __cdecl S_CDPlay(int16_t trackID, BOOL isLooped); 00455570 00000039 -R void __cdecl S_CDStop(void); 004555B0 00000084 -R BOOL __cdecl StartSyncedAudio(int32_t trackID); 00455640 00000061 -R DWORD __cdecl S_CDGetLoc(void); @@ -2050,5 +2166,10 @@ typedef struct CREATURE_INFO { 004BF3E0 - struct PHD_VBUF g_PhdVBuf[1500]; 004D6B60 - float g_FltWinRight; 004D6BF8 - int32_t g_PhdWinRight; +004D778C - int32_t g_IsChunkyCamera; 0051BD20 - char g_ErrorMessage[128]; +005206E0 - struct LARA_INFO g_Lara; +005207BC - struct ITEM_INFO *g_LaraItem; 005262F0 - struct ITEM_INFO g_Items[]; +00526320 - struct CAMERA_INFO g_Camera; +005263CC - struct BOX_INFO *g_Boxes; diff --git a/meson.build b/meson.build index d2cc7cf0..4db536c8 100644 --- a/meson.build +++ b/meson.build @@ -74,6 +74,7 @@ exe_sources = [ dll_sources = [ 'src/filesystem.c', + 'src/game/camera.c', 'src/game/math.c', 'src/game/matrix.c', 'src/game/shell.c', diff --git a/src/game/camera.c b/src/game/camera.c new file mode 100644 index 00000000..6d2772dd --- /dev/null +++ b/src/game/camera.c @@ -0,0 +1,37 @@ +#include "game/camera.h" + +#include "global/const.h" +#include "global/funcs.h" +#include "global/vars.h" + +void __cdecl Camera_Initialise(void) +{ + g_Camera.shift = g_LaraItem->pos.y - WALL_L; + + g_Camera.target.x = g_LaraItem->pos.x; + g_Camera.target.y = g_Camera.shift; + g_Camera.target.z = g_LaraItem->pos.z; + g_Camera.target.room_num = g_LaraItem->room_num; + + g_Camera.pos.x = g_Camera.target.x; + g_Camera.pos.y = g_Camera.shift; + g_Camera.pos.z = g_Camera.target.z - 100; + g_Camera.pos.room_num = g_LaraItem->room_num; + + g_Camera.target_distance = WALL_L * 3 / 2; + g_Camera.item = NULL; + + g_Camera.num_frames = 1; + if (!g_Lara.extra_anim) { + g_Camera.type = CAM_CHASE; + } + + g_Camera.speed = 1; + g_Camera.flags = 0; + g_Camera.bounce = 0; + g_Camera.num = -1; + g_Camera.fixed_camera = 0; + + Viewport_AlterFOV(GAME_FOV * PHD_DEGREE); + Camera_Update(); +} diff --git a/src/game/camera.h b/src/game/camera.h new file mode 100644 index 00000000..437b0bdc --- /dev/null +++ b/src/game/camera.h @@ -0,0 +1,5 @@ +#pragma once + +#include "global/types.h" + +void __cdecl Camera_Initialise(void); diff --git a/src/global/const.h b/src/global/const.h index 6bd9f158..f08e9a65 100644 --- a/src/global/const.h +++ b/src/global/const.h @@ -7,3 +7,5 @@ #define PHD_135 (PHD_45 * 3) // = 24576 = 0x6000 #define W2V_MATRIX 14 +#define WALL_L 1024 +#define GAME_FOV 80 diff --git a/src/global/funcs.h b/src/global/funcs.h index d2e139ad..ecab364b 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -117,7 +117,6 @@ #define Creature_Vault ((int32_t __cdecl (*)(int16_t item_num, int16_t angle, int32_t vault, int32_t shift))0x00410110) #define Creature_Kill ((void __cdecl (*)(struct ITEM_INFO *item, int32_t kill_anim, int32_t kill_state, int32_t lara_kill_state))0x00410250) #define Creature_GetBaddieTarget ((void __cdecl (*)(int16_t item_num, int32_t goody))0x004103C0) -#define Camera_Initialise ((void __cdecl (*)(void))0x004105A0) #define Camera_Move ((void __cdecl (*)(struct GAME_VECTOR *ideal, int32_t speed))0x00410650) #define Camera_Clip ((void __cdecl (*)(int32_t *x, int32_t *y, int32_t *h, int32_t target_x, int32_t target_y, int32_t target_h, int32_t left, int32_t top, int32_t right, int32_t bottom))0x004109D0) #define Camera_Shift ((void __cdecl (*)(int32_t *x, int32_t *y, int32_t *h, int32_t target_x, int32_t target_y, int32_t target_h, int32_t left, int32_t top, int32_t right, int32_t bottom))0x00410AB0) @@ -955,8 +954,8 @@ #define GetSavedGamesList ((void __cdecl (*)(REQUEST_INFO *req))0x0044CA20) #define DisplayCredits ((void __cdecl (*)(void))0x0044CA70) #define S_FrontEndCheck ((BOOL __cdecl (*)(void))0x0044CCB0) -#define S_SaveGame ((BOOL __cdecl (*)(LPCVOID saveData, DWORD saveSize, int32_t slotNumber))0x0044CE20) -#define S_LoadGame ((BOOL __cdecl (*)(LPVOID saveData, DWORD saveSize, int32_t slotNumber))0x0044CF40) +#define S_SaveGame ((int32_t __cdecl (*)(const void *save_data, uint32_t save_size, int32_t slot_num))0x0044CE20) +#define S_LoadGame ((int32_t __cdecl (*)(void *save_data, uint32_t save_size, int32_t slot_num))0x0044CF40) #define HWR_InitState ((void __cdecl (*)(void))0x0044CFE0) #define HWR_ResetTexSource ((void __cdecl (*)(void))0x0044D110) #define HWR_ResetColorKey ((void __cdecl (*)(void))0x0044D140) @@ -1012,7 +1011,7 @@ #define S_GetObjectBounds ((int32_t __cdecl (*)(int16_t *bPtr))0x00450CC0) #define S_InsertBackPolygon ((void __cdecl (*)(int32_t x0, int32_t y0, int32_t x1, int32_t y1))0x00450F30) #define S_PrintShadow ((void __cdecl (*)(int16_t radius, int16_t *bPtr, ITEM_INFO *item))0x00450F80) -#define S_CalculateLight ((void __cdecl (*)(int32_t x, int32_t y, int32_t z, int16_t roomNumber))0x00451180) +#define S_CalculateLight ((void __cdecl (*)(int32_t x, int32_t y, int32_t z, int16_t room_num))0x00451180) #define S_CalculateStaticLight ((void __cdecl (*)(int16_t adder))0x00451480) #define S_CalculateStaticMeshLight ((void __cdecl (*)(int32_t x, int32_t y, int32_t z, int32_t shade1, int32_t shade2, ROOM_INFO *room))0x004514C0) #define S_LightRoom ((void __cdecl (*)(ROOM_INFO *room))0x004515F0) @@ -1068,13 +1067,13 @@ #define SE_AdvancedDlgInit ((void __cdecl (*)(HWND hwndDlg))0x00454950) #define SE_FindSetupDialog ((HWND __cdecl (*)(void))0x00454960) #define GameMain ((BOOL __cdecl (*)(void))0x00454980) -#define TitleSequence ((__int16 __cdecl (*)(void))0x00454C50) +#define TitleSequence ((int16_t __cdecl (*)(void))0x00454C50) #define CheckCheatMode ((void __cdecl (*)(void))0x00454D60) #define S_SaveSettings ((void __cdecl (*)(void))0x004550C0) #define S_LoadSettings ((void __cdecl (*)(void))0x00455140) #define S_SoundPlaySample ((int32_t __cdecl (*)(int32_t channel, UINT16 volume, int32_t pitch, int32_t pan))0x00455220) #define S_Sound_CalculateSampleVolume ((int32_t __cdecl (*)(DWORD volume))0x00455270) -#define S_Sound_CalculateSamplePan ((int32_t __cdecl (*)(__int16 pan))0x004552A0) +#define S_Sound_CalculateSamplePan ((int32_t __cdecl (*)(int16_t pan))0x004552A0) #define S_SoundPlaySampleLooped ((int32_t __cdecl (*)(int32_t channel, UINT16 volume, DWORD pitch, int32_t pan))0x004552D0) #define S_SoundSetPanAndVolume ((void __cdecl (*)(int32_t channel, int32_t pan, UINT16 volume))0x00455320) #define S_SoundSetPitch ((void __cdecl (*)(int32_t channel, DWORD pitch))0x00455360) @@ -1084,7 +1083,7 @@ #define S_SoundSampleIsPlaying ((BOOL __cdecl (*)(int32_t channel))0x004553C0) #define CD_Init ((bool __cdecl (*)(void))0x004553E0) #define CD_Cleanup ((void __cdecl (*)(void))0x00455460) -#define S_CDPlay ((void __cdecl (*)(__int16 trackID, BOOL isLooped))0x00455500) +#define S_CDPlay ((void __cdecl (*)(int16_t trackID, BOOL isLooped))0x00455500) #define S_CDStop ((void __cdecl (*)(void))0x00455570) #define StartSyncedAudio ((BOOL __cdecl (*)(int32_t trackID))0x004555B0) #define S_CDGetLoc ((DWORD __cdecl (*)(void))0x00455640) diff --git a/src/global/types.h b/src/global/types.h index abad1ee9..5a193a66 100644 --- a/src/global/types.h +++ b/src/global/types.h @@ -7,6 +7,8 @@ #include #include +#pragma pack(push, 1) + typedef DDSURFACEDESC DDSDESC, *LPDDSDESC; typedef LPDIRECTDRAWSURFACE3 LPDDS; typedef D3DTEXTUREHANDLE HWR_TEXHANDLE; @@ -710,3 +712,121 @@ typedef struct CREATURE_INFO { struct PHD_VECTOR target; struct ITEM_INFO *enemy; } CREATURE_INFO; + +typedef enum CAMERA_TYPE { + CAM_CHASE = 0, + CAM_FIXED = 1, + CAM_LOOK = 2, + CAM_COMBAT = 3, + CAM_CINEMATIC = 4, + CAM_HEAVY = 5, +} CAMERA_TYPE; + +typedef struct GAME_VECTOR { + int32_t x; + int32_t y; + int32_t z; + int16_t room_num; + int16_t box_num; +} GAME_VECTOR; + +typedef struct CAMERA_INFO { + struct GAME_VECTOR pos; + struct GAME_VECTOR target; + enum CAMERA_TYPE type; + int32_t shift; + uint32_t flags; + int32_t fixed_camera; + int32_t num_frames; + int32_t bounce; + int32_t underwater; + int32_t target_distance; + int32_t target_square; + int16_t target_angle; + int16_t actual_angle; + int16_t target_elevation; + int16_t box; + int16_t num; + int16_t last; + int16_t timer; + int16_t speed; + struct ITEM_INFO *item; + struct ITEM_INFO *last_item; + struct OBJECT_VECTOR *fixed; + bool is_lara_mic; + struct PHD_VECTOR mic_pos; +} CAMERA_INFO; + +typedef struct LARA_ARM { + int16_t *frame_base; + int16_t frame_num; + int16_t anim_num; + int16_t lock; + int16_t y_rot; + int16_t x_rot; + int16_t z_rot; + int16_t flash_gun; +} LARA_ARM; + +typedef struct AMMO_INFO { + int32_t ammo; +} AMMO_INFO; + +typedef struct LARA_INFO { + int16_t item_num; + int16_t gun_status; + int16_t gun_type; + int16_t request_gun_type; + int16_t last_gun_type; + int16_t calc_fallspeed; + int16_t water_status; + int16_t climb_status; + int16_t pose_count; + int16_t hit_frame; + int16_t hit_direction; + int16_t air; + int16_t dive_count; + int16_t death_count; + int16_t current_active; + int16_t spaz_effect_count; + int16_t flare_age; + int16_t skidoo; + int16_t weapon_item; + int16_t back_gun; + int16_t flare_frame; + uint16_t flare_control_left : 1; + uint16_t flare_control_right : 1; + uint16_t extra_anim : 1; + uint16_t look : 1; + uint16_t burn : 1; + uint16_t keep_ducked : 1; + uint16_t can_monkey_swing : 1; + uint16_t pad : 9; + int32_t water_surface_dist; + struct PHD_VECTOR last_pos; + struct FX_INFO *spaz_effect; + uint32_t mesh_effects; + int16_t *mesh_ptrs[15]; + struct ITEM_INFO *target; + int16_t target_angles[2]; + int16_t turn_rate; + int16_t move_angle; + int16_t head_y_rot; + int16_t head_x_rot; + int16_t head_z_rot; + int16_t torso_y_rot; + int16_t torso_x_rot; + int16_t torso_z_rot; + struct LARA_ARM left_arm; + struct LARA_ARM right_arm; + struct AMMO_INFO pistol_ammo; + struct AMMO_INFO magnum_ammo; + struct AMMO_INFO uzi_ammo; + struct AMMO_INFO shotgun_ammo; + struct AMMO_INFO harpoon_ammo; + struct AMMO_INFO grenade_ammo; + struct AMMO_INFO m16_ammo; + struct CREATURE_INFO *creature; +} LARA_INFO; + +#pragma pack(pop) diff --git a/src/global/vars.h b/src/global/vars.h index 74006d1f..e350385c 100644 --- a/src/global/vars.h +++ b/src/global/vars.h @@ -31,6 +31,11 @@ #define g_PhdVBuf ARRAY_(0x004BF3E0, struct PHD_VBUF, [1500]) #define g_FltWinRight VAR_U_(0x004D6B60, float) #define g_PhdWinRight VAR_U_(0x004D6BF8, int32_t) +#define g_IsChunkyCamera VAR_U_(0x004D778C, int32_t) #define g_ErrorMessage ARRAY_(0x0051BD20, char, [128]) +#define g_Lara VAR_U_(0x005206E0, struct LARA_INFO) +#define g_LaraItem VAR_U_(0x005207BC, struct ITEM_INFO *) #define g_Items ARRAY_(0x005262F0, struct ITEM_INFO, []) +#define g_Camera VAR_U_(0x00526320, struct CAMERA_INFO) +#define g_Boxes VAR_U_(0x005263CC, struct BOX_INFO *) // clang-format on \ No newline at end of file diff --git a/src/inject_exec.c b/src/inject_exec.c index e79e79f7..b2c5c761 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -1,11 +1,20 @@ #include "inject_exec.h" +#include "game/camera.h" #include "game/math.h" #include "game/matrix.h" #include "game/shell.h" #include "inject_util.h" +static void Inject_Camera(void); +static void Inject_Math(void); static void Inject_Matrix(void); +static void Inject_Shell(void); + +static void Inject_Camera(void) +{ + INJECT(0x004105A0, Camera_Initialise); +} static void Inject_Matrix(void) { @@ -34,6 +43,7 @@ static void Inject_Shell(void) void Inject_Exec(void) { + Inject_Camera(); Inject_Matrix(); Inject_Math(); Inject_Shell();