Files
ReSkate/Extension/Progression/script_error_log.cpp
T
AyeZeeBB b7932535e5 Keep launcher alive through Skate startup; trim per-frame client work
Launcher
- "Close the launcher when Skate starts" now hides the launcher and exits
  when Skate.exe does, instead of exiting as the splash opens. Outside a
  Steam library, Skate's protection closed the game (TerminateProcess 0x32)
  when the launcher exited during startup; players confirmed turning the
  setting off avoided it.
- STATUS tile warns when Steam isn't open or signed in that PLAY starts
  offline as Unknown Player (hidden when Offline mode is chosen or while
  launching).
- Setting description updated to match.
Startup interventions (20260929)
- exit_return 0x87755f2 -> 0x87fe7fb: the last LEA RSP,[RSP]; JMP stub
  before the PUSHFQ / LOCK CMPXCHG routine, as 0x87367cf was in 20260908,
  and the return address player logs show. Only enforced once a frame site
  is armed; this build's protector has no equivalent rep stosb frame clear.
Client frame cost (profiled 2026-10-02)
- Transform interpolate is inline plain arithmetic (~1% of an MP frame).
- Script gameplay-setting and native-setting gets are served from small
  per-thread caches keyed on asset/key address, name prefix and a new
  profile::Store::changes() counter, instead of a store lookup each call.
- Hot-path reads in client tick, native settings and population controls
  use memory::peek instead of ReadProcessMemory.
- Script error logging probes each argument pointer once.
2026-10-02 18:56:57 -05:00

80 lines
4.0 KiB
C++

#include "script_natives.h"
#include "Engine/Core/Log/logging.h"
#include "Engine/Game/Build/addresses.h"
#include "Engine/Game/Build/20260929/script_natives.h"
#include <mutex>
#include <set>
#include <string>
#include "local_challenge_trace.h"
#include "local_entitlement_trigger_runtime.h"
namespace dingosdk::profile_runtime {
namespace {
void script_error(std::uintptr_t, std::uintptr_t*, std::uintptr_t* arguments) {
PreserveError preserve;
// Authored graphs raise the same error every frame, from the same constant text: a text
// pointer already looked at is not read again (each character was a system call).
static std::mutex mutex; static std::set<std::string> seen; static std::set<std::uintptr_t> looked_at, arguments_seen;
std::lock_guard lock(mutex);
try {
// The message position is not known from the binding alone; take the
// first argument that dereferences to readable text.
const auto printable = [](std::uintptr_t at) {
std::string value;
if (looked_at.contains(at)) return value;
if (looked_at.size() < 4096) looked_at.insert(at);
for (std::size_t i = 0; at && i < 400; ++i) {
char c{};
if (!memory::peek(at + i, c) || !c) break; // no system call per character
if (static_cast<unsigned char>(c) < 9 || static_cast<unsigned char>(c) > 126) return std::string{};
value += static_cast<unsigned char>(c) < 32 ? ' ' : c;
}
return value.size() >= 8 ? value : std::string{};
};
std::string message;
for (std::size_t index = 0; arguments && index < 4 && message.empty(); ++index) {
std::uintptr_t argument{}, inner{};
if (!memory::peek(reinterpret_cast<std::uintptr_t>(arguments) + index * 8, argument) || argument < 0x10000) break;
// The same arguments come back every frame: each is probed once (read, not peeked:
// it is often not a pointer, and a failed peek costs an exception).
if (arguments_seen.contains(argument)) continue;
if (arguments_seen.size() < 4096) arguments_seen.insert(argument);
if (read(argument, inner) && inner >= 0x10000) message = printable(inner);
if (message.empty()) message = printable(argument);
}
if (message.empty()) return;
std::uintptr_t resource{}; std::uint32_t graph{};
if (executing_expression) challenge_trace_identity(executing_expression, resource, graph);
// One line per distinct message; authored graphs repeat theirs per frame.
if (seen.size() < 256 && seen.insert(message).second)
logging::log(logging::Level::info, logging::Channel::progression,
"Script error (graph {:#x}): {}", graph, message);
} catch (...) {}
}
}
void install_script_error_log(std::uintptr_t base) noexcept {
static bool attempted{};
if (attempted || !base) return;
attempted = true;
constexpr std::uintptr_t record = addr::script_natives::script_error_record, stub = addr::script_natives::script_error_stub;
try {
std::uint32_t hash{};
if (!read(base + record, hash) || hash != 0xa5910db3) return;
unsigned patched{};
for (const auto offset : {0x30u, 0x40u, 0x48u}) {
std::uintptr_t current{};
const auto slot = base + record + offset;
if (!read(slot, current) || current != base + stub) continue;
DWORD old{};
if (!VirtualProtect(reinterpret_cast<void*>(slot), sizeof(current), PAGE_READWRITE, &old)) continue;
*reinterpret_cast<std::uintptr_t*>(slot) = reinterpret_cast<std::uintptr_t>(&script_error);
VirtualProtect(reinterpret_cast<void*>(slot), sizeof(current), old, &old);
++patched;
}
logging::log(logging::Level::info, logging::Channel::progression,
"Script error log: {} binding slot(s) redirected.", patched);
} catch (...) {}
}
}