Exemple #1
0
        public static int FixPartitionTable(PartitionSelection partsel, byte[] partTable)
        {
            if (partsel == PartitionSelection.AllPartitions)
            {
                return(0);
            }
            uint nPartitions = _be32(partTable, 0);

            if ((_be32(partTable, 4) - 0x10000) > 0x50)
            {
                return(-1);
            }

            uint part_offset = 0;
            uint part_type   = 0;
            uint b           = (_be32(partTable, 4) - 0x10000) * 4;
            uint j           = 0;

            byte[] v;

            for (uint i = 0; i < nPartitions; i++)
            {
                part_offset = _be32(partTable, (b + 8 * i));
                part_type   = _be32(partTable, (b + 8 * i + 4));

                if (!TestParitionSkip(part_type, partsel))
                {
                    v = BitConverter.GetBytes((uint)System.Net.IPAddress.HostToNetworkOrder((int)part_offset));
                    partTable[b + 8 * j]     = v[0];
                    partTable[b + 8 * j + 1] = v[1];
                    partTable[b + 8 * j + 2] = v[2];
                    partTable[b + 8 * j + 3] = v[3];

                    v = BitConverter.GetBytes((uint)System.Net.IPAddress.HostToNetworkOrder((int)part_type));
                    partTable[b + 8 * j + 4] = v[0];
                    partTable[b + 8 * j + 5] = v[1];
                    partTable[b + 8 * j + 6] = v[2];
                    partTable[b + 8 * j + 7] = v[3];

                    j++;
                }
            }

            v            = BitConverter.GetBytes((uint)System.Net.IPAddress.HostToNetworkOrder((int)j));
            partTable[0] = v[0];
            partTable[1] = v[1];
            partTable[2] = v[2];
            partTable[3] = v[3];

            v = null;
            return(0);
        }
Exemple #2
0
        public static Boolean TestParitionSkip(uint partitionType, PartitionSelection partitionSelector)
        {
            switch (partitionSelector)
            {
            case PartitionSelection.AllPartitions:
                return(false);

            case PartitionSelection.RemoveUpdatePartition:
                return(partitionType == 1);

            case PartitionSelection.OnlyGamePartition:
                return(partitionType != 0);

            default:
                return(partitionType != (uint)partitionSelector);
            }
        }
Exemple #3
0
        public int BuildDisc(PartitionSelection selector)
        {
            SectorUsageTable = new byte[WBFSDevice.wiiSectorsPerDisc];
            Partition        = selector;

            int r = DoDisc();

            UsedSectors = 0;
            if (r == 0)
            {
                for (int i = 0; i < SectorUsageTable.Length; i++)
                {
                    if (SectorUsageTable[i] != 0)
                    {
                        UsedSectors++;
                    }
                }
            }

            Partition = PartitionSelection.AllPartitions;
            return(r);
        }
        private IList <Color> DecodeMultiPartition(BitReader br, BlockMode blockMode, int partitions)
        {
            var colorEndpointModes = DecodeColorEndpointModes(br, blockMode, partitions);
            var colorValueCount    = colorEndpointModes.Sum(x => x.EndpointValueCount);

            if (colorValueCount > 18 || colorEndpointModes.Any(x => x.IsHdr != blockMode.IsHdr))
            {
                return(ErrorColors);
            }

            var colorBits         = ColorHelper.CalculateColorBits(partitions, blockMode.WeightBitCount, blockMode.IsDualPlane);
            var quantizationLevel = ColorHelper.QuantizationModeTable[colorValueCount >> 1][colorBits];

            if (quantizationLevel < 4)
            {
                return(ErrorColors);
            }

            br.Position = 19 + Constants.PartitionBits;
            var colorValues = IntegerSequenceEncoding.Decode(br, quantizationLevel, colorValueCount);

            var colorEndpoints = new UInt4[partitions][];

            for (var i = 0; i < partitions; i++)
            {
                colorEndpoints[i] = ColorUnquantization.DecodeColorEndpoints(colorValues, colorEndpointModes[i].Format, quantizationLevel);
            }

            br.Position = 13;
            var partitionIndex = br.ReadBits <uint>(10);

            var elementsInBlock  = _x * _y * _z;
            var partitionIndices = new int[elementsInBlock];

            for (int z = 0; z < _z; z++)
            {
                for (int y = 0; y < _y; y++)
                {
                    for (int x = 0; x < _x; x++)
                    {
                        partitionIndices[x * y * z] =
                            PartitionSelection.SelectPartition(partitionIndex, x, y, z, partitions, elementsInBlock < 32);
                    }
                }
            }

            var result = new Color[elementsInBlock];

            if (blockMode.IsDualPlane)
            {
                // TODO: Should those 2 bits below the weights be here for multi partition due to encodedType high part?
                br.Position = 128 - blockMode.WeightBitCount - 2;
                var plane2ColorComponent = br.ReadBits <int>(2);

                var indices = IntegerSequenceEncoding.Decode(br, blockMode.QuantizationMode, blockMode.WeightCount);
                for (var i = 0; i < blockMode.WeightCount; i++)
                {
                    var plane1Weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i * 2]];
                    var plane2Weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i * 2 + 1]];
                    result[i] = ColorHelper.InterpolateColor(colorEndpoints[partitionIndices[i]], plane1Weight, plane2Weight, plane2ColorComponent);
                }
            }
            else
            {
                var indices = IntegerSequenceEncoding.Decode(br, blockMode.QuantizationMode, blockMode.WeightCount);
                for (var i = 0; i < blockMode.WeightCount; i++)
                {
                    var weight = WeightUnquantization.WeightUnquantizationTable[blockMode.QuantizationMode][indices[i]];
                    result[i] = ColorHelper.InterpolateColor(colorEndpoints[partitionIndices[i]], weight, -1, -1);
                }
            }

            return(result);
        }
Exemple #5
0
        int partIndex = 0; //Partição atual

        //---------------------------- Rotinas

        //--------------------------- Construtor, inicializa a classe com um contexto de arquivo
        public WiiDisc(IIOContext context, bool generateExtendedInfo)
        {
            file                 = context;
            Partition            = PartitionSelection.AllPartitions;
            GenerateExtendedInfo = generateExtendedInfo;
        }