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 


Lua help. Download file from my url and save the file

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
dario3star
Newbie cheater
Reputation: 0

Joined: 14 Dec 2020
Posts: 23

PostPosted: Thu Oct 07, 2021 9:59 am    Post subject: Lua help. Download file from my url and save the file Reply with quote

Lua help. Download file from my url and save the file where my .exe trainer is located.

My .exe trainer located at D:\downloader
and i run my .exe trainer.
For example, i click "Download Now" button,
the file should download from my url and save the file in D:\downloader

Thank you so much!



downloader test.JPG
 Description:
 Filesize:  52.32 KB
 Viewed:  7210 Time(s)

downloader test.JPG


Back to top
View user's profile Send private message AIM Address
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1063
Location: 0x90

PostPosted: Thu Oct 07, 2021 10:18 am    Post subject: This post has 1 review(s) Reply with quote

You must reference the LuaSocket library and with that you can use this snippet to download a file from a specified URL.
Code:

-- retrieve the content of a URL
local http = require("socket.http")
local body, code = http.request("link_to_file.exe")
if not body then error(code) end

-- save the contents to a file, wb is used to set the flag for writing the file in binary mode
local myfile = assert(io.open('name_of_file.exe', 'wb'))
myfile:write(body)
myfile:close()


The LuaSocket library can be found here:
github.com/LuaSocket

Edit: Apologies. DB has pointed out the getInternet function in the celua.txt document. I wasn't aware of this function.


Last edited by LeFiXER on Thu Oct 07, 2021 2:05 pm; edited 1 time in total
Back to top
View user's profile Send private message
dario3star
Newbie cheater
Reputation: 0

Joined: 14 Dec 2020
Posts: 23

PostPosted: Thu Oct 07, 2021 11:07 am    Post subject: Reply with quote

Thanks. But this confuses me a lot.
Is there any way without using luasocket?
my url link is only a table.CT file and saving it anywhere in my desktop is fine.
I hope there's a simple lua code.

sorry, my english sucks
Back to top
View user's profile Send private message AIM Address
Dark Byte
Site Admin
Reputation: 465

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

PostPosted: Thu Oct 07, 2021 1:00 pm    Post subject: Reply with quote

use getInternet.

check out celua.txt

_________________
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
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1063
Location: 0x90

PostPosted: Thu Oct 07, 2021 2:27 pm    Post subject: Reply with quote

You can use it like this:
Code:

local ic = getInternet('inet').getURL('url_to_cheat_table')

if ic ~= nil then
  local myfile = assert(io.open('path_to_file.CT', 'w'))
  myfile:write(ic)
  myfile:close()
end
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Thu Oct 07, 2021 8:15 pm    Post subject: This post has 1 review(s) Reply with quote

If you're still in this code, let me expand on the topic with some explanations.
-----------------------------------------------
The main code is here:
@Zanzer: https://forum.cheatengine.org/viewtopic.php?t=597759
-----------------------------------------------
1) Make sure the URL will download the current trainer.
2) Upload your updates to a site that will always use the same URL.
3) Define a path for the current Trainer.

Code:
local path = TrainerOrigin or getMainForm()


4) If you are going to download the new version to a different location, identify it as well.

Code:
local path1=[[D:\downloader]]
local name = path1 .. "\\" .. newName


5) Create another url for version test and Trainer name.

Code:
local versionNum = 0
local ExVersion = 01
local newName=""
UDF1.CEButton1.Caption="Download"

local path = TrainerOrigin or getMainForm() --Ex Trainer path..
local path1=[[D:\downloader]] --New Trainer path..

function loadUrl(link33)
  local int=getInternet()
  s=int.getURL(link33)
  int.destroy()
  return s
end

function VersionCheck()
local result = loadUrl("https://docs.google.com/document/d/1_Px-WKrnyw8MsqmwJnz2__eufO6cey653n77VZTDEok/export?format=txt")
local SL1 = createStringlist()
SL1.Text=result
for i=0, strings_getCount(SL1)-1 do
versionNum=SL1[1]--:sub(1,9)
newName=SL1[2]
versionNum=tonumber(versionNum)
ExVersion=tonumber(ExVersion)
end
SL1.destroy()
if versionNum==ExVersion then
UDF1.CEButton1.Enabled=false
else
showMessage("There is a new version.\nClick the 'Download' button to download!")
UDF1.CEButton1.Enabled=true
end
end

VersionCheck() --Open Trainer.. Execute func..

local name = path1 .. "\\" .. newName

function TrainerUpload()
if syntaxcheck then return end
local TABLE_VERSION = tonumber(ExVersion)
local table_url = "https://docs.google.com/uc?export=download&id=1d-lCWA1fAEpkPDTxvjGu4dxgNSRCj1E0"
local http = getInternet()
  local version = tonumber(versionNum)
  if version > TABLE_VERSION then
    local answer = messageDialog("There is a newer version of this table.\nWould you like to download it now?", mtWarning, mbYes, mbNo)
    if answer == mrYes then

      messageDialog("Caution:\nThis update will permanently delete the old version.\nIf you do not want to delete the old version,\nget a copy before you approve!", mtInformation, mbOK)
      local latest = http.getURL(table_url)
      if latest ~= nil then
        local file = io.open(name, "wb")
        file:write(latest)
        file:close()
       local name = os.execute(name, "\\"..newName);
       --local file = os.remove(ExName)
        --closeCE()
        loadTable(name)
      else
        messageDialog("Failed to load the new table!", mtError, mbOK)
      end
    end
  else
    messageDialog("You currently have the latest version!", mtInformation, mbOK)
  end
--else
 -- messageDialog("Failed to find latest version!", mtError, mbOK)
--end
http.destroy()
--  int.destroy()
assert(true)
end

UDF1.CEButton1.OnClick function()
TrainerUpload()
end


Note: For ".exe" files, remote invocation may fail due to possible security errors in the installation and run procedures. My recommendation; Use the above code with ".CT" or ".Cetrainer".
Back to top
View user's profile Send private message
dario3star
Newbie cheater
Reputation: 0

Joined: 14 Dec 2020
Posts: 23

PostPosted: Fri Oct 08, 2021 6:21 am    Post subject: Reply with quote

It worked now! Thank you so much for helping me ByTransient, LeFiXER, DarkByte

Wait i will hit thumbs up
Back to top
View user's profile Send private message AIM Address
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1063
Location: 0x90

PostPosted: Fri Oct 08, 2021 6:23 am    Post subject: Reply with quote

You're welcome Smile. Glad we could help.
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