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 


Can you check sound volume changes through LUA?

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

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Oct 30, 2018 4:57 am    Post subject: Reply with quote

try this code below :

Code:
f = createForm()

btn1 = createButton(f) -- button volume down
btn1.top = 10
btn1.left = 10
btn1.width = 70
btn1.height = 50
btn1.caption = 'Vol Down'

btn2 = createButton(f) -- button volume up
btn2.top = 10
btn2.left = btn1.left + btn1.width + 10
btn2.width = 70
btn2.height = 50
btn2.caption = 'Vol Up'

btn3 = createButton(f) -- button volume down
btn3.top = 70
btn3.left = 10
btn3.width = 150
btn3.height = 50
btn3.caption = 'Master Volume'

function volup()
 doKeyPress(0xAF)
 end

function voldn()
 doKeyPress(0xAE)
end

function mstrvol()
 shellExecute("C:\\Windows\\System32\\SndVol.exe")
end

--function rdmute()
-- doKeyPress(0xAD)
--end

--function rdsnd()
-- doKeyPress(0xAD)
--end

btn1.onClick = voldn
btn2.onClick = volup
btn3.onClick = mstrvol
f.show()


To test :

- open and play a song / game (use your default song player)
- execute script above and test to increase/decrease system volume

Unlucky i am not find how to output volume indicator yet, as a number

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

Joined: 16 Feb 2017
Posts: 1250

PostPosted: Tue Oct 30, 2018 6:01 am    Post subject: Reply with quote

Here's a compiled example
This example: @mgr.inz.Player
was released by.
The complete code or only
You can take voice control and use it


Code:
--##############################################################################
--######################### Code By: mgr.inz.Player ############################
--################################ FORUM #######################################
--############ https://forum.cheatengine.org/viewtopic.php?t=584021 ############

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

--##############################################################################
--##############################################################################
--##############################################################################
--##############################################################################


mp3File = findTableFile('music13.mp3').Stream
examplePath = TrainerOrigin or getMainForm().OpenDialog1.InitialDir
examplePath = examplePath..'\\music13.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


You can try the starter pack:

https://www.dropbox.com/s/79nm1vc3scztvrf/mp3player%20or%20Volume.CT?dl=1

_________________
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: Tue Oct 30, 2018 7:49 am    Post subject: Reply with quote

Quote:
Aylin
You can take voice control and use it


Some questions :

1. If open a game / song or movie using Windows Media Player or other media player, how to control volume by use that script ?

2. How to ise that script to control volume only, not include play, pause, stop functions ?

Your explanation will be hep me a lot...

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

Joined: 16 Feb 2017
Posts: 1250

PostPosted: Tue Oct 30, 2018 11:49 am    Post subject: Re: Can you check sound volume changes through LUA? Reply with quote

This is the question that I gave the code:

AmyGrrl wrote:
Every search was just on how to play a sound in cheat engine.


That's the question of your code:

AmyGrrl wrote:
What I was looking to do was monitor either the sound output of the game or the whole system sound.


Probably your code will solve the problem.

I'm sorry, @Corroder, I've noticed now that you mean System voice. Wink

_________________
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: Tue Oct 30, 2018 7:04 pm    Post subject: Re: Can you check sound volume changes through LUA? Reply with quote

AmyGrrl wrote:
What I was looking to do was monitor either the sound output of the game or the whole system sound.


I am not misunderstand what you want. My script above is to show how to control (or set) master volume using keypress event. But as I said, I don't know how to GET sound volume level and print out it to console or others.

I am not see something to GET sound volume level from a media in Cheat Engine lua yet. Something call as Volume Enumerations, but if you must to do it using Lua, then check these :

https://awesomewm.org/awesome-www-backup-old/wiki/Volume_control_and_display.html
https://gist.github.com/rdp/8363580

or use tool :
https://www.nirsoft.net/utils/sound_volume_view.html

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

Joined: 16 Feb 2017
Posts: 1250

PostPosted: Wed Oct 31, 2018 1:07 am    Post subject: Reply with quote

AmyGrrl wrote:
I only want to monitor the sound being produced by the game. So the game is playing music and sound effects and being output at a certain decibel level. Then when the decibel jumps up a bit after this certain sound fx get played. Then it does what I tell it too in the script. I just don't know if this is possible using LUA.



First, in order to use these sounds in Lua
you need to search and encode the change.
Sample:
A Flash Decompiler program, game related
monitors all media and can give their execution codes.
and you can work with these codes in Lua.

So; A Piano Tiles game like hacking voice tones ..

_________________
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: Wed Oct 31, 2018 2:53 am    Post subject: Reply with quote

Give up! Case closed... Shocked Shocked Shocked
_________________
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: Wed Oct 31, 2018 5:44 am    Post subject: Reply with quote

AmyGrrl wrote:
I think people are misunderstanding what I am trying to do. ... Then when the decibel jumps up a bit after this certain sound fx get played. Then it does what I tell it too in the script. I just don't know if this is possible using LUA.
Lua/CE does not have a way to check the current amount of sound coming out of a speaker/from a process. Not sure if the windows API does either but maybe... In theory pretty much anything is possible if you have enough knowledge, unfortunately I've never worked with sound enough to know.
_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Wed Oct 31, 2018 1:51 pm    Post subject: This post has 1 review(s) Reply with quote

Look into doing things via Powershell instead. From Lua you can launch a PowerShell instance and execute a lot more in-depth things.

For example:
https://stackoverflow.com/a/31751275

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