1#define DTTR_SDK_ENABLE_UNSTABLE
13static uint8_t
sig_target[] = {0x55, 0x8B, 0xEC, 0x90, 0x90, 0xC3, 0x33, 0xC0};
23 const size_t len = strlen(mask);
24 if (!len || len >
size) {
28 for (
size_t offset = 0; offset + len <=
size; offset++) {
30 for (
size_t i = 0; i < len; i++) {
31 if (mask[i] ==
'x' && (uint8_t)sig[i] != bytes[offset + i]) {
38 return (uintptr_t)&bytes[offset];
45static uintptr_t
sigscan(HMODULE mod,
const char *sig,
const char *mask) {
61 .game_module = (HMODULE)1,
77 assert_ptr_equal((
void *)addr, &
sig_target[1]);
87 const uint8_t first_original[] = {0x10, 0x20, 0x30, 0x40};
88 const uint8_t first_patch[] = {0xA0, 0xB0, 0xC0, 0xD0};
89 const uint8_t added_original[] = {0x01, 0x02};
90 const uint8_t added_patch[] = {0x90, 0x90};
93 memcpy(
patch_target, first_original,
sizeof(first_original));
112 .patch_bytes = added_patch,
113 .patch_size =
sizeof(added_patch),
118 .aob =
"AA BB CC DD",
119 .patch_bytes = added_patch,
120 .patch_size =
sizeof(added_patch),
132 assert_memory_equal(
patch_target, first_patch,
sizeof(first_patch));
136 assert_memory_equal(
patch_target, first_original,
sizeof(first_original));
141 const char *filename,
162 void *movie_key_state_original =
NULL;
163 void *
const replacement = (
void *)0x33333333u;
186 ->PatchSpec(
false, replacement, &movie_key_state_original);
188 assert_false(movie_key_state.
required);
193 assert_ptr_equal(movie_key_state.
new_value, replacement);
194 assert_ptr_equal(movie_key_state.
out_original, &movie_key_state_original);
210 assert_ptr_equal(file_open.
out_original, &file_open_original);
225 assert_ptr_equal(
cleanup.out_original, &cleanup_original);
231 void *handle1_original =
NULL;
232 void *handle0_original =
NULL;
233 void *
const replacement1 = (
void *)0x11111111u;
234 void *
const replacement0 = (
void *)0x22222222u;
244 assert_ptr_equal(handle1.
new_value, replacement1);
245 assert_ptr_equal(handle1.
out_original, &handle1_original);
255 assert_ptr_equal(handle0.
new_value, replacement0);
256 assert_ptr_equal(handle0.
out_original, &handle0_original);
261 {
"core-sdk-patch-group-rollback",
263 {
"pcdogs-generated-function-patch-specs",
265 {
"pcdogs-generated-title-resource-patch-specs",
static void cleanup(DTTR_BackendState *state)
DTTR_Graphics_COM_Direct3DDevice7 DWORD block DTTR_Graphics_COM_Direct3DDevice7 DWORD block DTTR_Graphics_COM_Direct3DDevice7 void void void void DWORD f BOOL
const DTTR_BackendState * state
DTTR_Graphics_COM_DirectDrawSurface7 DWORD flags void NULL
static const DTTR_TestCase TEST_CASES[]
@ DTTR_TARGET_ADDRESS_PATCH
struct DTTR_Core_PatchGroup DTTR_Core_PatchGroup
DTTR_PCDOGS_API const struct dttr_pcdogs_function_accessor_DDraw_CreateEx *const DTTR_PCDOGS_F_DDraw_CreateEx
Accessor object for DDraw_CreateEx.
DTTR_PCDOGS_API const struct dttr_pcdogs_function_accessor_File_Open *const DTTR_PCDOGS_F_File_Open
Accessor object for File_Open.
GUID DTTR_PCDOGS_T_Win32_GUID
Win32 GUID value used by DirectDraw import entries.
@ DTTR_PCDOGS_DATA_TITLE_RESOURCE_HANDLE1
@ DTTR_PCDOGS_DATA_TITLE_RESOURCE_HANDLE0
@ DTTR_PCDOGS_DATA_VIDEO_PLAY_MOVIE_LOOP_GET_ASYNC_KEY_STATE_THUNK
BOOL(* DTTR_PCDOGS_F_Title_CleanupScreenResources_proto)()
HRESULT(* DTTR_PCDOGS_F_DDraw_CreateEx_proto)(DTTR_PCDOGS_T_Win32_GUID *lp_guid, void **lplp_dd, DTTR_PCDOGS_T_Win32_GUID *iid, DTTR_PCDOGS_T_COM_IUnknown *p_unk_outer)
DTTR_PCDOGS_API const struct DTTR_PCDOGS_D_Title_ResourceHandle1_type *const DTTR_PCDOGS_D_Title_ResourceHandle1
@ DTTR_PCDOGS_PATCH_DATA_POINTER_HOOK
@ DTTR_PCDOGS_PATCH_FUNCTION_HOOK
DTTR_PCDOGS_API const struct DTTR_PCDOGS_D_Video_PlayMovieLoop_GetAsyncKeyStateThunk_type *const DTTR_PCDOGS_D_Video_PlayMovieLoop_GetAsyncKeyStateThunk
DTTR_PCDOGS_API const struct DTTR_PCDOGS_D_Title_ResourceHandle0_type *const DTTR_PCDOGS_D_Title_ResourceHandle0
@ DTTR_PCDOGS_FUNCTION_FILE_OPEN
@ DTTR_PCDOGS_FUNCTION_TITLE_CLEANUP_SCREEN_RESOURCES
@ DTTR_PCDOGS_FUNCTION_DDRAW_CREATE_EX
DTTR_PCDOGS_API const struct dttr_pcdogs_function_accessor_Title_CleanupScreenResources *const DTTR_PCDOGS_F_Title_CleanupScreenResources
Accessor object for Title_CleanupScreenResources.
DTTR_PCDOGS_T_File_Handle *(* DTTR_PCDOGS_F_File_Open_proto)(char const *filename, char const *mode)
struct DTTR_PCDOGS_T_COM_IUnknown DTTR_PCDOGS_T_COM_IUnknown
@ DTTR_ERR_INVALID_ARGUMENT
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)
void DTTR_Core_HookCleanupAll()
Detach all remaining hooks and free the sigscan cache.
void DTTR_Core_HookDetach(DTTR_Core_Hook *hook)
bool DTTR_Core_HookDetachChecked(DTTR_Core_Hook *hook)
#define DTTR_TEST_ARRAY_COUNT(TESTS)
#define DTTR_TEST_MAIN(TESTS)
DTTR_Result DTTR_Core_PatchGroupDestroy(DTTR_Core_PatchGroup *group)
DTTR_Result DTTR_Core_SignatureFind(const DTTR_Core_Context *ctx, const char *sig, const char *mask, uintptr_t *out_addr)
DTTR_Result DTTR_Core_PatchGroupCreate(const DTTR_Core_Context *ctx, DTTR_Core_PatchGroup **out_group)
bool DTTR_ResultOK(DTTR_Result result)
DTTR_Result DTTR_Core_AOBFind(const DTTR_Core_Context *ctx, const char *aob, uintptr_t *out_addr)
DTTR_Result DTTR_Core_PatchGroupInstallTargets(DTTR_Core_PatchGroup *group, const DTTR_Core_TargetSpec *targets, size_t target_count, DTTR_Core_TargetReport *out_report)
DTTR_Result DTTR_Core_PatchGroupPatchBytes(DTTR_Core_PatchGroup *group, uintptr_t address, const uint8_t *bytes, size_t size, DTTR_Core_Patch **out_patch)
static void test_patch_group_target_failure_rolls_back_only_new_entries(void **state)
static void test_pcdogs_unstable_patch_specs_match_stable_shape(void **state)
static uintptr_t sigscan(HMODULE mod, const char *sig, const char *mask)
static uint8_t group_patch_target[2]
static uint8_t sig_target[]
static uintptr_t sigscan_bytes(const uint8_t *bytes, size_t size, const char *sig, const char *mask)
static HRESULT pcdogs_ddraw_create_ex_detour(DTTR_PCDOGS_T_Win32_GUID *guid, void **ddraw_out, DTTR_PCDOGS_T_Win32_GUID *iid, DTTR_PCDOGS_T_COM_IUnknown *outer)
static uint8_t patch_target[4]
static const DTTR_Core_API RUNTIME
static void test_pcdogs_generated_function_patch_specs_name_current_hooks(void **state)
static void test_signature_helpers_resolve_aob_patterns(void **state)
static DTTR_PCDOGS_T_File_Handle * pcdogs_file_open_detour(const char *filename, const char *mode)
static BOOL pcdogs_cleanup_title_resources_detour()
static DTTR_Core_Context runtime_context()
static void test_pcdogs_generated_title_resource_patch_specs_use_current_names(void **state)
CRT-compatible file handle layout, used by package and asset loading streams.
DTTR_PCDOGS_T_Data_ID global
DTTR_PCDOGS_T_Function_ID function
DTTR_PCDOGS_T_Patch_Kind kind