Skip to content

Commit 527c845

Browse files
committed
Changed the name to CoroToolkit, fixed a bug where the toolkit was always assuming all files were zlib compressed and added the ability to export multiple files at once
1 parent c6eb581 commit 527c845

File tree

13 files changed

+132
-66
lines changed

13 files changed

+132
-66
lines changed
File renamed without changes.

DeathEndFormats/Formats/CSH/CSH.cs renamed to CoroHeartFormats/Formats/CSH/CSH.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Text;
44
using System.IO;
55

6-
namespace DeathEndFormats.Formats.CSH
6+
namespace CoroHeart.Formats.CSH
77
{
88
public class CSH
99
{

DeathEndFormats/Formats/DATExtractor.cs renamed to CoroHeartFormats/Formats/DATExtractor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
namespace DeathEndFormats.Formats
5+
namespace CoroHeart.Formats
66
{
77
class DATExtractor
88
{

DeathEndFormats/Formats/GDAT/GDAT.cs renamed to CoroHeartFormats/Formats/GDAT/GDAT.cs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Text;
4-
namespace DeathEndFormats.Formats.GDAT
5+
namespace CoroHeart.Formats.GDAT
56
{
67
public class GDAT : IDisposable
78
{
@@ -38,34 +39,61 @@ public static string ReverseString(string myStr)
3839
Array.Reverse(myArr);
3940
return new string(myArr);
4041
}
42+
public static string CleanString(string dirtyString)
43+
{
44+
HashSet<char> removeChars = new HashSet<char>(" ?&^$#@!()+-,:;<>’\'-_*");
45+
StringBuilder result = new StringBuilder(dirtyString.Length);
46+
foreach (char c in dirtyString)
47+
if (!removeChars.Contains(c)) // prevent dirty chars
48+
result.Append(c);
49+
return result.ToString();
50+
}
51+
52+
public static bool isZLIB(byte[] data)
53+
{
54+
byte[] magic = new byte[4];
55+
Array.Copy(data, 0x80, magic, 0, 4);
56+
return ReverseString(Encoding.UTF8.GetString(magic)) == "ZLIB";
57+
}
58+
4159
public void Export(int id, string path)
4260
{
4361
GDATFile data = Files[id];
62+
Console.WriteLine("start export");
4463
Data.Seek(data.Offset, SeekOrigin.Begin);
4564
using (BinaryReader reader = new BinaryReader(Data, Encoding.UTF8, true))
4665
{
47-
byte[] bytes = reader.ReadBytes(4);
48-
string fileFormat = Encoding.UTF8.GetString(bytes);
66+
int MAGIC = reader.ReadInt32();
67+
string fileFormat = ReverseString(Encoding.UTF8.GetString(BitConverter.GetBytes(MAGIC)));
68+
string fileName = data.Offset + "." + string.Concat(fileFormat.Split(Path.GetInvalidFileNameChars()));
69+
Console.WriteLine(fileName);
4970
reader.BaseStream.Seek(data.Offset, SeekOrigin.Begin);
50-
using (FileStream fs = File.Create(path + "." + ReverseString(fileFormat).Replace('\0', '.')))
71+
byte[] buffer = reader.ReadBytes((int)data.Length);
72+
reader.BaseStream.Seek(data.Offset, SeekOrigin.Begin);
73+
string finalPath = path + fileName;
74+
using (FileStream fs = File.Create(finalPath))
5175
{
5276
using (BinaryWriter writer = new BinaryWriter(fs))
5377
{
54-
reader.BaseStream.Seek(data.Offset, SeekOrigin.Begin);
55-
writer.BaseStream.Seek(0, SeekOrigin.Begin);
56-
while (reader.BaseStream.Position < data.Offset + 0x80)
78+
if (isZLIB(buffer))
79+
{
80+
Console.WriteLine(fileName + " is a zlib archive, extracting...");
81+
reader.BaseStream.Seek(data.Offset, SeekOrigin.Begin);
82+
ZLIB.Load(Data, writer.BaseStream);
83+
}
84+
else
5785
{
58-
// writer.Write(reader.ReadByte());
59-
reader.ReadByte();
86+
Console.WriteLine(fileName + " is an unknown file type, it will be exported as is");
87+
reader.BaseStream.Seek(data.Offset, SeekOrigin.Begin);
88+
writer.Write(reader.ReadBytes((int)data.Length));
6089
}
61-
// Array.Reverse(bytes);
62-
// writer.Write(bytes);
63-
ZLIB.Load(Data, writer.BaseStream);
6490
}
6591
}
6692
}
6793
}
6894

95+
96+
6997
public void Dispose()
7098
{
7199
Data.Dispose();

DeathEndFormats/Formats/GDAT/GDATFile.cs renamed to CoroHeartFormats/Formats/GDAT/GDATFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
namespace DeathEndFormats.Formats.GDAT
5+
namespace CoroHeart.Formats.GDAT
66
{
77
public class GDATFile
88
{

DeathEndFormats/Formats/ICanExtract.cs renamed to CoroHeartFormats/Formats/ICanExtract.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
namespace DeathEndFormats
5+
namespace CoroHeart
66
{
77
interface ICanExtract
88
{

DeathEndFormats/Formats/ZLIB.cs renamed to CoroHeartFormats/Formats/ZLIB.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
using System.IO;
55
using System.IO.Compression;
66

7-
namespace DeathEndFormats.Formats
7+
namespace CoroHeart.Formats
88
{
99
public class ZLIB
1010
{
1111
const string MAGIC = "BILZ";
1212

1313
public static void Load(Stream data, Stream output)
1414
{
15+
data.Seek(data.Position + 0x80, SeekOrigin.Begin);
16+
output.Seek(0, SeekOrigin.Begin);
17+
1518
BinaryReader reader = new BinaryReader(data, Encoding.UTF8, true);
1619
using (reader)
1720
{

DeathEndFormats/Tools.cs renamed to CoroHeartFormats/Tools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.IO;
55
using System.IO.Compression;
66

7-
namespace DeathEndFormats
7+
namespace CoroHeart
88
{
99
public static class Tools
1010
{

DeathEndToolkit.sln renamed to CoroHeartToolkit.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30002.166
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeathEndToolkit", "DeathEndToolkit\DeathEndToolkit.csproj", "{0DDAD26A-CCBC-48D8-A9EA-E3F15730FB28}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoroHeartToolkit", "CoroHeartToolkit\CoroHeartToolkit.csproj", "{0DDAD26A-CCBC-48D8-A9EA-E3F15730FB28}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeathEndFormats", "DeathEndFormats\DeathEndFormats.csproj", "{B95CC3AA-F7B8-4907-9775-E766BEE2215A}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoroHeartFormats", "CoroHeartFormats\CoroHeartFormats.csproj", "{B95CC3AA-F7B8-4907-9775-E766BEE2215A}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution

DeathEndToolkit/DeathEndToolkit.csproj renamed to CoroHeartToolkit/CoroHeartToolkit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<ProjectReference Include="..\DeathEndFormats\DeathEndFormats.csproj" />
9+
<ProjectReference Include="..\DeathEndFormats\CoroHeartFormats.csproj" />
1010
</ItemGroup>
1111

1212
</Project>

0 commit comments

Comments
 (0)