Jump to content
Sign in to follow this  

My crappy method (lulz)

Recommended Posts

Originally posted here

Here is the source code to my command engine I developed for another project Im working on. Right now its patch's and everything are for starcraft but could be easily ported to wc, or any other game.


Please give credit where credit is due.


It's very easy to use, in your initialization code just put a

invoke CommandEngine_NewCmd, addr CommandProc,CTEXT("moneyhax"),2

and whenever someone types and enters /moneyhax with two paremeters (or however many parameters you specify, but in this example I put it to two) it will call CommandEngine_NewCmd with those two arguments pushed onto the stack. Here is what the CommandProc proc would look like.

CommandProc proc money:DWORD,gas:DWORD
mov [YourMineralAddress],money
mov [YourGasAddress],gas
CommandProc endp





And here is the actual source code to the commandengine.

;Uses functions from the masm32.asm file, htodw and atodw

;	DWORD CommandEngine_NewCmd cbCallback:DWORD,lpCmdName:DWORD,iArgCount:DWORD		
;	the returned valued can be used with the CommandEngine_DeleteCmd to remove the
;	command.
;	DWORD CommandEngine_DeleteCmd cmdHandle:DWORD
;	removes the cmdHandle command from the list

Command_Struct struct 
next dd ?
prev dd ?
callback dd ?
cmd db 16 dup (?)
args dd ?
Command_Struct ends 

CommandEngine_CmdFirst dd 0
CommandEngine_CmdLast dd 0

CommandEngine_CmdCount dd ?
CommandEngine_hHeap dd ?


CommandEngine_NewCmd proc callback:DWORD,cmd:DWORD,args:DWORD
LOCAL newObj:Dword
revoke newObj,HeapAlloc,CommandEngine_hHeap,HEAP_ZERO_MEMORY,sizeof Command_Struct
.if newObj!=0 && cmd!=0 && callback
	assume edi:ptr Command_Struct
	inc CommandEngine_CmdCount
	.if CommandEngine_CmdFirst==0
		mmv CommandEngine_CmdFirst,eax,newObj
		mmv CommandEngine_CmdLast,eax,newObj
		mov edi, CommandEngine_CmdLast
		mmv [edi].next,eax,newObj
		mov edi,newObj
		mmv [edi].prev,eax,CommandEngine_CmdLast
		mmv CommandEngine_CmdLast,eax,newObj

	mov edi,newObj
	mmv [edi].callback,ebx,callback
	mmv [edi].args,ebx,args
	lea ebx,[edi].cmd
	invoke lstrcpyn,ebx,cmd,15

	assume edi:Nothing
mov eax,newObj
CommandEngine_NewCmd endp

CommandEngine_DeleteCmd proc cmd:DWORD
.if cmd!=0
	dec CommandEngine_CmdCount

	.if CommandEngine_CmdCount==0
		mov CommandEngine_CmdFirst,0
		mov CommandEngine_CmdLast,0
		mov eax,CommandEngine_CmdFirst
		mov ebx,CommandEngine_CmdLast
		assume edi:ptr Command_Struct
		mov edi,cmd
		.if cmd==eax
			mov eax,[edi].next
			mov CommandEngine_CmdFirst,eax
			mov edi,eax
			mov [edi].prev,0
		.elseif cmd==ebx
			mov eax,[edi].prev
			mov CommandEngine_CmdLast,eax
			mov edi,eax
			mov [edi].next,0
			mov eax,[edi].prev
			mov ebx,[edi].next
			mov edi,eax
			mov [edi].next,ebx
			mov edi,ebx
			mov [edi].prev,eax

		assume edi:Nothing
	invoke HeapFree, CommandEngine_hHeap,0,cmd
CommandEngine_DeleteCmd endp

CommandEngine_CommandSent proc string:DWORD
LOCAL cmd[16]:BYTE
LOCAL argbuff[33]:byte
mov args,0
mov cbCalled,0

mov esi,string 
.if byte ptr [esi]=="/" && byte ptr [esi+1]!=" "
	mov ebx,string
	inc ebx
	invoke GetWord,ebx,0," ",addr cmd,16;Get the Command
	.if eax!=-1
		invoke GetWordCount,string
		mov ebx,eax
		dec ebx;Dont include the cmd itself in the argument count
		mov args,ebx

		.if eax!=-1
			assume edi:ptr Command_Struct
			mov edi,CommandEngine_CmdFirst
			.while edi!=0
				lea ebx,[edi].cmd
				push edi
				invoke lstrcmpi,ebx,addr cmd
				pop edi
				mov ebx,args
				.if eax==0 && ebx==[edi].args
					.if [edi].callback!=0

						mov ebx,args
						.while ebx>0;Push the args onto the stack
							invoke GetWord,string,ebx," ",addr argbuff,32
							lea ecx,argbuff
							xor eax,eax
							.if byte ptr [ecx]=="x";Is it a hex number?
								inc ecx
								invoke htodw,ecx
							.else;Its not a hex, so its a dec
								invoke atodw,ecx
							push eax;Push the argument onto the stack
							dec ebx

						call [edi].callback
					mov cbCalled,1
				mov edi,[edi].next
			assume edi:Nothing
mov eax,cbCalled
CommandEngine_CommandSent endp

CommandEngine_LANandOnlineandSinglePlayer proc
invoke CommandEngine_CommandSent,edx
.if eax==1
	add esp,12
	mov eax,004F2FFCh
	jmp eax
mov eax,0041008Eh
call eax
mov ecx,4F2FA2h
jmp ecx
CommandEngine_LANandOnlineandSinglePlayer endp

CommandEngine_DoPatchs proc

revoke CommandEngine_hHeap,HeapCreate,0,10000,0
.if CommandEngine_hHeap==0
	invoke MessageBox,0,CTXT("Couldnt not create the heap!"),CTXT("Error!"),MB_ICONERROR

invoke ProcPatch,004F2F9Dh,addr CommandEngine_LANandOnlineandSinglePlayer,0e9h
CommandEngine_DoPatchs endp

Share this post

Link to post
Share on other sites

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
Sign in to follow this