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 


FPS - Fly Cheat Code (lua)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Fri May 01, 2015 10:07 am    Post subject: FPS - Fly Cheat Code (lua) Reply with quote

X can go from 0 to 0.5
Y can go from 0 to 90

when X is 0 Y must be 90
when X is 0.5 Y must be 0

How much is X when Y is Y_val ?

_________________
... Fresco


Last edited by Fresco on Sun May 03, 2015 10:11 am; edited 1 time in total
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Fri May 01, 2015 10:38 am    Post subject: Re: X inversely proportional to Y Reply with quote

Fresco wrote:
X can go from 0 to 0.5
Y can go from 0 to 90

when X is 0 Y must be 90
when X is 0.5 Y must be 0

How much is X when Y is Y_val ?


Lua code:
Code:

--y = Y_val
x = (90 - y )/180


Last edited by Redouane on Fri May 01, 2015 11:24 am; edited 1 time in total
Back to top
View user's profile Send private message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Fri May 01, 2015 11:06 am    Post subject: Reply with quote

I never used Lua.

How exactly do you embed it in your AA code ?
Thanks.

_________________
... Fresco
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Fri May 01, 2015 11:21 am    Post subject: Reply with quote

Fresco wrote:
I never used Lua.

How exactly do you embed it in your AA code ?
Thanks.


That depends on what you're trying to do,to keep writing to x the result of that operation?Or to keep calculating x to update the GUI of a trainer?

You can do it in assembly,the formula is:
x = (90 - y )/180
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Fri May 01, 2015 1:15 pm    Post subject: Reply with quote

Code:
push eax
mov eax,#90
cvtsi2ss xmm1,eax

movss xmm0,xmm1   // xmm0=90, xmm1=90
subss xmm0,[y]    // xmm0=90-y
addss xmm1,xmm1   // xmm1=180
divss xmm0,xmm1   // xmm0=(90-y)/180

movss [x],xmm0
pop eax

_________________
Back to top
View user's profile Send private message MSN Messenger
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Fri May 01, 2015 1:52 pm    Post subject: Reply with quote

I have solved it like this:

Code:
fld dword ptr [y]
fld dword ptr [float90]
fsub st(0), st(1)
fdiv dword ptr [float180]


However, about Lua, where does one ever use it ?
Can it be used to simplify AA Coding ? Or is it just used to create macros ?
And how to use it? What is it's purpose in CE?

I have read a couple of posts in the Lua section but they only show Lua code which I'm learning from their website lua.org

_________________
... Fresco
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri May 01, 2015 3:25 pm    Post subject: Reply with quote

Lua is usually good for things that require user interaction.
For example, adding numbers to a game value with each press or teleporting the player someplace.
Those actions are also possible through assembly using switches and hooking routines that execute frequently.
Could also be used to parse through a dynamic list in game memory and provide your users with different options.
To my knowledge, you can't declare a Lua function and then call it through assembly. You can, however, do the opposite.
Back to top
View user's profile Send private message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Fri May 01, 2015 3:48 pm    Post subject: Reply with quote

Well if that's the case Lua might actually help me achieve my goal.
I'm trying to create a cheat code that allows the player to fly/noclip.

I have already implemented the code in assembly by injecting it somewhere in the game that gets executed every some milliseconds.

I've used the GetAsyncKeyState to detect whenever the user wants to fly.
I have found the crosshairs x and y, as well as the players x, y and z addesses.

So if the crosshairs is at 45 degrees, I know that I must move the player NorthEast, being 0.5 the maximum speed, I would have to add 0.25 to the player's x position and 0.25 to y position.

To get all the addresses I have to execute an assembly script, otherwise it's not possible, not with pointer not with anything else.

So the big question is: Can Lua help me achieve the same cheat code ?
Meaning:
1) Lua must get all the addresses from a memory location (that an assembly script declared/generated in newmem or whatever label)
2) The Lua code must run in parallel with the game, preferably without creating a new thread because that would totally slow down the game.
3) The Lua code must be able to increase/decrease the x, y, z player positon values based upon the crosshairs x and y.
4) The Lua code must only run when a certain key is pressed.

I don't need you to do my homework.
Just tell me if it's possible and if it is, where do I start (i.e. in cheat engine, because the Lua language I can learn from lua.org) ?

[EDIT]
Fount this:
http://tylerneylon.com/a/learn-lua/
Looks promising.

_________________
... Fresco
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Fri May 01, 2015 4:49 pm    Post subject: Reply with quote

Lua can do this I think
1-Just register newmem or any other label as a symbol,and you'll be able to get its address from Lua.

2-Lua scripts run on the Cheat Engine process,Lua is known for being fast and lightweight ,so you don't have to worry about performance.

3-You can use readFloat,writeFloat,readBytes...

4-Easy,register a function to be called when the key is pressed,and do whatever you want there.

I'd advice you to learn the language first,it's worth it I think.
Back to top
View user's profile Send private message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Fri May 01, 2015 4:59 pm    Post subject: Reply with quote

Code:
while true do
--stuff
end


Code:
pseudocode:
while true do
    if checkIfKeyIsPressed() then
        doFlyCode();
    end
end


Both of the codes crash Cheat Engine.

What exactly is the code for calling the function only when the key is pressed?
Or how do I do it ?
Another thing is, how do I add a Lua script/code to the CE Table ?

Due to my knowledge of JavaScript, Java, C and C++ I can already say that I have Lua handled.

_________________
... Fresco
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Fri May 01, 2015 5:19 pm    Post subject: Reply with quote

Code:

createHotkey(function()
showMessage'Hi,run your code here'
end, VK_H,VK_L)

now,press H and L at once,you can specify as many keys as you want.
Check defines.lua for a full list of key codes.

You can add a script as table entry,or as a script that gets executed when the table gets opened,for the 2nd option,click 'Show cheat table Lua script' (at the top)
Back to top
View user's profile Send private message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Fri May 01, 2015 5:25 pm    Post subject: Reply with quote

Thanks, works like a charm.
One more question: How do I stop the script ?

Say execute this:
Code:
createHotkey(function()
showMessage'Hi,run your code here'
end, VK_H,VK_L)


But I also execute this:
Code:
createHotkey(function()
showMessage'Hi, secon message here'
end, VK_H,VK_L)


How do I stop them ?
Also how do I add the Lua code to the table ? Is it even possible ?

[EDIT]
resetLuaState(): This will create a new lua state that will be used. (Does not destroy the old one, so memory leak)

However it still executes the old one:
Error:attempt to call a nil value

_________________
... Fresco
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Fri May 01, 2015 5:35 pm    Post subject: Reply with quote

Code:

a = createHotkey(function() end,VK_A)
--to stop
a.destroy();

everything is in main.lua

Also,read my previous post,Edited.
Back to top
View user's profile Send private message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Sun May 03, 2015 10:10 am    Post subject: Reply with quote

Code:
function fly()
    --ADDY GETTERS
    xCoordAddy = readPointer( getAddress( "xcoord" ));
    yCoordAddy = xCoordAddy+4;
    zCoordAddy = xCoordAddy+8;
    xCrossAddy = readPointer( getAddress( "crosshairbaseaddy" ));
    yCrossAddy = xCrossAddy+4;
    xCoord = readFloat( xCoordAddy );
    yCoord = readFloat( yCoordAddy );
    zCoord = readFloat( zCoordAddy );
    xCross = readFloat( xCrossAddy );
    yCross = readFloat( yCrossAddy );
    speed = readFloat( "speed" );

    writeFloat( yCoordAddy, yCoord+(( yCross*speed )/( -80.00 )));

    --bla bla the rest

end--function fly() end

flyCode = createHotkey( fly, VK_Z );


The above code works but it's not smooth.
It moves the player in the crosshair direction with the correct speed but it feels like it's teleporting instead of gradually flying.

The assembly version works well, very smooth, but is there a way to make the movements smooth in the Lua version ?

If you have any ideas please post.
Thank you.

_________________
... Fresco
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Sun May 03, 2015 3:33 pm    Post subject: Reply with quote

Fresco wrote:
Code:
function fly()
    --ADDY GETTERS
    xCoordAddy = readPointer( getAddress( "xcoord" ));
    yCoordAddy = xCoordAddy+4;
    zCoordAddy = xCoordAddy+8;
    xCrossAddy = readPointer( getAddress( "crosshairbaseaddy" ));
    yCrossAddy = xCrossAddy+4;
    xCoord = readFloat( xCoordAddy );
    yCoord = readFloat( yCoordAddy );
    zCoord = readFloat( zCoordAddy );
    xCross = readFloat( xCrossAddy );
    yCross = readFloat( yCrossAddy );
    speed = readFloat( "speed" );

    writeFloat( yCoordAddy, yCoord+(( yCross*speed )/( -80.00 )));

    --bla bla the rest

end--function fly() end

flyCode = createHotkey( fly, VK_Z );


The above code works but it's not smooth.
It moves the player in the crosshair direction with the correct speed but it feels like it's teleporting instead of gradually flying.

The assembly version works well, very smooth, but is there a way to make the movements smooth in the Lua version ?

If you have any ideas please post.
Thank you.


Cheat Engine hotkeys has 100ms interval, create your own timer and checked if they key is pressed.
Code:
timer = createTimer(getMainForm());
timer.Interval = 1;
timer.onTimer = function () if (isKeyPressed(VK_Z)) then fly(); end


A faster alternative would be running a loop in a new thread.

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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