Skip to content

Commit

Permalink
Updated for BioLib 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Bioruebe committed Aug 31, 2020
1 parent b356f0b commit 66fef21
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion godotdec/App.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
28 changes: 11 additions & 17 deletions godotdec/Program.cs
@@ -1,4 +1,5 @@
using BioLib;
using BioLib.Streams;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -7,14 +8,16 @@

namespace godotdec {
class Program {
private const string VERSION = "2.1.1";
private const string PROMPT_ID = "godotdec_overwrite";
private const int MAGIC = 0x43504447;

private static string inputFile;
private static string outputDirectory;
private static bool convertAssets;

static void Main(string[] args) {
Bio.Header("godotdec", "2.1.0", "2018-2020", "A simple unpacker for Godot Engine package files (.pck|.exe)",
Bio.Header("godotdec", VERSION, "2018-2020", "A simple unpacker for Godot Engine package files (.pck|.exe)",
"[<options>] <input_file> [<output_directory>]\n\nOptions:\n-c\t--convert\tConvert textures and audio files");

if (Bio.HasCommandlineSwitchHelp(args)) return;
Expand All @@ -27,17 +30,17 @@ class Program {

CheckMagic(inputStream.ReadInt32());

inputStream.BaseStream.Seek(-12, SeekOrigin.Current);
inputStream.BaseStream.Skip(-12);
var offset = inputStream.ReadInt64();
inputStream.BaseStream.Seek(-offset - 8, SeekOrigin.Current);
inputStream.BaseStream.Skip(-offset - 8);

CheckMagic(inputStream.ReadInt32());
}

Bio.Cout($"Godot Engine version: {inputStream.ReadInt32()}.{inputStream.ReadInt32()}.{inputStream.ReadInt32()}.{inputStream.ReadInt32()}");

// Skip reserved bytes (16x Int32)
inputStream.BaseStream.Seek(16 * 4, SeekOrigin.Current);
inputStream.BaseStream.Skip(16 * 4);

var fileCount = inputStream.ReadInt32();
Bio.Cout($"Found {fileCount} files in package");
Expand All @@ -50,7 +53,7 @@ class Program {
var fileEntry = new FileEntry(path.ToString(), inputStream.ReadInt64(), inputStream.ReadInt64());
fileIndex.Add(fileEntry);
Bio.Debug(fileEntry);
inputStream.BaseStream.Seek(16, SeekOrigin.Current);
inputStream.BaseStream.Skip(16);
//break;
}

Expand Down Expand Up @@ -87,21 +90,12 @@ class Program {
}
}

inputStream.BaseStream.Position = fileEntry.offset;
var destination = Path.Combine(outputDirectory, fileEntry.path);
destination = Bio.EnsureFileDoesNotExist(destination, "godotdec_overwrite");
inputStream.BaseStream.Seek(fileEntry.offset, SeekOrigin.Begin);
if (destination == null) continue;

try {
var fileMode = FileMode.CreateNew;
Directory.CreateDirectory(Path.GetDirectoryName(destination));

if (File.Exists(destination)) {
fileMode = FileMode.Create;
}
using (var outputStream = new FileStream(destination, fileMode)) {
Bio.CopyStream(inputStream.BaseStream, outputStream, (int) fileEntry.size, false);
}
Action<Stream, Stream> copyFunction = (input, output) => input.Copy(output, (int) fileEntry.size);
inputStream.BaseStream.WriteToFile(destination, PROMPT_ID, copyFunction);
}
catch (Exception e) {
Bio.Error(e);
Expand Down
7 changes: 3 additions & 4 deletions godotdec/godotdec.csproj
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>godotdec</RootNamespace>
<AssemblyName>godotdec</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
Expand All @@ -34,16 +34,15 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Bio.cs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Bioruebe.BioLib.1.0.0\lib\net45\Bio.cs.dll</HintPath>
<Reference Include="Bio.cs, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Bioruebe.BioLib.2.0.0\lib\net40\Bio.cs.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion godotdec/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bioruebe.BioLib" version="1.0.0" targetFramework="net45" />
<package id="Bioruebe.BioLib" version="2.0.0" targetFramework="net40" />
</packages>

0 comments on commit 66fef21

Please sign in to comment.