Exemplo n.º 1
0
        public bool IsAvailable(Type t)
        {
            if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, t))
            {
                return(false);
            }

            if (t == typeof(LuaConsole) && OSTailoredCode.CurrentOS != OSTailoredCode.DistinctOS.Windows)
            {
                return(false);
            }

            var tool = Assembly
                       .GetExecutingAssembly()
                       .GetTypes()
                       .FirstOrDefault(type => type == t);

            if (tool == null)             // This isn't a tool, must not be available
            {
                return(false);
            }

            var attr = tool.GetCustomAttributes(false)
                       .OfType <ToolAttribute>()
                       .FirstOrDefault();

            // start with the assumption that if no supported systems are mentioned and no unsupported cores are mentioned
            // then this is available for all
            bool supported = true;

            if (attr?.SupportedSystems != null && attr.SupportedSystems.Any())
            {
                // supported systems are available
                supported = attr.SupportedSystems.Contains(Global.Emulator.SystemId);

                if (supported)
                {
                    // check for a core not supported override
                    if (attr.UnsupportedCores.Contains(Global.Emulator.DisplayName()))
                    {
                        supported = false;
                    }
                }
            }
            else if (attr?.UnsupportedCores != null && attr.UnsupportedCores.Any())
            {
                // no supported system specified, but unsupported cores are
                if (attr.UnsupportedCores.Contains(Global.Emulator.DisplayName()))
                {
                    supported = false;
                }
            }

            return(supported);
        }
Exemplo n.º 2
0
        private void SetTools()
        {
            ToolBoxStrip.Items.Clear();

            foreach (var t in Assembly.GetAssembly(GetType()).GetTypes())
            {
                if (!typeof(IToolForm).IsAssignableFrom(t))
                {
                    continue;
                }
                if (!typeof(Form).IsAssignableFrom(t))
                {
                    continue;
                }
                if (typeof(ToolBox).IsAssignableFrom(t))                  //yo dawg i head you like toolboxes
                {
                    continue;
                }
                if (VersionInfo.DeveloperBuild && t.GetCustomAttributes(false).OfType <ToolAttribute>().Any(a => !a.Released))
                {
                    continue;
                }
                if (t == typeof(GBGameGenie))                 // Hack, this tool is specific to a system id and a sub-system (gb and gg) we have no reasonable way to declare a dependency like that
                {
                    continue;
                }
                if (!ServiceInjector.IsAvailable(Emulator.ServiceProvider, t))
                {
                    continue;
                }
//				if (!ApiInjector.IsAvailable(, t))
//					continue;
                if (t == typeof(HexView) && OSTailoredCode.CurrentOS != OSTailoredCode.DistinctOS.Windows)
                {
                    continue;                     // Skip this tool on Unix. It isn't finished and only causes exceptions
                }
                var instance = Activator.CreateInstance(t);

                var tsb = new ToolStripButton
                {
                    Image        = (instance as Form).Icon.ToBitmap(),
                    Text         = (instance as Form).Text,
                    DisplayStyle = (instance as Form).ShowIcon ? ToolStripItemDisplayStyle.Image : ToolStripItemDisplayStyle.Text
                };

                tsb.Click += (o, e) =>
                {
                    GlobalWin.Tools.Load(t);
                    Close();
                };

                ToolBoxStrip.Items.Add(tsb);
            }
        }
Exemplo n.º 3
0
        private void SetTools()
        {
            //RTC_HIJACK : Kill toolbox
            return;

            ToolBoxStrip.Items.Clear();

            foreach (var t in Assembly.GetAssembly(GetType()).GetTypes())
            {
                if (!typeof(IToolForm).IsAssignableFrom(t))
                {
                    continue;
                }
                if (!typeof(Form).IsAssignableFrom(t))
                {
                    continue;
                }
                if (typeof(ToolBox).IsAssignableFrom(t))                  //yo dawg i head you like toolboxes
                {
                    continue;
                }
                if (VersionInfo.DeveloperBuild && t.GetCustomAttributes(false).OfType <ToolAttribute>().Any(a => !a.Released))
                {
                    continue;
                }
                if (t == typeof(GBGameGenie))                 // Hack, this tool is specific to a system id and a sub-system (gb and gg) we have no reasonable way to declare a dependency like that
                {
                    continue;
                }
                if (!ServiceInjector.IsAvailable(Emulator.ServiceProvider, t))
                {
                    continue;
                }

                var instance = Activator.CreateInstance(t);

                var tsb = new ToolStripButton
                {
                    Image        = (instance as Form).Icon.ToBitmap(),
                    Text         = (instance as Form).Text,
                    DisplayStyle = (instance as Form).ShowIcon ? ToolStripItemDisplayStyle.Image : ToolStripItemDisplayStyle.Text
                };

                tsb.Click += (o, e) =>
                {
                    GlobalWin.Tools.Load(t);
                    Close();
                };

                ToolBoxStrip.Items.Add(tsb);
            }
        }
Exemplo n.º 4
0
        public EmuLuaLibrary(LuaConsole passed, IEmulatorServiceProvider serviceProvider)
            : this()
        {
            LuaWait = new AutoResetEvent(false);
            Docs.Clear();
            _caller = passed.Get();

            // Register lua libraries
            var libs = Assembly
                       .Load("BizHawk.Client.Common")
                       .GetTypes()
                       .Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t))
                       .Where(t => t.IsSealed)
                       .Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
                       .ToList();

            libs.AddRange(
                Assembly
                .GetAssembly(typeof(EmuLuaLibrary))
                .GetTypes()
                .Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t))
                .Where(t => t.IsSealed)
                .Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
                );

            foreach (var lib in libs)
            {
                bool addLibrary = true;
                var  attributes = lib.GetCustomAttributes(typeof(LuaLibraryAttributes), false);
                if (attributes.Any())
                {
                    addLibrary = VersionInfo.DeveloperBuild || (attributes.First() as LuaLibraryAttributes).Released;
                }

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

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

            EmulatorLuaLibrary.FrameAdvanceCallback = Frameadvance;
            EmulatorLuaLibrary.YieldCallback        = EmuYield;
        }
Exemplo n.º 5
0
        public void Restart()
        {
            // If Cheat tool is loaded, restarting will restart the list too anyway
            if (!GlobalWin.Tools.Has <Cheats>())
            {
                Global.CheatList.NewList(GenerateDefaultCheatFilename(), autosave: true);
            }

            var unavailable = new List <IToolForm>();

            foreach (var tool in _tools)
            {
                if (ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, tool.GetType()))
                {
                    ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, tool);
                    bool restartTool = false;
                    if ((tool.IsHandleCreated && !tool.IsDisposed) || tool is RamWatch)                     // Hack for Ram Watch - in display watches mode it wants to keep running even closed, it will handle disposed logic
                    {
                        restartTool = true;
                    }
                    if (tool is LuaConsole && ((LuaConsole)tool).IsRebootingCore)
                    {
                        restartTool = false;
                    }
                    if (restartTool)
                    {
                        tool.Restart();
                    }
                }
                else
                {
                    unavailable.Add(tool);
                    ServiceInjector.ClearServices(tool);                     // the services of the old emulator core are no longer valid on the tool
                }
            }

            foreach (var tool in unavailable)
            {
                tool.Close();
                _tools.Remove(tool);
            }
        }
Exemplo n.º 6
0
        public bool IsAvailable(Type tool)
        {
            if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, tool) ||
                !lazyAsmTypes.Value.Contains(tool.AssemblyQualifiedName) ||                 // not a tool
                (tool == typeof(LuaConsole) && OSTailoredCode.CurrentOS != OSTailoredCode.DistinctOS.Windows))                    // simply doesn't work (for now)
            {
                return(false);
            }

            ToolAttribute attr = tool.GetCustomAttributes(false).OfType <ToolAttribute>().SingleOrDefault();

            if (attr == null)
            {
                return(true);                // no ToolAttribute on given type -> assumed all supported
            }

            var sysName = Global.Emulator.DisplayName();

            return(!attr.UnsupportedCores.Contains(sysName) &&          // not unsupported
                   (!attr.SupportedSystems.Any() || attr.SupportedSystems.Contains(sysName)));                // supported (no supported list -> assumed all supported)
        }
Exemplo n.º 7
0
        private static ApiContainer Register(IEmulatorServiceProvider serviceProvider, Action <string> logCallback)
        {
            var ctorParamTypes = CtorParamTypes;
            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)))
            {
                var instance = api.GetConstructor(ctorParamTypes)?.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));
        }
Exemplo n.º 8
0
        public bool IsAvailable(Type tool)
        {
            if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, tool) ||
                !lazyAsmTypes.Value.Contains(tool.AssemblyQualifiedName))                    // not a tool
            {
                return(false);
            }

            ToolAttribute attr = tool.GetCustomAttributes(false).OfType <ToolAttribute>().SingleOrDefault();

            if (attr == null)
            {
                return(true);                // no ToolAttribute on given type -> assumed all supported
            }

            var displayName = Global.Emulator.DisplayName();
            var systemId    = Global.Emulator.SystemId;

            return(!attr.UnsupportedCores.Contains(displayName) &&          // not unsupported
                   (!attr.SupportedSystems.Any() || attr.SupportedSystems.Contains(systemId)));                // supported (no supported list -> assumed all supported)
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
            static ApiContainer InitApiHawkContainerInstance(IEmulatorServiceProvider sp, Action <string> logCallback)
            {
                var ctorParamTypes = new[] { typeof(Action <string>) };
                var ctorParams     = new object[] { logCallback };
                var libDict        = new Dictionary <Type, IExternalApi>();

                foreach (var api in Assembly.GetAssembly(typeof(EmuApi)).GetTypes()
                         .Concat(Assembly.GetAssembly(typeof(ToolApi)).GetTypes())
                         .Where(t => t.IsSealed && typeof(IExternalApi).IsAssignableFrom(t) && ServiceInjector.IsAvailable(sp, t)))
                {
                    var ctorWithParams = api.GetConstructor(ctorParamTypes);
                    var instance       = (IExternalApi)(ctorWithParams == null ? Activator.CreateInstance(api) : ctorWithParams.Invoke(ctorParams));
                    ServiceInjector.UpdateServices(sp, instance);
                    libDict.Add(api, instance);
                }
                return(ApiHawkContainerInstance = new ApiContainer(libDict));
            }
Exemplo n.º 11
0
 public bool IsAvailable <T>()
 {
     return(ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, typeof(T)));
 }
Exemplo n.º 12
0
        /// <summary>
        /// Loads a tool dialog of type toolType if it does not exist it will be
        /// created, if it is already open, it will be focused.
        /// </summary>
        public IToolForm Load(Type toolType, bool focus = true)
        {
            if (!typeof(IToolForm).IsAssignableFrom(toolType))
            {
                throw new ArgumentException(String.Format("Type {0} does not implement IToolForm.", toolType.Name));
            }

            if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, toolType))
            {
                return(null);
            }

            var existingTool = _tools.FirstOrDefault(x => toolType.IsAssignableFrom(x.GetType()));

            if (existingTool != null)
            {
                if (existingTool.IsDisposed)
                {
                    _tools.Remove(existingTool);
                }
                else
                {
                    if (focus)
                    {
                        existingTool.Show();
                        existingTool.Focus();
                    }
                    return(existingTool);
                }
            }

            var newTool = CreateInstance(toolType);

            if (newTool is Form)
            {
                (newTool as Form).Owner = GlobalWin.MainForm;
            }

            ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, newTool);

            // auto settings
            if (newTool is IToolFormAutoConfig)
            {
                ToolDialogSettings settings;
                if (!Global.Config.CommonToolSettings.TryGetValue(toolType.ToString(), out settings))
                {
                    settings = new ToolDialogSettings();
                    Global.Config.CommonToolSettings[toolType.ToString()] = settings;
                }
                AttachSettingHooks(newTool as IToolFormAutoConfig, settings);
            }

            // custom settings
            if (HasCustomConfig(newTool))
            {
                Dictionary <string, object> settings;
                if (!Global.Config.CustomToolSettings.TryGetValue(toolType.ToString(), out settings))
                {
                    settings = new Dictionary <string, object>();
                    Global.Config.CustomToolSettings[toolType.ToString()] = settings;
                }
                InstallCustomConfig(newTool, settings);
            }

            newTool.Restart();
            newTool.Show();
            return(newTool);
        }
Exemplo n.º 13
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));
                }
            }
        }
Exemplo n.º 14
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
        }
Exemplo n.º 15
0
        private void SetTools()
        {
            ToolBoxStrip.Items.Clear();

            var tools = EmuHawk.ReflectionCache.Types
                        .Where(t => typeof(IToolForm).IsAssignableFrom(t))
                        .Where(t => typeof(Form).IsAssignableFrom(t))
                        .Where(t => !typeof(ToolBox).IsAssignableFrom(t))
                        .Where(t => ServiceInjector.IsAvailable(Emulator.ServiceProvider, t))
                        .Where(t => VersionInfo.DeveloperBuild || !t.GetCustomAttributes(false).OfType <ToolAttribute>().Any(a => !a.Released));

            /*
             * for (int i = 0; i < tools.Count(); i++)
             * {
             *      Console.WriteLine(tools.ElementAt(i).FullName);
             * }
             */

            foreach (var t in tools)
            {
                if (t.FullName != "BizHawk.Client.EmuHawk.ToolFormBase")
                {
                    //var instance = Activator.CreateInstance(t);

                    var image_t = Properties.Resources.Logo;
                    var text_t  = "";

                    if (t.FullName == "BizHawk.Client.EmuHawk.CoreFeatureAnalysis")
                    {
                        image_t = Properties.Resources.Logo;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.LogWindow")
                    {
                        image_t = Properties.Resources.CommandWindow;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.LuaConsole")
                    {
                        image_t = Properties.Resources.TextDocIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.MacroInputTool")
                    {
                        image_t = Properties.Resources.TAStudioIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.MultiDiskBundler")
                    {
                        image_t = Properties.Resources.DualIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.VirtualpadTool")
                    {
                        image_t = Properties.Resources.GameControllerIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.BasicBot")
                    {
                        image_t = Properties.Resources.BasicBot;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.CDL")
                    {
                        image_t = Properties.Resources.CdLoggerIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.Cheats")
                    {
                        image_t = Properties.Resources.BugIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.GenericDebugger")
                    {
                        image_t = Properties.Resources.BugIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.GameShark")
                    {
                        image_t = Properties.Resources.SharkIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.GBPrinterView")
                    {
                        image_t = Properties.Resources.GambatteIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.GbGpuView")
                    {
                        image_t = Properties.Resources.GambatteIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.HexEditor")
                    {
                        image_t = Properties.Resources.FreezeIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.TAStudio")
                    {
                        image_t = Properties.Resources.TAStudioIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.TraceLogger")
                    {
                        image_t = Properties.Resources.PencilIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.RamSearch")
                    {
                        image_t = Properties.Resources.SearchIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.RamWatch")
                    {
                        image_t = Properties.Resources.WatchIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.NESSoundConfig")
                    {
                        image_t = Properties.Resources.NesControllerIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.NESMusicRipper")
                    {
                        image_t = Properties.Resources.NesControllerIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.NesPPU")
                    {
                        image_t = Properties.Resources.MonitorIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.NESNameTableViewer")
                    {
                        image_t = Properties.Resources.MonitorIcon;
                    }
                    if (t.FullName == "BizHawk.Client.EmuHawk.SmsVdpViewer")
                    {
                        image_t = Properties.Resources.SmsIcon;
                    }

                    var tsb = new ToolStripButton
                    {
                        Image        = image_t.ToBitmap(),
                        Text         = text_t,
                        DisplayStyle = ToolStripItemDisplayStyle.Image
                                       //Image = ((Form)instance).Icon.ToBitmap(),
                                       //Text = ((Form)instance).Text,
                                       //DisplayStyle = ((Form)instance).ShowIcon ? ToolStripItemDisplayStyle.Image : ToolStripItemDisplayStyle.Text
                    };

                    tsb.Click += (o, e) =>
                    {
                        Tools.Load(t);
                        //Close();
                    };

                    ToolBoxStrip.Items.Add(tsb);
                }
            }
        }
Exemplo n.º 16
0
 public bool IsAvailable(Type t)
 {
     return(ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, t));
 }
Exemplo n.º 17
0
 private static IExternalApiProvider Register(IEmulatorServiceProvider serviceProvider)
 {
     foreach (var api in Assembly.Load("BizHawk.Client.Common").GetTypes()
              .Concat(Assembly.Load("BizHawk.Client.ApiHawk").GetTypes())
              .Concat(Assembly.GetAssembly(typeof(ApiContainer)).GetTypes())
              .Where(t => typeof(IExternalApi).IsAssignableFrom(t) && t.IsSealed && ServiceInjector.IsAvailable(serviceProvider, t)))
     {
         var instance = (IExternalApi)Activator.CreateInstance(api);
         ServiceInjector.UpdateServices(serviceProvider, instance);
         Libraries.Add(api, instance);
     }
     _container = new ApiContainer(Libraries);
     return(new BasicApiProvider(_container));
 }
Exemplo n.º 18
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
        }