summaryrefslogtreecommitdiffstats
path: root/src/audio/AudioManager.cpp
blob: 1bcd98ae2fc00b17bdd12ff41158f89a9788ef3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "common.h"
#include "patcher.h"
#include "AudioManager.h"

cAudioManager &AudioManager = *(cAudioManager*)0x880FC0;

void
cAudioManager::PlayerJustLeftCar(void)
{
	// UNUSED: This is a perfectly empty function.
}

void
cAudioManager::GetPhrase(eAudioSamples *phrase, eAudioSamples *prevPhrase,
                         eAudioSamples sample, uint32 maxOffset)
{
	*phrase = eAudioSamples(
	    sample +
	    (uint32)m_anRandomTable[m_sQueueSample.m_nEntityIndex & 3] %
	        maxOffset);
	if(*phrase == *prevPhrase &&
	   ++*(uint32 *)phrase >= (uint32)sample + maxOffset)
		*phrase = sample;
	*prevPhrase = *phrase;
}

static bool &bUsedPlayerTalkSfx = *(bool *)0x6508f4;
static eAudioSamples &lastPlayerTalkSfx = *(eAudioSamples *)0x6508f0;

uint32
cAudioManager::GetPlayerTalkSfx(eSound sound)
{
	eAudioSamples sfx;

	if(!bUsedPlayerTalkSfx) {
		bUsedPlayerTalkSfx = true;
		lastPlayerTalkSfx = NO_SAMPLE;
	}
	switch(sound) {
	case SOUND_PED_DAMAGE:
		cAudioManager::GetPhrase(&sfx, &lastPlayerTalkSfx,
		                         AUDIO_SAMPLE_PED_DAMAGE_REACTION_1,
		                         11u);
		break;

	case SOUND_PED_HIT:
		cAudioManager::GetPhrase(&sfx, &lastPlayerTalkSfx,
		                         AUDIO_SAMPLE_PED_HIT_REACTION_1, 10u);
		break;

	case SOUND_PED_LAND:
		cAudioManager::GetPhrase(&sfx, &lastPlayerTalkSfx,
		                         AUDIO_SAMPLE_PED_FALL_REACTION_1, 6u);
		break;

	default: sfx = NO_SAMPLE; break;
	}
	return sfx;
}

static bool &bUsedGenericMaleTalkSfx = *(bool *)0x650B0C;
static eAudioSamples &lastGenericMaleTalkSfx = *(eAudioSamples *)0x650B08;

uint32
cAudioManager::GetGenericMaleTalkSfx(eSound sample)
{
	eAudioSamples sfx;

	if(!bUsedGenericMaleTalkSfx) {
		bUsedGenericMaleTalkSfx = 1;
		lastGenericMaleTalkSfx = NO_SAMPLE;
	}
	switch(sample) {
	case SOUND_PED_DEATH:
		cAudioManager::GetPhrase(&sfx, &lastGenericMaleTalkSfx,
		                         AUDIO_SAMPLE_PED_MALE_DEATH_1, 8u);
		break;
	case SOUND_PED_BULLET_HIT:
	case SOUND_PED_DEFEND:
		cAudioManager::GetPhrase(&sfx, &lastGenericMaleTalkSfx,
		                         AUDIO_SAMPLE_INJURED_PED_MALE_OUCH_1,
		                         15u);
		break;
	case SOUND_PED_BURNING:
		cAudioManager::GetPhrase(&sfx, &lastGenericMaleTalkSfx,
		                         AUDIO_SAMPLE_PED_MALE_BURNING_1, 8u);
		break;
	case SOUND_PED_FLEE_SPRINT:
		cAudioManager::GetPhrase(&sfx, &lastGenericMaleTalkSfx,
		                         AUDIO_SAMPLE_PED_MALE_FLEE_SPRINT_1,
		                         6u);
		break;
	default: return NO_SAMPLE;
	}
	return sfx;
}

WRAPPER void cAudioManager::Service() { EAXJMP(0x57A2A0); }

STARTPATCHES
InjectHook(0x56AD20, &cAudioManager::PlayerJustLeftCar, PATCH_JUMP);
InjectHook(0x570DB0, &cAudioManager::GetPhrase, PATCH_JUMP);
InjectHook(0x570E00, &cAudioManager::GetPlayerTalkSfx, PATCH_JUMP);
InjectHook(0x575460, &cAudioManager::GetGenericMaleTalkSfx, PATCH_JUMP);
ENDPATCHES