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 


Loading a function as a txt file from server

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Ludwig
Advanced Cheater
Reputation: 0

Joined: 10 Jan 2016
Posts: 68

PostPosted: Thu Mar 24, 2016 12:57 pm    Post subject: Loading a function as a txt file from server Reply with quote

hi guys...
This is what i got currently:
Code:
function CreateTrainer()
   local HackData = {};
   function HackData:HacksData()
       http = require("socket.http")
       local m_hacks = http.request("http://myserver/hactable1.txt")

      self.trainer.form.Caption = [[My Hacks]]
      self.trainer.title.Caption = [[BattlePirates Hacks]]
   
      self.hacktable = loadstring(m_hacks)()

which will load the whole hackatble that looks like:


Code:
return {
{' hac1',[[ ]],[[Hack1 descr) ]],[[JUST A DESCRIPTION...NOT A ACTUAL HACK )]], 'false'},

{' hac2',[[ ]],[[Hack2 descr) ]],[[JUST A DESCRIPTION...NOT A ACTUAL HACK )]], 'false'},

}


Now...what i want to do...
i got a Main_update function with subfunctions that i would also like to load in a similar manner as the hack table...:

Code:
function Main_Update
function SuB1()
....
....
end
function SuB2()
....
....
end
function SuB3()
....
....
end
end

How should i do to get

http = require("socket.http")
local m_hacks2 = http.request("http://myserver/hactable2.txt")

that would be all the sub functions into the Main_Update function from the txt file on server into m_hacks2
?

i tried something like this...:
Code:
function database_Updt()

http = require("socket.http")
       local  http.request("http://myserver/hactable2.txt")
loadstring(m_hacks2)

end;


but it doesnt seem to work...
i get an error:[string "function CreateTrainer()..."]:761: attempt to call a nil value"

my txt file on server side looks like:
Code:
return {
function SuB1()
....
....
end
function SuB2()
....
....
end
function SuB3()
....
....
end

}
[/code]
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Mar 24, 2016 3:35 pm    Post subject: Reply with quote

Code:
local str = [[return {
SuB1 = function()
  print("sub1")
end,
SuB2 = function()
  print("sub2")
end,
SuB3 = function()
  print("sub3")
end
}]]
local Main_Update = loadstring(str)()
Main_Update.SuB1()

By the way, CE 6.5 has:
Code:
local http = getInternet()
local response = http.getURL("www.google.com")
http.destroy()
Back to top
View user's profile Send private message
Ludwig
Advanced Cheater
Reputation: 0

Joined: 10 Jan 2016
Posts: 68

PostPosted: Fri Mar 25, 2016 12:50 am    Post subject: Reply with quote

Zanzer wrote:
Code:
local str = [[return {
SuB1 = function()
  print("sub1")
end,
SuB2 = function()
  print("sub2")
end,
SuB3 = function()
  print("sub3")
end
}]]
local Main_Update = loadstring(str)()
Main_Update.SuB1()

By the way, CE 6.5 has:
Code:
local http = getInternet()
local response = http.getURL("www.google.com")
http.destroy()

thnx zanzer...got it last night from viewtopic.php?p=5602331...got mine fixed...just didnt get to posting yet...Smile
i tried ce 6.5...got some bugs on some maths functions<think it was mod>...so i reverted back to 6.4...
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 Mar 25, 2016 6:45 am    Post subject: Reply with quote

Ludwig wrote:
i tried ce 6.5...got some bugs on some maths functions<think it was mod>...so i reverted back to 6.4...

Tell us which math function. There's always a possibility it can be fixed.

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

Joined: 01 Oct 2008
Posts: 959

PostPosted: Fri Mar 25, 2016 7:06 am    Post subject: Reply with quote

Likely the math.mod.

math.mod is deprecated in Lua 5.1 (ce 6.4) and remove in Lua 5.2 (so 5.3 and ce 6.5). It said the functionality is handled with math.fmod, should work the same if inputs are both integer . But the operator '%' will work as well.

For the favored function DEC_HEX2 , it can be replaced simply by string.format('%X',n).

They are not the same though, DEC_HEX2 does not handle negative number which may be a source of bug.
or with a bit more control on returned format:
Code:
function Hex(n,withsign)
  local fmt = string.format
  if withsign then
    return n<0 and fmt('-%02X',-n) or fmt('+%02X',n)
  else
    return fmt('%02X',n)
  end
end
local xx = getAddress('cheatengine-x86_64.exe-----'..Hex(-9,true),true)
print(Hex(xx))


CE should properly handle the unary minus sign in address parsing.

_________________
- Retarded.
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 Mar 25, 2016 7:20 am    Post subject: Reply with quote

@panraven, I'm using slightly different function:
Code:
function tohexwithsign(a) return (a>=0 and '+' or '-')..string.format('%x',(a>0 and a or -a)) end

function tohex(a) return (a>=0 and '' or '-')..string.format('%x',(a>0 and a or -a)) end

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

Joined: 01 Oct 2008
Posts: 959

PostPosted: Fri Mar 25, 2016 7:40 am    Post subject: Reply with quote

hi, mgr.inz.Player!

Any chance for "CE Lua from command line" ?
http://forum.cheatengine.org/viewtopic.php?t=588686

_________________
- Retarded.
Back to top
View user's profile Send private message
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