[1.10] Dynamic Health bar

This forum is for discussions on how to edit what can not be edited through the txt files, needless to say this isn't about battle net hacking.

Moderators: Nefarius, Havvoric

Post Reply
User avatar
Ogodei
Senior Moderator
Angel
Posts: 516
Joined: Thu Mar 10, 2016 8:31 am
Italy

Hand-picked

[1.10] Dynamic Health bar

Post by Ogodei » Tue Aug 30, 2016 1:39 pm

Ever played some good old games like Warcraft 2? There are some nice features that could be implemented to Diablo II, as it's the case of a dynamic health bar which changes colour depending on how many hit points the unit has (exactly as the player/hireling/single-pet portraits in the screen).
To achieve this, you have to follow these steps:

In D2Win.dll

Code: Select all

6F8AA83A    6A 10           PUSH 10     <-- nop
6F8AA83C    6A 10           PUSH 10     <-- nop
6F8AA83E    6A 60           PUSH 60     <--- nop
6F8AA840    E8 3B420000     CALL #10034  <-- leave as it is 
replace the NOP's obtained from the push with the following :

Code: Select all

6F8AA83A    E9 97EA0000     JMP 6F8B92D6    <-- jump to ur custom code
6F8AA83F    90                   NOP                  <-- don't touch
6F8AA840    E8 3B420000     CALL #10034      <-- standard leftover, don't touch
Also NOP the JNZ 6F8AA838 above your new JMP (thanks to Xaphan for pointing it out!)

Then go to a custom space in your dll and fill it with the following lines (if your D2Win is untouched - I mean, if you never added custom stuffs in empty space, feel free to use my addresses):

Code: Select all

________________ Custom Code in free space____________________________
Address   Hex dump          Command                                  Comments
6F8B92D6    83F9 50         CMP ECX,50                               ; check if life > 80%
6F8B92D9   7F 0C           JG SHORT 6F8B92E7             ->> jump to green
6F8B92DB    83F9 28         CMP ECX,28                                ; check if life > 40%
6F8B92DE   7F 12           JG SHORT 6F8B92F2              ->> jump to yellow tint            
6F8B92E0    83F9 01         CMP ECX,1                                   ; check if life > 1%
6F8B92E3   EB 18           JMP SHORT 6F8B92FD           ->> jump to red tint   
6F8B92E5    90              NOP
6F8B92E6    90              NOP
6F8B92E7    6A 10           PUSH 10 *
6F8B92E9    6A 60           PUSH 60 *   Green tint
6F8B92EB    6A 10           PUSH 10 *
6F8B92ED   E9 4E15FFFF     JMP 6F8AA840 -> return to the standard code
6F8B92F2    6A 10           PUSH 10 *
6F8B92F4    6A 60           PUSH 60 *   Yellow tint
6F8B92F6    6A 60           PUSH 60 *
6F8B92F8   E9 4315FFFF     JMP 6F8AA840 -> return to the standard code
6F8B92FD    6A 10           PUSH 10 *
6F8B92FF    6A 10           PUSH 10 *    Red tint
6F8B9301    6A 60           PUSH 60 *
6F8B9303   E9 3815FFFF     JMP 6F8AA840 -> return to the standard code
6F8B9308    90              NOP
Here you are :)

This video shows this modification at work :)



P.S: the health bar in the video shows a slightly different code (which I adjusted before posting). Also, keep in mind that this edit does NOT alter your health bar transparency. Mine is altered since I changed another part of code =)

Enjoy!
Last edited by Ogodei on Wed Aug 31, 2016 8:30 pm, edited 3 times in total.

User avatar
Xaphan
Hosted Forum Moderator
Arch-Angel
Posts: 1113
Joined: Fri Oct 08, 2010 10:55 am
France

Re: [1.10] Dynamic Health bar

Post by Xaphan » Wed Aug 31, 2016 6:40 pm

I don't see anything that call your custom code. I'm not the best codder out there, but diden't you missed anything in the 1st part of the code ?

I do like the idea btw. Gj on having this working.


User avatar
Xaphan
Hosted Forum Moderator
Arch-Angel
Posts: 1113
Joined: Fri Oct 08, 2010 10:55 am
France

Re: [1.10] Dynamic Health bar

Post by Xaphan » Wed Aug 31, 2016 7:36 pm

Ok I just tested, the custom code is correctly loaded (changing colors there do work) but no matter how many percent life the ennemy have, it always use the green color code to show it. It is like the game consider that it always have more than 80% life and just there no matter what. Any idea what can cause this ?

Thanks


User avatar
Xaphan
Hosted Forum Moderator
Arch-Angel
Posts: 1113
Joined: Fri Oct 08, 2010 10:55 am
France

Re: [1.10] Dynamic Health bar

Post by Xaphan » Wed Aug 31, 2016 8:22 pm

on your screen I see that you noped the JNZ at 6F8AA838, wich is not in the code you posted above so I haven't it noped. Maybe it's that, I will try.

EDIT : I can confirm that it was the issue. code now work properly :)
Last edited by Xaphan on Wed Aug 31, 2016 8:27 pm, edited 1 time in total.


User avatar
thaison
Junior Member
Paladin
Posts: 108
Joined: Fri Apr 03, 2015 11:59 am
Location: Viet Nam
Vietnam

Re: [1.10] Dynamic Health bar

Post by thaison » Thu Sep 01, 2016 1:17 am

I succeeded in 1.14b
Thank for Ogodei.

Image

Image

Image

jessedazebra
Junior Member
Paladin
Posts: 144
Joined: Sun Nov 11, 2012 9:46 am
Zimbabwe

Re: [1.10] Dynamic Health bar

Post by jessedazebra » Mon Feb 11, 2019 1:19 pm

Hello everyone,
Sorry for resurrecting the old topic, but I thought it'd be better to ask here than creating a new one.

I tried to implement all this code to 1.13c version, did everything the same, but I wasn't surprised it didn't work, not to mention 1.13c code slightly differs from 1.10 code. When I move cursor on enemy I get an unhandled error.

So here's what I did in olly:
Image
Looks pretty much the same, but doesn't work. :-|

User avatar
Necrolis
Senior Admin
Throne
Posts: 9125
Joined: Sat Mar 25, 2006 1:22 pm
Location: The Land of the Dead
Contact:
South Africa

Hand-picked

Re: [1.10] Dynamic Health bar

Post by Necrolis » Mon Feb 11, 2019 3:32 pm

jessedazebra wrote:
Mon Feb 11, 2019 1:19 pm
Hello everyone,
Sorry for resurrecting the old topic, but I thought it'd be better to ask here than creating a new one.

I tried to implement all this code to 1.13c version, did everything the same, but I wasn't surprised it didn't work, not to mention 1.13c code slightly differs from 1.10 code. When I move cursor on enemy I get an unhandled error.

So here's what I did in olly:
Image
Looks pretty much the same, but doesn't work. :-|
You need to jump back to 000134B7, else you will be missing the global palette param to D2FindPaletteIndexForColor (the call to what was D2Win.#10034 got inlined).
Image
Netiquette, Do you USE it?!?! | Nefarius' Fixed TXT Files | Terms Of Service
Blackened | Day of Death | D2GFEx
"What was yours is mine. Your land, your people, and now your life." - Lim-Dul, the Necromancer
Judgement is Final, Death is Eternal

jessedazebra
Junior Member
Paladin
Posts: 144
Joined: Sun Nov 11, 2012 9:46 am
Zimbabwe

Re: [1.10] Dynamic Health bar

Post by jessedazebra » Mon Feb 11, 2019 4:13 pm

Necrolis wrote:
Mon Feb 11, 2019 3:32 pm
You need to jump back to 000134B7, else you will be missing the global palette param to D2FindPaletteIndexForColor (the call to what was D2Win.#10034 got inlined).
Still the same error. Then I tried to jump to 000134B2, but still nothing. I guess this PUSH 100 does something with colors as well, 'cuz it actually changes colors when you use values lower than 100. Also tried this:
Image
Still no success. :(

User avatar
Necrolis
Senior Admin
Throne
Posts: 9125
Joined: Sat Mar 25, 2006 1:22 pm
Location: The Land of the Dead
Contact:
South Africa

Hand-picked

Re: [1.10] Dynamic Health bar

Post by Necrolis » Mon Feb 11, 2019 6:08 pm

jessedazebra wrote:
Mon Feb 11, 2019 4:13 pm
Necrolis wrote:
Mon Feb 11, 2019 3:32 pm
You need to jump back to 000134B7, else you will be missing the global palette param to D2FindPaletteIndexForColor (the call to what was D2Win.#10034 got inlined).
Still the same error. Then I tried to jump to 000134B2, but still nothing. I guess this PUSH 100 does something with colors as well, 'cuz it actually changes colors when you use values lower than 100. Also tried this:
Still no success. :(
You need to check where its crashing, your code now looks correct (and I forgot the PUSH 100, which is the size of the palette you are asking it to search).
Image
Netiquette, Do you USE it?!?! | Nefarius' Fixed TXT Files | Terms Of Service
Blackened | Day of Death | D2GFEx
"What was yours is mine. Your land, your people, and now your life." - Lim-Dul, the Necromancer
Judgement is Final, Death is Eternal

jessedazebra
Junior Member
Paladin
Posts: 144
Joined: Sun Nov 11, 2012 9:46 am
Zimbabwe

Re: [1.10] Dynamic Health bar

Post by jessedazebra » Mon Feb 11, 2019 6:25 pm

Necrolis wrote:
Mon Feb 11, 2019 6:08 pm
You need to check where its crashing, your code now looks correct (and I forgot the PUSH 100, which is the size of the palette you are asking it to search).
It crashes when I move cursor over enemy.
Image
Maybe it crashes because I use wrong place for custom code, I don't know.
I use the first line from the bottom of D2Win when it starts "ADD BYTE PTR DS:[EAX],AL" up to to end.
Image
Edit: I guess you meant to check on which line crash occurs, I feel stupid. :D

User avatar
devurandom
Forum Regular
Angel
Posts: 897
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: [1.10] Dynamic Health bar

Post by devurandom » Mon Feb 11, 2019 8:01 pm

You might have to rebase your D2Win.dll to get those long jumps working. If that's the case then you endup with the so called ALSR bug, really it's not ASLR but a reloc issue, where newer windows OS's forces a relocation on a file that expects not to be relocated.

I'll can add this cool edit of Ogodei's to next version of BaseMod, with option to use it or not.
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

jessedazebra
Junior Member
Paladin
Posts: 144
Joined: Sun Nov 11, 2012 9:46 am
Zimbabwe

Re: [1.10] Dynamic Health bar

Post by jessedazebra » Mon Feb 11, 2019 8:04 pm

devurandom wrote:
Mon Feb 11, 2019 8:01 pm
You might have to rebase your D2Win.dll to get those long jumps working. If that's the case then you endup with the so called ALSR bug, really it's not ASLR but a reloc issue, where newer windows OS's forces a relocation on a file that expects not to be relocated.

I'll can add this cool edit of Ogodei's to next version of BaseMod, with option to use it or not.
Yeah, that sounds cool :)

User avatar
karlock
Posts: 42
Joined: Mon Mar 16, 2015 1:16 pm

Re: [1.10] Dynamic Health bar

Post by karlock » Thu Feb 21, 2019 4:08 am

Code: Select all

void __stdcall DISPLAY_DrawEnemyLifeBar(int percentage, DWORD palette)
{
	int red = 256 * (100 - percentage) / 100;
	int green = 256 * percentage / 100;
	D2CMP_DrawEnemyLifeBar(palette, 0x100, red, green, 0x00);	//D2CMP.10075 in 1.13D
}
Colorful! :D

Post Reply

Return to “Code Editing”