Jump to content
Enyby

LUA scripting

Recommended Posts


1 hour ago, Enyby said:

You can store state to file and load on each start script. Or wait for some actions. In last case user do not need run script each time.

But this not always possible.


function sleep(s)
  local ntime = os.clock() + s
  repeat until os.clock() > ntime
end

while gg.getResultCount() < 10 do
	c = gg.getResultCount()
	gg.toast('I wait for you! Only '..(10 - c)..' need!', true)
	sleep(3)
end

gg.alert('You done!')

bandicam 2017-07-17 09-16-53-901.pngbandicam 2017-07-17 09-17-08-872.png

Well, the thing I wanted is this mechanism:

If found 1 value, edit it to 1000000 and end script.

If NOT, show the ('change the value and then open GG windows again')

By taping ok on that,  it closes GG windows, and waits for GG window to open again, then restart the script.

Share this post


Link to post
Share on other sites

In future we add function for test state of UI (show/hide) and allow set it (show/hide).

Share this post


Link to post
Share on other sites
11 minutes ago, Enyby said:

Try this test version.

GameGuardian.git_signed.apk

It's fixed.

Searched the correct region.

Script worked like a charm and it did it's job.

Screenshot_20170717-122008.png

Screenshot_20170717-122022.png

Screenshot_20170717-122043.png

Share this post


Link to post
Share on other sites
function sleep(s)
  local ntime = os.clock() + s
  repeat until os.clock() > ntime
end

gg.toast ('Quadropus 2.0.48 Hack by Backlift')
gg.clearResults()
--gg.setRanges(gg.REGION_JAVA_HEAP)
gg.setRanges(gg.REGION_C_ALLOC)
while true do
	if gg.isVisible() then
		local d = gg.prompt({A='Number of Orbs Or Dooblins'}, {A='0'})
		gg.searchNumber (d.A, gg.TYPE_DOUBLE, true, gg.SIGN_EQUAL, 0, -1)
		cnt = gg.getResultCount()
		if cnt == 0 then 
			gg.alert('Search failed')
			break
		end
		
		if cnt == 1 then 
			gg.editAll('100000000', gg.TYPE_DOUBLE)
			gg.alert('Hacking Done, Enjoy')
			break
		end 
		
		gg.alert ('Go to game and change the value, then open gg to continue')
		gg.setVisible(false)
	end
	sleep(1)
end

 

GameGuardian.git_signed.apk

Share this post


Link to post
Share on other sites
gg.toast ('Quadropus 2.0.48 Hack by Backlift')
gg.clearResults()
--gg.setRanges(gg.REGION_JAVA_HEAP)
gg.setRanges(gg.REGION_C_ALLOC)
while true do
	if gg.isVisible() then
		local d = gg.prompt({A='Number of Orbs Or Dooblins'}, {A='0'})
		if d == nil then
			gg.alert('Script canceled')
			break
		end
		gg.searchNumber (d.A, gg.TYPE_DOUBLE, true, gg.SIGN_EQUAL, 0, -1)
		cnt = gg.getResultCount()
		if cnt == 0 then 
			gg.alert('Search failed')
			break
		end
		
		if cnt == 1 then 
			gg.editAll('100000000', gg.TYPE_DOUBLE)
			gg.alert('Hacking Done, Enjoy')
			break
		end 
		
		gg.alert ('Go to game and change the value, then open gg to continue')
		gg.setVisible(false)
	end
	gg.sleep(100)
end

 

GameGuardian.git_signed.apk

Share this post


Link to post
Share on other sites

Ok testing the new version with "visible" parameters.

Share this post


Link to post
Share on other sites

You made my day enyby. I saw xmodgames use lua too. Ia it possible to protect lua scripts?

Share this post


Link to post
Share on other sites

Not in our implementation. We use LuaJ with custom changes. In general lua allow make compiled form of script but we do not plan support it.

Share this post


Link to post
Share on other sites

Interesting. Would be nice to mess around with this feature. Then I can get this to run that UNDO command I wanted.

Share this post


Link to post
Share on other sites

You can load data into script and make undo - redo in any depth. Also you can use files for store/load data and so on.

If some function common and widely used - we can add it into gg table. like function sleep.

_______________________________________________
added 0 minutes later

Good wiki for common solutions: http://lua-users.org/wiki/SleepFunction

Share this post


Link to post
Share on other sites

I'm looking in Lua manual for a "wait until X is true" command.... 

 

Does someone know such a command?

Edited by Backlift

Share this post


Link to post
Share on other sites
2 minutes ago, Enyby said:

Use while loop.

 


while not x do
	gg.sleep(100)
	end

 

Got this, wait I show you a cool code.

Share this post


Link to post
Share on other sites

Does it support "goto" command?

 

I found out it does.

But the "while not" seems not working...

Edited by Backlift

Share this post


Link to post
Share on other sites

Is this ok?

"While not X is happening do Y

Do Z

end"

I want Z to be done when X is done, if not, do Y (sleep), but it seems not working, it does Z anyway 

Share this post


Link to post
Share on other sites

I made it HAHA.

 

It's super Automatic.

Only input value

Share this post


Link to post
Share on other sites

I already post code which work in auto mode. Latest version of your script.

_______________________________________________
added 2 minutes later
1 hour ago, Backlift said:

Is this ok?

"While not X is happening do Y

Do Z

end"

I want Z to be done when X is done, if not, do Y (sleep), but it seems not working, it does Z anyway 

While not x do
	y
	end
	Z

_______________________________________________
added 4 minutes later
1 hour ago, Backlift said:

Does it support "goto" command?

 

I found out it does.

But the "while not" seems not working...

Better avoid goto at all.

I do not know - maybe it present. Read reference manual and try.

 

Share this post


Link to post
Share on other sites

1. Too many comments as for me.

Hard read code behind comments.

2.

1 hour ago, Backlift said:

if gg.getResultCount() == 4

Not good choice rely on exact count. I think better firstly for `== 0` and next is `<= 4`.

3.

1 hour ago, Backlift said:

gg.prompt

Can return nil if user press `cancel` - you script crashed in this case. See my last edition - i check for this.

4 hours ago, Enyby said:

local d = gg.prompt({A='Number of Orbs Or Dooblins'}, {A='0'}) if d == nil then gg.alert('Script canceled') break end

4.

1 hour ago, Backlift said:

print -- show the user a message, this is to inform the user there are currently too much values found, the user may go in the game and change the value then open the gameguardian window again by tapping on it's floating icon ('Too much values found, Go to game and change the value, then open gameguardian window again')

`print` not show any to user. You need `gg.alert` or `gg.toast`. `print` only print debug info into dcript log executin. User can see at only at the script end. Not while script run.

5.

1 hour ago, Backlift said:

gg.sleep(1) -- sleep 1 second until next command, so it will not continiously be running, or it supposed to be

`gg.sleep` defined as `gg.sleep(int milliseconds) -> nil` then take not seconds but milliseconds. You need pass 1000 for sleep in one second.

6.

1 hour ago, Backlift said:

if gg.isVisible() == false

More easy write `if not gg.isVisible()` or `if not(gg.isVisible())`.

7. you better avoid goto. For example I make similar script without it. With loop.

Share this post


Link to post
Share on other sites

Another good idea - check for gg.BUILD and gg.VERSION_INT for need version of GG for run this script. Because currently your script can not work on usual GG 8.28.0 - it not have gg.sleep and other functions. They present now only in test builds.

So you can something like:

if gg.BUILD < 5511 then
	gg.alert('You need more new version of GG for run this script. At least build 5511.')
	os.exit()
end

 

Share this post


Link to post
Share on other sites
1 minute ago, Enyby said:

Another good idea - check for gg.BUILD and gg.VERSION_INT for need version of GG for run this script. Because currently your script can not work on usual GG 8.28.0 - it not have gg.sleep and other functions. They present now only in test builds.

So you can something like:


if gg.BUILD < 5511 then
	gg.alert('You need more new version of GG for run this script. At least build 5511.')
	os.exit()
end

 

Thanks for reply, fixing the issues now.

Share this post


Link to post
Share on other sites
if gg.BUILD < 5511 then
	gg.alert('You need more new version of GG for run this script. At least build 5511.')
	os.exit()
end
gg.toast ('Quadropus 2.0.48 Hack by Backlift')
gg.clearResults()
gg.setRanges(gg.REGION_JAVA_HEAP)
--gg.setRanges(gg.REGION_C_ALLOC)
while true do
	if gg.isVisible() then
		gg.setVisible(false)
		local d = gg.prompt({A='Number of Orbs Or Dooblins'}, {A='0'})
		if d == nil then
			gg.alert('Script canceled')
			break
		end
		gg.searchNumber (d.A, gg.TYPE_DOUBLE, true, gg.SIGN_EQUAL, 0, -1)
		cnt = gg.getResultCount()
		if cnt == 0 then 
			gg.alert('Search failed')
			break
		end
		
		if cnt == 1 then 
			gg.editAll('100000000', gg.TYPE_DOUBLE)
			gg.alert('Hacking Done, Enjoy')
			break
		end 
		
		gg.alert ('Go to game and change the value, then click on gg icon to continue')		
	end
	gg.sleep(100)
end

Work without open gg UI at all. Need only click on icon gg for resume script,

I test it on our test app so I change regions set for java. You can comment and uncomment next line.

scr_1500296942.jpgscr_1500297050.jpg

Share this post


Link to post
Share on other sites

Also you can check selected app package via "gg.getSelectedPackage() -> string || nil".

Share this post


Link to post
Share on other sites

1_added some spaces, the comments are now bettter

2_fixed it's 4 or less now. 

3_i added the suggested code but it crashes, nevermind. 

4_yes, made it gg.alert

5_I thought its seconds, ok it's 100 now. 

0.1 second to ensure window pops up right after user opens game guardian again

6_well it does the job though anyway, but I changed it

7_i found goto command more convinient for myself. 

8_added version checking

_______________________________________________
added 1 minute later

Fixed version: (1.1)

--#1 lines that start with "--" are comments, they won't be run by script executer

--#2 you can execute "print(gg)" command to see a short help and available options for commands, it's also available at first post of Lua scripts by Enyby at gameguardian forum: https://gameguardian.net/forum/topic/17447-lua-scripting/

--#3 this is a simple example for lua scripts, provided by backlift at gameguardian forum: https://gameguardian.net/forum/profile/563312-backlift/

--#4 some functions of this script may conflict with gameguardian search helper function, recommend to disable it before running this script

--#5 each comment is related to the code above it

if gg.BUILD < 5511 then 	gg.alert('You need newer version of GG to run this script. At least build 5511.') 
	os.exit() 
	end

--if gameguardian build number is below 5511, means the script will not work,so it aborts the script and exits

::a::  

-- checkpoint "a" to restart the script if there are a lot of values found

d = gg.prompt 

-- "d" is a value and = means its equal to value got from "gg.prompt"

-- "gg.prompt" shows a window and requires an input from user

({A='Number of Orbs Or Dooblins'}, 

-- title of the required value, we named the value as "A" here, We could even use "Dooblins or orbs" but that makes the functional part of the code a bit long and it may bring some mistakes.

 {A='0',}) 

 -- default input of the value "A"

gg.toast 

-- toasts a message, for reminding credits, helps, warnings or etc...

('Quadropus 2.0.48 Hack by Backlift') 

-- text of the toast message

gg.setRanges 

-- set the search region

( gg.REGION_C_ALLOC) 

-- the region of the value, for comlplete list of regions, check comment #2

gg.searchNumber 

-- starts a search

(d['A'], 

-- searchs for value "d" that has the input of "A" from "gg.prompt"
 
 gg.TYPE_DOUBLE, 

 -- type of the value, for comlplete list of types, check comment #2

 true, 

 -- encrypted (true) or NOT encrypted (false)

 gg.SIGN_EQUAL, 

 -- define if it is equal, inequal, bigger or smaller than input value "A", see comment #2 for more info

 0, 
 
 -- starting position of memory for scanning

 -1) 

 -- ending position of memory for scanning

if gg.getResultCount() <= 4 

-- this is an "if" command to make the script do commands based on situation.

-- "gg.getResultCount()" will get the number of results found from search

-- this commands checks that "gg.getResultCount" is equal to 4 or not, if it is equal, it goes to "then" command, if Not, it goes to "else" command

then gg.editAll('100000000', 

-- edits all values and set them to '100000000'

 gg.TYPE_DOUBLE) 

 -- type of the values to edit, see comment #2 for more info

gg.alert 

-- show a window with Ok button
('Hacking Done, Enjoy') 

-- text of the "gg.alert" window

print 

-- shows a text at the script end window

('Quadropus 2.0.48 Hack by Backlift') 

-- text for the "print" function

goto c 

-- goto command will jump to the checkpoint defined

-- it jumps to checkpoint "c" to end the script if values are found and hacked successfully

else gg.setVisible(false) 

-- if value not found or too much, hide the gameguardian window

gg.alert

-- show the user a message, this is to inform the user there are currently too much values found, the user may go in the game and change the value then open the gameguardian window again by tapping on it's floating icon

('Too much values found, Go to game and change the value, then open gameguardian window again')

end 

-- end of if statement, it is mandatory

::b:: 

-- checkpoint "b" for gameguardian to sleep untill user has changed the value

gg.sleep(100) 

-- sleep 1 second until next command, so it will not continiously be running, or it supposed to be

if not gg.isVisible() then	goto b 

-- if gameguardian not visible, goto checkpoint b and rest 1 second then check again, user must change the value and then tap on gameguardian icon again so the code will pass this section and continue

else goto a 

-- if gameguardian is visible, means user has opened it because it changed the value, go to checkpoint "a" to start the process again

end 

-- end of if command

::c::

-- checkpoint "c" to end the script if the value is found and seccussfully hacked

-- example made by backlift

-- you may edit this example and make it for other games.

-- hit the thanks if you used it :)

 

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

×