mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-06-01 04:53:29 -05:00
Provide custom headers for anchors that are pointed to by named tables
This commit is contained in:
parent
2cf2dc4ce0
commit
5c76f35bb7
|
|
@ -767,14 +767,26 @@ namespace HavenSoft.HexManiac.Core.Models {
|
|||
// only produce headers for arrays with length based on other arrays that start with a text member.
|
||||
var run = GetNextRun(address);
|
||||
if (run.Start > address) return false;
|
||||
if (!(run is ArrayRun array)) return false;
|
||||
if (!(run is ArrayRun array)) {
|
||||
if (run.PointerSources != null && run.PointerSources.Count > 0 && run.Start == address) {
|
||||
var parentRun = GetNextRun(run.PointerSources[0]);
|
||||
if (parentRun is ArrayRun parentArray) {
|
||||
array = parentArray;
|
||||
var arrayIndex = parentArray.ConvertByteOffsetToArrayOffset(run.PointerSources[0]).ElementIndex;
|
||||
address = parentArray.Start + arrayIndex * parentArray.ElementLength;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((address - array.Start) % array.ElementLength != 0) return false;
|
||||
|
||||
using (ModelCacheScope.CreateScope(this)) {
|
||||
var index = (address - array.Start) / array.ElementLength;
|
||||
if (array.ElementNames.Count <= index) return false;
|
||||
header = array.ElementNames[index];
|
||||
}
|
||||
var index = (address - array.Start) / array.ElementLength;
|
||||
if (array.ElementNames.Count <= index) return false;
|
||||
header = array.ElementNames[index];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -632,7 +632,6 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
Assert.Equal(1, table.ElementCount);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TableWithNegativeOffset_ShrinkAndGrowParent_ChildLengthRestored() {
|
||||
CreateTextTable("names", 0, "adam", "bob", "carl", "dave");
|
||||
|
|
@ -661,6 +660,16 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
Assert.Equal(12, Model.ReadMultiByteValue(4, 2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PointerTable_RequestHeaderForDestination_GetTableIndexName() {
|
||||
Model.SetList("options", new[] { "Adam", "Bob", "Carl", "Dave" });
|
||||
ViewPort.Edit("^table[entry<>]options <100> <120> <140> <160>");
|
||||
|
||||
Model.TryGetUsefulHeader(0x120, out var header);
|
||||
|
||||
Assert.Equal("Bob", header);
|
||||
}
|
||||
|
||||
private void ArrangeTrainerPokemonTeamData(byte structType, byte pokemonCount, int trainerCount) {
|
||||
CreateTextTable(HardcodeTablesModel.PokemonNameTable, 0x180, "ABCDEFGHIJKLMNOP".Select(c => c.ToString()).ToArray());
|
||||
CreateTextTable(HardcodeTablesModel.MoveNamesTable, 0x1B0, "qrstuvwxyz".Select(c => c.ToString()).ToArray());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user