From 2796f988221626a70ca06b2c732a28f687414fc7 Mon Sep 17 00:00:00 2001 From: igorseabra4 Date: Sun, 2 Sep 2018 22:36:45 -0300 Subject: [PATCH] fix crash when building file from command line --- HipHopFile/Functions.cs | 20 ++++++++++++++++++-- HipHopFile/Sections/Section_AHDR.cs | 9 +++++++++ HipHopTool/Program.cs | 2 +- HipHopTool/readme.txt | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/HipHopFile/Functions.cs b/HipHopFile/Functions.cs index d0b3bed..fab7172 100644 --- a/HipHopFile/Functions.cs +++ b/HipHopFile/Functions.cs @@ -35,7 +35,23 @@ public static float Switch(float a) byte[] b = BitConverter.GetBytes(a); return BitConverter.ToSingle(new byte[] { b[3], b[2], b[1], b[0] }, 0); } - + + public static uint BKDRHash(string str) + { + str = str.ToUpper(); + uint seed = 131; + uint hash = 0; + int length = str.Length; + + if (length > 31) + length = 31; + + for (int i = 0; i < length; i++) + hash = (hash * seed) + str[i]; + + return hash; + } + public static byte[] ReadContainedFile(BinaryReader binaryReader, int position, int lenght) { long savePosition = binaryReader.BaseStream.Position; @@ -480,7 +496,7 @@ public static HipSection[] SetupStream(ref Section_HIPA HIPA, ref Section_PACK P DICT.SetBytes(ref temporaryFile); - STRM.DPAK.data = new byte[0]; + STRM.DPAK = new Section_DPAK() { data = new byte[0] }; STRM.SetBytes(ref temporaryFile); // Create the new STRM stream. diff --git a/HipHopFile/Sections/Section_AHDR.cs b/HipHopFile/Sections/Section_AHDR.cs index 88f3489..13fc19b 100644 --- a/HipHopFile/Sections/Section_AHDR.cs +++ b/HipHopFile/Sections/Section_AHDR.cs @@ -45,6 +45,15 @@ public Section_AHDR(uint assetID, AssetType assetType, AHDRFlags flags, Section_ this.ADBG = ADBG; } + public Section_AHDR(uint assetID, AssetType assetType, AHDRFlags flags, Section_ADBG ADBG, byte[] data) + { + this.assetID = assetID; + this.assetType = assetType; + this.flags = flags; + this.ADBG = ADBG; + containedFile = data; + } + public Section_AHDR(BinaryReader binaryReader) { sectionName = Section.AHDR; diff --git a/HipHopTool/Program.cs b/HipHopTool/Program.cs index 5db83d4..e448058 100644 --- a/HipHopTool/Program.cs +++ b/HipHopTool/Program.cs @@ -12,7 +12,7 @@ static void Main(string[] args) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); - SendMessage("HipHopTool v0.4.5 by igorseabra4"); + SendMessage("HipHopTool v0.4.6 by igorseabra4"); if (args.Length == 0) ShowNoArgsMenu(); diff --git a/HipHopTool/readme.txt b/HipHopTool/readme.txt index a4b4ff4..6757dd1 100644 --- a/HipHopTool/readme.txt +++ b/HipHopTool/readme.txt @@ -1,4 +1,4 @@ -= HipHopTool v0.4.5 by igorseabra4 = += HipHopTool v0.4.6 by igorseabra4 = Tool to extract and create HIP/HOP archive files used in games by Heavy Iron Studios. Currently supported games: