public HSE_Animation(string file_name) { using (FileStream strm = new FileStream(file_name, FileMode.Open)) { EndianBinaryReader reader = new EndianBinaryReader(strm, Endian.Little); int test = reader.PeekReadInt32(); if (reader.PeekReadInt32() == 5397068) { reader = LZR.Decompress(reader); } Load_HSE(reader); } }
public TIM(string file_name) { // Load a png. Simple! if (Path.GetExtension(file_name) == ".png") { m_Image = new Bitmap(file_name); return; } // Need to load a TIM. using (FileStream strm = new FileStream(file_name, FileMode.Open)) { EndianBinaryReader reader = new EndianBinaryReader(strm, Endian.Little); int test = reader.PeekReadInt32(); if (reader.PeekReadInt32() == 5397068) { reader = LZR.Decompress(reader); } Load_TIM(reader); } }
/// <summary> /// Read a RCO file. /// See description of an RCO file structure in /// https://github.com/kakaroto/RCOMage/blob/master/src/rcofile.h /// </summary> /// <returns> true RCO file is valid /// false RCO file is invalid </returns> private bool read() { int magic = endianSwap32(read32()); if (magic != RCO_MAGIC) { Console.WriteLine(string.Format("Invalid RCO magic 0x{0:X8}", magic)); return(false); } int version = read32(); //if (log.DebugEnabled) { Console.WriteLine(string.Format("RCO version 0x{0:X}", version)); } skip32(); // null int compression = read32(); int umdFlag = compression & 0x0F; int headerCompression = (compression & 0xF0) >> 4; //if (log.DebugEnabled) { Console.WriteLine(string.Format("umdFlag=0x{0:X}, headerCompression=0x{1:X}", umdFlag, headerCompression)); } int pMainTable = read32(); pVSMXTable = read32(); int pTextTable = read32(); int pSoundTable = read32(); int pModelTable = read32(); int pImgTable = read32(); skip32(); // pUnknown int pFontTable = read32(); int pObjTable = read32(); int pAnimTable = read32(); pTextData = read32(); lTextData = read32(); pLabelData = read32(); lLabelData = read32(); int pEventData = read32(); int lEventData = read32(); int pTextPtrs = read32(); int lTextPtrs = read32(); int pImgPtrs = read32(); int lImgPtrs = read32(); int pModelPtrs = read32(); int lModelPtrs = read32(); int pSoundPtrs = read32(); int lSoundPtrs = read32(); int pObjPtrs = read32(); int lObjPtrs = read32(); int pAnimPtrs = read32(); int lAnimPtrs = read32(); pImgData = read32(); lImgData = read32(); int pSoundData = read32(); int lSoundData = read32(); int pModelData = read32(); int lModelData = read32(); skip32(); // Always 0xFFFFFFFF skip32(); // Always 0xFFFFFFFF skip32(); // Always 0xFFFFFFFF //if (log.DebugEnabled) { Console.WriteLine(string.Format("pMainTable=0x{0:X}, pVSMXTable=0x{1:X}, pTextTable=0x{2:X}, pSoundTable=0x{3:X}, pModelTable=0x{4:X}, pImgTable=0x{5:X}, pFontTable=0x{6:X}, pObjTable=0x{7:X}, pAnimTable=0x{8:X}", pMainTable, pVSMXTable, pTextTable, pSoundTable, pModelTable, pImgTable, pFontTable, pObjTable, pAnimTable)); Console.WriteLine(string.Format("TextData=0x{0:X}[0x{1:X}], LabelData=0x{2:X}[0x{3:X}], EventData=0x{4:X}[0x{5:X}]", pTextData, lTextData, pLabelData, lLabelData, pEventData, lEventData)); Console.WriteLine(string.Format("TextPtrs=0x{0:X}[0x{1:X}], ImgPtrs=0x{2:X}[0x{3:X}], ModelPtrs=0x{4:X}[0x{5:X}], SoundPtrs=0x{6:X}[0x{7:X}], ObjPtrs=0x{8:X}[0x{9:X}], AnimPtrs=0x{10:X}[0x{11:X}]", pTextPtrs, lTextPtrs, pImgPtrs, lImgPtrs, pModelPtrs, lModelPtrs, pSoundPtrs, lSoundPtrs, pObjPtrs, lObjPtrs, pAnimPtrs, lAnimPtrs)); Console.WriteLine(string.Format("ImgData=0x{0:X}[0x{1:X}], SoundData=0x{2:X}[0x{3:X}], ModelData=0x{4:X}[0x{5:X}]", pImgData, lImgData, pSoundData, lSoundData, pModelData, lModelData)); } if (headerCompression != 0) { int lenPacked = read32(); int lenUnpacked = read32(); int lenLongestText = read32(); sbyte[] packedBuffer = readBytes(lenPacked); sbyte[] unpackedBuffer = new sbyte[lenUnpacked]; int result; if (headerCompression == RCO_DATA_COMPRESSION_RLZ) { result = LZR.decompress(unpackedBuffer, lenUnpacked, packedBuffer); } else { Console.WriteLine(string.Format("Unimplemented compression {0:D}", headerCompression)); result = -1; } if (log.TraceEnabled) { log.trace(string.Format("Unpack header longestText=0x{0:X}, result=0x{1:X}: {2}", lenLongestText, result, Utilities.getMemoryDump(unpackedBuffer, 0, lenUnpacked))); } if (pTextData != RCO_NULL_PTR && lTextData > 0) { seek(pTextData); int nextOffset; do { int textLang = read16(); skip16(); nextOffset = read32(); int textLenPacked = read32(); int textLenUnpacked = read32(); sbyte[] textPackedBuffer = readBytes(textLenPacked); sbyte[] textUnpackedBuffer = new sbyte[textLenUnpacked]; if (headerCompression == RCO_DATA_COMPRESSION_RLZ) { result = LZR.decompress(textUnpackedBuffer, textLenUnpacked, textPackedBuffer); } else { Console.WriteLine(string.Format("Unimplemented compression {0:D}", headerCompression)); result = -1; } if (log.TraceEnabled) { log.trace(string.Format("Unpack text lang={0:D}, result=0x{1:X}: {2}", textLang, result, Utilities.getMemoryDump(textUnpackedBuffer, 0, textLenUnpacked))); } if (result >= 0) { compressedTextDataOffset = extend(compressedTextDataOffset, textLang + 1); compressedTextDataOffset[textLang] = unpackedBuffer.Length + RCO_HEADER_SIZE; unpackedBuffer = append(unpackedBuffer, textUnpackedBuffer); } if (nextOffset == 0) { break; } skip(nextOffset - 16 - textLenPacked); } while (nextOffset != 0); } if (result >= 0) { buffer = append(buffer, RCO_HEADER_SIZE, unpackedBuffer); } } events = new Dictionary <int, string>(); if (pEventData != RCO_NULL_PTR && lEventData > 0) { seek(pEventData); while (tell() < pEventData + lEventData) { int index = tell() - pEventData; string s = readString(); if (!string.ReferenceEquals(s, null) && s.Length > 0) { events[index] = s; } } } entries = new Dictionary <int, RCO.RCOEntry>(); images = new Dictionary <int, System.Drawing.Bitmap>(); objects = new Dictionary <int, BaseObject>(); mainTable = readRCOEntry(pMainTable); //if (log.DebugEnabled) { Console.WriteLine(string.Format("mainTable: {0}", mainTable)); } if (pObjPtrs != RCO_NULL_PTR) { seek(pObjPtrs); for (int i = 0; i < lObjPtrs; i += 4) { int objPtr = read32(); if (objPtr != 0 && !objects.ContainsKey(objPtr)) { Console.WriteLine(string.Format("Object 0x{0:X} not read", objPtr)); } } } if (pImgPtrs != RCO_NULL_PTR) { seek(pImgPtrs); for (int i = 0; i < lImgPtrs; i += 4) { int imgPtr = read32(); if (imgPtr != 0 && !images.ContainsKey(imgPtr)) { Console.WriteLine(string.Format("Image 0x{0:X} not read", imgPtr)); } } } RCOContext context = new RCOContext(null, 0, events, images, objects); foreach (BaseObject @object in objects.Values) { @object.init(context); } return(true); }