Skip to content

[ZH] Make Zero Hour Tools compile with VS2022 c++20 #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ include(cmake/gamespy.cmake)
include(cmake/lzhl.cmake)
include(cmake/zlib.cmake)
add_subdirectory(Dependencies/Benchmark)
add_subdirectory(Dependencies/MaxSDK)
if (IS_VS6_BUILD)
# The original max sdk does not compile against a modern compiler.
# If there is a desire to make this work, then a fixed max sdk needs to be created.
add_subdirectory(Dependencies/MaxSDK)
endif()
add_subdirectory(Dependencies/SafeDisc)
add_subdirectory(Dependencies/Utility)
add_subdirectory(resources)
Expand Down
14 changes: 14 additions & 0 deletions Dependencies/Utility/Utility/fstream_adapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// TheSuperHackers
// This file includes the fstream that is compatible with vs6, STLPort and modern c++.

#pragma once

#ifdef USING_STLPORT

#include <fstream.h>

#else

#include <fstream>

#endif
25 changes: 25 additions & 0 deletions Dependencies/Utility/Utility/hash_map_adapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// TheSuperHackers
// This file includes a hash map that is compatible with vs6, STLPort and modern c++ for the most part.
// There are differences, for example std::hash_map::resize is the equivalent to std::unordered_map::reserve.

#pragma once

#if defined(USING_STLPORT) || (defined(_MSC_VER) && _MSC_VER < 1300)

#include <hash_map>

#else

#include <unordered_map>
namespace std
{
template <
class _Kty,
class _Ty,
class _Hasher = hash<_Kty>,
class _Keyeq = equal_to<_Kty>,
class _Alloc = allocator<pair<const _Kty, _Ty>>>
using hash_map = unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>;
}

#endif
33 changes: 33 additions & 0 deletions Dependencies/Utility/Utility/iostream_adapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// TheSuperHackers
// This file helps adapting modern iostream to legacy vs6 iostream,
// where symbols are not contained in the std namespace.

#pragma once

#if defined(USING_STLPORT) || (defined(_MSC_VER) && _MSC_VER < 1300)

#include <iostream.h>

#else

#include <iostream>

inline auto& cout = std::cout;
inline auto& cerr = std::cerr;

using streambuf = std::streambuf;
using ostream = std::ostream;

template <class _Elem, class _Traits>
std::basic_ostream<_Elem, _Traits>& endl(std::basic_ostream<_Elem, _Traits>& _Ostr)
{
return std::endl(_Ostr);
}

template <class _Elem, class _Traits>
std::basic_ostream<_Elem, _Traits>& flush(std::basic_ostream<_Elem, _Traits>& _Ostr)
{
return std::flush(_Ostr);
}

#endif
16 changes: 1 addition & 15 deletions GeneralsMD/Code/GameEngine/Include/Common/STLTypedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,7 @@ enum DrawableID;

#include <algorithm>
#include <bitset>
#ifdef USING_STLPORT
#include <hash_map>
#else
#include <unordered_map>
namespace std
{
template <
class _Kty,
class _Ty,
class _Hasher = hash<_Kty>,
class _Keyeq = equal_to<_Kty>,
class _Alloc = allocator<pair<const _Kty, _Ty>>>
using hash_map = unordered_map<_Kty, _Ty, _Hasher, _Keyeq, _Alloc>;
}
#endif
#include <Utility/hash_map_adapter.h>
#include <list>
#include <map>
#include <queue>
Expand Down
6 changes: 1 addition & 5 deletions GeneralsMD/Code/GameEngine/Include/Precompiled/PreRTS.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ class STLSpecialAlloc;
#include <direct.h>
#include <excpt.h>
#include <float.h>
#ifdef USING_STLPORT
#include <fstream.h>
#else
#include <fstream>
#endif
#include <Utility/fstream_adapter.h>
#include <imagehlp.h>
#include <io.h>
#include <limits.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target_include_directories(z_compression INTERFACE
)

target_link_libraries(z_compression PRIVATE
gz_config
zi_libraries_include
)

Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/CallbackHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CallbackHook
virtual ~CallbackHook()
{}

virtual bool DoCallback(void)
virtual bool DoCallback(void) const
{return false;}

protected:
Expand All @@ -66,7 +66,7 @@ template<class T> class Callback :
virtual ~Callback()
{}

virtual bool DoCallback(void)
virtual bool DoCallback(void) const
{
if (mCallback)
{
Expand Down
6 changes: 1 addition & 5 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

#include "sha.h"
#ifdef USING_STLPORT
#include <iostream.h>
#else
#include <iostream>
#endif
#include <Utility/iostream_adapter.h>
#include <stdlib.h>


Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/Tools/Autorun/CDCNTRL.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
CDControlClass CDControl;


void Last_Error_Text ( LPTSTR szPrefix, HRESULT hr );
void Last_Error_Text ( LPCTSTR szPrefix, HRESULT hr );


/***********************************************************************************************
Expand Down Expand Up @@ -1079,7 +1079,7 @@ bool WINAPI CDControlClass::Unlock_Logical_Volume (HANDLE vwin32, char drive)
* 6/24/99 4:44PM MML : Created *
*==============================================================================================*/

void Last_Error_Text ( LPTSTR szPrefix, HRESULT hr )
void Last_Error_Text ( LPCTSTR szPrefix, HRESULT hr )
{
LPVOID szMessage;
char szDisplay[1000];
Expand Down
20 changes: 11 additions & 9 deletions GeneralsMD/Code/Tools/Autorun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ set(AUTORUN_SRC
)

macro(setup_autorun appname)
add_executable(${appname} WIN32)
add_executable(${appname} WIN32)

target_sources(${appname} PRIVATE ${AUTORUN_SRC})
target_sources(${appname} PRIVATE ${AUTORUN_SRC})

target_link_libraries(${appname} PRIVATE
winmm
zi_libraries_include
)
target_link_libraries(${appname} PRIVATE
gz_config
gz_utility
winmm
zi_libraries_include
)

if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows")
target_sources(${appname} PRIVATE AUTORUN.RC)
endif()
if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows")
target_sources(${appname} PRIVATE AUTORUN.RC)
endif()
endmacro()

setup_autorun(z_autorun_en)
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/Tools/Autorun/CallbackHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CallbackHook
virtual ~CallbackHook()
{}

virtual bool DoCallback(void)
virtual bool DoCallback(void) const
{return false;}

protected:
Expand All @@ -67,7 +67,7 @@ template<class T> class Callback : public CallbackHook
{
}

virtual bool DoCallback(void)
virtual bool DoCallback(void) const
{
if (mCallback != NULL)
{
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/Tools/Autorun/DrawButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
// 07/15/1996 MML : Created.
//=============================================================================

DrawButton::DrawButton ( int id, RECT button_rect, char *normal, char *focus, char *pressed, const char * string, TTFontClass *fontptr )
DrawButton::DrawButton ( int id, RECT button_rect, const char *normal, const char *focus, const char *pressed, const char * string, TTFontClass *fontptr )
{
Id = id;

Expand Down Expand Up @@ -153,7 +153,7 @@ DrawButton::DrawButton ( int id, RECT button_rect, char *normal, char *focus, ch
Msg( __LINE__, TEXT(__FILE__), TEXT(" MyRect = [%d,%d,%d,%d]"), MyRect.X, MyRect.Y, MyRect.Width, MyRect.Height );
}

DrawButton::DrawButton ( int id, RECT button_rect, char *normal, char *focus, char *pressed, const wchar_t *string, TTFontClass *fontptr )
DrawButton::DrawButton ( int id, RECT button_rect, const char *normal, const char *focus, const char *pressed, const wchar_t *string, TTFontClass *fontptr )
{
Id = id;

Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/Tools/Autorun/DrawButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class DrawButton
FOCUS_STATE
};

DrawButton ( int id, RECT button_rect, char *normal, char *focus, char *pressed, const char *string, TTFontClass *fontptr );
DrawButton ( int id, RECT button_rect, char *normal, char *focus, char *pressed, const wchar_t *string, TTFontClass *fontptr );
DrawButton ( int id, RECT button_rect, const char *normal, const char *focus, const char *pressed, const char *string, TTFontClass *fontptr );
DrawButton ( int id, RECT button_rect, const char *normal, const char *focus, const char *pressed, const wchar_t *string, TTFontClass *fontptr );

char *Return_Normal_Bitmap ( void ) { return NormalBitmap; };
char *Return_Pressed_Bitmap ( void ) { return PressedBitmap; };
Expand Down
10 changes: 5 additions & 5 deletions GeneralsMD/Code/Tools/Autorun/GETCD.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
//-----------------------------------------------------------------------------
#if ( MISSION_DISK )

static char * _CD_Volume_Label[] = {
static const char * _CD_Volume_Label[] = {
"Renegade Mission", // Yuri's Revenge (mission disk)
};

#else

static char * _CD_Volume_Label[] = {
static const char * _CD_Volume_Label[] = {
"Renegade Game", // Red Alert 2
"Renegade Data", // Red Alert 2
};
Expand Down Expand Up @@ -161,7 +161,7 @@ GetCDClass::~GetCDClass(void)
* 10/18/2000 MML: Created. *
*==============================================================================*/

int GetCDClass::Get_CD_Drive_For_This_Volume ( char *volume_label )
int GetCDClass::Get_CD_Drive_For_This_Volume ( const char *volume_label )
{
char volume_name[128] = "";
int count = 0;
Expand Down Expand Up @@ -241,7 +241,7 @@ int GetCDClass::Get_CD_Drive_For_This_Volume ( char *volume_label )
* 10/31/2000 MML: Created. * Happy Halloween! * *
*==============================================================================*/

char * GetCDClass::Get_Volume_Label ( int index )
const char * GetCDClass::Get_Volume_Label ( int index )
{
if( index >= 0 && index < _Num_Volumes ) {
return( _CD_Volume_Label[ index ]);
Expand All @@ -263,7 +263,7 @@ char * GetCDClass::Get_Volume_Label ( int index )
* 10/31/2000 MML: Created. * Happy Halloween! * *
*==============================================================================*/

char *GetCDClass::Get_Volume_For_This_CD_Drive ( char *path, char *volume_name )
const char *GetCDClass::Get_Volume_For_This_CD_Drive ( const char *path, char *volume_name )
{
char buffer[128];
unsigned misc_dword;
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/Tools/Autorun/GameText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ extern char szArgvPath[];

void GameTextManager::init( void )
{
Char *strFile = "autorun.str";
Char *csfFile = "autorun.csf";
const Char *strFile = "autorun.str";
const Char *csfFile = "autorun.csf";
Int format;

Char realStrFile[_MAX_PATH];
Expand Down
8 changes: 4 additions & 4 deletions GeneralsMD/Code/Tools/Autorun/GetCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define GETCD_H


extern char * _CD_Volume_Label[];
extern const char * _CD_Volume_Label[];
extern int _Num_Volumes;


Expand Down Expand Up @@ -209,9 +209,9 @@ class GetCDClass
inline int Get_Index ( void ) { return( CDIndex ); };
inline void Reset_Index ( void ) { CDIndex = 0; };

int Get_CD_Drive_For_This_Volume ( char *volume_name );
char * Get_Volume_For_This_CD_Drive ( char *path, char *volume_name );
char * Get_Volume_Label ( int index );
int Get_CD_Drive_For_This_Volume ( const char *volume_name );
const char * Get_Volume_For_This_CD_Drive ( const char *path, char *volume_name );
const char * Get_Volume_Label ( int index );

protected:

Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/Tools/Autorun/Locale_API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

#define MISSING_STRING_HINTS_MAX (20)

wchar_t *localeStringsMissing[ MISSING_STRING_HINTS_MAX ] =
const wchar_t *localeStringsMissing[ MISSING_STRING_HINTS_MAX ] =
{
{ L"0 MissingInstall" },
{ L"1 MissingExplore" },
Expand Down
4 changes: 4 additions & 0 deletions GeneralsMD/Code/Tools/Autorun/POINT.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ template<class T>
class TPoint3D : public TPoint2D<T> {
typedef TPoint2D<T> BASECLASS;

public:
using BASECLASS::X;
using BASECLASS::Y;

public:
TPoint3D(void) {} // Default constructor does nothing by design.
TPoint3D(T x, T y, T z) : BASECLASS(x, y), Z(z) {}
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/Tools/Autorun/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void *Load_File ( char *filename, long *filesize )
* 10/08/2001 MML : Created. *
*==========================================================================*/

char *Make_Current_Path_To ( char *filename, char *path )
char *Make_Current_Path_To ( const char *filename, char *path )
{
char szPath [ _MAX_PATH ];
char drive [ _MAX_DRIVE];
Expand All @@ -358,7 +358,7 @@ char *Make_Current_Path_To ( char *filename, char *path )
return( path );
}

wchar_t *Make_Current_Path_To ( wchar_t *filename, wchar_t *path )
wchar_t *Make_Current_Path_To ( const wchar_t *filename, wchar_t *path )
{
wchar_t szPath [ _MAX_PATH ];
wchar_t drive [ _MAX_DRIVE];
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/Tools/Autorun/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void Fix_Single_Ampersands ( wchar_t *pszString, bool upper_case );
void Fix_Double_Ampersands ( LPSTR string, bool upper_case );
void * Load_Alloc_Data ( char *filename, long *filesize=0 );
void * Load_File ( char *filename, long *filesize=0 );
char * Make_Current_Path_To ( char *filename, char *path );
wchar_t * Make_Current_Path_To ( wchar_t *filename, wchar_t *path );
char * Make_Current_Path_To ( const char *filename, char *path );
wchar_t * Make_Current_Path_To ( const wchar_t *filename, wchar_t *path );
char * Path_Add_Back_Slash ( char *path );
char * Path_Remove_Back_Slash ( char *path );
wchar_t * Path_Add_Back_Slash ( wchar_t *path );
Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/Tools/Autorun/ViewHTML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*
******************************************************************************/

bool ViewHTML(const char* url, bool wait, CallbackHook& callback)
bool ViewHTML(const char* url, bool wait, const CallbackHook& callback)
{
// DebugPrint("ViewHTML()\n");
Msg( __LINE__, TEXT(__FILE__), TEXT("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ));
Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/Tools/Autorun/ViewHTML.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@

#include "CallbackHook.h"

bool ViewHTML(const char* url, bool wait = false, CallbackHook& callback = CallbackHook());
bool ViewHTML(const char* url, bool wait = false, const CallbackHook& callback = CallbackHook());

#endif // VIEWHTML_H
Loading