Add validation button

This commit is contained in:
Cj 2024-06-28 16:17:54 -04:00
parent 99e64e5e36
commit 8df90f628a
5 changed files with 588 additions and 416 deletions

File diff suppressed because it is too large Load Diff

View File

@ -255,21 +255,14 @@ public partial class ReCodeItForm : Form
_isSearched = false;
}
/// <summary>
/// Construct a new remap when the button is pressed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddRemapButton_Click(object sender, EventArgs e)
private RemapModel? CreateRemapFromGUI()
{
if (NewTypeName.Text == string.Empty)
{
MessageBox.Show("Please enter a new type name", "Invalid data");
return;
return null;
}
ResetSearchButton_Click(this, e);
var newRemap = new RemapModel
{
Succeeded = false,
@ -341,6 +334,22 @@ public partial class ReCodeItForm : Form
}
};
return newRemap;
}
/// <summary>
/// Construct a new remap when the button is pressed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddRemapButton_Click(object sender, EventArgs e)
{
ResetSearchButton_Click(this, e);
var newRemap = CreateRemapFromGUI();
if (newRemap is null) return;
bool projectMode = AppSettings.Remapper.UseProjectMappings;
Logger.Log(projectMode);
@ -467,6 +476,23 @@ public partial class ReCodeItForm : Form
ReloadRemapTreeView(DataProvider.Remaps);
}
private void ValidateRemapButton_Click(object sender, EventArgs e)
{
List<RemapModel> validation = [];
var remapToValidate = CreateRemapFromGUI();
if (remapToValidate is null) return;
validation.Add(remapToValidate);
Remapper.InitializeRemap(
validation,
AppSettings.Remapper.AssemblyPath,
AppSettings.Remapper.OutputPath,
validate: true);
}
/// <summary>
/// Only used by the manual remap process, not apart of the cross compiler process
/// </summary>

View File

@ -117,8 +117,11 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
<metadata name="groupBox6.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="groupBox7.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>

View File

@ -18,8 +18,4 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="DeMangler\" />
</ItemGroup>
</Project>

View File

@ -19,7 +19,7 @@ public class ReCodeItRemapper
public ReCodeItRemapper()
{ }
private ModuleDefMD Module { get; set; }
private ModuleDefMD? Module { get; set; }
private readonly ReCodeItCrossCompiler _compiler;
@ -48,7 +48,8 @@ public class ReCodeItRemapper
List<RemapModel> remapModels,
string assemblyPath,
string outPath,
bool crossMapMode = false)
bool crossMapMode = false,
bool validate = false)
{
_remaps = [];
_remaps = remapModels;
@ -79,6 +80,13 @@ public class ReCodeItRemapper
ChooseBestMatches();
// Don't go any further during a validation
if (validate)
{
DisplayEndBanner(validate: true);
return;
}
var renameTasks = new List<Task>(remapModels.Count);
foreach (var remap in remapModels)
{
@ -171,9 +179,9 @@ public class ReCodeItRemapper
}
/// <summary>
/// Choose best match from a collection of scores, then start the renaming process
/// Choose best match from a collection of types on a remap
/// </summary>
/// <param name="scores">Scores to rate</param>
/// <param name="remap"></param>
private void ChooseBestMatch(RemapModel remap)
{
if (remap.TypeCandidates.Count == 0) { return; }
@ -229,6 +237,7 @@ public class ReCodeItRemapper
}
Stopwatch.Reset();
Module = null;
IsRunning = false;
OnComplete?.Invoke();
@ -251,7 +260,7 @@ public class ReCodeItRemapper
}
}
private void DisplayEndBanner(string hollowedPath)
private void DisplayEndBanner(string hollowedPath = "", bool validate = false)
{
var failures = 0;
var changes = 0;
@ -294,10 +303,14 @@ public class ReCodeItRemapper
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
Logger.Log($"Result renamed {changes} Types. Failed to rename {failures} Types", ConsoleColor.Green);
if (!validate)
{
Logger.Log($"Assembly written to `{OutPath}`", ConsoleColor.Green);
Logger.Log($"Hollowed written to `{hollowedPath}`", ConsoleColor.Green);
Logger.Log($"Remap took {Stopwatch.Elapsed.TotalSeconds:F1} seconds", ConsoleColor.Green);
}
}
private void DisplayAlternativeMatches(RemapModel remap)
{