From f3f15a32feef2288e58514a49f22e50c21ff22ec Mon Sep 17 00:00:00 2001 From: Vladimir Kononovich Date: Sat, 19 Dec 2020 23:30:40 +0300 Subject: [PATCH] Reformat InteropDll (Resharper) --- InteropDLL/ConfigApiWrapper.cpp | 96 ++-- InteropDLL/EmuApiWrapper.cpp | 519 ++++++++++++---------- InteropDLL/HistoryViewerWrapper.cpp | 144 +++--- InteropDLL/InputApiWrapper.cpp | 97 ++-- InteropDLL/InteropNotificationListener.h | 4 +- InteropDLL/InteropNotificationListeners.h | 9 +- InteropDLL/NetplayApiWrapper.cpp | 71 +-- InteropDLL/RecordApiWrapper.cpp | 37 +- InteropDLL/TestApiWrapper.cpp | 42 +- InteropDLL/stdafx.h | 40 +- 10 files changed, 564 insertions(+), 495 deletions(-) diff --git a/InteropDLL/ConfigApiWrapper.cpp b/InteropDLL/ConfigApiWrapper.cpp index bf7ba42..bdfdc44 100644 --- a/InteropDLL/ConfigApiWrapper.cpp +++ b/InteropDLL/ConfigApiWrapper.cpp @@ -9,60 +9,60 @@ extern unique_ptr _soundManager; static string _returnString; extern "C" { - DllExport void __stdcall SetVideoConfig(VideoConfig config) - { - _console->GetSettings()->SetVideoConfig(config); - } +DllExport void __stdcall SetVideoConfig(VideoConfig config) +{ + _console->GetSettings()->SetVideoConfig(config); +} - DllExport void __stdcall SetAudioConfig(AudioConfig config) - { - _console->GetSettings()->SetAudioConfig(config); - } +DllExport void __stdcall SetAudioConfig(AudioConfig config) +{ + _console->GetSettings()->SetAudioConfig(config); +} - DllExport void __stdcall SetInputConfig(InputConfig config) - { - _console->GetSettings()->SetInputConfig(config); - } +DllExport void __stdcall SetInputConfig(InputConfig config) +{ + _console->GetSettings()->SetInputConfig(config); +} - DllExport void __stdcall SetEmulationConfig(EmulationConfig config) - { - _console->GetSettings()->SetEmulationConfig(config); - } - - DllExport void __stdcall SetGameboyConfig(GameboyConfig config) - { - _console->GetSettings()->SetGameboyConfig(config); - } +DllExport void __stdcall SetEmulationConfig(EmulationConfig config) +{ + _console->GetSettings()->SetEmulationConfig(config); +} - DllExport void __stdcall SetPreferences(PreferencesConfig config) - { - _console->GetSettings()->SetPreferences(config); - } +DllExport void __stdcall SetGameboyConfig(GameboyConfig config) +{ + _console->GetSettings()->SetGameboyConfig(config); +} - DllExport void __stdcall SetShortcutKeys(ShortcutKeyInfo shortcuts[], uint32_t count) - { - vector shortcutList(shortcuts, shortcuts + count); - _console->GetSettings()->SetShortcutKeys(shortcutList); - } +DllExport void __stdcall SetPreferences(PreferencesConfig config) +{ + _console->GetSettings()->SetPreferences(config); +} - DllExport ControllerType __stdcall GetControllerType(int player) - { - return _console->GetSettings()->GetInputConfig().Controllers[player].Type; - } +DllExport void __stdcall SetShortcutKeys(ShortcutKeyInfo shortcuts[], uint32_t count) +{ + vector shortcutList(shortcuts, shortcuts + count); + _console->GetSettings()->SetShortcutKeys(shortcutList); +} - DllExport const char* __stdcall GetAudioDevices() - { - _returnString = _soundManager ? _soundManager->GetAvailableDevices() : ""; - return _returnString.c_str(); - } +DllExport ControllerType __stdcall GetControllerType(int player) +{ + return _console->GetSettings()->GetInputConfig().Controllers[player].Type; +} - DllExport void __stdcall SetEmulationFlag(EmulationFlags flag, bool enabled) - { - _console->GetSettings()->SetFlagState(flag, enabled); - } +DllExport const char* __stdcall GetAudioDevices() +{ + _returnString = _soundManager ? _soundManager->GetAvailableDevices() : ""; + return _returnString.c_str(); +} - DllExport void __stdcall SetDebuggerFlag(DebuggerFlags flag, bool enabled) - { - _console->GetSettings()->SetDebuggerFlag(flag, enabled); - } -} \ No newline at end of file +DllExport void __stdcall SetEmulationFlag(EmulationFlags flag, bool enabled) +{ + _console->GetSettings()->SetFlagState(flag, enabled); +} + +DllExport void __stdcall SetDebuggerFlag(DebuggerFlags flag, bool enabled) +{ + _console->GetSettings()->SetDebuggerFlag(flag, enabled); +} +} diff --git a/InteropDLL/EmuApiWrapper.cpp b/InteropDLL/EmuApiWrapper.cpp index ab742f6..8164c82 100644 --- a/InteropDLL/EmuApiWrapper.cpp +++ b/InteropDLL/EmuApiWrapper.cpp @@ -18,9 +18,9 @@ #include "InteropNotificationListeners.h" #ifdef _WIN32 - #include "../Windows/Renderer.h" - #include "../Windows/SoundManager.h" - #include "../Windows/WindowsKeyManager.h" +#include "../Windows/Renderer.h" +#include "../Windows/SoundManager.h" +#include "../Windows/WindowsKeyManager.h" #else #include "../Linux/SdlRenderer.h" #include "../Linux/SdlSoundManager.h" @@ -61,12 +61,16 @@ enum class ConsoleId shared_ptr GetConsoleById(ConsoleId consoleId) { shared_ptr console; - switch (consoleId) { - case ConsoleId::Main: console = _console; break; - case ConsoleId::HistoryViewer: console = _historyConsole; break; + switch (consoleId) + { + case ConsoleId::Main: console = _console; + break; + case ConsoleId::HistoryViewer: console = _historyConsole; + break; } - if (!console) { + if (!console) + { //Otherwise return the main CPU console = _console; } @@ -74,249 +78,284 @@ shared_ptr GetConsoleById(ConsoleId consoleId) } extern "C" { - DllExport bool __stdcall TestDll() +DllExport bool __stdcall TestDll() +{ + return true; +} + +DllExport uint32_t __stdcall GetMesenVersion() { return _console->GetSettings()->GetVersion(); } + +DllExport void __stdcall InitDll() +{ + _console.reset(new Console()); + KeyManager::SetSettings(_console->GetSettings().get()); +} + +DllExport void __stdcall InitializeEmu(const char* homeFolder, void* windowHandle, void* viewerHandle, bool noAudio, + bool noVideo, bool noInput) +{ + _console->Initialize(); + + FolderUtilities::SetHomeFolder(homeFolder); + _shortcutKeyHandler.reset(new ShortcutKeyHandler(_console)); + + if (windowHandle != nullptr && viewerHandle != nullptr) { - return true; + _windowHandle = windowHandle; + _viewerHandle = viewerHandle; + + if (!noVideo) + { +#ifdef _WIN32 + _renderer.reset(new Renderer(_console, (HWND)_viewerHandle, true)); +#else + _renderer.reset(new SdlRenderer(_console, _viewerHandle, true)); +#endif + } + + if (!noAudio) + { +#ifdef _WIN32 + _soundManager.reset(new SoundManager(_console, (HWND)_windowHandle)); +#else + _soundManager.reset(new SdlSoundManager(_console)); +#endif + } + + if (!noInput) + { +#ifdef _WIN32 + _keyManager.reset(new WindowsKeyManager(_console, (HWND)_windowHandle)); +#else + _keyManager.reset(new LinuxKeyManager(_console)); +#endif + + KeyManager::RegisterKeyManager(_keyManager.get()); + } + } +} + +DllExport void __stdcall SetMasterVolume(double volume, ConsoleId consoleId) +{ + AudioConfig config = GetConsoleById(consoleId)->GetSettings()->GetAudioConfig(); + config.MasterVolume = volume; + GetConsoleById(consoleId)->GetSettings()->SetAudioConfig(config); +} + +DllExport void __stdcall SetVideoScale(double scale, ConsoleId consoleId) +{ + VideoConfig config = GetConsoleById(consoleId)->GetSettings()->GetVideoConfig(); + config.VideoScale = scale; + GetConsoleById(consoleId)->GetSettings()->SetVideoConfig(config); +} + + +DllExport void __stdcall SetFullscreenMode(bool fullscreen, void* windowHandle, uint32_t monitorWidth, + uint32_t monitorHeight) +{ + if (_renderer) + { + _renderer->SetFullscreenMode(fullscreen, windowHandle, monitorWidth, monitorHeight); + } +} + +DllExport bool __stdcall LoadRom(char* filename, char* patchFile) +{ + GameClient::Disconnect(); + return _console->LoadRom((VirtualFile)filename, patchFile ? (VirtualFile)patchFile : VirtualFile()); +} + +DllExport void __stdcall AddKnownGameFolder(char* folder) { FolderUtilities::AddKnownGameFolder(folder); } + +DllExport void __stdcall GetRomInfo(InteropRomInfo& info) +{ + RomInfo romInfo = {}; + string sha1; + if (_console->GetCartridge()) + { + romInfo = _console->GetCartridge()->GetRomInfo(); + sha1 = _console->GetCartridge()->GetSha1Hash(); } - DllExport uint32_t __stdcall GetMesenVersion() { return _console->GetSettings()->GetVersion(); } + _romPath = romInfo.RomFile; + _patchPath = romInfo.PatchFile; - DllExport void __stdcall InitDll() + info.Header = romInfo.Header; + info.RomPath = _romPath.c_str(); + info.PatchPath = _patchPath.c_str(); + info.Coprocessor = romInfo.Coprocessor; + + memcpy(info.Sha1, sha1.c_str(), sha1.size()); +} + +DllExport void __stdcall TakeScreenshot() { _console->GetVideoDecoder()->TakeScreenshot(); } + +DllExport const char* __stdcall GetArchiveRomList(char* filename) +{ + std::ostringstream out; + shared_ptr reader = ArchiveReader::GetReader(filename); + if (reader) { + for (string romName : reader->GetFileList(VirtualFile::RomExtensions)) + { + out << romName << "[!|!]"; + } + } + _returnString = out.str(); + return _returnString.c_str(); +} + +DllExport bool __stdcall IsRunning() +{ + return _console->IsRunning(); +} + +DllExport void __stdcall Stop() +{ + GameClient::Disconnect(); + _console->Stop(true); +} + +DllExport void __stdcall Pause(ConsoleId consoleId) +{ + if (!GameClient::Connected()) + { + GetConsoleById(consoleId)->Pause(); + } +} + +DllExport void __stdcall Resume(ConsoleId consoleId) +{ + if (!GameClient::Connected()) + { + GetConsoleById(consoleId)->Resume(); + } +} + +DllExport bool __stdcall IsPaused(ConsoleId consoleId) +{ + shared_ptr console = GetConsoleById(consoleId); + if (console) + { + return console->IsPaused(); + } + return true; +} + +DllExport void __stdcall Reset() +{ + if (!GameClient::Connected()) + { + _console->GetControlManager()->GetSystemActionManager()->Reset(); + } +} + +DllExport void __stdcall PowerCycle() +{ + if (!GameClient::Connected()) + { + _console->GetControlManager()->GetSystemActionManager()->PowerCycle(); + } +} + +DllExport void __stdcall ReloadRom() +{ + if (!GameClient::Connected()) + { + _console->ReloadRom(false); + } +} + +DllExport void __stdcall Release() +{ + GameClient::Disconnect(); + GameServer::StopServer(); + + _shortcutKeyHandler.reset(); + + _console->Stop(true); + + _console->Release(); + _console.reset(); + + _renderer.reset(); + _soundManager.reset(); + _keyManager.reset(); +} + +DllExport INotificationListener* __stdcall RegisterNotificationCallback(NotificationListenerCallback callback) +{ + return _listeners.RegisterNotificationCallback(callback, _console); +} + +DllExport void __stdcall UnregisterNotificationCallback(INotificationListener* listener) +{ + _listeners.UnregisterNotificationCallback(listener); +} + +DllExport void __stdcall DisplayMessage(char* title, char* message, char* param1) +{ + MessageManager::DisplayMessage(title, message, param1 ? param1 : ""); +} + +DllExport const char* __stdcall GetLog() +{ + _logString = MessageManager::GetLog(); + return _logString.c_str(); +} + +DllExport ScreenSize __stdcall GetScreenSize(bool ignoreScale, ConsoleId console) +{ + return GetConsoleById(console)->GetVideoDecoder()->GetScreenSize(ignoreScale); +} + +DllExport void __stdcall ClearCheats() { _console->GetCheatManager()->ClearCheats(); } +DllExport void __stdcall SetCheats(uint32_t codes[], uint32_t length) +{ + _console->GetCheatManager()->SetCheats(codes, length); +} + +DllExport void __stdcall WriteLogEntry(char* message) { MessageManager::Log(message); } + +DllExport void __stdcall SaveState(uint32_t stateIndex) { _console->GetSaveStateManager()->SaveState(stateIndex); } +DllExport void __stdcall LoadState(uint32_t stateIndex) { _console->GetSaveStateManager()->LoadState(stateIndex); } +DllExport void __stdcall SaveStateFile(char* filepath) { _console->GetSaveStateManager()->SaveState(filepath); } +DllExport void __stdcall LoadStateFile(char* filepath) { _console->GetSaveStateManager()->LoadState(filepath); } +DllExport void __stdcall LoadRecentGame(char* filepath, bool resetGame) +{ + _console->GetSaveStateManager()->LoadRecentGame(filepath, resetGame); +} + +DllExport int32_t __stdcall GetSaveStatePreview(char* saveStatePath, uint8_t* pngData) +{ + return _console->GetSaveStateManager()->GetSaveStatePreview(saveStatePath, pngData); +} + +DllExport void __stdcall PgoRunTest(vector testRoms, bool enableDebugger) +{ + FolderUtilities::SetHomeFolder("../PGOMesenHome"); + + for (size_t i = 0; i < testRoms.size(); i++) + { + std::cout << "Running: " << testRoms[i] << std::endl; + _console.reset(new Console()); KeyManager::SetSettings(_console->GetSettings().get()); - } - - DllExport void __stdcall InitializeEmu(const char* homeFolder, void *windowHandle, void *viewerHandle, bool noAudio, bool noVideo, bool noInput) - { _console->Initialize(); + GameboyConfig cfg = _console->GetSettings()->GetGameboyConfig(); + cfg.Model = GameboyModel::GameboyColor; + _console->GetSettings()->SetGameboyConfig(cfg); + _console->LoadRom((VirtualFile)testRoms[i], VirtualFile()); - FolderUtilities::SetHomeFolder(homeFolder); - _shortcutKeyHandler.reset(new ShortcutKeyHandler(_console)); - - if(windowHandle != nullptr && viewerHandle != nullptr) { - _windowHandle = windowHandle; - _viewerHandle = viewerHandle; - - if(!noVideo) { - #ifdef _WIN32 - _renderer.reset(new Renderer(_console, (HWND)_viewerHandle, true)); - #else - _renderer.reset(new SdlRenderer(_console, _viewerHandle, true)); - #endif - } - - if(!noAudio) { - #ifdef _WIN32 - _soundManager.reset(new SoundManager(_console, (HWND)_windowHandle)); - #else - _soundManager.reset(new SdlSoundManager(_console)); - #endif - } - - if(!noInput) { - #ifdef _WIN32 - _keyManager.reset(new WindowsKeyManager(_console, (HWND)_windowHandle)); - #else - _keyManager.reset(new LinuxKeyManager(_console)); - #endif - - KeyManager::RegisterKeyManager(_keyManager.get()); - } - } - } - - DllExport void __stdcall SetMasterVolume(double volume, ConsoleId consoleId) { - AudioConfig config = GetConsoleById(consoleId)->GetSettings()->GetAudioConfig(); - config.MasterVolume = volume; - GetConsoleById(consoleId)->GetSettings()->SetAudioConfig(config); - } - - DllExport void __stdcall SetVideoScale(double scale, ConsoleId consoleId) { - VideoConfig config = GetConsoleById(consoleId)->GetSettings()->GetVideoConfig(); - config.VideoScale = scale; - GetConsoleById(consoleId)->GetSettings()->SetVideoConfig(config); - } - - - DllExport void __stdcall SetFullscreenMode(bool fullscreen, void *windowHandle, uint32_t monitorWidth, uint32_t monitorHeight) - { - if(_renderer) { - _renderer->SetFullscreenMode(fullscreen, windowHandle, monitorWidth, monitorHeight); - } - } - - DllExport bool __stdcall LoadRom(char* filename, char* patchFile) - { - GameClient::Disconnect(); - return _console->LoadRom((VirtualFile)filename, patchFile ? (VirtualFile)patchFile : VirtualFile()); - } - - DllExport void __stdcall AddKnownGameFolder(char* folder) { FolderUtilities::AddKnownGameFolder(folder); } - - DllExport void __stdcall GetRomInfo(InteropRomInfo &info) - { - RomInfo romInfo = {}; - string sha1; - if(_console->GetCartridge()) { - romInfo = _console->GetCartridge()->GetRomInfo(); - sha1 = _console->GetCartridge()->GetSha1Hash(); + if (enableDebugger) + { + //turn on debugger to profile the debugger's code too + _console->GetDebugger(); } - _romPath = romInfo.RomFile; - _patchPath = romInfo.PatchFile; - - info.Header = romInfo.Header; - info.RomPath = _romPath.c_str(); - info.PatchPath = _patchPath.c_str(); - info.Coprocessor = romInfo.Coprocessor; - - memcpy(info.Sha1, sha1.c_str(), sha1.size()); - } - - DllExport void __stdcall TakeScreenshot() { _console->GetVideoDecoder()->TakeScreenshot(); } - - DllExport const char* __stdcall GetArchiveRomList(char* filename) { - std::ostringstream out; - shared_ptr reader = ArchiveReader::GetReader(filename); - if(reader) { - for(string romName : reader->GetFileList(VirtualFile::RomExtensions)) { - out << romName << "[!|!]"; - } - } - _returnString = out.str(); - return _returnString.c_str(); - } - - DllExport bool __stdcall IsRunning() - { - return _console->IsRunning(); - } - - DllExport void __stdcall Stop() - { - GameClient::Disconnect(); - _console->Stop(true); - } - - DllExport void __stdcall Pause(ConsoleId consoleId) - { - if(!GameClient::Connected()) { - GetConsoleById(consoleId)->Pause(); - } - } - - DllExport void __stdcall Resume(ConsoleId consoleId) - { - if(!GameClient::Connected()) { - GetConsoleById(consoleId)->Resume(); - } - } - - DllExport bool __stdcall IsPaused(ConsoleId consoleId) - { - shared_ptr console = GetConsoleById(consoleId); - if(console) { - return console->IsPaused(); - } - return true; - } - - DllExport void __stdcall Reset() - { - if(!GameClient::Connected()) { - _console->GetControlManager()->GetSystemActionManager()->Reset(); - } - } - - DllExport void __stdcall PowerCycle() - { - if(!GameClient::Connected()) { - _console->GetControlManager()->GetSystemActionManager()->PowerCycle(); - } - } - - DllExport void __stdcall ReloadRom() - { - if(!GameClient::Connected()) { - _console->ReloadRom(false); - } - } - - DllExport void __stdcall Release() - { - GameClient::Disconnect(); - GameServer::StopServer(); - - _shortcutKeyHandler.reset(); - - _console->Stop(true); - + std::this_thread::sleep_for(std::chrono::duration(5000)); + _console->Stop(false); _console->Release(); - _console.reset(); - - _renderer.reset(); - _soundManager.reset(); - _keyManager.reset(); } - - DllExport INotificationListener* __stdcall RegisterNotificationCallback(NotificationListenerCallback callback) - { - return _listeners.RegisterNotificationCallback(callback, _console); - } - - DllExport void __stdcall UnregisterNotificationCallback(INotificationListener *listener) - { - _listeners.UnregisterNotificationCallback(listener); - } - - DllExport void __stdcall DisplayMessage(char* title, char* message, char* param1) { MessageManager::DisplayMessage(title, message, param1 ? param1 : ""); } - DllExport const char* __stdcall GetLog() - { - _logString = MessageManager::GetLog(); - return _logString.c_str(); - } - - DllExport ScreenSize __stdcall GetScreenSize(bool ignoreScale, ConsoleId console) - { - return GetConsoleById(console)->GetVideoDecoder()->GetScreenSize(ignoreScale); - } - - DllExport void __stdcall ClearCheats() { _console->GetCheatManager()->ClearCheats(); } - DllExport void __stdcall SetCheats(uint32_t codes[], uint32_t length) { _console->GetCheatManager()->SetCheats(codes, length); } - - DllExport void __stdcall WriteLogEntry(char* message) { MessageManager::Log(message); } - - DllExport void __stdcall SaveState(uint32_t stateIndex) { _console->GetSaveStateManager()->SaveState(stateIndex); } - DllExport void __stdcall LoadState(uint32_t stateIndex) { _console->GetSaveStateManager()->LoadState(stateIndex); } - DllExport void __stdcall SaveStateFile(char* filepath) { _console->GetSaveStateManager()->SaveState(filepath); } - DllExport void __stdcall LoadStateFile(char* filepath) { _console->GetSaveStateManager()->LoadState(filepath); } - DllExport void __stdcall LoadRecentGame(char* filepath, bool resetGame) { _console->GetSaveStateManager()->LoadRecentGame(filepath, resetGame); } - DllExport int32_t __stdcall GetSaveStatePreview(char* saveStatePath, uint8_t* pngData) { return _console->GetSaveStateManager()->GetSaveStatePreview(saveStatePath, pngData); } - - DllExport void __stdcall PgoRunTest(vector testRoms, bool enableDebugger) - { - FolderUtilities::SetHomeFolder("../PGOMesenHome"); - - for(size_t i = 0; i < testRoms.size(); i++) { - std::cout << "Running: " << testRoms[i] << std::endl; - - _console.reset(new Console()); - KeyManager::SetSettings(_console->GetSettings().get()); - _console->Initialize(); - GameboyConfig cfg = _console->GetSettings()->GetGameboyConfig(); - cfg.Model = GameboyModel::GameboyColor; - _console->GetSettings()->SetGameboyConfig(cfg); - _console->LoadRom((VirtualFile)testRoms[i], VirtualFile()); - - if(enableDebugger) { - //turn on debugger to profile the debugger's code too - _console->GetDebugger(); - } - - std::this_thread::sleep_for(std::chrono::duration(5000)); - _console->Stop(false); - _console->Release(); - } - } -} \ No newline at end of file +} +} diff --git a/InteropDLL/HistoryViewerWrapper.cpp b/InteropDLL/HistoryViewerWrapper.cpp index 28149a4..80d9eae 100644 --- a/InteropDLL/HistoryViewerWrapper.cpp +++ b/InteropDLL/HistoryViewerWrapper.cpp @@ -22,102 +22,108 @@ unique_ptr _historyRenderer; unique_ptr _historySoundManager; enum class VideoCodec; -extern "C" +extern "C" { +DllExport bool __stdcall HistoryViewerEnabled() { - DllExport bool __stdcall HistoryViewerEnabled() - { - shared_ptr rewindManager = _console->GetRewindManager(); - return rewindManager ? rewindManager->HasHistory() : false; - } + shared_ptr rewindManager = _console->GetRewindManager(); + return rewindManager ? rewindManager->HasHistory() : false; +} - DllExport void __stdcall HistoryViewerInitialize(void* windowHandle, void* viewerHandle) - { - _historyConsole.reset(new Console()); - // TODO: something about initializing with settings? - _historyConsole->Initialize(); +DllExport void __stdcall HistoryViewerInitialize(void* windowHandle, void* viewerHandle) +{ + _historyConsole.reset(new Console()); + // TODO: something about initializing with settings? + _historyConsole->Initialize(); - _historyConsole->Lock(); - _historyConsole->LoadRom(_console->GetRomInfo().RomFile, _console->GetRomInfo().PatchFile); - _historyConsole->CopyRewindData(_console); - _historyConsole->Unlock(); + _historyConsole->Lock(); + _historyConsole->LoadRom(_console->GetRomInfo().RomFile, _console->GetRomInfo().PatchFile); + _historyConsole->CopyRewindData(_console); + _historyConsole->Unlock(); + + //Force some settings + VideoConfig config = _historyConsole->GetSettings()->GetVideoConfig(); + config.VideoScale = 2; + _historyConsole->GetSettings()->SetVideoConfig(config); + // TODO + // _historyConsole->GetSettings()->SetEmulationSpeed(100); + // _historyConsole->GetSettings()->ClearFlags(EmulationFlags::InBackground | EmulationFlags::Rewind /*|EmulationFlags::ForceMaxSpeed | EmulationFlags::DebuggerWindowEnabled*/); - //Force some settings - VideoConfig config = _historyConsole->GetSettings()->GetVideoConfig(); - config.VideoScale = 2; - _historyConsole->GetSettings()->SetVideoConfig(config); -// TODO -// _historyConsole->GetSettings()->SetEmulationSpeed(100); -// _historyConsole->GetSettings()->ClearFlags(EmulationFlags::InBackground | EmulationFlags::Rewind /*|EmulationFlags::ForceMaxSpeed | EmulationFlags::DebuggerWindowEnabled*/); - #ifdef _WIN32 - _historyRenderer.reset(new Renderer(_historyConsole, (HWND)viewerHandle, false)); - _historySoundManager.reset(new SoundManager(_historyConsole, (HWND)windowHandle)); -#else + _historyRenderer.reset(new Renderer(_historyConsole, (HWND)viewerHandle, false)); + _historySoundManager.reset(new SoundManager(_historyConsole, (HWND)windowHandle)); +#else _historyRenderer.reset(new SdlRenderer(_historyConsole, viewerHandle, false)); _historySoundManager.reset(new SdlSoundManager(_historyConsole)); #endif - } +} - DllExport void __stdcall HistoryViewerRelease() +DllExport void __stdcall HistoryViewerRelease() +{ + _historyConsole->Stop(true); + _historyConsole->Release(); // Mesen had True, "For ShutDown" + _historyRenderer.reset(); + _historySoundManager.reset(); + _historyConsole.reset(); +} + +DllExport uint32_t __stdcall HistoryViewerGetHistoryLength() +{ + if (_historyConsole) { - _historyConsole->Stop(true); - _historyConsole->Release(); // Mesen had True, "For ShutDown" - _historyRenderer.reset(); - _historySoundManager.reset(); - _historyConsole.reset(); + return _historyConsole->GetHistoryViewer()->GetHistoryLength(); } + return 0; +} - DllExport uint32_t __stdcall HistoryViewerGetHistoryLength() +DllExport void __stdcall HistoryViewerGetSegments(uint32_t* segmentBuffer, uint32_t& bufferSize) +{ + if (_historyConsole) { - if (_historyConsole) { - return _historyConsole->GetHistoryViewer()->GetHistoryLength(); - } - return 0; + _historyConsole->GetHistoryViewer()->GetHistorySegments(segmentBuffer, bufferSize); } +} - DllExport void __stdcall HistoryViewerGetSegments(uint32_t* segmentBuffer, uint32_t& bufferSize) +DllExport bool __stdcall HistoryViewerCreateSaveState(const char* outputFile, uint32_t position) +{ + if (_historyConsole) { - if (_historyConsole) { - _historyConsole->GetHistoryViewer()->GetHistorySegments(segmentBuffer, bufferSize); - } + return _historyConsole->GetHistoryViewer()->CreateSaveState(outputFile, position); } + return false; +} - DllExport bool __stdcall HistoryViewerCreateSaveState(const char* outputFile, uint32_t position) +DllExport bool __stdcall HistoryViewerSaveMovie(const char* movieFile, uint32_t startPosition, uint32_t endPosition) +{ + if (_historyConsole) { - if (_historyConsole) { - return _historyConsole->GetHistoryViewer()->CreateSaveState(outputFile, position); - } - return false; + return _historyConsole->GetHistoryViewer()->SaveMovie(movieFile, startPosition, endPosition); } + return false; +} - DllExport bool __stdcall HistoryViewerSaveMovie(const char* movieFile, uint32_t startPosition, uint32_t endPosition) +DllExport void __stdcall HistoryViewerResumeGameplay(uint32_t resumeAtSecond) +{ + if (_historyConsole) { - if (_historyConsole) { - return _historyConsole->GetHistoryViewer()->SaveMovie(movieFile, startPosition, endPosition); - } - return false; + _historyConsole->GetHistoryViewer()->ResumeGameplay(_console, resumeAtSecond); } +} - DllExport void __stdcall HistoryViewerResumeGameplay(uint32_t resumeAtSecond) +DllExport void __stdcall HistoryViewerSetPosition(uint32_t seekPosition) +{ + if (_historyConsole) { - if (_historyConsole) { - _historyConsole->GetHistoryViewer()->ResumeGameplay(_console, resumeAtSecond); - } + _historyConsole->GetHistoryViewer()->SeekTo(seekPosition); } +} - DllExport void __stdcall HistoryViewerSetPosition(uint32_t seekPosition) +DllExport uint32_t __stdcall HistoryViewerGetPosition() +{ + if (_historyConsole) { - if (_historyConsole) { - _historyConsole->GetHistoryViewer()->SeekTo(seekPosition); - } + return _historyConsole->GetHistoryViewer()->GetPosition(); } + return 0; +} - DllExport uint32_t __stdcall HistoryViewerGetPosition() - { - if (_historyConsole) { - return _historyConsole->GetHistoryViewer()->GetPosition(); - } - return 0; - } - -} \ No newline at end of file +} diff --git a/InteropDLL/InputApiWrapper.cpp b/InteropDLL/InputApiWrapper.cpp index 8b56a84..108d0b6 100644 --- a/InteropDLL/InputApiWrapper.cpp +++ b/InteropDLL/InputApiWrapper.cpp @@ -9,67 +9,74 @@ extern shared_ptr _console; static string _returnString; -extern "C" +extern "C" { +DllExport void __stdcall SetMousePosition(double x, double y) { - DllExport void __stdcall SetMousePosition(double x, double y) - { - KeyManager::SetMousePosition(_console, x, y); - } + KeyManager::SetMousePosition(_console, x, y); +} - DllExport void __stdcall SetMouseMovement(int16_t x, int16_t y) - { - KeyManager::SetMouseMovement(x, y); - } +DllExport void __stdcall SetMouseMovement(int16_t x, int16_t y) +{ + KeyManager::SetMouseMovement(x, y); +} - DllExport void __stdcall UpdateInputDevices() - { - if(_keyManager) { - _keyManager->UpdateDevices(); - } +DllExport void __stdcall UpdateInputDevices() +{ + if (_keyManager) + { + _keyManager->UpdateDevices(); } +} - DllExport void __stdcall GetPressedKeys(uint32_t *keyBuffer) +DllExport void __stdcall GetPressedKeys(uint32_t* keyBuffer) +{ + vector pressedKeys = KeyManager::GetPressedKeys(); + for (size_t i = 0; i < pressedKeys.size() && i < 3; i++) { - vector pressedKeys = KeyManager::GetPressedKeys(); - for(size_t i = 0; i < pressedKeys.size() && i < 3; i++) { - keyBuffer[i] = pressedKeys[i]; - } + keyBuffer[i] = pressedKeys[i]; } +} - DllExport void __stdcall DisableAllKeys(bool disabled) +DllExport void __stdcall DisableAllKeys(bool disabled) +{ + if (_keyManager) { - if(_keyManager) { - _keyManager->SetDisabled(disabled); - } + _keyManager->SetDisabled(disabled); } +} - DllExport void __stdcall SetKeyState(int32_t scanCode, bool state) +DllExport void __stdcall SetKeyState(int32_t scanCode, bool state) +{ + if (_keyManager) { - if(_keyManager) { - _keyManager->SetKeyState(scanCode, state); - _shortcutKeyHandler->ProcessKeys(); - } - } - - DllExport void __stdcall ResetKeyState() - { - if(_keyManager) { - _keyManager->ResetKeyState(); - } + _keyManager->SetKeyState(scanCode, state); + _shortcutKeyHandler->ProcessKeys(); } +} - DllExport const char* __stdcall GetKeyName(uint32_t keyCode) +DllExport void __stdcall ResetKeyState() +{ + if (_keyManager) { - _returnString = KeyManager::GetKeyName(keyCode); - return _returnString.c_str(); + _keyManager->ResetKeyState(); } +} - DllExport uint32_t __stdcall GetKeyCode(char* keyName) +DllExport const char* __stdcall GetKeyName(uint32_t keyCode) +{ + _returnString = KeyManager::GetKeyName(keyCode); + return _returnString.c_str(); +} + +DllExport uint32_t __stdcall GetKeyCode(char* keyName) +{ + if (keyName) { - if(keyName) { - return KeyManager::GetKeyCode(keyName); - } else { - return 0; - } + return KeyManager::GetKeyCode(keyName); } -} \ No newline at end of file + else + { + return 0; + } +} +} diff --git a/InteropDLL/InteropNotificationListener.h b/InteropDLL/InteropNotificationListener.h index e6d5791..bb18ff8 100644 --- a/InteropDLL/InteropNotificationListener.h +++ b/InteropDLL/InteropNotificationListener.h @@ -3,7 +3,7 @@ #include "../Core/INotificationListener.h" #include "../Core/NotificationManager.h" -typedef void(__stdcall *NotificationListenerCallback)(int, void*); +typedef void (__stdcall *NotificationListenerCallback)(int, void*); class InteropNotificationListener : public INotificationListener { @@ -23,4 +23,4 @@ public: { _callback((int)type, parameter); } -}; \ No newline at end of file +}; diff --git a/InteropDLL/InteropNotificationListeners.h b/InteropDLL/InteropNotificationListeners.h index 30520f9..faf0148 100644 --- a/InteropDLL/InteropNotificationListeners.h +++ b/InteropDLL/InteropNotificationListeners.h @@ -6,7 +6,7 @@ #include "../Utilities/SimpleLock.h" #include "InteropNotificationListener.h" -typedef void(__stdcall *NotificationListenerCallback)(int, void*); +typedef void (__stdcall *NotificationListenerCallback)(int, void*); class InteropNotificationListeners { @@ -14,7 +14,8 @@ class InteropNotificationListeners vector> _externalNotificationListeners; public: - INotificationListener* RegisterNotificationCallback(NotificationListenerCallback callback, shared_ptr console) + INotificationListener* RegisterNotificationCallback(NotificationListenerCallback callback, + shared_ptr console) { auto lock = _externalNotificationListenerLock.AcquireSafe(); auto listener = shared_ptr(new InteropNotificationListener(callback)); @@ -23,7 +24,7 @@ public: return listener.get(); } - void UnregisterNotificationCallback(INotificationListener *listener) + void UnregisterNotificationCallback(INotificationListener* listener) { auto lock = _externalNotificationListenerLock.AcquireSafe(); _externalNotificationListeners.erase( @@ -35,4 +36,4 @@ public: _externalNotificationListeners.end() ); } -}; \ No newline at end of file +}; diff --git a/InteropDLL/NetplayApiWrapper.cpp b/InteropDLL/NetplayApiWrapper.cpp index 5e467ec..31bfc0d 100644 --- a/InteropDLL/NetplayApiWrapper.cpp +++ b/InteropDLL/NetplayApiWrapper.cpp @@ -8,43 +8,56 @@ extern shared_ptr _console; extern "C" { - DllExport void __stdcall StartServer(uint16_t port, char* password, char* hostPlayerName) { GameServer::StartServer(_console, port, password, hostPlayerName); } - DllExport void __stdcall StopServer() { GameServer::StopServer(); } - DllExport bool __stdcall IsServerRunning() { return GameServer::Started(); } +DllExport void __stdcall StartServer(uint16_t port, char* password, char* hostPlayerName) +{ + GameServer::StartServer(_console, port, password, hostPlayerName); +} - DllExport void __stdcall Connect(char* host, uint16_t port, char* password, char* playerName, bool spectator) +DllExport void __stdcall StopServer() { GameServer::StopServer(); } +DllExport bool __stdcall IsServerRunning() { return GameServer::Started(); } + +DllExport void __stdcall Connect(char* host, uint16_t port, char* password, char* playerName, bool spectator) +{ + ClientConnectionData connectionData(host, port, password, playerName, spectator); + GameClient::Connect(_console, connectionData); +} + +DllExport void __stdcall Disconnect() { GameClient::Disconnect(); } +DllExport bool __stdcall IsConnected() { return GameClient::Connected(); } + +DllExport int32_t __stdcall NetPlayGetAvailableControllers() +{ + if (GameServer::Started()) { - ClientConnectionData connectionData(host, port, password, playerName, spectator); - GameClient::Connect(_console, connectionData); + return GameServer::GetAvailableControllers(); } - - DllExport void __stdcall Disconnect() { GameClient::Disconnect(); } - DllExport bool __stdcall IsConnected() { return GameClient::Connected(); } - - DllExport int32_t __stdcall NetPlayGetAvailableControllers() + else { - if(GameServer::Started()) { - return GameServer::GetAvailableControllers(); - } else { - return GameClient::GetAvailableControllers(); - } + return GameClient::GetAvailableControllers(); } +} - DllExport void __stdcall NetPlaySelectController(int32_t port) +DllExport void __stdcall NetPlaySelectController(int32_t port) +{ + if (GameServer::Started()) { - if(GameServer::Started()) { - return GameServer::SetHostControllerPort(port); - } else { - return GameClient::SelectController(port); - } + return GameServer::SetHostControllerPort(port); } + else + { + return GameClient::SelectController(port); + } +} - DllExport int32_t __stdcall NetPlayGetControllerPort() +DllExport int32_t __stdcall NetPlayGetControllerPort() +{ + if (GameServer::Started()) { - if(GameServer::Started()) { - return GameServer::GetHostControllerPort(); - } else { - return GameClient::GetControllerPort(); - } + return GameServer::GetHostControllerPort(); } -} \ No newline at end of file + else + { + return GameClient::GetControllerPort(); + } +} +} diff --git a/InteropDLL/RecordApiWrapper.cpp b/InteropDLL/RecordApiWrapper.cpp index 45a80dc..02437fc 100644 --- a/InteropDLL/RecordApiWrapper.cpp +++ b/InteropDLL/RecordApiWrapper.cpp @@ -7,23 +7,26 @@ extern shared_ptr _console; enum class VideoCodec; -extern "C" +extern "C" { +DllExport void __stdcall AviRecord(char* filename, VideoCodec codec, uint32_t compressionLevel) { - DllExport void __stdcall AviRecord(char* filename, VideoCodec codec, uint32_t compressionLevel) { _console->GetVideoRenderer()->StartRecording(filename, codec, compressionLevel); } - DllExport void __stdcall AviStop() { _console->GetVideoRenderer()->StopRecording(); } - DllExport bool __stdcall AviIsRecording() { return _console->GetVideoRenderer()->IsRecording(); } + _console->GetVideoRenderer()->StartRecording(filename, codec, compressionLevel); +} - DllExport void __stdcall WaveRecord(char* filename) { _console->GetSoundMixer()->StartRecording(filename); } - DllExport void __stdcall WaveStop() { _console->GetSoundMixer()->StopRecording(); } - DllExport bool __stdcall WaveIsRecording() { return _console->GetSoundMixer()->IsRecording(); } +DllExport void __stdcall AviStop() { _console->GetVideoRenderer()->StopRecording(); } +DllExport bool __stdcall AviIsRecording() { return _console->GetVideoRenderer()->IsRecording(); } - DllExport void __stdcall MoviePlay(char* filename) { _console->GetMovieManager()->Play(string(filename)); } - DllExport void __stdcall MovieStop() { _console->GetMovieManager()->Stop(); } - DllExport bool __stdcall MoviePlaying() { return _console->GetMovieManager()->Playing(); } - DllExport bool __stdcall MovieRecording() { return _console->GetMovieManager()->Recording(); } - DllExport void __stdcall MovieRecord(RecordMovieOptions *options) - { - RecordMovieOptions opt = *options; - _console->GetMovieManager()->Record(opt); - } -} \ No newline at end of file +DllExport void __stdcall WaveRecord(char* filename) { _console->GetSoundMixer()->StartRecording(filename); } +DllExport void __stdcall WaveStop() { _console->GetSoundMixer()->StopRecording(); } +DllExport bool __stdcall WaveIsRecording() { return _console->GetSoundMixer()->IsRecording(); } + +DllExport void __stdcall MoviePlay(char* filename) { _console->GetMovieManager()->Play(string(filename)); } +DllExport void __stdcall MovieStop() { _console->GetMovieManager()->Stop(); } +DllExport bool __stdcall MoviePlaying() { return _console->GetMovieManager()->Playing(); } +DllExport bool __stdcall MovieRecording() { return _console->GetMovieManager()->Recording(); } +DllExport void __stdcall MovieRecord(RecordMovieOptions* options) +{ + RecordMovieOptions opt = *options; + _console->GetMovieManager()->Record(opt); +} +} diff --git a/InteropDLL/TestApiWrapper.cpp b/InteropDLL/TestApiWrapper.cpp index f2a1b24..52e3949 100644 --- a/InteropDLL/TestApiWrapper.cpp +++ b/InteropDLL/TestApiWrapper.cpp @@ -5,27 +5,27 @@ extern shared_ptr _console; shared_ptr _recordedRomTest; -extern "C" +extern "C" { +DllExport int32_t __stdcall RunRecordedTest(char* filename, bool inBackground) { - DllExport int32_t __stdcall RunRecordedTest(char* filename, bool inBackground) - { - shared_ptr romTest(new RecordedRomTest(inBackground ? nullptr : _console)); - return romTest->Run(filename); - } + shared_ptr romTest(new RecordedRomTest(inBackground ? nullptr : _console)); + return romTest->Run(filename); +} - DllExport void __stdcall RomTestRecord(char* filename, bool reset) - { - _recordedRomTest.reset(new RecordedRomTest(_console)); - _recordedRomTest->Record(filename, reset); - } - - DllExport void __stdcall RomTestStop() - { - if(_recordedRomTest) { - _recordedRomTest->Stop(); - _recordedRomTest.reset(); - } - } +DllExport void __stdcall RomTestRecord(char* filename, bool reset) +{ + _recordedRomTest.reset(new RecordedRomTest(_console)); + _recordedRomTest->Record(filename, reset); +} - DllExport bool __stdcall RomTestRecording() { return _recordedRomTest != nullptr; } -} \ No newline at end of file +DllExport void __stdcall RomTestStop() +{ + if (_recordedRomTest) + { + _recordedRomTest->Stop(); + _recordedRomTest.reset(); + } +} + +DllExport bool __stdcall RomTestRecording() { return _recordedRomTest != nullptr; } +} diff --git a/InteropDLL/stdafx.h b/InteropDLL/stdafx.h index bb738b3..20ba241 100644 --- a/InteropDLL/stdafx.h +++ b/InteropDLL/stdafx.h @@ -6,43 +6,43 @@ #pragma once #if _WIN32 || _WIN64 - #if _WIN64 - #define ENVIRONMENT64 - #else +#if _WIN64 +#define ENVIRONMENT64 +#else #define ENVIRONMENT32 - #endif +#endif #endif #if __GNUC__ - #if __x86_64__ || __ppc64__ +#if __x86_64__ || __ppc64__ #define ENVIRONMENT64 - #else +#else #define ENVIRONMENT32 - #endif +#endif #endif #ifdef _DEBUG - #define MESEN_LIBRARY_DEBUG_SUFFIX "Debug" -#else +#define MESEN_LIBRARY_DEBUG_SUFFIX "Debug" +#else #define MESEN_LIBRARY_DEBUG_SUFFIX "Release" #endif #ifdef ENVIRONMENT32 #define MESEN_LIBRARY_SUFFIX "x86.lib" -#else - #define MESEN_LIBRARY_SUFFIX "x64.lib" +#else +#define MESEN_LIBRARY_SUFFIX "x64.lib" #endif #if _WIN32 || _WIN64 - //#pragma comment(lib, "Core.lib") - //#pragma comment(lib, "Utilities.lib") - //#pragma comment(lib, "Windows.lib") - //#pragma comment(lib, "SevenZip.lib") - //#pragma comment(lib, "Lua.lib") - //#pragma comment(lib, "ws2_32.lib") //Winsock Library - //#pragma comment(lib, "../Dependencies/DirectXTK." MESEN_LIBRARY_DEBUG_SUFFIX ".Static." MESEN_LIBRARY_SUFFIX) - #define DllExport __declspec(dllexport) +//#pragma comment(lib, "Core.lib") +//#pragma comment(lib, "Utilities.lib") +//#pragma comment(lib, "Windows.lib") +//#pragma comment(lib, "SevenZip.lib") +//#pragma comment(lib, "Lua.lib") +//#pragma comment(lib, "ws2_32.lib") //Winsock Library +//#pragma comment(lib, "../Dependencies/DirectXTK." MESEN_LIBRARY_DEBUG_SUFFIX ".Static." MESEN_LIBRARY_SUFFIX) +#define DllExport __declspec(dllexport) #else #define __stdcall #define DllExport __attribute__((visibility("default"))) -#endif \ No newline at end of file +#endif