static void PlatformDetection_DetectXbox360Dlc(string path, StfsArchive stfs, PlatformList platforms) { if (DetectDirectoryNode != null) { DetectDirectoryNode(path, stfs.Root, platforms); } }
static void PlatformDetection_DetectFile(string path, Stream stream, PlatformList platforms) { if (DetectWiiDisc != null) { try { stream.Position = 0; Disc disc = new Disc(stream); DetectWiiDisc(path, disc, platforms); } catch (FormatException) { } catch (Exception exception) { Exceptions.Warning(exception, "Trying to open as Wiidisc: " + path); } } if (DetectIso9660 != null) { try { stream.Position = 0; Iso9660 disc = new Iso9660(stream); DetectIso9660(path, disc, platforms); } catch (FormatException) { } catch (Exception exception) { Exceptions.Warning(exception, "Trying to open as ISO: " + path); } } if (DetectXbox360Dlc != null) { try { stream.Position = 0; StfsArchive stfs = new StfsArchive(stream); DetectXbox360Dlc(path, stfs, platforms); } catch (FormatException) { } catch (Exception exception) { Exceptions.Warning(exception, "Trying to open as 360 DLC: " + path); } } if (DetectWiiU8 != null) { try { stream.Position = 0; U8 u8 = new U8(stream); DetectWiiU8(path, u8, platforms); } catch (FormatException) { } catch (Exception exception) { Exceptions.Warning(exception, "Trying to open as U8: " + path); } } if (DetectWiiDlcBin != null) { try { stream.Position = 0; DlcBin dlc = new DlcBin(stream); DetectWiiDlcBin(path, dlc, platforms); } catch (FormatException) { } catch (Exception exception) { Exceptions.Warning(exception, "Trying to open as Wii DLC: " + path); } } if (DetectHarmonixArk != null) { string extension = Path.GetExtension(path).ToLower(); if (extension.EndsWith(".ark") || extension.EndsWith(".hdr")) { PlatformDetection_DetectDirectory(Path.GetDirectoryName(path), platforms); } } }
internal static void Export360(string path, FormatData original) { Program.Form.Progress.QueueTask(progress => { progress.NewTask("Exporting to 360 DLC file", 16); SongData song = original.Song; StfsArchive stfs = new StfsArchive(); stfs.Stfs.ContentType = StfsFile.ContentTypes.Marketplace; stfs.Stfs.TitleID = 0x45410829; for (int i = 0; i < stfs.Stfs.DisplayName.Length; i++) { stfs.Stfs.DisplayName[i] = song.Artist + " - " + song.Name; } for (int i = 0; i < stfs.Stfs.DisplayDescription.Length; i++) { stfs.Stfs.DisplayDescription[i] = "RawkSD DLC - http://rawksd.japaneatahand.com"; } stfs.Stfs.TitleName = "Rawk Band 2"; stfs.Stfs.Publisher = "RawkSD"; stfs.Stfs.TitleThumbnail = WiiImage.Create(new EndianReader(new MemoryStream(ConsoleHaxx.RawkSD.Properties.Resources.rawksd_albumart), Endianness.LittleEndian)).Bitmap; if (song.AlbumArt != null) { stfs.Stfs.Thumbnail = song.AlbumArt; } else { stfs.Stfs.Thumbnail = stfs.Stfs.TitleThumbnail; } StfsFile.SignedHeader header = new StfsFile.SignedHeader(StfsFile.FileTypes.LIVE); stfs.Stfs.Header = header; header.Licenses[0].ID = 0xFFFFFFFFFFFFFFFF; stfs.Stfs.MetadataVersion = 2; StfsFile.PackageDescriptor desc = new StfsFile.PackageDescriptor(); stfs.Stfs.Descriptor = desc; desc.StructSize = 0x24; desc.BlockSeparation = 1; desc.FileTableBlockCount = 0x100; // byte apparently stfs.Stfs.TransferFlags = 0xC0; FormatData data = original; Program.Form.TaskMutex.WaitOne(); bool local = data.PlatformData.Platform == PlatformLocalStorage.Instance; bool ownformat = false; if (!local && Configuration.MaxConcurrentTasks > 1) { data = new TemporaryFormatData(data.Song, data.PlatformData); original.SaveTo(data); ownformat = true; } Program.Form.TaskMutex.ReleaseMutex(); Stream songs = null; Stream audio = null; Stream chart = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.ChartFile); Stream pan = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.PanFile); Stream weights = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.WeightsFile); Stream milo = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.MiloFile); milo = new MemoryStream(Properties.Resources.rbn_milo); // TODO: properly convert milo if (milo == null) { milo = new MemoryStream(ConsoleHaxx.RawkSD.Properties.Resources.rawksd_milo); } using (DelayedStreamCache cache = new DelayedStreamCache()) { AudioFormat audioformat = (data.GetFormat(FormatType.Audio) as IAudioFormat).DecodeAudio(data, progress); ushort[] masks = PlatformRB2WiiCustomDLC.RemixAudioTracks(data.Song, audioformat); progress.Progress(); // RBN Required DTA settings SongsDTA dta = PlatformRB2WiiCustomDLC.GetSongsDTA(song, audioformat, false); dta.AlbumArt = false; dta.Song.Name = "songs/" + song.ID + "/" + song.ID; dta.Song.MidiFile = "songs/" + song.ID + "/" + song.ID + ".mid"; dta.Rating = 4; dta.SubGenre = "subgenre_core"; dta.Format = 4; //dta.SongID = 0; dta.Origin = "rb2"; //dta.Ugc = 1; //dta.SongLength = 300000; dta.Context = 2000; dta.BasePoints = 0; if (!dta.TuningOffsetCents.HasValue) { dta.TuningOffsetCents = 0; } audio = new TemporaryStream(); cache.AddStream(audio); progress.Progress(); progress.SetNextWeight(10); long samples = audioformat.Decoder.Samples; CryptedMoggStream mogg = new CryptedMoggStream(audio); mogg.WriteHeader(); RawkAudio.Encoder encoder = new RawkAudio.Encoder(mogg, audioformat.Mappings.Count, audioformat.Decoder.SampleRate); progress.NewTask("Transcoding Audio", samples); JaggedShortArray buffer = new JaggedShortArray(encoder.Channels, audioformat.Decoder.AudioBuffer.Rank2); AudioFormat.ProcessOffset(audioformat.Decoder, encoder, audioformat.InitialOffset); while (samples > 0) { int read = audioformat.Decoder.Read((int)Math.Min(samples, audioformat.Decoder.AudioBuffer.Rank2)); if (read <= 0) { break; } audioformat.Decoder.AudioBuffer.DownmixTo(buffer, masks, read); encoder.Write(buffer, read); samples -= read; progress.Progress(read); } progress.EndTask(); progress.Progress(10); encoder.Dispose(); audioformat.Decoder.Dispose(); audio.Position = 0; dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Drums)); dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Bass)); dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Guitar)); dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Vocals)); dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Ambient)); for (int i = 0; i < dta.Song.Cores.Count; i++) { dta.Song.Cores[i] = -1; } songs = new TemporaryStream(); cache.AddStream(songs); dta.ToDTB().SaveDTA(songs); ChartFormat chartformat = (data.GetFormat(FormatType.Chart) as IChartFormat).DecodeChart(data, progress); if (chart != null && ChartFormatRB.Instance.NeedsFixing(data)) { data.CloseStream(chart); chart = null; } if (chart == null) { chart = new TemporaryStream(); cache.AddStream(chart); PlatformRB2WiiCustomDLC.AdjustChart(song, audioformat, chartformat).ToMidi().ToMid().Save(chart); chart.Position = 0; } if (weights == null) { weights = new TemporaryStream(); cache.AddStream(weights); PlatformRB2WiiCustomDLC.CreateWeights(weights, chartformat); weights.Position = 0; } if (pan == null) { pan = new TemporaryStream(); cache.AddStream(pan); PlatformRB2WiiCustomDLC.CreatePan(pan, chartformat); pan.Position = 0; } progress.Progress(3); DirectoryNode dir = new DirectoryNode("songs"); stfs.Root.AddChild(dir); dir.AddChild(new FileNode("songs.dta", songs)); DirectoryNode songdir = new DirectoryNode(song.ID); dir.AddChild(songdir); songdir.AddChild(new FileNode(song.ID + ".mogg", audio)); songdir.AddChild(new FileNode(song.ID + ".mid", chart)); DirectoryNode gendir = new DirectoryNode("gen"); songdir.AddChild(gendir); gendir.AddChild(new FileNode(song.ID + ".milo_xbox", milo)); gendir.AddChild(new FileNode(song.ID + "_weights.bin", weights)); Stream ostream = new FileStream(path, FileMode.Create); stfs.Save(ostream); ostream.Close(); data.CloseStream(audio); data.CloseStream(chart); data.CloseStream(pan); data.CloseStream(weights); data.CloseStream(milo); if (ownformat) { data.Dispose(); } progress.Progress(); progress.EndTask(); } }); }