so I currently messing arround with Pantheon a bit and I wounder, if you can help me get a Script to unpack the Patch Files.
I am not sure if it actually just Patch files or if it simply replace them.
The Compression of the Archives is Pack1. The Patcher that is used is:
https://github.com/patchkit-net/patchkit-patcher-unity
Code: Select all
if (compressionMethod == "pack1")
{
usedSuffix = "_";
return new Pack1Unarchiver(this._packagePath, this._pack1Meta, destinationDir, this._packagePassword, "_");
}
}
throw new UnknownPackageCompressionModeException(string.Format("Unknown compression method: {0}", this._diffSummary.CompressionMethod));
}
Code: Select all
{
// Token: 0x02000018 RID: 24
public class Pack1Unarchiver : IUnarchiver
{
// Token: 0x0600007A RID: 122 RVA: 0x00002538 File Offset: 0x00000738
public Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, string key, string suffix = "") : this(packagePath, metaData, destinationDirPath, Encoding.ASCII.GetBytes(key), suffix, new BytesRange(0L, -1L))
{
}
// Token: 0x0600007B RID: 123 RVA: 0x0000255A File Offset: 0x0000075A
public Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, string key, string suffix, BytesRange range) : this(packagePath, metaData, destinationDirPath, Encoding.ASCII.GetBytes(key), suffix, range)
{
}
// Token: 0x0600007C RID: 124 RVA: 0x00006874 File Offset: 0x00004A74
public Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, byte[] key, string suffix, BytesRange range)
{
Checks.ArgumentFileExists(packagePath, "packagePath");
Checks.ArgumentDirectoryExists(destinationDirPath, "destinationDirPath");
Checks.ArgumentNotNull(suffix, "suffix");
if (range.Start == 0L)
{
Assert.AreEqual<MagicBytes.FileType>(MagicBytes.Pack1, MagicBytes.ReadFileType(packagePath), "Is not Pack1 format");
}
Pack1Unarchiver.DebugLogger.LogConstructor();
Pack1Unarchiver.DebugLogger.LogVariable(packagePath, "packagePath");
Pack1Unarchiver.DebugLogger.LogVariable(destinationDirPath, "destinationDirPath");
Pack1Unarchiver.DebugLogger.LogVariable(suffix, "suffix");
this._packagePath = packagePath;
this._metaData = metaData;
this._destinationDirPath = destinationDirPath;
this._suffix = suffix;
this._range = range;
using (SHA256 sha = SHA256.Create())
{
this._key = sha.ComputeHash(key);
}
this._iv = Convert.FromBase64String(this._metaData.Iv);
}
// Token: 0x14000002 RID: 2
// (add) Token: 0x0600007D RID: 125 RVA: 0x00006978 File Offset: 0x00004B78
// (remove) Token: 0x0600007E RID: 126 RVA: 0x000069B0 File Offset: 0x00004BB0
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public event UnarchiveProgressChangedHandler UnarchiveProgressChanged;
// Token: 0x0600007F RID: 127 RVA: 0x000069E8 File Offset: 0x00004BE8
public void Unarchive(CancellationToken cancellationToken)
{
int num = 1;
Pack1Unarchiver.DebugLogger.Log("Unpacking " + this._metaData.Files.Length + " files...");
Pack1Meta.FileEntry[] files = this._metaData.Files;
for (int i = 0; i < files.Length; i++)
{
Pack1Meta.FileEntry fileEntry = files[i];
this.OnUnarchiveProgressChanged(fileEntry.Name, fileEntry.Type == "regular", num, this._metaData.Files.Length, 0.0);
Pack1Meta.FileEntry currentFile = fileEntry;
int currentEntry = num;
if (this.CanUnpack(fileEntry))
{
this.Unpack(fileEntry, delegate(double progress)
{
this.OnUnarchiveProgressChanged(currentFile.Name, currentFile.Type == "regular", currentEntry, this._metaData.Files.Length, progress);
}, cancellationToken, null);
}
else
{
Pack1Unarchiver.DebugLogger.LogWarning(string.Format("The file {0} couldn't be unpacked.", fileEntry.Name));
}
this.OnUnarchiveProgressChanged(fileEntry.Name, fileEntry.Type == "regular", num, this._metaData.Files.Length, 1.0);
num++;
}
Pack1Unarchiver.DebugLogger.Log("Unpacking finished succesfully!");
}
// Token: 0x06000080 RID: 128 RVA: 0x00006B20 File Offset: 0x00004D20
public void UnarchiveSingleFile(Pack1Meta.FileEntry file, CancellationToken cancellationToken, string destinationDirPath = null)
{
this.OnUnarchiveProgressChanged(file.Name, file.Type == "regular", 0, 1, 0.0);
if (!this.CanUnpack(file))
{
throw new ArgumentOutOfRangeException("file", file, null);
}
this.Unpack(file, delegate(double progress)
{
this.OnUnarchiveProgressChanged(file.Name, file.Type == "regular", 1, 1, progress);
}, cancellationToken, destinationDirPath);
this.OnUnarchiveProgressChanged(file.Name, file.Type == "regular", 0, 1, 1.0);
}
// Token: 0x06000081 RID: 129 RVA: 0x00006BE0 File Offset: 0x00004DE0
private bool CanUnpack(Pack1Meta.FileEntry file)
{
if (file.Type != "regular")
{
return true;
}
if (this._range.Start == 0L && this._range.End == -1L)
{
return true;
}
bool result;
if (file.Offset >= this._range.Start)
{
long? offset = file.Offset;
bool flag = offset != null;
long? size = file.Size;
result = (((!(flag & size != null)) ? null : new long?(offset.GetValueOrDefault() + size.GetValueOrDefault())) <= this._range.End);
}
else
{
result = false;
}
return result;
}
// Token: 0x06000082 RID: 130 RVA: 0x00006CD8 File Offset: 0x00004ED8
private void Unpack(Pack1Meta.FileEntry file, Action<double> progress, CancellationToken cancellationToken, string destinationDirPath = null)
{
string type = file.Type;
if (type != null)
{
if (type == "regular")
{
this.UnpackRegularFile(file, progress, cancellationToken, destinationDirPath);
return;
}
if (type == "directory")
{
progress(0.0);
this.UnpackDirectory(file);
progress(1.0);
return;
}
if (type == "symlink")
{
progress(0.0);
this.UnpackSymlink(file);
progress(1.0);
return;
}
}
Pack1Unarchiver.DebugLogger.LogWarning("Unknown file type: " + file.Type);
}
// Token: 0x06000083 RID: 131 RVA: 0x00006DAC File Offset: 0x00004FAC
private void UnpackDirectory(Pack1Meta.FileEntry file)
{
string text = Path.Combine(this._destinationDirPath, file.Name);
Pack1Unarchiver.DebugLogger.Log("Creating directory " + text);
Directory.CreateDirectory(text);
Pack1Unarchiver.DebugLogger.Log("Directory " + text + " created successfully!");
}
// Token: 0x06000084 RID: 132 RVA: 0x00006E04 File Offset: 0x00005004
private void UnpackSymlink(Pack1Meta.FileEntry file)
{
string str = Path.Combine(this._destinationDirPath, file.Name);
Pack1Unarchiver.DebugLogger.Log("Creating symlink: " + str);
}
// Token: 0x06000085 RID: 133 RVA: 0x00006E38 File Offset: 0x00005038
private void UnpackRegularFile(Pack1Meta.FileEntry file, Action<double> onProgress, CancellationToken cancellationToken, string destinationDirPath = null)
{
string text = Path.Combine((destinationDirPath != null) ? destinationDirPath : this._destinationDirPath, file.Name + this._suffix);
Pack1Unarchiver.DebugLogger.LogFormat("Unpacking regular file {0} to {1}", new object[]
{
file,
text
});
Files.CreateParents(text);
RijndaelManaged rijndaelManaged = new RijndaelManaged
{
Mode = CipherMode.CBC,
Padding = PaddingMode.None,
KeySize = 256
};
ICryptoTransform decryptor = rijndaelManaged.CreateDecryptor(this._key, this._iv);
using (FileStream fileStream = new FileStream(this._packagePath, FileMode.Open))
{
fileStream.Seek(file.Offset.Value - this._range.Start, SeekOrigin.Begin);
using (LimitedStream limitedStream = new LimitedStream(fileStream, file.Size.Value))
{
using (FileStream fileStream2 = new FileStream(text, FileMode.Create))
{
this.ExtractFileFromStream(limitedStream, fileStream2, file, decryptor, onProgress, cancellationToken);
}
if (Platform.IsPosix())
{
Chmod.SetMode(file.Mode.Substring(3), text);
}
}
}
Pack1Unarchiver.DebugLogger.Log("File " + file.Name + " unpacked successfully!");
}
// Token: 0x06000086 RID: 134 RVA: 0x00006FCC File Offset: 0x000051CC
private void ExtractFileFromStream(Stream sourceStream, Stream targetStream, Pack1Meta.FileEntry file, ICryptoTransform decryptor, Action<double> onProgress, CancellationToken cancellationToken)
{
using (CryptoStream cryptoStream = new CryptoStream(sourceStream, decryptor, CryptoStreamMode.Read))
{
using (GZipStream gzipStream = new GZipStream(cryptoStream, CompressionMode.Decompress))
{
long num = 0L;
byte[] buffer = new byte[131072];
int num2;
while ((num2 = gzipStream.Read(buffer, 0, 131072)) != 0)
{
cancellationToken.ThrowIfCancellationRequested();
targetStream.Write(buffer, 0, num2);
num += (long)num2;
onProgress((double)gzipStream.Position / (double)file.Size.Value);
}
}
}
}
// Token: 0x06000087 RID: 135 RVA: 0x0000708C File Offset: 0x0000528C
protected virtual void OnUnarchiveProgressChanged(string name, bool isFile, int entry, int amount, double entryProgress)
{
UnarchiveProgressChangedHandler unarchiveProgressChanged = this.UnarchiveProgressChanged;
if (unarchiveProgressChanged != null)
{
unarchiveProgressChanged(name, isFile, entry, amount, entryProgress);
}
}
// Token: 0x04000035 RID: 53
private static readonly DebugLogger DebugLogger = new DebugLogger(typeof(Pack1Unarchiver));
// Token: 0x04000036 RID: 54
private readonly string _packagePath;
// Token: 0x04000037 RID: 55
private readonly Pack1Meta _metaData;
// Token: 0x04000038 RID: 56
private readonly string _destinationDirPath;
// Token: 0x04000039 RID: 57
private readonly string _suffix;
// Token: 0x0400003A RID: 58
private readonly byte[] _key;
// Token: 0x0400003B RID: 59
private readonly byte[] _iv;
// Token: 0x0400003C RID: 60
private readonly BytesRange _range;
}
}