[Neo-Desktop Refactor] [CLI] off-by-one fix and flavour pidgen type override (#108)

* Minor bugfixes in CLI

* Add 1 to modulus operations, fixes user-supplied all-nines channel ID and serial number

* Use product instead of flavor when checking pidgen type (fixes BINK ID autoselection for products with flavors)

* Fix sanity check for invalid serial and channel ID

* Much better way. Now flavor pidgen type is checked for and overridden in case it's different from the product's pidgen type. This allows Visual Studio 5/6 key generation to work properly again

thank you @aplumafreak500 !
This commit is contained in:
Alex Pensinger 2024-11-10 23:42:24 -05:00 committed by GitHub
parent 7a0faa42e8
commit 1cedbff4ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 7 deletions

View File

@ -244,13 +244,19 @@ BOOL CLI::processOptions()
flavour = product;
}
auto pidtype = product["meta"]["type"];
if (flavour["meta"].contains("type"))
{
pidtype = flavour["meta"]["type"];
}
if (options.state != Options::STATE_PIDGEN_GENERATE && options.state != Options::STATE_PIDGEN_VALIDATE)
{
// exit early if we're not doing PIDGEN
goto processOptionsExitEarly;
}
if (flavour["meta"]["type"] == "PIDGEN3")
if (pidtype == "PIDGEN3")
{
options.pidgenversion = Options::PIDGEN_VERSION::PIDGEN_3;
if (options.verbose)
@ -272,7 +278,7 @@ BOOL CLI::processOptions()
fmt::print("Selected BINK: {}\n", options.binkID);
}
}
else if (flavour["meta"]["type"] == "PIDGEN2")
else if (pidtype == "PIDGEN2")
{
options.pidgenversion = Options::PIDGEN_VERSION::PIDGEN_2;
if (options.verbose)
@ -544,7 +550,7 @@ BOOL CLI::SetChannelIDOption(const std::string &channum)
Integer channelID = UMSKT::IntegerS(channum);
// channel ids must be between 000 and 999
if (channelID > PIDGEN::MaxChannelID)
if (channelID >= PIDGEN::MaxChannelID)
{
fmt::print("ERROR: refusing to create a key with a Channel ID greater than 999\n");
return false;
@ -588,7 +594,7 @@ BOOL CLI::SetSerialOption(const std::string &arg)
Integer Serial = UMSKT::IntegerS(arg);
// serials must be between 000000 and 999999
if (Serial > PIDGEN::MaxSerial)
if (Serial >= PIDGEN::MaxSerial)
{
fmt::print("ERROR: refusing to create a key with a Serial not between 000000 and 999999\n");
return false;

View File

@ -59,7 +59,7 @@ BOOL CLI::InitPIDGEN3(PIDGEN3 *p3)
options.channelID.Randomize(UMSKT::rng, sizeof(DWORD32) * 8);
}
options.channelID %= 999;
options.channelID %= 1000;
p3->info.ChannelID = options.channelID;
if (options.verbose)
{
@ -162,7 +162,7 @@ BOOL CLI::PIDGEN3Generate(PIDGEN3 *p3)
}
// make sure it's less than 999999
serialRnd %= 999999;
serialRnd %= 1000000;
}
p3->info.isOEM = options.oem;
@ -316,4 +316,4 @@ BOOL CLI::PIDValidate()
}
return retval;
}
}