Exemplo n.º 1
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);

                    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
                    {
                        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.º 2
0
        public static object getInterfaces()
        {
            Console.WriteLine($"{RTC_Core.RemoteRTC?.expectedSide.ToString()} -> getInterfaces()");

            MemoryInterfaces.Clear();

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

            foreach (MemoryDomain _domain in MDRI.MemoryDomains)
            {
                if (!MemoryInterfaces.ContainsKey(_domain.ToString()))
                {
                    MemoryInterfaces.Add(_domain.ToString(), new MemoryDomainProxy(_domain));
                }
            }

            MainDomain = MDRI.MemoryDomains.MainMemory.ToString();
            DataSize   = (MemoryInterfaces[MainDomain] as MemoryDomainProxy).md.WordSize;
            BigEndian  = (MemoryInterfaces[MainDomain] as MemoryDomainProxy).md.EndianType == MemoryDomain.Endian.Big;

            //RefreshDomains();

            /*
             * if(VmdPool.Count > 0)
             *  foreach (string VmdKey in VmdPool.Keys)
             *      MemoryInterfaces.Add(VmdKey, VmdPool[VmdKey]);
             */

            return(new object[] { MemoryInterfaces.Values.ToArray(), MainDomain });
        }
Exemplo n.º 3
0
		public static MemoryDomainProxy[] GetInterfaces()
		{
			try
			{
				Console.WriteLine($" getInterfaces()");

				List<MemoryDomainProxy> interfaces = new List<MemoryDomainProxy>();

				if (Global.Emulator?.ServiceProvider == null || Global.Emulator is NullEmulator)
					return new MemoryDomainProxy[] { };

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

				foreach (MemoryDomain _domain in MDRI.MemoryDomains)
					if(!_domain.Name.Contains("Waterbox")) //Waterbox domains are banned
						interfaces.Add(new MemoryDomainProxy(new VanguardImplementation.BizhawkMemoryDomain(_domain)));


				return interfaces.ToArray();
			}
			catch (Exception ex)
			{
				if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
					throw new AbortEverythingException();

				return new MemoryDomainProxy[] { };
			}

		}
Exemplo n.º 4
0
 public void Restart(IEmulatorServiceProvider newServiceProvider)
 {
     foreach (var lib in Libraries)
     {
         ServiceInjector.UpdateServices(newServiceProvider, lib.Value);
     }
 }
Exemplo n.º 5
0
        public T CustomLoad <T>(bool focus = true)
            where T : class, IToolForm
        {
            IToolForm newTool = CreateInstance <T>("");

            if (newTool == null)
            {
                return(null);
            }

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

            ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, newTool);
            string toolType = typeof(T).ToString();

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

                AttachSettingHooks(newTool as IToolFormAutoConfig, settings);
            }
            return((T)newTool);
        }
Exemplo n.º 6
0
 public void Restart()
 {
     foreach (var lib in Libraries)
     {
         ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, lib.Value);
     }
 }
Exemplo n.º 7
0
        private static void Register(IEmulatorServiceProvider serviceProvider)
        {
            // Register external apis
            var apis = Assembly
                       .Load("BizHawk.Client.ApiHawk")
                       .GetTypes()
                       .Where(t => typeof(IExternalApi).IsAssignableFrom(t))
                       .Where(t => t.IsSealed)
                       .Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
                       .Concat(Assembly
                               .GetAssembly(typeof(ApiContainer))
                               .GetTypes()
                               .Where(t => typeof(IExternalApi).IsAssignableFrom(t))
                               .Where(t => t.IsSealed)
                               .Where(t => ServiceInjector.IsAvailable(serviceProvider, t)));

            foreach (var api in apis)
            {
                var instance = (IExternalApi)Activator.CreateInstance(api);
                ServiceInjector.UpdateServices(serviceProvider, instance);
                Libraries.Add(api, instance);
            }
            container             = new ApiContainer(Libraries);
            GlobalWin.ApiProvider = new BasicApiProvider(container);
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
0
        public EmuLuaLibrary(IEmulatorServiceProvider serviceProvider)
            : this()
        {
            LuaWait = new AutoResetEvent(false);
            Docs.Clear();

            // 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;

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

            var methods = luaCanvas
                          .GetMethods()
                          .Where(m => m.GetCustomAttributes(typeof(LuaMethodAttributes), false).Any());

            foreach (var method in methods)
            {
                Docs.Add(new LibraryFunction(nameof(LuaCanvas), luaCanvas.Description(), method));
            }
        }
Exemplo n.º 10
0
 public void Update(IEmulatorServiceProvider newServiceProvider)
 {
     ServiceInjector.UpdateServices(newServiceProvider, this);
     foreach (var provider in apiProviders)
     {
         ServiceInjector.UpdateServices(newServiceProvider, provider);
         provider.Update();
     }
 }
Exemplo n.º 11
0
        /// <summary>Loads the external tool's entry form.</summary>
        public IExternalToolForm LoadExternalToolForm(string toolPath, string customFormTypeName, bool focus = true)
        {
            var existingTool = _tools.OfType <IExternalToolForm>().FirstOrDefault(t => t.GetType().Assembly.Location == toolPath);

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

            var newTool = (IExternalToolForm)CreateInstance(typeof(IExternalToolForm), toolPath, customFormTypeName);

            if (newTool == null)
            {
                return(null);
            }
            if (newTool is Form form)
            {
                form.Owner = _owner;
            }
            ApiInjector.UpdateApis(_apiProvider, newTool);
            ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
            SetBaseProperties(newTool);
            // auto settings
            if (newTool is IToolFormAutoConfig autoConfigTool)
            {
                AttachSettingHooks(
                    autoConfigTool,
                    _config.CommonToolSettings.TryGetValue(customFormTypeName, out var settings)
                                                ? settings
                                                : (_config.CommonToolSettings[customFormTypeName] = new ToolDialogSettings())
                    );
            }
            // custom settings
            if (HasCustomConfig(newTool))
            {
                InstallCustomConfig(
                    newTool,
                    _config.CustomToolSettings.TryGetValue(customFormTypeName, out var settings)
                                                ? settings
                                                : (_config.CustomToolSettings[customFormTypeName] = new Dictionary <string, object>())
                    );
            }

            newTool.Restart();
            newTool.Show();
            return(newTool);
        }
Exemplo n.º 12
0
 private static IExternalApiProvider Register(IEmulatorServiceProvider serviceProvider)
 {
     foreach (var api in Assembly.GetAssembly(typeof(ApiSubsetContainer)).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.º 13
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);
     }
 }
Exemplo n.º 14
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.º 15
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.º 16
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.º 17
0
        /// <summary>
        /// Loads the tool dialog T (T must implement <see cref="IToolForm"/>) , if it does not exist it will be created, if it is already open, it will be focused
        /// </summary>
        /// <typeparam name="T">Type of tool you want to load</typeparam>
        /// <param name="toolPath">Path to the .dll of the external tool</param>
        /// <param name="focus">Define if the tool form has to get the focus or not (Default is true)</param>
        /// <returns>An instantiated <see cref="IToolForm"/></returns>
        public T Load <T>(string toolPath, bool focus = true)
            where T : class, IToolForm
        {
            bool isExternal = typeof(T) == typeof(IExternalToolForm);

            if (!IsAvailable <T>() && !isExternal)
            {
                return(null);
            }

            T existingTool;

            if (isExternal)
            {
                existingTool = (T)_tools.FirstOrDefault(t => t is T && t.GetType().Assembly.Location == toolPath);
            }
            else
            {
                existingTool = (T)_tools.FirstOrDefault(t => t is T);
            }

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

                    return(existingTool);
                }
            }

            IToolForm newTool = CreateInstance <T>(toolPath);

            if (newTool == null)
            {
                return(null);
            }

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

            if (isExternal)
            {
                ApiInjector.UpdateApis(GlobalWin.ApiProvider, newTool);
            }

            ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, newTool);
            string toolType = typeof(T).ToString();

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

                AttachSettingHooks(newTool as IToolFormAutoConfig, settings);
            }

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

                InstallCustomConfig(newTool, settings);
            }

            newTool.Restart();
            if (!OSTailoredCode.IsWindows() && newTool is RamSearch)
            {
                // the mono winforms implementation is buggy, skip to the return statement and call Show in MainForm instead
            }
            else
            {
                newTool.Show();
            }
            return((T)newTool);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Loads the tool dialog T (T must implement <see cref="IToolForm"/>) , if it does not exist it will be created, if it is already open, it will be focused
        /// </summary>
        /// <param name="focus">Define if the tool form has to get the focus or not (Default is true)</param>
        /// <param name="toolPath">Path to the .dll of the external tool</param>
        /// <typeparam name="T">Type of tool you want to load</typeparam>
        /// <returns>An instantiated <see cref="IToolForm"/></returns>
        public T Load <T>(bool focus = true, string toolPath = "")
            where T : class, IToolForm
        {
            if (!IsAvailable <T>())
            {
                return(null);
            }

            var existingTool = _tools.OfType <T>().FirstOrDefault();

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

            if (!(CreateInstance <T>(toolPath) is T newTool))
            {
                return(null);
            }

            if (newTool is Form form)
            {
                form.Owner = _owner;
            }
            ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
            SetBaseProperties(newTool);
            var toolTypeName = typeof(T).ToString();

            // auto settings
            if (newTool is IToolFormAutoConfig autoConfigTool)
            {
                AttachSettingHooks(
                    autoConfigTool,
                    _config.CommonToolSettings.TryGetValue(toolTypeName, out var settings)
                                                ? settings
                                                : (_config.CommonToolSettings[toolTypeName] = new ToolDialogSettings())
                    );
            }
            // custom settings
            if (HasCustomConfig(newTool))
            {
                InstallCustomConfig(
                    newTool,
                    _config.CustomToolSettings.TryGetValue(toolTypeName, out var settings)
                                                ? settings
                                                : (_config.CustomToolSettings[toolTypeName] = new Dictionary <string, object>())
                    );
            }

            newTool.Restart();
            newTool.Show();
            return(newTool);
        }
Exemplo n.º 19
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.º 20
0
        /// <summary>
        /// Loads the tool dialog T (T must implement <see cref="IToolForm"/>) , if it does not exist it will be created, if it is already open, it will be focused
        /// </summary>
        /// <typeparam name="T">Type of tool you want to load</typeparam>
        /// <param name="toolPath">Path to the .dll of the external tool</param>
        /// <param name="focus">Define if the tool form has to get the focus or not (Default is true)</param>
        /// <returns>An instantiated <see cref="IToolForm"/></returns>
        public T Load <T>(string toolPath, bool focus = true)
            where T : class, IToolForm
        {
            if (!IsAvailable <T>())
            {
                return(null);
            }

            var existingTool = _tools.OfType <T>().FirstOrDefault();

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

            var newTool = CreateInstance <T>(toolPath);

            if (newTool == null)
            {
                return(null);
            }

            if (newTool is Form form)
            {
                form.Owner = _owner;
            }
            ServiceInjector.UpdateServices(_emulator.ServiceProvider, newTool);
            SetBaseProperties(newTool);
            var toolTypeName = typeof(T).ToString();

            // auto settings
            if (newTool is IToolFormAutoConfig autoConfigTool)
            {
                AttachSettingHooks(
                    autoConfigTool,
                    _config.CommonToolSettings.TryGetValue(toolTypeName, out var settings)
                                                ? settings
                                                : (_config.CommonToolSettings[toolTypeName] = new ToolDialogSettings())
                    );
            }
            // custom settings
            if (HasCustomConfig(newTool))
            {
                InstallCustomConfig(
                    newTool,
                    _config.CustomToolSettings.TryGetValue(toolTypeName, out var settings)
                                                ? settings
                                                : (_config.CustomToolSettings[toolTypeName] = new Dictionary <string, object>())
                    );
            }

            newTool.Restart();
            if (OSTailoredCode.IsUnixHost && newTool is RamSearch)
            {
                // the mono winforms implementation is buggy, skip to the return statement and call Show in MainForm instead
            }
            else
            {
                newTool.Show();
            }
            return((T)newTool);
        }
Exemplo n.º 21
0
 public void Update(IEmulatorServiceProvider serviceProvider) => ServiceInjector.UpdateServices(serviceProvider, this);
Exemplo n.º 22
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.º 23
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.º 24
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
        }