From 69bc87dab917b0c1942dc6c313a56248ef7ca351 Mon Sep 17 00:00:00 2001 From: Herp Derpinstine Date: Sun, 30 Jun 2024 23:47:48 -0600 Subject: [PATCH] Fixed an issue with Preload module not replacing Mono libraries on Older Mono Games --- .../SupportModules/Preload/Preload.cs | 28 ++-- .../SupportModules/Preload/Preload.csproj | 16 ++- .../Preload/Properties/Resources.Designer.cs | 93 +++++++++++++ .../Preload/Properties/Resources.resx | 130 ++++++++++++++++++ 4 files changed, 246 insertions(+), 21 deletions(-) create mode 100644 Dependencies/SupportModules/Preload/Properties/Resources.Designer.cs create mode 100644 Dependencies/SupportModules/Preload/Properties/Resources.resx diff --git a/Dependencies/SupportModules/Preload/Preload.cs b/Dependencies/SupportModules/Preload/Preload.cs index b2cdf505..1e0c30c6 100644 --- a/Dependencies/SupportModules/Preload/Preload.cs +++ b/Dependencies/SupportModules/Preload/Preload.cs @@ -15,30 +15,24 @@ private static void Initialize() string managedFolder = string.Copy(GetManagedDirectory()); - string systemPath = Path.Combine(managedFolder, "System.dll"); - if (!File.Exists(systemPath)) - WriteResource("System.dll", systemPath); - - string systemCorePath = Path.Combine(managedFolder, "System.Core.dll"); - if (!File.Exists(systemCorePath)) - WriteResource("System.Core.dll", systemCorePath); - - string systemDrawingPath = Path.Combine(managedFolder, "System.Drawing.dll"); - if (!File.Exists(systemDrawingPath)) - WriteResource("System.Drawing.dll", systemDrawingPath); + WriteResource(Properties.Resources.System, Path.Combine(managedFolder, "System.dll")); + WriteResource(Properties.Resources.System_Core, Path.Combine(managedFolder, "System.Core.dll")); + WriteResource(Properties.Resources.System_Drawing, Path.Combine(managedFolder, "System.Drawing.dll")); } [MethodImpl(MethodImplOptions.InternalCall)] [return: MarshalAs(UnmanagedType.LPStr)] private static extern string GetManagedDirectory(); - private static void WriteResource(string name, string destination) + private static void WriteResource(byte[] data, string destination) { - var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MelonLoader.Support.Resources." + name); - var fileStream = new FileStream(destination, FileMode.CreateNew); - for (int i = 0; i < stream!.Length; i++) - fileStream.WriteByte((byte)stream.ReadByte()); - fileStream.Close(); + try + { + if (File.Exists(destination)) + File.Delete(destination); + File.WriteAllBytes(destination, data); + } + catch { } } } } \ No newline at end of file diff --git a/Dependencies/SupportModules/Preload/Preload.csproj b/Dependencies/SupportModules/Preload/Preload.csproj index 10d6b853..0c79f1cc 100644 --- a/Dependencies/SupportModules/Preload/Preload.csproj +++ b/Dependencies/SupportModules/Preload/Preload.csproj @@ -17,14 +17,22 @@ - + - - - + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + \ No newline at end of file diff --git a/Dependencies/SupportModules/Preload/Properties/Resources.Designer.cs b/Dependencies/SupportModules/Preload/Properties/Resources.Designer.cs new file mode 100644 index 00000000..d7760797 --- /dev/null +++ b/Dependencies/SupportModules/Preload/Properties/Resources.Designer.cs @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MelonLoader.Support.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MelonLoader.Support.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] System { + get { + object obj = ResourceManager.GetObject("System", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] System_Core { + get { + object obj = ResourceManager.GetObject("System.Core", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] System_Drawing { + get { + object obj = ResourceManager.GetObject("System.Drawing", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/Dependencies/SupportModules/Preload/Properties/Resources.resx b/Dependencies/SupportModules/Preload/Properties/Resources.resx new file mode 100644 index 00000000..a2b6ad7b --- /dev/null +++ b/Dependencies/SupportModules/Preload/Properties/Resources.resx @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\System.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\System.Core.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\System.Drawing.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file