public LuaRegisteredFunctionsList(IMainFormForApi mainForm, LuaFunctionList registeredFunctions)
 {
     _mainForm            = mainForm;
     _registeredFunctions = registeredFunctions;
     InitializeComponent();
     Icon = Properties.Resources.TextDocIcon;
 }
Ejemplo n.º 2
0
 public static IExternalApiProvider Restart(IMainFormForApi mainForm, IEmulatorServiceProvider newServiceProvider)
 {
     GlobalWin.ClientApi = null;
     _container          = Register(mainForm, newServiceProvider, Console.WriteLine);
     GlobalWin.ClientApi = _container.EmuClient as EmuClientApi;
     return(new BasicApiProvider(_container));
 }
Ejemplo n.º 3
0
        private static ApiContainer Register(
            IMainFormForApi mainForm,
            IEmulatorServiceProvider serviceProvider,
            Action <string> logCallback)
        {
            var libDict = new Dictionary <Type, IExternalApi>();

            foreach (var api in Assembly.GetAssembly(typeof(ApiSubsetContainer)).GetTypes()
                     .Concat(Assembly.GetAssembly(typeof(ApiContainer)).GetTypes())
                     .Where(t => /*t.IsClass && */ t.IsSealed &&
                            typeof(IExternalApi).IsAssignableFrom(t) &&
                            ServiceInjector.IsAvailable(serviceProvider, t)))
            {
                //TODO if extra params are ignored, we can use the same array for every ConstructorInfo.Invoke call --yoshi
                object instance;
                if (typeof(IEmuClientApi).IsAssignableFrom(api))
                {
                    instance = (api.GetConstructor(CtorParamTypesEmuClientApi) ?? throw new Exception("failed to call EmuClientApi's hack-filled ctor"))
                               .Invoke(new object[] { logCallback, GlobalWin.DisplayManager, GlobalWin.InputManager, mainForm, GlobalWin.Config, GlobalWin.Emulator, GlobalWin.Game });
                }
                else
                {
                    instance = api.GetConstructor(CtorParamTypesA)?.Invoke(new object[] { logCallback, GlobalWin.DisplayManager, GlobalWin.InputManager, mainForm })
                               ?? api.GetConstructor(CtorParamTypesB)?.Invoke(new object[] { logCallback })
                               ?? Activator.CreateInstance(api);
                }
                ServiceInjector.UpdateServices(serviceProvider, instance);
                libDict.Add(
                    api.GetInterfaces().First(intf => typeof(IExternalApi).IsAssignableFrom(intf) && intf != typeof(IExternalApi)),
                    (IExternalApi)instance
                    );
            }
            return(new ApiContainer(libDict));
        }
Ejemplo n.º 4
0
 public EmuClientApi(Action <string> logCallback, IMainFormForApi mainForm, DisplayManagerBase displayManager, Config config, IEmulator emulator, IGameInfo game)
 {
     _config         = config;
     _displayManager = displayManager;
     Emulator        = emulator;
     Game            = game;
     _logCallback    = logCallback;
     _mainForm       = mainForm;
     VideoProvider   = Emulator.AsVideoProviderOrDefault();
 }
Ejemplo n.º 5
0
        private static ApiContainer Register(
            IMainFormForApi mainForm,
            IEmulatorServiceProvider serviceProvider,
            Action <string> logCallback)
        {
            var libDict = _apiTypes.Keys.Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
                          .ToDictionary(
                t => _apiTypes[t],
                t => (IExternalApi)(
                    t.GetConstructor(_ctorParamTypesC)?.Invoke(new object[] { logCallback, mainForm, GlobalWin.DisplayManager, GlobalWin.InputManager, GlobalWin.Config, GlobalWin.Emulator, GlobalWin.Game })
                    ?? t.GetConstructor(_ctorParamTypesB)?.Invoke(new object[] { logCallback, mainForm })
                    ?? t.GetConstructor(_ctorParamTypesA)?.Invoke(new object[] { logCallback })
                    ?? Activator.CreateInstance(t)
                    )
                );

            foreach (var instance in libDict.Values)
            {
                ServiceInjector.UpdateServices(serviceProvider, instance);
            }
            return(new ApiContainer(libDict));
        }
Ejemplo n.º 6
0
 public InputApi(Action <string> logCallback, DisplayManager displayManager, InputManager inputManager, IMainFormForApi mainForm)
 {
     _displayManager = displayManager;
     _inputManager   = inputManager;
     _mainForm       = mainForm;
 }
Ejemplo n.º 7
0
        public Win32LuaLibraries(IMainFormForApi mainForm, IEmulatorServiceProvider serviceProvider)
            : this()
        {
            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(mainForm, 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));
                }
            }
        }
Ejemplo n.º 8
0
 public InputApi(Action <string> logCallback, IMainFormForApi mainForm, DisplayManager displayManager, InputManager inputManager, Config config, IEmulator emulator, GameInfo game)
 {
     _displayManager = displayManager;
     _inputManager   = inputManager;
     _mainForm       = mainForm;
 }
Ejemplo n.º 9
0
 public static ApiContainer RestartLua(IMainFormForApi mainForm, IEmulatorServiceProvider newServiceProvider, Action <string> logCallback)
 => _luaContainer = Register(mainForm, newServiceProvider, logCallback);
Ejemplo n.º 10
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
        }
Ejemplo n.º 11
0
 public SaveStateApi(Action <string> logCallback, DisplayManager displayManager, InputManager inputManager, IMainFormForApi mainForm)
 {
     LogCallback = logCallback;
     _mainForm   = mainForm;
 }
 public SaveStateApi(Action <string> logCallback, IMainFormForApi mainForm)
 {
     LogCallback = logCallback;
     _mainForm   = mainForm;
 }