Beispiel #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.");
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the framework.
        /// </summary>
        internal static string Initialize()
        {
            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.");
                }

                // 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.");
                }

                // 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.");
            }
            catch (Exception ex)
            {
                if (Log != null)
                {
                    Log.Append(ex);
                }

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

            return(null);
        }