Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ToolManager"/> class.
 /// </summary>
 public ToolManager(
     MainForm owner,
     Config config,
     IEmulator emulator,
     IMovieSession movieSession)
 {
     _owner        = owner;
     _config       = config;
     _emulator     = emulator;
     _movieSession = movieSession;
     _apiProvider  = ApiManager.Restart(_emulator.ServiceProvider);
 }
Esempio n. 2
0
 public void Restart(
     IEmulatorServiceProvider newServiceProvider,
     Config config,
     IEmulator emulator,
     IGameInfo game)
 {
     _apiContainer = ApiManager.RestartLua(newServiceProvider, LogToLuaConsole, _mainForm, _displayManager, _inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);
     foreach (var lib in Libraries.Values)
     {
         lib.APIs = _apiContainer;
         ServiceInjector.UpdateServices(newServiceProvider, lib);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ToolManager"/> class.
 /// </summary>
 public ToolManager(
     MainForm owner,
     Config config,
     InputManager inputManager,
     IEmulator emulator,
     IMovieSession movieSession,
     IGameInfo game)
 {
     _owner        = owner;
     _config       = config;
     _inputManager = inputManager;
     _emulator     = emulator;
     _movieSession = movieSession;
     _game         = game;
     _apiProvider  = ApiManager.Restart(_owner, _emulator.ServiceProvider);
 }
Esempio n. 4
0
        public Win32LuaLibraries(IEmulatorServiceProvider serviceProvider, MainForm mainForm)
            : this()
        {
            _mainForm = mainForm;

            LuaWait = new AutoResetEvent(false);
            Docs.Clear();

            // Register lua libraries
            foreach (var lib in Assembly.Load("BizHawk.Client.Common").GetTypes()
                     .Concat(Assembly.GetAssembly(typeof(Win32LuaLibraries)).GetTypes())
                     .Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t) && t.IsSealed && ServiceInjector.IsAvailable(serviceProvider, t)))
            {
                bool addLibrary = true;
                var  attributes = lib.GetCustomAttributes(typeof(LuaLibraryAttribute), false);
                if (attributes.Any())
                {
                    addLibrary = VersionInfo.DeveloperBuild || ((LuaLibraryAttribute)attributes.First()).Released;
                }

                if (addLibrary)
                {
                    var instance = (LuaLibraryBase)Activator.CreateInstance(lib, _lua);
                    instance.LuaRegister(lib, Docs);
                    instance.LogOutputCallback = ConsoleLuaLibrary.LogOutput;
                    ServiceInjector.UpdateServices(serviceProvider, instance);

                    // TODO: make EmuHawk libraries have a base class with common properties such as this
                    // and inject them here
                    if (instance is ClientLuaLibrary clientLib)
                    {
                        clientLib.MainForm = _mainForm;
                    }

                    ApiContainerInstance = ApiManager.RestartLua(serviceProvider, ConsoleLuaLibrary.LogOutput);
                    if (instance is DelegatingLuaLibraryEmu dlgInstanceEmu)
                    {
                        dlgInstanceEmu.APIs = ApiContainerInstance;                                                                         // this is necessary as the property has the `new` modifier
                    }
                    else if (instance is DelegatingLuaLibrary dlgInstance)
                    {
                        dlgInstance.APIs = ApiContainerInstance;
                    }

                    Libraries.Add(lib, instance);
                }
            }

            _lua.RegisterFunction("print", this, GetType().GetMethod("Print"));

            EmulationLuaLibrary.FrameAdvanceCallback = Frameadvance;
            EmulationLuaLibrary.YieldCallback        = EmuYield;

            // Add LuaCanvas to Docs
            Type luaCanvas = typeof(LuaCanvas);

            foreach (var method in luaCanvas.GetMethods())
            {
                if (method.GetCustomAttributes(typeof(LuaMethodAttribute), false).Length != 0)
                {
                    Docs.Add(new LibraryFunction(nameof(LuaCanvas), luaCanvas.Description(), method));
                }
            }
        }
Esempio n. 5
0
        public Win32LuaLibraries(
            LuaFileList scriptList,
            LuaFunctionList registeredFuncList,
            IEmulatorServiceProvider serviceProvider,
            MainForm mainForm,
            DisplayManagerBase displayManager,
            InputManager inputManager,
            Config config,
            IEmulator emulator,
            IGameInfo game)
        {
            void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
            {
                if (instance != null)
                {
                    _lua.NewTable(name);
                }
                foreach (var method in type.GetMethods())
                {
                    var foundAttrs = method.GetCustomAttributes(typeof(LuaMethodAttribute), false);
                    if (foundAttrs.Length == 0)
                    {
                        continue;
                    }
                    if (instance != null)
                    {
                        _lua.RegisterFunction($"{name}.{((LuaMethodAttribute) foundAttrs[0]).Name}", instance, method);
                    }
                    Docs.Add(new LibraryFunction(
                                 name,
                                 type.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast <DescriptionAttribute>()
                                 .Select(descAttr => descAttr.Description).FirstOrDefault() ?? string.Empty,
                                 method
                                 ));
                }
            }

            if (true /*NLua.Lua.WhichLua == "NLua"*/)
            {
                _lua["keepalives"] = _lua.NewTable();
            }
            _th                 = new NLuaTableHelper(_lua, LogToLuaConsole);
            _displayManager     = displayManager;
            _inputManager       = inputManager;
            _mainForm           = mainForm;
            LuaWait             = new AutoResetEvent(false);
            PathEntries         = config.PathEntries;
            RegisteredFunctions = registeredFuncList;
            ScriptList          = scriptList;
            Docs.Clear();
            _apiContainer = ApiManager.RestartLua(serviceProvider, LogToLuaConsole, _mainForm, _displayManager, _inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);

            // Register lua libraries
            foreach (var lib in Client.Common.ReflectionCache.Types.Concat(EmuHawk.ReflectionCache.Types)
                     .Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t) && t.IsSealed && ServiceInjector.IsAvailable(serviceProvider, t)))
            {
                bool addLibrary = true;
                var  attributes = lib.GetCustomAttributes(typeof(LuaLibraryAttribute), false);
                if (attributes.Any())
                {
                    addLibrary = VersionInfo.DeveloperBuild || ((LuaLibraryAttribute)attributes.First()).Released;
                }

                if (addLibrary)
                {
                    var instance = (LuaLibraryBase)Activator.CreateInstance(lib, this, _apiContainer, (Action <string>)LogToLuaConsole);
                    ServiceInjector.UpdateServices(serviceProvider, instance);

                    // TODO: make EmuHawk libraries have a base class with common properties such as this
                    // and inject them here
                    if (instance is ClientLuaLibrary clientLib)
                    {
                        clientLib.MainForm = _mainForm;
                    }
                    else if (instance is ConsoleLuaLibrary consoleLib)
                    {
                        consoleLib.Tools         = _mainForm.Tools;
                        _logToLuaConsoleCallback = consoleLib.Log;
                    }
                    else if (instance is GuiLuaLibrary guiLib)
                    {
                        // emu lib may be null now, depending on order of ReflectionCache.Types, but definitely won't be null when this is called
                        guiLib.CreateLuaCanvasCallback = (width, height, x, y) =>
                        {
                            var canvas = new LuaCanvas(EmulationLuaLibrary, width, height, x, y, _th, LogToLuaConsole);
                            canvas.Show();
                            return(_th.ObjectToTable(canvas));
                        };
                    }
                    else if (instance is TAStudioLuaLibrary tastudioLib)
                    {
                        tastudioLib.Tools = _mainForm.Tools;
                    }

                    EnumerateLuaFunctions(instance.Name, lib, instance);
                    Libraries.Add(lib, instance);
                }
            }

            _lua.RegisterFunction("print", this, typeof(Win32LuaLibraries).GetMethod(nameof(Print)));

            EmulationLuaLibrary.FrameAdvanceCallback = Frameadvance;
            EmulationLuaLibrary.YieldCallback        = EmuYield;

            EnumerateLuaFunctions(nameof(LuaCanvas), typeof(LuaCanvas), null);             // add LuaCanvas to Lua function reference table
        }
Esempio n. 6
0
        public Win32LuaLibraries(IMainFormForApi mainForm, IEmulatorServiceProvider serviceProvider)
            : this()
        {
            void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
            {
                instance?.Lua?.NewTable(name);
                foreach (var method in type.GetMethods())
                {
                    var foundAttrs = method.GetCustomAttributes(typeof(LuaMethodAttribute), false);
                    if (foundAttrs.Length == 0)
                    {
                        continue;
                    }
                    instance?.Lua?.RegisterFunction($"{name}.{((LuaMethodAttribute) foundAttrs[0]).Name}", instance, method);
                    Docs.Add(new LibraryFunction(
                                 name,
                                 type.GetCustomAttributes(typeof(DescriptionAttribute), false).Cast <DescriptionAttribute>()
                                 .Select(descAttr => descAttr.Description).FirstOrDefault() ?? string.Empty,
                                 method
                                 ));
                }
            }

            LuaWait = new AutoResetEvent(false);
            Docs.Clear();

            // Register lua libraries
            foreach (var lib in Assembly.Load("BizHawk.Client.Common").GetTypes()
                     .Concat(Assembly.GetAssembly(typeof(Win32LuaLibraries)).GetTypes())
                     .Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t) && t.IsSealed && ServiceInjector.IsAvailable(serviceProvider, t)))
            {
                bool addLibrary = true;
                var  attributes = lib.GetCustomAttributes(typeof(LuaLibraryAttribute), false);
                if (attributes.Any())
                {
                    addLibrary = VersionInfo.DeveloperBuild || ((LuaLibraryAttribute)attributes.First()).Released;
                }

                if (addLibrary)
                {
                    var instance = (LuaLibraryBase)Activator.CreateInstance(lib, _lua);
                    instance.LogOutputCallback = ConsoleLuaLibrary.LogOutput;
                    ServiceInjector.UpdateServices(serviceProvider, instance);

                    // TODO: make EmuHawk libraries have a base class with common properties such as this
                    // and inject them here
                    if (instance is ClientLuaLibrary clientLib)
                    {
                        clientLib.MainForm = mainForm;
                    }

                    ApiContainerInstance = ApiManager.RestartLua(mainForm, serviceProvider, ConsoleLuaLibrary.LogOutput);
                    if (instance is DelegatingLuaLibrary dlgInstance)
                    {
                        dlgInstance.APIs = ApiContainerInstance;
                    }

                    EnumerateLuaFunctions(instance.Name, lib, instance);
                    Libraries.Add(lib, instance);
                }
            }

            _lua.RegisterFunction("print", this, GetType().GetMethod("Print"));

            EmulationLuaLibrary.FrameAdvanceCallback = Frameadvance;
            EmulationLuaLibrary.YieldCallback        = EmuYield;

            EnumerateLuaFunctions(nameof(LuaCanvas), typeof(LuaCanvas), null);             // add LuaCanvas to Lua function reference table
        }