From bfbcbbc996e8ef4cefa678f4f345418e55db4e34 Mon Sep 17 00:00:00 2001 From: zsilencer Date: Fri, 3 Oct 2014 16:28:39 -0600 Subject: [PATCH] small fixes palette effects small fixes palette effects small fixes Merge branch 'test' Conflicts: src/window_music_credits.c palette effects palette effects small fixes Merge branch 'test' Conflicts: src/window_music_credits.c palette effects small fixes Merge branch 'test' Conflicts: src/window_music_credits.c Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 added window_music_credits.c added window_music_credits.c Merge branch 'master' of https://github.com/zsilencer/OpenRCT2 --- src/addresses.h | 6 ++- src/audio.c | 101 ++++++++++++++++++++++++++++++++-------------- src/audio.h | 7 ++-- src/osinterface.c | 11 ++--- src/rct2.c | 2 +- src/vehicle.c | 43 ++++++++++---------- 6 files changed, 107 insertions(+), 63 deletions(-) diff --git a/src/addresses.h b/src/addresses.h index 9263eef9b9..00f77551f9 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -52,6 +52,8 @@ #define RCT2_ADDRESS_APP_PATH 0x009AA214 +#define RCT2_ADDRESS_DSOUND_GUID 0x009AAC5D + #define RCT2_ADDRESS_CONFIG_SOUND_SW_BUFFER 0x009AAC6E #define RCT2_ADDRESS_CONFIG_MUSIC 0x009AAC72 @@ -166,7 +168,7 @@ #define RCT2_ADDRESS_DSOUND_BUFFERS 0x009E1AB0 #define RCT2_ADDRESS_NUM_DSOUND_DEVICES 0x009E2B88 #define RCT2_ADDRESS_DSOUND_DEVICES 0x009E2B8C -#define RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING 0x009E2B94 +#define RCT2_ADDRESS_SOUND_EFFECTS_MAPPING 0x009E2B94 #define RCT2_ADDRESS_SOUNDLIST_BEGIN 0x009E2B98 #define RCT2_ADDRESS_SOUNDLIST_END 0x009E2B9C #define RCT2_ADDRESS_DIRECTSOUND 0x009E2BA0 @@ -217,6 +219,8 @@ #define RCT2_ADDRESS_CONSTRUCT_PATH_FROM_Z 0x00F3EF8E #define RCT2_ADDRESS_CONSTRUCT_PATH_DIRECTION 0x00F3EF90 +#define RCT2_ADDRESS_VOLUME_ADJUST_ZOOM 0x00F438AC + #define RCT2_ADDRESS_STAFF_HIGHLIGHTED_INDEX 0x00F43908 #define RCT2_ADDRESS_CURRENT_MONTH_YEAR 0x00F663A8 diff --git a/src/audio.c b/src/audio.c index f9be13d26e..98c7f1a21c 100644 --- a/src/audio.c +++ b/src/audio.c @@ -98,12 +98,12 @@ int audio_release() * * rct2: 0x00404C45 */ -int unmap_sound_info() +int unmap_sound_effects() { - if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID)) { + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, LPVOID)) { sound_stop_all(); - unmap_file(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID)); - RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID) = 0; + unmap_file(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, LPVOID)); + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, LPVOID) = 0; return 1; } return 0; @@ -173,7 +173,7 @@ void audio_close() RCT2_GLOBAL(0x014241BC, uint32) = 0; } RCT2_GLOBAL(0x014241BC, uint32) = 1; - unmap_sound_info(); + unmap_sound_effects(); audio_release(); RCT2_GLOBAL(0x014241BC, uint32) = 0; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = -1; @@ -345,13 +345,13 @@ LPVOID map_file(LPCSTR lpFileName, DWORD dwCreationDisposition, DWORD dwNumberOf * * rct2: 0x00404C1A */ -int map_sound_info(const char* filename) +int map_sound_effects(const char* filename) { - if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID)) { + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, LPVOID)) { return 0; } else { - RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID) = map_file(filename, 0, 0); - return RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID) != 0; + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, LPVOID) = map_file(filename, 0, 0); + return RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, LPVOID) != 0; } } @@ -892,6 +892,48 @@ int audio_create_timer() return 1; } +/** +* +* rct2: 0x006BA8E0 +*/ +void audio_init1() +{ + int devicenum = 0; + if (RCT2_GLOBAL(0x009AAC5C, uint8)) { + rct_dsdevice* dsdevice = &RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)[0]; + while (dsdevice->guid.Data1 != RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_GUID, GUID).Data1 || + dsdevice->guid.Data2 != RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_GUID, GUID).Data2 || + dsdevice->guid.Data3 != RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_GUID, GUID).Data3 || + memcmp(dsdevice->guid.Data4, RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_GUID, GUID).Data4, sizeof(dsdevice->guid.Data4)) != 0) { + dsdevice++; + devicenum++; + if (devicenum >= RCT2_GLOBAL(RCT2_ADDRESS_NUM_DSOUND_DEVICES, int)) { + devicenum = 0; + break; + } + } + } + audio_init2(devicenum); + int m = 0; + do { + rct_music_info3* music_info3 = &RCT2_GLOBAL(0x009AF1C8, rct_music_info3*)[m]; + const char* path = get_file_path(music_info3->pathid); + RCT2_GLOBAL(0x014241BC, uint32) = 3; + HANDLE hfile = osinterface_file_open(path); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (hfile != INVALID_HANDLE_VALUE) { + RCT2_GLOBAL(0x014241BC, uint32) = 3; + osinterface_file_read(hfile, &RCT2_GLOBAL(0x009AF47E, uint32), 4); + osinterface_file_close(hfile); + RCT2_GLOBAL(0x014241BC, uint32) = 0; + if (RCT2_GLOBAL(0x009AF47E, uint32) == 0x78787878) { + music_info3->var_0 = 0; + } + } + m++; + } while(m + 1 < 0x2E); +} + /** * * rct2: 0x006BA9B5 @@ -915,7 +957,7 @@ void audio_init2(int device) } const char * filepath = get_file_path(2); RCT2_GLOBAL(0x014241BC, uint32) = 1; - int successmap = map_sound_info(filepath); + int successmap = map_sound_effects(filepath); RCT2_GLOBAL(0x014241BC, uint32) = 0; if (!successmap) { RCT2_GLOBAL(0x014241BC, uint32) = 1; @@ -925,20 +967,17 @@ void audio_init2(int device) } RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = device; rct_dsdevice dsdevice = RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, rct_dsdevice*)[device]; - RCT2_GLOBAL(0x009AAC5D, uint32) = dsdevice.guid.Data1; - RCT2_GLOBAL(0x009AAC61, uint32) = dsdevice.guid.Data2; - RCT2_GLOBAL(0x009AAC65, uint32) = dsdevice.guid.Data3; - RCT2_GLOBAL(0x009AAC69, uint32) = (uint32)dsdevice.guid.Data4; + RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_GUID, GUID) = dsdevice.guid; RCT2_GLOBAL(0x009AAC5C, uint8) = 1; config_save(); RCT2_GLOBAL(0x014241BC, uint32) = 1; int successtimer = audio_create_timer(); RCT2_GLOBAL(0x014241BC, uint32) = 0; if (successtimer) { - if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) { - for (int i = 0; i < 2; i++) { - RCT2_GLOBAL(0x009AF46C + (i * 8), uint8) = -1; - } + RCT2_GLOBAL(0x009AF284, uint32) |= (1 << 0); + for (int i = 0; i < 2; i++) { + rct_music_info2* music_info2 = &RCT2_ADDRESS(0x009AF46C, rct_music_info2)[i]; + music_info2->id = -1; } } if (!(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & 1 << 4)) { @@ -1047,10 +1086,10 @@ rct_sound* sound_next(rct_sound* sound) * * rct2: 0x00405206 */ -rct_sound_info* sound_get_info(uint16 sound_id) +rct_sound_effect* sound_get_effect(uint16 sound_id) { - if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, LPVOID) && sound_id < RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, uint32*)[0]) { - return (rct_sound_info*)(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, int) + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_INFO_LIST_MAPPING, uint32*)[sound_id + 1]); + if (RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, LPVOID) && sound_id < RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, uint32*)[0]) { + return (rct_sound_effect*)(RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, int) + RCT2_GLOBAL(RCT2_ADDRESS_SOUND_EFFECTS_MAPPING, uint32*)[sound_id + 1]); } return 0; } @@ -1059,11 +1098,11 @@ rct_sound_info* sound_get_info(uint16 sound_id) * * rct2: 0x00405054 */ -int sound_info_loadvars(rct_sound_info* sound_info, LPWAVEFORMATEX* waveformat, char** data, DWORD* buffersize) +int sound_effect_loadvars(rct_sound_effect* sound_effect, LPWAVEFORMATEX* waveformat, char** data, DWORD* buffersize) { - *buffersize = sound_info->size; - *waveformat = &sound_info->format; - *data = (char*)&sound_info->data; + *buffersize = sound_effect->size; + *waveformat = &sound_effect->format; + *data = (char*)&sound_effect->data; return 1; } @@ -1112,9 +1151,9 @@ int sound_prepare(int sound_id, rct_sound *sound, int channels, int software) return 1; } } - rct_sound_info* sound_info = sound_get_info(sound_id); - if (sound_info) { - if (sound_info_loadvars(sound_info, &bufferdesc.lpwfxFormat, &buffer, &bufferdesc.dwBufferBytes)) { + rct_sound_effect* sound_effect = sound_get_effect(sound_id); + if (sound_effect) { + if (sound_effect_loadvars(sound_effect, &bufferdesc.lpwfxFormat, &buffer, &bufferdesc.dwBufferBytes)) { bufferdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STATIC; if (channels) { if (channels == 2) { @@ -1631,12 +1670,12 @@ void stop_ride_music() { if ((RCT2_GLOBAL(0x009AF284, uint32) & (1 << 0))) { for (int i = 0; i < 2; i++) { - uint8 * data = RCT2_ADDRESS(0x009AF46C + (i * 8), uint8); - if (data[0] != 0xFF) { + rct_music_info2* music_info2 = &RCT2_ADDRESS(0x009AF46C, rct_music_info2)[i]; + if (music_info2->id != (uint8)-1) { RCT2_GLOBAL(0x014241BC, uint32) = 1; sound_channel_stop(i); RCT2_GLOBAL(0x014241BC, uint32) = 0; - data[0] = 0xFF; + music_info2->id = -1; } } } diff --git a/src/audio.h b/src/audio.h index 10ac0864d1..6dbdfbadd2 100644 --- a/src/audio.h +++ b/src/audio.h @@ -34,6 +34,7 @@ extern audio_device *gAudioDevices; void audio_init(); void audio_quit(); void audio_get_devices(); +void audio_init1(); void audio_init2(int device); #include @@ -84,8 +85,8 @@ typedef struct { typedef struct { uint32 size; WAVEFORMATEX format; - char* data; -} rct_sound_info; + uint8* data; +} rct_sound_effect; typedef struct { uint16 id; @@ -155,7 +156,7 @@ void sub_6BC6D8(); int audio_remove_timer(); void audio_close(); LPVOID map_file(LPCSTR lpFileName, DWORD dwCreationDisposition, DWORD dwNumberOfBytesToMap); -int unmap_sound_info(); +int unmap_sound_effects(); int sound_prepare(int sound_id, rct_sound *sound, int channels, int software); int sound_play_panned(int sound_id, int ebx, sint16 x, sint16 y, sint16 z); int sound_play(rct_sound* sound, int looping, int volume, int pan, int frequency); diff --git a/src/osinterface.c b/src/osinterface.c index 49a93aafbb..59b5a887c0 100644 --- a/src/osinterface.c +++ b/src/osinterface.c @@ -276,14 +276,15 @@ void osinterface_update_palette(char* colours, int start_index, int num_colours) exit(1); } - for (i = start_index; i < start_index + num_colours; i++) { - base[i].r = colours[(i * 4) + 2]; - base[i].g = colours[(i * 4) + 1]; - base[i].b = colours[(i * 4) + 0]; + for (i = 0; i < 256; i++) { + base[i].r = colours[2]; + base[i].g = colours[1]; + base[i].b = colours[0]; base[i].a = 0; + colours += 4; } - if (SDL_SetPaletteColors(_palette, &base[start_index], start_index, num_colours)) { + if (SDL_SetPaletteColors(_palette, base, 0, 256)) { RCT2_ERROR("SDL_SetPaletteColors failed %s", SDL_GetError()); exit(1); } diff --git a/src/rct2.c b/src/rct2.c index 0ffe6585ca..5d9c7ff135 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -170,7 +170,7 @@ void rct2_init() gfx_load_character_widths(); osinterface_init(); - RCT2_CALLPROC_EBPSAFE(0x006BA8E0); // init_audio(); + audio_init1();//RCT2_CALLPROC_EBPSAFE(0x006BA8E0); // init_audio(); viewport_init_all(); news_item_init_queue(); get_local_time(); diff --git a/src/vehicle.c b/src/vehicle.c index bf2e89f5f4..1f0b81ddfe 100644 --- a/src/vehicle.c +++ b/src/vehicle.c @@ -159,7 +159,6 @@ int sub_6BC2F3(rct_vehicle* vehicle) */ void vehicle_sounds_update() { - uint16 result; if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) != -1 && !RCT2_GLOBAL(0x009AF59C, uint8) && RCT2_GLOBAL(0x009AF59D, uint8) & 1) { RCT2_GLOBAL(0x00F438A4, rct_viewport*) = (rct_viewport*)-1; rct_window* window = RCT2_GLOBAL(RCT2_ADDRESS_NEW_WINDOW_PTR, rct_window*); @@ -174,11 +173,11 @@ void vehicle_sounds_update() if (viewport != (rct_viewport*)-1) { if (window) { RCT2_GLOBAL(0x00F438A8, rct_window*) = window; - RCT2_GLOBAL(0x00F438AC, uint8) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8) = 0; if (viewport->zoom) { - RCT2_GLOBAL(0x00F438AC, uint8) = 35; + RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8) = 35; if (viewport->zoom != 1) { - RCT2_GLOBAL(0x00F438AC, uint8) = 70; + RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8) = 70; } } } @@ -216,7 +215,8 @@ void vehicle_sounds_update() if (sound_unknown >= RCT2_GLOBAL(0x00F438B0, rct_sound_unknown*)) { return; } - result = (uint16)-1; + uint8 vol1 = 0xFF; + uint8 vol2 = 0xFF; sint16 v = sound_unknown->var_4; if (v < 0) { v = -v; @@ -229,11 +229,11 @@ void vehicle_sounds_update() v -= 0x400; v = -v; v = (uint16)v / 4; - result = MAKEWORD(LOBYTE(v), HIBYTE(result)); + vol1 = LOBYTE(v); if (HIBYTE(v) != 0) { - result = MAKEWORD(0xFF, HIBYTE(result)); + vol1 = 0xFF; if (HIBYTE(v) < 0) { - result = MAKEWORD(0, HIBYTE(result)); + vol1 = 0; } } } @@ -250,22 +250,22 @@ void vehicle_sounds_update() w -= 0x400; w = -w; w = (uint16)w / 4; - result = MAKEWORD(LOBYTE(result), LOBYTE(w)); + vol2 = LOBYTE(w); if (HIBYTE(w) != 0) { - result = MAKEWORD(LOBYTE(result), 0xFF); + vol2 = 0xFF; if (HIBYTE(w) < 0) { - result = MAKEWORD(LOBYTE(result), 0); + vol2 = 0; } } } - if (LOBYTE(result) >= HIBYTE(result)) { - result = MAKEWORD(HIBYTE(result), HIBYTE(result)); + if (vol1 >= vol2) { + vol1 = vol2; } - if (LOBYTE(result) < RCT2_GLOBAL(0x00F438AC, uint8)) { - result = MAKEWORD(0, HIBYTE(result)); + if (vol1 < RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8)) { + vol1 = 0; } else { - result = MAKEWORD(LOBYTE(result) - RCT2_GLOBAL(0x00F438AC, uint8), HIBYTE(result)); + vol1 = vol1 - RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8); } rct_vehicle_sound* vehicle_sound = &RCT2_GLOBAL(RCT2_ADDRESS_VEHICLE_SOUND_LIST, rct_vehicle_sound); @@ -300,16 +300,15 @@ void vehicle_sounds_update() } } vehicle_sound->var_2 = v22; - if (LOBYTE(result) < v22) { - result = MAKEWORD(0, HIBYTE(result)); + if (vol1 < v22) { + vol1 = 0; } else { - result = MAKEWORD(LOBYTE(result) - v22, HIBYTE(result)); + vol1 = vol1 - v22; } // do sound1 stuff, track noise - RCT2_ADDRESS_SPRITE_LIST; rct_sprite* sprite = &g_sprite_list[sound_unknown->id]; sint16 volume = sprite->vehicle.var_BC; - volume *= LOBYTE(result); + volume *= vol1; volume = (uint16)volume / 8; volume -= 0x1FFF; if (volume < -10000) { @@ -380,7 +379,7 @@ void vehicle_sounds_update() label87: // do sound2 stuff, screams sprite = &g_sprite_list[sound_unknown->id]; volume = sprite->vehicle.var_BE; - volume *= LOBYTE(result); + volume *= vol1; volume = (uint16)volume / 8; volume -= 0x1FFF; if (volume < -10000) {