Skip to content

Commit c6eb581

Browse files
committed
First Commit
0 parents  commit c6eb581

File tree

12 files changed

+324
-0
lines changed

12 files changed

+324
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vs
2+
bin
3+
obj
4+
Debug
5+
Release
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

DeathEndFormats/Formats/CSH/CSH.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.IO;
5+
6+
namespace DeathEndFormats.Formats.CSH
7+
{
8+
public class CSH
9+
{
10+
const int MAGIC = 0x00687363;
11+
12+
static public void Load(Stream data, Stream output)
13+
{
14+
BinaryReader reader = new BinaryReader(data, Encoding.UTF8, true);
15+
BinaryWriter writer = new BinaryWriter(output, Encoding.UTF8, true);
16+
using (reader)
17+
{
18+
using (writer)
19+
{
20+
int value = Tools.BigEndianToLittleEndian(reader.ReadInt32());
21+
bool correctFormat = value == CSH.MAGIC;
22+
if (!correctFormat)
23+
{
24+
throw new InvalidDataException();
25+
}
26+
writer.Write(Tools.BigEndianToLittleEndian(value));
27+
while (reader.BaseStream.Position < 0x80)
28+
{
29+
reader.ReadInt32();
30+
}
31+
ZLIB.Load(reader.BaseStream, writer.BaseStream);
32+
}
33+
}
34+
}
35+
}
36+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace DeathEndFormats.Formats
6+
{
7+
class DATExtractor
8+
{
9+
}
10+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
namespace DeathEndFormats.Formats.GDAT
5+
{
6+
public class GDAT : IDisposable
7+
{
8+
public static GDAT Load(Stream data)
9+
{
10+
GDAT GDatData = new GDAT();
11+
GDatData.Data = data;
12+
BinaryReader reader = new BinaryReader(data, Encoding.UTF8, true);
13+
14+
using (reader)
15+
{
16+
string MAGIC = Encoding.UTF8.GetString(reader.ReadBytes(GDAT.MAGIC.Length));
17+
bool correctFormat = GDAT.MAGIC == MAGIC;
18+
if (!correctFormat)
19+
{
20+
throw new InvalidDataException();
21+
}
22+
23+
GDatData.FileCount = reader.ReadUInt32();
24+
Console.WriteLine("There are " + GDatData.FileCount + " files in the GDAT !");
25+
GDatData.Files = new GDATFile[GDatData.FileCount];
26+
for (int i = 0; i < GDatData.FileCount; i++)
27+
{
28+
GDatData.Files[i] = new GDATFile(reader.ReadUInt32(), reader.ReadUInt32());
29+
var file = GDatData.Files[i];
30+
Console.WriteLine("File found at the address : 0x" + file.Offset.ToString("X") + " => Length : " + ((float)file.Length / 1024 / 1024).ToString("n4") + " Mb");
31+
}
32+
}
33+
return GDatData;
34+
}
35+
public static string ReverseString(string myStr)
36+
{
37+
char[] myArr = myStr.ToCharArray();
38+
Array.Reverse(myArr);
39+
return new string(myArr);
40+
}
41+
public void Export(int id, string path)
42+
{
43+
GDATFile data = Files[id];
44+
Data.Seek(data.Offset, SeekOrigin.Begin);
45+
using (BinaryReader reader = new BinaryReader(Data, Encoding.UTF8, true))
46+
{
47+
byte[] bytes = reader.ReadBytes(4);
48+
string fileFormat = Encoding.UTF8.GetString(bytes);
49+
reader.BaseStream.Seek(data.Offset, SeekOrigin.Begin);
50+
using (FileStream fs = File.Create(path + "." + ReverseString(fileFormat).Replace('\0', '.')))
51+
{
52+
using (BinaryWriter writer = new BinaryWriter(fs))
53+
{
54+
reader.BaseStream.Seek(data.Offset, SeekOrigin.Begin);
55+
writer.BaseStream.Seek(0, SeekOrigin.Begin);
56+
while (reader.BaseStream.Position < data.Offset + 0x80)
57+
{
58+
// writer.Write(reader.ReadByte());
59+
reader.ReadByte();
60+
}
61+
// Array.Reverse(bytes);
62+
// writer.Write(bytes);
63+
ZLIB.Load(Data, writer.BaseStream);
64+
}
65+
}
66+
}
67+
}
68+
69+
public void Dispose()
70+
{
71+
Data.Dispose();
72+
}
73+
74+
public const string MAGIC = "GDAT";
75+
public uint FileCount;
76+
public GDATFile[] Files;
77+
public Stream Data;
78+
}
79+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace DeathEndFormats.Formats.GDAT
6+
{
7+
public class GDATFile
8+
{
9+
public GDATFile(uint offset, uint length)
10+
{
11+
this.offset = offset;
12+
this.length = length;
13+
}
14+
15+
public uint Offset { get => this.offset; }
16+
public uint Length { get => this.length; }
17+
18+
19+
private uint offset = 0;
20+
private uint length = 0;
21+
}
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace DeathEndFormats
6+
{
7+
interface ICanExtract
8+
{
9+
ulong Extract(byte[] data);
10+
ulong ExtractAsync(byte[] data);
11+
}
12+
}

DeathEndFormats/Formats/ZLIB.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.IO;
5+
using System.IO.Compression;
6+
7+
namespace DeathEndFormats.Formats
8+
{
9+
public class ZLIB
10+
{
11+
const string MAGIC = "BILZ";
12+
13+
public static void Load(Stream data, Stream output)
14+
{
15+
BinaryReader reader = new BinaryReader(data, Encoding.UTF8, true);
16+
using (reader)
17+
{
18+
long originalPosition = reader.BaseStream.Position;
19+
string MAGIC = Encoding.UTF8.GetString(reader.ReadBytes(4));
20+
bool correctFormat = MAGIC == ZLIB.MAGIC;
21+
if (!correctFormat)
22+
{
23+
throw new InvalidDataException();
24+
}
25+
26+
int unknown = reader.ReadInt32();
27+
int Length = Tools.BigEndianToLittleEndian(reader.ReadInt32());
28+
int unknown2 = reader.ReadInt32();
29+
short args = reader.ReadInt16();
30+
31+
Tools.Decompress(reader.ReadBytes(Length - 2),output);
32+
33+
}
34+
}
35+
}
36+
}

DeathEndFormats/Tools.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.IO;
5+
using System.IO.Compression;
6+
7+
namespace DeathEndFormats
8+
{
9+
public static class Tools
10+
{
11+
public static int BigEndianToLittleEndian(int BigInt)
12+
{
13+
byte[] intBytes = BitConverter.GetBytes(BigInt);
14+
Array.Reverse(intBytes);
15+
return BitConverter.ToInt32(intBytes, 0);
16+
}
17+
18+
public static void Decompress(byte[] data, Stream output)
19+
{
20+
using (MemoryStream compressedFileStream = new MemoryStream(data))
21+
{
22+
using (DeflateStream decompressionStream = new DeflateStream(compressedFileStream, CompressionMode.Decompress))
23+
{
24+
decompressionStream.CopyTo(output);
25+
}
26+
}
27+
}
28+
}
29+
}

DeathEndToolkit.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30002.166
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeathEndToolkit", "DeathEndToolkit\DeathEndToolkit.csproj", "{0DDAD26A-CCBC-48D8-A9EA-E3F15730FB28}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeathEndFormats", "DeathEndFormats\DeathEndFormats.csproj", "{B95CC3AA-F7B8-4907-9775-E766BEE2215A}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{0DDAD26A-CCBC-48D8-A9EA-E3F15730FB28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{0DDAD26A-CCBC-48D8-A9EA-E3F15730FB28}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{0DDAD26A-CCBC-48D8-A9EA-E3F15730FB28}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{0DDAD26A-CCBC-48D8-A9EA-E3F15730FB28}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{B95CC3AA-F7B8-4907-9775-E766BEE2215A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{B95CC3AA-F7B8-4907-9775-E766BEE2215A}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{B95CC3AA-F7B8-4907-9775-E766BEE2215A}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{B95CC3AA-F7B8-4907-9775-E766BEE2215A}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {3A697B4C-3BE7-4794-9FFC-70EBC9BE5B96}
30+
EndGlobalSection
31+
EndGlobal

0 commit comments

Comments
 (0)