 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Aziixz Cheater
Reputation: 0
Joined: 26 Oct 2021 Posts: 31 Location: Earth
|
Posted: Mon Sep 12, 2022 8:44 pm Post subject: Sound effect on value increase |
|
|
How would I go about playing a sound effect .mp3 to be exact when a value increases on an address, im spefically trying to add a hit sound when I hit a target with a weapon, I found the address counting the hits but dont know how to add a sound effect everytime it increases |
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4697
|
Posted: Mon Sep 12, 2022 9:19 pm Post subject: |
|
|
Use code injection. Maybe load winmm.dll and call playSound from {$ccode}.
If you don't need it to be that exact, you could create a timer in Lua and monitor the value. If it ever goes up, call playSound from CE. _________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Aziixz Cheater
Reputation: 0
Joined: 26 Oct 2021 Posts: 31 Location: Earth
|
Posted: Mon Sep 12, 2022 10:44 pm Post subject: |
|
|
Sorry not very good at lua, it doesnt need to be exact a 60ms delay is fine, so second option would be fine, The address is 1F1E593152C and the mp3 file is Hit.mp3. |
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4697
|
Posted: Mon Sep 12, 2022 11:18 pm Post subject: |
|
|
You'll need to convert the mp3 into a waveform (.wav)
Create a timer (use createTimer), read the value at the address (e.g. readInteger), compare it to a previously read value (use an upvalue). If it increased, update the old value and call playSound.
The CE wiki has some information on various Lua functions, celua.txt has more documentation, and the forums have more examples.
{$ccode} was more interesting to me and currently has far less information around, so I made an example using step 2 of the CE tutorial:
Code: | define(address,"Tutorial-x86_64.exe"+2B4BC)
define(bytes,29 83 F8 07 00 00)
[ENABLE]
loadlibrary(winmm.dll)
{$lua}
-- maybe put this in the main Lua script
function initWav(force)
local oldwav = getAddressSafe'hitwav'
if not force and oldwav then
return
end
local tfile = assert(findTableFile'hit.wav', 'No table file for audio')
local streambuffer, size = tfile.Stream.Memory, tfile.Stream.Size
if oldwav then
unregisterSymbol'hitwav'
deAlloc(oldwav)
oldwav = nil
end
local wavbuffer = assert(allocateMemory(size))
if not copyMemory(streambuffer, size, wavbuffer, 2) then
deAlloc(wavbuffer)
error'Failed to copy memory'
end
registerSymbol('hitwav', wavbuffer, true)
end
initWav()
{$asm}
assert(address,bytes)
alloc(newmem,$1000,"Tutorial-x86_64.exe"+2B4BC)
label(return)
newmem:
{$ccode}
#define SND_SYNC 0x0000 /* play synchronously (default) */
#define SND_ASYNC 0x0001 /* play asynchronously */
#define SND_NODEFAULT 0x0002 /* don't use default sound */
#define SND_MEMORY 0x0004 /* lpszSoundName points to a memory file */
#define SND_LOOP 0x0008 /* loop the sound until next sndPlaySound */
#define SND_NOSTOP 0x0010 /* don't stop any currently playing sound */
#define SND_NOWAIT 0x00002000 /* don't wait if the driver is busy */
#define SND_ALIAS 0x00010000 /* name is a registry alias */
#define SND_ALIAS_ID 0x00110000 /* alias is a predefined ID */
#define SND_FILENAME 0x00020000 /* name is file name */
#define SND_RESOURCE 0x00040004 /* name is resource name or atom */
#define SND_PURGE 0x00000040 /* purge all sounds */
#define SND_APPLICATION 0x00000080 /* look for application specific association */
extern char hitwav[0];
int PlaySound(void *pszSound, void *hmod, unsigned long fdwSound);
PlaySound((void *)hitwav, 0, SND_ASYNC | SND_MEMORY);
{$asm}
sub [rbx+000007F8],eax
jmp return
address:
jmp newmem
nop
return:
[DISABLE]
address:
db bytes
// sub [rbx+000007F8],eax
dealloc(newmem)
{
// ORIGINAL CODE - INJECTION POINT: Tutorial-x86_64.exe+2B4BC
Tutorial-x86_64.exe+2B490: 55 - push rbp
Tutorial-x86_64.exe+2B491: 48 89 E5 - mov rbp,rsp
Tutorial-x86_64.exe+2B494: 48 8D A4 24 D0 FE FF FF - lea rsp,[rsp-00000130]
Tutorial-x86_64.exe+2B49C: 48 89 9D F0 FE FF FF - mov [rbp-00000110],rbx
Tutorial-x86_64.exe+2B4A3: 48 89 CB - mov rbx,rcx
Tutorial-x86_64.exe+2B4A6: 48 C7 45 F8 00 00 00 00 - mov qword ptr [rbp-08],00000000
Tutorial-x86_64.exe+2B4AE: 90 - nop
Tutorial-x86_64.exe+2B4AF: B9 05 00 00 00 - mov ecx,00000005
Tutorial-x86_64.exe+2B4B4: E8 57 47 FE FF - call Tutorial-x86_64.exe+FC10
Tutorial-x86_64.exe+2B4B9: 83 C0 01 - add eax,01
// ---------- INJECTING HERE ----------
Tutorial-x86_64.exe+2B4BC: 29 83 F8 07 00 00 - sub [rbx+000007F8],eax
// ---------- DONE INJECTING ----------
Tutorial-x86_64.exe+2B4C2: 48 8D 4D F8 - lea rcx,[rbp-08]
Tutorial-x86_64.exe+2B4C6: E8 45 DA FD FF - call Tutorial-x86_64.exe+8F10
Tutorial-x86_64.exe+2B4CB: 8B 8B F8 07 00 00 - mov ecx,[rbx+000007F8]
Tutorial-x86_64.exe+2B4D1: 41 B9 FF 00 00 00 - mov r9d,000000FF
Tutorial-x86_64.exe+2B4D7: 4C 8D 85 F8 FE FF FF - lea r8,[rbp-00000108]
Tutorial-x86_64.exe+2B4DE: 48 C7 C2 FF FF FF FF - mov rdx,FFFFFFFFFFFFFFFF
Tutorial-x86_64.exe+2B4E5: 48 63 C9 - movsxd rcx,ecx
Tutorial-x86_64.exe+2B4E8: E8 A3 AB FD FF - call Tutorial-x86_64.exe+6090
Tutorial-x86_64.exe+2B4ED: 45 31 C0 - xor r8d,r8d
Tutorial-x86_64.exe+2B4F0: 48 8D 95 F8 FE FF FF - lea rdx,[rbp-00000108]
} |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Aziixz Cheater
Reputation: 0
Joined: 26 Oct 2021 Posts: 31 Location: Earth
|
Posted: Tue Sep 13, 2022 12:42 am Post subject: |
|
|
ParkourPenguin wrote: | You'll need to convert the mp3 into a waveform (.wav)
Create a timer (use createTimer), read the value at the address (e.g. readInteger), compare it to a previously read value (use an upvalue). If it increased, update the old value and call playSound.
The CE wiki has some information on various Lua functions, celua.txt has more documentation, and the forums have more examples.
{$ccode} was more interesting to me and currently has far less information around, so I made an example using step 2 of the CE tutorial:
Code: | define(address,"Tutorial-x86_64.exe"+2B4BC)
define(bytes,29 83 F8 07 00 00)
[ENABLE]
loadlibrary(winmm.dll)
{$lua}
-- maybe put this in the main Lua script
function initWav(force)
local oldwav = getAddressSafe'hitwav'
if not force and oldwav then
return
end
local tfile = assert(findTableFile'hit.wav', 'No table file for audio')
local streambuffer, size = tfile.Stream.Memory, tfile.Stream.Size
if oldwav then
unregisterSymbol'hitwav'
deAlloc(oldwav)
oldwav = nil
end
local wavbuffer = assert(allocateMemory(size))
if not copyMemory(streambuffer, size, wavbuffer, 2) then
deAlloc(wavbuffer)
error'Failed to copy memory'
end
registerSymbol('hitwav', wavbuffer, true)
end
initWav()
{$asm}
assert(address,bytes)
alloc(newmem,$1000,"Tutorial-x86_64.exe"+2B4BC)
label(return)
newmem:
{$ccode}
#define SND_SYNC 0x0000 /* play synchronously (default) */
#define SND_ASYNC 0x0001 /* play asynchronously */
#define SND_NODEFAULT 0x0002 /* don't use default sound */
#define SND_MEMORY 0x0004 /* lpszSoundName points to a memory file */
#define SND_LOOP 0x0008 /* loop the sound until next sndPlaySound */
#define SND_NOSTOP 0x0010 /* don't stop any currently playing sound */
#define SND_NOWAIT 0x00002000 /* don't wait if the driver is busy */
#define SND_ALIAS 0x00010000 /* name is a registry alias */
#define SND_ALIAS_ID 0x00110000 /* alias is a predefined ID */
#define SND_FILENAME 0x00020000 /* name is file name */
#define SND_RESOURCE 0x00040004 /* name is resource name or atom */
#define SND_PURGE 0x00000040 /* purge all sounds */
#define SND_APPLICATION 0x00000080 /* look for application specific association */
extern char hitwav[0];
int PlaySound(void *pszSound, void *hmod, unsigned long fdwSound);
PlaySound((void *)hitwav, 0, SND_ASYNC | SND_MEMORY);
{$asm}
sub [rbx+000007F8],eax
jmp return
address:
jmp newmem
nop
return:
[DISABLE]
address:
db bytes
// sub [rbx+000007F8],eax
dealloc(newmem)
{
// ORIGINAL CODE - INJECTION POINT: Tutorial-x86_64.exe+2B4BC
Tutorial-x86_64.exe+2B490: 55 - push rbp
Tutorial-x86_64.exe+2B491: 48 89 E5 - mov rbp,rsp
Tutorial-x86_64.exe+2B494: 48 8D A4 24 D0 FE FF FF - lea rsp,[rsp-00000130]
Tutorial-x86_64.exe+2B49C: 48 89 9D F0 FE FF FF - mov [rbp-00000110],rbx
Tutorial-x86_64.exe+2B4A3: 48 89 CB - mov rbx,rcx
Tutorial-x86_64.exe+2B4A6: 48 C7 45 F8 00 00 00 00 - mov qword ptr [rbp-08],00000000
Tutorial-x86_64.exe+2B4AE: 90 - nop
Tutorial-x86_64.exe+2B4AF: B9 05 00 00 00 - mov ecx,00000005
Tutorial-x86_64.exe+2B4B4: E8 57 47 FE FF - call Tutorial-x86_64.exe+FC10
Tutorial-x86_64.exe+2B4B9: 83 C0 01 - add eax,01
// ---------- INJECTING HERE ----------
Tutorial-x86_64.exe+2B4BC: 29 83 F8 07 00 00 - sub [rbx+000007F8],eax
// ---------- DONE INJECTING ----------
Tutorial-x86_64.exe+2B4C2: 48 8D 4D F8 - lea rcx,[rbp-08]
Tutorial-x86_64.exe+2B4C6: E8 45 DA FD FF - call Tutorial-x86_64.exe+8F10
Tutorial-x86_64.exe+2B4CB: 8B 8B F8 07 00 00 - mov ecx,[rbx+000007F8]
Tutorial-x86_64.exe+2B4D1: 41 B9 FF 00 00 00 - mov r9d,000000FF
Tutorial-x86_64.exe+2B4D7: 4C 8D 85 F8 FE FF FF - lea r8,[rbp-00000108]
Tutorial-x86_64.exe+2B4DE: 48 C7 C2 FF FF FF FF - mov rdx,FFFFFFFFFFFFFFFF
Tutorial-x86_64.exe+2B4E5: 48 63 C9 - movsxd rcx,ecx
Tutorial-x86_64.exe+2B4E8: E8 A3 AB FD FF - call Tutorial-x86_64.exe+6090
Tutorial-x86_64.exe+2B4ED: 45 31 C0 - xor r8d,r8d
Tutorial-x86_64.exe+2B4F0: 48 8D 95 F8 FE FF FF - lea rdx,[rbp-00000108]
} |
|
I tried this but it doesnt play anything when the value changes
if syntaxcheck then return end
ExitTimer = true
oldValue = nil
myAddress = "Hitmarker" --Description of the memrec
function checkValue()
local al = getAddressList()
if oldValue == nil then
for i=0,al.Count-1 do
if al[i].Description == Hit then
oldValue = al[i].Value
end
end
else
for i=0,al.Count-1 do
if al[i].Description == Hit then
if al[i].Value ~= oldValue then
playSound(findTableFile('hitmarker.wav'))
oldValue = al[i].Value --Make sure you change the old value to the current one
end
end
end
end
if ExitTimer == true then
cycleTimer.destroy() --Destroy timer
end
end |
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1516
|
Posted: Tue Sep 13, 2022 3:55 am Post subject: |
|
|
--Execute CE Lua Script table or ASM script ..
Code: | --[ENABLE]
--{$lua}
if cycleTimer then cycleTimer.Destroy() cycleTimer=nil end
cycleTimer=createTimer() cycleTimer.Interval=100 cycleTimer.Enabled=false
--ExitTimer = true
oldValue = nil
myAddress = "Hitmarker" --Description of the memrec
function checkValue()
local al = getAddressList()
if oldValue == nil then
for i=0,al.Count-1 do
if al[i].Description == myAddress then
oldValue = al[i].Value
end
end
else
for i=0,al.Count-1 do
if al[i].Description == myAddress then
if al[i].Value ~= oldValue then
playSound(findTableFile('hitmarker.wav'))
oldValue = al[i].Value --Make sure you change the old value to the current one
end
end
end
end
--if ExitTimer == true then
--cycleTimer.destroy() --Destroy timer
--end
end
cycleTimer.OnTimer = checkValue
if ExitKey then ExitKey.Destroy() ExitKey=nil end
-- check open-close key (F8)
ExitKey = createHotkey((function()
sleep(200)
if cycleTimer.Enabled==false then
cycleTimer.Enabled=true
else
cycleTimer.Enabled=false
end
end), VK_F8)
--{$asm}
--[DISABLE]
--{$lua}
--if ExitKey then ExitKey.Destroy() ExitKey=nil end
--if cycleTimer then cycleTimer.Destroy() cycleTimer=nil end |
_________________
|
|
Back to top |
|
 |
Aziixz Cheater
Reputation: 0
Joined: 26 Oct 2021 Posts: 31 Location: Earth
|
Posted: Tue Sep 13, 2022 4:43 am Post subject: |
|
|
AylinCE wrote: | --Execute CE Lua Script table or ASM script ..
Code: | --[ENABLE]
--{$lua}
if cycleTimer then cycleTimer.Destroy() cycleTimer=nil end
cycleTimer=createTimer() cycleTimer.Interval=100 cycleTimer.Enabled=false
--ExitTimer = true
oldValue = nil
myAddress = "Hitmarker" --Description of the memrec
function checkValue()
local al = getAddressList()
if oldValue == nil then
for i=0,al.Count-1 do
if al[i].Description == myAddress then
oldValue = al[i].Value
end
end
else
for i=0,al.Count-1 do
if al[i].Description == myAddress then
if al[i].Value ~= oldValue then
playSound(findTableFile('hitmarker.wav'))
oldValue = al[i].Value --Make sure you change the old value to the current one
end
end
end
end
--if ExitTimer == true then
--cycleTimer.destroy() --Destroy timer
--end
end
cycleTimer.OnTimer = checkValue
if ExitKey then ExitKey.Destroy() ExitKey=nil end
-- check open-close key (F8)
ExitKey = createHotkey((function()
sleep(200)
if cycleTimer.Enabled==false then
cycleTimer.Enabled=true
else
cycleTimer.Enabled=false
end
end), VK_F8)
--{$asm}
--[DISABLE]
--{$lua}
--if ExitKey then ExitKey.Destroy() ExitKey=nil end
--if cycleTimer then cycleTimer.Destroy() cycleTimer=nil end |
|
Hey thanks but no sound plays when the value changes, I added the file via table --> Add file --> hitmarker.wav and execute the script but no sound plays. |
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1516
|
|
Back to top |
|
 |
Aziixz Cheater
Reputation: 0
Joined: 26 Oct 2021 Posts: 31 Location: Earth
|
Posted: Tue Sep 13, 2022 6:43 am Post subject: |
|
|
AylinCE wrote: | my sound:
-------------------
Unlike, you have to make sure you get the value correctly. (Are you reading the value correctly?)
ParkourPenguin wrote: | read the value at the address (e.g. readInteger), compare it to a previously read value (use an upvalue). |
I posted this code because it works.  |
I don't doubt it works I just cant get it to work on my end, The value im reading from is an address with te description Hitmarker, the value is a 4 byte and starts at one when i boot the game and increases by 1 everytime i hit an enemy, I'm not quite what you mean by not reading the value correctly, Or maybe I just dont understand |
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1516
|
Posted: Tue Sep 13, 2022 7:01 am Post subject: |
|
|
Code: | --[ENABLE]
--{$lua}
if cycleTimer then cycleTimer.Destroy() cycleTimer=nil end
cycleTimer=createTimer() cycleTimer.Interval=100 cycleTimer.Enabled=false
--ExitTimer = true
oldValue = nil
myAddress = "Hitmarker" --Description of the memrec
--check description:
local al = getAddressList()
for i=0,al.Count-1 do
print(i .. " - " .. al[i].Description .. " - " .. al[i].Value)
end
function checkValue()
local al = getAddressList()
if oldValue == nil then
for i=0,al.Count-1 do
if al[i].Description == myAddress then
print("Value1: " .. al[i].Value)
oldValue = al[i].Value
end
end
else
for i=0,al.Count-1 do
if al[i].Description == myAddress then
print("Value2: " .. al[i].Value)
if al[i].Value ~= oldValue then
playSound(findTableFile('hitmarker.wav'))
print("Sound effect enabled!")
oldValue = al[i].Value --Make sure you change the old value to the current one
end
end
end
end
--if ExitTimer == true then
--cycleTimer.destroy() --Destroy timer
--end
end
cycleTimer.OnTimer = checkValue
if ExitKey then ExitKey.Destroy() ExitKey=nil end
-- check open-close key (F8)
ExitKey = createHotkey((function()
sleep(200)
if cycleTimer.Enabled==false then
cycleTimer.Enabled=true
print("Timer start!")
else
cycleTimer.Enabled=false
print("Timer stop!")
end
end), VK_F8)
--{$asm}
--[DISABLE]
--{$lua}
--if ExitKey then ExitKey.Destroy() ExitKey=nil end
--if cycleTimer then cycleTimer.Destroy() cycleTimer=nil end |
I added a few tests to the code. (If the script description is correct, it will print the value. If everything goes well, a sound effect active warning will appear.)
Also, after activating the code, you should make sure that you press the "F8" key to make the timer work. If you press "F8" again, the timer will stop.
As with my first post, the code still works fine. Check which of the tests I added did not come up. _________________
|
|
Back to top |
|
 |
Aziixz Cheater
Reputation: 0
Joined: 26 Oct 2021 Posts: 31 Location: Earth
|
Posted: Tue Sep 13, 2022 7:26 pm Post subject: |
|
|
Hi thank you so much for helping me, I'm an idiot and didn't hit the F8 button, everything works perfectly now, Just curious if there's anyway to allow sounds to play over each other instead of waiting for each sound to finish since I usually hit enemies many times within 1 second but only 1 sound effect plays. Thanks again |
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1516
|
Posted: Wed Sep 14, 2022 6:55 am Post subject: |
|
|
Just play with the timer duration that reads the script value. (Shorten it). But this will cause the sound to sound shorter, so if you set the timer reading speed to 100 (Timer.Interval=100); 1000 ms (1sec) plays 100 ms from the beginning of the sound.
Here is an example without a game. (Just connect it to the CE process and match it with a valid address. Then run the script and press "F8" to see what happens.
https://www.mediafire.com/file/7qymtxhdz8ikcvq/sampleHitmarker25ms.CT/file
If you consider shortening the sound length;
https://audiotrimmer.com/ _________________
|
|
Back to top |
|
 |
|
|
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
|
|