Esempio n. 1
0
        /// <summary>
        /// Perform the actual initialization.
        /// </summary>
        /// <param name="p">The parameters.</param>
        internal static void _Initialize_Actual(FrameworkInitializationParameters p)
        {
            // Prepare code for .NET hooking.
            Memory.PrepareNETHook();

            // Initialize assembly loader for plugin loading.
            Loader.Initialize();

            // Prepare game info before loading plugins.
            LoadGameInfo();

            // Load plugins.
            PluginManager.Initialize();

            // Write startup info.
            Log.AppendLine("Finished framework initialization.");
        }
Esempio n. 2
0
        /// <summary>
        /// Runs the delayed initialization on another thread.
        /// </summary>
        private static void _Run_Delayed_Initialize()
        {
            var p = _saved_p;

            _saved_p = null;

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            while (sw.ElapsedMilliseconds < p.DelayedInitialize)
            {
                Thread.Sleep(1);
            }

            try
            {
                _Initialize_Actual(p);
            }
            catch (Exception ex)
            {
                CriticalException(ex, false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes the framework.
        /// </summary>
        /// <param name="p">The parameters.</param>
        internal static string Initialize(FrameworkInitializationParameters p)
        {
            try
            {
                // Make sure state is correct.
                if (Interlocked.CompareExchange(ref Status, 1, 0) != 0)
                {
                    throw new InvalidOperationException("Trying to initialize the framework more than once!");
                }

                if (GetRuntimeVersion() < RequiredRuntimeVersion)
                {
                    throw new InvalidOperationException("The runtime DLL version is too old! Make sure NetScriptFramework.Runtime.dll is updated.");
                }

                // Setup path.
                FrameworkPath = p.FrameworkPath;

                // This is needed later so we can cache this call.
                FrameworkAssembly = System.Reflection.Assembly.GetExecutingAssembly();

                // Initialize ID generator.
                IDGenerator = new Tools.UIDGenerator();

                // Allocate trash memory.
                {
                    var alloc = Memory.Allocate(1024);
                    alloc.Pin();
                    TrashMemory = alloc.Address;
                }

                // Prepare and load configuration file.
                bool loadedConfiguration = PrepareAndLoadConfiguration();

                // Initialize log file.
                InitializeLog();

                // Setup managed unhandled exception filter.
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                // Setup exit handler.
                AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

                // Write startup info.
                Log.AppendLine("Initializing framework version " + FrameworkVersion + ".");
                if (!loadedConfiguration)
                {
                    Log.AppendLine("Warning: failed to load configuration file! Attempting to create a new default one.");
                }
                else
                {
                    Log.AppendLine("Loaded configuration file.");
                }

                // Initialize.
                if (p.DelayedInitialize > 0)
                {
                    _saved_p = p;
                    var t = new Thread(_Run_Delayed_Initialize);
                    t.Start();
                }
                else
                {
                    _Initialize_Actual(p);
                }
            }
            catch (Exception ex)
            {
                if (Log != null)
                {
                    Log.Append(ex);
                }

                return(ex.GetType().Name + "(" + (ex.Message ?? string.Empty) + ")");
            }

            return(null);
        }