diff --git a/RecodeItLib/CrossCompiler/ProjectManager.cs b/RecodeItLib/CrossCompiler/ProjectManager.cs index 6b2ab45..5891f72 100644 --- a/RecodeItLib/CrossCompiler/ProjectManager.cs +++ b/RecodeItLib/CrossCompiler/ProjectManager.cs @@ -1,4 +1,6 @@ -using Newtonsoft.Json; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Newtonsoft.Json; using ReCodeIt.Models; using ReCodeIt.Utils; @@ -9,6 +11,8 @@ public static class ProjectManager public static CrossCompilerProjectModel ActiveProject { get; private set; } private static CrossCompilerSettings Settings => DataProvider.Settings.CrossCompiler; + public static List AllProjectSourceFiles { get; private set; } = []; + public static void CreateProject( string OrigAssemblyPath, string RemappedAssemblyOutputPath, @@ -51,6 +55,7 @@ public static class ProjectManager { ActiveProject = LoadCrossCompilerProjModel(path); CopyVisualStudioProject(ActiveProject); + LoadVSProjectFromClone(); Logger.Log($"Found and Loaded ReCodeIt Project at {path}"); } @@ -139,7 +144,7 @@ public static class ProjectManager DataProvider.Settings.CrossCompiler.LastLoadedProject = path; DataProvider.SaveAppSettings(); - Logger.Log($"Cross Compiler project json generated to {path}", ConsoleColor.Green); + Logger.Log($"Cross Compiler project json saved to {path}", ConsoleColor.Green); } private static CrossCompilerProjectModel LoadCrossCompilerProjModel(string path) @@ -160,4 +165,36 @@ public static class ProjectManager return model!; } + + private static void LoadVSProjectFromClone() + { + var path = Path.Combine( + DataProvider.ReCodeItProjectsPath, + ActiveProject.SolutionName); + + // Find all the source files in the project, we dont want anything from the obj folder. + AllProjectSourceFiles = Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories) + .Where(file => !file.Contains(Path.DirectorySeparatorChar + "obj" + Path.DirectorySeparatorChar)) + .ToList(); + + Logger.Log($"Found {AllProjectSourceFiles.Count} source files in the project", ConsoleColor.Yellow); + } + + private static void AnalyzeSyntaxTree(SyntaxNode root) + { + // Example: Find all method declarations + var methodDeclarations = root.DescendantNodes().OfType(); + + foreach (var method in methodDeclarations) + { + Logger.Log($"Method: {method.Identifier.Text}"); + Logger.Log($"Return Type: {method.ReturnType}"); + Logger.Log("Parameters:"); + foreach (var parameter in method.ParameterList.Parameters) + { + Logger.Log($" {parameter.Type} {parameter.Identifier}"); + } + Logger.Log(string.Empty); + } + } } \ No newline at end of file diff --git a/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs b/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs index 25eb14f..5fa7bba 100644 --- a/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs +++ b/RecodeItLib/CrossCompiler/ReCodeItCrossCompiler.cs @@ -1,4 +1,7 @@ -using ReCodeIt.Models; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using ReCodeIt.Models; using ReCodeIt.ReMapper; using ReCodeIt.Utils; @@ -55,6 +58,45 @@ public class ReCodeItCrossCompiler public void StartCrossCompile() { - //CopyVisualStudioProject(); + AnalyzeSourceFiles(); + } + + private void AnalyzeSourceFiles() + { + foreach (var file in ProjectManager.AllProjectSourceFiles) + { + AnalyzeSourcefile(file); + } + } + + private void AnalyzeSourcefile(string file) + { + var source = LoadSourceFile(file); + var syntaxTree = CSharpSyntaxTree.ParseText(source); + var root = syntaxTree.GetCompilationUnitRoot(); + + var identifiers = root.DescendantNodes() + .OfType() + .Where(id => ActiveProject.ChangedTypes.ContainsKey(id.Identifier.Text)); + + if (!identifiers.Any()) { return; } + + Logger.Log($"found {identifiers.Count()} objects to change in file {Path.GetFileNameWithoutExtension(file)}"); + + // Replace "RigClass" with "NewRigClass" + var newRoot = root.ReplaceNodes(identifiers, (oldNode, newNode) => + SyntaxFactory.IdentifierName(ActiveProject.ChangedTypes[oldNode.Identifier.Text]) + .WithLeadingTrivia(oldNode.GetLeadingTrivia()) + .WithTrailingTrivia(oldNode.GetTrailingTrivia())); + } + + /// + /// Loads a source file from disk + /// + /// + /// + private string LoadSourceFile(string path) + { + return File.ReadAllText(path); } } \ No newline at end of file diff --git a/RecodeItLib/ReCodeItLib.csproj b/RecodeItLib/ReCodeItLib.csproj index de044f1..701e648 100644 --- a/RecodeItLib/ReCodeItLib.csproj +++ b/RecodeItLib/ReCodeItLib.csproj @@ -8,6 +8,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RecodeItLib/Remapper/ReCodeItRemapper.cs b/RecodeItLib/Remapper/ReCodeItRemapper.cs index 914de3c..f8550f7 100644 --- a/RecodeItLib/Remapper/ReCodeItRemapper.cs +++ b/RecodeItLib/Remapper/ReCodeItRemapper.cs @@ -34,6 +34,8 @@ public class ReCodeItRemapper private bool CrossMapMode { get; set; } = false; + private string AssemblyPath { get; set; } + /// /// Start the remapping process /// @@ -45,6 +47,7 @@ public class ReCodeItRemapper { DataProvider.LoadAssemblyDefinition(assemblyPath); + AssemblyPath = assemblyPath; CrossMapMode = crossMapMode; OutPath = outPath; @@ -275,7 +278,12 @@ public class ReCodeItRemapper /// private void WriteAssembly() { - var path = DataProvider.WriteAssemblyDefinition(OutPath); + var fileName = Path.GetFileName(AssemblyPath); + var path = Path.Combine(OutPath, fileName); + + Logger.Log(fileName); + + path = DataProvider.WriteAssemblyDefinition(path); Logger.Log("-----------------------------------------------", ConsoleColor.Green); Logger.Log($"Complete: Assembly written to `{path}`", ConsoleColor.Green); diff --git a/RecodeItLib/Utils/DataProvider.cs b/RecodeItLib/Utils/DataProvider.cs index ca76906..50a6e2f 100644 --- a/RecodeItLib/Utils/DataProvider.cs +++ b/RecodeItLib/Utils/DataProvider.cs @@ -194,20 +194,10 @@ public static class DataProvider Logger.Log($"Module {fileName} not found in assembly {fileName}"); } - public static string WriteAssemblyDefinition(string path, string filename = "") + public static string WriteAssemblyDefinition(string path) { - filename = filename != string.Empty - ? filename - : Path.GetFileNameWithoutExtension(path) + "-Remapped.dll"; + AssemblyDefinition.Write(path); - var strippedPath = Path.GetDirectoryName(path); - - var remappedPath = Path.Combine(strippedPath!, filename); - - AssemblyDefinition.Write(remappedPath); - - Logger.Log($"Writing Assembly {filename} to path {remappedPath}"); - - return remappedPath; + return path; } } \ No newline at end of file