Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions godot-mono-decomp/GodotMonoDecomp/GodotStuff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.Util;

namespace GodotMonoDecomp;

Expand Down Expand Up @@ -353,22 +354,19 @@ public static Dictionary<string, List<TypeDefinitionHandle>> CreateFileMap(Metad
var canonicalPaths = new HashSet<string>();
var canonicalHandles = new HashSet<TypeDefinitionHandle>();
var metadata = module.Metadata;
Dictionary<string, string>? metadataFQNToFileMap = null;
Dictionary<string, string[]>? metadataFQNToFileMap = null;
// look at the files in the original project and find a common root for all the files
// var allFiles = filesInOriginal.Select(f => Path.GetDirectoryName(f) ?? "").Where(d => !string.IsNullOrEmpty(d) && !d.StartsWith("addons", StringComparison.OrdinalIgnoreCase)).ToHashSet<string>();
string? globalCommonRoot = null;//Common.FindCommonRoot(allFiles) ?? null;

if (scriptMetadata != null)
{
// create a map of metadata FQN to file path
metadataFQNToFileMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
metadataFQNToFileMap = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
foreach (var pair in scriptMetadata)
{
var fqn = pair.Value.Class.GetFullClassName();
if (!metadataFQNToFileMap.ContainsKey(fqn))
{
metadataFQNToFileMap[fqn] = pair.Key;
}
metadataFQNToFileMap[fqn] = metadataFQNToFileMap.TryGetValue(fqn, out var files) ? files.Append(pair.Key).ToArray() : [pair.Key];
}
}

Expand Down Expand Up @@ -552,10 +550,11 @@ void addToCanonicalPaths(string path, TypeDefinitionHandle h, TypeDefinition typ
{
// check if the type has a metadata FQN in the script metadata
var fqn = type.GetFullTypeName(metadata).ToString();
if (metadataFQNToFileMap.TryGetValue(fqn, out var filePath))
if (metadataFQNToFileMap.TryGetValue(fqn, out var filePaths))
{
filePath = Common.TrimPrefix(filePath, "res://");
addToCanonicalPaths(filePath, h, type);
// If more than one file path exists in the metadata for the class name, pick the one that is actually in the original project.
var filePath = filePaths.Count() == 1 ? filePaths.First() : filePaths.FirstOrDefault(f => filesInOriginal.Contains(Common.TrimPrefix(f, "res://")), filePaths.First());
addToCanonicalPaths(Common.TrimPrefix(filePath, "res://"), h, type);
continue;
}
}
Expand Down
Loading
Loading