Add RED4ext logging shim
This commit is contained in:
@@ -3,3 +3,5 @@ __pycache__/
|
|||||||
*.pyc
|
*.pyc
|
||||||
/work/
|
/work/
|
||||||
/work-*.txt
|
/work-*.txt
|
||||||
|
/build/
|
||||||
|
/vendor/
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# RED4ext logging shim
|
||||||
|
|
||||||
|
`EdgeWeightGPS` is a minimal RED4ext plugin used to verify a native logging foothold without changing gameplay data.
|
||||||
|
|
||||||
|
It writes `EdgeWeightGPS.log` beside the installed DLL:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Cyberpunk 2077/red4ext/plugins/EdgeWeightGPS/EdgeWeightGPS.log
|
||||||
|
```
|
||||||
|
|
||||||
|
Current behavior:
|
||||||
|
|
||||||
|
- Logs plugin load/unload.
|
||||||
|
- Logs the RED4ext plugin handle and SDK pointer value passed to `Main`.
|
||||||
|
- Does not call game RTTI or register script functions.
|
||||||
|
|
||||||
|
Planned next step:
|
||||||
|
|
||||||
|
- Build a richer RTTI/hooking variant with an MSVC-compatible Windows toolchain or a narrower hand-written SDK surface. The upstream RED4ext SDK headers build under MinGW for loader-only use, but the full SDK/static library currently pulls in generated native/GPU structures with MSVC layout assumptions.
|
||||||
|
|
||||||
|
Build and install from the Fedora toolbox:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
toolbox run -c 2077 ./tools/install_red4ext_shim.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This shim is read-only. It does not enable any of the archived traffic data patches.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.21)
|
||||||
|
|
||||||
|
project(EdgeWeightGPS VERSION 0.1.0 LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
add_library(EdgeWeightGPS SHARED src/Main.cpp)
|
||||||
|
target_include_directories(
|
||||||
|
EdgeWeightGPS
|
||||||
|
PRIVATE
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/include"
|
||||||
|
"${CMAKE_CURRENT_LIST_DIR}/../../vendor/RED4ext.SDK/include"
|
||||||
|
)
|
||||||
|
target_compile_definitions(EdgeWeightGPS PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
|
||||||
|
target_compile_options(EdgeWeightGPS PRIVATE -fmax-errors=12)
|
||||||
|
|
||||||
|
set_target_properties(
|
||||||
|
EdgeWeightGPS
|
||||||
|
PROPERTIES
|
||||||
|
PREFIX ""
|
||||||
|
OUTPUT_NAME "EdgeWeightGPS"
|
||||||
|
)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
set(CMAKE_SYSTEM_NAME Windows)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||||
|
|
||||||
|
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||||
|
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
||||||
|
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||||
|
|
||||||
|
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <RED4ext/RTTI/ERTTIType.hpp>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <RED4ext/RTTI/IType-inl.hpp>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <RED4ext/RTTI/IType.hpp>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include_next <windows.h>
|
||||||
|
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
extern "C" inline char InterlockedExchange8(volatile char* aTarget, char aValue)
|
||||||
|
{
|
||||||
|
return __atomic_exchange_n(aTarget, aValue, __ATOMIC_SEQ_CST);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" inline char _InterlockedExchangeAdd8(volatile char* aTarget, char aValue)
|
||||||
|
{
|
||||||
|
return __atomic_fetch_add(aTarget, aValue, __ATOMIC_SEQ_CST);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
#include <RED4ext/Api/ApiVersion.hpp>
|
||||||
|
#include <RED4ext/Api/v1/EMainReason.hpp>
|
||||||
|
#include <RED4ext/Api/v1/PluginHandle.hpp>
|
||||||
|
#include <RED4ext/Api/v1/PluginInfo.hpp>
|
||||||
|
#include <RED4ext/Api/v1/Runtime.hpp>
|
||||||
|
#include <RED4ext/Api/v1/Version.hpp>
|
||||||
|
#include <RED4ext/Common.hpp>
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <mutex>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace RED4ext::v1
|
||||||
|
{
|
||||||
|
struct Sdk;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
HMODULE gModule = nullptr;
|
||||||
|
std::mutex gLogMutex;
|
||||||
|
|
||||||
|
std::filesystem::path GetLogPath()
|
||||||
|
{
|
||||||
|
wchar_t modulePath[MAX_PATH]{};
|
||||||
|
if (gModule && GetModuleFileNameW(gModule, modulePath, MAX_PATH) > 0)
|
||||||
|
{
|
||||||
|
auto path = std::filesystem::path(modulePath);
|
||||||
|
return path.parent_path() / L"EdgeWeightGPS.log";
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::filesystem::path(L"red4ext") / L"plugins" / L"EdgeWeightGPS" / L"EdgeWeightGPS.log";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Log(std::string_view aMessage)
|
||||||
|
{
|
||||||
|
std::lock_guard lock(gLogMutex);
|
||||||
|
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto time = std::chrono::system_clock::to_time_t(now);
|
||||||
|
std::tm localTime{};
|
||||||
|
localtime_s(&localTime, &time);
|
||||||
|
|
||||||
|
std::ofstream out(GetLogPath(), std::ios::app);
|
||||||
|
if (!out)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
out << std::put_time(&localTime, "%Y-%m-%d %H:%M:%S") << " " << aMessage << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* ReasonToString(RED4ext::v1::EMainReason aReason)
|
||||||
|
{
|
||||||
|
switch (aReason)
|
||||||
|
{
|
||||||
|
case RED4ext::v1::EMainReason::Load:
|
||||||
|
return "Load";
|
||||||
|
case RED4ext::v1::EMainReason::Unload:
|
||||||
|
return "Unload";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL APIENTRY DllMain(HMODULE aModule, DWORD aReason, LPVOID)
|
||||||
|
{
|
||||||
|
if (aReason == DLL_PROCESS_ATTACH)
|
||||||
|
{
|
||||||
|
gModule = aModule;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
RED4EXT_C_EXPORT bool RED4EXT_CALL Main(RED4ext::v1::PluginHandle aHandle, RED4ext::v1::EMainReason aReason,
|
||||||
|
const RED4ext::v1::Sdk* aSdk)
|
||||||
|
{
|
||||||
|
std::ostringstream line;
|
||||||
|
line << "EdgeWeightGPS Main reason=" << ReasonToString(aReason) << " handle=" << aHandle << " sdk=" << aSdk;
|
||||||
|
Log(line.str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
RED4EXT_C_EXPORT void RED4EXT_CALL Query(RED4ext::v1::PluginInfo* aInfo)
|
||||||
|
{
|
||||||
|
aInfo->name = L"EdgeWeightGPS";
|
||||||
|
aInfo->author = L"salt+Codex";
|
||||||
|
aInfo->version = RED4ext::v1::SemVer{0, 1, 0, {0, 0}};
|
||||||
|
aInfo->runtime = RED4ext::v1::FileVer{3, 0, 80, 51928};
|
||||||
|
aInfo->sdk = RED4ext::v1::SemVer{RED4EXT_VER_MAJOR, RED4EXT_VER_MINOR, RED4EXT_VER_PATCH, {0, 0}};
|
||||||
|
}
|
||||||
|
|
||||||
|
RED4EXT_C_EXPORT uint32_t RED4EXT_CALL Supports()
|
||||||
|
{
|
||||||
|
return RED4EXT_API_VERSION_1;
|
||||||
|
}
|
||||||
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
plugin_dir="$repo_root/red4ext/EdgeWeightGPS"
|
||||||
|
build_dir="$repo_root/build/red4ext/EdgeWeightGPS-mingw64"
|
||||||
|
sdk_dir="$repo_root/vendor/RED4ext.SDK"
|
||||||
|
|
||||||
|
if [[ ! -f "$sdk_dir/include/RED4ext/Api/v1/PluginInfo.hpp" ]]; then
|
||||||
|
mkdir -p "$repo_root/vendor"
|
||||||
|
git clone --depth 1 https://github.com/WopsS/RED4ext.SDK.git "$sdk_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmake -S "$plugin_dir" -B "$build_dir" \
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE="$plugin_dir/cmake/mingw64-toolchain.cmake" \
|
||||||
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||||
|
cmake --build "$build_dir" --parallel
|
||||||
|
|
||||||
|
printf '%s\n' "$build_dir/EdgeWeightGPS.dll"
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
game_dir="${CYBERPUNK2077_GAME_DIR:-/var/home/salt/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/common/Cyberpunk 2077}"
|
||||||
|
plugin_out="$game_dir/red4ext/plugins/EdgeWeightGPS"
|
||||||
|
|
||||||
|
dll_path="$("$repo_root/tools/build_red4ext_shim.sh" | tail -n 1)"
|
||||||
|
mkdir -p "$plugin_out"
|
||||||
|
install -m 0644 "$dll_path" "$plugin_out/EdgeWeightGPS.dll"
|
||||||
|
|
||||||
|
printf 'Installed %s\n' "$plugin_out/EdgeWeightGPS.dll"
|
||||||
Reference in New Issue
Block a user