102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
entrypoint.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "dttr_crashdump.h"
#include "graphics/graphics_com_private.h"
#include "inputs/inputs_private.h"
#include <dttr_config.h>
#include <dttr_log.h>
#include <dttr_path.h>
#include <sds.h>
#include <SDL3/SDL.h>
#include "audio/hooks_private.h"
#include "dttr_errors.h"
#include "dttr_hooks.h"
#include "game/hooks_private.h"
#include "graphics/graphics_private.h"
#include "graphics/hooks_private.h"
#include "inputs/hooks_private.h"
#include "movies/hooks_private.h"
#include "movies/movies_private.h"
#include "sidecar_private.h"
#include <dttr_pcdogs.h>
#include <dttr_runtime.h>
#include <xxhash.h>

Go to the source code of this file.

Macros

#define after_sdl_event(event, consumed)
#define REQUIRE_PCDOGS_CALL(expr_)

Enumerations

enum  dttr_startup_movies_result { DTTR_STARTUP_MOVIES_CONTINUE , DTTR_STARTUP_MOVIES_QUIT , DTTR_STARTUP_MOVIES_FAILED }

Functions

static bool dttr_sidecar_store_sds (char *dst, size_t dst_size, sds src)
static bool dttr_sidecar_write_exception_report (const DTTR_Mods_ExceptionReportRequest *request, DTTR_Mods_ExceptionReport *report)
const DTTR_Mods_Contextdttr_sidecar_context ()
const DTTR_Core_Contextdttr_sidecar_runtime_context ()
static void init_sidecar_context (HMODULE game_module, HMODULE sidecar_module)
static bool install_required_sidecar_hooks (const DTTR_Mods_Context *ctx)
static void set_default_exe_hash ()
static void compute_exe_hash ()
static sds get_loader_dir ()
static sds get_config_path ()
static void toggle_fullscreen ()
static bool require_pcdogs_call (const char *name, DTTR_Result result)
void dttr_sidecar_handle_sdl_event (const SDL_Event *event)
void dttr_sidecar_poll_sdl_events ()
static void cleanup_runtime (const DTTR_Mods_Context *ctx)
static bool initialize_pcdogs_runtime (const DTTR_Core_Context *ctx, HWND hwnd)
static bool start_pcdogs_runtime (const DTTR_Core_Context *ctx, HWND hwnd)
static bool tick_main_loop ()
static dttr_startup_movies_result attempt_play_startup_movies ()
static void install_win_main_hook ()
int32_t _stdcall DTTR_Hook_WinMainCallback (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int32_t nCmdShow)
 Callback target for the patched game Window_RunWinMain routine.
BOOL DllMain (HMODULE module, const DWORD reason_for_call, LPVOID reserved)

Variables

HINSTANCE dttr_sidecar_module
char dttr_loader_dir [MAX_PATH]
char dttr_exe_hash [DTTR_EXE_HASH_LENGTH+1]
static HMODULE pc_dogs_module
static DTTR_Mods_Context sidecar_ctx
static const DTTR_Mods_API MOD_API
static const DTTR_Core_API RUNTIME_API

Macro Definition Documentation

◆ after_sdl_event

#define after_sdl_event ( event,
consumed )
Value:
do { \
} while (0)

Definition at line 295 of file entrypoint.c.

Referenced by dttr_sidecar_handle_sdl_event().

◆ REQUIRE_PCDOGS_CALL

#define REQUIRE_PCDOGS_CALL ( expr_)
Value:
require_pcdogs_call(#expr_, (expr_))
static bool require_pcdogs_call(const char *name, DTTR_Result result)
Definition entrypoint.c:300

Definition at line 313 of file entrypoint.c.

Referenced by attempt_play_startup_movies(), DTTR_Hook_WinMainCallback(), dttr_sidecar_handle_sdl_event(), initialize_pcdogs_runtime(), start_pcdogs_runtime(), and tick_main_loop().

Enumeration Type Documentation

◆ dttr_startup_movies_result

Enumerator
DTTR_STARTUP_MOVIES_CONTINUE 
DTTR_STARTUP_MOVIES_QUIT 
DTTR_STARTUP_MOVIES_FAILED 

Definition at line 439 of file entrypoint.c.

Function Documentation

◆ attempt_play_startup_movies()

◆ cleanup_runtime()

◆ compute_exe_hash()

void compute_exe_hash ( )
static

◆ DllMain()

BOOL DllMain ( HMODULE module,
const DWORD reason_for_call,
LPVOID reserved )

◆ DTTR_Hook_WinMainCallback()

int32_t _stdcall DTTR_Hook_WinMainCallback ( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int32_t nCmdShow )

Callback target for the patched game Window_RunWinMain routine.

Definition at line 574 of file entrypoint.c.

References attempt_play_startup_movies(), cleanup(), cleanup_runtime(), compute_exe_hash(), ctx, dttr_backend, dttr_config, DTTR_CONFIG_FILENAME, DTTR_Config_Load(), DTTR_CrashDump_Init(), DTTR_FATAL, dttr_game_data_init(), dttr_graphics_get_device(), dttr_graphics_get_window(), dttr_graphics_init(), dttr_graphics_mod_device_created(), dttr_graphics_mod_device_restored(), dttr_graphics_mod_window_created(), dttr_imgui_init(), dttr_inputs_late_init(), dttr_loader_dir, DTTR_Log_AddFP(), DTTR_LOG_ERROR, DTTR_LOG_INFO, DTTR_Log_SetLevel(), DTTR_LOG_WARN, dttr_mods_init(), dttr_mods_input_mode_changed(), dttr_mods_late_init(), dttr_mods_overlay_visible_changed(), DTTR_Path_CopySds(), DTTR_Path_ResolveRelativeTo(), dttr_pcdogs_crash_symbols_register(), DTTR_PCDOGS_D_Audio_InitializeSystem_DigitalDriver, DTTR_PCDOGS_D_Input_ProcessWindowMessages_ShouldQuit, DTTR_PCDOGS_D_Window_MainHandle, DTTR_PCDOGS_D_Window_ProcessGameProc_Initialized, DTTR_PCDOGS_D_Window_RunWinMain_RenderingEnabled, DTTR_PCDOGS_D_Window_RunWinMain_SecondaryWindowHandle, DTTR_PCDOGS_ResolveAll(), dttr_sidecar_context(), dttr_sidecar_module, dttr_sidecar_poll_sdl_events(), DTTR_STARTUP_MOVIES_FAILED, DTTR_STARTUP_MOVIES_QUIT, get_config_path(), get_loader_dir(), init_sidecar_context(), initialize_pcdogs_runtime(), install_required_sidecar_hooks(), NULL, pc_dogs_module, REQUIRE_PCDOGS_CALL, start_pcdogs_runtime(), and tick_main_loop().

Referenced by install_win_main_hook().

◆ dttr_sidecar_context()

const DTTR_Mods_Context * dttr_sidecar_context ( )

Definition at line 152 of file entrypoint.c.

References sidecar_ctx.

Referenced by DTTR_Hook_WinMainCallback(), DTTR_STORAGE_SLOT(), and init_mod().

◆ dttr_sidecar_handle_sdl_event()

◆ dttr_sidecar_poll_sdl_events()

◆ dttr_sidecar_runtime_context()

◆ dttr_sidecar_store_sds()

bool dttr_sidecar_store_sds ( char * dst,
size_t dst_size,
sds src )
static

Definition at line 42 of file entrypoint.c.

References dst, and src.

Referenced by dttr_sidecar_write_exception_report().

◆ dttr_sidecar_write_exception_report()

◆ get_config_path()

sds get_config_path ( )
static

Definition at line 275 of file entrypoint.c.

References DTTR_CONFIG_FILENAME.

Referenced by DTTR_Hook_WinMainCallback().

◆ get_loader_dir()

sds get_loader_dir ( )
static

Definition at line 260 of file entrypoint.c.

References DTTR_Path_ModuleDir(), dttr_sidecar_module, and NULL.

Referenced by DTTR_Hook_WinMainCallback().

◆ init_sidecar_context()

void init_sidecar_context ( HMODULE game_module,
HMODULE sidecar_module )
static

◆ initialize_pcdogs_runtime()

◆ install_required_sidecar_hooks()

◆ install_win_main_hook()

void install_win_main_hook ( )
static

◆ require_pcdogs_call()

bool require_pcdogs_call ( const char * name,
DTTR_Result result )
static

Definition at line 300 of file entrypoint.c.

References DTTR_LOG_ERROR, DTTR_ResultOK(), and dttr_sidecar_result_detail().

◆ set_default_exe_hash()

void set_default_exe_hash ( )
static

Definition at line 198 of file entrypoint.c.

References dttr_exe_hash.

Referenced by compute_exe_hash().

◆ start_pcdogs_runtime()

bool start_pcdogs_runtime ( const DTTR_Core_Context * ctx,
HWND hwnd )
static

◆ tick_main_loop()

◆ toggle_fullscreen()

void toggle_fullscreen ( )
static

Definition at line 281 of file entrypoint.c.

References dttr_backend, and DTTR_LOG_WARN.

Referenced by dttr_sidecar_handle_sdl_event().

Variable Documentation

◆ dttr_exe_hash

◆ dttr_loader_dir

char dttr_loader_dir[MAX_PATH]

◆ dttr_sidecar_module

HINSTANCE dttr_sidecar_module

Definition at line 35 of file entrypoint.c.

Referenced by DllMain(), DTTR_Hook_WinMainCallback(), and get_loader_dir().

◆ MOD_API

const DTTR_Mods_API MOD_API
static
Initial value:
= {
.log = DTTR_Log,
.log_is_enabled = DTTR_Log_IsEnabled,
.log_unchecked = DTTR_Log_Unchecked,
.struct_size = sizeof(DTTR_Mods_API),
.abi_version = DTTR_SDK_ABI_VERSION,
.write_exception_report = dttr_sidecar_write_exception_report,
}
void DTTR_Log(int level, const char *file, int line, const char *fmt,...)
Definition log.c:125
bool DTTR_Log_IsEnabled(int level)
Definition log.c:79
void DTTR_Log_Unchecked(int level, const char *file, int line, const char *fmt,...)
Definition log.c:136
#define DTTR_SDK_ABI_VERSION
static bool dttr_sidecar_write_exception_report(const DTTR_Mods_ExceptionReportRequest *request, DTTR_Mods_ExceptionReport *report)
Definition entrypoint.c:60

Definition at line 130 of file entrypoint.c.

Referenced by init_sidecar_context().

◆ pc_dogs_module

HMODULE pc_dogs_module
static

◆ RUNTIME_API

const DTTR_Core_API RUNTIME_API
static
Initial value:
= {
.hook_function = DTTR_Core_HookAttachFunction,
.hook_pointer = DTTR_Core_HookAttachPointer,
.patch_bytes = DTTR_Core_HookPatchBytes,
.hook_is_active = DTTR_Core_HookIsActive,
.unhook_checked = DTTR_Core_HookDetachChecked,
.struct_size = sizeof(DTTR_Core_API),
.abi_version = DTTR_SDK_ABI_VERSION,
}
DTTR_Core_Hook * DTTR_Core_HookAttachPointer(uintptr_t addr, void *new_value, void **out_original)
bool DTTR_Core_HookIsActive(DTTR_Core_Hook *hook)
DTTR_Core_Hook * DTTR_Core_HookAttachFunction(uintptr_t addr, int prologue_size, void *handler, void **out_original)
DTTR_Core_Hook * DTTR_Core_HookPatchBytes(uintptr_t addr, const uint8_t *bytes, size_t size)
uintptr_t DTTR_Core_HookCachedSigscan(HMODULE mod, const char *sig, const char *mask)
void DTTR_Core_HookDetach(DTTR_Core_Hook *hook)
bool DTTR_Core_HookDetachChecked(DTTR_Core_Hook *hook)

Definition at line 139 of file entrypoint.c.

Referenced by init_sidecar_context().

◆ sidecar_ctx

DTTR_Mods_Context sidecar_ctx
static