Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/TSMapEditor/CCEngine/CCFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ private bool LoadMixFile(string name)
{
// Logger.Log("Loading MIX file " + name + " from existing MIX file " + Path.GetFileName(value.MixFile.FilePath));
var mixFile = new MixFile(value.MixFile, value.Offset);
mixFile.Parse();

try
{
mixFile.Parse();
}
catch (Exception ex)
{
Logger.Log($"Failed to parse MIX file {name}: {ex.Message}");
}

AddMix(mixFile);
return true;
}
Expand Down Expand Up @@ -129,7 +138,16 @@ private bool LoadMixFromDirectories(string name)

Logger.Log("Loading MIX file " + name + " from " + searchDir);
var mixFile = new MixFile();
mixFile.Parse(Path.Combine(searchDir, name));

try
{
mixFile.Parse(Path.Combine(searchDir, name));
}
catch (Exception ex)
{
Logger.Log($"Failed to parse MIX file {name}: {ex.Message}");
}

AddMix(mixFile);

return true;
Expand Down
9 changes: 7 additions & 2 deletions src/TSMapEditor/CCEngine/MixFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public void Parse(Stream stream = null)

MixFileHeader header = new MixFileHeader(buffer);

// A zero file count means the (possibly encrypted) index came out garbage.
// Fail loudly rather than silently registering an empty MIX.
if (header.FileCount == 0)
throw new MixParseException($"Invalid MIX index (fileCount=0, encrypted={isEncrypted}).");

bodyOffset = INDEX_POSITION + MixFileEntry.SIZE_OF_FILE_ENTRY * header.FileCount;

if (isEncrypted)
Expand Down Expand Up @@ -259,14 +264,14 @@ public MixFileHeader(byte[] buffer)
if (buffer.Length < SIZE_OF_HEADER)
throw new ArgumentException("buffer is not long enough");

FileCount = BitConverter.ToInt16(buffer, 0);
FileCount = BitConverter.ToUInt16(buffer, 0);
BodySize = BitConverter.ToInt32(buffer, 2);
}

/// <summary>
/// The number of files in the MIX file.
/// </summary>
public short FileCount { get; private set; }
public ushort FileCount { get; private set; }

/// <summary>
/// The size of the MIX file, excluding the header and index.
Expand Down
Loading