public static Theme Read(Stream s) { if (!s.CanSeek) throw new ArgumentException("Stream can't Seek", nameof(s)); var body = new Theme(); using (var br = new BinaryReader(s, Encoding.ASCII, true)) { var flag = br.ReadUInt32() == 1; if (!flag) throw new InvalidDataException("Not a Theme File (Was File Decompressed?)"); var flags = Read_Flags(s); var cOffs = Read_ColorOffsets(s, flags); var tOffs = Read_TextureOffsets(s, flags); var colors = Read_Colors(s, flags, cOffs); var textures = Read_Textures(s, flags, tOffs); var cwav = Read_CWav(s, flags); body.Flags = flags; body.Colors = colors; body.Textures = textures; body.CWAV = cwav; } return body; }
public ThemeViewModel(Theme model) : base(model, Guid.NewGuid().ToString()) { Flags = new FlagsViewModel(model.Flags, Tag); Colors = new ColorsViewModel(model.Colors, Tag); Textures = new TexturesViewModel(model.Textures, Tag); SetupRules(); }
public ThemeViewModel(Theme model, SMDH info = null) : base(model, Guid.NewGuid().ToString()) { Flags = new FlagsViewModel(model.Flags, Tag); Colors = new ColorsViewModel(model.Colors, Tag); Textures = new TexturesViewModel(model.Textures, Tag); Info = new ThemeInfoViewModel(info ?? new SMDH(), Tag); SetupRules(); }
private static TextureOffsets Write_Textures(Stream s, Theme b) { TextureOffsets offsets = new TextureOffsets(); // Top if (b.Flags.TopDrawType == TopDrawType.Texture && b.Textures.Top.Format != RawTexture.DataFormat.Invalid) { offsets.Top = (uint) s.Position; var data = b.Textures.Top.Data; s.Write(data, 0, data.Length); } else if (b.Flags.TopDrawType == TopDrawType.SolidColorTexture && b.Textures.Top.Format != RawTexture.DataFormat.Invalid) { offsets.Top = (uint) s.Position; var data = b.Textures.Top.Data; s.Write(data, 0, data.Length); } // Top Ext if (b.Flags.TopDrawType == TopDrawType.SolidColorTexture && b.Textures.TopExt.Format != RawTexture.DataFormat.Invalid) { offsets.TopExt = (uint)s.Position; var data = b.Textures.TopExt.Data; s.Write(data, 0, data.Length); } // Bottom if (b.Flags.BottomDrawType == BottomDrawType.Texture && b.Textures.Bottom.Format != RawTexture.DataFormat.Invalid) { offsets.Bottom = (uint) s.Position; var data = b.Textures.Bottom.Data; s.Write(data, 0, data.Length); } // Folder if (b.Flags.FolderTexture && b.Textures.FolderClosed.Format != RawTexture.DataFormat.Invalid && b.Textures.FolderOpen.Format != RawTexture.DataFormat.Invalid) { offsets.FolderClosed = (uint) s.Position; var data = b.Textures.FolderClosed.Data; s.Write(data, 0, data.Length); offsets.FolderOpen = (uint) s.Position; data = b.Textures.FolderOpen.Data; s.Write(data, 0, data.Length); } // Files if (b.Flags.FileTexture && b.Textures.FileLarge.Format != RawTexture.DataFormat.Invalid && b.Textures.FileSmall.Format != RawTexture.DataFormat.Invalid) { offsets.FileLarge = (uint) s.Position; var data = b.Textures.FileLarge.Data; s.Write(data, 0, data.Length); offsets.FileSmall = (uint) s.Position; data = b.Textures.FileSmall.Data; s.Write(data, 0, data.Length); } return offsets; }
private static ColorOffsets Write_Colors(Stream s, Theme b) { var offsets = new ColorOffsets(); using (BinaryWriter bw = new BinaryWriter(s, Encoding.ASCII, true)) { // Top Solid #if SKIP_COLOR_NOT_SET if (b.Flags.TopDrawType == TopDrawType.SolidColor || b.Flags.TopDrawType == TopDrawType.SolidColorTexture) #endif { offsets.TopBackground = (uint) s.Position; var seven = b.Flags.TopDrawType == TopDrawType.SolidColorTexture; b.Colors.TopBackground.Write(bw, seven); } // Cursor #if SKIP_COLOR_NOT_SET if (b.Flags.CursorColor) #endif { offsets.Cursor = (uint) s.Position; b.Colors.Cursor.Write(bw); } // 3D Folder #if SKIP_COLOR_NOT_SET if (b.Flags.FolderColor) #endif { offsets.Folder = (uint) s.Position; b.Colors.Folder.Write(bw); } // 3D File #if SKIP_COLOR_NOT_SET if (b.Flags.FileColor) #endif { offsets.File = (uint) s.Position; b.Colors.File.Write(bw); } // Arrow Button #if SKIP_COLOR_NOT_SET if (b.Flags.ArrowButtonColor) #endif { offsets.ArrowButton = (uint) s.Position; b.Colors.ArrowButton.Write(bw); } // Arrow #if SKIP_COLOR_NOT_SET if (b.Flags.ArrowColor) #endif { offsets.Arrow = (uint) s.Position; b.Colors.Arrow.Write(bw); } // Open Close Button #if SKIP_COLOR_NOT_SET if (b.Flags.OpenCloseColor) #endif { offsets.Open = (uint) s.Position; b.Colors.Open.Write(bw); offsets.Close = (uint) s.Position; b.Colors.Close.Write(bw); } // Game Text #if SKIP_COLOR_NOT_SET if (b.Flags.GameTextDrawType) #endif { offsets.GameText = (uint) s.Position; b.Colors.GameText.Write(bw); } // Bottom Solid #if SKIP_COLOR_NOT_SET if (b.Flags.BottomBackgroundInnerColor) #endif { offsets.BottomSolid = (uint) s.Position; b.Colors.BottomBackgroundInner.Write(bw); } // Bottom Outer #if SKIP_COLOR_NOT_SET if (b.Flags.BottomBackgroundOuterColor) #endif { offsets.BottomOuter = (uint) s.Position; b.Colors.BottomBackgroundOuter.Write(bw); } // Folder BG #if SKIP_COLOR_NOT_SET if (b.Flags.FolderBackgroundColor) #endif { offsets.FolderBackground = (uint) s.Position; b.Colors.FolderBackground.Write(bw); } // Folder Arrow #if SKIP_COLOR_NOT_SET if (b.Flags.FolderArrowColor) #endif { offsets.FolderArrow = (uint) s.Position; b.Colors.FolderArrow.Write(bw); } // Bottom Corner #if SKIP_COLOR_NOT_SET if (b.Flags.BottomCornerButtonColor) #endif { offsets.BottomCornerButton = (uint) s.Position; b.Colors.BottomCornerButton.Write(bw); } // Top Corner #if SKIP_COLOR_NOT_SET if (b.Flags.TopCornerButtonColor) #endif { offsets.TopCornerButton = (uint) s.Position; b.Colors.TopCornerButton.Write(bw); } // Demo Text #if SKIP_COLOR_NOT_SET if (b.Flags.DemoTextColor) #endif { offsets.DemoText = (uint) s.Position; b.Colors.DemoText.Write(bw); } } return offsets; }
private static void Write_Flags (Stream s, Theme body, TextureOffsets tOff, ColorOffsets cOff, uint wOff) { using (BinaryWriter bw = new BinaryWriter(s, Encoding.ASCII, true)) { // Version bw.Write(1); // BGM Flag bw.Write((byte) 0); bw.Write((byte) (body.Flags.BackgroundMusic ? 1 : 0)); bw.Write((byte) 0); bw.Write((byte) 0); // Unkown bw.Write((uint) 0); // Top Screen bw.Write((uint) body.Flags.TopDrawType); bw.Write((uint) body.Flags.TopFrameType); bw.Write((uint) cOff.TopBackground); bw.Write((uint) tOff.Top); bw.Write((uint) tOff.TopExt); // Bottom Screen bw.Write((uint) body.Flags.BottomDrawType); bw.Write((uint) body.Flags.BottomFrameType); bw.Write((uint) tOff.Bottom); // Cursor bw.Write((uint) (body.Flags.CursorColor ? 1 : 0)); bw.Write((uint) cOff.Cursor); // 3D Folder bw.Write((uint) (body.Flags.FolderColor ? 1 : 0)); bw.Write((uint) cOff.Folder); // 2D Folder bw.Write((uint) (body.Flags.FolderTexture ? 1 : 0)); bw.Write((uint) tOff.FolderClosed); bw.Write((uint) tOff.FolderOpen); // 3D File bw.Write((uint) (body.Flags.FileColor ? 1 : 0)); bw.Write((uint) cOff.File); // 2D File bw.Write((uint) (body.Flags.FileTexture ? 1 : 0)); bw.Write((uint) tOff.FileLarge); bw.Write((uint) tOff.FileSmall); // Arrow Button bw.Write((uint) (body.Flags.ArrowButtonColor ? 1 : 0)); bw.Write((uint) cOff.ArrowButton); // Arrow bw.Write((uint) (body.Flags.ArrowColor ? 1 : 0)); bw.Write((uint) cOff.Arrow); // Open Close bw.Write((uint) (body.Flags.OpenCloseColor ? 1 : 0)); bw.Write((uint) cOff.Open); bw.Write((uint) cOff.Close); // Game Text bw.Write((uint) body.Flags.GameTextDrawType); bw.Write((uint) cOff.GameText); // Bottom Solid bw.Write((uint) (body.Flags.BottomBackgroundInnerColor ? 1 : 0)); bw.Write((uint) cOff.BottomSolid); // Bottom Outer bw.Write((uint) (body.Flags.BottomBackgroundOuterColor ? 1 : 0)); bw.Write((uint) cOff.BottomOuter); // Folder BG bw.Write((uint) (body.Flags.FolderBackgroundColor ? 1 : 0)); bw.Write((uint) cOff.FolderBackground); // Folder Arrow bw.Write((uint) (body.Flags.FolderArrowColor ? 1 : 0)); bw.Write((uint) cOff.FolderArrow); // Bottom Corner bw.Write((uint) (body.Flags.BottomCornerButtonColor ? 1 : 0)); bw.Write((uint) cOff.BottomCornerButton); // Top Corner bw.Write((uint) (body.Flags.TopCornerButtonColor ? 1 : 0)); bw.Write((uint) cOff.TopCornerButton); // Demo Text bw.Write((uint) (body.Flags.DemoTextColor ? 1 : 0)); bw.Write((uint) cOff.DemoText); // SFX bw.Write((uint) (body.Flags.SoundEffect ? 1 : 0)); bw.Write((uint) body.CWAV.Length); bw.Write((uint) wOff); } }
private static uint Write_CWavs(Stream s, Theme theme) { var pos = s.Position; s.Write(theme.CWAV, 0, theme.CWAV.Length); return (uint) pos; }
public static void Write(Theme b, Stream s) { if (!s.CanSeek || !s.CanWrite) throw new ArgumentException("Provided Stream can't Seek or Write", nameof(s)); int start = (int) s.Position; using (BinaryWriter bw = new BinaryWriter(s, Encoding.ASCII, true)) { // Data Pad bw.Seek(0xD0 + start, SeekOrigin.Current); // Write Data var cOffs = Write_Colors(s, b); var tOffs = Write_Textures(s, b); var wOff = Write_CWavs(s, b); // Offset into Start cOffs.Offset(-start); tOffs.Offset(-start); wOff = (uint) (wOff - start); // Header Offset bw.Seek(0 + start, SeekOrigin.Begin); // Write Header Write_Flags(s, b, tOffs, cOffs, wOff); // 0x10c Pad int rem = (int) (s.Position % 0x10); bw.Seek(rem - 1, SeekOrigin.End); bw.Write((byte) 0); } }