Skip to content

Commit

Permalink
tools/cxbe: Added -TITLEID:{%c%c-%u|%x}
Browse files Browse the repository at this point in the history
The Title ID is interpreted in Main.cpp and passed as x_dwTitleID when creating the XBE. Title IDs can be in human-readable form (like CX-9999) or a hex code (like 4358270F). Strings without - in them are tried as hex codes.
  • Loading branch information
PQCraft committed Jul 28, 2023
1 parent d368083 commit 3505eb7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
50 changes: 43 additions & 7 deletions tools/cxbe/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ int main(int argc, char *argv[])
char szXbeFilename[OPTION_LEN + 1] = { 0 };
char szDumpFilename[OPTION_LEN + 1] = { 0 };
char szXbeTitle[OPTION_LEN + 1] = "Untitled";
char szXbeTitleID[OPTION_LEN + 1] = "";
char szMode[OPTION_LEN + 1] = "retail";
char szLogo[OPTION_LEN + 1] = "";
char szDebugPath[OPTION_LEN + 1] = "";

bool bRetail;
uint32 dwTitleId = 0x4358270F; // CX-9999

const char *program = argv[0];
const char *program_desc = "CXBE EXE to XBE (win32 to Xbox) Relinker (Version: " VERSION ")";
Option options[] = {
{ szExeFilename, NULL, "exefile" }, { szXbeFilename, "OUT", "filename" },
{ szDumpFilename, "DUMPINFO", "filename" }, { szXbeTitle, "TITLE", "title" },
{ szMode, "MODE", "{debug|retail}" }, { szLogo, "LOGO", "filename" },
{ szDebugPath, "DEBUGPATH", "path" }, { NULL }
};
Option options[] = { { szExeFilename, NULL, "exefile" },
{ szXbeFilename, "OUT", "filename" },
{ szDumpFilename, "DUMPINFO", "filename" },
{ szXbeTitle, "TITLE", "title" },
{ szXbeTitleID, "TITLEID", "{%c%c-%u|%x}" },
{ szMode, "MODE", "{debug|retail}" },
{ szLogo, "LOGO", "filename" },
{ szDebugPath, "DEBUGPATH", "path" },
{ NULL } };

if(ParseOptions(argv, argc, options, szErrorMessage))
{
Expand All @@ -54,6 +60,36 @@ int main(int argc, char *argv[])
szXbeTitle[40] = '\0';
}

// interpret title id
if(szXbeTitleID[0])
{
bool hex = true;
for(int i = 0; szXbeTitleID[i]; ++i)
{
if(szXbeTitleID[i] == '-')
{
hex = false;
break;
}
}
if(hex)
{
sscanf(szXbeTitleID, "%x", &dwTitleId);
}
else
{
char titlechar[2] = { 'C', 'X' };
unsigned titleno = 9999;
sscanf(szXbeTitleID, "%c%c-%u", &titlechar[0], &titlechar[1], &titleno);
if(titleno > 0xFFFF)
{
printf("WARNING: Title ID number too high (max is 65535)\n");
titleno = 0xFFFF;
}
dwTitleId = (titlechar[0] << 24) | (titlechar[1] << 16) | titleno;
}
}

// verify we received the required parameters
if(szExeFilename[0] == '\0')
{
Expand Down Expand Up @@ -90,7 +126,7 @@ int main(int argc, char *argv[])
LogoPtr = &logo;
}

Xbe *XbeFile = new Xbe(ExeFile, szXbeTitle, bRetail, LogoPtr, szDebugPath);
Xbe *XbeFile = new Xbe(ExeFile, szXbeTitle, dwTitleId, bRetail, LogoPtr, szDebugPath);

if(XbeFile->GetError() != 0)
{
Expand Down
7 changes: 3 additions & 4 deletions tools/cxbe/Xbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ static size_t BasenameOffset(const std::string &path)
}

// construct via Exe file object
Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vector<uint08> *logo,
const char *x_szDebugPath)
Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, uint32 x_dwTitleID, bool x_bRetail,
const std::vector<uint08> *logo, const char *x_szDebugPath)
{
ConstructorInit();

Expand Down Expand Up @@ -279,8 +279,7 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec

m_Certificate.dwTimeDate = CurrentTime;

// TODO: generate in the form CX-9999
m_Certificate.dwTitleId = 0xFFFF0002;
m_Certificate.dwTitleId = x_dwTitleID;

// title name
memset(m_Certificate.wszTitleName, 0, sizeof(m_Certificate.wszTitleName));
Expand Down
2 changes: 1 addition & 1 deletion tools/cxbe/Xbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Xbe : public Error
{
public:
// construct via Exe file object
Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail,
Xbe(class Exe *x_Exe, const char *x_szTitle, uint32 x_dwTitleID, bool x_bRetail,
const std::vector<uint08> *logo = nullptr, const char *x_szDebugPath = nullptr);

// deconstructor
Expand Down

0 comments on commit 3505eb7

Please sign in to comment.