Hopefully fix map reloading

This commit is contained in:
nukeykt 2019-10-01 02:08:35 +09:00 committed by Christoph Oelckers
parent 528e7f8320
commit 61f8b8c2d6

View file

@ -671,14 +671,38 @@ MAPHEADER2 byte_19AE44;
unsigned int dbReadMapCRC(const char *pPath) unsigned int dbReadMapCRC(const char *pPath)
{ {
char name2[BMAX_PATH];
byte_1A76C7 = 0; byte_1A76C7 = 0;
byte_1A76C8 = 0; byte_1A76C8 = 0;
DICTNODE *pNode = gSysRes.Lookup(pPath, "MAP");
int const bakpathsearchmode = pathsearchmode;
pathsearchmode = 1;
Bstrncpy(name2, pPath, BMAX_PATH);
Bstrupr(name2);
DICTNODE* pNode = *gSysRes.Probe(name2, "MAP");
if (pNode && pNode->flags & DICT_EXTERNAL)
{
gSysRes.RemoveNode(pNode);
}
pNode = gSysRes.Lookup(pPath, "MAP");
if (!pNode) 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);
pathsearchmode = bakpathsearchmode;
return -1;
} }
char *pData = (char*)gSysRes.Lock(pNode); char *pData = (char*)gSysRes.Lock(pNode);
pathsearchmode = bakpathsearchmode;
int nSize = pNode->size; int nSize = pNode->size;
MAPSIGNATURE header; MAPSIGNATURE header;
IOBuffer(nSize, pData).Read(&header, 6); IOBuffer(nSize, pData).Read(&header, 6);
@ -713,6 +737,7 @@ const int nXWallSize = 24;
int 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)
{ {
char name2[BMAX_PATH];
int16_t tpskyoff[256]; int16_t tpskyoff[256];
memset(show2dsector, 0, sizeof(show2dsector)); memset(show2dsector, 0, sizeof(show2dsector));
memset(show2dwall, 0, sizeof(show2dwall)); memset(show2dwall, 0, sizeof(show2dwall));
@ -724,17 +749,15 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
int const bakpathsearchmode = pathsearchmode; int const bakpathsearchmode = pathsearchmode;
pathsearchmode = 1; pathsearchmode = 1;
Bstrncpy(name2, pPath, BMAX_PATH);
Bstrupr(name2);
DICTNODE* pNode = *gSysRes.Probe(name2, "MAP");
if (pNode && pNode->flags & DICT_EXTERNAL)
{ {
char name2[BMAX_PATH]; gSysRes.RemoveNode(pNode);
Bstrncpy(name2, pPath, BMAX_PATH);
Bstrupr(name2);
DICTNODE* pNode = *gSysRes.Probe(name2, "MAP");
if (pNode && pNode->flags & DICT_EXTERNAL)
{
gSysRes.RemoveNode(pNode);
}
} }
DICTNODE *pNode = gSysRes.Lookup(pPath, "MAP");
pNode = gSysRes.Lookup(pPath, "MAP");
if (!pNode) if (!pNode)
{ {
char name2[BMAX_PATH]; char name2[BMAX_PATH];
@ -743,14 +766,14 @@ int dbLoadMap(const char *pPath, int *pX, int *pY, int *pZ, short *pAngle, short
pNode = gSysRes.Lookup(name2, "MAP"); pNode = gSysRes.Lookup(name2, "MAP");
} }
pathsearchmode = bakpathsearchmode;
if (!pNode) if (!pNode)
{ {
initprintf("Error opening map file %s", pPath); initprintf("Error opening map file %s", pPath);
pathsearchmode = bakpathsearchmode;
return -1; return -1;
} }
char *pData = (char*)gSysRes.Lock(pNode); char *pData = (char*)gSysRes.Lock(pNode);
pathsearchmode = bakpathsearchmode;
int nSize = pNode->size; int nSize = pNode->size;
MAPSIGNATURE header; MAPSIGNATURE header;
IOBuffer IOBuffer1 = IOBuffer(nSize, pData); IOBuffer IOBuffer1 = IOBuffer(nSize, pData);