// // copied the source file by https://github.com/stackprobe/Factory/blob/master/SubTools/CopyLib.c // public static void INIT() { ReleaseMode = File.Exists(DDConsts.ResourceFile_01); if (ReleaseMode) { foreach (string resFile in new string[] { DDConsts.ResourceFile_01, DDConsts.ResourceFile_02 }) { List <ResInfo> resInfos = new List <ResInfo>(); using (FileStream reader = new FileStream(resFile, FileMode.Open, FileAccess.Read)) { while (reader.Position < reader.Length) { int size = BinTools.ToInt(FileTools.Read(reader, 4)); if (size < 0) { throw new DDError(); } resInfos.Add(new ResInfo() { ResFile = resFile, Offset = reader.Position, Size = size, }); reader.Seek((long)size, SeekOrigin.Current); } } string[] files = FileTools.TextToLines(StringTools.ENCODING_SJIS.GetString(LoadFile(resInfos[0]))); if (files.Length != resInfos.Count) { throw new DDError(files.Length + ", " + resInfos.Count); } for (int index = 1; index < files.Length; index++) { string file = files[index]; if (File2ResInfo.ContainsKey(file)) { throw new DDError(file); } File2ResInfo.Add(file, resInfos[index]); } } } }
public ResourceClusterFile(string file) { this.ClusterFile = file; long fileSize = new FileInfo(file).Length; using (FileStream reader = new FileStream(file, FileMode.Open, FileAccess.Read)) { byte[] signature = FileTools.Read(reader, SIGNATURE.Length); if (BinTools.Comp(signature, SIGNATURE) != 0) { throw new GameError("Bad signature"); } this.ResCount = BinTools.ToInt(FileTools.Read(reader, 4)); if (this.ResCount < 0 || IntTools.IMAX < this.ResCount) { throw new GameError("Bad ResCount"); } this.ResStartPositions = new long[this.ResCount]; this.ResSizes = new int[this.ResCount]; long count = SIGNATURE.Length + 4 + this.ResCount * 4; for (int index = 0; index < this.ResCount; index++) { int resSize = BinTools.ToInt(FileTools.Read(reader, 4)); if (resSize < 0 || IntTools.IMAX < resSize) { throw new GameError("Bad resSize " + resSize); } this.ResStartPositions[index] = count; this.ResSizes[index] = resSize; if (LongTools.IMAX_64 - count < (long)resSize) { throw new GameError("Bad resSize " + resSize + ", " + count); } count += (long)resSize; } if (count + 64L != fileSize) { throw new GameError("Bad fileSize " + fileSize + ", " + count); } reader.Seek(0L, SeekOrigin.Begin); byte[] hash = SecurityTools.GetSHA512(FileTools.Iterate(new LimitedReader(count, reader.Read).Read)); byte[] hash2 = FileTools.Read(reader, 64); if (BinTools.Comp(hash, hash2) != 0) { throw new GameError("Bad hash"); } } }