fix decap algorithm

Now works right for capital letters that come after escape bytes
also fix random crash in ModelTable string recognition
also fi random assert from adding an anchor to a pointer
This commit is contained in:
haven1433 2022-11-01 23:36:40 -05:00
parent 0ddee84a10
commit d3d2422ec0
4 changed files with 34 additions and 11 deletions

View File

@ -87,6 +87,7 @@ namespace HavenSoft.HexManiac.Core.Models {
valueAddress = model.ReadPointer(valueAddress);
if (valueAddress < 0 || valueAddress >= model.Count) return string.Empty;
var length = PCSString.ReadString(model, valueAddress, true);
if (length < 1) return string.Empty;
return model.TextConverter.Convert(model, valueAddress, length).Trim('"');
} else {
throw new NotImplementedException();

View File

@ -1071,6 +1071,12 @@ namespace HavenSoft.HexManiac.Core.Models {
changeToken.RemoveRun(runs[index]);
RemoveIndex(index);
}
if (run is PointerRun && run.PointerSources != null && run.PointerSources.Count == 0 && !anchorForAddress.ContainsKey(run.Start)) {
// this run contains useful information, but no useful anchors. Remove the pointer sources.
run = run.Duplicate(run.Start, null);
changeToken.AddRun(run);
SetIndex(index, run);
}
if (existingRun is ArrayRun arrayRun2 && arrayRun2.SupportsInnerPointers && arrayRun2.Length > run.Length) {
for (int i = 0; i < arrayRun2.ElementCount; i++) {

View File

@ -125,21 +125,27 @@ namespace HavenSoft.HexManiac.Core.ViewModels.QuickEditItems {
if (address < 0 || address >= model.Count) return;
var textLength = PCSString.ReadString(model, address, true);
if (textLength < 3) return;
var text = model.TextConverter.Convert(model, address, textLength).ToCharArray();
for (int i = 1; i < text.Length; i++) {
if (IsLetter(text[i - 1]) && IsCap(text[i])) {
text[i] += (char)('a' - 'A');
var (_A, _a) = (0xBB, 0xD5);
var run = new PCSRun(model, address, textLength);
if (address == 0x245F01) ;
bool previousIsCap = run.CreateDataFormat(model, address) is PCS pcs0 && IsCap(pcs0.ThisCharacter);
for (int i = 1; i < textLength; i++) {
if (run.CreateDataFormat(model, address + i) is not PCS pcs) {
previousIsCap = false;
continue;
}
var isCap = IsCap(pcs.ThisCharacter);
if (previousIsCap && isCap) {
token.ChangeData(model, address + i, (byte)(model[address + i] - _A + _a));
}
previousIsCap = isCap;
}
token.ChangeData(model, address, model.TextConverter.Convert(new string(text), out var _));
}
private bool IsLetter(char c) {
return char.IsLetter(c);
}
private bool IsCap(char c) {
return 'A' <= c && c <= 'Z';
private bool IsCap(string c) {
if (c.StartsWith("\"")) c = c.Substring(1);
if (c.Length != 1) return false;
return 'A' <= c[0] && c[0] <= 'Z';
}
}
}

View File

@ -970,6 +970,16 @@ namespace HavenSoft.HexManiac.Tests {
Assert.IsType<PointerRun>(p2);
}
[Fact]
public void PointerToLocation_AddAnchorToPointer_NoError() {
ViewPort.Edit("<100> ");
ViewPort.Edit("@000 ^ ");
Assert.Null(Model.GetNextRun(0).PointerSources);
Assert.Empty(Errors);
}
private void StandardSetup(out byte[] data, out PokemonModel model, out ViewPort viewPort) {
data = new byte[0x200];
model = new PokemonModel(data);