armoha / euddraft

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

StringBuffer.printfAt(), {:s} bug: reading 4-byte allignment #26

Closed Chromowolf closed 3 years ago

Chromowolf commented 3 years ago

The basemap's map name is "abcdef" Memory 0x6D0F91 stores the map name.

function afterTriggerExec() {
    const cp = getcurpl();
    setcurpl(getuserplayerid());
    const pp = StringBuffer(1024);

    pp.printfAt(0, "Map name, from0 = {:s}", 0x6D0F91); //Expected output: abcdef
    pp.printfAt(1, "Map name, from1 = {:s}", 0x6D0F92); //Expected output: bcdef
    pp.printfAt(2, "Map name, from2 = {:s}", 0x6D0F93); //Expected output: cdef
    pp.printfAt(3, "Map name, from3 = {:s}", 0x6D0F94); //Expected output: def
    pp.printfAt(4, "Map name, from4 = {:s}", 0x6D0F95); //Expected output: ef
    pp.printfAt(5, "0x6D0F90, 0x6D0F94 Hex = {}, {}", hptr(dwread_epd(EPD(0x6D0F90))),hptr(dwread_epd(EPD(0x6D0F94))));
    pp.printfAt(6, "strcmp = {}", strcmp(Db("abcdef"), 0x6D0F91)); //Expected output: 0

    setcurpl(cp);
}

Test result: image

Is this intended feature or bug? I'm expecting {:s} to read from the specified address, not from the alligned address.

armoha commented 3 years ago

It is bug only occur when addstr input is malaligned constant expression.

image

function afterTriggerExec() {
    setcurpl(getuserplayerid());
    const name = Db("\0aBcDeFgH") + 1;
    const dbg = StringBuffer(1024);
    var title = name + 2;

    foreach(i : py_range(5)) {
        const i2 = i + i;
        dbg.printfAt(i2, "name[{}..] = {:s}", i, name + i);
        dbg.printfAt(i2 + 1, "title[{}..] = {:s}", i, title + i);
    }
}

image

function afterTriggerExec() {
    setcurpl(getuserplayerid());
    const name = Db("\0aBcDe") + 1;
    const dbg = StringBuffer(1024);
    var title = name;

    for(var i = 0 ; i < 5 ; i += 1) {
        const i2 = i + i;
        dbg.printfAt(i2, "name[{}..] = {:s}", i, name + i);
        dbg.printfAt(i2 + 1, "title[{}..] = {:s}", i, title + i);
    }
}
armoha commented 3 years ago

Actually it is bug only for formatted print. dbg.printAt(i2, "name[", i, "..] = ", ptr2s(name + i)); works fine. "s" format always converts to "t", epd2s(EPD(constant)), missing check if constant is dividable by 4.

armoha commented 3 years ago

Fixed in new release 0.9.1.5: https://github.com/armoha/euddraft/releases/tag/v0.9.1.5 Thanks!

Chromowolf commented 3 years ago

Cannot compile. Maybe there is some file missing. image

image

image

armoha commented 3 years ago

__pycache__ is generated after compile so it is not related. I have no problem running 🤔 ![Uploading image.png…]()

Chromowolf commented 3 years ago

Weird... I deleted the __pycache__ and __epspy__ folders in my project folder, and then it could compile...... thx for the update