armoha / euddraft

System for pluginizing eudplib codes.
Other
29 stars 4 forks source link

EPDCUnitMap() bug and enhancement #19

Closed Chromowolf closed 3 years ago

Chromowolf commented 3 years ago

Missing attribute flingyTurnRadius?

function afterTriggerExec() {
    const unitAddr = ......;
    const u = EPDCUnitMap(EPD(unitAddr));
    const fl = u.flingyTurnRadius;
}

[Error] 'flingyTurnRadius' Traceback (most recent call last): File xxx, line xxx, in afterTriggerExec const fl = u.flingyTurnRadius; File "C:\Py\lib\site-packages\eudplib-0.64.0-py3.8-win32.egg\eudplib\eudlib\epdoffsetmap.py", line 49, in getattr KeyError: 'flingyTurnRadius'

Attribute current_speed is actually current_speedX, which is CUnitAddr+0x40 Missing current_speedY, i.e. no attribute corresponds to CUnitAddr+0x44

const s = StringBuffer(1024);
s.printfAt(0, "current_speed={}, 0x40={}, 0x44={}", u.current_speed, dwread(unitAddr + 0x40), dwread(unitAddr + 0x44));

The same bug also goes for halt. halt and current_speed are both dword pairs (8 byte each).

Besides, to be consistent, more attributes could be added for 4-byte coordinate variables, like positionX, positionY. There are moveTargetPosition (4-byte), moveTargetX (2-byte), moveTargetY (2-byte) But there is only position, but no positionX, positionY Same for targetResource.

There may also be other potential bug in class EPDCUnitMap that I haven't found yet.

armoha commented 3 years ago

All entries in EPDCUnitOffsetMap: https://github.com/armoha/eudplib/blob/cb0ea1f7d7b86267ab65eb8db1ebe4fabdcf2d75/eudplib/eudlib/epdoffsetmap.py#L83

Missing attribute flingyTurnRadius?

Yeah, flingyTurnRadius (0x22, 1) seems missing.

Attribute current_speed is actually current_speedX, which is CUnitAddr+0x40 Missing current_speedY, i.e. no attribute corresponds to CUnitAddr+0x44 The same bug also goes for halt. halt and current_speed are both dword pairs (8 byte each).

point type CUnit members look incorrect.

        ("halt", 0x02C, 4),
        ("current_speed", 0x040, 4),

They should be

        ("haltX", 0x02C, 4),
        ("haltY", 0x030, 4),
        ("current_speedX", 0x040, 4),
        ("current_speedY", 0x044, 4),

.

Besides, to be consistent, more attributes could be added for 4-byte coordinate variables, like positionX, positionY. There are moveTargetPosition (4-byte), moveTargetX (2-byte), moveTargetY (2-byte) But there is only position, but no positionX, positionY Same for targetResource.

Using f_posread_epd would be best for reading those positional data. e.g. let u.position be a pair of (x, y) so const x, y = u.position; and add u.positionXY as dword value.