March 28, 2024, 17:39
bigger smaller reset     1020px Wide width Full width Reset   * *

Gildor's Forums

  Homepage Facebook Read news on Twitter Youtube channel Github page
Welcome, Guest. Please login or register.
Did you miss your activation email?

« previous next »
Print
Author Topic: Repacking .afc files  (Read 24544 times)
The Fobbinger
Newbie
*
Posts: 13


View Profile
« on: July 07, 2012, 09:02 »

Hi guys,

I was wondering if there is a way to repack .afc files. Basically I want to mod sound and dialogue in the game. Is there a way to extract .afcs into .oggs, modify them (but keep file length and size exactly the same), repack them and put them back where they belong (e.g. in an .sfar)? I think I have figured out all the necessary steps (in theory) apart from repacking .oggs to .afcs. Not sure if that is even possible without access to BWs original tools.
Logged
warrantyvoider
Full Member
***
Posts: 109


View Profile
« Reply #1 on: July 07, 2012, 23:08 »

Hi,
Im looking for something similar, all you need is pretty much a wav/ogg to wwise format converter. They have a free SDK but I dunno if you can write a converter with that. Btw with my tool you can extract from afcs direct (they are "audio file cache") or by their references in the pccs. If you find a way to convert the format back, let me know.

Greetz Warranty Voider

PS: tool http://me3explorer.wikispaces.com/
Logged
The Fobbinger
Newbie
*
Posts: 13


View Profile
« Reply #2 on: July 08, 2012, 18:02 »

Hey, thanks. I am already using your tool (and others) to convert the afcs to oggs and wavs.
I am kinda new to this so I am not sure if I have it all figured out correctly but if I got it right, all wwise should do is to add some new headers to the files. Is that correct? Because if that is the case, one could theoretically be able to keep the headers and thus all the meta-data that is important for the game itself and just switch out the actual audio information. Not sure if this is feasible though. As I said, I am pretty new to sound file conversion and I have a lot to catch up on. I'll do some more reading when I have more time next weekend but I'd be grateful for any further information. E.g. how did you incorporate your afc converter into the me3explorer? did you just use a pre-existing ww2ogg program/library or did you actually play around with the files themselves (from what I read, the vanilla ww2ogg didn't really work that well for mass effect's afcs)? Any info on the data structure within the files would be extremely useful.
In any case, I am afraid this will take quite a bit of time. If we can manage it at all.
Logged
warrantyvoider
Full Member
***
Posts: 109


View Profile
« Reply #3 on: July 08, 2012, 23:34 »

well the source code is always available and the latest build is on SVN. There you can see how its handled, in pcc you get an offset for an afc file, there the wwise WAV container has the disguised ogg file, which will be extracted with ww2ogg as you said, someone has to write a ogg2ww converter. Wwise just adds game infos to the header. I dunno more, sry.
greetz
Logged
The Fobbinger
Newbie
*
Posts: 13


View Profile
« Reply #4 on: July 09, 2012, 16:13 »

Hi warrantyvoider. Thanks again for your help. Ok, I had a look through your source code, the code for the ww2ogg and the Audiokinetic SDK. The SDK doesn't have much info on the conversion itself that I can see but I think in principle, with everything there is in the ww2ogg, it should be possible to build a reverse converter with a lot of time and effort. Maybe someone over at hcs64 wants to do it. Unfortunately I lack the time at the moment.
However, there might be a workaround. What I managed to do so far was convert a wav file, simply using wwise itself. It's a freer license for non-commercial use so you can simply download it. Just convert whatever sound file you want to use into a wav file with any programm. (it might be a good idea to match the sampling rate to the one ME3 uses already which I believe is 38352 bps at 24kHz. Than make a new project with wwise and import the wav file. Set the shared conversion settings for windows to "Vorbis" and if you already have the right sample rate, choose "As input". Convert the file and in the .cache folder of your project, you will find a .wem file with the same name as your sound file which should now be in ww encoded.
At least, my ww2ogg could convert it back into an ogg file without an error.
But here is the bad news: The ogg file did not play on my vlc player.
If I extract a .riff from a an ME3 afc with Gibbet's audio extractor, and I manually run this riff through ww2ogg, the resulting ogg doesn't play either at first. However, if I run this newly created ogg through revorb.exe it works.
Sadly, revorb.exe crashes if I try to use it on the new ogg file that I created from the wwise wem file so I am not sure if there is something wrong with the conversion itself or if they changed their bitstream format or what is going on. I feel like I am half way there though and I'll keep working on it when I have time.
Feel free to try it out. Maybe you have an idea how to fix it. As I said, I am fairly inexperienced with all this. Cheers!
Logged
warrantyvoider
Full Member
***
Posts: 109


View Profile
« Reply #5 on: July 09, 2012, 22:35 »

wow, thats alot research, nice, thank you! If you can convert something back try to compare it with the original binary before its converted with ww2ogg in a hexeditor, I guess wwise already added some gameinfos to the header so you cant play it normally anymore.
greetz

PS:I have not much time these days, real coding will start in a week or two
Logged
The Fobbinger
Newbie
*
Posts: 13


View Profile
« Reply #6 on: July 10, 2012, 09:19 »

Well, I got it to work in principle, just need to make it work for ME3 now.
Here is the deal: Audiokinetics changed their bitstream format and is using new codebooks since the middle of 2011. These new codebooks are even included in the latest version of ww2ogg (packed_codebooks_aoTuV_603.bin) and if I use them with the ww2ogg --pcb option and then use revorb.exe on the resulting ogg file, it will play in vlc just as intended.
That means the method works in principle and we should be able to recode any sound file we want into a format ME3 can read eventually.
So here are the 2 problems:
1. We need a the correct build of wwise (I guess it's gonna be 2011.1.x because we need the converter that uses the same codebooks as they used for ME3. I am sure we can get a hand on an older wwise build somehow though. I didn't find any way to get it in my initial search but I'll keep at it (if someone reads this who has one, please post).
2. I am not sure how successful we will be in modifying file headers. Thus I'd suggest that (for a first step at least) we make sure that our converted sound files have the exact same sample size and bps as the originals (which means the exact same length as well). That way, we can just keep the headers and selectively exchange only the actual bitstream data. If we can do it right, the game should never know the difference and play our new sound with the old header. You seem to be more familiar with the headers though and how they are implemented in the game itself so maybe I am too pessimistic.

Anyway,so far so good. Cheers!

EDIT: So I found an older version of wwise and now the encoding (with wwise) and decoding (with ww2ogg and revorb) works perfectly, just the same as for ME3 riffs. However, from what I gather from the ww2ogg source code, we can forget about leaving the headers in the afcs because the data is devided into chunks and packages which are different in every file. I just tried to exchange a whole file in an afc with one that I recorded (including the headers). It doesn't break the game but it doesn't play either. I'll try and figure out more about how exactly these data chunks and packages are organised. Maybe there is a way to do it somehow after all.
« Last Edit: July 10, 2012, 16:18 by The Fobbinger » Logged
warrantyvoider
Full Member
***
Posts: 109


View Profile
« Reply #7 on: July 10, 2012, 17:18 »

hey, I got some infos from a friend, maybe that helps you. I really have no plan about sound formats, so sorry I cant help you there, but this maybe:

ME3 WWISE RIFF header structure:
bytes:
0 - 3  : (32) "RIFF" name
4 - 7  : (32) riff size - 8
8 - 11 : (32) "WAVE" name
12 - 15: (32) chunk type: "fmt "
16 - 19: (32) chunk size
20 - 21: (16) 0xFFFF (audio format) 0xFFFF means experimental
22 - 23: (16) num of channels
24 - 27: (32) sample rate (in Hz) es: 0x5DC0 = 24000Hz
28 - 31: (32) avg bytes per second
32 - 33: (16) 0x0000 (block align)
34 - 35: (16) 0x0000 bits per sample (expected 0bps)
36 - 37: (16) chunk size - 12
38 - 39: (16) extra fmt? (1 = yes)
40 - 43: (32) subtype (4 = 1 channel, no seek table)
44 - 47: (32) num of samples (num of bit per sample)
48 - 51: (32) mod signal
52 - 53: (16) data size (go to 90 - 93)
54 - 57: (32) setup packet offset
58 - 61: (32) first audio packet offset

62 - 79: dunno...

80 - 83: uid
84     : _blocksize_0_pow
85     : _blocksize_1_pow
86 - 89: "data"
90 - 93: data size


greetz WV
Logged
The Fobbinger
Newbie
*
Posts: 13


View Profile
« Reply #8 on: July 10, 2012, 18:01 »

Thanks! Didn't know about the location of the blocsize0 and blocksize1 yet. This might help but I am not sure yet (haha, I am learning this stuff as I go along).
The good news is that I can definitely modify data directly in the game without breaking the file. If I just change the right bytes in an afc file to 0, I can create a pause in the playback of the sound directly in the game without stopping the whole thing from being played. That's encouraging. The problem is going to be to replace it with some useful data and for that, I have to figure out the audio package boundaries within the files. Have to go through the ww2ogg source code again and try to make sense the parts I didn't quite understand yet.
I'll let you know as soon as I figure something out but this time it may really take  a while. Cheers!
Logged
The Fobbinger
Newbie
*
Posts: 13


View Profile
« Reply #9 on: July 10, 2012, 19:33 »

Ok, forget my last post (about the time) because I did it! It worked!
I just played Mass Effect 3 and heard my own recorded sound instead of a piece of dialogue in the game. I had to change the headers manually, byte by byte but now that I know what I have to do, I can easily write a program or at least a scrip for it.
Basically all you have to do is search the correct bytes from the newly encoded file together (which is a bit tricky because its header has a "vorb" chunk which the ME3 files don't have). Than you copy all your data in there, replace the space that is left over with zeros and adjust the riff file length byte at the beginning of the file. And that's it! Works like a charm. Only downside is, you can only use sound files that are the same size or shorter then what is in the game so you don't change the offset of the files that are stored after the one you modify. You can possibly compensate by using lower bps values though, now that we actually change the headers, that shouldn't be a problem.
YAY! I am happy. Now I can go to bed (it's like 1:30 in the morning here and I gotta go to work tomorrow morning Smiley). Thanks again warranty voider. Without your tools and help this would never have worked. Let me know if you need any further info on how to do this. I'll make some sort of script for this as soon as possible but can't really say when so maybe you'll have a chance to do it sooner. Cheers!
Logged
warrantyvoider
Full Member
***
Posts: 109


View Profile
« Reply #10 on: July 10, 2012, 20:50 »

yeah, great! I cant wait to see it! could you also make a tool or description on how you converted it back in the first place? and then a script on how to edit the bytes would be awesome! thanky YOU alot!
greetz WV
Logged
The Fobbinger
Newbie
*
Posts: 13


View Profile
« Reply #11 on: July 11, 2012, 14:17 »

Sure. I'll try and put something together asap. I am a bit bogged down by work at the moment but I hope I can get something going on the weekend.
Logged
warrantyvoider
Full Member
***
Posts: 109


View Profile
« Reply #12 on: July 15, 2012, 12:21 »

Hey man,
how is it going? Could you put something together in the meantime?
greetz
Logged
The Fobbinger
Newbie
*
Posts: 13


View Profile
« Reply #13 on: July 15, 2012, 13:08 »

I sent you a pm.

EDIT: A bit off topic but just because I am not sure how many people actually look into the "particular recourse" forum section, I am looking for info on the meshes or textures of the star kid at the end of ME3. If anyone knows anything,here is a link to the thread.
« Last Edit: July 16, 2012, 07:42 by The Fobbinger » Logged
kublikhan
Newbie
*
Posts: 3


View Profile
« Reply #14 on: May 23, 2014, 17:30 »

I know this thread is old, but I was wondering if I could get a copy of the mentioned tool/script/detailed steps on converting ogg to ww.
Logged
Print 
« previous next »
Jump to:  

Powered by SMF | SMF © 2006-2009, Simple Machines LLC
Leviathan design by Bloc | XHTML | CSS