Skip to content

Commit

Permalink
Split Interop into new library
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Jan 27, 2023
1 parent 1e1d4ee commit b111a1f
Show file tree
Hide file tree
Showing 193 changed files with 220 additions and 206 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(Core)
add_subdirectory(Interop)
add_subdirectory(Math)
add_subdirectory(OpenLoco)
add_subdirectory(Resources)
Expand Down
23 changes: 23 additions & 0 deletions src/Interop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(public_files
"${CMAKE_CURRENT_SOURCE_DIR}/include/OpenLoco/Interop/Interop.hpp"
)

set(private_files
"${CMAKE_CURRENT_SOURCE_DIR}/src/Hook.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Interop.cpp"
)

loco_add_library(Interop STATIC
PUBLIC_FILES
${public_files}
PRIVATE_FILES
${private_files}
)

# Disable optimizations for interop.cpp for all compilers, to allow optimized
# builds without need for -fno-omit-frame-pointer
if (MSVC)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/src/Interop/Interop.cpp" PROPERTIES COMPILE_FLAGS "/Oy- /Od")
else ()
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/src/Interop/Interop.cpp" PROPERTIES COMPILE_FLAGS "-fno-omit-frame-pointer -O0")
endif ()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#else
#include <sys/mman.h>
#endif // _WIN32
#include "Console.h"

#include "Interop.hpp"

namespace OpenLoco::Interop
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace OpenLoco::Interop
done = WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, data, i, 0);
if (!done)
{
Console::error("WriteProcessMemory failed! address = 0x%08x, size = %u, GetLastError() = 0x%08x", address, i, GetLastError());
fprintf(stderr, "WriteProcessMemory failed! address = 0x%08x, size = %u, GetLastError() = 0x%08x", address, i, GetLastError());
}
#else
done = true;
Expand Down Expand Up @@ -183,7 +183,7 @@ namespace OpenLoco::Interop
}
if (_hookTableOffset > kMaxHooks)
{
Console::error("Failed registering hook for 0x%08x. Ran out of hook table space", address);
fprintf(stderr, "Failed registering hook for 0x%08x. Ran out of hook table space", address);
return;
}
// Do a few retries here. This can fail on some versions of wine which inexplicably would fail on
Expand All @@ -209,7 +209,7 @@ namespace OpenLoco::Interop
retries--;
if (!done)
{
Console::error("Failed registering hook for 0x%08x. Retries left: %d", address, retries);
fprintf(stderr, "Failed registering hook for 0x%08x. Retries left: %d", address, retries);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <windows.h>
#endif // _WIN32

#include "Console.h"
#include "Interop.hpp"

#pragma warning(disable : 4731) // frame pointer register 'ebp' modified by inline assembly code
Expand Down Expand Up @@ -298,7 +297,7 @@ namespace OpenLoco::Interop
#ifdef _WIN32
if (!ReadProcessMemory(GetCurrentProcess(), (LPVOID)address, data, size, nullptr))
{
Console::error("ReadProcessMemory failed! address = 0x%08x, size = %u, GetLastError() = 0x%08x", address, size, GetLastError());
fprintf(stderr, "ReadProcessMemory failed! address = 0x%08x, size = %u, GetLastError() = 0x%08x", address, size, GetLastError());
throw std::runtime_error("ReadProcessMemory failed");
}
#else
Expand All @@ -312,7 +311,7 @@ namespace OpenLoco::Interop
#ifdef _WIN32
if (!WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, data, size, nullptr))
{
Console::error("WriteProcessMemory failed! address = 0x%08x, size = %u, GetLastError() = 0x%08x", address, size, GetLastError());
fprintf(stderr, "WriteProcessMemory failed! address = 0x%08x, size = %u, GetLastError() = 0x%08x", address, size, GetLastError());
throw std::runtime_error("WriteProcessMemory failed");
}
#else
Expand Down
3 changes: 3 additions & 0 deletions src/Math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ loco_add_library(Math STATIC
${private_files}
)

target_link_libraries(Math PUBLIC
Interop
)
2 changes: 1 addition & 1 deletion src/Math/src/Trigonometry.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Trigonometry.hpp"
#include "Interop/Interop.hpp"
#include <OpenLoco/Interop/Interop.hpp>

namespace OpenLoco::Math::Trigonometry
{
Expand Down
2 changes: 1 addition & 1 deletion src/Math/src/Vector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Vector.hpp"
#include "Interop/Interop.hpp"
#include <OpenLoco/Interop/Interop.hpp>

namespace OpenLoco::Math::Vector
{
Expand Down
13 changes: 2 additions & 11 deletions src/OpenLoco/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ set(OLOCO_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/Input/MouseInput.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Input/ShortcutManager.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Input.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Interop/Hook.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Interop/Hooks.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Interop/Interop.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Intro.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/LastGameOptionManager.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Localisation/Conversion.cpp"
Expand Down Expand Up @@ -469,7 +467,6 @@ set(OLOCO_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/src/Drawing/DrawSpriteHelper.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Drawing/DrawSpriteRLE.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameException.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Interop/Interop.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Localisation/ArgsWrapper.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Localisation/FormatArguments.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Location.hpp"
Expand All @@ -487,14 +484,6 @@ if (APPLE)
set_source_files_properties(${OLOCO_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++")
endif()

# Disable optimizations for interop.cpp for all compilers, to allow optimized
# builds without need for -fno-omit-frame-pointer
if (MSVC)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/src/Interop/Interop.cpp" PROPERTIES COMPILE_FLAGS "/Oy- /Od")
else ()
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/src/Interop/Interop.cpp" PROPERTIES COMPILE_FLAGS "-fno-omit-frame-pointer -O0")
endif ()

if (MINGW)
loco_add_library(OpenLoco SHARED
PRIVATE_FILES
Expand Down Expand Up @@ -533,6 +522,7 @@ endif ()

target_link_libraries(OpenLoco
Core
Interop
Utility
Math
${SDL2_LIB}
Expand Down Expand Up @@ -645,6 +635,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_include_directories(OpenLoco-headers-check PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(OpenLoco-headers-check PUBLIC
Core
Interop
Utility
Math
${SDL2_LIB} # These libraries are used in some of our headers try to minimize doing this
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Audio/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Environment.h"
#include "Game.h"
#include "GameStateFlags.h"
#include "Interop/Interop.hpp"
#include "Localisation/StringIds.h"
#include "Map/SurfaceElement.h"
#include "Map/TileLoop.hpp"
Expand All @@ -20,6 +19,7 @@
#include "Ui/WindowManager.h"
#include "VehicleChannel.h"
#include "Vehicles/Vehicle.h"
#include <OpenLoco/Interop/Interop.hpp>
#include <OpenLoco/Utility/Stream.hpp>
#include <array>
#include <cassert>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Audio/VehicleChannel.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "VehicleChannel.h"
#include "Entities/EntityManager.h"
#include "Interop/Interop.hpp"
#include "Map/SurfaceElement.h"
#include "Map/TileManager.h"
#include "Ui/WindowManager.h"
#include "Vehicles/Vehicle.h"
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Company.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "GameState.h"
#include "Graphics/Gfx.h"
#include "IndustryManager.h"
#include "Interop/Interop.hpp"
#include "Localisation/FormatArguments.hpp"
#include "Localisation/StringIds.h"
#include "Map/BuildingElement.h"
Expand All @@ -24,6 +23,7 @@
#include "Ui/WindowManager.h"
#include "Vehicles/Vehicle.h"
#include "ViewportManager.h"
#include <OpenLoco/Interop/Interop.hpp>
#include <OpenLoco/Math/Bound.hpp>
#include <OpenLoco/Utility/Numeric.hpp>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/CompanyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "GameState.h"
#include "GameStateFlags.h"
#include "Graphics/Colour.h"
#include "Interop/Interop.hpp"
#include "Localisation/FormatArguments.hpp"
#include "Map/Tile.h"
#include "Map/TileManager.h"
Expand All @@ -27,6 +26,7 @@
#include "Ui/WindowManager.h"
#include "Vehicles/Vehicle.h"
#include "Vehicles/VehicleManager.h"
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;
using namespace OpenLoco::Ui;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "ConfigConvert.hpp"
#include "Environment.h"
#include "Input/ShortcutManager.h"
#include "Interop/Interop.hpp"
#include <OpenLoco/Core/FileSystem.hpp>
#include <OpenLoco/Interop/Interop.hpp>
#include <fstream>
#include <yaml-cpp/yaml.h>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Date.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Date.h"
#include "GameState.h"
#include "Interop/Interop.hpp"
#include <OpenLoco/Interop/Interop.hpp>
#include <limits>
#include <utility>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Drawing/SoftwareDrawingContext.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "SoftwareDrawingContext.h"
#include "DrawSprite.h"
#include "Graphics/ImageIds.h"
#include "Interop/Interop.hpp"
#include "Ui.h"
#include "Ui/WindowManager.h"
#include <OpenLoco/Interop/Interop.hpp>
#include <SDL2/SDL.h>
#include <algorithm>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Drawing/SoftwareDrawingEngine.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "SoftwareDrawingEngine.h"
#include "Interop/Interop.hpp"
#include "Ui.h"
#include "Ui/WindowManager.h"
#include <OpenLoco/Interop/Interop.hpp>
#include <SDL2/SDL.h>
#include <algorithm>

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Economy/Economy.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "Economy.h"
#include "CompanyManager.h"
#include "GameState.h"
#include "Interop/Interop.hpp"
#include "Objects/CargoObject.h"
#include "Objects/ObjectManager.h"
#include "Ui/WindowManager.h"
#include "Ui/WindowType.h"
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/EditorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "GameCommands/GameCommands.h"
#include "GameState.h"
#include "GameStateFlags.h"
#include "Interop/Interop.hpp"
#include "Localisation/StringIds.h"
#include "Objects/BuildingObject.h"
#include "Objects/CargoObject.h"
Expand All @@ -18,6 +17,7 @@
#include "ScenarioObjective.h"
#include "TownManager.h"
#include "Ui/WindowManager.h"
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;
using namespace OpenLoco::Ui;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Entities/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include "Config.h"
#include "EntityManager.h"
#include "Graphics/Gfx.h"
#include "Interop/Interop.hpp"
#include "Ui/WindowManager.h"
#include "ViewportManager.h"
#include <OpenLoco/Interop/Interop.hpp>
#include <algorithm>

using namespace OpenLoco;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Entities/EntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include "GameCommands/GameCommands.h"
#include "GameState.h"
#include "GameStateFlags.h"
#include "Interop/Interop.hpp"
#include "Localisation/StringIds.h"
#include "Map/Tile.h"
#include "SceneManager.h"
#include "Vehicles/Vehicle.h"
#include <OpenLoco/Core/LocoFixedVector.hpp>
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Environment.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Environment.h"
#include "Config.h"
#include "Interop/Interop.hpp"
#include "Platform/Platform.h"
#include "Ui.h"
#include <OpenLoco/Interop/Interop.hpp>
#include <OpenLoco/Utility/Collection.hpp>
#include <OpenLoco/Utility/String.hpp>
#include <cstring>
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "GameState.h"
#include "GameStateFlags.h"
#include "Input.h"
#include "Interop/Interop.hpp"
#include "Localisation/StringIds.h"
#include "MultiPlayer.h"
#include "Objects/ObjectIndex.h"
Expand All @@ -18,6 +17,7 @@
#include "Ui/ProgressBar.h"
#include "Ui/WindowManager.h"
#include "Ui/WindowType.h"
#include <OpenLoco/Interop/Interop.hpp>

namespace OpenLoco::Game
{
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/GameCommands/ChangeCompanyFace.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "CompanyManager.h"
#include "GameCommands.h"
#include "Interop/Interop.hpp"
#include "Localisation/StringIds.h"
#include "Objects/CompetitorObject.h"
#include "Objects/ObjectManager.h"
#include "Ui/WindowManager.h"
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/GameCommands/Cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "Economy/Currency.h"
#include "Entities/EntityManager.h"
#include "GameCommands.h"
#include "Interop/Interop.hpp"
#include "Map/RoadElement.h"
#include "Map/TileManager.h"
#include "Map/TrackElement.h"
Expand All @@ -15,6 +14,7 @@
#include "Types.hpp"
#include "Ui/WindowManager.h"
#include "Vehicles/Vehicle.h"
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;
using namespace OpenLoco::Map;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/GameCommands/GameCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "Company.h"
#include "Economy/Currency.h"
#include "Entities/Entity.h"
#include "Interop/Interop.hpp"
#include "Map/Tile.h"
#include "Objects/Object.h"
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/GameCommands/RenameCompanyName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include "Engine/Limits.h"
#include "GameCommands.h"
#include "Graphics/Gfx.h"
#include "Interop/Interop.hpp"
#include "Localisation/FormatArguments.hpp"
#include "Localisation/StringIds.h"
#include "Localisation/StringManager.h"
#include "Types.hpp"
#include <OpenLoco/Interop/Interop.hpp>

using namespace OpenLoco::Interop;

Expand Down

0 comments on commit b111a1f

Please sign in to comment.