mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-10-01 20:56:36 -05:00
fix fairy script (when run twice)
Make it so that adding an additional copy of a constant will change the current byte to match the other bytes, so that the constant value remains the same.
This commit is contained in:
@@ -564,7 +564,12 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Visitors {
|
||||
model.ClearFormat(token, newArray.Start, array.Length);
|
||||
}
|
||||
}
|
||||
model.ClearFormat(token, newArray.Start, newArray.Length);
|
||||
|
||||
// clear any anchors that would be added as inner-pointers
|
||||
for (var nextRun = model.GetNextRun(newArray.Start); nextRun.Start < newArray.Start + newArray.Length; nextRun = model.GetNextRun(nextRun.Start + nextRun.Length)) {
|
||||
if (nextRun.Start == newArray.Start) continue;
|
||||
model.ClearAnchor(token, nextRun.Start, nextRun.Length);
|
||||
}
|
||||
model.ObserveRunWritten(token, newArray);
|
||||
|
||||
// if this run has pointers, those may have been cleared by some earlier update
|
||||
@@ -767,8 +772,18 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Visitors {
|
||||
ErrorText = "Cannot write constant with no name.";
|
||||
return;
|
||||
}
|
||||
var addresses = Model.GetMatchedWords(constantName);
|
||||
if (CurrentChange is not NoDataChangeDeltaModel && newValue == int.MinValue && addresses.Count > 0) {
|
||||
var valueSource = (WordRun)Model.GetNextRun(addresses[0]);
|
||||
int value = Model.ReadMultiByteValue(valueSource.Start, valueSource.Length);
|
||||
value /= valueSource.MultOffset;
|
||||
value -= valueSource.ValueOffset;
|
||||
Model.WriteMultiByteValue(memoryLocation, byteCount, CurrentChange, (value + offset) * multOffset);
|
||||
newValue = (value + offset) * multOffset;
|
||||
}
|
||||
|
||||
var coreValue = (Model[memoryLocation] / multOffset) - offset;
|
||||
// var coreValue = (Model[memoryLocation] / multOffset) - offset;
|
||||
var coreValue = Model.ReadMultiByteValue(memoryLocation, byteCount) / multOffset - offset;
|
||||
if (newValue != int.MinValue) coreValue = newValue / multOffset - offset;
|
||||
var maxValue = Math.Pow(2, byteCount * 8) - 1;
|
||||
if (coreValue < 0) {
|
||||
|
||||
@@ -28,12 +28,12 @@ namespace HavenSoft.HexManiac.Tests {
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConstantFormat_EnterNewConstantOnByteWithDifferentValue_OtherBytesChangeToMatchCurrentValue() {
|
||||
public void ConstantFormat_EnterNewConstantOnByteWithDifferentValue_CurrentValueCHangesToMatchConstant() {
|
||||
ViewPort.Edit("@100 03 @100 .some.number+1 ");
|
||||
|
||||
ViewPort.Edit("@000 .some.number ");
|
||||
|
||||
Assert.Equal(1, Model[0x100]);
|
||||
Assert.Equal(2, Model[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user