SVN r191 (trunk)

This commit is contained in:
Randy Heit 2006-06-15 03:31:19 +00:00
parent 6e198e034b
commit d99f5b4b99
7 changed files with 165 additions and 104 deletions

View File

@ -1,4 +1,8 @@
June 14, 2006
- Fixed loading of Build/Blood maps.
- FWadLump::Read() now handles Blood decryption directly.
- Fixed: A fatal error thrown during map loading after the sectors have been
counted but before they are allocated crashed in PointerSubstitution().
- Removed my "backwards compatibility fix" for APROP_Speed. It turns out that
in all the public versions where monster speed is not fixed point, you
couldn't modify the monster's speed due to a bug in P_Move() anyway. So

View File

@ -499,6 +499,8 @@ void DObject::PointerSubstitution (DObject *old, DObject *notOld)
players[i].FixPointers (old, notOld);
}
if (sectors != NULL)
{
for (i = 0; i < (unsigned int)numsectors; ++i)
{
if (sectors[i].SoundTarget == old)
@ -507,6 +509,7 @@ void DObject::PointerSubstitution (DObject *old, DObject *notOld)
}
}
}
}
// Search for references to a single object and NULL them.
// It should not be listed in ToDestroy.

View File

@ -742,6 +742,8 @@ static void CalcPlane (SlopeWork &slope, secplane_t &plane)
//
// Decrypt
//
// Note that this is different from the general RFF encryption.
//
//==========================================================================
static void Decrypt (void *to_, const void *from_, int len, int key)
@ -749,13 +751,9 @@ static void Decrypt (void *to_, const void *from_, int len, int key)
BYTE *to = (BYTE *)to_;
const BYTE *from = (const BYTE *)from_;
while (len > 0)
for (int i = 0; i < len; ++i, ++key)
{
*to = *from ^ key;
to++;
from++;
key++;
len--;
to[i] = from[i] ^ key;
}
}

View File

@ -181,17 +181,20 @@ static void P_SetSideNum (DWORD *sidenum_p, WORD sidenum);
//
// GetMapIndex
//
// Gets the type of map lump or -1 if invalid
// Gets the type of map lump or -1 if invalid or -2 if required and not found.
//
//===========================================================================
static int GetMapIndex(const char * mapname, int lastindex, const char * lumpname)
{
static struct checkstruct
struct checkstruct
{
char *lumpname;
bool required;
} check[]={
};
static int GetMapIndex(const char *mapname, int lastindex, const char *lumpname, bool needrequired)
{
static const checkstruct check[] =
{
{NULL, true},
{"THINGS", true},
{"LINEDEFS", true},
@ -215,9 +218,13 @@ static int GetMapIndex(const char * mapname, int lastindex, const char * lumpnam
return (int)i;
if (check[i].required)
{
if (needrequired)
{
I_Error("'%s' not found in %s\n", check[i].lumpname, mapname);
}
return -2;
}
}
return -1; // End of map reached
@ -269,6 +276,12 @@ MapData * P_OpenMapData(const char * mapname)
map->MapLumps[0].FilePos = Wads.GetLumpOffset(lump_name);
map->MapLumps[0].Size = Wads.LumpLength(lump_name);
map->Encrypted = Wads.IsEncryptedFile(lump_name);
if (map->Encrypted)
{ // If it's encrypted, then it's a Blood file, presumably a map.
return map;
}
int index = 0;
for(int i = 1;; i++)
@ -276,7 +289,7 @@ MapData * P_OpenMapData(const char * mapname)
// Since levels must be stored in WADs they can't really have full
// names and for any valid level lump this always returns the short name.
const char * lumpname = Wads.GetLumpFullName(lump_name + i);
index = GetMapIndex(mapname, index, lumpname);
index = GetMapIndex(mapname, index, lumpname, i != 1 || map->MapLumps[0].Size == 0);
// The next lump is not part of this map anymore
if (index < 0) break;
@ -325,7 +338,7 @@ MapData * P_OpenMapData(const char * mapname)
if (i>0)
{
index = GetMapIndex(maplabel, index, lumpname);
index = GetMapIndex(maplabel, index, lumpname, true);
// The next lump is not part of this map anymore
if (index < 0) break;
@ -468,7 +481,6 @@ void P_FloodZones ()
void P_LoadVertexes (MapData * map)
{
FWadLump data;
int i;
// Determine number of vertices:
@ -3362,7 +3374,18 @@ void P_SetupLevel (char *lumpname, int position)
if (map->MapLumps[0].Size > 0)
{
BYTE *mapdata = new BYTE[map->MapLumps[0].Size];
map->Seek(0);
map->file->Read(mapdata, map->MapLumps[0].Size);
if (map->Encrypted)
{
// Why can't the linker find this function? Ugh.
//BloodCrypt (mapdata, 0, MIN<int> (map->MapLumps[0].Size, 256));
int len = MIN<int> (map->MapLumps[0].Size, 256);
for (int i = 0; i < len; ++i)
{
mapdata[i] ^= i >> 1;
}
}
buildmap = P_LoadBuildMap (mapdata, map->MapLumps[0].Size, &buildthings, &numbuildthings);
delete[] mapdata;
}

View File

@ -33,6 +33,7 @@ struct MapData
wadlump_t MapLumps[ML_BEHAVIOR+1];
bool HasBehavior;
bool CloseOnDestruct;
bool Encrypted;
int lumpnum;
FileReader * file;
@ -43,6 +44,7 @@ struct MapData
lumpnum = -1;
HasBehavior = false;
CloseOnDestruct = true;
Encrypted = false;
}
~MapData()

View File

@ -1603,10 +1603,6 @@ void FWadCollection::ReadLump (int lump, void *dest)
I_Error ("W_ReadLump: only read %ld of %ld on lump %i\n",
numread, size, lump);
}
if (LumpInfo[lump].flags & LUMPF_BLOODCRYPT)
{
BloodCrypt (dest, 0, MIN<int> (size, 256));
}
}
//==========================================================================
@ -1629,10 +1625,6 @@ FMemLump FWadCollection::ReadLump (int lump)
I_Error ("W_ReadLump: only read %ld of %ld on lump %i\n",
numread, size, lump);
}
if (LumpInfo[lump].flags & LUMPF_BLOODCRYPT)
{
BloodCrypt (dest, 0, MIN<int> (size, 256));
}
return FMemLump (dest);
}
@ -1657,24 +1649,13 @@ FWadLump FWadCollection::OpenLumpNum (int lump)
l = &LumpInfo[lump];
wad = Wads[l->wadnum];
#if 0
// Blood encryption?
if (writeable || l->flags & LUMPF_BLOODCRYPT)
{
ptr = Malloc (l->size);
NonMappedPointers.insert (ptr);
W_ReadLump (lump, ptr);
return ptr;
}
#endif
wad->Seek (l->position, SEEK_SET);
if (l->flags & LUMPF_COMPRESSED)
{
// A compressed entry in a .zip file
char * buffer = new char[l->size+1]; // the last byte is used as a reference counter
buffer[l->size] = 0;
FileReaderZ frz(*wad, true);
frz.Read(buffer, l->size);
return FWadLump(buffer, l->size, true);
@ -1690,7 +1671,7 @@ FWadLump FWadCollection::OpenLumpNum (int lump)
else
{
// An uncompressed lump in a .wad or .zip
return FWadLump (*wad, l->size);
return FWadLump (*wad, l->size, !!(l->flags & LUMPF_BLOODCRYPT));
}
}
@ -1835,6 +1816,23 @@ bool FWadCollection::IsUncompressedFile(int lump) const
else return true;
}
//==========================================================================
//
// IsEncryptedFile
//
// Returns true if the first 256 bytes of the lump are encrypted for Blood.
//
//==========================================================================
bool FWadCollection::IsEncryptedFile(int lump) const
{
if ((unsigned)lump >= (unsigned)NumLumps)
{
return false;
}
return !!(LumpInfo[lump].flags & LUMPF_BLOODCRYPT);
}
//==========================================================================
//
// W_SkinHack
@ -1901,7 +1899,7 @@ void FWadCollection::SkinHack (int baselump)
//
//==========================================================================
static void BloodCrypt (void *data, int key, int len)
void BloodCrypt (void *data, int key, int len)
{
int p = (BYTE)key, i;
@ -2013,7 +2011,7 @@ long FWadCollection::WadFileRecord::Read (void *buffer, long len)
// FWadLump -----------------------------------------------------------------
FWadLump::FWadLump ()
: FileReader (), sourceData(NULL)
: FileReader(), SourceData(NULL), DestroySource(false), Encrypted(false)
{
}
@ -2025,13 +2023,12 @@ FWadLump::FWadLump (const FWadLump &copy)
FilePos = copy.FilePos;
StartPos = copy.StartPos;
CloseOnDestruct = false;
if (copy.sourceData!=NULL)
SourceData = copy.SourceData;
DestroySource = copy.DestroySource;
if (SourceData != NULL && DestroySource)
{
sourceData=copy.sourceData;
destroySource=copy.destroySource;
if (destroySource) sourceData[copy.Length]++;
SourceData[copy.Length]++;
}
else sourceData=NULL;
}
#ifdef _DEBUG
@ -2043,48 +2040,55 @@ FWadLump & FWadLump::operator= (const FWadLump &copy)
FilePos = copy.FilePos;
StartPos = copy.StartPos;
CloseOnDestruct = false; // For WAD lumps this is always false!
if (copy.sourceData!=NULL)
SourceData = copy.SourceData;
DestroySource = copy.DestroySource;
if (SourceData != NULL && DestroySource)
{
sourceData=copy.sourceData;
destroySource=copy.destroySource;
if (destroySource) sourceData[copy.Length]++;
SourceData[copy.Length]++;
}
else sourceData=NULL;
return *this;
}
#endif
FWadLump::FWadLump (const FileReader &other, long length)
: FileReader (other, length), sourceData(NULL)
FWadLump::FWadLump (const FileReader &other, long length, bool encrypted)
: FileReader(other, length), SourceData(NULL), DestroySource(false), Encrypted(encrypted)
{
}
FWadLump::FWadLump (FILE *file, long length)
: FileReader (file, length), sourceData(NULL)
: FileReader(file, length), SourceData(NULL), DestroySource(false), Encrypted(false)
{
}
FWadLump::FWadLump (char *data, long length, bool destroy)
: FileReader (), sourceData(data)
: FileReader(), SourceData(data), DestroySource(destroy), Encrypted(false)
{
FilePos = StartPos = 0;
Length = length;
destroySource=destroy;
if (destroySource) data[length]=0;
if (destroy)
{
data[length] = 0;
}
}
FWadLump::~FWadLump()
{
if (sourceData && destroySource)
if (SourceData && DestroySource)
{
if (sourceData[Length]==0) delete [] sourceData;
else sourceData[Length]--;
if (SourceData[Length] == 0)
{
delete[] SourceData;
}
else
{
SourceData[Length]--;
}
}
}
long FWadLump::Seek (long offset, int origin)
{
if (sourceData)
if (SourceData)
{
switch (origin)
{
@ -2095,27 +2099,50 @@ long FWadLump::Seek (long offset, int origin)
case SEEK_END:
offset += Length;
break;
default:
break;
}
if (offset<0) offset=0;
else if (offset>Length) offset=Length;
FilePos=offset;
FilePos = clamp<long> (offset, 0, Length);
return 0;
}
else return FileReader::Seek(offset, origin);
return FileReader::Seek(offset, origin);
}
long FWadLump::Read (void *buffer, long len)
{
if (sourceData)
long numread;
long startread = FilePos;
if (SourceData != NULL)
{
if (FilePos+len>Length) len=Length-FilePos;
memcpy(buffer, sourceData+FilePos, len);
FilePos+=len;
return len;
if (FilePos + len > Length)
{
len = Length - FilePos;
}
else return FileReader::Read(buffer, len);
memcpy(buffer, SourceData + FilePos, len);
FilePos += len;
numread = len;
}
else
{
numread = FileReader::Read(buffer, len);
}
// Blood, you are so mean to me with your encryption.
if (Encrypted && startread - StartPos < 256)
{
int cryptstart = startread - StartPos;
int cryptlen = MIN<int> (FilePos - StartPos, 256);
BYTE *data = (BYTE *)buffer - cryptstart;
for (int i = cryptstart; i < cryptlen; ++i)
{
data[i] ^= i >> 1;
}
}
return numread;
}
// FMemLump -----------------------------------------------------------------

View File

@ -79,6 +79,9 @@ typedef enum {
// [RH] Copy an 8-char string and uppercase it.
void uppercopy (char *to, const char *from);
// Perform Blood encryption/decryption.
void BloodCrypt (void *data, int key, int len);
// A very loose reference to a lump on disk. This is really just a wrapper
// around the main wad's FILE object with a different length recorded. Since
// the two lumps from the same wad share the same FILE, you cannot read from
@ -97,12 +100,13 @@ public:
long Read (void *buffer, long len);
private:
FWadLump (const FileReader &reader, long length);
FWadLump (const FileReader &reader, long length, bool encrypted);
FWadLump (FILE *file, long length);
FWadLump (char * data, long length, bool destroy);
char * sourceData;
bool destroySource;
char *SourceData;
bool DestroySource;
bool Encrypted;
friend class FWadCollection;
};
@ -189,7 +193,7 @@ public:
bool CheckLumpName (int lump, const char *name) const; // [RH] Returns true if the names match
bool IsUncompressedFile(int lump) const;
bool IsEncryptedFile(int lump) const;
int GetNumLumps () const;