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 


[solved]Format text as "Aob".

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1257

PostPosted: Thu Mar 21, 2019 2:10 pm    Post subject: [solved]Format text as "Aob". Reply with quote

It's not clear when you need it.
Sometimes practical jobs, with one click,
You may want to format the text as Aob.
Here's the code, down there.
For this code: @Corroder +1, befitting. Smile

Code:
f = createForm(true)
f.Position = poDesktopCenter
f.Width = 398
f.Height = 130

e1 = createEdit(f)
e1.Height = 23
e1.Left = 7
e1.Top = 49
e1.Width = 384

e2 = createEdit(f)
e2.Height = 23
e2.Left = 7
e2.Top = 84
e2.Width = 384

b1 = createButton(f)
b1.Left = 56
b1.Top = 10
b1.caption = "Format"

b2 = createButton(f)
b2.Left = 223
b2.Top = 10
b2.caption = "Reset"
--===================================--
-- @Corroder Code.. Thanks Dude --
--===================================--

function num2hex(num)
    local hexstr = '0123456789ABCDEF'
    local s = ' ' --The gap between the quote solves the problem
    while num > 0 do
        local mod = math.fmod(num, 16)
        s = string.sub(hexstr, mod+1, mod+1) .. s
        num = math.floor(num / 16)
    end
    if s == '' then s = '0' end
    return s
end

function str2hex(str)
    local hex = ''
    while #str > 0 do
        local hb = num2hex(string.byte(str, 1, 1))
        if #hb < 2 then hb = '1' .. hb end
        hex = hex .. hb
        str = string.sub(str, 2)
    end
    return hex
end;
--===================================--
b1.OnClick = function()
a = e1.Text
b = str2hex(a)
e2.Text=(b)
end

b2.OnClick = function()
e1.Text=""
e2.Text=""
end


Example Text: e_powerup_avatar_speed
Output: 65 5F 70 6F 77 65 72 75 70 5F 61 76 61 74 61 72 5F 73 70 65 65 64

Enjoy it! Smile

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past


Last edited by AylinCE on Sat Mar 23, 2019 2:19 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Thu Mar 21, 2019 4:12 pm    Post subject: This post has 1 review(s) Reply with quote

You're passing a number to "stringToByteTable", it takes a string and returns a table of bytes that is the string.

https://wiki.cheatengine.org/index.php?title=Lua:stringToByteTable

If you're trying to turn a WORD DWORD or QWORD into a byte table use the corresponding function, i.e. "dwordToByteTable".

https://wiki.cheatengine.org/index.php?title=Lua#To_Byte_Table

_________________
Back to top
View user's profile Send private message Visit poster's website
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri Mar 22, 2019 2:05 am    Post subject: Reply with quote

Since CEEdit contains is 'Text', of course, your function only accepts number when an input on CEEdit field with convert input text number to real number using tonumber() command.

String '100' will give result number 100 with tonumber('100'), but will give result as nil if you input 'ab100', etc.

But, here as mentioned by @TheyCallMeTim:

Code:
local bt = stringToByteTable('test')
 for i, v in ipairs(bt) do
   print(i - 1, string.format('%02X', v))
 end

result : [[
0  74
1  65
2  73
3  74
]] -- you need format result to '74 65 73 74'


other :

Code:
function num2hex(num)
    local hexstr = '0123456789abcdef'
    local s = ''
    while num > 0 do
        local mod = math.fmod(num, 16)
        s = string.sub(hexstr, mod+1, mod+1) .. s
        num = math.floor(num / 16)
    end
    if s == '' then s = '0' end
    return s
end

function str2hex(str)
    local hex = ''
    while #str > 0 do
        local hb = num2hex(string.byte(str, 1, 1))
        if #hb < 2 then hb = '0' .. hb end
        hex = hex .. hb
        str = string.sub(str, 2)
    end
    return hex
end;

a = '100 Cheat Engine'
b = str2hex(a)
print(b)

-- result : 31303020436865617420456e67696e65 
-- you need format it as output you wish


Btw, I have other version sor string to AOB in lua script.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1257

PostPosted: Fri Mar 22, 2019 3:34 am    Post subject: Reply with quote

@TheyCallMeTim, Your link has a very rich code page.
Thanks dude.

@Corroder, Still possible in CE. I think @DarkByte knows the answer. Smile

In the game I'm interested in, there are 65 thousand codes as follows.

String:
Code:
e_powerup_avatar_speed_7d

Aob:
Code:
65 5F 70 6F 77 65 72 75 70 5F 61 76 61 74 61 72 5F 73 70 65 65 64 5F 37 64


Currently, only 43'll format.
Coding at CE every time will be exhausting.
I'll have a little more research. Smile

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25291
Location: The netherlands

PostPosted: Fri Mar 22, 2019 4:17 am    Post subject: Reply with quote

use string.byte to convert strings to bytes

http://lua-users.org/wiki/StringLibraryTutorial

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1257

PostPosted: Fri Mar 22, 2019 5:46 am    Post subject: Reply with quote

@Corroder, big thanks dude..
I'm sorry I noticed late.
But the code worked great with intermediate spaces.

code: e_powerup_avatar_speed
AOB output: 65 5F 70 6F 77 65 72 75 70 5F 61 76 61 74 61 72 5F 73 70 65 65 64

Code:
f = createForm(true)
f.Position = poDesktopCenter
f.Width = 398
f.Height = 130

e1 = createEdit(f)
e1.Height = 23
e1.Left = 7
e1.Top = 49
e1.Width = 384

e2 = createEdit(f)
e2.Height = 23
e2.Left = 7
e2.Top = 84
e2.Width = 384

b1 = createButton(f)
b1.Left = 56
b1.Top = 10
b1.caption = "Format"

b2 = createButton(f)
b2.Left = 223
b2.Top = 10
b2.caption = "Reset"
--===================================--
-- @Corroder Code.. Thanks Dude --
--===================================--

function num2hex(num)
    local hexstr = '0123456789ABCDEF'
    local s = ' ' --The gap between the quote solves the problem
    while num > 0 do
        local mod = math.fmod(num, 16)
        s = string.sub(hexstr, mod+1, mod+1) .. s
        num = math.floor(num / 16)
    end
    if s == '' then s = '0' end
    return s
end

function str2hex(str)
    local hex = ''
    while #str > 0 do
        local hb = num2hex(string.byte(str, 1, 1))
        if #hb < 2 then hb = '1' .. hb end
        hex = hex .. hb
        str = string.sub(str, 2)
    end
    return hex
end;
--===================================--
b1.OnClick = function()
a = e1.Text
b = str2hex(a)
e2.Text=(b)
end

b2.OnClick = function()
e1.Text=""
e2.Text=""
end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website 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