Skip to content

Commit a97977d

Browse files
committed
Detect offset as hex or decimal value
1 parent 017ad88 commit a97977d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/main/java/com/romraider/xml/ConversionLayer/XDFConversionLayer.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* RomRaider Open-Source Tuning, Logging and Reflashing
3-
* Copyright (C) 2006-2022 RomRaider.com
3+
* Copyright (C) 2006-2025 RomRaider.com
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -42,6 +42,7 @@
4242

4343
import com.romraider.util.HexUtil;
4444
import com.romraider.util.ResourceUtil;
45+
import com.romraider.xml.RomAttributeParser;
4546

4647
public class XDFConversionLayer extends ConversionLayer {
4748
protected static final ResourceBundle rb = new ResourceUtil().getBundle(
@@ -67,7 +68,7 @@ private class EmbedInfoData {
6768
Node axisNode;
6869
Node flagsNodeTable;
6970
}
70-
71+
7172
@Override
7273
public String getDefinitionPickerInfo() {
7374
return rb.getString("LOADINGWARNING");
@@ -295,13 +296,13 @@ private Element parseAxis(Document doc, Element tableNodeRR, Node axisNode, Node
295296
targetTable.setAttribute("size" + id, "" + staticCells.size());
296297
targetTable.removeAttribute("endian");
297298
targetTable.removeAttribute("storagetype");
298-
299+
299300
for(String label : staticCells)
300301
{
301302
Element data = doc.createElement("data");
302303
data.setTextContent(label);
303304
targetTable.appendChild(data);
304-
305+
305306
if (numDigitsStatic == -1) {
306307
// Assume the format from the static data
307308
String split[] = label.split("\\.");
@@ -397,14 +398,14 @@ private Element getScalingNodeForTable(Element tableNodeRR) {
397398
private void postProcessTable(Element tableNodeRR) {
398399
int validAxis = 0;
399400
int nodeCountTable = tableNodeRR.getChildNodes().getLength();
400-
401+
401402
LinkedList <Element> nodesToRemove = new LinkedList <Element> ();
402403
for (int i = 0; i < nodeCountTable; i++) {
403404
Element n = (Element) tableNodeRR.getChildNodes().item(i);
404405
if (n.getNodeName().equalsIgnoreCase("table")) {
405406
if (n.hasAttribute("storageaddress") || n.getAttributeNode("type").getValue().contains("Static")) {
406407
validAxis++;
407-
408+
408409
// Use the sizes of the X and Y axis
409410
// for the main table
410411
Attr sizex = n.getAttributeNode("sizex");
@@ -416,7 +417,7 @@ else if (sizey != null)
416417
} else {
417418
Element scalingNode = getScalingNodeForTable(tableNodeRR);
418419
Element axisScalingNode = getScalingNodeForTable(n);
419-
420+
420421
// 2D Tables work different in XDFs
421422
// We have to use the unit of the "missing" axis for the main table
422423
if (scalingNode != null && axisScalingNode != null && !scalingNode.hasAttribute("units")) {
@@ -482,7 +483,14 @@ private Node parseXDFHeader(Document doc, Node romNode, Node header) {
482483
Node offsetNode = n.getAttributes().getNamedItem("offset");
483484

484485
if (offsetNode != null) {
485-
offset = Integer.parseInt(offsetNode.getNodeValue());
486+
String nv = offsetNode.getNodeValue();
487+
if (nv.length() > 2 && nv.substring(0, 2).equalsIgnoreCase("0x")) {
488+
// node value is hex in string format
489+
offset = RomAttributeParser.parseHexString(nv);
490+
} else {
491+
// node value is decimal in string format
492+
offset = Integer.parseInt(nv);
493+
}
486494

487495
if (!n.getAttributes().getNamedItem("subtract").getNodeValue().equals("0")) {
488496
offset *= -1;

0 commit comments

Comments
 (0)