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; }
private StructureValueCollection SerializePredictionA(ResourcePredictionA prediction, IStream stream) { var result = new StructureValueCollection(); result.SetInteger("value", prediction.Value.Value); return(result); }
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); } }
public ExtractedResourcePredictionA(ResourcePredictionA pred) { OriginalIndex = pred.Index; OriginalResourceIndex = pred.Resource; OriginalResourceSubIndex = pred.SubResource; }
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); }