Skip to content

Commit

Permalink
WzLib: Support file size over 2GB.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagamia committed Aug 10, 2017
1 parent 9907910 commit 5ecb5f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions WzComparerR2.WzLib/Wz_File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Wz_File(string fileName, Wz_Structure wz)
this.imageCount = 0;
this.wzStructure = wz;
this.loaded = InitLoad(fileName);
this.stringTable = new Dictionary<int, string>();
this.stringTable = new Dictionary<long, string>();
}

private FileStream fileStream;
Expand All @@ -30,7 +30,7 @@ public Wz_File(string fileName, Wz_Structure wz)

public readonly object ReadLock = new object();

internal Dictionary<int, string> stringTable;
internal Dictionary<long, string> stringTable;
internal byte[] tempBuffer;

public FileStream FileStream
Expand Down Expand Up @@ -126,7 +126,7 @@ public float ReadSingle()
return (fl == -128) ? this.BReader.ReadSingle() : fl;
}

public string ReadString(int offset)
public string ReadString(long offset)
{
byte b = this.BReader.ReadByte();
switch (b)
Expand All @@ -149,7 +149,7 @@ public string ReadString(int offset)
return string.Empty;
}

public string ReadStringAt(int offset)
public string ReadStringAt(long offset)
{
long oldoffset = this.FileStream.Position;
string str;
Expand Down Expand Up @@ -239,7 +239,7 @@ private byte[] GetStringBuffer(int size)
}
}

public int CalcOffset(uint filePos, uint hashedOffset)
public uint CalcOffset(uint filePos, uint hashedOffset)
{
uint offset = (uint)(filePos - 0x3C) ^ 0xFFFFFFFF;
int distance = 0;
Expand All @@ -252,7 +252,7 @@ public int CalcOffset(uint filePos, uint hashedOffset)
offset ^= hashedOffset;
offset += 0x78;

return (int)offset;
return offset;
}

public void GetDirTree(Wz_Node parent)
Expand Down Expand Up @@ -505,7 +505,7 @@ public void DetectWzVersion()

while (this.header.TryGetNextVersion())
{
int offs = CalcOffset(minSizeImg.HashedOffsetPosition, minSizeImg.HashedOffset);
uint offs = CalcOffset(minSizeImg.HashedOffsetPosition, minSizeImg.HashedOffset);

if (offs < this.header.HeaderSize || offs + minSizeImg.Size > this.fileStream.Length) //img块越界
{
Expand Down
9 changes: 5 additions & 4 deletions WzComparerR2.WzLib/Wz_Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Wz_Image(string name, int size, int cs32, uint hashOff, uint hashPos, Wz_
public int Checksum { get; set; }
public uint HashedOffset { get; set; }
public uint HashedOffsetPosition { get; set; }
public int Offset { get; set; }
public long Offset { get; set; }
//已经废弃 使用BMS替代OnList
public bool IsOnList { get; set; }
public Wz_Node Node { get; private set; }
Expand Down Expand Up @@ -112,7 +112,8 @@ private unsafe int GetCheckSum()
this.WzFile.FileStream.Position = this.Offset;
int cs = 0;
byte[] buffer = new byte[4096];
int count, size = this.Size;
int count;
int size = this.Size;
while ((count = this.WzFile.FileStream.Read(buffer, 0, Math.Min(size, buffer.Length))) > 0)
{
fixed (byte* pBuffer = buffer)
Expand All @@ -136,7 +137,7 @@ private unsafe int GetCheckSum()
}
}

private void ExtractImg(int offset, Wz_Node parent, int eob)
private void ExtractImg(long offset, Wz_Node parent, int eob)
{
int entries = 0;
string tag = this.WzFile.ReadString(offset);
Expand Down Expand Up @@ -259,7 +260,7 @@ private bool IsIllegalTag()
}


private void ExtractValue(int offset, Wz_Node parent)
private void ExtractValue(long offset, Wz_Node parent)
{
parent = parent.Nodes.Add(this.WzFile.ReadString(offset));
byte flag = this.WzFile.BReader.ReadByte();
Expand Down

0 comments on commit 5ecb5f3

Please sign in to comment.