/// <summary> /// Changes action record at specified position. /// </summary> /// <param name="blockName">Name of block file.</param> /// <param name="position">Start position of action record.</param> /// <param name="axis">Rotation axis.</param> /// <param name="duration">Duration of action.</param> /// <param name="magnitude">Magnitude of action.</param> public void ModActionRecord(string blockName, long position, byte axis, UInt16 duration, UInt16 magnitude) { // Load resources string path = Path.Combine(arena2Path, "BLOCKS.BSA"); BsaFile bsaFile = new BsaFile( path, FileUsage.UseDisk, false); // Get binary record int index = bsaFile.GetRecordIndex(blockName); byte[] buffer = bsaFile.GetRecordBytes(index); // Create stream to binary record MemoryStream ms = new MemoryStream(buffer); ms.Position = position; // Write new data BinaryWriter writer = new BinaryWriter(ms, Encoding.UTF8); writer.Write(axis); writer.Write(duration); writer.Write(magnitude); writer.Close(); // Save back binary record bsaFile.RewriteRecord(index, buffer); }
/// <summary> /// ARCH3D.BSA: Modify base texture assigned to plane. /// </summary> /// <param name="MeshID">ID of mesh.</param> /// <param name="planeIndex">Plane index.</param> /// <param name="textureArchive">New texture archive index to set.</param> /// <param name="textureRecord">New texture record inex to set.</param> public void ModPlaneTexture(uint MeshID, int planeIndex, int textureArchive, int textureRecord) { // Load resources string path = Path.Combine(arena2Path, "ARCH3D.BSA"); Arch3dFile arch3dFile = new Arch3dFile( path, FileUsage.UseMemory, true); BsaFile bsaFile = new BsaFile( path, FileUsage.UseDisk, false); // Get mesh record int index = arch3dFile.GetRecordIndex(MeshID); arch3dFile.LoadRecord(index); Arch3dFile.MeshRecord record = arch3dFile.MeshRecords[index]; // Get binary record byte[] buffer = bsaFile.GetRecordBytes(index); // Compose new texture bitfield UInt16 textureBitfield = (UInt16)((textureArchive << 7) + textureRecord); // Get start position of plane header long position = record.PureMesh.Planes[planeIndex].Header.Position; // Offset to texture bitfield position += 2; // Create stream to binary record MemoryStream ms = new MemoryStream(buffer); ms.Position = position; // Write new bitfield BinaryWriter writer = new BinaryWriter(ms, Encoding.UTF8); writer.Write(textureBitfield); writer.Close(); // Save back binary record bsaFile.RewriteRecord(index, buffer); }