Jump to content
Enyby

LUA scripting

Recommended Posts

Looks like I've finally (kind of) figured it out. I think part of what I was doing wrong was not initializing a[2] as a table, and trying to do the math to change the address while defining it. I'm sure there's a far simpler way to achieve what I was trying to do, but having created my first successful GG script I feel pleased ?

 

if gg.isVisible() then gg.setVisible(false) end 
newgame = gg.alert('Have you restarted the level?', 'Yes', 'No') 
if newgame == 2 then
  gg.toast.('Start fresh and try again!'
  os.exit() 
end 

--initial search
gg.processPause() 
gg.searchNumber('0', gg.TYPE_DWORD, false, gg.SIGN_EQUAL) 
gg.toast('Results: '..gg.getResultCount()) 

gg.processResume() 

while gg.getResultCount() > 1 do 
   gg.toast('Cause an accident!') 
   gg.sleep(5000) 
   gg.processPause() 
   acc = gg.alert('Did you crash some vehichles?', 'Yes', 'No') 
   if acc == 2 then 
      gg.searchFuzzy() 
   else 
      gg.searchFuzzy('0', gg.SIGN_FUZZY_LESS) 
   end 
   gg.processResume() 
end 

--[[
if gg.getResultCount() <10 then 
   while gg.getResultCount() > 1 do 
      gg.searchNumber('0~-10000', gg.TYPE_DWORD, false, gg.SIGN_EQUAL)
   end 
end 
]]--
  
gg.toast('Results narrowed to: '.. gg.getResultCount()) 
a = gg.getResults(1) 
a[1].value = '0' 
a[1].freeze = true
cn = a[1].address - 4
rn = a[1].address + 4
c = {}
c[1] = {}
c[1].flags = gg.TYPE_DWORD
c[1].address = cn
c[1].value = '85'
c[1].freeze = true
c[1].freezeType = gg.FREEZE_MAY_INCREASE
c[2] = {}
c[2].flags = gg.TYPE_DWORD
c[2].address = rn
c[2].value = '0'
c[2].freeze = true
c[2].freezeType = gg.FREEZE_NORMAL
gg.addListItems(a)
gg.addListItems(c)
print('Cars: '..c[1].address)
print('Traffic: '..c[2].address)
--gg.clearResults()

One thing I can't figure out is how to filter results by value. I tried searching by number after the fuzzy search, for anything between 0 to -10000(like the searchNumber() examples show for positive numbers) using SIGN_EQUAL or SIGN_GREATER but it kept getting stuck in the while loop with two results, the desired one and one that was always around -1,000,000 which I was hoping to filter out. 

Thanks again for your help, and all of your dedication to this project, it's greatly appreciated!

Share this post


Link to post
Share on other sites

8 hours ago, M_JuJu said:

I can simply create a new item in the table and do

Yes.

But if a[2] not exists - you need create it before assignment values:

a[2] = {}

 

_______________________________________________
added 1 minute later
6 hours ago, M_JuJu said:

I can't figure out is how to filter results by value

Proper refine or use loop over table with results and check value. Values which not fit your criteria - set to nil.

_______________________________________________
added 3 minutes later
6 hours ago, M_JuJu said:

0 to -10000

Wrong range.

Number can not be greater 0 and smaller negative. You need swap limits. First must be smaller then second.

Share this post


Link to post
Share on other sites
1 hour ago, SolarHacks said:

How to use string.dump command???

I guess that another question needs to be asked first.
Execute this example and try to determine which one.

local env = 1234
function f()
  if env == 1234 then
    print('How to use string.dump function?')
  else
    env.print('Do I really need to use string.dump function?')
  end
end

print('\n'..tostring(f))
f()

local chunk = string.dump(f)
local f_ = load(chunk)
print('\n'..tostring(f_))
f_()

 

Share this post


Link to post
Share on other sites

The Script is auto end d***

 

Share this post


Link to post
Share on other sites

I'm having troubles updating certain values.

Let's say i have address: BFEBF00C
with value: 198

which i got from using this:
gg.searchNumber('198',gg.TYPE_DWORD,false,gg.SIGN_EQUAL,0xBF000000,0xC1000000)
gg.getResults()

I have a fixed offset: 3BF7C
which points to: BFEFAF88

how can i modify the value of this address? (BFEFAF88)
from what I can tell, there is no function searchaddress() where I can input the offset as variable..

I tried:

local offset = tonumber('3BF7C',16)
local address = (address + offset)
t = {}
t[1].address = address

but this throws an error: table expected for set index ('address') value, got nil
if i alert the value of address, it shows a decimal number

Share this post


Link to post
Share on other sites

Get results to table, modify address and set or get value via setValues or getValues.

In your example you make empty table and try get 1 element from it. Of course it is always nil.

Share this post


Link to post
Share on other sites
1 hour ago, Double_D said:

this throws an error: table expected for set index ('address') value, got nil

if i alert the value of address, it shows a decimal number

If you look a few post above for my script I'm pretty sure you can just copy part if it as that's the same mistake I was making. Basically after you've gotten the results and all, or if you know the specific address just do: 

...
t = gg.getResults(1)
addrs = t[1].address + 245628
t[2] = {}
t[2].address = addrs
t[2].flags = gg.TYPE_DWORD
t[2].value = 'new value'
...
-- then finish with
gg.addListItems(t)

You can add in the freeze and such if needed, then voila (or at least I think - I'm also a noob, but this should work).

Edited by M_JuJu
Correction

Share this post


Link to post
Share on other sites
How I use the value is encrypted command on the Lua file

 

Please guide me

Screenshot_20181113-155529_1.jpg

Share this post


Link to post
Share on other sites
45 minutes ago, shashuke said:

How I use the value is encrypted command on the Lua file

 


Please guide me

Screenshot_20181113-155529_1.jpg

How to ask primitive questions without reading API help?

Please, do it in reverse order (first - check help pages, then ask question, if answer was not found there).

https://gameguardian.net/help/classgg.html#a7efd4ac7766e72688cb4a84a3915721e

Share this post


Link to post
Share on other sites
1 hour ago, CmP said:

How to ask primitive questions without reading API help?

Please, do it in reverse order (first - check help pages, then ask question, if answer was not found there).

https://gameguardian.net/help/classgg.html#a7efd4ac7766e72688cb4a84a3915721e

thanks bro. i have read help,but change value random.i can't take

Share this post


Link to post
Share on other sites

Try call functions which not exists.

Extra 'end' on last line.

Share this post


Link to post
Share on other sites
7 hours ago, Enyby said:

Try call functions which not exists.

Extra 'end' on last line.

Thanks @Enyby

 

_______________________________________________
added 2 minutes later

why did this happen? please help me

 

Screenshot_2018-11-22-07-27-51-096_com.estrongs.android.pop.png

Screenshot_2018-11-22-07-28-11-547_com.estrongs.android.pop.png

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

×
×
  • Create New...