From 61196b3c6011a37694ea583ff42599f2bb7720e2 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Thu, 14 Mar 2024 14:43:36 +0100 Subject: [PATCH 01/16] Fix compilation of the editors when using SDL1 SHIFT-HOME and HOME have the same values for SDL1; use CTRL-HOME instead --- redalert/mapedit.cpp | 4 ++++ tiberiandawn/mapedit.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/redalert/mapedit.cpp b/redalert/mapedit.cpp index 4a12e09e..59fa8d92 100644 --- a/redalert/mapedit.cpp +++ b/redalert/mapedit.cpp @@ -772,10 +772,14 @@ void MapEditClass::AI(KeyNumType& input, int x, int y) input = KN_NONE; break; +#if (KN_HOME | KN_SHIFT_BIT) != KN_HOME /* ** SHIFT-HOME: set new Home Cell position */ case ((int)KN_HOME | (int)KN_SHIFT_BIT): +#else + case ((int)KN_HOME | (int)KN_CTRL_BIT): +#endif if (CurrentCell != 0) { /* diff --git a/tiberiandawn/mapedit.cpp b/tiberiandawn/mapedit.cpp index a46334fa..04708fb3 100644 --- a/tiberiandawn/mapedit.cpp +++ b/tiberiandawn/mapedit.cpp @@ -858,10 +858,14 @@ void MapEditClass::AI(KeyNumType& input, int x, int y) input = KN_NONE; break; +#if (KN_HOME | KN_SHIFT_BIT) != KN_HOME /*--------------------------------------------------------------------- SHIFT-HOME: set new Home Cell position ---------------------------------------------------------------------*/ case ((int)KN_HOME | (int)KN_SHIFT_BIT): +#else + case ((int)KN_HOME | (int)KN_CTRL_BIT): +#endif /* ** Unflag the old Home Cell, if there are no other waypoints ** pointing to it From 18eea91a81c01811cab2c5549253133b068208ef Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Wed, 20 Mar 2024 09:43:44 +0100 Subject: [PATCH 02/16] Fix a wrong extern definition --- common/alloc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/alloc.cpp b/common/alloc.cpp index 3338d910..ee6de9ea 100644 --- a/common/alloc.cpp +++ b/common/alloc.cpp @@ -56,7 +56,7 @@ static size_t TotalRam = 0; static unsigned int Memory_Calls = 0; void (*Memory_Error)(void) = NULL; -extern void (*Memory_Error_Exit)(char* string) = NULL; +void (*Memory_Error_Exit)(char* string) = NULL; /*************************************************************************** * Alloc -- Allocates system RAM. * From d0fb60f5d45a9c4de8b70cd4b738592c1757425a Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Wed, 20 Mar 2024 13:17:59 +0100 Subject: [PATCH 03/16] Include in files that need it Without this, operations on fixed values are miscompiled on big-endian machines --- common/fixed.h | 1 + tiberiandawn/defines.h | 1 + 2 files changed, 2 insertions(+) diff --git a/common/fixed.h b/common/fixed.h index e79a99db..b8da0b45 100644 --- a/common/fixed.h +++ b/common/fixed.h @@ -36,6 +36,7 @@ #define FIXED_H #include +#include "endianness.h" /* ** This is a very simple fixed point class that functions like a regular integral type. However diff --git a/tiberiandawn/defines.h b/tiberiandawn/defines.h index f69fc694..82ff91d8 100644 --- a/tiberiandawn/defines.h +++ b/tiberiandawn/defines.h @@ -35,6 +35,7 @@ #define DEFINES_H #include "common/bitfields.h" +#include "common/endianness.h" /********************************************************************** ** If defined, then the advanced balancing features will be enabled From d5d959a938f4740fa4083897e219e4a8aa26bbb6 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Wed, 20 Mar 2024 13:23:15 +0100 Subject: [PATCH 04/16] Fix a printf format TriggerClass::Write_INI "Data" is a int, not a long int --- tiberiandawn/trigger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiberiandawn/trigger.cpp b/tiberiandawn/trigger.cpp index 7fabbac2..477634bd 100644 --- a/tiberiandawn/trigger.cpp +++ b/tiberiandawn/trigger.cpp @@ -1192,7 +1192,7 @@ void TriggerClass::Write_INI(CCINIClass& ini, bool refresh) } sprintf(buf, - "%s,%s,%ld,%s,%s,%d", + "%s,%s,%d,%s,%s,%d", TriggerClass::Name_From_Event(trigger->Event), TriggerClass::Name_From_Action(trigger->Action), trigger->Data, From 1279a0141bc25905ad693491838ac6c3dab12fa4 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Wed, 20 Mar 2024 10:20:14 +0100 Subject: [PATCH 05/16] Avoid undefined behaviour when deleting a void * --- common/bfiofile.cpp | 2 +- common/mixfile.h | 6 +++--- redalert/event.cpp | 2 +- redalert/init.cpp | 4 ++-- redalert/msgbox.cpp | 2 +- redalert/queue.cpp | 6 +++--- redalert/stats.cpp | 2 +- tiberiandawn/ending.cpp | 4 ++-- tiberiandawn/init.cpp | 4 ++-- tiberiandawn/msgbox.cpp | 2 +- tiberiandawn/stats.cpp | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/common/bfiofile.cpp b/common/bfiofile.cpp index ff688985..8b80ec73 100644 --- a/common/bfiofile.cpp +++ b/common/bfiofile.cpp @@ -320,7 +320,7 @@ void BufferIOFileClass::Free(void) { if (Buffer) { if (IsAllocated) { - delete[] Buffer; + delete[] static_cast(Buffer); IsAllocated = false; } diff --git a/common/mixfile.h b/common/mixfile.h index 61d8ccc8..3a4f3604 100644 --- a/common/mixfile.h +++ b/common/mixfile.h @@ -653,7 +653,7 @@ template bool MixFileClass::Cache(Buffer const* b */ int actual = straw->Get(Data, DataSize); if (actual != DataSize) { - delete[] Data; + delete[] static_cast(Data); Data = NULL; file.Error(EIO); return (false); @@ -670,7 +670,7 @@ template bool MixFileClass::Cache(Buffer const* b sha.Result(digest2); fstraw.Get(digest1, sizeof(digest1)); if (memcmp(digest1, digest2, sizeof(digest1)) != 0) { - delete[] Data; + delete[] static_cast(Data); Data = NULL; return (false); } @@ -702,7 +702,7 @@ template bool MixFileClass::Cache(Buffer const* b template void MixFileClass::Free(void) { if (Data != NULL && IsAllocated) { - delete[] Data; + delete[] static_cast(Data); } Data = NULL; IsAllocated = false; diff --git a/redalert/event.cpp b/redalert/event.cpp index 30139439..ab298b04 100644 --- a/redalert/event.cpp +++ b/redalert/event.cpp @@ -901,7 +901,7 @@ void EventClass::Execute(void) printf("%d\n", ((char*)Data.Variable.Pointer)[i]); } if (ID != PlayerPtr->ID) { - delete[] Data.Variable.Pointer; + delete[] static_cast(Data.Variable.Pointer); } break; diff --git a/redalert/init.cpp b/redalert/init.cpp index 0650af75..558360c0 100644 --- a/redalert/init.cpp +++ b/redalert/init.cpp @@ -2910,7 +2910,7 @@ void Free_Heaps(void) */ for (int index = 0; index < ARRAY_SIZE(SpeechBuffer); index++) { if (SpeechBuffer[index]) { - delete[] SpeechBuffer[index]; + delete[] static_cast(SpeechBuffer[index]); SpeechBuffer[index] = NULL; } } @@ -2928,4 +2928,4 @@ void Free_Heaps(void) delete InterpolationTable; InterpolationTable = NULL; } -} \ No newline at end of file +} diff --git a/redalert/msgbox.cpp b/redalert/msgbox.cpp index 64b811f6..98fa248b 100644 --- a/redalert/msgbox.cpp +++ b/redalert/msgbox.cpp @@ -442,7 +442,7 @@ int WWMessageBox::Process(const char* msg, const char* b1txt, const char* b2txt, } SeenBuff.Unlock(); - delete[] back; + delete[] static_cast(back); back = NULL; Show_Mouse(); } diff --git a/redalert/queue.cpp b/redalert/queue.cpp index 5db08d27..ed429d87 100644 --- a/redalert/queue.cpp +++ b/redalert/queue.cpp @@ -2870,7 +2870,7 @@ static int Extract_Uncompressed_Events(void* buf, int bufsize) if (!DoList.Add(*event)) { if (event->Type == EventClass::ADDPLAYER) { - delete[] event->Data.Variable.Pointer; + delete[] static_cast(event->Data.Variable.Pointer); } return (-1); } @@ -3035,7 +3035,7 @@ static int Extract_Compressed_Events(void* buf, int bufsize) if (!DoList.Add(eventdata)) { if (eventdata.Type == EventClass::ADDPLAYER) { - delete[] eventdata.Data.Variable.Pointer; + delete[] static_cast(eventdata.Data.Variable.Pointer); } return (-1); } @@ -4399,4 +4399,4 @@ void Check_Mirror(void) #endif } // end of Check_Mirror -/*************************** end of queue.cpp ******************************/ \ No newline at end of file +/*************************** end of queue.cpp ******************************/ diff --git a/redalert/stats.cpp b/redalert/stats.cpp index b90ec5d4..f1fef53a 100644 --- a/redalert/stats.cpp +++ b/redalert/stats.cpp @@ -829,7 +829,7 @@ void Send_Statistics_Packet(void) /* ** Tidy up */ - delete[] packet; + delete[] static_cast(packet); GameStatisticsPacketSent = true; #endif // INTERNET_OFF diff --git a/tiberiandawn/ending.cpp b/tiberiandawn/ending.cpp index a907c153..8c7a0367 100644 --- a/tiberiandawn/ending.cpp +++ b/tiberiandawn/ending.cpp @@ -246,8 +246,8 @@ void Nod_Ending(void) Play_Movie("CC2TEASE"); - delete[] localpal; + delete[] static_cast(localpal); delete TextPrintBuffer; BlitList.Clear(); } -#endif \ No newline at end of file +#endif diff --git a/tiberiandawn/init.cpp b/tiberiandawn/init.cpp index e1cced9f..ce2a979f 100644 --- a/tiberiandawn/init.cpp +++ b/tiberiandawn/init.cpp @@ -635,7 +635,7 @@ void Uninit_Game(void) { Map.Free_Cells(); - delete[] SpeechBuffer; + delete[] static_cast(SpeechBuffer); CCFileClass::Clear_Search_Drives(); MFCD::Free_All(); @@ -2075,7 +2075,7 @@ void Parse_INI_File(void) Fetch working pointer to the INI staging buffer. Make sure that the buffer is cleared out before proceeding. ------------------------------------------------------------------------*/ - buffer = (char*)_ShapeBuffer; + buffer = _ShapeBuffer; memset(buffer, '\0', _ShapeBufferSize); /*------------------------------------------------------------------------ diff --git a/tiberiandawn/msgbox.cpp b/tiberiandawn/msgbox.cpp index 4f7ff2dc..fb74f871 100644 --- a/tiberiandawn/msgbox.cpp +++ b/tiberiandawn/msgbox.cpp @@ -447,7 +447,7 @@ int WWMessageBox::Process(const char* msg, const char* b1txt, const char* b2txt, } SeenBuff.Unlock(); - delete[] back; + delete[] static_cast(back); back = NULL; Show_Mouse(); } diff --git a/tiberiandawn/stats.cpp b/tiberiandawn/stats.cpp index 53f0f69e..57c04823 100644 --- a/tiberiandawn/stats.cpp +++ b/tiberiandawn/stats.cpp @@ -593,7 +593,7 @@ void Send_Statistics_Packet(void) ** Tidy up */ CCDebugString("C&C95 - About to delete packet memory.\n"); - delete[] packet; + delete[] static_cast(packet); GameStatisticsPacketSent = true; CCDebugString("C&C95 - Returning from Send_Statistics_Packet.\n"); From 77e2da04a83dc8c1afa1dc92dd48239375c2179e Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Thu, 14 Mar 2024 14:40:17 +0100 Subject: [PATCH 06/16] Fix compliation of some test programs They refer to stderr etc. but fail to include --- tests/face.cpp | 1 + tests/fading.cpp | 1 + tests/lcw.cpp | 1 + tests/rect.cpp | 1 + tests/xordelta.cpp | 1 + 5 files changed, 5 insertions(+) diff --git a/tests/face.cpp b/tests/face.cpp index 1b723d7c..9da4e6d2 100644 --- a/tests/face.cpp +++ b/tests/face.cpp @@ -1,5 +1,6 @@ #include "common/face.h" +#include #include #include diff --git a/tests/fading.cpp b/tests/fading.cpp index e47035bc..bb46d45e 100644 --- a/tests/fading.cpp +++ b/tests/fading.cpp @@ -1,5 +1,6 @@ #include "common/fading.h" +#include #include #include #include diff --git a/tests/lcw.cpp b/tests/lcw.cpp index 410db3d0..e5cb7e22 100644 --- a/tests/lcw.cpp +++ b/tests/lcw.cpp @@ -1,5 +1,6 @@ #include "common/lcw.h" +#include #include #include #include diff --git a/tests/rect.cpp b/tests/rect.cpp index fc91a73b..349644b1 100644 --- a/tests/rect.cpp +++ b/tests/rect.cpp @@ -1,5 +1,6 @@ #include "common/rect.h" +#include #include #include diff --git a/tests/xordelta.cpp b/tests/xordelta.cpp index 2e961d9a..a3af9f75 100644 --- a/tests/xordelta.cpp +++ b/tests/xordelta.cpp @@ -1,5 +1,6 @@ #include "common/xordelta.h" +#include #include #include #include From 4ed8f34bd1fa9e3a9e2720b44079f6fb26b3b669 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Sat, 23 Mar 2024 15:18:39 +0100 Subject: [PATCH 07/16] Include also in base64 Without this, base64 decoder (used to encode/decrypt the PKeys) does not work, resulting in division by zero --- common/base64.cpp | 3 ++- common/mp.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/base64.cpp b/common/base64.cpp index e14f1e84..66947822 100644 --- a/common/base64.cpp +++ b/common/base64.cpp @@ -36,6 +36,7 @@ #include "base64.h" #include +#include "endianness.h" /* ** This is the magic padding character used to fill out the encoded data to a multiple of @@ -425,4 +426,4 @@ implementations. within base64-encoded parts of multipart entities because no hyphen characters are used in the base64 encoding. -*/ \ No newline at end of file +*/ diff --git a/common/mp.cpp b/common/mp.cpp index fdeef76a..e064cb23 100644 --- a/common/mp.cpp +++ b/common/mp.cpp @@ -265,6 +265,8 @@ void XMP_DER_Decode(digit* result, unsigned char const* input, int precision) } } +#ifndef __BIG_ENDIAN__ +// FIXME: does not for work big-endian /*********************************************************************************************** * XMP_Encode -- Encode MP number into buffer. * * * @@ -308,6 +310,7 @@ unsigned XMP_Encode(unsigned char* to, unsigned tobytes, digit const* from, int return (tobytes); } +#endif /*********************************************************************************************** * XMP_Encode -- Encode MP number into buffer as compactly as possible. * @@ -358,7 +361,8 @@ unsigned XMP_Encode(unsigned char* to, digit const* from, int precision) unsigned char* number_ptr; unsigned char* const end = (unsigned char*)from; - for (number_ptr = (unsigned char*)end + precision - 1; number_ptr > (unsigned char*)end; number_ptr--) { + for (number_ptr = (unsigned char*)end + precision * sizeof(digit) - 1; number_ptr > (unsigned char*)end; + number_ptr--) { if (*number_ptr != filler) break; } @@ -922,6 +926,8 @@ unsigned XMP_Count_Bits(const digit* number, int precision) return (total_bit_count); } +#ifndef __BIG_ENDIAN__ +// FIXME: does not work for big-endian /*********************************************************************************************** * XMP_Count_Bytes -- Counts the number of precision bytes in MP number. * * * @@ -951,6 +957,7 @@ int XMP_Count_Bytes(const digit* number, int precision) } return (count); } +#endif /*********************************************************************************************** * XMP_Move -- Assign one MP number to another. * From 0d6fee7b431746640b7c08b8db663e3730e1be29 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Thu, 14 Mar 2024 14:38:40 +0100 Subject: [PATCH 08/16] Make OPENAL optional also on non-windows platforms There are some system where OPENAL is not available --- CMakeLists.txt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77ae270d..3ce8dad3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,19 +33,9 @@ if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Windows") option(WIN9X "Enable support for Windows 95/98/ME." OFF) option(DSOUND "Enable DirectSound audio. (deprecated)" OFF) option(DDRAW "Enable DirectDraw video backend. (deprecated)" OFF) - option(SDL1 "Enable SDL1 video backend." OFF) - option(SDL2 "Enable SDL2 video backend." ON) - option(OPENAL "Enable OpenAL audio backend." ON) add_feature_info(Windows9x WIN9X "Windows 95/98/ME support" OFF) add_feature_info(DirectSound DSOUND "DirectSound audio backend (deprecated)") add_feature_info(DirectDraw DDRAW "DirectDraw video backend (deprecated)") - add_feature_info(SDL1 SDL1 "SDL1 video backend") - add_feature_info(SDL2 SDL2 "SDL2 video backend") - add_feature_info(OpenAL OPENAL "OpenAL audio backend") -else() - add_feature_info(SDL1 SDL1 "SDL1 video backend") - add_feature_info(SDL2 SDL2 "SDL2 video backend") - set(OPENAL TRUE) endif() if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -56,6 +46,9 @@ if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") endif() endif() +add_feature_info(SDL1 SDL1 "SDL1 video backend") +add_feature_info(SDL2 SDL2 "SDL2 video backend") +add_feature_info(OpenAL OPENAL "OpenAL audio backend") add_feature_info(RemasterTD BUILD_REMASTERTD, "Remastered Tiberian Dawn dll") add_feature_info(RemasterRA BUILD_REMASTERRA "Remastered Red Alert dll") add_feature_info(VanillaTD BUILD_VANILLATD "Tiberian Dawn executable") From dcfe358efacb19329272f0f41264671c6ce35cb5 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Thu, 21 Mar 2024 13:56:38 +0100 Subject: [PATCH 09/16] Avoid operator ++ on bool --- common/vqatask.cpp | 2 +- redalert/ending.cpp | 2 +- tiberiandawn/ending.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/vqatask.cpp b/common/vqatask.cpp index 390558fc..28f9dc50 100644 --- a/common/vqatask.cpp +++ b/common/vqatask.cpp @@ -117,7 +117,7 @@ VQAErrorType VQA_Play(VQAHandle* handle, VQAPlayMode mode) } if (data->Flags & VQA_DATA_FLAG_VIDEO_MEMORY_SET) { - ++VQAMovieDone; + VQAMovieDone = true; } else { rc = (VQAErrorType)VQA_LoadFrame(handle); diff --git a/redalert/ending.cpp b/redalert/ending.cpp index a0f778d1..08768bcb 100644 --- a/redalert/ending.cpp +++ b/redalert/ending.cpp @@ -105,7 +105,7 @@ void Nod_Ending(void) bool printedtext = false; while (!done) { if (!printedtext && !Is_Sample_Playing(kanefinl)) { - printedtext++; + printedtext = true; Alloc_Object(new ScorePrintClass(Text_String(TXT_SEL_TARGET), 0, 180, _tanpal)); mouseshown = true; Show_Mouse(); diff --git a/tiberiandawn/ending.cpp b/tiberiandawn/ending.cpp index 8c7a0367..f622399f 100644 --- a/tiberiandawn/ending.cpp +++ b/tiberiandawn/ending.cpp @@ -159,7 +159,7 @@ void Nod_Ending(void) bool printedtext = false; while (!done) { if (!printedtext && !Is_Sample_Playing(kanefinl)) { - printedtext++; + printedtext = true; Alloc_Object(new ScorePrintClass(Text_String(TXT_SEL_TARGET), 0, 180, _tanpal)); mouseshown = true; Show_Mouse(); @@ -177,7 +177,7 @@ void Nod_Ending(void) int mousex = Keyboard->MouseQX; int mousey = Keyboard->MouseQY; if (mousey >= 22 * factor && mousey <= 177 * factor) { - done++; + done = true; if (mousex < 160 * factor && mousey < 100 * factor) selection = 2; if (mousex < 160 * factor && mousey >= 100 * factor) From b2038569d3d1ff4ac17ad20b45a746095db08830 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Wed, 20 Mar 2024 10:28:35 +0100 Subject: [PATCH 10/16] Avoid redefinition of __USE_POSIX199309/_POSIX_C_SOURCE On glibc systems, they are already defined in which is pulled in by any system header. Defining such macros in header files is too late. --- common/mssleep.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/mssleep.h b/common/mssleep.h index 9f7c8a66..eb1f8ebc 100644 --- a/common/mssleep.h +++ b/common/mssleep.h @@ -11,8 +11,12 @@ #elif defined(_WIN32) #include #else /* Assuming recent posix*/ -#define __USE_POSIX199309 +#ifndef __USE_POSIX199309 +#define __USE_POSIX199309 1 +#endif +#ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199309L +#endif #include #endif From 4f4e5066a01a0bab631490994d5606d932bb3d7d Mon Sep 17 00:00:00 2001 From: Walter Barrett Date: Wed, 27 Mar 2024 09:13:37 -0400 Subject: [PATCH 11/16] Implement Texture_Fill_Rect --- common/graphicsviewport.cpp | 12 ++++++++++++ common/graphicsviewport.h | 15 +-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/common/graphicsviewport.cpp b/common/graphicsviewport.cpp index 987affe8..063a721f 100644 --- a/common/graphicsviewport.cpp +++ b/common/graphicsviewport.cpp @@ -980,3 +980,15 @@ void GraphicViewPortClass::Draw_Rect(int x1_pixel, int y1_pixel, int x2_pixel, i Draw_Line(x2_pixel, y1_pixel, x2_pixel, y2_pixel, color); Unlock(); } + +void GraphicViewPortClass::Texture_Fill_Rect(int xpos, int ypos, int width, int height, unsigned char* shape_pointer, int source_width, int source_height) +{ + if (Lock()) { + for (int y = ypos; y < ypos + height; y++) { + for (int x = xpos; x < xpos + width; x++) { + LogicPage->Put_Pixel(x, y, *(shape_pointer + ((y % source_height) * source_width) + (x % source_width))); + } + } + Unlock(); + } +} diff --git a/common/graphicsviewport.h b/common/graphicsviewport.h index 7a310a42..5ccb878d 100644 --- a/common/graphicsviewport.h +++ b/common/graphicsviewport.h @@ -289,20 +289,7 @@ class GraphicViewPortClass void Remap(int sx, int sy, int width, int height, void* remap); void Remap(void* remap); void Draw_Stamp(void const* icondata, int icon, int x_pixel, int y_pixel, void const* remap, int clip_window); - - // PG_TO_FIX - // This seems to be missing. Might not be needed anyway since it looks like it's only used for UI drawing. ST - - // 12/17/2018 6:11PM - void Texture_Fill_Rect(int xpos, - int ypos, - int width, - int height, - void const* shape_pointer, - int source_width, - int source_height) - { - return; - } + void Texture_Fill_Rect(int xpos, int ypos, int width, int height, unsigned char* shape_pointer, int source_width, int source_height); // This doesnt seem to exist anywhere?? - Steve T 9/26/95 6:05PM // VOID Grey_Out_Region(int x, int y, int width, int height, int color); From 20387694fd9cc6707df40d022db75fb87c1ba4cd Mon Sep 17 00:00:00 2001 From: Walter Barrett Date: Wed, 27 Mar 2024 09:16:02 -0400 Subject: [PATCH 12/16] TD: Selectable button style --- common/graphicsviewport.cpp | 11 +++++++-- common/graphicsviewport.h | 8 ++++++- common/settings.cpp | 15 ++++++++++++ common/settings.h | 1 + tiberiandawn/dialog.cpp | 47 ++++++++++++++++++++++++------------- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/common/graphicsviewport.cpp b/common/graphicsviewport.cpp index 063a721f..bcdc7b8b 100644 --- a/common/graphicsviewport.cpp +++ b/common/graphicsviewport.cpp @@ -981,12 +981,19 @@ void GraphicViewPortClass::Draw_Rect(int x1_pixel, int y1_pixel, int x2_pixel, i Unlock(); } -void GraphicViewPortClass::Texture_Fill_Rect(int xpos, int ypos, int width, int height, unsigned char* shape_pointer, int source_width, int source_height) +void GraphicViewPortClass::Texture_Fill_Rect(int xpos, + int ypos, + int width, + int height, + unsigned char* shape_pointer, + int source_width, + int source_height) { if (Lock()) { for (int y = ypos; y < ypos + height; y++) { for (int x = xpos; x < xpos + width; x++) { - LogicPage->Put_Pixel(x, y, *(shape_pointer + ((y % source_height) * source_width) + (x % source_width))); + LogicPage->Put_Pixel( + x, y, *(shape_pointer + ((y % source_height) * source_width) + (x % source_width))); } } Unlock(); diff --git a/common/graphicsviewport.h b/common/graphicsviewport.h index 5ccb878d..26c62b01 100644 --- a/common/graphicsviewport.h +++ b/common/graphicsviewport.h @@ -289,7 +289,13 @@ class GraphicViewPortClass void Remap(int sx, int sy, int width, int height, void* remap); void Remap(void* remap); void Draw_Stamp(void const* icondata, int icon, int x_pixel, int y_pixel, void const* remap, int clip_window); - void Texture_Fill_Rect(int xpos, int ypos, int width, int height, unsigned char* shape_pointer, int source_width, int source_height); + void Texture_Fill_Rect(int xpos, + int ypos, + int width, + int height, + unsigned char* shape_pointer, + int source_width, + int source_height); // This doesnt seem to exist anywhere?? - Steve T 9/26/95 6:05PM // VOID Grey_Out_Region(int x, int y, int width, int height, int color); diff --git a/common/settings.cpp b/common/settings.cpp index bff02b6d..3b14cfcc 100644 --- a/common/settings.cpp +++ b/common/settings.cpp @@ -1,3 +1,4 @@ +#include "wwstd.h" #include "settings.h" #include "ini.h" #include "miscasm.h" @@ -36,6 +37,8 @@ SettingsClass::SettingsClass() void SettingsClass::Load(INIClass& ini) { + char buf[128]; + /* ** Mouse settings */ @@ -77,6 +80,15 @@ void SettingsClass::Load(INIClass& ini) if (Video.Boxing || Mouse.RawInput || Mouse.ControllerEnabled) { Video.HardwareCursor = false; } + + ini.Get_String("Video", "ButtonStyle", "Default", buf, sizeof(buf)); + if (!stricmp(buf, "Gold")) { + Video.ButtonStyle = 1; + } else if (!stricmp(buf, "Classic") || !stricmp(buf, "DOS")) { + Video.ButtonStyle = 0; + } else { + Video.ButtonStyle = -1; + } } void SettingsClass::Save(INIClass& ini) @@ -111,4 +123,7 @@ void SettingsClass::Save(INIClass& ini) ** VQA and WSA interpolation mode 0 = scanlines, 1 = vertical doubling, 2 = linear */ ini.Put_Int("Video", "InterpolationMode", Video.InterpolationMode); + + ini.Put_String( + "Video", "ButtonStyle", Video.ButtonStyle == -1 ? "Default" : (Video.ButtonStyle == 1 ? "Gold" : "Classic")); } diff --git a/common/settings.h b/common/settings.h index cd2b4ea3..304127b5 100644 --- a/common/settings.h +++ b/common/settings.h @@ -33,6 +33,7 @@ class SettingsClass int InterpolationMode; bool HardwareCursor; bool DOSMode; + int ButtonStyle; std::string Scaler; std::string Driver; std::string PixelFormat; diff --git a/tiberiandawn/dialog.cpp b/tiberiandawn/dialog.cpp index f1843961..acf06cb5 100644 --- a/tiberiandawn/dialog.cpp +++ b/tiberiandawn/dialog.cpp @@ -44,6 +44,7 @@ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #include "function.h" +#include "settings.h" /*********************************************************************************************** * Dialog_Box -- draws a dialog background box * @@ -93,10 +94,8 @@ extern void CC_Texture_Fill(void const* shapefile, int shapenum, int xpos, int y void Draw_Box(int x, int y, int w, int h, BoxStyleEnum up, bool filled) { - static BoxStyleType const ButtonColors[BOXSTYLE_COUNT] = { - + static BoxStyleType const ButtonColorsClassic[BOXSTYLE_COUNT] = { // Filler, Shadow, Hilite, Corner colors - {LTGREY, WHITE, DKGREY, LTGREY}, // 0 Button is down. {LTGREY, DKGREY, WHITE, LTGREY}, // 1 Button is up w/border. {LTBLUE, BLUE, LTCYAN, LTBLUE}, // 2 Raised blue. @@ -105,29 +104,45 @@ void Draw_Box(int x, int y, int w, int h, BoxStyleEnum up, bool filled) {LTGREY, DKGREY, WHITE, LTGREY}, // 5 Button is up w/arrows. {CC_GREEN_BKGD, CC_LIGHT_GREEN, CC_GREEN_SHADOW, CC_GREEN_CORNERS}, // 6 Button is down. {CC_GREEN_BKGD, CC_GREEN_SHADOW, CC_LIGHT_GREEN, CC_GREEN_CORNERS}, // 7 Button is up w/border. - // {CC_GREEN_BKGD, 14, 12, 13}, // 6 Button is down. - // {CC_GREEN_BKGD, 12, 14, 13}, // 7 Button is up w/border. - {DKGREY, WHITE, BLACK, DKGREY}, // 8 Button is disabled down. - {DKGREY, BLACK, LTGREY, DKGREY}, // 9 Button is disabled up. - {BLACK, CC_GREEN_BOX, CC_GREEN_BOX, BLACK}, // 10 List box. - {BLACK, CC_GREEN_BOX, CC_GREEN_BOX, BLACK}, // 11 Menu box. - // {BLACK, 14, 14, BLACK}, // 10 List box. - // {BLACK, 14, 14, BLACK}, // 11 Menu box. + {DKGREY, WHITE, BLACK, DKGREY}, // 8 Button is disabled down. + {DKGREY, BLACK, LTGREY, DKGREY}, // 9 Button is disabled up. + {BLACK, CC_GREEN_BOX, CC_GREEN_BOX, BLACK}, // 10 List box. + {BLACK, CC_GREEN_BOX, CC_GREEN_BOX, BLACK}, // 11 Menu box. + }; + + static BoxStyleType const ButtonColorsGold[BOXSTYLE_COUNT] = { + // Filler, Shadow, Hilite, Corner colors + {LTGREY, WHITE, DKGREY, LTGREY}, // 0 Button is down. + {LTGREY, DKGREY, WHITE, LTGREY}, // 1 Button is up w/border. + {LTBLUE, BLUE, LTCYAN, LTBLUE}, // 2 Raised blue. + {DKGREY, WHITE, BLACK, DKGREY}, // 3 Button is disabled down. + {DKGREY, BLACK, WHITE, LTGREY}, // 4 Button is disabled up. + {LTGREY, DKGREY, WHITE, LTGREY}, // 5 Button is up w/arrows. + {CC_GREEN_BKGD, 14, 12, 13}, // 6 Button is down. + {CC_GREEN_BKGD, 12, 14, 13}, // 7 Button is up w/border. + {DKGREY, WHITE, BLACK, DKGREY}, // 8 Button is disabled down. + {DKGREY, BLACK, LTGREY, DKGREY}, // 9 Button is disabled up. + {BLACK, 14, 14, BLACK}, // 10 List box. + {BLACK, 14, 14, BLACK}, // 11 Menu box. }; + bool useGoldStyle; + if (Settings.Video.ButtonStyle == -1) { + useGoldStyle = !Settings.Video.DOSMode; + } else { + useGoldStyle = Settings.Video.ButtonStyle == 1; + } + w--; h--; - BoxStyleType const& style = ButtonColors[up]; + BoxStyleType const& style = useGoldStyle ? ButtonColorsGold[up] : ButtonColorsClassic[up]; if (filled) { - /* - if (style.Filler == CC_GREEN_BKGD) { + if (useGoldStyle && style.Filler == CC_GREEN_BKGD) { CC_Texture_Fill(MFCD::Retrieve("BTEXTURE.SHP"), InMainLoop, x, y, w, h); } else { LogicPage->Fill_Rect(x, y, x + w, y + h, style.Filler); } - */ - LogicPage->Fill_Rect(x, y, x + w, y + h, style.Filler); } switch (up) { From 8688c7a9bcf101fd5675312144461179a619eec0 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Thu, 14 Mar 2024 14:53:00 +0100 Subject: [PATCH 13/16] Avoid use of ftime() and fix overflow of unsigned int ftime() is an obsolete interface, and may not be present on all platforms. Also, multiplying a time_t by 1000 will overflow the range of an unsigned 32-bit int. --- common/connect.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/common/connect.cpp b/common/connect.cpp index 13b3386d..191336b3 100644 --- a/common/connect.cpp +++ b/common/connect.cpp @@ -44,7 +44,7 @@ #include //#include -#include +#include #include #include "connect.h" @@ -227,6 +227,8 @@ int ConnectionClass::Send_Packet(void* buf, int buflen, int ack_req) SwapCommHeaderType((CommHeaderType*)PacketBuf); + SwapCommHeaderType((CommHeaderType*)PacketBuf); + /*------------------------------------------------------------------------ Now build the packet ------------------------------------------------------------------------*/ @@ -747,7 +749,6 @@ int ConnectionClass::Service_Receive_Queue(void) *=========================================================================*/ unsigned int ConnectionClass::Time(void) { - static struct timeb mytime; // DOS time unsigned int msec; #ifdef WWLIB32_H @@ -764,23 +765,19 @@ unsigned int ConnectionClass::Time(void) /*------------------------------------------------------------------------ Otherwise, use the DOS timer ------------------------------------------------------------------------*/ - else { - ftime(&mytime); - msec = (unsigned int)mytime.time * 1000 + (unsigned int)mytime.millitm; - return ((msec / 100) * 6); - } #else /*------------------------------------------------------------------------ If the Westwood library isn't being used, use the DOS timer. ------------------------------------------------------------------------*/ - ftime(&mytime); - msec = (unsigned int)mytime.time * 1000 + (unsigned int)mytime.millitm; - return ((msec / 100) * 6); - #endif + static auto epoch = std::chrono::steady_clock::now().time_since_epoch(); + auto now = std::chrono::steady_clock::now().time_since_epoch(); + msec = unsigned(std::chrono::duration_cast(now - epoch).count()); + + return ((msec / 100) * 6); } /* end of Time */ /*************************************************************************** From 5e9160e9a335c8abf14249fa1729ca8642b75f75 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Thu, 21 Mar 2024 14:04:36 +0100 Subject: [PATCH 14/16] Fix warnings "arithmetic on NULL" --- redalert/cell.cpp | 6 +++--- redalert/mapedplc.cpp | 4 ++-- redalert/mapedsel.cpp | 6 +++--- redalert/object.cpp | 4 ++-- redalert/team.cpp | 20 ++++++++++---------- redalert/vessel.cpp | 2 +- tiberiandawn/mapedplc.cpp | 4 ++-- tiberiandawn/mapedsel.cpp | 6 +++--- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/redalert/cell.cpp b/redalert/cell.cpp index 744ace5f..e3067afa 100644 --- a/redalert/cell.cpp +++ b/redalert/cell.cpp @@ -396,8 +396,8 @@ void CellClass::Redraw_Objects(bool forced) #else optr->Mark(MARK_CHANGE); #endif - if (optr->Next != NULL && !optr->Next->IsActive) { - optr->Next = NULL; + if (optr->Next != nullptr && !optr->Next->IsActive) { + optr->Next = nullptr; } optr = optr->Next; } @@ -604,7 +604,7 @@ void CellClass::Occupy_Down(ObjectClass* object) */ if (object->What_Am_I() == RTTI_BUILDING && Cell_Occupier()) { optr = Cell_Occupier(); - while (optr->Next != NULL) { + while (optr->Next != nullptr) { assert(optr != object); assert(optr->What_Am_I() != RTTI_BUILDING); optr = optr->Next; diff --git a/redalert/mapedplc.cpp b/redalert/mapedplc.cpp index a9781c47..776ad8f3 100644 --- a/redalert/mapedplc.cpp +++ b/redalert/mapedplc.cpp @@ -942,13 +942,13 @@ int MapEditClass::Place_Object(void) if (Is_Spot_Free(Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y()))) { obj_coord = Closest_Free_Spot(Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y())); } else { - obj_coord = NULL; + obj_coord = 0; } /* ** No free spots; don't place the object */ - if (obj_coord == NULL) { + if (obj_coord == 0) { // ScenarioInit--; return (-1); } diff --git a/redalert/mapedsel.cpp b/redalert/mapedsel.cpp index cb555aa1..64935c24 100644 --- a/redalert/mapedsel.cpp +++ b/redalert/mapedsel.cpp @@ -464,7 +464,7 @@ int MapEditClass::Move_Grabbed_Object(void) */ ((InfantryClass*)GrabbedObject)->Clear_Occupy_Bit(GrabbedObject->Coord); } else { - new_coord = NULL; + new_coord = 0; } } else { @@ -483,10 +483,10 @@ int MapEditClass::Move_Grabbed_Object(void) ** Try to place object at new coordinate */ if (GrabbedObject->Can_Enter_Cell(Coord_Cell(new_coord)) != MOVE_OK) { - new_coord = NULL; + new_coord = 0; } } - if (new_coord != NULL) { + if (new_coord != 0) { /* ** If this object is part of the AI's Base list, change the coordinate diff --git a/redalert/object.cpp b/redalert/object.cpp index bc08208c..529044c2 100644 --- a/redalert/object.cpp +++ b/redalert/object.cpp @@ -1335,7 +1335,7 @@ void ObjectClass::Debug_Dump(MonoClass* mono) const { mono->Set_Cursor(1, 1); mono->Printf("%-18.18s", Text_String(Full_Name())); - if (Next != NULL) { + if (Next != nullptr) { mono->Set_Cursor(20, 5); mono->Printf("%08X", Next->As_Target()); } @@ -2451,4 +2451,4 @@ BuildingClass* ObjectTypeClass::Who_Can_Build_Me(bool intheory, bool legal, Hous } } return (anybuilding); -} \ No newline at end of file +} diff --git a/redalert/team.cpp b/redalert/team.cpp index 287c0ef7..a4b902be 100644 --- a/redalert/team.cpp +++ b/redalert/team.cpp @@ -98,7 +98,7 @@ static inline bool _Is_It_Breathing(FootClass const* object) ** If the object is not present or appears to be dead, then it ** certainly isn't an active member of the team. */ - if (object == NULL || !object->IsActive || object->Strength == 0) + if (object == nullptr || !object->IsActive || object->Strength == 0) return (false); /* @@ -292,7 +292,7 @@ void TeamClass::operator delete(void* ptr) TeamClass::~TeamClass(void) { if (GameActive && Class.Is_Valid()) { - while (Member != NULL) { + while (Member != nullptr) { Remove(Member); } Class->Number--; @@ -306,7 +306,7 @@ TeamClass::~TeamClass(void) if (Trigger->AttachCount == 0) { delete (TriggerClass*)Trigger; } - Trigger = NULL; + Trigger = nullptr; } } } @@ -677,7 +677,7 @@ void TeamClass::AI(void) ** If there are no members of the team and the team has reached ** full strength at one time, then delete the team. */ - if (Member == NULL && IsHasBeen) { + if (Member == nullptr && IsHasBeen) { /* ** If this team had no members (i.e., the team object wasn't terminated by some @@ -718,7 +718,7 @@ void TeamClass::AI(void) break; case TMISSION_MOVE: - if ((unsigned)mission->Data.Value < WAYPT_COUNT && Member != NULL) { + if ((unsigned)mission->Data.Value < WAYPT_COUNT && Member != nullptr) { FootClass* leader = Fetch_A_Leader(); CELL movecell = Scen.Waypoint[mission->Data.Value]; if (!Is_Leaving_Map()) { @@ -757,7 +757,7 @@ void TeamClass::AI(void) /* ** Perform mission of the team. This depends on the mission list. */ - if (Member != NULL && IsMoving && !IsReforming && !IsUnderStrength) { + if (Member != nullptr && IsMoving && !IsReforming && !IsUnderStrength) { /* ** If the current Target has been dealt with but the mission target @@ -912,7 +912,7 @@ bool TeamClass::Add(FootClass* obj) ** Actually add the object to the team. */ Quantity[typeindex]++; - obj->IsInitiated = (Member == NULL); + obj->IsInitiated = (Member == nullptr); obj->Member = Member; Member = obj; obj->Team = this; @@ -1144,7 +1144,7 @@ bool TeamClass::Remove(FootClass* obj, int typeindex) ** team captain. Mark the center location of the team as invalid so that ** it will be centered around the captain. */ - if (!initiated && Member != NULL) { + if (!initiated && Member != nullptr) { Member->IsInitiated = true; Zone = TARGET_NONE; } @@ -1639,7 +1639,7 @@ void TeamClass::Coordinate_Attack(void) ** can "attack" an empty cell and this is perfectly ok (paratrooper drop and parabombs ** are prime examples). */ - if (Is_Target_Cell(Target) && Member != NULL && Fetch_A_Leader()->What_Am_I() != RTTI_AIRCRAFT) { + if (Is_Target_Cell(Target) && Member != nullptr && Fetch_A_Leader()->What_Am_I() != RTTI_AIRCRAFT) { CellClass* cellptr = &Map[As_Cell(Target)]; TemplateType tt = cellptr->TType; if (cellptr->Cell_Object()) { @@ -2671,7 +2671,7 @@ int TeamClass::TMission_Formation(void) *=============================================================================================*/ int TeamClass::TMission_Attack(void) { - if (!Target_Legal(MissionTarget) && Member != NULL) { + if (!Target_Legal(MissionTarget) && Member != nullptr) { TeamMissionClass const* mission = &Class->MissionList[CurrentMission]; /* diff --git a/redalert/vessel.cpp b/redalert/vessel.cpp index 3414f746..5c3c1d79 100644 --- a/redalert/vessel.cpp +++ b/redalert/vessel.cpp @@ -718,7 +718,7 @@ void VesselClass::Per_Cell_Process(PCPType why) CELL cell = Coord_Cell(Adjacent_Cell(Center_Coord(), face)); SmartPtr whom; whom = Map[cell].Cell_Building(); - if (whom != NULL && ((*whom == STRUCT_SHIP_YARD) || (*whom == STRUCT_SUB_PEN))) { + if (whom != nullptr && ((*whom == STRUCT_SHIP_YARD) || (*whom == STRUCT_SUB_PEN))) { // MBL 04.27.2020: Make only audible to the correct player // if (IsOwnedByPlayer) Speak(VOX_REPAIRING); diff --git a/tiberiandawn/mapedplc.cpp b/tiberiandawn/mapedplc.cpp index c32f7ff5..4743621c 100644 --- a/tiberiandawn/mapedplc.cpp +++ b/tiberiandawn/mapedplc.cpp @@ -1171,13 +1171,13 @@ int MapEditClass::Place_Object(void) if (Is_Spot_Free(Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y()))) { obj_coord = Closest_Free_Spot(Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y())); } else { - obj_coord = NULL; + obj_coord = 0; } /* ................ No free spots; don't place the object ................ */ - if (obj_coord == NULL) { + if (obj_coord == 0) { // ScenarioInit--; return (-1); } diff --git a/tiberiandawn/mapedsel.cpp b/tiberiandawn/mapedsel.cpp index 1212f2c8..8812de43 100644 --- a/tiberiandawn/mapedsel.cpp +++ b/tiberiandawn/mapedsel.cpp @@ -481,7 +481,7 @@ int MapEditClass::Move_Grabbed_Object(void) // Map[Coord_Cell(GrabbedObject->Coord)].Flag.Composite &= // ~(1 << CellClass::Spot_Index(GrabbedObject->Coord)); } else { - new_coord = NULL; + new_coord = 0; } } else { @@ -500,10 +500,10 @@ int MapEditClass::Move_Grabbed_Object(void) ................ Try to place object at new coordinate ................ */ if (GrabbedObject->Can_Enter_Cell(Coord_Cell(new_coord)) != MOVE_OK) { - new_coord = NULL; + new_coord = 0; } } - if (new_coord != NULL) { + if (new_coord != 0) { /* ** If this object is part of the AI's Base list, change the coordinate ** in the Base's Node list. From cc994a40cb0676877b1c0352974323c3b6d5cb0b Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Fri, 29 Mar 2024 03:29:35 +0100 Subject: [PATCH 15/16] Remove accidently duplicated call to SwapCommHeaderType This slipped in from commit https://github.com/TheAssemblyArmada/Vanilla-Conquer/commit/8688c7a9bcf101fd5675312144461179a619eec0 --- common/connect.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/connect.cpp b/common/connect.cpp index 191336b3..3a3f5c46 100644 --- a/common/connect.cpp +++ b/common/connect.cpp @@ -227,8 +227,6 @@ int ConnectionClass::Send_Packet(void* buf, int buflen, int ack_req) SwapCommHeaderType((CommHeaderType*)PacketBuf); - SwapCommHeaderType((CommHeaderType*)PacketBuf); - /*------------------------------------------------------------------------ Now build the packet ------------------------------------------------------------------------*/ From 5071cd6f6b8c8858bf9005a7e4fe985ab29ad4c2 Mon Sep 17 00:00:00 2001 From: Thorsten Otto Date: Thu, 14 Mar 2024 15:34:28 +0100 Subject: [PATCH 16/16] Define _GNU_SOURCE to get a definition of FNM_CASEFOLD --- common/file_posix.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/file_posix.cpp b/common/file_posix.cpp index 534f576b..233ba0f9 100644 --- a/common/file_posix.cpp +++ b/common/file_posix.cpp @@ -1,3 +1,6 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include "file.h" #include