Initial commit of Command & Conquer Generals and Command & Conquer Generals Zero Hour source code.
This commit is contained in:
parent
2e338c00cb
commit
3d0ee53a05
6072 changed files with 2283311 additions and 0 deletions
193
GeneralsMD/Code/Tools/Launcher/DatGen/DatGen.cpp
Normal file
193
GeneralsMD/Code/Tools/Launcher/DatGen/DatGen.cpp
Normal file
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
** Command & Conquer Generals Zero Hour(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// DatGen.cpp : Defines the entry point for the application.
|
||||
//
|
||||
|
||||
#include <windows.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "bfish.h"
|
||||
#include "SafeDisk\CdaPfn.h"
|
||||
#include <Debug\DebugPrint.h>
|
||||
|
||||
void __cdecl doIt(void);
|
||||
|
||||
CDAPFN_DECLARE_GLOBAL(doIt, CDAPFN_OVERHEAD_L5, CDAPFN_CONSTRAINT_NONE);
|
||||
|
||||
static void doIt(void)
|
||||
{
|
||||
// Generate passkey
|
||||
char passKey[128];
|
||||
passKey[0] = '\0';
|
||||
unsigned char installPath[MAX_PATH] = "";
|
||||
|
||||
// Get game information
|
||||
HKEY hKey;
|
||||
bool usesHKeycurrentUser = false;
|
||||
LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour", 0, KEY_READ, &hKey);
|
||||
if (result != ERROR_SUCCESS)
|
||||
{
|
||||
result = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour", 0, KEY_READ, &hKey);
|
||||
usesHKeycurrentUser = true;
|
||||
}
|
||||
assert((result == ERROR_SUCCESS) && "Failed to open game registry key");
|
||||
|
||||
if (result != ERROR_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Retrieve install path
|
||||
DWORD type;
|
||||
DWORD sizeOfBuffer = sizeof(installPath);
|
||||
result = RegQueryValueEx(hKey, "InstallPath", NULL, &type, installPath, &sizeOfBuffer);
|
||||
|
||||
assert((result == ERROR_SUCCESS) && "Failed to obtain game install path!");
|
||||
assert((strlen((const char*)installPath) > 0) && "Game install path invalid!");
|
||||
DebugPrint("Game install path: %s\n", installPath);
|
||||
|
||||
// Retrieve Hard drive S/N
|
||||
char drive[8];
|
||||
_splitpath((const char*)installPath, drive, NULL, NULL, NULL);
|
||||
strcat(drive, "\\");
|
||||
|
||||
DWORD volumeSerialNumber = 0;
|
||||
DWORD maxComponentLength;
|
||||
DWORD fileSystemFlags;
|
||||
BOOL volInfoSuccess = GetVolumeInformation((const char*)drive, NULL, 0,
|
||||
&volumeSerialNumber, &maxComponentLength, &fileSystemFlags, NULL, 0);
|
||||
|
||||
if (volInfoSuccess == FALSE)
|
||||
{
|
||||
PrintWin32Error("***** GetVolumeInformation() Failed!");
|
||||
}
|
||||
|
||||
DebugPrint("Drive Serial Number: %lx\n", volumeSerialNumber);
|
||||
|
||||
// Add hard drive serial number portion
|
||||
char volumeSN[16];
|
||||
sprintf(volumeSN, "%lx-", volumeSerialNumber);
|
||||
strcat(passKey, volumeSN);
|
||||
|
||||
// Retrieve game serial #
|
||||
unsigned char gameSerialNumber[64];
|
||||
gameSerialNumber[0] = '\0';
|
||||
sizeOfBuffer = sizeof(gameSerialNumber);
|
||||
if (usesHKeycurrentUser)
|
||||
{
|
||||
result = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour\\ergc", 0, KEY_READ, &hKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Electronic Arts\\EA Games\\Command and Conquer Generals Zero Hour\\ergc", 0, KEY_READ, &hKey);
|
||||
}
|
||||
assert((result == ERROR_SUCCESS) && "Failed to open game serial registry key");
|
||||
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
result = RegQueryValueEx(hKey, "", NULL, &type, gameSerialNumber, &sizeOfBuffer);
|
||||
assert((result == ERROR_SUCCESS) && "Failed to obtain game serial number!");
|
||||
assert((strlen((const char*)gameSerialNumber) > 0) && "Game serial number invalid!");
|
||||
}
|
||||
|
||||
DebugPrint("Game serial number: %s\n", gameSerialNumber);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
// Add game serial number portion
|
||||
strcat(passKey, (char*)gameSerialNumber);
|
||||
|
||||
// Obtain windows product ID
|
||||
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &hKey);
|
||||
assert((result == ERROR_SUCCESS) && "Failed to open windows registry key!");
|
||||
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
// Retrieve Windows Product ID
|
||||
unsigned char winProductID[64];
|
||||
winProductID[0] = '\0';
|
||||
|
||||
DWORD type;
|
||||
DWORD sizeOfBuffer = sizeof(winProductID);
|
||||
result = RegQueryValueEx(hKey, "ProductID", NULL, &type, winProductID, &sizeOfBuffer);
|
||||
|
||||
assert((result == ERROR_SUCCESS) && "Failed to obtain windows product ID!");
|
||||
assert((strlen((const char*)winProductID) > 0) && "Invalid windows product ID");
|
||||
|
||||
DebugPrint("Windows Product ID: %s\n", winProductID);
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
// Add windows product ID portion
|
||||
strcat(passKey, "-");
|
||||
strcat(passKey, (char*)winProductID);
|
||||
}
|
||||
|
||||
DebugPrint("Retrieved PassKey: %s\n", passKey);
|
||||
|
||||
const char *plainText = "Play the \"Command & Conquer: Generals\" Multiplayer Test.";
|
||||
int textLen = strlen(plainText);
|
||||
char cypherText[128];
|
||||
|
||||
DebugPrint("Retrieved PassKey: %s\n", passKey);
|
||||
|
||||
// Decrypt protected data into the memory mapped file
|
||||
BlowfishEngine blowfish;
|
||||
int len = strlen(passKey);
|
||||
if (len > BlowfishEngine::MAX_KEY_LENGTH)
|
||||
len = BlowfishEngine::MAX_KEY_LENGTH;
|
||||
blowfish.Submit_Key(passKey, len);
|
||||
|
||||
blowfish.Encrypt(plainText, textLen, cypherText);
|
||||
cypherText[textLen] = 0;
|
||||
DebugPrint("Encrypted data: %s\n", cypherText);
|
||||
|
||||
DebugPrint("Install dir = '%s'\n", installPath);
|
||||
|
||||
char *lastBackslash = strrchr((char *)installPath, '\\');
|
||||
if (lastBackslash)
|
||||
*lastBackslash = 0; // strip of \\game.exe from install path
|
||||
|
||||
strcat((char *)installPath, "\\Generals.dat");
|
||||
|
||||
DebugPrint("DAT file = '%s'\n", installPath);
|
||||
|
||||
FILE *fp = fopen((char *)installPath, "wb");
|
||||
if (fp)
|
||||
{
|
||||
fwrite(cypherText, textLen, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
CDAPFN_ENDMARK(doIt);
|
||||
}
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
doIt();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
130
GeneralsMD/Code/Tools/Launcher/DatGen/DatGen.dsp
Normal file
130
GeneralsMD/Code/Tools/Launcher/DatGen/DatGen.dsp
Normal file
|
@ -0,0 +1,130 @@
|
|||
# Microsoft Developer Studio Project File - Name="DatGen" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Application" 0x0101
|
||||
|
||||
CFG=DatGen - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "DatGen.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "DatGen.mak" CFG="DatGen - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "DatGen - Win32 Release" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "DatGen - Win32 Debug" (based on "Win32 (x86) Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName "DatGen"
|
||||
# PROP Scc_LocalPath "."
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "DatGen - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I ".." /I "../toolkit" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /pdb:"..\..\..\..\Run\DatGen.pdb" /map:"..\..\..\..\Run\DatGen.map" /debug /machine:I386 /out:"..\..\..\..\Run\DatGen.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "DatGen - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /I "../toolkit" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /pdb:"..\..\..\..\Run\DatGenD.pdb" /map:"..\..\..\..\Run\DatGenD.map" /debug /machine:I386 /out:"..\..\..\..\Run\DatGenD.exe"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "DatGen - Win32 Release"
|
||||
# Name "DatGen - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\BFISH.CPP
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DatGen.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Toolkit\Debug\DebugPrint.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\BFISH.H
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\SafeDisk\CdaPfn.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Toolkit\Debug\DebugPrint.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
Reference in a new issue