diff --git a/CMakeLists.txt b/CMakeLists.txt index 98d2b6a865ca..8174d97527f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -520,7 +520,6 @@ if(UNIX) message(STATUS "Using named pipes as controller inputs") add_definitions(-DUSE_PIPES=1) message(STATUS "Watching game memory for changes") - add_definitions(-DUSE_MEMORYWATCHER=1) endif() if(ENABLE_ANALYTICS) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index d70d9ff7120c..155f5220454f 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -38,9 +38,7 @@ #include "Core/DSPEmulator.h" #include "Core/Host.h" #include "Core/MemTools.h" -#ifdef USE_MEMORYWATCHER #include "Core/MemoryWatcher.h" -#endif #include "Core/Boot/Boot.h" #include "Core/FifoPlayer/FifoPlayer.h" #include "Core/HLE/HLE.h" @@ -289,9 +287,7 @@ void Stop() // - Hammertime! GCAdapter::ResetRumble(); #endif -#ifdef USE_MEMORYWATCHER MemoryWatcher::Shutdown(); -#endif } void DeclareAsCPUThread() @@ -383,9 +379,7 @@ static void CpuThread() } #endif -#ifdef USE_MEMORYWATCHER MemoryWatcher::Init(); -#endif // Enter CPU run loop. When we leave it - we are done. CPU::Run(); diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 5e275711dea2..a7a9d55c02c0 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -237,6 +237,7 @@ + @@ -486,6 +487,7 @@ + @@ -586,4 +588,4 @@ - + \ No newline at end of file diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 167fcec00770..9710d2b08fcd 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -889,6 +889,7 @@ IOS\Network\NCD + @@ -1559,8 +1560,9 @@ HW %28Flipper/Hollywood%29\WiimoteCommon + - + \ No newline at end of file diff --git a/Source/Core/Core/MemoryWatcher.cpp b/Source/Core/Core/MemoryWatcher.cpp index 3aea80a6b65e..2526ac134c01 100644 --- a/Source/Core/Core/MemoryWatcher.cpp +++ b/Source/Core/Core/MemoryWatcher.cpp @@ -6,7 +6,12 @@ #include #include #include +#ifdef _WIN32 +#include +#include +#else #include +#endif #include "Common/FileUtil.h" #include "Core/CoreTiming.h" @@ -53,7 +58,11 @@ MemoryWatcher::~MemoryWatcher() return; m_running = false; +#ifdef _WIN32 + CloseHandle(m_pipe); +#else close(m_fd); +#endif } bool MemoryWatcher::LoadAddresses(const std::string& path) @@ -83,12 +92,19 @@ void MemoryWatcher::ParseLine(const std::string& line) bool MemoryWatcher::OpenSocket(const std::string& path) { +#ifdef _WIN32 + m_pipe = CreateFile(L"\\\\.\\pipe\\Dolphin Emulator\\MemoryWatcher", GENERIC_READ | GENERIC_WRITE, + 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + + return m_pipe != INVALID_HANDLE_VALUE; +#else memset(&m_addr, 0, sizeof(m_addr)); m_addr.sun_family = AF_UNIX; strncpy(m_addr.sun_path, path.c_str(), sizeof(m_addr.sun_path) - 1); m_fd = socket(AF_UNIX, SOCK_DGRAM, 0); return m_fd >= 0; +#endif } u32 MemoryWatcher::ChasePointer(const std::string& line) @@ -122,8 +138,16 @@ void MemoryWatcher::Step() // Update the value current_value = new_value; std::string message = ComposeMessage(address, new_value); +#ifdef _WIN32 + unsigned long m_written; + if (m_pipe != INVALID_HANDLE_VALUE) + WriteFile(m_pipe, message.c_str(), static_cast(message.size() + 1), &m_written, + nullptr); +#else sendto(m_fd, message.c_str(), message.size() + 1, 0, reinterpret_cast(&m_addr), sizeof(m_addr)); +#endif } } } + diff --git a/Source/Core/Core/MemoryWatcher.h b/Source/Core/Core/MemoryWatcher.h index e2dc4790bcad..c983b4289e7c 100644 --- a/Source/Core/Core/MemoryWatcher.h +++ b/Source/Core/Core/MemoryWatcher.h @@ -5,10 +5,14 @@ #pragma once #include +#ifndef _WIN32 #include #include +#endif #include +#include "Common/CommonTypes.h" + // MemoryWatcher reads a file containing in-game memory addresses and outputs // changes to those memory addresses to a unix domain socket as the game runs. // @@ -37,8 +41,12 @@ class MemoryWatcher final bool m_running; +#ifdef _WIN32 + void* m_pipe; +#else int m_fd; sockaddr_un m_addr; +#endif // Address as stored in the file -> list of offsets to follow std::map> m_addresses;