Temple+ Modding Question

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

Remove all ads!
  1. _doug_

    _doug_ Established Member

    Joined:
    Jul 9, 2009
    Messages:
    290
    Likes Received:
    117
    I tried to add a python function to get the turn based status in order to do the same things being done in a section of decompiled code (0x100cd0a0). When I called my function on condition add, memory got corrupted and TOEE later crashed. Any idea what I am doing wrong?

    m.def("cur_seq_get_turn_based_status", []() {
    return actSeqSys.curSeqGetTurnBasedStatus();
    });

    Thanks!
     
  2. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    3,613
    Likes Received:
    537
    Well you should make sure the current sequence pointer is valid if that func isn't doing that internally.
     
  3. _doug_

    _doug_ Established Member

    Joined:
    Jul 9, 2009
    Messages:
    290
    Likes Received:
    117
    Definitely agree there should be a validity check if I add the function (should I return null and check the value in python?). The problem is that the function is returning an invalid pointer in add condition when similar code in the Temple DLL does not seem to do that. Do you know why this pointer would be bad when adding a spell condition?
     
  4. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    3,613
    Likes Received:
    537
    No idea. Can provide more detail?
     
  5. _doug_

    _doug_ Established Member

    Joined:
    Jul 9, 2009
    Messages:
    290
    Likes Received:
    117
    Sure. I am trying to recreate the following functionality from the DLL in python for a spell condition:

    //----- (100CD0A0) --------------------------------------------------------
    int __cdecl TouchAttackOnAdd(Dispatcher_Callback_Args a1)
    {
    TurnBasedStatus *v1; // eax@1
    int v2; // eax@1

    v1 = CurSeqGetTurnBasedStatus();
    v1->tbsFlags |= D20CAF_ACTIONFRAME_PROCESSED;
    v2 = CondNodeGetArg(a1.subDispNode->condNode, 0);
    d20SendSignal(a1.objHndCaller, Disp_Key_S_TouchAttackAdded, v2, 0);
    return 0;
    }

    I wrote the C++ function I showed you earlier:

    m.def("cur_seq_get_turn_based_status", []() {
    return actSeqSys.curSeqGetTurnBasedStatus();
    });

    I use it in python as follows:

    def TouchOfFatigueConditionAdd(attachee, args, evt_obj):
    tbStatus = tpdp.cur_seq_get_turn_based_status()
    tbStatus.flags = tbStatus.flags | D20CAF_ACTIONFRAME_PROCESSED
    attachee.d20_send_signal(S_TouchAttackAdded, 1001, 0)
    return 0

    TouchOfFatigue.AddHook(ET_OnConditionAdd, EK_NONE, TouchOfFatigueConditionAdd, ())

    The function ends up crashing due to the cur_seq_get_turn_based_status() call.
     
  6. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,651
    Likes Received:
    350
    Sorry to interrupt, Doug, but are you going to add fatigue in general? I would love to see it in the game, my understanding is that the fatigue after a barbarian finishes raging is the only thing the game currently recognises.
     
  7. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    3,613
    Likes Received:
    537
    When are you adding the ToF condition? It sounds like it's expected that it's part of a particular action (for the section of code you copied at least).

    Also note that actSeqSys.curSeqGetTurnBasedStatus() can return nullptr, and then python code has no guard against that. What do you see when debugging that?
    To keep things simple and safe you can just have a setter for curseq tbstatus flag that checks this on the c side.
     
  8. _doug_

    _doug_ Established Member

    Joined:
    Jul 9, 2009
    Messages:
    290
    Likes Received:
    117
    The condition gets added to the caster of a spell in OnSpellEffect(). The pointer returned actually looks decent at that point but when the python object gets destroyed it takes out TOEE. I also rigged something up to call the function at 100CD0A0 in python directly and it also blows up.

    Ted: yes adding fatigue is my plan. At least for the touch of fatigue spell right now. :)
     
  9. _doug_

    _doug_ Established Member

    Joined:
    Jul 9, 2009
    Messages:
    290
    Likes Received:
    117
    When I changed the code to use get/set turn based flags functions everything worked! Thanks for the help!
     
    Allyx likes this.
  10. Endarire

    Endarire Ronald Rynnwrathi

    Joined:
    Jan 7, 2004
    Messages:
    953
    Likes Received:
    112
    @_doug_
    Do you also plan to add Waves/Ray of Exhaustion and Waves of Fatigue if they aren't already in?
     
    Allyx likes this.
  11. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    3,613
    Likes Received:
    537
    Glad you got it sorted out!
     
    _doug_ likes this.
  12. _doug_

    _doug_ Established Member

    Joined:
    Jul 9, 2009
    Messages:
    290
    Likes Received:
    117
    I am interested in doing those spells and some point. The difficulty would be adding graphics effects and sounds. Anyone interested in helping with sounds and graphics?
     
  13. Allyx

    Allyx Master Crafter Global Moderator Supporter

    Joined:
    Dec 2, 2004
    Messages:
    5,001
    Likes Received:
    250
    @_doug_ There are tools to help with those... but that's about all I know about it.
     
  14. _doug_

    _doug_ Established Member

    Joined:
    Jul 9, 2009
    Messages:
    290
    Likes Received:
    117
    I've seen the tools that are available. My problem is more that I lack artistic skill :(
     
  15. Allyx

    Allyx Master Crafter Global Moderator Supporter

    Joined:
    Dec 2, 2004
    Messages:
    5,001
    Likes Received:
    250
    I believe there are a number of effects already in the game that were never actually used, if you can find one that seems appropriate you should just be able to assign it to your spell.
     
    Last edited: Feb 29, 2020
    _doug_ likes this.
Our Host!