From e7e77ccfa7bd4566ffbbd874751a4caafb0df724 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 11 Jul 2015 08:27:22 -0400 Subject: [PATCH] Converted all wide strings to utf8 strings Fixed exception throwing to be standard --- Core/APU.cpp | 2 - Core/BaseMapper.h | 6 +- Core/Breakpoint.h | 10 +- Core/CPU.h | 2 +- Core/ClientConnectionData.h | 4 +- Core/Console.cpp | 28 +- Core/Console.h | 12 +- Core/ControlManager.cpp | 8 +- Core/ControlManager.h | 4 +- Core/Core.vcxproj | 12 + Core/GameClient.cpp | 2 +- Core/GameClientConnection.cpp | 6 +- Core/GameInformationMessage.h | 8 +- Core/GameServer.cpp | 4 +- Core/GameServerConnection.cpp | 6 +- Core/HandShakeMessage.h | 8 +- Core/IKeyManager.h | 4 +- Core/IMemoryHandler.h | 4 +- Core/IMessageManager.h | 16 +- Core/MapperFactory.cpp | 4 +- Core/MapperFactory.h | 2 +- Core/MemoryManager.cpp | 4 +- Core/MessageManager.cpp | 5 +- Core/MessageManager.h | 4 +- Core/Movie.cpp | 38 +- Core/Movie.h | 12 +- Core/NetMessage.h | 6 +- Core/ROMLoader.h | 20 +- Core/SaveStateManager.cpp | 18 +- Core/SaveStateManager.h | 8 +- Core/StandardController.cpp | 2 +- Core/VRC2_4.h | 2 +- Core/stdafx.h | 11 +- GUI.NET/Forms/NetPlay/frmPlayerProfile.cs | 4 +- GUI.NET/InteropEmu.cs | 105 +++++- InteropDLL/ConsoleWrapper.cpp | 30 +- InteropDLL/InteropDLL.vcxproj | 12 + PGOHelper/PGOHelper.vcxproj | 12 + Utilities/CRC32.h | 2 +- Utilities/FolderUtilities.cpp | 101 +++--- Utilities/FolderUtilities.h | 34 +- Utilities/PNGWriter.h | 3 +- Utilities/UPnPPortMapper.h | 2 + Utilities/UTF8Util.h | 70 ++++ Utilities/Utilities.vcxproj | 13 + Utilities/Utilities.vcxproj.filters | 3 + Utilities/stdafx.h | 11 +- Windows/Renderer.cpp | 69 ++-- Windows/Renderer.h | 12 +- Windows/WindowsKeyManager.cpp | 7 +- Windows/WindowsKeyManager.h | 420 +++++++++++----------- Windows/stdafx.h | 1 - 52 files changed, 701 insertions(+), 492 deletions(-) create mode 100644 Utilities/UTF8Util.h diff --git a/Core/APU.cpp b/Core/APU.cpp index b816431a..6b037d34 100644 --- a/Core/APU.cpp +++ b/Core/APU.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "APU.h" #include "CPU.h" diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index 6eeea8cc..0b953e6a 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -27,7 +27,7 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat bool _hasCHRRAM; bool _hasBattery; - wstring _romFilename; + string _romFilename; MirroringType _mirroringType; @@ -109,9 +109,9 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat return (addr >> _chrShift) & _chrSlotMaxIndex; } - wstring GetBatteryFilename() + string GetBatteryFilename() { - return FolderUtilities::GetSaveFolder() + _romFilename + L".sav"; + return FolderUtilities::GetSaveFolder() + _romFilename + ".sav"; } void RestoreOriginalPrgRam() diff --git a/Core/Breakpoint.h b/Core/Breakpoint.h index adaebdde..ef80ec31 100644 --- a/Core/Breakpoint.h +++ b/Core/Breakpoint.h @@ -34,14 +34,14 @@ public: return _type; } - wstring GetTypeText() + string GetTypeText() { switch(_type) { - case BreakpointType::Execute: return L"Exec"; - case BreakpointType::Read: return L"Read"; - case BreakpointType::Write: return L"Write"; + case BreakpointType::Execute: return "Exec"; + case BreakpointType::Read: return "Read"; + case BreakpointType::Write: return "Write"; } - return L""; + return ""; } bool IsEnabled() diff --git a/Core/CPU.h b/Core/CPU.h index 61a5ee28..175d449b 100644 --- a/Core/CPU.h +++ b/Core/CPU.h @@ -214,7 +214,7 @@ private: case AddrMode::AbsY: return GetAbsYAddr(false); case AddrMode::AbsYW: return GetAbsYAddr(true); } - throw new exception(); + throw std::runtime_error("invalid addressing mode"); } uint16_t GetOperand() diff --git a/Core/ClientConnectionData.h b/Core/ClientConnectionData.h index adc8c870..d34ee838 100644 --- a/Core/ClientConnectionData.h +++ b/Core/ClientConnectionData.h @@ -8,11 +8,11 @@ public: string Host; uint16_t Port; - wstring PlayerName; + string PlayerName; uint8_t* AvatarData; uint32_t AvatarSize; - ClientConnectionData(string host, uint16_t port, wstring playerName, uint8_t* avatarData, uint32_t avatarSize) : + ClientConnectionData(string host, uint16_t port, string playerName, uint8_t* avatarData, uint32_t avatarSize) : Host(host), Port(port), PlayerName(playerName), AvatarSize(avatarSize) { if(avatarSize > 0) { diff --git a/Core/Console.cpp b/Core/Console.cpp index 0f1859f9..01b44770 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -26,7 +26,7 @@ shared_ptr Console::GetInstance() return Console::Instance; } -void Console::Initialize(wstring filename) +void Console::Initialize(string filename) { MessageManager::SendNotification(ConsoleNotificationType::GameStopped); shared_ptr mapper = MapperFactory::InitializeFromFile(filename); @@ -51,23 +51,23 @@ void Console::Initialize(wstring filename) _initialized = true; FolderUtilities::AddKnowGameFolder(FolderUtilities::GetFolderName(filename)); - MessageManager::DisplayMessage(L"Game loaded", FolderUtilities::GetFilename(filename, false)); + MessageManager::DisplayMessage("Game loaded", FolderUtilities::GetFilename(filename, false)); } else { - MessageManager::DisplayMessage(L"Error", wstring(L"Could not load file: ") + FolderUtilities::GetFilename(filename, true)); + MessageManager::DisplayMessage("Error", string("Could not load file: ") + FolderUtilities::GetFilename(filename, true)); } } -void Console::LoadROM(wstring filepath) +void Console::LoadROM(string filepath) { Console::Pause(); Instance->Initialize(filepath); Console::Resume(); } -bool Console::LoadROM(wstring filename, uint32_t crc32Hash) +bool Console::LoadROM(string filename, uint32_t crc32Hash) { - wstring currentRomFilepath = Console::GetROMPath(); - wstring currentFolder = FolderUtilities::GetFolderName(currentRomFilepath); + string currentRomFilepath = Console::GetROMPath(); + string currentFolder = FolderUtilities::GetFolderName(currentRomFilepath); if(!currentRomFilepath.empty()) { if(ROMLoader::GetCRC32(Console::GetROMPath()) == crc32Hash) { //Current game matches, no need to do anything @@ -75,16 +75,16 @@ bool Console::LoadROM(wstring filename, uint32_t crc32Hash) } //Try to find the game in the same folder as the current game's folder - wstring match = ROMLoader::FindMatchingRomInFolder(currentFolder, filename, crc32Hash); + string match = ROMLoader::FindMatchingRomInFolder(currentFolder, filename, crc32Hash); if(!match.empty()) { Console::LoadROM(match); return true; } } - for(wstring folder : FolderUtilities::GetKnowGameFolders()) { + for(string folder : FolderUtilities::GetKnowGameFolders()) { if(folder != currentFolder) { - wstring match = ROMLoader::FindMatchingRomInFolder(folder, filename, crc32Hash); + string match = ROMLoader::FindMatchingRomInFolder(folder, filename, crc32Hash); if(!match.empty()) { Console::LoadROM(match); return true; @@ -94,13 +94,9 @@ bool Console::LoadROM(wstring filename, uint32_t crc32Hash) return false; } -wstring Console::GetROMPath() +string Console::GetROMPath() { - wstring filepath; - if(Instance->_initialized) { - filepath = Instance->_romFilepath; - } - return filepath; + return Instance->_romFilepath; } void Console::Reset(bool softReset) diff --git a/Core/Console.h b/Core/Console.h index 8a8598df..5701a8da 100644 --- a/Core/Console.h +++ b/Core/Console.h @@ -34,7 +34,7 @@ class Console unique_ptr _controlManager; shared_ptr _memoryManager; - wstring _romFilepath; + string _romFilepath; bool _stop = false; bool _reset = false; @@ -42,7 +42,7 @@ class Console bool _initialized = false; void ResetComponents(bool softReset); - void Initialize(wstring filename); + void Initialize(string filename); public: Console(); @@ -63,10 +63,10 @@ class Console static void LoadState(istream &loadStream); static void LoadState(uint8_t *buffer, uint32_t bufferSize); - static void LoadROM(wstring filepath); - static bool LoadROM(wstring romName, uint32_t crc32Hash); - static wstring FindMatchingRomInFolder(wstring folder, wstring romFilename, uint32_t crc32Hash); - static wstring GetROMPath(); + static void LoadROM(string filepath); + static bool LoadROM(string romName, uint32_t crc32Hash); + static string FindMatchingRomInFolder(string folder, string romFilename, uint32_t crc32Hash); + static string GetROMPath(); static bool CheckFlag(int flag); static void SetFlags(int flags); diff --git a/Core/ControlManager.cpp b/Core/ControlManager.cpp index 114be42b..a68b2295 100644 --- a/Core/ControlManager.cpp +++ b/Core/ControlManager.cpp @@ -34,7 +34,7 @@ uint32_t ControlManager::GetPressedKey() return 0; } -wchar_t* ControlManager::GetKeyName(uint32_t keyCode) +string ControlManager::GetKeyName(uint32_t keyCode) { if(_keyManager != nullptr) { return _keyManager->GetKeyName(keyCode); @@ -42,7 +42,7 @@ wchar_t* ControlManager::GetKeyName(uint32_t keyCode) return 0; } -uint32_t ControlManager::GetKeyCode(wchar_t* keyName) +uint32_t ControlManager::GetKeyCode(string keyName) { if(_keyManager != nullptr) { return _keyManager->GetKeyCode(keyName); @@ -146,7 +146,7 @@ bool ControlManager::HasFourScoreAdapter() void ControlManager::RefreshStateBuffer(uint8_t port) { if(port >= 2) { - throw exception("Invalid port"); + throw std::runtime_error("Invalid port"); } //First 8 bits : Gamepad 1/2 @@ -170,7 +170,7 @@ void ControlManager::RefreshStateBuffer(uint8_t port) uint8_t ControlManager::GetPortValue(uint8_t port) { if(port >= 2) { - throw exception("Invalid port"); + throw std::runtime_error("Invalid port"); } if(_refreshState) { diff --git a/Core/ControlManager.h b/Core/ControlManager.h index 9b88984a..3820108f 100644 --- a/Core/ControlManager.h +++ b/Core/ControlManager.h @@ -39,8 +39,8 @@ class ControlManager : public Snapshotable, public IMemoryHandler static void RegisterKeyManager(IKeyManager* keyManager); static bool IsKeyPressed(uint32_t keyCode); static uint32_t GetPressedKey(); - static wchar_t* GetKeyName(uint32_t keyCode); - static uint32_t GetKeyCode(wchar_t* keyName); + static string GetKeyName(uint32_t keyCode); + static uint32_t GetKeyCode(string keyName); static void BackupControlDevices(); static void RestoreControlDevices(); diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 3535f4c0..cba5d5c3 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -140,6 +140,8 @@ ProgramDatabase Default Cdecl + + Console @@ -162,6 +164,8 @@ ProgramDatabase Default Cdecl + + Console @@ -184,6 +188,8 @@ AnySuitable true Speed + + Console @@ -204,6 +210,8 @@ AnySuitable true Speed + + Console @@ -224,6 +232,8 @@ AnySuitable true Speed + + Console @@ -244,6 +254,8 @@ AnySuitable true Speed + + Console diff --git a/Core/GameClient.cpp b/Core/GameClient.cpp index 744ffdf0..105fb1df 100644 --- a/Core/GameClient.cpp +++ b/Core/GameClient.cpp @@ -52,7 +52,7 @@ void GameClient::PrivateConnect(shared_ptr connectionData) _connection.reset(new GameClientConnection(_socket, connectionData)); _connected = true; } else { - MessageManager::DisplayMessage(L"Net Play", L"Could not connect to server."); + MessageManager::DisplayMessage("Net Play", "Could not connect to server."); _connected = false; _socket.reset(); } diff --git a/Core/GameClientConnection.cpp b/Core/GameClientConnection.cpp index ed9233d4..bcce8c3c 100644 --- a/Core/GameClientConnection.cpp +++ b/Core/GameClientConnection.cpp @@ -16,7 +16,7 @@ GameClientConnection::GameClientConnection(shared_ptr socket, shared_ptr _controlDevice = ControlManager::GetControlDevice(0); ControlManager::BackupControlDevices(); - MessageManager::DisplayMessage(L"Net Play", L"Connected to server."); + MessageManager::DisplayMessage("Net Play", "Connected to server."); SendHandshake(); } @@ -25,7 +25,7 @@ GameClientConnection::~GameClientConnection() { _virtualControllers.clear(); ControlManager::RestoreControlDevices(); - MessageManager::DisplayMessage(L"Net Play", L"Connection to server lost."); + MessageManager::DisplayMessage("Net Play", "Connection to server lost."); } void GameClientConnection::SendHandshake() @@ -77,7 +77,7 @@ void GameClientConnection::ProcessMessage(NetMessage* message) gameInfo = (GameInformationMessage*)message; if(gameInfo->GetPort() != _controllerPort) { _controllerPort = gameInfo->GetPort(); - MessageManager::DisplayMessage(wstring(L"Connected as player ") + std::to_wstring(_controllerPort + 1)); + MessageManager::DisplayMessage(string("Connected as player ") + std::to_string(_controllerPort + 1)); } DisposeVirtualControllers(); diff --git a/Core/GameInformationMessage.h b/Core/GameInformationMessage.h index 73e98bed..7bdea6a2 100644 --- a/Core/GameInformationMessage.h +++ b/Core/GameInformationMessage.h @@ -9,7 +9,7 @@ class GameInformationMessage : public NetMessage { private: - wchar_t *_romFilename = nullptr; + char* _romFilename = nullptr; uint32_t _romFilenameLength = 0; uint32_t _crc32Hash = 0; uint8_t _controllerPort = 0; @@ -27,7 +27,7 @@ protected: public: GameInformationMessage(void* buffer, uint32_t length) : NetMessage(buffer, length) { } - GameInformationMessage(wstring filepath, uint8_t port, bool paused) : NetMessage(MessageType::GameInformation) + GameInformationMessage(string filepath, uint8_t port, bool paused) : NetMessage(MessageType::GameInformation) { CopyString(&_romFilename, _romFilenameLength, FolderUtilities::GetFilename(filepath, true)); _crc32Hash = ROMLoader::GetCRC32(filepath); @@ -37,12 +37,12 @@ public: bool AttemptLoadGame() { - wstring filename = _romFilename; + string filename = _romFilename; if(filename.size() > 0) { if(Console::LoadROM(filename, _crc32Hash)) { return true; } else { - MessageManager::DisplayMessage(L"Net Play", L"Could not find matching game ROM."); + MessageManager::DisplayMessage("Net Play", "Could not find matching game ROM."); return false; } } diff --git a/Core/GameServer.cpp b/Core/GameServer.cpp index 453873b8..1fb3e8c4 100644 --- a/Core/GameServer.cpp +++ b/Core/GameServer.cpp @@ -62,7 +62,7 @@ void GameServer::Exec() _listener->Listen(10); _stop = false; _initialized = true; - MessageManager::DisplayMessage(L"Net Play" , L"Server started (Port: " + std::to_wstring(_port) + L")"); + MessageManager::DisplayMessage("Net Play" , "Server started (Port: " + std::to_string(_port) + ")"); while(!_stop) { AcceptConnections(); @@ -76,7 +76,7 @@ void GameServer::Stop() { _initialized = false; _listener.reset(); - MessageManager::DisplayMessage(L"Net Play", L"Server stopped"); + MessageManager::DisplayMessage("Net Play", "Server stopped"); } void GameServer::StartServer(uint16_t port) diff --git a/Core/GameServerConnection.cpp b/Core/GameServerConnection.cpp index e5e0a6e6..699b5511 100644 --- a/Core/GameServerConnection.cpp +++ b/Core/GameServerConnection.cpp @@ -25,9 +25,9 @@ GameServerConnection::GameServerConnection(shared_ptr socket, int contro GameServerConnection::~GameServerConnection() { if(_connectionData) { - MessageManager::DisplayToast(L"Net Play", _connectionData->PlayerName + L" (Player " + std::to_wstring(_controllerPort + 1) + L") disconnected.", _connectionData->AvatarData, _connectionData->AvatarSize); + MessageManager::DisplayToast("Net Play", _connectionData->PlayerName + " (Player " + std::to_string(_controllerPort + 1) + ") disconnected.", _connectionData->AvatarData, _connectionData->AvatarSize); } else { - MessageManager::DisplayMessage(L"Net Play", L"Player " + std::to_wstring(_controllerPort + 1) + L" disconnected."); + MessageManager::DisplayMessage("Net Play", "Player " + std::to_string(_controllerPort + 1) + " disconnected."); } ControlManager::RestoreControlDevices(); @@ -88,7 +88,7 @@ void GameServerConnection::ProcessMessage(NetMessage* message) if(((HandShakeMessage*)message)->IsValid()) { _connectionData.reset(new ClientConnectionData("", 0, ((HandShakeMessage*)message)->GetPlayerName(), ((HandShakeMessage*)message)->GetAvatarData(), ((HandShakeMessage*)message)->GetAvatarSize())); - MessageManager::DisplayToast(L"Net Play", _connectionData->PlayerName + L" (Player " + std::to_wstring(_controllerPort + 1) + L") connected.", _connectionData->AvatarData, _connectionData->AvatarSize); + MessageManager::DisplayToast("Net Play", _connectionData->PlayerName + " (Player " + std::to_string(_controllerPort + 1) + ") connected.", _connectionData->AvatarData, _connectionData->AvatarSize); SendGameInformation(); SendGameState(); } diff --git a/Core/HandShakeMessage.h b/Core/HandShakeMessage.h index 0c2ff805..77629424 100644 --- a/Core/HandShakeMessage.h +++ b/Core/HandShakeMessage.h @@ -7,7 +7,7 @@ class HandShakeMessage : public NetMessage private: const static int CurrentVersion = 1; uint32_t _protocolVersion = CurrentVersion; - wchar_t *_playerName = nullptr; + char* _playerName = nullptr; uint32_t _playerNameLength = 0; void* _avatarData = nullptr; uint32_t _avatarSize = 0; @@ -22,7 +22,7 @@ protected: public: HandShakeMessage(void* buffer, uint32_t length) : NetMessage(buffer, length) { } - HandShakeMessage(wstring playerName, uint8_t* avatarData, uint32_t avatarSize) : NetMessage(MessageType::HandShake) + HandShakeMessage(string playerName, uint8_t* avatarData, uint32_t avatarSize) : NetMessage(MessageType::HandShake) { _protocolVersion = 1; CopyString(&_playerName, _playerNameLength, playerName); @@ -30,9 +30,9 @@ public: _avatarData = avatarData; } - wstring GetPlayerName() + string GetPlayerName() { - return wstring(_playerName); + return string(_playerName); } uint8_t* GetAvatarData() diff --git a/Core/IKeyManager.h b/Core/IKeyManager.h index ceed93df..d2bf2fe7 100644 --- a/Core/IKeyManager.h +++ b/Core/IKeyManager.h @@ -8,6 +8,6 @@ public: virtual void RefreshState() = 0; virtual bool IsKeyPressed(uint32_t keyCode) = 0; virtual uint32_t GetPressedKey() = 0; - virtual wchar_t* GetKeyName(uint32_t keyCode) = 0; - virtual uint32_t GetKeyCode(wchar_t* keyName) = 0; + virtual string GetKeyName(uint32_t keyCode) = 0; + virtual uint32_t GetKeyCode(string keyName) = 0; }; \ No newline at end of file diff --git a/Core/IMemoryHandler.h b/Core/IMemoryHandler.h index 9dc716d2..7dcd5805 100644 --- a/Core/IMemoryHandler.h +++ b/Core/IMemoryHandler.h @@ -60,6 +60,6 @@ public: virtual void GetMemoryRanges(MemoryRanges &ranges) = 0; virtual uint8_t ReadRAM(uint16_t addr) = 0; virtual void WriteRAM(uint16_t addr, uint8_t value) = 0; - virtual uint8_t ReadVRAM(uint16_t addr) { throw exception("Operation not implemented"); } - virtual void WriteVRAM(uint16_t addr, uint8_t value) { throw exception("Operation not implemented"); } + virtual uint8_t ReadVRAM(uint16_t addr) { throw std::runtime_error("Operation not implemented"); } + virtual void WriteVRAM(uint16_t addr, uint8_t value) { throw std::runtime_error("Operation not implemented"); } }; \ No newline at end of file diff --git a/Core/IMessageManager.h b/Core/IMessageManager.h index def8e31a..9a2198fe 100644 --- a/Core/IMessageManager.h +++ b/Core/IMessageManager.h @@ -8,21 +8,21 @@ class ToastInfo; class IMessageManager { public: - virtual void DisplayMessage(wstring title, wstring message) = 0; + virtual void DisplayMessage(string title, string message) = 0; virtual void DisplayToast(shared_ptr toast) = 0; }; class ToastInfo { private: - wstring _title; - wstring _message; + string _title; + string _message; uint8_t* _icon; uint32_t _iconSize; uint64_t _endTime; uint64_t _startTime; - uint8_t* ReadFile(wstring filename, uint32_t &fileSize) + uint8_t* ReadFile(string filename, uint32_t &fileSize) { ifstream file(filename, ios::in | ios::binary); if(file) { @@ -43,7 +43,7 @@ private: } public: - ToastInfo(wstring title, wstring message, int displayDuration, wstring iconFile) + ToastInfo(string title, string message, int displayDuration, string iconFile) { _title = title; _message = message; @@ -54,7 +54,7 @@ public: _endTime = _startTime + displayDuration; } - ToastInfo(wstring title, wstring message, int displayDuration, uint8_t* iconData, uint32_t iconSize) + ToastInfo(string title, string message, int displayDuration, uint8_t* iconData, uint32_t iconSize) { _title = title; _message = message; @@ -74,12 +74,12 @@ public: } } - wstring GetToastTitle() + string GetToastTitle() { return _title; } - wstring GetToastMessage() + string GetToastMessage() { return _message; } diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 84725967..8a1d4aef 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -37,13 +37,13 @@ BaseMapper* MapperFactory::GetMapperFromID(uint8_t mapperID) case 71: return new UNROM(); //TODO: "It's largely a clone of UNROM, and Camerica games were initially emulated under iNES Mapper 002 before 071 was assigned." case 163: return new Nanjing(); case 189: return new MMC3_189(); - default: MessageManager::DisplayMessage(L"Error", L"Unsupported mapper, cannot load game."); + default: MessageManager::DisplayMessage("Error", "Unsupported mapper, cannot load game."); } return nullptr; } -shared_ptr MapperFactory::InitializeFromFile(wstring filename) +shared_ptr MapperFactory::InitializeFromFile(string filename) { ROMLoader loader; diff --git a/Core/MapperFactory.h b/Core/MapperFactory.h index 8f361339..2b1bed4a 100644 --- a/Core/MapperFactory.h +++ b/Core/MapperFactory.h @@ -7,5 +7,5 @@ class MapperFactory static BaseMapper* GetMapperFromID(uint8_t mapperID); public: - static shared_ptr InitializeFromFile(wstring filename); + static shared_ptr InitializeFromFile(string filename); }; diff --git a/Core/MemoryManager.cpp b/Core/MemoryManager.cpp index 9428162f..3afa4df8 100644 --- a/Core/MemoryManager.cpp +++ b/Core/MemoryManager.cpp @@ -78,7 +78,7 @@ void MemoryManager::InitializeMemoryHandlers(IMemoryHandler** memoryHandlers, IM { for(uint16_t address : *addresses) { if(memoryHandlers[address] != nullptr) { - throw exception("Not supported"); + throw std::runtime_error("Not supported"); } memoryHandlers[address] = handler; } @@ -207,7 +207,7 @@ void MemoryManager::WriteVRAM(uint16_t addr, uint8_t value) break; default: - throw exception("Not implemented yet"); + throw std::runtime_error("Not implemented yet"); } } } diff --git a/Core/MessageManager.cpp b/Core/MessageManager.cpp index 9dd7acd4..652d47c8 100644 --- a/Core/MessageManager.cpp +++ b/Core/MessageManager.cpp @@ -10,15 +10,14 @@ void MessageManager::RegisterMessageManager(IMessageManager* messageManager) MessageManager::_messageManager = messageManager; } -void MessageManager::DisplayMessage(wstring title, wstring message) +void MessageManager::DisplayMessage(string title, string message) { - std::wcout << message << std::endl; if(MessageManager::_messageManager) { MessageManager::_messageManager->DisplayMessage(title, message); } } -void MessageManager::DisplayToast(wstring title, wstring message, uint8_t* iconData, uint32_t iconSize) +void MessageManager::DisplayToast(string title, string message, uint8_t* iconData, uint32_t iconSize) { if(MessageManager::_messageManager) { MessageManager::_messageManager->DisplayToast(shared_ptr(new ToastInfo(title, message, 4000, iconData, iconSize))); diff --git a/Core/MessageManager.h b/Core/MessageManager.h index e5393944..bfbd35cd 100644 --- a/Core/MessageManager.h +++ b/Core/MessageManager.h @@ -13,8 +13,8 @@ private: public: static void RegisterMessageManager(IMessageManager* messageManager); - static void DisplayMessage(wstring title, wstring message = L""); - static void DisplayToast(wstring title, wstring message, uint8_t* iconData, uint32_t iconSize); + static void DisplayMessage(string title, string message = ""); + static void DisplayToast(string title, string message, uint8_t* iconData, uint32_t iconSize); static void RegisterNotificationListener(INotificationListener* notificationListener); static void UnregisterNotificationListener(INotificationListener* notificationListener); diff --git a/Core/Movie.cpp b/Core/Movie.cpp index 3cf7aa47..ee5623f7 100644 --- a/Core/Movie.cpp +++ b/Core/Movie.cpp @@ -46,7 +46,7 @@ uint8_t Movie::GetState(uint8_t port) if(_readPosition[port] >= _data.DataSize[port]) { //End of movie file - MessageManager::DisplayMessage(L"Movies", L"Movie ended."); + MessageManager::DisplayMessage("Movies", "Movie ended."); _playing = false; } @@ -68,10 +68,10 @@ void Movie::Reset() _playing = false; } -void Movie::StartRecording(wstring filename, bool reset) +void Movie::StartRecording(string filename, bool reset) { _filename = filename; - _file = ofstream(filename, ios::out | ios::binary); + _file.open(filename, ios::out | ios::binary); if(_file) { Console::Pause(); @@ -88,7 +88,7 @@ void Movie::StartRecording(wstring filename, bool reset) Console::Resume(); - MessageManager::DisplayMessage(L"Movies", L"Recording to: " + FolderUtilities::GetFilename(filename, true)); + MessageManager::DisplayMessage("Movies", "Recording to: " + FolderUtilities::GetFilename(filename, true)); } } @@ -102,12 +102,12 @@ void Movie::StopAll() Save(); } if(_playing) { - MessageManager::DisplayMessage(L"Movies", L"Movie stopped."); + MessageManager::DisplayMessage("Movies", "Movie stopped."); _playing = false; } } -void Movie::PlayMovie(wstring filename) +void Movie::PlayMovie(string filename) { StopAll(); @@ -123,16 +123,16 @@ void Movie::PlayMovie(wstring filename) } _playing = true; Console::Resume(); - MessageManager::DisplayMessage(L"Movies", L"Playing movie: " + FolderUtilities::GetFilename(filename, true)); + MessageManager::DisplayMessage("Movies", "Playing movie: " + FolderUtilities::GetFilename(filename, true)); } } -void Movie::Record(wstring filename, bool reset) +void Movie::Record(string filename, bool reset) { Instance->StartRecording(filename, reset); } -void Movie::Play(wstring filename) +void Movie::Play(string filename) { Instance->PlayMovie(filename); } @@ -157,15 +157,15 @@ bool Movie::Save() _file.write("MMO", 3); _data.SaveStateSize = (uint32_t)_startState.tellp(); - wstring romFilepath = Console::GetROMPath(); - wstring romFilename = FolderUtilities::GetFilename(romFilepath, true); + string romFilepath = Console::GetROMPath(); + string romFilename = FolderUtilities::GetFilename(romFilepath, true); uint32_t romCrc32 = ROMLoader::GetCRC32(romFilepath); _file.write((char*)&romCrc32, sizeof(romCrc32)); uint32_t romNameSize = (uint32_t)romFilename.size(); _file.write((char*)&romNameSize, sizeof(uint32_t)); - _file.write((char*)romFilename.c_str(), romNameSize * sizeof(wchar_t)); + _file.write((char*)romFilename.c_str(), romNameSize); _file.write((char*)&_data.SaveStateSize, sizeof(uint32_t)); @@ -187,12 +187,12 @@ bool Movie::Save() _file.close(); - MessageManager::DisplayMessage(L"Movies", L"Movie saved to file: " + FolderUtilities::GetFilename(_filename, true)); + MessageManager::DisplayMessage("Movies", "Movie saved to file: " + FolderUtilities::GetFilename(_filename, true)); return true; } -bool Movie::Load(wstring filename) +bool Movie::Load(string filename) { ifstream file(filename, ios::in | ios::binary); @@ -211,11 +211,11 @@ bool Movie::Load(wstring filename) uint32_t romNameSize; file.read((char*)&romNameSize, sizeof(uint32_t)); - wchar_t* romFilename = new wchar_t[romNameSize + 1]; - memset(romFilename, 0, (romNameSize+1)*sizeof(wchar_t)); - file.read((char*)romFilename, romNameSize * sizeof(wchar_t)); + char* romFilename = new char[romNameSize + 1]; + memset(romFilename, 0, (romNameSize+1)); + file.read((char*)romFilename, romNameSize); - wstring currentRom = Console::GetROMPath(); + string currentRom = Console::GetROMPath(); bool loadedGame = true; if(currentRom.empty() || romCrc32 != ROMLoader::GetCRC32(currentRom)) { //Loaded game isn't the same as the game used for the movie, attempt to load the correct game @@ -241,7 +241,7 @@ bool Movie::Load(wstring filename) delete[] readBuffer; } } else { - MessageManager::DisplayMessage(L"Movies", L"Missing ROM required (" + wstring(romFilename) + L") to play movie."); + MessageManager::DisplayMessage("Movies", "Missing ROM required (" + string(romFilename) + ") to play movie."); } file.close(); diff --git a/Core/Movie.h b/Core/Movie.h index 4b67c4bc..72ec2711 100644 --- a/Core/Movie.h +++ b/Core/Movie.h @@ -21,14 +21,14 @@ class Movie uint8_t _lastState[4]; uint32_t _readPosition[4]; ofstream _file; - wstring _filename; + string _filename; stringstream _startState; MovieData _data; private: void PushState(uint8_t port); - void StartRecording(wstring filename, bool reset); - void PlayMovie(wstring filename); + void StartRecording(string filename, bool reset); + void PlayMovie(string filename); void StopAll(); void Reset(); @@ -36,11 +36,11 @@ class Movie uint8_t GetState(uint8_t port); bool Save(); - bool Load(wstring filename); + bool Load(string filename); public: - static void Record(wstring filename, bool reset); - static void Play(wstring filename); + static void Record(string filename, bool reset); + static void Play(string filename); static void Stop(); static bool Playing(); static bool Recording(); diff --git a/Core/NetMessage.h b/Core/NetMessage.h index de208d76..b98ff6a7 100644 --- a/Core/NetMessage.h +++ b/Core/NetMessage.h @@ -95,10 +95,10 @@ public: socket.SendBuffer(); } - void CopyString(wchar_t** dest, uint32_t &length, wstring src) + void CopyString(char** dest, uint32_t &length, string src) { - length = (uint32_t)(src.length() + 1)*sizeof(wchar_t); - *dest = (wchar_t*)new uint8_t[length]; + length = (uint32_t)(src.length() + 1); + *dest = new char[length]; memcpy(*dest, src.c_str(), length); _pointersToRelease.push_back(*dest); } diff --git a/Core/ROMLoader.h b/Core/ROMLoader.h index 2cc7813c..c3e09e01 100644 --- a/Core/ROMLoader.h +++ b/Core/ROMLoader.h @@ -54,7 +54,7 @@ class ROMLoader { private: NESHeader _header; - wstring _filename; + string _filename; uint8_t* _prgRAM = nullptr; uint8_t* _chrRAM = nullptr; uint32_t _crc32; @@ -156,7 +156,7 @@ class ROMLoader } } - bool LoadFile(wstring filename) + bool LoadFile(string filename) { bool result = false; ifstream file(filename, ios::in | ios::binary); @@ -218,12 +218,12 @@ class ROMLoader return _header.HasBattery(); } - wstring GetFilename() + string GetFilename() { return _filename; } - static uint32_t GetCRC32(wstring filename) + static uint32_t GetCRC32(string filename) { ROMLoader loader; uint32_t crc = 0; @@ -233,13 +233,13 @@ class ROMLoader return crc; } - static wstring FindMatchingRomInFolder(wstring folder, wstring romFilename, uint32_t crc32Hash) + static string FindMatchingRomInFolder(string folder, string romFilename, uint32_t crc32Hash) { - vector romFiles = FolderUtilities::GetFilesInFolder(folder, L"*.nes", true); - for(wstring zipFile : FolderUtilities::GetFilesInFolder(folder, L"*.zip", true)) { + vector romFiles = FolderUtilities::GetFilesInFolder(folder, "*.nes", true); + for(string zipFile : FolderUtilities::GetFilesInFolder(folder, "*.zip", true)) { romFiles.push_back(zipFile); } - for(wstring romFile : romFiles) { + for(string romFile : romFiles) { //Quick search by filename if(FolderUtilities::GetFilename(romFile, true).compare(romFilename) == 0) { if(ROMLoader::GetCRC32(romFile) == crc32Hash) { @@ -248,7 +248,7 @@ class ROMLoader } } - for(wstring romFile : romFiles) { + for(string romFile : romFiles) { //Slower search by CRC value if(ROMLoader::GetCRC32(romFile) == crc32Hash) { //Matching ROM found @@ -256,7 +256,7 @@ class ROMLoader } } - return L""; + return ""; } }; diff --git a/Core/SaveStateManager.cpp b/Core/SaveStateManager.cpp index 62079fd0..de2abe44 100644 --- a/Core/SaveStateManager.cpp +++ b/Core/SaveStateManager.cpp @@ -5,16 +5,16 @@ #include "Console.h" #include "../Utilities/FolderUtilities.h" -wstring SaveStateManager::GetStateFilepath(int stateIndex) +string SaveStateManager::GetStateFilepath(int stateIndex) { - wstring folder = FolderUtilities::GetSaveStateFolder(); - wstring filename = FolderUtilities::GetFilename(Console::GetROMPath(), false) + L"_" + std::to_wstring(stateIndex) + L".mst"; + string folder = FolderUtilities::GetSaveStateFolder(); + string filename = FolderUtilities::GetFilename(Console::GetROMPath(), false) + "_" + std::to_string(stateIndex) + ".mst"; return FolderUtilities::CombinePath(folder, filename); } uint64_t SaveStateManager::GetStateInfo(int stateIndex) { - wstring filepath = SaveStateManager::GetStateFilepath(stateIndex); + string filepath = SaveStateManager::GetStateFilepath(stateIndex); ifstream file(filepath, ios::in | ios::binary); if(file) { @@ -26,7 +26,7 @@ uint64_t SaveStateManager::GetStateInfo(int stateIndex) void SaveStateManager::SaveState(int stateIndex) { - wstring filepath = SaveStateManager::GetStateFilepath(stateIndex); + string filepath = SaveStateManager::GetStateFilepath(stateIndex); ofstream file(filepath, ios::out | ios::binary); if(file) { @@ -34,13 +34,13 @@ void SaveStateManager::SaveState(int stateIndex) Console::SaveState(file); Console::Resume(); file.close(); - MessageManager::DisplayMessage(L"Game States", L"State #" + std::to_wstring(stateIndex) + L" saved."); + MessageManager::DisplayMessage("Game States", "State #" + std::to_string(stateIndex) + " saved."); } } bool SaveStateManager::LoadState(int stateIndex) { - wstring filepath = SaveStateManager::GetStateFilepath(stateIndex); + string filepath = SaveStateManager::GetStateFilepath(stateIndex); ifstream file(filepath, ios::in | ios::binary); if(file) { @@ -48,10 +48,10 @@ bool SaveStateManager::LoadState(int stateIndex) Console::LoadState(file); Console::Resume(); file.close(); - MessageManager::DisplayMessage(L"Game States", L"State #" + std::to_wstring(stateIndex) + L" loaded."); + MessageManager::DisplayMessage("Game States", "State #" + std::to_string(stateIndex) + " loaded."); return true; } - MessageManager::DisplayMessage(L"Game States", L"Slot is empty."); + MessageManager::DisplayMessage("Game States", "Slot is empty."); return false; } \ No newline at end of file diff --git a/Core/SaveStateManager.h b/Core/SaveStateManager.h index 99f01c37..bef51684 100644 --- a/Core/SaveStateManager.h +++ b/Core/SaveStateManager.h @@ -5,11 +5,11 @@ class SaveStateManager { private: - static wstring SaveStateManager::GetStateFilepath(int stateIndex); + static string GetStateFilepath(int stateIndex); public: - static uint64_t SaveStateManager::GetStateInfo(int stateIndex); - static void SaveStateManager::SaveState(int stateIndex); - static bool SaveStateManager::LoadState(int stateIndex); + static uint64_t GetStateInfo(int stateIndex); + static void SaveState(int stateIndex); + static bool LoadState(int stateIndex); }; \ No newline at end of file diff --git a/Core/StandardController.cpp b/Core/StandardController.cpp index 1e8a335f..0e314d37 100644 --- a/Core/StandardController.cpp +++ b/Core/StandardController.cpp @@ -41,7 +41,7 @@ ButtonState StandardController::GetButtonState() //Turbo buttons - need to be applied for at least 2 reads in a row (some games require this) uint8_t turboFreq = 1 << (4 - keyMapping.TurboSpeed); - bool turboOn = PPU::GetFrameCount() % turboFreq < turboFreq / 2; + bool turboOn = (uint8_t)(PPU::GetFrameCount() % turboFreq) < turboFreq / 2; if(turboOn) { state.A |= ControlManager::IsKeyPressed(keyMapping.TurboA); state.B |= ControlManager::IsKeyPressed(keyMapping.TurboB); diff --git a/Core/VRC2_4.h b/Core/VRC2_4.h index 404c6318..bfec3354 100644 --- a/Core/VRC2_4.h +++ b/Core/VRC2_4.h @@ -166,7 +166,7 @@ class VRC2_4 : public BaseMapper A1 |= (addr >> 3) & 0x01; break; default: - throw exception("not supported"); + throw std::runtime_error("not supported"); break; } diff --git a/Core/stdafx.h b/Core/stdafx.h index 26d6a404..a8f3618f 100644 --- a/Core/stdafx.h +++ b/Core/stdafx.h @@ -1,9 +1,6 @@ #pragma once -#include - #include -#include #include #include @@ -20,17 +17,17 @@ #include #include +#include "../Utilities/UTF8Util.h" + using std::vector; using std::shared_ptr; using std::unique_ptr; using std::ios; -using std::ifstream; using std::istream; using std::ostream; using std::stringstream; -using std::ofstream; -using std::wstring; -using std::exception; +using utf8::ifstream; +using utf8::ofstream; using std::list; using std::max; using std::string; diff --git a/GUI.NET/Forms/NetPlay/frmPlayerProfile.cs b/GUI.NET/Forms/NetPlay/frmPlayerProfile.cs index b202e824..d7ef1b0b 100644 --- a/GUI.NET/Forms/NetPlay/frmPlayerProfile.cs +++ b/GUI.NET/Forms/NetPlay/frmPlayerProfile.cs @@ -33,13 +33,13 @@ namespace Mesen.GUI.Forms.NetPlay } } } - /* + protected override void UpdateConfig() { PlayerProfile profile = new PlayerProfile(); profile.PlayerName = this.txtPlayerName.Text; profile.SetAvatar(this.picAvatar.Image); ConfigManager.Config.Profile = profile; - }*/ + } } } diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index e05ccf41..3c36fd53 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -12,16 +12,16 @@ namespace Mesen.GUI public class InteropEmu { private const string DLLPath = "WinMesen.dll"; - [DllImport(DLLPath)] public static extern void InitializeEmu([MarshalAs(UnmanagedType.LPWStr)]string homeFolder, IntPtr windowHandle, IntPtr dxViewerHandle); + [DllImport(DLLPath)] public static extern void InitializeEmu([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string homeFolder, IntPtr windowHandle, IntPtr dxViewerHandle); [DllImport(DLLPath)] public static extern void Release(); - [DllImport(DLLPath)] public static extern void LoadROM([MarshalAs(UnmanagedType.LPWStr)]string filename); - [DllImport(DLLPath)] public static extern void AddKnowGameFolder([MarshalAs(UnmanagedType.LPWStr)]string folder); + [DllImport(DLLPath)] public static extern void LoadROM([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename); + [DllImport(DLLPath)] public static extern void AddKnowGameFolder([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string folder); [DllImport(DLLPath)] public static extern void AddKeyMappings(int port, KeyMapping mapping); [DllImport(DLLPath)] public static extern void ClearKeyMappings(int port); [DllImport(DLLPath)] public static extern UInt32 GetPressedKey(); - [DllImport(DLLPath)] public static extern UInt32 GetKeyCode([MarshalAs(UnmanagedType.LPWStr)]string keyName); + [DllImport(DLLPath)] public static extern UInt32 GetKeyCode([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string keyName); [DllImport(DLLPath, EntryPoint="GetKeyName")] private static extern IntPtr GetKeyNameWrapper(UInt32 key); [DllImport(DLLPath)] public static extern void Run(); @@ -36,7 +36,7 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern void StartServer(UInt16 port); [DllImport(DLLPath)] public static extern void StopServer(); [DllImport(DLLPath)] public static extern bool IsServerRunning(); - [DllImport(DLLPath)] public static extern void Connect(string host, UInt16 port, [MarshalAs(UnmanagedType.LPWStr)]string playerName, byte[] avatarData, UInt32 avatarSize); + [DllImport(DLLPath)] public static extern void Connect(string host, UInt16 port, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string playerName, byte[] avatarData, UInt32 avatarSize); [DllImport(DLLPath)] public static extern void Disconnect(); [DllImport(DLLPath)] public static extern bool IsConnected(); @@ -46,10 +46,10 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern IntPtr RegisterNotificationCallback(NotificationListener.NotificationCallback callback); [DllImport(DLLPath)] public static extern void UnregisterNotificationCallback(IntPtr notificationListener); - [DllImport(DLLPath)] public static extern void DisplayMessage([MarshalAs(UnmanagedType.LPWStr)]string title, [MarshalAs(UnmanagedType.LPWStr)]string message); + [DllImport(DLLPath)] public static extern void DisplayMessage([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string title, [MarshalAs(UnmanagedType.LPWStr)]string message); - [DllImport(DLLPath)] public static extern void MoviePlay([MarshalAs(UnmanagedType.LPWStr)]string filename); - [DllImport(DLLPath)] public static extern void MovieRecord([MarshalAs(UnmanagedType.LPWStr)]string filename, bool reset); + [DllImport(DLLPath)] public static extern void MoviePlay([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename); + [DllImport(DLLPath)] public static extern void MovieRecord([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename, bool reset); [DllImport(DLLPath)] public static extern void MovieStop(); [DllImport(DLLPath)] public static extern bool MoviePlaying(); [DllImport(DLLPath)] public static extern bool MovieRecording(); @@ -77,10 +77,29 @@ namespace Mesen.GUI [DllImport(DLLPath)] public static extern Byte DebugGetMemoryValue(UInt32 addr); [DllImport(DLLPath)] public static extern UInt32 DebugGetRelativeAddress(UInt32 addr); - - public static string GetROMPath() { return Marshal.PtrToStringAuto(InteropEmu.GetROMPathWrapper()); } - public static string GetKeyName(UInt32 key) { return Marshal.PtrToStringAuto(InteropEmu.GetKeyNameWrapper(key)); } + public static string GetROMPath() { return PtrToStringUtf8(InteropEmu.GetROMPathWrapper()); } + public static string GetKeyName(UInt32 key) { return PtrToStringUtf8(InteropEmu.GetKeyNameWrapper(key)); } + + private static string PtrToStringUtf8(IntPtr ptr) + { + if(ptr == IntPtr.Zero) { + return ""; + } + + int len = 0; + while(System.Runtime.InteropServices.Marshal.ReadByte(ptr, len) != 0) { + len++; + } + + if(len == 0) { + return ""; + } + + byte[] array = new byte[len]; + System.Runtime.InteropServices.Marshal.Copy(ptr, array, 0, len); + return System.Text.Encoding.UTF8.GetString(array); + } public enum ConsoleNotificationType { @@ -252,4 +271,68 @@ namespace Mesen.GUI return null; } } + + public class UTF8Marshaler : ICustomMarshaler + { + static UTF8Marshaler _instance; + + public IntPtr MarshalManagedToNative(object managedObj) + { + if(managedObj == null) { + return IntPtr.Zero; + } + if(!(managedObj is string)) { + throw new MarshalDirectiveException("UTF8Marshaler must be used on a string."); + } + + // not null terminated + byte[] strbuf = Encoding.UTF8.GetBytes((string)managedObj); + IntPtr buffer = Marshal.AllocHGlobal(strbuf.Length + 1); + Marshal.Copy(strbuf, 0, buffer, strbuf.Length); + + // write the terminating null + Marshal.WriteByte(buffer + strbuf.Length, 0); + return buffer; + } + + public unsafe object MarshalNativeToManaged(IntPtr pNativeData) + { + byte* walk = (byte*)pNativeData; + + // find the end of the string + while(*walk != 0) { + walk++; + } + int length = (int)(walk - (byte*)pNativeData); + + // should not be null terminated + byte[] strbuf = new byte[length]; + // skip the trailing null + Marshal.Copy((IntPtr)pNativeData, strbuf, 0, length); + string data = Encoding.UTF8.GetString(strbuf); + return data; + } + + public void CleanUpNativeData(IntPtr pNativeData) + { + Marshal.FreeHGlobal(pNativeData); + } + + public void CleanUpManagedData(object managedObj) + { + } + + public int GetNativeDataSize() + { + return -1; + } + + public static ICustomMarshaler GetInstance(string cookie) + { + if(_instance == null) { + return _instance = new UTF8Marshaler(); + } + return _instance; + } + } } diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index c8f1a6dc..80b88d76 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -17,7 +17,7 @@ static SoundManager *_soundManager = nullptr; static vector> _inputDevices; static HWND _windowHandle = nullptr; static HWND _viewerHandle = nullptr; -static wstring _romFilename; +static string _returnString; typedef void (__stdcall *NotificationListenerCallback)(int); @@ -38,7 +38,7 @@ namespace InteropEmu { }; extern "C" { - DllExport void __stdcall InitializeEmu(wchar_t* homeFolder, HWND windowHandle, HWND dxViewerHandle) + DllExport void __stdcall InitializeEmu(char* homeFolder, HWND windowHandle, HWND dxViewerHandle) { FolderUtilities::SetHomeFolder(homeFolder); @@ -58,15 +58,19 @@ namespace InteropEmu { } } - DllExport void __stdcall LoadROM(wchar_t* filename) { Console::LoadROM(filename); } - DllExport void __stdcall AddKnowGameFolder(wchar_t* folder) { FolderUtilities::AddKnowGameFolder(folder); } + DllExport void __stdcall LoadROM(char* filename) { Console::LoadROM(filename); } + DllExport void __stdcall AddKnowGameFolder(char* folder) { FolderUtilities::AddKnowGameFolder(folder); } DllExport void __stdcall AddKeyMappings(uint32_t port, KeyMapping mapping) { _inputDevices[port]->AddKeyMappings(mapping); } DllExport void __stdcall ClearKeyMappings(uint32_t port) { _inputDevices[port]->ClearKeyMappings(); } DllExport uint32_t __stdcall GetPressedKey() { return ControlManager::GetPressedKey(); } - DllExport wchar_t* __stdcall GetKeyName(uint32_t keyCode) { return ControlManager::GetKeyName(keyCode); } - DllExport uint32_t __stdcall GetKeyCode(wchar_t* keyName) { return ControlManager::GetKeyCode(keyName); } + DllExport const char* __stdcall GetKeyName(uint32_t keyCode) + { + _returnString = ControlManager::GetKeyName(keyCode); + return _returnString.c_str(); + } + DllExport uint32_t __stdcall GetKeyCode(char* keyName) { return ControlManager::GetKeyCode(keyName); } DllExport void __stdcall Run() { @@ -83,10 +87,10 @@ namespace InteropEmu { Console::GetInstance()->Stop(); } } - DllExport const wchar_t* __stdcall GetROMPath() + DllExport const char* __stdcall GetROMPath() { - _romFilename = Console::GetROMPath(); - return _romFilename.c_str(); + _returnString = Console::GetROMPath(); + return _returnString.c_str(); } DllExport void __stdcall Reset() { Console::Reset(); } @@ -97,7 +101,7 @@ namespace InteropEmu { DllExport void __stdcall StopServer() { GameServer::StopServer(); } DllExport int __stdcall IsServerRunning() { return GameServer::Started(); } - DllExport void __stdcall Connect(char* host, uint16_t port, wchar_t* playerName, uint8_t* avatarData, uint32_t avatarSize) + DllExport void __stdcall Connect(char* host, uint16_t port, char* playerName, uint8_t* avatarData, uint32_t avatarSize) { shared_ptr connectionData(new ClientConnectionData( host, @@ -140,14 +144,14 @@ namespace InteropEmu { } DllExport void __stdcall UnregisterNotificationCallback(INotificationListener *listener) { MessageManager::UnregisterNotificationListener(listener); } - DllExport void __stdcall DisplayMessage(wchar_t* title, wchar_t* message) { MessageManager::DisplayMessage(title, message); } + DllExport void __stdcall DisplayMessage(char* title, char* message) { MessageManager::DisplayMessage(title, message); } DllExport void __stdcall SaveState(uint32_t stateIndex) { SaveStateManager::SaveState(stateIndex); } DllExport uint32_t __stdcall LoadState(uint32_t stateIndex) { return SaveStateManager::LoadState(stateIndex); } DllExport int64_t __stdcall GetStateInfo(uint32_t stateIndex) { return SaveStateManager::GetStateInfo(stateIndex); } - DllExport void __stdcall MoviePlay(wchar_t* filename) { Movie::Play(filename); } - DllExport void __stdcall MovieRecord(wchar_t* filename, int reset) { Movie::Record(filename, reset != 0); } + DllExport void __stdcall MoviePlay(char* filename) { Movie::Play(filename); } + DllExport void __stdcall MovieRecord(char* filename, int reset) { Movie::Record(filename, reset != 0); } DllExport void __stdcall MovieStop() { Movie::Stop(); } DllExport int __stdcall MoviePlaying() { return Movie::Playing(); } DllExport int __stdcall MovieRecording() { return Movie::Recording(); } diff --git a/InteropDLL/InteropDLL.vcxproj b/InteropDLL/InteropDLL.vcxproj index 59ed860c..37813e44 100644 --- a/InteropDLL/InteropDLL.vcxproj +++ b/InteropDLL/InteropDLL.vcxproj @@ -137,6 +137,8 @@ Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;INTEROPDLL_EXPORTS;%(PreprocessorDefinitions) Cdecl + + Windows @@ -151,6 +153,8 @@ Disabled WIN32;_DEBUG;_WINDOWS;_USRDLL;INTEROPDLL_EXPORTS;%(PreprocessorDefinitions) Cdecl + + Windows @@ -166,6 +170,8 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;INTEROPDLL_EXPORTS;%(PreprocessorDefinitions) + + Windows @@ -183,6 +189,8 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;INTEROPDLL_EXPORTS;%(PreprocessorDefinitions) + + Windows @@ -200,6 +208,8 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;INTEROPDLL_EXPORTS;%(PreprocessorDefinitions) + + Windows @@ -217,6 +227,8 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;INTEROPDLL_EXPORTS;%(PreprocessorDefinitions) + + Windows diff --git a/PGOHelper/PGOHelper.vcxproj b/PGOHelper/PGOHelper.vcxproj index c5a0bb64..a3b828e8 100644 --- a/PGOHelper/PGOHelper.vcxproj +++ b/PGOHelper/PGOHelper.vcxproj @@ -131,6 +131,8 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + Console @@ -144,6 +146,8 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + Console @@ -159,6 +163,8 @@ true true WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + Console @@ -176,6 +182,8 @@ true true WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + Console @@ -193,6 +201,8 @@ true true WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + Console @@ -210,6 +220,8 @@ true true WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + Console diff --git a/Utilities/CRC32.h b/Utilities/CRC32.h index 6ac2f683..199e1c99 100644 --- a/Utilities/CRC32.h +++ b/Utilities/CRC32.h @@ -91,7 +91,7 @@ public: return crc._crc; } - static uint32_t GetCRC(wstring filename) + static uint32_t GetCRC(string filename) { uint32_t crc = 0; diff --git a/Utilities/FolderUtilities.cpp b/Utilities/FolderUtilities.cpp index d7534fb8..2f8bacb1 100644 --- a/Utilities/FolderUtilities.cpp +++ b/Utilities/FolderUtilities.cpp @@ -2,17 +2,18 @@ #include #include #include "FolderUtilities.h" +#include "UTF8Util.h" -wstring FolderUtilities::_homeFolder = L""; -vector FolderUtilities::_gameFolders = vector(); +string FolderUtilities::_homeFolder = ""; +vector FolderUtilities::_gameFolders = vector(); -void FolderUtilities::SetHomeFolder(wstring homeFolder) +void FolderUtilities::SetHomeFolder(string homeFolder) { _homeFolder = homeFolder; - CreateDirectory(homeFolder.c_str(), nullptr); + CreateFolder(homeFolder); } -wstring FolderUtilities::GetHomeFolder() +string FolderUtilities::GetHomeFolder() { if(_homeFolder.size() == 0) { throw std::exception("Home folder not specified"); @@ -20,10 +21,10 @@ wstring FolderUtilities::GetHomeFolder() return _homeFolder; } -void FolderUtilities::AddKnowGameFolder(wstring gameFolder) +void FolderUtilities::AddKnowGameFolder(string gameFolder) { bool alreadyExists = false; - for(wstring folder : _gameFolders) { + for(string folder : _gameFolders) { if(folder.compare(gameFolder) == 0) { alreadyExists = true; break; @@ -35,53 +36,59 @@ void FolderUtilities::AddKnowGameFolder(wstring gameFolder) } } -vector FolderUtilities::GetKnowGameFolders() +vector FolderUtilities::GetKnowGameFolders() { return _gameFolders; } -wstring FolderUtilities::GetSaveFolder() +string FolderUtilities::GetSaveFolder() { - wstring folder = CombinePath(GetHomeFolder(), L"Saves\\"); - CreateDirectory(folder.c_str(), nullptr); + string folder = CombinePath(GetHomeFolder(), "Saves\\"); + CreateFolder(folder); return folder; } -wstring FolderUtilities::GetSaveStateFolder() +string FolderUtilities::GetSaveStateFolder() { - wstring folder = CombinePath(GetHomeFolder(), L"SaveStates\\"); - CreateDirectory(folder.c_str(), nullptr); + string folder = CombinePath(GetHomeFolder(), "SaveStates\\"); + CreateFolder(folder); return folder; } -wstring FolderUtilities::GetMovieFolder() +string FolderUtilities::GetMovieFolder() { - wstring folder = CombinePath(GetHomeFolder(), + L"Movies\\"); - CreateDirectory(folder.c_str(), nullptr); + string folder = CombinePath(GetHomeFolder(), + "Movies\\"); + CreateFolder(folder); return folder; } -wstring FolderUtilities::GetScreenshotFolder() +string FolderUtilities::GetScreenshotFolder() { - wstring folder = CombinePath(GetHomeFolder(), L"Screenshots\\"); - CreateDirectory(folder.c_str(), nullptr); + string folder = CombinePath(GetHomeFolder(), "Screenshots\\"); + CreateFolder(folder); return folder; } -vector FolderUtilities::GetFolders(wstring rootFolder) +void FolderUtilities::CreateFolder(string folder) { + CreateDirectory(utf8::utf8::decode(folder).c_str(), nullptr); +} + +vector FolderUtilities::GetFolders(string rootFolder) +{ + vector folders; +#ifdef _WIN32 HANDLE hFind; WIN32_FIND_DATA data; - vector folders; - - hFind = FindFirstFile((rootFolder + L"*").c_str(), &data); + hFind = FindFirstFile(utf8::utf8::decode(rootFolder + "*").c_str(), &data); if(hFind != INVALID_HANDLE_VALUE) { do { - if(data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY && wcscmp(data.cFileName, L".") != 0 && wcscmp(data.cFileName, L"..") != 0) { - wstring subfolder = rootFolder + data.cFileName + L"\\"; + string filename = utf8::utf8::encode(data.cFileName); + if(data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY && filename.compare(".") != 0 && filename.compare("..") != 0) { + string subfolder = rootFolder + filename + "\\"; folders.push_back(subfolder); - for(wstring folderName : GetFolders(subfolder.c_str())) { + for(string folderName : GetFolders(subfolder.c_str())) { folders.push_back(folderName); } } @@ -89,34 +96,34 @@ vector FolderUtilities::GetFolders(wstring rootFolder) while(FindNextFile(hFind, &data)); FindClose(hFind); } - +#endif return folders; } -vector FolderUtilities::GetFilesInFolder(wstring rootFolder, wstring mask, bool recursive) +vector FolderUtilities::GetFilesInFolder(string rootFolder, string mask, bool recursive) { HANDLE hFind; WIN32_FIND_DATA data; - vector folders; - vector files; + vector folders; + vector files; if(rootFolder[rootFolder.size() - 1] != '/' && rootFolder[rootFolder.size() - 1] != '\\') { - rootFolder += L"/"; + rootFolder += "/"; } folders.push_back(rootFolder); if(recursive) { - for(wstring subFolder : GetFolders(rootFolder)) { + for(string subFolder : GetFolders(rootFolder)) { folders.push_back(subFolder); } } - for(wstring folder : folders) { - hFind = FindFirstFile((folder + mask).c_str(), &data); + for(string folder : folders) { + hFind = FindFirstFile(utf8::utf8::decode(folder + mask).c_str(), &data); if(hFind != INVALID_HANDLE_VALUE) { do { - files.push_back(folder + data.cFileName); + files.push_back(folder + utf8::utf8::encode(data.cFileName)); } while(FindNextFile(hFind, &data)); FindClose(hFind); } @@ -125,28 +132,28 @@ vector FolderUtilities::GetFilesInFolder(wstring rootFolder, wstring ma return files; } -wstring FolderUtilities::GetFilename(wstring filepath, bool includeExtension) +string FolderUtilities::GetFilename(string filepath, bool includeExtension) { - size_t index = filepath.find_last_of(L"/\\"); - wstring filename = (index == std::string::basic_string::npos) ? filepath : filepath.substr(index + 1); + size_t index = filepath.find_last_of("/\\"); + string filename = (index == std::string::basic_string::npos) ? filepath : filepath.substr(index + 1); if(!includeExtension) { - filename = filename.substr(0, filename.find_last_of(L".")); + filename = filename.substr(0, filename.find_last_of(".")); } return filename; } -wstring FolderUtilities::GetFolderName(wstring filepath) +string FolderUtilities::GetFolderName(string filepath) { - size_t index = filepath.find_last_of(L"/\\"); + size_t index = filepath.find_last_of("/\\"); return filepath.substr(0, index); } -wstring FolderUtilities::CombinePath(wstring folder, wstring filename) +string FolderUtilities::CombinePath(string folder, string filename) { #ifdef WIN32 - wstring separator = L"\\"; + string separator = "\\"; #else - wstring separator = L"/"; + string separator = "/"; #endif if(folder.find_last_of(separator) != folder.length() - 1) { @@ -156,9 +163,9 @@ wstring FolderUtilities::CombinePath(wstring folder, wstring filename) return folder + filename; } -int64_t FolderUtilities::GetFileModificationTime(wstring filepath) +int64_t FolderUtilities::GetFileModificationTime(string filepath) { WIN32_FILE_ATTRIBUTE_DATA fileAttrData = {0}; - GetFileAttributesEx(filepath.c_str(), GetFileExInfoStandard, &fileAttrData); + GetFileAttributesEx(utf8::utf8::decode(filepath).c_str(), GetFileExInfoStandard, &fileAttrData); return ((int64_t)fileAttrData.ftLastWriteTime.dwHighDateTime << 32) | (int64_t)fileAttrData.ftLastWriteTime.dwLowDateTime; } \ No newline at end of file diff --git a/Utilities/FolderUtilities.h b/Utilities/FolderUtilities.h index 906ba30b..5a73aa80 100644 --- a/Utilities/FolderUtilities.h +++ b/Utilities/FolderUtilities.h @@ -5,28 +5,30 @@ class FolderUtilities { private: - static wstring _homeFolder; - static vector _gameFolders; + static string _homeFolder; + static vector _gameFolders; public: - static void SetHomeFolder(wstring homeFolder); - static wstring GetHomeFolder(); + static void SetHomeFolder(string homeFolder); + static string GetHomeFolder(); - static void AddKnowGameFolder(wstring gameFolder); - static vector GetKnowGameFolders(); + static void AddKnowGameFolder(string gameFolder); + static vector GetKnowGameFolders(); - static wstring GetSaveFolder(); - static wstring GetSaveStateFolder(); - static wstring GetMovieFolder(); - static wstring GetScreenshotFolder(); + static string GetSaveFolder(); + static string GetSaveStateFolder(); + static string GetMovieFolder(); + static string GetScreenshotFolder(); - static vector GetFolders(wstring rootFolder); - static vector GetFilesInFolder(wstring rootFolder, wstring mask, bool recursive); + static vector GetFolders(string rootFolder); + static vector GetFilesInFolder(string rootFolder, string mask, bool recursive); - static wstring GetFilename(wstring filepath, bool includeExtension); - static wstring GetFolderName(wstring filepath); + static string GetFilename(string filepath, bool includeExtension); + static string GetFolderName(string filepath); - static int64_t GetFileModificationTime(wstring filepath); + static void CreateFolder(string folder); - static wstring CombinePath(wstring folder, wstring filename); + static int64_t GetFileModificationTime(string filepath); + + static string CombinePath(string folder, string filename); }; \ No newline at end of file diff --git a/Utilities/PNGWriter.h b/Utilities/PNGWriter.h index 4aaf0619..27ee9b66 100644 --- a/Utilities/PNGWriter.h +++ b/Utilities/PNGWriter.h @@ -1,12 +1,11 @@ #pragma once #include "stdafx.h" #include "miniz.h" -using std::ofstream; class PNGWriter { public: - static bool WritePNG(wstring filename, uint8_t* buffer, uint32_t xSize, uint32_t ySize, uint32_t bitsPerPixel = 32) + static bool WritePNG(string filename, uint8_t* buffer, uint32_t xSize, uint32_t ySize, uint32_t bitsPerPixel = 32) { size_t pngSize = 0; void *pngData = tdefl_write_image_to_png_file_in_memory_ex(buffer, xSize, ySize, bitsPerPixel/8, &pngSize, MZ_DEFAULT_LEVEL, MZ_FALSE); diff --git a/Utilities/UPnPPortMapper.h b/Utilities/UPnPPortMapper.h index fd2836e4..a926da55 100644 --- a/Utilities/UPnPPortMapper.h +++ b/Utilities/UPnPPortMapper.h @@ -5,6 +5,8 @@ #include #include +using std::wstring; + enum class IPProtocol { TCP = 0, diff --git a/Utilities/UTF8Util.h b/Utilities/UTF8Util.h new file mode 100644 index 00000000..57a4e96e --- /dev/null +++ b/Utilities/UTF8Util.h @@ -0,0 +1,70 @@ +#pragma once + +#include +#ifdef _MSC_VER +#define WIN32_LEAN_AND_MEAN +#include +#endif + +namespace utf8 { +#ifdef _WIN32 + class utf8 + { + public: + static std::wstring decode(const std::string &str) + { + if(str.empty()) return std::wstring(); + int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); + std::wstring wstrTo(size_needed, 0); + MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); + return wstrTo; + } + + static std::string encode(const std::wstring &wstr) + { + if(wstr.empty()) return std::string(); + int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); + std::string strTo(size_needed, 0); + WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); + return strTo; + } + }; + + class ifstream : public std::ifstream + { + public: + ifstream(const std::string& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = (int)ios_base::_Openprot) : std::ifstream(utf8::decode(_Str), _Mode, _Prot) + { + } + + ifstream() : std::ifstream() + { + } + + void open(const std::string& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = (int)ios_base::_Openprot) + { + std::ifstream::open(utf8::decode(_Str), _Mode, _Prot); + } + }; + + class ofstream : public std::ofstream + { + public: + ofstream(const std::string& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = (int)ios_base::_Openprot) : std::ofstream(utf8::decode(_Str), _Mode, _Prot) + { + } + + ofstream() : std::ofstream() + { + } + + void open(const std::string& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = (int)ios_base::_Openprot) + { + std::ofstream::open(utf8::decode(_Str), _Mode, _Prot); + } + }; +#else + using std::ifstream; + using std::ofstream; +#endif +} \ No newline at end of file diff --git a/Utilities/Utilities.vcxproj b/Utilities/Utilities.vcxproj index 7da825cf..9d8208f1 100644 --- a/Utilities/Utilities.vcxproj +++ b/Utilities/Utilities.vcxproj @@ -126,6 +126,8 @@ WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) true Cdecl + + Windows @@ -140,6 +142,8 @@ WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) true Cdecl + + Windows @@ -155,6 +159,8 @@ true WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true + + Windows @@ -172,6 +178,8 @@ true WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true + + Windows @@ -189,6 +197,8 @@ true WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true + + Windows @@ -206,6 +216,8 @@ true WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true + + Windows @@ -225,6 +237,7 @@ + diff --git a/Utilities/Utilities.vcxproj.filters b/Utilities/Utilities.vcxproj.filters index f4ce66a5..7dc6ffa8 100644 --- a/Utilities/Utilities.vcxproj.filters +++ b/Utilities/Utilities.vcxproj.filters @@ -44,6 +44,9 @@ Header Files + + Header Files + diff --git a/Utilities/stdafx.h b/Utilities/stdafx.h index f91fc559..eeb712f4 100644 --- a/Utilities/stdafx.h +++ b/Utilities/stdafx.h @@ -1,23 +1,18 @@ #pragma once -#include - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include - #include #include #include #include -#include #include #include #include +#include "UTF8Util.h" + using std::shared_ptr; -using std::ifstream; +using utf8::ifstream; using std::string; -using std::wstring; using std::vector; using std::atomic; using std::atomic_flag; \ No newline at end of file diff --git a/Windows/Renderer.cpp b/Windows/Renderer.cpp index 2b8dd9c7..e37e9afe 100644 --- a/Windows/Renderer.cpp +++ b/Windows/Renderer.cpp @@ -1,12 +1,13 @@ #include "stdafx.h" #include "Renderer.h" -#include "DirectXTK\SpriteBatch.h" -#include "DirectXTK\SpriteFont.h" -#include "DirectXTK\DDSTextureLoader.h" -#include "DirectXTK\WICTextureLoader.h" -#include "..\Core\PPU.h" -#include "..\Core\Console.h" -#include "..\Core\MessageManager.h" +#include "DirectXTK/SpriteBatch.h" +#include "DirectXTK/SpriteFont.h" +#include "DirectXTK/DDSTextureLoader.h" +#include "DirectXTK/WICTextureLoader.h" +#include "../Core/PPU.h" +#include "../Core/Console.h" +#include "../Core/MessageManager.h" +#include "../Utilities/UTF8Util.h" using namespace DirectX; @@ -328,9 +329,9 @@ namespace NES return shaderResourceView; } - void Renderer::DisplayMessage(wstring title, wstring message) + void Renderer::DisplayMessage(string title, string message) { - shared_ptr toast(new ToastInfo(title, message, 4000, L"Resources\\MesenIcon.bmp")); + shared_ptr toast(new ToastInfo(title, message, 4000, "Resources\\MesenIcon.bmp")); DisplayToast(toast); } @@ -339,24 +340,25 @@ namespace NES _toasts.push_front(toast); } - void Renderer::DrawOutlinedString(wstring message, float x, float y, DirectX::FXMVECTOR color, float scale) + void Renderer::DrawOutlinedString(string message, float x, float y, DirectX::FXMVECTOR color, float scale) { SpriteBatch* spritebatch = _spriteBatch.get(); - const wchar_t* msg = message.c_str(); + std::wstring textStr = utf8::utf8::decode(message); + const wchar_t *text = textStr.c_str(); for(uint8_t offsetX = 2; offsetX > 0; offsetX--) { for(uint8_t offsetY = 2; offsetY > 0; offsetY--) { - _font->DrawString(spritebatch, msg, XMFLOAT2(x + offsetX, y + offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); - _font->DrawString(spritebatch, msg, XMFLOAT2(x - offsetX, y + offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); - _font->DrawString(spritebatch, msg, XMFLOAT2(x + offsetX, y - offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); - _font->DrawString(spritebatch, msg, XMFLOAT2(x - offsetX, y - offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); - _font->DrawString(spritebatch, msg, XMFLOAT2(x + offsetX, y), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); - _font->DrawString(spritebatch, msg, XMFLOAT2(x - offsetX, y), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); - _font->DrawString(spritebatch, msg, XMFLOAT2(x, y + offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); - _font->DrawString(spritebatch, msg, XMFLOAT2(x, y - offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x + offsetX, y + offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x - offsetX, y + offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x + offsetX, y - offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x - offsetX, y - offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x + offsetX, y), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x - offsetX, y), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x, y + offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x, y - offsetY), Colors::Black, 0.0f, XMFLOAT2(0, 0), scale); } } - _font->DrawString(spritebatch, msg, XMFLOAT2(x, y), color, 0.0f, XMFLOAT2(0, 0), scale); + _font->DrawString(spritebatch, text, XMFLOAT2(x, y), color, 0.0f, XMFLOAT2(0, 0), scale); } void Renderer::DrawNESScreen() @@ -411,7 +413,7 @@ namespace NES _spriteBatch->Draw(shaderResourceView, destRect); // , position, &sourceRect, Colors::White, 0.0f, position, 4.0f); shaderResourceView->Release(); - DrawOutlinedString(L"PAUSED", (float)_hdScreenWidth / 2 - 145, (float)_hdScreenHeight / 2 - 47, Colors::AntiqueWhite, 4.5f); + DrawOutlinedString("PAUSED", (float)_hdScreenWidth / 2 - 145, (float)_hdScreenHeight / 2 - 47, Colors::AntiqueWhite, 4.5f); } void Renderer::Render() @@ -437,7 +439,7 @@ namespace NES } else { //Draw FPS counter if(CheckFlag(UIFlags::ShowFPS)) { - wstring fpsString = wstring(L"FPS: ") + std::to_wstring(Console::GetFPS()); + string fpsString = string("FPS: ") + std::to_string(Console::GetFPS()); DrawOutlinedString(fpsString, 256 * 4 - 80, 13, Colors::AntiqueWhite, 1.0f); } } @@ -471,8 +473,10 @@ namespace NES } } - wstring Renderer::WrapText(wstring text, SpriteFont* font, float maxLineWidth) + std::wstring Renderer::WrapText(string utf8Text, SpriteFont* font, float maxLineWidth) { + using std::wstring; + wstring text = utf8::utf8::decode(utf8Text); wstring wrappedText; list words; wstring currentWord; @@ -493,6 +497,11 @@ namespace NES float spaceWidth = font->MeasureString(L" ").m128_f32[0]; float lineWidth = 0.0f; for(wstring word : words) { + for(unsigned int i = 0; i < word.size(); i++) { + if(!font->ContainsCharacter(word[i])) { + word[i] = L'?'; + } + } float wordWidth = font->MeasureString(word.c_str()).m128_f32[0]; if(lineWidth + wordWidth < maxLineWidth) { @@ -549,7 +558,7 @@ namespace NES _frameLock.Release(); } - void Renderer::TakeScreenshot(wstring romFilename) + void Renderer::TakeScreenshot(string romFilename) { uint32_t* frameBuffer = new uint32_t[256 * 240]; @@ -563,14 +572,14 @@ namespace NES } int counter = 0; - wstring baseFilename = FolderUtilities::GetScreenshotFolder() + FolderUtilities::GetFilename(romFilename, false); - wstring ssFilename; + string baseFilename = FolderUtilities::GetScreenshotFolder() + FolderUtilities::GetFilename(romFilename, false); + string ssFilename; while(true) { - wstring counterStr = std::to_wstring(counter); + string counterStr = std::to_string(counter); while(counterStr.length() < 3) { - counterStr = L"0" + counterStr; + counterStr = "0" + counterStr; } - ssFilename = baseFilename + L"_" + counterStr + L".png"; + ssFilename = baseFilename + "_" + counterStr + ".png"; ifstream file(ssFilename, ios::in); if(file) { file.close(); @@ -581,7 +590,7 @@ namespace NES } PNGWriter::WritePNG(ssFilename, (uint8_t*)frameBuffer, 256, 240); - MessageManager::DisplayMessage(L"Screenshot saved", FolderUtilities::GetFilename(ssFilename, true)); + MessageManager::DisplayMessage("Screenshot saved", FolderUtilities::GetFilename(ssFilename, true)); } } \ No newline at end of file diff --git a/Windows/Renderer.h b/Windows/Renderer.h index 21215b0c..a0bd4f91 100644 --- a/Windows/Renderer.h +++ b/Windows/Renderer.h @@ -78,22 +78,20 @@ namespace NES { void DrawNESScreen(); void DrawPauseScreen(); - wstring WrapText(wstring text, SpriteFont* font, float maxLineWidth); - void DrawOutlinedString(wstring message, float x, float y, DirectX::FXMVECTOR color, float scale); + std::wstring WrapText(string text, SpriteFont* font, float maxLineWidth); + void DrawOutlinedString(string message, float x, float y, DirectX::FXMVECTOR color, float scale); void DrawToasts(); void DrawToast(shared_ptr toast, int posIndex); void RemoveOldToasts(); - - //HRESULT CompileShader(wstring filename, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut); - + public: Renderer(HWND hWnd); ~Renderer(); void Render(); - void DisplayMessage(wstring title, wstring message); + void DisplayMessage(string title, string message); void SetFlags(uint32_t flags) { @@ -113,6 +111,6 @@ namespace NES { void UpdateFrame(uint8_t* frameBuffer); void DisplayToast(shared_ptr toast); - void TakeScreenshot(wstring romFilename); + void TakeScreenshot(string romFilename); }; } \ No newline at end of file diff --git a/Windows/WindowsKeyManager.cpp b/Windows/WindowsKeyManager.cpp index 91b4e4d4..857a5cb3 100644 --- a/Windows/WindowsKeyManager.cpp +++ b/Windows/WindowsKeyManager.cpp @@ -56,7 +56,7 @@ uint32_t WindowsKeyManager::GetPressedKey() return 0; } -wchar_t* WindowsKeyManager::GetKeyName(uint32_t key) +string WindowsKeyManager::GetKeyName(uint32_t key) { for(KeyDefinition keyDef : _keyDefinitions) { if(keyDef.keyCode == key) { @@ -66,11 +66,10 @@ wchar_t* WindowsKeyManager::GetKeyName(uint32_t key) return nullptr; } -uint32_t WindowsKeyManager::GetKeyCode(wchar_t* keyName) +uint32_t WindowsKeyManager::GetKeyCode(string keyName) { - wstring name(keyName); for(KeyDefinition keyDef : _keyDefinitions) { - if(name.compare(keyDef.description) == 0) { + if(keyName.compare(keyDef.description) == 0) { return keyDef.keyCode; } } diff --git a/Windows/WindowsKeyManager.h b/Windows/WindowsKeyManager.h index feaba44f..56866176 100644 --- a/Windows/WindowsKeyManager.h +++ b/Windows/WindowsKeyManager.h @@ -5,222 +5,222 @@ #include "GamePad.h" struct KeyDefinition { - char* name; + string name; uint32_t keyCode; - wchar_t* description; + string description; }; const KeyDefinition _keyDefinitions[] = { - //{ "VK_LBUTTON", 0x01, L"Left mouse button" }, - //{ "VK_RBUTTON", 0x02, L"Right mouse button" }, - { "VK_CANCEL", 0x03, L"Control-break processing" }, - //{ "VK_MBUTTON", 0x04, L"Middle mouse button (three-button mouse)" }, - //{ "VK_XBUTTON1", 0x05, L"X1 mouse button" }, - //{ "VK_XBUTTON2", 0x06, L"X2 mouse button" }, - { "-", 0x07, L"Undefined" }, - { "VK_BACK", 0x08, L"Backspace" }, - { "VK_TAB", 0x09, L"Tab" }, - //{ "-", 0x0A - 0B, L"Reserved" }, - { "VK_CLEAR", 0x0C, L"Clear" }, - { "VK_RETURN", 0x0D, L"Enter" }, - //{ "-", 0x0E - 0F, L"Undefined" }, - { "VK_SHIFT", 0x10, L"Shift" }, - { "VK_CONTROL", 0x11, L"Ctrl" }, - { "VK_MENU", 0x12, L"Alt" }, - { "VK_PAUSE", 0x13, L"Pause" }, - { "VK_CAPITAL", 0x14, L"Caps Lock" }, - { "VK_KANA", 0x15, L"IME Kana mode" }, - { "VK_HANGUEL", 0x15, L"IME Hanguel mode" }, - { "VK_HANGUL", 0x15, L"IME Hangul mode" }, - //{ "-", 0x16, L"Undefined" }, - { "VK_JUNJA", 0x17, L"IME Junja mode" }, - { "VK_FINAL", 0x18, L"IME final mode" }, - { "VK_HANJA", 0x19, L"IME Hanja mode" }, - { "VK_KANJI", 0x19, L"IME Kanji mode" }, - //{ "-", 0x1A, L"Undefined" }, - { "VK_ESCAPE", 0x1B, L"Esc" }, - { "VK_CONVERT", 0x1C, L"IME convert" }, - { "VK_NONCONVERT", 0x1D, L"IME nonconvert" }, - { "VK_ACCEPT", 0x1E, L"IME accept" }, - { "VK_MODECHANGE", 0x1F, L"IME mode change request" }, - { "VK_SPACE", 0x20, L"Spacebar" }, - { "VK_PRIOR", 0x21, L"Page Up" }, - { "VK_NEXT", 0x22, L"Page Down" }, - { "VK_END", 0x23, L"End" }, - { "VK_HOME", 0x24, L"Home" }, - { "VK_LEFT", 0x25, L"Left Arrow" }, - { "VK_UP", 0x26, L"Up Arrow" }, - { "VK_RIGHT", 0x27, L"Right Arrow" }, - { "VK_DOWN", 0x28, L"Down Arrow" }, - { "VK_SELECT", 0x29, L"Select" }, - { "VK_PRINT", 0x2A, L"Print" }, - { "VK_EXECUTE", 0x2B, L"Execute" }, - { "VK_SNAPSHOT", 0x2C, L"Print Screen" }, - { "VK_INSERT", 0x2D, L"Ins" }, - { "VK_DELETE", 0x2E, L"Del" }, - { "VK_HELP", 0x2F, L"Help" }, - { "0", 0x30, L"0" }, - { "1", 0x31, L"1" }, - { "2", 0x32, L"2" }, - { "3", 0x33, L"3" }, - { "4", 0x34, L"4" }, - { "5", 0x35, L"5" }, - { "6", 0x36, L"6" }, - { "7", 0x37, L"7" }, - { "8", 0x38, L"8" }, - { "9", 0x39, L"9" }, - //{ "undefined", 0x3A - 40, L"undefined" }, - { "A", 0x41, L"A" }, - { "B", 0x42, L"B" }, - { "C", 0x43, L"C" }, - { "D", 0x44, L"D" }, - { "E", 0x45, L"E" }, - { "F", 0x46, L"F" }, - { "G", 0x47, L"G" }, - { "H", 0x48, L"H" }, - { "I", 0x49, L"I" }, - { "J", 0x4A, L"J" }, - { "K", 0x4B, L"K" }, - { "L", 0x4C, L"L" }, - { "M", 0x4D, L"M" }, - { "N", 0x4E, L"N" }, - { "O", 0x4F, L"O" }, - { "P", 0x50, L"P" }, - { "Q", 0x51, L"Q" }, - { "R", 0x52, L"R" }, - { "S", 0x53, L"S" }, - { "T", 0x54, L"T" }, - { "U", 0x55, L"U" }, - { "V", 0x56, L"V" }, - { "W", 0x57, L"W" }, - { "X", 0x58, L"X" }, - { "Y", 0x59, L"Y" }, - { "Z", 0x5A, L"Z" }, - { "VK_LWIN", 0x5B, L"Left Windows" }, - { "VK_RWIN", 0x5C, L"Right Windows" }, - { "VK_APPS", 0x5D, L"Applications Key" }, - //{ "-", 0x5E, L"Reserved" }, - { "VK_SLEEP", 0x5F, L"Computer Sleep" }, - { "VK_NUMPAD0", 0x60, L"Keypad 0" }, - { "VK_NUMPAD1", 0x61, L"Keypad 1" }, - { "VK_NUMPAD2", 0x62, L"Keypad 2" }, - { "VK_NUMPAD3", 0x63, L"Keypad 3" }, - { "VK_NUMPAD4", 0x64, L"Keypad 4" }, - { "VK_NUMPAD5", 0x65, L"Keypad 5" }, - { "VK_NUMPAD6", 0x66, L"Keypad 6" }, - { "VK_NUMPAD7", 0x67, L"Keypad 7" }, - { "VK_NUMPAD8", 0x68, L"Keypad 8" }, - { "VK_NUMPAD9", 0x69, L"Keypad 9" }, - { "VK_MULTIPLY", 0x6A, L"Multiply" }, - { "VK_ADD", 0x6B, L"Add" }, - { "VK_SEPARATOR", 0x6C, L"Separator" }, - { "VK_SUBTRACT", 0x6D, L"Subtract" }, - { "VK_DECIMAL", 0x6E, L"Decimal" }, - { "VK_DIVIDE", 0x6F, L"Divide" }, - { "VK_F1", 0x70, L"F1" }, - { "VK_F2", 0x71, L"F2" }, - { "VK_F3", 0x72, L"F3" }, - { "VK_F4", 0x73, L"F4" }, - { "VK_F5", 0x74, L"F5" }, - { "VK_F6", 0x75, L"F6" }, - { "VK_F7", 0x76, L"F7" }, - { "VK_F8", 0x77, L"F8" }, - { "VK_F9", 0x78, L"F9" }, - { "VK_F10", 0x79, L"F10" }, - { "VK_F11", 0x7A, L"F11" }, - { "VK_F12", 0x7B, L"F12" }, - { "VK_F13", 0x7C, L"F13" }, - { "VK_F14", 0x7D, L"F14" }, - { "VK_F15", 0x7E, L"F15" }, - { "VK_F16", 0x7F, L"F16" }, - { "VK_F17", 0x80, L"F17" }, - { "VK_F18", 0x81, L"F18" }, - { "VK_F19", 0x82, L"F19" }, - { "VK_F20", 0x83, L"F20" }, - { "VK_F21", 0x84, L"F21" }, - { "VK_F22", 0x85, L"F22" }, - { "VK_F23", 0x86, L"F23" }, - { "VK_F24", 0x87, L"F24" }, - //{ "-", 0x88 - 8F, L"Unassigned" }, - { "VK_NUMLOCK", 0x90, L"Num Lock" }, - { "VK_SCROLL", 0x91, L"Scroll Lock" }, + //{ "VK_LBUTTON", 0x01, "Left mouse button" }, + //{ "VK_RBUTTON", 0x02, "Right mouse button" }, + { "VK_CANCEL", 0x03, "Control-break processing" }, + //{ "VK_MBUTTON", 0x04, "Middle mouse button (three-button mouse)" }, + //{ "VK_XBUTTON1", 0x05, "X1 mouse button" }, + //{ "VK_XBUTTON2", 0x06, "X2 mouse button" }, + { "-", 0x07, "Undefined" }, + { "VK_BACK", 0x08, "Backspace" }, + { "VK_TAB", 0x09, "Tab" }, + //{ "-", 0x0A - 0B, "Reserved" }, + { "VK_CLEAR", 0x0C, "Clear" }, + { "VK_RETURN", 0x0D, "Enter" }, + //{ "-", 0x0E - 0F, "Undefined" }, + { "VK_SHIFT", 0x10, "Shift" }, + { "VK_CONTROL", 0x11, "Ctrl" }, + { "VK_MENU", 0x12, "Alt" }, + { "VK_PAUSE", 0x13, "Pause" }, + { "VK_CAPITAL", 0x14, "Caps Lock" }, + { "VK_KANA", 0x15, "IME Kana mode" }, + { "VK_HANGUEL", 0x15, "IME Hanguel mode" }, + { "VK_HANGUL", 0x15, "IME Hangul mode" }, + //{ "-", 0x16, "Undefined" }, + { "VK_JUNJA", 0x17, "IME Junja mode" }, + { "VK_FINAL", 0x18, "IME final mode" }, + { "VK_HANJA", 0x19, "IME Hanja mode" }, + { "VK_KANJI", 0x19, "IME Kanji mode" }, + //{ "-", 0x1A, "Undefined" }, + { "VK_ESCAPE", 0x1B, "Esc" }, + { "VK_CONVERT", 0x1C, "IME convert" }, + { "VK_NONCONVERT", 0x1D, "IME nonconvert" }, + { "VK_ACCEPT", 0x1E, "IME accept" }, + { "VK_MODECHANGE", 0x1F, "IME mode change request" }, + { "VK_SPACE", 0x20, "Spacebar" }, + { "VK_PRIOR", 0x21, "Page Up" }, + { "VK_NEXT", 0x22, "Page Down" }, + { "VK_END", 0x23, "End" }, + { "VK_HOME", 0x24, "Home" }, + { "VK_LEFT", 0x25, "Left Arrow" }, + { "VK_UP", 0x26, "Up Arrow" }, + { "VK_RIGHT", 0x27, "Right Arrow" }, + { "VK_DOWN", 0x28, "Down Arrow" }, + { "VK_SELECT", 0x29, "Select" }, + { "VK_PRINT", 0x2A, "Print" }, + { "VK_EXECUTE", 0x2B, "Execute" }, + { "VK_SNAPSHOT", 0x2C, "Print Screen" }, + { "VK_INSERT", 0x2D, "Ins" }, + { "VK_DELETE", 0x2E, "Del" }, + { "VK_HELP", 0x2F, "Help" }, + { "0", 0x30, "0" }, + { "1", 0x31, "1" }, + { "2", 0x32, "2" }, + { "3", 0x33, "3" }, + { "4", 0x34, "4" }, + { "5", 0x35, "5" }, + { "6", 0x36, "6" }, + { "7", 0x37, "7" }, + { "8", 0x38, "8" }, + { "9", 0x39, "9" }, + //{ "undefined", 0x3A - 40, "undefined" }, + { "A", 0x41, "A" }, + { "B", 0x42, "B" }, + { "C", 0x43, "C" }, + { "D", 0x44, "D" }, + { "E", 0x45, "E" }, + { "F", 0x46, "F" }, + { "G", 0x47, "G" }, + { "H", 0x48, "H" }, + { "I", 0x49, "I" }, + { "J", 0x4A, "J" }, + { "K", 0x4B, "K" }, + { "L", 0x4C, "L" }, + { "M", 0x4D, "M" }, + { "N", 0x4E, "N" }, + { "O", 0x4F, "O" }, + { "P", 0x50, "P" }, + { "Q", 0x51, "Q" }, + { "R", 0x52, "R" }, + { "S", 0x53, "S" }, + { "T", 0x54, "T" }, + { "U", 0x55, "U" }, + { "V", 0x56, "V" }, + { "W", 0x57, "W" }, + { "X", 0x58, "X" }, + { "Y", 0x59, "Y" }, + { "Z", 0x5A, "Z" }, + { "VK_LWIN", 0x5B, "Left Windows" }, + { "VK_RWIN", 0x5C, "Right Windows" }, + { "VK_APPS", 0x5D, "Applications Key" }, + //{ "-", 0x5E, "Reserved" }, + { "VK_SLEEP", 0x5F, "Computer Sleep" }, + { "VK_NUMPAD0", 0x60, "Keypad 0" }, + { "VK_NUMPAD1", 0x61, "Keypad 1" }, + { "VK_NUMPAD2", 0x62, "Keypad 2" }, + { "VK_NUMPAD3", 0x63, "Keypad 3" }, + { "VK_NUMPAD4", 0x64, "Keypad 4" }, + { "VK_NUMPAD5", 0x65, "Keypad 5" }, + { "VK_NUMPAD6", 0x66, "Keypad 6" }, + { "VK_NUMPAD7", 0x67, "Keypad 7" }, + { "VK_NUMPAD8", 0x68, "Keypad 8" }, + { "VK_NUMPAD9", 0x69, "Keypad 9" }, + { "VK_MULTIPLY", 0x6A, "Multiply" }, + { "VK_ADD", 0x6B, "Add" }, + { "VK_SEPARATOR", 0x6C, "Separator" }, + { "VK_SUBTRACT", 0x6D, "Subtract" }, + { "VK_DECIMAL", 0x6E, "Decimal" }, + { "VK_DIVIDE", 0x6F, "Divide" }, + { "VK_F1", 0x70, "F1" }, + { "VK_F2", 0x71, "F2" }, + { "VK_F3", 0x72, "F3" }, + { "VK_F4", 0x73, "F4" }, + { "VK_F5", 0x74, "F5" }, + { "VK_F6", 0x75, "F6" }, + { "VK_F7", 0x76, "F7" }, + { "VK_F8", 0x77, "F8" }, + { "VK_F9", 0x78, "F9" }, + { "VK_F10", 0x79, "F10" }, + { "VK_F11", 0x7A, "F11" }, + { "VK_F12", 0x7B, "F12" }, + { "VK_F13", 0x7C, "F13" }, + { "VK_F14", 0x7D, "F14" }, + { "VK_F15", 0x7E, "F15" }, + { "VK_F16", 0x7F, "F16" }, + { "VK_F17", 0x80, "F17" }, + { "VK_F18", 0x81, "F18" }, + { "VK_F19", 0x82, "F19" }, + { "VK_F20", 0x83, "F20" }, + { "VK_F21", 0x84, "F21" }, + { "VK_F22", 0x85, "F22" }, + { "VK_F23", 0x86, "F23" }, + { "VK_F24", 0x87, "F24" }, + //{ "-", 0x88 - 8F, "Unassigned" }, + { "VK_NUMLOCK", 0x90, "Num Lock" }, + { "VK_SCROLL", 0x91, "Scroll Lock" }, //{"-", 0x92-96,"OEM specific"}, - //{ "-", 0x97 - 9F, L"Unassigned" }, - { "VK_LSHIFT", 0xA0, L"Left Shift" }, - { "VK_RSHIFT", 0xA1, L"Right Shift" }, - { "VK_LCONTROL", 0xA2, L"Left Control" }, - { "VK_RCONTROL", 0xA3, L"Right Control" }, - { "VK_LMENU", 0xA4, L"Left Menu" }, - { "VK_RMENU", 0xA5, L"Right Menu" }, - { "VK_BROWSER_BACK", 0xA6, L"Browser Back" }, - { "VK_BROWSER_FORWARD", 0xA7, L"Browser Forward" }, - { "VK_BROWSER_REFRESH", 0xA8, L"Browser Refresh" }, - { "VK_BROWSER_STOP", 0xA9, L"Browser Stop" }, - { "VK_BROWSER_SEARCH", 0xAA, L"Browser Search" }, - { "VK_BROWSER_FAVORITES", 0xAB, L"Browser Favorites" }, - { "VK_BROWSER_HOME", 0xAC, L"Browser Start and Home" }, - { "VK_VOLUME_MUTE", 0xAD, L"Volume Mute" }, - { "VK_VOLUME_DOWN", 0xAE, L"Volume Down" }, - { "VK_VOLUME_UP", 0xAF, L"Volume Up" }, - { "VK_MEDIA_NEXT_TRACK", 0xB0, L"Next Track" }, - { "VK_MEDIA_PREV_TRACK", 0xB1, L"Previous Track" }, - { "VK_MEDIA_STOP", 0xB2, L"Stop Media" }, - { "VK_MEDIA_PLAY_PAUSE", 0xB3, L"Play/Pause Media" }, - { "VK_LAUNCH_MAIL", 0xB4, L"Start Mail" }, - { "VK_LAUNCH_MEDIA_SELECT", 0xB5, L"Select Media" }, - { "VK_LAUNCH_APP1", 0xB6, L"Start Application 1" }, - { "VK_LAUNCH_APP2", 0xB7, L"Start Application 2" }, - //{ "-", 0xB8 - B9, L"Reserved" }, - { "VK_OEM_1", 0xBA, L"Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the \';:\' key VK_OEM_PLUS" }, - { "VK_OEM_PLUS", 0xBB, L"+" }, - { "VK_OEM_COMMA", 0xBC, L"," }, - { "VK_OEM_MINUS", 0xBD, L"-" }, - { "VK_OEM_PERIOD", 0xBE, L"." }, - { "VK_OEM_2", 0xBF, L"/" }, - { "VK_OEM_3", 0xC0, L"`" }, - //{ "-", 0xC1 - D7, L"Reserved" }, - //{ "-", 0xD8 - DA, L"Unassigned" }, - { "VK_OEM_4", 0xDB, L"[" }, - { "VK_OEM_5", 0xDC, L"\\" }, - { "VK_OEM_6", 0xDD, L"]" }, - { "VK_OEM_7", 0xDE, L"'" }, - { "VK_OEM_8", 0xDF, L"Used for miscellaneous characters; it can vary by keyboard." }, - //{ "-", 0xE0, L"Reserved" }, - //{ "-", 0xE1, L"OEM specific" }, - { "VK_OEM_102", 0xE2, L"Either the angle bracket key or the backslash key on the RT 102-key keyboard" }, - //{ "-", 0xE3 - E4, L"OEM specific" }, - { "VK_PROCESSKEY", 0xE5, L"IME PROCESS" }, - //{ "-", 0xE6, L"OEM specific" }, - { "VK_PACKET", 0xE7, L"Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP" }, - //{ "-", 0xE8, L"Unassigned" }, + //{ "-", 0x97 - 9F, "Unassigned" }, + { "VK_LSHIFT", 0xA0, "Left Shift" }, + { "VK_RSHIFT", 0xA1, "Right Shift" }, + { "VK_LCONTROL", 0xA2, "Left Control" }, + { "VK_RCONTROL", 0xA3, "Right Control" }, + { "VK_LMENU", 0xA4, "Left Menu" }, + { "VK_RMENU", 0xA5, "Right Menu" }, + { "VK_BROWSER_BACK", 0xA6, "Browser Back" }, + { "VK_BROWSER_FORWARD", 0xA7, "Browser Forward" }, + { "VK_BROWSER_REFRESH", 0xA8, "Browser Refresh" }, + { "VK_BROWSER_STOP", 0xA9, "Browser Stop" }, + { "VK_BROWSER_SEARCH", 0xAA, "Browser Search" }, + { "VK_BROWSER_FAVORITES", 0xAB, "Browser Favorites" }, + { "VK_BROWSER_HOME", 0xAC, "Browser Start and Home" }, + { "VK_VOLUME_MUTE", 0xAD, "Volume Mute" }, + { "VK_VOLUME_DOWN", 0xAE, "Volume Down" }, + { "VK_VOLUME_UP", 0xAF, "Volume Up" }, + { "VK_MEDIA_NEXT_TRACK", 0xB0, "Next Track" }, + { "VK_MEDIA_PREV_TRACK", 0xB1, "Previous Track" }, + { "VK_MEDIA_STOP", 0xB2, "Stop Media" }, + { "VK_MEDIA_PLAY_PAUSE", 0xB3, "Play/Pause Media" }, + { "VK_LAUNCH_MAIL", 0xB4, "Start Mail" }, + { "VK_LAUNCH_MEDIA_SELECT", 0xB5, "Select Media" }, + { "VK_LAUNCH_APP1", 0xB6, "Start Application 1" }, + { "VK_LAUNCH_APP2", 0xB7, "Start Application 2" }, + //{ "-", 0xB8 - B9, "Reserved" }, + { "VK_OEM_1", 0xBA, "Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard, the \';:\' key VK_OEM_PLUS" }, + { "VK_OEM_PLUS", 0xBB, "+" }, + { "VK_OEM_COMMA", 0xBC, "," }, + { "VK_OEM_MINUS", 0xBD, "-" }, + { "VK_OEM_PERIOD", 0xBE, "." }, + { "VK_OEM_2", 0xBF, "/" }, + { "VK_OEM_3", 0xC0, "`" }, + //{ "-", 0xC1 - D7, "Reserved" }, + //{ "-", 0xD8 - DA, "Unassigned" }, + { "VK_OEM_4", 0xDB, "[" }, + { "VK_OEM_5", 0xDC, "\\" }, + { "VK_OEM_6", 0xDD, "]" }, + { "VK_OEM_7", 0xDE, "'" }, + { "VK_OEM_8", 0xDF, "Used for miscellaneous characters; it can vary by keyboard." }, + //{ "-", 0xE0, "Reserved" }, + //{ "-", 0xE1, "OEM specific" }, + { "VK_OEM_102", 0xE2, "Either the angle bracket key or the backslash key on the RT 102-key keyboard" }, + //{ "-", 0xE3 - E4, "OEM specific" }, + { "VK_PROCESSKEY", 0xE5, "IME PROCESS" }, + //{ "-", 0xE6, "OEM specific" }, + { "VK_PACKET", 0xE7, "Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP" }, + //{ "-", 0xE8, "Unassigned" }, // {"-",0xE6,"OEM specific"}, - { "VK_PACKET", 0xE7, L"Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP" }, + { "VK_PACKET", 0xE7, "Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP" }, // {"-",0xE8,"Unassigned"}, - //{ "-", 0xE9 - F5, L"OEM specific" }, - { "VK_ATTN", 0xF6, L"Attn" }, - { "VK_CRSEL", 0xF7, L"CrSel" }, - { "VK_EXSEL", 0xF8, L"ExSel" }, - { "VK_EREOF", 0xF9, L"Erase EOF" }, - { "VK_PLAY", 0xFA, L"Play" }, - { "VK_ZOOM", 0xFB, L"Zoom" }, - { "VK_NONAME", 0xFC, L"Reserved" }, - { "VK_PA1", 0xFD, L"PA1" }, - { "VK_OEM_CLEAR", 0xFE, L"Clear" }, + //{ "-", 0xE9 - F5, "OEM specific" }, + { "VK_ATTN", 0xF6, "Attn" }, + { "VK_CRSEL", 0xF7, "CrSel" }, + { "VK_EXSEL", 0xF8, "ExSel" }, + { "VK_EREOF", 0xF9, "Erase EOF" }, + { "VK_PLAY", 0xFA, "Play" }, + { "VK_ZOOM", 0xFB, "Zoom" }, + { "VK_NONAME", 0xFC, "Reserved" }, + { "VK_PA1", 0xFD, "PA1" }, + { "VK_OEM_CLEAR", 0xFE, "Clear" }, - { "", 0xFFFF + 0x01, L"Pad1 Up" }, - { "", 0xFFFF + 0x02, L"Pad1 Down" }, - { "", 0xFFFF + 0x03, L"Pad1 Left" }, - { "", 0xFFFF + 0x04, L"Pad1 Right" }, - { "", 0xFFFF + 0x05, L"Pad1 Start" }, - { "", 0xFFFF + 0x06, L"Pad1 Back" }, - { "", 0xFFFF + 0x07, L"Pad1 Left Thumb" }, - { "", 0xFFFF + 0x08, L"Pad1 Right Thumb" }, - { "", 0xFFFF + 0x09, L"Pad1 Left Bumper" }, - { "", 0xFFFF + 0x0A, L"Pad1 Right Bumper" }, - { "", 0xFFFF + 0x0D, L"Pad1 A" }, - { "", 0xFFFF + 0x0E, L"Pad1 B" }, - { "", 0xFFFF + 0x0F, L"Pad1 X" }, - { "", 0xFFFF + 0x10, L"Pad1 Y" } + { "", 0xFFFF + 0x01, "Pad1 Up" }, + { "", 0xFFFF + 0x02, "Pad1 Down" }, + { "", 0xFFFF + 0x03, "Pad1 Left" }, + { "", 0xFFFF + 0x04, "Pad1 Right" }, + { "", 0xFFFF + 0x05, "Pad1 Start" }, + { "", 0xFFFF + 0x06, "Pad1 Back" }, + { "", 0xFFFF + 0x07, "Pad1 Left Thumb" }, + { "", 0xFFFF + 0x08, "Pad1 Right Thumb" }, + { "", 0xFFFF + 0x09, "Pad1 Left Bumper" }, + { "", 0xFFFF + 0x0A, "Pad1 Right Bumper" }, + { "", 0xFFFF + 0x0D, "Pad1 A" }, + { "", 0xFFFF + 0x0E, "Pad1 B" }, + { "", 0xFFFF + 0x0F, "Pad1 X" }, + { "", 0xFFFF + 0x10, "Pad1 Y" } }; class WindowsKeyManager : public IKeyManager @@ -238,6 +238,6 @@ class WindowsKeyManager : public IKeyManager void RefreshState(); bool IsKeyPressed(uint32_t key); uint32_t GetPressedKey(); - wchar_t* GetKeyName(uint32_t key); - uint32_t GetKeyCode(wchar_t* keyName); + string GetKeyName(uint32_t key); + uint32_t GetKeyCode(string keyName); }; diff --git a/Windows/stdafx.h b/Windows/stdafx.h index 70217178..92f5cad0 100644 --- a/Windows/stdafx.h +++ b/Windows/stdafx.h @@ -43,5 +43,4 @@ using std::list; using std::vector; using std::shared_ptr; -using std::wstring; using std::string; \ No newline at end of file