Merge pull request #354 from zsilencer/master

Decompiled audio functions
This commit is contained in:
Ted John 2014-08-24 11:31:40 +01:00
commit 2bec80b722
7 changed files with 212 additions and 14 deletions

View File

@ -154,8 +154,11 @@
#define RCT2_ADDRESS_WINDOW_DPI 0x009DEA74
#define RCT2_ADDRESS_DSOUND_BUFFERS 0x009E1AB0
#define RCT2_ADDRESS_NUM_DSOUND_DEVICES 0x009E2B88
#define RCT2_ADDRESS_DSOUND_DEVICES 0x009E2B8C
#define RCT2_ADDRESS_SOUNDLIST_BEGIN 0x009E2B98
#define RCT2_ADDRESS_SOUNDLIST_END 0x009E2B9C
#define RCT2_ADDRESS_CMDLINE 0x009E2D98

View File

@ -65,6 +65,10 @@ void audio_get_devices()
}
}
/**
*
* rct2: 0x0040502E
*/
void get_dsound_devices()
{
RCT2_CALLPROC(0x0040502E);
@ -80,14 +84,176 @@ void sound_play_panned(int sound_id, int x)
RCT2_CALLPROC_X(0x006BB76E, sound_id, x, 0, 0, 0, 0, 0);
}
int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency)
/**
*
* rct2: 0x00401999
*/
int sound_channel_play(int channel, int a2, int volume, int pan, int frequency)
{
return RCT2_CALLFUNC_5(0x00404E7F, int, rct_sound*, int, int, int, int, sound, looping, volume, pan, frequency);
RCT2_GLOBAL(0x1426444 + (91 * channel * 4), uint32) = a2;
sound_channel_set_frequency(channel, frequency);
sound_channel_set_pan(channel, pan);
sound_channel_set_volume(channel, volume);
LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel];
dsbuffer->lpVtbl->SetCurrentPosition(dsbuffer, 0);
dsbuffer->lpVtbl->Play(dsbuffer, 0, 0, DSBPLAY_LOOPING);
RCT2_GLOBAL(0x14262E0 + (91 * channel * 4), uint32) = 1;
return 1;
}
/**
*
* rct2: 0x00401A93
*/
int sound_channel_set_frequency(int channel, int frequency)
{
LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel];
if (dsbuffer) {
if (SUCCEEDED(dsbuffer->lpVtbl->SetFrequency(dsbuffer, frequency)))
return 1;
}
return 0;
}
/**
*
* rct2: 0x00401AB3
*/
int sound_channel_set_pan(int channel, int pan)
{
LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel];
if (dsbuffer) {
if (SUCCEEDED(dsbuffer->lpVtbl->SetPan(dsbuffer, pan)))
return 1;
}
return 0;
}
/**
*
* rct2: 0x00401AD3
*/
int sound_channel_set_volume(int channel, int volume)
{
LPDIRECTSOUNDBUFFER dsbuffer = RCT2_ADDRESS(RCT2_ADDRESS_DSOUND_BUFFERS, LPDIRECTSOUNDBUFFER)[channel];
if (dsbuffer) {
if (SUCCEEDED(dsbuffer->lpVtbl->SetVolume(dsbuffer, volume)))
return 1;
}
return 0;
}
/**
*
* rct2: 0x00404E7F
*/
int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency)
{
if (sound) {
sound_set_frequency(sound, frequency);
sound_set_pan(sound, pan);
sound_set_volume(sound, volume);
DWORD playflags;
if (looping) {
if (looping != 1)
return 1;
playflags = DSBPLAY_LOOPING;
} else {
playflags = 0;
}
if (SUCCEEDED(sound->dsbuffer->lpVtbl->Play(sound->dsbuffer, 0, 0, playflags)))
return 1;
}
return 0;
}
/**
*
* rct2: 0x00404ED7
*/
int sound_set_frequency(rct_sound* sound, int frequency)
{
if (sound) {
if (SUCCEEDED(sound->dsbuffer->lpVtbl->SetFrequency(sound->dsbuffer, frequency)))
return 1;
}
return 0;
}
/**
*
* rct2: 0x00404EF2
*/
int sound_set_pan(rct_sound* sound, int pan)
{
if (sound) {
if (SUCCEEDED(sound->dsbuffer->lpVtbl->SetPan(sound->dsbuffer, pan)))
return 1;
}
return 0;
}
/**
*
* rct2: 0x00404F0D
*/
int sound_set_volume(rct_sound* sound, int volume)
{
if (sound) {
if (SUCCEEDED(sound->dsbuffer->lpVtbl->SetVolume(sound->dsbuffer, volume)))
return 1;
}
return 0;
}
/**
*
* rct2: 0x00404DD8
*/
void sound_stop(rct_sound* sound)
{
RCT2_CALLPROC_1(0x00404DD8, rct_sound*, sound);
if (sound->dsbuffer) {
sound->dsbuffer->lpVtbl->Release(sound->dsbuffer);
sound->dsbuffer = 0;
sound_remove(sound);
}
}
/**
*
* rct2: 0x00405143
*/
rct_sound* sound_remove(rct_sound* sound)
{
rct_sound* result = RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_BEGIN, rct_sound*);
if (sound == result) {
if (sound == RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_END, rct_sound*)) {
RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_END, rct_sound*) = 0;
RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_BEGIN, rct_sound*) = 0;
}
result = sound->next;
RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_BEGIN, rct_sound*) = result;
} else {
while (result->next != sound)
result = result->next;
if (sound == RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_END, rct_sound*)) {
RCT2_GLOBAL(RCT2_ADDRESS_SOUNDLIST_END, rct_sound*) = result;
result->next = 0;
} else
result->next = sound->next;
}
sound->next = 0;
return result;
}
/**

View File

@ -47,19 +47,27 @@ typedef struct {
/**
* Represents a prepared sound.
*/
typedef struct {
typedef struct rct_sound {
LPDIRECTSOUNDBUFFER dsbuffer;
int id;
int has_caps;
int var_0C;
int var_10;
struct rct_sound* next;
} rct_sound;
void get_dsound_devices();
int sound_prepare(int sound_id, rct_sound *sound, int var_8, int var_c);
void sound_play_panned(int sound_id, int x);
int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency);
int sound_set_frequency(rct_sound* sound, int frequency);
int sound_set_pan(rct_sound* sound, int pan);
int sound_set_volume(rct_sound* sound, int volume);
int sound_channel_play(int channel, int a2, int volume, int pan, int frequency);
int sound_channel_set_frequency(int channel, int frequency);
int sound_channel_set_pan(int channel, int pan);
int sound_channel_set_volume(int channel, int volume);
void sound_stop(rct_sound *sound);
rct_sound* sound_remove(rct_sound* sound);
void pause_sounds();
void unpause_sounds();

View File

@ -109,7 +109,9 @@ typedef struct {
uint16 build_date;
sint16 upkeep_cost; // 0x182
uint16 race_winner; // 0x184
uint8 pad_186[0x10];
uint8 pad_186[0x06];
uint8 var_18C;
uint8 pad_18D[0x09];
uint16 var_196;
// used in computing excitement, nausea, etc
uint8 var_198;

View File

@ -35,8 +35,27 @@ typedef struct {
sint16 x; // 0x0E
sint16 y; // 0x10
sint16 z; // 0x12
uint8 pad_14[0x2A];
uint8 pad_14[0x0B];
uint8 var_1F;
uint8 pad_20[0x08];
uint32 var_28;
uint8 pad_2C[0x04];
uint8 ride; // 0x30
uint8 var_31;
uint8 pad_32[0x0C];
uint16 next_vehicle_on_train; // 0x3E
uint8 pad_40[0x08];
uint16 var_48;
uint8 pad_4A[0x06];
uint8 var_50;
uint8 var_51;
uint8 pad_52[0x69];
uint16 var_BB;
uint16 var_BD;
uint8 pad_BF[0x0D];
uint8 var_CC;
uint8 pad_CD[0x09];
uint8 var_D6;
} rct_vehicle;
void vehicle_update_all();

View File

@ -28,7 +28,7 @@
#include "window.h"
#include "window_dropdown.h"
#define SELECTED_RIDE_UNDEFINED ((sint16)0xFFFF)
#define SELECTED_RIDE_UNDEFINED ((uint16)0xFFFF)
enum WINDOW_NEW_CAMPAIGN_WIDGET_IDX {
WIDX_BACKGROUND,

View File

@ -431,7 +431,7 @@ void window_new_ride_open()
w->colours[0] = 24;
w->colours[1] = 26;
w->colours[2] = 26;
w->new_ride.selected_ride_countdown = -1;
w->new_ride.selected_ride_id = -1;
w->new_ride.highlighted_ride_id = -1;
_lastTrackDesignCountRideType.type = 255;
_lastTrackDesignCountRideType.entry_index = 255;
@ -603,7 +603,7 @@ static void window_new_ride_update(rct_window *w)
widget_invalidate(w->classification, w->number, WIDX_TAB_1 + _window_new_ride_current_tab);
if (w->new_ride.selected_ride_countdown != -1 && w->new_ride.selected_ride_countdown-- == 0)
if (w->new_ride.selected_ride_id != -1 && w->new_ride.selected_ride_countdown-- == 0)
window_new_ride_select(w);
}
@ -657,7 +657,7 @@ static void window_new_ride_scrollmousedown()
return;
RCT2_ADDRESS(0x00F43825, ride_list_item)[_window_new_ride_current_tab] = item;
w->new_ride.selected_ride_countdown = *((sint16*)&item);
w->new_ride.selected_ride_id = *((sint16*)&item);
sound_play_panned(SOUND_CLICK_1, w->x + (w->width / 2));
w->new_ride.selected_ride_countdown = 8;
@ -676,7 +676,7 @@ static void window_new_ride_scrollmouseover()
window_scrollmouse_get_registers(w, x, y);
if (w->new_ride.selected_ride_countdown != -1)
if (w->new_ride.selected_ride_id != -1)
return;
item = window_new_ride_scroll_get_ride_list_item_at(w, x, y);
@ -832,7 +832,7 @@ static void window_new_ride_scrollpaint()
uint8 *rideEntry;
// Draw flat button rectangle
int flags = 0;
if (w->new_ride.selected_ride_countdown == *((sint16*)listItem))
if (w->new_ride.selected_ride_id == *((sint16*)listItem))
flags |= 0x20;
if (w->new_ride.highlighted_ride_id == *((sint16*)listItem) || flags != 0)
gfx_fill_rect_inset(dpi, x, y, x + 115, y + 115, w->colours[1], 0x80 | flags);
@ -973,7 +973,7 @@ static void window_new_ride_paint_ride_information(rct_window *w, rct_drawpixeli
*/
static void window_new_ride_select(rct_window *w)
{
ride_list_item item = *((ride_list_item*)&w->new_ride.selected_ride_countdown);
ride_list_item item = *((ride_list_item*)&w->new_ride.selected_ride_id);
if (item.type == 255)
return;