예제 #1
0
        private void InjectPrediction(ExtractedResourcePredictionD pred)
        {
            //was the tag for this prediction injected?
            var tag = InjectedTags.FirstOrDefault(t => t.OriginalIndex == pred.OriginalTagIndex);

            if (tag == null)
            {
                return;
            }

            ResourcePredictionD newpred = new ResourcePredictionD();

            var newtag = _tagIndices[tag];

            newpred.Tag = _cacheFile.Tags[newtag.Index];

            newpred.Index    = -1;
            newpred.Unknown1 = pred.Unknown1;
            newpred.Unknown2 = pred.Unknown2;

            foreach (ExtractedResourcePredictionC expc in pred.CEntries)
            {
                ResourcePredictionC pc = new ResourcePredictionC();
                pc.OverallIndex = -1;
                pc.Index        = -1;
                pc.BEntry       = new ResourcePredictionB();

                pc.BEntry.Index        = -1;
                pc.BEntry.OverallIndex = -1;

                foreach (ExtractedResourcePredictionA expa in expc.BEntry.AEntries)
                {
                    ResourcePredictionA pa = GeneratePredictionA(expa);
                    if (pa != null)
                    {
                        pc.BEntry.AEntries.Add(pa);
                    }
                }

                if (!pc.BEntry.IsEmpty)
                {
                    newpred.CEntries.Add(pc);
                }
            }

            foreach (ExtractedResourcePredictionA expa in pred.AEntries)
            {
                ResourcePredictionA pa = GeneratePredictionA(expa);
                if (pa != null)
                {
                    newpred.AEntries.Add(pa);
                }
            }

            if (!newpred.IsEmpty)
            {
                _resources.Predictions.Add(newpred);
            }
            return;
        }
예제 #2
0
        private StructureValueCollection SerializePredictionC(ResourcePredictionC prediction, int bStart, int overall, IStream stream)
        {
            var result = new StructureValueCollection();

            if (prediction.OverallIndex == -1)
            {
                result.SetInteger("overall index", (uint)overall);
            }
            else
            {
                result.SetInteger("overall index", (uint)prediction.OverallIndex);
            }

            result.SetInteger("b index", (uint)bStart);

            return(result);
        }
예제 #3
0
 public ExtractedResourcePredictionC(ResourcePredictionC pred)
 {
     OriginalIndex = pred.Index;
     OverallIndex  = pred.OverallIndex;
     BEntry        = new ExtractedResourcePredictionB(pred.BEntry);
 }
예제 #4
0
        public IEnumerable <ResourcePredictionD> LoadPredictions(IReader reader, TagTable tags, List <Resource> resources)
        {
            StructureValueCollection values = LoadTag(reader);

            if (!values.HasInteger("number of prediction d2s") || !values.HasInteger("prediction d2 table address"))
            {
                return(null);
            }

            int             subcount   = 2;
            StructureLayout templayout = _buildInfo.Layouts.GetLayout("raw segment table entry");

            if (templayout.HasField("tertiary page index"))
            {
                subcount = 3;
            }

            var result = new List <ResourcePredictionD>();

            StructureValueCollection[] d2entries = ReadReflexive(values, reader, "number of prediction d2s", "prediction d2 table address", "prediction d2 entry");
            StructureValueCollection[] dentries  = ReadReflexive(values, reader, "number of prediction ds", "prediction d table address", "prediction d entry");
            StructureValueCollection[] centries  = ReadReflexive(values, reader, "number of prediction cs", "prediction c table address", "prediction c entry");
            StructureValueCollection[] bentries  = ReadReflexive(values, reader, "number of prediction bs", "prediction b table address", "prediction b entry");
            StructureValueCollection[] aentries  = ReadReflexive(values, reader, "number of prediction as", "prediction a table address", "prediction a entry");

            for (int i = 0; i < d2entries.Length; i++)
            {
                ResourcePredictionD pd = new ResourcePredictionD();
                pd.Index = i;
                var tag = new DatumIndex(d2entries[i].GetInteger("tag datum"));
                pd.Tag      = tag.IsValid ? tags[tag] : null;
                pd.Unknown1 = (int)d2entries[i].GetInteger("unknown 1");
                pd.Unknown2 = (int)d2entries[i].GetInteger("unknown 2");

                var dccount = (int)dentries[i].GetInteger("c count");
                var dcindex = (int)dentries[i].GetInteger("c index");

                var dacount = (int)dentries[i].GetInteger("a count");
                var daindex = (int)dentries[i].GetInteger("a index");

                for (int c = dcindex; c < dcindex + dccount; c++)
                {
                    ResourcePredictionC pc = new ResourcePredictionC();
                    pc.Index = c;
                    var cbindex = (int)centries[c].GetInteger("b index");
                    pc.OverallIndex = (short)centries[c].GetInteger("overall index");

                    ResourcePredictionB pb = new ResourcePredictionB();
                    pb.Index = cbindex;
                    var bacount = (int)bentries[cbindex].GetInteger("a count");
                    var baindex = (int)bentries[cbindex].GetInteger("a index");
                    pb.OverallIndex = (short)bentries[cbindex].GetInteger("overall index");

                    for (int a = baindex; a < baindex + bacount; a++)
                    {
                        ResourcePredictionA pa = new ResourcePredictionA();
                        pa.Index = a;
                        pa.Value = new DatumIndex(aentries[a].GetInteger("value"));

                        int resolvedresource = pa.Value.Index / subcount;
                        int subresource      = pa.Value.Index - resolvedresource * subcount;

                        if (resolvedresource >= resources.Count)
                        {
                            continue;
                        }
                        var res = resources[resolvedresource];

                        pa.Resource    = res.Index;
                        pa.SubResource = subresource;

                        pb.AEntries.Add(pa);
                    }

                    pc.BEntry = pb;
                    pd.CEntries.Add(pc);
                }

                for (int a = daindex; a < daindex + dacount; a++)
                {
                    ResourcePredictionA pa = new ResourcePredictionA();
                    pa.Index = a;
                    pa.Value = new DatumIndex(aentries[a].GetInteger("value"));

                    int resolvedresource = pa.Value.Index / subcount;
                    int subresource      = pa.Value.Index - resolvedresource * subcount;

                    if (resolvedresource >= resources.Count)
                    {
                        continue;
                    }
                    var res = resources[resolvedresource];

                    pa.Resource    = res.Index;
                    pa.SubResource = subresource;

                    pd.AEntries.Add(pa);
                }
                result.Add(pd);
            }
            return(result);
        }