Fixed the blast decompression. Fixes #13689

This commit is contained in:
IceReaper
2022-11-06 21:20:24 +01:00
committed by Matthias Mailänder
parent 621c85059e
commit 09b32f7f98
10 changed files with 364 additions and 4329 deletions

View File

@@ -12,7 +12,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using OpenRA.Mods.Common.FileFormats;
using OpenRA.Mods.Common.Widgets.Logic;
using FS = OpenRA.FileSystem.FileSystem;
@@ -28,6 +27,26 @@ namespace OpenRA.Mods.Common.Installer
using (var source = File.OpenRead(sourcePath))
{
source.Position = 12;
var numFiles = source.ReadUInt16();
source.Position = 51;
source.Position = source.ReadUInt32();
var entries = new Dictionary<string, (uint Length, uint Offset)>();
for (var i = 0; i < numFiles; i++)
{
source.Position += 7;
var entry = (source.ReadUInt32(), source.ReadUInt32());
source.Position += 14;
var key = source.ReadASCII(source.ReadByte());
source.Position += 13;
// This does not apply on game relevant data.
if (!entries.ContainsKey(key))
entries.Add(key, entry);
}
foreach (var node in actionYaml.Nodes)
{
var targetPath = Platform.ResolvePath(node.Key);
@@ -38,32 +57,19 @@ namespace OpenRA.Mods.Common.Installer
continue;
}
var offsetNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Offset");
if (offsetNode == null)
{
Log.Write("install", "Skipping entry with missing Offset definition " + targetPath);
continue;
}
var entry = entries[node.Value.Value];
var lengthNode = node.Value.Nodes.FirstOrDefault(n => n.Key == "Length");
if (lengthNode == null)
{
Log.Write("install", "Skipping entry with missing Length definition " + targetPath);
continue;
}
var length = FieldLoader.GetValue<int>("Length", lengthNode.Value.Value);
source.Position = FieldLoader.GetValue<int>("Offset", offsetNode.Value.Value);
source.Position = entry.Offset;
extracted.Add(targetPath);
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
var displayFilename = Path.GetFileName(Path.GetFileName(targetPath));
Action<long> onProgress = null;
if (length < InstallFromSourceLogic.ShowPercentageThreshold)
if (entry.Length < InstallFromSourceLogic.ShowPercentageThreshold)
updateMessage(modData.Translation.GetString(InstallFromSourceLogic.Extracing, Translation.Arguments("filename", displayFilename)));
else
onProgress = b => updateMessage(modData.Translation.GetString(InstallFromSourceLogic.ExtracingProgress, Translation.Arguments("filename", displayFilename, "progress", 100 * b / length)));
onProgress = b => updateMessage(modData.Translation.GetString(InstallFromSourceLogic.ExtracingProgress, Translation.Arguments("filename", displayFilename, "progress", 100 * b / entry.Length)));
using (var target = File.OpenWrite(targetPath))
{