// First pass over texture bundles, collect texture path data private static Dictionary <long, string> LoadTextureInfo(List <string> textureFiles) { var textureRefs = new Dictionary <long, string>(); foreach (var file in textureFiles) { AssestFile af = new AssestFile(file); foreach (var obj in af.Objects) { var unityClass = (UnityClass)obj.Info.ClassId; // only interested in AssetBundle class, on this pass to collect refs if (unityClass == UnityClass.AssetBundle) { var data = BinaryBlock.Create(obj.Buffer); var ab = new AssetBundle(data); foreach (var kp in ab.Container) { var text = kp.Key; var id = kp.Value.PathID; if (!textureRefs.ContainsKey(id)) { textureRefs[id] = text; } else { Logger.Log("Path entry duplicated: " + text + " (" + id + ")"); } } } } } Logger.Log("{0} tex refs found.", textureRefs.Count); return(textureRefs); }
// Load a simple card db from "cardxml0.unity3d" private static void LoadCardDb(string outDir) { // Extract card xml files var cardXml = Path.Combine(_hsDataPath, "cardxml0.unity3d"); if (File.Exists(cardXml)) { AssestFile xmlBundle = new AssestFile(cardXml); var extractor = new TextExtractor(); foreach (var obj in xmlBundle.Objects) { extractor.Extract(obj, outDir); } // Create cardDB from english xml var xmlFile = Path.Combine(outDir, "TextAsset", "enUS.txt"); if (File.Exists(xmlFile)) { CardDb.Read(xmlFile); Logger.Log("CardDB loaded: {0} cards", CardDb.All.Count); Logger.Log("CardDB loaded: {0} cards (filtered)", CardDb.Filtered.Count); } else { Logger.Log(LogLevel.ERROR, "Card XML file not extracted: {0}", xmlFile); } } else { Logger.Log(LogLevel.ERROR, "{0} does not exist.", cardXml); } }
public static void ClassInitialize(TestContext context) { var file = @".\Data\bundle_5.1.unity3d"; var abr = new AssestFile(file); _tree = abr.TypeTree; }
public static void ClassInitialize(TestContext context) { var file = @".\Data\bundle_5.1.unity3d"; var abr = new AssestFile(file); _header = abr.Header; }
public static void ClassInitialize(TestContext context) { var file = @".\Data\bundle_5.3_fs.unity3d"; var abr = new AssestFile(file); _info = abr.InfoTable; }
public static void ClassInitialize(TestContext context) { var file = @".\Data\bundle_5.1.unity3d"; var abr = new AssestFile(file); _entry = abr.BundleEntry; }
private void BuildReferences(AssestFile bundle) { foreach (var obj in bundle.Objects) { var unityClass = (UnityClass)obj.Info.ClassId; var data = BinaryBlock.Create(obj.Buffer); switch (unityClass) { case UnityClass.GameObject: _gameObjects[obj.Id] = new GameObject(data); break; case UnityClass.MonoBehaviour: // In this bundle, its a HS CardDef, SoundDef, HiddenCard var cd = new CardDef(data); if (!cd.FailedToLoad) // only want carddef (Hack) { _cardDefObjects[obj.Id] = cd; } break; case UnityClass.Material: _materialObjects[obj.Id] = new GameMaterial(data); break; default: break; } } }
public CardsBundle(List <string> bundles) : this() { // get all card objects over all files foreach (var file in bundles) { var af = new AssestFile(file); BuildReferences(af); } ProcessObjects(); }
public Dictionary <string, string> Extract(Dictionary <long, string> refs, List <ArtCard> cards) { Dictionary <string, string> bundleMap = new Dictionary <string, string>(); var countFound = 0; foreach (var tf in _files) { AssestFile af = new AssestFile(tf); foreach (var obj in af.Objects) { // check to see if obj id is found in texrefs var unityClass = (UnityClass)obj.Info.ClassId; if (unityClass == UnityClass.Texture2D && refs.ContainsKey(obj.Id)) { countFound++; var refPath = refs[obj.Id]; var refName = StringUtils.GetFilenameNoExt(refPath).ToUpper(); var refCardId = StringUtils.GetFilePathParentDir(refPath).ToUpper(); refPath = refPath.Replace("final/", "").ToLower(); var cardMatches = cards.Where(x => x.Texture.Path.ToLower() == refPath).ToList(); Texture2D tex = new Texture2D(BinaryBlock.Create(obj.Buffer)); if (tex.Name.ToUpper() == refName) { foreach (var match in cardMatches) { SaveImages(tex, match); // add card id to filename record if (bundleMap.ContainsKey(match.Id)) { Logger.Log(LogLevel.WARN, $"{refName} multi match {match}"); } else { bundleMap.Add(match.Id, tf); } } } } } } Logger.Log(LogLevel.DEBUG, "TextureBundle Refs matched: " + countFound); return(bundleMap); }
private static void ExtractAssets(IEnumerable <IExtractor> extractors, string outDir, string[] files) { if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } foreach (var f in files) { if (File.Exists(f)) { AssestFile bundle = new AssestFile(f); var bundleDir = Path.Combine(outDir, bundle.FlieName); Directory.CreateDirectory(bundleDir); foreach (var obj in bundle.Objects) { foreach (var ex in extractors) { ex.Extract(obj, bundleDir); } } } } }
public static void AllImages(string[] files, string dir, bool alpha, bool flip) { IExtractor extractor = new ImageExtractor(alpha, flip); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } foreach (var f in files) { if (File.Exists(f)) { AssestFile bundle = new AssestFile(f); var bundleDir = Path.Combine(dir, bundle.FlieName); System.Console.WriteLine("Extracting {0}...", bundle.FlieName); foreach (var obj in bundle.Objects) { extractor.Extract(obj, bundleDir); } } } }