Skip to content

Commit d879baf

Browse files
committed
Prevent (lock)achievement console commands from interpreting negative numbers as their positive version, and (un)locking that achievement
Example: `lockachievement -1` would lock Maggy. This can potentially be triggered by a mod unintentionally due to GetAchievementIdByName returning -1 for incorrect names
1 parent ec27b65 commit d879baf

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

repentogon/Patches/AchievementsStuff.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ HOOK_METHOD(Manager, SetSaveSlot, (unsigned int slot) -> void) {
261261
}
262262

263263
bool LockAchievement(int achievementid) {
264-
if (!achset) { return false; }
264+
if (!achset || achievementid <= 0) { return false; }
265265
if (achievementid < 641) {
266266
PersistentGameData* ps = g_Manager->GetPersistentGameData();
267267
bool had = ps->achievements[achievementid];
@@ -287,7 +287,7 @@ static std::vector<std::string> ParseCommandA(std::string command, int size = 0)
287287
std::string cmdlet;
288288
char space = ' ';
289289
while (std::getline(sstream, cmdlet, space)) {
290-
cmdlet.erase(std::remove_if(cmdlet.begin(), cmdlet.end(), ispunct), cmdlet.end());
290+
// cmdlet.erase(std::remove_if(cmdlet.begin(), cmdlet.end(), ispunct), cmdlet.end());
291291
cmdlets.push_back(cmdlet);
292292
if (size > 0 && cmdlets.size() == size) {
293293
break;
@@ -317,7 +317,7 @@ HOOK_METHOD(Console, RunCommand, (std_string& in, std_string* out, Entity_Player
317317
std::vector<std::string> cmdlets = ParseCommandA(in, 2);
318318
if (cmdlets.size() > 1) {
319319
int id = toint(cmdlets[1]);
320-
if (id == 0) {
320+
if (id <= 0) {
321321
g_Game->GetConsole()->PrintError("No achievement Id Provided. \n");
322322
}
323323
else if (LockAchievement(id)) {
@@ -334,7 +334,7 @@ HOOK_METHOD(Console, RunCommand, (std_string& in, std_string* out, Entity_Player
334334
if (cmdlets.size() < 2) { g_Game->GetConsole()->PrintError("No achievement Id Provided. \n"); super(in, out, player); return; }
335335
int id = toint(cmdlets[1]);
336336
PersistentGameData* ps = g_Manager->GetPersistentGameData();
337-
if (id == 0) {
337+
if (id <= 0) {
338338
g_Game->GetConsole()->PrintError("No achievement Id Provided. \n");
339339
}
340340
else if (ps->TryUnlock(id)) {

0 commit comments

Comments
 (0)