Skip to content

Instantly share code, notes, and snippets.

@barncastle
barncastle / ShakedownHawaiiBFP2.cs
Last active August 31, 2022 15:03
Code for reading Vblank Entertainment' Shakedown: Hawaii's BFP archives
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Linq;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using System.IO.Compression;
@barncastle
barncastle / DragonManiaLegendsPAK.cs
Created August 12, 2022 16:19
Sample code for decompressing the header of Dragon Mania Legends PAK files
// iterate each sample file
foreach (var sample in Directory.GetFiles(@"C:\Users\temp\Downloads\sample"))
{
// open the file stream and create a reader
using var stream = File.OpenRead(sample);
using var reader = new BinaryReader(stream);
// read the header
var magic = reader.ReadString(4);
var fileTableCompressedSize = reader.ReadInt32();
@barncastle
barncastle / WarForKingship.js
Created August 10, 2022 16:00
Core functions for reading War For Kingship's BIN files
var PackageItemType;
(function (PackageItemType) {
PackageItemType[PackageItemType["Image"] = 0] = "Image";
PackageItemType[PackageItemType["MovieClip"] = 1] = "MovieClip";
PackageItemType[PackageItemType["Sound"] = 2] = "Sound";
PackageItemType[PackageItemType["Component"] = 3] = "Component";
PackageItemType[PackageItemType["Atlas"] = 4] = "Atlas";
PackageItemType[PackageItemType["Font"] = 5] = "Font";
PackageItemType[PackageItemType["Swf"] = 6] = "Swf";
PackageItemType[PackageItemType["Misc"] = 7] = "Misc";
@barncastle
barncastle / muk.cpp
Created August 8, 2022 12:06
Bio F.R.E.A.K.S Muk archive format
struct MukArchive {
uint16 version
uint16 fileCount
uint32 fileNameLength; // unused, game always uses 8
FileInfo fileInfos[fileCount];
byte fileData[x];
}
struct FileInfo {
char Name[8];
@barncastle
barncastle / FastLZ.cs
Last active July 30, 2022 01:02
C# port of Ariya Hidayat's FastLZ
unsafe static class FastLZ
{
private const int MAX_COPY = 32;
private const int MAX_LEN = 264; /* 256 + 8 */
private const uint MAX_L1_DISTANCE = 8192;
private const uint MAX_L2_DISTANCE = 8191;
private const uint MAX_FARDISTANCE = 65535 + MAX_L2_DISTANCE - 1;
private const int HASH_LOG = 14;
private const int HASH_SIZE = 1 << HASH_LOG;
private const uint HASH_MASK = HASH_SIZE - 1;
public class WELL512
{
private readonly uint[] State;
private int Index;
public WELL512(uint seed)
{
Index = 0;
State = new uint[16];
@barncastle
barncastle / StarskyHutchBTW.cs
Last active June 23, 2022 20:10
Code for reading Mind's Eye Productions' Starsky and Hutch's BTW files
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace ConsoleAppFramework
{
class StarskyHutchBTW : FileStream
{
public readonly BTWHeader Header;
public readonly BTWOffsets Offsets;
@barncastle
barncastle / Gami.cs
Last active June 15, 2022 09:20
Run Length Decoder for The Nations 2 Image files
using FileStream fs = File.OpenRead(@"D:\Games\The Nations Gold\dump\file691_gami_MM_VK2_00.tga");
ushort width = fs.Read<ushort>();
ushort height = fs.Read<ushort>();
fs.Position = 20; // not needed
// convert the remaining data to a uint16 array
int inputSize = (int)(fs.Length - 20) / 2;
ushort[] input = fs.Read<ushort>(inputSize);
@barncastle
barncastle / DavinciPak.cs
Last active June 13, 2022 10:54
Code for reading 2K Games' - The Da Vinci Code's PAK files
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace ConsoleApp2
{
@barncastle
barncastle / CombinedFile.cs
Last active June 1, 2022 16:40
Code for reading and extracting files from Out of Sight Game's - A Hero's Call's Adventure.dat
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace Parser
{
public class CombinedFile : FileStream
{
public IEnumerable<string> Files => TOC.Keys;