Islet-Online-Unpacker/Program.cs

77 lines
2.8 KiB
C#
Raw Normal View History

2024-03-04 20:12:01 +01:00
//Written for Islet Online. https://store.steampowered.com/app/428180/
using System.IO;
2024-03-03 00:53:01 +01:00
using System.IO.Compression;
namespace Islet_Online_Unpacker
{
static class Program
{
static void Main(string[] args)
{
2024-04-20 19:15:27 +02:00
using FileStream input = File.OpenRead(args[0]);
BinaryReader br = new(input);
Directory.CreateDirectory(Path.GetDirectoryName(input.Name) + "//" + Path.GetFileNameWithoutExtension(input.Name));
2024-04-20 19:17:34 +02:00
2024-03-03 00:53:01 +01:00
while (br.BaseStream.Position < br.BaseStream.Length)
{
int size = br.ReadInt32();
if (size == 0x100)
{
br.BaseStream.Position -= 4;
break;
};
br.BaseStream.Position += size;
}
2024-04-20 19:15:27 +02:00
System.Collections.Generic.List<Subfile> subfiles = new();
2024-03-03 00:53:01 +01:00
while (br.BaseStream.Position < br.BaseStream.Length - 0x28)
{
2024-04-20 19:15:27 +02:00
Subfile subfile = new()
2024-03-03 00:53:01 +01:00
{
isCompressed = br.ReadInt32(),
sizeUncompressed = br.ReadInt32(),
sizeCompressed = br.ReadInt32(),
2024-04-20 19:15:27 +02:00
start = br.ReadInt32()
2024-03-03 00:53:01 +01:00
};
br.ReadBytes(20);
subfile.name = new(br.ReadChars(br.ReadInt16()));
subfiles.Add(subfile);
}
2024-04-20 19:17:34 +02:00
2024-04-20 19:15:27 +02:00
foreach (Subfile sub in subfiles)
2024-03-03 00:53:01 +01:00
{
2024-04-20 19:15:27 +02:00
br.BaseStream.Position = sub.start;
2024-03-03 00:53:01 +01:00
int size = br.ReadInt32();
if ((sub.isCompressed == 0 && size != sub.sizeUncompressed) || (sub.isCompressed == 0x100 && size != sub.sizeCompressed))
throw new System.Exception("Fuck.");
if (sub.name.Contains(@"\"))
2024-04-20 19:15:27 +02:00
Directory.CreateDirectory(Path.GetDirectoryName(input.Name) + "//" + Path.GetDirectoryName(sub.name));
2024-03-03 00:53:01 +01:00
2024-04-20 19:15:27 +02:00
using FileStream FS = File.Create(Path.GetDirectoryName(input.Name) + "//" + sub.name);
2024-03-03 00:53:01 +01:00
BinaryWriter bw = new(FS);
if (sub.isCompressed == 0x100)
{
MemoryStream ms = new();
br.ReadInt16();
using (var ds = new DeflateStream(new MemoryStream(br.ReadBytes(size)), CompressionMode.Decompress))
2024-04-20 19:24:52 +02:00
ds.CopyTo(FS);
2024-03-03 00:53:01 +01:00
continue;
}
bw.Write(br.ReadBytes(size));
bw.Close();
}
}
2024-04-20 19:17:34 +02:00
2024-04-20 19:15:27 +02:00
struct Subfile
2024-03-03 00:53:01 +01:00
{
public int isCompressed;
public int sizeUncompressed;
public int sizeCompressed;
2024-04-20 19:15:27 +02:00
public int start;
2024-03-03 00:53:01 +01:00
public string name;
}
}
2024-03-04 20:12:01 +01:00
}