public ArkTribeProfile(string pathname, ArkWorld world) { //Set values linkedWorld = world; //Open inline file var indes = new Deserializer.Inline.InlineFileDeserializer(); source = indes.ReadInlineFile(pathname); //Grab tribe data struct. var tribeData = (InlineStructProperty)source.props[0]; tribeDataStruct = (InlineStructProperty.ArkStructInlineProps)tribeData.data; //Grab data InlineProperty temp; temp = GetPropertyByName("TribeName"); if (temp != null) { tribeName = ((InlineStrProperty)temp).value; } temp = GetPropertyByName("OwnerPlayerDataID"); if (temp != null) { tribeOwnerId = ((InlineUInt32Property)temp).value; } temp = GetPropertyByName("TribeID"); if (temp != null) { tribeId = ((InlineIntProperty)temp).value; } }
public void EnsureThat_InlineFile_Tag_MatchesClassName() { var sut = new InlineFile(TestEnvironment.GetMockedLog()); const string expected = nameof(InlineFile); Assert.AreEqual(expected, sut.Tag); }
public void EnsureThat_InlineFile_ReturnsCorrectString() { var sut = new InlineFile(TestEnvironment.GetMockedLog()); var arguments = new Arguments(new Dictionary <string, string> { { "File", TestEnvironment.GetFile("TestFile.txt") } }); var result = sut.Generate(arguments); Assert.AreEqual("Test", result); }
public Image3D(InlineFile f, bool color0, int width, int height, int format, long offset2) { this.f = f; this.color0Transp = color0; this.color0 = color0; this.width = width; this.height = height; this.format = format; offset = offset2; f.beginEdit(this); data = f.getContents(); }
public Image3Dformat5(InlineFile f, InlineFile f5, int width, int height) { this.f = f; this.f5 = f5; f.beginEdit(this); f5.beginEdit(this); this.width = width; this.height = height; offset = f.fileBegin; offset5 = f5.fileBegin; fdata = f.getContents(); f5data = f5.getContents(); format = 5; }
private void WriteROMIcon() { const int ImageSize = 512; const int PaletteSize = 32; // Virtual banner file used in NSMBe simplifies this a lot var banner_f = NSMBeROM.getLevelFile("banner"); var image_f = new InlineFile(banner_f, PaletteSize, ImageSize, banner_f.name); var palette_f = new InlineFile(banner_f, ImageSize + PaletteSize, PaletteSize, banner_f.name); var image = new Image2D(image_f, 32, true, false); var palette = new FilePalette(palette_f); image.replaceImgAndPal(Icon, palette); Array.Copy(image.getData(), ROM.Banner.Banner.Image, ImageSize); Array.Copy(palette.getData(), ROM.Banner.Banner.Pltt, PaletteSize); }
public static void gotSection(File f, int offs, int size) { uint magic = f.getUintAt(offs); if (magic == 0x504C5454) //PLTT { new PaletteViewer(new InlineFile(f, offs + 0x18, size - 0x18, f.name)).Show(); } else if (magic == 0x43484152) //CHAR { LevelChooser.showImgMgr(); int tileWidth = f.getUshortAt(offs + 0xA); if (tileWidth == 0xFFFF) { tileWidth = 8; } LevelChooser.imgMgr.m.addImage(new Image2D(new InlineFile(f, offs + 0x20, size - 0x20, f.name), 8 * tileWidth, true, false)); } else if (magic == 0x5343524E) //SCRN { if (LevelChooser.imgMgr == null) { return; } Image2D img = LevelChooser.imgMgr.m.getSelectedImage(); Palette[] pals = LevelChooser.imgMgr.m.getPalettes(); if (img == null) { return; } if (pals == null) { return; } if (pals.Length == 0) { return; } InlineFile ff = new InlineFile(f, offs + 0x14, size - 0x14, f.name); Tilemap t = new Tilemap(ff, 32, img, pals, 0, 0); new TilemapEditorWindow(t).Show(); } else { Console.WriteLine(String.Format("Unknown magic: {0:X8}", magic)); } }
private void addPalette(int i) { int palSize = 256; if (is4bpp.Checked) { palSize = 16; } int palOffs = i * palSize; int palLen = palSize; if (palOffs + palLen > pal.Length) { palLen = pal.Length - palOffs; } File ifl = new InlineFile(f, palOffs * 2, palLen * 2, f.name + " - " + i); LevelChooser.showImgMgr(); LevelChooser.imgMgr.m.addPalette(new FilePalette(ifl)); }
public NSBTX(File f) { this.f = f; data = f.getContents(); str = new ByteArrayInputStream(data); bool LZd = false; if (str.readUInt() == 0x37375A4C) //LZ77 { byte[] ndata = new byte[data.Length - 4]; Array.Copy(data, 4, ndata, 0, ndata.Length); data = ROM.LZ77_Decompress(ndata); str = new ByteArrayInputStream(data); LZd = true; } //look for TEX0 block //ugly, but i'm lazy to implement it properly. bool found = false; int blockStart = 0; while (str.lengthAvailable(4)) { uint v = str.readUInt(); if (v == 0x30584554) // "TEX0" { str.setOrigin(str.getPos() - 4); blockStart = (int)(str.getPos() - 4); found = true; startoffset = (int)str.getPos() - 4; break; } // else // str.skipback(3); //just in case its not word-aligned } str.seek(0); if (!found) { textures = new PalettedImage[0]; palettes = new PaletteDef[0]; return; } Console.Out.WriteLine("\n"); //Read stuff str.seek(0x14); texDataOffset = str.readInt() + blockStart; Console.Out.WriteLine("Texdata " + texDataOffset.ToString("X8")); str.seek(0x24); f5texDataOffset = str.readInt() + blockStart; Console.Out.WriteLine("f5Texdata " + f5texDataOffset.ToString("X8")); f5dataOffset = str.readInt() + blockStart; Console.Out.WriteLine("f5data " + f5dataOffset.ToString("X8")); str.seek(0x30); palDataSize = str.readInt() * 8; Console.Out.WriteLine("paldata size " + palDataSize.ToString("X8")); str.seek(0x34); palDefOffset = str.readInt(); Console.Out.WriteLine("paldef " + palDefOffset.ToString("X8")); palDataOffset = str.readInt(); Console.Out.WriteLine("paldata " + palDataOffset.ToString("X8")); //Read texture definitions str.seek(0x3D); textures = new PalettedImage[str.readByte()]; str.skip((uint)(0xE + textures.Length * 4)); //ImageManagerWindow mgr = new ImageManagerWindow(); //mgr.Text = f.name + " - Texture Editor"; bool hasFormat5 = false; for (int i = 0; i < textures.Length; i++) { int offset = 8 * str.readUShort(); ushort param = str.readUShort(); int format = (param >> 10) & 7; if (format == 5) { offset += f5texDataOffset; } else { offset += texDataOffset; } int width = 8 << ((param >> 4) & 7); int height = 8 << ((param >> 7) & 7); bool color0 = ((param >> 13) & 1) != 0; str.readUInt(); // unused int size = width * height * Image3D.bpps[format] / 8; Console.Out.WriteLine(offset.ToString("X8") + " " + format + " " + width + "x" + height + " " + color0 + " LZ" + LZd); InlineFile mainfile = new InlineFile(f, offset, size, Image3D.formatNames[format], null, LZd ? InlineFile.CompressionType.LZWithHeaderComp : InlineFile.CompressionType.NoComp); if (format == 5) { hasFormat5 = true; int f5size = (width * height) / 16 * 2; InlineFile f5file = new InlineFile(f, f5dataOffset, f5size, Image3D.formatNames[format], null, LZd ? InlineFile.CompressionType.LZWithHeaderComp : InlineFile.CompressionType.NoComp); f5dataOffset += f5size; textures[i] = new Image3Dformat5(mainfile, f5file, width, height); } else { textures[i] = new Image3D(mainfile, color0, width, height, format, offset); } // textures[i] = new Texture(this, color0, width, height, format, offset, ""); /* if (format == 5) * { * textures[i].f5DataOffset = f5dataOffset; * f5dataOffset += (uint)(width * height) / 16 * 2; * }*/ } for (int i = 0; i < textures.Length; i++) { if (textures[i] == null) { continue; } textures[i].name = str.ReadString(16); //mgr.m.addImage(textures[i]); } //Read palette definitions str.seek(palDefOffset + 1); palettes = new PaletteDef[str.readByte()]; str.skip((uint)(0xE + palettes.Length * 4)); for (int i = 0; i < palettes.Length; i++) { int offset = 8 * str.readUShort() + palDataOffset + blockStart; str.readUShort(); palettes[i] = new PaletteDef(); palettes[i].offs = offset; } Array.Sort(palettes); for (int i = 0; i < palettes.Length; i++) { palettes[i].name = str.ReadString(16); if (i != palettes.Length - 1) { palettes[i].size = palettes[i + 1].offs - palettes[i].offs; } } palettes[palettes.Length - 1].size = blockStart + palDataOffset + palDataSize - palettes[palettes.Length - 1].offs; for (int i = 0; i < palettes.Length; i++) { if (hasFormat5) { FilePalette pa = new FilePalette(new InlineFile(f, palettes[i].offs, palettes[i].size, palettes[i].name, null, LZd ? InlineFile.CompressionType.LZWithHeaderComp : InlineFile.CompressionType.NoComp)); pal.Add((NSMBe4.Palette)pa); //mgr.m.addPalette(pa); } else { int extrapalcount = (palettes[i].size) / 512; for (int j = 0; j < extrapalcount; j++) { FilePalette pa = new FilePalette(new InlineFile(f, palettes[i].offs + j * 512, 512, palettes[i].name + ":" + j, null, LZd ? InlineFile.CompressionType.LZWithHeaderComp : InlineFile.CompressionType.NoComp)); pal.Add((NSMBe4.Palette)pa); //mgr.m.addPalette(pa); } int lastsize = palettes[i].size % 512; if (lastsize != 0) { FilePalette pa = new FilePalette(new InlineFile(f, palettes[i].offs + extrapalcount * 512, lastsize, palettes[i].name + ":" + extrapalcount, null, LZd ? InlineFile.CompressionType.LZWithHeaderComp : InlineFile.CompressionType.NoComp)); pal.Add((NSMBe4.Palette)pa); //mgr.m.addPalette(pa); } } } //mgr.Show(); // new ImagePreviewer(textures[0].render(palettes[0])).Show(); }
ushort unk; //Let's save it just in case. public Bncd(File f) { ByteArrayInputStream inp = new ByteArrayInputStream(f.getContents()); inp.readInt(); //Magic; unk = inp.readUShort(); ushort entryCount = inp.readUShort(); uint entriesOffset = inp.readUInt(); uint subEntriesOffset = inp.readUInt(); uint dataOffset = inp.readUInt(); uint dataSize = inp.readUInt(); bool BPP4 = true; //*/BPP4 = false; inp.seek(entriesOffset); //Stores tilenum, tilecount to imageid Dictionary <uint, int> imagesDict = new Dictionary <uint, int> (); for (uint entryId = 0; entryId < entryCount; entryId++) { BncdEntry e = new BncdEntry(); e.width = inp.readByte(); e.height = inp.readByte(); uint subEntryIdx = inp.readUShort(); uint subEntryCt = inp.readUShort(); inp.savePos(); inp.seek(subEntriesOffset + subEntryIdx * 12); for (int i = 0; i < subEntryCt; i++) { BncdSubEntry se = new BncdSubEntry(); e.subEntries.Add(se); se.oamAttr0 = inp.readUShort(); se.oamAttr1 = inp.readUShort(); se.unk = inp.readUInt(); se.tileNumber = inp.readUShort(); se.tileCount = inp.readUShort(); //*/se.tileCount *= 2; uint imageCode = (uint)((se.tileNumber << 16) | se.tileCount); int imageId = imagesDict.Count; if (imagesDict.ContainsKey(imageCode)) { imageId = imagesDict[imageCode]; } else { imagesDict[imageCode] = imageId; BncdImage img = new BncdImage(); images.Add(img); img.tileNumber = se.tileNumber; img.tileCount = se.tileCount; int oamShape = se.oamAttr0 >> 14; int oamSize = se.oamAttr1 >> 14; img.tileWidth = widths[oamSize, oamShape]; } se.imageId = imageId; } inp.loadPos(); } LevelChooser.showImgMgr(); int tileLen = 8 * 8 / 2; foreach (BncdImage img in images) { File imgFile = new InlineFile(f, (int)dataOffset + img.tileNumber * tileLen, img.tileCount * tileLen, f.name); LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 8 * img.tileWidth, BPP4)); } }
public NSBTX(File f) { this.f = f; data = f.getContents(); str = new ByteArrayInputStream(data); //look for TEX0 block //ugly, but i'm lazy to implement it properly. bool found = false; int blockStart = 0; while (str.lengthAvailable(4)) { uint v = str.readUInt(); if (v == 0x30584554) // "TEX0" { str.setOrigin(str.getPos() - 4); blockStart = (int)(str.getPos() - 4); found = true; break; } // else // str.skipback(3); //just in case its not word-aligned } str.seek(0); if (!found) { textures = new PalettedImage[0]; palettes = new PaletteDef[0]; MessageBox.Show("This model file doesn't contain any valid texture data.", "NSMBe5.3", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Console.Out.WriteLine("\n"); //Read stuff str.seek(0x14); texDataOffset = str.readInt() + blockStart; Console.Out.WriteLine("Texdata " + texDataOffset.ToString("X8")); str.seek(0x24); f5texDataOffset = str.readInt() + blockStart; Console.Out.WriteLine("f5Texdata " + f5texDataOffset.ToString("X8")); f5dataOffset = str.readInt() + blockStart; Console.Out.WriteLine("f5data " + f5dataOffset.ToString("X8")); str.seek(0x30); palDataSize = str.readInt() * 8; Console.Out.WriteLine("paldata size " + palDataSize.ToString("X8")); str.seek(0x34); palDefOffset = str.readInt(); Console.Out.WriteLine("paldef " + palDefOffset.ToString("X8")); palDataOffset = str.readInt(); Console.Out.WriteLine("paldata " + palDataOffset.ToString("X8")); //Read texture definitions str.seek(0x3D); textures = new PalettedImage[str.readByte()]; str.skip((uint)(0xE + textures.Length * 4)); ImageManagerWindow mgr = new ImageManagerWindow(); mgr.Text = string.Format(LanguageManager.Get("ImageManager", "textureTitle"), f.name); bool hasFormat5 = false; for (int i = 0; i < textures.Length; i++) { int offset = 8 * str.readUShort(); ushort param = str.readUShort(); int format = (param >> 10) & 7; if (format == 5) { offset += f5texDataOffset; } else { offset += texDataOffset; } int width = 8 << ((param >> 4) & 7); int height = 8 << ((param >> 7) & 7); bool color0 = ((param >> 13) & 1) != 0; str.readUInt(); // unused int size = width * height * Image3D.bpps[format] / 8; //Console.Out.WriteLine(offset.ToString("X8") + " " + format + " " + width + "x" + height + " " + color0 + " LZ"); InlineFile mainfile = new InlineFile(f, offset, size, Image3D.formatNames[format]); if (format == 5) { hasFormat5 = true; int f5size = (width * height) / 16 * 2; InlineFile f5file = new InlineFile(f, f5dataOffset, f5size, Image3D.formatNames[format]); f5dataOffset += f5size; textures[i] = new Image3Dformat5(mainfile, f5file, width, height); } else { textures[i] = new Image3D(mainfile, color0, width, height, format); } // textures[i] = new Texture(this, color0, width, height, format, offset, ""); /* if (format == 5) * { * textures[i].f5DataOffset = f5dataOffset; * f5dataOffset += (uint)(width * height) / 16 * 2; * }*/ } for (int i = 0; i < textures.Length; i++) { if (textures[i] == null) { continue; } textures[i].name = str.ReadString(16); mgr.m.addImage(textures[i]); } //Read palette definitions str.seek(palDefOffset + 1); palettes = new PaletteDef[str.readByte()]; str.skip((uint)(0xE + palettes.Length * 4)); for (int i = 0; i < palettes.Length; i++) { int offset = 8 * str.readUShort() + palDataOffset + blockStart; str.readUShort(); palettes[i] = new PaletteDef(); palettes[i].offs = offset; } Array.Sort(palettes); for (int i = 0; i < palettes.Length; i++) { palettes[i].name = str.ReadString(16); if (i != palettes.Length - 1) { palettes[i].size = palettes[i + 1].offs - palettes[i].offs; } } palettes[palettes.Length - 1].size = blockStart + palDataOffset + palDataSize - palettes[palettes.Length - 1].offs; for (int i = 0; i < palettes.Length; i++) { if (hasFormat5) { FilePalette pa = new FilePalette(new InlineFile(f, palettes[i].offs, palettes[i].size, palettes[i].name)); mgr.m.addPalette(pa); } else { int extrapalcount = (palettes[i].size) / 512; for (int j = 0; j < extrapalcount; j++) { FilePalette pa = new FilePalette(new InlineFile(f, palettes[i].offs + j * 512, 512, palettes[i].name + ":" + j)); mgr.m.addPalette(pa); } int lastsize = palettes[i].size % 512; if (lastsize != 0) { FilePalette pa = new FilePalette(new InlineFile(f, palettes[i].offs + extrapalcount * 512, lastsize, palettes[i].name + ":" + extrapalcount)); mgr.m.addPalette(pa); } } } mgr.Show(); // new ImagePreviewer(textures[0].render(palettes[0])).Show(); }