Skip to content
Merged
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
36 changes: 31 additions & 5 deletions DXMainClient/Domain/SavedGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace DTAClient.Domain
public class SavedGame
{
const string SAVED_GAME_PATH = "Saved Games/";
const int MAX_SCENARIO_DESCRIPTION_BYTES = 1024 * 1024;

public SavedGame(string fileName)
{
Expand All @@ -36,15 +37,40 @@ public bool ParseInfo()
FileInfo savedGameFileInfo = SafePath.GetFile(ProgramConstants.GamePath, SAVED_GAME_PATH, FileName);

using (Stream file = savedGameFileInfo.Open(FileMode.Open, FileAccess.Read))
using (RootStorage root = RootStorage.Open(file))
{
var cf = new CompoundFile(file);
using (CfbStream scenarioDescStream = root.OpenStream("Scenario Description"))
{
if (scenarioDescStream.Length > MAX_SCENARIO_DESCRIPTION_BYTES)
throw new InvalidDataException($"Scenario Description stream was unexpectedly large: {scenarioDescStream.Length} bytes.");

int scenarioDescLength = checked((int)scenarioDescStream.Length);
byte[] scenarioDescData = new byte[scenarioDescLength];
int bytesRead = 0;
while (bytesRead < scenarioDescLength)
{
int readCount = scenarioDescStream.Read(scenarioDescData, bytesRead, scenarioDescLength - bytesRead);
if (readCount == 0)
throw new EndOfStreamException("Unexpected end of stream while reading Scenario Description.");

bytesRead += readCount;
}

GUIName = System.Text.Encoding.Unicode.GetString(scenarioDescData).TrimEnd(['\0']);
Comment on lines +42 to +59
}

GUIName = System.Text.Encoding.Unicode.GetString(cf.RootStorage.GetStream("Scenario Description").GetData()).TrimEnd(['\0']);
try
if (root.TryOpenStream("CustomMissionID", out CfbStream? customMissionIdStream))
{
CustomMissionID = BinaryPrimitives.ReadInt32LittleEndian(cf.RootStorage.GetStream("CustomMissionID").GetData());
using (customMissionIdStream)
{
byte[] customMissionIdData = new byte[sizeof(int)];
int bytesRead = customMissionIdStream.Read(customMissionIdData, 0, customMissionIdData.Length);
CustomMissionID = bytesRead < customMissionIdData.Length
? throw new EndOfStreamException("Unexpected end of stream while reading CustomMissionID.")
: BinaryPrimitives.ReadInt32LittleEndian(customMissionIdData);
Comment thread
SadPencil marked this conversation as resolved.
}
}
catch (CFItemNotFound)
else
{
CustomMissionID = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(DotnetLibrariesVersion)" />
<PackageVersion Include="OpenMcdf" Version="2.4.1" />
<PackageVersion Include="OpenMcdf" Version="3.1.4" />
<PackageVersion Include="SixLabors.ImageSharp" Version="2.1.11" />
<PackageVersion Include="System.DirectoryServices" Version="$(DotnetLibrariesVersion)" />
<PackageVersion Include="System.Management" Version="$(DotnetLibrariesVersion)" />
Expand Down
Loading