예제 #1
0
        private List <string> ApplySubFilters(string mapValue, AssetTypeValueField absoluteRoot, AssetTypeValueField relativeRoot, AssetFile file,
                                              AssetToolUtils assetUtils)
        {
            List <string> result = new List <string>();

            AssetTypeValueField targetRoot = subFilter.pathType switch {
                EOnlineInterpreterPathType.relative => relativeRoot,
                EOnlineInterpreterPathType.absolute => absoluteRoot,
                _ => throw new InvalidOperationException("pathType " + subFilter.pathType + " is not supported by DownloaderInterpreterConfig.cs")
            };

            List <AssetTypeValueField> basePathFields = AssetToolUtils.GetFieldAtPath(file, targetRoot, subFilter.basePath.Split(':'));
            List <string> filterValues = new List <string>();

            foreach (List <AssetTypeValueField> pathFields in basePathFields
                     .Select(field => AssetToolUtils.GetFieldAtPath(file, field, subFilter.valuePath.Split(':'))))
            {
                filterValues.AddRange(pathFields.Where(pathField => pathField.GetValue() != null).Select(pathField => pathField.GetValue().AsString().Trim()));
            }

            if (subFilter.optional && (basePathFields.Count == 0 || basePathFields.Count > filterValues.Count))
            {
                //this file has no filtered basePathElements
                //or this file has some filtered basePathElements without a filterValue
                result.Add(mapValue);
            }

            var fileNameModifierRegex = new Regex(subFilter.fileNameModifierRegex);

            result.AddRange(filterValues
                            .Where(value => CustomRegex.AllMatching(value, subFilter.valueRegexFilters))
                            .Select(value =>
                                    fileNameModifierRegex.Replace(mapValue, subFilter.fileNameModifierReplacement.Replace("${value}", value))
                                    ));

            return(result);
        }

        bool YamlObject.Save(ref List <string> lines, int startLine, ref int endLine, int currentTabDepth)
        {
            return(true);
        }

        string IMenuObject.GetInfoString()
        {
            return("no menu options, adjust the config file instead.");
        }

        IMenuProperty[] IMenuObject.GetOptions()
        {
            return(new IMenuProperty[0]);
        }
    }
예제 #2
0
        private void BuildBundleContent(ref List <string> result, string fileUrl, AssetFile file, AssetToolUtils assetToolUtils)
        {
            foreach (AssetFileInfoEx info in file.fileInstance.table.assetFileInfo)
            {
                ClassDatabaseType type = AssetHelper.FindAssetClassByID(file.classDBFile, info.curFileType);
                if (type == null)
                {
                    continue;
                }

                string typeName = type.name.GetString(file.classDBFile);
                if (typeName != "MonoBehaviour")
                {
                    continue;
                }

                AssetTypeValueField        baseField    = AssetToolUtils.GetATI(file, info).GetBaseField();
                List <AssetTypeValueField> targetFields = AssetToolUtils.GetFieldAtPath(file, baseField, configPath.Split(':'));
                if (targetFields.Count == 0)
                {
                    continue;
                }

                if (!AssetToolUtils.IsMatchingPathConstraints(file, baseField, pathConstraints))
                {
                    continue;
                }

                Console.WriteLine("found " + targetFields.Count + " matches in mono-behaviour at path: " + configPath);

                foreach (AssetTypeValueField targetField in targetFields)
                {
                    List <AssetTypeValueField> fileNameFields = AssetToolUtils.GetFieldAtPath(file, targetField, fileNamePath.Split(':'));
                    Console.WriteLine("found " + fileNameFields.Count + " fileNameFields in targetField at path: " + fileNamePath);

                    foreach (string value in fileNameFields
                             .Select(fileNameField => fileNameField.GetValue().AsString().Trim())
                             .Where(fileName => CustomRegex.AllMatching(fileName, fileNameRegexFilters))
                             .SelectMany(fileName => ApplySubFilters(fileName, baseField, targetField, file, assetToolUtils)))
                    {
                        if (!result.Contains(value))
                        {
                            result.Add(value);
                        }
                    }
                }
            }
        }
예제 #3
0
 List <string> IMappingValue.GetMapValues(string fileUrl, AssetFile assetFile, AssetTypeValueField baseField, AssetTypeValueField targetField,
                                          AssetToolUtils assetToolUtils)
 {
     return(AssetToolUtils.GetFieldAtPath(assetFile, targetField, path.Split(':')).Select(field => field.GetValue().AsString()).ToList());
 }
        private void BuildBundleContent(ref Dictionary <string, Dictionary <string, List <string> > > result, string fileUrl, AssetFile file,
                                        AssetToolUtils assetToolUtils)
        {
            Console.WriteLine("building bundle content!");
            foreach (AssetFileInfoEx info in file.fileInstance.table.assetFileInfo)
            {
                ClassDatabaseType type = AssetHelper.FindAssetClassByID(file.classDBFile, info.curFileType);
                if (type == null)
                {
                    continue;
                }

                string typeName = type.name.GetString(file.classDBFile);
                if (typeName != "MonoBehaviour")
                {
                    continue;
                }

                AssetTypeValueField baseField = AssetToolUtils.GetATI(file, info).GetBaseField();

                List <AssetTypeValueField> targetFields = AssetToolUtils.GetFieldAtPath(file, baseField, configPath.Split(':'));
                if (targetFields.Count == 0)
                {
                    continue;
                }

                if (!AssetToolUtils.IsMatchingPathConstraints(file, baseField, pathConstraints))
                {
                    continue;
                }

                Console.WriteLine("found " + targetFields.Count + " matches in mono-behaviour at path " + configPath);

                foreach (AssetTypeValueField targetField in targetFields)
                {
                    List <string> mapByField = mapConfigBy.GetMapValues(fileUrl, file, baseField, targetField, assetToolUtils);
                    Console.WriteLine("found " + mapByField.Count + " mapFields in targetField at mapConfigBy.path");

                    foreach (string mapValue in mapByField)
                    {
                        Dictionary <string, List <string> > secondaryValues = new Dictionary <string, List <string> >();

                        foreach (OnlineInterpreterFilter filter in configFilter)
                        {
                            List <string> filterValues = new List <string>();

                            List <AssetTypeValueField> filterFields = filter.pathType switch {
                                EOnlineInterpreterPathType.relative => AssetToolUtils.GetFieldAtPath(file, targetField, filter.path.Split(':')),
                                EOnlineInterpreterPathType.absolute => AssetToolUtils.GetFieldAtPath(file, baseField, filter.path.Split(':')),
                                _ => throw new InvalidOperationException("pathType " + filter.pathType +
                                                                         " is not supported by OnlineSourceInterpreterConfig.cs")
                            };

                            Console.WriteLine("found " + filterFields.Count + " fields at path: " + filter.path);
                            filterValues.AddRange(filterFields
                                                  .Where(field => field.GetValue() != null)
                                                  .Select(field => ResolveTranslationValue(field.GetValue().AsString().Trim(), filter.outputName)));

                            secondaryValues[filter.outputName] = filterValues;
                        }

                        if (result.ContainsKey(mapValue))
                        {
                            foreach (string key in secondaryValues.Keys)
                            {
                                if (result[mapValue].ContainsKey(key))
                                {
                                    result[mapValue][key].AddRange(secondaryValues[key]);
                                }
                                else
                                {
                                    result[mapValue][key] = secondaryValues[key];
                                }
                            }
                        }
                        else
                        {
                            result[mapValue] = secondaryValues;
                        }

                        LevelMappingResult(ref result, mapValue);
                    }
                }
            }
        }
        private void Run()
        {
            EOnlineDataType onlineDataType = materialExtractor.onlineSourcesConfig.GetValue().dataType.GetValue();

            switch (onlineDataType)
            {
            case EOnlineDataType.bundleFile:
                Dictionary <string, List <string> > materialToColorList = new Dictionary <string, List <string> >();
                foreach (string dataFileUrL in materialExtractor.onlineSourcesConfig.GetValue().GetDataFileURLs())
                {
                    if (!materialExtractor.downloadSettings.GetValue().doDownload.GetValue())
                    {
                        Console.WriteLine("would download: " + dataFileUrL);
                        continue;
                    }

                    List <string> pathConstraints = new List <string> {
                        "m_SavedProperties:m_Colors:Array:data:first=_PrimaryColor",
                        "m_SavedProperties:m_Colors:Array:data:first=_SecondaryColor",
                        "m_SavedProperties:m_Colors:Array:data:first=_TertiaryColor"
                    };

                    try {
                        Console.WriteLine("loading bundle data from url: " + dataFileUrL);
                        using var client = new WebClient();
                        using var stream = new MemoryStream(client.DownloadData(dataFileUrL));
                        var assetToolUtils = new AssetToolUtils();
                        Console.WriteLine("Download done, building AssetsFileInstance...");
                        foreach (AssetFile file in assetToolUtils.BuildAssetsFileInstance(stream))
                        {
                            foreach (AssetFileInfoEx info in file.fileInstance.table.assetFileInfo)
                            {
                                ClassDatabaseType type = AssetHelper.FindAssetClassByID(file.classDBFile, info.curFileType);
                                if (type == null)
                                {
                                    continue;
                                }

                                string typeName = type.name.GetString(file.classDBFile);
                                if (typeName != "Material")
                                {
                                    continue;
                                }

                                AssetTypeValueField baseField = AssetToolUtils.GetATI(file, info).GetBaseField();
                                string materialName           = AssetToolUtils.GetFieldAtPath(file, baseField, "m_Name".Split(":")).FirstOrDefault()?.GetValue()?.AsString();
                                if (materialName == null)
                                {
                                    continue;
                                }

                                Console.WriteLine($"\tchecking Material '{materialName}'");

                                if (!AssetToolUtils.IsMatchingPathConstraints(file, baseField, pathConstraints))
                                {
                                    Console.WriteLine("\t\tMaterial did not match path constraints!");
                                    continue;
                                }

                                List <string> colors = new List <string> {
                                    "", "", ""
                                };
                                foreach (AssetTypeValueField colorDataField in AssetToolUtils.GetFieldAtPath(file, baseField, "m_SavedProperties:m_Colors:Array:data".Split(":")))
                                {
                                    string red   = AssetToolUtils.GetFieldAtPath(file, colorDataField, "second:r".Split(":")).FirstOrDefault()?.GetValue()?.AsString();
                                    string green = AssetToolUtils.GetFieldAtPath(file, colorDataField, "second:g".Split(":")).FirstOrDefault()?.GetValue()?.AsString();
                                    string blue  = AssetToolUtils.GetFieldAtPath(file, colorDataField, "second:b".Split(":")).FirstOrDefault()?.GetValue()?.AsString();
                                    string alpha = AssetToolUtils.GetFieldAtPath(file, colorDataField, "second:a".Split(":")).FirstOrDefault()?.GetValue()?.AsString();
                                    if (red == null || green == null || blue == null || alpha == null)
                                    {
                                        Console.WriteLine("\t\trgba was null!");
                                        continue;
                                    }
                                    string colorString = $"r={red};g={green};b={blue};a={alpha}";

                                    if (AssetToolUtils.IsMatchingPathConstraints(file, colorDataField, "first=_PrimaryColor"))
                                    {
                                        colors[0] = colorString;
                                    }
                                    else if (AssetToolUtils.IsMatchingPathConstraints(file, colorDataField, "first=_SecondaryColor"))
                                    {
                                        colors[1] = colorString;
                                    }
                                    else if (AssetToolUtils.IsMatchingPathConstraints(file, colorDataField, "first=_TertiaryColor"))
                                    {
                                        colors[2] = colorString;
                                    }
                                }
                                materialToColorList[materialName] = colors;
                            }
                        }
                    } catch (Exception e) {
                        Console.WriteLine($"\tEncountered an exception! {e}");
                        if (materialExtractor.downloadSettings.GetValue().pauseDownloadOnError.GetValue())
                        {
                            Console.WriteLine("\twaiting for user acknowledgement. Press any key to continue...");
                            Console.ReadKey(true);
                        }
                    }
                }

                string targetFile      = materialExtractor.GetResultFile("extraction");
                string targetDirectory = Path.GetDirectoryName(targetFile);
                if (!Directory.Exists(targetDirectory))
                {
                    Console.WriteLine("Had to create directory: " + targetDirectory);
                    Directory.CreateDirectory(targetDirectory);
                }

                using (StreamWriter writer = new StreamWriter(targetFile, false)) {
                    List <string> header = new List <string> {
                        "MaterialName", "Primary", "Secondary", "Tertiary"
                    };
                    Console.WriteLine(string.Join("\t", header));
                    writer.WriteLine(string.Join("\t", header));
                    foreach ((string materialName, List <string> colorsInOrder) in materialToColorList)
                    {
                        Console.WriteLine(materialName + "\t" + string.Join("\t", colorsInOrder));
                        writer.WriteLine(materialName + "\t" + string.Join("\t", colorsInOrder));
                    }
                }

                break;

            case EOnlineDataType.xmlFile:
            default:
                throw new InvalidOperationException("OnlineDataType " + onlineDataType + " not supported by MaterialExtractor!");
            }

            Console.WriteLine("Press any key to continue.");
            Console.ReadKey(true);
        }