Example #1
0
        public static string GetChunkID(Type type)
        {
            string id;

            if (ChunkIDs.TryGetValue(type, out id))
            {
                return(id);
            }
            ChunkAttribute chunkInfo = type.GetCustomAttribute <ChunkAttribute>();

            if (chunkInfo != null)
            {
                return(ChunkIDs[type] = chunkInfo.ID);
            }
            throw new InvalidDataException("Unregistered chunk type");
        }
Example #2
0
 public static void RegisterChunksFromModule(EverestModule module)
 {
     foreach (Type type in module.GetType().Assembly.GetTypes())
     {
         ChunkAttribute chunkInfo = type.GetCustomAttribute <ChunkAttribute>();
         if (chunkInfo == null)
         {
             continue;
         }
         // TODO: Can be optimized. Who wants to write a DynamicMethod generator for this? :^)
         RegisterChunk(type, chunkInfo.ID, reader => {
             IChunk chunk = (IChunk)Activator.CreateInstance(type);
             chunk.Read(reader);
             return(chunk);
         });
     }
 }