Skip to content

Commit

Permalink
add base to export json
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Sep 1, 2018
1 parent 2236046 commit 6ba40e5
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 29 deletions.
167 changes: 140 additions & 27 deletions HipHopFile/Functions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -135,14 +136,15 @@ public static void HipArrayToIni(HipSection[] hipFile, string unpackFolder, bool

StreamWriter INIWriter = new StreamWriter(new FileStream(fileName, FileMode.Create));
INIWriter.WriteLine("Game=" + currentGame.ToString());
INIWriter.WriteLine("IniVersion=1");

foreach (HipSection i in hipFile)
{
if (i is Section_PACK PACK)
{
INIWriter.WriteLine("PACK.PVER=" + PACK.PVER.subVersion.ToString() + "," + PACK.PVER.clientVersion.ToString() + "," + PACK.PVER.compatible.ToString());
INIWriter.WriteLine("PACK.PVER=" + PACK.PVER.subVersion.ToString() + v1s + PACK.PVER.clientVersion.ToString() + v1s + PACK.PVER.compatible.ToString());
INIWriter.WriteLine("PACK.PFLG=" + PACK.PFLG.flags.ToString());
INIWriter.WriteLine("PACK.PCRT=" + PACK.PCRT.fileDate.ToString() + "," + PACK.PCRT.dateString);
INIWriter.WriteLine("PACK.PCRT=" + PACK.PCRT.fileDate.ToString() + v1s + PACK.PCRT.dateString);
if (currentGame == Game.BFBB | currentGame == Game.Incredibles)
{
INIWriter.WriteLine("PACK.PLAT.Target=" + PACK.PLAT.TargetPlatform);
Expand All @@ -158,33 +160,17 @@ public static void HipArrayToIni(HipSection[] hipFile, string unpackFolder, bool
}
else if (i is Section_DICT DICT)
{
ExtractAssetsToFolders(unpackFolder, ref DICT, multiFolder);

INIWriter.WriteLine("DICT.ATOC.AINF=" + DICT.ATOC.AINF.value.ToString());
INIWriter.WriteLine("DICT.LTOC.LINF=" + DICT.LTOC.LINF.value.ToString());
INIWriter.WriteLine();

Dictionary<uint, string> AHDRDictionary = new Dictionary<uint, string>();

string directoryToUnpack = Path.Combine(unpackFolder, "files");


foreach (Section_AHDR AHDR in DICT.ATOC.AHDRList)
{
if (multiFolder)
directoryToUnpack = Path.Combine(unpackFolder, AHDR.assetType.ToString());

if (!Directory.Exists(directoryToUnpack))
Directory.CreateDirectory(directoryToUnpack);

string assetFileName = "[" + AHDR.assetID.ToString("X8") + "] " + AHDR.ADBG.assetName;

foreach (char c in Path.GetInvalidFileNameChars())
{
assetFileName = assetFileName.Replace(c, '_');
}

File.WriteAllBytes(Path.Combine(directoryToUnpack, assetFileName), AHDR.containedFile);
AHDRDictionary.Add(AHDR.assetID, AHDR.assetID.ToString("X8") + "," + AHDR.assetType + "," + ((uint)AHDR.flags).ToString() + "," + AHDR.ADBG.alignment.ToString() + "," + AHDR.ADBG.assetName + "," + AHDR.ADBG.assetFileName + "," + AHDR.ADBG.checksum.ToString("X8"));
}

AHDRDictionary.Add(AHDR.assetID, AHDR.assetID.ToString("X8") + v1s + AHDR.assetType + v1s + ((uint)AHDR.flags).ToString() + v1s + AHDR.ADBG.alignment.ToString() + v1s + AHDR.ADBG.assetName + v1s + AHDR.ADBG.assetFileName + v1s + AHDR.ADBG.checksum.ToString("X8"));

foreach (Section_LHDR LHDR in DICT.LTOC.LHDRList)
{
INIWriter.WriteLine("LayerType=" + (int)LHDR.layerType + " " + LHDR.layerType.ToString());
Expand All @@ -209,11 +195,133 @@ public static void HipArrayToIni(HipSection[] hipFile, string unpackFolder, bool
INIWriter.Close();
}

public static void HipArrayToJson(HipSection[] hipFile, string unpackFolder, bool multiFolder)
{
Directory.CreateDirectory(unpackFolder);

switch (currentGame)
{
case Game.Scooby:
SendMessage("Game: Scooby-Doo: Night of 100 Frights");
break;
case Game.Incredibles:
SendMessage("Game: The Incredibles, The Spongebob Squarepants Movie, or Rise of the Underminer");
break;
case Game.BFBB:
SendMessage("Game: Spongebob Squarepants: Battle For Bikini Bottom");
break;
default:
SendMessage("Error: Unknown game.");
break;
}

HipSerializer serializer = new HipSerializer()
{
currentGame = currentGame
};

foreach (HipSection i in hipFile)
{
if (i is Section_PACK PACK)
{
serializer.PACK_PVER_subVersion = PACK.PVER.subVersion;
serializer.PACK_PVER_clientVersion = PACK.PVER.clientVersion;
serializer.PACK_PVER_compatible = PACK.PVER.compatible;
serializer.PACK_PFLG_flags = PACK.PFLG.flags;
serializer.PACK_PCRT_fileDate = PACK.PCRT.fileDate;
serializer.PACK_PCRT_dateString = PACK.PCRT.dateString;

if (currentGame == Game.BFBB | currentGame == Game.Incredibles)
{
serializer.PACK_PLAT_TargetPlatform = PACK.PLAT.TargetPlatform;
serializer.PACK_PLAT_RegionFormat = PACK.PLAT.RegionFormat;
serializer.PACK_PLAT_Language = PACK.PLAT.Language;
serializer.PACK_PLAT_TargetGame = PACK.PLAT.TargetGame;

if (currentGame == Game.BFBB)
serializer.PACK_PLAT_TargetPlatformName = PACK.PLAT.TargetPlatformName;
}
else if (currentGame != Game.Scooby)
throw new Exception("Unknown game");
}
else if (i is Section_DICT DICT)
{
ExtractAssetsToFolders(unpackFolder, ref DICT, multiFolder);

serializer.DICT_ATOC_AINF_value = DICT.ATOC.AINF.value;
serializer.DICT_LTOC_LINF_value = DICT.LTOC.LINF.value;

Dictionary<uint, AssetSerializer> assetDictionary = new Dictionary<uint, AssetSerializer>();

foreach (Section_AHDR AHDR in DICT.ATOC.AHDRList)
assetDictionary.Add(AHDR.assetID, new AssetSerializer()
{
assetType = AHDR.assetType,
flags = AHDR.flags,
ADBG_alignment = AHDR.ADBG.alignment,
ADBG_assetName = AHDR.ADBG.assetName,
ADBG_assetFileName = AHDR.ADBG.assetFileName,
checksum = AHDR.ADBG.checksum
});

serializer.layers = new List<LayerSerializer>();
foreach (Section_LHDR LHDR in DICT.LTOC.LHDRList)
{
Dictionary<uint, AssetSerializer> assets = new Dictionary<uint, AssetSerializer>();

foreach (uint j in LHDR.assetIDlist)
assets.Add(j, assetDictionary[j]);

serializer.layers.Add(new LayerSerializer()
{
layerType = LHDR.layerType,
LHDR_LDBG_value = LHDR.LDBG.value,
assets = assets
});
}
}
else if (i is Section_STRM STRM)
{
serializer.SRTM_DHDR_value = STRM.DHDR.value;
serializer.SRTM_DPAK_firstPadding = STRM.DPAK.firstPadding;
}
}

File.WriteAllText(Path.Combine(unpackFolder, "Settings.json"), JsonConvert.SerializeObject(serializer, Formatting.Indented));
}

private static void ExtractAssetsToFolders(string unpackFolder, ref Section_DICT DICT, bool multiFolder)
{
string directoryToUnpack = Path.Combine(unpackFolder, "files");

foreach (Section_AHDR AHDR in DICT.ATOC.AHDRList)
{
if (multiFolder)
directoryToUnpack = Path.Combine(unpackFolder, AHDR.assetType.ToString());

if (!Directory.Exists(directoryToUnpack))
Directory.CreateDirectory(directoryToUnpack);

string assetFileName = "[" + AHDR.assetID.ToString("X8") + "] " + AHDR.ADBG.assetName;

foreach (char c in Path.GetInvalidFileNameChars())
{
assetFileName = assetFileName.Replace(c, '_');
}

File.WriteAllBytes(Path.Combine(directoryToUnpack, assetFileName), AHDR.containedFile);
}
}

private static readonly char v0s = ',';
private static readonly char v1s = ';';

public static HipSection[] IniToHipArray(string INIFile)
{
// Let's load the data from the INI first

string[] INI = File.ReadAllLines(INIFile);
char sep = v0s;

Section_HIPA HIPA = new Section_HIPA();

Expand All @@ -239,9 +347,14 @@ public static HipSection[] IniToHipArray(string INIFile)
{
SetGame(s.Split('=')[1]);
}
else if (s.StartsWith("IniVersion"))
{
if (Convert.ToInt32(s.Split('=')[1]) == 1)
sep = v1s;
}
else if (s.StartsWith("PACK.PVER"))
{
string[] j = s.Split('=')[1].Split(',');
string[] j = s.Split('=')[1].Split(sep);
PACK.PVER = new Section_PVER(Convert.ToInt32(j[0]), Convert.ToInt32(j[1]), Convert.ToInt32(j[2]));
}
else if (s.StartsWith("PACK.PFLG"))
Expand All @@ -250,7 +363,7 @@ public static HipSection[] IniToHipArray(string INIFile)
}
else if (s.StartsWith("PACK.PCRT"))
{
string[] j = s.Split('=')[1].Split(',');
string[] j = s.Split('=')[1].Split(sep);
PACK.PMOD = new Section_PMOD(Convert.ToInt32(j[0]));
PACK.PCRT = new Section_PCRT(Convert.ToInt32(j[0]), j[1]);
}
Expand Down Expand Up @@ -296,7 +409,7 @@ public static HipSection[] IniToHipArray(string INIFile)
}
else if (s.StartsWith("Asset="))
{
AddAsset(s.Split('=')[1].Split(','), ref assetIDlist, ref DICT);
AddAsset(s.Split('=')[1].Split(sep), ref assetIDlist, ref DICT);
}
else if (s.StartsWith("LHDR.LDBG"))
{
Expand Down
5 changes: 5 additions & 0 deletions HipHopFile/HipHopFile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="Functions.cs" />
<Compile Include="HipSerializer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sections\Enums\AHDRFlags.cs" />
<Compile Include="Sections\Enums\AssetType.cs" />
Expand Down Expand Up @@ -71,6 +75,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
48 changes: 48 additions & 0 deletions HipHopFile/HipSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;

namespace HipHopFile
{
public class AssetSerializer
{
public AssetType assetType;
public AHDRFlags flags;
public int ADBG_alignment;
public string ADBG_assetName;
public string ADBG_assetFileName;
public int checksum;
}

public class LayerSerializer
{
public LayerType layerType;
public int LHDR_LDBG_value;
public Dictionary<uint, AssetSerializer> assets;
}

public class HipSerializer
{
public Game currentGame;

public int PACK_PVER_subVersion;
public int PACK_PVER_clientVersion;
public int PACK_PVER_compatible;

public int PACK_PFLG_flags;

public int PACK_PCRT_fileDate;
public string PACK_PCRT_dateString;

public string PACK_PLAT_TargetPlatform;
public string PACK_PLAT_RegionFormat;
public string PACK_PLAT_Language;
public string PACK_PLAT_TargetGame;
public string PACK_PLAT_TargetPlatformName;

public int DICT_ATOC_AINF_value;
public int DICT_LTOC_LINF_value;
public List<LayerSerializer> layers;

public int SRTM_DHDR_value;
public int SRTM_DPAK_firstPadding;
}
}
4 changes: 4 additions & 0 deletions HipHopFile/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net40" />
</packages>
2 changes: 1 addition & 1 deletion HipHopTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void Main(string[] args)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

SendMessage("HipHopTool v0.4.4 by igorseabra4");
SendMessage("HipHopTool v0.4.5 by igorseabra4");

if (args.Length == 0)
ShowNoArgsMenu();
Expand Down
2 changes: 1 addition & 1 deletion HipHopTool/readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= HipHopTool v0.4.4 by igorseabra4 =
= HipHopTool v0.4.5 by igorseabra4 =
Tool to extract and create HIP/HOP archive files used in games by Heavy Iron Studios.

Currently supported games:
Expand Down

0 comments on commit 6ba40e5

Please sign in to comment.