mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
Primary Content Extraction should respect export settings
Resolves #1942
This commit is contained in:
parent
43fea56266
commit
41d464112b
@ -65,14 +65,14 @@ public sealed class PrimaryContentExporter
|
||||
exporters.OverrideHandler(type, handler, allowInheritance);
|
||||
}
|
||||
|
||||
public static PrimaryContentExporter CreateDefault(GameData gameData)
|
||||
public static PrimaryContentExporter CreateDefault(GameData gameData, FullConfiguration settings)
|
||||
{
|
||||
PrimaryContentExporter exporter = new(gameData);
|
||||
exporter.RegisterDefaultHandlers();
|
||||
exporter.RegisterDefaultHandlers(settings);
|
||||
return exporter;
|
||||
}
|
||||
|
||||
private void RegisterDefaultHandlers()
|
||||
private void RegisterDefaultHandlers(FullConfiguration settings)
|
||||
{
|
||||
RegisterHandler<IUnityObjectBase>(new JsonContentExtractor());
|
||||
|
||||
@ -115,16 +115,16 @@ public sealed class PrimaryContentExporter
|
||||
|
||||
RegisterHandler<IAudioClip>(new AudioContentExtractor());
|
||||
|
||||
RegisterHandler<IImageTexture>(new TextureExporter(ImageExportFormat.Png));
|
||||
RegisterHandler<IImageTexture>(new TextureExporter(settings.ExportSettings.ImageExportFormat));
|
||||
|
||||
RegisterHandler<IMonoScript>(new ScriptContentExtractor(gameData.AssemblyManager));
|
||||
RegisterHandler<IMonoScript>(new ScriptContentExtractor(gameData.AssemblyManager, settings.ExportSettings.ScriptLanguageVersion.ToCSharpLanguageVersion(gameData.ProjectVersion)));
|
||||
|
||||
// Deleted assets
|
||||
// This must be the last handler
|
||||
RegisterHandler<IUnityObjectBase>(DeletedAssetsExporter.Instance);
|
||||
}
|
||||
|
||||
public void Export(GameBundle fileCollection, CoreConfiguration options, FileSystem fileSystem)
|
||||
public void Export(GameBundle fileCollection, FullConfiguration settings, FileSystem fileSystem)
|
||||
{
|
||||
List<ExportCollectionBase> collections = CreateCollections(fileCollection);
|
||||
|
||||
@ -134,7 +134,7 @@ public sealed class PrimaryContentExporter
|
||||
if (collection.Exportable)
|
||||
{
|
||||
Logger.Info(LogCategory.ExportProgress, $"({i + 1}/{collections.Count}) Exporting '{collection.Name}'");
|
||||
bool exportedSuccessfully = collection.Export(options.ExportRootPath, fileSystem);
|
||||
bool exportedSuccessfully = collection.Export(settings.ExportRootPath, fileSystem);
|
||||
if (!exportedSuccessfully)
|
||||
{
|
||||
Logger.Warning(LogCategory.ExportProgress, $"Failed to export '{collection.Name}'");
|
||||
|
||||
@ -1,23 +1,26 @@
|
||||
using AssetRipper.Assets;
|
||||
using AssetRipper.Import.Structure.Assembly.Managers;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_115;
|
||||
using ICSharpCode.Decompiler.CSharp;
|
||||
|
||||
namespace AssetRipper.Export.PrimaryContent.Scripts;
|
||||
|
||||
public sealed class ScriptContentExtractor : IContentExtractor
|
||||
{
|
||||
public IAssemblyManager AssemblyManager { get; }
|
||||
public LanguageVersion LanguageVersion { get; }
|
||||
private bool first = true;
|
||||
public ScriptContentExtractor(IAssemblyManager assemblyManager)
|
||||
public ScriptContentExtractor(IAssemblyManager assemblyManager, LanguageVersion languageVersion = LanguageVersion.Latest)
|
||||
{
|
||||
AssemblyManager = assemblyManager;
|
||||
LanguageVersion = languageVersion;
|
||||
}
|
||||
|
||||
public bool TryCreateCollection(IUnityObjectBase asset, [NotNullWhen(true)] out ExportCollectionBase? exportCollection)
|
||||
{
|
||||
if (asset is IMonoScript)
|
||||
{
|
||||
exportCollection = first ? new ScriptExportCollection(this) : EmptyExportCollection.Instance;
|
||||
exportCollection = first ? new ScriptExportCollection(this, LanguageVersion) : EmptyExportCollection.Instance;
|
||||
first = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ using AssetRipper.Assets;
|
||||
using AssetRipper.Import.Structure.Assembly.Managers;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_115;
|
||||
using ICSharpCode.Decompiler;
|
||||
using ICSharpCode.Decompiler.CSharp;
|
||||
using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
|
||||
using ICSharpCode.Decompiler.Metadata;
|
||||
|
||||
@ -10,13 +11,16 @@ namespace AssetRipper.Export.PrimaryContent.Scripts;
|
||||
|
||||
public sealed class ScriptExportCollection : ExportCollectionBase
|
||||
{
|
||||
public ScriptExportCollection(ScriptContentExtractor contentExtractor)
|
||||
public ScriptExportCollection(ScriptContentExtractor contentExtractor, LanguageVersion languageVersion = LanguageVersion.Latest)
|
||||
{
|
||||
ContentExtractor = contentExtractor;
|
||||
LanguageVersion = languageVersion;
|
||||
}
|
||||
|
||||
public override IContentExtractor ContentExtractor { get; }
|
||||
|
||||
public LanguageVersion LanguageVersion { get; }
|
||||
|
||||
public override IEnumerable<IUnityObjectBase> Assets => [];
|
||||
|
||||
public override string Name => nameof(ScriptExportCollection);
|
||||
@ -57,6 +61,8 @@ public sealed class ScriptExportCollection : ExportCollectionBase
|
||||
|
||||
DecompilerSettings settings = new();
|
||||
|
||||
settings.SetLanguageVersion(LanguageVersion);
|
||||
|
||||
settings.AlwaysShowEnumMemberValues = true;
|
||||
settings.ShowXmlDocumentation = true;
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ public class ExportHandler
|
||||
{
|
||||
Logger.Info(LogCategory.Export, "Starting export");
|
||||
Logger.Info(LogCategory.Export, $"Attempting to export assets to {outputPath}...");
|
||||
Logger.Info(LogCategory.Export, $"Game files have these Unity versions:{GetListOfVersions(gameData.GameBundle)}");
|
||||
Logger.Info(LogCategory.Export, $"Game files have these Unity versions: {GetListOfVersions(gameData.GameBundle)}");
|
||||
Logger.Info(LogCategory.Export, $"Exporting to Unity version {gameData.ProjectVersion}");
|
||||
|
||||
Settings.ExportRootPath = outputPath;
|
||||
|
||||
@ -29,6 +29,13 @@ public static class GameFileLoader
|
||||
field = value;
|
||||
}
|
||||
} = new(Settings);
|
||||
|
||||
/// <summary>
|
||||
/// Is this the premium edition?
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is purely for UI functionality and has no direct effect on the presense of features.
|
||||
/// </remarks>
|
||||
public static bool Premium => ExportHandler.GetType() != typeof(ExportHandler);
|
||||
|
||||
public static void Reset()
|
||||
@ -84,7 +91,7 @@ public static class GameFileLoader
|
||||
Logger.Info(LogCategory.Export, "Starting primary content export");
|
||||
Logger.Info(LogCategory.Export, $"Attempting to export assets to {path}...");
|
||||
Settings.ExportRootPath = path;
|
||||
PrimaryContentExporter.CreateDefault(GameData).Export(GameBundle, Settings, LocalFileSystem.Instance);
|
||||
PrimaryContentExporter.CreateDefault(GameData, Settings).Export(GameBundle, Settings, LocalFileSystem.Instance);
|
||||
Logger.Info(LogCategory.Export, "Finished exporting primary content.");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user