Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ravahn committed Mar 18, 2018
2 parents f0ed9d9 + 8987830 commit 909570b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Machina.FFXIV/FFXIVBundleDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,7 @@ public unsafe void StoreData(byte[] buffer)
if (LastMessageTimestamp != DateTime.MinValue)
Trace.WriteLine("FFXIVBundleDecoder: Invalid magic # in header:" + Utility.ByteArrayToHexString(_bundleBuffer, offset, 36));

offset = GetNextMagicNumberPos(_bundleBuffer, offset);
if (offset == -1)
{
//reset stream
_allocated = 0;
_bundleBuffer = null;
return;
}
offset = ResetStream(offset);
continue;
}

Expand All @@ -100,12 +93,10 @@ public unsafe void StoreData(byte[] buffer)
}
int messageBufferSize;
byte[] message = DecompressFFXIVMessage(ref header, _bundleBuffer, offset, out messageBufferSize);

// Handle error condition from decompression - stream may be invalid.
if (message == null)
if (message == null || messageBufferSize <= 0)
{
_allocated = 0;
return;
offset = ResetStream(offset);
continue;
}

offset += header.length;
Expand Down Expand Up @@ -199,6 +190,18 @@ private unsafe byte[] DecompressFFXIVMessage(ref FFXIVBundleHeader header, byte[
return _decompressionBuffer;
}

private unsafe int ResetStream(int offset)
{
offset = GetNextMagicNumberPos(_bundleBuffer, offset);
if (offset == -1)
{
//reset stream
_allocated = 0;
_bundleBuffer = null;
}

return offset;
}

private unsafe int GetNextMagicNumberPos(byte[] buffer, int offset)
{
Expand Down
1 change: 1 addition & 0 deletions Machina.FFXIV/Headers/FFXIMessageHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum ServerMessageType : ushort
ActorCast = 0x0162,
AddStatusEffect = 0x0141,
ActorControl142 = 0x0142,
ActorControl143 = 0x0143,
ActorControl144 = 0x0144,
//ActorSpawn = 0x0190,
ActorGauge = 0x027d
Expand Down

0 comments on commit 909570b

Please sign in to comment.