Go Back   BWHacks > Development > Reverse Engineering > Code Snippets and Tutorials

Code Snippets and Tutorials The place for open source releases, great information, and tutorials written by other members.

Reply
 
LinkBack Thread Tools

Old 06-21-2007, 05:59 PM   #21 (permalink)
Perma
rol 3905h, 8
Senior Member
Administrator

Saint
 
Perma's Avatar
 
Join Date: Jul 2004
Location: Canada
Posts: 5,414
Perma has disabled reputation
Default

Quote:
Originally Posted by DivineNoodle View Post
Now, the same thing in c!

Code:
void BW_DrawTransparentBox(DWORD x, DWORD y, DWORD w,DWORD h,BYTE clr, BYTE midclr)
{
	for(int i = y; i < h+y; i+=2)
		BW_DrawBox( x, i, w, 1, midclr);

	BW_DrawBox(x, y, w, 2, clr);
	BW_DrawBox(x, y+h, w, 2, clr);
	BW_DrawBox(x, y, 1, h, clr);
	BW_DrawBox(x+w, y, 1, h, clr);

}
Awesome.
Perma 15 0FF11|\|3   Reply With Quote
Sponsored links
Advertisement
 
Advertisement
Advertisement


Old 06-21-2007, 09:11 PM   #22 (permalink)
Zephyrix
Ereetu.
Senior Member
Game Hacking Staff

High Priest
 
Zephyrix's Avatar
 
Join Date: Oct 2005
Location: xor 1D27,1337
Posts: 1,565
Zephyrix is a name known to allZephyrix is a name known to allZephyrix is a name known to allZephyrix is a name known to all
Default

And an even better looking drawtransparentbox, thanks to KC!
Code:
void BW_DrawTransparentBox(DWORD x, DWORD y, DWORD w,DWORD h,BYTE clr, BYTE midclr)
{
    bool bDraw = true;
    for(int i = y; i < y+h; i++)
    {
        for(int z = x; z < x+w; z++)
        {
            if(bDraw)
                BW_DrawBox( z, i, 1, 1, midclr);
            bDraw = !bDraw;
        }
        bDraw = !bDraw;
    }

    BW_DrawBox(x, y, w, 2, clr);
    BW_DrawBox(x, y+h, w, 2, clr);
    BW_DrawBox(x, y, 1, h, clr);
    BW_DrawBox(x+w, y, 1, h, clr);

}
^ looks like this:


If the image is too small,

it draws in a checker pattern.

xoxoxoxoxoxox
oxoxoxoxoxoxo
xoxoxoxoxoxox
oxoxoxoxoxoxo
xoxoxoxoxoxox
oxoxoxoxoxoxo
Zephyrix 15 0FF11|\|3   Reply With Quote

Old 06-22-2007, 02:50 AM   #23 (permalink)
Jiggie=#1

Advocate
 
Jiggie=#1's Avatar
 
Join Date: Jul 2006
Location: Cream
Posts: 304
Jiggie=#1 is on a distinguished road
Default

How exacly would we invoke the draw box fxn if you wanted it in the top left corner of your screen? I cant figure it out.. -.-
__________________
Jiggie=#1 15 0FF11|\|3   Reply With Quote

Old 06-22-2007, 03:42 AM   #24 (permalink)
K? Pŕo?ćtiόnŹ
=)
Senior Member
Retired Staff Member

Messiah
 
K? Pŕo?ćtiόnŹ's Avatar
 
Join Date: Oct 2004
Location: Okinawa
Posts: 9,347
K? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond repute
Send a message via AIM to K? Pŕo?ćtiόnŹ
Default

invoke DrawBox, 0, 0, 100,100,186

Draws a green box at (0,0) 100 pixels wide and 100 pixels high
__________________
K? Pŕo?ćtiόnŹ 15 0FF11|\|3   Reply With Quote

Old 05-03-2008, 04:34 PM   #25 (permalink)
kovarex

Heretic
 
Join Date: Apr 2008
Posts: 28
kovarex is an unknown quantity at this point
Default c++

Could you pls provide how to use the drawbox function in c++ without the use of assambler?

I tried this
void (_stdcall*drawBox)(int x, int y, int width, int height, u8 color) = (void(_stdcall*)(int x, int y, int width, int height, u8 color))0x4E18E0;

But got crash
kovarex 15 0FF11|\|3   Reply With Quote

Old 05-03-2008, 05:01 PM   #26 (permalink)
kovarex

Heretic
 
Join Date: Apr 2008
Posts: 28
kovarex is an unknown quantity at this point
Default

The problem probably is, that 004E18C0h is 1.15.1 (old) offset, anyeone knows the new one?
kovarex 15 0FF11|\|3   Reply With Quote

Old 05-03-2008, 05:22 PM   #27 (permalink)
Perma
rol 3905h, 8
Senior Member
Administrator

Saint
 
Perma's Avatar
 
Join Date: Jul 2004
Location: Canada
Posts: 5,414
Perma has disabled reputation
Default

004E18E0h is the current offset.
Perma 15 0FF11|\|3   Reply With Quote

Old 05-04-2008, 01:37 PM   #28 (permalink)
MasterOfChaos

Deviant
 
MasterOfChaos's Avatar
 
Join Date: Oct 2007
Posts: 53
MasterOfChaos is on a distinguished road
Default

When I did an automatic conversion 1.14->1.15.2 the address 004E18C0 was translated to 004E2620. Btw how do you update offsets for patches which changed the compiler(settings) and thus generates a different asmcode? I think 1.13->1.14 was such a patch.
__________________
We are the Others. We serve different forces, but in the Twilight there is no difference between the absence of darkness and the absence of light.
MasterOfChaos 15 0FF11|\|3   Reply With Quote

Old 05-04-2008, 02:31 PM   #29 (permalink)
K? Pŕo?ćtiόnŹ
=)
Senior Member
Retired Staff Member

Messiah
 
K? Pŕo?ćtiόnŹ's Avatar
 
Join Date: Oct 2004
Location: Okinawa
Posts: 9,347
K? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond repute
Send a message via AIM to K? Pŕo?ćtiόnŹ
Default

You look for them.
__________________
K? Pŕo?ćtiόnŹ 15 0FF11|\|3   Reply With Quote

Old 05-04-2008, 06:53 PM   #30 (permalink)
Perma
rol 3905h, 8
Senior Member
Administrator

Saint
 
Perma's Avatar
 
Join Date: Jul 2004
Location: Canada
Posts: 5,414
Perma has disabled reputation
Default

Quote:
Originally Posted by MasterOfChaos View Post
When I did an automatic conversion 1.14->1.15.2 the address 004E18C0 was translated to 004E2620. Btw how do you update offsets for patches which changed the compiler(settings) and thus generates a different asmcode? I think 1.13->1.14 was such a patch.
There are almost always blocks of assembly code that don't differ from one compile to another, and that's generally what I look for when converting to a new version. Often times, the code block I'm comparing is nowhere near the function I need but holds some relationship to it.

The rare time that there is really nothing to cross reference, you just have to find the function on your own the way you did it the first time. It doesn't take too long if you've done it already.
Perma 15 0FF11|\|3   Reply With Quote

Old 05-20-2008, 01:45 AM   #31 (permalink)
Perma
rol 3905h, 8
Senior Member
Administrator

Saint
 
Perma's Avatar
 
Join Date: Jul 2004
Location: Canada
Posts: 5,414
Perma has disabled reputation
Default

I've updated this function to work with patch v1.15.2. Please see the original post.
Perma 15 0FF11|\|3   Reply With Quote

Old 05-20-2008, 02:30 AM   #32 (permalink)
ulliklliwi

Disciple
 
ulliklliwi's Avatar
 
Join Date: May 2007
Location: The Code Cave after the JMP Gate
Posts: 545
ulliklliwi has a spectacular aura about
Send a message via MSN to ulliklliwi
Default

Quote:
Originally Posted by Perma View Post
I've updated this function to work with patch v1.15.2. Please see the original post.
u need to change

mov byte ptr ds:[006CF494h], cl

to

MOV DS:[6CF494h], al

or else ur going to crash . . . so u may wanted to change that code in the original post.
ulliklliwi 15 0FF11|\|3   Reply With Quote

Old 05-20-2008, 02:40 AM   #33 (permalink)
Perma
rol 3905h, 8
Senior Member
Administrator

Saint
 
Perma's Avatar
 
Join Date: Jul 2004
Location: Canada
Posts: 5,414
Perma has disabled reputation
Default

Quote:
Originally Posted by ulliklliwi View Post
u need to change

mov byte ptr ds:[006CF494h], cl

to

MOV DS:[6CF494h], al

or else ur going to crash . . . so u may wanted to change that code in the original post.
No, I wouldn't want to change that. cl is holding the color reference that I want to store at that address. al is not holding anything significant.
Perma 15 0FF11|\|3   Reply With Quote

Old 05-20-2008, 04:02 AM   #34 (permalink)
K? Pŕo?ćtiόnŹ
=)
Senior Member
Retired Staff Member

Messiah
 
K? Pŕo?ćtiόnŹ's Avatar
 
Join Date: Oct 2004
Location: Okinawa
Posts: 9,347
K? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond repute
Send a message via AIM to K? Pŕo?ćtiόnŹ
Default

I dont see how he would crash from that....
__________________
K? Pŕo?ćtiόnŹ 15 0FF11|\|3   Reply With Quote

Old 05-21-2008, 02:47 AM   #35 (permalink)
ulliklliwi

Disciple
 
ulliklliwi's Avatar
 
Join Date: May 2007
Location: The Code Cave after the JMP Gate
Posts: 545
ulliklliwi has a spectacular aura about
Send a message via MSN to ulliklliwi
Default

Quote:
Originally Posted by K? Pŕo?ćtiόnŹ View Post
I dont see how he would crash from that....
after looking at my code again, i use ecx for something, so when i used cl, it crash... so my bad.
ulliklliwi 15 0FF11|\|3   Reply With Quote

Old 05-21-2008, 03:56 AM   #36 (permalink)
K? Pŕo?ćtiόnŹ
=)
Senior Member
Retired Staff Member

Messiah
 
K? Pŕo?ćtiόnŹ's Avatar
 
Join Date: Oct 2004
Location: Okinawa
Posts: 9,347
K? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond reputeK? Pŕo?ćtiόnŹ has a reputation beyond repute
Send a message via AIM to K? Pŕo?ćtiόnŹ
Default

understandable
__________________
K? Pŕo?ćtiόnŹ 15 0FF11|\|3   Reply With Quote

Old 07-02-2008, 04:47 AM   #