Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPC messaging system #206

Merged
merged 38 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c44eaf6
Initial implementation
igor725 May 19, 2024
5c42d7a
Merge remote-tracking branch 'origin/features' into ipc
igor725 Jun 5, 2024
785daec
Fixes
igor725 Jun 5, 2024
8d01b71
Move ipc to core
igor725 Jun 5, 2024
a0be33b
More fixes
igor725 Jun 5, 2024
29697f5
Mmm
igor725 Jun 5, 2024
24f41c2
Rungame command
igor725 Jun 5, 2024
0fa1226
IPC runner
igor725 Jun 5, 2024
07b26bf
Move started message
igor725 Jun 5, 2024
9a96eb0
Sanic
igor725 Jun 5, 2024
f3297fa
Uncomment pipe argument
igor725 Jun 5, 2024
350c74a
Merge branch 'features' of https://github.com/SysRay/psOff_public int…
igor725 Jun 8, 2024
af5a8d5
Main IPC process
igor725 Jun 8, 2024
a1fb698
Unneeded now
igor725 Jun 8, 2024
d1fb1ed
Cleanup + arguments
igor725 Jun 8, 2024
2d05eb4
Some reader mess
igor725 Jun 9, 2024
2e61a4b
Fix things
igor725 Jun 9, 2024
17271b0
Rename things
igor725 Jun 9, 2024
779e4c3
Merge branch 'features' of https://github.com/SysRay/psOff_public int…
igor725 Jun 9, 2024
5bc3704
Some things
igor725 Jun 9, 2024
eaeff93
Preparations for exec request reader
igor725 Jun 9, 2024
d0bf4c8
Split things
igor725 Jun 10, 2024
0a3e2fe
Separate packet for arguments
igor725 Jun 10, 2024
3916c00
Cleanup
igor725 Jun 10, 2024
2f0aeeb
LoadExec event and some things
igor725 Jun 10, 2024
cf13d98
Merge branch 'features' into ipc
igor725 Jun 11, 2024
2b964ed
winapi -> boost
igor725 Jun 11, 2024
e2d4b68
Deps
igor725 Jun 11, 2024
b721e2f
Cleanup
igor725 Jun 11, 2024
de9002d
Do not capture
igor725 Jun 11, 2024
44cebdd
rework systemEvents
nopnopnopnopnopnop Jun 12, 2024
f7e37b9
Cleanup
igor725 Jun 12, 2024
31e58f4
Check if emu process still alive
igor725 Jun 12, 2024
0d692bf
It works
igor725 Jun 13, 2024
e6903bf
Whoopsie
igor725 Jun 13, 2024
5caebec
Fix things
igor725 Jun 13, 2024
35fd48e
Fix crash on exit
igor725 Jun 13, 2024
7959f50
Merge branch 'features' into ipc
igor725 Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,31 @@
"request": "launch",
"program": "${workspaceRoot}/_build/_Install/psoff.exe",
"args": [
"--d",
// "--d",
// "--vkValidation",
"${config:psoff.add-arg}",
"--file=${config:psoff.game-path}/eboot.bin",
"--file=${config:psoff.game-path}/eboot.bin"
],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/_build/_Install",
"environment": [],
"console": "integratedTerminal",
"symbolSearchPath": "${workspaceRoot}/_build/_Install/debug"
},
{
"name": "(Windows) Attach",
"type": "cppvsdbg",
"request": "attach",
"processId": "${command:pickProcess}"
}
],
"compounds": [
{
"name": "Launch + Attach",
"configurations": [
"(Windows) Launch",
"(Windows) Attach"
]
}
]
}
31 changes: 18 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

set(PSOFF_LIB_VERSION v.0.3)
set(PSOFF_LIB_VERSION v.0.4)
set(PSOFF_RENDER_VERSION v.0.6-nightly_08.06.2024)

set(ProjectName psOff_${CMAKE_BUILD_TYPE})
set(ProjectName psOffChild_${CMAKE_BUILD_TYPE})
project(${ProjectName} VERSION 0.0.1)

unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
Expand All @@ -20,11 +20,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_INSTALL_MESSAGE LAZY)

set(CMAKE_CXX_FLAGS_RELEASE "/MD /GS- /GF /Gy /GR /Oi -fno-strict-aliasing -Wno-unused-command-line-argument")

if(ISDEBUG)
set(CMAKE_CXX_FLAGS_RELEASE "/MD /Zi /GS- /GF /Gy /GR /Oi -O0 -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi -O0")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG /OPT:REF,ICF")
else()
set(CMAKE_CXX_FLAGS_RELEASE "/MD /GS- /GF /Gy /GR /Oi -Ofast -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF,ICF")
endif()

Expand Down Expand Up @@ -101,6 +103,8 @@ add_subdirectory(tools/logging)
add_subdirectory(tools/config_emu)
add_subdirectory(tools/dll2Nids)

add_subdirectory(mainprocess)

add_subdirectory(eventsystem)
add_dependencies(dll2Nids third_party)

Expand Down Expand Up @@ -185,13 +189,13 @@ set_target_properties(core
)

# ## Executable
add_executable(psoff
add_executable(psOffChild
main.cpp
)

add_dependencies(psoff logging core psOff_utility gamereport)
add_dependencies(psOffChild logging core eventsystem psOff_utility gamereport)

target_link_libraries(psoff PRIVATE
target_link_libraries(psOffChild PRIVATE
eventsystem
core.lib
gamereport.lib
Expand All @@ -200,9 +204,9 @@ target_link_libraries(psoff PRIVATE
$<TARGET_OBJECTS:asmHelper>
)

target_link_options(psoff PUBLIC /DYNAMICBASE:NO /DEBUG --image-base=${IMAGE_BASE})
target_link_options(psOffChild PUBLIC /DYNAMICBASE:NO /DEBUG --image-base=${IMAGE_BASE})

set_property(TARGET psoff PROPERTY VS_DPI_AWARE "PerMonitor") # SDL2 High dpi window
set_property(TARGET psOffChild PROPERTY VS_DPI_AWARE "PerMonitor") # SDL2 High dpi window

# # Install
install(DIRECTORY "${CMAKE_BINARY_DIR}/third_party/src/third_party/bin/" DESTINATION ${CMAKE_INSTALL_PREFIX}
Expand All @@ -225,16 +229,17 @@ if(DEFINED ISACTION)
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/bin/vulkan-1.dll CONTENT "") # cmake needs to find the file in order to ignore it
endif()

install(TARGETS psoff
COMPONENT psoff
install(TARGETS psOffChild
COMPONENT psOffChild
RUNTIME_DEPENDENCIES
PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll" ".*vulkan-1\\.dll"

DIRECTORIES
$<TARGET_FILE_DIR:psoff>
$<TARGET_FILE_DIR:psOffChild>
${CMAKE_BINARY_DIR}/third_party/src/third_party/bin
${CMAKE_BINARY_DIR}/third_party/src/third_party/lib
${CMAKE_BINARY_DIR}/eventsystem/lib
${CMAKE_BINARY_DIR}/bin
${CMAKE_BINARY_DIR}/lib
${CMAKE_CURRENT_BINARY_DIR}/core
Expand All @@ -243,4 +248,4 @@ install(TARGETS psoff
DESTINATION .
)

install(FILES $<TARGET_PDB_FILE:psoff> DESTINATION ${CMAKE_INSTALL_PREFIX}/debug OPTIONAL)
install(FILES $<TARGET_PDB_FILE:psOffChild> DESTINATION ${CMAKE_INSTALL_PREFIX}/debug OPTIONAL)
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ add_subdirectory(fileManager)
add_subdirectory(memory)
add_subdirectory(dmem)
add_subdirectory(unwinding)
add_subdirectory(runtime)
add_subdirectory(runtime)
23 changes: 0 additions & 23 deletions core/initParams/initParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class InitParams: public IInitParams {
bool init(int argc, char** argv) final;
bool isDebug() final;

std::string getApplicationPath() final;
std::string getApplicationRoot() final;
std::string getUpdateRoot() final;

bool enableValidation() final;
bool enableBrightness() final;
bool useVSYNC() final;
Expand All @@ -38,9 +34,6 @@ bool InitParams::init(int argc, char** argv) {
("bright", "use srgb display format (brightness)")
("4k", "try 4K display mode if game supports it")
("vsync", po::value<bool>()->default_value(true), "Enable vertical synchronization")
("file", po::value<std::string>(), "fullpath to applications binary")
("root", po::value<std::string>(), "Applications root")
("update", po::value<std::string>(), "update files folder")
// clang-format on
;

Expand All @@ -55,10 +48,6 @@ bool InitParams::init(int argc, char** argv) {
std::cout << desc << '\n';
return false;
}
if (m_vm.count("file") == 0) {
std::cout << "--file missing\n";
return false;
}

return true;
}
Expand All @@ -72,18 +61,6 @@ bool InitParams::isDebug() {
return m_vm.count("d");
}

std::string InitParams::getApplicationPath() {
return m_vm.count("file") ? m_vm["file"].as<std::string>() : std::string();
}

std::string InitParams::getApplicationRoot() {
return m_vm.count("root") ? m_vm["root"].as<std::string>() : std::string();
}

std::string InitParams::getUpdateRoot() {
return m_vm.count("update") ? m_vm["update"].as<std::string>() : std::string();
}

bool InitParams::enableValidation() {
return m_vm.count("vkValidation");
}
Expand Down
6 changes: 1 addition & 5 deletions core/initParams/initParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class IInitParams {
virtual bool init(int argc, char** argv) = 0;
virtual bool isDebug() = 0;

virtual std::string getApplicationPath() = 0;
virtual std::string getApplicationRoot() = 0;
virtual std::string getUpdateRoot() = 0;

virtual bool enableValidation() = 0;
virtual bool enableBrightness() = 0;
virtual bool useVSYNC() = 0;
Expand All @@ -34,4 +30,4 @@ class IInitParams {
#endif

__APICALL IInitParams* accessInitParams();
#undef __APICALL
#undef __APICALL
2 changes: 1 addition & 1 deletion core/runtime/runtimeExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class IRuntimeExport {

virtual std::vector<const char*> const& getEntryParams() const = 0;

virtual void addEntryParam(std::string const& arg) = 0;
virtual void addEntryParam(std::string_view const arg) = 0;

virtual void cxa_add_atexit(CxaDestructor&&, int moduleId) = 0;
virtual void cxa_finalize(int moduleId) = 0;
Expand Down
8 changes: 4 additions & 4 deletions core/runtime/runtimeLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class RuntimeLinker: public IRuntimeLinker {

int loadStartModule(std::filesystem::path const& path, size_t args, const void* argp, int* pRes) final;

uintptr_t execute() final;
uintptr_t relocate() final;

void stopModules() final;
void stopModule(int moduleId) final;
Expand Down Expand Up @@ -413,7 +413,7 @@ class RuntimeLinker: public IRuntimeLinker {

std::vector<const char*> const& getEntryParams() const final { return m_entryParams; };

void addEntryParam(std::string const& arg) final {
void addEntryParam(std::string_view const arg) final {
auto& item = m_argsSave.emplace_back(arg);
m_entryParams.push_back(item.data());
}
Expand Down Expand Up @@ -886,9 +886,9 @@ bool RuntimeLinker::interceptInternal(Program* prog, uintptr_t progoffset, uintp
return true;
}

uintptr_t RuntimeLinker::execute() {
uintptr_t RuntimeLinker::relocate() {
LOG_USE_MODULE(RuntimeLinker);
LOG_INFO(L"Execute()");
LOG_INFO(L"Relocate()");

initTlsStaticBlock();
// pthread::initSelfForMainThread(m_tlsStaticInitBlock.size()); // call before runtimelinker
Expand Down
2 changes: 1 addition & 1 deletion core/runtime/runtimeLinker.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IRuntimeLinker: public IRuntimeExport {
virtual Program* findProgram(uint64_t vaddr) = 0;
virtual Program* findProgramById(size_t id) const = 0;

virtual uintptr_t execute() = 0;
virtual uintptr_t relocate() = 0;
virtual void stopModules() = 0;

virtual void stopModule(int id) = 0;
Expand Down
21 changes: 17 additions & 4 deletions eventsystem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
add_subdirectory(events/template)
add_subdirectory(events/system_cross)
add_subdirectory(events/system_circle)
add_subdirectory(test)

add_library(eventsystem_core SHARED
$<TARGET_OBJECTS:events_intern_template>
$<TARGET_OBJECTS:events_intern_system_cross>
$<TARGET_OBJECTS:events_intern_system_circle>
)

add_library(eventsystem STATIC
$<TARGET_OBJECTS:events_template>
$<TARGET_OBJECTS:events_system_cross>
$<TARGET_OBJECTS:events_system_circle>
)

target_link_libraries(eventsystem PUBLIC eventsystem_core.lib)
target_link_directories(eventsystem PUBLIC ${CMAKE_BINARY_DIR}/eventsystem/lib)
target_link_libraries(eventsystem_core PUBLIC libboost_serialization)
target_link_directories(eventsystem_core PUBLIC
${CMAKE_BINARY_DIR}/third_party/src/third_party/include
)

target_link_libraries(eventsystem PUBLIC eventsystem_core.lib libboost_serialization)
target_link_directories(eventsystem PUBLIC
${CMAKE_BINARY_DIR}/eventsystem/lib
)

add_dependencies(eventsystem eventsystem_core)
add_dependencies(eventsystem eventsystem_core third_party)

install(TARGETS eventsystem_core LIBRARY DESTINATION .)

Expand All @@ -28,4 +41,4 @@ set_target_properties(eventsystem_core
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/eventsystem/lib"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/eventsystem/bin"
PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/"
)
)
16 changes: 16 additions & 0 deletions eventsystem/events/system_circle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
add_library(events_system_circle OBJECT
events.cpp
handler.cpp
)

add_dependencies(events_system_circle third_party)

target_compile_definitions(events_system_circle PUBLIC _CRT_SECURE_NO_WARNINGS)

add_library(events_intern_system_circle OBJECT
intern/core.cpp
)

add_dependencies(events_intern_system_circle third_party)

target_compile_definitions(events_intern_system_circle PUBLIC _CRT_SECURE_NO_WARNINGS)
44 changes: 44 additions & 0 deletions eventsystem/events/system_circle/events.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "events.h"

#include "intern/export.h"

#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/string.hpp>
#include <sstream>

// todo use boost archive

namespace events::system_circle {
void initChild() {
core::initChild();
}

void postEventLoadExec(LoadArgs const& data) {
std::vector<char> cont;

std::ostringstream oss(std::ios::binary);
boost::archive::binary_oarchive oa(oss);
oa << (int32_t)0;
oa << data;

core::postEvent(oss.str());
}

void postEventSetArguments(SetArg const& data) {
std::vector<char> cont;

std::ostringstream oss(std::ios::binary);
boost::archive::binary_oarchive oa(oss);
oa << (int32_t)1;
oa << data;

core::postEvent(oss.str());
}

void postEventRunExec() {
std::ostringstream oss(std::ios::binary);
boost::archive::binary_oarchive oa(oss);
oa << (int32_t)2;
core::postEvent(oss.str());
}
} // namespace events::system_circle
11 changes: 11 additions & 0 deletions eventsystem/events/system_circle/events.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include "types.h"

namespace events::system_circle {

void initChild();

void postEventLoadExec(LoadArgs const& data);
void postEventSetArguments(SetArg const& data);
void postEventRunExec();
} // namespace events::system_circle
9 changes: 9 additions & 0 deletions eventsystem/events/system_circle/handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "handler.h"

#include "intern/export.h"

namespace events::system_circle {
IEventHandler::IEventHandler() {
core::registerSelf(this);
}
} // namespace events::system_circle
15 changes: 15 additions & 0 deletions eventsystem/events/system_circle/handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include "types.h"

namespace events::system_circle {
class IEventHandler {
protected:
IEventHandler();

public:
virtual ~IEventHandler() = default;

virtual void onEventLoadExec(LoadArgs const& data) = 0;
virtual void onEventSetArguments(SetArg const& data) = 0;
};
} // namespace events::system_circle
Loading
Loading