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 


Implementing Lua Scripting To Creating CE Mp3 Player

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater
Reputation: 17

Joined: 10 Apr 2015
Posts: 647

PostPosted: Sat Mar 03, 2018 2:17 am    Post subject: Implementing Lua Scripting To Creating CE Mp3 Player This post has 2 review(s) Reply with quote

In connection to these topics :

http://forum.cheatengine.org/viewtopic.php?t=584021
http://forum.cheatengine.org/viewtopic.php?t=606901

which already answerd by the 'play MP3 sound in CE function' creator : mgr.inz.Player
as also knew as ones most respected Cheat Engine / CEF users.

So, the fisrt thing I want to do is to thank so much to mgr.inz.Player and also Dark Byte as
Cheat Engine creator.

Form those topics above, I have created a 'Simple MP3 Player' by followed 'play MP3 sound in CE function'
including added and modified some functions and use pure Cheat Engine Lua scripting.
My goal by doing this project is for learning purpose and more than it is to prove and show if CE not only use
for memory hacking, it also can use for other purpose, specially for Lua scripting.

The project as below :

--================================================================--
-- Project name : CRDR-MP3Player-Ver.4.0
-- Creator : Corroder a.k.a VCLBro
-- Created date : 28-02-2018
-- Scripting Language : Lua 5.3 compatible Lua 5.1, Lua 5.2
-- Scripting IDE : CE 6.7 Lua Engine
-- Special thanks to : mgr.inz.Player, Dark Byte, CEF Members
-- Purpose : Learning, show CE not only use for hack
--================================================================--
-- Note :
-- 1.All Form GUI on this project made use Lua Scripting
-- 2.GUI Images and Icons, has store as stream files
-- 3.Some notes has added inside script code for references
-- 4.NOT FOR COMMERCIAL USE
--================================================================--

What inside this project ? :

A. Work with Lua Table

1.Function to save and load lua table to a file

Code:
do
local function exportstring( s )
 s = string.format( "%q",s )
 s = string.gsub( s,"\\\n","\\n" )
 s = string.gsub( s,"\r","\\r" )
 s = string.gsub( s,string.char(26),"\"..string.char(26)..\"" )
 return s
end

function table.save(  tbl,filename )
 local charS,charE = "   ","\n"
 local file,err
 if not filename then
 file =  { write = function( self,newstr ) self.str = self.str..newstr end, str = "" }
 charS,charE = "",""
 elseif filename == true or filename == 1 then
 charS,charE,file = "","",io.tmpfile()
 else
 file,err = io.open( filename, "w" )
 if err then return _,err end
 end
 local tables,lookup = { tbl },{ [tbl] = 1 }
 file:write( "return {"..charE )
 for idx,t in ipairs( tables ) do
 if filename and filename ~= true and filename ~= 1 then
 file:write( "-- Table: {"..idx.."}"..charE )
 end
 file:write( "{"..charE )
 local thandled = {}
 for i,v in ipairs( t ) do
 thandled[i] = true
 if type( v ) ~= "userdata" then
 if type( v ) == "table" then
 if not lookup[v] then
 table.insert( tables, v )
 lookup[v] = #tables
 end
 file:write( charS.."{"..lookup[v].."},"..charE )
 elseif type( v ) == "function" then
 file:write( charS.."loadstring("..exportstring(string.dump( v )).."),"..charE )
 else
 local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
 file:write(  charS..value..","..charE )
 end
 end
 end
 for i,v in pairs( t ) do
 if (not thandled[i]) and type( v ) ~= "userdata" then
 if type( i ) == "table" then
 if not lookup[i] then
 table.insert( tables,i )
 lookup[i] = #tables
 end
 file:write( charS.."[{"..lookup[i].."}]=" )
 else
 local index = ( type( i ) == "string" and "["..exportstring( i ).."]" ) or string.format( "[%d]",i )
 file:write( charS..index.."=" )
 end
 if type( v ) == "table" then
 if not lookup[v] then
 table.insert( tables,v )
 lookup[v] = #tables
 end
 file:write( "{"..lookup[v].."},"..charE )
 elseif type( v ) == "function" then
 file:write( "loadstring("..exportstring(string.dump( v )).."),"..charE )
 else
 local value =  ( type( v ) == "string" and exportstring( v ) ) or tostring( v )
 file:write( value..","..charE )
 end
 end
 end
 file:write( "},"..charE )
 end
 file:write( "}" )
 if not filename then
 return file.str.."--|"
 elseif filename == true or filename == 1 then
 file:seek ( "set" )
 return file:read( "*a" ).."--|"
 else
 file:close()
 return 1
 end
end

function table.load( sfile )
 local tables, err, _
 if string.sub( sfile,-3,-1 ) == "--|" then
 tables,err = loadstring( sfile )
 else
 tables,err = loadfile( sfile )
 end
 if err then return _,err
 end
 tables = tables()
 for idx = 1,#tables do
 local tolinkv,tolinki = {},{}
 for i,v in pairs( tables[idx] ) do
 if type( v ) == "table" and tables[v[1]] then
 table.insert( tolinkv,{ i,tables[v[1]] } )
 end
 if type( i ) == "table" and tables[i[1]] then
 table.insert( tolinki,{ i,tables[i[1]] } )
 end
 end
 for _,v in ipairs( tolinkv ) do
 tables[idx][v[1]] = v[2]
 end
 for _,v in ipairs( tolinki ) do
 tables[idx][v[2]],tables[idx][v[1]] =  tables[idx][v[1]],nil
 end
 end
 return tables[1]
 end
end



2.Get a table length

Code:
function tablelength(T)
 local count = 0
 for _ in pairs(T) do count = count + 1 end
 return count
end



3.Clearing / empty a table

Code:
function clearTable(tb)
 for i, v in pairs(tb) do
 tb[i] = nil
 end
end
-- [table] = {} also use to clear a table, but in fact with this function but in fact the table still store a nil value



B. Function to convert seconds to time format HH:MM:SS or 00:00:00

Code:
function SecondsToClock(seconds)
 local seconds = tonumber(seconds)
 if seconds <= 0 then
 return "00:00:00";
 else
 hours = string.format("%02.f", math.floor(seconds/3600));
 mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
 secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
 return hours..":"..mins..":"..secs
 end
end



C. Other functions or and logics to create custom GUI, etc

What about this CRDR-MP3Player-Ver.4.0 player ?
1. Common mp3 player functions : Play, Stop, Resume, Pause
2. Added : Mute / Un-mute volume
3. Added : Filtering mp3 files when browsing on PC/Extrnal storage
4. Added : Created mp3 songs playlist which editable and save
5. Added : Automatic load last saved songs playlist
6. Added : Option to play single song or play songs shuffle
7. Added : Song info when playing -> Title, Path, Duration, File Size
8. Added : Song play elapsed time with custom progress bar
9. Added : MP3 player skin theme selector
10. Added : Loud speaker control -> Balance, Left/Right Volume, Bass/Treble Volume

On future update (plan) :
- Added 'media seek = fast forward / back'
- Added 'sound visualization'

Download Source Code (CT file) :

https://mega.nz/#!Xw8FVZAB!cUOGWWogAvdB5Xxv8XzgSCZcfJDiYVV7Y6JZUPHqQSs

NOTE 2 :
This project is not perfect, it's possible contain some error (I hope not). Anyhow, if you think you can create better then goes on,
then use this project as your motivation.
Even I can do same thing like this using other programming language such as VB, C++ and others but
the main purpose from this project is to prove and show if CE is not iuse for hacking only.
It's more than it if on right hands...


EDIT : 18/03/2018
CRDR-MP3 Player V.5
https://youtu.be/pwBsDrFQEic

Download source code / CT file CRDR-MP3-Player-V5:
https://mega.nz/#!jtkjmQ7Z!_DC-ri1R_CEMQN-mkTBgzH1celOtwBf97GMrxZ_Nc8c


Also if you want play MIDI file format, add this :

Code:
function playMID(path) 
 if not initializeMP3Player() then return end
 MP3PlayerSendCommand('close midifile')
 MP3PlayerSendCommand(string.format('open "%s" type sequencer alias midifile',path))
 MP3PlayerSendCommand('play midifile')
end


To play WMA file format (example with openDialog to locate wma file)

Code:
function playWMA() -- work
 if not initializeMP3Player() then return end
 load_dialog = createOpenDialog(self)
 load_dialog.InitalDir = os.getenv('%USERPROFILE%')
-- load_dialog.Filter = 'MP3 files|*.mp3|*'
 load_dialog.Filter = 'Audio files|*.mp3;*.mid;*.wav;*.wma|Mp3 files (*.mp3)|*.MP3|Mid files (*.mid)|*.MID|Wav files (*.wav)|*.WAV|Wma files (*.wma)|*.WMA|*'
 load_dialog.execute()
 local file = load_dialog.FileName
 s_file = string.sub(file, -4)
 print(s_file)
 if s_file == '.wma' then
 MP3PlayerSendCommand('play '..file)
 else
 print('not WMA file...')
 end
end


Cheers...
Corroder

_________________
Singapore Sling + Johnnie Walker + Some Peanuts....


Last edited by Corroder on Thu Mar 15, 2018 4:01 am; edited 3 times in total
Back to top
View user's profile Send private message
Aylin
Expert Cheater
Reputation: 2

Joined: 16 Feb 2017
Posts: 154

PostPosted: Sat Mar 03, 2018 8:03 am    Post subject: Reply with quote

Nice work, original work. Congratulations.
still foreign to me a lot of coding.
I guess I'm used to 'UDF1' coding.
'CreateTable' is an encoding I still can not figure out.
It also opens and the sliding menu is great. You do it for the 2nd time.
I noticed something;
Still does not install multiple song list.
Songs single, single loading.
A file, 'Ctrl + A' or list selection can not be made. Wink
Without changing any letters in this file,
By registering as a trainer,
Do we have a chance to open it in another trainer?
The writer's identity and identity are present,
there is no need to make a new table.
It will be more accurate to present original articles and works to members.
'AddFile' with this file, we will apply your previous coding?

Thanks @Corroder.

_________________
See Hitler ! This Trainer is for you!
http://forum.cheatengine.org/viewtopic.php?t=606786
Enthusiastic people: Always one step ahead!
Do not underestimate me Master: You were a beginner in the past!
Back to top
View user's profile Send private message MSN Messenger
.lua
How do I cheat?
Reputation: 0

Joined: 13 Sep 2018
Posts: 2

PostPosted: Fri Sep 14, 2018 2:14 pm    Post subject: CT download the website, you are not right. Please send a li Reply with quote

CT download the website, you are not right. Please send a link again.
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 Tutorials -> LUA Tutorials 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 cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites