From 7e3b925e3ec270c08ab831deb7d60840405088f6 Mon Sep 17 00:00:00 2001 From: Joshua Peisach Date: Sun, 2 Jul 2023 21:26:39 -0400 Subject: [PATCH] Push MxPalette progress - read comments in code. --- LEGO1/mxpalette.cpp | 32 ++++++++++++++++++++++++++++---- LEGO1/mxpalette.h | 3 ++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/LEGO1/mxpalette.cpp b/LEGO1/mxpalette.cpp index 58265964..0a2dbfd7 100644 --- a/LEGO1/mxpalette.cpp +++ b/LEGO1/mxpalette.cpp @@ -47,6 +47,17 @@ MxPalette* MxPalette::Clone() return pal; } +// OFFSET: LEGO1 0x100beed0 +MxPalette* MxPalette::FromBitmapPalette(RGBQUAD* p_bmp) +{ + // FIXME: Incomplete + this->m_overrideSkyColor = FALSE; + ApplySystemEntriesToPalette(this->m_entries); + memcpy(this->m_entries + 10, &p_bmp[10], 246); + this->m_skyColor = this->m_entries[141]; + return this; +} + // OFFSET: LEGO1 0x100bf150 MxResult MxPalette::GetEntries(LPPALETTEENTRY p_entries) { @@ -89,11 +100,24 @@ void MxPalette::GetDefaultPalette(LPPALETTEENTRY p_entries) } // OFFSET: LEGO1 0x100bf340 -MxBool MxPalette::operator==(MxPalette &) +MxBool MxPalette::operator==(MxPalette *p_palette) { - // TODO - return FALSE; - + // FIXME: ok, idk what is happening here: trying memcpy in different ways showed 0.00% match. Here is literally what it does. + // My guess is that memcpy doesn't break its loop when something is incorrect, and this function is only intended to check + // the RGB and memcpy does everything? The paramater 'rhs' in ghidra suggests it was likely some memcmp. For now, + // this is literally down to instruction swap. + int i = 0; + PALETTEENTRY *our = this->m_entries; + PALETTEENTRY *their = p_palette->m_entries; + do { + if(our->peRed != their->peRed) return FALSE; + if(our->peGreen != their->peGreen) return FALSE; + if(our->peBlue != their->peBlue) return FALSE; + their += 1; + our += 1; + i += 1; + } while (i < 256); + return TRUE; } // OFFSET: LEGO1 0x100bf330 diff --git a/LEGO1/mxpalette.h b/LEGO1/mxpalette.h index 937de207..a34d8271 100644 --- a/LEGO1/mxpalette.h +++ b/LEGO1/mxpalette.h @@ -11,7 +11,7 @@ class MxPalette : public MxCore { public: - __declspec(dllexport) MxBool operator==(MxPalette &); + __declspec(dllexport) MxBool operator==(MxPalette *p_palette); __declspec(dllexport) void Detach(); MxPalette(); @@ -19,6 +19,7 @@ class MxPalette : public MxCore void ApplySystemEntriesToPalette(LPPALETTEENTRY p_entries); MxPalette* Clone(); + MxPalette* FromBitmapPalette(RGBQUAD* p_bmp); void GetDefaultPalette(LPPALETTEENTRY p_entries); MxResult GetEntries(LPPALETTEENTRY p_entries); MxResult SetSkyColor(LPPALETTEENTRY p_entries);