| 
			
				|  | Cheat Engine The Official Site of Cheat Engine
 
 
 |  
 
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| MindCaged Newbie cheater
 
 ![]() Reputation: 0 
 Joined: 25 Apr 2013
 Posts: 10
 
 
 | 
			
				|  Posted: Thu Apr 25, 2013 2:24 pm    Post subject: Trouble making a custom type in Lua |   |  
				| 
 |  
				| Okay, I've been looking and looking and can't find any documentation or examples of making a custom value type in Lua. 
 I'm currently trying to do a simple thing where I multiply the 4 byte value by 2 and add 1 for RPG Maker games. I could just do the math manually, but it'd be a time saver if I could get it to be automatic. I'm not familiar enough with assembly to try to do it there, even though I'm sure it'd probably be really simple, like a bit shift and add 1 or something.
 
 I also am just curious how to do it in Lua. I have had some experience with it in the past, although I'm a little rusty, and I'm not sure what libraries are included. It'd be pretty useful to have a function to convert between bytes and a 4-byte integer, instead of having to do the math.
 
 This is what I've tried so far, although I can't get it to register so I'm wondering if I made a syntax error.
 
 I'm using version 6.1, so I'm wondering if it's bugged, because nothing happens when I click the ok button to try to add it.
 
 
  	  | Code: |  	  | --Note: keep the function base name unique. typename="RPG Maker Value" --shown as the typename in ce
 bytecount=4  --number of bytes of this type
 functionbasename="rpgmakerval"
 
 function rpgmakerval_bytestovalue(b1,b2,b3,b4)
 --Add extra byte parameters as required
 local tmp
 tmp = ((b4 * 256 + b3) * 256 + b2) *  256 + b1
 return (tmp-1)/2
 
 end
 
 function rpgmakerval_valuetobytes(i)
 local b1, b2, b3, b4
 i = i * 2 + 1
 b1 = i % 256
 i = (i - b1) / 256
 b2 = i % 256
 i = (i - b2) / 256
 b3 = i % 256
 i = (i - b3) / 256
 b4 = i
 --return the bytes to write (usually only used when you change the value)
 return b1,b2,b3,b4
 
 end
 return typename,bytecount,functionbasename
 
 | 
 
 Edit: Hmm, I updated to 6.2 and it now seems to be working fine. I'm not sure if it's the best written code though.
 |  |  
		| Back to top |  |  
		|  |  
		| mgr.inz.Player I post too much
 
  Reputation: 222 
 Joined: 07 Nov 2008
 Posts: 4438
 Location: W kraju nad Wisla. UTC+01:00
 
 | 
			
				|  Posted: Thu Apr 25, 2013 5:28 pm    Post subject: |   |  
				| 
 |  
				|   
 
 better use AA custom type:
 
  	  | Code: |  	  | alloc(ConvertRoutine,1024) alloc(ConvertBackRoutine,1024)
 alloc(TypeName,256)
 alloc(ByteSize,4)
 
 TypeName:
 db 'RPG Maker Value - AA',0
 
 ByteSize:
 dd 4
 
 ConvertRoutine:
 [64-bit]
 mov eax,[rcx]
 
 dec eax
 shr eax,1
 
 ret
 [/64-bit]
 
 [32-bit]
 push ebp
 mov ebp,esp
 mov eax,[ebp+8]
 mov eax,[eax]
 
 dec eax
 shr eax,1
 
 pop ebp
 ret 4
 [/32-bit]
 
 ConvertBackRoutine:
 [64-bit]
 
 shl ecx,1
 inc ecx
 
 mov [rdx],ecx
 ret
 [/64-bit]
 
 [32-bit]
 push ebp
 mov ebp,esp
 push eax
 push ebx
 mov eax,[ebp+8]
 mov ebx,[ebp+c]
 
 shl eax,1
 inc eax
 
 mov [ebx],eax
 pop ebx
 pop eax
 pop ebp
 ret 8
 [/32-bit]
 
 | 
 _________________
 
 |  |  
		| Back to top |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 You cannot attach files in this forum
 You can download files in this forum
 
 |  |