public static bool Find(string name, ref AnimData animData) { name = name.ToUpper(); byte hash = Hash(name); if (buckets[hash].data == null) { return(false); } foreach (var data in buckets[hash].data) { if (data.cofName == name) { animData = data; return(true); } } return(false); }
public static COF Load(string basePath, string token, string weaponClass, string mode) { var filename = basePath + @"\" + token + @"\cof\" + token + mode + weaponClass + ".cof"; if (cache.ContainsKey(filename)) { return(cache[filename]); } UnityEngine.Profiling.Profiler.BeginSample("COF.Load"); COF cof = new COF(); cof.basePath = basePath; cof.token = token; cof.mode = mode; byte[] bytes = Mpq.ReadAllBytes(filename); using (var stream = new MemoryStream(bytes)) using (var reader = new BinaryReader(stream)) { cof.layerCount = reader.ReadByte(); cof.framesPerDirection = reader.ReadByte(); cof.directionCount = reader.ReadByte(); stream.Seek(25, SeekOrigin.Current); cof.compositLayers = new Layer[16]; cof.layers = new Layer[cof.layerCount]; for (int i = 0; i < cof.layerCount; ++i) { Layer layer = new Layer(); layer.index = i; layer.compositIndex = reader.ReadByte(); layer.name = layerNames[layer.compositIndex]; layer.shadow = reader.ReadByte() != 0; reader.ReadByte(); bool transparent = reader.ReadByte() != 0; int blendMode = reader.ReadByte(); if (transparent) { layer.material = Materials.softAdditive; } else { layer.material = Materials.normal; } layer.weaponClass = System.Text.Encoding.Default.GetString(reader.ReadBytes(4), 0, 3); cof.layers[i] = layer; cof.compositLayers[layer.compositIndex] = layer; } stream.Seek(cof.framesPerDirection, SeekOrigin.Current); cof.priority = reader.ReadBytes(cof.directionCount * cof.framesPerDirection * cof.layerCount); } AnimData animData = new AnimData(); if (AnimData.Find(token + mode + weaponClass, ref animData)) { cof.frameDuration = animData.frameDuration; float refFrameCount = referenceFrameCount.GetValueOrDefault(token + mode, animData.framesPerDir); cof.frameDuration *= animData.framesPerDir / refFrameCount; } else { Debug.LogWarning("animdata not found " + (token + mode + weaponClass)); } cache.Add(filename, cof); UnityEngine.Profiling.Profiler.EndSample(); return(cof); }