mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-13 01:50:45 -05:00
WIP: Remap classes based on parents in item.json
This commit is contained in:
parent
53c9685580
commit
663148d3ed
524563
Assets/Templates/items.json
Normal file
524563
Assets/Templates/items.json
Normal file
File diff suppressed because it is too large
Load Diff
9
RecodeItLib/Models/ItemTemplateModel.cs
Normal file
9
RecodeItLib/Models/ItemTemplateModel.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace ReCodeIt.Models;
|
||||
|
||||
public class ItemTemplateModel
|
||||
{
|
||||
public string _id;
|
||||
public string _name;
|
||||
public string _parent;
|
||||
public string _type;
|
||||
}
|
@ -6,6 +6,7 @@ using ReCodeIt.ReMapper.Search;
|
||||
using ReCodeIt.Utils;
|
||||
using ReCodeItLib.Remapper.Search;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ReCodeIt.ReMapper;
|
||||
|
||||
@ -62,6 +63,8 @@ public class ReCodeItRemapper
|
||||
return;
|
||||
}
|
||||
|
||||
HandleTypeTableRemaps(assemblyPath, types);
|
||||
|
||||
var tasks = new List<Task>(remapModels.Count);
|
||||
foreach (var remap in remapModels)
|
||||
{
|
||||
@ -427,6 +430,50 @@ public class ReCodeItRemapper
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleTypeTableRemaps(string path, IEnumerable<TypeDef> types)
|
||||
{
|
||||
// HACK: Because this is written in net8 and the assembly is net472 we must resolve the type this way instead of
|
||||
// filtering types directly using GetTypes() Otherwise, it causes serialization issues.
|
||||
// This is also necessary because we can't access non-compile time constants with dnlib.
|
||||
var templateMappingTypeDef = types.Single(t => t.FindField("TypeTable") != null);
|
||||
var assembly = Assembly.LoadFrom(path);
|
||||
var templateMappingClass = assembly.Modules
|
||||
.First()
|
||||
.GetType(templateMappingTypeDef.Name);
|
||||
|
||||
if (templateMappingClass is null)
|
||||
{
|
||||
Logger.Log($"Could not find {templateMappingTypeDef.Name} in the assembly.", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
var typeTable = (Dictionary<string, Type>)templateMappingClass
|
||||
.GetField("TypeTable")
|
||||
.GetValue(templateMappingClass);
|
||||
|
||||
foreach (var type in typeTable)
|
||||
{
|
||||
if (DataProvider.ItemTemplates!.TryGetValue(type.Key, out var template))
|
||||
{
|
||||
if (!type.Value.Name.StartsWith("GClass")) continue;
|
||||
|
||||
Logger.Log($"Key: {type.Key} Type: {type.Value.Name} Associated to {template._name}", ConsoleColor.Green);
|
||||
|
||||
var remap = new RemapModel
|
||||
{
|
||||
OriginalTypeName = type.Value.Name,
|
||||
NewTypeName = $"{template._name}",
|
||||
UseForceRename = true
|
||||
};
|
||||
|
||||
_remaps.Add(remap);
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger.Log($"Found no association for key: {type.Key} Type: {type.Value}", ConsoleColor.Yellow);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Choose the best possible match from all remaps
|
||||
/// </summary>
|
||||
|
@ -7,6 +7,11 @@ namespace ReCodeIt.Utils;
|
||||
|
||||
public static class DataProvider
|
||||
{
|
||||
static DataProvider()
|
||||
{
|
||||
LoadItems();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is this running in the CLI?
|
||||
/// </summary>
|
||||
@ -15,6 +20,7 @@ public static class DataProvider
|
||||
public static string DataPath => Path.Combine(AppContext.BaseDirectory, "Data");
|
||||
|
||||
public static List<RemapModel> Remaps { get; set; } = [];
|
||||
public static Dictionary<string, ItemTemplateModel>? ItemTemplates { get; private set; }
|
||||
|
||||
public static Settings Settings { get; private set; }
|
||||
|
||||
@ -116,7 +122,7 @@ public static class DataProvider
|
||||
public static ModuleDefMD LoadModule(string path)
|
||||
{
|
||||
var mcOptions = new ModuleCreationOptions(ModuleDef.CreateModuleContext());
|
||||
ModuleDefMD module = ModuleDefMD.Load(path, mcOptions);
|
||||
var module = ModuleDefMD.Load(path, mcOptions);
|
||||
|
||||
module.Context = mcOptions.Context;
|
||||
|
||||
@ -127,4 +133,12 @@ public static class DataProvider
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
private static void LoadItems()
|
||||
{
|
||||
var itemsPath = Path.Combine(DataPath, "items.json");
|
||||
var jsonText = File.ReadAllText(itemsPath);
|
||||
|
||||
ItemTemplates = JsonConvert.DeserializeObject<Dictionary<string, ItemTemplateModel>>(jsonText);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user