public uint add_music(string file) { string s = Path.GetFileNameWithoutExtension(file); uint mid = 0; if (!uint.TryParse(s, out mid)) { Console.WriteLine("Soundbank : add_music -- Invalid WEM ID"); Environment.Exit(0); } if (mid < 1 || mid > 0xFFFFFFFF) { Console.WriteLine("Soundbank : add_music -- Invalid WEM ID"); Environment.Exit(0); } WemFile wem = new WemFile(); wem.LoadFromFile(file, WwAudioFileType.Wem); double new_time = (wem.sample_count / wem.sample_rate) * 1000; SBObject segment = null; foreach (var obj in _objects._objects) { if (obj._type == SBObject.TYPE_MUSIC_TRACK) { if (obj._obj_mto._id1 == mid) { Console.WriteLine("Add new music : ID " + mid + " is already used"); Environment.Exit(0); } } else if (obj._type == SBObject.TYPE_MUSIC_SEGMENT) { if (segment == null) { segment = obj; } } } if (segment != null) { Console.WriteLine("No music segments within the soundbank"); Environment.Exit(0); } uint musicTrackId = _objects.get_new_id(); SBObject musicTrackObject = new SBObject(); musicTrackObject._type = SBObject.TYPE_MUSIC_TRACK; musicTrackObject._id = musicTrackId; musicTrackObject._obj_mto_custom = new SBMusicTrackCustomObject(mid, new_time, 0); musicTrackObject._current_obj = "MusicTrackCustom"; musicTrackObject.calculateLength(); _objects._objects.Add(musicTrackObject); uint musicSegmentId = _objects.get_new_id(); musicTrackObject._obj_mto_custom._parent = musicSegmentId; SBObject musicSegmentObject = segment; musicSegmentObject._id = musicSegmentId; musicSegmentObject._obj_mso._children = 1; musicSegmentObject._obj_mso._child_ids = new List <uint>(); musicSegmentObject._obj_mso._child_ids.Add(musicTrackId); musicSegmentObject._obj_mso._unk_double_1 = 1000; musicSegmentObject._obj_mso._unk_field64_1 = 0; musicSegmentObject._obj_mso._unk_field64_2 = 0; musicSegmentObject._obj_mso._time_length = new_time; musicSegmentObject._obj_mso._time_length_next = new_time; musicSegmentObject._obj_mso._sound_structure._parent_id = 0; musicSegmentObject.calculateLength(); _objects._objects.Add(musicSegmentObject); _objects.calculate_length(); return(musicSegmentId); }
public void rebuild_music(string file) { uint mid = 0; if (!uint.TryParse(Path.GetFileNameWithoutExtension(file), out mid)) { Console.WriteLine("Soundbank : rebuild_music -- wrong file"); return; } if (mid < 1 || mid > 0xFFFFFFFF) { Console.WriteLine("Soundbank : rebuild_music -- Invalid WEM ID"); return; } WemFile wem = new WemFile(); wem.LoadFromFile(file, WwAudioFileType.Wem); double new_time = (wem.sample_count / (float)wem.sample_rate) * 1000; Dictionary <uint, List <uint> > trackids = new Dictionary <uint, List <uint> >(); uint i = 0; foreach (var obj in _objects._objects) { if (obj._type == SBObject.TYPE_MUSIC_TRACK) { if (obj._obj_mto._id1 == mid) { List <uint> v = new List <uint> { i, 0 }; trackids.Add(obj._id, v); } } i++; } if (trackids.Count == 0) { Console.WriteLine("Could not find ID " + mid + " within soundbank -- rebuild_music"); return; } foreach (var obj in _objects._objects) { if (obj._type == SBObject.TYPE_MUSIC_SEGMENT) { if (obj._obj_mso._child_ids.Count == 1) { obj._obj_mso._unk_double_1 = 1000; obj._obj_mso._unk_field64_1 = 0; obj._obj_mso._unk_field64_2 = 0; obj._obj_mso._time_length = new_time; obj._obj_mso._time_length_next = new_time; trackids[obj._obj_mso._child_ids[0]][1] = obj._id; } else { long hasTrack = -1; foreach (var trackid in trackids) { if (obj._obj_mso._child_ids.Contains(trackid.Key)) { hasTrack = (long)trackid.Key; } } if (hasTrack != -1) { obj._obj_mso._children = 1; obj._obj_mso._child_ids = new List <uint>(); obj._obj_mso._child_ids.Add((uint)hasTrack); obj._obj_mso._unk_double_1 = 1000; obj._obj_mso._unk_field64_1 = 0; obj._obj_mso._unk_field64_2 = 0; obj._obj_mso._time_length = new_time; obj._obj_mso._time_length_next = new_time; obj.calculateLength(); trackids[(uint)hasTrack][1] = obj._id; } } } } foreach (var t in trackids) { if (t.Value[1] != 0) { _objects._objects[(int)t.Value[0]]._obj_mto_custom = new SBMusicTrackCustomObject(mid, new_time, t.Value[1]); _objects._objects[(int)t.Value[0]].calculateLength(); } } _objects.calculate_length(); }