diff --git a/BSIPA.sln b/BSIPA.sln index 548da4f3..34c5c3a7 100644 --- a/BSIPA.sln +++ b/BSIPA.sln @@ -5,18 +5,18 @@ VisualStudioVersion = 15.0.27428.2043 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPA", "IPA\IPA.csproj", "{14092533-98BB-40A4-9AFC-27BB75672A70}" ProjectSection(ProjectDependencies) = postProject - {D1C61AF5-0D2D-4752-8203-1C6929025F7C} = {D1C61AF5-0D2D-4752-8203-1C6929025F7C} - {E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71} = {E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71} + {5AD344F0-01A0-4CA8-92E5-9D095737744D} = {5AD344F0-01A0-4CA8-92E5-9D095737744D} + {2A1AF16B-27F1-46E0-9A95-181516BC1CB7} = {2A1AF16B-27F1-46E0-9A95-181516BC1CB7} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IllusionPlugin", "IllusionPlugin\IllusionPlugin.csproj", "{E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IllusionInjector", "IllusionInjector\IllusionInjector.csproj", "{D1C61AF5-0D2D-4752-8203-1C6929025F7C}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPA.Tests", "IPA.Tests\IPA.Tests.csproj", "{C66092B0-5C1E-44E9-B524-E0E8E1425379}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSBuildTasks", "MSBuildTasks\MSBuildTasks.csproj", "{F08C3C7A-3221-432E-BAB8-32BCE58408C8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPA.Loader", "IPA.Loader\IPA.Loader.csproj", "{5AD344F0-01A0-4CA8-92E5-9D095737744D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPA.Injector", "IPA.Injector\IPA.Injector.csproj", "{2A1AF16B-27F1-46E0-9A95-181516BC1CB7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,14 +27,6 @@ Global {14092533-98BB-40A4-9AFC-27BB75672A70}.Debug|Any CPU.Build.0 = Debug|Any CPU {14092533-98BB-40A4-9AFC-27BB75672A70}.Release|Any CPU.ActiveCfg = Release|Any CPU {14092533-98BB-40A4-9AFC-27BB75672A70}.Release|Any CPU.Build.0 = Release|Any CPU - {E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71}.Release|Any CPU.Build.0 = Release|Any CPU - {D1C61AF5-0D2D-4752-8203-1C6929025F7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D1C61AF5-0D2D-4752-8203-1C6929025F7C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D1C61AF5-0D2D-4752-8203-1C6929025F7C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D1C61AF5-0D2D-4752-8203-1C6929025F7C}.Release|Any CPU.Build.0 = Release|Any CPU {C66092B0-5C1E-44E9-B524-E0E8E1425379}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C66092B0-5C1E-44E9-B524-E0E8E1425379}.Debug|Any CPU.Build.0 = Debug|Any CPU {C66092B0-5C1E-44E9-B524-E0E8E1425379}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -43,6 +35,14 @@ Global {F08C3C7A-3221-432E-BAB8-32BCE58408C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {F08C3C7A-3221-432E-BAB8-32BCE58408C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {F08C3C7A-3221-432E-BAB8-32BCE58408C8}.Release|Any CPU.Build.0 = Release|Any CPU + {5AD344F0-01A0-4CA8-92E5-9D095737744D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5AD344F0-01A0-4CA8-92E5-9D095737744D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5AD344F0-01A0-4CA8-92E5-9D095737744D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5AD344F0-01A0-4CA8-92E5-9D095737744D}.Release|Any CPU.Build.0 = Release|Any CPU + {2A1AF16B-27F1-46E0-9A95-181516BC1CB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A1AF16B-27F1-46E0-9A95-181516BC1CB7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A1AF16B-27F1-46E0-9A95-181516BC1CB7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A1AF16B-27F1-46E0-9A95-181516BC1CB7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/IPA.Injector/Bootstrapper.cs b/IPA.Injector/Bootstrapper.cs new file mode 100644 index 00000000..1d0f2261 --- /dev/null +++ b/IPA.Injector/Bootstrapper.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace IPA.Injector +{ + class Bootstrapper : MonoBehaviour + { + public event Action Destroyed = delegate {}; + + void Awake() + { + //if (Environment.CommandLine.Contains("--verbose")) + //{ + Ipa.Injector.Windows.WinConsole.Initialize(); + //} + } + + void Start() + { + Destroy(gameObject); + } + void OnDestroy() + { + Destroyed(); + } + } +} diff --git a/IPA.Injector/ConsoleWindow.cs b/IPA.Injector/ConsoleWindow.cs new file mode 100644 index 00000000..1121d765 --- /dev/null +++ b/IPA.Injector/ConsoleWindow.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections; +using System.Runtime.InteropServices; +using System.IO; +using System.Text; +using Microsoft.Win32.SafeHandles; + +namespace Ipa.Injector.Windows +{ + // https://stackoverflow.com/a/48864902/3117125 + static class WinConsole + { + static public void Initialize(bool alwaysCreateNewConsole = true) + { + bool consoleAttached = true; + if (alwaysCreateNewConsole + || (AttachConsole(ATTACH_PARRENT) == 0 + && Marshal.GetLastWin32Error() != ERROR_ACCESS_DENIED)) + { + consoleAttached = AllocConsole() != 0; + } + + if (consoleAttached) + { + InitializeOutStream(); + InitializeInStream(); + } + } + + private static void InitializeOutStream() + { + var fs = CreateFileStream("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, FileAccess.Write); + if (fs != null) + { + var writer = new StreamWriter(fs) { AutoFlush = true }; + Console.SetOut(writer); + Console.SetError(writer); + } + } + + private static void InitializeInStream() + { + var fs = CreateFileStream("CONIN$", GENERIC_READ, FILE_SHARE_READ, FileAccess.Read); + if (fs != null) + { + Console.SetIn(new StreamReader(fs)); + } + } + + private static FileStream CreateFileStream(string name, uint win32DesiredAccess, uint win32ShareMode, + FileAccess dotNetFileAccess) + { + var file = new SafeFileHandle(CreateFileW(name, win32DesiredAccess, win32ShareMode, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero), true); + if (!file.IsInvalid) + { + var fs = new FileStream(file, dotNetFileAccess); + return fs; + } + return null; + } + + #region Win API Functions and Constants + [DllImport("kernel32.dll", + EntryPoint = "AllocConsole", + SetLastError = true, + CharSet = CharSet.Auto, + CallingConvention = CallingConvention.StdCall)] + private static extern int AllocConsole(); + + [DllImport("kernel32.dll", + EntryPoint = "AttachConsole", + SetLastError = true, + CharSet = CharSet.Auto, + CallingConvention = CallingConvention.StdCall)] + private static extern UInt32 AttachConsole(UInt32 dwProcessId); + + [DllImport("kernel32.dll", + EntryPoint = "CreateFileW", + SetLastError = true, + CharSet = CharSet.Auto, + CallingConvention = CallingConvention.StdCall)] + private static extern IntPtr CreateFileW( + string lpFileName, + UInt32 dwDesiredAccess, + UInt32 dwShareMode, + IntPtr lpSecurityAttributes, + UInt32 dwCreationDisposition, + UInt32 dwFlagsAndAttributes, + IntPtr hTemplateFile + ); + + private const UInt32 GENERIC_WRITE = 0x40000000; + private const UInt32 GENERIC_READ = 0x80000000; + private const UInt32 FILE_SHARE_READ = 0x00000001; + private const UInt32 FILE_SHARE_WRITE = 0x00000002; + private const UInt32 OPEN_EXISTING = 0x00000003; + private const UInt32 FILE_ATTRIBUTE_NORMAL = 0x80; + private const UInt32 ERROR_ACCESS_DENIED = 5; + + private const UInt32 ATTACH_PARRENT = 0xFFFFFFFF; + + #endregion + } +} \ No newline at end of file diff --git a/IPA.Injector/IPA.Injector.csproj b/IPA.Injector/IPA.Injector.csproj new file mode 100644 index 00000000..e8e044a1 --- /dev/null +++ b/IPA.Injector/IPA.Injector.csproj @@ -0,0 +1,82 @@ + + + + + Debug + AnyCPU + {2A1AF16B-27F1-46E0-9A95-181516BC1CB7} + Library + Properties + IPA.Injector + IPA.Injector + v4.6 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + False + ..\..\..\..\..\..\Game Library\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll + False + + + + + + + + + + + {5ad344f0-01a0-4ca8-92e5-9d095737744d} + IPA.Loader + + + + + Libraries\Included\0Harmony.dll + Always + + + Libraries\Mono\I18N.dll + Always + + + Libraries\Mono\I18N.West.dll + Always + + + Libraries\Mono\System.Runtime.Serialization.dll + Always + + + + + + + \ No newline at end of file diff --git a/IllusionInjector/Injector.cs b/IPA.Injector/Injector.cs similarity index 57% rename from IllusionInjector/Injector.cs rename to IPA.Injector/Injector.cs index d70a6ec6..a36e2cb0 100644 --- a/IllusionInjector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -1,49 +1,63 @@ -using System; -using System.IO; -using System.Reflection; -using UnityEngine; - -namespace IllusionInjector -{ - public static class Injector - { - private static bool injected = false; - public static void Inject() - { - if (!injected) - { - injected = true; - AppDomain.CurrentDomain.AssemblyResolve += AssemblyLibLoader; - var bootstrapper = new GameObject("Bootstrapper").AddComponent(); - bootstrapper.Destroyed += Bootstrapper_Destroyed; - } - } - - private static string libsDir; - private static Assembly AssemblyLibLoader(object source, ResolveEventArgs e) - { - if (libsDir == null) - libsDir = Path.Combine(Environment.CurrentDirectory, "Libs"); - - var asmName = new AssemblyName(e.Name); - //Logger.log.Debug($"Resolving library {asmName}"); - - var testFilen = Path.Combine(libsDir, $"{asmName.Name}.{asmName.Version}.dll"); - //Logger.log.Debug($"Looking for file {testFilen}"); - - if (File.Exists(testFilen)) - { - return Assembly.LoadFile(testFilen); - } - - //Logger.log.Error($"Could not load library {asmName}"); - - return null; - } - - private static void Bootstrapper_Destroyed() - { - PluginComponent.Create(); - } - } -} +using IPA.Loader; +using IPA.Logging; +using System; +using System.IO; +using System.Reflection; +using UnityEngine; +using static IPA.Logging.Logger; +using Logger = IPA.Logging.Logger; + +namespace IPA.Injector +{ + public static class Injector + { + private static bool injected = false; + public static void Inject() + { + if (!injected) + { + injected = true; + AppDomain.CurrentDomain.AssemblyResolve += AssemblyLibLoader; + var bootstrapper = new GameObject("Bootstrapper").AddComponent(); + bootstrapper.Destroyed += Bootstrapper_Destroyed; + } + } + + private static string libsDir; + private static Assembly AssemblyLibLoader(object source, ResolveEventArgs e) + { + if (libsDir == null) + libsDir = Path.Combine(Environment.CurrentDirectory, "Libs"); + + var asmName = new AssemblyName(e.Name); + Log(Level.Debug, $"Resolving library {asmName}"); + + var testFilen = Path.Combine(libsDir, $"{asmName.Name}.{asmName.Version}.dll"); + Log(Level.Debug, $"Looking for file {testFilen}"); + + if (File.Exists(testFilen)) + return Assembly.LoadFile(testFilen); + + Log(Level.Critical, $"Could not load library {asmName}"); + + return null; + } + private static void Log(Level lvl, string message) + { // multiple proxy methods to delay loading of assemblies until it's done + if (Logger.LogCreated) + AssemblyLibLoaderCallLogger(lvl, message); + else + if (((byte)lvl & (byte)StandardLogger.PrintFilter) != 0) + Console.WriteLine($"[{lvl}] {message}"); + } + private static void AssemblyLibLoaderCallLogger(Level lvl, string message) + { + Logger.log.Log(lvl, message); + } + + private static void Bootstrapper_Destroyed() + { + PluginComponent.Create(); + } + } +} diff --git a/IllusionInjector/PostBuild.msbuild b/IPA.Injector/PostBuild.msbuild similarity index 73% rename from IllusionInjector/PostBuild.msbuild rename to IPA.Injector/PostBuild.msbuild index 72841a21..20f1fccb 100644 --- a/IllusionInjector/PostBuild.msbuild +++ b/IPA.Injector/PostBuild.msbuild @@ -10,22 +10,22 @@ - - - - + + + - + - + - + + diff --git a/IllusionInjector/Properties/AssemblyInfo.cs b/IPA.Injector/Properties/AssemblyInfo.cs similarity index 64% rename from IllusionInjector/Properties/AssemblyInfo.cs rename to IPA.Injector/Properties/AssemblyInfo.cs index e967a81a..bae971d5 100644 --- a/IllusionInjector/Properties/AssemblyInfo.cs +++ b/IPA.Injector/Properties/AssemblyInfo.cs @@ -1,40 +1,37 @@ -using System.Resources; -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("IllusionInjector")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("IllusionInjector")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[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("400a540a-d21f-4609-966b-206059b6e73b")] -[assembly: InternalsVisibleTo("IllusionPlugin")] - -// 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")] -[assembly: NeutralResourcesLanguage("en")] - +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("IPA.Injector")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IPA.Injector")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[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("2a1af16b-27f1-46e0-9a95-181516bc1cb7")] +[assembly: InternalsVisibleTo("IPA.Loader")] + +// 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("3.9.0")] +[assembly: AssemblyFileVersion("3.9.0")] diff --git a/IPA.Loader/IPA.Loader.csproj b/IPA.Loader/IPA.Loader.csproj new file mode 100644 index 00000000..c15ab9df --- /dev/null +++ b/IPA.Loader/IPA.Loader.csproj @@ -0,0 +1,97 @@ + + + + + Debug + AnyCPU + {5AD344F0-01A0-4CA8-92E5-9D095737744D} + Library + Properties + IPA + IPA.Loader + v4.6 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + true + + + + + + + + + + + + ..\..\..\..\..\..\Game Library\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll + False + + + ..\..\..\..\..\..\Game Library\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UnityWebRequestModule.dll + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1.9.1.8 + + + 0.9.6.4 + + + 11.0.2 + + + + + \ No newline at end of file diff --git a/IllusionPlugin/IniFile.cs b/IPA.Loader/IniFile.cs similarity index 99% rename from IllusionPlugin/IniFile.cs rename to IPA.Loader/IniFile.cs index b8f47bce..94ff4f3f 100644 --- a/IllusionPlugin/IniFile.cs +++ b/IPA.Loader/IniFile.cs @@ -4,7 +4,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Text; -namespace IllusionPlugin +namespace IPA { /// /// Create a New INI file to store or load data diff --git a/IllusionInjector/BeatSaber/CompositeBSPlugin.cs b/IPA.Loader/Loader/Composite/CompositeBSPlugin.cs similarity index 95% rename from IllusionInjector/BeatSaber/CompositeBSPlugin.cs rename to IPA.Loader/Loader/Composite/CompositeBSPlugin.cs index 96d6ddf0..98169fad 100644 --- a/IllusionInjector/BeatSaber/CompositeBSPlugin.cs +++ b/IPA.Loader/Loader/Composite/CompositeBSPlugin.cs @@ -1,14 +1,14 @@ -using IllusionPlugin; -using IllusionPlugin.BeatSaber; +using IPA; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; using UnityEngine.SceneManagement; -using Logger = IllusionInjector.Logging.Logger; +using Logger = IPA.Logging.Logger; -namespace IllusionInjector { +namespace IPA.Loader.Composite +{ public class CompositeBSPlugin : IBeatSaberPlugin { IEnumerable plugins; diff --git a/IllusionInjector/IPA/CompositeIPAPlugin.cs b/IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs similarity index 94% rename from IllusionInjector/IPA/CompositeIPAPlugin.cs rename to IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs index 001677a6..c70714b6 100644 --- a/IllusionInjector/IPA/CompositeIPAPlugin.cs +++ b/IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs @@ -1,13 +1,15 @@ -using IllusionPlugin; -using System; +using System; using System.Collections.Generic; +using IPA; +using IPA.Old; using System.Linq; using System.Text; using UnityEngine; using UnityEngine.SceneManagement; -using Logger = IllusionInjector.Logging.Logger; +using Logger = IPA.Logging.Logger; -namespace IllusionInjector { +namespace IPA.Loader.Composite +{ #pragma warning disable CS0618 // Type or member is obsolete public class CompositeIPAPlugin : IPlugin { diff --git a/IllusionInjector/PluginComponent.cs b/IPA.Loader/Loader/PluginComponent.cs similarity index 84% rename from IllusionInjector/PluginComponent.cs rename to IPA.Loader/Loader/PluginComponent.cs index 2c8140fa..07e1e054 100644 --- a/IllusionInjector/PluginComponent.cs +++ b/IPA.Loader/Loader/PluginComponent.cs @@ -3,8 +3,11 @@ using System.Collections.Generic; using System.Text; using UnityEngine; using UnityEngine.SceneManagement; +using IPA.Loader; +using IPA.Loader.Composite; +using IPA.Logging; -namespace IllusionInjector +namespace IPA.Loader { public class PluginComponent : MonoBehaviour { @@ -14,6 +17,13 @@ namespace IllusionInjector public static PluginComponent Create() { + Application.logMessageReceived += delegate (string condition, string stackTrace, LogType type) + { + var level = UnityLogInterceptor.LogTypeToLevel(type); + UnityLogInterceptor.UnityLogger.Log(level, $"{condition.Trim()}"); + UnityLogInterceptor.UnityLogger.Log(level, $"{stackTrace.Trim()}"); + }; + return new GameObject("IPA_PluginManager").AddComponent(); } @@ -23,9 +33,7 @@ namespace IllusionInjector bsPlugins = new CompositeBSPlugin(PluginManager.BSPlugins); ipaPlugins = new CompositeIPAPlugin(PluginManager.Plugins); - - // this has no relevance since there is a new mod updater system - //gameObject.AddComponent(); // AFTER plugins are loaded, but before most things + gameObject.AddComponent(); bsPlugins.OnApplicationStart(); diff --git a/IllusionInjector/PluginManager.cs b/IPA.Loader/Loader/PluginManager.cs similarity index 71% rename from IllusionInjector/PluginManager.cs rename to IPA.Loader/Loader/PluginManager.cs index 14c67222..72e477e1 100644 --- a/IllusionInjector/PluginManager.cs +++ b/IPA.Loader/Loader/PluginManager.cs @@ -1,8 +1,9 @@ -using IllusionInjector.Logging; -using IllusionInjector.Updating; -using IllusionInjector.Utilities; -using IllusionPlugin; -using IllusionPlugin.BeatSaber; +using IPA; +using IPA.Logging; +using IPA.Old; +using IPA.Updating; +using IPA.Utilities; +using Mono.Cecil; using System; using System.Collections.Generic; using System.Diagnostics; @@ -13,9 +14,8 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; -using LoggerBase = IllusionPlugin.Logging.Logger; -namespace IllusionInjector +namespace IPA.Loader { public static class PluginManager { @@ -176,6 +176,50 @@ namespace IllusionInjector try { + #region Fix assemblies for refactor + + var module = ModuleDefinition.ReadModule(file); + bool modifiedModule = false; + foreach (var @ref in module.AssemblyReferences) + { // fix assembly references + if (@ref.Name == "IllusionPlugin" || @ref.Name == "IllusionInjector") + { + @ref.Name = "IPA.Loader"; + modifiedModule = true; + } + } + if (modifiedModule) + { // types don't need to be fixed if it's already referencing the new version + foreach (var @ref in module.GetTypeReferences()) + { // fix type references + if (@ref.FullName == "IllusionPlugin.IPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.IEnhancedPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.IBeatSaberPlugin") @ref.Namespace = "IPA"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.IEnhancedBeatSaberPlugin") @ref.Namespace = "IPA"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.BeatSaber.ModsaberModInfo") @ref.Namespace = "IPA"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.IniFile") @ref.Namespace = "IPA"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.IModPrefs") @ref.Namespace = "IPA"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.ModPrefs") @ref.Namespace = "IPA"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.Utils.ReflectionUtil") @ref.Namespace = "IPA.Utilities"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.Logging.Logger") @ref.Namespace = "IPA.Logging"; //@ref.Name = ""; + if (@ref.FullName == "IllusionPlugin.Logging.LogPrinter") @ref.Namespace = "IPA.Logging"; //@ref.Name = ""; + if (@ref.FullName == "IllusionInjector.PluginManager") @ref.Namespace = "IPA.Loader"; //@ref.Name = ""; + if (@ref.FullName == "IllusionInjector.PluginComponent") @ref.Namespace = "IPA.Loader"; //@ref.Name = ""; + if (@ref.FullName == "IllusionInjector.CompositeBSPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = ""; + if (@ref.FullName == "IllusionInjector.CompositeIPAPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = ""; + if (@ref.FullName == "IllusionInjector.Logging.UnityLogInterceptor") @ref.Namespace = "IPA.Logging"; //@ref.Name = ""; + if (@ref.FullName == "IllusionInjector.Logging.StandardLogger") @ref.Namespace = "IPA.Logging"; //@ref.Name = ""; + if (@ref.FullName == "IllusionInjector.Updating.SelfPlugin") @ref.Namespace = "IPA.Updating"; //@ref.Name = ""; + if (@ref.FullName == "IllusionInjector.Updating.Backup.BackupUnit") @ref.Namespace = "IPA.Updating.Backup"; //@ref.Name = ""; + if (@ref.Namespace == "IllusionInjector.Utilities") @ref.Namespace = "IPA.Utilities"; //@ref.Name = ""; + if (@ref.Namespace == "IllusionInjector.Logging.Printers") @ref.Namespace = "IPA.Logging.Printers"; //@ref.Name = ""; + if (@ref.Namespace == "IllusionInjector.Updating.ModsaberML") @ref.Namespace = "IPA.Updating.ModsaberML"; //@ref.Name = ""; + } + module.Write(file); + } + + #endregion + Assembly assembly = Assembly.LoadFrom(file); foreach (Type t in assembly.GetTypes()) @@ -191,13 +235,13 @@ namespace IllusionInjector var initArgs = new List(); var initParams = init.GetParameters(); - LoggerBase modLogger = null; + Logger modLogger = null; IModPrefs modPrefs = null; foreach (var param in initParams) { var ptype = param.ParameterType; - if (ptype.IsAssignableFrom(typeof(LoggerBase))) { + if (ptype.IsAssignableFrom(typeof(Logger))) { if (modLogger == null) modLogger = new StandardLogger(bsPlugin.Name); initArgs.Add(modLogger); } diff --git a/IllusionPlugin/Logging/LogPrinter.cs b/IPA.Loader/Logging/LogPrinter.cs similarity index 97% rename from IllusionPlugin/Logging/LogPrinter.cs rename to IPA.Loader/Logging/LogPrinter.cs index 441029e6..3458cb61 100644 --- a/IllusionPlugin/Logging/LogPrinter.cs +++ b/IPA.Loader/Logging/LogPrinter.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IllusionPlugin.Logging +namespace IPA.Logging { /// /// The log printer's base class. diff --git a/IllusionPlugin/Logging/Logger.cs b/IPA.Loader/Logging/Logger.cs similarity index 95% rename from IllusionPlugin/Logging/Logger.cs rename to IPA.Loader/Logging/Logger.cs index befa4ccd..bfc187ec 100644 --- a/IllusionPlugin/Logging/Logger.cs +++ b/IPA.Loader/Logging/Logger.cs @@ -4,13 +4,25 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IllusionPlugin.Logging +namespace IPA.Logging { /// /// The logger base class. Provides the format for console logs. /// public abstract class Logger { + private static Logger _log; + internal static Logger log + { + get + { + if (_log == null) + _log = new StandardLogger("IPA"); + return _log; + } + } + internal static bool LogCreated => _log != null; + /// /// The standard format for log messages. /// diff --git a/IllusionInjector/Logging/Printers/ColoredConsolePrinter.cs b/IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs similarity index 56% rename from IllusionInjector/Logging/Printers/ColoredConsolePrinter.cs rename to IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs index a4759b28..bc05ded5 100644 --- a/IllusionInjector/Logging/Printers/ColoredConsolePrinter.cs +++ b/IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs @@ -4,25 +4,24 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using IllusionPlugin.Logging; -using LoggerBase = IllusionPlugin.Logging.Logger; +using IPA.Logging; -namespace IllusionInjector.Logging.Printers +namespace IPA.Logging.Printers { public class ColoredConsolePrinter : LogPrinter { - LoggerBase.LogLevel filter = LoggerBase.LogLevel.All; - public override LoggerBase.LogLevel Filter { get => filter; set => filter = value; } + Logger.LogLevel filter = Logger.LogLevel.All; + public override Logger.LogLevel Filter { get => filter; set => filter = value; } ConsoleColor color = Console.ForegroundColor; public ConsoleColor Color { get => color; set => color = value; } - public override void Print(LoggerBase.Level level, DateTime time, string logName, string message) + public override void Print(Logger.Level level, DateTime time, string logName, string message) { if (((byte)level & (byte)StandardLogger.PrintFilter) == 0) return; Console.ForegroundColor = color; foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) - Console.WriteLine(string.Format(LoggerBase.LogFormat, line, logName, time, level.ToString().ToUpper())); + Console.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper())); Console.ResetColor(); } } diff --git a/IllusionInjector/Logging/Printers/GZFilePrinter.cs b/IPA.Loader/Logging/Printers/GZFilePrinter.cs similarity index 97% rename from IllusionInjector/Logging/Printers/GZFilePrinter.cs rename to IPA.Loader/Logging/Printers/GZFilePrinter.cs index 7a3fac36..bc0f9d86 100644 --- a/IllusionInjector/Logging/Printers/GZFilePrinter.cs +++ b/IPA.Loader/Logging/Printers/GZFilePrinter.cs @@ -1,4 +1,4 @@ -using IllusionPlugin.Logging; +using IPA.Logging; using Ionic.Zlib; using System; using System.Collections.Generic; @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; -namespace IllusionInjector.Logging.Printers +namespace IPA.Logging.Printers { public abstract class GZFilePrinter : LogPrinter { diff --git a/IllusionInjector/Logging/Printers/GlobalLogFilePrinter.cs b/IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs similarity index 57% rename from IllusionInjector/Logging/Printers/GlobalLogFilePrinter.cs rename to IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs index 9f617b72..a3b14187 100644 --- a/IllusionInjector/Logging/Printers/GlobalLogFilePrinter.cs +++ b/IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs @@ -4,19 +4,18 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using IllusionPlugin.Logging; -using LoggerBase = IllusionPlugin.Logging.Logger; +using IPA.Logging; -namespace IllusionInjector.Logging.Printers +namespace IPA.Logging.Printers { class GlobalLogFilePrinter : GZFilePrinter { - public override LoggerBase.LogLevel Filter { get; set; } = LoggerBase.LogLevel.All; + public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All; - public override void Print(IllusionPlugin.Logging.Logger.Level level, DateTime time, string logName, string message) + public override void Print(IPA.Logging.Logger.Level level, DateTime time, string logName, string message) { foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) - fileWriter.WriteLine(string.Format(LoggerBase.LogFormat, line, logName, time, level.ToString().ToUpper())); + fileWriter.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper())); } protected override FileInfo GetFileInfo() diff --git a/IllusionInjector/Logging/Printers/PluginLogFilePrinter.cs b/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs similarity index 72% rename from IllusionInjector/Logging/Printers/PluginLogFilePrinter.cs rename to IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs index cd0c41e4..c34a5481 100644 --- a/IllusionInjector/Logging/Printers/PluginLogFilePrinter.cs +++ b/IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs @@ -1,17 +1,16 @@ -using IllusionPlugin.Logging; +using IPA.Logging; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using LoggerBase = IllusionPlugin.Logging.Logger; -namespace IllusionInjector.Logging.Printers +namespace IPA.Logging.Printers { class PluginLogFilePrinter : GZFilePrinter { - public override LoggerBase.LogLevel Filter { get; set; } = LoggerBase.LogLevel.All; + public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All; private string name; @@ -28,7 +27,7 @@ namespace IllusionInjector.Logging.Printers this.name = name; } - public override void Print(IllusionPlugin.Logging.Logger.Level level, DateTime time, string logName, string message) + public override void Print(IPA.Logging.Logger.Level level, DateTime time, string logName, string message) { foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) fileWriter.WriteLine(string.Format("[{3} @ {2:HH:mm:ss}] {0}", line, logName, time, level.ToString().ToUpper())); diff --git a/IllusionInjector/Logging/StandardLogger.cs b/IPA.Loader/Logging/StandardLogger.cs similarity index 86% rename from IllusionInjector/Logging/StandardLogger.cs rename to IPA.Loader/Logging/StandardLogger.cs index 4b4a329a..c1c821cd 100644 --- a/IllusionInjector/Logging/StandardLogger.cs +++ b/IPA.Loader/Logging/StandardLogger.cs @@ -1,6 +1,4 @@ -using IllusionInjector.Logging.Printers; -using IllusionPlugin; -using IllusionPlugin.Logging; +using IPA.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -9,24 +7,12 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using LoggerBase = IllusionPlugin.Logging.Logger; +using IPA; +using LoggerBase = IPA.Logging.Logger; +using IPA.Logging.Printers; -namespace IllusionInjector.Logging +namespace IPA.Logging { - internal static class Logger - { - private static LoggerBase _log; - internal static LoggerBase log - { - get - { - if (_log == null) - _log = new StandardLogger("IPA"); - return _log; - } - } - } - public class StandardLogger : LoggerBase { private static readonly IReadOnlyList defaultPrinters = new List() @@ -60,15 +46,14 @@ namespace IllusionInjector.Logging }; private string logName; - private static LogLevel showFilter = LogLevel.InfoUp; private static bool showSourceClass = true; - public static LogLevel PrintFilter { get => showFilter; set => showFilter = value; } + public static LogLevel PrintFilter { get; set; } = LogLevel.InfoUp; private List printers = new List(defaultPrinters); static StandardLogger() { if (ModPrefs.GetBool("IPA", "PrintDebug", false, true)) - showFilter = LogLevel.All; + PrintFilter = LogLevel.All; showSourceClass = ModPrefs.GetBool("IPA", "DebugShowCallSource", false, true); } diff --git a/IPA.Loader/Logging/UnityLogInterceptor.cs b/IPA.Loader/Logging/UnityLogInterceptor.cs new file mode 100644 index 00000000..908f11bf --- /dev/null +++ b/IPA.Loader/Logging/UnityLogInterceptor.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace IPA.Logging +{ + internal class UnityLogInterceptor + { + public static Logger UnityLogger = new StandardLogger("UnityEngine"); + + public static Logger.Level LogTypeToLevel(LogType type) + { + switch (type) + { + case LogType.Assert: + return Logger.Level.Debug; + case LogType.Error: + return Logger.Level.Error; + case LogType.Exception: + return Logger.Level.Critical; + case LogType.Log: + return Logger.Level.Info; + case LogType.Warning: + return Logger.Level.Warning; + default: + return Logger.Level.Info; + } + } + } +} diff --git a/IllusionPlugin/ModPrefs.cs b/IPA.Loader/ModPrefs.cs similarity index 99% rename from IllusionPlugin/ModPrefs.cs rename to IPA.Loader/ModPrefs.cs index 198cc6aa..3657a81d 100644 --- a/IllusionPlugin/ModPrefs.cs +++ b/IPA.Loader/ModPrefs.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Reflection; using System.Text; -namespace IllusionPlugin +namespace IPA { /// /// Allows to get and set preferences for your mod. diff --git a/IllusionPlugin/BeatSaber/IBeatSaberPlugin.cs b/IPA.Loader/PluginInterfaces/BeatSaber/IBeatSaberPlugin.cs similarity index 96% rename from IllusionPlugin/BeatSaber/IBeatSaberPlugin.cs rename to IPA.Loader/PluginInterfaces/BeatSaber/IBeatSaberPlugin.cs index a9e2753c..48dba55a 100644 --- a/IllusionPlugin/BeatSaber/IBeatSaberPlugin.cs +++ b/IPA.Loader/PluginInterfaces/BeatSaber/IBeatSaberPlugin.cs @@ -1,10 +1,9 @@ -using IllusionPlugin.BeatSaber; -using System; +using System; using System.Collections.Generic; using System.Text; using UnityEngine.SceneManagement; -namespace IllusionPlugin +namespace IPA { /// /// Interface for Beat Saber plugins. Every class that implements this will be loaded if the DLL is placed at diff --git a/IllusionPlugin/BeatSaber/IEnhancedBeatSaberPlugin.cs b/IPA.Loader/PluginInterfaces/BeatSaber/IEnhancedBeatSaberPlugin.cs similarity index 91% rename from IllusionPlugin/BeatSaber/IEnhancedBeatSaberPlugin.cs rename to IPA.Loader/PluginInterfaces/BeatSaber/IEnhancedBeatSaberPlugin.cs index dfbd4f9f..3a31ef13 100644 --- a/IllusionPlugin/BeatSaber/IEnhancedBeatSaberPlugin.cs +++ b/IPA.Loader/PluginInterfaces/BeatSaber/IEnhancedBeatSaberPlugin.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace IllusionPlugin +namespace IPA { /// /// An enhanced version of a standard BeatSaber plugin. diff --git a/IllusionPlugin/BeatSaber/ModsaberModInfo.cs b/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs similarity index 94% rename from IllusionPlugin/BeatSaber/ModsaberModInfo.cs rename to IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs index 6defe31c..ba5fb374 100644 --- a/IllusionPlugin/BeatSaber/ModsaberModInfo.cs +++ b/IPA.Loader/PluginInterfaces/BeatSaber/ModsaberModInfo.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IllusionPlugin.BeatSaber +namespace IPA { /// /// A class to provide information about a mod on ModSaber.ML diff --git a/IllusionPlugin/IGenericEnhancedPlugin.cs b/IPA.Loader/PluginInterfaces/IGenericEnhancedPlugin.cs similarity index 96% rename from IllusionPlugin/IGenericEnhancedPlugin.cs rename to IPA.Loader/PluginInterfaces/IGenericEnhancedPlugin.cs index 80327f5c..b3c9a935 100644 --- a/IllusionPlugin/IGenericEnhancedPlugin.cs +++ b/IPA.Loader/PluginInterfaces/IGenericEnhancedPlugin.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IllusionPlugin +namespace IPA { /// /// A generic interface for the modification for enhanced plugins. diff --git a/IllusionPlugin/IPA/IEnhancedPlugin.cs b/IPA.Loader/PluginInterfaces/IPA/IEnhancedPlugin.cs similarity index 92% rename from IllusionPlugin/IPA/IEnhancedPlugin.cs rename to IPA.Loader/PluginInterfaces/IPA/IEnhancedPlugin.cs index ac925b2e..91c0e42e 100644 --- a/IllusionPlugin/IPA/IEnhancedPlugin.cs +++ b/IPA.Loader/PluginInterfaces/IPA/IEnhancedPlugin.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace IllusionPlugin +namespace IPA.Old { /// /// An enhanced version of the standard IPA plugin. diff --git a/IllusionPlugin/IPA/IPlugin.cs b/IPA.Loader/PluginInterfaces/IPA/IPlugin.cs similarity index 98% rename from IllusionPlugin/IPA/IPlugin.cs rename to IPA.Loader/PluginInterfaces/IPA/IPlugin.cs index 0610da73..fe9adba2 100644 --- a/IllusionPlugin/IPA/IPlugin.cs +++ b/IPA.Loader/PluginInterfaces/IPA/IPlugin.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace IllusionPlugin +namespace IPA.Old { /// /// Interface for generic Illusion unity plugins. Every class that implements this will be loaded if the DLL is placed at diff --git a/IllusionPlugin/Properties/AssemblyInfo.cs b/IPA.Loader/Properties/AssemblyInfo.cs similarity index 72% rename from IllusionPlugin/Properties/AssemblyInfo.cs rename to IPA.Loader/Properties/AssemblyInfo.cs index 73d2f6b4..a4c96091 100644 --- a/IllusionPlugin/Properties/AssemblyInfo.cs +++ b/IPA.Loader/Properties/AssemblyInfo.cs @@ -1,37 +1,37 @@ -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("IllusionPlugin")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("IllusionPlugin")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[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("e8cea89d-6c2f-4729-94b3-f355f7db19e5")] -[assembly: InternalsVisibleTo("IllusionInjector")] - -// 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")] \ No newline at end of file +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("IPA.Loader")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IPA.Loader")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[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("5ad344f0-01a0-4ca8-92e5-9d095737744d")] +[assembly: InternalsVisibleTo("IPA.Injector")] + +// 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/IllusionInjector/Updating/Backup/BackupUnit.cs b/IPA.Loader/Updating/Backup/BackupUnit.cs similarity index 53% rename from IllusionInjector/Updating/Backup/BackupUnit.cs rename to IPA.Loader/Updating/Backup/BackupUnit.cs index 3aad5ab0..0796d27e 100644 --- a/IllusionInjector/Updating/Backup/BackupUnit.cs +++ b/IPA.Loader/Updating/Backup/BackupUnit.cs @@ -1,4 +1,5 @@ -using IllusionInjector.Utilities; +using IPA.Logging; +using IPA.Utilities; using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -6,7 +7,7 @@ using System.IO; using System.Linq; using System.Text; -namespace IllusionInjector.Updating.Backup +namespace IPA.Updating.Backup { /// /// A unit for backup. WIP. @@ -17,26 +18,39 @@ namespace IllusionInjector.Updating.Backup private DirectoryInfo _BackupPath; private List _Files = new List(); - - public BackupUnit(string backupPath) : this(backupPath, DateTime.Now.ToString("yyyy-MM-dd_h-mm-ss")) + private FileInfo _ManifestFile; + private static string _ManifestFileName = "$manifest$.txt"; + + public BackupUnit(string path) : this(path, DateTime.Now.ToString("yyyy-MM-dd_h-mm-ss")) { } - public BackupUnit(string backupPath, string name) + internal BackupUnit(string path, string name) { Name = name; - _BackupPath = new DirectoryInfo(Path.Combine(backupPath, Name)); - _BackupPath.Create(); + _BackupPath = new DirectoryInfo(Path.Combine(path, Name)); + _ManifestFile = new FileInfo(Path.Combine(_BackupPath.FullName, _ManifestFileName)); } - + public static BackupUnit FromDirectory(DirectoryInfo directory, string backupPath) { var unit = new BackupUnit(backupPath, directory.Name); - // Parse directory - foreach(var file in directory.GetFiles("*", SearchOption.AllDirectories)) { - var relativePath = file.FullName.Substring(directory.FullName.Length + 1); - unit._Files.Add(relativePath); + // Read Manifest + if (unit._ManifestFile.Exists) + { + string manifest = File.ReadAllText(unit._ManifestFile.FullName); + foreach (var line in manifest.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) + unit._Files.Add(line); + } + else + { + foreach (var file in directory.GetFiles("*", SearchOption.AllDirectories)) + { + if (file.Name == _ManifestFileName) continue; + var relativePath = file.FullName.Substring(directory.FullName.Length + 1); + unit._Files.Add(relativePath); + } } return unit; @@ -60,25 +74,31 @@ namespace IllusionInjector.Updating.Backup { var relativePath = LoneFunctions.GetRelativePath(Environment.CurrentDirectory, file.FullName); var backupPath = new FileInfo(Path.Combine(_BackupPath.FullName, relativePath)); - - if(_Files.Contains(relativePath)) + + if (_Files.Contains(relativePath)) { - Console.WriteLine("Skipping backup of {0}", relativePath); + Logger.log.Debug($"Skipping backup of {relativePath}"); return; } - // Copy over backupPath.Directory.Create(); if (file.Exists) { - file.CopyTo(backupPath.FullName, true); - } else + file.CopyTo(backupPath.FullName); + } + else { // Make empty file backupPath.Create().Close(); } + if (!File.Exists(_ManifestFile.FullName)) + _ManifestFile.Create().Close(); + var stream = _ManifestFile.AppendText(); + stream.WriteLine(relativePath); + stream.Close(); + // Add to list _Files.Add(relativePath); } @@ -88,9 +108,9 @@ namespace IllusionInjector.Updating.Backup /// public void Restore() { - foreach(var relativePath in _Files) + foreach (var relativePath in _Files) { - //Console.WriteLine("Restoring {0}", relativePath); + Logger.log.Debug($"Restoring {relativePath}"); // Original version var backupFile = new FileInfo(Path.Combine(_BackupPath.FullName, relativePath)); var target = new FileInfo(Path.Combine(Environment.CurrentDirectory, relativePath)); @@ -99,22 +119,26 @@ namespace IllusionInjector.Updating.Backup { if (backupFile.Length > 0) { - //Console.WriteLine(" {0} => {1}", backupFile.FullName, target.FullName); + Logger.log.Debug($" {backupFile.FullName} => {target.FullName}"); target.Directory.Create(); backupFile.CopyTo(target.FullName, true); - } else + } + else { - //Console.WriteLine(" x {0}", target.FullName); - if(target.Exists) + Logger.log.Debug($" x {target.FullName}"); + if (target.Exists) { target.Delete(); } } - } else { - //Console.Error.WriteLine("Backup not found!"); + } + else + { + Logger.log.Error("Backup not found!"); } } } + } } diff --git a/IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs b/IPA.Loader/Updating/ModsaberML/ApiEndpoint.cs similarity index 97% rename from IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs rename to IPA.Loader/Updating/ModsaberML/ApiEndpoint.cs index 6465f381..38776d50 100644 --- a/IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs +++ b/IPA.Loader/Updating/ModsaberML/ApiEndpoint.cs @@ -1,5 +1,5 @@ -using IllusionInjector.Logging; -using IllusionInjector.Utilities; +using IPA.Logging; +using IPA.Utilities; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IllusionInjector.Updating.ModsaberML +namespace IPA.Updating.ModsaberML { class ApiEndpoint { diff --git a/IllusionInjector/Updating/ModsaberML/Updater.cs b/IPA.Loader/Updating/ModsaberML/Updater.cs similarity index 98% rename from IllusionInjector/Updating/ModsaberML/Updater.cs rename to IPA.Loader/Updating/ModsaberML/Updater.cs index 26a5c653..6ce5daab 100644 --- a/IllusionInjector/Updating/ModsaberML/Updater.cs +++ b/IPA.Loader/Updating/ModsaberML/Updater.cs @@ -1,5 +1,5 @@ -using IllusionInjector.Updating.Backup; -using IllusionInjector.Utilities; +using IPA.Utilities; +using IPA.Loader; using Ionic.Zip; using Newtonsoft.Json; using System; @@ -15,9 +15,10 @@ using System.Threading; using System.Threading.Tasks; using UnityEngine; using UnityEngine.Networking; -using Logger = IllusionInjector.Logging.Logger; +using Logger = IPA.Logging.Logger; +using IPA.Updating.Backup; -namespace IllusionInjector.Updating.ModsaberML +namespace IPA.Updating.ModsaberML { class Updater : MonoBehaviour { diff --git a/IllusionInjector/Updating/SelfPlugin.cs b/IPA.Loader/Updating/SelfPlugin.cs similarity index 87% rename from IllusionInjector/Updating/SelfPlugin.cs rename to IPA.Loader/Updating/SelfPlugin.cs index 39863d70..12c79b51 100644 --- a/IllusionInjector/Updating/SelfPlugin.cs +++ b/IPA.Loader/Updating/SelfPlugin.cs @@ -1,5 +1,4 @@ -using IllusionPlugin; -using IllusionPlugin.BeatSaber; +using IPA; using System; using System.Collections.Generic; using System.Linq; @@ -7,12 +6,12 @@ using System.Text; using System.Threading.Tasks; using UnityEngine.SceneManagement; -namespace IllusionInjector.Updating +namespace IPA.Updating { internal class SelfPlugin : IBeatSaberPlugin { internal const string IPA_Name = "Beat Saber IPA"; - internal const string IPA_Version = "3.8.9"; + internal const string IPA_Version = "3.9.0"; public string Name => IPA_Name; diff --git a/IllusionInjector/Utilities/Extensions.cs b/IPA.Loader/Utilities/Extensions.cs similarity index 91% rename from IllusionInjector/Utilities/Extensions.cs rename to IPA.Loader/Utilities/Extensions.cs index 326c675a..7a1c3399 100644 --- a/IllusionInjector/Utilities/Extensions.cs +++ b/IPA.Loader/Utilities/Extensions.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IllusionInjector.Utilities +namespace IPA.Utilities { public static class Extensions { diff --git a/IllusionInjector/Utilities/LoneFunctions.cs b/IPA.Loader/Utilities/LoneFunctions.cs similarity index 98% rename from IllusionInjector/Utilities/LoneFunctions.cs rename to IPA.Loader/Utilities/LoneFunctions.cs index c270f6e8..1ed0b4db 100644 --- a/IllusionInjector/Utilities/LoneFunctions.cs +++ b/IPA.Loader/Utilities/LoneFunctions.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IllusionInjector.Utilities +namespace IPA.Utilities { public static class LoneFunctions { diff --git a/IllusionPlugin/Utils/ReflectionUtil.cs b/IPA.Loader/Utilities/ReflectionUtil.cs similarity index 99% rename from IllusionPlugin/Utils/ReflectionUtil.cs rename to IPA.Loader/Utilities/ReflectionUtil.cs index cf8fdde1..5a716359 100644 --- a/IllusionPlugin/Utils/ReflectionUtil.cs +++ b/IPA.Loader/Utilities/ReflectionUtil.cs @@ -2,7 +2,7 @@ using System.Reflection; using UnityEngine; -namespace IllusionPlugin.Utils +namespace IPA.Utilities { /// /// A utility class providing reflection helper methods. diff --git a/IllusionInjector/Utilities/SteamCheck.cs b/IPA.Loader/Utilities/SteamCheck.cs similarity index 92% rename from IllusionInjector/Utilities/SteamCheck.cs rename to IPA.Loader/Utilities/SteamCheck.cs index a4f9624b..08bb004e 100644 --- a/IllusionInjector/Utilities/SteamCheck.cs +++ b/IPA.Loader/Utilities/SteamCheck.cs @@ -1,11 +1,10 @@ -using IllusionInjector.Logging; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IllusionInjector.Utilities +namespace IPA.Utilities { public static class SteamCheck { diff --git a/IPA.Tests/IPA.Tests.csproj b/IPA.Tests/IPA.Tests.csproj index fb98f0df..15546da8 100644 --- a/IPA.Tests/IPA.Tests.csproj +++ b/IPA.Tests/IPA.Tests.csproj @@ -67,7 +67,6 @@ - diff --git a/IPA.Tests/updater_test.json b/IPA.Tests/updater_test.json deleted file mode 100644 index 19df2e06..00000000 --- a/IPA.Tests/updater_test.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "bsipa-test-plugin", - "version": "0.0.1", - "approved": true, - "title": "BSIPA Test Plugin", - "description": "", - "type": "mod", - "published": "2018-08-02T03:12:18.805Z", - "gameVersion": "0.11.2", - "gameVersionID": "5b626bb15d243a0008b8886e", - "oldVersions": [], - "dependsOn": [], - "conflictsWith": [], - "files": { - "steam": { - "hash": "a94e7eea2f656b2830a86000ee222b6cb06f8da5", - "files": { - "Plugins/": "da39a3ee5e6b4b0d3255bfef95601890afd80709", - "Plugins/RandomSong.dll": "64ee1ecfeda73c550004bdb5123c7ac47a45e428" - }, - "url": "https://www.modsaber.ml/cdn/randomsong/1.0.0-default.zip" - } - }, - "weight": 7, - "author": "danike", - "authorID": "5b62723f288b110008291cb9" -} \ No newline at end of file diff --git a/IPA/IPA.csproj b/IPA/IPA.csproj index f55672d3..705e0703 100644 --- a/IPA/IPA.csproj +++ b/IPA/IPA.csproj @@ -13,6 +13,21 @@ 512 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -39,23 +54,10 @@ favicon.ico + + IPA.Program + - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll - True - - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll - False - - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll - False - - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll - False - @@ -77,7 +79,6 @@ - @@ -85,6 +86,23 @@ + + + 0.9.6.4 + + + + + False + Microsoft .NET Framework 4.6.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + - \ No newline at end of file diff --git a/IllusionInjector/Logging/UnityLogInterceptor.cs b/IllusionInjector/Logging/UnityLogInterceptor.cs deleted file mode 100644 index 64e42926..00000000 --- a/IllusionInjector/Logging/UnityLogInterceptor.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UnityEngine; -using LoggerBase = IllusionPlugin.Logging.Logger; - -namespace IllusionInjector.Logging -{ - public class UnityLogInterceptor - { - public static LoggerBase Unitylogger = new StandardLogger("UnityEngine"); - - public static LoggerBase.Level LogTypeToLevel(LogType type) - { - switch (type) - { - case LogType.Assert: - return LoggerBase.Level.Debug; - case LogType.Error: - return LoggerBase.Level.Error; - case LogType.Exception: - return LoggerBase.Level.Critical; - case LogType.Log: - return LoggerBase.Level.Info; - case LogType.Warning: - return LoggerBase.Level.Warning; - default: - return LoggerBase.Level.Info; - } - } - } -} diff --git a/IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache b/IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache deleted file mode 100644 index 484972a6..00000000 --- a/IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache +++ /dev/null @@ -1 +0,0 @@ -dae758b90b096a39aa928b136ec952d8ed591e5d diff --git a/IllusionInjector/packages.config b/IllusionInjector/packages.config deleted file mode 100644 index 71c37d6d..00000000 --- a/IllusionInjector/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/IllusionPlugin/IllusionPlugin.XML b/IllusionPlugin/IllusionPlugin.XML deleted file mode 100644 index 493113b0..00000000 --- a/IllusionPlugin/IllusionPlugin.XML +++ /dev/null @@ -1,178 +0,0 @@ - - - - IllusionPlugin - - - - - Gets a list of executables this plugin should be excuted on (without the file ending) - - { "PlayClub", "PlayClubStudio" } - - - - Create a New INI file to store or load data - - - - - INIFile Constructor. - - - - - - Write Data to the INI File - - - Section name - - Key Name - - Value Name - - - - Read Data Value From the Ini File - - - - - - - - - Interface for generic Illusion unity plugins. Every class that implements this will be loaded if the DLL is placed at - data/Managed/Plugins. - - - - - Gets the name of the plugin. - - - - - Gets the version of the plugin. - - - - - Gets invoked when the application is started. - - - - - Gets invoked when the application is closed. - - - - - Gets invoked whenever a level is loaded. - - - - - - Gets invoked after the first update cycle after a level was loaded. - - - - - - Gets invoked on every graphic update. - - - - - Gets invoked on ever physics update. - - - - - Allows to get and set preferences for your mod. - - - - - Gets a string from the ini. - - Section of the key. - Name of the key. - Value that should be used when no value is found. - Whether or not the default value should be written if no value is found. - - - - - Gets an int from the ini. - - Section of the key. - Name of the key. - Value that should be used when no value is found. - Whether or not the default value should be written if no value is found. - - - - - Gets a float from the ini. - - Section of the key. - Name of the key. - Value that should be used when no value is found. - Whether or not the default value should be written if no value is found. - - - - - Gets a bool from the ini. - - Section of the key. - Name of the key. - Value that should be used when no value is found. - Whether or not the default value should be written if no value is found. - - - - - Checks whether or not a key exists in the ini. - - Section of the key. - Name of the key. - - - - - Sets a float in the ini. - - Section of the key. - Name of the key. - Value that should be written. - - - - Sets an int in the ini. - - Section of the key. - Name of the key. - Value that should be written. - - - - Sets a string in the ini. - - Section of the key. - Name of the key. - Value that should be written. - - - - Sets a bool in the ini. - - Section of the key. - Name of the key. - Value that should be written. - - - diff --git a/IllusionPlugin/IllusionPlugin.csproj b/IllusionPlugin/IllusionPlugin.csproj deleted file mode 100644 index f5f34363..00000000 --- a/IllusionPlugin/IllusionPlugin.csproj +++ /dev/null @@ -1,69 +0,0 @@ - - - - - Debug - AnyCPU - {E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71} - Library - Properties - IllusionPlugin - IllusionPlugin - v4.6 - 512 - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - none - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\IllusionPlugin.XML - false - true - - - - - - - ..\Libs\UnityEngine.CoreModule.dll - False - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/IllusionPlugin/obj/Debug/IllusionPlugin.csproj.CoreCompileInputs.cache b/IllusionPlugin/obj/Debug/IllusionPlugin.csproj.CoreCompileInputs.cache deleted file mode 100644 index 2a6cf0f9..00000000 --- a/IllusionPlugin/obj/Debug/IllusionPlugin.csproj.CoreCompileInputs.cache +++ /dev/null @@ -1 +0,0 @@ -77d5fd2376e4df56c59ee712f4f804807c24fc6f