mirror of
https://github.com/electronicarts/CnC_Renegade.git
synced 2026-02-03 23:43:56 -05:00
Initial commit of Command & Conquer Renegade source code.
This commit is contained in:
154
Code/Tools/bin2cpp/bin2cpp.cpp
Normal file
154
Code/Tools/bin2cpp/bin2cpp.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(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/>.
|
||||
*/
|
||||
|
||||
#include "windows.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
char _StringBuf[1024];
|
||||
|
||||
void Print_Usage(void);
|
||||
void Write(HANDLE file,const char * format,...);
|
||||
void Write_Bytes(HANDLE file,const char * bytes,int bytecount);
|
||||
|
||||
|
||||
/*
|
||||
** This program simply reads in the specified file and creates a cpp and h file
|
||||
** which define an array of bytes that contain the contents of the input file.
|
||||
** The cpp and h files will have the same root filename with the extension replaced.
|
||||
*/
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
Print_Usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Open the input file
|
||||
*/
|
||||
HANDLE inputfile = CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
if (inputfile == INVALID_HANDLE_VALUE) {
|
||||
printf("Could not open file: %s\n",argv[1]);
|
||||
Print_Usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
DWORD inputsize = GetFileSize(inputfile,NULL);
|
||||
|
||||
/*
|
||||
** Open up the two output files
|
||||
*/
|
||||
char drive[_MAX_FNAME];
|
||||
char dir[_MAX_DIR];
|
||||
char fname[_MAX_FNAME];
|
||||
char cpp_fname[_MAX_DRIVE + _MAX_DIR + _MAX_FNAME + _MAX_EXT];
|
||||
char h_fname[_MAX_DRIVE + _MAX_DIR + _MAX_FNAME + _MAX_EXT];
|
||||
|
||||
_splitpath(argv[1],drive,dir,fname,NULL);
|
||||
_makepath(cpp_fname,drive,dir,fname,"cpp");
|
||||
_makepath(h_fname,drive,dir,fname,"h");
|
||||
|
||||
HANDLE hfile = CreateFile(h_fname,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
if (hfile == INVALID_HANDLE_VALUE) {
|
||||
printf("Could not create file: %s\n",h_fname);
|
||||
Print_Usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
HANDLE cppfile = CreateFile(cpp_fname,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
|
||||
if (cppfile == INVALID_HANDLE_VALUE) {
|
||||
printf("Could not create file: %s\n",h_fname);
|
||||
Print_Usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Write the cpp file
|
||||
*/
|
||||
Write(cppfile,"\n\nconst unsigned char %s[%d] = \n",fname,inputsize);
|
||||
Write(cppfile,"{\n");
|
||||
|
||||
/*
|
||||
** Read the file, writing it in text form into the cpp file
|
||||
*/
|
||||
const int LINELEN = 16;
|
||||
char bytes[LINELEN];
|
||||
DWORD bytesread = 0;
|
||||
|
||||
while(bytesread < inputsize) {
|
||||
|
||||
DWORD readsize = min(LINELEN,inputsize - bytesread);
|
||||
DWORD actualread;
|
||||
|
||||
ReadFile(inputfile,bytes,readsize,&actualread,NULL);
|
||||
assert(actualread == readsize);
|
||||
bytesread += readsize;
|
||||
|
||||
Write_Bytes(cppfile,bytes,readsize);
|
||||
}
|
||||
|
||||
/*
|
||||
** read in remainder
|
||||
*/
|
||||
Write(cppfile,"};\n");
|
||||
|
||||
|
||||
/*
|
||||
** Write the h file
|
||||
*/
|
||||
Write(hfile,"\n\nextern const unsigned char %s[%d];\n\n",fname,inputsize);
|
||||
|
||||
/*
|
||||
** Close the files
|
||||
*/
|
||||
CloseHandle(inputfile);
|
||||
CloseHandle(hfile);
|
||||
CloseHandle(cppfile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Write(HANDLE file,const char * format,...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vsprintf(_StringBuf, format, va);
|
||||
assert((strlen(_StringBuf) < sizeof(_StringBuf)));
|
||||
va_end(va);
|
||||
|
||||
unsigned long byteswritten;
|
||||
WriteFile(file,_StringBuf,strlen(_StringBuf),&byteswritten,NULL);
|
||||
}
|
||||
|
||||
void Write_Bytes(HANDLE file,const char * bytes,int bytecount)
|
||||
{
|
||||
Write(file,"\t");
|
||||
for (int i=0;i<bytecount;i++) {
|
||||
unsigned char val = (unsigned char)bytes[i];
|
||||
Write(file,"0x%2.2X,",val);
|
||||
}
|
||||
Write(file,"\n");
|
||||
}
|
||||
|
||||
void Print_Usage(void)
|
||||
{
|
||||
printf("USAGE: bin2h <inputfilename>\n");
|
||||
}
|
||||
102
Code/Tools/bin2cpp/bin2cpp.dsp
Normal file
102
Code/Tools/bin2cpp/bin2cpp.dsp
Normal file
@@ -0,0 +1,102 @@
|
||||
# Microsoft Developer Studio Project File - Name="bin2cpp" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=bin2cpp - 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 "bin2cpp.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 "bin2cpp.mak" CFG="bin2cpp - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "bin2cpp - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "bin2cpp - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""$/Commando/Code/Tools/bin2cpp", XVOBAAAA"
|
||||
# PROP Scc_LocalPath "."
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "bin2cpp - 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 Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# 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 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:console /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 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:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "bin2cpp - 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 Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# 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 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:console /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 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:console /debug /machine:I386
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "bin2cpp - Win32 Release"
|
||||
# Name "bin2cpp - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bin2cpp.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# 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 New Issue
Block a user