rofl0r / agsutils

contains utils for AGS: game extractor, repacker, disassembler and assembler
44 stars 14 forks source link

busybox 32-bit compatibility #36

Closed xloem closed 9 months ago

xloem commented 9 months ago

These changes get the repository building on 32-bit busybox for me.

~I haven’t tried running it. I was curious to try to make a very simple one-room thing from scratch. Is there a template anywhere?~

The utilities are now working great for me and I understand they are incomplete.

rofl0r commented 9 months ago

i'm using busybox myself. it appears the issue in your version seems to be that printf must use parens - so the obvious fix would be to just add parens, rather than remodeling the string for print usage. you also modified hbmap.h, which is unrelated to busybox. what is the error you're getting without your modification, and which compiler version are you using ?

rofl0r commented 9 months ago

as far as "incomplete" goes - the utilities are meant to modify existing ags projects, not to create some from scratch. they also support only functionality that's relevant to the working of each of the tools. since we for example dont offer tools to modify fonts, everything related to fonts is just copied from old to new.

xloem commented 9 months ago

i'm using busybox myself. it appears the issue in your version seems to be that printf must use parens - so the obvious fix would be to just add parens, rather than remodeling the string for print usage.

The problem was that the % escapes were getting output verbatim into the minishilka file, such that %type became %%type and %%\n became %%%%\n, preventing parsing with either minishilka or dino shilka. This was hard for me to find, involving comprehending the shilka format from your code. I have busybox v1.33.1 on alpine linux 3.14.2 .

you also modified hbmap.h, which is unrelated to busybox. what is the error you're getting without your modification, and which compiler version are you using ?

The problem was that the value type was 4 bytes large on this 32-bit platform, preventing calculation of a correct bucket index when shifted left by 32 bits (see changed line). I tried to upcast it to the 64-bit return type to protect any intention of the code.

This gcc 10.3.1_git20210424 . The error presented as a warning but the impacted line seemed significant enough to warrant a fix: all the bits of the bucket index overflow.

2023-12-03-build.log

I may have done something wrong here, just trying to patch it together.

xloem commented 9 months ago

as far as "incomplete" goes - the utilities are meant to modify existing ags projects, not to create some from scratch. they also support only functionality that's relevant to the working of each of the tools. since we for example dont offer tools to modify fonts, everything related to fonts is just copied from old to new.

Thanks. They do still seem very useful for pursuing this. I tried it a little but ended up needing to make my own .dta encoder (I did make a little progress on this in python).

rofl0r commented 9 months ago

oh. that build log was really helpful. i fixed the actual bug in c77bca9

now i downloaded an alpine 3.14.2 x86 rootfs, but:

# busybox awk 'BEGIN{printf "%%type short\n%%%%\n";}'
%type short
%%

the output is as expected. maybe you installed a 3rd-party awk that's buggy ?

I tried it a little but ended up needing to make my own .dta encoder (I did make a little progress on this in python)

can you be a little more specific about what you're trying to do ?

xloem commented 9 months ago

oh. that build log was really helpful. i fixed the actual bug in c77bca9

Great!

# busybox awk 'BEGIN{printf "%%type short\n%%%%\n";}'
%type short
%%
iPad:~/src/agsutils# busybox awk 'BEGIN{printf "%%type short\n%%%%\n";}'
%%type short
%%%%
iPad:~/src/agsutils# sha256sum $(type -p busybox)
cdc8efe04df96dd7d386c6bca0a818874faf1943da493175afca0d89762eb40f  /bin/busybox
iPad:~/src/agsutils# apk version busybox
Installed:                                Available:
busybox-1.33.1-r8                       = 1.33.1-r8 

Maybe it is a bug in the iSH x86 emulator I am using, or a virus or something.

I'll open an issue with iSH.

I tried it a little but ended up needing to make my own .dta encoder (I did make a little progress on this in python)

can you be a little more specific about what you're trying to do ?

I thought I'd make a hello world game until I found windows somewhere some day. Something with a background picture and a character that moves where clickedM But it seemed it would be more productive to make a small part of a tool or library, unsure.

rofl0r commented 9 months ago
# apk upgrade busybox
(1/2) Upgrading busybox (1.33.1-r3 -> 1.33.1-r8)
Executing busybox-1.33.1-r8.post-upgrade
(2/2) Upgrading ssl_client (1.33.1-r3 -> 1.33.1-r8)
�Executing busybox-1.33.1-r8.trigger
OK: 6 MiB in 14 packages
pc:/# apk version busybox
Installed:                                Available:
busybox-1.33.1-r8                       = 1.33.1-r8
pc:/#  sha256sum $(type -p busybox)
cdc8efe04df96dd7d386c6bca0a818874faf1943da493175afca0d89762eb40f  /bin/busybox
pc:/# busybox awk 'BEGIN{printf "%%type short\n%%%%\n";}'
%%type short
%%%%

i updated to 1.33.1-r8 and the bug happens now. seems someone at alpine messed up seriously.

xloem commented 9 months ago

Thanks a bunch for figuring that out.

This is a really old Alpine release that comes bundled with iSH but I asked in discord and they said it is EOL and to install a new image. I’ll probably run my patch locally for now and change my system soon.

rofl0r commented 9 months ago

i talked to some alpine devs on IRC and since there's still builders for 3.14 i got the recommendation to file a bug report with the details from here on https://gitlab.alpinelinux.org/alpine/aports/-/issues

alternatively you can downgrade your busybox to -r3 like this:

https://www.arvanta.net/2x3d1kfg/x86/busybox-1.33.1-r3.apk
download and `apk add --allow-untrusted busybox-1.33.1-r3.apk

or extract the busybox binary from the 3.14.2 x86 "minimal rootfs" that's available from the alpine download site.

xloem commented 9 months ago

https://gitlab.alpinelinux.org/alpine/aports/-/issues/15539

rofl0r commented 9 months ago

the only commit i can find that potentially fixes it is https://git.alpinelinux.org/aports/commit/main/busybox?id=4ffd996b3f8298c7dd424b912c245864c816e354 it was never applied to busybox 1.33.1 though