public PcbFile(IO.File file) { this.File = file; // todo: fix this //Build(); }
public Renderer(VideoSystem videosystem) { if (videosystem == null) { throw new ArgumentNullException("videosystem"); } m_videosystem = videosystem; using (IO.File effectfile = m_videosystem.GetSubSystem <IO.FileSystem>().OpenFile("xnaMugen.data.Shader.fx")) { CompiledEffect compiled = Effect.CompileEffectFromSource(effectfile.ReadToEnd(), null, null, CompilerOptions.None, TargetPlatform.Windows); if (compiled.Success == false) { throw new InvalidOperationException("Cannot successfully create shader."); } m_effect = new Effect(Device, compiled.GetEffectCode(), CompilerOptions.NotCloneable, null); } m_drawbuffer = new Vertex[500]; m_parameters = new KeyedCollection <String, EffectParameter>(x => x.Name); m_nullpixels = m_videosystem.CreatePixelTexture(new Point(2, 2)); m_nullpalette = m_videosystem.CreatePaletteTexture(); Byte[] pixels = new Byte[] { 1, 2, 1, 2 }; m_nullpixels.SetData <Byte>(pixels); Color[] paldata = new Color[256]; paldata[1] = Color.White; paldata[2] = Color.Red; m_nullpalette.SetData <Color>(paldata); }
public ImcFile(IO.File sourceFile) { this.SourceFile = sourceFile; byte[] buffer = SourceFile.GetData(); this.Count = BitConverter.ToInt16(buffer, 0); this.PartsMask = BitConverter.ToInt16(buffer, 2); int offset = 4; for (byte bit = 0; bit < 8; ++bit) { int match = 1 << bit; if ((PartsMask & match) == match) { _Parts.Add(bit, new ImcPart(buffer, bit, ref offset)); } } short rem = Count; while (--rem >= 0) { foreach (ImcPart part in _Parts.Values) { part._Variants.Add(buffer.ToStructure <ImcVariant>(ref offset)); } } }
SpriteFile CreateSpriteFile(String filepath) { if (filepath == null) { throw new ArgumentNullException("filepath"); } IO.File file = GetSubSystem <IO.FileSystem>().OpenFile(filepath); IO.FileHeaders.SpriteFileHeader header = new IO.FileHeaders.SpriteFileHeader(file); List <SpriteFileData> datalist = new List <SpriteFileData>(header.NumberOfImages); Int32 subheader_offset = header.SubheaderOffset; for (file.SeekFromBeginning(subheader_offset); file.ReadPosition != file.FileLength; file.SeekFromBeginning(subheader_offset)) { IO.FileHeaders.SpriteFileSubHeader subheader = new IO.FileHeaders.SpriteFileSubHeader(file); SpriteFileData data = new SpriteFileData((Int32)file.ReadPosition + 13, subheader.ImageSize, subheader.Axis, subheader.Id, subheader.SharedIndex, subheader.CopyLastPalette); datalist.Add(data); subheader_offset = subheader.NextOffset; } return(new SpriteFile(this, file, header.Version, datalist, header.SharedPalette)); }
public Material(MaterialDefinition definition, IO.File file, ImcVariant variant) { this.Definition = definition; this.File = file; this.Variant = variant; Build(); }
public Boolean LoadImage(IO.File file, Int32 pcxsize, out Point size, out Texture2D pixels, out Texture2D palette) { if (file == null) { throw new ArgumentNullException("file"); } return(m_loader.Load(file, pcxsize, out size, out pixels, out palette)); }
public bool LoadImage(IO.File file, int pcxsize, out Point size, out Texture2D pixels, out Texture2D palette) { if (file == null) { throw new ArgumentNullException(nameof(file)); } return(m_loader.Load(file, pcxsize, out size, out pixels, out palette)); }
public ScdFile(IO.File sourceFile) { if (sourceFile == null) { throw new ArgumentNullException("sourceFile"); } this.SourceFile = sourceFile; Decode(); }
public SgbVfxEntry(IO.PackCollection packs, byte[] buffer, int offset) { this.Header = buffer.ToStructure <HeaderData>(offset); this.Name = buffer.ReadString(offset + Header.NameOffset); this.AvfxFilePath = buffer.ReadString(offset + Header.AvfxFileOffset); if (!string.IsNullOrEmpty(AvfxFilePath)) { this.AvfxFile = packs.GetFile(AvfxFilePath); } }
/// <summary> /// Read a part of a SND file and created a new byte[] from the contained sound. /// </summary> /// <param name="file">The file where the sound to be loaded from. The read position must be set at the beginning the sound part of the file.</param> /// <param name="length">The length of the sound in the filestream.</param> /// <returns></returns> private byte[] CreateSoundBuffer(IO.File file, int length) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (length <= 0) { throw new ArgumentOutOfRangeException(nameof(length), "length must be greater than zero."); } var buffer = file.ReadBytes(length); return(buffer); }
public Texture2D LoadPaletteFile(String filepath) { if (filepath == null) { throw new ArgumentNullException("filepath"); } Texture2D palette; if (m_palettefilecache.TryGetValue(filepath, out palette) == true) { return(palette); } palette = GetSubSystem <Video.VideoSystem>().CreatePaletteTexture(); m_palettefilecache.Add(filepath, palette); using (IO.File file = GetSubSystem <IO.FileSystem>().OpenFile(filepath)) { if (file.FileLength != (256 * 3)) { Log.Write(LogLevel.Error, LogSystem.SpriteSystem, "{0} is not a character palette file", filepath); } else { Byte[] buffer = new Byte[256 * 4]; Byte[] filedata = file.ReadBytes(256 * 3); for (Int32 i = 0; i != 256; ++i) { Int32 bufferindex = (255 - i) * 4; Int32 fileindex = i * 3; buffer[bufferindex + 0] = filedata[fileindex + 2]; buffer[bufferindex + 1] = filedata[fileindex + 1]; buffer[bufferindex + 2] = filedata[fileindex + 0]; buffer[bufferindex + 3] = 255; } palette.SetData <Byte>(buffer, 0, 256 * 4, SetDataOptions.None); } } return(palette); }
/// <summary> /// Loads sounds contained in a SND file. /// </summary> /// <param name="filepath">The filepath of the SND file to load sounds from.</param> /// <returns>A cached ReadOnlyDictionary mapping SoundIds to their respective SecondaryBuffers.</returns> private ReadOnlyDictionary <SoundId, byte[]> GetSounds(string filepath) { if (filepath == null) { throw new ArgumentNullException(nameof(filepath)); } var sounds = new Dictionary <SoundId, byte[]>(); using (IO.File file = GetSubSystem <IO.FileSystem>().OpenFile(filepath)) { var header = new IO.FileHeaders.SoundFileHeader(file); file.SeekFromBeginning(header.SubheaderOffset); for (var i = 0; i != header.NumberOfSounds; ++i) { var subheader = new IO.FileHeaders.SoundFileSubHeader(file); if (sounds.ContainsKey(subheader.Id) == true) { Log.Write(LogLevel.Warning, LogSystem.SoundSystem, "Duplicate sound with ID {0} discarded.", subheader.Id); } else { try { sounds.Add(subheader.Id, CreateSoundBuffer(file, subheader.SoundLength)); } catch { Log.Write(LogLevel.Warning, LogSystem.SoundSystem, "Error reading sound with ID {0}.", subheader.Id); } } file.SeekFromBeginning(subheader.NextOffset); } } ReadOnlyDictionary <SoundId, byte[]> savedsounds = new ReadOnlyDictionary <SoundId, byte[]>(sounds); m_soundcache.Add(filepath, savedsounds); return(savedsounds); }
/// <summary> /// Get the model for a specific QWord, character type, and the current <see cref="EquipSlot" />. /// </summary> /// <param name="key">The identifier of the model.</param> /// <param name="characterType">Character type to get the model for.</param> /// <param name="materialVersion">When this method returns, contains the variant contained within <c>key</c>.</param> /// <returns>Returns the <see cref="Model" /> for the specified <c>key</c> and <c>characterType</c>.</returns> public ModelDefinition GetModel(Quad key, int characterType, out Graphics.ImcVariant variant) { variant = Graphics.ImcVariant.Default; ModelHelper helper; if (!ModelHelpers.TryGetValue(Key, out helper)) { return(null); } if (helper == null) { return(null); } var packs = Collection.Collection.PackCollection; var variantIndex = (int)((key.ToInt64() >> (helper.VariantIndexWord * 16)) & 0xFFFF); var imcPath = string.Format(helper.ImcFileFormat, key.Value1, key.Value2, key.Value3, key.Value4, characterType); IO.File imcBase; if (!packs.TryGetFile(imcPath, out imcBase)) { return(null); } var imc = new Graphics.ImcFile(imcBase); variant = imc.GetVariant(helper.ImcPartKey, variantIndex); IO.File modelBase = null; while (!packs.TryGetFile(string.Format(helper.ModelFileFormat, key.Value1, key.Value2, key.Value3, key.Value4, characterType), out modelBase) && CharacterTypeFallback.TryGetValue(characterType, out characterType)) { } var asModel = modelBase as Graphics.ModelFile; if (asModel == null) { return(null); } return(asModel.GetModelDefinition()); }
public bool Load(IO.File file, int pcxsize, out Point size, out Texture2D pixels, out Texture2D palette) { if (file == null) { throw new ArgumentNullException(nameof(file)); } size = new Point(int.MinValue, int.MinValue); pixels = null; palette = null; var filedata = file.ReadBytes(pcxsize); if (filedata.Length != pcxsize) { return(false); } var header = new IO.FileHeaders.PcxFileHeader(filedata); var tempsize = new Point(header.XMax - header.XMin + 1, header.YMax - header.YMin + 1); if (header.Manufacturer != 10 || header.Encoding != 1 || header.Version > 5 || header.BitsPerPixel != 8) { return(false); } if (header.ColorPlanes != 1) { return(false); } if (tempsize.X <= 0 || tempsize.Y <= 0) { return(false); } size = tempsize; var readoffset = 0; pixels = LoadPixels(filedata, size, header.BytesPerLine, ref readoffset); palette = LoadPalette(filedata, ref readoffset); return(true); }
public GraphicsFileTextureDefinition(IO.File file) { this.File = file; byte[] buffer = file.GetData(); if (BitConverter.ToUInt64(buffer, 0) != 0x3030313064746667) // gftd0100 { throw new ArgumentException(); } int count = BitConverter.ToInt32(buffer, 8); int offset = 0x10; while (--count >= 0) { GftdEntry entry = buffer.ToStructure <GftdEntry>(ref offset); _Entries.Add(entry.Id, entry); } }
/// <summary> /// Read a part of a SND file and created a new SecondaryBuffer from the contained sound. /// </summary> /// <param name="file">The file where the sound to be loaded from. The read position must be set at the beginning the sound part of the file.</param> /// <param name="length">The length of the sound in the filestream.</param> /// <returns></returns> SecondaryBuffer CreateSoundBuffer(IO.File file, Int32 length) { if (file == null) { throw new ArgumentNullException("file"); } if (length <= 0) { throw new ArgumentOutOfRangeException("length", "length must be greater than zero."); } BufferDescription description = new BufferDescription(); description.CanGetCurrentPosition = true; description.Control3D = false; description.ControlFrequency = true; description.ControlPan = true; description.ControlPositionNotify = true; description.ControlVolume = true; SecondaryBuffer buffer = new SecondaryBuffer(file.Stream, length, description, m_sounddevice); return(buffer); }
public Terrain(IO.File file) { this.File = file; Build(); }
public ColorMap(IO.File file) { this.File = file; Build(); }
public Font LoadFont(String filepath) { if (filepath == null) { throw new ArgumentNullException("filepath"); } if (m_fontcache.Contains(filepath) == true) { return(m_fontcache[filepath]); } Point size = new Point(0, 0); Texture2D pixels = null; Texture2D palette = null; IO.TextFile textfile = null; using (IO.File file = GetSubSystem <IO.FileSystem>().OpenFile(filepath)) { IO.FileHeaders.FontFileHeader header = new IO.FileHeaders.FontFileHeader(file); file.SeekFromBeginning(header.ImageOffset); LoadImage(file, header.ImageSize, out size, out pixels, out palette); file.SeekFromBeginning(header.ImageOffset + header.ImageSize); textfile = GetSubSystem <IO.FileSystem>().BuildTextFile(file); } Sprite sprite = new Sprite(size, new Point(0, 0), true, pixels, true, palette, false); IO.TextSection data = textfile.GetSection("Def"); IO.TextSection textmap = textfile.GetSection("Map"); Int32 colors = data.GetAttribute <Int32>("colors"); Point defaultcharsize = data.GetAttribute <Point>("size"); Int32 numchars = 0; Dictionary <Char, Rectangle> sizemap = new Dictionary <Char, Rectangle>(); foreach (String line in textmap.Lines) { Match m = m_fontlinemapregex.Match(line); if (m.Success == false) { continue; } Char c = GetChar(m.Groups[1].Value); Point offset = (m.Groups[2].Value == "") ? new Point(defaultcharsize.X * numchars, 0) : new Point(Int32.Parse(m.Groups[2].Value), 0); Point charsize = (m.Groups[3].Value == "") ? defaultcharsize : new Point(Int32.Parse(m.Groups[3].Value), sprite.Size.Y); if (sizemap.ContainsKey(c) == false) { Rectangle r = new Rectangle(offset.X, offset.Y, charsize.X, charsize.Y); sizemap.Add(c, r); } ++numchars; } Font font = new Font(this, filepath, sprite, new ReadOnlyDictionary <Char, Rectangle>(sizemap), defaultcharsize, colors); m_fontcache.Add(font); return(font); }
public PcbFile(IO.File file) { this.File = file; Build(); }
private Material Create(string path, ImcVariant variant) { IO.File file = _Packs.GetFile(path); return(new Material(this, file, variant)); }