void SwitchNWrite(BlockRecord RecIn, SwitchType Change) { // As a temp, this will just grab the correct offset and write to it // I disabled the switch/backup effect in order to preserve functionality // // RECONSTRUCT // bool canswitch = (xSTFSStruct.ThisType == STFSType.Type1); //const uint basetable = 0xFFFFF000; BlockRecord current = xSTFSStruct.TopRecord; long[] pos = new long[] { 0, 0, 0 }; // Grab base starting points if (RecIn.ThisBlock >= Constants.BlockLevel[0] || xSTFSStruct.xBlockCount > Constants.BlockLevel[0]) { if (RecIn.ThisBlock >= Constants.BlockLevel[1] || xSTFSStruct.xBlockCount > Constants.BlockLevel[1]) pos[0] = xSTFSStruct.GenerateHashOffset(RecIn.ThisBlock, TreeLevel.L2) + 0x14; pos[1] = xSTFSStruct.GenerateHashOffset(RecIn.ThisBlock, TreeLevel.L1) + 0x14; } pos[2] = xSTFSStruct.GenerateHashOffset(RecIn.ThisBlock, TreeLevel.L0) + 0x14; //bool wipe = current.BlocksFree >= (Constants.BlockLevel[1] * Constants.BlockLevel[0]); long len = GenerateDataOffset(RecIn.ThisBlock) + 0x1000; if (xIO.Length < len) xIO.SetLength(len); if (Change == SwitchType.Allocate) xSTFSStruct.TopRecord.BlocksFree--; else if (Change == SwitchType.Delete) xSTFSStruct.TopRecord.BlocksFree++; if (pos[0] != 0) { //if (wipe) //{ // xIO.Position = (pos[0] & basetable) + (current.Index << 0xC); // xIO.Write(new byte[0x1000]); // xIO.Flush(); //} /*if (canswitch) // If this table hasn't been switched yet { if (!switched2) { xIO.Position = (pos[0] & basetable) + (current.Index << 0xC); // Get starting of table byte[] data = xIO.ReadBytes(0x1000); // Read it xSTFSStruct.TopRecord.Switch(); // Switch the index pos[0] += (xSTFSStruct.TopRecord.Index << 0xC); // Add to the base STFS function result xIO.Position = (pos[0] & basetable); // Go to new position and write it xIO.Write(data); xIO.Flush(); data = null; switched2 = true; } else pos[0] += (current.Index << 0xC); // Already switched, add the index }*/ //KILL ON RECONSTRUCTION if (canswitch) pos[0] += (current.Index << 0xC); // --------------------- xIO.Position = pos[0]; current = new BlockRecord(xIO.ReadUInt32()); //wipe = current.BlocksFree >= Constants.BlockLevel[1]; if (Change != SwitchType.None) { if (Change == SwitchType.Allocate) current.BlocksFree--; // Takes away a free block else current.BlocksFree++; // Adds a free block xIO.Position = pos[0]; xIO.Write(current.Flags); xIO.Flush(); } } // Follows same pattern if (pos[1] != 0) { //if (wipe) //{ // xIO.Position = (pos[1] & basetable) + (current.Index << 0xC); // xIO.Write(new byte[0x1000]); // xIO.Flush(); //} /*if (canswitch) { if (!switched1.Contains((int)(RecIn.ThisBlock / Constants.BlockLevel[1]))) { xIO.Position = (pos[1] & basetable) + (current.Index << 0xC); byte[] data = xIO.ReadBytes(0x1000); current.Switch(); pos[1] += (current.Index << 0xC); xIO.Position = (pos[1] & basetable); xIO.Write(data); xIO.Flush(); data = null; if (pos[0] != 0) { xIO.Position = pos[0]; xIO.Write(current.Flags); xIO.Flush(); } switched1.Add((int)(RecIn.ThisBlock / Constants.BlockLevel[1])); if (xSTFSStruct.xBlockCount <= Constants.BlockLevel[1]) xSTFSStruct.TopRecord.Switch(); } else pos[1] += (current.Index << 0xC); }*/ //KILL ON RECONSTRUCTION if (canswitch) pos[1] += (current.Index << 0xC); // --------------------- xIO.Position = pos[1]; current = new BlockRecord(xIO.ReadUInt32()); //wipe = current.BlocksFree >= Constants.BlockLevel[0]; if (Change != SwitchType.None) { if (Change == SwitchType.Allocate) current.BlocksFree--; // Takes away a free block else current.BlocksFree++; // Adds a free block xIO.Position = pos[1]; xIO.Write(current.Flags); xIO.Flush(); } } //if (wipe) //{ // xIO.Position = (pos[0] & basetable) + (current.Index << 0xC); // xIO.Write(new byte[0x1000]); // xIO.Flush(); //} /*if (canswitch) { if (!switched0.Contains((int)(RecIn.ThisBlock / Constants.BlockLevel[0]))) { xIO.Position = (pos[2] & basetable) + (current.Index << 0xC); byte[] data = xIO.ReadBytes(0x1000); current.Switch(); pos[2] += (current.Index << 0xC); xIO.Position = (pos[2] & basetable); xIO.Write(data); xIO.Flush(); data = null; if (pos[1] != 0) { xIO.Position = pos[1]; xIO.Write(current.Flags); xIO.Flush(); } switched1.Add((int)(RecIn.ThisBlock / Constants.BlockLevel[0])); if (xSTFSStruct.xBlockCount <= Constants.BlockLevel[0]) xSTFSStruct.TopRecord.Switch(); } else pos[2] += (current.Index << 0xC); }*/ //KILL ON RECONSTRUCTION if (canswitch) pos[2] += (current.Index << 0xC); // --------------------- if (Change == SwitchType.Allocate) { if (RecIn.Status == HashStatus.Old) RecIn.Status = HashStatus.Reused; else RecIn.Status = HashStatus.New; } else if (Change == SwitchType.Delete) RecIn.MarkOld(); xIO.Position = pos[2]; xIO.Write(RecIn.Flags); xIO.Flush(); if (RecIn.ThisBlock >= xSTFSStruct.xBlockCount) xSTFSStruct.xBlockCount = RecIn.ThisBlock + 1; }
void SwitchNWrite(BlockRecord RecIn, SwitchType Change) { bool canswitch = (xSTFSStruct.ThisType == STFSType.Type1); BlockRecord current = xSTFSStruct.TopRecord; long[] pos = new long[] { 0, 0, 0 }; // Grab base starting points if (RecIn.ThisBlock >= Constants.BlockLevel[0] || xSTFSStruct.xBlockCount > Constants.BlockLevel[0]) { if (RecIn.ThisBlock >= Constants.BlockLevel[1] || xSTFSStruct.xBlockCount > Constants.BlockLevel[1]) pos[0] = xSTFSStruct.GenerateHashOffset(RecIn.ThisBlock, TreeLevel.L2) + 0x14; pos[1] = xSTFSStruct.GenerateHashOffset(RecIn.ThisBlock, TreeLevel.L1) + 0x14; } pos[2] = xSTFSStruct.GenerateHashOffset(RecIn.ThisBlock, TreeLevel.L0) + 0x14; long len = GenerateDataOffset(RecIn.ThisBlock) + 0x1000; if (xIO.Length < len) xIO.SetLength(len); if (Change == SwitchType.Allocate) xSTFSStruct.TopRecord.BlocksFree--; else if (Change == SwitchType.Delete) xSTFSStruct.TopRecord.BlocksFree++; if (pos[0] != 0) { if (canswitch) pos[0] += (current.Index << 0xC); // --------------------- xIO.Position = pos[0]; current = new BlockRecord(xIO.ReadUInt32()); if (Change != SwitchType.None) { if (Change == SwitchType.Allocate) current.BlocksFree--; // Takes away a free block else current.BlocksFree++; // Adds a free block xIO.Position = pos[0]; xIO.Write(current.Flags); xIO.Flush(); } } // Follows same pattern if (pos[1] != 0) { if (canswitch) pos[1] += (current.Index << 0xC); // --------------------- xIO.Position = pos[1]; current = new BlockRecord(xIO.ReadUInt32()); if (Change != SwitchType.None) { if (Change == SwitchType.Allocate) current.BlocksFree--; // Takes away a free block else current.BlocksFree++; // Adds a free block xIO.Position = pos[1]; xIO.Write(current.Flags); xIO.Flush(); } } if (canswitch) pos[2] += (current.Index << 0xC); // --------------------- if (Change == SwitchType.Allocate) { if (RecIn.Status == HashStatus.Old) RecIn.Status = HashStatus.Reused; else RecIn.Status = HashStatus.New; } else if (Change == SwitchType.Delete) RecIn.MarkOld(); xIO.Position = pos[2]; xIO.Write(RecIn.Flags); xIO.Flush(); if (RecIn.ThisBlock >= xSTFSStruct.xBlockCount) xSTFSStruct.xBlockCount = RecIn.ThisBlock + 1; }