Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

If you read this I love you #87

Merged
merged 9 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[submodule "fmt"]
path = vendored/fmt
url = https://github.com/fmtlib/fmt
[submodule "core"]
path = core
url = https://github.com/hydra-emu/core
[submodule "protocol"]
path = protocol
url = https://github.com/hydra-emu/protocol
[submodule "vendored/argparse"]
path = vendored/argparse
url = https://github.com/cofyc/argparse/
141 changes: 42 additions & 99 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,75 +1,38 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.12)

include(ExternalProject)

project(hydra VERSION 0.2.0 LANGUAGES CXX)
project(hydra_server)
project(hydra
VERSION 0.2.0
LANGUAGES C CXX
HOMEPAGE_URL "https://github.com/hydra-emu/hydra"
DESCRIPTION "A multi-system, multi-platform emulator frontend"
)

option(USE_LUA "Use lua for script support" ON)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
add_subdirectory(vendored/fmt)
add_subdirectory(vendored/argparse)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /std:c++20")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcrc32")
endif()
elseif(APPLE)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crc")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
endif()
elseif(LINUX)
set(WARNINGS
"-Werror=return-type"
"-Werror=unused-variable"
"-Werror=unused-but-set-variable"
"-Werror=unused-function"
"-Werror=uninitialized"
"-Wimplicit-fallthrough"
"-Werror=sign-compare"
"-Werror=shadow"
"-Werror=deprecated-declarations"
)
string(REPLACE ";" " " WARNINGS_FLAGS "${WARNINGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcrc32 ${WARNINGS_FLAGS} -g -O2")
elseif(EMSCRIPTEN)
else()
message(FATAL_ERROR "Unsupported platform")
endif()
set(OpenGL_GL_PREFERENCE GLVND)

find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets OpenGL OpenGLWidgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets OpenGL OpenGLWidgets)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets OpenGLWidgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets OpenGLWidgets)
find_package(OpenSSL REQUIRED)

if (USE_LUA)
find_package(Lua REQUIRED)
set(HYDRA_INCLUDE_DIRECTORIES
${HYDRA_INCLUDE_DIRECTORIES}
${LUA_INCLUDE_DIR}
)
endif()
find_package(OpenSSL REQUIRED)

add_subdirectory(vendored/fmt)
add_subdirectory(vendored/argparse)

# add_compile_options(-fsanitize=address -fsanitize=undefined)
# add_link_options(-fsanitize=address -fsanitize=undefined)

set(HYDRA_COMMON_FILES
)

set(HYDRA_QT_FILES
data/resources.qrc
qt/main.cxx
qt/mainwindow.cxx
qt/screenwidget.cxx
qt/settingswindow.cxx
Expand All @@ -80,72 +43,52 @@ set(HYDRA_QT_FILES
qt/terminalwindow.cxx
qt/downloaderwindow.cxx
qt/cheatswindow.cxx
src/corewrapper.cxx
src/main.cxx
vendored/miniaudio.c
vendored/stb_image_write.c
vendored/miniz/miniz.c
)

set(HYDRA_SERVER_FILES
server/main.cxx
server/server.cxx
vendored/glad.c
vendored/argparse/argparse.c
)

set(HYDRA_INCLUDE_DIRECTORIES
${HYDRA_INCLUDE_DIRECTORIES}
include
core/include
vendored
vendored/fmt/include
qt/
man/
)

if(USE_LUA)
set(HYDRA_INCLUDE_DIRECTORIES
${HYDRA_INCLUDE_DIRECTORIES}
${LUA_INCLUDE_DIR}
)
endif()

qt_add_executable(hydra
MANUAL_FINALIZATION
${HYDRA_COMMON_FILES}
${HYDRA_QT_FILES}
)

if(APPLE)
target_link_libraries(hydra PRIVATE "-framework Security")
endif()

if(WIN32)
set_target_properties(hydra PROPERTIES COMPILE_FLAGS "/EHsc")
target_compile_definitions(hydra PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
set_target_properties(hydra PROPERTIES WIN32_EXECUTABLE TRUE)
elseif(APPLE)
target_link_libraries(hydra PRIVATE "-framework Security")
set_target_properties(hydra PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER com.hydra_emu.hydra
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
)
endif()

target_link_libraries(hydra PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::OpenGL
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::OpenGLWidgets
${CMAKE_DL_LIBS} fmt::fmt ${LUA_LIBRARIES}
OpenSSL::SSL)
target_include_directories(hydra PRIVATE ${HYDRA_INCLUDE_DIRECTORIES})
set_target_properties(hydra PROPERTIES hydra_properties
MACOSX_BUNDLE_GUI_IDENTIFIER offtkp.hydra.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
${CMAKE_DL_LIBS}
${LUA_LIBRARIES}
OpenSSL::SSL
fmt::fmt
)
target_include_directories(hydra PRIVATE ${HYDRA_INCLUDE_DIRECTORIES})
target_compile_definitions(hydra PRIVATE HYDRA_VERSION="${PROJECT_VERSION}")

qt_finalize_executable(hydra)

if(BUILD_SERVER)
find_package(glfw3 REQUIRED)
endif()
# Server
add_executable(
hydra_server
${HYDRA_COMMON_FILES}
${HYDRA_SERVER_FILES}
)
target_include_directories(hydra_server PRIVATE ${HYDRA_INCLUDE_DIRECTORIES})
target_link_libraries(hydra_server PRIVATE argparse glfw)
if (NOT BUILD_SERVER)
set_target_properties(hydra_server PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()
2 changes: 1 addition & 1 deletion android/app/src/main/cpp/android.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <android/log.h>
#include <core_loader.hxx>
#include <corewrapper.hxx>
#include <cstdio>
#include <dlfcn.h>
#include <EGL/egl.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

public class HydraGlRenderer implements GLSurfaceView.Renderer {

HydraGlRenderer() {
super();
}

int screenWidth, screenHeight;
int screenTexture;
public int screenFbo;
Expand Down
2 changes: 1 addition & 1 deletion core
Submodule core updated 1 files
+88 −5 include/hydra/core.hxx
Binary file added data/images/Android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/Linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/MacOS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/Windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/images/android.png
Binary file not shown.
Binary file modified data/images/hydra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions data/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<file>images/run.png</file>
<file>images/save.png</file>
<file>images/open.png</file>
<file>images/Windows.png</file>
<file>images/MacOS.png</file>
<file>images/Linux.png</file>
<file>images/Android.png</file>
<file>default_mappings.json</file>
<file>core.html</file>
<file>about.html</file>
Expand Down
25 changes: 25 additions & 0 deletions include/compatibility.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,29 @@ namespace hydra
return splits;
}

inline std::vector<uint8_t> hex_to_bytes(const std::string& cheat)
{
std::vector<uint8_t> bytes;
for (size_t i = 0; i < cheat.size(); i += 2)
{
std::string hex = cheat.substr(i, 2);
bytes.push_back((uint8_t)std::stoul(hex, nullptr, 16));
}
return bytes;
}

// Function for hashing a string in compile time in order to be used in a switch statement
// https://stackoverflow.com/a/46711735
// If there's a collision between two strings, we will know
// at compile time since the cases can't use the same number twice
constexpr uint32_t str_hash(std::string_view data) noexcept
{
uint32_t hash = 5381;
const size_t size = data.size();
for (size_t i = 0; i < size; i++)
hash = ((hash << 5) + hash) + (unsigned char)data[i];

return hash;
}

} // namespace hydra
42 changes: 28 additions & 14 deletions include/core_loader.hxx → include/corewrapper.hxx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#pragma once

#include "hsystem.h"
#include "hsystem.hxx"
#include <cstring>
#include <string>
#include <vector>
#if defined(HYDRA_LINUX) || defined(HYDRA_MACOS)
#include <dlfcn.h>
#elif defined(HYDRA_WINDOWS)
#include <windows.h>
#elif defined(HYDRA_WII)
#include "ELFIO/elfio/elfio.hpp"
#endif
#include "scopeguard.hxx"
#include <filesystem>
#include <hydra/core.hxx>

Expand Down Expand Up @@ -113,32 +115,44 @@ namespace hydra
#endif
}

struct CheatMetadata
{
bool enabled = false;
std::string name{};
std::string code{};
uint32_t handle = hydra::BAD_CHEAT;
};

// Should only be made through the factory
struct EmulatorWrapper
{
IBase* shell = nullptr;

~EmulatorWrapper()
{
destroy_function(shell);
dynlib_close(handle);
}
~EmulatorWrapper();

const char* GetInfo(hydra::InfoType type)
{
return get_info_function(type);
}
const char* GetInfo(hydra::InfoType type);
const CheatMetadata& GetCheat(uint32_t handle);
const std::vector<CheatMetadata>& GetCheats();

bool LoadGame(const std::filesystem::path& path);
uint32_t EditCheat(const CheatMetadata& cheat, uint32_t old_handle = hydra::BAD_CHEAT);
void RemoveCheat(uint32_t handle);
void EnableCheat(uint32_t handle);
void DisableCheat(uint32_t handle);

private:
dynlib_handle_t handle;
void (*destroy_function)(IBase*);
const char* (*get_info_function)(hydra::InfoType);
std::string game_hash_;

EmulatorWrapper(IBase* shl, dynlib_handle_t hdl, void (*dfunc)(IBase*),
const char* (*gfunc)(hydra::InfoType))
: shell(shl), handle(hdl), destroy_function(dfunc), get_info_function(gfunc)
{
}
const char* (*gfunc)(hydra::InfoType));

void init_cheats();
void save_cheats();

std::vector<CheatMetadata> cheats_;

EmulatorWrapper(const EmulatorWrapper&) = delete;
friend struct EmulatorFactory;
Expand Down
Loading
Loading