예제 #1
0
        public static int DllMain(string arg)
        {
            assemblyPath = null;

            Args args = new Args(arg);

            assemblyPath = args.GetString("MainAssembly");
            if (!string.IsNullOrEmpty(assemblyPath))
            {
                if (string.IsNullOrEmpty(assemblyPath) || !File.Exists(assemblyPath))
                {
                    return((int)AssemblyLoaderError.MainAssemblyNotFound);
                }
                mainAssemblyDirectory = Path.GetDirectoryName(assemblyPath);
            }
            else
            {
                return((int)AssemblyLoaderError.MainAssemblyPathNotProvided);
            }

            IntPtr asyncTaskAddr      = (IntPtr)args.GetInt64("AsyncTask");
            IntPtr isInGameThreadAddr = (IntPtr)args.GetInt64("IsInGameThread");

            if (asyncTaskAddr == IntPtr.Zero || isInGameThreadAddr == IntPtr.Zero)
            {
                return((int)AssemblyLoaderError.GameThreadAsyncNull);
            }
            GameThreadHelper.Init(asyncTaskAddr, isInGameThreadAddr);

            entryPointArg = arg;

            string currentAssemblyPath     = Assembly.GetExecutingAssembly().Location;
            string currentAssemblyFileName = Path.GetFileNameWithoutExtension(currentAssemblyPath);

            currentAssemblyDirectory = Path.GetDirectoryName(currentAssemblyPath);

            if (!IsSameOrSubDirectory(currentAssemblyDirectory, mainAssemblyDirectory))
            {
                return((int)AssemblyLoaderError.MainAssemblyPathNotProvided);
            }

            if (!ReloadAppDomain())
            {
                return((int)AssemblyLoaderError.LoadFailed);
            }

            return(0);
        }
예제 #2
0
        public static int DllMain(string arg)
        {
            try
            {
                Args args = new Args(arg);

                if (!SharedRuntimeState.Initialized)
                {
                    SharedRuntimeState.Initialize((IntPtr)args.GetInt64("RuntimeState"));

                    AssemblyContextRef currentContext;
                    AssemblyContextRef.TryParse(args.GetString("AssemblyContext"), out currentContext);
                    AssemblyContext.Initialize(currentContext);
                    CurrentAssemblyContext.Initialize(currentContext);
                }

                if (args.GetBool("Preloading"))
                {
                    Preloading = true;
                    IntPtr address = (IntPtr)args.GetInt64("RegisterFuncs");
                    if (address != IntPtr.Zero)
                    {
                        NativeFunctions.RegisterFunctions(address);
                        Preloaded = true;
                    }
                    Preloading = false;
                    return(0);
                }
                else
                {
                    unsafe
                    {
                        SharedRuntimeState.Instance->ActiveRuntime = SharedRuntimeState.CurrentRuntime;
                    }

                    DateTime beginUnload = default(DateTime);
                    TimeSpan beginReload = DateTime.Now.TimeOfDay;

                    bool isReloading = false;
                    using (var timing = HotReload.Timing.Create(HotReload.Timing.TotalLoadTime))
                    {
                        using (var subTiming = HotReload.Timing.Create(HotReload.Timing.DataStore_Load))
                        {
                            // If this is a hot-reload then set up the data store
                            HotReload.Data = HotReload.DataStore.Load(SharedRuntimeState.GetHotReloadData());
                            beginUnload    = HotReload.Data.BeginUnloadTime;
                        }

                        HotReload.IsReloading = args.GetBool("Reloading");
                        isReloading           = HotReload.IsReloading;

                        IntPtr address = (IntPtr)args.GetInt64("RegisterFuncs");
                        if (address != IntPtr.Zero)
                        {
                            NativeFunctions.RegisterFunctions(address);
                        }
                    }

                    SharedRuntimeState.SetHotReloadAssemblyPaths(HotReloadAssemblyPaths);

                    TimeSpan endTime = DateTime.Now.TimeOfDay;
                    FMessage.Log("BeginReload: " + beginReload + " (BeginUnload-BeginReload: " + (beginReload - beginUnload.TimeOfDay) + ")");
                    FMessage.Log("EndReload: " + endTime + " (BeginUnload-EndReload: " + (endTime - beginUnload.TimeOfDay) + ")");
                    HotReload.Timing.Print(isReloading);
                    HotReload.Timing.PrintAll();
                    return(0);
                }
            }
            catch (Exception e)
            {
                string exceptionStr = "Entry point exception (UnrealEngine.Runtime): " + e;
                if (SharedRuntimeState.Initialized)
                {
                    SharedRuntimeState.LogError(exceptionStr);
                    SharedRuntimeState.MessageBox(exceptionStr, "Error");
                }
                return(1005);// AssemblyLoaderError.Exception
            }
        }
예제 #3
0
        public static int DllMain(string arg)
        {
            try
            {
                Args args = new Args(arg);

                SharedRuntimeState.Initialize((IntPtr)args.GetInt64("RuntimeState"));
                Runtime.AssemblyContext.Initialize();

                mainAssemblyPath = args.GetString("MainAssembly");
                if (!string.IsNullOrEmpty(mainAssemblyPath))
                {
                    if (string.IsNullOrEmpty(mainAssemblyPath) || !File.Exists(mainAssemblyPath))
                    {
                        return((int)AssemblyLoaderError.MainAssemblyNotFound);
                    }
                    mainAssemblyDirectory = Path.GetDirectoryName(mainAssemblyPath);
                }
                else
                {
                    return((int)AssemblyLoaderError.MainAssemblyPathNotProvided);
                }

                IntPtr addTickerAddr      = (IntPtr)args.GetInt64("AddTicker");
                IntPtr isInGameThreadAddr = (IntPtr)args.GetInt64("IsInGameThread");
                if (addTickerAddr == IntPtr.Zero || isInGameThreadAddr == IntPtr.Zero)
                {
                    return((int)AssemblyLoaderError.GameThreadHelpersNull);
                }
                GameThreadHelper.Init(addTickerAddr, isInGameThreadAddr, OnRuntimeChanged);

                Debug.Assert(GameThreadHelper.IsInGameThread());

                entryPointArg = arg;

                string currentAssemblyPath     = Assembly.GetExecutingAssembly().Location;
                string currentAssemblyFileName = Path.GetFileNameWithoutExtension(currentAssemblyPath);
                currentAssemblyDirectory = Path.GetDirectoryName(currentAssemblyPath);

                if (!IsSameOrSubDirectory(currentAssemblyDirectory, mainAssemblyDirectory))
                {
                    return((int)AssemblyLoaderError.MainAssemblyPathNotProvided);
                }

                // If there is already a loaded runtime only do a pre-load
                if (SharedRuntimeState.GetLoadedRuntimes() != EDotNetRuntime.None)
                {
                    Debug.Assert(mainContextRef.IsInvalid);

                    // Make sure the main assembly path exists
                    if (!File.Exists(mainAssemblyPath))
                    {
                        return((int)AssemblyLoaderError.LoadFailed);
                    }

                    // Make sure we are using assmbly contexts loadding otherwise hotreload wont work which defeats the purpose of
                    // using multiple runtimes
                    if (LoadAssemblyWithoutContexts)
                    {
                        return((int)AssemblyLoaderError.LoadFailed);
                    }

                    // Preload now and then do a full load when NextRuntime is set to this runtime type
                    PreloadNextContext();

                    // Watch for assembly changes (the paths should have been set up by the full load in the other runtime)
                    UpdateAssemblyWatchers();

                    return(0);
                }

                unsafe
                {
                    SharedRuntimeState.Instance->ActiveRuntime = SharedRuntimeState.CurrentRuntime;
                }

                bool loaded;
                if (LoadAssemblyWithoutContexts)
                {
                    loaded = LoadWithoutUsingContexts();
                }
                else
                {
                    loaded = ReloadMainContext();
                }
                if (!loaded)
                {
                    unsafe
                    {
                        SharedRuntimeState.Instance->ActiveRuntime = EDotNetRuntime.None;
                    }
                    return((int)AssemblyLoaderError.LoadFailed);
                }
            }
            catch (Exception e)
            {
                string exceptionStr = "Entry point exception (Loader): " + e;
                if (SharedRuntimeState.Initialized)
                {
                    SharedRuntimeState.LogError(exceptionStr);
                    SharedRuntimeState.MessageBox(exceptionStr, errorMsgBoxTitle);
                }
                return((int)AssemblyLoaderError.Exception);
            }

            return(0);
        }