Esempio n. 1
0
        public LibretroEmulator(CoreComm comm, IGameInfo game, string corePath, bool analysis = false)
        {
            try
            {
                cbHandler = bridge.LibretroBridge_CreateCallbackHandler();

                if (cbHandler == IntPtr.Zero)
                {
                    throw new Exception("Failed to create callback handler!");
                }

                UpdateCallbackHandler();

                api = BizInvoker.GetInvoker <LibretroApi>(
                    new DynamicLibraryImportResolver(corePath, hasLimitedLifetime: false), CallingConventionAdapters.Native);

                _serviceProvider = new(this);
                Comm             = comm;

                if (api.retro_api_version() != 1)
                {
                    throw new InvalidOperationException("Unsupported Libretro API version (or major error in interop)");
                }

                var SystemDirectory     = RetroString(Comm.CoreFileProvider.GetRetroSystemPath(game));
                var SaveDirectory       = RetroString(Comm.CoreFileProvider.GetRetroSaveRAMDirectory(game));
                var CoreDirectory       = RetroString(Path.GetDirectoryName(corePath));
                var CoreAssetsDirectory = RetroString(Path.GetDirectoryName(corePath));

                bridge.LibretroBridge_SetDirectories(cbHandler, SystemDirectory, SaveDirectory, CoreDirectory, CoreAssetsDirectory);

                ControllerDefinition = CreateControllerDefinition();

                // check if we're just analysing the core and the core path matches the loaded core path anyways
                if (analysis && corePath == LoadedCorePath)
                {
                    Description = CalculateDescription();
                    Description.SupportsNoGame = LoadedCoreSupportsNoGame;
                    // don't set init, we don't want the core deinit later
                }
                else
                {
                    api.retro_set_environment(cb_procs.retro_environment_proc);
                    Description = CalculateDescription();
                }

                if (!analysis)
                {
                    LoadedCorePath           = corePath;
                    LoadedCoreSupportsNoGame = Description.SupportsNoGame;
                }
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Esempio n. 2
0
        public LibretroCore(CoreComm nextComm, string corePath)
        {
            //TODO: codepath just for introspection (lighter weight; no speex, no controls, etc.)

            ServiceProvider = new BasicServiceProvider(this);
            _SyncSettings   = new SyncSettings();
            CoreComm        = nextComm;

            string dllPath = Path.Combine(CoreComm.CoreFileProvider.DllPath(), "LibretroBridge.dll");

            api = new LibretroApi(dllPath, corePath);

            if (api.comm->env.retro_api_version != 1)
            {
                throw new InvalidOperationException("Unsupported Libretro API version (or major error in interop)");
            }

            //SO: I think I need these paths set before I call retro_set_environment
            //and I need retro_set_environment set so I can find out if the core supports no-game
            //therefore, I need a complete environment (including pathing) before I can complete my introspection of the core.
            //Sucky, but that's life.
            //I dont even know for sure what paths I should use until... (what?)


            //not sure about each of these.. but we may be doing things different than retroarch.
            //I wish I could initialize these with placeholders during a separate introspection codepath..
            string SystemDirectory     = CoreComm.CoreFileProvider.GetRetroSystemPath();
            string SaveDirectory       = CoreComm.CoreFileProvider.GetRetroSaveRAMDirectory();
            string CoreDirectory       = Path.GetDirectoryName(corePath);
            string CoreAssetsDirectory = Path.GetDirectoryName(corePath);

            api.CopyAscii(LibretroApi.BufId.SystemDirectory, SystemDirectory);
            api.CopyAscii(LibretroApi.BufId.SaveDirectory, SaveDirectory);
            api.CopyAscii(LibretroApi.BufId.CoreDirectory, CoreDirectory);
            api.CopyAscii(LibretroApi.BufId.CoreAssetsDirectory, CoreAssetsDirectory);

            api.CMD_SetEnvironment();

            //TODO: IT'S A BOWL OF SPAGHETTI! I KNOW, IM GOING TO FIX IT
            api.core = this;

            Description = api.CalculateDescription();

            ControllerDefinition = CreateControllerDefinition(_SyncSettings);
        }