Spaceship Warlock
Last week, i’m not able to do much works, but i’ve already gone back home now. So i’m ready to boost my self this week 🙂
I wrote a blog a few days ago, which recodes the process of how i implement and fix the external sound for director.
Check this:
BEGIN
This is a post which records the whole process of implementing loading external sounds file for Director.
Actually, i don’t know whether is could be called reverse-engineering. But this task really makes me “Breaks the Shell”
Let me describe it at the very begining part.
At first, i was wandering around in stambul to test whether the new implementation of fplay xobjs work well. And just after i pressed the cab tag, the sound of flying cab didn’t occurs. Instead, i got a lot ot debug output in terminal said: trying to play non-sound cast member.
So i opened Basilisk to check the original movie. Surprisingly, the original movie really uses the sound channel to play sound, but it didn’t use the sound cast member. The describtion on score shows that it was using sample sound.
I came back to scummvm and tried to print the sound channel info for all of those frames. It turns out that even we have ID which may represent the sound, but sound type isn’t match. So i opened the D2 manual to check the sound part. After reading the manual, i found that were sample sound data. And i’ve then check the sound menu in Basilisk, fortunately, the sound we are playing in sound menu is F-xx. F represent 15 which is exactly the sound type we have read. So then i start to looking the missing external sound files.
I remembered that we have the unhandled STR resource, so i tried to dump that STR resouce. Also, very fortunately, i’ve got a string which is related to the sound name that i need. Then i re-read the manual and found it said the sound file should be put at the same directory with movie. So i checked the movie directory, and found the file which has the same name as we got in STR resource.
Then the logic becomes very clear now, STR contains the file name, and we just need to read sound from that file.
I opened that sound file, and scummvm told me there is many resources contains STR and CSND. That’s it, the CSND resource must contains what i want.
I tried to google how to read the CSND resource, and also the refered the “Inside Macintosh: Sound”. And i’ve found a anwer which said the CSND resource is compressed snd resource with lzss algorithm and delta-encoding.
So i looked at their code and learned lzss algorithm. I’ve tried to implement lzss decompress for scummvm. But saidly, no matter what implementation i tried, i always can’t read the correct data.
After a lot of times of confirming, i think that the way i was reading data was wrong. There is only one csnd file that contains the sound i need. And i need 3 sound resource eventually. Thus, i think there should be a flag or something to indicate the location of those sound resources.
After comparing with other csnd resources, i found the snd resource and offset was saved at the begining of that csnd resource. So i read those offsets and try to deal with those data streams separatly. Due to the lack experience of decompiling work. I initially thought those offsets were relative to the begining of file. After a long time of doubting myself, i then compared two different external sound file. And i found those files are kind of same at the begining, where is exactly the place i thought which saves the sound data i need. Then i realize that the offset is not relative to the begining of file, but the begining of csnd resource.
Then, i finally locate the correct data area which contains the sound i need. The last step would be resolving those data.
At the begining, i thought the data was compressed by lzss, so i try to decompressed the data. After another a long time of implementing and testing, i failed. Then i refered the book which i mentioned earlier. I’ve tried to match hex code of the sample rate data.
But i didn’t found any sample rate data in that file. So i was convinced that the data was somehow compressed.
So i tried a lot of method to analyze and find the compressing method and try to decompress it.
check this 🙂
Then i re-read the D2 manual again, and i found a important info. Those sample data was fixed, there are only 4 options. And that inspired me that the reason i didn’t read sample rate data was because that was fixed in director.
And the strange unknown flag that i read earlier must indicate that sample rate.
Then i tried to open the same movie which didn’t use the external sound but sound cast member. I’ve compared the data which i think it was compressed with the sample data of sound cast. it turns out that those data was directly the sample data which no compression.(I should do this early, to compare the original one with this one, locate the data i need would be much easier for this task)
Then all of the problem was solved. And finally after 18 hours working on this one, i managed to implement reading external sound files.
Almost done with warlock now.
END
Ok, back there.
After implemented playing the external sound, mostly, i was doing the fixing work to make warlock more completeable.
Including amend fplay, which will use a queue to playing the sounds.
Also i’ve implemented some sound-related functions. E.g. soundEnabled, soundLevel. After that, the warlock can modify sound level now, which means i’m more closer to the complete version.
djsrv told me we should not overwrite the properities of cast member. So i amend our code for setting cast in sprites. A not that happy thing is after i do that, the logic in setClean where is the place we are replacing sprites and widgets becomes more complex. That means i need to organize the logic and refactor that part some day. But before doing that, i need more experiences in cast i won’t cause regression.
Today, i’ve fix the way we are using snd resource, i’ve implement the loopstart and loopend part, which bring us the correct behaviour of sounds for D2/3.
So i think i can say, that warlock-mac is fixed now. Maybe there are still small cases which has some problem that i havn’t noticed. If you find that please tell me. 🙂
Today i’m also doing some fixing work for macfonts, which seems has wrong kern offset. And after that, this week i will start working on fixing l-zone. And i think since warlock-mac is fixed now. that game won’t have much problem left.
Waiting for my good news.