From ba2e8b246136e742c93e8b9b5506e5896ad93a0e Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 15 Mar 2012 19:08:19 +0000 Subject: [PATCH] - Fixed: Old-style ACS has the string table record offsets from the start of the object file to the strings, not from the start of the string table, so UnescapeStringTable() needs to be told where the offsets are based. SVN r3436 (trunk) --- src/p_acs.cpp | 20 ++++++++++++++------ src/p_acs.h | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index a50113782b..0dcac898aa 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -1169,7 +1169,7 @@ FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) { StringTable = LittleLong(((DWORD *)Data)[1]); StringTable += LittleLong(((DWORD *)(Data + StringTable))[0]) * 12 + 4; - UnescapeStringTable(Data + StringTable, false); + UnescapeStringTable(Data + StringTable, Data, false); } else { @@ -1178,7 +1178,7 @@ FBehavior::FBehavior (int lumpnum, FileReader * fr, int len) if (strings != NULL) { StringTable = DWORD(strings - Data + 8); - UnescapeStringTable(strings + 8, true); + UnescapeStringTable(strings + 8, NULL, true); } else { @@ -1621,7 +1621,7 @@ void FBehavior::LoadScriptsDirectory () scripts.b = FindChunk(MAKE_ID('S','N','A','M')); if (scripts.dw != NULL) { - UnescapeStringTable(scripts.b + 8, false); + UnescapeStringTable(scripts.b + 8, NULL, false); for (i = 0; i < NumScripts; ++i) { // ACC stores script names as an index into the SNAM chunk, with the first index as @@ -1688,15 +1688,23 @@ void FBehavior::UnencryptStrings () // FBehavior :: UnescapeStringTable // // Processes escape sequences for every string in a string table. +// Chunkstart points to the string table. Datastart points to the base address +// for offsets in the string table; if NULL, it will use chunkstart. If +// has_padding is true, then this is a STRL chunk with four bytes of padding +// on either side of the string count. // //============================================================================ -void FBehavior::UnescapeStringTable(BYTE *chunkstart, bool has_padding) +void FBehavior::UnescapeStringTable(BYTE *chunkstart, BYTE *datastart, bool has_padding) { assert(chunkstart != NULL); DWORD *chunk = (DWORD *)chunkstart; + if (datastart == NULL) + { + datastart = chunkstart; + } if (!has_padding) { chunk[0] = LittleLong(chunk[0]); @@ -1704,7 +1712,7 @@ void FBehavior::UnescapeStringTable(BYTE *chunkstart, bool has_padding) { int ofs = LittleLong(chunk[1 + strnum]); // Byte swap offset, if needed. chunk[1 + strnum] = ofs; - strbin((char *)chunk + ofs); + strbin((char *)datastart + ofs); } } else @@ -1714,7 +1722,7 @@ void FBehavior::UnescapeStringTable(BYTE *chunkstart, bool has_padding) { int ofs = LittleLong(chunk[3 + strnum]); // Byte swap offset, if needed. chunk[3 + strnum] = ofs; - strbin((char *)chunk + ofs); + strbin((char *)datastart + ofs); } } } diff --git a/src/p_acs.h b/src/p_acs.h index 6bdce50b1a..d09773f304 100644 --- a/src/p_acs.h +++ b/src/p_acs.h @@ -220,7 +220,7 @@ private: static int STACK_ARGS SortScripts (const void *a, const void *b); void UnencryptStrings (); - void UnescapeStringTable(BYTE *chunkstart, bool haspadding); + void UnescapeStringTable(BYTE *chunkstart, BYTE *datastart, bool haspadding); int FindStringInChunk (DWORD *chunk, const char *varname) const; const char *LookupString (DWORD index) const;