Esempio n. 1
0
        private static void _Run(bool doorstop)
        {
            Console.WriteLine();
            Console.WriteLine();
            UnityModManager.Logger.Log("Injection...");

            if (!UnityModManager.Initialize())
            {
                UnityModManager.Logger.Log($"Cancel start due to an error.");
                UnityModManager.OpenUnityFileLog();
                return;
            }

            Fixes.Apply();

            if (!string.IsNullOrEmpty(UnityModManager.Config.StartingPoint))
            {
                if (!doorstop && UnityModManager.Config.StartingPoint == UnityModManager.Config.EntryPoint)
                {
                    UnityModManager.Start();
                }
                else
                {
                    if (TryGetEntryPoint(UnityModManager.Config.StartingPoint, out var @class, out var method, out var place))
                    {
                        var usePrefix = (place == "before");
                        var harmony   = new HarmonyLib.Harmony(nameof(UnityModManager));
                        var prefix    = typeof(Injector).GetMethod(nameof(Prefix_Start), BindingFlags.Static | BindingFlags.NonPublic);
                        var postfix   = typeof(Injector).GetMethod(nameof(Postfix_Start), BindingFlags.Static | BindingFlags.NonPublic);
                        harmony.Patch(method, usePrefix ? new HarmonyMethod(prefix) : null, !usePrefix ? new HarmonyMethod(postfix) : null);
                        UnityModManager.Logger.Log("Injection successful.");
                    }
                    else
                    {
                        UnityModManager.Logger.Log("Injection canceled.");
                        UnityModManager.OpenUnityFileLog();
                        return;
                    }
                }
Esempio n. 2
0
        private static void _Run(bool doorstop)
        {
            var stringFields  = typeof(UnityModManager.Textures).GetFields(BindingFlags.Static | BindingFlags.NonPublic).Where(x => x.FieldType == typeof(string)).ToArray();
            var textureFields = typeof(UnityModManager.Textures).GetFields(BindingFlags.Static | BindingFlags.Public).Where(x => x.FieldType == typeof(Texture2D)).ToArray();

            foreach (var f in textureFields)
            {
                f.SetValue(null, new Texture2D(2, 2, TextureFormat.ARGB32, false, true));
            }

            Console.WriteLine();
            Console.WriteLine();
            UnityModManager.Logger.Log("Injection...");

            if (!UnityModManager.Initialize())
            {
                UnityModManager.Logger.Log($"Cancel start due to an error.");
                UnityModManager.OpenUnityFileLog();
                return;
            }

            Fixes.Apply();

            if (UnityModManager.unityVersion.Major >= 2017)
            {
                var assembly  = Assembly.Load("UnityEngine.ImageConversionModule");
                var LoadImage = assembly.GetType("UnityEngine.ImageConversion").GetMethod("LoadImage", new Type[] { typeof(Texture2D), typeof(byte[]) });
                if (LoadImage != null)
                {
                    foreach (var f in textureFields)
                    {
                        LoadImage.Invoke(null, new object[] { (Texture2D)f.GetValue(null), Convert.FromBase64String((string)stringFields.FirstOrDefault(x => x.Name == f.Name + "Base64")?.GetValue(null) ?? "") });
                    }
                }
            }
            else
            {
                var LoadImage = typeof(Texture2D).GetMethod("LoadImage", new Type[] { typeof(byte[]) });
                if (LoadImage != null)
                {
                    foreach (var f in textureFields)
                    {
                        LoadImage.Invoke((Texture2D)f.GetValue(null), new object[] { Convert.FromBase64String((string)stringFields.FirstOrDefault(x => x.Name == f.Name + "Base64")?.GetValue(null) ?? "") });
                    }
                }
            }
            foreach (var f in textureFields)
            {
                UMMLoader.UMMLoader.Logger.LogMessage(f.Name + " : " + ((Texture2D)f.GetValue(null) == null).ToString());
            }



            if (!string.IsNullOrEmpty(UnityModManager.Config.StartingPoint))
            {
                if (!doorstop && UnityModManager.Config.StartingPoint == UnityModManager.Config.EntryPoint)
                {
                    UnityModManager.Start();
                }
                else
                {
                    if (TryGetEntryPoint(UnityModManager.Config.StartingPoint, out var @class, out var method, out var place))
                    {
                        usePrefix = (place == "before");
                        var harmony = HarmonyInstance.Create(nameof(UnityModManager));
                        var prefix  = typeof(Injector).GetMethod(nameof(Prefix_Start), BindingFlags.Static | BindingFlags.NonPublic);
                        var postfix = typeof(Injector).GetMethod(nameof(Postfix_Start), BindingFlags.Static | BindingFlags.NonPublic);
                        harmony.Patch(method, new HarmonyMethod(prefix), new HarmonyMethod(postfix));
                        UnityModManager.Logger.Log("Injection successful.");
                    }
                    else
                    {
                        UnityModManager.Logger.Log("Injection canceled.");
                        UnityModManager.OpenUnityFileLog();
                        return;
                    }
                }