Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(audio): play real sound through the game's own mss32.dll
Olcay Seygan5114774c5edd
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex 44a73c45b..0927763f0 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -376,19 +376,31 @@ file(GLOB_RECURSE GAMEENGINEDEVICE_SOURCES ${GED}/Source/*.cpp)# shipping build uses the Win32 message mouse instead).list(REMOVE_ITEM GAMEENGINEDEVICE_SOURCES${GED}/Source/Win32Device/GameClient/Win32DIMouse.cpp)-# Miles and Bink are binary-only SDKs that are not in the release, so their two-# device implementations are replaced by the null devices in Stubs/ (PLAN.md-# Phase 4: silence and skipped movies, not a launch blocker).+# Bink is a binary-only SDK that is not in the release, so its device is+# replaced by the null device in Stubs/ (PLAN.md Phase 4: skipped movies).list(REMOVE_ITEM GAMEENGINEDEVICE_SOURCES- ${GED}/Source/MilesAudioDevice/MilesAudioManager.cpp${GED}/Source/VideoDevice/Bink/BinkVideoPlayer.cpp)+# Miles is binary-only too, but the game ships mss32.dll and it exports+# decorated stdcall names (_AIL_startup@0, ...), so MilesAudioManager can bind+# to the real DLL through an import library - real audio, no SDK. Thyme's+# recipe: build a no-op stub as mss32.dll from miles.c + miles.def (the def+# mirrors the shipped DLL's export table); linking against the stub's import+# lib makes the exe resolve those names from whatever mss32.dll sits next to+# it at runtime - the game's real one. (`lib /def` alone can't produce this+# import lib: it prepends a second underscore to the already-decorated names.)+add_library(milesstub SHARED+ ${WW}/Miles6/stub/miles.c ${WW}/Miles6/stub/miles.def)+set_target_properties(milesstub PROPERTIES OUTPUT_NAME mss32)+target_include_directories(milesstub PRIVATE ${WW}/Miles6/stub ${WW}/Miles6/include)+add_library(gameenginedevice STATIC ${GAMEENGINEDEVICE_SOURCES})target_include_directories(gameenginedevice PUBLIC- ${GED}/Include ${STUBS} ${CMAKE_CURRENT_SOURCE_DIR}/Main)+ ${GED}/Include ${STUBS} ${CMAKE_CURRENT_SOURCE_DIR}/Main+ ${WW}/Miles6/include)set_target_properties(gameenginedevice PROPERTIES CXX_STANDARD 17)-target_link_libraries(gameenginedevice PUBLIC gameengine ww3d2)+target_link_libraries(gameenginedevice PUBLIC gameengine ww3d2 milesstub)# ---- generals.exe ---------------------------------------------------------# BuildVersion.h and GeneratedVersion.h are normally written by Tools/diff --git a/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.h b/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.hindex bbe411976..6dffe897c 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/Win32Device/Common/Win32GameEngine.h@@ -40,7 +40,7 @@#include "GameNetwork/NetworkInterface.h"// The Miles SDK is binary-only and absent from the source release, so the audio// device is the silent one in Stubs/ instead of MilesAudioManager.-#include "NullAudioManager.h"+#include "MilesAudioDevice/MilesAudioManager.h"#include "Win32Device/Common/Win32BIGFileSystem.h"#include "Win32Device/Common/Win32LocalFileSystem.h"#include "W3DDevice/Common/W3DModuleFactory.h"@@ -104,6 +104,6 @@ inline ParticleSystemManager* Win32GameEngine::createParticleSystemManager( voidinline NetworkInterface *Win32GameEngine::createNetwork( void ) { return NetworkInterface::createNetwork(); }inline Radar *Win32GameEngine::createRadar( void ) { return NEW W3DRadar; }inline WebBrowser *Win32GameEngine::createWebBrowser( void ) { return NEW CComObject<W3DWebBrowser>; }-inline AudioManager *Win32GameEngine::createAudioManager( void ) { return NEW NullAudioManager; }+inline AudioManager *Win32GameEngine::createAudioManager( void ) { return NEW MilesAudioManager; }#endif // end __WIN32GAMEENGINE_H_diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/.gitignore b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/.gitignoreindex a5d046be4..ba341a9b4 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/.gitignore+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/.gitignore@@ -2,8 +2,16 @@*# Except this file!.gitignore-# ...and our own hand-written Miles stub (not EA/RAD code, so it is committed:-# the real Miles SDK is binary-only and absent, and a fresh clone cannot re-fetch-# a file we wrote ourselves).+# ...and our own hand-written Miles declarations (not EA/RAD code, so they are+# committed: the real Miles SDK is binary-only and absent, and a fresh clone+# cannot re-fetch files we wrote ourselves). MSS/MSS.h is the one true header+# (reconstructed API surface); Mss.h and stub/mss/mss.h just forward to it.!include/!include/Mss.h+!include/MSS/+!include/MSS/MSS.h+!stub/+!stub/mss/+!stub/mss/mss.h+# stub/miles.c, stub/miles.def, stub/cleanup.c stay unvendored: they are+# re-fetched from Thyme (see CLAUDE.md), with one local patch documented there.diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.h b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.hnew file mode 100644index 000000000..5a5402b5d--- /dev/null+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/MSS/MSS.h@@ -0,0 +1,233 @@+/*+ * Miles Sound System 6.5 declarations, reconstructed - not the SDK header.+ *+ * The real SDK is binary-only and absent, but the game ships mss32.dll and it+ * exports decorated stdcall names (_AIL_startup@0, ...), so the exe can bind to+ * it directly through an import library generated from stub/miles.def. This+ * header declares just the surface MilesAudioManager.cpp and the WWAudio+ * headers touch.+ *+ * Sources of truth, in order:+ * - stub/miles.def (from Thyme, github.com/TheAssemblyArmada/Thyme) - the+ * stdcall @N byte counts validate every signature's argument bytes against+ * the real DLL's export table (dumpbin /exports on the shipped mss32.dll+ * matches this def name for name);+ * - Thyme's deps/miles/miles.h - signatures reverse-engineered against this+ * same game;+ * - a public copy of the Miles 6.0 mss.h - constants (speaker types, pipeline+ * stages, HPROENUM_FIRST) and the AIL_MSS_version macro. The 5.1/7.1+ * speaker values are 6.5 additions that continue the 6.0 sequence; they only+ * select a speaker layout, so a mismatch cannot corrupt anything.+ */++#ifndef MSS_H+#define MSS_H++/* The real Mss.H pulls in the Windows multimedia headers; WWAudio relies on+ * that for LPWAVEFORMAT in its Miles-facing signatures. */+#include <windows.h>+#include <mmsystem.h>++#define AILCALL __stdcall+#ifndef AILCALLBACK+#define AILCALLBACK __stdcall+#endif++/* Miles' scalar names are the long family (S32 = signed long), and the game+ * passes long* where the API wants S32* - keep the real SDK's choice. */+typedef signed char S8;+typedef unsigned char U8;+typedef signed short S16;+typedef unsigned short U16;+typedef signed long S32;+typedef unsigned long U32;+typedef float F32;+typedef double F64;+typedef char C8;++/* Opaque Miles handles. The real SDK declares these as pointers to undefined+ * structs; keep that shape so `= NULL` and pointer comparisons still compile.+ * A 3D sample IS a positionable object in Miles: H3DSAMPLE aliases H3DPOBJECT+ * (the game passes samples to AIL_set_3D_position et al). */+struct _AIL_DIGDRIVER; typedef struct _AIL_DIGDRIVER *HDIGDRIVER;+struct _AIL_SAMPLE; typedef struct _AIL_SAMPLE *HSAMPLE;+struct _AIL_STREAM; typedef struct _AIL_STREAM *HSTREAM;+struct _AIL_3DPOBJECT; typedef struct _AIL_3DPOBJECT *H3DPOBJECT;+typedef H3DPOBJECT H3DSAMPLE;+struct _AIL_TIMER; typedef struct _AIL_TIMER *HTIMER;+struct _AIL_AUDIO; typedef struct _AIL_AUDIO *HAUDIO;+struct _AIL_MDIDRIVER; typedef struct _AIL_MDIDRIVER *HMDIDRIVER;+struct _AIL_DLSDEVICE; typedef struct _AIL_DLSDEVICE *HDLSDEVICE;++/* mmsystem.h leaves the compressed-format tags to mmreg.h. */+#ifndef WAVE_FORMAT_IMA_ADPCM+#define WAVE_FORMAT_IMA_ADPCM 0x0011+#endif++/* Providers are enumerated by value, not by pointer. */+typedef U32 HPROVIDER;+typedef U32 HPROENUM;+#define HPROENUM_FIRST 0+typedef S32 M3DRESULT;++typedef void *AILLPDIRECTSOUND;+typedef void *AILLPDIRECTSOUNDBUFFER;++/* 3D speaker types (AIL_set_3D_speaker_type). 0-3 are verbatim Miles 6.0;+ * 4-5 are the 6.5 additions continuing the sequence. */+#define AIL_3D_2_SPEAKER 0+#define AIL_3D_HEADPHONE 1+#define AIL_3D_SURROUND 2+#define AIL_3D_4_SPEAKER 3+#define AIL_3D_51_SPEAKER 4+#define AIL_3D_71_SPEAKER 5++/* Digital pipeline stages (AIL_set_sample_processor). */+typedef enum+{+ DP_ASI_DECODER = 0, /* Must be "ASI codec stream" provider */+ DP_FILTER, /* Must be "MSS pipeline filter" provider */+ DP_MERGE, /* Must be "MSS mixer" provider */+ N_SAMPLE_STAGES,+ SAMPLE_ALL_STAGES+} SAMPLESTAGE;++/* AIL_WAV_info / AIL_decompress_ADPCM exchange this. */+typedef struct _AILSOUNDINFO+{+ S32 format;+ const void *data_ptr;+ U32 data_len;+ U32 rate;+ S32 bits;+ S32 channels;+ U32 samples;+ U32 block_size;+ const void *initial_ptr;+} AILSOUNDINFO;++/* Callback shapes as the game defines them (typed handles, U32 file handles). */+typedef void (AILCALLBACK *AILSAMPLECB) (HSAMPLE sample);+typedef void (AILCALLBACK *AIL3DSAMPLECB) (H3DSAMPLE sample);+typedef void (AILCALLBACK *AILSTREAMCB) (HSTREAM stream);+typedef U32 (AILCALLBACK *AILFILEOPENCB) (const char *filename, U32 *file_handle);+typedef void (AILCALLBACK *AILFILECLOSECB)(U32 file_handle);+typedef S32 (AILCALLBACK *AILFILESEEKCB) (U32 file_handle, S32 offset, U32 type);+typedef U32 (AILCALLBACK *AILFILEREADCB) (U32 file_handle, void *buffer, U32 bytes);++/* Thyme's stub miles.c spells the same callback types this way. */+typedef AILSAMPLECB AIL_sample_callback;+typedef AIL3DSAMPLECB AIL_3dsample_callback;+typedef AILSTREAMCB AIL_stream_callback;+typedef AILFILEOPENCB AIL_file_open_callback;+typedef AILFILECLOSECB AIL_file_close_callback;+typedef AILFILESEEKCB AIL_file_seek_callback;+typedef AILFILEREADCB AIL_file_read_callback;++/* The version string lives in the DLL's string table, resource id 1; the real+ * header reads it the same way instead of importing a function. */+#define MSSDLLNAME "MSS32.DLL"+#define AIL_MSS_version(str, len) \+{ \+ HINSTANCE mssvl = LoadLibraryA(MSSDLLNAME); \+ if (mssvl == NULL) \+ *(str) = 0; \+ else { \+ LoadStringA(mssvl, 1, str, len); \+ FreeLibrary(mssvl); \+ } \+}++#ifdef __cplusplus+extern "C" {+#endif++/* ---- startup / global ------------------------------------------------- */+S32 AILCALL AIL_startup(void);+void AILCALL AIL_shutdown(void);+S32 AILCALL AIL_quick_startup(S32 use_digital, S32 use_MIDI, U32 output_rate, S32 output_bits, S32 output_channels);+void AILCALL AIL_quick_handles(HDIGDRIVER *pdig, HMDIDRIVER *pmdi, HDLSDEVICE *pdls);+char * AILCALL AIL_set_redist_directory(const char *dir);+void AILCALL AIL_lock(void);+void AILCALL AIL_unlock(void);+S32 AILCALL AIL_get_timer_highest_delay(void);+void AILCALL AIL_set_file_callbacks(AILFILEOPENCB opencb, AILFILECLOSECB closecb, AILFILESEEKCB seekcb, AILFILEREADCB readcb);++/* ---- providers / filters ---------------------------------------------- */+S32 AILCALL AIL_enumerate_3D_providers(HPROENUM *next, HPROVIDER *dest, char **name);+S32 AILCALL AIL_open_3D_provider(HPROVIDER lib);+void AILCALL AIL_close_3D_provider(HPROVIDER lib);+S32 AILCALL AIL_enumerate_filters(HPROENUM *next, HPROVIDER *dest, char **name);+void AILCALL AIL_set_3D_speaker_type(HPROVIDER lib, S32 speaker_type);+HPROVIDER AILCALL AIL_set_sample_processor(HSAMPLE sample, S32 pipeline_stage, HPROVIDER provider);+void AILCALL AIL_set_filter_sample_preference(HSAMPLE sample, const char *name, const void *val);++/* ---- 2D samples -------------------------------------------------------- */+HSAMPLE AILCALL AIL_allocate_sample_handle(HDIGDRIVER dig);+void AILCALL AIL_release_sample_handle(HSAMPLE sample);+void AILCALL AIL_init_sample(HSAMPLE sample);+S32 AILCALL AIL_set_sample_file(HSAMPLE sample, const void *file_image, S32 block);+void AILCALL AIL_start_sample(HSAMPLE sample);+void AILCALL AIL_stop_sample(HSAMPLE sample);+void AILCALL AIL_resume_sample(HSAMPLE sample);+void AILCALL AIL_end_sample(HSAMPLE sample);+void AILCALL AIL_set_sample_volume_pan(HSAMPLE sample, F32 volume, F32 pan);+void AILCALL AIL_sample_volume_pan(HSAMPLE sample, F32 *volume, F32 *pan);+void AILCALL AIL_set_sample_playback_rate(HSAMPLE sample, S32 playback_rate);+S32 AILCALL AIL_sample_playback_rate(HSAMPLE sample);+void AILCALL AIL_set_sample_user_data(HSAMPLE sample, U32 index, S32 value);+S32 AILCALL AIL_sample_user_data(HSAMPLE sample, U32 index);+AILSAMPLECB AILCALL AIL_register_EOS_callback(HSAMPLE sample, AILSAMPLECB EOS);+void AILCALL AIL_get_DirectSound_info(HSAMPLE sample, AILLPDIRECTSOUND *lplpDS, AILLPDIRECTSOUNDBUFFER *lplpDSB);++/* ---- 3D samples -------------------------------------------------------- */+H3DSAMPLE AILCALL AIL_allocate_3D_sample_handle(HPROVIDER lib);+void AILCALL AIL_release_3D_sample_handle(H3DSAMPLE sample);+S32 AILCALL AIL_set_3D_sample_file(H3DSAMPLE sample, const void *file_image);+void AILCALL AIL_start_3D_sample(H3DSAMPLE sample);+void AILCALL AIL_stop_3D_sample(H3DSAMPLE sample);+void AILCALL AIL_resume_3D_sample(H3DSAMPLE sample);+void AILCALL AIL_end_3D_sample(H3DSAMPLE sample);+void AILCALL AIL_set_3D_sample_volume(H3DSAMPLE sample, F32 volume);+void AILCALL AIL_set_3D_sample_playback_rate(H3DSAMPLE sample, S32 playback_rate);+S32 AILCALL AIL_3D_sample_playback_rate(H3DSAMPLE sample);+void AILCALL AIL_set_3D_sample_distances(H3DSAMPLE sample, F32 max_dist, F32 min_dist);+void AILCALL AIL_set_3D_sample_occlusion(H3DSAMPLE sample, F32 occlusion);+void AILCALL AIL_set_3D_user_data(H3DPOBJECT obj, U32 index, S32 value);+S32 AILCALL AIL_3D_user_data(H3DPOBJECT obj, U32 index);+AIL3DSAMPLECB AILCALL AIL_register_3D_EOS_callback(H3DSAMPLE sample, AIL3DSAMPLECB EOS);++/* ---- 3D positioning ---------------------------------------------------- */+H3DPOBJECT AILCALL AIL_open_3D_listener(HPROVIDER lib);+void AILCALL AIL_close_3D_listener(H3DPOBJECT listener);+void AILCALL AIL_set_3D_position(H3DPOBJECT obj, F32 X, F32 Y, F32 Z);+void AILCALL AIL_set_3D_orientation(H3DPOBJECT obj, F32 X_face, F32 Y_face, F32 Z_face, F32 X_up, F32 Y_up, F32 Z_up);+void AILCALL AIL_set_3D_velocity_vector(H3DPOBJECT obj, F32 dX, F32 dY, F32 dZ);++/* ---- streams ----------------------------------------------------------- */+HSTREAM AILCALL AIL_open_stream(HDIGDRIVER dig, const char *filename, S32 stream_mem);+void AILCALL AIL_close_stream(HSTREAM stream);+void AILCALL AIL_start_stream(HSTREAM stream);+void AILCALL AIL_pause_stream(HSTREAM stream, S32 onoff);+void AILCALL AIL_set_stream_loop_count(HSTREAM stream, S32 count);+S32 AILCALL AIL_stream_loop_count(HSTREAM stream);+void AILCALL AIL_set_stream_volume_pan(HSTREAM stream, F32 volume, F32 pan);+void AILCALL AIL_stream_volume_pan(HSTREAM stream, F32 *volume, F32 *pan);+void AILCALL AIL_stream_ms_position(HSTREAM stream, S32 *total_milliseconds, S32 *current_milliseconds);+AILSTREAMCB AILCALL AIL_register_stream_callback(HSTREAM stream, AILSTREAMCB callback);++/* ---- quick API (music) ------------------------------------------------- */+HAUDIO AILCALL AIL_quick_load_and_play(const char *filename, U32 loop_count, S32 wait_request);+void AILCALL AIL_quick_unload(HAUDIO audio);+void AILCALL AIL_quick_set_volume(HAUDIO audio, F32 volume, F32 extravol);++/* ---- file format helpers ---------------------------------------------- */+S32 AILCALL AIL_WAV_info(const void *data, AILSOUNDINFO *info);+S32 AILCALL AIL_decompress_ADPCM(const AILSOUNDINFO *info, void **outdata, U32 *outsize);+void AILCALL AIL_mem_free_lock(void *ptr);++#ifdef __cplusplus+} /* extern "C" */+#endif++#endif /* MSS_H */diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/Mss.h b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/Mss.hindex eab9e37d7..eceb953b4 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/Mss.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/include/Mss.h@@ -1,50 +1,8 @@/*- * Minimal Miles Sound System 6 stub header.- *- * The real Miles SDK is binary-only and absent from this repo (Libraries/Source/- * WWVegas/Miles6 is gitignored, like the other stripped SDKs). WWAudio headers- * pull Mss.H in for a handful of opaque handles and scalar typedefs only, so the- * declarations below are enough to compile everything the ww3d2 target reaches- * (soundrobj.cpp -> wwaudio.h). No audio actually plays.- *- * ponytail: stub sized to what WWAudio/*.h references today; grow it per missing- * symbol when Phase 4 links MilesAudioDevice, or drop it entirely if a real- * audio backend (OpenAL/miniaudio) replaces Miles.+ * Compatibility shim: WWAudio includes <Mss.H> flat, MilesAudioManager includes+ * "MSS/MSS.h" - one header serves both. See MSS/MSS.h for provenance.*/--#ifndef MSS_H-#define MSS_H--/* The real Mss.H pulls in the Windows multimedia headers; WWAudio relies on that- * for LPWAVEFORMAT in its Miles-facing signatures. */-#include <windows.h>-#include <mmsystem.h>--#ifndef AILCALLBACK-#define AILCALLBACK __stdcall+#ifndef MSS_FLAT_H+#define MSS_FLAT_H+#include "MSS/MSS.h"#endif--typedef signed char S8;-typedef unsigned char U8;-typedef signed short S16;-typedef unsigned short U16;-typedef signed int S32;-typedef unsigned int U32;-typedef float F32;-typedef double F64;--/* Opaque Miles handles. The real SDK declares these as pointers to undefined- * structs; keep that shape so `= NULL` and pointer comparisons still compile. */-struct _AIL_DIGDRIVER; typedef struct _AIL_DIGDRIVER *HDIGDRIVER;-struct _AIL_SAMPLE; typedef struct _AIL_SAMPLE *HSAMPLE;-struct _AIL_STREAM; typedef struct _AIL_STREAM *HSTREAM;-struct _AIL_PROVIDER; typedef struct _AIL_PROVIDER *HPROVIDER;-struct _AIL_3DSAMPLE; typedef struct _AIL_3DSAMPLE *H3DSAMPLE;-struct _AIL_3DPOBJECT; typedef struct _AIL_3DPOBJECT *H3DPOBJECT;-struct _AIL_TIMER; typedef struct _AIL_TIMER *HTIMER;--/* Global mutex around the Miles mixer; WWAudio/Utils.h wraps it in MMSLockClass. */-void AIL_lock(void);-void AIL_unlock(void);--#endif /* MSS_H */diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/stub/mss/mss.h b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/stub/mss/mss.hnew file mode 100644index 000000000..d48cd9a08--- /dev/null+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/stub/mss/mss.h@@ -0,0 +1,4 @@+/* The stub's miles.c is the W3D-flavored Thyme variant and expects the same+ * declarations the game compiles against - use the one true header. Relative+ * path on purpose: "MSS/MSS.h" would resolve back to this very file. */+#include "../../include/MSS/MSS.h"