From 13a6f1b24d2b0f2dc66bd2b6020ca0bdf47decd3 Mon Sep 17 00:00:00 2001
From: biwa <6475593+biwa@users.noreply.github.com>
Date: Sun, 21 May 2023 09:54:55 +0200
Subject: [PATCH] Added the Unity port IWADs (and some others) to the list of
known official IWADs
---
Source/Core/Builder.csproj | 1 +
Source/Core/BuilderMono.csproj | 1 +
Source/Core/General/Hasher.cs | 45 ++++++++++++++
Source/Core/IO/WAD.cs | 104 ++++++++++++++++++++-------------
4 files changed, 112 insertions(+), 39 deletions(-)
create mode 100644 Source/Core/General/Hasher.cs
diff --git a/Source/Core/Builder.csproj b/Source/Core/Builder.csproj
index 7da9bd22..ddd9b274 100644
--- a/Source/Core/Builder.csproj
+++ b/Source/Core/Builder.csproj
@@ -241,6 +241,7 @@
+
diff --git a/Source/Core/BuilderMono.csproj b/Source/Core/BuilderMono.csproj
index 4dd04cea..821e581b 100644
--- a/Source/Core/BuilderMono.csproj
+++ b/Source/Core/BuilderMono.csproj
@@ -233,6 +233,7 @@
+
diff --git a/Source/Core/General/Hasher.cs b/Source/Core/General/Hasher.cs
new file mode 100644
index 00000000..3a7d27a3
--- /dev/null
+++ b/Source/Core/General/Hasher.cs
@@ -0,0 +1,45 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace CodeImp.DoomBuilder
+{
+ public static class Hasher where T : HashAlgorithm
+ {
+ // We have to do it this ugly way because we can't directly call the method from the type and the "Create" method is overloaded
+ private static T hasher = (T)typeof(T).GetMethods().SingleOrDefault(m => m.Name == "Create" && m.GetParameters().Length == 0).Invoke(null, null);
+
+ public static string Get(Stream stream)
+ {
+ // Rewind the stream
+ stream.Position = 0;
+
+ // Check hash
+ byte[] data = hasher.ComputeHash(stream);
+
+ // Rewind the stream again...
+ stream.Position = 0;
+
+ // Create a new Stringbuilder to collect the bytes and create a string.
+ StringBuilder hash = new StringBuilder();
+
+ // Loop through each byte of the hashed data and format each one as a hexadecimal string.
+ for (int i = 0; i < data.Length; i++) hash.Append(data[i].ToString("x2"));
+
+ return hash.ToString();
+ }
+
+ ///
+ /// Computes the MD5 hash of a string.
+ ///
+ /// The string to compute the MD5 hash of
+ /// The MD5 hash as a string
+ public static string Get(string input)
+ {
+ byte[] bytes = hasher.ComputeHash(Encoding.ASCII.GetBytes(input));
+ return string.Concat(Array.ConvertAll(bytes, x => x.ToString("x2")));
+ }
+ }
+}
diff --git a/Source/Core/IO/WAD.cs b/Source/Core/IO/WAD.cs
index b5d5997c..43f4a76f 100755
--- a/Source/Core/IO/WAD.cs
+++ b/Source/Core/IO/WAD.cs
@@ -20,6 +20,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
+using System.Security.Cryptography;
#endregion
@@ -36,51 +37,75 @@ namespace CodeImp.DoomBuilder.IO
// Encoder
public static readonly Encoding ENCODING = Encoding.ASCII;
- //mxd. Official IWAD MD5 hashes
+ //mxd. Official IWAD SHA1 hashes
+ // Source of hashes: https://github.com/Doom-Utils/iwad-patches
private static readonly HashSet IWAD_HASHES = new HashSet
{
- ////// DOOM IWADS //////
- "d9153ced9fd5b898b36cc5844e35b520", // DOOM2 1.666g MD5
- "30e3c2d0350b67bfbf47271970b74b2f", // DOOM2 1.666 MD5
- "ea74a47a791fdef2e9f2ea8b8a9da13b", // DOOM2 1.7 MD5
- "d7a07e5d3f4625074312bc299d7ed33f", // DOOM2 1.7a MD5
- "c236745bb01d89bbb866c8fed81b6f8c", // DOOM2 1.8 MD5
- "25e1459ca71d321525f84628f45ca8cd", // DOOM2 1.9 MD5
- "3cb02349b3df649c86290907eed64e7b", // DOOM2 French MD5
- "c3bea40570c23e511a7ed3ebcd9865f7", // BFG DOOM2 MD5
+ // Doom 1
+ "df0040ccb29cc1622e74ceb3b7793a2304cca2c8", // Doom 1.1
+ "b5f86a559642a2b3bdfb8a75e91c8da97f057fe6", // Doom 1.2
+ "2e89b86859acd9fc1e552f587b710751efcffa8e", // Doom 1.666
+ "2c8212631b37f21ad06d18b5638c733a75e179ff", // Doom 1.8
+ "7742089b4468a736cadb659a7deca3320fe6dcbd", // Doom 1.9
+ "e5ec79505530e151ff0e6f517f3ce1fd65969c46", // Doom Bfg
+ "a89b39d91122882214c3088b8cd6b308713bd7c2", // Doom Ppc
+ "117015379c529573510be08cf59810aa10bb934e", // Doom Psn
+ "f770111ca9eb6d49aead51fcbd398719b462e64b", // Doom Unity 1.0
+ "08ab2507e1d525c4c06b6df4f6d5862568a6b009", // Doom Unity 1.1
+ "2a8a1ce0f29497a2781b2902c76115fd60d8bbf8", // Doom Unity 1.3
+ "9b07b02ab3c275a6a7570c3f73cc20d63a0e3833", // Doom Ud
+ "37de4510216eb3ce9a835dd939109443375d10c5", // Doom Xbla
+ "1d1d4f69fe14fa255228d8243470678b1b4efdc5", // Doom Xbox
- "981b03e6d1dc033301aa3095acc437ce", // DOOM 1.1 MD5
- "792fd1fea023d61210857089a7c1e351", // DOOM 1.2 MD5
- "464e3723a7e7f97039ac9fd057096adb", // DOOM 1.6b MD5
- "54978d12de87f162b9bcc011676cb3c0", // DOOM 1.666 MD5
- "11e1cd216801ea2657723abc86ecb01f", // DOOM 1.8 MD5
- "1cd63c5ddff1bf8ce844237f580e9cf3", // DOOM 1.9 MD5
- "fb35c4a5a9fd49ec29ab6e900572c524", // BFG DOOM MD5
+ // Doom 2
+ "a4ce5128d57cb129fdd1441c12b58245be55c8ce", // Doom2 1.666g
+ "6d559b7ceece4f5ad457415049711992370d520a", // Doom2 1.666
+ "70192b8d5aba65c7e633a7c7bcfe7e3e90640c97", // Doom2 1.7a
+ "78009057420b792eacff482021db6fe13b370dcc", // Doom2 1.7
+ "79c283b18e61b9a989cfd3e0f19a42ea98fda551", // Doom2 1.8
+ "d510c877031bbd5f3d198581a2c8651e09b9861f", // Doom2 1.8f
+ "7ec7652fcfce8ddc6e801839291f0e28ef1d5ae7", // Doom2 1.9
+ "a59548125f59f6aa1a41c22f615557d3dd2e85a9", // Doom2 Bfg
+ "f1b6ba94352d53f646b67c01d2da88c5c40e3179", // Doom2 Psn Eur
+ "ca8db908a7c9fbac764f34c148f0bcc78d18553e", // Doom2 Psn Usa
+ "9b39107b5bcfd1f989bcfe46f68dbc1f49222922", // Doom2 Unity 1.0
+ "b723882122e90b61a1d92a11dcfcf9cbf95a407e", // Doom2 Unity 1.1
+ "9574851209c9dfbede56db0dee0660ecd51e6150", // Doom2 Unity 1.3
+ "55e445badd63d8841ebea887910c26c62c7f525e", // Doom2 Xbla
+ "1c91d86cd8a2f3817227986503a6672a5e1613f0", // Doom2 Xbox
+ "b7ba1c68631023ea1aab1d7b9f7f6e9afc508f39", // Doom2 Xbox360bfg
+ "2cda310805397ae44059bbcaed3cd602f4864a82", // Doom2 Zodiac
- "c4fe9fd920207691a9f493668e0a2083", // ULTIMATE DOOM MD5
+ // Plutonia
+ "90361e2a538d2388506657252ae41aceeb1ba360", // Plutonia 1.9
+ "f131cbe1946d7fddb3caec4aa258c83399c21e60", // Plutonia Anthology
+ "85c3517434135a5886111b324955f9288c01046c", // Plutonia Psn Eur
+ "327f8c41ebd4138354e9fca63cebbbd1b9489749", // Plutonia Psn Usa
+ "54e27b5791fbc5677bf7e83c1de3a92ea3ef935b", // Plutonia Unity 1.0
+ "20fd23ee410c466b263a741bbd53bbef573ab47d", // Plutonia Unity 1.3
- "75c8cf89566741fa9d22447604053bd7", // PLUTONIA MD5
- "3493be7e1e2588bc9c8b31eab2587a04", // PLUTONIA RARE MD5
+ // TNT
+ "9fbc66aedef7fe3bae0986cdb9323d2b8db4c9d3", // Tnt 1.9
+ "4a65c8b960225505187c36040b41a40b152f8f3e", // Tnt Anthology
+ "5066833da047117241cdda05a708b009eb266c91", // Tnt Psn Eur
+ "139e26d801a64b404b8d898defca10227a61867b", // Tnt Psn Usa
+ "503271390606ebded04a2cfaa1a4e249c0313a9d", // Tnt Unity 1.0
+ "ca0f0495a6c2813b49620202774c56560d6d7621", // Tnt Unity 1.3
- "4e158d9953c79ccf97bd0663244cc6b6", // TNT MD5
- "1d39e405bf6ee3df69a8d2646c8d5c49", // TNT Fixed MD5
- "be626c12b7c9d94b1dfb9c327566b4ff", // PSN TNT MD5
+ // Heretic
+ "b5a6cc79cde48d97905b44282e82c4c966a23a87", // Heretic 1.0
+ "a54c5d30629976a649119c5ce8babae2ddfb1a60", // Heretic 1.2
+ "f489d479371df32f6d280a0cb23b59a35ba2b833", // Heretic 1.3
- ////// HERETIC IWADS //////
- "3117e399cdb4298eaa3941625f4b2923", // HERETIC 1.0 MD5
- "1e4cb4ef075ad344dd63971637307e04", // HERETIC 1.2 MD5
- "66d686b1ed6d35ff103f15dbd30e0341", // HERETIC 1.3 MD5
+ // Hexen
+ "ae797f5fdce845be24a7a24dd5bfc3e762a17bbe", // Hexen Beta
+ "ac129c4331bf26f0f080c4a56aaa40d64969c98a", // Hexen 1.0
+ "4b53832f0733c1e29e5f1de2428e5475e891af29", // Hexen 1.1
+ "4343fbe5aef905ef6d077a1517a50c919e5cc906", // Hexen Mac
- ////// HEXEN IWADS //////
- "c88a2bb3d783e2ad7b599a8e301e099e", // HEXEN Beta MD5
- "b2543a03521365261d0a0f74d5dd90f0", // HEXEN 1.0 MD5
- "abb033caf81e26f12a2103e1fa25453f", // HEXEN 1.1 MD5
- "1077432e2690d390c256ac908b5f4efa", // HEXEN DK 1.0 MD5
- "78d5898e99e220e4de64edaa0e479593", // HEXEN DK 1.1 MD5
-
- ////// STRIFE IWADS //////
- "8f2d3a6a289f5d2f2f9c1eec02b47299", // STRIFE 1.0 MD5
- "2fed2031a5b03892106e0f117f17901f", // STRIFE 1.2 MD5
+ // Strife
+ "eb0f3e157b35c34d5a598701f775e789ec85b4ae", // Strife1 1.1
+ "64c13b951a845ca7f8081f68138a6181557458d1", // Strife1 1.2
};
#endregion
@@ -334,8 +359,9 @@ namespace CodeImp.DoomBuilder.IO
{
// Rewind
r.BaseStream.Position = 0;
- isofficialiwad = IWAD_HASHES.Contains(MD5Hash.Get(r.BaseStream));
- if(!isreadonly && isofficialiwad) isreadonly = true;
+ //isofficialiwad = IWAD_HASHES.Contains(MD5Hash.Get(r.BaseStream));
+ isofficialiwad = IWAD_HASHES.Contains(Hasher.Get(r.BaseStream));
+ if (!isreadonly && isofficialiwad) isreadonly = true;
}
// Close the reader