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 ReCodeIt.Utils;
|
||||||
using ReCodeItLib.Remapper.Search;
|
using ReCodeItLib.Remapper.Search;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace ReCodeIt.ReMapper;
|
namespace ReCodeIt.ReMapper;
|
||||||
|
|
||||||
@ -61,6 +62,8 @@ public class ReCodeItRemapper
|
|||||||
Logger.Log("You must de-obfuscate the assembly before remapping it.\n", ConsoleColor.Red);
|
Logger.Log("You must de-obfuscate the assembly before remapping it.\n", ConsoleColor.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HandleTypeTableRemaps(assemblyPath, types);
|
||||||
|
|
||||||
var tasks = new List<Task>(remapModels.Count);
|
var tasks = new List<Task>(remapModels.Count);
|
||||||
foreach (var remap in remapModels)
|
foreach (var remap in remapModels)
|
||||||
@ -95,7 +98,7 @@ public class ReCodeItRemapper
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
Task.WaitAll(renameTasks.ToArray());
|
Task.WaitAll(renameTasks.ToArray());
|
||||||
|
|
||||||
// Don't publicize and unseal until after the remapping, so we can use those as search parameters
|
// Don't publicize and unseal until after the remapping, so we can use those as search parameters
|
||||||
if (Settings.MappingSettings.Publicize)
|
if (Settings.MappingSettings.Publicize)
|
||||||
{
|
{
|
||||||
@ -103,7 +106,7 @@ public class ReCodeItRemapper
|
|||||||
|
|
||||||
SPTPublicizer.PublicizeClasses(Module);
|
SPTPublicizer.PublicizeClasses(Module);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are done, write the assembly
|
// We are done, write the assembly
|
||||||
WriteAssembly();
|
WriteAssembly();
|
||||||
}
|
}
|
||||||
@ -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>
|
/// <summary>
|
||||||
/// Choose the best possible match from all remaps
|
/// Choose the best possible match from all remaps
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -7,6 +7,11 @@ namespace ReCodeIt.Utils;
|
|||||||
|
|
||||||
public static class DataProvider
|
public static class DataProvider
|
||||||
{
|
{
|
||||||
|
static DataProvider()
|
||||||
|
{
|
||||||
|
LoadItems();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this running in the CLI?
|
/// Is this running in the CLI?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -15,7 +20,8 @@ public static class DataProvider
|
|||||||
public static string DataPath => Path.Combine(AppContext.BaseDirectory, "Data");
|
public static string DataPath => Path.Combine(AppContext.BaseDirectory, "Data");
|
||||||
|
|
||||||
public static List<RemapModel> Remaps { get; set; } = [];
|
public static List<RemapModel> Remaps { get; set; } = [];
|
||||||
|
public static Dictionary<string, ItemTemplateModel>? ItemTemplates { get; private set; }
|
||||||
|
|
||||||
public static Settings Settings { get; private set; }
|
public static Settings Settings { get; private set; }
|
||||||
|
|
||||||
public static void LoadAppSettings()
|
public static void LoadAppSettings()
|
||||||
@ -116,7 +122,7 @@ public static class DataProvider
|
|||||||
public static ModuleDefMD LoadModule(string path)
|
public static ModuleDefMD LoadModule(string path)
|
||||||
{
|
{
|
||||||
var mcOptions = new ModuleCreationOptions(ModuleDef.CreateModuleContext());
|
var mcOptions = new ModuleCreationOptions(ModuleDef.CreateModuleContext());
|
||||||
ModuleDefMD module = ModuleDefMD.Load(path, mcOptions);
|
var module = ModuleDefMD.Load(path, mcOptions);
|
||||||
|
|
||||||
module.Context = mcOptions.Context;
|
module.Context = mcOptions.Context;
|
||||||
|
|
||||||
@ -127,4 +133,12 @@ public static class DataProvider
|
|||||||
|
|
||||||
return module;
|
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