0x00401AF3, 0x006BC6D8, corrections

This commit is contained in:
zsilencer 2014-09-17 13:44:29 -06:00
parent d87ede04a4
commit d276e40b7f
6 changed files with 302 additions and 89 deletions

View File

@ -23,6 +23,7 @@
#include "addresses.h"
#include "config.h"
#include "map.h"
#include "osinterface.h"
#include "rct2.h"
#include "sprite.h"
#include "viewport.h"
@ -480,11 +481,26 @@ int sub_4015E7(int channel)
return result;
}
/**
*
* rct2: 0x00401AF3
*/
void sub_401AF3(int channel, const char* filename, int a3, int a4)
{
rct_sound_channel* sound_channel = &RCT2_ADDRESS(RCT2_ADDRESS_SOUND_CHANNEL_LIST, rct_sound_channel)[channel];
sound_channel->var_4 = 1;
memcpy(sound_channel->filename, filename, sizeof(sound_channel->filename));
sound_channel->var_10C = 0;
sound_channel->var_110 = a4;
sound_channel->var_114 = a3;
sound_channel->var_164 = 1;
}
/**
*
* rct2: 0x004016FF
*/
int sound_channel_load_file(int channel, char* filename, int offset)
int sound_channel_load_file(int channel, const char* filename, int offset)
{
rct_sound_channel* sound_channel = &RCT2_ADDRESS(0x014262E0, rct_sound_channel)[channel];
sound_channel->hmem;
@ -525,7 +541,7 @@ int sound_channel_load_file(int channel, char* filename, int offset)
*
* rct2: 0x00405222
*/
MMRESULT mmio_open(char* filename, HMMIO* hmmio, HGLOBAL* hmem, LPMMCKINFO mmckinfo)
MMRESULT mmio_open(const char* filename, HMMIO* hmmio, HGLOBAL* hmem, LPMMCKINFO mmckinfo)
{
HGLOBAL* hmemold;
HGLOBAL hmemold2;
@ -536,7 +552,7 @@ MMRESULT mmio_open(char* filename, HMMIO* hmmio, HGLOBAL* hmem, LPMMCKINFO mmcki
hmemold = hmem;
*hmem = 0;
hmmio1 = mmioOpenA(filename, 0, MMIO_ALLOCBUF);
hmmio1 = mmioOpenA((char*)filename, 0, MMIO_ALLOCBUF);
if (hmmio1) {
result = mmioDescend(hmmio1, mmckinfo, 0, 0);
if (result != MMSYSERR_NOERROR) {
@ -1245,7 +1261,7 @@ int sub_401B63(int channel)
*
* rct2: 0x0040194E
*/
int sound_channel_load_file2(int channel, char* filename, int offset)
int sound_channel_load_file2(int channel, const char* filename, int offset)
{
if (!RCT2_GLOBAL(0x009E1AA4, int)) {
return 0;
@ -1687,4 +1703,171 @@ void unpause_sounds()
{
RCT2_GLOBAL(0x009AF59C, uint8)--;
g_sounds_disabled = 0;
}
}
/**
* Play/update ride music based on structs updated somewhere else
* rct2: 0x006BC6D8
*/
void sub_6BC6D8()
{
int edi;
int ebx;
if (!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 2)) {
if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) {
if (!RCT2_GLOBAL(0x009AF59C, uint8) && RCT2_GLOBAL(0x009AF59D, uint8) & 1 && RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) && !(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 1)) {
while (1) {
int v8 = 0;
int v9 = 1;
rct_music_info* music_info = &RCT2_GLOBAL(0x009AF430, rct_music_info);
while (music_info < RCT2_GLOBAL(0x009AF42C, rct_music_info*)) {
if (music_info->id != (uint8)-1) {
rct_music_info3* music_info3 = &RCT2_GLOBAL(0x009AF1C8, rct_music_info3*)[music_info->var_1] + 8;
if (RCT2_ADDRESS(0x009AA0B1, uint8*)[music_info3->var_0]) {
v8++;
if (v9 >= music_info->volume) {
v9 = music_info->volume;
edi = (int)music_info;
}
}
}
music_info++;
}
if (v8 <= 1) {
break;
}
edi = -1;
}
while (1) {
int v8 = 0;
int v9 = 1;
rct_music_info* music_info = &RCT2_GLOBAL(0x009AF430, rct_music_info);
while (music_info < RCT2_GLOBAL(0x009AF42C, rct_music_info*)) {
if (music_info->id != (uint8)-1) {
v8++;
if (v9 >= music_info->volume) {
v9 = music_info->volume;
edi = (int)music_info;
}
}
music_info++;
}
if (v8 <= 2) {
break;
}
edi = -1;
}
rct_music_info2* music_info2 = &RCT2_GLOBAL(0x009AF46C, rct_music_info2);
int channel = 0;
do {
if (music_info2->id != (uint8)-1) {
rct_music_info* music_info = &RCT2_GLOBAL(0x009AF430, rct_music_info);
while (music_info < RCT2_GLOBAL(0x009AF42C, rct_music_info*)) {
if (music_info->id == music_info2->id && music_info->var_1 == music_info2->var_1) {
RCT2_GLOBAL(0x014241BC, uint32) = 1;
int v16 = sub_401B63(channel);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
if (v16) {
goto label32;
}
break;
}
music_info++;
}
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_channel_stop(channel);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
music_info2->id = -1;
}
label32:
music_info2++;
channel++;
} while(channel < 2);
for (rct_music_info* music_info = &RCT2_GLOBAL(0x009AF430, rct_music_info); music_info < RCT2_GLOBAL(0x009AF42C, rct_music_info*); music_info++) {
if (music_info->id != (uint8)-1) {
rct_music_info2* music_info2 = &RCT2_GLOBAL(0x009AF46C, rct_music_info2);
int channel = 0;
while (music_info->id != music_info2->id || music_info->var_1 != music_info2->var_1) {
if (music_info2->id == (uint8)-1) {
ebx = channel;
}
music_info2++;
channel++;
if (channel >= 2) {
rct_music_info3* music_info3 = &RCT2_GLOBAL(0x009AF1C8, rct_music_info3*)[music_info->var_1];
const char* filename = get_file_path(music_info3->pathid);
RCT2_GLOBAL(0x014241BC, uint32) = 3;
HANDLE hfile = osinterface_file_open(filename);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
if (hfile != INVALID_HANDLE_VALUE) {
RCT2_GLOBAL(0x014241BC, uint32) = 3;
osinterface_file_read(hfile, &RCT2_GLOBAL(0x009AF47E, uint32), 4);
RCT2_GLOBAL(0x014241BC, uint32) = 3;
osinterface_file_close(hfile);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
if (hfile == INVALID_HANDLE_VALUE || RCT2_GLOBAL(0x009AF47E, uint32) != 0x78787878) {
int offset = music_info->offset - 10000;
if (offset < 0) {
offset = 0;
}
RCT2_GLOBAL(0x014241BC, uint32) = 1;
int musicloaded = sound_channel_load_file2(ebx, filename, offset & 0xFFFFFFF0);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
if (musicloaded) {
RCT2_GLOBAL(0x014241BC, uint32) = 1;
int musicplayed = sound_channel_play(ebx, 0, music_info->volume, music_info->pan, music_info->freq);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
if (musicplayed) {
rct_music_info3* music_info3 = &RCT2_GLOBAL(0x009AF1C8, rct_music_info3*)[music_info->var_1];
if (music_info3->var_9) {
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sub_401AF3(ebx, get_file_path(music_info3->pathid), 1, 0);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
rct_music_info2* music_info2 = &RCT2_ADDRESS(0x009AF46C, rct_music_info2)[ebx];
music_info2->volume = music_info->volume;
music_info2->pan = music_info->pan;
music_info2->freq = music_info->freq;
music_info2->id = music_info->id;
music_info2->var_1 = music_info->var_1;
}
} else {
RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) = 0;
}
}
return;
}
}
if (music_info->volume != music_info2->volume) {
music_info2->volume = music_info->volume;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_channel_set_volume(channel, music_info->volume);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
if (music_info->pan != music_info2->pan) {
music_info2->pan = music_info->pan;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_channel_set_pan(channel, music_info->pan);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
if (music_info->freq != music_info2->freq) {
music_info2->freq = music_info->freq;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_channel_set_frequency(channel, music_info->freq);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
}
}
}
}
}
}

View File

@ -62,7 +62,8 @@ typedef struct rct_sound {
typedef struct {
uint32 var_0;
uint32 var_4;
char filename[0x108]; // 0x8
char filename[MAX_PATH]; // 0x8
uint32 var_10C;
uint32 var_110;
uint32 var_114;
uint32 var_118;
@ -115,15 +116,42 @@ typedef struct {
uint16 next; // 0xA
} rct_sound_unknown;
typedef struct {
uint8 id;
uint8 var_1;
sint32 offset; //0x2
sint16 volume; //0x6
sint16 pan; //0x8
uint16 freq; //0xA
} rct_music_info;
typedef struct {
uint8 id;
uint8 var_1;
uint16 volume; //0x2
uint16 pan; //0x4
uint16 freq; //0x6
} rct_music_info2;
typedef struct {
uint8 var_0;
uint8 pad_1[0x7];
uint8 pathid; //0x8
uint8 var_9;
} rct_music_info3;
int get_dsound_devices();
int dsound_create_primary_buffer(int a, int device, int channels, int samples, int bits);
void audio_timefunc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2, int channel);
int audio_release();
MMRESULT mmio_read(HMMIO hmmio, uint32 size, char* buffer, LPMMCKINFO mmckinfo, int* read);
MMRESULT mmio_seek(HMMIO* hmmio, LPMMCKINFO mmckinfo1, LPMMCKINFO mmckinfo2, int offset);
MMRESULT mmio_open(char* filename, HMMIO* hmmio, HGLOBAL* hmem, LPMMCKINFO mmckinfo);
MMRESULT mmio_open(const char* filename, HMMIO* hmmio, HGLOBAL* hmem, LPMMCKINFO mmckinfo);
int sub_40153B(int channel);
int sub_4015E7(int channel);
void sub_401AF3(int channel, const char* filename, int a3, int a4);
int sub_401B63(int channel);
void sub_6BC6D8();
int audio_remove_timer();
void audio_close();
LPVOID map_file(LPCSTR lpFileName, DWORD dwCreationDisposition, DWORD dwNumberOfBytesToMap);
@ -139,8 +167,8 @@ 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);
int sound_channel_load_file2(int channel, char* filename, int offset);
int sound_channel_load_file(int channel, char* filename, int offset);
int sound_channel_load_file2(int channel, const char* filename, int offset);
int sound_channel_load_file(int channel, const char* filename, int offset);
void sound_channel_free(HMMIO* hmmio, HGLOBAL* hmem);
int sound_stop(rct_sound *sound);
int sound_stop_all();

View File

@ -21,10 +21,6 @@
#ifndef _HOOK_H_
#define _HOOK_H_
extern void* g_hooktableaddress;
extern int g_hooktableoffset;
extern int g_maxhooks;
enum REGISTER_ARGS {
EAX = 1 << 0,
EBX = 1 << 1,

View File

@ -654,7 +654,7 @@ int osinterface_file_close(HANDLE handle)
*
* rct2: 0x00408060
*/
HANDLE osinterface_file_open(char* filename)
HANDLE osinterface_file_open(const char* filename)
{
return CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS | FILE_ATTRIBUTE_NORMAL, 0);
}
@ -663,7 +663,7 @@ HANDLE osinterface_file_open(char* filename)
*
* rct2: 0x0040807D
*/
HANDLE osinterface_file_create(char* filename)
HANDLE osinterface_file_create(const char* filename)
{
return CreateFileA(filename, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
}
@ -672,7 +672,7 @@ HANDLE osinterface_file_create(char* filename)
*
* rct2: 0x00408099
*/
int osinterface_file_move(char* srcfilename, char* dstfilename)
int osinterface_file_move(const char* srcfilename, const char* dstfilename)
{
return (MoveFileA(srcfilename, dstfilename) != 0) - 1;
}
@ -681,7 +681,7 @@ int osinterface_file_move(char* srcfilename, char* dstfilename)
*
* rct2: 0x004080AF
*/
int osinterface_file_delete(char* filename)
int osinterface_file_delete(const char* filename)
{
return (DeleteFileA(filename) != 0) - 1;
}

View File

@ -21,6 +21,7 @@
#ifndef _SDL_INTERFACE_H_
#define _SDL_INTERFACE_H_
#include <windows.h>
#include "rct2.h"
enum {
@ -96,6 +97,10 @@ void osinterface_progressbar_setpos(int pos);
void osinterface_set_cursor(char cursor);
HANDLE osinterface_file_open(const char* filename);
int osinterface_file_read(HANDLE handle, void* data, int size);
int osinterface_file_close(HANDLE handle);
int osinterface_open_common_file_dialog(int type, char *title, char *filename, char *filterPattern, char *filterName);
void osinterface_show_messagebox(char* message);
char* osinterface_open_directory_browser(char *title);

View File

@ -173,7 +173,6 @@ void vehicle_sounds_update()
RCT2_GLOBAL(0x00F438A4, rct_viewport*) = viewport;
if (viewport != (rct_viewport*)-1) {
if (window) {
RCT2_GLOBAL(0x00F438A4, rct_viewport*) = window->viewport;
RCT2_GLOBAL(0x00F438A8, rct_window*) = window;
RCT2_GLOBAL(0x00F438AC, uint8) = 0;
if (viewport->zoom) {
@ -356,9 +355,11 @@ void vehicle_sounds_update()
}
if (sound_unknown->pan != vehicle_sound->sound1_pan) {
vehicle_sound->sound1_pan = sound_unknown->pan;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_set_pan(&vehicle_sound->sound1, sound_unknown->pan);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
if (RCT2_GLOBAL(0x009AAC6D, uint8)) {
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_set_pan(&vehicle_sound->sound1, sound_unknown->pan);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
}
if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 3) && sound_unknown->frequency != vehicle_sound->sound1_freq) {
vehicle_sound->sound1_freq = sound_unknown->frequency;
@ -370,86 +371,86 @@ void vehicle_sounds_update()
sound_set_frequency(&vehicle_sound->sound1, frequency);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
label87: // do sound2 stuff, screams
sprite = &g_sprite_list[sound_unknown->id];
volume = sprite->vehicle.var_BE;
volume *= LOBYTE(result);
volume = (uint16)volume / 8;
volume -= 0x1FFF;
if (volume < -10000) {
volume = -10000;
}
label87: // do sound2 stuff, screams
sprite = &g_sprite_list[sound_unknown->id];
volume = sprite->vehicle.var_BE;
volume *= LOBYTE(result);
volume = (uint16)volume / 8;
volume -= 0x1FFF;
if (volume < -10000) {
volume = -10000;
}
if (sprite->vehicle.var_BD == (uint8)-1) {
if (vehicle_sound->sound2_id != (uint16)-1) {
vehicle_sound->sound2_id = -1;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_stop(&vehicle_sound->sound2);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
if (sprite->vehicle.var_BD == (uint8)-1) {
if (vehicle_sound->sound2_id != (uint16)-1) {
vehicle_sound->sound2_id = -1;
} else {
if (vehicle_sound->sound2_id == (uint16)-1) {
goto label93;
}
if (sprite->vehicle.var_BD != vehicle_sound->sound2_id) {
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_stop(&vehicle_sound->sound2);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
label93:
vehicle_sound->sound2_id = sprite->vehicle.var_BD;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_prepare(sprite->vehicle.var_BD, &vehicle_sound->sound2, 1, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32));
RCT2_GLOBAL(0x014241BC, uint32) = 0;
vehicle_sound->sound2_pan = sound_unknown->pan;
vehicle_sound->sound2_volume = volume;
vehicle_sound->sound2_freq = sound_unknown->frequency;
uint16 frequency = sound_unknown->frequency;
if (RCT2_ADDRESS(0x009AF51F, uint8)[2 * sprite->vehicle.var_BD] & 1) {
frequency = 12649;
}
frequency = (frequency * 2) - 3248;
if (frequency > 25700) {
frequency = 25700;
}
uint8 looping = RCT2_ADDRESS(0x009AF51E, uint8)[2 * sprite->vehicle.var_BD];
int pan = sound_unknown->pan;
if (!RCT2_GLOBAL(0x009AAC6D, uint8)) {
pan = 0;
}
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_play(&vehicle_sound->sound2, looping, volume, pan, frequency);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
goto label114;
}
if (volume != vehicle_sound->sound2_volume) {
vehicle_sound->sound2_volume = volume;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_set_volume(&vehicle_sound->sound2, volume);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
if (sound_unknown->pan != vehicle_sound->sound2_pan) {
vehicle_sound->sound2_pan = sound_unknown->pan;
if (RCT2_GLOBAL(0x009AAC6D, uint8)) {
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_stop(&vehicle_sound->sound2);
sound_set_pan(&vehicle_sound->sound2, sound_unknown->pan);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
} else {
if (vehicle_sound->sound2_id == (uint16)-1) {
goto label93;
}
if (sprite->vehicle.var_BD != vehicle_sound->sound2_id) {
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_stop(&vehicle_sound->sound2);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
label93:
vehicle_sound->sound2_id = sprite->vehicle.var_BD;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_prepare(sprite->vehicle.var_BD, &vehicle_sound->sound2, 1, RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER, uint32));
RCT2_GLOBAL(0x014241BC, uint32) = 0;
vehicle_sound->sound2_pan = sound_unknown->pan;
vehicle_sound->sound2_volume = volume;
vehicle_sound->sound2_freq = sound_unknown->frequency;
uint16 frequency = sound_unknown->frequency;
if (RCT2_ADDRESS(0x009AF51F, uint8)[2 * sprite->vehicle.var_BD] & 1) {
frequency = 12649;
}
frequency = (frequency * 2) - 3248;
}
if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 3) && sound_unknown->frequency != vehicle_sound->sound2_freq) {
vehicle_sound->sound2_freq = sound_unknown->frequency;
if (!(RCT2_ADDRESS(0x009AF51F, uint8)[2 * sprite->vehicle.var_BD] & 1)) {
uint16 frequency = (sound_unknown->frequency * 2) - 3248;
if (frequency > 25700) {
frequency = 25700;
}
uint8 looping = RCT2_ADDRESS(0x009AF51E, uint8)[2 * sprite->vehicle.var_BD];
int pan = sound_unknown->pan;
if (!RCT2_GLOBAL(0x009AAC6D, uint8)) {
pan = 0;
}
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_play(&vehicle_sound->sound2, looping, volume, pan, frequency);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
goto label114;
}
if (volume != vehicle_sound->sound2_volume) {
vehicle_sound->sound2_volume = volume;
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_set_volume(&vehicle_sound->sound2, volume);
sound_set_frequency(&vehicle_sound->sound2, frequency);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
if (sound_unknown->pan != vehicle_sound->sound2_pan) {
vehicle_sound->sound2_pan = sound_unknown->pan;
if (RCT2_GLOBAL(0x009AAC6D, uint8)) {
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_set_pan(&vehicle_sound->sound2, sound_unknown->pan);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
}
if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 3) && sound_unknown->frequency != vehicle_sound->sound2_freq) {
vehicle_sound->sound2_freq = sound_unknown->frequency;
if (!(RCT2_ADDRESS(0x009AF51F, uint8)[2 * sprite->vehicle.var_BD] & 1)) {
uint16 frequency = (sound_unknown->frequency * 2) - 3248;
if (frequency > 25700) {
frequency = 25700;
}
RCT2_GLOBAL(0x014241BC, uint32) = 1;
sound_set_frequency(&vehicle_sound->sound2, frequency);
RCT2_GLOBAL(0x014241BC, uint32) = 0;
}
}
label114:
1;
}
}
label114:
1;
}
}
}