mirror of https://github.com/OpenRCT2/OpenRCT2.git
finish ride music decompile
This commit is contained in:
parent
0e414ebae7
commit
c3086a5b9f
|
@ -1599,12 +1599,12 @@ void stop_ride_music()
|
|||
{
|
||||
if ((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];
|
||||
if (music_info2->id != (uint8)-1) {
|
||||
rct_ride_music* ride_music = &RCT2_ADDRESS(0x009AF46C, rct_ride_music)[i];
|
||||
if (ride_music->rideid != (uint8)-1) {
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_stop(i);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
music_info2->id = -1;
|
||||
ride_music->rideid = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1680,8 +1680,8 @@ void audio_init1()
|
|||
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);
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[m];
|
||||
const char* path = get_file_path(ride_music_info->pathid);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 3;
|
||||
HANDLE hfile = osinterface_file_open(path);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
|
@ -1691,7 +1691,7 @@ void audio_init1()
|
|||
osinterface_file_close(hfile);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
if (RCT2_GLOBAL(0x009AF47E, uint32) == 0x78787878) {
|
||||
music_info3->var_0 = 0;
|
||||
ride_music_info->var_0 = 0;
|
||||
}
|
||||
}
|
||||
m++;
|
||||
|
@ -1741,8 +1741,8 @@ void audio_init2(int device)
|
|||
if (successtimer) {
|
||||
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;
|
||||
rct_ride_music* ride_music = &RCT2_ADDRESS(0x009AF46C, rct_ride_music)[i];
|
||||
ride_music->rideid = -1;
|
||||
}
|
||||
}
|
||||
if (!(RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & 1 << 4)) {
|
||||
|
@ -1835,352 +1835,3 @@ void stop_vehicle_sounds()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006BC3AC
|
||||
* Update ride music
|
||||
* cant properly hook this function, because the EBP register is used as a return value,
|
||||
* so it isn't fully tested. need to decompile 6ABE4C (ride_update_all) first
|
||||
* @param x (ax)
|
||||
* @param y (cx)
|
||||
* @param z (dx)
|
||||
* @param sampleRate (di)
|
||||
* @param rideIndex (bl)
|
||||
* @param position (ebp)
|
||||
* @param tuneId (bh)
|
||||
* @returns new position (ebp)
|
||||
*/
|
||||
int sub_6BC3AC(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint16 sampleRate, uint32 position, uint8 *tuneId)
|
||||
{
|
||||
{
|
||||
int a_eax, a_ebx, a_ecx, a_edx, a_esi, a_edi, a_ebp;
|
||||
|
||||
a_eax = x;
|
||||
a_ebx = (*tuneId << 8) | rideIndex;
|
||||
a_ecx = y;
|
||||
a_edx = z;
|
||||
a_edi = sampleRate;
|
||||
a_ebp = position;
|
||||
RCT2_CALLFUNC_X(0x006BC3AC, &a_eax, &a_ebx, &a_ecx, &a_edx, &a_esi, &a_edi, &a_ebp);
|
||||
|
||||
*tuneId = (a_ebx >> 8) & 0xFF;
|
||||
return a_ebp;
|
||||
}
|
||||
|
||||
// TODO fix / bh needs returning too!
|
||||
if(!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) && !RCT2_GLOBAL(0x009AF59C, uint8) && RCT2_GLOBAL(0x00F438A4, rct_viewport*) != (rct_viewport*)-1) {
|
||||
RCT2_GLOBAL(0x009AF47C, uint16) = sampleRate;
|
||||
sint16 v11;
|
||||
sint16 v12;
|
||||
switch (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32)) {
|
||||
case 0:
|
||||
v11 = y - x;
|
||||
v12 = ((y + x) / 2) - z;
|
||||
break;
|
||||
case 1:
|
||||
v11 = -x - y;
|
||||
v12 = ((y - x) / 2) - z;
|
||||
break;
|
||||
case 2:
|
||||
v11 = x - y;
|
||||
v12 = ((-y - x) / 2) - z;
|
||||
break;
|
||||
case 3:
|
||||
v11 = y + x;
|
||||
v12 = ((x - y) / 2) - z;
|
||||
break;
|
||||
}
|
||||
RCT2_GLOBAL(0x009AF5A0, sint16) = v11;
|
||||
RCT2_GLOBAL(0x009AF5A2, sint16) = v12;
|
||||
rct_viewport* viewport = RCT2_GLOBAL(0x00F438A4, rct_viewport*);
|
||||
sint16 view_width = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_width;
|
||||
sint16 view_width2 = view_width * 2;
|
||||
sint16 view_x = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_x - view_width2;
|
||||
sint16 view_y = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_y - view_width;
|
||||
sint16 v16 = view_width2 + view_width2 + RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_width + view_x;
|
||||
sint16 v17 = view_width + view_width + RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_height + view_y;
|
||||
if (view_x >= RCT2_GLOBAL(0x009AF5A0, sint16) ||
|
||||
view_y >= RCT2_GLOBAL(0x009AF5A2, sint16) ||
|
||||
v16 < RCT2_GLOBAL(0x009AF5A0, sint16) ||
|
||||
v17 < RCT2_GLOBAL(0x009AF5A2, sint16)) {
|
||||
goto label58;
|
||||
}
|
||||
int x2 = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->x + ((RCT2_GLOBAL(0x009AF5A0, sint16) - RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_x) >> RCT2_GLOBAL(0x00F438A4, rct_viewport*)->zoom);
|
||||
x2 <<= 16;
|
||||
uint16 screenwidth = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16);
|
||||
if (screenwidth < 64) {
|
||||
screenwidth = 64;
|
||||
}
|
||||
int panx = ((x2 / screenwidth) - 0x8000) >> 4;
|
||||
|
||||
int y2 = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->y + ((RCT2_GLOBAL(0x009AF5A2, sint16) - RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_y) >> RCT2_GLOBAL(0x00F438A4, rct_viewport*)->zoom);
|
||||
y2 <<= 16;
|
||||
uint16 screenheight = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16);
|
||||
if (screenheight < 64) {
|
||||
screenheight = 64;
|
||||
}
|
||||
int pany = ((y2 / screenheight) - 0x8000) >> 4;
|
||||
|
||||
uint8 v24l = -1;
|
||||
uint8 v24h = -1;
|
||||
if (pany < 0) {
|
||||
pany = -pany;
|
||||
}
|
||||
if (pany > 6143) {
|
||||
pany = 6143;
|
||||
}
|
||||
if (pany > 2048) {
|
||||
uint16 v27 = -(((pany - 2048) >> 2) - 1024) >> 2;
|
||||
v24l = (uint8)v27;
|
||||
if (v27 & 0xFF00) {
|
||||
v24l = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (panx < 0) {
|
||||
panx = -panx;
|
||||
}
|
||||
if (panx > 6143) {
|
||||
panx = 6143;
|
||||
}
|
||||
if (panx > 2048) {
|
||||
uint16 v27 = -(((panx - 2048) >> 2) - 1024) >> 2;
|
||||
v24h = (uint8)v27;
|
||||
if (v27 & 0xFF00) {
|
||||
v24h = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (v24l >= v24h) {
|
||||
v24l = v24h;
|
||||
}
|
||||
|
||||
sint8 v31 = v24l - (3 * RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8));
|
||||
if (v24l < (3 * RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8))) {
|
||||
v31 = 0;
|
||||
}
|
||||
int v32 = -(((-v31 - 1) * (-v31 - 1)) >> 4) - 700;
|
||||
if (v31 && v32 >= -4000) {
|
||||
if (panx > 10000) {
|
||||
panx = 10000;
|
||||
}
|
||||
if (panx < -10000) {
|
||||
panx = -10000;
|
||||
}
|
||||
if (!RCT2_GLOBAL(0x009AAC6D, uint8)) {
|
||||
panx = 0;
|
||||
}
|
||||
rct_music_info2* music_info2 = &RCT2_GLOBAL(0x009AF46C, rct_music_info2);
|
||||
int channel = 0;
|
||||
uint32 a1;
|
||||
while (music_info2->id != rideIndex && music_info2->var_1 != *tuneId) {
|
||||
music_info2++;
|
||||
channel++;
|
||||
if (channel >= 2) {
|
||||
rct_music_info3* music_info3 = &RCT2_GLOBAL(0x009AF1C8, rct_music_info3*)[*tuneId];
|
||||
a1 = position + music_info3->var_4;
|
||||
goto label51;
|
||||
}
|
||||
}
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
int playing = sound_channel_is_playing(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
if (!playing) {
|
||||
return 0;
|
||||
}
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
a1 = sub_401B46(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
label51:
|
||||
if (a1 < RCT2_GLOBAL(0x009AF1C8, rct_music_info3*)[*tuneId].var_0) {
|
||||
rct_music_info* music_info = RCT2_GLOBAL(0x009AF42C, rct_music_info*);
|
||||
if (music_info < (rct_music_info*)0x009AF46C/*music_info list end*/) {
|
||||
music_info->id = rideIndex;
|
||||
music_info->var_1 = *tuneId;
|
||||
music_info->offset = a1;
|
||||
music_info->volume = v32;
|
||||
music_info->pan = panx;
|
||||
music_info->freq = RCT2_GLOBAL(0x009AF47C, uint16);
|
||||
RCT2_GLOBAL(0x009AF42C, rct_music_info*)++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uint32 eax;
|
||||
label58:
|
||||
eax = position;
|
||||
position = *tuneId;
|
||||
rct_music_info3* music_info3 = &RCT2_GLOBAL(0x009AF1C8, rct_music_info3*)[*tuneId];
|
||||
eax += music_info3->var_4;
|
||||
if (eax < music_info3->var_0) {
|
||||
position = eax;
|
||||
}
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play/update ride music based on structs updated in 0x006BC3AC
|
||||
* rct2: 0x006BC6D8
|
||||
*/
|
||||
void sub_6BC6D8()
|
||||
{
|
||||
rct_music_info* 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)) {
|
||||
// set to stop music if volume <= 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];
|
||||
if (RCT2_ADDRESS(0x009AA0B1, uint8*)[music_info3->pathid]) { // file_on_cdrom[]
|
||||
v8++;
|
||||
if (v9 >= music_info->volume) {
|
||||
v9 = music_info->volume;
|
||||
edi = music_info;
|
||||
}
|
||||
}
|
||||
}
|
||||
music_info++;
|
||||
}
|
||||
if (v8 <= 1) {
|
||||
break;
|
||||
}
|
||||
edi->id = -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 = music_info;
|
||||
}
|
||||
}
|
||||
music_info++;
|
||||
}
|
||||
if (v8 <= 2) {
|
||||
break;
|
||||
}
|
||||
edi->id = -1;
|
||||
}
|
||||
|
||||
// stop currently playing music that is not in music_info list or not playing?
|
||||
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 = sound_channel_is_playing(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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,28 +121,28 @@ typedef struct {
|
|||
} rct_other_sound;
|
||||
|
||||
typedef struct {
|
||||
uint8 id;
|
||||
uint8 var_1;
|
||||
uint8 rideid;
|
||||
uint8 tuneid;
|
||||
sint32 offset; //0x2
|
||||
sint16 volume; //0x6
|
||||
sint16 pan; //0x8
|
||||
uint16 freq; //0xA
|
||||
} rct_music_info;
|
||||
} rct_ride_music_params;
|
||||
|
||||
typedef struct {
|
||||
uint8 id;
|
||||
uint8 var_1;
|
||||
uint8 rideid;
|
||||
uint8 tuneid;
|
||||
uint16 volume; //0x2
|
||||
uint16 pan; //0x4
|
||||
uint16 freq; //0x6
|
||||
} rct_music_info2;
|
||||
} rct_ride_music;
|
||||
|
||||
typedef struct {
|
||||
uint32 var_0;
|
||||
uint32 var_4;
|
||||
uint8 pathid; //0x8
|
||||
uint8 var_9;
|
||||
} rct_music_info3;
|
||||
} rct_ride_music_info;
|
||||
|
||||
extern rct_vehicle_sound gVehicleSoundList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
extern rct_vehicle_sound_params gVehicleSoundParamsList[AUDIO_MAX_VEHICLE_SOUNDS];
|
||||
|
@ -213,8 +213,6 @@ void audio_close();
|
|||
void pause_sounds();
|
||||
void unpause_sounds();
|
||||
void stop_vehicle_sounds();
|
||||
void sub_6BC6D8();
|
||||
int sub_6BC3AC(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint16 sampleRate, uint32 position, uint8 *tuneId);
|
||||
|
||||
// 0x009AF59C probably does the same job
|
||||
// once it's confirmed and calls in pause_sounds() are reversed, it can be used instead of this
|
||||
|
|
|
@ -1822,7 +1822,7 @@ void window_update_viewport_ride_music()
|
|||
rct_viewport *viewport;
|
||||
rct_window *w;
|
||||
|
||||
RCT2_GLOBAL(0x009AF42C, rct_music_info*) = (rct_music_info*)0x009AF430;
|
||||
RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*) = (rct_ride_music_params*)0x009AF430;
|
||||
RCT2_GLOBAL(0x00F438A4, rct_viewport*) = (rct_viewport*)-1;
|
||||
|
||||
for (w = RCT2_LAST_WINDOW; w >= g_window_list; w--) {
|
||||
|
|
357
src/ride/ride.c
357
src/ride/ride.c
|
@ -29,6 +29,7 @@
|
|||
#include "../management/news_item.h"
|
||||
#include "../peep/peep.h"
|
||||
#include "../peep/staff.h"
|
||||
#include "../platform/osinterface.h"
|
||||
#include "../scenario.h"
|
||||
#include "../util/util.h"
|
||||
#include "../windows/error.h"
|
||||
|
@ -1022,7 +1023,7 @@ void ride_update_all()
|
|||
FOR_ALL_RIDES(i, ride)
|
||||
ride_update(i);
|
||||
|
||||
sub_6BC6D8();
|
||||
ride_music_update_final();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1742,7 +1743,7 @@ static void ride_music_update(int rideIndex)
|
|||
sampleRate += 22050;
|
||||
}
|
||||
|
||||
ride->music_position = sub_6BC3AC(x, y, z, rideIndex, sampleRate, ride->music_position, &ride->music_tune_id);
|
||||
ride->music_position = ride_music_params_update(x, y, z, rideIndex, sampleRate, ride->music_position, &ride->music_tune_id);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
@ -2251,4 +2252,356 @@ void ride_set_map_tooltip(rct_map_element *mapElement)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x006BC3AC
|
||||
* Update ride music parameters
|
||||
* @param x (ax)
|
||||
* @param y (cx)
|
||||
* @param z (dx)
|
||||
* @param sampleRate (di)
|
||||
* @param rideIndex (bl)
|
||||
* @param position (ebp)
|
||||
* @param tuneId (bh)
|
||||
* @returns new position (ebp)
|
||||
*/
|
||||
int ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint16 sampleRate, uint32 position, uint8 *tuneId)
|
||||
{
|
||||
/*{
|
||||
int a_eax, a_ebx, a_ecx, a_edx, a_esi, a_edi, a_ebp;
|
||||
|
||||
a_eax = x;
|
||||
a_ebx = (*tuneId << 8) | rideIndex;
|
||||
a_ecx = y;
|
||||
a_edx = z;
|
||||
a_edi = sampleRate;
|
||||
a_ebp = position;
|
||||
RCT2_CALLFUNC_X(0x006BC3AC, &a_eax, &a_ebx, &a_ecx, &a_edx, &a_esi, &a_edi, &a_ebp);
|
||||
|
||||
*tuneId = (a_ebx >> 8) & 0xFF;
|
||||
return a_ebp;
|
||||
}*/
|
||||
if(!(RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_SCENARIO_EDITOR) && !RCT2_GLOBAL(0x009AF59C, uint8) && RCT2_GLOBAL(0x00F438A4, rct_viewport*) != (rct_viewport*)-1) {
|
||||
RCT2_GLOBAL(0x009AF47C, uint16) = sampleRate;
|
||||
sint16 v11;
|
||||
sint16 v12;
|
||||
switch (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32)) {
|
||||
case 0:
|
||||
v11 = y - x;
|
||||
v12 = ((y + x) / 2) - z;
|
||||
break;
|
||||
case 1:
|
||||
v11 = -x - y;
|
||||
v12 = ((y - x) / 2) - z;
|
||||
break;
|
||||
case 2:
|
||||
v11 = x - y;
|
||||
v12 = ((-y - x) / 2) - z;
|
||||
break;
|
||||
case 3:
|
||||
v11 = y + x;
|
||||
v12 = ((x - y) / 2) - z;
|
||||
break;
|
||||
}
|
||||
RCT2_GLOBAL(0x009AF5A0, sint16) = v11;
|
||||
RCT2_GLOBAL(0x009AF5A2, sint16) = v12;
|
||||
rct_viewport* viewport = RCT2_GLOBAL(0x00F438A4, rct_viewport*);
|
||||
sint16 view_width = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_width;
|
||||
sint16 view_width2 = view_width * 2;
|
||||
sint16 view_x = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_x - view_width2;
|
||||
sint16 view_y = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_y - view_width;
|
||||
sint16 v16 = view_width2 + view_width2 + RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_width + view_x;
|
||||
sint16 v17 = view_width + view_width + RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_height + view_y;
|
||||
if (view_x >= RCT2_GLOBAL(0x009AF5A0, sint16) ||
|
||||
view_y >= RCT2_GLOBAL(0x009AF5A2, sint16) ||
|
||||
v16 < RCT2_GLOBAL(0x009AF5A0, sint16) ||
|
||||
v17 < RCT2_GLOBAL(0x009AF5A2, sint16)) {
|
||||
goto label58;
|
||||
}
|
||||
int x2 = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->x + ((RCT2_GLOBAL(0x009AF5A0, sint16) - RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_x) >> RCT2_GLOBAL(0x00F438A4, rct_viewport*)->zoom);
|
||||
x2 <<= 16;
|
||||
uint16 screenwidth = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16);
|
||||
if (screenwidth < 64) {
|
||||
screenwidth = 64;
|
||||
}
|
||||
int panx = ((x2 / screenwidth) - 0x8000) >> 4;
|
||||
|
||||
int y2 = RCT2_GLOBAL(0x00F438A4, rct_viewport*)->y + ((RCT2_GLOBAL(0x009AF5A2, sint16) - RCT2_GLOBAL(0x00F438A4, rct_viewport*)->view_y) >> RCT2_GLOBAL(0x00F438A4, rct_viewport*)->zoom);
|
||||
y2 <<= 16;
|
||||
uint16 screenheight = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16);
|
||||
if (screenheight < 64) {
|
||||
screenheight = 64;
|
||||
}
|
||||
int pany = ((y2 / screenheight) - 0x8000) >> 4;
|
||||
|
||||
uint8 vol1 = -1;
|
||||
uint8 vol2 = -1;
|
||||
if (pany < 0) {
|
||||
pany = -pany;
|
||||
}
|
||||
if (pany > 6143) {
|
||||
pany = 6143;
|
||||
}
|
||||
pany -= 2048;
|
||||
if (pany > 0) {
|
||||
pany = -((pany / 4) - 1024) / 4;
|
||||
vol1 = (uint8)pany;
|
||||
if (pany >= 256) {
|
||||
vol1 = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (panx < 0) {
|
||||
panx = -panx;
|
||||
}
|
||||
if (panx > 6143) {
|
||||
panx = 6143;
|
||||
}
|
||||
panx -= 2048;
|
||||
if (panx > 0) {
|
||||
panx = -((panx / 4) - 1024) / 4;
|
||||
vol2 = (uint8)panx;
|
||||
if (panx >= 256) {
|
||||
vol2 = -1;
|
||||
}
|
||||
}
|
||||
if (vol1 >= vol2) {
|
||||
vol1 = vol2;
|
||||
}
|
||||
if (vol1 < RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8) * 3) {
|
||||
vol1 = 0;
|
||||
} else {
|
||||
vol1 = vol1 - (RCT2_GLOBAL(RCT2_ADDRESS_VOLUME_ADJUST_ZOOM, uint8) * 3);
|
||||
}
|
||||
int v32 = -(((uint8)(-vol1 - 1) * (uint8)(-vol1 - 1)) / 16) - 700;
|
||||
if (vol1 && v32 >= -4000) {
|
||||
if (panx > 10000) {
|
||||
panx = 10000;
|
||||
}
|
||||
if (panx < -10000) {
|
||||
panx = -10000;
|
||||
}
|
||||
if (!RCT2_GLOBAL(0x009AAC6D, uint8)) {
|
||||
panx = 0;
|
||||
}
|
||||
rct_ride_music* ride_music = &RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
int channel = 0;
|
||||
uint32 a1;
|
||||
while (ride_music->rideid != rideIndex || ride_music->tuneid != *tuneId) {
|
||||
ride_music++;
|
||||
channel++;
|
||||
if (channel >= 2) {
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[*tuneId];
|
||||
a1 = position + ride_music_info->var_4;
|
||||
goto label51;
|
||||
}
|
||||
}
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
int playing = sound_channel_is_playing(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
if (!playing) {
|
||||
*tuneId = 0xFF;
|
||||
return 0;
|
||||
}
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
a1 = sub_401B46(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
label51:
|
||||
if (a1 < RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[*tuneId].var_0) {
|
||||
position = a1;
|
||||
rct_ride_music_params* ride_music_params = RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*);
|
||||
if (ride_music_params < (rct_ride_music_params*)0x009AF46C/*ride_music_params list end*/) {
|
||||
ride_music_params->rideid = rideIndex;
|
||||
ride_music_params->tuneid = *tuneId;
|
||||
ride_music_params->offset = a1;
|
||||
ride_music_params->volume = v32;
|
||||
ride_music_params->pan = panx;
|
||||
ride_music_params->freq = RCT2_GLOBAL(0x009AF47C, uint16);
|
||||
RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)++;
|
||||
}
|
||||
} else {
|
||||
*tuneId = 0xFF;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
label58:
|
||||
;
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[*tuneId];
|
||||
position += ride_music_info->var_4;
|
||||
if (position < ride_music_info->var_0) {
|
||||
return position;
|
||||
} else {
|
||||
*tuneId = 0xFF;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play/update ride music based on structs updated in 0x006BC3AC
|
||||
* rct2: 0x006BC6D8
|
||||
*/
|
||||
void ride_music_update_final()
|
||||
{
|
||||
rct_ride_music_params* 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)) {
|
||||
// set to stop music if volume <= 1 ?
|
||||
while (1) {
|
||||
int v8 = 0;
|
||||
int v9 = 1;
|
||||
rct_ride_music_params* ride_music_params = &RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)) {
|
||||
if (ride_music_params->rideid != (uint8)-1) {
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[ride_music_params->tuneid];
|
||||
if (RCT2_ADDRESS(0x009AA0B1, uint8*)[ride_music_info->pathid]) { // file_on_cdrom[]
|
||||
v8++;
|
||||
if (v9 >= ride_music_params->volume) {
|
||||
v9 = ride_music_params->volume;
|
||||
edi = ride_music_params;
|
||||
}
|
||||
}
|
||||
}
|
||||
ride_music_params++;
|
||||
}
|
||||
if (v8 <= 1) {
|
||||
break;
|
||||
}
|
||||
edi->rideid = -1;
|
||||
}
|
||||
while (1) {
|
||||
int v8 = 0;
|
||||
int v9 = 1;
|
||||
rct_ride_music_params* ride_music_params = &RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)) {
|
||||
if (ride_music_params->rideid != (uint8)-1) {
|
||||
v8++;
|
||||
if (v9 >= ride_music_params->volume) {
|
||||
v9 = ride_music_params->volume;
|
||||
edi = ride_music_params;
|
||||
}
|
||||
}
|
||||
ride_music_params++;
|
||||
}
|
||||
if (v8 <= 2) {
|
||||
break;
|
||||
}
|
||||
edi->rideid = -1;
|
||||
}
|
||||
|
||||
// stop currently playing music that is not in music params list or not playing?
|
||||
rct_ride_music* ride_music = &RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
int channel = 0;
|
||||
do {
|
||||
if (ride_music->rideid != (uint8)-1) {
|
||||
rct_ride_music_params* ride_music_params = &RCT2_GLOBAL(0x009AF430, rct_ride_music_params);
|
||||
while (ride_music_params < RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*)) {
|
||||
if (ride_music_params->rideid == ride_music->rideid && ride_music_params->tuneid == ride_music->tuneid) {
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
int v16 = sound_channel_is_playing(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
if (v16) {
|
||||
goto label32;
|
||||
}
|
||||
break;
|
||||
}
|
||||
ride_music_params++;
|
||||
}
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_stop(channel);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
ride_music->rideid = -1;
|
||||
}
|
||||
label32:
|
||||
ride_music++;
|
||||
channel++;
|
||||
} while(channel < 2);
|
||||
|
||||
for (rct_ride_music_params* ride_music_params = &RCT2_GLOBAL(0x009AF430, rct_ride_music_params); ride_music_params < RCT2_GLOBAL(0x009AF42C, rct_ride_music_params*); ride_music_params++) {
|
||||
if (ride_music_params->rideid != (uint8)-1) {
|
||||
rct_ride_music* ride_music = &RCT2_GLOBAL(0x009AF46C, rct_ride_music);
|
||||
int channel = 0;
|
||||
while (ride_music_params->rideid != ride_music->rideid || ride_music_params->tuneid != ride_music->tuneid) {
|
||||
if (ride_music->rideid == (uint8)-1) {
|
||||
ebx = channel;
|
||||
}
|
||||
ride_music++;
|
||||
channel++;
|
||||
if (channel >= 2) {
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[ride_music_params->tuneid];
|
||||
const char* filename = get_file_path(ride_music_info->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 = ride_music_params->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, ride_music_params->volume, ride_music_params->pan, ride_music_params->freq);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
if (musicplayed) {
|
||||
rct_ride_music_info* ride_music_info = &RCT2_GLOBAL(0x009AF1C8, rct_ride_music_info*)[ride_music_params->tuneid];
|
||||
if (ride_music_info->var_9) {
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sub_401AF3(ebx, get_file_path(ride_music_info->pathid), 1, 0);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
}
|
||||
rct_ride_music* ride_music = &RCT2_ADDRESS(0x009AF46C, rct_ride_music)[ebx];
|
||||
ride_music->volume = ride_music_params->volume;
|
||||
ride_music->pan = ride_music_params->pan;
|
||||
ride_music->freq = ride_music_params->freq;
|
||||
ride_music->rideid = ride_music_params->rideid;
|
||||
ride_music->tuneid = ride_music_params->tuneid;
|
||||
}
|
||||
} else {
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_MUSIC, uint8) = 0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ride_music_params->volume != ride_music->volume) {
|
||||
ride_music->volume = ride_music_params->volume;
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_set_volume(channel, ride_music_params->volume);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
}
|
||||
if (ride_music_params->pan != ride_music->pan) {
|
||||
ride_music->pan = ride_music_params->pan;
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_set_pan(channel, ride_music_params->pan);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
}
|
||||
if (ride_music_params->freq != ride_music->freq) {
|
||||
ride_music->freq = ride_music_params->freq;
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 1;
|
||||
sound_channel_set_frequency(channel, ride_music_params->freq);
|
||||
RCT2_GLOBAL(0x014241BC, uint32) = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
|
@ -628,5 +628,7 @@ void ride_breakdown_add_news_item(int rideIndex);
|
|||
rct_peep *ride_find_closest_mechanic(rct_ride *ride, int forInspection);
|
||||
int sub_6CC3FB(int rideIndex);
|
||||
void ride_set_map_tooltip(rct_map_element *mapElement);
|
||||
int ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, uint16 sampleRate, uint32 position, uint8 *tuneId);
|
||||
void ride_music_update_final();
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue