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 


Play two playsounds at the same time

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
HexaG0n
How do I cheat?
Reputation: 0

Joined: 29 Mar 2021
Posts: 9

PostPosted: Sat Apr 03, 2021 9:54 pm    Post subject: Play two playsounds at the same time Reply with quote

How do i play a playsound without stopping another playsound [ currently playing ]? if its possible, can you tell me how? e.g

playSound(findTableFile("1.wav"))
playSound(findTableFile("2.wav"))

-- play without stopping
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 406

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

PostPosted: Thu Apr 08, 2021 6:34 am    Post subject: Reply with quote

playSound(findTableFile("1.wav"), false)
_________________
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
HexaG0n
How do I cheat?
Reputation: 0

Joined: 29 Mar 2021
Posts: 9

PostPosted: Thu Apr 08, 2021 9:01 am    Post subject: Reply with quote

do i always need to keep pasting the script to play different sounds together? like

a()

b()

c()

-- all in seperate scripts [ eg function a(), b(), c() ]

if u dont understand i mean this



playSoundExampleSc.PNG
 Description:
 Filesize:  47.39 KB
 Viewed:  280 Time(s)

playSoundExampleSc.PNG


Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 1

Joined: 05 Sep 2020
Posts: 123

PostPosted: Thu Apr 08, 2021 10:55 am    Post subject: Reply with quote

There is a simpler way.
Code (Play MP3 audio on CE): By mgr.inz.Player
First, convert your ".wav" audio format to ".mp3".

https://online-audio-converter.com/

I made a few additions to the existing code.
Here is a usable and tried version.
Play and end multiple sounds at the same time.

Note: If you want to add more sound, edit the deleted positions of "Bass3" and "Bass4". Or add "Bass5" +.

Code:
--##############################################################################
--############################# By mgr.inz.Player ##############################

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, media)
  if not initializeMP3Player() then return end

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


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

  MP3PlayerSendCommand('close MediaFile1')
  MP3PlayerSendCommand('close MediaFile2')
  --MP3PlayerSendCommand('close MediaFile3')
  --MP3PlayerSendCommand('close MediaFile4')
end

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

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

local pth = TrainerOrigin or getMainForm()

function checkFile(fileMP3) --Fix="Error:Unable to create file"
local f2=(pth..'\\'..fileMP3)
if f2==nil then
findTableFile(fileMP3).saveToFile(pth..'\\'..fileMP3)
end
return f2
end

file1=checkFile("Bass.mp3")
file2=checkFile("Bass2.mp3")
--file3=checkFile("Bass3.mp3")
--file4=checkFile("Bass4.mp3")

stopMP3()

function Play1()
stopMP3()
playMP3(file1,"MediaFile1")
playMP3(file2,"MediaFile2")
end

function Play2()
stopMP3()
playMP3(file1,"MediaFile1")
playMP3(file2,"MediaFile2")
--playMP3(file3,"MediaFile3")
--playMP3(file4,"MediaFile4")
end
Back to top
View user's profile Send private message
HexaG0n
How do I cheat?
Reputation: 0

Joined: 29 Mar 2021
Posts: 9

PostPosted: Thu Apr 08, 2021 10:48 pm    Post subject: Reply with quote

can you send me a example ct for this script? cuz when i try to run it, it keeps giving me this error:

Error:[string "--###########################################..."]:109: attempt to concatenate a userdata value (upvalue 'pth')
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 1

Joined: 05 Sep 2020
Posts: 123

PostPosted: Fri Apr 09, 2021 6:04 am    Post subject: Reply with quote

HexaG0n wrote:
can you send me a example ct for this script? cuz when i try to run it, it keeps giving me this error:

Error:[string "--###########################################..."]:109: attempt to concatenate a userdata value (upvalue 'pth')


Code:
local pth = TrainerOrigin veya getMainForm ()


For this code to be valid; After copying and pasting the code, save the current table (.CT).
Next, continue from the registered table (sample.CT).

Or create a different location for recording;
Change;
Code:
local pth = TrainerOrigin veya getMainForm ()


New:
Code:
--local pth = TrainerOrigin or getMainForm()

local pth1 = os.getenv("APPDATA").."\\Local\\Temp";
local pth = (pth1..[[\AudioFile\]])

if pth then
os.execute([[mkdir "]]..pth1..[[\AudioFile"]]);

findTableFile("Bass.mp3").saveToFile(pth.."Bass.mp3")
findTableFile("Bass2.mp3").saveToFile(pth.."Bass2.mp3")
file1=(pth.."Bass.mp3")
file2=(pth.."Bass2.mp3")
--findTableFile("Bass3.mp3").saveToFile(pth.."Bass3.mp3")
--findTableFile("Bass4.mp3").saveToFile(pth.."Bass4.mp3")
--file3=(pth.."Bass3.mp3")
--file4=(pth.."Bass4.mp3")
end


Of course, when closing the Trainer, it is necessary to delete this added file.
Add to trainer close function;
Code:
os.remove(pth)
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 63

Joined: 10 Apr 2015
Posts: 1548

PostPosted: Sat Apr 10, 2021 7:21 pm    Post subject: This post has 1 review(s) Reply with quote

First, you don't need convert your WAV sound file to MP3 format. mciSendString is capable to play wav file by default.

Here is an example, how to play sound1, play sound2 or combine the two sounds or play the two sounds at the same time.

Note:
1. Remember to give correct path name for the sounds location and sound file extension.
2. You also can create new functions to handle sounds playing as you want


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

local script64bit=[[loadlibrary(C:\Windows\System32\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(C:\Windows\System32\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 play1(sound1)
 if not initializeMP3Player() then return end
 local fileName
 fileName = sound1
 MP3PlayerSendCommand("open "..fileName.." type mpegvideo alias FirstSound", 0, 0, 0)
 MP3PlayerSendCommand("play FirstSound", 0, 0, 0)
end

function play2(sound2)
 if not initializeMP3Player() then return end
 local fileName
 fileName = sound2
 MP3PlayerSendCommand("open "..fileName.." type mpegvideo alias SecondSound", 0, 0, 0)
 MP3PlayerSendCommand("play SecondSound", 0, 0, 0)
end

function playMulti(song1, song2, song3, song4, ...)
 if not initializeMP3Player() then return end
 local fileName
 fileName = song1
 MP3PlayerSendCommand("open "..fileName.." type mpegvideo alias FirstSound", 0, 0, 0)
 MP3PlayerSendCommand("play FirstSound", 0, 0, 0)

 fileName = song2
 MP3PlayerSendCommand("open "..fileName.." type mpegvideo alias SecondSound", 0, 0, 0)
 MP3PlayerSendCommand("play SecondSound repeat",0, 0, 0)
end

function stopAll()
 if not initializeMP3Player() then return end
 MP3PlayerSendCommand('stop FirstSound')
 MP3PlayerSendCommand('close FirstSound')
 MP3PlayerSendCommand('stop SecondSound')
 MP3PlayerSendCommand('close SecondSound')
end

s1 = "D:\\Audio1.mp3"
s2 = "D:\\Audio2.wav"


UDF1.CEButton1.OnClick = function()
 play1(s1)
end

UDF1.CEButton2.OnClick = function()
 play2(s2)
end

UDF1.CEButton4.OnClick = function()
 stopAll()
end

UDF1.CEButton5.OnClick = function()
 playMulti(s1, s2)
end

UDF1.Show()

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 1

Joined: 05 Sep 2020
Posts: 123

PostPosted: Sat Apr 10, 2021 7:59 pm    Post subject: Reply with quote

HexaG0n wrote:
how can i loop playsounds? when it ends it plays the sound again.


In @Corroder's code above, there is an answer to the question.
Code:
 fileName = song2
 MP3PlayerSendCommand("open "..fileName.." type mpegvideo alias SecondSound", 0, 0, 0)
 MP3PlayerSendCommand("play SecondSound repeat",0, 0, 0)


Alternatively, you can compare the current length and position of the music and use restart when it reaches the same position (or earlier).
The codes below will provide you with these times.

Code:
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


However, if you are going to insist on "playSound", you will be left with limited possibilities. Wink

Corroder wrote:
First, you don't need convert your WAV sound file to MP3 format. mciSendString is capable to play wav file by default.


I assumed MP3 would use less memory in the Trainer.
I saw you store the audio files in the table.
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