summaryrefslogblamecommitdiff
path: root/patch.c
blob: b0a2cf86ba9c2e1ff7fa310efed391e48d7e9900 (plain) (tree)





























                                                                                       















                                                                                                
/*
	Copyright (C) 2020-2021 Reiko Asakura. All Rights Reserved.

	Moonshine
*/

#include <libdbg.h>

#include "patch.h"

/* ARGSUSED */
static int hook_common(SceUID hook_id, const char *name) {
	int ret = SCE_OK;
	if (hook_id < 0) {
		SCE_DBG_LOG_ERROR("Failed to hook %s %08X", name, hook_id);
		ret = hook_id;
	} else {
		SCE_DBG_LOG_INFO("Hooked %s %08X", name, hook_id);
	}
	return ret;
}

int hook_offset(
	SceUID modid, int segidx, int offset, int thumb, void *func,
	SceUID *hook_id, tai_hook_ref_t *hook_ref, const char *name)
{
	*hook_id = taiHookFunctionOffset(hook_ref, modid, segidx, offset, thumb, func);
	return hook_common(*hook_id, name);
}

/* ARGSUSED */
int unhook(SceUID *hook_id, tai_hook_ref_t hook_ref, const char *name) {
	int ret = SCE_OK;
	if (*hook_id < 0) {
		SCE_DBG_LOG_WARNING("Skipped unhooking %s %08X", name, *hook_id);
	} else {
		ret = taiHookRelease(*hook_id, hook_ref);
		if (ret == SCE_OK) {
			SCE_DBG_LOG_INFO("Unhooked %s %08X", name, *hook_id);
			*hook_id = -1;
		} else {
			SCE_DBG_LOG_ERROR("Failed to unhook %s %08X %08X", name, *hook_id, ret);
		}
	}
	return ret;
}