Exemplo n.º 1
0
        private ResourcePredictionA GeneratePredictionA(ExtractedResourcePredictionA expa)
        {
            ResourcePredictionA result = new ResourcePredictionA();

            result.Index       = -1;
            result.SubResource = expa.OriginalResourceSubIndex;

            int subcount = 2;

            if (_cacheFile.HeaderSize == 0x1E000)
            {
                subcount = 3;
            }

            //ignore it if the resource was null
            if (expa.OriginalResourceGroup == -1)
            {
                return(null);
            }

            DatumIndex foundresource = DatumIndex.Null;

            //check if resource was injected
            var res = InjectedResources.FirstOrDefault(r => r.OriginalIndex == expa.OriginalResourceIndex);

            if (res != null)
            {
                foundresource = _resourceIndices[res];
            }
            else
            {
                var foundtag = _cacheFile.Tags.FindTagByName(expa.OriginalResourceName, expa.OriginalResourceGroup, _cacheFile.FileNames);

                if (foundtag != null)
                {
                    var ress = _resources.Resources.Find(r => r.ParentTag == foundtag);
                    if (ress != null)
                    {
                        foundresource = ress.Index;
                    }
                }
            }

            if (foundresource != DatumIndex.Null)
            {
                int    notsalt = ~foundresource.Salt & 0x1FFF;
                int    salt    = notsalt | 0xE000;
                ushort ind     = (ushort)((foundresource.Index * subcount) + result.SubResource);

                result.Value = new DatumIndex((ushort)salt, ind);

                return(result);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        private static ExtractedResourcePredictionD ReadPrediction(IReader reader, byte version)
        {
            if (version > 0)
            {
                throw new InvalidOperationException("Unrecognized \"pdct\" block version");
            }

            var prediction = new ExtractedResourcePredictionD();

            prediction.OriginalIndex    = reader.ReadInt32();
            prediction.OriginalTagIndex = new DatumIndex(reader.ReadUInt32());

            prediction.Unknown1 = reader.ReadInt32();
            prediction.Unknown2 = reader.ReadInt32();

            int cCount = reader.ReadInt32();

            for (int c = 0; c < cCount; c++)
            {
                var expc = new ExtractedResourcePredictionC();

                expc.BEntry = new ExtractedResourcePredictionB();

                int baCount = reader.ReadInt32();
                for (int a = 0; a < baCount; a++)
                {
                    ExtractedResourcePredictionA expa = new ExtractedResourcePredictionA();
                    expa.OriginalResourceSubIndex = reader.ReadInt32();
                    expa.OriginalResourceIndex    = new DatumIndex(reader.ReadUInt32());
                    expa.OriginalResourceGroup    = reader.ReadInt32();
                    expa.OriginalResourceName     = reader.ReadAscii();
                    expc.BEntry.AEntries.Add(expa);
                }
                prediction.CEntries.Add(expc);
            }

            int aCount = reader.ReadInt32();

            for (int a = 0; a < aCount; a++)
            {
                ExtractedResourcePredictionA expa = new ExtractedResourcePredictionA();
                expa.OriginalResourceSubIndex = reader.ReadInt32();
                expa.OriginalResourceIndex    = new DatumIndex(reader.ReadUInt32());
                expa.OriginalResourceGroup    = reader.ReadInt32();
                expa.OriginalResourceName     = reader.ReadAscii();
                prediction.AEntries.Add(expa);
            }

            return(prediction);
        }