public GameStructureExporter(ExportSettings settings, List <string> files, Func <uTinyRipper.Classes.Object, bool> filter = null) { GameDir = settings.GameDir; ExportPath = settings.ExportDir; options = new ExportOptions() { Platform = Platform.NoTarget, Flags = TransferInstructionFlags.NoTransferInstructionFlags, }; GameStructure = GameStructure.Load(files); if (string.IsNullOrEmpty(settings.ExportVersion)) { options.Version = new Version(2017, 3, 0, VersionType.Final, 3); } else if (settings.ExportVersion.ToLower() == "detect") { //The version in unity default resources and unity_builtin_extra seem to differ from the game version var versionCheckFile = GameStructure.FileCollection.Files.FirstOrDefault(f => !Path.GetFileName(f.Name).Contains("unity")); if (versionCheckFile != null) { options.Version = versionCheckFile.Version; Logger.Log(LogType.Info, LogCategory.Export, $"Version detected as {options.Version.ToString()}"); } else { Logger.Log(LogType.Warning, LogCategory.Export, $"Could not detect version"); options.Version = new Version(2017, 3, 0, VersionType.Final, 3); } } else { options.Version = new Version(); options.Version.Parse(settings.ExportVersion); Logger.Log(LogType.Info, LogCategory.Export, $"Version set to {options.Version.ToString()}"); } if (filter != null) { Filter = filter; } else { Filter = (obj) => true; } var fileCollection = GameStructure.FileCollection; var textureExporter = new TextureAssetExporter(); var engineExporter = new EngineAssetExporter(); fileCollection.Exporter.OverrideExporter(ClassIDType.Material, engineExporter); fileCollection.Exporter.OverrideExporter(ClassIDType.Mesh, engineExporter); fileCollection.Exporter.OverrideExporter(ClassIDType.Shader, new CustomShaderAssetExporter()); fileCollection.Exporter.OverrideExporter(ClassIDType.TextAsset, new TextAssetExporter()); fileCollection.Exporter.OverrideExporter(ClassIDType.AudioClip, new AudioAssetExporter()); fileCollection.Exporter.OverrideExporter(ClassIDType.Font, new FontAssetExporter()); fileCollection.Exporter.OverrideExporter(ClassIDType.MovieTexture, new MovieTextureAssetExporter()); fileCollection.Exporter.OverrideExporter(ClassIDType.Texture2D, textureExporter); fileCollection.Exporter.OverrideExporter(ClassIDType.Cubemap, textureExporter); fileCollection.Exporter.OverrideExporter(ClassIDType.Sprite, engineExporter); //engine or texture exporter? fileCollection.Exporter.EventExportStarted += () => { Logger.Log(LogType.Info, LogCategory.Export, "EventExportStarted"); UpdateTitle($"EventExportStarted"); }; fileCollection.Exporter.EventExportPreparationStarted += () => { Logger.Log(LogType.Info, LogCategory.Export, "EventExportPreparationStarted"); UpdateTitle($"EventExportPreparationStarted"); }; fileCollection.Exporter.EventExportPreparationFinished += () => { Logger.Log(LogType.Info, LogCategory.Export, "EventExportPreparationFinished"); UpdateTitle($"EventExportPreparationFinished"); }; fileCollection.Exporter.EventExportFinished += () => { Logger.Log(LogType.Info, LogCategory.Export, "EventExportFinished"); UpdateTitle($"EventExportFinished"); }; fileCollection.Exporter.EventExportStarted += () => { Logger.Log(LogType.Info, LogCategory.Export, "EventExportStarted"); UpdateTitle($"EventExportStarted"); }; fileCollection.Exporter.EventExportProgressUpdated += (int number, int total) => { UpdateTitle($"Exported {number / (float)total * 100:0.#} - {number} of {total}"); }; if (settings.ScriptByName) { foreach (var asset in fileCollection.FetchAssets()) { if (asset is MonoScript script) { using (MD5 md5 = MD5.Create()) { var data = md5.ComputeHash(Encoding.UTF8.GetBytes($"{script.AssemblyName}.{script.Namespace}.{script.ClassName}")); var newGuid = new Guid(data); Util.SetGUID(script, newGuid); } } } } if (settings.ShaderByName) { foreach (var asset in fileCollection.FetchAssets()) { if (asset is Shader shader) { using (MD5 md5 = MD5.Create()) { var data = md5.ComputeHash(Encoding.UTF8.GetBytes($"{shader.ValidName}")); var newGuid = new Guid(data); var engGuid = new EngineGUID(newGuid); Util.SetGUID(shader, newGuid); Console.WriteLine($"Set shader {shader.ValidName} to Guid {engGuid}"); } } } } }