Jump to content
Tuts 4 You

Code Conversion Help


atom0s

Recommended Posts

Hey guys, first post here, sorry to make it seem like I'm leeching. Firstly, I want to give a huge thanks to ufo-Pu55y for releasing the source codes to some of his keygens. Along with that, uPPP. After seeing some of the things uPPP could make, I kinda wanted to mimic them and create the same effects, but in C/C++

My ASM knowledge is pretty basic, I know what the opcodes are, what they do, etc. but I lack the knowledge in the given section that my question is going to pertain to. Part of the code to some of the Keygens I mentioned above use MMX functions which I haven't the slightest clue how to use or convert.

For better reference to any that look over this topic, take a look at this keygen template:

http://www.tuts4you.com/forum/index.php?au...mp;showfile=189

The function in question is 'AlphaBlend2':

AlphaBlend2 proc hSrcBm:DWORD,srcx:DWORD,srcy:DWORD,srcw:DWORD,srch:DWORD,hDstBm:DWORD,dstx:DWORD,dsty:DWORD,Fade:BOOL
LOCAL bmsrc:BITMAP, bmdst:BITMAP
LOCAL srci:DWORD, dsti:DWORD
LOCAL ScrWidth invoke GetObject,hSrcBm,sizeof bmsrc,addr bmsrc
invoke GetObject,hDstBm,sizeof bmdst,addr bmdst
mov eax,bmsrc.bmWidth
sub eax,srcw
shl eax,2
mov srci,eax
mov eax,bmdst.bmWidth
sub eax,srcw
shl eax,2
mov dsti,eax
mov eax,bmdst.bmWidth
mov edx,bmdst.bmHeight
sub edx,dsty
sub edx,srch
mul edx
add eax,dstx
shl eax,2
add eax,bmdst.bmBits
mov edx,eax
push edx
mov eax,bmsrc.bmWidth
mov edx,bmsrc.bmHeight
sub edx,srcy
sub edx,srch
mul edx
add eax,srcx
shl eax,2
add eax,bmsrc.bmBits
pop edx
shr srcw,1
; Following code originally by bitRAKE
.data
__FF000000FF000000 dq 0FF000000FF000000h
__00FFFFFF00FFFFFF dq 000FFFFFF00FFFFFFh
__FADING_MASK dq 000FFFFFF00FFFFFFh
.code AlphaBlendLoop:; 13056 ticks for 1000 quads on Athlon.
mov ecx,srcw; number of pixels/2
dec ecx
pxor mm7,mm7
movq mm0,[eax+ecx*8]
movq mm1,[edx+ecx*8]
@@:
.if Fade
.if ecx >= ( ScrWndWidth / 2 - 12 )
pand mm0,__FADING_MASK
add byte ptr __FADING_MASK+3,011h
add byte ptr __FADING_MASK+7,011h
.elseif ecx < 12
sub byte ptr __FADING_MASK+3,011h
sub byte ptr __FADING_MASK+7,011h
pand mm0,__FADING_MASK
.else
pand mm0,__FADING_MASK
.endif
.endif
movq mm4,mm0
movq mm6,mm0
;psrlw mm6,1; optional effect
paddusb mm6,mm1
pand mm6,__FF000000FF000000
movq mm2,mm0
psrlw mm4,1
movq mm3,mm1
movq mm5,mm4
punpcklbw mm0,mm7
punpcklbw mm1,mm7
punpckhbw mm2,mm7
punpckhbw mm3,mm7
psubsw mm0,mm1
psubsw mm2,mm3
punpcklwd mm4,mm4
punpckhwd mm5,mm5
punpckhdq mm4,mm4
punpckhdq mm5,mm5
psllw mm0,1
psllw mm2,1
pmulhw mm0,mm4
pmulhw mm2,mm5
paddsw mm0,mm1
paddsw mm2,mm3
packuswb mm0,mm2
pand mm0,__00FFFFFF00FFFFFF
por mm0,mm6
; stored alpha = (-dA * sA)/256 + dA (better!?)
movq [edx+ecx*8],mm0
dec ecx
js @F ; It crashes when I don't add this???
movq mm0,[eax+ecx*8]
movq mm1,[edx+ecx*8]
jns @B
@@:
mov ecx,srcw
shl ecx,3
add eax,ecx
add edx,ecx
add eax,srci
add edx,dsti
dec srch
jnz AlphaBlendLoop ret AlphaBlend2 endp

From what I can see in the code and comparing it to other functions inside the template, AlphaBlend2 blends two HBITMAP (C++) pointers together. The template uses this function to draw the scroll text and the interface buttons. Like I said, I am trying to mimic the keygen almost completely spot on, so I am trying to obtain the same effect from this function, but in C++

To give some reference to the rest of the template, here is a piece of code I converted that is also found inside this template:

   ; Copy frame bitmap into main canvas
invoke GetObject,bFrame,sizeof bm,addr bm
mov esi,bm.bmBits
invoke GetObject,dibMain,sizeof bm,addr bm
mov edi,bm.bmBits
mov eax,bm.bmHeight
mul bm.bmWidth
mov ebx,eax
@@: mov eax,[esi]
mov [edi],eax
add esi,4
add edi,4
dec ebx
jnz @B

In C++, this would convert to: (My own conversion and best guess, it works so I figure its right lol.)

	void BitmapToBitmap( HBITMAP hDest, HBITMAP hSrc )
{
BITMAP bmpDest = {0};
BITMAP bmpSource = {0};
GetObject( hDest, sizeof(bmpDest), &bmpDest );
GetObject( hSrc, sizeof(bmpSource), &bmpSource ); for( int x=(bmpSource.bmWidth*bmpSource.bmHeight); x>=0; x-- )
memcpy( (DWORD*)bmpDest.bmBits+x, (DWORD*)bmpSource.bmBits+x, 4 );
}

Again, full credits to Ufo-Pu55y, I am simply converting it to C++ :)

I plan to release all this open source, giving credits to the proper people, when this is done.

If you need anymore info on me, this project, or anything just post and I will respond to the best of my ability. Sorry my first post is a request >.> I don't want to seem like a leecher but this is what I'm currently working on. :unsure:

Link to comment

As far as i know, you have three possibilities to use the code:

If you use Visual Studio, you can use MMX Technology intrinsics.

(I bet other vendors have come with similar approaches)...

Here are a couple of links to get you started.

http://msdn2.microsoft.com/en-us/library/y0dh78ez.aspx

http://www.codeproject.com/KB/recipes/mmxintro.aspx

Or, you can use inline assembler in your C++ project.

Or, take the easy way out (as i would):

Compile the function into a static library (exporting it first), and link the static library to your project.

Edited by HVC
Link to comment
As far as i know, you have three possibilities to use the code:

If you use Visual Studio, you can use MMX Technology intrinsics.

(I bet other vendors have come with similar approaches)...

Here are a couple of links to get you started.

http://msdn2.microsoft.com/en-us/library/y0dh78ez.aspx

http://www.codeproject.com/KB/recipes/mmxintro.aspx

Or, you can use inline assembler in your C++ project.

Or, take the easy way out (as i would):

Compile the function into a static library, exporting it, and link the static library to your project.

Hey HVC, thank you for the reply. I am currently trying to avoid using inline ASM as I want to fully convert the project over to C/C++

I do use VS2008 so inline ASM is a possibility, however, I did try to use the function via inline and ran into errors while running the code which I couldn't really do much to fix as I don't fully understand the MMX functions much. (Access violations and all the typical jazz.)

I have read the links you provided above before in my 'quest' to locate a function that does this similar effect, but have yet to find much info on alpha blending other then othe API 'AlphaBlend' which is not what I want and wont work for this.

Any other help would be greatly appreciated. :)

EDIT:

Oh, HVC I forgot to ask. I don't know how to make static libraries in MASM, let alone if they are even compatible with C/C++ (VS2008). If it is compatible, would you mind compiling just that function into a static lib? Or point me in the right direction on how to make them in MASM? Thanks again. :)

Edited by Atomos
Link to comment
EDIT:

Oh, HVC I forgot to ask. I don't know how to make static libraries in MASM, let alone if they are even compatible with C/C++ (VS2008). If it is compatible, would you mind compiling just that function into a static lib? Or point me in the right direction on how to make them in MASM? Thanks again. :)

In the evening I'd find some time to do that, if nobody does it until then.

I will also check what else would be worth compiled as a lib.

I'm not sure, if converting this piece into c++ would be cool,

coz this part really deserves some speed..

EDIT/

Oh, always be sure to use 32bit stuff. If you're mixing it up, you got ur access violations.

Edited by Ufo-Pu55y
Link to comment

I actually located some info on compiling libs in MASM and compiled this using:

; ################################################################################
##########.586
.model flat,stdcall
.mmx
option casemap:none; ################################################################################
##########include c:\masm32\include\windows.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\gdi32.incincludelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\gdi32.libAlphaBlend2 PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:BOOL.const
ScrWndWidth equ 416.code; ################################################################################
##########AlphaBlend2 proc hSrcBm:DWORD,srcx:DWORD,srcy:DWORD,srcw:DWORD,srch:DWORD,hDstBm:DWORD,dstx:DWORD,dsty:DWORD,Fade:BOOL
LOCAL bmsrc:BITMAP, bmdst:BITMAP
LOCAL srci:DWORD, dsti:DWORD
LOCAL ScrWidth invoke GetObject,hSrcBm,sizeof bmsrc,addr bmsrc
invoke GetObject,hDstBm,sizeof bmdst,addr bmdst
mov eax,bmsrc.bmWidth
sub eax,srcw
shl eax,2
mov srci,eax
mov eax,bmdst.bmWidth
sub eax,srcw
shl eax,2
mov dsti,eax
mov eax,bmdst.bmWidth
mov edx,bmdst.bmHeight
sub edx,dsty
sub edx,srch
mul edx
add eax,dstx
shl eax,2
add eax,bmdst.bmBits
mov edx,eax
push edx
mov eax,bmsrc.bmWidth
mov edx,bmsrc.bmHeight
sub edx,srcy
sub edx,srch
mul edx
add eax,srcx
shl eax,2
add eax,bmsrc.bmBits
pop edx
shr srcw,1
; Following code originally by bitRAKE
.data
__FF000000FF000000 dq 0FF000000FF000000h
__00FFFFFF00FFFFFF dq 000FFFFFF00FFFFFFh
__FADING_MASK dq 000FFFFFF00FFFFFFh
.codeAlphaBlendLoop:; 13056 ticks for 1000 quads on Athlon.
mov ecx,srcw; number of pixels/2
dec ecx
pxor MM7,MM7
movq MM0,[eax+ecx*8]
movq MM1,[edx+ecx*8]
@@:
.if Fade
.if ecx >= ( ScrWndWidth / 2 - 12 )
pand MM0,__FADING_MASK
add byte ptr __FADING_MASK+3,011h
add byte ptr __FADING_MASK+7,011h
.elseif ecx < 12
sub byte ptr __FADING_MASK+3,011h
sub byte ptr __FADING_MASK+7,011h
pand MM0,__FADING_MASK
.else
pand MM0,__FADING_MASK
.endif
.endif
movq MM4,MM0
movq MM6,MM0
;psrlw MM6,1; optional effect
paddusb MM6,MM1
pand MM6,__FF000000FF000000
movq MM2,MM0
psrlw MM4,1
movq MM3,MM1
movq MM5,MM4
punpcklbw MM0,MM7
punpcklbw MM1,MM7
punpckhbw MM2,MM7
punpckhbw MM3,MM7
psubsw MM0,MM1
psubsw MM2,MM3
punpcklwd MM4,MM4
punpckhwd MM5,MM5
punpckhdq MM4,MM4
punpckhdq MM5,MM5
psllw MM0,1
psllw MM2,1
pmulhw MM0,MM4
pmulhw MM2,MM5
paddsw MM0,MM1
paddsw MM2,MM3
packuswb MM0,MM2
pand MM0,__00FFFFFF00FFFFFF
por MM0,MM6
; stored alpha = (-dA * sA)/256 + dA (better!?)
movq [edx+ecx*8],MM0
dec ecx
js @F; It crashes when I don't add this???
movq MM0,[eax+ecx*8]
movq MM1,[edx+ecx*8]
jns @B
@@:
mov ecx,srcw
shl ecx,3
add eax,ecx
add edx,ecx
add eax,srci
add edx,dsti
dec srch
jnz AlphaBlendLoop retAlphaBlend2 endp
; ################################################################################
##########
end

Batch to build:

c:\masm32\bin\ml /c /coff *asm
c:\masm32\bin\lib /OUT:alphablend2.lib *.obj

I'm not totally sure if I got this correct but it compiled. >.> Tried importing it into VS2008 and get issues with importing the function. :(

Not sure if I compiled it correctly or not with those settings and such.

Edit: Whoops, my mistake, forgot to embrace the define in C++ with 'extern "C"{ }, linked fine now. Giving me access violation errors when running though :(

Edited by Atomos
Link to comment

Thanks HVC but actually, I found out the issue, it was my fault. If you attempt to draw past the memory DCs size, that is what causes the access violation, I was passing an incorrect size param for the image that I was testing with. Fixed the params up and now it works perfect. Thanks a ton for the suggestion, it completely slipped my mind to use a static lib for it. I would still love to see this function converted to C++ if anyone has the ability to, and as Pu55y said, optimization would be great too since the MMX functions apparently are not good to use I assume?

Heres a pic of my converted project 'so-far' running all this code converted to C++ :D

I'm using the 'The Blues' template from uPPP as my test template cause its a nice template and easy to work with.

pictw9.png

Things done so far that I have converted:

- PNG loader via pnglib C++ compile.

- BitmapToBitmap function to copy bitmaps to each other.

- Premultiply Alpha blending thanks to the Wine source code for their function.

- Static lib import for AlphaBlend2 to handle other drawing. (Thanks HVC for the suggestion :D )

Things left to do:

- Add mouse track function to handle mouse events for buttons.

- Add text scroller.

- Add music.

- Cleanup and optimize code.

- Release open source :D

Thanks a ton again guys.

@Pu55y: I hope you don't mind I'm doing this, I really love what uPPP did effects wise so I had to learn how to do it. But beings that your code is all ASM I had to learn and convert and I don't wanna keep it to myself, would rather see others be able to learn and use it too. I wont release it open source or at all if you do not want me to. I don't want to upset anyone here. :)

Link to comment
optimization would be great too since the MMX functions apparently are not good to use I assume?
Not sure, if I got u right. I meant, use of mmx IS cool for it.. means more speed !
I hope you don't mind I'm doing this
Ofc I don't mind.. how could I ?

The most important stuff like pnglib or the routine above are done by other guys anyway.

And also cool, if this will result in better templates out there !

Link to comment
optimization would be great too since the MMX functions apparently are not good to use I assume?
Not sure, if I got u right. I meant, use of mmx IS cool for it.. means more speed !
I hope you don't mind I'm doing this
Ofc I don't mind.. how could I ?

The most important stuff like pnglib or the routine above are done by other guys anyway.

And also cool, if this will result in better templates out there !

Ah ok I misunderstood you then with the MMX functions. Also, glad to hear you don't mind :D

Some updates to this:

- Button State Handler Done (Detects if mouse is over button and draws correct button state image.)

- Button Event Handler Done (Detects if click is done over button.)

- All buttons being drawn now :)

Basically almost done with this now for the template outline. Things left to do is cleanup the code, add miniFmod which I already made a class for that a while ago, and release. I think I am going to convert everything into a drop and go class that will only require you to do very little to implement the effects and such. Will make it very easy for others to use the code to create templates quickly.

Thanks again everyone for the support and such. :)

Link to comment
Try this one...

I also added ScrWndWidth as a parameter.

Actually, I am using yours now HVC due to needing to pass a different value for ScrWndWidth depending on the size of the program window. But, I did happen to run into an issue. The location you replaced to allow the code to compare against the given number is overwriting EAX which is inuse and needed later. A quick fix for the code:

		PUSH EAX
MOV EAX, ScrWndWidth
MOV dwScreenWidth, EAX
POP EAX
SHR dwScreenWidth, 1
SUB dwScreenWidth, 12
.if( ecx >= dwScreenWidth )

Nothing huge, just get access violations if you overwrite EAX there.

Currently working on the fader at the moment which is giving me a tough time. Lots of flickering for some reason as well as the math not wanting to cooperate to position the text at the right location with the correct width to fade in and out at.

Edit: Alright fixed the issues with the scroller, and got it to load resource fonts to let users use custom fonts :D

New pic of my C++ version:

picit1.png

Working good so far :D Code is extremely messy at the moment lol, but thats what code looks like during development stages. >.>

Thanks again everyone.

Credits List At This Time:

- Ufo-Pu55y (Original ASM Template Code, uPPP)

- HVC (AlphaBlend2 static-lib)

- Wine.org (Premultiply Alpha function)

I've debugged the uPPP compiled example for this skin so much I know the asm in it by heart now basically x.x I could bleed ASM at the moment. ; ;

Edited by Atomos
Link to comment

Another update for this, basically done. The code is still a bit messy which I don't really like that much but it runs, and the file size isn't too big.. I'm kinda saddened by the fact that using std::strings are causing some optimization features to '****' things up, but overall it runs, it works, and it is fairly easy to customize. :)

Newest picture:

newpicyq3.png

So let me explain some stuff since this is 90% redone in C++ with the exception of two functions. The first version I did of this was all done hard coded in 1 .cpp file which made things pretty messy, completely static, and hard to customize if you were to have the source and want to make your own skin and such.

I decided to rewrite this yesterday to make it:

a.) Run better / faster.

b.) Have more customization.

c.) Less work for users to edit to make it custom.

The new version uses the following 'outside' support libraries, all of which are compiled in a static-lib form so you do not need to distribute .dlls with your patch and stuff. Less files = less hassle:

- pngLib [Thanks to Tomas Bleeker: www.MadWizard.org]

- uFMod [Thanks to Asterix and Quantum: http://ufmod.sourceforge.net/]

- AlphaBlend2 [Thanks to HVC, edited by Atomos to include PrintText and not be a .dll]

- TinyXML [Thanks to Lee Thomason: http://www.grinninglizard.com/tinyxml/]

The new version is driven on an XML file. Currently what it looks for inside the XML is all static so you can't add buttons, text, etc. without editing the code too. But for the default template of what it does now, you can fully customize the look and position of everything that it looks for. The example application picture above uses this XML file:

<?xml version="1.0"?>
<GUI>
<FontEntry>
<Font r="1" g="0" b="0" h="14" n="bit1"/>
</FontEntry>
<ImageEntry>
<Image w="354" h="204" id="Frame"/>
</ImageEntry>
<ButtonEntries>
<Button x="14" y="178" w="80" h="36" s="2" id="Music"/>
<Button x="95" y="178" w="81" h="80" s="2" id="Backup"/>
<Button x="177" y="178" w="81" h="54" s="3" id="Patch"/>
<Button x="259" y="178" w="81" h="54" s="3" id="Exit"/>
</ButtonEntries>
<StringEntries>
<Text x="89" y="117" id="application" t="Dummy Application Name v1.2b"/>
<Text x="62" y="152" id="author" t="Atomos"/>
<Text x="240" y="152" id="date" t="00/00/0000"/>
<Text x="42" y="135" id="url" t="www.dummy-site.com"/>
<Text x="362" y="3" w="336" id="scroller" t="This is some example text that is used in the scroller...."/>
</StringEntries>
</GUI>

The only thing I am aware of that mine can't do, that uPPP can do is the URL link on the printed text for the URL. At this time, I didn't add this since it was a bitch of a time getting the rest of this to work, so I took a break on adding all the features. But, everything else works.

- Buttons have an unlimited number of states, you just have to code the state stuff yourself.

- Text is drawn based on the font created for the scroller, you can customize it via the code currently.

I did this all driven inside classes for the main code except the buttons. I did that to get things out of the way that people don't need to edit at all. There are 4 classes total:

- CWindow

Handles the creation and destruction of the actual window that is created to render onto. Also creates the main DIB section that is rendered onto.

- CFader

Handles the fading in and out functions. Abstract class to CWindow.

- CScroller

Handles the scroller. Currently creates the logfont from the resource to be used for the text information as well. Abstract class to CWindow.

- CPng

Handles loading PNGs from the resource file with pngLib. Also includes some extra functions such as, BitmapToBitmap to copy one bitmap to another. Abstract class to CWindow

CPng also includes IsOverButton since all the buttons are pictures, I figured would be best to just stick it in there for now. I plan to rewrite this again when I have the time to make it fully dynamic driven on the XML file to allow you to have an infinite number of anything with the exception of a few things.

Attached is a demo exe that does nothing currently but show off the end result coded in C++ :)

Thanks again Ufo-Pu55y for an awesome tool for me to base this on. :D

Template_Update.rar

Link to comment

Without trying to be annoying, would you mind sharing the source ?

Would be a good help for me and certainly many other people on here.

Link to comment
Without trying to be annoying, would you mind sharing the source ?

Would be a good help for me and certainly many other people on here.

Heh don't worry you aren't being annoying. I plan to post this fully open source when I get it cleaned up. So within the next day or so I plan to post it up. :)

Link to comment
Heh don't worry you aren't being annoying. I plan to post this fully open source when I get it cleaned up. So within the next day or so I plan to post it up. :)

Thanks man, looking forward to taking a look at it :thumbsup:

Link to comment
Thanks man, looking forward to taking a look at it

Same here! This would help me so much with my trainers, to add a decent GUI =D

Link to comment

Sorry for the absence on this. Been sick this past week so haven't had much time to work on fixing up the old version. I'm working on version 4 atm which is completely dynamic, meaning you can have inf. number of buttons, texts, and so on. (I'm limiting it 1 single scroller and font though for now I don't think people need more then that..)

Anyway, currently, I have it able to do the following dynamically:

- Fade in.

- Fade out.

- Create and draw the window based on the frame image size.

- Draw the frame image with the alpha effects.

- Load, Draw, and display inf number of text objects.

The text objects are all drawn on their own DC so you can set them all to different colors, or even change their colors at runtime. :)

Currently working on rewriting the button loader to be fully dynamic to let users set everything up from the XML, even allow them to set a callback function pointer in the XML so you have to edit VERY little in the CPP files.

This will make it a drop and go type framework if all goes to plan. :)

I would release the older version that is posted above but it looks like crap code wise. Everything is tossed together and there are a TON of extra variables that wouldn't be needed lol. I really don't want to release it and make people think thats my coding style. :s I will hope to have this new version done within the next few days if all goes well though. Wish me luck. >.>

Thanks again to those above. :)

Link to comment

Another update, just want to keep everyone in the loop of whats going on. :) (Almost done! :D :D)

I left off working on the last bit of the text objects, as far as I can see, text objects are now fully completed and working 100%

I just finished the button objects to what I would say are complete as well. Along with them I had two create two more classes for the engine:

- CMouse

- CCommand

CMouse handles the mouse messages sent to and from the window. It is very easy to use, all you have to do to use the mouse handler inside the engine is add the following into the WndProc callback for your window before you handle any other messages yourself:

	if( cEngine )
if( cEngine->m_vMouse->HandleMessage( hWnd, uMsg, wParam, lParam ) )
return 0;

CCommand is a command event handler for the buttons. This is still basically the only part of code you have to edit for the engine. Before you load the interface, you create commands and push them into a memory map inside the engine. For example, an exit button could be implemented like this:

Inside your XML resource, you would add a button entry such as:

<Button x="259" y="178" w="81" h="54" s="3" n="Exit" resid="3003" callback="$Exit"/>

This shows that the button is located at 259x178. The button has an overall width of 81px and an overall height of 54px. (Overall means that if it includes more then one state (up,down,mouseover), you include the full image size, the engine will handle the button offsets automatically.) 's' stands for button states. This button has a total of 3 states, which are static to the engine, 3 states is up, down, mouse over, if this had 2 states, it would be on / off like music or backups. resid is the ID number of the image this button uses, and callback is the name of the callback function this button will use.

Inside our WM_CREATE, we would create an instance of the engine then create a command callback like so:

	case WM_CREATE:
cEngine = new CEngine( hWnd );
cEngine->m_vCommands[ "$Exit" ] = new CCommand( DoExit );
// Other code here...

And our exit command would be:

std::string DoExit( const char*, CButton* )
{
PostMessage( m_hWnd, WM_CLOSE, NULL, NULL );
return std::string();
}

The exit button uses PostMessage() WM_CLOSE because of how the engine handles fading in and out, those are coded into the main message loop which you have to enter into the program. I will try to thread them into the engine later on though.

Currently, the only things I see left to do are:

- Add loading of an icon for the task bar.

- Add loading of a cursor from resource.

- Add music file handler.

- Add scroller class.

- Add URL class. (I have an idea on how to do it now with the new rewrite of this.)

For those that might be wondering or worried, the command engine is setup for easy access to the given button handling the command, meaning, lets say you have a toggle button for like, music. It would have 2 states, on and off. You want the button to toggle the music as well as draw the correct state if the music is on or off, you can do that like this:

std::string DoMusic( const char*, CButton* pButton )
{
bMusicEnabled = !bMusicEnabled;
if( pButton )
pButton->m_bEnabledFlag = bMusicEnabled;
return std::string();
}

Every button has the m_bEnabledFlag, but, only buttons set to have 2 states make use of it. So setting a button to 3 states will do nothing with this flag.

Questions, commands, feedback of development notes, just post :D I'm having loads of fun making this lol.

Credits List Update

External Resouces

-> AlphaBlend2 (Thanks to HVC, UFO-Pu55y, and bitRAKE)

-> pngLib (www.MadWizard.org)

-> TinyXML (http://www.grinninglizard.com/tinyxml/)

-> uFMod (http://ufmod.sourceforge.net/)

Personal Thanks And Credits:

-> UFO-Pu55y [For the original uPPP templates, the keygen sources in MASM that I used to base this on.]

-> HVC [For your support, help with the MASM code, and your version of the AlphaBlend2 static lib.]

-> Bobbysing [For his DirectX9 GUI lib that this engine is based on.]

-> MSDN [For the API references.]

If I missed anyone from the credits list, I'm sorry. Not trying to skimp out on anyone.

Link to comment

CUrl class is now done, fully working as planned. :) Urls now have their own entry type inside the XML:

<Url r="0" g="0" b="0" ro="255" go="255" bo="255" x="42" y="135" n="url1" t="www.dummy-site.com"/>

This allows you to set the normal state color as well as the mouse over color to make sure it is visible at all times with your custom GUI. :)

r/g/b are the colors for the normal state when the mouse is not over the text.

ro/go/bo are the colors for the mouse over state.

x/y are the top left most point of where the text starts.

n is the url name. The name is used to 'single out' the given entry incase you need to edit at runtime.

t is the text to display as well as the url to be displayed.

Project Class Setup

  • CEngine (Main Engine Class)
    • CCommand (Button Event Handler Class)
    • CFrame (Window Background Image Class)
    • CMusic (Music Handler Class)
    • CWindow (Window Object Class)
      • CButton (Button Object Class)
      • CText (Text Object Class)
      • CUrl (Url Object Class)

Edit1: Just finished up the cursor loader which works fine. :) Close to finished ^_^

Edit2: Just finished up the music loader. Works fine and easy to use / toggle the music. :)

Edited by Atomos
Link to comment

Sorry for posting over and over x.x I wont anymore after this post :x

Final update post before release of this, since anything else will just be additions and code cleanup from here out. I will start with some updates to the old classes.

CWindow has been updated to handle the frame class now, along with that it has been edited to accept a custom window title for the tray/task manager window listing. Some other minor changes to obtain pointers to objects has been added and edited some. It should be fairly easy to obtain an object that you have added during runtime if needed now.

CUrl has been updated with a suggestion from Ufo-Pu55y. There are two texts to handle the link and visual link that is drawn. This is in case a link is very long. Instead of drawing some huge link, you can tell it to render a small link, but open a longer one, for example:

<Url r="0" g="0" b="0" ro="255" go="255" bo="255" x="42" y="135" n="url1" t="www.dummy-site.com" url="http://www.dummy-site.com/test_no_follow_link.html"/>

With this code, the user will see "www.dummy-site.com" on the screen, but when the url is clicked, it will open &quot;http://www.dummy-site.com/test_no_follow_link.html".

CEngine has been updated to handle loading the template in a different manner for a few sections, as well as an additional section to load an icon for the window. I did this to cleanup the size of the XML text to make it a bit slimmer. Instead of an entry like:

<FrameEntry>
<Frame resid="5000"/>
</FrameEntry>

The new code will only read a frame entry setup like this now:

<FrameEntry resid="5000"/>

Entries that this change effected:

- CursorEntry

- FontEntry

- FrameEntry

- IconEntry

- MusicEntry

The window entry has been updated to handle a new parameter for the window title, as I said above:

  <WindowEntry>
<Window w="354" h="204" n=" .: pATCH nAME :. ">

The music handler class has been changed a little bit, nothing major and nothing that really effects anything. Just some updates to the code to do some better checks.

The mouse handler class has been updated some to fix some bugs when moving the mouse on and off a url. Some minor conflicts would occur but seems to be fixed now.

CScroller class is now finished and allows you to do a sine scroll effect as well as a normal scroll effect. The code is the same used in uPPP (as far as I know) with some tweaks and corrections to be used inside C++. This code has been added to the AlphaBlend static lib that has been created with MASM for this project to import some functions that couldn't be converted for certain reasons. This new function is called AlphaBlendScroller which is designed to be used specifically for scrollers.

The scroller object is dynamic as well meaning you can have as many as you want. Please understand though, the more scrollers you use, the less performance your patch/keygen will have. I tested it with 2 and 3 scrollers myself, which ran smooth on my dual core system, on older machines though, it might run slower and "lag". I suggest limited your projects to only 1 if you use this code, and if you use 2 be sure to go easy on other objects.

An example scroller entry would be:

<Scroller x="362" y="3" w="336" r="175" g="255" b="0" f="0.06" s="0.2" a="3" n="MainScroll" t="This is some text that will be scrolled inside our scroller..." />

x y = location to render the scroller.

w = width that the scroller scrolls, the edges of the scroller are faded automatically.

r g b = color of the scroller.

f = Frequency (How much the buttons move when they bounce.)

s = Speed of bounce (How fast the letters bounce up and down.)

a = Amplitude (How high the buttons bounce.)

n = Name of the scroller to be used when obtaining a pointer to the object.

t = Text to scroll.

If you wish to have a basic scroller that does not bounce, all you have to do is simply change f s and a to all be 0 and it will create a basic scroller that does not have a sine effect. :)

As far as I can tell this is finished now. I just want to clean up the code, add some functions to each of the object classes to help allow changes during runtime, and cleanup some code inside the main engine class. Then, I will be creating a new project for this to compile it into a static lib to make it easier to use. While it will be in a static lib, all you will need to do is drop in the lib and add the header files then do some minor changes to your main code to work with the engine.

I will include the example project I've been using to test this with as well to help give people an understanding of how to use the lib, as well as write a full read me for it to know what functions are available, what means what, how to use the XML and so on.

Thanks a ton to everyone, again, that has helped me with this. :) I can't wait to release it. :D

A new picture of the updated engine:

updateed9.png

Link to comment
Sorry for posting over and over x.x I wont anymore after this post :x

No worries mate. Interesting stuff which I'm sure will benefit a lot of people here. Keep them coming :thumbsup:

Link to comment
Thanks a ton to everyone, again, that has helped me with this. I can't wait to release it.

And I can't wait to see your source. I'm especially interested in the irregular dialog code and scroller code ^^

Link to comment
Thanks a ton to everyone, again, that has helped me with this. I can't wait to release it.

And I can't wait to see your source. I'm especially interested in the irregular dialog code and scroller code ^^

The scroller code and such is all from Ufo-Pu55y's keygen sources that are released here already. We modded the scroller code some to get it to work correctly when imported to C++ yesterday (thanks for the help pu55y :) ). I left those in ASM as they use MMX functions which I'm not sure how to convert to C++ I'm not a huge ASM freak, I know parts and code flow and such but it's not something I can dive into and get things done fluently / efficiently.

Scroller code is taken from:

http://www.tuts4you.com/forum/index.php?au...mp;showfile=195

With edits to handle the floats via pointers because for some reason C++ didn't want to properly hand over float values to the ASM lib. (All of that code will be included when I release mine.)

Along with that, the AlphaBlend2 function used to draw the buttons and such is also in the lib. Along with the PaintText function. (Because I got lazy on converting lol.)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...