Exemplo n.º 1
0
static void nwn_hook_data (void) {
    unsigned char *p = (unsigned char *)NX_NWN_SEARCH_START, *end = p + 0x8000;

    while (p < end && !(*p == 0x89 && *(p + 1) == 0x1C && *(p + 2) == 0x24 && *(p + 3) == 0xE8))
        p++;

    if (p < end) {
        void *data = *((void **)(p += 10)) - 20;

        nx_log(NX_LOG_NOTICE, 0, "server data segment location found at %p (%p)", p, data);

        NWN_ClientServerMode = data;
        NWN_ExoBase          = data + 4;
        NWN_ExoResMan        = data + 8;
        NWN_VirtualMachine   = data + 12;
        NWN_ScriptCompiler   = data + 16;
        NWN_AppManager       = data + 20;
        NWN_TlkTable         = data + 24;
        NWN_Rules            = data + 28;
        NWN_ExitProgram      = data + 32;
        NWN_ProcessCommand   = data + 36;
        NWN_Interactive      = data + 40;
    } else
        nx_log(NX_LOG_NOTICE, 0, "server data segment location not found");

    /* XXX: these will only work for NWN 1.69 */
    NWN_DebugCombat  = (int32_t *)0x832FBE8;
    NWN_DebugSaves   = (int32_t *)0x832FBEC;
    NWN_DebugSpeed   = (int32_t *)0x832FBF0;
    NWN_DebugHitDice = (int32_t *)0x832FBF4;
}
Exemplo n.º 2
0
static void nwn_hook_callback (int id, void *addr) {
    nx_log(NX_LOG_NOTICE, 0, "%s (%d) found at %p%s",
        nwn_hooks[id].name, id, addr,
        (*(void **)(nwn_hooks[id].func) == NULL ? "" : " (duplicate)"));

    *(void **)(nwn_hooks[id].func) = addr;
}
Exemplo n.º 3
0
static void TweaksSearchCallback(int id, void *addr)
{
    nx_log(NX_LOG_NOTICE, 0, "%s (%d) found at %p%s",
           Table_TweakSignatures[id].name, id, addr,
           (*(void **)Table_TweakSignatures[id].ref == NULL ? "" : " (duplicate)"));

    *(void **)(Table_TweakSignatures[id].ref) = addr;
}
Exemplo n.º 4
0
static int HookFunctions(uintptr_t p)
{
	if (hooked)
		return true;

	nx_log(NX_LOG_INFO, 0, "core: Hooking CServerExoApp__MainLoopInner.");
	NX_HOOK(CServerExoApp__MainLoopInner, 0x080B2050, Hook_MainLoopInner, 9);

	hooked = true;

	return true;
}
Exemplo n.º 5
0
void Func_DumpObject (CGameObject *ob, char *value) {
    int i, j;
    char buf[2048], chbuf[16], prbuf[32], *p;
    unsigned char *dump = (unsigned char *)ob;

    sprintf(buf, "object: %p  tag: %s  type: %d", ob, ob->tag, ob->type);
    p = buf + strlen(buf);

    if (ob->type == 5) {
        sprintf(p, "  creature: %p", ((CNWSCreature *)ob)->cre_stats);
        p = buf + strlen(buf);
    }

    p = stpcpy(p, "\n");

    for (i = 0; i < 16; i++) {
        prbuf[0] = 0;

        for (j = (i * 256); j < ((i + 1) * 256); j++) {
            if (j % 16 == 0) {
                snprintf(chbuf, sizeof(chbuf), "\n0x%04X:  ", j);
                strcat(prbuf, chbuf);
                p = stpcpy(p, prbuf);

                snprintf(prbuf, sizeof(prbuf), "|................|");
            }

            if (j % 8 == 7)
                snprintf(chbuf, sizeof(chbuf), "%02x  ", dump[j]);
            else
                snprintf(chbuf, sizeof(chbuf), "%02x ", dump[j]);

            p = stpcpy(p, chbuf);

            if (dump[j] >= ' ' && dump[j] < 127)
                prbuf[(j % 16) + 1] = dump[j];
        }

        p = stpcpy(p, prbuf);
        p = stpcpy(p, "\n");

        nx_log(NX_LOG_DEBUG, 0, "%s", buf);

        p = buf;
    }
}
Exemplo n.º 6
0
static void TweaksSearchSignatures(void)
{
    int i;

    nx_sig_search_t *sig = nx_sig_search_create(TweaksSearchCallback);

    for (i = 1; Table_TweakSignatures[i].sig != NULL; i++)
        nx_sig_search_add_signature(sig, i, Table_TweakSignatures[i].sig);

    nx_sig_search_run(sig);
    nx_sig_search_destroy(sig);


    for (i = 1; Table_TweakSignatures[i].sig != NULL; i++) {
        if (*(void **)Table_TweakSignatures[i].ref == NULL)
            nx_log(NX_LOG_NOTICE, 0, "%s (%d) not found", Table_TweakSignatures[i].name, i);
    }
}
Exemplo n.º 7
0
void nwn_hook_init (void) {
    int i;

    nwn_hook_data();

    nx_sig_search_t *sig = nx_sig_search_create(nwn_hook_callback);

    for (i = 1; nwn_hooks[i].sig != NULL; i++)
        nx_sig_search_add_signature(sig, i, nwn_hooks[i].sig);

    nx_sig_search_run(sig);
    nx_sig_search_destroy(sig);


    for (i = 1; nwn_hooks[i].sig != NULL; i++) {
        if (*(void **)nwn_hooks[i].func == NULL)
            nx_log(NX_LOG_NOTICE, 0, "%s (%d) not found", nwn_hooks[i].name, i);
    }
}
Exemplo n.º 8
0
void nx_log_exception(nx_logmodule_t		logmodule,
		      const nx_exception_t	*e,
		      const char		*fmt,
		      ...)
{
    int i;
    char errmsg[1024];
    nx_loglevel_t loglevel = NX_LOGLEVEL_ERROR;
    nx_ctx_t *ctx;
    nx_string_t *tmpstr;
    boolean empty = TRUE;
    int size;

    ASSERT(e != NULL);
    ASSERT(e->num_throw > 0);

    ctx = nx_ctx_get();
    if ( ctx != NULL )
    {
	loglevel = ctx->loglevel;
    }

    tmpstr = nx_string_new();

    if ( fmt != NULL )
    {
	va_list ap;

	va_start(ap, fmt);
	size = apr_vsnprintf(errmsg, sizeof(errmsg), fmt, ap);
	va_end(ap);
	nx_string_append(tmpstr, errmsg, size);
	empty = FALSE;
    }

    if ( loglevel == NX_LOGLEVEL_DEBUG )
    {
        if ( (e->caused_by)[0] != '\0' )
	{
	    ASSERT(e->num_throw > 0);
	    i = (int) (e->num_throw) - 1;
	    if ( empty != TRUE )
	    {
		nx_string_append(tmpstr, NX_LINEFEED, -1);
	    }
	    size = apr_snprintf(errmsg, sizeof(errmsg), 
				"Exception was caused by \"%s\" at %s:%d/%s()", 
				e->caused_by, e->throwlist[i].file,
				e->throwlist[i].line, e->throwlist[i].func);
	    nx_string_append(tmpstr, errmsg, size);
	    empty = FALSE;
	}
    }
    for ( i = ((int) e->num_throw) - 1; i >= 0; i-- )
    {
	if ( loglevel == NX_LOGLEVEL_DEBUG )
	{
	    if ( e->throwlist[i].msgoffs < 0 )
	    {
		if ( empty != TRUE )
		{
		    nx_string_append(tmpstr, NX_LINEFEED, -1);
		}
		size = apr_snprintf(errmsg, sizeof(errmsg), 
				    "[%s:%d/%s()] -",
				    e->throwlist[i].file, e->throwlist[i].line,
				    e->throwlist[i].func);
		nx_string_append(tmpstr, errmsg, size);
		empty = FALSE;
	    }
	    else
	    {
		if ( empty != TRUE )
		{
		    nx_string_append(tmpstr, NX_LINEFEED, -1);
		}
		size = apr_snprintf(errmsg, sizeof(errmsg), 
				    "[%s:%d/%s()] %s",
				    e->throwlist[i].file, e->throwlist[i].line,
				    e->throwlist[i].func, e->msgbuf + e->throwlist[i].msgoffs);
		nx_string_append(tmpstr, errmsg, size);
		empty = FALSE;
	    }
	}
	else
	{
	    if ( e->throwlist[i].msgoffs < 0 )
	    {
	    }
	    else
	    {
		if ( empty != TRUE )
		{
		    nx_string_append(tmpstr, NX_LINEFEED, -1);
		}
		nx_string_append(tmpstr, e->msgbuf + e->throwlist[i].msgoffs, -1);
		empty = FALSE;
	    }
	}
    }

    if ( e->code != APR_SUCCESS )
    {
	apr_strerror(e->code, errmsg, sizeof(errmsg));
	if ( empty != TRUE )
	{
	    nx_string_append(tmpstr, NX_LINEFEED, -1);
	}
	nx_string_append(tmpstr, errmsg, -1);
	empty = FALSE;
    }

    nx_log(e->code, NX_LOGLEVEL_ERROR, logmodule, "%s", tmpstr->buf);
    nx_string_free(tmpstr);
}