예제 #1
0
 public static void Config(IEnumerable <Type> cfg_check_types)
 {
     if (cfg_check_types != null)
     {
         if (hotfixCfg == null)
         {
             hotfixCfg = new Dictionary <string, int>();
         }
         HotfixConfig.GetConfig(hotfixCfg, cfg_check_types);
     }
 }
예제 #2
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Useage();
                return;
            }

            try
            {
                var    injectAssmblyPath = Path.GetFullPath(args[0]);
                var    xluaAssmblyPath   = Path.GetFullPath(args[1]);
                string cfg_append        = null;
                if (args.Length > 3)
                {
                    cfg_append = Path.GetFullPath(args[3]);
                    if (!cfg_append.EndsWith(".data"))
                    {
                        cfg_append = null;
                    }
                }
                AppDomain     currentDomain = AppDomain.CurrentDomain;
                List <string> search_paths  = args.Skip(cfg_append == null ? 3 : 4).ToList();
                currentDomain.AssemblyResolve += new ResolveEventHandler((object sender, ResolveEventArgs rea) =>
                {
                    foreach (var search_path in search_paths)
                    {
                        string assemblyPath = Path.Combine(search_path, new AssemblyName(rea.Name).Name + ".dll");
                        if (File.Exists(assemblyPath))
                        {
                            return(Assembly.Load(File.ReadAllBytes(assemblyPath)));
                        }
                    }
                    return(null);
                });
                var assembly  = Assembly.Load(File.ReadAllBytes(injectAssmblyPath));
                var hotfixCfg = new Dictionary <string, int>();
                HotfixConfig.GetConfig(hotfixCfg, assembly.GetTypes());
                if (cfg_append != null)
                {
                    using (BinaryReader reader = new BinaryReader(File.Open(cfg_append, FileMode.Open)))
                    {
                        int count = reader.ReadInt32();
                        for (int i = 0; i < count; i++)
                        {
                            string k = reader.ReadString();
                            int    v = reader.ReadInt32();
                            if (!hotfixCfg.ContainsKey(k))
                            {
                                hotfixCfg.Add(k, v);
                            }
                        }
                    }
                }
                Hotfix.HotfixInject(injectAssmblyPath, xluaAssmblyPath, args.Skip(cfg_append == null ? 3 : 3), args[2], hotfixCfg);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in hotfix inject: " + e);
            }
        }
예제 #3
0
        public static void HotfixInject()
        {
            if (EditorApplication.isCompiling || Application.isPlaying)
            {
                return;
            }

#if UNITY_EDITOR_OSX
            var mono_path = Path.Combine(Path.GetDirectoryName(typeof(UnityEngine.Debug).Module.FullyQualifiedName),
                                         "../MonoBleedingEdge/bin/mono");
            if (!File.Exists(mono_path))
            {
                mono_path = Path.Combine(Path.GetDirectoryName(typeof(UnityEngine.Debug).Module.FullyQualifiedName),
                                         "../../MonoBleedingEdge/bin/mono");
            }
            if (!File.Exists(mono_path))
            {
                UnityEngine.Debug.LogError("can not find mono!");
            }
#elif UNITY_EDITOR_WIN
            var mono_path = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName),
                                         "Data/MonoBleedingEdge/bin/mono.exe");
#endif
            var inject_tool_path = "./Tools/XLuaHotfixInject.exe";
            if (!File.Exists(inject_tool_path))
            {
                UnityEngine.Debug.LogError("please install the Tools");
                return;
            }

            var assembly_csharp_path = "./Library/ScriptAssemblies/Assembly-CSharp.dll";
            var id_map_file_path     = CSObjectWrapEditor.GeneratorConfig.common_path + "Resources/hotfix_id_map.lua.txt";
            var hotfix_cfg_in_editor = CSObjectWrapEditor.GeneratorConfig.common_path + "hotfix_cfg_in_editor.data";

            Dictionary <string, int> editor_cfg = new Dictionary <string, int>();
            Assembly editor_assembly            = typeof(Hotfix).Assembly;
            HotfixConfig.GetConfig(editor_cfg, Utils.GetAllTypes().Where(t => t.Assembly == editor_assembly));

            using (BinaryWriter writer = new BinaryWriter(new FileStream(hotfix_cfg_in_editor, FileMode.Create, FileAccess.Write)))
            {
                writer.Write(editor_cfg.Count);
                foreach (var kv in editor_cfg)
                {
                    writer.Write(kv.Key);
                    writer.Write(kv.Value);
                }
            }

            List <string> args = new List <string>()
            {
                inject_tool_path, assembly_csharp_path, id_map_file_path, hotfix_cfg_in_editor
            };

            foreach (var path in
                     (from asm in AppDomain.CurrentDomain.GetAssemblies() select asm.ManifestModule.FullyQualifiedName)
                     .Distinct())
            {
                try
                {
                    args.Add(System.IO.Path.GetDirectoryName(path));
                }
                catch (Exception)
                {
                }
            }

            Process hotfix_injection = new Process();
            hotfix_injection.StartInfo.FileName               = mono_path;
            hotfix_injection.StartInfo.Arguments              = "\"" + String.Join("\" \"", args.Distinct().ToArray()) + "\"";
            hotfix_injection.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            hotfix_injection.StartInfo.RedirectStandardOutput = true;
            hotfix_injection.StartInfo.UseShellExecute        = false;
            hotfix_injection.StartInfo.CreateNoWindow         = true;
            hotfix_injection.Start();
            hotfix_injection.WaitForExit();
            File.Delete(hotfix_cfg_in_editor);
            UnityEngine.Debug.Log(hotfix_injection.StandardOutput.ReadToEnd());
            AssetDatabase.Refresh();
        }