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): crashes from the v3.2.0 reports, mods and game start
Olcay Seygan200dc880f4ac
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9f1e10dcd..be167e76a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -58,6 +58,7 @@ found and fixed — EA's own, not port damage.**- You can call them too. A beacon you place asks your computer allies to attack there, and typing `help`, `attack` or `money` in chat (`yardim`, `saldir`, `para` in Turkish) asks for help where you are looking, an attack there, or cash.- A personality is a preference, never a bonus: no personality gets extra money, faster building or tougher units.- Computer players with a personality now and then say something in chat, in their own voice, at most once every two and a half minutes. Normal ones stay quiet.+- An Infantry computer player no longer crashes the game while one of its factories researches an upgrade. Shopping for a troop carrier, it read the upgrade in the queue as if it were a vehicle.- The choice travels with the game to every player in a LAN or online match and into the replay. Replays and saves from earlier versions load with every computer player on Normal; a save made with this version does not load in an earlier one.## Turbo mode instead of a speed dropdown@@ -191,6 +192,16 @@ found and fixed — EA's own, not port damage.**- ShockWave's EMP Patriot fires its missiles again. ShockWave switched on a short-range field around the battery that EA had left commented out, and every time the field pulsed, every 0.75 seconds, the battery's missiles had to wait their turn again from the start. The turret kept tracking its target and nothing left the rails: a lone EMP Patriot fired 0 missiles in 6 seconds at rocket soldiers 200 away, where Zero Hour's fires 12. The field now keeps its own clock, so the battery fires 12 like Zero Hour's and the field still pulses. ShockWave's Superweapon Humvee, its Reaper tank and its Salvage SA-2 site carried the same pairing.- ShockWave's Armor General's cluster missiles land where you aim them. The missile is built to cruise high and drop straight onto the target, splitting into warheads on the way down, but it was flying Reforged's smooth Scud curve instead and split a long way off: aimed at a Scud Launcher, the warheads came down 180 to 270 short of it. A missile like this one now flies the way Zero Hour flew it, and the same two shots landed 4 and 5 from the aim and killed both launchers. Scuds and Tomahawks keep their curve.- Shockwave Chaos beside a second full mod starts now. With Contra, ShockWave and Shockwave Chaos switched on together the game stopped while loading, on one line of Chaos's Black Market tank that lists 43 of the mod's own tanks it can turn into. Keeping each mod's armies apart puts a short mark in front of every name the mod defines, and that line grew past the room the game gave a line of text. A line has three times the room now, more than any mod can fill.+- Five full mods side by side start now. Contra, ShockWave, Shockwave Chaos, The End of Days and Tiberian Dawn Redux together bring about 700 upgrades, and the game had room for 512: it stopped while loading at The End of Days' Fanaticism. It has room for 1024.+- Contra, The End of Days and Rise of the Reds no longer crash the moment certain missiles fly. Some of their missiles have no engine of their own and fly on the push they leave the launcher with, which Zero Hour always allowed; the weave Reforged gives missiles on their way in, and the lead they take on a moving tank, reached for that engine anyway and took the game down. Such a missile now just flies straight, as it did in Zero Hour.+- ShockWave's and Reborn's Superweapon General no longer crashes the game the moment its Particle Cannon finishes building. Reforged's fix for that cannon's glow named Zero Hour's particle cannon power, and these mods give the Superweapon General a power of their own, so the cannon found no power to charge from. It now charges from the power its building carries.+- Shockwave Chaos no longer crashes when a drone or other slaved unit set to scout follows a building rather than a vehicle. The drone looked for where its master was driving to, and a building drives nowhere; it now guards the building instead.+- A map with two players of the same name no longer crashes the main menu or a match the first time a point defense laser looks for a target. The second of the two was left with no team, and the laser's search for enemies tripped over it.+- The End of Days no longer crashes in the middle of a match when some of its guns fire. A shell flies a path worked out from its speed, and a shell with next to no speed asked for a path of hundreds of millions of steps, gigabytes of it; the game handed back far less memory than that and the path was written on past the end, so the match died at once or a little later in some unrelated place. A shell that would take more than ten minutes to land is now dropped as it is fired, and the game refuses any request for more than 2 GB of memory at once instead of handing back a short one.+- Generals' Challenge starts under Contra and The End of Days. Both mods ship their own list of maps, and that list stands in for Zero Hour's, so a Challenge map that was right there in the game's files was missing from the list, and the game went down dealing out start positions on a map it said did not exist. A map the list leaves out is now read the moment it is asked for.+- Picking USA, GLA or China under The End of Days opens the mission list instead of crashing. The mod's campaign file holds only the Challenge campaigns, and the list asked a campaign that was not there for its first mission. The list comes up with every mission greyed, and Back takes you out again.+- A mod whose team colour textures are stored in a format the colour cannot be painted into, a compressed one for instance, no longer crashes the game as such a unit comes out (a player hit it under The Power of the West). The unit keeps the texture's own colours.+- A shortcut button on the powers bar whose power the mod does not have stays off the bar instead of crashing the game while the command bar fills. A mod's own button, or a Reforged button loaded over a mod, can name a power that was never defined.- 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@@ -228,6 +239,7 @@ found and fixed — EA's own, not port damage.**- Point at the attack, hold position or move key and a card says what it does, in English or Turkish. Those three are painted onto the grid rather than given to a unit, so the game had no card for them and showed nothing. The card stands on top of the command bar like every other button's.- HUD Size grows the console from its middle, and on a narrow screen it stops at the size that still fits.- The grid under a building you are placing is fainter and its lines thinner, and the red squares where nothing can stand are lighter, so the ground under them shows through. Untick grid placement on the Controls page and the lines go altogether.+- Placing a building no longer crashes the game now and then. The ground can still be marked as taken by something that has already gone, and the red squares under the building you are placing asked that missing thing who owned it. Such a square stays red until the ground is free.- Hold Ctrl while placing a building and grid placement flips for as long as the key is down. With the box unticked the building snaps to the grid and the lines come up, so one flush row is a held key away; with it ticked you get a free hand for the odd building that has to sit between two squares. It works the same in Classic.- The camera works the same way with Shift. Turn it with the middle button or the rotate keys while Shift is down and the 45 degree camera steps flip: with the box unticked the view clicks round the eight headings, with it ticked it turns freely, and letting go of Shift mid-turn hands back whatever the box says. A quick square-on look no longer means a trip to the options.- Your general's promotion screen opens in the middle of the screen, in the Classic interface as well, instead of hanging from the top edge. The battlefield dims behind it, and a click anywhere off the screen closes it without selecting or ordering anything underneath.@@ -1222,6 +1234,8 @@ A third pass went through the generals' powers, promotions and unit abilities.- Fallen Empire's great wall takes no garrison again. Its towers have room for ten soldiers, but the map makes the wall indestructible and switches it off for clicking, so in Zero Hour nobody could ever send a man in. The computer's habit of filling map buildings near a fight found them anyway, and its soldiers sat in a wall nothing could damage, out of reach of everything but a flash-bang or a toxin or flame shot. A building the map has switched off for clicking now refuses a garrison from you and from the computer; a mission's own script can still put men in one, as it always could. Replays recorded before this change play out differently.- Burning infantry run in every direction, not always north-east.- A player name long enough to fill the LAN game room no longer hangs the lobby, changing settings there no longer crashes it, and the list of LAN games keeps its place instead of jumping back to the top every time it refreshes.+- The pointer resting on a player's name in the LAN game room when the host leaves no longer crashes the game. The game is gone the moment the host goes, the room stays on screen while it slides back to the lobby, and the name's tooltip went looking for a player in it.+- A save that fails to load shows its error box instead of crashing. A garrisoned building read before the fault counted soldiers it had not been handed yet, and clearing away the half-loaded match asked it for the first of them.- Holding Ctrl while the beacon text box was open no longer leaves force-attack armed after you let go.- The camera stops following a unit the moment it goes stealthed or into the fog, instead of showing you where it went.- A broken map.ini, a damaged map cache in your user folder or a map name with forward slashes no longer crash the game or lose the map from the list; the cache is rebuilt.@@ -1712,6 +1726,9 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same## It does not crash+- The rings the battle lays on the ground, a nuke's target circle or a Spectre gunship's, no longer crash the game now and then. Since 3.2.0 the battle runs beside the picture, and those rings were laid and lifted from the battle's side while the picture was walking the list of them, so the picture could read a ring that had just been thrown away. They are laid and lifted between pictures now.+- A graphics driver that stops responding no longer takes the game down through the radar. The battle carries on while the picture is lost, and the radar kept redrawing its unit dots into a texture that had nothing behind it. It skips the redraw until there is something to draw into.+- Your aircraft's ammo pips no longer crash the game. They have shown all the time since the jets learned to fly, and they are lined up with the health bar, so a plane drawn without a health bar took the game down. Such a plane shows no pips.- Starting a match with the Direct3D 11 picture on took the game down. Both devices were presenting into the same window, the old one lost itself, and the fog texture then locked a surface that was never made.- Selling with more than one building selected no longer takes the game down. Each building that goes up for sale is taken out of the selection, and that rebuilt the group the sell order was still working through, so the second building was read from memory that had already been handed back. A player lost a match an hour in this way.- A machine whose graphics stack faults while the Direct3D 11 picture is being set up starts the game anyway, on the Direct3D 9 picture. A player's report showed the fault happening inside Windows' own graphics library, before the game got an answer back, and it ended in "Uncaught Exception during initialization". An overlay hooking the graphics calls or a stray dxgi.dll in the game folder is the usual cause. Until now the only way past it was typing -d3d9.@@ -1721,6 +1738,9 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- A tank or truck with no orders of its own, the burning wreck some mods leave behind, crashed the game the first time it was drawn. The new tread and chassis motion asked every drawn vehicle for its engine, and a wreck has none. A wreck now sits still.- Opening Skirmish crashed on a game that loads its menus from a mod or from the original files, as the Shockwave mod does. Those menus have no game speed box, and the game set one up anyway. The same was true of the tree sway box and the detail presets on the Options screen. A missing box is now left out, and a skirmish without one plays at normal speed.- The opening movies froze on their first frame with that picture on. A movie writes a new image every frame into a texture the copy had already taken.+- A map that fills all sixteen player seats no longer crashes as it finishes loading. Every match adds one more player, the watcher its replay is seen through, and on such a map there was no seat left for him; the load went down looking for him. One player met it on America's first mission, whose map already holds fifteen. Such a map now starts with no watcher, and its replay watches from the seat it was recorded in.+- Leaving a Generals' Challenge match while its opening movie still played could crash the game on the way back to the menu. Clearing the match closed every movie, the load screen's own among them, and the load screen was left up to close it again; it now goes with the match.+- A one-player mission map started from the Skirmish menu could crash before its load screen came up. The game still had the last campaign you played in mind and tried to show that campaign's briefing, which, once you had finished that campaign, did not exist. A map from the Skirmish menu loads as a map of its own.- Opening Single Player could take the game down a quarter of a second in, as the buttons flashed in. The menu's animation list names a Custom Mission button that only the 1.04 patch's main menu has, and on an install whose menu lacks it, every step of the flash skipped the missing button except one, which tried to draw it. That step skips it now too.- On those same installs Single Player then froze the menu instead. The buttons lit up under the pointer and none of them did anything until Alt+F4. The menu waits for its animation to end before it takes a click, and the missing button's flash never got to say it had ended. The animation now ends on its last frame whatever its buttons say, and the dropdown takes clicks a second after it opens, as it does on a full install.- A skirmish against the computer could crash when a fresh unit joined one of its teams. The newcomer copies what a teammate is doing, and when that teammate was following a road the map had drawn for it, the newcomer got the order without the road and the game fell over looking for its first stop. It now gets the road as well, and a unit handed that order with no road at all gives it up instead.@@ -1736,6 +1756,8 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- Starting the game from the folder the zip was unpacked to says what is wrong. None of Zero Hour's own files are in that folder, so the first one the game asked for was missing, and the box that came up blamed viruses and overheated hardware. It now names the folder it looked in and tells you to run install.bat.- A machine that once had Generals installed from a disc or The First Decade, and later removed it, no longer loses the original game's files. The old install leaves its address behind in Windows, the game trusted it over the copy Steam keeps beside Zero Hour, and the main menu came up over magenta water and black hills. A folder that turns out to be empty is passed over now.- Buying both games on Steam is enough. Steam writes nothing to Windows saying where it put them and installs the two side by side in their own folders, so the game had no way of finding the original one unless you had copied its files across by hand: a fresh install of both came up on a magenta main menu with most of the sound effects missing. The folder next to Zero Hour's is searched now. When the original game's files really are nowhere, a box names the folder to put them in, rather than leaving you to read a pink menu.+- The EA app and Origin copies find the original game too. They install both games in one folder, Generals as "Command and Conquer Generals" beside Zero Hour, and write no address for it, so three players on 2026-10-21 got the box saying the original game was nowhere with it sitting right there. That folder is searched now.+- A game folder buried deep in other folders starts. Windows will not open a file by its plain name once the whole path passes 260 characters, and one player's install sat 198 characters down, which put one of Reforged's interface files at 264: the game listed it, could not open it and stopped at start. Files past that length are opened by their long name now.- A tank driving into a wood no longer takes the game down. On an install missing the original game's artwork, trees whose model could not be loaded were still planted on the map, half set up, and the first unit that drove close enough to shove one aside read from the half of them that was never filled in. One missing folder was costing a crash in the middle of a match as well as a pink menu. A tree whose model will not load is simply left out.- Nor can a map handed to you over the network, however long a name the other machine gives it.- An order too big for one packet arrives in pieces, and a piece that claims to belong outside the order is dropped instead of landing there.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.hindex 9c3a50245..052b860c5 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h@@ -58,8 +58,10 @@ enum UpgradeStatusType : Int//The maximum number of upgrades.// How many distinct upgrades the game may know about. A mod that adds its own runs into this, and// the failure is silent - the mask simply has no bit left for the new one. The mask is a bit-// field, so raising it costs 48 bytes per player and per object that carries one.-#define UPGRADE_MAX_COUNT 512+// field, so raising it costs 48 bytes per player and per object that carries one. 512 ran out under+// -modfactions with five mods (Contra, ShockWave, Shockwave Chaos, The End of Days and Tiberian Dawn+// Redux) at The End of Days' upgrade 513, about 700 in all.+#define UPGRADE_MAX_COUNT 1024typedef BitFlags<UPGRADE_MAX_COUNT, 6> UpgradeMaskType;diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/RadiusDecal.h b/GeneralsMD/Code/GameEngine/Include/GameClient/RadiusDecal.hindex f8d42d04a..19ea36841 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/RadiusDecal.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/RadiusDecal.h@@ -35,18 +35,47 @@#include "Common/GameType.h"#include "GameClient/Color.h"+#include <memory>+enum ShadowType : int;class Player;class Shadow;class RadiusDecalTemplate;+// ------------------------------------------------------------------------------------------------+/** The decal itself, held where a call queued for after the tick can still reach it once its+ * RadiusDecal is gone. Logic modules create and clear these inside the tick, which runs beside the+ * render, and adding or releasing a decal edits the decal list the render walks, so both go through+ * LogicThread::callAfterTick and only ever happen on the main thread. Until the add has run, what+ * the owner sets (a module animates its decal in the tick that created it) waits here and the add+ * puts it on. */+struct RadiusDecalCell+{+ Shadow* decal;+ Bool hasPosition;+ Coord3D position;+ Bool hasOpacity;+ Int opacity;+ Bool hasAngle;+ Real angle;++ RadiusDecalCell() : decal(NULL), hasPosition(FALSE), hasOpacity(FALSE), opacity(0), hasAngle(FALSE), angle(0.0f)+ {+ position.x = position.y = position.z = 0.0f;+ }++ void setPosition(const Coord3D& pos);+ void setOpacity(Int o);+ void setAngle(Real a);+};+// ------------------------------------------------------------------------------------------------class RadiusDecal{friend class RadiusDecalTemplate;private:const RadiusDecalTemplate* m_template;- Shadow* m_decal;+ std::shared_ptr<RadiusDecalCell> m_decal;Bool m_empty;public:RadiusDecal();diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.hindex 514854e63..1a11acdf4 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h@@ -73,8 +73,9 @@ public:ProductionEntry( void );// virtual destructor provided by memory pool object- /// query what kind of thing is being produced by this entry- const ThingTemplate *getProductionObject( void ) const { return m_objectToProduce; }+ /// query what kind of thing is being produced by this entry; NULL for an upgrade, whose template+ /// shares the storage and read as a ThingTemplate is garbage+ const ThingTemplate *getProductionObject( void ) const { return m_type == PRODUCTION_UNIT ? m_objectToProduce : NULL; }/// query what kind of upgrade is being produced by this entryconst UpgradeTemplate *getProductionUpgrade( void ) const { return m_upgradeToResearch; }diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex b20581e92..934e5488e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -36,6 +36,7 @@#include <unistd.h> // getpid, for the model-checksum cache's scratch file#endif#include "Lib/Clock.h"+#include <exception>#include "Lib/WideCharFns.h"@@ -3411,7 +3412,27 @@ void GameEngine::execute( void )catch (...){}- RELEASE_CRASH(("Uncaught Exception in GameEngine::update"));+ /* A C++ throw carries no exception record, so the report's "Last error" stayed empty+ and named nothing (crash reports 1194 and 1198, both Shockwave Chaos matches). Say+ what was thrown; a fault the SEH translator dumped keeps the old reason. */+ char why[ 160 ];+ try+ {+ throw;+ }+ catch (ErrorCode ec)+ {+ snprintf( why, sizeof(why), "Uncaught ErrorCode 0x%08x in GameEngine::update", (UnsignedInt)ec );+ }+ catch (const std::exception &e)+ {+ snprintf( why, sizeof(why), "Uncaught std::exception in GameEngine::update: %s", e.what() );+ }+ catch (...)+ {+ snprintf( why, sizeof(why), "Uncaught Exception in GameEngine::update" );+ }+ RELEASE_CRASH((why));} // catchtFrameEnd = Clock_Ticks();// from the last picture an earlier part of the pass presented, if it presented anydiff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cppindex 0e09d860f..682e14656 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp@@ -237,10 +237,14 @@ void PlayerList::newGame()p->setPlayerRelationship(p, ALLIES);if (p != getNeutralPlayer())p->setPlayerRelationship(getNeutralPlayer(), NEUTRAL);-- p->setDefaultTeam();}+ /* Every player gets its default team, walked by player rather than looked up by side name: a map+ with two sides of one name made two players, the lookup above found the first twice, and the+ second was left with no default team for the first enemy search to read. */+ for( i = 0; i < m_playerCount; i++ )+ m_players[i]->setDefaultTeam();+/* Now that the players exist and are named, write down which network slot each one came from.The two numbers are not the same and never were: player 0 is the neutral player, so a humanin slot 0 is player 1. Everything in GameNetwork is indexed by the slot. */diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cppindex bdf0e8806..6f7cee32c 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cpp@@ -3324,12 +3324,26 @@ static int theLinkTester = 0;#endif//------------------------------------------------------------------------------void* STLSpecialAlloc::allocate(size_t __n)-{+/**+ The allocator counts bytes in an Int, and the operators below are handed a size_t. A request past+ INT_MAX used to narrow on the way in, to a negative count or to whatever its low 32 bits said, and the caller+ (a vector value-initialising its elements) wrote its full size past the end of what it got. Such a+ request is a bug somewhere; it fails here as out of memory instead of corrupting the heap.+*/+static Int dmaRequestSize(size_t size)+{+ if (size > (size_t)INT_MAX)+ throw ERROR_OUT_OF_MEMORY;+ return (Int)size;+}++//-----------------------------------------------------------------------------+void* STLSpecialAlloc::allocate(size_t __n)+{++theLinkTester;preMainInitMemoryManager();DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("must init memory manager before calling global operator new"));- return TheDynamicMemoryAllocator->allocateBytes(__n, "STL_");+ return TheDynamicMemoryAllocator->allocateBytes(dmaRequestSize(__n), "STL_");}//-----------------------------------------------------------------------------@@ -3375,7 +3389,7 @@ void *operator new(size_t size)++theLinkTester;preMainInitMemoryManager();DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("must init memory manager before calling global operator new"));- return TheDynamicMemoryAllocator->allocateBytes(size, "global operator new");+ return TheDynamicMemoryAllocator->allocateBytes(dmaRequestSize(size), "global operator new");}//-----------------------------------------------------------------------------@@ -3387,7 +3401,7 @@ void *operator new[](size_t size)++theLinkTester;preMainInitMemoryManager();DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("must init memory manager before calling global operator new"));- return TheDynamicMemoryAllocator->allocateBytes(size, "global operator new[]");+ return TheDynamicMemoryAllocator->allocateBytes(dmaRequestSize(size), "global operator new[]");}//-----------------------------------------------------------------------------@@ -3472,9 +3486,9 @@ void* operator new(size_t size, const char * fname, int)preMainInitMemoryManager();DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("must init memory manager before calling global operator new"));#ifdef MEMORYPOOL_DEBUG- return TheDynamicMemoryAllocator->allocateBytesImplementation(size, fname);+ return TheDynamicMemoryAllocator->allocateBytesImplementation(dmaRequestSize(size), fname);#else- return TheDynamicMemoryAllocator->allocateBytesImplementation(size);+ return TheDynamicMemoryAllocator->allocateBytesImplementation(dmaRequestSize(size));#endif}@@ -3500,9 +3514,9 @@ void* operator new[](size_t size, const char * fname, int)preMainInitMemoryManager();DEBUG_ASSERTCRASH(TheDynamicMemoryAllocator != NULL, ("must init memory manager before calling global operator new"));#ifdef MEMORYPOOL_DEBUG- return TheDynamicMemoryAllocator->allocateBytesImplementation(size, fname);+ return TheDynamicMemoryAllocator->allocateBytesImplementation(dmaRequestSize(size), fname);#else- return TheDynamicMemoryAllocator->allocateBytesImplementation(size);+ return TheDynamicMemoryAllocator->allocateBytesImplementation(dmaRequestSize(size));#endif}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LocalFile.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LocalFile.cppindex 96770d8bd..d23a42654 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LocalFile.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LocalFile.cpp@@ -52,6 +52,7 @@#include <fcntl.h>#if defined(_WIN32)#include <io.h>+#include <string>#else#include <unistd.h>#include "zhio.h"@@ -135,7 +136,29 @@ enumOPEN_READ_ONLY = _O_RDONLY};-static inline int openFile(const Char *filename, int flags) { return _open(filename, flags, _S_IREAD | _S_IWRITE); }+/* A name that comes out past MAX_PATH once Windows puts the working directory in front of it does not+ open through the narrow call. A player's install 198 characters deep put the fork's+ ReforgedHudAmericaCommandBar.ini at 264: the directory scan listed it, the open refused it and the+ game stopped at start (crash report 1199). The wide call takes the absolute name behind "\\?\",+ which has no such limit. */+static int openFile(const Char *filename, int flags)+{+ const int handle = _open(filename, flags, _S_IREAD | _S_IWRITE);+ if (handle != -1)+ return handle;++ const int wideLength = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);+ std::wstring wide(wideLength, L'\0');+ MultiByteToWideChar(CP_ACP, 0, filename, -1, &wide[0], wideLength);+ const DWORD fullLength = GetFullPathNameW(wide.c_str(), 0, NULL, NULL);+ std::wstring full(fullLength, L'\0');+ full.resize(GetFullPathNameW(wide.c_str(), fullLength, &full[0], NULL));+ if (full.size() < MAX_PATH)+ return handle; // short enough: the narrow call's answer stands++ const std::wstring prefixed = (full.compare(0, 2, L"\\\\") == 0) ? L"\\\\?\\UNC\\" + full.substr(2) : L"\\\\?\\" + full;+ return _wopen(prefixed.c_str(), flags, _S_IREAD | _S_IWRITE);+}static inline int readFile(int handle, void *buffer, Int bytes, Bool) { return _read(handle, buffer, bytes); }static inline int writeFile(int handle, const void *buffer, Int bytes) { return _write(handle, buffer, bytes); }static inline long seekFile(int handle, long offset, int origin) { return _lseek(handle, offset, origin); }diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex 644914984..98a398a62 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -3614,7 +3614,12 @@ void Drawable::drawEmoticon( const IRegion2D *healthBarRegion )// ------------------------------------------------------------------------------------------------void Drawable::drawAmmo( const IRegion2D *healthBarRegion ){- const Object *obj = getObject();+ // the pips are left-justified on the health bar, as drawContained's are. EA only drew them for a+ // selected or moused-over unit, which has a bar; an aircraft that shows them always may have none.+ if (!healthBarRegion)+ return;++ const Object *obj = getObject();//// Our own aircraft show their load all the time, not just while selected or under the cursor:diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cppindex 854acb7e0..34b0e9213 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp@@ -1241,7 +1241,10 @@ CommandAvailability ControlBar::getCommandAvailability( const CommandButton *comif( command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT|| command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT ){- if (ThePlayerList && ThePlayerList->getLocalPlayer())+ // A shortcut whose SpecialPower named a power that does not exist (a mod's button, or a patch+ // button over a mod that lacks the power, INI::parseSpecialPowerTemplate) stands for nothing:+ // it is hidden like a shortcut with no building behind it.+ if (ThePlayerList && ThePlayerList->getLocalPlayer() && command->getSpecialPowerTemplate())obj = ThePlayerList->getLocalPlayer()->findMostReadyShortcutSpecialPowerOfType( command->getSpecialPowerTemplate()->getSpecialPowerType() );elseobj = NULL;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cppindex d60928ae4..fdc5a4ed1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp@@ -240,16 +240,19 @@ static void playerTooltip(GameWindow *window,if (idx == -1)return;- // was i, the loop counter above: it only escaped its scope under VC6, and the- // loop breaks the instant it sets idx = i, so the two are the same value here.- LANGameSlot *slot = TheLAN->GetMyGame()->getLANSlot(idx);- if (!slot)+ // The host leaving drops the game at once, and the menu stays on screen while the shell pops it+ // back to the lobby: a pointer resting on a slot then has no game to name a player from.+ LANGameInfo *myGame = TheLAN->GetMyGame();+ if (!myGame)+ {+ TheMouse->setCursorTooltip( UnicodeString::TheEmptyString );return;+ }- LANPlayer *player = slot->getUser();+ LANPlayer *player = myGame->getLANSlot(idx)->getUser();if (!player){- DEBUG_ASSERTCRASH(TheLAN->GetMyGame()->getIP(i) == 0, ("No player info in listbox!"));+ DEBUG_ASSERTCRASH(myGame->getIP(idx) == 0, ("No player info in listbox!"));TheMouse->setCursorTooltip( UnicodeString::TheEmptyString );return;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cppindex b8fa386dc..2e002fb38 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp@@ -270,8 +270,10 @@ static void showSelectiveButtons( Int show )// that flashes the panel in would show it again.static void showMissionMenu( const char *group ){+ // a mod's Campaign.ini can leave a side's campaign out (End of Days has only the challenge ones);+ // setCampaign found none, and that side's panel comes up with every button greyedCampaign *campaign = TheCampaignManager->getCurrentCampaign();- Mission *mission = campaign->getNextMission( NULL );+ Mission *mission = campaign ? campaign->getNextMission( NULL ) : NULL;for( Int i = 0; i < MISSION_BUTTONS; ++i ){UnicodeString label;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cppindex 70c7407a6..229d2c6d3 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp@@ -44,6 +44,7 @@#include "Common/SkirmishPreferences.h"#include "GameLogic/GameLogic.h"#include "GameClient/AnimateWindowManager.h"+#include "GameClient/CampaignManager.h"#include "GameClient/WindowLayout.h"#include "GameClient/Gadget.h"#include "GameClient/Shell.h"@@ -496,6 +497,11 @@ void reallyDoStart( void )two menus was not the same mission. */InitRandom(0);+ /* Nor is it a campaign mission. The campaign manager still held whatever campaign was played+ last, so the load picked that campaign's screen and read the briefing of a mission that was+ not being played - or of none, when that campaign had been played through. */+ TheCampaignManager->setCampaign( AsciiString::TheEmptyString );+GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_NEW_GAME );msg->appendIntegerArgument(GAME_SINGLE_PLAYER);msg->appendIntegerArgument(DIFFICULTY_NORMAL); // not really used; just specified so we can add the game speed lastdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cppindex dac56a3a6..cbaf47298 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp@@ -1222,24 +1222,31 @@ const MapMetaData *MapCache::findMap(AsciiString mapName)return &(it->second);//- // A generated map is in the cache only if something staged it this run, and a replay, a save or- // a game somebody else is hosting names one that nothing here has built. The name carries the- // settings, so the map is built now and cached like any other rather than reported missing -- // which is what the map is asked for at, among other places, the point where the start- // positions are dealt out, and that caller does not survive a no.+ // A map that is there but not in the cache is read now and cached like any other rather than+ // reported missing - which is what the map is asked for at, among other places, the point where+ // the start positions are dealt out, and that caller does not survive a no. Two ways to get+ // here: a generated map is in the cache only if something staged it this run, and a replay, a+ // save or a game somebody else is hosting names one that nothing here has built (the name+ // carries the settings, so it is built on the spot); and a mod's own Maps\MapCache.ini shadows+ // the shipped one, so a shipped map the mod's file leaves out - the Generals Challenge maps+ // under some mods - is in the archives but nowhere in the cache.//- if (!isGeneratedMapPath(mapName))- return NULL;-- FileInfo generatedInfo;- if (!TheFileSystem->getFileInfo(mapName, &generatedInfo))+ FileInfo fileInfo;+ if (!TheFileSystem->getFileInfo(mapName, &fileInfo))return NULL;+ const Bool isUserMap = isGeneratedMapPath(mapName) || mapName.startsWithNoCase(getUserMapDir());m_seen[mapName] = TRUE;- addMap(getUserMapDir(), mapName, &generatedInfo, FALSE);+ addMap(isUserMap ? getUserMapDir() : getMapDir(), mapName, &fileInfo, FALSE);it = find(mapName);- return (it == end()) ? NULL : &(it->second);+ if (it == end())+ return NULL;+ // added as unofficial so a map that does not parse is left out instead of thrown; one from the+ // archives is still a shipped map, and nothing offers to send it to the other players+ if (!isUserMap)+ it->second.m_isOfficial = TRUE;+ return &(it->second);}// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/RadiusDecal.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/RadiusDecal.cppindex d98318db7..d9c1bc33a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/RadiusDecal.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/RadiusDecal.cpp@@ -32,6 +32,7 @@#define DEFINE_SHADOW_NAMES#include "Common/GlobalData.h"+#include "Common/LogicThread.h"#include "Common/Player.h"#include "Common/PlayerList.h"#include "Common/Xfer.h"@@ -111,28 +112,47 @@ void RadiusDecalTemplate::createRadiusDecal(const Coord3D& pos, Real radius, con(!m_onlyVisibleToOwningPlayer ||owningPlayer->getPlayerIndex() == ThePlayerList->getLocalPlayer()->getPlayerIndex())){- Shadow::ShadowTypeInfo decalInfo;- decalInfo.allowUpdates = FALSE; // shadow texture will never update- decalInfo.allowWorldAlign = TRUE; // shadow image will wrap around world objects- decalInfo.m_type = m_shadowType;- strcpy(decalInfo.m_ShadowName, m_name.str()); // name of your texture- decalInfo.m_sizeX = radius*2; // world space dimensions- decalInfo.m_sizeY = radius*2; // world space dimensions-- result.m_decal = TheProjectedShadowManager->addDecal(&decalInfo);- if (result.m_decal)+ // Logic modules call this inside the tick, which runs beside the render: addDecal links the decal+ // into the list the render is walking and loads its texture, so it waits for the tick's end.+ std::shared_ptr<RadiusDecalCell> cell = std::make_shared<RadiusDecalCell>();+ cell->setPosition(pos);+ cell->setAngle(0.0f);+ result.m_decal = cell;+ result.m_template = this;+ // By value, not through this: a template can be a module's own copy (DeliverPayloadAIUpdate's),+ // gone before the call runs when its object is made and destroyed in the same tick.+ const AsciiString name = m_name;+ const ShadowType shadowType = m_shadowType;+ const Real size = radius*2;+ const Color color = m_color == 0 ? clientPlayerColor(owningPlayer) : m_color;+ if (m_lightReference > 0.0f)+ DEBUG_LOG(("AURA RING LIGHT %s ground=%.3f scale=%.2f\n", m_name.str(), groundLight(), lightScale()));+ LogicThread::callAfterTick( [cell, name, shadowType, size, color](){- result.m_decal->setAngle(0.0f);- result.m_decal->setColor(m_color == 0 ? clientPlayerColor(owningPlayer) : m_color);- result.m_decal->setPosition(pos.x, pos.y, pos.z);- result.m_template = this;- if (m_lightReference > 0.0f)- DEBUG_LOG(("AURA RING LIGHT %s ground=%.3f scale=%.2f\n", m_name.str(), groundLight(), lightScale()));- }- else- {- DEBUG_CRASH(("Unable to add decal %s\n",decalInfo.m_ShadowName));- }+ Shadow::ShadowTypeInfo decalInfo;+ decalInfo.allowUpdates = FALSE; // shadow texture will never update+ decalInfo.allowWorldAlign = TRUE; // shadow image will wrap around world objects+ decalInfo.m_type = shadowType;+ strcpy(decalInfo.m_ShadowName, name.str()); // name of your texture+ decalInfo.m_sizeX = size; // world space dimensions+ decalInfo.m_sizeY = size; // world space dimensions++ Shadow *decal = TheProjectedShadowManager->addDecal(&decalInfo);+ if (decal == NULL)+ {+ DEBUG_CRASH(("Unable to add decal %s\n",decalInfo.m_ShadowName));+ return;+ }+ decal->setColor(color);+ // what the owner set while the add waited, the creation's own position and angle among it+ if (cell->hasPosition)+ decal->setPosition(cell->position.x, cell->position.y, cell->position.z);+ if (cell->hasAngle)+ decal->setAngle(cell->angle);+ if (cell->hasOpacity)+ decal->setOpacity(cell->opacity);+ cell->decal = decal;+ } );}}@@ -176,17 +196,15 @@ void RadiusDecalTemplate::xferRadiusDecalTemplate( Xfer *xfer )}// -------------------------------------------------------------------------------------------------RadiusDecal::RadiusDecal() :- m_template(NULL),- m_decal(NULL),+RadiusDecal::RadiusDecal() :+ m_template(NULL),m_empty(true){}// -------------------------------------------------------------------------------------------------RadiusDecal::RadiusDecal(const RadiusDecal& that) :- m_template(NULL),- m_decal(NULL),+RadiusDecal::RadiusDecal(const RadiusDecal& that) :+ m_template(NULL),m_empty(true){DEBUG_CRASH(("not fully implemented"));@@ -197,11 +215,7 @@ RadiusDecal& RadiusDecal::operator=(const RadiusDecal& that){if (this != &that){- m_template = NULL;- if (m_decal)- m_decal->release();- m_decal = NULL;- m_empty = true;+ clear();DEBUG_CRASH(("not fully implemented"));}return *this;@@ -223,9 +237,16 @@ void RadiusDecal::clear()m_template = NULL;if (m_decal){- m_decal->release();+ // after the tick, like the add: the cell outlives this RadiusDecal and its module+ std::shared_ptr<RadiusDecalCell> cell = m_decal;+ LogicThread::callAfterTick( [cell]()+ {+ if (cell->decal)+ cell->decal->release();+ cell->decal = NULL;+ } );}- m_decal = NULL;+ m_decal.reset();m_empty = true;}@@ -238,7 +259,9 @@ RadiusDecal::~RadiusDecal()// ------------------------------------------------------------------------------------------------void RadiusDecal::update(){- if (m_decal && m_template)+ // the decal itself turns up after the tick that created it; until then the cell keeps what is set+ RadiusDecalCell *decal = m_decal.get();+ if (decal && m_template){UnsignedInt now = TheGameLogic->getFrame();Real theta = (2*PI) * (Real)(now % m_template->m_opacityThrobTime) / (Real)m_template->m_opacityThrobTime;@@ -256,14 +279,14 @@ void RadiusDecal::update()//Scripts turned this off, or -cinema did, so don't show them!opac = 0;}- m_decal->setOpacity(opac);+ decal->setOpacity(opac);// a turn every SpinTime, on the logic clock like the throb, so a paused game holds it stillif (m_template->m_spinTime != 0){const UnsignedInt period = MAX(1, abs(m_template->m_spinTime) * LOGICFRAMES_PER_SECOND / 1000);const Real angle = (2*PI) * (Real)(now % period) / (Real)period;- m_decal->setAngle(m_template->m_spinTime > 0 ? angle : -angle);+ decal->setAngle(m_template->m_spinTime > 0 ? angle : -angle);}}}@@ -283,6 +306,42 @@ void RadiusDecal::setPosition(const Coord3D& pos){if (m_decal){- m_decal->setPosition(pos.x, pos.y, pos.z); //world space position of center of decal+ m_decal->setPosition(pos); //world space position of center of decal+ }+}++// ------------------------------------------------------------------------------------------------+// Straight to the decal once the add has run, into the cell until then. The two never overlap: the+// add runs after the tick, on the main thread, while no tick is writing.+void RadiusDecalCell::setPosition(const Coord3D& pos)+{+ if (decal)+ decal->setPosition(pos.x, pos.y, pos.z);+ else+ {+ position = pos;+ hasPosition = TRUE;+ }+}++void RadiusDecalCell::setOpacity(Int o)+{+ if (decal)+ decal->setOpacity(o);+ else+ {+ opacity = o;+ hasOpacity = TRUE;+ }+}++void RadiusDecalCell::setAngle(Real a)+{+ if (decal)+ decal->setAngle(a);+ else+ {+ angle = a;+ hasAngle = TRUE;}}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cppindex 9c690a503..9f4d65775 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp@@ -506,6 +506,18 @@ Bool DumbProjectileBehavior::calcFlightPath(Bool recalcNumSegments){retailSegments = m_flightPathSegments > 1 ? (m_flightPathSegments - 1) / LOGICFRAMES_PER_RETAIL_FRAME + 1 : m_flightPathSegments;}+ // A speed of zero or next to it (every crash report of this ran End of Days) asks for a flight of hundreds of+ // millions of frames, or an infinite one that comes back as INT_MIN. The path that size needs is+ // gigabytes, and a request past 2 GB came back from the allocator short and was written past its+ // end. Ten minutes of flight is more than any shell flies; past that the path is as wrong as one+ // off the map.+ const Int MAX_RETAIL_SEGMENTS = 10 * 60 * RETAIL_LOGICFRAMES_PER_SECOND;+ if (retailSegments < 0 || retailSegments > MAX_RETAIL_SEGMENTS)+ {+ DEBUG_LOG(("DumbProjectileBehavior: '%s' asked for a flight of %d frames at speed %g, dropped\n",+ getObject()->getTemplate()->getName().str(), retailSegments, m_flightPathSpeed));+ return false;+ }VecCoord3D retailPath;flightCurve.getSegmentPoints( retailSegments, &retailPath );m_flightPathSegments = retailSegments > 1 ? (retailSegments - 1) * LOGICFRAMES_PER_RETAIL_FRAME + 1 : retailSegments;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cppindex 7b22c114c..dc4c89a8a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp@@ -1755,11 +1755,13 @@ void OpenContain::xfer( Xfer *xfer )} // end if- // contain list size- xfer->xferUnsignedInt( &m_containListSize );+ // contain list size; the count stays at the empty list's zero until loadPostProcess fills the+ // list, so a load that throws before then leaves no container claiming riders it has not got+ UnsignedInt containCount;+ xfer->xferUnsignedInt( &containCount );// read all contained items- for( UnsignedInt i = 0; i < m_containListSize; ++i )+ for( UnsignedInt i = 0; i < containCount; ++i ){// read id@@ -1919,6 +1921,7 @@ void OpenContain::loadPostProcess( void )// put object on listm_containList.push_back( obj );+ m_containListSize++;// remove this object from the world if we need toif( isEnclosingContainerFor( obj ) )@@ -1942,10 +1945,6 @@ void OpenContain::loadPostProcess( void )}}- // sanity- DEBUG_ASSERTCRASH( m_containListSize == m_containList.size(),- ("OpenContain::loadPostProcess - contain list count mismatch\n") );-// clear the list as we don't need it anymorem_xferContainIDList.clear();diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cppindex 52060be31..751b05381 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp@@ -333,7 +333,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, covoid MissileAIUpdate::projectileLeadVictim( const Object *victim ){const PhysicsBehavior *victimPhysics = victim->getPhysics();- if (m_isTrackingTarget || victimPhysics == NULL || victim->isAboveTerrain())+ if (m_isTrackingTarget || victimPhysics == NULL || victim->isAboveTerrain() || getCurLocomotor() == NULL)return;const Coord3D *from = getObject()->getPosition();@@ -756,6 +756,11 @@ void MissileAIUpdate::updateChaseOffset()const Real SWAY_FADE_FAR = 150.0f;const Real SWAY_FADE_NEAR = 60.0f;+ // a mod missile can come without a locomotor and fly on its launch force alone; nothing to steer+ Locomotor* curLoco = getCurLocomotor();+ if (curLoco == NULL)+ return;+Coord3D offset;offset.zero();Object* victim = m_isTrackingTarget ? getGoalObject() : NULL;@@ -788,7 +793,7 @@ void MissileAIUpdate::updateChaseOffset()}}- getCurLocomotor()->setChaseOffset(offset);+ curLoco->setChaseOffset(offset);}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cppindex 03da34acc..e4152ad06 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp@@ -39,6 +39,7 @@#include "Common/ThingFactory.h"#include "Common/Player.h"#include "Common/PlayerList.h"+#include "Common/SpecialPower.h"#include "Common/Xfer.h"#include "Common/ClientUpdateModule.h"@@ -269,6 +270,19 @@ void ParticleUplinkCannonUpdate::onObjectCreated()}m_specialPowerModule = obj->getSpecialPowerModule( data->m_specialPowerTemplate );+ if( !m_specialPowerModule )+ {+ // FixesReforged.ini replaces the Superweapon General's cannon module naming EA's power, and a+ // mod that gives that cannon a power of its own name keeps it on the building's special power+ // module. Drive the building's power of the same kind.+ m_specialPowerModule = obj->findSpecialPowerModuleInterface( data->m_specialPowerTemplate->getSpecialPowerType() );+ }+ if( !m_specialPowerModule )+ {+ DEBUG_CRASH( ("%s object's ParticleUplinkCannonUpdate finds no special power module for %s.", obj->getTemplate()->getName().str(), data->m_specialPowerTemplate->getName().str() ) );+ m_invalidSettings = TRUE;+ return;+ }m_connectorNodePosition.set( obj->getPosition() );m_laserOriginPosition.set( obj->getPosition() );@@ -288,7 +302,7 @@ Bool ParticleUplinkCannonUpdate::initiateIntentToDoSpecialPower(const SpecialPow{const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();- if( m_specialPowerModule->getSpecialPowerTemplate() != specialPowerTemplate )+ if( !m_specialPowerModule || m_specialPowerModule->getSpecialPowerTemplate() != specialPowerTemplate ){//Check to make sure our modules are connected.return FALSE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cppindex 6229a9dbf..9773eed3d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp@@ -235,8 +235,8 @@ UpdateSleepTime SlavedUpdate::update( void )if( data->m_scoutRange ){//3RD PRIORITY: Hover above master's current move destination (as close as wander distance- //allows).- if( masterAI->getPath() )+ //allows). A master with no AI is a building and never moves.+ if( masterAI && masterAI->getPath() ){const Coord3D *masterDest = masterAI->getPath()->getLastNode()->getPosition();diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex 27cce3e0b..38c24c130 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -1915,9 +1915,19 @@ void GameLogic::startNewGame( Bool loadingSaveGame )// update the loadscreenupdateLoadProgress(LOAD_PROGRESS_POST_PATHFINDER_NEW_MAP);- // reveal the map for the permanent observer- ThePartitionManager->revealMapForPlayerPermanently( ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey("ReplayObserver"))->getPlayerIndex() );- DEBUG_LOG(("Reveal shroud for %s whose index is %d\n", WideCharAsUtf8( ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey("ReplayObserver"))->getPlayerDisplayName().str() ).str(),ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey("ReplayObserver"))->getPlayerIndex()));+ // reveal the map for the permanent observer. The observer side goes in after the map's own, and a+ // map whose sides already fill all MAX_PLAYER_COUNT seats leaves it no room (SidesList::addSide+ // drops it), so such a match simply has no observer to reveal for.+ Player *replayObserver = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey("ReplayObserver"));+ if (replayObserver)+ {+ ThePartitionManager->revealMapForPlayerPermanently( replayObserver->getPlayerIndex() );+ DEBUG_LOG(("Reveal shroud for %s whose index is %d\n", WideCharAsUtf8( replayObserver->getPlayerDisplayName().str() ).str(), replayObserver->getPlayerIndex()));+ }+ else+ {+ DEBUG_LOG(("No ReplayObserver: the map's %d sides leave no seat for one\n", TheSidesList->getNumSides()));+ }if (game){@@ -2464,7 +2474,11 @@ void GameLogic::startNewGame( Bool loadingSaveGame )if(m_gameMode == GAME_REPLAY ){- ThePlayerList->setLocalPlayer(ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey("ReplayObserver")));+ // a map that filled every seat has no observer (see the reveal above); the replay then+ // watches from the seat it was recorded in+ Player *observer = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey("ReplayObserver"));+ if (observer)+ ThePlayerList->setLocalPlayer(observer);TheRadar->forceOn(TRUE);ThePartitionManager->refreshShroudForLocalPlayer();TheControlBar->setControlBarSchemeByPlayer( ThePlayerList->getLocalPlayer());diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex caf9060e3..8acef1735 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -402,6 +402,13 @@ void GameLogic::clearGameData( Bool showScoreScreen )if( !isInShellGame() )TheWritableGlobalData->m_noDraw = 0;+ // A single-player start is two passes: the first puts the load screen up and plays its movie, the+ // next update loads the map. Cleared in between, that start is off, and its load screen goes now:+ // the reset below closes every video stream, the load screen's own among them, and a later start+ // that found it still up drew through it and then deleted it, closing that stream a second time.+ deleteLoadScreen();+ m_startNewGame = FALSE;+TheGameEngine->reset();setGameMode(GAME_NONE);// m_background->bringForward();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cppindex c2f77ccd0..b85a752cd 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp@@ -1009,10 +1009,16 @@ void W3DRadar::update( void )// phase 3).if( m_overlayDrawn && TheGameClient->getFrame() % OVERLAY_REFRESH_RATE == 0 ){+ // The simulation runs on while the device is lost (the log's "Direct3D device LOST", a driver+ // reset), and then the texture has no surface to give. Nothing can be drawn into it until the+ // device is back; the next refresh redraws the overlay whole.+ SurfaceClass *surface = m_overlayTexture->Get_Surface_Level();+ if( surface == NULL )+ return;+m_overlayDrawn = FALSE;// reset the overlay texture- SurfaceClass *surface = m_overlayTexture->Get_Surface_Level();surface->Clear();REF_PTR_RELEASE(surface);diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cppindex b6912fe25..bd1f8c6b4 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp@@ -696,7 +696,15 @@ TextureClass * W3DAssetManager::Recolor_Texture_One_Time(TextureClass *texture,Int psize;psize=PixelSize(desc);- DEBUG_ASSERTCRASH( psize == 2 || psize == 4, ("Can't Recolor Texture %s", name) );+ // The palette remap reads 16- and 32-bit pixels and nothing else. A mod's house-colour texture+ // shipped compressed (DXT) or in another format has nothing it can remap, and Direct3D 9 refuses+ // the scratch surface for some of them (a DXT image whose sides are not multiples of 4), which+ // left newsurf without a surface for Copy to crash on. The unit keeps the texture uncoloured.+ if (psize != 2 && psize != 4)+ {+ DEBUG_LOG(("Can't recolor texture %s: format %d is not 16 or 32 bit\n", name, (Int)desc.Format));+ return NULL;+ }oldsurf=texture->Get_Surface_Level();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex aff8bd458..21ccaf1bb 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -1043,7 +1043,10 @@ void W3DInGameUI::takeBuildGrid( void )if( blocked && cell->getType() == PathfindCell::CELL_OBSTACLE ){- blocked = !BuildAssistant_isHiddenFromLocalPlayer( TheGameLogic->findObjectByID( cell->getObstacleID() ) );+ // the cell can still name an object the tick has already destroyed; nothing is left to+ // hide, and the pathfinder still refuses the cell, so it draws red+ const Object *obstacle = TheGameLogic->findObjectByID( cell->getObstacleID() );+ blocked = obstacle == NULL || !BuildAssistant_isHiddenFromLocalPlayer( obstacle );}else if( blocked && cell->getType() == PathfindCell::CELL_RUBBLE ){diff --git a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cppindex 84e4efadc..e51a663b4 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp@@ -69,11 +69,13 @@ static const char *const BASE_GAME_ARCHIVE = "Textures.big";// over; a copied-over install puts the same bigs in ZH_Generals next to the exe. The First Decade// does the same with its own folder name, and registers the collection's root folder as the base// game's InstallPath, so a player on v2.0.1 got "no base game archives" with Generals one folder-// over.+// over. The EA app and Origin spell it with "and", under one folder holding both games, and register+// no InstallPath for it: three v3.2.0 reports from such installs stopped at "no base game archives".static const char *const BASE_GAME_DIRECTORIES[] = {"ZH_Generals\\","..\\Command & Conquer Generals\\","..\\Command & Conquer(tm) Generals\\",+ "..\\Command and Conquer Generals\\",};// The folder inside the First Decade's registered root that holds the base game.