/// <summary> /// Loads no game. /// </summary> public void LoadGame() { ThrowIfNotInitialized(); if (gameLoaded) { throw new Exception("You need to unload the currently loaded game."); } Native.retro_game_info gameInfo = new Native.retro_game_info(); gameInfo.path = ""; if (Info.RequiresFullGamePath || !Info.SupportsNoGame) { throw new Exception("This core does not supported the specified loading mode."); } else { gameInfo.data = IntPtr.Zero; gameInfo.size = 0; } gameInfo.meta = ""; IntPtr gamePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Native.retro_game_info))); Marshal.StructureToPtr(gameInfo, gamePtr, false); retro_load_game(gamePtr); IntPtr infoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Native.retro_system_av_info))); retro_get_system_av_info(infoPtr); Native.retro_system_av_info info = (Native.retro_system_av_info)Marshal.PtrToStructure(infoPtr, typeof(Native.retro_system_av_info)); HandleAVInfo(info, false); gameLoaded = true; }
/// <summary> /// Load a game from a file. /// </summary> public void LoadGame(string filename) { ThrowIfNotInitialized(); if (gameLoaded) { throw new Exception("You need to unload the currently loaded game."); } Native.retro_game_info gameInfo = new Native.retro_game_info(); gameInfo.path = filename; if(Info.RequiresFullGamePath) { gameInfo.data = IntPtr.Zero; gameInfo.size = 0; } else { byte[] data = File.ReadAllBytes(filename); gameInfo.data = Marshal.AllocHGlobal(data.Length); Marshal.Copy(data, 0, gameInfo.data, data.Length); gameInfo.size = (uint)data.Length; } gameInfo.meta = ""; IntPtr gamePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Native.retro_game_info))); Marshal.StructureToPtr(gameInfo, gamePtr, false); retro_load_game(gamePtr); IntPtr infoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Native.retro_system_av_info))); retro_get_system_av_info(infoPtr); Native.retro_system_av_info info = (Native.retro_system_av_info)Marshal.PtrToStructure(infoPtr, typeof(Native.retro_system_av_info)); HandleAVInfo(info, false); if(gameInfo.data != IntPtr.Zero) { Marshal.FreeHGlobal(gameInfo.data); } gameLoaded = true; }