This repository has been archived by the owner on Apr 15, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Super hacky BLS reader changes, good thing nothing uses it!
- Loading branch information
Showing
5 changed files
with
208 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,154 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.IO; | ||
using WoWFormatLib.DBC; | ||
using WoWFormatLib.FileReaders; | ||
using WoWFormatLib.Utils; | ||
using System.Security.Cryptography; | ||
using WoWFormatLib; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
|
||
namespace WoWFormatLib | ||
namespace WoWFormatTest | ||
{ | ||
internal class Program | ||
{ | ||
private static Dictionary<string, List<byte>> preShaderMD5Total = new Dictionary<string, List<byte>>(); | ||
private static Dictionary<string, List<byte>> postShaderMD5Total = new Dictionary<string, List<byte>>(); | ||
|
||
private static void Main(string[] args) | ||
{ | ||
CASC.InitCasc(null, null, "wowt", CASCLib.LocaleFlags.enUS); | ||
|
||
if (!File.Exists("listfile.txt")) | ||
var reader = new BLSReader(); | ||
//reader.LoadBLS(File.OpenRead(@"D:\shaders\shaders_30093\unknown\\FILEDATA_1106926.bls")); | ||
//File.WriteAllBytes("out.bin", reader.targetStream.ToArray()); | ||
foreach (var file in Directory.GetFiles(@"D:\shaders\shaders_30093\unknown", "*.bls", SearchOption.AllDirectories)) | ||
{ | ||
throw new Exception("Listfile not found!"); | ||
try | ||
{ | ||
reader.LoadBLS(File.OpenRead(file)); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine("Error loading shader " + file + ": " + e.Message); | ||
Console.ResetColor(); | ||
continue; | ||
} | ||
var cleanName = file; | ||
for (var i = 0; i < reader.shaderFile.decompressedBlocks.Count; i++) | ||
{ | ||
using (var md5 = MD5.Create()) | ||
{ | ||
var rawhash = md5.ComputeHash(reader.shaderFile.decompressedBlocks[i]); | ||
if (!preShaderMD5Total.ContainsKey(cleanName)) | ||
{ | ||
preShaderMD5Total.Add(cleanName, new List<byte>()); | ||
} | ||
|
||
preShaderMD5Total[cleanName].AddRange(rawhash); | ||
} | ||
} | ||
} | ||
|
||
foreach (var line in File.ReadAllLines("listfile.txt")) | ||
var finalMD5Dict = new Dictionary<string, string>(); | ||
foreach(var shader in preShaderMD5Total) | ||
{ | ||
if (line.EndsWith(".wdt", StringComparison.CurrentCultureIgnoreCase) && !line.Contains("_mpv") && !line.Contains("_fogs") && !line.Contains("_occ") && !line.Contains("_lgt")) | ||
using (var md5 = MD5.Create()) | ||
{ | ||
if (!CASC.FileExists(line)) | ||
continue; | ||
|
||
var reader = new WDTReader(); | ||
reader.LoadWDT(line); | ||
|
||
if(reader.wdtfile.filedataids == null) | ||
var finalHash = md5.ComputeHash(shader.Value.ToArray()).ToHexString(); | ||
if (finalMD5Dict.ContainsKey(finalHash)) | ||
{ | ||
Console.WriteLine(shader.Key + " has the same internal shaders as " + finalMD5Dict[finalHash]); | ||
} | ||
else | ||
{ | ||
Console.WriteLine(line + " does not have MAID chunk"); | ||
continue; | ||
finalMD5Dict.Add(finalHash, shader.Key); | ||
} | ||
} | ||
} | ||
|
||
foreach (var file in Directory.GetFiles(@"D:\shaders\shaders_30096\unknown", "*.bls", SearchOption.AllDirectories)) | ||
{ | ||
try | ||
{ | ||
reader.LoadBLS(File.OpenRead(file)); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine("Error loading shader " + file + ": " + e.Message); | ||
Console.ResetColor(); | ||
continue; | ||
} | ||
|
||
foreach(var filedataids in reader.wdtfile.filedataids) | ||
var cleanName = file; | ||
for (var i = 0; i < reader.shaderFile.decompressedBlocks.Count; i++) | ||
{ | ||
using (var md5 = MD5.Create()) | ||
{ | ||
if (filedataids.rootADT != 0) | ||
var rawhash = md5.ComputeHash(reader.shaderFile.decompressedBlocks[i]); | ||
if (!postShaderMD5Total.ContainsKey(cleanName)) | ||
{ | ||
Console.WriteLine(line + " " + filedataids.rootADT); | ||
postShaderMD5Total.Add(cleanName, new List<byte>()); | ||
} | ||
|
||
postShaderMD5Total[cleanName].AddRange(rawhash); | ||
} | ||
} | ||
} | ||
|
||
if (File.Exists("matches.txt")) | ||
{ | ||
File.Delete("matches.txt"); | ||
} | ||
|
||
var matches = new List<string>(); | ||
Console.ForegroundColor = ConsoleColor.DarkGreen; | ||
var preShaderCopy = finalMD5Dict.Values.ToList(); | ||
var postShaderCopy = postShaderMD5Total.Keys.ToList(); | ||
foreach (var shader in postShaderMD5Total) | ||
{ | ||
using (var md5 = MD5.Create()) | ||
{ | ||
var finalHash = md5.ComputeHash(shader.Value.ToArray()).ToHexString(); | ||
if (finalMD5Dict.ContainsKey(finalHash)) | ||
{ | ||
matches.Add(Path.GetFileNameWithoutExtension(shader.Key).Replace("FILEDATA_", "") + ";" + Path.GetFileNameWithoutExtension(finalMD5Dict[finalHash]).Replace("FILEDATA_", "")); | ||
preShaderCopy.Remove(finalMD5Dict[finalHash]); | ||
postShaderCopy.Remove(shader.Key); | ||
} | ||
} | ||
} | ||
|
||
File.WriteAllLines("matches.txt", matches.ToArray()); | ||
File.WriteAllLines("leftovers-pre.txt", preShaderCopy.ToArray()); | ||
File.WriteAllLines("leftovers-post.txt", postShaderCopy.ToArray()); | ||
|
||
/* | ||
var preShaderCount = new Dictionary<string, string>(); | ||
foreach (var shader in File.ReadAllLines("leftovers-pre.txt")) | ||
{ | ||
reader.LoadBLS(File.OpenRead(shader)); | ||
preShaderCount.Add(shader, reader.shaderFile.nShaders + "-" + reader.shaderFile.nCompressedChunks + "-" + reader.shaderFile.decompressedBlocks[0].Length); | ||
} | ||
//{[D:\shaders\shaders_30093\unknown\FILEDATA_1139694.bls, 126-74-8473] | ||
//{[D:\shaders\shaders_30096\unknown\FILEDATA_2976993.bls, 126-74-6320]} | ||
//{[D:\shaders\shaders_30093\unknown\FILEDATA_1316520.bls, 1440-595-8441]} | ||
//{[D:\shaders\shaders_30096\unknown\FILEDATA_2977492.bls, 1440-596-8461]} | ||
//{[D:\shaders\shaders_30093\unknown\FILEDATA_1316520.bls, 1440-595-8441]} | ||
//{[D:\shaders\shaders_30096\unknown\FILEDATA_2977492.bls, 1440-596-8461] | ||
//{[D:\shaders\shaders_30096\unknown\FILEDATA_2976993.bls, 126-74-6320] | ||
var postShaderCount = new Dictionary<string, string>(); | ||
foreach (var shader in File.ReadAllLines("leftovers-post.txt")) | ||
{ | ||
reader.LoadBLS(File.OpenRead(shader)); | ||
postShaderCount.Add(shader, reader.shaderFile.nShaders + "-" + reader.shaderFile.nCompressedChunks + "-" + reader.shaderFile.decompressedBlocks[0].Length); | ||
} | ||
*/ | ||
//{[D:\shaders\shaders_30093\unknown\FILEDATA_1139630.bls, 640-287-8857] | ||
//{[D:\shaders\shaders_30096\unknown\FILEDATA_2977414.bls, 640-287-1] | ||
|
||
} | ||
} | ||
} |