Skip to content

Commit 03fbd6a

Browse files
committed
cyka
1 parent 42f488b commit 03fbd6a

9 files changed

Lines changed: 90 additions & 2 deletions

File tree

‎docs/User-Interface.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,16 @@ In `RA2MD.ini`:
589589
[Phobos]
590590
SaveGameOnScenarioStart=true ; boolean
591591
```
592+
593+
594+
### Forbid saving game
595+
596+
Game save can be forbidden in singleplayer games as some sort of "hardcore" mode. All existing save/load functionalities will be disabled.
597+
- When trying to click the save button, a message box with `TXT_HARDCORE_NOSAVE` CSF entry will appear instead of saving the game.
598+
- Scenarios successions will be disabled as well.
599+
- On the loading screen, the single-frame `hardcorelogo.shp` (for `Palette.pal`) will be drawn on the top right corner of the screen. If not present, the text with csf `TXT_HARDCORE_MODE` will be displayed instead.
600+
In `RA2MD.ini`:
601+
```ini
602+
[Phobos]
603+
NoSaveLoad=false ; boolean
604+
```

‎docs/Whats-New.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ ToolTipDescriptions=true ; boolean
9292
ToolTipBlur=false ; boolean
9393
SaveGameOnScenarioStart=true ; boolean
9494
HideLightFlashEffects=false ; boolean
95+
NoSaveLoad = false ; boolean
9596
```
9697

9798
### For Map Editor (Final Alert 2)
@@ -549,6 +550,7 @@ Vanilla fixes:
549550
- Fixed infantry `SecondaryFire` / `SecondaryProne` sequences being displayed in water instead of `WetAttack` (by Starkku)
550551
- Fixed objects with ally target and `AttackFriendlies=true` having their target reset every frame, particularly AI-owned buildings (by Starkku)
551552
- Follower vehicle index for preplaced vehicles in maps is now explicitly constrained to `[Units]` list in map files and is no longer thrown off by vehicles that could not be created or created vehicles having other vehicles as initial passengers (by Starkku)
553+
- Save game disabler (by Trsdy)
552554
553555
Phobos fixes:
554556
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)

‎src/Commands/QuickSave.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ void QuickSaveCommandClass::Execute(WWKey eInput) const
3737
);
3838
};
3939

40+
if(Phobos::Config::NoSaveLoad)
41+
{
42+
PrintMessage(StringTable::LoadString(GameStrings::TXT_ERROR_SAVING_GAME));
43+
return;
44+
}
45+
4046
if (SessionClass::IsSingleplayer())
4147
{
4248
*reinterpret_cast<bool*>(0xABCE08) = false;

‎src/Ext/Scenario/Body.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ void ScenarioExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
148148
this->ShowBriefing = ini_missionmd.ReadBool(scenarioName, "ShowBriefing", pINI->ReadBool(GameStrings::Basic, "ShowBriefing", this->ShowBriefing));
149149
this->BriefingTheme = ini_missionmd.ReadTheme(scenarioName, "BriefingTheme", pINI->ReadTheme(GameStrings::Basic, "BriefingTheme", this->BriefingTheme));
150150

151+
if (Phobos::Config::NoSaveLoad)
152+
ScenarioClass::Instance->EndOfGame = true;
151153
}
152154
}
153155

‎src/Misc/Hooks.PCX.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,30 @@ DEFINE_HOOK(0x552FCB, LoadProgressMgr_Draw_PCXLoadingScreen_Campaign, 0x6)
8383
return 0;
8484
}
8585

86+
DEFINE_HOOK(0x553076,LoadProgressMgr_Draw_ExtraText_Campaign,0x5)
87+
{
88+
GET(LoadProgressManager*, self, EBP);
89+
if(Phobos::Config::NoSaveLoad)
90+
{
91+
Point2D pos
92+
{
93+
self->TitleBarRect.X + self->TitleBarRect.Width - 100,
94+
self->TitleBarRect.Y + 10
95+
};
96+
LEA_STACK(RectangleStruct*, pBnd, STACK_OFFSET(0x1268,-0x1204));
97+
if(auto logo = FileSystem::LoadSHPFile("hardcorelogo.shp"))
98+
{
99+
self->ProgressSurface->DrawSHP(FileSystem::PALETTE_PAL,logo,0,&pos,pBnd,BlitterFlags::bf_400,0,0,ZGradient::Ground,1000,0,nullptr,0,0,0);
100+
}
101+
else
102+
{
103+
auto msg = GeneralUtils::LoadStringUnlessMissing("TXT_HARDCORE_MODE",L"HARDCORE");
104+
self->ProgressSurface->DrawTextA(msg,&pos,COLOR_RED);
105+
}
106+
}
107+
return 0;
108+
}
109+
86110
DEFINE_HOOK(0x6A99F3, StripClass_Draw_DrawMissing, 0x6)
87111
{
88112
GET_STACK(SHPStruct*, pCameo, STACK_OFFSET(0x48C, -0x444));

‎src/Misc/RetryDialog.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <GameOptionsClass.h>
77
#include <GScreenClass.h>
88
#include <EvadeClass.h>
9+
#include <Phobos.h>
910

1011
namespace RetryDialogFlag
1112
{
@@ -16,6 +17,12 @@ DEFINE_HOOK(0x686092, DoLose_RetryDialogForCampaigns, 0x7)
1617
{
1718
enum { OK = 0x6860F6, Cancel = 0x6860EE, LoadGame = 0x686231 };
1819

20+
if(Phobos::Config::NoSaveLoad)
21+
{
22+
WWMessageBox::Instance->Process(L"GG",StringTable::LoadString(GameStrings::TXT_OK),nullptr,nullptr);
23+
return Cancel;
24+
}
25+
1926
while (true)
2027
{
2128
// WWMessageBox buttons look like below:

‎src/Phobos.Ext.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ DEFINE_HOOK(0x67D04E, GameSave_SavegameInformation, 0x7)
279279
Info.ExecutableName.Size - sizeof(" + Phobos " FILE_VERSION_STR)
280280
);
281281

282+
if (Phobos::Config::NoSaveLoad)
283+
{
284+
// You've somehow cheated to make through this
285+
Debug::FatalErrorAndExit("Hard Core mode enabled, save game not allowed!");
286+
}
287+
282288
return 0;
283289
}
284290

‎src/Phobos.INI.cpp‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include <SessionClass.h>
66
#include <MessageListClass.h>
77
#include <HouseClass.h>
8-
8+
#include <LoadOptionsClass.h>
9+
#include <WWMessageBox.h>
910
#include <Utilities/Parser.h>
1011
#include <Utilities/GeneralUtils.h>
1112
#include <Utilities/Patch.h>
@@ -55,6 +56,7 @@ bool Phobos::Config::ShowHarvesterCounter = false;
5556
bool Phobos::Config::ShowPowerDelta = true;
5657
bool Phobos::Config::ShowWeedsCounter = false;
5758
bool Phobos::Config::HideLightFlashEffects = true;
59+
bool Phobos::Config::NoSaveLoad = false;
5860

5961
bool Phobos::Misc::CustomGS = false;
6062
int Phobos::Misc::CustomGS_ChangeInterval[7] = { -1, -1, -1, -1, -1, -1, -1 };
@@ -92,6 +94,13 @@ DEFINE_HOOK(0x5FACDF, OptionsClass_LoadSettings_LoadPhobosSettings, 0x5)
9294
}
9395

9496
Phobos::Config::ShowDesignatorRange = CCINIClass::INI_RA2MD->ReadBool("Phobos", "ShowDesignatorRange", false);
97+
Phobos::Config::NoSaveLoad = CCINIClass::INI_RA2MD->ReadBool("Phobos", "NoSaveLoad", false);
98+
if (Phobos::Config::NoSaveLoad)
99+
{
100+
Patch::Apply_LJMP(0x55DBCD, 0x55DC99); // Disable MainLoop_SaveGame
101+
Patch::Apply_RAW(0x67CEF0, {0x33,0xC0,0xC3}); // Corrupt savegame function
102+
Patch::Apply_TYPED(0x83D560, {(DWORD)std::rand()}); // Corrupt save game magicn
103+
}
95104

96105
CCINIClass ini_uimd {};
97106
ini_uimd.LoadFromFile(GameStrings::UIMD_INI);
@@ -259,7 +268,7 @@ DEFINE_HOOK(0x55DBCD, MainLoop_SaveGame, 0x6)
259268
enum { SkipSave = 0x55DC99, InitialSave = 0x55DBE6 };
260269

261270
bool& scenario_saved = *reinterpret_cast<bool*>(0xABCE08);
262-
if (SessionClass::IsSingleplayer() && !scenario_saved)
271+
if (SessionClass::IsSingleplayer() && !scenario_saved && !Phobos::Config::NoSaveLoad)
263272
{
264273
scenario_saved = true;
265274
if (Phobos::ShouldQuickSave)
@@ -274,3 +283,21 @@ DEFINE_HOOK(0x55DBCD, MainLoop_SaveGame, 0x6)
274283

275284
return SkipSave;
276285
}
286+
287+
// Yeah I know you are going to say Ares pre 0.A had similar save/load button disable, but better not use that less informative approach
288+
DEFINE_HOOK(0x558DDC, LoadOptionsClass_MakeDlg_NoSL, 0x5)
289+
{
290+
if (!Phobos::Config::NoSaveLoad)
291+
return 0;
292+
293+
GET(LoadOptionsClass*, self, ESI);
294+
if (self->Mode != LoadOptionsMode::Save && self->Mode != LoadOptionsMode::Load)
295+
return 0;
296+
297+
WWMessageBox::Instance->Process(
298+
GeneralUtils::LoadStringUnlessMissing("TXT_HARDCORE_NOSAVE",L"Hard-Core mode on, save/load forbidden!"),
299+
StringTable::LoadString(GameStrings::TXT_OK),
300+
nullptr, nullptr
301+
);
302+
return 0x558EA9;
303+
}

‎src/Phobos.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Phobos
9090
static bool ShowWeedsCounter;
9191
static bool ShowPlanningPath;
9292
static bool HideLightFlashEffects;
93+
static bool NoSaveLoad;
9394
};
9495

9596
class Misc

0 commit comments

Comments
 (0)