Mercurial > hg > Members > kono > nitros9-code
changeset 2076:b2820d3f1e38
Utils written by G. Major for VOL conversion to CoCo interpreter
author | boisy |
---|---|
date | Fri, 21 Jul 2006 14:41:13 +0000 |
parents | eb13221efaed |
children | 110599fca80d |
files | 3rdparty/packages/sierra/convutils/cc3snd.c 3rdparty/packages/sierra/convutils/cc3snd.dsp 3rdparty/packages/sierra/convutils/picpatch.c 3rdparty/packages/sierra/convutils/picpatch.dsp 3rdparty/packages/sierra/convutils/sndpatch.c 3rdparty/packages/sierra/convutils/sndpatch.dsp |
diffstat | 6 files changed, 829 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/sierra/convutils/cc3snd.c Fri Jul 21 14:41:13 2006 +0000 @@ -0,0 +1,234 @@ +/*********************************************************************************** +* Program Name : cc3snd * +* Description : Converts AGI sounds for the AGI Coco interpreter. * +* Author : Guillaume Major * +* Date : July 18, 2006 * +* License : Freeware. Do whatever you want with it! * +***********************************************************************************/ + +#include <stdio.h> +#include <ctype.h> +#include <string.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <io.h> +#include <direct.h> +#include <windows.h> + +/* Be sure to set the struct member alignment at 1 in the compiler settings */ + +/* AGI sound format */ +struct MUSIC_NOTE { + unsigned short duration; + unsigned char tone_2; + unsigned char tone_1; + unsigned char attenuation; +}; + +/* Coco AGI sound format */ +struct COCO_MUSIC_NOTE { + unsigned char tone; + unsigned char volume; /* 0x00: Silence, 0x3F: Full volume */ + unsigned char unused; + unsigned char duration; +}; + +/* Coco tone frequencies. The position of the freqency in the table gives the coco tone number. */ +unsigned short COCO_TONES_TABLE[] = { + 130, 138, 146, 155, 164, 174, 184, 195, 207, 220, 233, 246, // O3 + 261, 277, 293, 311, 329, 349, 369, 391, 415, 440, 466, 493, // O4 + 523, 554, 587, 622, 659, 698, 739, 783, 830, 880, 932, 987, // O5 + 1046, 1108, 1174, 1244, 1318, 1396, 1479, 1567, 1661, 1760, 1864, 1975, // O6 + 2093, 2217, 2349, 2489, 2637, 2793, 2959, 3135, 3322, 3520, 3729, 3951 // O7 +}; + +/* Function prototypes */ +unsigned char GetCocoTone(unsigned short uiFreq); +void ConvertSound(char *sInFile, char *sOutFile); +void ShowUsage(); + +/* Main */ +int main(int argc, char **argv) { + + char sInFile[MAX_PATH], sOutFile[MAX_PATH]; + char sInPath[MAX_PATH], sOutPath[MAX_PATH]; + char sFullPath[MAX_PATH]; + + long hFind; + struct _finddata_t finddata; + + printf("\n"); + printf("cc3snd AGI sound resource converter for the Coco\n"); + printf("Version 1.0 (July 2006)\n\n"); + + if (argc < 2) { + ShowUsage(); + } + + if (strcmp(argv[1], "-b") == 0 || strcmp(argv[1], "-B") == 0) { + if (argc < 3) { + ShowUsage(); + } + else if (argc < 4) { + sInPath[0] = '\0'; + strncpy(sOutPath, argv[2], MAX_PATH); + } + else { + strncpy(sInPath, argv[2], MAX_PATH); + strncpy(sOutPath, argv[3], MAX_PATH); + } + /* Get the list of files */ + if (sInPath[0] != '\0') + sprintf(sFullPath, "%s\\sound.???", sInPath); + else + strncpy(sFullPath, "sound.???", 10); + hFind = _findfirst(sFullPath, &finddata); + if (hFind > -1) { + /* Make sure the output path exists */ + _mkdir(sOutPath); + /* Loop through the sound files */ + do { + if (!(finddata.attrib & _A_SUBDIR) ) { + if (sInPath[0] != '\0') + sprintf(sInFile, "%s\\%s", sInPath, finddata.name); + else + strncpy(sInFile, finddata.name, strlen(finddata.name)+1); + sprintf(sOutFile, "%s\\%s", sOutPath, finddata.name); + ConvertSound(sInFile, sOutFile); + } + else { + printf("Skipping directory %s.\n", finddata.name); + } + } + while (_findnext(hFind, &finddata) > -1); + _findclose(hFind); + } + else { + printf("No SOUND file was found! The sound files name must match this format: sound.xxx where xxx is the number of the sound.\n"); + exit(1); + } + } + else { + if (argc < 2) { + ShowUsage(); + } + else { + strncpy(sInFile, argv[1], MAX_PATH); + if (argc < 3) { + sprintf(sOutFile, "%s.cc3", argv[1]); + } + else { + strncpy(sOutFile, argv[2], MAX_PATH); + } + ConvertSound(sInFile, sOutFile); + } + } + + printf("Done!\n\n"); + + /* Exit normally */ + exit(0); +} + +/* Converts an AGI format sound file to the Coco AGI interpreter format */ +void ConvertSound(char *sInFile, char *sOutFile) { + + FILE *infile, *outfile; + unsigned short uiOffset; + struct MUSIC_NOTE note; + struct COCO_MUSIC_NOTE cocoNote; + unsigned short uiFreq, uiFreqDiv; + + if ((infile = fopen(sInFile, "rb")) == NULL) { + perror("Error opening input file"); + exit(1); + } + + if ((outfile = fopen(sOutFile, "wb")) == NULL) { + perror("Error opening output file"); + exit(1); + } + + printf("Converting %s -> %s\n", sInFile, sOutFile); + + /* Get voice 1 offset */ + fseek(infile, 0, SEEK_SET); + fread(&uiOffset, sizeof(unsigned short), 1, infile); + + /* Seek to voice 1 offset */ + fseek(infile, uiOffset, SEEK_SET); + memset(¬e, 0, sizeof(note)); + + while (!ferror(infile) && !feof(infile) && fread(¬e, sizeof(note), 1, infile) && note.duration != 0xFFFF) { + /* Verify that it's not a noise tone */ + if (note.tone_1 >> 4 != 0x0E) { + /* Get the frequency divider */ + uiFreqDiv = (((note.tone_2 & 0x3F) << 4) + (note.tone_1 & 0x0F)); + if (uiFreqDiv > 0) { + /* Get the frequency of the tone */ + uiFreq = 111860 / uiFreqDiv; + /* Get the corresponding coco tone */ + cocoNote.tone = GetCocoTone(uiFreq); + if ((note.attenuation & 0x0F) == 0x0F) + cocoNote.volume = 0x00; + else + cocoNote.volume = 0x3F; + } + else { + /* Insert a silence if the frequency equals zero */ + cocoNote.tone = 0; + cocoNote.volume = 0x00; + } + cocoNote.unused = 0; + cocoNote.duration = (unsigned char)note.duration / 6; + /* Make sure the duration equals at least 1 or else the sound will play indefinitely */ + if (cocoNote.duration == 0) + cocoNote.duration = 1; + /* Write the note to the file */ + fwrite(&cocoNote, sizeof(cocoNote), 1, outfile); + } + } + + /* Write the footer. The last 2 bytes seems to do nothing but every sound in KQ3 for the coco + ends with 0xFF and 2 bytes */ + fprintf(outfile, "%c%c%c", 0xFF, 0x00, 0x30); + + /* Close files */ + fclose(outfile); + fclose(infile); + +} + +/* Gets the coco tone number from the specified frequency */ +unsigned char GetCocoTone(unsigned short uiFreq) { + + int count, i, iTone = 0; + + count = sizeof(COCO_TONES_TABLE) / sizeof(unsigned short); + + for (i = 0; i < count; i++) { + if (uiFreq <= COCO_TONES_TABLE[i]) { + iTone = i - 1; + break; + } + } + + /* Make sure the tone is not negative */ + if (iTone < 0) + iTone = 0; + + return iTone; + +} + +/* Shows usage */ +void ShowUsage() { + + printf("Usage: cc3snd input-file [output-file]\n"); + printf(" cc3snd -b [input-path] output-path (batch mode)\n"); + + /* Exit normally */ + exit(0); + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/sierra/convutils/cc3snd.dsp Fri Jul 21 14:41:13 2006 +0000 @@ -0,0 +1,93 @@ +# Microsoft Developer Studio Project File - Name="cc3snd" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=cc3snd - 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 "cc3snd.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 "cc3snd.mak" CFG="cc3snd - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "cc3snd - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "cc3snd - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "cc3snd - 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" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# 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: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 /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "cc3snd - 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" /YX /FD /GZ /c +# ADD CPP /nologo /Zp1 /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c +# SUBTRACT CPP /YX +# 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:console /debug /machine:I386 /pdbtype:sept +# 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:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "cc3snd - Win32 Release" +# Name "cc3snd - Win32 Debug" +# Begin Source File + +SOURCE=.\cc3snd.c +# End Source File +# Begin Source File + +SOURCE=.\cc3snd.h +# End Source File +# End Target +# End Project
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/sierra/convutils/picpatch.c Fri Jul 21 14:41:13 2006 +0000 @@ -0,0 +1,143 @@ +/*********************************************************************************** +* Program Name : picpatch * +* Description : Removes the Plot command (0xFA) from all the pictures to make * +* them compatible with the coco AGI interpreter. * +* Author : Guillaume Major * +* Date : July 19, 2006 * +* License : Freeware. Do whatever you want with it! * +***********************************************************************************/ + +#include <stdio.h> +#include <ctype.h> +#include <string.h> +#include <stdlib.h> +#include <io.h> +#include <direct.h> +#include <windows.h> + +/* VOL directory entry structure */ +struct DIRECTORY_ENTRY { + unsigned char byte1; + unsigned char byte2; + unsigned char byte3; +}; + +/* Global variables */ +char sGamePath[MAX_PATH]; + +/* Function prototypes */ +void PatchPicture(unsigned int iVolFile, unsigned int iPicNum, unsigned int iPicPos); +void ShowUsage(); + +/* Main */ +int main(int argc, char **argv) { + + FILE *picDir; + char sPicDir[MAX_PATH]; + unsigned int iPicNum, iVolFile, iPicPos; + struct DIRECTORY_ENTRY dir; + + printf("\n"); + printf("picpatch AGI picture resources patcher\n"); + printf("Version 1.0 (July 2006)\n\n"); + + if (argc < 2) { + ShowUsage(); + } + else { + strncpy(sGamePath, argv[1], MAX_PATH); + } + + /* Get the full path of picDir */ + sprintf(sPicDir, "%s\\picDir", sGamePath); + + /* Open picDir file */ + if ((picDir = fopen(sPicDir, "rb")) == NULL) { + perror("Error opening picDir file"); + exit(1); + } + + /* Initialize the picture counter */ + iPicNum = 0; + + /* Loop through the picDir file to remove plot commands */ + while (!ferror(picDir) && !feof(picDir) && fread(&dir, sizeof(dir), 1, picDir)) { + /* Verify if the picture resource exists */ + if (dir.byte1 != 0xFF) { + iVolFile = (dir.byte1 >> 4); + iPicPos = ((dir.byte1 & 0x0F) << 16) + (dir.byte2 << 8) + dir.byte3; + PatchPicture(iVolFile, iPicNum, iPicPos); + } + iPicNum++; + } + + printf("Done!\n\n"); + + /* Exit normally */ + exit(0); +} + +/* Patch the picture number specified in the VOL file */ +void PatchPicture(unsigned int iVolFile, unsigned int iPicNum, unsigned int iPicPos) { + + FILE *volFile; + char sVolFile[MAX_PATH]; + unsigned short iPicSize = 0; + unsigned char acBuffer[16184]; + unsigned char cChar; + BOOL bSkip = FALSE; + + printf("Patching picture.%03i\n", iPicNum); + + /* Get the VOL file name */ + sprintf(sVolFile, "%s\\vol.%i", sGamePath, iVolFile); + + /* Open the VOL file for writing */ + if ((volFile = fopen(sVolFile, "r+b")) == NULL) { + perror("Error opening VOL file"); + exit(1); + } + + /* Skip the resource header */ + fseek(volFile, iPicPos + 5, SEEK_SET); + + while (!ferror(volFile) && !feof(volFile) && fread(&cChar, sizeof(unsigned char), 1, volFile) && cChar != 0xFF) { + if ((cChar & 0xF0) == 0xF0) { + bSkip = FALSE; + } + if (bSkip == FALSE) { + if (cChar != 0xFA) { + acBuffer[iPicSize] = cChar; + iPicSize++; + } + else { + bSkip = TRUE; + } + } + } + + /* Add 0xFF to the buffer */ + acBuffer[iPicSize] = 0xFF; + iPicSize++; + + /* Modify the size of the picture in the header */ + fseek(volFile, 0, SEEK_SET); + fwrite(&iPicSize, sizeof(unsigned short), 1, volFile); + + /* Write the buffer in the VOL file */ + fwrite(acBuffer, sizeof(char), iPicSize, volFile); + + /* Close the VOL file */ + fclose(volFile); + +} + +/* Shows usage */ +void ShowUsage() { + + printf("Usage: picpatch game-path\n"); + + /* Exit normally */ + exit(0); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/sierra/convutils/picpatch.dsp Fri Jul 21 14:41:13 2006 +0000 @@ -0,0 +1,103 @@ +# Microsoft Developer Studio Project File - Name="picpatch" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=picpatch - 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 "picpatch.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 "picpatch.mak" CFG="picpatch - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "picpatch - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "picpatch - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "picpatch - 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" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# 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)" == "picpatch - 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 "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /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 /pdbtype:sept +# 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 /pdbtype:sept +# SUBTRACT LINK32 /incremental:no + +!ENDIF + +# Begin Target + +# Name "picpatch - Win32 Release" +# Name "picpatch - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\picpatch.c +# 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/sierra/convutils/sndpatch.c Fri Jul 21 14:41:13 2006 +0000 @@ -0,0 +1,156 @@ +/*********************************************************************************** +* Program Name : sndpatch * +* Description : Replaces sounds of an AGI game with the ones in the specified * +* directory. * +* Author : Guillaume Major * +* Date : July 18, 2006 * +* License : Freeware. Do whatever you want with it! * +***********************************************************************************/ + +#include <stdio.h> +#include <ctype.h> +#include <string.h> +#include <stdlib.h> +#include <io.h> +#include <direct.h> +#include <windows.h> + +/* VOL directory entry structure */ +struct DIRECTORY_ENTRY { + unsigned char byte1; + unsigned char byte2; + unsigned char byte3; +}; + +/* Global variables */ +char sGamePath[MAX_PATH], sSoundPath[MAX_PATH]; + +/* Function prototypes */ +void PatchSound(unsigned int iVolFile, unsigned int iSndNum, unsigned int iSndPos); +void ShowUsage(); + +/* Main */ +int main(int argc, char **argv) { + + FILE *sndDir; + char sSndDir[MAX_PATH]; + unsigned int iSndNum, iVolFile, iSndPos; + struct DIRECTORY_ENTRY dir; + + printf("\n"); + printf("sndpatch AGI sound resources patcher\n"); + printf("Version 1.0 (July 2006)\n\n"); + + if (argc < 2) { + ShowUsage(); + } + + if (argc < 3) { + sGamePath[0] = '\0'; + strncpy(sSoundPath, argv[1], MAX_PATH); + } + else { + strncpy(sGamePath, argv[1], MAX_PATH); + strncpy(sSoundPath, argv[2], MAX_PATH); + } + + /* Get the full path of sndDir */ + if (sGamePath[0] != '\0') + sprintf(sSndDir, "%s\\sndDir", sGamePath); + else + strncpy(sSndDir, "sndDir", 7); + + /* Open sndDir file */ + if ((sndDir = fopen(sSndDir, "rb")) == NULL) { + perror("Error opening sndDir file"); + exit(1); + } + + iSndNum = 0; + + /* Loop through the sndDir file to replace sounds */ + while (!ferror(sndDir) && !feof(sndDir) && fread(&dir, sizeof(dir), 1, sndDir)) { + /* Verify if the sound resources exists */ + if (dir.byte1 != 0xFF) { + iVolFile = (dir.byte1 >> 4); + iSndPos = ((dir.byte1 & 0x0F) << 16) + (dir.byte2 << 8) + dir.byte3; + PatchSound(iVolFile, iSndNum, iSndPos); + } + iSndNum++; + } + + printf("Done!\n\n"); + + /* Exit normally */ + exit(0); +} + +/* Replaces the sound number specified in the VOL file */ +void PatchSound(unsigned int iVolFile, unsigned int iSndNum, unsigned int iSndPos) { + + FILE *sndFile, *volFile; + char sSndFile[MAX_PATH], sVolFile[MAX_PATH]; + unsigned short iSndSize, iVolSndSize; + char acBuffer[4096]; + + printf("Patching sound.%03i\n", iSndNum); + + /* Get the sound file name */ + if (sSoundPath[0] != '\0') + sprintf(sSndFile, "%s\\sound.%03i", sSoundPath, iSndNum); + else + sprintf(sSndFile, "sound.%03i", iSndNum); + + /* Open the sound file for reading */ + if ((sndFile = fopen(sSndFile, "rb")) == NULL) { + perror("Error opening sound file"); + exit(1); + } + + /* Get the VOL file name */ + if (sGamePath[0] != '\0') + sprintf(sVolFile, "%s\\vol.%i", sGamePath, iVolFile); + else + sprintf(sVolFile, "vol.%i", iVolFile); + + /* Open the VOL file for writing */ + if ((volFile = fopen(sVolFile, "r+b")) == NULL) { + perror("Error opening VOL file"); + exit(1); + } + + /* Read the entire sound file into the buffer */ + fseek(sndFile, 0, SEEK_SET); + iSndSize = fread(acBuffer, sizeof(char), sizeof(acBuffer), sndFile); + + /* Check if the new sound will fit in the VOL file */ + fseek(volFile, iSndPos + 3, SEEK_SET); + fread(&iVolSndSize, sizeof(unsigned short), 1, volFile); + if (iSndSize > iVolSndSize) { + printf("Not enough space in the VOL file for sound.%03i!\n" + "Sound size: %i Space available: %i\n", iSndNum, iSndSize, iVolSndSize); + exit(1); + } + + /* Modify the size of the sound file in the header */ + fseek(volFile, iSndPos + 3, SEEK_SET); + fwrite(&iSndSize, sizeof(unsigned short), 1, volFile); + + /* Write the sound file in the VOL file */ + fwrite(acBuffer, sizeof(char), iSndSize, volFile); + + /* Close files */ + fclose(volFile); + fclose(sndFile); + +} + +/* Shows usage */ +void ShowUsage() { + + printf("Usage: sndpatch [game-path] sound-path\n"); + + /* Exit normally */ + exit(0); + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/3rdparty/packages/sierra/convutils/sndpatch.dsp Fri Jul 21 14:41:13 2006 +0000 @@ -0,0 +1,100 @@ +# Microsoft Developer Studio Project File - Name="sndpatch" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=sndpatch - 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 "sndpatch.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 "sndpatch.mak" CFG="sndpatch - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "sndpatch - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "sndpatch - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "sndpatch - 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" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# 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)" == "sndpatch - 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" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# 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 /pdbtype:sept +# 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 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "sndpatch - Win32 Release" +# Name "sndpatch - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\sndpatch.c +# 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