From ec9fb8d159af9f6d73158cf2496583761bcf438c Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 19 Nov 2024 16:39:19 +0100 Subject: [PATCH] tr2: fix regression in DisplayCredits Resolves #1915. --- docs/tr2/CHANGELOG.md | 1 + src/tr2/decomp/decomp.c | 66 ++++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/docs/tr2/CHANGELOG.md b/docs/tr2/CHANGELOG.md index 43d3902f6..7c93150e1 100644 --- a/docs/tr2/CHANGELOG.md +++ b/docs/tr2/CHANGELOG.md @@ -15,6 +15,7 @@ - fixed one of the collapsible tiles in Opera House room 184 not triggering (#1902) - fixed being unable to use the drawbridge key in Tibetan Foothills after the flipmap (#1744) - fixed missing death tiles in Temple of Xian room 91 (#1920) +- fixed broken final stats screen in software rendering mode (#1915, regression from 0.6) ## [0.6](https://github.com/LostArtefacts/TRX/compare/tr2-0.5...tr2-0.6) - 2024-11-06 - added a fly cheat key (#1642) diff --git a/src/tr2/decomp/decomp.c b/src/tr2/decomp/decomp.c index 4cd313131..dc2d1713f 100644 --- a/src/tr2/decomp/decomp.c +++ b/src/tr2/decomp/decomp.c @@ -47,6 +47,7 @@ #define IDI_MAINICON 100 +static void M_DisplayPicture(const char *file_name, bool copy_palette); static bool M_InsertDisplayModeInListSorted( DISPLAY_MODE_LIST *mode_list, DISPLAY_MODE *src_mode); @@ -61,6 +62,34 @@ static DISPLAY_MODE *M_InsertDisplayModeInListHead( static DISPLAY_MODE *M_InsertDisplayModeInListTail( DISPLAY_MODE_LIST *mode_list); +static void M_DisplayPicture( + const char *const file_name, const bool copy_palette) +{ + char *compressed_data = NULL; + size_t compressed_data_size = 0; + if (!File_Load(file_name, &compressed_data, &compressed_data_size)) { + return; + } + + const size_t width = 640; + const size_t height = 480; + uint8_t *pixels = GameBuf_Alloc(width * height, GBUF_LOAD_PICTURE_BUFFER); + DecompPCX( + (uint8_t *)compressed_data, compressed_data_size, pixels, + g_PicturePalette); + Memory_FreePointer(&compressed_data); + if (g_SavedAppSettings.render_mode == RM_SOFTWARE) { + WinVidCopyBitmapToBuffer(g_PictureBufferSurface, pixels); + } else { + BGND_Make640x480(pixels, g_PicturePalette); + } + if (copy_palette) { + CopyBitmapPalette( + g_PicturePalette, pixels, width * height, g_GamePalette8); + } + GameBuf_Free(width * height); +} + static void M_DisplayModeListInit(DISPLAY_MODE_LIST *mode_list) { mode_list->head = NULL; @@ -2832,33 +2861,10 @@ BOOL __cdecl S_InitialiseSystem(void) void __cdecl S_DisplayPicture(const char *const file_name, const BOOL is_title) { - char *compressed_data = NULL; - size_t compressed_data_size = 0; - if (!File_Load(file_name, &compressed_data, &compressed_data_size)) { - return; - } - if (!is_title) { GameBuf_Reset(); } - - const size_t width = 640; - const size_t height = 480; - uint8_t *pixels = GameBuf_Alloc(width * height, GBUF_LOAD_PICTURE_BUFFER); - DecompPCX( - (uint8_t *)compressed_data, compressed_data_size, pixels, - g_PicturePalette); - Memory_FreePointer(&compressed_data); - if (g_SavedAppSettings.render_mode == RM_SOFTWARE) { - WinVidCopyBitmapToBuffer(g_PictureBufferSurface, pixels); - } else { - BGND_Make640x480(pixels, g_PicturePalette); - } - if (!is_title) { - CopyBitmapPalette( - g_PicturePalette, pixels, width * height, g_GamePalette8); - } - GameBuf_Free(width * height); + M_DisplayPicture(file_name, !is_title); } void __cdecl DisplayCredits(void) @@ -2869,19 +2875,19 @@ void __cdecl DisplayCredits(void) return; } + g_IsVidModeLock = true; RGB_888 old_palette[256]; - memcpy(old_palette, g_GamePalette8, sizeof(old_palette)); - memset(g_GamePalette8, 0, sizeof(g_GamePalette8)); + memcpy(old_palette, g_GamePalette8, sizeof(RGB_888) * 256); + memset(g_GamePalette8, 0, sizeof(RGB_888) * 256); Music_Play(MX_SKIDOO_THEME, MPM_ALWAYS); for (int32_t i = 0; i < 9; i++) { char file_name[60]; sprintf(file_name, "data/credit0%d.pcx", i + 1); - g_IsVidModeLock = true; - FadeToPal(0, g_GamePalette8); - S_DisplayPicture(file_name, false); + FadeToPal(0, g_GamePalette8); + M_DisplayPicture(file_name, true); S_InitialisePolyList(0); S_CopyBufferToScreen(); @@ -2903,7 +2909,7 @@ void __cdecl DisplayCredits(void) memcpy(g_GamePalette8, old_palette, sizeof(g_GamePalette8)); S_Wait(300, true); FadeToPal(30, g_GamePalette8); - g_IsVidModeLock = 0; + g_IsVidModeLock = false; } DWORD __cdecl S_DumpScreen(void)