Exemplo n.º 1
0
        public T ReadPropertyEnum <T>(Stream stream)
        {
            UInt64 value = stream.ReadValueU64();

            if (Enum.IsDefined(typeof(T), value) == false)
            {
                throw new Exception(FightHashes.Lookup(value));
            }
            return((T)Enum.ToObject(typeof(T), value));
        }
Exemplo n.º 2
0
        public void Deserialize(Stream input)
        {
            if (input.ReadString(4, Encoding.ASCII) != "fig0")
            {
                throw new FormatException("not a fight file");
            }

            this.Flags    = input.ReadValueU32();
            this.Unknown1 = input.ReadValueU32();

            if (input.ReadValueU64() != (UInt64)FightHash.Chunk)
            {
                throw new FormatException("containing fight type is not chunk");
            }

            this.Unknown2 = input.ReadValueU32();
            this.Unknown3 = input.ReadValueU32();

            this.NameHash = this.ReadHash(input);

            UInt64 contextHash = this.ReadHash(input);

            this.Path     = input.ReadStringAlignedASCII();
            this.Unknown4 = input.ReadValueU32();

            if ((this.Flags & 1) == 0)
            {
                throw new Exception();
            }

            Type contextType = Fight.ContextCache.GetContext(contextHash);

            if (contextType == null)
            {
                throw new InvalidOperationException("unknown context type (" + FightHashes.Lookup(contextHash) + ")");
            }

            try
            {
                this.Context = (Fight.ContextBase)Activator.CreateInstance(contextType);
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }

            this.Context.Deserialize(input, this);
        }