public IntPtr AttachPlugin(m64p_plugin_type type, string PluginName)
        {
            if (plugins.ContainsKey(type))
            {
                DetachPlugin(type);
            }

            AttachedPlugin plugin;

            plugin.dllHandle = LoadLibrary(PluginName);
            if (plugin.dllHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException(string.Format("Failed to load plugin {0}, error code: 0x{1:X}", PluginName, GetLastError()));
            }

            plugin.dllStartup  = (PluginStartup)Marshal.GetDelegateForFunctionPointer(GetProcAddress(plugin.dllHandle, "PluginStartup"), typeof(PluginStartup));
            plugin.dllShutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(GetProcAddress(plugin.dllHandle, "PluginShutdown"), typeof(PluginShutdown));
            plugin.dllStartup(CoreDll, null, null);

            m64p_error result = m64pCoreAttachPlugin(type, plugin.dllHandle);

            if (result != m64p_error.M64ERR_SUCCESS)
            {
                FreeLibrary(plugin.dllHandle);
                throw new InvalidOperationException(string.Format("Error during attaching plugin {0}", PluginName));
            }

            plugins.Add(type, plugin);
            return(plugin.dllHandle);
        }
Example #2
0
        public IntPtr AttachPlugin(m64p_plugin_type type, string PluginName)
        {
            if (plugins.ContainsKey(type))
            {
                DetachPlugin(type);
            }

            AttachedPlugin plugin;

            plugin.dllHandle = libLoader.LoadPlatformSpecific(PluginName);

            plugin.dllStartup  = (PluginStartup)Marshal.GetDelegateForFunctionPointer(libLoader.GetProcAddr(plugin.dllHandle, "PluginStartup"), typeof(PluginStartup));
            plugin.dllShutdown = (PluginShutdown)Marshal.GetDelegateForFunctionPointer(libLoader.GetProcAddr(plugin.dllHandle, "PluginShutdown"), typeof(PluginShutdown));
            plugin.dllStartup(CoreDll, null, null);

            m64p_error result = m64pCoreAttachPlugin(type, plugin.dllHandle);

            if (result != m64p_error.M64ERR_SUCCESS)
            {
                libLoader.FreePlatformSpecific(plugin.dllHandle);
                throw new InvalidOperationException(string.Format("Error during attaching plugin {0}", PluginName));
            }

            plugins.Add(type, plugin);
            return(plugin.dllHandle);
        }
        public mupen64plusApi(N64 bizhawkCore, byte[] rom, VideoPluginSettings video_settings, int SaveType, int CoreType, bool DisableExpansionSlot)
        {
            // There can only be one core (otherwise breaks mupen64plus)
            if (AttachedCore != null)
            {
                AttachedCore.Dispose();
                AttachedCore = null;
            }
            this.bizhawkCore = bizhawkCore;

            CoreDll = LoadLibrary("mupen64plus.dll");
            if (CoreDll == IntPtr.Zero)
            {
                throw new InvalidOperationException(string.Format("Failed to load mupen64plus.dll"));
            }

            connectFunctionPointers();

            // Start up the core
            m64p_error result = m64pCoreStartup(0x20001, "", "", "Core",
                                                null, "", IntPtr.Zero);

            // Open the core settings section in the config system
            IntPtr core_section = IntPtr.Zero;

            m64pConfigOpenSection("Core", ref core_section);

            // Set the savetype if needed
            if (DisableExpansionSlot)
            {
                int disable = 1;
                m64pConfigSetParameter(core_section, "DisableExtraMem", m64p_type.M64TYPE_INT, ref disable);
            }

            // Set the savetype if needed
            if (SaveType != 0)
            {
                m64pConfigSetParameter(core_section, "SaveType", m64p_type.M64TYPE_INT, ref SaveType);
            }

            m64pConfigSetParameter(core_section, "R4300Emulator", m64p_type.M64TYPE_INT, ref CoreType);

            // Pass the rom to the core
            result = m64pCoreDoCommandByteArray(m64p_command.M64CMD_ROM_OPEN, rom.Length, rom);

            // Open the general video settings section in the config system
            IntPtr video_section = IntPtr.Zero;

            m64pConfigOpenSection("Video-General", ref video_section);

            // Set the desired width and height for mupen64plus
            result = m64pConfigSetParameter(video_section, "ScreenWidth", m64p_type.M64TYPE_INT, ref video_settings.Width);
            result = m64pConfigSetParameter(video_section, "ScreenHeight", m64p_type.M64TYPE_INT, ref video_settings.Height);

            set_video_parameters(video_settings);

            InitSaveram();

            // Initialize event invoker
            m64pFrameCallback  = new FrameCallback(FireFrameFinishedEvent);
            result             = m64pCoreDoCommandFrameCallback(m64p_command.M64CMD_SET_FRAME_CALLBACK, 0, m64pFrameCallback);
            m64pVICallback     = new VICallback(FireVIEvent);
            result             = m64pCoreDoCommandVICallback(m64p_command.M64CMD_SET_VI_CALLBACK, 0, m64pVICallback);
            m64pRenderCallback = new RenderCallback(FireRenderEvent);
            result             = m64pCoreDoCommandRenderCallback(m64p_command.M64CMD_SET_RENDER_CALLBACK, 0, m64pRenderCallback);

            // Prepare to start the emulator in a different thread
            m64pEmulator = new Thread(ExecuteEmulator);

            AttachedCore = this;
        }