Added support for panning sfx sounds

Removed the tweak that adds the city name in the description for empty
save slots (commit b0a35ee)
This commit is contained in:
NovaRain
2020-12-26 21:57:18 +08:00
parent 279f91274e
commit 3798247a68
4 changed files with 47 additions and 30 deletions
+2 -1
View File
@@ -19,6 +19,7 @@
#pragma once
#include <Windows.h>
#include <dsound.h>
#include "Enums.h"
@@ -922,7 +923,7 @@ struct ACMSoundData {
void* FileSizeFunc;
long openAudioIndex;
long memData;
long soundBuffer;
IDirectSoundBuffer* soundBuffer;
long dwSize; // begin DSBUFFERDESC structure
long dwFlags;
long dwBufferBytes;
-28
View File
@@ -482,31 +482,6 @@ static void __declspec(naked) SaveGame_hack1() {
}
}
///////////////////////////////////////////////////////////////////////////////
static void __fastcall SetSaveComment(char* comment) {
int i = 0;
const char* mapName = fo::func::map_get_short_name(fo::var::map_number);
do {
comment[i] = mapName[i];
} while (++i < 20 && mapName[i]);
comment[i++] = ':';
comment[i] = '\0';
}
static void __declspec(naked) GetComment_hack() {
__asm {
cmp [ecx], 0;
jne notEmpty;
pushadc;
call SetSaveComment;
popadc;
notEmpty:
push 0x47F031;
jmp fo::funcoffs::get_input_str2_;
}
}
void ExtraSaveSlots::init() {
bool extraSaveSlots = (GetConfigInt("Misc", "ExtraSaveSlots", 0) != 0);
if (extraSaveSlots) {
@@ -534,9 +509,6 @@ void ExtraSaveSlots::init() {
MakeJump(0x47B984, SaveGame_hack0);
dlogr(" Done", DL_INIT);
}
// Adds the city name in the description for empty save slots
MakeJump(0x47F02C, GetComment_hack);
}
void ExtraSaveSlots::exit() {
+1
View File
@@ -584,6 +584,7 @@ static void InterfaceWindowPatch() {
SafeWrite8(0x41B966, (*(BYTE*)0x41B966) ^ fo::WinFlags::MoveOnTop); // Automap
// Set OwnerFlag flag
SafeWrite8(0x4D5EBF, fo::WinFlags::OwnerFlag); // win_init_ (main win)
SafeWrite8(0x481CEC, (*(BYTE*)0x481CEC) | fo::WinFlags::OwnerFlag); // _display_win (map win)
SafeWrite8(0x44E7D2, (*(BYTE*)0x44E7D2) | fo::WinFlags::OwnerFlag); // gmovie_play_ (movie win)
+44 -1
View File
@@ -18,6 +18,7 @@
#include <unordered_map>
#include <algorithm>
#include <dsound.h>
#include <dshow.h>
#include "..\main.h"
@@ -896,6 +897,43 @@ rawFile:
}
}
///////////////////////////////////////////////////////////////////////////////
static fo::GameObject* relativeObject;
static long relativeDistance = 0;
static void __declspec(naked) gsound_compute_relative_volume_hook() {
__asm {
call fo::funcoffs::obj_dist_;
mov relativeDistance, eax;
mov relativeObject, ecx;
retn;
}
}
static void __fastcall SetPanPosition(fo::ACMSoundData* sound) {
if (relativeDistance <= 5) return;
long direction = fo::func::tile_dir(fo::var::obj_dude->tile, relativeObject->tile);
bool isRightSide = (direction <= 2);
long panValue = (relativeDistance / 2) * 1000;
if (panValue > 10000) panValue = 10000;
if (!isRightSide) panValue = -panValue; // left mute 10000 ... -10000 right mute
sound->soundBuffer->SetPan(panValue);
relativeDistance = 0;
}
static void __declspec(naked) gsound_load_sound_volume_hook() {
__asm {
call fo::funcoffs::soundVolume_;
mov ecx, ebx; // sound
jmp SetPanPosition;
}
}
constexpr int SampleRate = 44100; // 44.1kHz
void Sound::init() {
@@ -906,6 +944,11 @@ void Sound::init() {
LoadGameHook::OnGameReset() += WipeSounds;
LoadGameHook::OnBeforeGameClose() += WipeSounds;
// Enable support for panning sfx sounds
SafeWrite8(0x45237E, (*(BYTE*)0x45237E) | 4); // set mode for DSBCAPS_CTRLPAN
HookCall(0x4515AC, gsound_compute_relative_volume_hook);
HookCall(0x451483, gsound_load_sound_volume_hook);
HookCall(0x44E816, gmovie_play_hook_pause);
HookCall(0x44EA84, gmovie_play_hook_unpause);
MakeCall(0x450525, gsound_background_volume_set_hack);
@@ -952,7 +995,7 @@ void Sound::init() {
});
int sBuff = GetConfigInt("Sound", "NumSoundBuffers", 0);
if (sBuff > 0) {
if (sBuff > 4) {
SafeWrite8(0x451129, (sBuff > 32) ? (BYTE)32 : (BYTE)sBuff);
}