From 29cd430b174b9de3a32b8091f8dece2362d94075 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 17 Feb 2022 10:20:56 +0800 Subject: [PATCH] Moved 24-bit BMP code refs to HRP\Image.cpp Minor edits to code/documents. Updated version number. --- artifacts/ddraw.ini | 2 +- artifacts/scripting/hooks.yml | 2 +- artifacts/scripting/hookscripts.md | 2 +- sfall/HRP/Image.cpp | 59 ++++++++++++++++++ sfall/Modules/Graphics.cpp | 73 ++--------------------- sfall/Modules/Scripting/Handlers/Misc.cpp | 2 +- sfall/Modules/Scripting/Handlers/Misc.h | 2 +- sfall/version.h | 4 +- 8 files changed, 72 insertions(+), 74 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 143f89d3..7e16365f 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -1,5 +1,5 @@ ;sfall configuration settings -;v4.3.3 +;v4.3.3.1 [Main] ;Set to 1 to enable the built-in High Resolution Patch mode that is similar to the hi-res patch by Mash diff --git a/artifacts/scripting/hooks.yml b/artifacts/scripting/hooks.yml index 76eb2616..fdf309c1 100644 --- a/artifacts/scripting/hooks.yml +++ b/artifacts/scripting/hooks.yml @@ -83,7 +83,7 @@ Does not run for critters in the knockdown/out state. ``` - Item arg0 - The pid of the weapon performing the attack. (May be -1 if the attack is unarmed) + int arg0 - The pid of the weapon performing the attack. (May be -1 if the attack is unarmed) Critter arg1 - The attacker Critter arg2 - The target int arg3 - The amount of damage diff --git a/artifacts/scripting/hookscripts.md b/artifacts/scripting/hookscripts.md index 564efb72..ae79b317 100644 --- a/artifacts/scripting/hookscripts.md +++ b/artifacts/scripting/hookscripts.md @@ -167,7 +167,7 @@ When using `critter_dmg` function, this script will also run. In that case weapo Does not run for critters in the knockdown/out state. ``` -Item arg0 - The pid of the weapon performing the attack. (May be -1 if the attack is unarmed) +int arg0 - The pid of the weapon performing the attack. (May be -1 if the attack is unarmed) Critter arg1 - The attacker Critter arg2 - The target int arg3 - The amount of damage diff --git a/sfall/HRP/Image.cpp b/sfall/HRP/Image.cpp index 43232db3..ffc2a038 100644 --- a/sfall/HRP/Image.cpp +++ b/sfall/HRP/Image.cpp @@ -156,4 +156,63 @@ void Image::ScaleText(BYTE* dstSurf, const char* text, long txtWidth, long dstWi } } +#pragma pack(push, 1) +struct BMPHEADER { + BITMAPFILEHEADER bFile; + BITMAPINFOHEADER bInfo; +}; +#pragma pack(pop) + +/* BMP 24-bit +bool MakeBMP(const char* file, BYTE* dataRGB32, long width, long height, long pitch) { + long bmpExtraSize = width * 3 % 4; + if (bmpExtraSize != 0) bmpExtraSize = 4 - bmpExtraSize; + + DWORD sizeImage = width * height * 3; + sizeImage += height * bmpExtraSize; + + BMPHEADER bmpHeader; + std::memset(&bmpHeader, 0, sizeof(BMPHEADER)); + + bmpHeader.bFile.bfType = 'BM'; + bmpHeader.bFile.bfSize = sizeImage + sizeof(BMPHEADER); + bmpHeader.bFile.bfOffBits = sizeof(BMPHEADER); + bmpHeader.bInfo.biSize = sizeof(BITMAPINFOHEADER); + bmpHeader.bInfo.biWidth = width; + bmpHeader.bInfo.biHeight = 0 - height; + bmpHeader.bInfo.biPlanes = 1; + bmpHeader.bInfo.biBitCount = 24; + bmpHeader.bInfo.biCompression = BI_RGB; + bmpHeader.bInfo.biSizeImage = sizeImage; + + BYTE* bmpImageData = new BYTE[sizeImage]; + BYTE* dData = bmpImageData; + + // 32-bit to 24-bit + for (size_t h = 0; h < height; h++) { + BYTE* sData = dataRGB32; + for (size_t w = 0; w < width; w++) { + *dData++ = *sData++; + *dData++ = *sData++; + *dData++ = *sData++; + sData++; + } + dataRGB32 += pitch; + dData += bmpExtraSize; + } + + HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); + bool result = (hFile != INVALID_HANDLE_VALUE); + + if (result) { + DWORD dwWritten; + WriteFile(hFile, &bmpHeader, sizeof(BMPHEADER), &dwWritten, 0); + WriteFile(hFile, bmpImageData, sizeImage, &dwWritten, 0); + CloseHandle(hFile); + } + delete[] bmpImageData; + + return result; +}*/ + } diff --git a/sfall/Modules/Graphics.cpp b/sfall/Modules/Graphics.cpp index 8a6bcb32..ecf42161 100644 --- a/sfall/Modules/Graphics.cpp +++ b/sfall/Modules/Graphics.cpp @@ -188,11 +188,12 @@ static void ResetDevice(bool create) { static D3DFORMAT textureFormat = D3DFMT_X8R8G8B8; if (create) { - DWORD mThreadFlags = (dShowMovies) ? D3DCREATE_MULTITHREADED : 0; + DWORD deviceFlags = D3DCREATE_FPU_PRESERVE; + if (dShowMovies) deviceFlags |= D3DCREATE_MULTITHREADED; dlog("Creating D3D9 Device...", DL_MAIN); - if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | mThreadFlags, ¶ms, &d3d9Device))) { // D3DCREATE_PUREDEVICE - if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | mThreadFlags, ¶ms, &d3d9Device))) { + if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING | deviceFlags, ¶ms, &d3d9Device))) { // D3DCREATE_PUREDEVICE + if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | deviceFlags, ¶ms, &d3d9Device))) { d3d9Device = nullptr; dlogr(" Failed!", DL_MAIN); return; @@ -206,7 +207,7 @@ static void ResetDevice(bool create) { ShaderVersion = ((caps.PixelShaderVersion & 0x0000FF00) >> 8) * 10 + (caps.PixelShaderVersion & 0xFF); bool npow2 = ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) != 0); //(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) - if (npow2) dlogr("Warning: The graphics card does not support non-power-of-two textures.", DL_MAIN); + if (npow2) dlog("Warning: The graphics card does not support non-power-of-two textures.", DL_MAIN); // Use: 0 - only CPU, 1 - force GPU, 2 - Auto Mode (GPU or switch to CPU) if (Graphics::GPUBlt == 2 && ShaderVersion < 20) Graphics::GPUBlt = 0; @@ -1013,7 +1014,7 @@ public: HRESULT __stdcall RestoreDisplayMode() { // called from GNW95_reset_mode_ #ifdef NDEBUG - ShowWindow(window, SW_HIDE); + if (!Graphics::IsWindowedMode) ShowWindow(window, SW_HIDE); #endif return DD_OK; } @@ -1193,13 +1194,6 @@ void Graphics::BackgroundClearColor(long indxColor) { } } -//#pragma pack(push, 1) -//struct BMPHEADER { -// BITMAPFILEHEADER bFile; -// BITMAPINFOHEADER bInfo; -//}; -//#pragma pack(pop) - long __stdcall SaveScreen(const char* file) { IDirect3DSurface9* surface; d3d9Device->CreateOffscreenPlainSurface(gWidth, gHeight, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, 0); @@ -1222,61 +1216,6 @@ long __stdcall SaveScreen(const char* file) { surface->Release(); buffer->Release(); - /* BMP 24-bit - long bmpExtraSize = gWidth * 3 % 4; - if (bmpExtraSize != 0) bmpExtraSize = 4 - bmpExtraSize; - - DWORD sizeImage = gWidth * gHeight * 3; - sizeImage += gHeight * bmpExtraSize; - - BMPHEADER bmpHeader; - std::memset(&bmpHeader, 0, sizeof(BMPHEADER)); - - bmpHeader.bFile.bfType = 'BM'; - bmpHeader.bFile.bfSize = sizeImage + sizeof(BMPHEADER); - bmpHeader.bFile.bfOffBits = sizeof(BMPHEADER); - bmpHeader.bInfo.biSize = sizeof(BITMAPINFOHEADER); - bmpHeader.bInfo.biWidth = gWidth; - bmpHeader.bInfo.biHeight = 0 - gHeight; - bmpHeader.bInfo.biPlanes = 1; - bmpHeader.bInfo.biBitCount = 24; - bmpHeader.bInfo.biCompression = BI_RGB; - bmpHeader.bInfo.biSizeImage = sizeImage; - - BYTE* bmpImageData = new BYTE[sizeImage]; - BYTE* dData = bmpImageData; - - D3DLOCKED_RECT lockRect; - surface->LockRect(&lockRect, 0, 0); - BYTE* lockData = (BYTE*)lockRect.pBits; - - // 32-bit to 24-bit - for (size_t h = 0; h < gHeight; h++) { - BYTE* sData = lockData; - for (size_t x = 0; x < gWidth; x++) { - *dData++ = *sData++; - *dData++ = *sData++; - *dData++ = *sData++; - sData++; - } - lockData += lockRect.Pitch; - dData += bmpExtraSize; - } - - surface->UnlockRect(); - surface->Release(); - - HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); - bool resultOK = (hFile != INVALID_HANDLE_VALUE); - - if (resultOK) { - DWORD dwWritten; - WriteFile(hFile, &bmpHeader, sizeof(BMPHEADER), &dwWritten, 0); - WriteFile(hFile, bmpImageData, sizeImage, &dwWritten, 0); - CloseHandle(hFile); - } - delete[] bmpImageData;*/ - return (resultOK) ? 0 : 1; } diff --git a/sfall/Modules/Scripting/Handlers/Misc.cpp b/sfall/Modules/Scripting/Handlers/Misc.cpp index 5b5ad5bc..caab0781 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.cpp +++ b/sfall/Modules/Scripting/Handlers/Misc.cpp @@ -98,7 +98,7 @@ void op_get_year(OpcodeContext& ctx) { void __declspec(naked) op_eax_available() { __asm { - xor edx, edx + xor edx, edx; // EAX support has been removed since 2.1a _J_RET_VAL_TYPE(VAR_TYPE_INT); } } diff --git a/sfall/Modules/Scripting/Handlers/Misc.h b/sfall/Modules/Scripting/Handlers/Misc.h index 15d7764d..fb379476 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.h +++ b/sfall/Modules/Scripting/Handlers/Misc.h @@ -66,7 +66,7 @@ void op_set_palette(OpcodeContext&); //numbers subgame functions void __declspec() op_nb_create_char(); -void __declspec() op_hero_select_win() ; +void __declspec() op_hero_select_win(); void __declspec() op_set_hero_style(); diff --git a/sfall/version.h b/sfall/version.h index bfde003d..ea039e83 100644 --- a/sfall/version.h +++ b/sfall/version.h @@ -25,6 +25,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 3 #define VERSION_BUILD 3 -#define VERSION_REV 0 +#define VERSION_REV 1 -#define VERSION_STRING "4.3.3" +#define VERSION_STRING "4.3.3.1"