Beispiel #1
0
        public void UnloadPlugin(AsiPlugin plugin)
        {
            string name = plugin.Name;

            Log.Info("Unloading \"" + name + '"');

            foreach (AsiThread thread in plugin.ScriptThreads)
            {
                if (thread.Fiber.IsAlive)
                {
                    thread.Fiber.Abort();
                }
            }

            IntPtr module = plugin.Module;

            if (module != IntPtr.Zero)
            {
                if (FreeLibrary(module))
                {
                    Log.Info("Plugin \"" + name + "\" unloaded successfully.");
                }
                else
                {
                    Log.Error("Unable to unload plugin \"" + name + "\", you will need to reboot your game to load it again: " + new Win32Exception(Marshal.GetLastWin32Error()));
                }
            }
            else
            {
                Log.Warn("Unable to release plugin module. Either the module was never loaded, or you will need to reboot your game to load it again.");
            }

            this.LoadedPlugins.Remove(plugin);
        }
Beispiel #2
0
        private static void ScriptRegisterAdditionalThread(IntPtr module, IntPtr threadMain)
        {
            AsiPlugin plugin = Support.Instance.Loader.GetPlugin(module);

            if (plugin != null)
            {
                plugin.ScriptThreads.Add(new AsiThread(plugin.Name + "-additional" + (plugin.ScriptThreads.Count - 1), Marshal.GetDelegateForFunctionPointer <Action>(threadMain)));
            }
            else
            {
                Log.Warn("Unable to register additional script thread: unknown plugin");
            }
        }
Beispiel #3
0
        private static void ScriptRegister(IntPtr module, IntPtr scriptMain)
        {
            AsiPlugin plugin = Support.Instance.Loader.GetPlugin(module);

            if (plugin != null)
            {
                plugin.ScriptThreads.Add(new AsiThread(plugin.Name + "-main", Marshal.GetDelegateForFunctionPointer <Action>(scriptMain)));
            }
            else
            {
                Log.Warn("Unable to register script: unknown plugin");
            }
        }
Beispiel #4
0
 public void LoadPlugin(string name)
 {
     if (!this.IsLoaded(name))
     {
         if (AsiPlugin.Exists(name))
         {
             this.LoadPlugin(new AsiPlugin(name));
         }
         else
         {
             Log.Info("Cannot load plugin \"" + name + "\" as it doesn't exist");
         }
     }
     else
     {
         Log.Info("Plugin \"" + name + "\" is already loaded.");
     }
 }
Beispiel #5
0
        public void LoadPlugin(AsiPlugin plugin)
        {
            this.Loading = true;
            Log.Info("Loading \"" + plugin.Name + '"');

            try
            {
                //In case ScriptHookV is present and has already loaded the ASI
                Game.TerminateAllScriptsWithName(plugin.Name.ToLower() + ".asi");

                if (plugin.Type == AsiType.NonUniversal)
                {
                    Log.Info("Non universal ASI detected. Converting it...");
                    plugin.ConvertAsi();
                    this.integrityMap.UpdateConversionHash(plugin.Name, IOUtil.GetFileChecksum(plugin.Name + ".asi"), IOUtil.GetFileChecksum(plugin.UASIPath));
                    Log.Info("Plugin converted successfully.");
                    GameFiber.Yield();
                }
                else if (plugin.Type == AsiType.UniversalConverted)
                {
                    bool outdated;

                    if (this.integrityMap.HasConversionHash(plugin.Name))
                    {
                        outdated = IOUtil.GetFileChecksum(plugin.Name + ".asi") != this.integrityMap.GetAsiHash(plugin.Name) || IOUtil.GetFileChecksum(plugin.UASIPath) != this.integrityMap.GetUnivHash(plugin.Name);
                    }
                    else
                    {
                        outdated = true;
                    }

                    if (outdated)
                    {
                        Log.Info("New version of ASI detected. Converting it again...");
                        plugin.ConvertAsi();
                        this.integrityMap.UpdateConversionHash(plugin.Name, IOUtil.GetFileChecksum(plugin.Name + ".asi"), IOUtil.GetFileChecksum(plugin.UASIPath));
                        Log.Info("Plugin converted successfully.");
                    }

                    GameFiber.Yield();
                }

                this.LoadedPlugins.Add(plugin);

                IntPtr module = LoadLibraryA(plugin.UASIPath);

                if (module != IntPtr.Zero)
                {
                    if (plugin.ScriptThreads.Count > 0)
                    {
                        Log.Info("Plugin \"" + plugin.Name + "\" loaded successfully.");

                        foreach (AsiThread thread in plugin.ScriptThreads)
                        {
                            thread.Start();
                        }
                    }
                    else
                    {
                        Log.Warn("Plugin \"" + plugin.Name + "\" has been loaded successfully, but didn't register any thread. Try rebooting your game to fix this issue.");
                    }
                }
                else
                {
                    this.LoadedPlugins.Remove(plugin);
                    Log.Error("Unable to load \"" + plugin.Name + "\", try rebooting your game: " + new Win32Exception(Marshal.GetLastWin32Error()));
                }

                this.Loading = false;

                if (this.integrityMap.Dirty)
                {
                    this.integrityMap.SaveMap();
                }
            }
            catch (NotScriptException)
            {
                Log.Info("Skipping \"" + plugin.Name + "\" as it is not a ScriptHookV script.");
            }
            catch (Exception e)
            {
                if (this.LoadedPlugins.Contains(plugin))
                {
                    this.LoadedPlugins.Remove(plugin);
                }

                Log.Error("Unable to load \"" + plugin.Name + "\": " + e);
            }
        }