Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Trouble making a custom type in Lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
MindCaged
Newbie cheater
Reputation: 0

Joined: 25 Apr 2013
Posts: 10

PostPosted: Thu Apr 25, 2013 2:24 pm    Post subject: Trouble making a custom type in Lua Reply with quote

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
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Apr 25, 2013 5:28 pm    Post subject: Reply with quote




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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites