private static bool ExtractResource(string cachePath, uint index, IReadOnlyList<string> args) { if (args.Count != 5) return false; uint compressedSize; if (!uint.TryParse(args[3], NumberStyles.HexNumber, null, out compressedSize)) return false; var outPath = args[4]; try { using (var stream = File.OpenRead(cachePath)) { var cache = new ResourceCache(stream); using (var outStream = File.Open(outPath, FileMode.Create, FileAccess.Write)) { cache.Decompress(stream, (int)index, compressedSize, outStream); Console.WriteLine("Wrote 0x{0:X} bytes to {1}.", outStream.Position, outPath); } } } catch (Exception ex) { Console.WriteLine("Failed to extract resource: {0}", ex.Message); } return true; }
private bool ImportAnimationResource(TagInstance tagIndex, string cachePath, string dataPath) { ModelAnimationGraph animation; ResourceCache resourceCache; uint compressedSize = 0; var data = File.ReadAllBytes(dataPath); using (var cacheStream = _info.OpenCacheReadWrite()) { var tagContext = new TagSerializationContext(cacheStream, _info.Cache, _info.StringIDs, tagIndex); animation = _info.Deserializer.Deserialize<ModelAnimationGraph>(tagContext); } using (var stream = File.Open(_info.CacheFile.DirectoryName + "\\" + cachePath, FileMode.Open, FileAccess.ReadWrite)) { resourceCache = new ResourceCache(stream); animation.ResourceGroups[0].Resource.Index = resourceCache.Add(stream, data, out compressedSize); animation.ResourceGroups[0].Resource.CompressedSize = compressedSize; animation.ResourceGroups[0].Resource.OldLocationFlags = (OldResourceLocationFlags)2; } using (var cacheStream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite)) { var context = new TagSerializationContext(cacheStream, _cache, _stringIds, tagIndex); _info.Serializer.Serialize(context, animation); } Console.WriteLine("{1}: Imported 0x{0}.", compressedSize, tagIndex); return true; }
private static bool ImportResource(string cachePath, uint index, IReadOnlyList<string> args) { if (args.Count != 4) return false; var inPath = args[3]; try { using (var stream = File.Open(cachePath, FileMode.Open, FileAccess.ReadWrite)) { var cache = new ResourceCache(stream); var data = File.ReadAllBytes(inPath); var compressedSize = cache.Compress(stream, (int)index, data); Console.WriteLine("Imported 0x{0:X} bytes.", data.Length); Console.WriteLine("Compressed size = 0x{0:X}", compressedSize); } } catch (Exception ex) { Console.WriteLine("Failed to import resource: {0}", ex.Message); } return true; }
private bool ImportBitmapResource(TagInstance tagIndex, string cachePath, string dataPath) { Bitmap bitmap; ResourceCache resourceCache; uint compressedSize = 0; using (var cacheStream = _info.OpenCacheRead()) { var tagContext = new TagSerializationContext(cacheStream, _info.Cache, _info.StringIDs, tagIndex); bitmap = _info.Deserializer.Deserialize<Bitmap>(tagContext); } using (var stream = File.Open(_info.CacheFile.DirectoryName + "\\" + cachePath, FileMode.Open, FileAccess.ReadWrite)) { int imageIndex = 0; foreach (string file in Directory.EnumerateFiles(dataPath, "*.bitm")) { byte[] inBitmapData = File.ReadAllBytes(file); resourceCache = new ResourceCache(stream); bitmap.Resources[imageIndex].Resource.Index = resourceCache.Add(stream, inBitmapData, out compressedSize); bitmap.Resources[imageIndex].Resource.CompressedSize = compressedSize; imageIndex++; } } using (var cacheStream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite)) { var context = new TagSerializationContext(cacheStream, _cache, _stringIds, tagIndex); _info.Serializer.Serialize(context, bitmap); } Console.WriteLine("{1}: Imported 0x{0}.", compressedSize, tagIndex); return true; }
private bool ImportModelResource(TagInstance tagIndex, string cachePath, string dataPath) { RenderModel renderModel; ResourceCache resourceCache; uint compressedSize = 0; var data = File.ReadAllBytes(dataPath); using (var cacheStream = _info.OpenCacheReadWrite()) { var tagContext = new TagSerializationContext(cacheStream, _info.Cache, _info.StringIDs, tagIndex); renderModel = _info.Deserializer.Deserialize<RenderModel>(tagContext); } using (var stream = File.Open(_info.CacheFile.DirectoryName + "\\" + cachePath, FileMode.Open, FileAccess.ReadWrite)) { resourceCache = new ResourceCache(stream); renderModel.Geometry.Resource.Index = resourceCache.Add(stream, data, out compressedSize); renderModel.Geometry.Resource.CompressedSize = compressedSize; } using (var cacheStream = _fileInfo.Open(FileMode.Open, FileAccess.ReadWrite)) { var context = new TagSerializationContext(cacheStream, _cache, _stringIds, tagIndex); _info.Serializer.Serialize(context, renderModel); } Console.WriteLine("{1}: Imported 0x{0}.", compressedSize, tagIndex); return true; }