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 


Add file to stream

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Master Cheater
Reputation: 8

Joined: 10 Apr 2015
Posts: 405

PostPosted: Tue Mar 14, 2017 10:03 am    Post subject: Add file to stream Reply with quote

Hi there,

How to add local file or maybe online file to stream. ?
Example, add a mp3 file to stream and then able to play sound using playSound(filename, ...).

Thanks
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 332

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

PostPosted: Tue Mar 14, 2017 10:22 am    Post subject: Reply with quote

createFileStream(filename) or ms=createMemoryStream() followed my ms.loadFromFile

for online use a stringstream and load it with the text of geturl

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
Corroder
Master Cheater
Reputation: 8

Joined: 10 Apr 2015
Posts: 405

PostPosted: Tue Mar 14, 2017 7:54 pm    Post subject: Reply with quote

Thanks DB, it work

for local file :

Code:
function loadTableCode(n)
 local t = findTableFile(n)
 if t ~= nil then
 local s = t.Stream
 local c = readStringLocal(s.Memory,s.Size)
 return c ~= nil and loadstring(c) -- return a function
 end
end
--
local f = loadTableCode('plsound.lua')
print(type(f))
if type(f) == 'function' then f() else print('not loaded') end

local ss = createMemoryStream()
path = "E:\\firestone.mp3"
ss.loadFromFile(path)

playSound(ss)


Now, I am trying to get MP3 from URL. Will edit this post if it done.

Regards

EDIT 1 : Done with simple MP3 Player

-- Add table file 'playMP3file lua file' by mgr.inz.Player to possible play sound MP3
-- Manually add song name and song path to Song Table
-- Add a file to table : 'silence.mp3' as default file to stop mp3 playing
-- You can try improving your own trainer by adding this mp player if you want

Code:
getLuaEngine().cbShowOnPrint.Checked=false
getLuaEngine().hide()

function loadTableCode(n)
 local t = findTableFile(n)
 if t ~= nil then
 local s = t.Stream
 local c = readStringLocal(s.Memory,s.Size)
 return c ~= nil and loadstring(c) -- return a function
 end
end
--
local f = loadTableCode('plsound.lua')
print(type(f))
if type(f) == 'function' then f() else print('not loaded') end

local Mform = createForm()
Mform.Width = 250
Mform.Height = 150
Mform.Position = 'poScreenCenter'
Mform.BorderStyle = 'bsNone'
Mform.Color = '0x00595959'
Mform.Name = 'Mform'

local TitlePanel = createPanel(Mform)
TitlePanel.Left = 1
TitlePanel.Top = 1
TitlePanel.Height = 30
TitlePanel.Width = Mform.Width - 1
TitlePanel.Caption = ' '
TitlePanel.BavelInner = 'bvRaised'
TitlePanel.BavelOuter = 'bvRaised'
TitlePanel.Color = '0x00DFF7FF'  --'0x00868686'
TitlePanel.Name = 'TitlePanel'
TitlePanel.OnMouseDown = function() Mform.DragNow() end

local TitleLabel = createLabel(TitlePanel)
TitleLabel.Left = 10
TitleLabel.Top = 7
TitleLabel.Font.Name = 'Armalite Rifle'
TitleLabel.Font.Style = 'fsBold'
TitleLabel.Font.Size = '12'
TitleLabel.Font.Color = '0x00595959'
TitleLabel.Caption = 'MP3 Song - Player'
TitleLabel.Name = 'TitleLabel'

local SongBox = createComboBox(Mform)
SongBox.Top = TitlePanel.Top + TitlePanel.Height + 10
SongBox.Left = 10
SongBox.Width = Mform.Width - SongBox.Left - 10
SongBox.Color = '0x00DFF7FF'
SongBox.Style = 'csDropDown'
SongBox.Text = 'Pick a song..'
SongBox.Name = 'SongBox'

MsLabel = createLabel(Mform)
MsLabel.Left = 10
MsLabel.Top = SongBox.Top + SongBox.Height + 10
MsLabel.Font.Name = 'Arial'
MsLabel.Font.Size = 9
MsLabel.Font.Style = 'fsBold'
MsLabel.Font.Color = '0x00DFF7FF'
MsLabel.Caption = 'Idle..'
MsLabel.Name = 'MsLabel'

items = combobox_getItems(SongBox)
strings_add(items, "Pick a song..")
SongBox.ItemIndex = 0

songTable = {
{songName = "Adele - Hello", songPath = "E:\\Sogs\\Adele - Hello.mp3"},
{songName = "Billy Joel - An Innocent Man", songPath = "E:\\Songs\\Billy Joel - An Innocent Man.mp3"},
{songName = "Celine Dion - My Heart Will Go On", songPath = "E:\\Songs\\Celine Dion - My Heart Will Go On.mp3"},
{songName = "Chris Brown - Dont Wake Up", songPath = "E:\\Songs\\Chris Brown - Dont Wake Up.mp3"},
{songName = 'Kate Bush - Wuthering Height', songPath = "E:\\Songs\\Kate Bush - Wuthering Height.mp3"}
}

for i,v in ipairs(songTable) do
 strings_add(items, v.songName)
end

function cbboxOnChange()
 index = getProperty(SongBox, "ItemIndex")
 index = songTable[index]
 if index == nil then
 MsLabel.Caption = 'Idle..'
 else
 local ss = createMemoryStream()
 path = index.songPath
 ss.loadFromFile(path)
 playSound(ss)
 MsLabel.Caption = "Playing - "..index.songName
 end
end
SongBox.onChange = cbboxOnChange

bStop = createButton(Mform)
bStop.Left = 10
bStop.Top = MsLabel.Top + MsLabel.Height + 20
bStop.Height = 25
bStop.Width = 70
bStop.Caption = 'Stop'
bStop.Cursor = -21
bStop.Name = 'bStop'

bExit = createButton(Mform)
bExit.Width = 70
bExit.Left = Mform.Width - bExit.Width - 10
bExit.Top = MsLabel.Top + MsLabel.Height + 20
bExit.Height = 25
bExit.Caption = 'Exit'
bExit.Cursor = -21
bExit.Name = 'bExit'

function songStop()
 if SongBox.ItemIndex == 0 then
 showMessage("No song playing...")
 end
 playSound('silence.mp3')
 MsLabel.Caption = "Idle.."
 SongBox.ItemIndex = 0
 SongBox.Text = 'Pick a song..'
 ss.destroy()
end

function exit()
 closeCE()
 return caFree
end

bExit.onClick = exit
bStop.onClick = songStop
Mform.Show()



EDIT 2 :
-- Add function to allow user to select MP3 file from local dir to playing.
-- Edit stop playing function

Code:
function songStop()
 local check = MsLabel.Caption
 if check == 'Idle..' then
 showMessage("No song playing...")
 end
 playSound('silence.mp3')
 MsLabel.Caption = "Idle.."
 SongBox.ItemIndex = 0
 SongBox.Text = 'Pick a song..'
end
// ....
bExplo = createButton(Mform)
bExplo.Left = bStop.Left + bStop.Width + 25
bExplo.Top = MsLabel.Top + MsLabel.Height + 20
bExplo.Height = 25
bExplo.Width = 70
bExplo.Caption = 'Find MP3'
bExplo.Cursor = -21
bExplo.Name = 'bExplo'
// ....
function GetFileName(f)
 local str = f
 local temp = ""
 local result = ""
 for i = str:len(), 1, -1 do
 if str:sub(i,i) ~= "/"  then
 temp = temp..str:sub(i,i)
 else
 break
 end
 end
 for j = temp:len(), 1, -1 do
 result = result..temp:sub(j,j)
 end
 return result
end

function exploMP3()
 load_dialog = createOpenDialog(self)
 load_dialog.InitalDir = os.getenv('%USERPROFILE%')
 load_dialog.execute()
 file = load_dialog.FileName
 a = GetFileName(file)
 if a == nil then
 return a
 else
 MsLabel.Caption = a
 local ss = createMemoryStream()
 ss.loadFromFile(file)
 playSound(ss)
 ss.destroy()
 end
end
//....
bExplo.onClick = exploMP3


Question :
1. Is function pause and resume can be applied with mgr.inz Player playMP3file.lua ?



Capture.JPG
 Description:
Updated MP3 Player
 Filesize:  14.72 KB
 Viewed:  2183 Time(s)

Capture.JPG



Capture.JPG
 Description:
CE Custom MP3 Player
 Filesize:  15.56 KB
 Viewed:  2275 Time(s)

Capture.JPG



plsound.lua
 Description:
lua file need add to stream file table

Download
 Filename:  plsound.lua
 Filesize:  4.88 KB
 Downloaded:  189 Time(s)

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