Skip to content

Commit 02e6151

Browse files
committed
Added the ability to export complete directories and fixed a bug of identification of csh files
1 parent 527c845 commit 02e6151

File tree

6 files changed

+62
-22
lines changed

6 files changed

+62
-22
lines changed

CoroHeartFormats/Formats/CSH/CSH.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ namespace CoroHeart.Formats.CSH
77
{
88
public class CSH
99
{
10-
const int MAGIC = 0x00687363;
10+
const string MAGIC = "\0hsc";
11+
12+
static public bool isCSH(Stream data)
13+
{
14+
byte[] buffer = new byte[4];
15+
data.Read(buffer, 0, 4);
16+
data.Seek(0, SeekOrigin.Begin);
17+
int value =BitConverter.ToInt32(buffer,0);
18+
byte[] magicBytes = Encoding.UTF8.GetBytes(MAGIC);
19+
return value == BitConverter.ToInt32(magicBytes,0);
20+
}
1121

1222
static public void Load(Stream data, Stream output)
1323
{
@@ -17,17 +27,8 @@ static public void Load(Stream data, Stream output)
1727
{
1828
using (writer)
1929
{
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-
}
30+
reader.BaseStream.Seek(0, SeekOrigin.Begin);
31+
writer.BaseStream.Seek(0, SeekOrigin.Begin);
3132
ZLIB.Load(reader.BaseStream, writer.BaseStream);
3233
}
3334
}

CoroHeartFormats/Formats/GDAT/GDAT.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ namespace CoroHeart.Formats.GDAT
66
{
77
public class GDAT : IDisposable
88
{
9+
public static bool isGDAT(Stream data)
10+
{
11+
byte[] buffer = new byte[4];
12+
data.Read(buffer, 0, 4);
13+
data.Seek(0, SeekOrigin.Begin);
14+
int value = BitConverter.ToInt32(buffer, 0);
15+
byte[] magicBytes = Encoding.UTF8.GetBytes(MAGIC);
16+
return value == BitConverter.ToInt32(magicBytes, 0);
17+
}
918
public static GDAT Load(Stream data)
1019
{
1120
GDAT GDatData = new GDAT();

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\CoroHeartFormats.csproj" />
9+
<ProjectReference Include="..\CoroHeartFormats\CoroHeartFormats.csproj" />
1010
</ItemGroup>
1111

1212
</Project>

CoroHeartToolkit/Program.cs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,45 @@ static void Main(string[] args)
1111
{
1212
if (args.Length < 1)
1313
{
14-
Console.WriteLine("Drag and drop your .csh or your .dat on DeathEndToolkit.exe then try again !");
14+
Console.WriteLine("Drag and drop your .csh or your .dat on CoroHeartToolkit.exe to extract them !");
1515
Console.ReadLine();
1616
return;
1717
}
18-
foreach (string FileName in args)
18+
string[] files = null;
19+
if (Directory.Exists(args[0]))
20+
{
21+
files = Directory.GetFiles(args[0]);
22+
}
23+
else
24+
{
25+
files = args;
26+
}
27+
foreach (string FileName in files)
1928
{
2029
FileStream file = File.OpenRead(FileName);
30+
Console.WriteLine("Opening " + FileName);
2131
using (file)
2232
{
23-
if (FileName.EndsWith(".csh"))
33+
if (CSH.isCSH(file))
2434
{
25-
FileStream outputFile = File.Create(FileName + ".extracted");
35+
DirectoryInfo info = Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\" + Path.GetFileNameWithoutExtension(FileName));
36+
FileStream outputFile = File.Create(info.FullName + "\\" + Path.GetFileName(FileName) + ".extracted");
2637
using (outputFile)
2738
{
28-
CSH.Load(file, outputFile);
39+
try
40+
{
41+
CSH.Load(file, outputFile);
42+
Console.WriteLine(FileName + " Exported successfully !");
43+
}
44+
catch (Exception ex)
45+
{
46+
Console.WriteLine("An exception occurred while loading " + FileName + " contact SeleDreams to determine what happened.");
47+
Console.WriteLine(ex.GetType().Name + " : " + ex.Message);
48+
}
49+
2950
}
3051
}
31-
else if (FileName.EndsWith(".dat"))
52+
else if (GDAT.isGDAT(file))
3253
{
3354
using (GDAT gdat = GDAT.Load(file))
3455
{
@@ -62,11 +83,12 @@ static void Main(string[] args)
6283
}
6384
else
6485
{
65-
Console.WriteLine("Incorrect argument, the valid file types are .dat and .csh");
86+
Console.WriteLine("Incorrect file, the valid file types are .dat and .csh");
6687
}
6788
}
68-
Console.ReadLine();
6989
}
90+
Console.WriteLine("All files finished extracting !");
91+
Console.ReadLine();
7092
}
7193
}
7294
}

CoroHeartToolkit/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"DeathEndToolkit": {
44
"commandName": "Project",
5-
"commandLineArgs": "\"D:\\Games\\steamapps\\common\\Megadimension Neptunia VIIR\\resource\\masterWin64\\GxArchivedFile002.dat\""
5+
"commandLineArgs": "\"D:\\Games\\steamapps\\common\\Megadimension Neptunia VIIR\\resource\\masterWin64\\GxArchivedTable052.csh\""
66
}
77
}
88
}

README.MD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# CoroHeartToolkit
2+
CoroHeart toolkit is a tool that allows to export assets from games from Compile Hearts made with the Orochi Engine such as Death End Re;Quest and Megadimension Neptunia VIIR
3+
4+
# Usage
5+
To use it, you need the .net core runtime, you can download it here :
6+
https://dotnet.microsoft.com/download/dotnet-core/current/runtime
7+
8+
once installed, just drag and drop the .dat and .csh files you want to extract or a directory containing them on the executable and it will extract them in their respective directories

0 commit comments

Comments
 (0)