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 


How to change the music volume on the trainer?
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Feb 19, 2018 2:34 pm    Post subject: This post has 1 review(s) Reply with quote

Example for 64bit CE
Code:
function initializeMP3Player()
  if initializeMP3Player_done then return true end

  if autoAssemble([[loadlibrary(winmm.dll)

alloc(SimpleMp3Player,4096)
registersymbol(SimpleMp3Player)

SimpleMp3Player:
lea rsp,[rsp-28]

lea rsi,[rcx+400]
mov rdx,0
mov r8,0
mov r9,0
call mciSendStringA
mov rcx,rax
mov rdx,rsi
mov r8,400
call mciGetErrorStringA
lea rsp,[rsp+28]
ret]],true)
  then
    initializeMP3Player_done = true
    MP3PlayerCommandMS = createMemoryStream()
    MP3PlayerCommandMS.Size = 2048
    return true
  else
    return false
  end
end

function MP3PlayerSendCommand(command)
  writeStringLocal(MP3PlayerCommandMS.Memory          , command)
  writeBytesLocal (MP3PlayerCommandMS.Memory+#command , 0)
  executeCodeLocal('SimpleMp3Player',MP3PlayerCommandMS.Memory)
  return readStringLocal(MP3PlayerCommandMS.Memory+1024,100)
end

function playMP3(path)
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('close MediaFile')
  MP3PlayerSendCommand( string.format('open "%s" type mpegvideo alias MediaFile',path) )
  MP3PlayerSendCommand('play MediaFile')
end

function pauseMP3()
  if not initializeMP3Player() then return end

  if not MP3PlayerPaused then
    MP3PlayerSendCommand('pause MediaFile')
    MP3PlayerPaused=true
  else
    MP3PlayerSendCommand('resume MediaFile')
    MP3PlayerPaused=false
  end
end

function stopMP3()
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('stop MediaFile')
end

function volumeMP3(vol)
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('setaudio MediaFile volume to '..vol)
end






Usage:
Code:
mp3File = findTableFile('DeusExM00Title.mp3').Stream
examplePath = TrainerOrigin or getMainForm().OpenDialog1.InitialDir
examplePath = examplePath..'\\DeusExM00Title.mp3'

mp3File.saveToFile(examplePath)


function CEButton1Click(sender)
  playMP3(examplePath)
  volumeMP3(UDF1.CETrackBar1.Position*10)
end

function CEButton2Click(sender)
  pauseMP3()
end

function CEButton3Click(sender)
  stopMP3()
end

function CETrackBar1Change(sender)
  -- value from 0 to 1000
  -- trackbar has range 0 to 100
  volumeMP3(UDF1.CETrackBar1.Position*10)
end



play, pause/unpause, stop buttons and volume trackbar.

Example file:
https://docs.google.com/uc?authuser=0&id=16SnIg-woJL0cL_lC0p-jgtbruUXRr6Dw&export=download


Made in 20 minutes. Maybe I will add later a better one as Lua Extension.


 

_________________
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon Feb 19, 2018 3:23 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
Example for 64bit CE
Code:
function initializeMP3Player()
  if initializeMP3Player_done then return true end

  if autoAssemble([[loadlibrary(winmm.dll)

alloc(SimpleMp3Player,4096)
registersymbol(SimpleMp3Player)

SimpleMp3Player:
lea rsp,[rsp-28]

lea rsi,[rcx+400]
mov rdx,0
mov r8,0
mov r9,0
call mciSendStringA
mov rcx,rax
mov rdx,rsi
mov r8,400
call mciGetErrorStringA
lea rsp,[rsp+28]
ret]],true)
  then
    initializeMP3Player_done = true
    MP3PlayerCommandMS = createMemoryStream()
    MP3PlayerCommandMS.Size = 2048
    return true
  else
    return false
  end
end

function MP3PlayerSendCommand(command)
  writeStringLocal(MP3PlayerCommandMS.Memory          , command)
  writeBytesLocal (MP3PlayerCommandMS.Memory+#command , 0)
  executeCodeLocal('SimpleMp3Player',MP3PlayerCommandMS.Memory)
  return readStringLocal(MP3PlayerCommandMS.Memory+1024,100)
end

function playMP3(path)
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('close MediaFile')
  MP3PlayerSendCommand( string.format('open "%s" type mpegvideo alias MediaFile',path) )
  MP3PlayerSendCommand('play MediaFile')
end

function pauseMP3()
  if not initializeMP3Player() then return end

  if not MP3PlayerPaused then
    MP3PlayerSendCommand('pause MediaFile')
    MP3PlayerPaused=true
  else
    MP3PlayerSendCommand('resume MediaFile')
    MP3PlayerPaused=false
  end
end

function stopMP3()
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('stop MediaFile')
end

function volumeMP3(vol)
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('setaudio MediaFile volume to '..vol)
end






Usage:
Code:
mp3File = findTableFile('DeusExM00Title.mp3').Stream
examplePath = TrainerOrigin or getMainForm().OpenDialog1.InitialDir
examplePath = examplePath..'\\DeusExM00Title.mp3'

mp3File.saveToFile(examplePath)


function CEButton1Click(sender)
  playMP3(examplePath)
  volumeMP3(UDF1.CETrackBar1.Position*10)
end

function CEButton2Click(sender)
  pauseMP3()
end

function CEButton3Click(sender)
  stopMP3()
end

function CETrackBar1Change(sender)
  -- value from 0 to 1000
  -- trackbar has range 0 to 100
  volumeMP3(UDF1.CETrackBar1.Position*10)
end



play, pause/unpause, stop buttons and volume trackbar.

Example file:
https://docs.google.com/uc?authuser=0&id=16SnIg-woJL0cL_lC0p-jgtbruUXRr6Dw&export=download


Made in 20 minutes. Maybe I will add later a better one as Lua Extension.


 


Thanks.. Thanks.. Thanks.. Master Thanks.. Smile Smile Smile Smile

The world has changed for me now.
It's a unique job in such a short time.
You are making wonders with Letters. Smile Crying or Very sad Smile Crying or Very sad Thanks.. Smile

You must write the name master,
or reminding you must have a name?
always code owners, remind my trainers.
You have to give a name, no matter what? Smile

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website MSN Messenger
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Feb 19, 2018 3:33 pm    Post subject: This post has 1 review(s) Reply with quote

You don't have to quote whole post. Do not worry, I won't delete my post.

Quote:
You must write the name master,

it is: mgr.inz.Player

Smile

_________________
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon Feb 19, 2018 4:02 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
You don't have to quote whole post. Do not worry, I won't delete my post.

Quote:
You must write the name master,

it is: mgr.inz.Player

Smile


Thanks.. There is a link on my photo,
here in the forum CT. have a look at master, fun job;)

I will color the Project you gave and I will throw a CT.
Thank you again for helping to keep the fun going. Wink
"mgr.inz.Player" this code will be referred to by this name and I will not allow it to be forgotten.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Mon Feb 19, 2018 7:13 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
CE actually loads winmm.dll module. There you can find this API:
WINMM.mciSendStringA


Downside is, you will have to save mp3 file to temp folder.


since Lua 5.1 we have, example :

Code:
package.loadlib([[c:\path\to\winmm.dll]], 'luaopen_winmm')


1. Is it mean we can use 'WINMM.mciSendStringA' and other winmm commands + parameters directly on CE Lua script ?

2. Would you provide an example how to use/load corona library or garry's mod library to pure lua / CE Lua?. Specially (as topic of this post) because corona have 'audio.play( audioHandle [, options ] )' and gmod have 'sound.Play( string Name, Vector Pos, number Level, number Pitch, number Volume )'

Thanks in advance

EDIT :
@mgr.inz.Player, I try your mp3player with CE 6.7 (no setup version) on Windows 7 Ultimate 64 bit and i got error 'attempt to call a nil value'; maybe because of 'path name' or 'winmm.dll not load in case using CE 6.7 no setup version'. I can't find which line contains error because no specific line number to show contain error.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Feb 19, 2018 7:55 pm    Post subject: Reply with quote

Corroder wrote:
since Lua 5.1 we have, example :
Code:
package.loadlib([[c:\path\to\winmm.dll]], 'luaopen_winmm')
1. Is it mean we can use 'WINMM.mciSendStringA' and other winmm commands + parameters directly on CE Lua script ?


based on http://lua-users.org/wiki/LoadLibrary , http://pgl.yoyo.org/luai/i/package.loadlib and http://pgl.yoyo.org/luai/i/lua_CFunction no. but you could create a wrapper dll around winmm which exports lua_CFunctions and you could then load those functions with loadlib. But at that point you could just use the standard lua dll package format ( https://www.youtube.com/watch?v=UiZ051A22h8 ) and use require rather than loadlib for individual functions.

2 hours later:
Ok, I played around with the whole lua wrapper thing and got this: src dlls

and once the dlls are properly placed in the CE directory (x86 straight in CE, x64 in CE\clibs64, though perhaps there's another way to manage it) you can just use

Code:
mci = require 'mciSendStringLuaWrapper'
local success, errorStr = mci.mciSendString(('open %s\\music\\%s type mpegvideo alias MediaFile'):format(os.getenv('userprofile'), 'some song in your music folder.mp3'))
if not success then
  print(errorStr)
else
  local success, errorStr = mci.mciSendString('play MediaFile')
end


Probably wouldn't be too much work to actually signal an error but I had to fight with it to get everything compiling (x64 lua (copied from CE repo) wasn't exporting some functions for who knows what reason, compared option differences and finally changed something with "%AdditionalOptions%" and it worked, then fought with the settings to get everything put into one folder...) and now I'm tired Smile

As simple as this is it's probably easier to just use the lua + auto assemble route shown earlier but I wanted to play with a C/C++ lua module Smile

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Mon Feb 19, 2018 11:01 pm    Post subject: Reply with quote

@FreeER, thank you so much for your kind efforts and then it's all make you tired. I hope you take a rest and keep your healthy so well.

Anyway, thanks for provided some links about Lua loadlib rules. It help so much.
I am playing around with Lua by following tutorial video as you gave. Here we go :

Code:
--- add_math.lua  (a lua module)
local add_math = {}
 function add_math.add(x,y)
  return x + y
 end
return add_math

--- sample to test using add_math module
--- in case using with CE, add_math module must be place on CE folder
local a = require'add_math'
local x = 13
local y = 12 + 10
z = a.add(x,y)
print(z)  --- result 35


Now, i try load dll module for play media on Windows and test with CE as you provided above, this is for learning purpose for my self.
And also I do same thing with call C/C++ function through Lua.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Feb 20, 2018 12:13 am    Post subject: Reply with quote

Corroder wrote:
EDIT :
@mgr.inz.Player, I try your mp3player with CE 6.7 (no setup version) on Windows 7 Ultimate 64 bit and i got error 'attempt to call a nil value'; maybe because of 'path name' or 'winmm.dll not load in case using CE 6.7 no setup version'. I can't find which line contains error because no specific line number to show contain error.


It an simple example. I did not make it for other use cases (32bit CE, paths with non-english characters, etc.)

_________________
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Feb 20, 2018 1:21 am    Post subject: Reply with quote

mgr.inz.Player wrote:
Corroder wrote:
EDIT :
@mgr.inz.Player, I try your mp3player with CE 6.7 (no setup version) on Windows 7 Ultimate 64 bit and i got error 'attempt to call a nil value'; maybe because of 'path name' or 'winmm.dll not load in case using CE 6.7 no setup version'. I can't find which line contains error because no specific line number to show contain error.


It an simple example. I do not test it for other use cases (32bit CE, paths with non-english characters, etc.)


Yup, I got what is error and fix it for my PC. Change this line :
Code:
if autoAssemble([[loadlibrary(C:\Windows\System32\winmm.dll)


Thanks for codes and support.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Tue Feb 20, 2018 6:39 am    Post subject: Reply with quote

@Corroder no problem and btw "module[s] must be placed on CE folder", they can actually be in many different locations defined by the package.path string, including iirc in TrainerOrigin (so with the trainer/CT) and in "Documents\My Cheat Tables" Smile
There's a similar string for dlls called package.cpath which is how I figured out the clibs64 folder.

Code:
if autoAssemble([[loadlibrary(C:\Windows\System32\winmm.dll)
ah, yeah. I'd just changed it to ...loadlibrary(winmm.dll) and it worked Smile
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Feb 20, 2018 8:11 am    Post subject: Reply with quote

@freeER
Quote:
btw "module[s] must be placed on CE folder"


Yes, that is true. I have tried. As shown on my sample script module above.
Code:
.... --- in case using with CE, add_math module must be place on CE folder

Soon, will try package.path string and package.cpath to define specific path where modules store.

Meanwhile, I have finish my trial to make MP3 Player using CE Lua; basic using mgr.inz.Player mp3Player function scripts (Thank so much). Just make little modifications, such as :

1. Allow user to select their own mp3 file from their PC
2. No need add mp3 file to CE Table > Add File
3. Not use stream file and next save to file with considering to keep media storage capacities not reduce by auto add new or copy of mp3 file
4. Add option to open Windows Master Volume
5. Compiled as stand alone exe trainer file and work properly (tested)

Soon, I will provide a link for forum members to download CT file if they need.

EDIT :
link to download CT file :
[url]https://mega.nz/#!D5tTwa4K!GwsIyGa2hfxGZeIPI3iQqxfLiUGhSzA-o11SFgJfOy8[/url]



Capture.JPG
 Description:
CRDR MP3 Player Ver.2
 Filesize:  79.6 KB
 Viewed:  9821 Time(s)

Capture.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Feb 20, 2018 12:14 pm    Post subject: Reply with quote

Corroder wrote:
EDIT :
@mgr.inz.Player, I try your mp3player with CE 6.7 (no setup version) on Windows 7 Ultimate 64 bit and i got error 'attempt to call a nil value';

Or maybe you didn't execute Lua first, you just clicked "play" button?
Or you downloaded CT file to folder which path contains non english characters.

PS: For me loadlibrary(winmm.dll) works on both Windows (seven and ten)



EDIT:
UPDATE

- added 32bit CE version support
- added unicode characters support (e.g. mp3 path can be C:\Users\username\Desktop\zażółćПрипять\DeusExM00Title.mp3)
- length, position

Code:
function initializeMP3Player()
  if initializeMP3Player_done then return true end

local script64bit=[[loadlibrary(winmm.dll)
alloc(SimpleMp3Player,4096)
registersymbol(SimpleMp3Player)

SimpleMp3Player:
lea rsp,[rsp-28]
lea rsi,[rcx+400]

lea rdx,[rcx+300]
mov r8d,80
xor r9d,r9d
call mciSendStringW
mov rcx,rax
mov rdx,rsi
mov r8,200
call mciGetErrorStringW

lea rsp,[rsp+28]
ret]]

local script32bit=[[loadlibrary(winmm.dll)
alloc(SimpleMp3Player,4096)
registersymbol(SimpleMp3Player)

SimpleMp3Player:
push ebp
mov ebp,esp
push ebx

mov ebx,[ebp+8]

sub esp,10
mov [esp],ebx
lea ebx,[ebx+300]
mov [esp+4],ebx
mov [esp+8],80
mov [esp+c],0
call mciSendStringW

mov ebx,[ebp+8]
lea ebx,[ebx+400]

sub esp,0c
mov [esp],eax
mov [esp+0x4],ebx
mov [esp+0x8],200
call mciGetErrorStringW

pop ebx
leave
ret 004]]

  if cheatEngineIs64Bit() then script = script64bit else script = script32bit end

  if autoAssemble(script,true)
  then
    initializeMP3Player_done = true
    MP3PlayerCommandMS = createMemoryStream()
    MP3PlayerCommandMS.Size = 2048
    return true
  else
    return false
  end

end

function MP3PlayerSendCommand(command)
  writeStringLocal(MP3PlayerCommandMS.Memory, command, true)
  writeBytesLocal (MP3PlayerCommandMS.Memory+2*#command, 0, 0)
  executeCodeLocal('SimpleMp3Player',MP3PlayerCommandMS.Memory)
  return readStringLocal(MP3PlayerCommandMS.Memory+1024,512,true),
         readStringLocal(MP3PlayerCommandMS.Memory+768,128,true)
end

function playMP3(path)
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('close MediaFile')
  MP3PlayerSendCommand( string.format('open "%s" type mpegvideo alias MediaFile',path) )
  MP3PlayerSendCommand('play MediaFile')
end

function pauseMP3()
  if not initializeMP3Player() then return end

  if not MP3PlayerPaused then
    MP3PlayerSendCommand('pause MediaFile')
    MP3PlayerPaused=true
  else
    MP3PlayerSendCommand('resume MediaFile')
    MP3PlayerPaused=false
  end
end

function stopMP3()
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('stop MediaFile')
end

function volumeMP3(vol)
  if not initializeMP3Player() then return end

  MP3PlayerSendCommand('setaudio MediaFile volume to '..vol)
end

function lengthMP3()
  if not initializeMP3Player() then return end

  local a,b=MP3PlayerSendCommand('status MediaFile length')
  return tonumber(b) or 0
end

function positionMP3()
  if not initializeMP3Player() then return end

  local a,b=MP3PlayerSendCommand('status MediaFile position')
  return tonumber(b) or 0
end


Example:
https://docs.google.com/uc?authuser=0&id=1gwOWgBvdHW_L-uagEYS3lUjYAwMniOu9&export=download


_________________
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Tue Feb 20, 2018 4:19 pm    Post subject: Reply with quote

There is a detail, and he may have missed it. Rolling Eyes
CT or Trainer, whenever activated,
She is recording Table music on the table.
and the 'Error' message appears after the first recording.
and for the record again on the same file on the desk
It gives an error message instead of sending the message!
I also upload music and assigned command 3,
I listened once when CT was completed and then did not work.
Play icons are not active,
Only playing music while opening INTRO is running. Rolling Eyes
Check CT, please.
Register and try as a trainer.
Warning: OnTimer is on.
And do not forget to delete the music file saved on the desk!


https://www.dropbox.com/s/zd65wtpb6zz7l8f/PLAY_MP3-INTRO.CT?dl=0

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website MSN Messenger
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Tue Feb 20, 2018 5:15 pm    Post subject: Reply with quote

@mgrinzPlayer you know, pause is a bit pointless if play causes it to restart from the beginning all the time... Smile

@aylin CETimer23Timer is constantly calling stopMP3...

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Feb 20, 2018 5:47 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
Quote:
Or maybe you didn't execute Lua first, you just clicked "play" button?


Yup, I forget if my CE setting to never run CE Table script when open CT files. I fixed it.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
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