Skip to content

Commit

Permalink
Initial support for reach hoppers.
Browse files Browse the repository at this point in the history
  • Loading branch information
craftycodie committed Jul 27, 2024
1 parent 013c282 commit 4c92ef4
Show file tree
Hide file tree
Showing 7 changed files with 763 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private void RegisterChunks()
RegisterChunk<MatchmakingBanhammerMessages>();
RegisterChunk<MatchmakingHopperDescriptions3>();
RegisterChunk<MapManifest>();
RegisterChunk<HopperConfigurationTable27>();
}

public override string GetVersion()
Expand Down
4 changes: 2 additions & 2 deletions WarthogInc/BlfChunks/HopperConfigurationTable11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ public void WriteChunk(ref BitStream<StreamByteStream> hoppersStream)
hoppersStream.Write<byte>(configuration.imageIndex, 6);
hoppersStream.Write<byte>(configuration.xLastIndex, 5);
hoppersStream.Write<ushort>(configuration.richPresenceId, 16);
hoppersStream.Write<ulong>(configuration.startTime, 64);
hoppersStream.Write<ulong>(configuration.endTime, 64);
hoppersStream.WriteLong(configuration.startTime, 64);
hoppersStream.WriteLong(configuration.endTime, 64);
hoppersStream.Write<uint>(configuration.regions, 32);
hoppersStream.Write<uint>(configuration.minimumBaseXp, 17);
hoppersStream.Write<uint>(configuration.maximumBaseXp, 17);
Expand Down
565 changes: 565 additions & 0 deletions WarthogInc/BlfChunks/HopperConfigurationTable27.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions WarthogInc/SunriseBlfTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Sewer56.BitStream" Version="1.2.1" />
<PackageReference Include="ZLibDotNet" Version="0.1.1" />
</ItemGroup>
</Project>
176 changes: 176 additions & 0 deletions WarthogInc/TitleConverters/HaloReach/TitleConverter_11860.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using SunriseBlfTool;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SunriseBlfTool.BlfChunks.ChunkNameMaps;

namespace SunriseBlfTool.TitleConverters.HaloReach
{
public class TitleConverter_11860 : ITitleConverter
{
private static readonly AbstractBlfChunkNameMap chunkNameMap = new BlfChunks.ChunkNameMaps.HaloReach.BlfChunkNameMap_12065();
public void ConvertBlfToJson(string blfFolder, string jsonFolder)
{
Console.WriteLine("Converting BLF files to JSON...");

var titleDirectoryEnumerator = Directory.EnumerateFiles(blfFolder, "*.*", SearchOption.AllDirectories).GetEnumerator();

while (titleDirectoryEnumerator.MoveNext())
{
// We remake the manifest on conversion back to BLF.
if (titleDirectoryEnumerator.Current.EndsWith("manifest_001.bin"))
continue;

string fileRelativePath = titleDirectoryEnumerator.Current.Replace(blfFolder, "");
if (fileRelativePath.Contains("\\"))
{
string fileDirectoryRelativePath = fileRelativePath.Substring(0, fileRelativePath.LastIndexOf("\\"));
Directory.CreateDirectory(jsonFolder + fileDirectoryRelativePath);
}

if (titleDirectoryEnumerator.Current.EndsWith(".bin")
|| titleDirectoryEnumerator.Current.EndsWith(".mvar")
|| titleDirectoryEnumerator.Current.EndsWith(".blf")
|| !titleDirectoryEnumerator.Current.Contains('.')
)
{
Console.WriteLine("Converting file: " + fileRelativePath);

try
{
BlfFile blfFile = new BlfFile();
blfFile.ReadFile(titleDirectoryEnumerator.Current, chunkNameMap);
string output = blfFile.ToJSON();

File.WriteAllText(jsonFolder + fileRelativePath.Replace(".bin", "").Replace(".mvar", "").Replace(".blf", "") + ".json", output);
Console.WriteLine("Converted file: " + fileRelativePath);
}
catch (Exception ex)
{
Console.WriteLine("Failed to convert file: " + titleDirectoryEnumerator.Current);
Console.WriteLine(ex.Message);
//File.Copy(titleDirectoryEnumerator.Current, jsonFolder + fileRelativePath, true);
}
}
else if (titleDirectoryEnumerator.Current.EndsWith(".jpg"))
{
if (titleDirectoryEnumerator.Current.Equals(jsonFolder + fileRelativePath))
continue;
File.Copy(titleDirectoryEnumerator.Current, jsonFolder + fileRelativePath, true);
}
}
}

public string GetVersion()
{
return "reach_11860";
}

public void ConvertJsonToBlf(string jsonFolder, string blfFolder)
{
jsonFolder += "\\";
blfFolder += "\\";

Console.WriteLine("Converting JSON files to BLF...");

var hoppersFolderEnumerator = Directory.EnumerateDirectories(jsonFolder, "*", SearchOption.TopDirectoryOnly).GetEnumerator();

while (hoppersFolderEnumerator.MoveNext())
{
var hopperFolder = hoppersFolderEnumerator.Current;
var hopperFolderName = hopperFolder.Substring(hopperFolder.LastIndexOf("\\") + 1);

Console.WriteLine("Converting " + hopperFolderName);

var jsonFileEnumerator = Directory.EnumerateFiles(hopperFolder, "*.*", SearchOption.AllDirectories).GetEnumerator();

var fileHashes = new Dictionary<string, byte[]>();

while (jsonFileEnumerator.MoveNext())
{
string fileName = jsonFileEnumerator.Current;
if (fileName.Contains("\\"))
fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);

string fileRelativePath = jsonFileEnumerator.Current.Replace(jsonFolder, "");
string fileDirectoryRelativePath;
if (fileRelativePath.Contains("\\"))
{
fileDirectoryRelativePath = fileRelativePath.Substring(0, fileRelativePath.LastIndexOf("\\"));
Directory.CreateDirectory(blfFolder + fileDirectoryRelativePath);
}

if (fileName.EndsWith(".bin") || fileName.EndsWith(".jpg"))
{
File.Copy(jsonFileEnumerator.Current, blfFolder + fileRelativePath, true);
Console.WriteLine("Copied file: " + fileRelativePath);

continue;
}

try
{
BlfFile blfFile = BlfFile.FromJSON(File.ReadAllText(jsonFileEnumerator.Current), chunkNameMap);

blfFile.WriteFile(blfFolder + fileRelativePath.Replace(".json", ".bin"));

Console.WriteLine("Converted file: " + fileRelativePath);

if (blfFile.HasChunk<MatchmakingHopperDescriptions3>()
|| blfFile.HasChunk<MatchmakingTips>()
|| blfFile.HasChunk<MapManifest>()
|| blfFile.HasChunk<MatchmakingBanhammerMessages>())
{
fileHashes.Add("/title/default_hoppers/" + fileRelativePath.Replace("\\", "/").Replace(".json", ".bin"), BlfFile.ComputeHash(blfFolder + fileRelativePath.Replace(".json", ".bin")));
}
}
catch (Exception ex)
{
Console.WriteLine("FAILED TO CONVERT FILE " + fileRelativePath);
}
}

fileHashes.Add("/dlc_map_manifest.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\dlc_map_manifest.bin"));
fileHashes.Add("/matchmaking_hopper_027.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\matchmaking_hopper_027.bin"));
fileHashes.Add("/network_configuration_241.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\network_configuration_241.bin"));
//fileHashes.Add("/network_configuration_245.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\network_configuration_245.bin"));
fileHashes.Add("/en/file_megalo_categories.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\en\\file_megalo_categories.bin"));
fileHashes.Add("/en/file_predefined_queries.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\en\\file_predefined_queries.bin"));
//fileHashes.Add("/en/matchmaking_banhammer_messages.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\en\\matchmaking_banhammer_messages.bin"));
//fileHashes.Add("/en/matchmaking_hopper_descriptions_003.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\en\\matchmaking_hopper_descriptions_003.bin"));
//fileHashes.Add("/en/matchmaking_tips.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\en\\matchmaking_tips.bin"));
fileHashes.Add("/en/rsa_manifest.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\en\\rsa_manifest.bin"));
fileHashes.Add("/00102/images/hopper.jpg/", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\00102\\images\\hopper.jpg"));
//fileHashes.Add("/00104/images/hopper.jpg/", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\00104\\images\\hopper.jpg"));

Manifest.FileEntry[] fileEntries = new Manifest.FileEntry[fileHashes.Count];
int i = 0;
foreach (KeyValuePair<string, byte[]> fileNameHash in fileHashes)
{
fileEntries[i] = new Manifest.FileEntry()
{
filePath = fileNameHash.Key,
fileHash = fileNameHash.Value
};
i++;
}

var onfm = new Manifest()
{
files = fileEntries
};

BlfFile manifestFile = new BlfFile();
manifestFile.AddChunk(onfm);
manifestFile.WriteFile(blfFolder + "\\default_hoppers\\manifest_001.bin");

Console.WriteLine(blfFolder + "\\default_hoppers\\manifest_001.bin");

Console.WriteLine("Created file: manifest_001.bin");
}
}
}
}
17 changes: 17 additions & 0 deletions WarthogInc/TitleConverters/HaloReach/TitleConverter_12065.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public void ConvertJsonToBlf(string jsonFolder, string blfFolder)
continue;
}

if (fileName == "matchmaking_hopper_027.json")
continue; // Handle manually, after game sets.

try
{
BlfFile blfFile = BlfFile.FromJSON(File.ReadAllText(jsonFileEnumerator.Current), chunkNameMap);
Expand All @@ -133,6 +136,20 @@ public void ConvertJsonToBlf(string jsonFolder, string blfFolder)
}
}

var hopperConfigurationTableBlfFile = BlfFile.FromJSON(File.ReadAllText(jsonFolder + $"{hopperFolderName}\\matchmaking_hopper_027.json"), chunkNameMap);
var mhcf = hopperConfigurationTableBlfFile.GetChunk<HopperConfigurationTable27>();

//We need to calculate the hash of every gameset.
foreach (HopperConfigurationTable27.HopperConfiguration hopperConfiguration in mhcf.configurations)
{
hopperConfiguration.gameSetHash = BlfFile.ComputeHash(blfFolder + $"\\{hopperFolderName}\\" + hopperConfiguration.identifier.ToString("D5") + "\\game_set_015.bin");
}
BlfFile hoppersFile = new BlfFile();
hoppersFile.AddChunk(mhcf);
hoppersFile.WriteFile(blfFolder + $"\\{hopperFolderName}\\matchmaking_hopper_027.bin");

Console.WriteLine($"Converted file: {hopperFolderName}\\matchmaking_hopper_027.json");

fileHashes.Add("/dlc_map_manifest.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\dlc_map_manifest.bin"));
fileHashes.Add("/matchmaking_hopper_027.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\matchmaking_hopper_027.bin"));
fileHashes.Add("/network_configuration_241.bin", BlfFile.ComputeHash(blfFolder + "\\default_hoppers\\network_configuration_241.bin"));
Expand Down
1 change: 1 addition & 0 deletions WarthogInc/TitleConverters/TitleConverterVersionMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void RegisterTitles()
RegisterTitle<Halo3.TitleConverter_12065>();
RegisterTitle<Halo3.TitleConverter_12070>();
RegisterTitle<Halo3ODST.TitleConverter_13895>();
RegisterTitle<HaloReach.TitleConverter_11860>();
RegisterTitle<HaloReach.TitleConverter_12065>();
RegisterTitle<HaloOnline.TitleConverter_106708>();
}
Expand Down

0 comments on commit 4c92ef4

Please sign in to comment.