public wnd1(EndianBinaryReader er) : base(er) { long basepos = er.BaseStream.Position - 0x4C; InflationLeft = er.ReadUInt16() / 16f; InflationRight = er.ReadUInt16() / 16f; InflationTop = er.ReadUInt16() / 16f; InflationBottom = er.ReadUInt16() / 16f; FrameSizeLeft = er.ReadUInt16(); FrameSizeRight = er.ReadUInt16(); FrameSizeTop = er.ReadUInt16(); FrameSizeBottom = er.ReadUInt16(); NrFrames = er.ReadByte(); byte tmp = er.ReadByte(); UseLTMaterial = (tmp & 1) == 1; UseVtxColorForAllWindow = (tmp & 2) == 2; Kind = (WindowKind)((tmp >> 2) & 3); DontDrawContent = (tmp & 8) == 16; Padding = er.ReadUInt16(); ContentOffset = er.ReadUInt32(); FrameOffsetTableOffset = er.ReadUInt32(); er.BaseStream.Position = basepos + ContentOffset; Content = new WindowContent(er); er.BaseStream.Position = basepos + FrameOffsetTableOffset; WindowFrameOffsets = er.ReadUInt32s(NrFrames); WindowFrames = new WindowFrame[NrFrames]; for (int i = 0; i < NrFrames; i++) { er.BaseStream.Position = basepos + WindowFrameOffsets[i]; WindowFrames[i] = new WindowFrame(er); } er.BaseStream.Position = basepos + SectionSize; }
public CANM(EndianBinaryReader er) { Signature = er.ReadString(Encoding.ASCII, 4); if (Signature != "CANM") throw new SignatureNotCorrectException(Signature, "CANM", er.BaseStream.Position); Revision = er.ReadUInt32(); NameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32(); TargetAnimationGroupNameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32(); LoopMode = er.ReadUInt32(); FrameSize = er.ReadSingle(); NrMemberAnimations = er.ReadUInt32(); MemberAnimationDictOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32(); NrUserDataEntries = er.ReadUInt32(); UserDataOffset = er.ReadUInt32(); long curpos = er.BaseStream.Position; er.BaseStream.Position = NameOffset; Name = er.ReadStringNT(Encoding.ASCII); er.BaseStream.Position = TargetAnimationGroupNameOffset; TargetAnimationGroupName = er.ReadStringNT(Encoding.ASCII); er.BaseStream.Position = MemberAnimationDictOffset; MemberAnimationDictionary = new DICT(er); MemberAnimations = new MemberAnimationData[NrMemberAnimations]; for (int i = 0; i < NrMemberAnimations; i++) { er.BaseStream.Position = MemberAnimationDictionary[i].DataOffset; MemberAnimations[i] = new MemberAnimationData(er); } er.BaseStream.Position = curpos; }
public DICT(EndianBinaryReader er) { Signature = er.ReadString(Encoding.ASCII, 4); if (Signature != "DICT") throw new SignatureNotCorrectException(Signature, "DICT", er.BaseStream.Position); SectionSize = er.ReadUInt32(); NrEntries = er.ReadUInt32(); RootNode = new Node(er); Entries = new List<Node>();// new Node[NrEntries]; for (int i = 0; i < NrEntries; i++) { Entries.Add(new Node(er)); } }
public TEX0(EndianBinaryReader er) { long basepos = er.BaseStream.Position; Signature = er.ReadString(Encoding.ASCII, 4); if (Signature != "TEX0") throw new SignatureNotCorrectException(Signature, "TEX0", er.BaseStream.Position - 4); SectionSize = er.ReadUInt32(); TexInfo = new texInfo(er); Tex4x4Info = new tex4x4Info(er); PlttInfo = new plttInfo(er); dictTex = new Dictionary<DictTexData>(er); for (int i = 0; i < dictTex.numEntry; i++) { dictTex[i].Value.ReadData(er, TexInfo.ofsTex, Tex4x4Info.ofsTex, Tex4x4Info.ofsTexPlttIdx, basepos); } dictPltt = new Dictionary<DictPlttData>(er); List<UInt32> Offset = new List<uint>(); for (int i = 0; i < dictPltt.numEntry; i++) { Offset.Add(dictPltt[i].Value.offset); } Offset = Offset.Distinct().ToList(); Offset.Sort(); for (int i = 0; i < dictPltt.numEntry; i++) { int idx = Offset.IndexOf(dictPltt[i].Value.offset); if (idx == Offset.Count - 1) { dictPltt[i].Value.ReadData(er, PlttInfo.ofsPlttData, (uint)er.BaseStream.Length - (Offset[idx] + PlttInfo.ofsPlttData + (uint)basepos), basepos); } else { dictPltt[i].Value.ReadData(er, PlttInfo.ofsPlttData, Offset[idx + 1] - Offset[idx], basepos); } } }
public mat1(EndianBinaryReader er) { long startpos = er.BaseStream.Position; Signature = er.ReadString(Encoding.ASCII, 4); if (Signature != "mat1") throw new SignatureNotCorrectException(Signature, "mat1", er.BaseStream.Position - 4); SectionSize = er.ReadUInt32(); NrMaterials = er.ReadUInt32(); MaterialEntryOffsets = er.ReadUInt32s((int)NrMaterials); Materials = new MaterialEntry[NrMaterials]; for (int i = 0; i < NrMaterials; i++) { er.BaseStream.Position = startpos + MaterialEntryOffsets[i]; Materials[i] = new MaterialEntry(er); } er.BaseStream.Position = startpos + SectionSize; }
public ImageTextureCtr(EndianBinaryReader er) : base(er) { TextureImageOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32(); long curpos = er.BaseStream.Position; er.BaseStream.Position = TextureImageOffset; TextureImage = new PixelBasedImageCtr(er); er.BaseStream.Position = curpos; }
public static BoundingVolume FromStream(EndianBinaryReader er) { uint type = er.ReadUInt32(); er.BaseStream.Position -= 4; switch (type) { case 0x80000000: return new OrientedBoundingBox(er); } return new BoundingVolume(er); }
public MaterialEntry(EndianBinaryReader er) { Name = er.ReadString(Encoding.ASCII, 20).Replace("\0", ""); BufferColor = er.ReadColor8(); ConstColors = new Color[6]; ConstColors[0] = er.ReadColor8(); ConstColors[1] = er.ReadColor8(); ConstColors[2] = er.ReadColor8(); ConstColors[3] = er.ReadColor8(); ConstColors[4] = er.ReadColor8(); ConstColors[5] = er.ReadColor8(); Flags = er.ReadUInt32(); //Material Flag: // 0-1: Nr texMap // 2-3: Nr texMatrix // 4-5: Nr texCoordGen // 6-8: Nr tevStage // 9: Has alphaCompare // 10: Has blendMode // 11: Use Texture Only // 12: Separate Blend Mode // 14: Has Indirect Parameter //15-16: Nr projectionTexGenParameter // 17: Has Font Shadow Parameter TexMaps = new TexMap[Flags & 3]; for (int i = 0; i < (Flags & 3); i++) { TexMaps[i] = new TexMap(er); } TexMatrices = new TexMatrix[(Flags >> 2) & 3]; for (int i = 0; i < ((Flags >> 2) & 3); i++) { TexMatrices[i] = new TexMatrix(er); } TexCoordGens = new TexCoordGen[(Flags >> 4) & 3]; for (int i = 0; i < ((Flags >> 4) & 3); i++) { TexCoordGens[i] = new TexCoordGen(er); } TevStages = new TevStage[(Flags >> 6) & 7]; for (int i = 0; i < ((Flags >> 6) & 7); i++) { TevStages[i] = new TevStage(er); } if (((Flags >> 9) & 1) == 1) AlphaTest = new AlphaCompare(er); if (((Flags >> 10) & 1) == 1) ColorBlendMode = new BlendMode(er); if (((Flags >> 12) & 1) == 1) AlphaBlendMode = new BlendMode(er); //Some more things }
public MDL0(EndianBinaryReader er) { long basepos = er.BaseStream.Position; Signature = er.ReadString(Encoding.ASCII, 4); if (Signature != "MDL0") throw new SignatureNotCorrectException(Signature, "MDL0", er.BaseStream.Position - 4); SectionSize = er.ReadUInt32(); dict = new Dictionary<MDL0Data>(er); models = new Model[dict.numEntry]; long curpos = er.BaseStream.Position; for (int i = 0; i < dict.numEntry; i++) { er.BaseStream.Position = dict[i].Value.Offset + basepos;//er.GetMarker("ModelSet"); models[i] = new Model(er); } }
public void decode(EndianBinaryReader binReader) { m_ushort = binReader.ReadUInt16(); m_int = binReader.ReadInt32(); m_uint = binReader.ReadUInt32(); m_Boolean = binReader.ReadBoolean(); m_Binary = binReader.ReadBytes(binReader.ReadInt32()); m_string = binReader.ReadUTF(); }
public pan1(EndianBinaryReader er) { Signature = er.ReadString(Encoding.ASCII, 4); if (Signature != "pan1" && Signature != "pic1" && Signature != "txt1" && Signature != "bnd1" && Signature != "wnd1" && Signature != "prt1") throw new SignatureNotCorrectException(Signature, "pan1, pic1, txt1, bnd1, wnd1, prt1", er.BaseStream.Position - 4); SectionSize = er.ReadUInt32(); Flags = (PaneFlags)er.ReadByte(); Origin = er.ReadByte(); Alpha = er.ReadByte(); MagnifyFlags = (PaneMagnifyFlags)er.ReadByte(); Name = er.ReadString(Encoding.ASCII, 24).Replace("\0", ""); Translation = er.ReadVector3(); Rotation = er.ReadVector3(); Scale = er.ReadVector2(); Size = er.ReadVector2(); }
public txt1(EndianBinaryReader er) : base(er) { long baseoffset = er.BaseStream.Position - 0x4C; NrCharacters = er.ReadUInt16(); NrCharacters2 = er.ReadUInt16(); MaterialId = er.ReadUInt16(); FontId = er.ReadUInt16(); PositionType = er.ReadByte(); TextAlignment = er.ReadByte(); TextFlags = er.ReadByte(); Padding = er.ReadByte(); StringOffset = er.ReadUInt32(); TopColor = er.ReadColor8(); BottomColor = er.ReadColor8(); FontSize = er.ReadVector2(); CharSize = er.ReadSingle(); LineSize = er.ReadSingle(); er.BaseStream.Position = baseoffset + StringOffset; Text = er.ReadStringNT(Encoding.Unicode); er.BaseStream.Position = baseoffset + SectionSize; }
public override void Read(EndianBinaryReader er) { texImageParam = er.ReadUInt32(); Offset = (texImageParam & 0xFFFF) << 3; S = (UInt16)(8 << (int)((texImageParam & 0x700000) >> 20)); T = (UInt16)(8 << (int)((texImageParam & 0x3800000) >> 23)); Fmt = (Textures.ImageFormat)((texImageParam & 0x1C000000) >> 26); TransparentColor = ((texImageParam >> 29) & 1) == 1; extraParam = er.ReadUInt32(); }
public Material(EndianBinaryReader er) { itemTag = er.ReadUInt16(); size = er.ReadUInt16(); diffAmb = er.ReadUInt32(); specEmi = er.ReadUInt32(); polyAttr = er.ReadUInt32(); polyAttrMask = er.ReadUInt32(); texImageParam = er.ReadUInt32(); texImageParamMask = er.ReadUInt32(); texPlttBase = er.ReadUInt16(); flag = (NNS_G3D_MATFLAG)er.ReadUInt16(); origWidth = er.ReadUInt16(); origHeight = er.ReadUInt16(); magW = er.ReadFx32(); magH = er.ReadFx32(); if ((flag & NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_SCALEONE) == 0) { scaleS = er.ReadFx32(); scaleT = er.ReadFx32(); } if ((flag & NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_ROTZERO) == 0) { rotSin = er.ReadFx16(); rotCos = er.ReadFx16(); } if ((flag & NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_TRANSZERO) == 0) { transS = er.ReadFx32(); transT = er.ReadFx32(); } if ((flag & NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_EFFECTMTX) == NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_EFFECTMTX) { effectMtx = er.ReadFx32s(16); } }
public BoundingVolume(EndianBinaryReader er) { Type = er.ReadUInt32(); }
public PixelBasedImageCtr(EndianBinaryReader er) { Height = er.ReadUInt32(); Width = er.ReadUInt32(); DataSize = er.ReadUInt32(); DataOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32(); DynamicAllocator = er.ReadUInt32(); BitsPerPixel = er.ReadUInt32(); LocationAddress = er.ReadUInt32(); MemoryAddress = er.ReadUInt32(); long curpos = er.BaseStream.Position; er.BaseStream.Position = DataOffset; Data = er.ReadBytes((int)DataSize); er.BaseStream.Position = curpos; }
public static TXOB FromStream(EndianBinaryReader er) { uint type = er.ReadUInt32(); er.BaseStream.Position -= 4; //Image Texture = 0x20000011 //Cube Texture = 0x20000009 //Reference Texture = 0x20000004 //Procedural Texture = 0x20000002 //Shadow Texture = 0x20000021 switch (type) { case 0x20000004://reference texture return new ReferenceTexture(er); case 0x20000011: return new ImageTextureCtr(er); } return new TXOB(er); }
public AlphaCompare(EndianBinaryReader er) { AlphaFunc = (AlphaFunction)er.ReadUInt32(); Reference = er.ReadSingle(); }
public texInfo(EndianBinaryReader er) { vramKey = er.ReadUInt32(); sizeTex = (UInt32)(er.ReadUInt16() << 3); ofsDict = er.ReadUInt16(); flag = er.ReadUInt16(); er.ReadBytes(2);//PADDING(2 bytes); ofsTex = er.ReadUInt32(); }
public ReferenceTexture(EndianBinaryReader er) : base(er) { LinkedTextureNameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32(); LinkedTextureOffset = er.ReadUInt32(); if (LinkedTextureOffset != 0) LinkedTextureOffset += (UInt32)er.BaseStream.Position - 4; long curpos = er.BaseStream.Position; er.BaseStream.Position = LinkedTextureNameOffset; LinkedTextureName = er.ReadStringNT(Encoding.ASCII); er.BaseStream.Position = curpos; }
public PixelBasedTexture(EndianBinaryReader er) : base(er) { Height = er.ReadUInt32(); Width = er.ReadUInt32(); GLFormat = er.ReadUInt32(); Type = er.ReadUInt32(); NrLevels = er.ReadUInt32(); TextureObject = er.ReadUInt32(); LocationFlag = er.ReadUInt32(); HWFormat = (Textures.ImageFormat)er.ReadUInt32(); }
static void Handle(object client_obj) { string name = Thread.CurrentThread.Name; FileStream[] files = new FileStream[256]; Dictionary<int, FileStream> files_request = new Dictionary<int, FileStream>(); StreamWriter log = null; Dictionary<string, Dictionary<string, byte>> dir_files = new Dictionary<string, Dictionary<string, byte>>(); try { TcpClient client = (TcpClient)client_obj; using (NetworkStream stream = client.GetStream()) { EndianBinaryReader reader = new EndianBinaryReader(stream); EndianBinaryWriter writer = new EndianBinaryWriter(stream); uint[] ids = reader.ReadUInt32s(4); string LocalRootDump = root + "\\" + "dump" + "\\" + ids[0].ToString("X8") + "-" + ids[1].ToString("X8") + "\\"; string LocalRootInject = root + "\\" + "inject" + "\\" + ids[0].ToString("X8") + "-" + ids[1].ToString("X8") + "\\"; if (!ids[0].ToString("X8").Equals("00050000")) { writer.Write(BYTE_NORMAL); throw new Exception("Not interested."); } else { if (!Directory.Exists(LocalRootDump)) { Directory.CreateDirectory(LocalRootDump); } if (!Directory.Exists(LocalRootInject)) { Directory.CreateDirectory(LocalRootInject); } } // Log connection Console.WriteLine(name + " Accepted connection from client " + client.Client.RemoteEndPoint.ToString()); Console.WriteLine(name + " TitleID: " + ids[0].ToString("X8") + "-" + ids[1].ToString("X8")); // Create log file for current thread log = new StreamWriter(logs_root + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "-" + name + "-" + ids[0].ToString("X8") + "-" + ids[1].ToString("X8") + ".txt", true, Encoding.ASCII, 1024*64); log.WriteLine(name + " Accepted connection from client " + client.Client.RemoteEndPoint.ToString()); string title_id = ids[0].ToString("X8") + "-" + ids[1].ToString("X8"); log.WriteLine(name + " TitleID: " + title_id); writer.Write(BYTE_SPECIAL); while (true) { //Log(log, "cmd_byte"); byte cmd_byte = reader.ReadByte(); switch (cmd_byte) { case BYTE_OPEN: { //Log(log, "BYTE_OPEN"); Boolean failed = false; int len_path = reader.ReadInt32(); int len_mode = reader.ReadInt32(); string path = reader.ReadString(Encoding.ASCII, len_path - 1); if (reader.ReadByte() != 0) throw new InvalidDataException(); string mode = reader.ReadString(Encoding.ASCII, len_mode - 1); if (reader.ReadByte() != 0) throw new InvalidDataException(); //Log(log, "old path" + path); //Log(log, "currentID: " + currentPersistentID); if (op_mode == BYTE_MODE_I) path = getRealPathCurrentInject(path, title_id); //Log(log, "new path" + path); if (path.Length == 0) failed = true; if (File.Exists(path) && !failed) { //Log(log, "path exits"); int handle = -1; for (int i = 1; i < files.Length; i++) { if (files[i] == null) { handle = i; break; } } if (handle == -1) { Log(log, name + " Out of file handles!"); writer.Write(BYTE_SPECIAL); writer.Write(-19); writer.Write(0); break; } //Log(log, name + " -> fopen(\"" + path + "\", \"" + mode + "\") = " + handle.ToString()); files[handle] = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); writer.Write(BYTE_SPECIAL); writer.Write(0); writer.Write(handle); break; } //Log(log, "error fopen"); //else on error: writer.Write(BYTE_NORMAL); break; } case BYTE_SETPOS: { //Log(log, "BYTE_SETPOS"); int fd = reader.ReadInt32(); int pos = reader.ReadInt32(); if ((fd & 0x0fff00ff) == 0x0fff00ff) { int handle = (fd >> 8) & 0xff; if (files[handle] == null) { writer.Write(BYTE_SPECIAL); writer.Write(-38); break; } FileStream f = files[handle]; Log(log, "Postion was set to " + pos + "for handle " + handle); f.Position = pos; writer.Write(BYTE_SPECIAL); writer.Write(0); } else { writer.Write(BYTE_NORMAL); } break; } case BYTE_INJECTSTART: { long wiiUpersistentID = (long)reader.ReadUInt32(); int dumpCommon = 0; Boolean injectioncanceled = false; SaveSelectorDialog ofd = new SaveSelectorDialog(title_id, wiiUpersistentID); try { DialogResult result = ofd.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { currentPersistentID = ofd.NewPersistentID; dumpCommon = ofd.DumpCommon; //Console.WriteLine("Injecting " + currentPersistentID.ToString() + " into " + wiiUpersistentID.ToString() + " for title id " + title_id); if (dumpCommon == 1) Console.WriteLine("clean and inject common folder"); if (dumpCommon == 2) Console.WriteLine("inject common folder"); if (dumpCommon > 0 && currentPersistentID == 0) currentPersistentID = COMMON_PERSISTENTID; } else { Console.WriteLine("Injection canceled"); injectioncanceled = true; } } catch (Exception e) { Console.WriteLine("Injection canceled"); injectioncanceled = true; } if (injectioncanceled) { writer.Write(BYTE_NORMAL); } else { writer.Write(BYTE_SPECIAL); } int dumpmask = MASK_NORMAL; if (currentPersistentID != 0 && currentPersistentID != COMMON_PERSISTENTID) dumpmask |= MASK_USER; if (dumpCommon >= 1) { dumpmask |= MASK_COMMON; if(dumpCommon == 2) dumpmask |= MASK_COMMON_CLEAN; } writer.Write(dumpmask); writer.Write(BYTE_SPECIAL); break; } case BYTE_INJECTEND: { currentPersistentID = 0; //close all opened files for (int i = 1; i < files.Length; i++) { if (files[i] != null) { files[i].Close(); files[i] = null; } } writer.Write(BYTE_OK); //Console.WriteLine("InjectionEND"); break; } case BYTE_DUMPSTART: { long wiiUpersistentID = (long)reader.ReadUInt32(); Boolean dumpCommon = false; Boolean dumpUser = false; currentPersistentID = wiiUpersistentID; Boolean dumpcanceled = false; DumpDialog ofd = new DumpDialog(title_id, wiiUpersistentID); try { DialogResult result = ofd.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { dumpUser = ofd.DumpUser; dumpCommon = ofd.DumpCommon; //Console.WriteLine("Injecting " + currentPersistentID.ToString() + " into " + wiiUpersistentID.ToString() + " for title id " + title_id); if (dumpCommon) Console.WriteLine("dumping common data"); if (dumpUser) Console.WriteLine("dumping user data"); } else { Console.WriteLine("dump canceled"); dumpcanceled = true; } } catch (Exception e) { Console.WriteLine("dump canceled"); dumpcanceled = true; } if (dumpcanceled) { writer.Write(BYTE_NORMAL); } else { writer.Write(BYTE_SPECIAL); } int dumpmask = MASK_NORMAL; if (dumpUser) dumpmask |= MASK_USER; if (dumpCommon) { dumpmask |= MASK_COMMON; } writer.Write(dumpmask); writer.Write(BYTE_SPECIAL); break; } case BYTE_DUMPEND: { currentPersistentID = 0; //close all opened files for (int i = 1; i < files.Length; i++) { if (files[i] != null) { files[i].Close(); files[i] = null; } } writer.Write(BYTE_OK); //Console.WriteLine("dumpEND"); break; } case BYTE_READ_DIR: { Boolean failed = false; int len_path = reader.ReadInt32(); string path = reader.ReadString(Encoding.ASCII, len_path-1); if (reader.ReadByte() != 0) throw new InvalidDataException(); int x = 0; //Console.WriteLine("old" + path); if(op_mode == BYTE_MODE_I) path = getRealPathCurrentInject(path, title_id); //Console.WriteLine("new" + path); if(path.Length == 0)failed = true; if (Directory.Exists(path) && !failed) { x = countDirectory(path); if (x > 0) { Dictionary<string, byte> value; if (!dir_files.TryGetValue(path, out value)) { //Console.Write("found no \"" + path + "\" in dic \n"); value = new Dictionary<string, byte>(); string[] fileEntries = Directory.GetFiles(path); foreach (string fn in fileEntries) { string fileName = Path.GetFileName(fn); value.Add(fileName, BYTE_FILE); } string[] subdirectoryEntries = Directory.GetDirectories(path); foreach (string sd in subdirectoryEntries) { string subdirectory = Path.GetFileName(sd); value.Add(subdirectory, BYTE_FOLDER); } dir_files.Add(path, value); //Console.Write("added \"" + path + "\" to dic \n"); } else { //Console.Write("dic for \"" + path + "\" ready \n"); } if (value.Count > 0) { writer.Write(BYTE_OK); //Console.Write("sent ok byte \n"); foreach (var item in value) { //Write writer.Write(item.Value); //Console.Write("type : " + item.Value); writer.Write(item.Key.Length); //Console.Write("length : " + item.Key.Length); writer.Write(item.Key, Encoding.ASCII, true); //Console.Write("filename : " + item.Key); int length = 0; if (item.Value == BYTE_FILE) length = (int)new System.IO.FileInfo(path + "/" + item.Key).Length; writer.Write(length); //Console.Write("filesize : " + length + " \n"); value.Remove(item.Key); //Console.Write("removed from list! " + value.Count + " remaining\n"); break; } writer.Write(BYTE_SPECIAL); // //Console.Write("file sent, wrote special byte \n"); break; } else { dir_files.Remove(path); //Console.Write("removed \"" + path + "\" from dic \n"); } } } writer.Write(BYTE_END); // //Console.Write("list was empty return BYTE_END \n"); //Console.Write("in break \n"); break; } case BYTE_READ: { //Log(log,"BYTE_READ"); int size = reader.ReadInt32(); int fd = reader.ReadInt32(); FileStream f = files[fd]; byte[] buffer = new byte[size]; int sz = (int)f.Length; int rd = 0; //Log(log, "want size:" + size + " for handle: " + fd); writer.Write(BYTE_SPECIAL); rd = f.Read(buffer, 0, buffer.Length); //Log(log,"rd:" + rd); writer.Write(rd); writer.Write(buffer, 0, rd); int offset = (int)f.Position; int progress = (int)(((float)offset / (float)sz) * 100); string strProgress = progress.ToString().PadLeft(3, ' '); string strSize = (sz / 1024).ToString(); string strCurrent = (offset / 1024).ToString().PadLeft(strSize.Length, ' '); Console.Write("\r\t--> {0}% ({1} kB / {2} kB)", strProgress, strCurrent, strSize); //Console.Write("send " + rd ); if (offset == sz) { Console.Write("\n"); log.Write("\r\t--> {0}% ({1} kB / {2} kB)\n", strProgress, strCurrent, strSize); } int ret = -5; if ((ret =reader.ReadByte()) != BYTE_OK) { Console.Write("error, got " + ret + " instead of " + BYTE_OK); //throw new InvalidDataException(); } //Log(log, "break READ"); break; } case BYTE_HANDLE: { //Log(log,"BYTE_HANDLE"); // Read buffer params : fd, path length, path string int fd = reader.ReadInt32(); int len_path = reader.ReadInt32(); string path = reader.ReadString(Encoding.ASCII, len_path - 1); if (reader.ReadByte() != 0) throw new InvalidDataException(); //Console.WriteLine("old " + path); if (op_mode == BYTE_MODE_D) path = getRealPathCurrentDump(path, title_id); //Console.WriteLine("new " + path); if (path.Length == 0) { writer.Write(BYTE_SPECIAL); break; } if (!Directory.Exists(path)) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } // Add new file for incoming data files_request.Add(fd, new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)); // Send response if (fastmode) { writer.Write(BYTE_REQUEST); } else { writer.Write(BYTE_REQUEST_SLOW); } LogNoLine(log, "-> ["); // Send response writer.Write(BYTE_SPECIAL); break; } case BYTE_DUMP: { //Log(log,"BYTE_DUMP"); // Read buffer params : fd, size, file data int fd = reader.ReadInt32(); int sz = reader.ReadInt32(); byte[] buffer = new byte[sz]; buffer = reader.ReadBytes(sz); // Look for file descriptor foreach (var item in files_request) { if (item.Key == fd) { FileStream dump_file = item.Value; if (dump_file == null) break; LogNoLine(log, "."); // Write to file dump_file.Write(buffer, 0, sz); break; } } // Send response writer.Write(BYTE_SPECIAL); break; } case BYTE_CLOSE: { //Log(log, "BYTE_CLOSE"); int fd = reader.ReadInt32(); if (files[fd] == null) { writer.Write(BYTE_SPECIAL); writer.Write(-38); break; } //Log(log, name + " close(" + fd.ToString() + ")"); FileStream f = files[fd]; writer.Write(BYTE_SPECIAL); writer.Write(0); f.Close(); files[fd] = null; break; } case BYTE_CLOSE_DUMP: { int fd = reader.ReadInt32(); if ((fd & 0x0fff00ff) != 0x0fff00ff) { // Check if it is a file to dump foreach (var item in files_request) { if (item.Key == fd) { FileStream dump_file = item.Value; if (dump_file == null) break; LogNoLine(log,"]"); Log(log, ""); // Close file and remove from request list dump_file.Close(); files_request.Remove(fd); break; } } // Send response writer.Write(BYTE_NORMAL); } break; } case BYTE_PING: { //Log(log, "BYTE_PING"); int val1 = reader.ReadInt32(); int val2 = reader.ReadInt32(); Log(log, name + " PING RECEIVED with values : " + val1.ToString() + " - " + val2.ToString()); break; } case BYTE_G_MODE: { if (op_mode == BYTE_MODE_D) { writer.Write(BYTE_MODE_D); } else if (op_mode == BYTE_MODE_I) { writer.Write(BYTE_MODE_I); } break; } case BYTE_LOG_STR: { //Log(log, "BYTE_LOG_STR"); int len_str = reader.ReadInt32(); string str = reader.ReadString(Encoding.ASCII, len_str - 1); if (reader.ReadByte() != 0) throw new InvalidDataException(); Log(log,"-> " + str); break; } default: Log(log, "xx" + cmd_byte); throw new InvalidDataException(); } } } } catch (Exception e) { if (log != null) Log(log, name + " " + e.Message); else Console.WriteLine(name + " " + e.Message); } finally { foreach (var item in files) { if (item != null) item.Close(); } foreach (var item in files_request) { if (item.Value != null) item.Value.Close(); } if (log != null) log.Close(); } Console.WriteLine(name + " Exit"); }
public override void Read(EndianBinaryReader er) { Flag = er.ReadUInt32(); Offset = (ushort)(Flag & 0xFFFF); NrMat = (byte)(Flag >> 16 & 0x7F); Bound = (byte)(Flag >> 24 & 0xFF); /*Materials = new int[NrMat]; long curpos = er.BaseStream.Position; er.BaseStream.Position = Offset + er.GetMarker("MaterialSet"); for (int i = 0; i < NrMat; i++) { Materials[i] = er.ReadByte(); } er.BaseStream.Position = curpos;*/ }
public NamedNode(EndianBinaryReader reader) { Address = reader.BaseStream.Position; Nodes = new Collection<KeyValuePair<int, ByamlNode>>(); int count = reader.ReadInt32() & 0xffffff; for (int i = 0; i < count; i++) { uint temp = reader.ReadUInt32(); int name = (int)(temp >> 8); ByamlNodeType type = (ByamlNodeType)(byte)temp; switch (type) { case ByamlNodeType.String: Nodes.Add(new KeyValuePair<int, ByamlNode>(name, new String(reader))); break; case ByamlNodeType.Data: Nodes.Add(new KeyValuePair<int, ByamlNode>(name, new Data(reader))); break; case ByamlNodeType.Boolean: Nodes.Add(new KeyValuePair<int, ByamlNode>(name, new Boolean(reader))); break; case ByamlNodeType.Int: Nodes.Add(new KeyValuePair<int, ByamlNode>(name, new Int(reader))); break; case ByamlNodeType.Single: Nodes.Add(new KeyValuePair<int, ByamlNode>(name, new Single(reader))); break; case ByamlNodeType.UnamedNode: reader.BaseStream.Position = reader.ReadInt32(); Nodes.Add(new KeyValuePair<int, ByamlNode>(name, new UnamedNode(reader))); break; case ByamlNodeType.NamedNode: reader.BaseStream.Position = reader.ReadInt32(); Nodes.Add(new KeyValuePair<int, ByamlNode>(name, new NamedNode(reader))); break; default: throw new InvalidDataException(); } reader.BaseStream.Position = Address + (i + 1) * 8 + 4; } Length = reader.BaseStream.Position - Length; }
private static void ConvertFromByaml(EndianBinaryReader reader, string outpath) { if (reader.ReadUInt32() != 0x42590001) throw new InvalidDataException(); uint[] offsets = reader.ReadUInt32s(4); if (offsets[0] > reader.BaseStream.Length) throw new InvalidDataException(); if (offsets[1] > reader.BaseStream.Length) throw new InvalidDataException(); if (offsets[2] > reader.BaseStream.Length) throw new InvalidDataException(); if (offsets[3] > reader.BaseStream.Length) { if (offsets[0] == 0x10) { offsets[3] = offsets[2]; // Splatoon byamls are missing offsets[2] offsets[2] = 0; } else { throw new InvalidDataException(); } } List<string> nodes = new List<string>(); List<string> values = new List<string>(); List<byte[]> data = new List<byte[]>(); if (offsets[0] != 0) { reader.BaseStream.Seek(offsets[0], SeekOrigin.Begin); nodes.AddRange(new ByamlNode.StringList(reader).Strings); } if (offsets[1] != 0) { reader.BaseStream.Seek(offsets[1], SeekOrigin.Begin); values.AddRange(new ByamlNode.StringList(reader).Strings); } if (offsets[2] != 0) { reader.BaseStream.Seek(offsets[2], SeekOrigin.Begin); data.AddRange(new ByamlNode.BinaryDataList(reader).DataList); } ByamlNode tree; ByamlNodeType rootType; reader.BaseStream.Seek(offsets[3], SeekOrigin.Begin); rootType = (ByamlNodeType)reader.ReadByte(); reader.BaseStream.Seek(-1, SeekOrigin.Current); if (rootType == ByamlNodeType.UnamedNode) tree = new ByamlNode.UnamedNode(reader); else tree = new ByamlNode.NamedNode(reader); XmlDocument yaml = new XmlDocument(); yaml.AppendChild(yaml.CreateXmlDeclaration("1.0", "UTF-8", null)); XmlElement root = yaml.CreateElement("yaml"); yaml.AppendChild(root); tree.ToXml(yaml, root, nodes, values, data); using (StreamWriter writer = new StreamWriter(new FileStream(outpath, FileMode.Create), Encoding.UTF8)) { yaml.Save(writer); } }
public plttInfo(EndianBinaryReader er) { vramKey = er.ReadUInt32(); sizePltt = (UInt32)(er.ReadUInt16() << 3); flag = er.ReadUInt16(); ofsDict = er.ReadUInt16(); er.ReadBytes(2);//PADDING(2 bytes); ofsPlttData = er.ReadUInt32(); }
public Shape(EndianBinaryReader er) { long pos = er.BaseStream.Position; itemTag = er.ReadUInt16(); size = er.ReadUInt16(); flag = (NNS_G3D_SHPFLAG)er.ReadUInt32(); ofsDL = er.ReadUInt32(); sizeDL = er.ReadUInt32(); long curpos = er.BaseStream.Position; er.BaseStream.Position = pos + ofsDL; DL = er.ReadBytes((int)sizeDL); er.BaseStream.Position = curpos; }
public override void Read(EndianBinaryReader er) { Offset = er.ReadUInt32(); }
public TXOB(EndianBinaryReader er) { Type = er.ReadUInt32(); Signature = er.ReadString(Encoding.ASCII, 4); if (Signature != "TXOB") throw new SignatureNotCorrectException(Signature, "TXOB", er.BaseStream.Position); Revision = er.ReadUInt32(); NameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32(); Unknown2 = er.ReadUInt32(); Unknown3 = er.ReadUInt32(); long curpos = er.BaseStream.Position; er.BaseStream.Position = NameOffset; Name = er.ReadStringNT(Encoding.ASCII); er.BaseStream.Position = curpos; }
public TevStage(EndianBinaryReader er) { uint tmp = er.ReadUInt32(); ColorSources = new TevSource[] { (TevSource)(tmp & 0xF), (TevSource)((tmp >> 4) & 0xF), (TevSource)((tmp >> 8) & 0xF) }; ColorOperators = new TevColorOp[] { (TevColorOp)((tmp >> 12) & 0xF), (TevColorOp)((tmp >> 16) & 0xF), (TevColorOp)((tmp >> 20) & 0xF) }; ColorMode = (TevMode)((tmp >> 24) & 0xF); ColorScale = (TevScale)((tmp >> 28) & 0x3); ColorSavePrevReg = ((tmp >> 30) & 0x1) == 1; tmp = er.ReadUInt32(); AlphaSources = new TevSource[] { (TevSource)(tmp & 0xF), (TevSource)((tmp >> 4) & 0xF), (TevSource)((tmp >> 8) & 0xF) }; AlphaOperators = new TevAlphaOp[] { (TevAlphaOp)((tmp >> 12) & 0xF), (TevAlphaOp)((tmp >> 16) & 0xF), (TevAlphaOp)((tmp >> 20) & 0xF) }; AlphaMode = (TevMode)((tmp >> 24) & 0xF); AlphaScale = (TevScale)((tmp >> 28) & 0x3); AlphaSavePrevReg = ((tmp >> 30) & 0x1) == 1; ConstColors = er.ReadUInt32(); }