How about NWN style HP??(high end random)

Discussion in 'General Modification' started by bradrinwi, Sep 8, 2005.

Remove all ads!
  1. bradrinwi

    bradrinwi Established Member

    Joined:
    Mar 18, 2005
    Messages:
    226
    Likes Received:
    0
    anyone able to whip up a script /mod for high end random hp?)

    d6 4-6 d8 5-8 etc it still leaves in some of the randomness

    maybe have an option to do the same for npcs? or critters/bad guys

    where would i look maybe something i could tackle myself??
     
  2. Cerulean the Blue

    Cerulean the Blue Blue Meanie Veteran

    Joined:
    Apr 23, 2005
    Messages:
    1,962
    Likes Received:
    0
    I find giving the NPCs (which includes all baddies and monsters) max hp more than makes up for my PCs having max hp. I find it makes the battles harder.
     
  3. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,655
    Likes Received:
    352
    Drifter (who did the original maxHP thing) mentioned a while back it would be easy to do - '10 letters' or something I think was his estimate, but I'm not a .dll hacker. And I tried very hard to be :(
     
  4. Drifter

    Drifter Established Member

    Joined:
    Dec 24, 2004
    Messages:
    118
    Likes Received:
    1
    As I said in other threads on this topic (NWN style HP on level up , Max HP/Level? etc.), yes, it's doable.
    But since it's impossible to please everyone in such matters, I chose the easier way of "leave-or-max". Very simple to implement too, basically a banal 5 byte fix disabling the call to the diceroller function.
    For what you want, I thought of two possible ways to implement it. First one would be playing it safe. The principle is obvious and doesn't really present any programming challenge, but it simply requires more stuff to write in and I thought it tedious. Second approach is more bold, comes very close to Max version in number of bytes needed to change, but possibly risky because it skips most of the error protection measures and therefore could crash. So it would need some additional debugging to do to check everything is right, and I decided against it, because for me tracing through code isn't the most exciting thing to do. Besides I wanted Max option anyway. Thing is, I won't be able to check it now neither, because I don't have ToEE installed at the moment (HDD is full of various crap, no free space :)) So if you need it, test it yourself if it crashes or does something weird.

    Make backup copy of temple.dll and open in any hex-editor and make these changes:
    Code:
    (offset: old_byte new_byte)
    
    000733A6: 83 59
    000733A7: C4 50
    000733A8: 04 D1
    000733A9: 50 F8
    000733AA: 6A 40
    000733AB: 01 50
    000733AD: AF 3F
    000733AE: 57 5A
    
    Which, if you're interested,
    changes this
    Code:
    .1007339E: 6A00                         push 000  ;pass 0 as one of params to diceroller
    .100733A0: 50                           push eax  ;
    .100733A1: E8EA080000                   call .010073C90  ;get class dice size, return in eax
    .100733A6: 83C404                       add esp,004 ;fix stack
    .100733A9: 50                           push eax  ;param dice size
    .100733AA: 6A01                         push 001  ;param roll 1 time
    .100733AC: E8AF57FCFF                   call .010038B60  ;diceroller, returns in eax
    .100733B1: 8BE8                         mov ebp,eax
    
    into this
    Code:
    .1007339E: 6A00                         push 000  ;same as before, but redundant now
    .100733A0: 50                           push eax  ;
    .100733A1: E8EA080000                   call .010073C90  ;get class dice size, return in eax
    .100733A6: 59                           pop ecx  ;fix stack and pray that ecx isn't important :P
    .100733A7: 50                           push eax ;param max_value (dice size)
    .100733A8: D1F8                         sar eax,1 ;divide dice by 2...
    .100733AA: 40                           inc eax  ; ...and add 1 to it
    .100733AB: 50                           push eax ;param min_value
    .100733AC: E83F5AFCFF                   call .010038DF0 ;RNG, returns in eax
    .100733B1: 8BE8                         mov ebp,eax
    
    This is done in such way because we don't really need to call generic function diceroller (or whatever you may call it) in our lvlup code. Because the dice is rolled only 1 time, and the hp bonus (or whatever that is) is 0, so we don't need any of diceroller's code, except the very call to RNG. But we can call that on our own nicely. This also solves the problem of modifying min_value, because diceroller always has it as 1, and we can't modify it there coz diceroller is called from other functions too, not only our lvlup...
    If you don't understand any of the ASM above but care to learn, google for "assembler tutorial" or something like that. All this stuff is very basic.

    What hex-editor to use? - I use Hiew. It has ASM view (Decode mode, which you can switch with F4) which is essential for assembly coding or even if you simply want to see any of the code snippets posted above.

    If anyone who tries it bumps into some problem or finds a bug, post here. As I said, I can't check it myself, I can only provide theoretical help.
     
  5. bradrinwi

    bradrinwi Established Member

    Joined:
    Mar 18, 2005
    Messages:
    226
    Likes Received:
    0
    cool once translated i followed that been a long long time since i read 6502 assm and other hardware mysterys or browsed my beaten up copy of cpm vrs VAX asm..

    cica 1974-76 time of the pdp 8-11

    anyways.. one question isnt hp bnus the same as con bonus?
    to hp??
    you mentioned leaving it at 0..but wondered if it was =to con hp bonus youd need a call??

    )
     
  6. Drifter

    Drifter Established Member

    Joined:
    Dec 24, 2004
    Messages:
    118
    Likes Received:
    1
    No, not exactly the same.
    It's just some bonus, because that diceroller function is used in many places for rolling the dice - pretty much everywhere (combat rolls, saves, skillchecks etc.)
    If we say that generally the dice is:
    XdY+Z (for example 2d6+4),
    so I was talking about the Z. Which in our case of HP rolling would be CON bonus indeed in terms of P&P, but the game is coded in such way that it adds ability/skill bonuses separately elsewhere, and so here it passes it to diceroller as 0. [Although for NPCs HD value (not Class, but monster HD) it could be something other if set in protos.tab (Column162 in phalzyr's editor). So if you'd want to implement such "high end random" for monster HD too, you'd have to keep that in mind when coding it.]
    If you look into that asm snippet I posted before, it's like this:
    Code:
    push 0     ;Z
    ...
    push eax   ;Y
    push 1     ;X
    call diceroller
    ...
    add esp, 0c
    
    And doing addition of 0 is as good as doing nothing. :)
    And X=1, so the RNG would be called only once and we don't need to loop it.
    So if you examine the diceroller function (starting at .010038B60), you'd see that all it does in our case is call RNG to roll the dice 1dY once, which we can do fine on our own (besides we need to change the min from 1 to (y/2+1) ). The only other good thing that diceroller does which we don't, is saving/restoring some registers (ebx, edi, esi), so that's why I said it's risky. Because if those registers stored something important and it gets overwritten with some other stuff and program reads it later hoping to find the old value, it's a trouble. Same for ECX which I used to fix the stack pointer instead of the usual way "add esp, x" to free up 2 bytes for extra code. So if our new code causes some problems it's because of that and we would have to do something about it (add the "saving before the call /restoring after it" stuff, which wouldn't be hard). I didn't do it yet because it would require more work trying to fit everything in, and I hope it won't cause problems, from what I've seen, the RNG function should be doing register save/restore too (that's just how compiller usually work, overprotection), besides the program doesn't read them afterwards, just writes into them (although I'm not totally sure about that).
     
    Last edited: Sep 9, 2005
  7. bradrinwi

    bradrinwi Established Member

    Joined:
    Mar 18, 2005
    Messages:
    226
    Likes Received:
    0
    gotcha was thinking in game terms makes sense dice roller would be a generic one size fits all routine..
     
Our Host!