mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-12 14:50:44 -05:00
commit
70ac2326fc
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@ mono_crash.*
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
WAIT_FOR_DEBUGGER/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"MappingPath": "",
|
||||
"TypeNamesToMatch": [ // These are the only types considered when looking for a match
|
||||
"TypeNamesToMatch": [
|
||||
"Class",
|
||||
"GClass",
|
||||
"GStruct",
|
||||
@ -9,12 +9,12 @@
|
||||
"Interface",
|
||||
"GInterface"
|
||||
],
|
||||
"MethodNamesToIgnore": [ // Don't try to match on these
|
||||
"MethodNamesToIgnore": [
|
||||
"method_",
|
||||
"smethod_",
|
||||
"vmethod_"
|
||||
],
|
||||
"FieldNamesToIgnore": [ // Don't try to match on these
|
||||
"FieldNamesToIgnore": [
|
||||
"action",
|
||||
"bool",
|
||||
"dictionary",
|
||||
|
1138594
Assets/Templates/items.json
1138594
Assets/Templates/items.json
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Configuration>Debug</Configuration>
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -15,9 +17,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="Build">
|
||||
<Exec Command="pwsh -NoProfile -ExecutionPolicy Bypass .\PostBuild.ps1"
|
||||
WorkingDirectory="$(ProjectDir)"
|
||||
StandardOutputImportance="High"
|
||||
StandardErrorImportance="High" />
|
||||
<Exec Command="pwsh -NoProfile -ExecutionPolicy Bypass .\PostBuild.ps1 $(ConfigurationName)" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
@ -13,7 +13,7 @@ if (Test-Path $buildPath) {
|
||||
}
|
||||
|
||||
Write-Host "Copying ReCodeItCLI output..."
|
||||
$cliOutputDir = Join-Path (Join-Path $solutionDir "ReCodeItCLI") "bin\$Configuration\net8.0"
|
||||
$cliOutputDir = Join-Path (Join-Path $solutionDir "ReCodeItCLI") "bin\$Configuration\net9.0"
|
||||
if (Test-Path $cliOutputDir) {
|
||||
New-Item -Path $buildPath -ItemType Directory -ErrorAction SilentlyContinue
|
||||
Copy-Item -Path (Join-Path $cliOutputDir "*.*") -Destination $buildPath -Recurse
|
||||
|
@ -7,6 +7,8 @@
|
||||
<LangVersion>latestmajor</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
56
README.md
56
README.md
@ -1,19 +1,51 @@
|
||||
# ReCodeIt
|
||||
# Commands
|
||||
|
||||
![image](https://github.com/CJ-SPT/ReCodeIt/assets/161484149/3bdec51c-ca48-4678-a492-5cfd0595f980)
|
||||
- `addmissingproperties` - This command will add missing properties to the provided mapping.json.
|
||||
- Param `MappingsPath` - Path to the mapping.json file to be fixed
|
||||
|
||||
- Note: This is a development command and should not be used unless you know what you're doing. Always make backups when using this command.
|
||||
|
||||
---
|
||||
|
||||
ReCodeIt is a .net assembly tool for working with obfuscated assemblies. It allows you to deobfuscate using de4dot, create remaps for types and generated a re-mapped reference for your project. It has two main components. The GUI pictured above and a CLI companion that can be placed on the system path for access anywhere on your machine at any given time.
|
||||
- `automatch` - This command will Automatically try to generate a mapping object given old type and new type names.
|
||||
- Param `AssemblyPath` - The absolute path to your assembly, folder must contain all references to be resolved.
|
||||
- Param `MappingsPath` - Path to your mapping file so it can be updated if a match is found.
|
||||
- Param `OldTypeName` - Full old type name including namespace `Foo.Bar` for nested classes `Foo.Bar/FooBar`
|
||||
- Param `NewTypeName` - The name you want the type to be renamed to.
|
||||
|
||||
# Building
|
||||
- fork or clone the project to a local directory
|
||||
- Make sure you have [.net 8 sdk](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) installed or install it through the visual studio installer.
|
||||
- Open the solution in visual studio and build
|
||||
- Run the project from visual studio or the build folder.
|
||||
- This command will prompt you to append your created mapping to the mapping file.
|
||||
- It will then prompt you to run the remap process.
|
||||
|
||||
# Using
|
||||
See the [wiki](https://github.com/CJ-SPT/ReCodeIt/wiki)
|
||||
---
|
||||
|
||||
# Support me
|
||||
- `deobfuscate` - This command will run the de4dot de-obfuscater over the assembly provided. It supports both the
|
||||
primary game assembly and the launcher assembly.
|
||||
- Param `AssemblyPath` - The absolute path to your obfuscated assembly or exe file, the folder must contain all
|
||||
references needed to be resolved.
|
||||
- Param `IsLauncher` - Is the target the EFT launcher?
|
||||
|
||||
---
|
||||
|
||||
- `Dumper` - Generates a dumper zip.
|
||||
- Param `ManagedDirectory` - The absolute path to your Managed folder for EFT, folder must contain all references to
|
||||
be resolved. Assembly-CSharp-cleaned.dll, mscorlib.dll, FilesChecker.dll
|
||||
|
||||
---
|
||||
|
||||
- `GenRefCountList` - Generates a print out of the most used classes. Useful to prioritize remap targets.
|
||||
- Param `AssemblyPath` - The absolute path to your de-obfuscated and remapped dll.
|
||||
|
||||
---
|
||||
|
||||
- `regensig` - regenerates the signature of a mapping if it is failing
|
||||
- Param `MappingPath` - The absolute path to mapping.json.
|
||||
- Param `AssemblyPath` - The absolute path to the assembly you want to regenerate the signature for.
|
||||
- Param `NewTypeName` - The new type name as listed in the mapping file.
|
||||
- Param `OldTypeName` - Full old type name including namespace `Foo.Bar` for nested classes `Foo.Bar/FooBar`
|
||||
|
||||
---
|
||||
|
||||
- `remap` - Generates a re-mapped dll provided a mapping file and dll. If the dll is obfuscated, it will automatically de-obfuscate.
|
||||
- Param `MappingJsonPath` - The absolute path to the `mapping.json` file supports both `json` and `jsonc`.
|
||||
- Param `AssemblyPath` - The absolute path to the dll generated from the `deobfuscate` command.
|
||||
|
||||
If you want to support the project you [buy me a coffee!](https://ko-fi.com/dirtbikercj)
|
||||
|
26
ReCodeItCLI/Commands/AddMissingProperties.cs
Normal file
26
ReCodeItCLI/Commands/AddMissingProperties.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using ReCodeItCLI.Utils;
|
||||
using ReCodeItLib.Utils;
|
||||
|
||||
namespace ReCodeItCLI.Commands;
|
||||
|
||||
[Command("AddMissingProperties", Description = "[DEVELOPMENT COMMAND] This command will add missing properties to the provided mapping.json.")]
|
||||
public class AddMissingProperties : ICommand
|
||||
{
|
||||
[CommandParameter(0, IsRequired = true, Description = "Path to the mapping.json file to be fixed")]
|
||||
public string MappingsPath { get; init; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Debugger.TryWaitForDebuggerAttach();
|
||||
|
||||
var remaps = DataProvider.LoadMappingFile(MappingsPath);
|
||||
DataProvider.UpdateMapping(MappingsPath, remaps);
|
||||
|
||||
Logger.LogSync("Successfully updated mapping file");
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using ReCodeItCLI.Utils;
|
||||
using ReCodeItLib.Models;
|
||||
using ReCodeItLib.ReMapper;
|
||||
using ReCodeItLib.Utils;
|
||||
@ -16,15 +17,16 @@ public class AutoMatchCommand : ICommand
|
||||
[CommandParameter(1, IsRequired = true, Description = "Path to your mapping file so it can be updated if a match is found")]
|
||||
public string MappingsPath { get; init; }
|
||||
|
||||
[CommandParameter(2, IsRequired = true, Description = "Full old type name including namespace")]
|
||||
[CommandParameter(2, IsRequired = true, Description = "Full old type name including namespace `Foo.Bar` for nested classes `Foo.Bar/FooBar`")]
|
||||
public required string OldTypeName { get; init; }
|
||||
|
||||
[CommandParameter(3, IsRequired = true, Description = "The name you want the type to be renamed to")]
|
||||
public required string NewTypeName { get; init; }
|
||||
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Debugger.TryWaitForDebuggerAttach();
|
||||
|
||||
Logger.LogSync("Finding match...");
|
||||
|
||||
var remaps = new List<RemapModel>();
|
||||
|
@ -1,6 +1,7 @@
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using ReCodeItCLI.Utils;
|
||||
using ReCodeItLib.Utils;
|
||||
using ReCodeItLib.ReMapper;
|
||||
|
||||
@ -17,6 +18,8 @@ public class DeObfuscate : ICommand
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Debugger.TryWaitForDebuggerAttach();
|
||||
|
||||
Logger.Log("Deobfuscating assembly...");
|
||||
|
||||
Deobfuscator.Deobfuscate(AssemblyPath, IsLauncher);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using ReCodeItCLI.Utils;
|
||||
using ReCodeItLib.Utils;
|
||||
using ReCodeItLib.Dumper;
|
||||
|
||||
@ -14,6 +15,8 @@ public class Dumper : ICommand
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Debugger.TryWaitForDebuggerAttach();
|
||||
|
||||
Logger.Log("Creating DumperClass...");
|
||||
|
||||
var dumper = new DumperClass(ManagedDirectory);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using dnlib.DotNet;
|
||||
using ReCodeItCLI.Utils;
|
||||
|
||||
namespace ReCodeItCLI.Commands;
|
||||
|
||||
@ -23,6 +24,8 @@ public class GenRefList : ICommand
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Debugger.TryWaitForDebuggerAttach();
|
||||
|
||||
var references = CountTypeReferences(AssemblyPath);
|
||||
|
||||
// Sort and display the top 10 most referenced types
|
||||
|
25
ReCodeItCLI/Commands/GetRuntimeVersion.cs
Normal file
25
ReCodeItCLI/Commands/GetRuntimeVersion.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using ReCodeItCLI.Utils;
|
||||
using ReCodeItLib.Utils;
|
||||
|
||||
namespace ReCodeItCLI.Commands;
|
||||
|
||||
[Command("GetRuntimeVersion", Description = "Prints out the .net runtime version this assembly targets")]
|
||||
public class GetRuntimeVersion : ICommand
|
||||
{
|
||||
[CommandParameter(0, IsRequired = true, Description = "The absolute path to your dll.")]
|
||||
public required string AssemblyPath { get; init; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Debugger.TryWaitForDebuggerAttach();
|
||||
|
||||
var module = DataProvider.LoadModule(AssemblyPath);
|
||||
|
||||
Logger.LogSync($"Target Runtime Version: {module.RuntimeVersion}");
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using ReCodeItCLI.Utils;
|
||||
using ReCodeItLib.Utils;
|
||||
using ReCodeItLib.ReMapper;
|
||||
|
||||
@ -19,6 +20,8 @@ public class ReMap : ICommand
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Debugger.TryWaitForDebuggerAttach();
|
||||
|
||||
DataProvider.Settings.MappingPath = MappingJsonPath;
|
||||
|
||||
var remaps = DataProvider.LoadMappingFile(MappingJsonPath);
|
||||
|
45
ReCodeItCLI/Commands/RegenerateSignature.cs
Normal file
45
ReCodeItCLI/Commands/RegenerateSignature.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using ReCodeItCLI.Utils;
|
||||
using ReCodeItLib.ReMapper;
|
||||
using ReCodeItLib.Utils;
|
||||
|
||||
namespace ReCodeItCLI.Commands;
|
||||
|
||||
[Command("regensig", Description = "regenerates the signature of a mapping if it is failing")]
|
||||
public class RegenerateSignature : CliFx.ICommand
|
||||
{
|
||||
[CommandParameter(0, IsRequired = true, Description = "The absolute path to the assembly you want to regenerate the signature for")]
|
||||
public required string AssemblyPath { get; init; }
|
||||
|
||||
[CommandParameter(1, IsRequired = true, Description = "The absolute path to mapping.json")]
|
||||
public required string MappingPath { get; init; }
|
||||
|
||||
[CommandParameter(2, IsRequired = true, Description = "Full old type name including namespace `Foo.Bar` for nested classes `Foo.Bar/FooBar`")]
|
||||
public required string OldTypeName { get; init; }
|
||||
|
||||
[CommandParameter(3, IsRequired = true, Description = "The new type name as listed in the mapping file")]
|
||||
public required string NewTypeName { get; init; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
Debugger.TryWaitForDebuggerAttach();
|
||||
|
||||
DataProvider.Settings.MappingPath = MappingPath;
|
||||
var remaps = DataProvider.LoadMappingFile(MappingPath);
|
||||
|
||||
var target = remaps.SingleOrDefault(r => r.NewTypeName == NewTypeName);
|
||||
|
||||
if (target is null)
|
||||
{
|
||||
Logger.LogSync("Could not find signature to regenerate", ConsoleColor.Red);
|
||||
return default;
|
||||
}
|
||||
|
||||
new AutoMatcher(remaps, MappingPath)
|
||||
.AutoMatch(AssemblyPath, OldTypeName, NewTypeName);
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>0.1.0</Version>
|
||||
<Version>1.0.0</Version>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<ServerGarbageCollection>true</ServerGarbageCollection>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
25
ReCodeItCLI/Utils/Debugger.cs
Normal file
25
ReCodeItCLI/Utils/Debugger.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.Diagnostics;
|
||||
using ReCodeItLib.Utils;
|
||||
|
||||
namespace ReCodeItCLI.Utils;
|
||||
|
||||
public static class Debugger
|
||||
{
|
||||
[Conditional("WAIT_FOR_DEBUGGER")]
|
||||
public static void TryWaitForDebuggerAttach()
|
||||
{
|
||||
const int maxDots = 3;
|
||||
var dotCount = 0;
|
||||
|
||||
while (!System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
var dots = new string('.', dotCount);
|
||||
|
||||
Console.Clear();
|
||||
Logger.LogSync($"Waiting for debugger{dots}");
|
||||
|
||||
dotCount = (dotCount + 1) % (maxDots + 1);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
# RecodeIt Command Line
|
||||
|
||||
This is the command line interface for ReCodeIt. It offers a streamlined way to operate the application without the
|
||||
use of the graphical user interface (GUI). It can be used to de-obfuscate, re-map, and other smaller utilities.
|
||||
It can be placed on the system path and accessed from anywhere.
|
||||
|
||||
## Commands
|
||||
|
||||
- `deobfuscate` - This command will run the de4dot de-obfuscater over the assembly provided. It supports both the
|
||||
primary game assembly and the launcher assembly.
|
||||
- Param `AssemblyPath` - The absolute path to your obfuscated assembly or exe file, the folder must contain all
|
||||
references needed to be resolved.
|
||||
- Param `IsLauncher` - Is the target the EFT launcher?
|
||||
|
||||
---
|
||||
|
||||
- `automatch` - This command will Automatically try to generate a mapping object given old type and new type names.
|
||||
- `AssemblyPath` - The absolute path to your assembly, folder must contain all references to be resolved.
|
||||
- `MappingsPath` - Path to your mapping file so it can be updated if a match is found.
|
||||
- `OldTypeName` - Full old type name including namespace.
|
||||
- `NewTypeName` - The name you want the type to be renamed to.
|
||||
|
||||
- This command will prompt you to append your created mapping to the mapping file.
|
||||
- It will then prompt you to run the remap process.
|
||||
|
||||
---
|
||||
|
||||
- `remap` - Generates a re-mapped dll provided a mapping file and dll. If the dll is obfuscated, it will automatically de-obfuscate.
|
||||
- Param `MappingJsonPath` - The absolute path to the `mapping.json` file supports both `json` and `jsonc`.
|
||||
- Param `AssemblyPath` - The absolute path to the dll generated from the `deobfuscate` command.
|
||||
|
||||
---
|
||||
|
||||
- `GenRefCountList` - Generates a print out of the most used classes. Useful to prioritize remap targets.
|
||||
- Param `AssemblyPath` - The absolute path to your de-obfuscated and remapped dll.
|
||||
|
||||
---
|
||||
|
||||
- `Dumper` - Generates a dumper zip.
|
||||
- Param `ManagedDirectory` - The absolute path to your Managed folder for EFT, folder must contain all references to
|
||||
be resolved. Assembly-CSharp-cleaned.dll, mscorlib.dll, FilesChecker.dll
|
23
RecodeIt.sln
23
RecodeIt.sln
@ -39,6 +39,7 @@ Global
|
||||
Release|ARM64 = Release|ARM64
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
WAIT_FOR_DEBUGGER|Any CPU = WAIT_FOR_DEBUGGER|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
@ -61,6 +62,8 @@ Global
|
||||
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Release|x86.Build.0 = Release|Any CPU
|
||||
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{FDA58DB6-E114-4FE0-AAF1-C3DEE44AEF99}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{E404EC0B-06D2-4964-8ABA-A634F259655C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E404EC0B-06D2-4964-8ABA-A634F259655C}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{E404EC0B-06D2-4964-8ABA-A634F259655C}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -81,6 +84,8 @@ Global
|
||||
{E404EC0B-06D2-4964-8ABA-A634F259655C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E404EC0B-06D2-4964-8ABA-A634F259655C}.Release|x86.Build.0 = Release|Any CPU
|
||||
{E404EC0B-06D2-4964-8ABA-A634F259655C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E404EC0B-06D2-4964-8ABA-A634F259655C}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{E404EC0B-06D2-4964-8ABA-A634F259655C}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{D0837899-F129-46DB-8BDB-7C9AFB72BD30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D0837899-F129-46DB-8BDB-7C9AFB72BD30}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{D0837899-F129-46DB-8BDB-7C9AFB72BD30}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -101,6 +106,8 @@ Global
|
||||
{D0837899-F129-46DB-8BDB-7C9AFB72BD30}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{D0837899-F129-46DB-8BDB-7C9AFB72BD30}.Release|x86.Build.0 = Release|Any CPU
|
||||
{D0837899-F129-46DB-8BDB-7C9AFB72BD30}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D0837899-F129-46DB-8BDB-7C9AFB72BD30}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{D0837899-F129-46DB-8BDB-7C9AFB72BD30}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{7C68B124-809B-4D4A-960B-467B2DAF2A0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7C68B124-809B-4D4A-960B-467B2DAF2A0A}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{7C68B124-809B-4D4A-960B-467B2DAF2A0A}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -120,6 +127,8 @@ Global
|
||||
{7C68B124-809B-4D4A-960B-467B2DAF2A0A}.Release|x64.Build.0 = Release|Any CPU
|
||||
{7C68B124-809B-4D4A-960B-467B2DAF2A0A}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{7C68B124-809B-4D4A-960B-467B2DAF2A0A}.Release|x86.Build.0 = Release|Any CPU
|
||||
{7C68B124-809B-4D4A-960B-467B2DAF2A0A}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{7C68B124-809B-4D4A-960B-467B2DAF2A0A}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{2BCD50E1-77D5-47E3-B317-04568BF051AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2BCD50E1-77D5-47E3-B317-04568BF051AB}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{2BCD50E1-77D5-47E3-B317-04568BF051AB}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -139,6 +148,8 @@ Global
|
||||
{2BCD50E1-77D5-47E3-B317-04568BF051AB}.Release|x64.Build.0 = Release|Any CPU
|
||||
{2BCD50E1-77D5-47E3-B317-04568BF051AB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{2BCD50E1-77D5-47E3-B317-04568BF051AB}.Release|x86.Build.0 = Release|Any CPU
|
||||
{2BCD50E1-77D5-47E3-B317-04568BF051AB}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{2BCD50E1-77D5-47E3-B317-04568BF051AB}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{C3C1267E-CDB9-4C47-B7F1-C929A6F2F31C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3C1267E-CDB9-4C47-B7F1-C929A6F2F31C}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{C3C1267E-CDB9-4C47-B7F1-C929A6F2F31C}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -158,6 +169,8 @@ Global
|
||||
{C3C1267E-CDB9-4C47-B7F1-C929A6F2F31C}.Release|x64.Build.0 = Release|Any CPU
|
||||
{C3C1267E-CDB9-4C47-B7F1-C929A6F2F31C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C3C1267E-CDB9-4C47-B7F1-C929A6F2F31C}.Release|x86.Build.0 = Release|Any CPU
|
||||
{C3C1267E-CDB9-4C47-B7F1-C929A6F2F31C}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{C3C1267E-CDB9-4C47-B7F1-C929A6F2F31C}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{CF1A1A5E-292B-42DE-AAA0-6801AD1AD407}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CF1A1A5E-292B-42DE-AAA0-6801AD1AD407}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{CF1A1A5E-292B-42DE-AAA0-6801AD1AD407}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -178,6 +191,8 @@ Global
|
||||
{CF1A1A5E-292B-42DE-AAA0-6801AD1AD407}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{CF1A1A5E-292B-42DE-AAA0-6801AD1AD407}.Release|x86.Build.0 = Release|Any CPU
|
||||
{CF1A1A5E-292B-42DE-AAA0-6801AD1AD407}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CF1A1A5E-292B-42DE-AAA0-6801AD1AD407}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{CF1A1A5E-292B-42DE-AAA0-6801AD1AD407}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{02FBA28C-E86C-49DC-8B44-A69CC542F693}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{02FBA28C-E86C-49DC-8B44-A69CC542F693}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{02FBA28C-E86C-49DC-8B44-A69CC542F693}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -197,6 +212,8 @@ Global
|
||||
{02FBA28C-E86C-49DC-8B44-A69CC542F693}.Release|x64.Build.0 = Release|Any CPU
|
||||
{02FBA28C-E86C-49DC-8B44-A69CC542F693}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{02FBA28C-E86C-49DC-8B44-A69CC542F693}.Release|x86.Build.0 = Release|Any CPU
|
||||
{02FBA28C-E86C-49DC-8B44-A69CC542F693}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{02FBA28C-E86C-49DC-8B44-A69CC542F693}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{8365D905-3BC4-42A0-B072-035598C6AF8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8365D905-3BC4-42A0-B072-035598C6AF8C}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{8365D905-3BC4-42A0-B072-035598C6AF8C}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -216,6 +233,8 @@ Global
|
||||
{8365D905-3BC4-42A0-B072-035598C6AF8C}.Release|x64.Build.0 = Release|Any CPU
|
||||
{8365D905-3BC4-42A0-B072-035598C6AF8C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{8365D905-3BC4-42A0-B072-035598C6AF8C}.Release|x86.Build.0 = Release|Any CPU
|
||||
{8365D905-3BC4-42A0-B072-035598C6AF8C}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{8365D905-3BC4-42A0-B072-035598C6AF8C}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{3D0F9399-7814-4EB9-8436-D56BA87F874C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3D0F9399-7814-4EB9-8436-D56BA87F874C}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{3D0F9399-7814-4EB9-8436-D56BA87F874C}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
@ -236,6 +255,8 @@ Global
|
||||
{3D0F9399-7814-4EB9-8436-D56BA87F874C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{3D0F9399-7814-4EB9-8436-D56BA87F874C}.Release|x86.Build.0 = Release|Any CPU
|
||||
{3D0F9399-7814-4EB9-8436-D56BA87F874C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3D0F9399-7814-4EB9-8436-D56BA87F874C}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{3D0F9399-7814-4EB9-8436-D56BA87F874C}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{55E928FA-93D2-410C-8AF6-C074C63D126B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{55E928FA-93D2-410C-8AF6-C074C63D126B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{55E928FA-93D2-410C-8AF6-C074C63D126B}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
@ -256,6 +277,8 @@ Global
|
||||
{55E928FA-93D2-410C-8AF6-C074C63D126B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{55E928FA-93D2-410C-8AF6-C074C63D126B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{55E928FA-93D2-410C-8AF6-C074C63D126B}.Release|x86.Build.0 = Release|Any CPU
|
||||
{55E928FA-93D2-410C-8AF6-C074C63D126B}.WAIT_FOR_DEBUGGER|Any CPU.ActiveCfg = WAIT_FOR_DEBUGGER|Any CPU
|
||||
{55E928FA-93D2-410C-8AF6-C074C63D126B}.WAIT_FOR_DEBUGGER|Any CPU.Build.0 = WAIT_FOR_DEBUGGER|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -5,11 +5,11 @@ public enum ENoMatchReason
|
||||
AmbiguousWithPreviousMatch,
|
||||
AmbiguousNewTypeNames,
|
||||
IsPublic,
|
||||
IsAbstract,
|
||||
IsEnum,
|
||||
IsNested,
|
||||
IsSealed,
|
||||
IsInterface,
|
||||
IsStruct,
|
||||
IsDerived,
|
||||
HasGenericParameters,
|
||||
HasAttribute,
|
||||
@ -26,6 +26,7 @@ public enum ENoMatchReason
|
||||
NestedTypeInclude,
|
||||
NestedTypeExclude,
|
||||
NestedTypeCount,
|
||||
NestedVisibility,
|
||||
EventsInclude,
|
||||
EventsExclude
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
namespace ReCodeItLib.Models;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ReCodeItLib.Models;
|
||||
|
||||
public class ItemTemplateModel
|
||||
{
|
||||
public string? _id;
|
||||
public string? _name;
|
||||
public string? _parent;
|
||||
public string? _type;
|
||||
[JsonPropertyName("_id")]
|
||||
public string? Id { get; set; }
|
||||
|
||||
[JsonPropertyName("_name")]
|
||||
public string? Name { get; set; }
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
using dnlib.DotNet;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using dnlib.DotNet;
|
||||
using ReCodeItLib.Enums;
|
||||
|
||||
namespace ReCodeItLib.Models;
|
||||
@ -15,7 +15,8 @@ public class RemapModel
|
||||
[JsonIgnore]
|
||||
public List<ENoMatchReason> NoMatchReasons { get; set; } = [];
|
||||
|
||||
[JsonIgnore] public string AmbiguousTypeMatch { get; set; } = string.Empty;
|
||||
[JsonIgnore]
|
||||
public string AmbiguousTypeMatch { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// This is a list of type candidates that made it through the filter
|
||||
@ -56,14 +57,12 @@ public class SearchParams
|
||||
public class GenericParams
|
||||
{
|
||||
public bool IsPublic { get; set; } = true;
|
||||
|
||||
public bool? IsAbstract { get; set; } = null;
|
||||
public bool? IsInterface { get; set; } = null;
|
||||
public bool? IsStruct { get; set; } = null;
|
||||
public bool? IsEnum { get; set; } = null;
|
||||
public bool? IsSealed { get; set; } = null;
|
||||
public bool IsAbstract { get; set; }
|
||||
public bool IsInterface { get; set; }
|
||||
public bool IsEnum { get; set; }
|
||||
public bool IsSealed { get; set; }
|
||||
public bool? HasAttribute { get; set; } = null;
|
||||
public bool? HasGenericParameters { get; set; } = null;
|
||||
public bool HasGenericParameters { get; set; }
|
||||
public bool? IsDerived { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
@ -97,6 +96,12 @@ public class PropertyParams
|
||||
public class NestedTypeParams
|
||||
{
|
||||
public bool IsNested { get; set; }
|
||||
public bool IsNestedAssembly { get; set; }
|
||||
public bool IsNestedFamily { get; set; }
|
||||
public bool IsNestedPrivate { get; set; }
|
||||
public bool IsNestedPublic { get; set; }
|
||||
public bool IsNestedFamilyAndAssembly { get; set; }
|
||||
public bool IsNestedFamilyOrAssembly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the nested types parent
|
||||
|
@ -3,14 +3,16 @@
|
||||
<PropertyGroup>
|
||||
<Version>0.1.0</Version>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<ServerGarbageCollection>true</ServerGarbageCollection>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dnlib" Version="4.4.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -22,12 +22,9 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||
out var module);
|
||||
|
||||
Module = module;
|
||||
CandidateTypes = Module.GetTypes()
|
||||
.Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token)))
|
||||
.ToList();
|
||||
|
||||
var targetTypeDef = FindTargetType(oldTypeName);
|
||||
|
||||
|
||||
if (targetTypeDef is null)
|
||||
{
|
||||
Logger.LogSync($"Could not target type: {oldTypeName}", ConsoleColor.Red);
|
||||
@ -36,9 +33,24 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||
|
||||
Logger.LogSync($"Found target type: {targetTypeDef!.FullName}", ConsoleColor.Green);
|
||||
|
||||
var remapModel = new RemapModel();
|
||||
remapModel.NewTypeName = newTypeName;
|
||||
remapModel.AutoGenerated = true;
|
||||
if (targetTypeDef.IsNested)
|
||||
{
|
||||
CandidateTypes = targetTypeDef.DeclaringType.NestedTypes
|
||||
.Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token)))
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
CandidateTypes = Module.Types
|
||||
.Where(t => TypesToMatch.Any(token => t.Name.StartsWith(token)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
var remapModel = new RemapModel()
|
||||
{
|
||||
NewTypeName = newTypeName,
|
||||
AutoGenerated = true
|
||||
};
|
||||
|
||||
StartFilter(targetTypeDef, remapModel, assemblyPath);
|
||||
}
|
||||
@ -57,36 +69,42 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||
{
|
||||
if (!PassesGeneralChecks(target, candidate, remapModel.SearchParams.GenericParams))
|
||||
{
|
||||
Logger.LogSync($"Candidate: {candidate.Name} filtered out after general checks", ConsoleColor.Yellow);
|
||||
CandidateTypes!.Remove(candidate);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ContainsTargetMethods(target, candidate, remapModel.SearchParams.Methods))
|
||||
{
|
||||
Logger.LogSync($"Candidate: {candidate.Name} filtered out after method checks", ConsoleColor.Yellow);
|
||||
CandidateTypes!.Remove(candidate);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ContainsTargetFields(target, candidate, remapModel.SearchParams.Fields))
|
||||
{
|
||||
Logger.LogSync($"Candidate: {candidate.Name} filtered out after field checks", ConsoleColor.Yellow);
|
||||
CandidateTypes!.Remove(candidate);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ContainsTargetProperties(target, candidate, remapModel.SearchParams.Properties))
|
||||
{
|
||||
Logger.LogSync($"Candidate: {candidate.Name} filtered out after property checks", ConsoleColor.Yellow);
|
||||
CandidateTypes!.Remove(candidate);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ContainsTargetNestedTypes(target, candidate, remapModel.SearchParams.NestedTypes))
|
||||
{
|
||||
Logger.LogSync($"Candidate: {candidate.Name} filtered out after nested checks", ConsoleColor.Yellow);
|
||||
CandidateTypes!.Remove(candidate);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ContainsTargetEvents(target, candidate, remapModel.SearchParams.Events))
|
||||
{
|
||||
Logger.LogSync($"Candidate: {candidate.Name} filtered out after event checks", ConsoleColor.Yellow);
|
||||
CandidateTypes!.Remove(candidate);
|
||||
}
|
||||
}
|
||||
@ -102,8 +120,11 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||
|
||||
new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true);
|
||||
|
||||
ProcessEndQuestions(remapModel, assemblyPath);
|
||||
return;
|
||||
if (remapModel.Succeeded)
|
||||
{
|
||||
ProcessEndQuestions(remapModel, assemblyPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.LogSync("Could not find a match... :(", ConsoleColor.Red);
|
||||
@ -125,7 +146,6 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||
parms.IsAbstract = target.IsAbstract;
|
||||
parms.IsInterface = target.IsInterface;
|
||||
parms.IsEnum = target.IsEnum;
|
||||
parms.IsStruct = target.IsValueType && !target.IsEnum;
|
||||
parms.HasGenericParameters = target.HasGenericParameters;
|
||||
parms.IsSealed = target.IsSealed;
|
||||
parms.HasAttribute = target.HasCustomAttributes;
|
||||
@ -183,7 +203,8 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||
methods.ConstructorParameterCount = target.Methods.First(m => m.IsConstructor && m.Parameters.Count > 0).Parameters.Count - 1;
|
||||
}
|
||||
|
||||
return commonMethods.Any();
|
||||
// True if we have common methods, or all methods are constructors
|
||||
return commonMethods.Any() || target.Methods.All(m => m.IsConstructor);
|
||||
}
|
||||
|
||||
private bool ContainsTargetFields(TypeDef target, TypeDef candidate, FieldParams fields)
|
||||
@ -294,13 +315,19 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||
|
||||
nt.NestedTypeCount = target.NestedTypes.Count;
|
||||
nt.IsNested = target.IsNested;
|
||||
|
||||
nt.IsNestedAssembly = target.IsNestedAssembly;
|
||||
nt.IsNestedFamily = target.IsNestedFamily;
|
||||
nt.IsNestedPrivate = target.IsNestedPrivate;
|
||||
nt.IsNestedPublic = target.IsNestedPublic;
|
||||
nt.IsNestedFamilyAndAssembly = target.IsNestedFamilyAndAssembly;
|
||||
nt.IsNestedFamilyOrAssembly = target.IsNestedFamilyOrAssembly;
|
||||
|
||||
if (target.DeclaringType is not null)
|
||||
{
|
||||
nt.NestedTypeParentName = target.DeclaringType.Name.String;
|
||||
}
|
||||
|
||||
return commonNts.Any() || !target.IsNested;
|
||||
return commonNts.Any() || target.NestedTypes.Count == 0;
|
||||
}
|
||||
|
||||
private bool ContainsTargetEvents(TypeDef target, TypeDef candidate, EventParams events)
|
||||
@ -376,7 +403,7 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||
}
|
||||
|
||||
mappings.Add(remapModel);
|
||||
DataProvider.UpdateMapping(mappingPath, mappings);
|
||||
DataProvider.UpdateMapping(mappingPath, mappings, false);
|
||||
}
|
||||
|
||||
Logger.LogSync("Would you like to run the remap process?... (y/n)", ConsoleColor.Yellow);
|
||||
|
@ -1,226 +0,0 @@
|
||||
using dnlib.DotNet;
|
||||
using ReCodeItLib.Models;
|
||||
|
||||
namespace ReCodeItLib.ReMapper.Filters;
|
||||
|
||||
internal static class GenericTypeFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Filters based on public, or nested public or private if the nested flag is set. This is a
|
||||
/// required property
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterPublic(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
// REQUIRED PROPERTY
|
||||
if (parms.GenericParams.IsPublic)
|
||||
{
|
||||
if (parms.NestedTypes.IsNested is true)
|
||||
{
|
||||
types = types.Where(t => t.IsNestedPublic);
|
||||
|
||||
types = FilterNestedByName(types, parms);
|
||||
}
|
||||
else
|
||||
{
|
||||
types = types.Where(t => t.IsPublic);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parms.NestedTypes.IsNested is true)
|
||||
{
|
||||
types = types.Where(t => t.IsNestedPrivate
|
||||
|| t.IsNestedFamily
|
||||
|| t.IsNestedFamilyAndAssembly
|
||||
|| t.IsNestedAssembly);
|
||||
|
||||
types = FilterNestedByName(types, parms);
|
||||
}
|
||||
else
|
||||
{
|
||||
types = types.Where(t => t.IsNotPublic);
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
private static IEnumerable<TypeDef> FilterNestedByName(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
if (parms.NestedTypes.NestedTypeParentName is not "")
|
||||
{
|
||||
types = types.Where(t => t.DeclaringType.Name.String == parms.NestedTypes.NestedTypeParentName);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on IsAbstract
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterAbstract(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
// Filter based on abstract or not
|
||||
if (parms.GenericParams.IsAbstract is true)
|
||||
{
|
||||
types = types.Where(t => t.IsAbstract && !t.IsInterface);
|
||||
}
|
||||
else if (parms.GenericParams.IsAbstract is false)
|
||||
{
|
||||
types = types.Where(t => !t.IsAbstract);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on IsAbstract
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterSealed(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
// Filter based on abstract or not
|
||||
if (parms.GenericParams.IsSealed is true)
|
||||
{
|
||||
types = types.Where(t => t.IsSealed);
|
||||
}
|
||||
else if (parms.GenericParams.IsSealed is false)
|
||||
{
|
||||
types = types.Where(t => !t.IsSealed);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on IsInterface
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterInterface(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
// Filter based on interface or not
|
||||
if (parms.GenericParams.IsInterface is true)
|
||||
{
|
||||
types = types.Where(t => t.IsInterface);
|
||||
}
|
||||
else if (parms.GenericParams.IsInterface is false)
|
||||
{
|
||||
types = types.Where(t => !t.IsInterface);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on IsStruct
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterStruct(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
if (parms.GenericParams.IsStruct is true)
|
||||
{
|
||||
types = types.Where(t => t.IsValueType && !t.IsEnum);
|
||||
}
|
||||
else if (parms.GenericParams.IsStruct is false)
|
||||
{
|
||||
types = types.Where(t => !t.IsValueType);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on IsEnum
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterEnum(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
// Filter based on enum or not
|
||||
if (parms.GenericParams.IsEnum is true)
|
||||
{
|
||||
types = types.Where(t => t.IsEnum);
|
||||
}
|
||||
else if (parms.GenericParams.IsEnum is false)
|
||||
{
|
||||
types = types.Where(t => !t.IsEnum);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on HasAttribute
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterAttributes(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
// Filter based on HasAttribute or not
|
||||
if (parms.GenericParams.HasAttribute is true)
|
||||
{
|
||||
types = types.Where(t => t.HasCustomAttributes);
|
||||
}
|
||||
else if (parms.GenericParams.HasAttribute is false)
|
||||
{
|
||||
types = types.Where(t => !t.HasCustomAttributes);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on HasAttribute
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterDerived(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
// Filter based on IsDerived or not
|
||||
if (parms.GenericParams.IsDerived is true)
|
||||
{
|
||||
types = types.Where(t => t.GetBaseType()?.Name?.String != "Object");
|
||||
|
||||
if (parms.GenericParams.MatchBaseClass is not null and not "")
|
||||
{
|
||||
types = types.Where(t => t.GetBaseType()?.Name?.String == parms.GenericParams.MatchBaseClass);
|
||||
}
|
||||
}
|
||||
else if (parms.GenericParams.IsDerived is false)
|
||||
{
|
||||
types = types.Where(t => t.GetBaseType()?.Name?.String is "Object");
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters based on method count
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns>Filtered list</returns>
|
||||
public static IEnumerable<TypeDef> FilterByGenericParameters(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
if (parms.GenericParams.HasGenericParameters is null) return types;
|
||||
|
||||
types = types.Where(t => t.HasGenericParameters == parms.GenericParams.HasGenericParameters);
|
||||
|
||||
return types;
|
||||
}
|
||||
}
|
@ -71,4 +71,32 @@ internal static class NestedTypeFilters
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
public static IEnumerable<TypeDef> FilterByNestedVisibility(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
types = FilterNestedByName(types, parms);
|
||||
|
||||
var ntp = parms.NestedTypes;
|
||||
|
||||
types = types.Where(t =>
|
||||
t.IsNestedAssembly == ntp.IsNestedAssembly
|
||||
&& t.IsNestedFamily == ntp.IsNestedFamily
|
||||
&& t.IsNestedPrivate == ntp.IsNestedPrivate
|
||||
&& t.IsNestedPublic == ntp.IsNestedPublic
|
||||
&& t.IsNestedFamilyAndAssembly == ntp.IsNestedFamilyAndAssembly
|
||||
&& t.IsNestedFamilyOrAssembly == ntp.IsNestedFamilyOrAssembly
|
||||
);
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
private static IEnumerable<TypeDef> FilterNestedByName(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
if (parms.NestedTypes.NestedTypeParentName is not "")
|
||||
{
|
||||
types = types.Where(t => t.DeclaringType.Name.String == parms.NestedTypes.NestedTypeParentName);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
}
|
@ -5,33 +5,7 @@ namespace ReCodeItLib.ReMapper;
|
||||
|
||||
internal class Publicizer
|
||||
{
|
||||
public void PublicizeClasses(ModuleDefMD definition, bool isLauncher = false)
|
||||
{
|
||||
var types = definition.GetTypes();
|
||||
|
||||
var publicizeTasks = new List<Task>();
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsNested) continue; // Nested types are handled when publicizing the parent type
|
||||
|
||||
publicizeTasks.Add(
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
PublicizeType(type, isLauncher);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: This is broken. No idea why.
|
||||
while (!publicizeTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
|
||||
{
|
||||
Logger.DrawProgressBar(publicizeTasks.Where(t => t.IsCompleted)!.Count() + 1, publicizeTasks.Count, 50);
|
||||
}
|
||||
|
||||
Task.WaitAll(publicizeTasks.ToArray());
|
||||
}
|
||||
|
||||
private static void PublicizeType(TypeDef type, bool isLauncher)
|
||||
public void PublicizeType(TypeDef type)
|
||||
{
|
||||
// if (type.CustomAttributes.Any(a => a.AttributeType.Name ==
|
||||
// nameof(CompilerGeneratedAttribute))) { return; }
|
||||
@ -45,7 +19,7 @@ internal class Publicizer
|
||||
}
|
||||
}
|
||||
|
||||
if (type.IsSealed && !isLauncher)
|
||||
if (type.IsSealed)
|
||||
{
|
||||
type.Attributes &= ~TypeAttributes.Sealed; // Remove the Sealed attribute if it exists
|
||||
}
|
||||
@ -63,7 +37,7 @@ internal class Publicizer
|
||||
|
||||
foreach (var nestedType in type.NestedTypes)
|
||||
{
|
||||
PublicizeType(nestedType, isLauncher);
|
||||
PublicizeType(nestedType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,15 +11,13 @@ namespace ReCodeItLib.ReMapper;
|
||||
public class ReMapper
|
||||
{
|
||||
private ModuleDefMD? Module { get; set; }
|
||||
|
||||
public static bool IsRunning { get; private set; } = false;
|
||||
|
||||
private static readonly Stopwatch Stopwatch = new();
|
||||
private string OutPath { get; set; } = string.Empty;
|
||||
|
||||
private List<RemapModel> _remaps = [];
|
||||
|
||||
private List<string> _alreadyGivenNames = [];
|
||||
private readonly List<string> _alreadyGivenNames = [];
|
||||
|
||||
/// <summary>
|
||||
/// Start the remapping process
|
||||
@ -30,9 +28,7 @@ public class ReMapper
|
||||
string outPath = "",
|
||||
bool validate = false)
|
||||
{
|
||||
_remaps = [];
|
||||
_remaps = remapModels;
|
||||
_alreadyGivenNames = [];
|
||||
|
||||
assemblyPath = AssemblyUtils.TryDeObfuscate(
|
||||
DataProvider.LoadModule(assemblyPath),
|
||||
@ -44,18 +40,18 @@ public class ReMapper
|
||||
OutPath = outPath;
|
||||
|
||||
if (!Validate(_remaps)) return;
|
||||
|
||||
IsRunning = true;
|
||||
|
||||
Stopwatch.Start();
|
||||
|
||||
var types = Module.GetTypes();
|
||||
|
||||
var typeDefs = types as TypeDef[] ?? types.ToArray();
|
||||
if (!validate)
|
||||
{
|
||||
GenerateDynamicRemaps(assemblyPath, types);
|
||||
GenerateDynamicRemaps(assemblyPath, typeDefs);
|
||||
}
|
||||
|
||||
FindBestMatches(types, validate);
|
||||
FindBestMatches(typeDefs, validate);
|
||||
ChooseBestMatches();
|
||||
|
||||
// Don't go any further during a validation
|
||||
@ -67,11 +63,8 @@ public class ReMapper
|
||||
return;
|
||||
}
|
||||
|
||||
RenameMatches(types);
|
||||
|
||||
RenameMatches(typeDefs);
|
||||
Publicize();
|
||||
|
||||
// We are done, write the assembly
|
||||
WriteAssembly();
|
||||
}
|
||||
|
||||
@ -92,9 +85,9 @@ public class ReMapper
|
||||
|
||||
if (!validate)
|
||||
{
|
||||
while (!tasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
|
||||
while (!tasks.TrueForAll(t => t.Status is TaskStatus.RanToCompletion or TaskStatus.Faulted))
|
||||
{
|
||||
Logger.DrawProgressBar(tasks.Where(t => t.IsCompleted)!.Count() + 1, tasks.Count, 50);
|
||||
Logger.DrawProgressBar(tasks.Count(t => t.IsCompleted), tasks.Count, 50);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,9 +111,9 @@ public class ReMapper
|
||||
);
|
||||
}
|
||||
|
||||
while (!renameTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
|
||||
while (!renameTasks.TrueForAll(t => t.Status is TaskStatus.RanToCompletion or TaskStatus.Faulted))
|
||||
{
|
||||
Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count() + 1, renameTasks.Count, 50);
|
||||
Logger.DrawProgressBar(renameTasks.Count(t => t.IsCompleted), renameTasks.Count, 50);
|
||||
}
|
||||
|
||||
Task.WaitAll(renameTasks.ToArray());
|
||||
@ -128,33 +121,51 @@ public class ReMapper
|
||||
|
||||
private void Publicize()
|
||||
{
|
||||
// Don't publicize and unseal until after the remapping, so we can use those as search parameters
|
||||
Logger.LogSync("\nPublicizing classes...", ConsoleColor.Green);
|
||||
|
||||
var publicizer = new Publicizer();
|
||||
|
||||
var publicizeTasks = new List<Task>(Module!.Types.Count(t => !t.IsNested));
|
||||
foreach (var type in Module!.Types)
|
||||
{
|
||||
if (type.IsNested) continue; // Nested types are handled when publicizing the parent type
|
||||
|
||||
publicizeTasks.Add(
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
publicizer.PublicizeType(type);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogSync($"Exception in task: {ex.Message}", ConsoleColor.Red);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
new Publicizer().PublicizeClasses(Module);
|
||||
Task.WaitAll(publicizeTasks.ToArray());
|
||||
}
|
||||
|
||||
private bool Validate(List<RemapModel> remaps)
|
||||
private static bool Validate(List<RemapModel> remaps)
|
||||
{
|
||||
var duplicateGroups = remaps
|
||||
.GroupBy(m => m.NewTypeName)
|
||||
.Where(g => g.Count() > 1)
|
||||
.ToList();
|
||||
|
||||
if (duplicateGroups.Count() > 1)
|
||||
if (duplicateGroups.Count <= 1) return true;
|
||||
|
||||
Logger.Log($"There were {duplicateGroups.Count} duplicated sets of remaps.", ConsoleColor.Yellow);
|
||||
|
||||
foreach (var duplicate in duplicateGroups)
|
||||
{
|
||||
Logger.Log($"There were {duplicateGroups.Count()} duplicated sets of remaps.", ConsoleColor.Yellow);
|
||||
|
||||
foreach (var duplicate in duplicateGroups)
|
||||
{
|
||||
var duplicateNewTypeName = duplicate.Key;
|
||||
Logger.Log($"Ambiguous NewTypeName: {duplicateNewTypeName} found. Cancelling Remap.", ConsoleColor.Red);
|
||||
}
|
||||
|
||||
return false;
|
||||
var duplicateNewTypeName = duplicate.Key;
|
||||
Logger.Log($"Ambiguous NewTypeName: {duplicateNewTypeName} found. Cancelling Remap.", ConsoleColor.Red);
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -162,9 +173,10 @@ public class ReMapper
|
||||
/// where null is a third disabled state. Then we score the types based on the search parameters
|
||||
/// </summary>
|
||||
/// <param name="mapping">Mapping to score</param>
|
||||
/// <param name="types">Types to filter</param>
|
||||
private void ScoreMapping(RemapModel mapping, IEnumerable<TypeDef> types)
|
||||
{
|
||||
var tokens = DataProvider.Settings?.TypeNamesToMatch;
|
||||
var tokens = DataProvider.Settings.TypeNamesToMatch;
|
||||
|
||||
if (mapping.UseForceRename)
|
||||
{
|
||||
@ -173,14 +185,13 @@ public class ReMapper
|
||||
}
|
||||
|
||||
// Filter down nested objects
|
||||
if (mapping.SearchParams.NestedTypes.IsNested is false)
|
||||
{
|
||||
types = types.Where(type => tokens!.Any(token => type.Name.StartsWith(token)));
|
||||
}
|
||||
types = !mapping.SearchParams.NestedTypes.IsNested
|
||||
? types.Where(type => tokens.Any(token => type.Name.StartsWith(token)))
|
||||
: types.Where(t => t.DeclaringType != null);
|
||||
|
||||
if (mapping.SearchParams.NestedTypes.NestedTypeParentName != string.Empty)
|
||||
{
|
||||
types = types.Where(t => t.DeclaringType != null && t.DeclaringType.Name == mapping.SearchParams.NestedTypes.NestedTypeParentName);
|
||||
types = types.Where(t => t.DeclaringType.Name == mapping.SearchParams.NestedTypes.NestedTypeParentName);
|
||||
}
|
||||
|
||||
// Run through a series of filters and report an error if all types are filtered out.
|
||||
@ -195,16 +206,15 @@ public class ReMapper
|
||||
{
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.Name == mapping.OriginalTypeName)
|
||||
{
|
||||
mapping.TypePrimeCandidate = type;
|
||||
mapping.OriginalTypeName = type.Name.String;
|
||||
mapping.Succeeded = true;
|
||||
if (type.Name != mapping.OriginalTypeName) continue;
|
||||
|
||||
mapping.TypePrimeCandidate = type;
|
||||
mapping.OriginalTypeName = type.Name.String;
|
||||
mapping.Succeeded = true;
|
||||
|
||||
_alreadyGivenNames.Add(mapping.OriginalTypeName);
|
||||
_alreadyGivenNames.Add(mapping.OriginalTypeName);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,23 +243,23 @@ public class ReMapper
|
||||
}
|
||||
|
||||
var typeTable = (Dictionary<string, Type>)templateMappingClass
|
||||
.GetField("TypeTable")
|
||||
.GetValue(templateMappingClass);
|
||||
.GetField("TypeTable")!
|
||||
.GetValue(templateMappingClass)!;
|
||||
|
||||
BuildAssociationFromTable(typeTable!, "ItemClass");
|
||||
BuildAssociationFromTable(typeTable, "ItemClass");
|
||||
|
||||
var templateTypeTable = (Dictionary<string, Type>)templateMappingClass
|
||||
.GetField("TemplateTypeTable")
|
||||
.GetValue(templateMappingClass);
|
||||
.GetField("TemplateTypeTable")!
|
||||
.GetValue(templateMappingClass)!;
|
||||
|
||||
BuildAssociationFromTable(templateTypeTable!, "TemplateClass");
|
||||
BuildAssociationFromTable(templateTypeTable, "TemplateClass");
|
||||
}
|
||||
|
||||
private void BuildAssociationFromTable(Dictionary<string, Type> table, string extName)
|
||||
{
|
||||
foreach (var type in table)
|
||||
{
|
||||
if (!DataProvider.ItemTemplates!.TryGetValue(type.Key, out var template) ||
|
||||
if (!DataProvider.ItemTemplates.TryGetValue(type.Key, out var template) ||
|
||||
!type.Value.Name.StartsWith("GClass"))
|
||||
{
|
||||
continue;
|
||||
@ -258,10 +268,10 @@ public class ReMapper
|
||||
var remap = new RemapModel
|
||||
{
|
||||
OriginalTypeName = type.Value.Name,
|
||||
NewTypeName = $"{template._name}{extName}",
|
||||
NewTypeName = $"{template.Name}{extName}",
|
||||
UseForceRename = true
|
||||
};
|
||||
|
||||
|
||||
_remaps.Add(remap);
|
||||
}
|
||||
}
|
||||
@ -315,7 +325,7 @@ public class ReMapper
|
||||
{
|
||||
var moduleName = Module?.Name;
|
||||
|
||||
var dllName = "-cleaned-remapped-publicized.dll";
|
||||
const string dllName = "-cleaned-remapped-publicized.dll";
|
||||
OutPath = Path.Combine(OutPath, moduleName?.Replace(".dll", dllName));
|
||||
|
||||
try
|
||||
@ -327,9 +337,8 @@ public class ReMapper
|
||||
Logger.LogSync(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
Logger.LogSync("\nCreating Hollow...", ConsoleColor.Green);
|
||||
Hollow();
|
||||
|
||||
StartHollow();
|
||||
|
||||
var hollowedDir = Path.GetDirectoryName(OutPath);
|
||||
var hollowedPath = Path.Combine(hollowedDir!, "Assembly-CSharp-hollowed.dll");
|
||||
@ -344,9 +353,9 @@ public class ReMapper
|
||||
throw;
|
||||
}
|
||||
|
||||
if (DataProvider.Settings?.MappingPath != string.Empty)
|
||||
if (DataProvider.Settings.MappingPath != string.Empty)
|
||||
{
|
||||
DataProvider.UpdateMapping(DataProvider.Settings!.MappingPath!.Replace("mappings.", "mappings-new."), _remaps);
|
||||
DataProvider.UpdateMapping(DataProvider.Settings.MappingPath.Replace("mappings.", "mappings-new."), _remaps);
|
||||
}
|
||||
|
||||
new Statistics(_remaps, Stopwatch, OutPath, hollowedPath)
|
||||
@ -354,24 +363,42 @@ public class ReMapper
|
||||
|
||||
Stopwatch.Reset();
|
||||
Module = null;
|
||||
|
||||
IsRunning = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hollows out all logic from the dll
|
||||
/// </summary>
|
||||
private void Hollow()
|
||||
private void StartHollow()
|
||||
{
|
||||
foreach (var type in Module!.GetTypes())
|
||||
Logger.LogSync("Creating Hollow...", ConsoleColor.Green);
|
||||
|
||||
var tasks = new List<Task>(Module!.GetTypes().Count());
|
||||
foreach (var type in Module.GetTypes())
|
||||
{
|
||||
foreach (var method in type.Methods.Where(m => m.HasBody))
|
||||
tasks.Add(Task.Run(() =>
|
||||
{
|
||||
if (!method.HasBody) continue;
|
||||
try
|
||||
{
|
||||
HollowType(type);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogSync($"Exception in task: {ex.Message}", ConsoleColor.Red);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
}
|
||||
|
||||
method.Body = new CilBody();
|
||||
method.Body.Instructions.Add(OpCodes.Ret.ToInstruction());
|
||||
}
|
||||
private void HollowType(TypeDef type)
|
||||
{
|
||||
foreach (var method in type.Methods.Where(m => m.HasBody))
|
||||
{
|
||||
if (!method.HasBody) continue;
|
||||
|
||||
method.Body = new CilBody();
|
||||
method.Body.Instructions.Add(OpCodes.Ret.ToInstruction());
|
||||
}
|
||||
}
|
||||
}
|
@ -7,34 +7,26 @@ namespace ReCodeItLib.ReMapper;
|
||||
internal class Renamer
|
||||
{
|
||||
private static List<string> TokensToMatch => DataProvider.Settings!.TypeNamesToMatch;
|
||||
|
||||
/// <summary>
|
||||
/// Only used by the manual remapper, should probably be removed
|
||||
/// </summary>
|
||||
/// <param name="module"></param>
|
||||
/// <param name="remap"></param>
|
||||
/// <param name="direct"></param>
|
||||
|
||||
public void RenameAll(IEnumerable<TypeDef> types, RemapModel remap)
|
||||
{
|
||||
if (remap.TypePrimeCandidate is null)
|
||||
{
|
||||
Logger.Log($"Unable to rename {remap.NewTypeName} as TypePrimeCandidate value is null/empty, skipping", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
if (remap.TypePrimeCandidate is null) return;
|
||||
|
||||
// Rename all fields and properties first
|
||||
var typesToCheck = types as TypeDef[] ?? types.ToArray();
|
||||
RenameAllFields(
|
||||
remap.TypePrimeCandidate.Name.String,
|
||||
remap.NewTypeName,
|
||||
types);
|
||||
typesToCheck);
|
||||
|
||||
RenameAllProperties(
|
||||
remap!.TypePrimeCandidate!.Name.String,
|
||||
remap.TypePrimeCandidate!.Name.String,
|
||||
remap.NewTypeName,
|
||||
types);
|
||||
typesToCheck);
|
||||
|
||||
FixMethods(types, remap);
|
||||
RenameType(types, remap);
|
||||
FixMethods(typesToCheck, remap);
|
||||
|
||||
remap.TypePrimeCandidate.Name = remap.NewTypeName;
|
||||
}
|
||||
|
||||
private static void FixMethods(
|
||||
@ -43,15 +35,17 @@ internal class Renamer
|
||||
{
|
||||
foreach (var type in typesToCheck)
|
||||
{
|
||||
var methods = type.Methods
|
||||
.Where(method => method.Name.StartsWith(remap!.TypePrimeCandidate!.Name.String)
|
||||
&& type.Methods.Count(m2 => m2.Name.String.EndsWith(method.Name.String.Split(".")[1])) < 2);
|
||||
List<MethodDef> methodsToFix = [];
|
||||
|
||||
methodsToFix.AddRange(
|
||||
from method in type.Methods where method.Name.StartsWith(remap.TypePrimeCandidate!.Name.String)
|
||||
let splitName = method.Name.String.Split(".") where splitName.Length != 1 select method);
|
||||
|
||||
foreach (var method in methods)
|
||||
foreach (var method in methodsToFix)
|
||||
{
|
||||
var name = method.Name.String.Split(".");
|
||||
|
||||
if (methods.Count(m => m.Name.String.EndsWith(name[1])) > 1)
|
||||
if (methodsToFix.Count(m => m.Name.String.EndsWith(name[1])) > 1)
|
||||
continue;
|
||||
|
||||
method.Name = name[1];
|
||||
@ -59,43 +53,35 @@ internal class Renamer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rename all fields recursively, returns number of fields changed
|
||||
/// </summary>
|
||||
/// <param name="oldTypeName"></param>
|
||||
/// <param name="newTypeName"></param>
|
||||
/// <param name="typesToCheck"></param>
|
||||
private static void RenameAllFields(
|
||||
|
||||
string oldTypeName,
|
||||
string newTypeName,
|
||||
IEnumerable<TypeDef> typesToCheck)
|
||||
{
|
||||
foreach (var type in typesToCheck)
|
||||
var typeDefs = typesToCheck as TypeDef[] ?? typesToCheck.ToArray();
|
||||
foreach (var type in typeDefs)
|
||||
{
|
||||
var fields = type.Fields
|
||||
.Where(field => field.Name.IsFieldOrPropNameInList(TokensToMatch!));
|
||||
|
||||
if (!fields.Any()) { continue; }
|
||||
|
||||
int fieldCount = 0;
|
||||
.Where(field => field.Name.IsFieldOrPropNameInList(TokensToMatch));
|
||||
|
||||
var fieldCount = 0;
|
||||
foreach (var field in fields)
|
||||
{
|
||||
if (field.FieldType.TypeName == oldTypeName)
|
||||
{
|
||||
var newFieldName = GetNewFieldName(newTypeName, fieldCount);
|
||||
if (field.FieldType.TypeName != oldTypeName) continue;
|
||||
|
||||
var newFieldName = GetNewFieldName(newTypeName, fieldCount);
|
||||
|
||||
// Dont need to do extra work
|
||||
if (field.Name == newFieldName) { continue; }
|
||||
// Dont need to do extra work
|
||||
if (field.Name == newFieldName) { continue; }
|
||||
|
||||
var oldName = field.Name.ToString();
|
||||
var oldName = field.Name.ToString();
|
||||
|
||||
field.Name = newFieldName;
|
||||
field.Name = newFieldName;
|
||||
|
||||
UpdateAllTypeFieldMemberRefs(typesToCheck, field, oldName);
|
||||
UpdateAllTypeFieldMemberRefs(typeDefs, field, oldName);
|
||||
|
||||
fieldCount++;
|
||||
}
|
||||
fieldCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,12 +110,6 @@ internal class Renamer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rename all properties recursively, returns number of fields changed
|
||||
/// </summary>
|
||||
/// <param name="oldTypeName"></param>
|
||||
/// <param name="newTypeName"></param>
|
||||
/// <param name="typesToCheck"></param>
|
||||
private static void RenameAllProperties(
|
||||
string oldTypeName,
|
||||
string newTypeName,
|
||||
@ -138,61 +118,34 @@ internal class Renamer
|
||||
foreach (var type in typesToCheck)
|
||||
{
|
||||
var properties = type.Properties
|
||||
.Where(prop => prop.Name.IsFieldOrPropNameInList(TokensToMatch!));
|
||||
|
||||
if (!properties.Any()) { continue; }
|
||||
|
||||
int propertyCount = 0;
|
||||
.Where(prop => prop.Name.IsFieldOrPropNameInList(TokensToMatch));
|
||||
|
||||
var propertyCount = 0;
|
||||
foreach (var property in properties)
|
||||
{
|
||||
if (property.PropertySig.RetType.TypeName == oldTypeName)
|
||||
{
|
||||
var newPropertyName = GetNewPropertyName(newTypeName, propertyCount);
|
||||
if (property.PropertySig.RetType.TypeName != oldTypeName) continue;
|
||||
|
||||
var newPropertyName = GetNewPropertyName(newTypeName, propertyCount);
|
||||
|
||||
// Dont need to do extra work
|
||||
if (property.Name == newPropertyName) { continue; }
|
||||
// Dont need to do extra work
|
||||
if (property.Name == newPropertyName) continue;
|
||||
|
||||
property.Name = new UTF8String(newPropertyName);
|
||||
property.Name = newPropertyName;
|
||||
|
||||
propertyCount++;
|
||||
}
|
||||
propertyCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetNewFieldName(string NewName, int fieldCount = 0)
|
||||
private static string GetNewFieldName(string newName, int fieldCount = 0)
|
||||
{
|
||||
string newFieldCount = fieldCount > 0 ? $"_{fieldCount}" : string.Empty;
|
||||
var newFieldCount = fieldCount > 0 ? $"_{fieldCount}" : string.Empty;
|
||||
|
||||
return $"{char.ToLower(NewName[0])}{NewName[1..]}{newFieldCount}";
|
||||
return $"{char.ToLower(newName[0])}{newName[1..]}{newFieldCount}";
|
||||
}
|
||||
|
||||
private static string GetNewPropertyName(string newName, int propertyCount = 0)
|
||||
{
|
||||
return propertyCount > 0 ? $"{newName}_{propertyCount}" : newName;
|
||||
}
|
||||
|
||||
private static void RenameType(IEnumerable<TypeDef> typesToCheck, RemapModel remap)
|
||||
{
|
||||
foreach (var type in typesToCheck)
|
||||
{
|
||||
if (type.HasNestedTypes)
|
||||
{
|
||||
RenameType(type.NestedTypes, remap!);
|
||||
}
|
||||
|
||||
if (remap?.TypePrimeCandidate?.Name is null) { continue; }
|
||||
|
||||
if (remap.SearchParams.NestedTypes.IsNested is true &&
|
||||
type.IsNested && type.Name == remap.TypePrimeCandidate.Name)
|
||||
{
|
||||
type.Name = remap.NewTypeName;
|
||||
}
|
||||
|
||||
if (type.FullName == remap.TypePrimeCandidate.Name)
|
||||
{
|
||||
type.Name = remap.NewTypeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -53,27 +53,31 @@ public class Statistics(
|
||||
|
||||
foreach (var remap in remapModels)
|
||||
{
|
||||
if (remap.Succeeded is false && remap.NoMatchReasons.Contains(ENoMatchReason.AmbiguousWithPreviousMatch))
|
||||
switch (remap.Succeeded)
|
||||
{
|
||||
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
|
||||
Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red);
|
||||
Logger.Log($"New Type Name: {remap.NewTypeName}", ConsoleColor.Red);
|
||||
Logger.Log($"{remap.AmbiguousTypeMatch} already assigned to a previous match.", ConsoleColor.Red);
|
||||
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
|
||||
}
|
||||
else if (remap.Succeeded is false)
|
||||
{
|
||||
Logger.Log("-----------------------------------------------", ConsoleColor.Red);
|
||||
Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red);
|
||||
|
||||
foreach (var reason in remap.NoMatchReasons)
|
||||
case false when remap.NoMatchReasons.Contains(ENoMatchReason.AmbiguousWithPreviousMatch):
|
||||
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
|
||||
Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red);
|
||||
Logger.Log($"New Type Name: {remap.NewTypeName}", ConsoleColor.Red);
|
||||
Logger.Log($"{remap.AmbiguousTypeMatch} already assigned to a previous match.", ConsoleColor.Red);
|
||||
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
|
||||
|
||||
failures++;
|
||||
break;
|
||||
case false:
|
||||
{
|
||||
Logger.Log($"Reason: {reason}", ConsoleColor.Red);
|
||||
}
|
||||
Logger.Log("-----------------------------------------------", ConsoleColor.Red);
|
||||
Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red);
|
||||
|
||||
Logger.Log("-----------------------------------------------", ConsoleColor.Red);
|
||||
failures++;
|
||||
continue;
|
||||
foreach (var reason in remap.NoMatchReasons)
|
||||
{
|
||||
Logger.Log($"Reason: {reason}", ConsoleColor.Red);
|
||||
}
|
||||
|
||||
Logger.Log("-----------------------------------------------", ConsoleColor.Red);
|
||||
failures++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (validate && remap.Succeeded)
|
||||
|
@ -22,83 +22,76 @@ public class TypeFilters
|
||||
|
||||
private static bool FilterTypesByGeneric(RemapModel mapping, ref IEnumerable<TypeDef> types)
|
||||
{
|
||||
types = GenericTypeFilters.FilterPublic(types, mapping.SearchParams);
|
||||
var parms = mapping.SearchParams;
|
||||
|
||||
types = types.Where(t => t.IsPublic == parms.GenericParams.IsPublic);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.IsPublic);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = GenericTypeFilters.FilterAbstract(types, mapping.SearchParams);
|
||||
types = types.Where(t => t.IsAbstract == parms.GenericParams.IsAbstract);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsPublic);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.IsAbstract);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = GenericTypeFilters.FilterSealed(types, mapping.SearchParams);
|
||||
types = types.Where(t => t.IsSealed == parms.GenericParams.IsSealed);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsSealed);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.IsSealed);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = types.Where(t => t.IsInterface == parms.GenericParams.IsInterface);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AddNoMatchReason(mapping, ENoMatchReason.IsInterface);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = GenericTypeFilters.FilterInterface(types, mapping.SearchParams);
|
||||
types = types.Where(t => t.IsEnum == parms.GenericParams.IsEnum);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsInterface);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.IsEnum);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = GenericTypeFilters.FilterStruct(types, mapping.SearchParams);
|
||||
types = FilterAttributes(types, mapping.SearchParams);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsStruct);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.HasAttribute);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = GenericTypeFilters.FilterEnum(types, mapping.SearchParams);
|
||||
types = FilterDerived(types, mapping.SearchParams);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsEnum);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.IsDerived);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = GenericTypeFilters.FilterAttributes(types, mapping.SearchParams);
|
||||
types = types.Where(t => t.HasGenericParameters == parms.GenericParams.HasGenericParameters);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.HasAttribute);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = GenericTypeFilters.FilterDerived(types, mapping.SearchParams);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.IsDerived);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = GenericTypeFilters.FilterByGenericParameters(types, mapping.SearchParams);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.HasGenericParameters);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.HasGenericParameters);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -112,7 +105,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsInclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.MethodsInclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -121,7 +114,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsExclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.MethodsExclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -130,7 +123,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.MethodsCount);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.MethodsCount);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -139,7 +132,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.ConstructorParameterCount);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.ConstructorParameterCount);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -153,7 +146,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsInclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.FieldsInclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -162,7 +155,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsExclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.FieldsExclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -171,7 +164,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.FieldsCount);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.FieldsCount);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -185,7 +178,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesInclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.PropertiesInclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -194,7 +187,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesExclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.PropertiesExclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -203,7 +196,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.PropertiesCount);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.PropertiesCount);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -217,7 +210,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeInclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.NestedTypeInclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -226,7 +219,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeExclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.NestedTypeExclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -235,7 +228,16 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.NestedTypeCount);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.NestedTypeCount);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
|
||||
types = NestedTypeFilters.FilterByNestedVisibility(types, mapping.SearchParams);
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AddNoMatchReason(mapping, ENoMatchReason.NestedVisibility);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -249,7 +251,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsInclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.EventsInclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -258,7 +260,7 @@ public class TypeFilters
|
||||
|
||||
if (!types.Any())
|
||||
{
|
||||
AllTypesFilteredOutFor(mapping, ENoMatchReason.EventsExclude);
|
||||
AddNoMatchReason(mapping, ENoMatchReason.EventsExclude);
|
||||
mapping.TypeCandidates.UnionWith(types);
|
||||
return false;
|
||||
}
|
||||
@ -266,13 +268,43 @@ public class TypeFilters
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used to log that all types for a given remap were filtered out.
|
||||
/// </summary>
|
||||
/// <param name="remap">remap model that failed</param>
|
||||
/// <param name="noMatchReason">Reason for filtering</param>
|
||||
private static void AllTypesFilteredOutFor(RemapModel remap, ENoMatchReason noMatchReason)
|
||||
private static IEnumerable<TypeDef> FilterAttributes(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
Logger.Log($"All types filtered out after `{noMatchReason}` filter for: `{remap.NewTypeName}`", ConsoleColor.Red);
|
||||
// Filter based on HasAttribute or not
|
||||
if (parms.GenericParams.HasAttribute is true)
|
||||
{
|
||||
types = types.Where(t => t.HasCustomAttributes);
|
||||
}
|
||||
else if (parms.GenericParams.HasAttribute is false)
|
||||
{
|
||||
types = types.Where(t => !t.HasCustomAttributes);
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
private static IEnumerable<TypeDef> FilterDerived(IEnumerable<TypeDef> types, SearchParams parms)
|
||||
{
|
||||
// Filter based on IsDerived or not
|
||||
if (parms.GenericParams.IsDerived is true)
|
||||
{
|
||||
types = types.Where(t => t.GetBaseType()?.Name?.String != "Object");
|
||||
|
||||
if (parms.GenericParams.MatchBaseClass is not null and not "")
|
||||
{
|
||||
types = types.Where(t => t.GetBaseType()?.Name?.String == parms.GenericParams.MatchBaseClass);
|
||||
}
|
||||
}
|
||||
else if (parms.GenericParams.IsDerived is false)
|
||||
{
|
||||
types = types.Where(t => t.GetBaseType()?.Name?.String is "Object");
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
private static void AddNoMatchReason(RemapModel remap, ENoMatchReason noMatchReason)
|
||||
{
|
||||
remap.NoMatchReasons.Add(noMatchReason);
|
||||
}
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
using dnlib.DotNet;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using dnlib.DotNet;
|
||||
using Newtonsoft.Json;
|
||||
using ReCodeItLib.Models;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace ReCodeItLib.Utils;
|
||||
|
||||
@ -27,26 +30,33 @@ public static class DataProvider
|
||||
}
|
||||
|
||||
var jsonText = File.ReadAllText(path);
|
||||
|
||||
var remaps = JsonConvert.DeserializeObject<List<RemapModel>>(jsonText);
|
||||
|
||||
JsonSerializerOptions settings = new()
|
||||
{
|
||||
AllowTrailingCommas = true,
|
||||
};
|
||||
|
||||
var remaps = JsonSerializer.Deserialize<List<RemapModel>>(jsonText, settings);
|
||||
|
||||
return remaps ?? [];
|
||||
}
|
||||
|
||||
public static void UpdateMapping(string path, List<RemapModel> remaps)
|
||||
public static void UpdateMapping(string path, List<RemapModel> remaps, bool respectNullableAnnotations = true)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
File.Create(path).Close();
|
||||
}
|
||||
|
||||
JsonSerializerSettings settings = new()
|
||||
JsonSerializerOptions settings = new()
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
Formatting = Formatting.Indented
|
||||
WriteIndented = true,
|
||||
RespectNullableAnnotations = !respectNullableAnnotations,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
};
|
||||
|
||||
var jsonText = JsonConvert.SerializeObject(remaps, settings);
|
||||
var jsonText = JsonSerializer.Serialize(remaps, settings);
|
||||
|
||||
File.WriteAllText(path, jsonText);
|
||||
|
||||
@ -73,7 +83,12 @@ public static class DataProvider
|
||||
var settingsPath = Path.Combine(DataPath, "Settings.jsonc");
|
||||
var jsonText = File.ReadAllText(settingsPath);
|
||||
|
||||
return JsonConvert.DeserializeObject<Settings>(jsonText);
|
||||
JsonSerializerOptions settings = new()
|
||||
{
|
||||
AllowTrailingCommas = true,
|
||||
};
|
||||
|
||||
return JsonSerializer.Deserialize<Settings>(jsonText, settings)!;
|
||||
}
|
||||
|
||||
private static Dictionary<string, ItemTemplateModel> LoadItems()
|
||||
@ -81,6 +96,12 @@ public static class DataProvider
|
||||
var itemsPath = Path.Combine(DataPath, "items.json");
|
||||
var jsonText = File.ReadAllText(itemsPath);
|
||||
|
||||
return JsonConvert.DeserializeObject<Dictionary<string, ItemTemplateModel>>(jsonText);
|
||||
JsonSerializerOptions settings = new()
|
||||
{
|
||||
RespectNullableAnnotations = true,
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
return JsonSerializer.Deserialize<Dictionary<string, ItemTemplateModel>>(jsonText, settings)!;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using ReCodeItLib.Models;
|
||||
|
||||
namespace ReCodeItLib.Utils;
|
||||
@ -123,12 +124,13 @@ public static class Logger
|
||||
|
||||
public static void LogRemapModel(RemapModel remapModel)
|
||||
{
|
||||
var settings = new JsonSerializerSettings()
|
||||
JsonSerializerOptions settings = new()
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
WriteIndented = true,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
};
|
||||
|
||||
var str = JsonConvert.SerializeObject(remapModel, Formatting.Indented, settings);
|
||||
var str = JsonSerializer.Serialize(remapModel, settings);
|
||||
LogSync(str, ConsoleColor.Blue);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\De4DotCommon.props" />
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -5,6 +5,8 @@
|
||||
<PropertyGroup>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<OutputType>Exe</OutputType>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -6,6 +6,8 @@
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,5 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\De4DotCommon.props" />
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,5 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="..\De4DotCommon.props" />
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Configurations>Debug;Release;WAIT_FOR_DEBUGGER</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user