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
fix(gameengine): mod path checks, camera tilt, crash and sound fixes
Olcay Seygan215996026046
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9feb93b67..1628f84a7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -42,6 +42,7 @@ found and fixed — EA's own, not port damage.**- A Paladin under Contra no longer crashes the game. Reforged gives every Paladin a second laser for infantry, and that laser borrowed a Zero Hour weapon nothing else fires. Contra deleted it, so the laser had no gun, and the game went down a moment after the first Paladin rolled out. The laser is Reforged's own weapon now and is there whatever mod you load. The same kind of gap took the guns off Contra's Toxin Tunnel Defender and Toxin Stinger soldier, the Chemical Suits off its Rangers, and the death blast off its Demolition Scud Launcher, Toxin demo trap and Toxin Tractors (ShockWave's trap too). Where Reforged names a weapon or armour the mod dropped, the unit now keeps the mod's own, and the death blasts carry Zero Hour's charge.- Contra's units have their attack move, guard and stop buttons again, and A, G and S press them. Contra draws its command bar with eighteen buttons and keeps those three in the last row, which our fourteen-button bar does not have, so they went missing on every Contra unit, the Cybernetic general's cyborgs among them. A button a mod puts past the end of our bar now moves to an empty one, the three orders to the places Zero Hour gives them.- Contra's cyborgs no longer stand on black squares. Their little ground shadow is drawn the way Zero Hour draws it again, darkening the ground by the shape painted in the picture, so it comes out as a soft patch under the feet. We had been reading the shape from the picture's transparency instead, and Contra's shadow picture has none: it filled its whole square. Zero Hour's own shadows look as they did.+- A `-mod` path with `.` or `..` in it is refused. An archive counts as your mod's only when it was loaded for that mod. Two mods under `-modfactions` that define a command set with the same name both load now, and the later one wins.## One interface@@ -353,6 +354,8 @@ found and fixed — EA's own, not port damage.**- Ctrl+D takes every unit of the kinds you have selected that is on the screen, and pressed twice inside half a second takes them across the whole map. One tank selected and two keystrokes is your whole armour, wherever it is standing. It was on Shift+Ctrl+E, which is three fingers for something you do in every fight, and it only ever reached across the map when the screen had nothing left to give - so the wide selection happened to you instead of being asked for.- U takes you to the next combat unit standing with no orders: it is selected and the view centres on it. Press again for the one after. Idle workers stay on I.- Shift and a number puts what you have selected into that control group and keeps everyone already in it, the way StarCraft does it. Fresh tanks off the line join group 1 with one key, where you used to select group 1, shift-click the new tanks in and press Ctrl+1 again. The selection stays as it is. Retail used Shift and a number to pull a group into your selection instead; that is gone, and Alt and the number still centres the view on the group.+- Ordering a very large army works. A selection of more than 254 units reaches the game whole, and Ctrl+number groups keep all their units.+- Hold Alt and drag with the middle mouse button, or hold Alt and turn the wheel, to tilt the camera between 20 and 60 degrees. Home resets heading, tilt and zoom, the way Numpad 5 does.## Aircraft, guards, and orders that used to be ignored@@ -1129,6 +1132,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- Switch it mid-match and the map repaints itself. So does the picture when an alliance is made or broken by a map script.- A building being captured flashes in the capturer's colour from the setting too. It used to blink in the capturer's original colour while that player's units, radar dots and capture clock showed the new one. The flash on a selected unit and the flashes a mission script asks for follow the setting the same way.## You can see where your ally is pointing+- Vote kick. Type /kick and a name in chat to start a 30-second vote. It passes only when every other living player answers /yes, and it needs at least two voters besides the one being voted on.- Your ally's mouse is on your map: a soft pool of their own player colour on the ground where it rests, with their name across the middle of it. No second arrow on your screen - one is confusing enough, and the name is the part that says whose it is.- Two people playing together spend half the match describing places to each other. "Behind the oil derrick, no, the other one" is a sentence nobody has to type when you can watch where they are pointing while they say it.@@ -1622,6 +1626,14 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- A missing save folder no longer costs you maps. The game listed the folder it runs from instead, and the tidy-up after a match deleted the .map files it found there.- Screenshots come out straight at any width. At 1366 wide each row slid sideways, and at any width that does not divide by eight the game read past the end of the picture.- Quitting the Windows game under Proton, the way a Steam Deck used to run it, no longer crashes on the way out.+- A full disk or a crash in the middle of a save no longer destroys the earlier save in that slot. A broken or tampered save is refused instead of crashing the game or overwriting other files, and a save from the original game or from an older Reforged version is refused with a clear message.+- A Chinook or Helix repaired at an airfield no longer takes off while infantry are still boarding or getting out.+- A rare crash when infantry thrown out of a transport were in the middle of an attack is fixed.+- A Battle Bus under a damage-reducing bonus such as Hold the Line no longer loses its first life to a hit it would have survived.+- On AMD X3D processors with two halves, the 7950X3D and the 9950X3D, the game runs on the half with the big cache.+- Another player can no longer make your game write files the host never announced, rewrite or remove someone else's LAN game, crash you with a malformed network or lobby message, or flood your memory with oversized commands. A command with an invalid weapon slot is refused.+- Crash fixes: ordering an upgrade with a Supply Drop Zone, a GLA Hole or a captured Oil Derrick selected, a map that shows a counter it never set, a camera shake at a waypoint that is not there, and closing a menu while it animates. A map message with a percent sign in it shows as written.+- Stopped sounds really stop. A destroyed unit's engine loop and a turret's turning loop no longer play on, and the Idle Worker tooltip shows its key.## Units take corners wide, and drive round a jam instead of into itdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h b/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.hindex 573e707a3..e06477175 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ArchiveFileSystem.h@@ -174,6 +174,8 @@ class ArchiveFileSystem : public SubsystemInterface// Unprotected this for copy-protection routinesAsciiString getArchiveFilenameForFile(const AsciiString& filename) const;void loadMods( void );+ /// the -mod or -modpatch path, exactly as given, that loadMods loaded this archive for; empty for retail's+ AsciiString modLayerOf( const AsciiString& archiveFilename ) const;/// FileSystem::setFocus: a -mod index sees that mod's archives alone. FILE_FOCUS_ALL is the merged/// tree, which -modfactions leaves as retail's and FILE_FOCUS_RETAIL always is.@@ -199,6 +201,7 @@ protected:ArchivedDirectoryInfo m_rootDirectory;std::vector<ArchivedDirectoryInfo> m_modRoots; ///< -modfactions: each -mod's archives alone, in its own orderstd::map<AsciiString, Int> m_archiveMod; ///< -modfactions: archive -> -mod index; retail's are not in it+ std::map<AsciiString, AsciiString> m_archiveLayer; ///< archive -> the -mod or -modpatch path that loaded it (modLayerOf)Int m_focus;};diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowTransitions.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowTransitions.hindex 367ec463d..8b93cee63 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowTransitions.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameWindowTransitions.h@@ -125,7 +125,10 @@ public:virtual void draw( void ) = 0;virtual void skip( void ) = 0;-++ /// does this transition hold `win`, so that it must not run once `win` is destroyed+ virtual Bool usesWindow( const GameWindow *win ) const { return m_win == win; }+Bool isFinished( void ) { return m_isFinished; }Int getFrameLength( void ){ return m_frameLength; }protected:@@ -349,6 +352,8 @@ protected:ICoord2D m_incrementPos;ICoord2D m_incrementSize;GameWindow *m_growWin;+public:+ virtual Bool usesWindow( const GameWindow *win ) const { return m_win == win || m_growWin == win; }};@@ -378,6 +383,8 @@ protected:ICoord2D m_growSize;ICoord2D m_incrementSize;GameWindow *m_growWin;+public:+ virtual Bool usesWindow( const GameWindow *win ) const { return m_win == win || m_growWin == win; }};//-----------------------------------------------------------------------------@@ -402,7 +409,7 @@ protected:MAINMENUSMALLSCALEDOWNTRANSITION_3 = 3,MAINMENUSMALLSCALEDOWNTRANSITION_4 = 4,MAINMENUSMALLSCALEDOWNTRANSITION_5 = 5,- MAINMENUSMALLSCALEDOWNTRANSITION_END+ MAINMENUSMALLSCALEDOWNTRANSITION_END};ICoord2D m_pos;ICoord2D m_size;@@ -411,6 +418,8 @@ protected:ICoord2D m_growSize;ICoord2D m_incrementSize;GameWindow *m_growWin;+public:+ virtual Bool usesWindow( const GameWindow *win ) const { return m_win == win || m_growWin == win; }};//-----------------------------------------------------------------------------@@ -611,6 +620,7 @@ public:Int getTotalFrames( void );void skip( void );void draw( void );+ void forgetWindow( const GameWindow *win );// INI parsed varsAsciiString m_winName;@@ -641,6 +651,7 @@ public:AsciiString getName( void ) { return m_name; }void setName( AsciiString name){ m_name = name; }void addWindow( TransitionWindow *transWin );+ void forgetWindow( const GameWindow *win );Bool isReversed( void );Bool isFireOnce( void ) { return m_fireOnce; }Bool m_fireOnce;@@ -675,6 +686,7 @@ public:void setGroup(AsciiString groupName, Bool immidiate = FALSE); // THis will be the next group to fire off.void reverse( AsciiString groupName );// reverse the animations for the current group.void remove( AsciiString groupName, Bool skipPending = FALSE );// remove the animation from the current or pending groups.+ void forgetWindow( const GameWindow *win ); ///< a window is being destroyed: no transition may touch it againTransitionGroup *getNewGroup( AsciiString name );private:TransitionGroup *findGroup( AsciiString groupName );diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.hindex babde2516..378c43a22 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h@@ -87,6 +87,10 @@ private:extern LookAtTranslator *TheLookAtTranslator;+/** A view pitch kept where the player's own tilt (Alt+middle drag, Alt+wheel) may put it: the+ * camera between 20 and 60 degrees above the ground. */+extern Real LookAt_clampPlayerPitch( Real pitch );+// EDGE SCROLL ////////////////////////////////////////////////////////////////////////////////////// The map scrolls while the pointer is in a band along the screen's edges, faster the deeper in// it goes. Free functions so the arithmetic can be tested without a display.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex b47a8ecc8..f6b3d23c4 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -2620,6 +2620,16 @@ static Int addMod(char *args[], Int num, Bool isPatch)if (TheWritableGlobalData && num > 1){AsciiString modPath = args[1];+ // "." or ".." as a part would let a relative -mod climb out of the user folder, and give one+ // folder two names that the file system's prefix and archive checks read as two mods+ std::string parts( modPath.str() );+ std::replace( parts.begin(), parts.end(), '/', '\\' );+ parts = "\\" + parts + "\\";+ if (parts.find( "\\.\\" ) != std::string::npos || parts.find( "\\..\\" ) != std::string::npos)+ {+ DEBUG_LOG(("Mod path '%s' is refused: it holds a '.' or '..' part.\n", modPath.str()));+ return 2;+ }if (strchr(modPath.str(), ':') || modPath.startsWith("/") || modPath.startsWith("\\")){// full path passed in. Don't append base path.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cppindex 593024cc6..4e6667635 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ArchiveFileSystem.cpp@@ -247,6 +247,7 @@ void ArchiveFileSystem::loadMods() {continue;}DEBUG_LOG(("ArchiveFileSystem::loadMods - loading %s into the directory tree.\n", it->str()));+ m_archiveLayer[*it] = mod;addModArchive(layers[layer].first, archiveFile, *it);}}@@ -258,6 +259,12 @@ void ArchiveFileSystem::loadMods() {}}+AsciiString ArchiveFileSystem::modLayerOf(const AsciiString& archiveFilename) const+{+ std::map<AsciiString, AsciiString>::const_iterator it = m_archiveLayer.find(archiveFilename);+ return it == m_archiveLayer.end() ? AsciiString() : it->second;+}+void ArchiveFileSystem::keepModsApart(size_t modCount){m_modRoots.assign(modCount, ArchivedDirectoryInfo());diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cppindex 0420e584b..2ff081682 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp@@ -465,9 +465,11 @@ AsciiString FileSystem::modLooseFile(const AsciiString& filename, Bool *inModArc}// The last -mod that has the file wins, whether it has it loose or in an archive: a later mod's- // .big beats an earlier mod's loose copy. An archive key is the -mod path itself, or that folder- // followed by the archive's name (loadMods).+ // .big beats an earlier mod's loose copy. An archive is a mod's when loadMods loaded it for that+ // mod, not when its name merely starts with the mod's folder: a -mod naming the install folder, or+ // a folder above another -mod's, claimed every archive under it by the text alone.const AsciiString archive = TheArchiveFileSystem->getArchiveFilenameForFile(filename);+ const AsciiString archiveLayer = TheArchiveFileSystem->modLayerOf(archive);AsciiString loose;Bool archived = FALSE;for (size_t i = mods.size(); i-- > 0 && loose.isEmpty() && !archived; )@@ -484,7 +486,7 @@ AsciiString FileSystem::modLooseFile(const AsciiString& filename, Bool *inModArcbreak;}}- archived = archive.isNotEmpty() && (isFolder ? archive.startsWithNoCase(mod.str()) : archive.compareNoCase(mod) == 0);+ archived = archiveLayer.isNotEmpty() && archiveLayer.compareNoCase(mod) == 0;}// ...except over a file the fork ships: retail < mods < the fork. That copy is the one the installdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex 76e95010a..7992098dd 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -3642,6 +3642,14 @@ CommandButton *ControlBar::newCommandButtonOverride( CommandButton *buttonToOver// a patch file's set replaces the set whole, in place, so every pointer to it stays goodcommandSet->friend_clearCommands();}+ else if( ini->getLoadType() == INI_LOAD_OVERWRITE )+ {+ // two mods under -modfactions can both name a set "CommandSet GLA" once their Side names are+ // stripped; the later one wins, as a patch file's does, instead of refusing the whole load+ DEBUG_LOG(( "[LINE: %d in '%s'] commandset %s defined again, the later one replaces it\n",+ ini->getLineNum(), ini->getFilename().str(), name.str() ));+ commandSet->friend_clearCommands();+ }else if( ini->getLoadType() != INI_LOAD_CREATE_OVERRIDES ){//Holy crap, this sucks to debug!!!diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cppindex fd10a4bfa..5bdf359df 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp@@ -88,6 +88,7 @@#include "GameClient/GameText.h"#include "GameClient/GUICallbacks.h"#include "GameClient/InGameUI.h"+#include "GameClient/MetaEvent.h"#include "GameClient/ControlBar.h"#include "GameClient/DisplayStringManager.h"#include "GameLogic/GameLogic.h"@@ -113,6 +114,41 @@ static AnimateWindowManager *theAnimateWindowManager = NULL;static GameWindow *prevWindow = NULL;static Bool useAnimation = FALSE;+//-------------------------------------------------------------------------------------------------+/** " (Ctrl+Shift+I)" for the key the player's command map gives a meta event in a match, empty for+ * one with no key. The Idle Worker button has no letter of its own: its key is a chord in the+ * command map, so the tooltip is the only place the button can say what it is. */+//-------------------------------------------------------------------------------------------------+static UnicodeString metaKeySuffix( GameMessage::Type meta )+{+ UnicodeString suffix;+ for( const MetaMapRec *rec = TheMetaMap->getFirstMetaMapRec(); rec; rec = rec->m_next )+ {+ if( rec->m_meta != meta || rec->m_transition != DOWN || !( rec->m_usableIn & COMMANDUSABLE_GAME ) )+ continue;++ const char *keyName = NULL;+ for( const LookupListRec *k = KeyNames; k->name; ++k )+ if( k->value == rec->m_key )+ keyName = k->name + 4; // past "KEY_"+ if( keyName == NULL || rec->m_key == MK_NONE )+ continue;++ AsciiString text( " (" );+ if( rec->m_modState & CTRL )+ text.concat( "Ctrl+" );+ if( rec->m_modState & ALT )+ text.concat( "Alt+" );+ if( rec->m_modState & SHIFT )+ text.concat( "Shift+" );+ text.concat( keyName );+ text.concat( ")" );+ suffix.translate( text );+ break;+ }+ return suffix;+}+//-------------------------------------------------------------------------------------------------/** What the build tooltip says beyond retail's name, price and description, piece by piece, the* way Reforged's card laid it out; ControlBarPopupDescription.wnd gets it as lines of its text. */@@ -1109,6 +1145,8 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,GameWindow *win = TheWindowManager->winGetWindowFromId(m_buildToolTipLayout->getFirstWindow(), TheNameKeyGenerator->nameToKey("ControlBarPopupDescription.wnd:StaticTextName"));if(win){+ if( commandButton && commandButton->getName() == "NonCommand_IdleWorker" )+ name.concat( metaKeySuffix( GameMessage::MSG_META_SELECT_NEXT_IDLE_WORKER ) );GadgetStaticTextSetText(win, name);}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cppindex 615fbfa2b..ec20a2c36 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowManager.cpp@@ -1521,6 +1521,10 @@ Int GameWindowManager::winDestroy( GameWindow *window )if( m_grabWindow == window )m_grabWindow = NULL;+ // a menu closed mid-transition: the transition must not run on the window once it is freed+ if( TheTransitionHandler )+ TheTransitionHandler->forgetWindow( window );+for( child = window->m_child; child; child = next ){next = child->m_next;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowTransitions.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowTransitions.cppindex 0361ce597..19642b00d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowTransitions.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GameWindowTransitions.cpp@@ -189,11 +189,25 @@ Bool TransitionWindow::init( void )void TransitionWindow::update( Int frame ){- if(frame < m_currentFrameDelay || frame > (m_currentFrameDelay + m_transition->getFrameLength()))+ if(!m_transition || frame < m_currentFrameDelay || frame > (m_currentFrameDelay + m_transition->getFrameLength()))return;-- if(m_transition)- m_transition->update( frame - m_currentFrameDelay);++ m_transition->update( frame - m_currentFrameDelay);+}++//-----------------------------------------------------------------------------+/** A menu closed while its windows were still animating freed them, and the next+ * GameWindowManager::update ran the transition on the freed window straight after the destroy+ * pass. The transition goes with its window; the group's next init builds it again from the+ * window found by name then. */+void TransitionWindow::forgetWindow( const GameWindow *win )+{+ if( m_transition && m_transition->usesWindow( win ) )+ {+ delete m_transition;+ m_transition = NULL;+ m_win = NULL;+ }}Bool TransitionWindow::isFinished( void )@@ -270,6 +284,12 @@ void TransitionGroup::init( void )}+void TransitionGroup::forgetWindow( const GameWindow *win )+{+ for( TransitionWindowList::iterator it = m_transitionWindowList.begin(); it != m_transitionWindowList.end(); ++it )+ (*it)->forgetWindow( win );+}+void TransitionGroup::update( void ){//@@ -509,6 +529,8 @@ void GameWindowTransitionsHandler::setGroup(AsciiString groupName, Bool immidiatvoid GameWindowTransitionsHandler::reverse( AsciiString groupName ){TransitionGroup *g = findGroup(groupName);+ if(!g)+ return; // a group no WindowTransitions.ini names; with nothing playing this was a call through NULLif( m_currentGroup == g ){m_currentGroup->reverse();@@ -531,6 +553,12 @@ void GameWindowTransitionsHandler::reverse( AsciiString groupName )m_pendingGroup = NULL;}+void GameWindowTransitionsHandler::forgetWindow( const GameWindow *win )+{+ for( TransitionGroupList::iterator it = m_transitionGroupList.begin(); it != m_transitionGroupList.end(); ++it )+ (*it)->forgetWindow( win );+}+void GameWindowTransitionsHandler::remove( AsciiString groupName, Bool skipPending ){TransitionGroup *g = findGroup(groupName);diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 9fdb03f4c..010412fb7 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -3650,7 +3650,10 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessageTheInGameUI->setCameraZoomOut( false );break;case GameMessage::MSG_META_CAMERA_RESET:- TheInGameUI->resetCamera();+ // the same home view as a middle click: InGameUI::resetCamera eased the scripted pitch+ // factor back but left the player's own tilt where Alt+drag or Alt+wheel put it.+ TheTacticalView->setAngleAndPitchToDefault();+ TheTacticalView->setZoomToDefault();break;case GameMessage::MSG_META_TOGGLE_CAMERA_TRACKING_DRAWABLE:TheInGameUI->setCameraTrackingDrawable( true );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cppindex b22d2a776..f3acbd9dd 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp@@ -80,6 +80,27 @@ static const Int edgeScrollSize = 3;// farthest is about fifteen notches, so three of these cross it.static const Real CTRL_WHEEL_ZOOM_NOTCHES = 5.0f;+// Alt+wheel tilts the camera this far a notch.+static const Real TILT_PER_NOTCH = 2.0f * PI / 180.0f;++//-----------------------------------------------------------------------------+/** The player's tilt keeps the camera between 20 and 60 degrees above the ground. The view's+ * pitch is an offset from GameData's CameraPitch, and a larger pitch lays the camera flatter,+ * so the elevation it gives is CameraPitch minus the pitch. */+//-----------------------------------------------------------------------------+Real LookAt_clampPlayerPitch( Real pitch )+{+ const Real DEGREES = PI / 180.0f;+ const Real base = TheGlobalData->m_cameraPitch * DEGREES;+ const Real flattest = base - 20.0f * DEGREES;+ const Real steepest = base - 60.0f * DEGREES;+ if (pitch > flattest)+ return flattest;+ if (pitch < steepest)+ return steepest;+ return pitch;+}+//-----------------------------------------------------------------------------Int EdgeScroll_bandForHeight( Int displayHeight ){@@ -366,7 +387,12 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage// The middle button turns the camera: drag it sideways and the heading follows. The pan// is on the right button, so no modifier is needed. A click without a drag puts the- // camera back, below.+ // camera back, below. With Alt held the drag tilts the camera up and down instead.+ if (TheKeyboard->isAlt())+ {+ m_isPitching = true;+ break;+ }m_isRotating = true;// the drag turns this, and under SnapCameraRotateTo45 the camera stands on whichever// eighth it is nearest - so start it where the camera already is.@@ -383,6 +409,7 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessageconst UnsignedInt PIXEL_OFFSET = 5;m_isRotating = false;+ m_isPitching = false;Int dx = m_currentPos.x-m_originalAnchor.x;if (dx<0) dx = -dx;Int dy = m_currentPos.y-m_originalAnchor.y;@@ -477,7 +504,7 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessageReal angle = FACTOR * (m_currentPos.y - m_anchor.y);// Dragging down tips the camera down. The sign used to be the other way round.- TheTacticalView->setPitch( TheTacticalView->getPitch() - angle );+ TheTacticalView->setPitch( LookAt_clampPlayerPitch( TheTacticalView->getPitch() - angle ) );m_anchor = msg->getArgument( 0 )->pixel;}@@ -517,6 +544,13 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessageTheInGameUI->rotatePendingPlacement( rotateSteps ))return DESTROY_MESSAGE;+ // Alt+wheel tilts instead of zooming: forward lays the camera flatter, toward the horizon.+ if (!classic && TheKeyboard->isAlt())+ {+ TheTacticalView->setPitch( LookAt_clampPlayerPitch( TheTacticalView->getPitch() + spin * TILT_PER_NOTCH ) );+ return DESTROY_MESSAGE;+ }+// ZoomToCursor: the view holds the ground under the cursor while the zoom eases in. It does// it inside its own update, between the zoom moving and the frame being drawn; held from// here, the correction always landed a frame late.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cppindex e4414e9b5..d784d18ae 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp@@ -630,9 +630,18 @@ GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessadisp = DESTROY_MESSAGE;break;}- }-+ }+ // Home puts the camera back as well as CAMERA_RESET's own key (Numpad 5 in the shipped+ // CommandMap.ini, which keyboards without a numpad lack), unless the player gave Home to+ // something else.+ if( disp == KEEP_MESSAGE && key == MK_HOME && newModState == NONE &&+ ( keyState & KEY_STATE_DOWN ) && !( keyState & KEY_STATE_AUTOREPEAT ) &&+ TheGameClient->getFrame() >= 1 && !( TheShell && TheShell->isShellActive() ) )+ {+ TheMessageStream->appendMessage( GameMessage::MSG_META_CAMERA_RESET );+ disp = DESTROY_MESSAGE;+ }// remember, or forget, that this key is held with these modifiersif( !isModifierKey && newModState != NONE && key >= 0 && key < NUM_MAPPABLE_KEYS )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cppindex 04d0be4ca..f9f815644 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp@@ -2588,7 +2588,8 @@ void ScriptActions::doPlayerKill(const AsciiString& playerName)//-------------------------------------------------------------------------------------------------void ScriptActions::doDisplayText(const AsciiString& displayText){- TheInGameUI->message(displayText);+ // the map's text is the message, not a format: "HQ at 10%." read arguments nobody passed+ TheInGameUI->message(UnicodeString(u"%ls"), TheGameText->fetch(displayText).str());}//-------------------------------------------------------------------------------------------------@@ -6148,6 +6149,8 @@ void ScriptActions::doC3CameraShake{Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);DEBUG_ASSERTLOG( (way != NULL), ("Camera shake with No Valid Waypoint\n") );+ if( way == NULL )+ return; // the map names a waypoint it does not have; every other waypoint action skips it tooCoord3D pos = *way->getLocation();TheTacticalView->Add_Camera_Shake(pos, radius, duration_seconds, amplitude);diff --git a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.hindex 8335e077d..9ffdd5a9b 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h@@ -263,6 +263,7 @@ class MilesAudioManager : public AudioManager// Looping functionsBool startNextLoop( PlayingAudio *looping );+ void endLoopPassNow( PlayingAudio *audio );void playStream( AudioEventRTS *event, HSTREAM stream );// Returns the file handle for attachment to the PlayingAudio structurediff --git a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cppindex ae235b6e8..59a3a67d5 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp@@ -1113,6 +1113,7 @@ void MilesAudioManager::stopAudioEvent( AudioHandle handle )// it straight to PS_Stopping cut death cries, build-complete barks and weapon tails off// the frame they were asked to stop.audio->m_requestStop = true;+ endLoopPassNow( audio );break;}}@@ -1128,11 +1129,36 @@ void MilesAudioManager::stopAudioEvent( AudioHandle handle )DEBUG_LOG((" (%s)\n", audio->m_audioEventRTS->getEventName()));#endifaudio->m_requestStop = true;+ endLoopPassNow( audio );break;}}}+//-------------------------------------------------------------------------------------------------+/** A loop told to stop used to play its current pass to the end: a destroyed unit's engine hum or+ * a turret that had stopped turning went on for as long as the sample ran. A one-shot sound keeps+ * its tail (that is what m_requestStop is for), but a loop ends the pass now, the same way the+ * stream branch above does it: completing it with m_requestStop set starts no further loop, plays+ * the decay portion if the sound has one, and otherwise leaves it for the next sweep to free. */+//-------------------------------------------------------------------------------------------------+void MilesAudioManager::endLoopPassNow( PlayingAudio *audio )+{+ const AudioEventInfo *info = audio->m_audioEventRTS->getAudioEventInfo();+ if (!audio->isPlaying() || info == NULL || !(info->m_control & AC_LOOP)) {+ return;+ }++ // stopped first: completing it closes the file the mixer is still reading+ if (audio->m_type == PAT_Sample) {+ AIL_stop_sample(audio->m_sample);+ notifyOfAudioCompletion((UnsignedIntPtr)(audio->m_sample), PAT_Sample);+ } else if (audio->m_type == PAT_3DSample) {+ AIL_stop_3D_sample(audio->m_3DSample);+ notifyOfAudioCompletion((UnsignedIntPtr)(audio->m_3DSample), PAT_3DSample);+ }+}+//-------------------------------------------------------------------------------------------------void MilesAudioManager::killAudioEventImmediately( AudioHandle audioEvent ){diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cppindex 463b0bc42..3d9095f3d 100644--- a/GeneralsMD/Code/Main/WinMain.cpp+++ b/GeneralsMD/Code/Main/WinMain.cpp@@ -40,6 +40,7 @@#include <eh.h>#include <ole2.h>#include <dbt.h>+#include <vector>// USER INCLUDES //////////////////////////////////////////////////////////////#include "WinMain.h"@@ -1045,6 +1046,63 @@ char *nextParam(char *newSource, char *seps)// Necessary to allow memory managers and such to have useful critical sectionsstatic CriticalSection critSec1, critSec2, critSec3, critSec4, critSec5;+/** AMD's X3D parts with two CCDs (7950X3D, 9950X3D) stack the extra L3 on one of them, and Windows+ * puts the game on either. GeneralsX measured a match at 29-32 fps on the plain CCD and 37-38 on the+ * stacked one, so the whole process goes on the logical processors that share the largest L3. One+ * L3, or several of one size (Intel, a plain 9950X, EPYC), is left alone, and so are -multiInstance+ * copies: a batch spreads one match a core over every CCD. */+static void pinToLargestL3( void )+{+ if (findEarlyCommandLineOption( L"-multiInstance" ) != NULL)+ return;++ GROUP_AFFINITY ownGroup;+ GetThreadGroupAffinity( GetCurrentThread(), &ownGroup );++ DWORD length = 0;+ GetLogicalProcessorInformationEx( RelationCache, NULL, &length );+ std::vector<char> buffer( length );+ if (!GetLogicalProcessorInformationEx( RelationCache, (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)&buffer[0], &length ))+ {+ DEBUG_LOG(("CPU: GetLogicalProcessorInformationEx failed (%u), no L3 pinning\n", GetLastError()));+ return;+ }++ Int caches = 0;+ DWORD largest = 0, smallest = MAXDWORD;+ KAFFINITY largestMask = 0;+ for (DWORD at = 0; at < length; )+ {+ const SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info = (const SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)&buffer[at];+ const CACHE_RELATIONSHIP &cache = info->Cache;+ if (cache.Level == 3 && cache.GroupMask.Group == ownGroup.Group)+ {+ ++caches;+ if (cache.CacheSize < smallest)+ smallest = cache.CacheSize;+ if (cache.CacheSize > largest)+ {+ largest = cache.CacheSize;+ largestMask = cache.GroupMask.Mask;+ }+ }+ at += info->Size;+ }++ if (caches < 2 || largest == smallest)+ {+ DEBUG_LOG(("CPU: %d L3 cache(s) of %u KB in processor group %u, no pinning\n", caches, largest / 1024, ownGroup.Group));+ return;+ }+ if (!SetProcessAffinityMask( GetCurrentProcess(), largestMask ))+ {+ DEBUG_LOG(("CPU: SetProcessAffinityMask(0x%llx) failed (%u)\n", (unsigned long long)largestMask, GetLastError()));+ return;+ }+ DEBUG_LOG(("CPU: %d L3 caches, %u KB and %u KB; pinned to the %u KB one, mask 0x%llx\n",+ caches, smallest / 1024, largest / 1024, largest / 1024, (unsigned long long)largestMask));+}+// _set_se_translator below only covers the thread that installs it, so a fault on one// of the engine's worker threads (WW3D's texture loader, the GameSpy threads) took the// process down with nothing in the log at all. The unhandled-exception filter is@@ -1394,6 +1452,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,// start the logDEBUG_INIT(DEBUG_FLAGS_DEFAULT);initMemoryManager();+ pinToLargestL3();// Set up version infodiff --git a/GeneralsMD/Code/Tests/test_camera_behavior.inc b/GeneralsMD/Code/Tests/test_camera_behavior.incindex a818a20c8..83b3ded7f 100644--- a/GeneralsMD/Code/Tests/test_camera_behavior.inc+++ b/GeneralsMD/Code/Tests/test_camera_behavior.inc@@ -285,6 +285,68 @@ TEST(ctrl_wheel_zooms_five_notches_for_one)CHECK_NEAR(1000.0f - heightAfterOneNotch(), plain, 0.01f);}+TEST(alt_wheel_and_alt_middle_drag_tilt_between_20_and_60_degrees)+{+ CHECK(bootOnce());+ CameraInputFixture f;+ GameClient *savedClient = TheGameClient;+ TheGameClient = getTestGameClient();+ f.global->m_windowed = TRUE;+ f.global->m_edgeScrollInWindowedMode = FALSE;+ f.global->m_cameraPitch = 37.5f;+ const Real DEGREES = PI / 180.0f;+ const auto elevation = [&f, DEGREES]() { return f.global->m_cameraPitch - f.view.getPitch() / DEGREES; };+ const auto wheel = [&f](Real notches)+ {+ GameMessage *message = newInstance(GameMessage)(GameMessage::MSG_RAW_MOUSE_WHEEL);+ const ICoord2D cursor = {320, 240};+ message->appendPixelArgument(cursor);+ message->appendRealArgument(notches);+ f.camera.translateGameMessage(message);+ message->deleteInstance();+ };+ const auto mouse = [&f](GameMessage::Type type, Int x, Int y)+ {+ GameMessage *message = newInstance(GameMessage)(type);+ const ICoord2D pixel = {x, y};+ message->appendPixelArgument(pixel);+ f.camera.translateGameMessage(message);+ message->deleteInstance();+ };++ f.view.setPitch(0.0f);+ f.view.setHeightAboveGround(1000.0f);+ f.keyboard.modifiers(KEY_STATE_LALT);+ // a notch forward lays the camera 2 degrees flatter and does not zoom+ wheel(1.0f);+ CHECK_NEAR(elevation(), 35.5f, 0.001f);+ CHECK_NEAR(f.view.getHeightAboveGround(), 1000.0f, 0.001f);+ wheel(50.0f);+ CHECK_NEAR(elevation(), 20.0f, 0.001f);+ wheel(-50.0f);+ CHECK_NEAR(elevation(), 60.0f, 0.001f);++ // Alt+middle drag tilts instead of turning, inside the same limits+ f.view.setPitch(0.0f);+ const Real heading = f.view.getAngle();+ mouse(GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN, 300, 300);+ mouse(GameMessage::MSG_RAW_MOUSE_POSITION, 340, 310);+ CHECK(f.camera.isMovingCamera());+ CHECK_NEAR(elevation(), 37.5f + 0.1f / DEGREES, 0.001f);+ CHECK_EQ(f.view.getAngle(), heading);+ mouse(GameMessage::MSG_RAW_MOUSE_POSITION, 340, 900);+ CHECK_NEAR(elevation(), 60.0f, 0.001f);+ mouse(GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP, 340, 900);+ CHECK(!f.camera.isMovingCamera());++ // without Alt the wheel zooms again and leaves the tilt alone+ f.keyboard.modifiers(0);+ wheel(1.0f);+ CHECK_NEAR(elevation(), 60.0f, 0.001f);+ CHECK(f.view.getHeightAboveGround() < 1000.0f);+ TheGameClient = savedClient;+}+TEST(right_drag_follows_the_scroll_speed){CHECK(bootOnce());