Skip to content

Commit

Permalink
feat(gt_core): add playMP3
Browse files Browse the repository at this point in the history
  • Loading branch information
loktionov129 committed Apr 21, 2020
1 parent 785d870 commit 4864c9e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
5 changes: 4 additions & 1 deletion app/lib/gt_core/src/trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ namespace gt::core

lua.registerFunction("addValueTo", lambada);

lua.registerFunction("playSound", os::playSound);
// TODO: remove unused parameter for stopMP3.
lua.registerFunction("stopMP3", os::stopMP3);
lua.registerFunction("playMP3", os::playMP3);
lua.registerFunction("playWAV", os::playWAV);

lua.registerFunction("readFile", lua::LuaWrapper::createUserData);

Expand Down
4 changes: 3 additions & 1 deletion app/lib/gt_os/inc/gt_os/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

namespace gt::os
{
void playSound(const char* sound);
void stopMP3(const char* sound);
void playMP3(const char* sound);
void playWAV(const char* sound);
void setConsoleTitle(const char* title);
void sleep(size_t ms);

Expand Down
18 changes: 17 additions & 1 deletion app/lib/gt_os/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@

namespace gt::os
{
void playSound(const char* sound)
void playWAV(const char* sound)
{
PlaySoundA((LPCSTR)sound, nullptr, SND_APPLICATION | SND_ASYNC | SND_NODEFAULT); // NOLINT(hicpp-signed-bitwise)
}

void playMP3(const char* sound)
{
char cmd[MAX_PATH] = { '\0' };
lstrcat(cmd, "play \"");
lstrcat(cmd, sound);
lstrcat(cmd, "\"");
mciSendString(cmd, nullptr, 0, nullptr);
}

// TODO: remove unused parameter.
void stopMP3(const char* sound)
{
mciSendString("stop all", nullptr, 0, nullptr);
mciSendString("close all", nullptr, 0, nullptr);
}

void setConsoleTitle(const char* title)
{
SetConsoleTitle(title);
Expand Down
39 changes: 32 additions & 7 deletions app/resources/data/scripts/KillingFloor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,51 @@ registeredKeys = {
keyCodes.VK_F6,
keyCodes.VK_F7,
keyCodes.VK_F8,
keyCodes.VK_F9
keyCodes.VK_F9,
keyCodes.VK_F11
}

godmode = false
noreload = false

function toggleCheat(cheat, name)
if cheat then
print(name .. ' enabled')
api.playWAV('sounds/on.wav')
else
print(name .. ' disabled')
api.playWAV('sounds/off.wav')
end
end

function handleKey (key, shift, ctrl, alt)
if key == keyCodes.VK_F6 then
print('god mode')
api.playSound('sounds/on.wav')
godmode = not godmode
toggleCheat(godmode, 'godmode')
elseif key == keyCodes.VK_F7 then
print('no reload')
api.playSound('sounds/on.wav')
noreload = not noreload
toggleCheat(noreload, 'noreload')
elseif key == keyCodes.VK_F8 then
api.addValueTo(entries.money, 1000)
print('increase money')
api.playSound('sounds/money.wav')
api.playWAV('sounds/money.wav')
elseif key == keyCodes.VK_F9 and shift and ctrl and alt then
print('level up for all perks')
api.playSound('sounds/experience.wav')
api.playMP3('sounds/surprise.mp3')
elseif key == keyCodes.VK_F11 then
api.stopMP3('')
end
end

function tick()
if godmode then
-- addValueTo(entries.health, 100)
-- addValueTo(entries.armor, 100)
end

if noreload then
-- addValueTo(entries.ammo_magazine, 30)
-- addValueTo(entries.ammo_total, 30)
-- addValueTo(entries.ammo_gren, 5)
end
end
4 changes: 3 additions & 1 deletion app/resources/data/scripts/shared/api.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
return {
playSound = playSound,
stopMP3 = stopMP3,
playMP3 = playMP3,
playWAV = playWAV,
addValueTo = addValueTo,
readFile = readFile
}
Binary file added app/resources/data/sounds/surprise.mp3
Binary file not shown.

0 comments on commit 4864c9e

Please sign in to comment.