From 475270451c3e138995dfefabb15f11b475ac3d51 Mon Sep 17 00:00:00 2001 From: Roman Masanin <36927roma@gmail.com> Date: Thu, 6 Jul 2023 00:37:31 +0200 Subject: [PATCH] move _countof, impove up to 96.90% --- LEGO1/decomp.h | 4 ++++ LEGO1/mxdirectdraw.cpp | 42 +++++++++++++++++++++++++++++------------- LEGO1/mxdirectdraw.h | 13 +------------ 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/LEGO1/decomp.h b/LEGO1/decomp.h index 5466e6d8..cd179ae6 100644 --- a/LEGO1/decomp.h +++ b/LEGO1/decomp.h @@ -4,6 +4,10 @@ #define DECOMP_STATIC_ASSERT(V) namespace { typedef int foo[(V)?1:-1]; } #define DECOMP_SIZE_ASSERT(T, S) DECOMP_STATIC_ASSERT(sizeof(T) == S) +#ifndef _countof +#define _countof(arr) sizeof(arr) / sizeof(arr[0]) +#endif + typedef unsigned char undefined; typedef unsigned short undefined2; typedef unsigned int undefined4; diff --git a/LEGO1/mxdirectdraw.cpp b/LEGO1/mxdirectdraw.cpp index 57715619..6557c2f6 100644 --- a/LEGO1/mxdirectdraw.cpp +++ b/LEGO1/mxdirectdraw.cpp @@ -1,10 +1,7 @@ #include "mxdirectdraw.h" +#include "decomp.h" -//TODO: make commonn place for defines like that -#ifndef _countof -#define _countof(arr) sizeof(arr) / sizeof(arr[0]) -#endif #ifndef DDSCAPS_3DDEVICE #define DDSCAPS_3DDEVICE 0x00002000l @@ -32,6 +29,20 @@ void EnableResizing(HWND hwnd, BOOL flag) } } +// OFFSET: LEGO1 0x1009EFD0 +MxDirectDraw::DeviceModesInfo::~DeviceModesInfo() +{ + if (p_guid != NULL) + { + free(p_guid); + } + + if (m_mode_ARRAY != NULL) + { + free(m_mode_ARRAY); + } +} + // OFFSET: LEGO1 0x1009D490 MxDirectDraw::MxDirectDraw() { @@ -1038,49 +1049,54 @@ BOOL MxDirectDraw::SetPaletteEntries( int paletteEntryCount, BOOL fullscreen) { - HRESULT result; + int reservedLowEntryCount = 10; + int reservedHighEntryCount = 10; + int arraySize = _countof(m_paletteEntries); HDC hdc; int i; if (g_is_PALETTEINDEXED8) { hdc = GetDC(NULL); - GetSystemPaletteEntries(hdc, 0, _countof(m_paletteEntries), m_paletteEntries); + GetSystemPaletteEntries(hdc, 0, arraySize, m_paletteEntries); ReleaseDC(NULL, hdc); } - for (i = 0; i < 10; i++) + for (i = 0; i < reservedLowEntryCount; i++) { m_paletteEntries[i].peFlags = 0x80; } - for (i = 10; i < 142; i++) + for (i = reservedLowEntryCount; i < 142; i++) { m_paletteEntries[i].peFlags = 0x44; } - for (i = 142; i < 246; i++) + for (i = 142; i < arraySize - reservedHighEntryCount; i++) { m_paletteEntries[i].peFlags = 0x84; } - for (i = 246; i < 256; i++) + for (i = arraySize - reservedHighEntryCount; i < arraySize; i++) { m_paletteEntries[i].peFlags = 0x80; } if (paletteEntryCount != 0) { - for (i = 10; (i < paletteEntryCount) && (i < 246); i++) + for (i = reservedLowEntryCount; + (i < paletteEntryCount) && (i < arraySize - reservedHighEntryCount); + i++) { - m_paletteEntries[i].peRed = pPaletteEntries[i].peRed; + m_paletteEntries[i].peRed = pPaletteEntries[i].peRed; m_paletteEntries[i].peGreen = pPaletteEntries[i].peGreen; - m_paletteEntries[i].peBlue = pPaletteEntries[i].peBlue; + m_paletteEntries[i].peBlue = pPaletteEntries[i].peBlue; } } if (m_pPalette != NULL) { + HRESULT result; result = m_pPalette->SetEntries(0, 0, _countof(m_paletteEntries), m_paletteEntries); if (result != DD_OK) { diff --git a/LEGO1/mxdirectdraw.h b/LEGO1/mxdirectdraw.h index 0e19ec6b..f4ecd61e 100644 --- a/LEGO1/mxdirectdraw.h +++ b/LEGO1/mxdirectdraw.h @@ -37,18 +37,7 @@ class MxDirectDraw DDCAPS m_ddcaps; void* a_178; - ~DeviceModesInfo() - { - if (p_guid != NULL) - { - free(p_guid); - } - - if (m_mode_ARRAY != NULL) - { - free(m_mode_ARRAY); - } - } + ~DeviceModesInfo(); };