Temple+ Modding Question

Discussion in 'General Modification' started by _doug_, Feb 21, 2018.

Remove all ads!
  1. _doug_

    _doug_ Member

    Joined:
    Jul 9, 2009
    Messages:
    77
    Likes Received:
    2
    That makes sense but I still can't seem to get it to override. I am replacing the function as below but there seems to be no effect. No errors from miniHook and no crashes. The old function gets called the same as before. Any ideas?

    int __cdecl _checkSpellResistance(SpellPacketBody *spellPkt, objHndl objHnd)

    {
    if (!spellPkt || !objHnd) return 0;
    return spellSys.CheckSpellResistance(spellPkt, objHnd);

    }


    int __declspec(naked) _CheckSpellResistanceWrapper(objHndl objHnd)

    {
    __asm { // esi is SpellPacketBody *

    push ebx
    push ebp
    push edi

    mov eax, [ebp + 12];
    push eax;
    mov eax, [ebp + 8];
    push eax;
    push esi;
    mov eax, _checkSpellResistance;
    call eax;
    pop esi;
    add esp, 8;

    pop edi
    pop ebp
    pop ebx
    retn;
    }
    }

    //..............

    auto pFn = replaceFunction (0x100C3810, _CheckSpellResistanceWrapper);
     
  2. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    2,700
    Likes Received:
    81
    Are you saying you don't even hit the breakpoint inside the _CheckSpellResistanceWrapper function? If so that's weird...

    Not sure if related but you need to add mov ebp,esp if you want to use ebp as a stack pointer. (I like doing this because that way the register doesn't change when you do a push)

    Anyway I implemented and tested it myself and it worked fine, so I'll just push the code and you can compare. It's probably something subtle which I'm not seeing at the moment...
     
  3. _doug_

    _doug_ Member

    Joined:
    Jul 9, 2009
    Messages:
    77
    Likes Received:
    2
    Thanks for the help!

    I originally had a more orthodox function with a move ebp,esp instruction. The version I posted was more of a "trying everything" version.:)

    Unfortunately, it is still not working for me. It will not break in that code even after I reverted my changes. I am testing against a vrock and I am seeing the spell resistance message but it is not going into the new code. Any thoughts on what is going wrong? Is there any way I can verify that mini hook is getting its job done? I assume I should see a change in the disassembly at the function's address.
     
  4. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    2,700
    Likes Received:
    81
    How exactly are you testing?

    Note that if you are testing with magic missile, it doesn't go through that function at all. The relevant code is the one that goes through the target list, it's essentially a duplicate of that function (might have been inlined by the original compiler). You can find it via searching for "spell resistance".
     
    Last edited: May 14, 2019
  5. _doug_

    _doug_ Member

    Joined:
    Jul 9, 2009
    Messages:
    77
    Likes Received:
    2
    I see... Looks like that was my problem the whole time. I was testing with color spray, magic missile and ray of frost. I bet all of those get processed in PerformCastSpellProcessTargets(). I may take a shot at replacing that with my own function. It shouldn't be that bad since a lot of that function seems to be checking spell resistance. I assume al as the return value means the first 8 bits of the eax register? I would also need to make a update to spell immunity it seems since the spell resistance spell gets processed there also but it should not be that bad.
     
  6. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    2,700
    Likes Received:
    81
    Eh? It's already effectively replaced, since it only appears in the Perform callback of cast spell and I rewrote that one completely. Look for CastSpellProcessTargets.

    Pretty sure I've also hooked spell immunity.
     
  7. _doug_

    _doug_ Member

    Joined:
    Jul 9, 2009
    Messages:
    77
    Likes Received:
    2
    I hadn't looked through the code thoroughly before my previous comment. Looks like I need to make my change in CastSpellProcessTargets and the spell immunity hook and I will be good to go! Thanks for the help.
     
Our Host!