Esempio n. 1
0
        // 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);
        }
Esempio n. 2
0
        // 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);
            }
        }
Esempio n. 3
0
        public static void ClassInitialize(TestContext context)
        {
            var file = @".\Data\bundle_5.1.unity3d";
            var abr  = new AssestFile(file);

            _tree = abr.TypeTree;
        }
Esempio n. 4
0
        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;
        }
Esempio n. 6
0
        public static void ClassInitialize(TestContext context)
        {
            var file = @".\Data\bundle_5.1.unity3d";
            var abr  = new AssestFile(file);

            _entry = abr.BundleEntry;
        }
Esempio n. 7
0
        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;
                }
            }
        }
Esempio n. 8
0
 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();
 }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        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);
                    }
                }
            }
        }