diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index cb6b934be..632a3d345 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -539,7 +539,11 @@ void StartLevel(GAMEOPTIONS *gameOptions) memset(xsprite,0,sizeof(xsprite)); memset(sprite,0,kMaxSprites*sizeof(spritetype)); drawLoadingScreen(); - dbLoadMap(gameOptions->zLevelName,(int*)&startpos.x,(int*)&startpos.y,(int*)&startpos.z,&startang,&startsectnum,(unsigned int*)&gameOptions->uMapCRC); + if (dbLoadMap(gameOptions->zLevelName,(int*)&startpos.x,(int*)&startpos.y,(int*)&startpos.z,&startang,&startsectnum,(unsigned int*)&gameOptions->uMapCRC)) + { + gQuitGame = true; + return; + } wsrand(gameOptions->uMapCRC); gKillMgr.Clear(); gSecretMgr.Clear(); @@ -1478,24 +1482,7 @@ int app_main(int argc, char const * const * argv) gGuiRes.Init("GUI.RFF"); gSoundRes.Init(pUserSoundRFF ? pUserSoundRFF : "SOUNDS.RFF"); - - { // Replace - void qinitspritelists(); - int32_t qinsertsprite(int16_t nSector, int16_t nStat); - int32_t qdeletesprite(int16_t nSprite); - int32_t qchangespritesect(int16_t nSprite, int16_t nSector); - int32_t qchangespritestat(int16_t nSprite, int16_t nStatus); - animateoffs_replace = qanimateoffs; - paletteLoadFromDisk_replace = qloadpalette; - getpalookup_replace = qgetpalookup; - initspritelists_replace = qinitspritelists; - insertsprite_replace = qinsertsprite; - deletesprite_replace = qdeletesprite; - changespritesect_replace = qchangespritesect; - changespritestat_replace = qchangespritestat; - loadvoxel_replace = qloadvoxel; - bloodhack = true; - } + HookReplaceFunctions(); initprintf("Initializing Build 3D engine\n"); scrInit(); diff --git a/source/blood/src/db.cpp b/source/blood/src/db.cpp index e9d16af09..d61e246e2 100644 --- a/source/blood/src/db.cpp +++ b/source/blood/src/db.cpp @@ -699,7 +699,7 @@ unsigned int dbReadMapCRC(const char *pPath) int gMapRev, gSongId, gSkyCount; //char byte_19AE44[128]; -void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short *pSector, unsigned int *pCRC) +int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short *pSector, unsigned int *pCRC) { int16_t tpskyoff[256]; memset(show2dsector, 0, sizeof(show2dsector)); @@ -721,7 +721,15 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, shor DICTNODE *pNode = gSysRes.Lookup(pPath, "MAP"); if (!pNode) { - ThrowError("Error opening map file %s", pPath); + char name2[BMAX_PATH]; + Bstrncpy(name2, pPath, BMAX_PATH); + ChangeExtension(name2, ""); + pNode = gSysRes.Lookup(name2, "MAP"); + } + if (!pNode) + { + initprintf("Error opening map file %s", pPath); + return -1; } char *pData = (char*)gSysRes.Lock(pNode); int nSize = pNode->size; @@ -733,7 +741,9 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, shor #endif if (memcmp(header.signature, "BLM\x1a", 4)) { - ThrowError("Map file corrupted"); + initprintf("Map file corrupted"); + gSysRes.Unlock(pNode); + return -1; } byte_1A76C8 = 0; if ((header.version & 0xff00) == 0x600) @@ -745,7 +755,9 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, shor } else { - ThrowError("Map file is wrong version"); + initprintf("Map file is wrong version"); + gSysRes.Unlock(pNode); + return -1; } MAPHEADER mapHeader; IOBuffer1.Read(&mapHeader,37/* sizeof(mapHeader)*/); @@ -792,12 +804,16 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, shor } else { - ThrowError("Corrupted Map file"); + initprintf("Corrupted Map file"); + gSysRes.Unlock(pNode); + return -1; } } else if (mapHeader.at16) { - ThrowError("Corrupted Map file"); + initprintf("Corrupted Map file"); + gSysRes.Unlock(pNode); + return -1; } parallaxtype = mapHeader.at1a; gMapRev = mapHeader.at1b; @@ -1165,9 +1181,12 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, shor #endif if (Bcrc32(pData, nSize-4, 0) != nCRC) { - ThrowError("Map File does not match CRC"); + initprintf("Map File does not match CRC"); + gSysRes.Unlock(pNode); + return -1; } - *pCRC = nCRC; + if (pCRC) + *pCRC = nCRC; gSysRes.Unlock(pNode); PropagateMarkerReferences(); if (byte_1A76C8) @@ -1182,12 +1201,16 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, shor } else { - ThrowError("Corrupted Map file"); + initprintf("Corrupted Map file"); + gSysRes.Unlock(pNode); + return -1; } } else if (gSongId != 0) { - ThrowError("Corrupted Shareware Map file"); + initprintf("Corrupted Map file"); + gSysRes.Unlock(pNode); + return -1; } #ifdef POLYMER @@ -1246,4 +1269,14 @@ void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, shor #ifdef YAX_ENABLE yax_update(numyaxbunches > 0 ? 2 : 1); #endif + + g_loadedMapVersion = 7; + + return 0; +} + +int32_t qloadboard(const char* filename, char flags, vec3_t* dapos, int16_t* daang, int16_t* dacursectnum) +{ + // NUKE-TODO: implement flags + return dbLoadMap(filename, &dapos->x, &dapos->y, &dapos->z, (short*)daang, (short*)dacursectnum, NULL); } diff --git a/source/blood/src/db.h b/source/blood/src/db.h index 902212f8e..4552cddea 100644 --- a/source/blood/src/db.h +++ b/source/blood/src/db.h @@ -320,4 +320,4 @@ void dbXSectorClean(void); void dbInit(void); void PropagateMarkerReferences(void); unsigned int dbReadMapCRC(const char *pPath); -void dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short *pSector, unsigned int *pCRC); +int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short *pSector, unsigned int *pCRC); diff --git a/source/blood/src/replace.cpp b/source/blood/src/replace.cpp index a8c6e9171..580026135 100644 --- a/source/blood/src/replace.cpp +++ b/source/blood/src/replace.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "crc32.h" #include "globals.h" +#include "tile.h" #include "screen.h" int qanimateoffs(int a1, int a2) @@ -70,4 +71,25 @@ int32_t qgetpalookup(int32_t a1, int32_t a2) return ClipHigh(a1 >> 8, 15) * 16 + ClipRange(a2, 0, 15); else return ClipRange((a1 >> 8) + a2, 0, 63); -} \ No newline at end of file +} + +void HookReplaceFunctions(void) +{ + void qinitspritelists(); + int32_t qinsertsprite(int16_t nSector, int16_t nStat); + int32_t qdeletesprite(int16_t nSprite); + int32_t qchangespritesect(int16_t nSprite, int16_t nSector); + int32_t qchangespritestat(int16_t nSprite, int16_t nStatus); + int32_t qloadboard(const char* filename, char flags, vec3_t* dapos, int16_t* daang, int16_t* dacursectnum); + animateoffs_replace = qanimateoffs; + paletteLoadFromDisk_replace = qloadpalette; + getpalookup_replace = qgetpalookup; + initspritelists_replace = qinitspritelists; + insertsprite_replace = qinsertsprite; + deletesprite_replace = qdeletesprite; + changespritesect_replace = qchangespritesect; + changespritestat_replace = qchangespritestat; + loadvoxel_replace = qloadvoxel; + loadboard_replace = qloadboard; + bloodhack = true; +} diff --git a/source/blood/src/replace.h b/source/blood/src/replace.h index 622823eaf..529777b6f 100644 --- a/source/blood/src/replace.h +++ b/source/blood/src/replace.h @@ -25,4 +25,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. int qanimateoffs(int a1, int a2); void qloadpalette(); -int32_t qgetpalookup(int32_t a1, int32_t a2); \ No newline at end of file +int32_t qgetpalookup(int32_t a1, int32_t a2); +void HookReplaceFunctions(); \ No newline at end of file diff --git a/source/build/include/build.h b/source/build/include/build.h index b98003589..e01998117 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -1599,6 +1599,7 @@ extern int32_t(*deletesprite_replace)(int16_t spritenum); extern int32_t(*changespritesect_replace)(int16_t spritenum, int16_t newsectnum); extern int32_t(*changespritestat_replace)(int16_t spritenum, int16_t newstatnum); extern void(*loadvoxel_replace)(int32_t voxel); +extern int32_t(*loadboard_replace)(const char *filename, char flags, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum); #ifdef USE_OPENGL extern void(*PolymostProcessVoxels_Callback)(void); #endif diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index ae567290c..e9c8ea251 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -9665,6 +9665,8 @@ LUNATIC_CB int32_t (*loadboard_maptext)(buildvfs_kfd fil, vec3_t *dapos, int16_t #include "md4.h" +int32_t(*loadboard_replace)(const char *filename, char flags, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum) = NULL; + // flags: 1, 2: former parameter "fromwhere" // 4: don't call polymer_loadboard // 8: don't autoexec .cfg @@ -9675,7 +9677,9 @@ LUNATIC_CB int32_t (*loadboard_maptext)(buildvfs_kfd fil, vec3_t *dapos, int16_t // <= -4: map-text error int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum) { - int32_t i; + if (loadboard_replace) + return loadboard_replace(filename, flags, dapos, daang, dacursectnum); + int32_t fil, i; int16_t numsprites; const char myflags = flags&(~3);