Example #1
0
        private void WriteMainHeader(SaveIO.SaveWriter writer)
        {
            // Write the new header to a MemoryStream for resigning purposes
            MemoryStream tempStream = new MemoryStream(HeaderSize - CRC32Size);

            SaveIO.SaveWriter tempWriter = new SaveIO.SaveWriter(tempStream);
            tempWriter.WriteUInt32(_unknown);
            tempWriter.WriteInt32(_cfgSize);
            tempWriter.WriteInt32(_dataBlock1Size);
            tempWriter.WriteInt32(_dataBlock2Size);
            tempWriter.WriteInt32(_saveDataSize);

            // Grab its CRC32
            CRC32 crc32 = new CRC32();

            byte[] checksum = crc32.ComputeHash(tempStream.GetBuffer());

            // Now write it to the destination stream
            writer.WriteBlock(checksum);
            writer.WriteBlock(tempStream.GetBuffer());
            tempWriter.Close();
        }
Example #2
0
        protected override void DoUpdate(SaveIO.SaveWriter writer, long start)
        {
            base.DoUpdate(writer, start);

            // Actor
            writer.Seek(start + 0x1BC, SeekOrigin.Begin);
            if (_actor != null)
            {
                writer.WriteUInt32(_actor.DatumIndex);
            }
            else
            {
                writer.WriteUInt32(0xFFFFFFFF);
            }

            // Unit flags
            writer.Seek(start + 0x1C4, SeekOrigin.Begin);
            writer.WriteInt32(_unitFlags.Data);

            // Team
            writer.Seek(start + 0x1C8, SeekOrigin.Begin);
            writer.WriteByte(_team);

            // Write weapon index info
            writer.Seek(start + 0x340, SeekOrigin.Begin);
            writer.WriteUInt16((ushort)(_weapons.Count + 2));
            writer.WriteSByte(_currentWeaponIndex);
            writer.Skip(1);

            writer.WriteUInt16((ushort)(_weapons.Count + 2));
            writer.WriteSByte(_backupWeaponIndex);
            writer.Skip(1);

            // Write the weapon list
            foreach (WeaponObject weapon in _weapons)
            {
                writer.WriteUInt32(weapon.ID);
            }

            // Write empty spots
            for (int i = _weapons.Count; i < 4; i++)
            {
                writer.WriteUInt32(0xFFFFFFFF);
            }
        }
Example #3
0
        /// <summary>
        /// Override this to write out any changed properties.
        /// </summary>
        /// <param name="writer">The SaveWriter to write to</param>
        /// <param name="start">The start of the object's data</param>
        protected virtual void DoUpdate(SaveIO.SaveWriter writer, long start)
        {
            // If the object's position has changed, awaken it
            if (_x != _originalX || _y != _originalY || _z != _originalZ || !_velocity.Equals(_originalVelocity))
            {
                IsAwake = true;
            }

            writer.Seek(start + 0x4, SeekOrigin.Begin);
            writer.WriteInt32(_flags.Data);
            writer.WriteUInt16(_zone);
            writer.Seek(2, SeekOrigin.Current);

            if (_nextCarried != null)
            {
                writer.WriteUInt32(_nextCarried.ID);
            }
            else
            {
                writer.WriteUInt32(0xFFFFFFFF);
            }

            if (_firstCarried != null)
            {
                writer.WriteUInt32(_firstCarried.ID);
            }
            else
            {
                writer.WriteUInt32(0xFFFFFFFF);
            }

            if (_carrier != null)
            {
                writer.WriteUInt32(_carrier.ID);
            }
            else
            {
                writer.WriteUInt32(0xFFFFFFFF);
            }
            writer.WriteSByte(_parentNodeIndex);

            writer.Seek(start + 0x20, SeekOrigin.Begin);
            writer.WriteFloat(_x);
            writer.WriteFloat(_y);
            writer.WriteFloat(_z);

            /*writer.WriteFloat(_boundsX1);
            *  writer.WriteFloat(_boundsY1);
            *  writer.WriteFloat(_boundsZ1);*/
            writer.Seek(4, SeekOrigin.Current);
            writer.WriteFloat(_x);
            writer.WriteFloat(_y);
            writer.WriteFloat(_z);

            /*writer.WriteFloat(_boundsX2);
            *  writer.WriteFloat(_boundsY2);
            *  writer.WriteFloat(_boundsZ2);*/
            writer.Seek(8, SeekOrigin.Current);
            writer.WriteFloat(_x);
            writer.WriteFloat(_y);
            writer.WriteFloat(_z);

            writer.WriteFloat(_right.X);
            writer.WriteFloat(-_right.Y);   // hax
            writer.WriteFloat(_right.Z);
            writer.WriteFloat(_up.X);
            writer.WriteFloat(-_up.Y);  // hax
            writer.WriteFloat(_up.Z);

            writer.Seek(start + 0x68, SeekOrigin.Begin);
            writer.WriteFloat(_velocity.X);
            writer.WriteFloat(_velocity.Y);
            writer.WriteFloat(_velocity.Z);

            writer.Seek(start + 0x80, SeekOrigin.Begin);
            // Scale is stored twice??
            writer.WriteFloat(_scale);
            writer.WriteFloat(_scale);

            writer.Seek(start + 0xDC, SeekOrigin.Begin);
            writer.WriteInt32(_physicsFlags.Data);

            writer.Seek(start + 0x13C, SeekOrigin.Begin);
            writer.WriteInt32(_invincibilityFlags.Data);

            // Write strength info
            writer.Seek(start + 0x110, SeekOrigin.Begin);
            _healthInfo.WriteTo(writer);

            if (_nodeDataOffset != 0xFFFF)
            {
                writer.Seek(start + _nodeDataOffset, SeekOrigin.Begin);
                foreach (ModelNode node in _nodes)
                {
                    node.Update(writer, this);
                }
            }
        }