commit 6ec193961b8192e9d377908ab093e4f3cd3ea375 Author: bmgjet <50484759+bmgjet@users.noreply.github.com> Date: Fri Mar 8 20:33:05 2024 +1300 Upload diff --git a/.vs/HarmonyUpgrader/FileContentIndex/070070d1-bf48-408b-b2d2-e0cc41abdcd4.vsidx b/.vs/HarmonyUpgrader/FileContentIndex/070070d1-bf48-408b-b2d2-e0cc41abdcd4.vsidx new file mode 100644 index 0000000..cb6240f Binary files /dev/null and b/.vs/HarmonyUpgrader/FileContentIndex/070070d1-bf48-408b-b2d2-e0cc41abdcd4.vsidx differ diff --git a/.vs/HarmonyUpgrader/v17/.suo b/.vs/HarmonyUpgrader/v17/.suo new file mode 100644 index 0000000..89cfc3c Binary files /dev/null and b/.vs/HarmonyUpgrader/v17/.suo differ diff --git a/HarmonyUpgrader.sln b/HarmonyUpgrader.sln new file mode 100644 index 0000000..d1e1304 --- /dev/null +++ b/HarmonyUpgrader.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34112.27 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HarmonyUpgrader", "HarmonyUpgrader\HarmonyUpgrader.csproj", "{C959B646-1189-428B-9AEA-6DAD8DF98FF0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C959B646-1189-428B-9AEA-6DAD8DF98FF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C959B646-1189-428B-9AEA-6DAD8DF98FF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C959B646-1189-428B-9AEA-6DAD8DF98FF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C959B646-1189-428B-9AEA-6DAD8DF98FF0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1552512E-ECA2-42AC-BE3E-24C5F56A0AF2} + EndGlobalSection +EndGlobal diff --git a/HarmonyUpgrader/App.config b/HarmonyUpgrader/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/HarmonyUpgrader/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HarmonyUpgrader/HarmonyUpgrader.csproj b/HarmonyUpgrader/HarmonyUpgrader.csproj new file mode 100644 index 0000000..69d6cff --- /dev/null +++ b/HarmonyUpgrader/HarmonyUpgrader.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {C959B646-1189-428B-9AEA-6DAD8DF98FF0} + Exe + HarmonyUpgrader + HarmonyUpgrader + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\..\..\marchstagingbranch\RustDedicated_Data\Managed\Mono.Cecil.dll + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HarmonyUpgrader/Program.cs b/HarmonyUpgrader/Program.cs new file mode 100644 index 0000000..19994fe --- /dev/null +++ b/HarmonyUpgrader/Program.cs @@ -0,0 +1,183 @@ +using Mono.Cecil; +using System; +using System.IO; +namespace HarmonyUpgrader +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine(string.Concat(new string[] + { + " .-'''-. ", + System.Environment.NewLine, + " ' _ \\ .-''-. ..-'''-. ", + System.Environment.NewLine, + " . __ __ ___ / /` '. \\ _..._ .' .-. ) \\.-'''\\ \\ ", + System.Environment.NewLine, + " .'| | |/ `.' `. . | \\ ' .' '..-. .- / .' / / | | ", + System.Environment.NewLine, + "< | .-,.--. | .-. .-. '| ' | '. .-. .\\ \\ / /(_/ / / __/ / ", + System.Environment.NewLine, + " | | __ | .-. || | | | | |\\ \\ / / | ' ' | \\ \\ / / / / |_ '. ", + System.Environment.NewLine, + " | | .'''-. .:--.'. | | | || | | | | | `. ` ..' / | | | | \\ \\ / / / / `. \\ ", + System.Environment.NewLine, + " | |/.'''. \\ / | \\ | | | | || | | | | | '-...-'` | | | | \\ \\ / / . ' \\ '. ", + System.Environment.NewLine, + " | / | | `\" __ | | | | '- | | | | | | | | | | \\ ` / / / _.-'),.--. , | ", + System.Environment.NewLine, + " | | | | .'.''| | | | |__| |__| |__| | | | | \\ / .' ' _.'.-''// \\ | | ", + System.Environment.NewLine, + " | | | | / / | |_| | | | | | / / / /.-'_.' \\ / / ,' ", + System.Environment.NewLine, + " | '. | '.\\ \\._,\\ '/|_| | | | | |`-' / / _.' `'--'-....--' / ", + System.Environment.NewLine, + " '---' '---'`--' `\" '--' '--' '..' ( _.-' `.. __..-' ", + System.Environment.NewLine, + System.Environment.NewLine, + "Upgrader by bmgjet", + })); + if (args.Length <= 0) + { + Console.WriteLine("File not found, Drop .cs or .dll on this exe"); + Console.ReadKey(); + return; + } + string InputFile = args[0]; + Console.WriteLine("Opening " + InputFile); + if (File.Exists(InputFile)) + { + if (InputFile.EndsWith(".dll")) + { + CheckHarmonyDlls(new FileInfo(InputFile)); + Console.WriteLine("Dll Upgraded"); + Console.ReadKey(); + return; + } + else if (InputFile.EndsWith(".cs")) + { + CheckOxidePlugins(new FileInfo(InputFile)); + Console.WriteLine(".cs Upgraded"); + Console.ReadKey(); + return; + } + else + { + Console.WriteLine("Must Be .cs or .dll file"); + Console.ReadKey(); + return; + } + } + Console.WriteLine("File not found, Drop .cs or .dll on this exe"); + Console.ReadKey(); + } + + #region Functions + private static void CheckHarmonyDlls(FileInfo file) + { + if (file == null) { return; } + ModuleDefinition asm = ModuleDefinition.ReadModule(file.FullName); //Read dll assembly + try + { + //Check version + AssemblyDefinition a = asm.Assembly; + for (int i = a.MainModule.AssemblyReferences.Count - 1; i >= 0; i--) + { + if (a.MainModule.AssemblyReferences[i].Name == "0Harmony" && a.MainModule.AssemblyReferences[i].Version.ToString() == "1.2.0.1") + { + //Change version number + a.MainModule.AssemblyReferences[i].Version = new Version(2, 3, 0, 0); + Console.WriteLine("Found Harmony V1.2 dll " + file.Name + " Creating Back Up As " + file.Name.Replace(".dll", ".V1_2") + " And Upgrading."); + //Update Referece + foreach (var MetaData in asm.GetMemberReferences()) + { + if (MetaData.FullName.Contains("HarmonyPatch") || MetaData.FullName.Contains("HarmonyPrefix") || MetaData.FullName.Contains("HarmonyPostfix") || MetaData.FullName.Contains("HarmonyTranspiler")) + { + MetaData.FullName.Replace("Harmony.", "HarmonyLib."); + } + } + + //Update Name Spaces + foreach (var moduleDefinition in a.Modules) + { + foreach (var typeDefinition in moduleDefinition.Types) + { + if (typeDefinition.Namespace == "Harmony") { typeDefinition.Namespace = "HarmonyLib"; } + } + foreach (var TypeReferences in moduleDefinition.GetTypeReferences()) + { + if (TypeReferences.Namespace == "Harmony") { TypeReferences.Namespace = "HarmonyLib"; } + } + } + asm.Write(file.FullName.Replace(".dll", "modded.dll")); //Save as modded version + asm.Dispose(); //Close opened dll + File.Move(file.FullName, file.FullName.Replace(".dll", ".V1_2")); //Create back up of orignal dll + File.Move(file.FullName.Replace(".dll", "modded.dll"), file.FullName); //Rename modded dll to orignals name + break; + } + } + } + catch + { + //Something went wrong + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Failed To Process: " + file.FullName); + Console.ForegroundColor = ConsoleColor.Magenta; + } + if (asm != null) { asm.Dispose(); } //Close dll + } + + private static void CheckOxidePlugins(FileInfo file) + { + if (file == null) { return; } + bool Upgraded = false; + string[] PluginSRC = File.ReadAllLines(file.FullName); //Read all plugin lines + for (int i = PluginSRC.Length - 1; i >= 0; i--) //Check each line and upgrade any harmony init code + { + if (PluginSRC[i] == "using Harmony;") + { + Upgraded = true; + PluginSRC[i] = "using HarmonyLib;"; + } + if (PluginSRC[i].Contains("HarmonyInstance")) + { + Upgraded = true; + PluginSRC[i] = PluginSRC[i].Replace("HarmonyInstance", "Harmony"); + } + if (PluginSRC[i].Contains("HarmonyInstance.Create")) + { + Upgraded = true; + PluginSRC[i] = PluginSRC[i].Replace("HarmonyInstance.Create", "new HarmonyLib.Harmony"); + string[] getname = PluginSRC[i].Split('='); + if (getname.Length == 2) + { + PluginSRC[i] += System.Environment.NewLine + getname[0].TrimEnd() + ".PatchAll();"; + } + } + if (PluginSRC[i].Contains("Harmony.Create")) + { + Upgraded = true; + PluginSRC[i] = PluginSRC[i].Replace("Harmony.Create", "new HarmonyLib.Harmony"); + string[] getname = PluginSRC[i].Split('='); + if (getname.Length == 2) + { + PluginSRC[i] += System.Environment.NewLine + getname[0].TrimEnd() + ".PatchAll();"; + } + } + if (PluginSRC[i].Contains("PatchProcessor")) + { + Upgraded = true; + PluginSRC[i] = ""; + } + } + if (Upgraded) + { + Console.WriteLine("Found Oxide Harmony V1.2 plugin " + file.Name + " Saving Backup And Creating Patched Version."); + File.Copy(file.FullName, file.FullName.Replace(".cs", ".old")); + File.WriteAllLines(file.FullName, PluginSRC); + } + } + #endregion + } +} \ No newline at end of file diff --git a/HarmonyUpgrader/Properties/AssemblyInfo.cs b/HarmonyUpgrader/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e13b994 --- /dev/null +++ b/HarmonyUpgrader/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("HarmonyUpgrader")] +[assembly: AssemblyDescription("Upgrades Plugins")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("bmgjet")] +[assembly: AssemblyProduct("HarmonyUpgrader")] +[assembly: AssemblyCopyright("Copyright © bmgjet 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c959b646-1189-428b-9aea-6dad8df98ff0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/HarmonyUpgrader/bin/Release/HarmonyUpgrader.exe b/HarmonyUpgrader/bin/Release/HarmonyUpgrader.exe new file mode 100644 index 0000000..ee16756 Binary files /dev/null and b/HarmonyUpgrader/bin/Release/HarmonyUpgrader.exe differ diff --git a/HarmonyUpgrader/bin/Release/Mono.Cecil.dll b/HarmonyUpgrader/bin/Release/Mono.Cecil.dll new file mode 100644 index 0000000..9b78a39 Binary files /dev/null and b/HarmonyUpgrader/bin/Release/Mono.Cecil.dll differ