Skip to content

Commit

Permalink
tools/cxbe: Added -REGION:{-|[n][j][w][m]|a}
Browse files Browse the repository at this point in the history
Region flags can be 'a' for all regions, '-' for no regions, or any combo of 'n' for North America, 'j' for Japan, 'w' for world, and/or 'm' for manufacturing
  • Loading branch information
PQCraft committed Jul 28, 2023
1 parent 3505eb7 commit 46b8489
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
68 changes: 58 additions & 10 deletions tools/cxbe/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,31 @@ int main(int argc, char *argv[])
char szDumpFilename[OPTION_LEN + 1] = { 0 };
char szXbeTitle[OPTION_LEN + 1] = "Untitled";
char szXbeTitleID[OPTION_LEN + 1] = "";
char szXbeRegions[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
uint32 dwRegions;

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" },
{ szXbeTitleID, "TITLEID", "{%c%c-%u|%x}" },
{ 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}" },
{ szXbeRegions, "REGION",
"{-|[n][j][w][m]|a}\n"
" -=none, n=North America, j=Japan, w=world, m=manufacturing, a=njwm" },
{ szMode, "MODE", "{debug|retail}" },
{ szLogo, "LOGO", "filename" },
{ szDebugPath, "DEBUGPATH", "path" },
{ NULL }
};

if(ParseOptions(argv, argc, options, szErrorMessage))
{
Expand Down Expand Up @@ -90,6 +97,47 @@ int main(int argc, char *argv[])
}
}

// interpret region flags
if(szXbeRegions[0])
{
char c;
for(int i = 0; (c = szXbeRegions[i]); ++i)
{
switch(c)
{
case '-':;
dwRegions = 0;
goto breakfor;
case 'a':;
dwRegions = XBEIMAGE_GAME_REGION_NA | XBEIMAGE_GAME_REGION_JAPAN |
XBEIMAGE_GAME_REGION_RESTOFWORLD |
XBEIMAGE_GAME_REGION_MANUFACTURING;
goto breakfor;
case 'n':;
dwRegions |= XBEIMAGE_GAME_REGION_NA;
break;
case 'j':;
dwRegions |= XBEIMAGE_GAME_REGION_JAPAN;
break;
case 'w':;
dwRegions |= XBEIMAGE_GAME_REGION_RESTOFWORLD;
break;
case 'm':;
dwRegions |= XBEIMAGE_GAME_REGION_MANUFACTURING;
break;
default:;
printf("WARNING: Invalid region char: %c\n", c);
break;
}
}
breakfor:;
}
else
{
dwRegions = XBEIMAGE_GAME_REGION_NA | XBEIMAGE_GAME_REGION_JAPAN |
XBEIMAGE_GAME_REGION_RESTOFWORLD | XBEIMAGE_GAME_REGION_MANUFACTURING;
}

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

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

if(XbeFile->GetError() != 0)
{
Expand Down
9 changes: 3 additions & 6 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, uint32 x_dwTitleID, 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, uint32 x_dwRegions,
bool x_bRetail, const std::vector<uint08> *logo, const char *x_szDebugPath)
{
ConstructorInit();

Expand Down Expand Up @@ -304,10 +304,7 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, uint32 x_dwTitleID, bool x_bRe
XBEIMAGE_MEDIA_TYPE_MEDIA_BOARD | XBEIMAGE_MEDIA_TYPE_NONSECURE_HARD_DISK |
XBEIMAGE_MEDIA_TYPE_NONSECURE_MODE;

// TODO: allow configuration
m_Certificate.dwGameRegion = XBEIMAGE_GAME_REGION_MANUFACTURING |
XBEIMAGE_GAME_REGION_NA | XBEIMAGE_GAME_REGION_JAPAN |
XBEIMAGE_GAME_REGION_RESTOFWORLD;
m_Certificate.dwGameRegion = x_dwRegions;

// TODO: allow configuration
m_Certificate.dwGameRatings = 0xFFFFFFFF;
Expand Down
4 changes: 2 additions & 2 deletions tools/cxbe/Xbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Xbe : public Error
{
public:
// construct via Exe file object
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);
Xbe(class Exe *x_Exe, const char *x_szTitle, uint32 x_dwTitleID, uint32 x_dwRegions,
bool x_bRetail, const std::vector<uint08> *logo = nullptr, const char *x_szDebugPath = nullptr);

// deconstructor
~Xbe();
Expand Down

0 comments on commit 46b8489

Please sign in to comment.