public MTCFrame(GTFS fs, int mtcWidth, int mtcHeight) { //pixels = new Color[mtcWidth * mtcHeight]; bitmap = new Bitmap(mtcWidth, mtcHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); int i = 0; for (int y = 0; y < mtcHeight; y++) { for (int x = 0; x < mtcWidth; x++) { byte left = (byte)fs.ReadByte(); byte right = (byte)fs.ReadByte(); ushort palette = (ushort)(right | left << 8); Color c = FRM.Palette2Color(palette); if (c.R != c.G && c.G != c.B) { c = Color.FromArgb(150, c); } else { c = Color.FromArgb(0, c); } //pixels[i++] = c; bitmap.SetPixel(x, y, c); } } }
public ANM(GTFS fs) { flip = false; this.fs = fs; FileName = fs.FilePath; SafeFileName = Path.GetFileName(FileName); listPackFrames = new List <Pack>(); listFrames = new List <FRM>(); //-- uint unk1 = GT.ReadUInt32(fs, 4, flip); uint numFrames = GT.ReadUInt32(fs, 4, flip); uint numFramesHeaderLen = GT.ReadUInt32(fs, 4, flip); uint unk2 = GT.ReadUInt32(fs, 4, flip); Height = GT.ReadUInt16(fs, 2, flip); Width = GT.ReadUInt16(fs, 2, flip); uint unk3 = GT.ReadUInt32(fs, 4, flip); uint unk4 = GT.ReadUInt32(fs, 4, flip); uint unk5 = GT.ReadUInt32(fs, 4, flip); for (int i = 0; i < numFrames; i++) { uint frameOffset = GT.ReadUInt32(fs, 4, flip); uint frameLen = GT.ReadUInt32(fs, 4, flip); uint frameUnk = GT.ReadUInt32(fs, 4, flip); uint framePad = GT.ReadUInt32(fs, 4, flip); string name = "Frame " + i + ".frm"; listPackFrames.Add(new Pack(name, frameOffset, frameLen)); } Bitmap lastBitmap = null; foreach (Pack pack in listPackFrames) { FRM frm = new FRM(fs, pack, Height, Width, lastBitmap); listFrames.Add(frm); lastBitmap = frm.bitmap; } //-- string filemtc = FileName.Replace(".anm", "m_.mtc"); if (File.Exists(filemtc)) { mtc = new MTC(new GTFS(filemtc)); Console.WriteLine(); } }
public override void Open(OpenFileDialog openFileDialog, bool export = false, bool useGTFSView = false) { openFileDialog.FileName = ""; openFileDialog.Filter = "All Hotel Dusk|*.anm;*.frm;*.wpf;*.bin;*.txt;*.dtx|" + "All Files (*.*)|*.*"; DialogResult res = openFileDialog.ShowDialog(); if (res == DialogResult.OK) { string[] filenameParts = openFileDialog.SafeFileName.Split('.'); Array.Reverse(filenameParts); if (filenameParts[0].ToUpper() == "FRM") { GTFS fs = new GTFS(openFileDialog.FileName); FRM frm = new FRM(fs); new FormImage(frm.bitmap).Show(); } else if (filenameParts[0].ToUpper() == "ANM") { GTFS fs = new GTFS(openFileDialog.FileName); ANM anm = new ANM(fs); new FormImageAnimated(anm.BitmapsBlended()).Show(); } else if (filenameParts[0].ToUpper() == "WPF") { WPF.Open(openFileDialog); } else if (filenameParts[0].ToUpper() == "WPFBIN" || filenameParts[0].ToUpper() == "BIN") { GTFS fs = new GTFS(openFileDialog.FileName); byte[] magic = GT.ReadBytes(fs, 4, false); fs.Position = 0; if (magic.SequenceEqual(LRIM.Magic)) { LRIM lrim = new LRIM(fs); } else { WPFBIN wpfbin = new WPFBIN(fs); new FormImage(wpfbin.bitmap).Show(); } } else if (filenameParts[0].ToUpper() == "DTX") { GTFS fs = new GTFS(openFileDialog.FileName); WPFBIN wpfbin = new WPFBIN(fs); new FormImage(wpfbin.bitmap).Show(); //GTFS compressed = new GTFS(openFileDialog.FileName); //GTFS decompressed = Decompress.ToGTFS(compressed); //decompressed.WriteBytesToFile("GT-KH-DecompDTX.gtbin"); } else if (filenameParts[0].ToUpper() == "TXT") { GTFS compressed = new GTFS(openFileDialog.FileName); GTFS decompressed = Decompress.ToGTFS(compressed); //decompressed.WriteBytesToFile("GT-KH-DecompTXT.gtbin"); byte[] test = GT.ReadBytes(decompressed, 4, false); decompressed.Position = 0; if (test[0] == 0 || test[1] == 0 || test[2] == 0 || test[3] == 3) { int total = GT.ReadInt32(decompressed, 4, false); for (int i = 0; i < total; i++) { int offset = GT.ReadInt32(decompressed, 4, false); } long baseOffset = decompressed.Position; string input = GT.ReadASCII(decompressed, (int)(decompressed.Length - 1 - baseOffset), false); input = input.Replace((char)0x00, (char)0x20); new FormText(input).Show(); } else { string input = GT.ReadASCII(decompressed, decompressed.Length - 1, false); input = input.Replace("\n", "\r\n"); new FormText(input).Show(); } } else { MessageBox.Show("Unexpected file extension: " + filenameParts[0]); } } }
public WPFBIN(GTFS fs) { int header = GT.ReadInt32(fs, 4, false); if (header == 0) { fs.Seek(16, SeekOrigin.Begin); } else if (header == 14302482) { //123DDA00 fs.Seek(32, SeekOrigin.Begin); } else if (header == 31079698) { //123DDA01 fs = Decompress.ToGTFS(fs); //fs.WriteBytesToFile("GT-KH-Decomp.gtbin"); header = GT.ReadInt32(fs, 4, false); if (header == 0) { fs.Seek(16, SeekOrigin.Begin); } else { Console.WriteLine(); } } else { throw new Exception(); } bool flip = false; int height = GT.ReadUInt16(fs, 2, flip); int width = GT.ReadUInt16(fs, 2, flip); int heightConfirm = GT.ReadUInt16(fs, 2, flip); int widthConfirm = GT.ReadUInt16(fs, 2, flip); int four = GT.ReadUInt16(fs, 2, flip); if (height != heightConfirm || width != widthConfirm) { throw new Exception(); } //if (four != 4) //Console.WriteLine("Wasn't 4, may be a problem?"); int paletteLen = GT.ReadUInt16(fs, 2, flip); int thirtytwo = GT.ReadUInt16(fs, 4, flip); if (thirtytwo != 32) { throw new Exception(); } int headerLen = (int)fs.Position; paletteLen = paletteLen * 2; long offsetStart = headerLen + paletteLen; //560 long offsetLast; fs.Position = offsetStart; if (width <= 0 || height <= 0) { throw new Exception(); } bitmap = new Bitmap(width, height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int look = fs.ReadByte(); offsetLast = fs.Position; fs.Seek(look * 2 + headerLen, SeekOrigin.Begin); //+48 for header byte left = (byte)fs.ReadByte(); byte right = (byte)fs.ReadByte(); //ushort palette = (ushort)(left | right << 8); ushort palette = (ushort)(right | left << 8); bitmap.SetPixel(x, height - y - 1, FRM.Palette2Color(palette)); //bmp.SetPixel(x, y, Color.FromArgb(look, look, look)); fs.Seek(offsetLast, SeekOrigin.Begin); } } }