Skip to content

Commit 59951c5

Browse files
committed
Fixes for recent FFileReader changes
1 parent c999ccc commit 59951c5

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

Unreal/UnCoreSerialize.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,9 @@ FFileArchive::FFileArchive(const char *Filename, unsigned InOptions)
496496
: Options(InOptions)
497497
, f(NULL)
498498
, Buffer(NULL)
499-
, BufferPos(0)
500499
, BufferSize(0)
500+
, BufferPos(0)
501+
, FilePos(0)
501502
{
502503
// process the filename
503504
FullName = appStrdup(Filename);
@@ -636,9 +637,15 @@ void FFileReader::Serialize(void *data, int size)
636637
}
637638
SeekPos = -1;
638639
}
640+
#if MAX_DEBUG
641+
int tell = ftell(f);
642+
if (tell != FilePos)
643+
appError("Bad FilePos!");
644+
#endif
639645
if (size >= FILE_BUFFER_SIZE / 2)
640646
{
641647
// Large block, read directly to destination skipping buffer
648+
// appPrintf("read2: %d+%d -> %d\n", (int)FilePos, size, (int)FilePos + size);
642649
int res = fread(data, size, 1, f);
643650
if (res != 1)
644651
appError("Unable to read %d bytes at pos=0x%llX", size, FilePos);
@@ -647,10 +654,16 @@ void FFileReader::Serialize(void *data, int size)
647654
GSerializeBytes += size;
648655
#endif
649656
FilePos += size;
657+
BufferPos = FilePos;
658+
// Invalidate buffer
659+
BufferSize = 0;
660+
BufferBytesLeft = 0;
661+
LocalReadPos = 0;
650662
return;
651663
}
652664
// Fill buffer
653665
int ReadBytes = fread(Buffer, 1, FILE_BUFFER_SIZE, f);
666+
// appPrintf("read: %d+%d -> %d\n", (int)FilePos, ReadBytes, (int)FilePos + ReadBytes);
654667
if (ReadBytes == 0)
655668
appError("Unable to read %d bytes at pos=0x%llX", 1, FilePos);
656669
#if PROFILE
@@ -680,14 +693,17 @@ void FFileReader::Seek(int Pos)
680693

681694
void FFileReader::Seek64(int64 Pos)
682695
{
696+
// appPrintf("seek: %d\n", (int)Pos);
683697
// Check for buffer validity
684698
int64 LocalPos64 = Pos - BufferPos;
685699
if (LocalPos64 < 0 || LocalPos64 >= BufferSize)
686700
{
687-
// Outside of the buffer
701+
// Outside of the current buffer, invalidate it
702+
BufferSize = 0;
688703
BufferBytesLeft = 0;
704+
LocalReadPos = 0;
689705
// SeekPos will be reset to -1 after actual seek
690-
SeekPos = Pos;
706+
BufferPos = SeekPos = Pos;
691707
}
692708
else
693709
{
@@ -717,6 +733,7 @@ int64 FFileReader::GetFileSize64() const
717733
FFileReader* _this = const_cast<FFileReader*>(this);
718734
// don't rewind file back
719735
_this->FilePos = _this->FileSize = _filelengthi64(fileno(f));
736+
_this->SeekPos = 0;
720737
#else
721738
fseeko64(f, 0, SEEK_END);
722739
FFileReader* _this = const_cast<FFileReader*>(this);

Unreal/UnPackage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,7 @@ void UnPackage::SetupReader(int ExportIndex)
18571857
// setup for object
18581858
const FObjectExport &Exp = GetExport(ExportIndex);
18591859
SetStopper(Exp.SerialOffset + Exp.SerialSize);
1860+
// appPrintf("Setup for %s: %d + %d -> %d\n", *Exp.ObjectName, Exp.SerialOffset, Exp.SerialSize, Exp.SerialOffset + Exp.SerialSize);
18601861
Seek(Exp.SerialOffset);
18611862
unguard;
18621863
}

Unreal/UnPackage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ class UnPackage : public FArchive
380380
{
381381
Loader->SetStopper(Pos);
382382
}
383-
virtual int GetStopper() const
383+
virtual int GetStopper() const
384384
{
385385
return Loader->GetStopper();
386386
}

umodel

0 Bytes
Binary file not shown.

umodel.exe

1 KB
Binary file not shown.

0 commit comments

Comments
 (0)