danoon2 / Boxedwine

Emulator that can run 32-bit Windows programs/games on multiple platforms via Wine
GNU General Public License v2.0
767 stars 65 forks source link

Game(s) running on Boxedwine for Windows but not on web (Touhou: Embodiment of Scarlet Devil) #94

Open andrigamerita opened 1 month ago

andrigamerita commented 1 month ago

Hi, I've been experimenting a lot with this project in the last days. It seems like a pretty neat option for running games on Linux without the hassle of setting up Wine. However, what interests me the most is not the desktop version of Boxedwine, but in fact the web one. And, while general program incompatibilities due to Wine are to be expected, I'm experiencing some really strange inconsistencies between the desktop (Windows x64) version of Boxedwine, and the web one running with proper WASM (in the latest versions of both Firefox and Chromium).

There's one game in particular that I've tried on desktop Boxedwine and have seen it be very playable, and then not even being able to start on the web, and that's "Touhou: Embodiment of Scarlet Devil" (from 2002). But I fear there might be a lot more software that I've tried on web Boxedwine with zero to insufficient success, that maybe will run fine on desktop, but that I've not yet been able to try. Yet, the fact that even just one software behaves differently between the emulator builds points to a probable fault in the emulator itself.

I tried this Touhou game with the following versions of the Wine filesystems downloaded directly from the desktop launcher, with both the Windows x64 and web build of Boxedwine taken from the zip of the latest workflow on your Jenkins server (master#70 as of now), and these are the results on Windows:

Instead, as I said, the game fails to start on web with the exact same file systems and build version. The emulator throws an exception and crashes entirely. The bad behaviour is a bit different on different Wine versions, but overall the outcome is the same; for example, this is the console log when trying to run the game on 5.0, which on desktop just works but here does this:

Browser log ``` running initial setup setting auto run to: false setting root zip file to: Wine5.0-debian10.zip not setting app zip file not setting program to execute setting sound to: true setting BPP to: 32 setting ondemand to: notset setting skipFrameFPS to: 0 setting DirectDrawRenderer to: gdi not setting cdrom iso image not setting Resolution Use Storage mode: MEMORY Unable to delete:/lib/wine/wineboot.exe.so error:Error: ENOENT: No such file or directory., '/lib/wine/wineboot.exe.so' Unable to find DirectDrawRenderer in user.reg Emulator params:-root,/root/base,-mount_drive,/root/files/,d,-nozip,-w,/home/username/.wine/dosdevices/d:,/bin/wine,th06e.exe Starting ... Command line arguments: "./this.program" "-root" "/root/base" "-mount_drive" "/root/files/" "d" "-nozip" "-w" "/home/username/.wine/dosdevices/d:" "/bin/wine" "th06e.exe" Using root directory: /root/base Launching "/bin/wine" "th06e.exe" 000b:err:module:__wine_process_init L"C:\\windows\\system32\\wineboot.exe" not found 0009:err:environ:run_wineboot failed to start wineboot c0000135 0009:err:winediag:MIDIMAP_drvOpen No software synthesizer midi port found, Midi sound output probably won't work. indirect call to null @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[3956]:0x14aacc @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[3672]:0x139545 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[1683]:0x89db7 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[1697]:0x8a314 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[1683]:0x89db7 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[1683]:0x89db7 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[1683]:0x89db7 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[1683]:0x89db7 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[1883]:0x9327c @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[3543]:0x134131 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[3539]:0x133a27 @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[3109]:0x124abf @https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.wasm:wasm-function[3817]:0x140bc8 callUserCallback@https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.js:1:98479 runIter@https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.js:1:99901 Browser_mainLoop_runner@https://hlb0.octt.eu.org/Misc/BoxedWine/boxedwine.js:1:97959 ```

It's curious to note that on Wine1.7.55-v8 (the file system from boxedwine.org) I don't get an emulator crash, but rather the program terminates with an error that, translated from japanese to english, roughly reads like the following:

Touhou action record
T&L HAL appears to be unavailable
HAL does not appear to be available.
Try making the back buffer unblockable.
The T&L HAL does not appear to be a usable HAL
It doesn't even look usable
Direct3D initialization failed, game cannot be played.

Anyways, the last thing I noticed about this game is that it doesn't work even on Boxedwine for Windows if I use Mesa graphics instead of the Default one. Specifically, the emulator crashes on there too, but I can't really understand if that's related to the web crashes. Perhaps software graphics instead of native are the problem, since I assume on Web native graphics can't be used? I ran the emulator under normal Wine on my Debian Linux system to generate a stack trace, since on Windows the emulator just crashes silently:

Native stack trace ``` Unhandled exception: page fault on execute access to 0x0000000000000000 in 64-bit code (0000000000000000). Register dump: rip:0000000000000000 rsp:000000000692f718 rbp:0000000000000000 eflags:00010246 ( R- -- I Z- -P- ) rax:0000000000000008 rbx:00000001404f31e8 rcx:000000000692f750 rdx:0000000000000000 rsi:0000000000000000 rdi:0000000031ba82e0 r8:0000000000000060 r9:0000000000000060 r10:0000000140000000 r11:00000001403a8256 r12:0000000000000000 r13:0000000000000000 r14:000000000692f970 r15:0000000000000000 Stack dump: 0x0000000692f718: 0000000140207a9f 0000000000000009 0x0000000692f728: 0000000000000085 0000000000000001 0x0000000692f738: 000000000692f800 000000000692f970 0x0000000692f748: 00000001403915f1 0000000100000022 0x0000000692f758: 0000000000000030 0000000000000031 0x0000000692f768: 0000000000000032 0000000000000000 0x0000000692f778: 0000000000000000 0000000000000000 0x0000000692f788: 0000000000000000 0000000000000000 0x0000000692f798: 0000000000000000 0000000000000000 0x0000000692f7a8: 0000000000000000 0000000000000000 0x0000000692f7b8: 0000000000000000 0000000000000000 0x0000000692f7c8: 0000000000000000 0000000000000000 Backtrace: =>0 0000000000000000 (0000000000000000) 0000000000000000: -- no code accessible -- Modules: Module Address Debug info Name (121 modules) PE 000000007a800000-000000007a909000 Deferred opengl32 PE 000000007b600000-000000007b65d000 Deferred kernel32 ELF 000000007d000000-000000007d005000 Deferred PE 0000000140000000-0000000140965000 Deferred boxedwine_console PE 0000000170000000-00000001700a3000 Deferred ntdll PE 0000000174000000-0000000174299000 Deferred kernelbase PE 00000001d0e20000-00000001d0f5d000 Deferred oleaut32 PE 00000001d8c90000-00000001d8cd3000 Deferred advapi32 PE 00000001de160000-00000001de202000 Deferred urlmon PE 00000001eaf60000-00000001eaf8a000 Deferred sechost PE 000000020b860000-000000020b980000 Deferred ole32 PE 000000020f400000-000000020f42b000 Deferred mmdevapi PE 00000002169d0000-0000000216b7c000 Deferred user32 PE 0000000222ed0000-0000000222fda000 Deferred comdlg32 PE 0000000223d50000-0000000223d80000 Deferred winspool PE 0000000228280000-000000022831b000 Deferred msvcrt PE 0000000235120000-000000023512f000 Deferred msacm32 PE 000000023bc00000-000000023c52a000 Deferred shell32 PE 0000000250cd0000-0000000250cef000 Deferred mpr PE 0000000251d80000-0000000251db2000 Deferred winex11 PE 000000025dc30000-000000025dc3e000 Deferred version PE 000000026c230000-000000026c266000 Deferred uxtheme PE 0000000270f60000-000000027130e000 Deferred d3d9 PE 0000000284ea0000-0000000284ead000 Deferred powrprof PE 00000002945e0000-00000002946a4000 Deferred winmm PE 00000002a2380000-00000002a23db000 Deferred shlwapi PE 00000002bb0a0000-00000002bb121000 Deferred gdi32 PE 00000002bde30000-00000002bde4b000 Deferred shcore PE 00000002c73a0000-00000002c73d9000 Deferred win32u PE 00000002c7470000-00000002c7534000 Deferred ucrtbase PE 00000002eb230000-00000002eb25f000 Deferred winepulse PE 00000002fb3c0000-00000002fb50d000 Deferred comctl32 PE 00000002fda10000-00000002fda44000 Deferred winealsa PE 0000000313390000-00000003133ae000 Deferred compstui PE 000000031c5d0000-000000031c62d000 Deferred combase PE 0000000343520000-000000034357d000 Deferred dsound PE 0000000345640000-00000003456c2000 Deferred wininet PE 0000000351a60000-0000000351a80000 Deferred msacm32 PE 0000000368420000-00000003684ab000 Deferred rpcrt4 PE 000000036d860000-000000036d8df000 Deferred setupapi PE 0000000370f70000-0000000370f98000 Deferred ws2_32 PE 00000003874b0000-00000003874bd000 Deferred midimap PE 0000000393730000-000000039374a000 Deferred imm32 ELF 00007f03f7400000-00007f03fbf1d000 Deferred libllvm-15.so ELF 00007f0431971000-00007f043197d000 Deferred libpciaccess.so.0 ELF 00007f043197d000-00007f04319be000 Deferred libtinfo.so.6 ELF 00007f04319be000-00007f04319e4000 Deferred libdrm_intel.so.1 ELF 00007f04319e4000-00007f0431a00000 Deferred libelf.so.1 ELF 00007f0431a00000-00007f0433b4a000 Deferred radeonsi_dri.so ELF 00007f0433b54000-00007f0433b61000 Deferred libdrm_amdgpu.so.1 ELF 00007f0433b61000-00007f0433b6f000 Deferred libdrm_radeon.so.1 ELF 00007f0433b6f000-00007f0433b7a000 Deferred libdrm_nouveau.so.2 ELF 00007f0433b7a000-00007f0433c3d000 Deferred libzstd.so.1 ELF 00007f0433c3d000-00007f0433c48000 Deferred libxcb-xfixes.so.0 ELF 00007f0433c48000-00007f0433c52000 Deferred libxcb-sync.so.1 ELF 00007f0433c52000-00007f0433c57000 Deferred libxcb-present.so.0 ELF 00007f0433c57000-00007f0433c5e000 Deferred libxcb-dri3.so.0 ELF 00007f0433c5e000-00007f0433c72000 Deferred libxcb-randr.so.0 ELF 00007f0433c72000-00007f0433c77000 Deferred libxshmfence.so.1 ELF 00007f0433c77000-00007f0433c7c000 Deferred libxcb-shm.so.0 ELF 00007f0433c7c000-00007f0433c83000 Deferred libxcb-dri2.so.0 ELF 00007f0433c83000-00007f0433ca1000 Deferred libxcb-glx.so.0 ELF 00007f0433ca1000-00007f0433cba000 Deferred libdrm.so.2 ELF 00007f0433cba000-00007f0433cef000 Deferred libglapi.so.0 ELF 00007f0433cef000-00007f0433d62000 Deferred libglx_mesa.so.0 ELF 00007f0433d62000-00007f0433e1b000 Deferred libgldispatch.so.0 ELF 00007f0433e1b000-00007f0433e4e000 Deferred libglx.so.0 ELF 00007f0433e4e000-00007f0433edc000 Deferred libgl.so.1 ELF 00007f0433edc000-00007f0433fee000 Deferred libasound.so.2 ELF 00007f0433ffe000-00007f043405d000 Deferred libopus.so.0 ELF 00007f043405d000-00007f0434108000 Deferred libvorbisenc.so.2 ELF 00007f0434108000-00007f0434137000 Deferred libvorbis.so.0 ELF 00007f0434137000-00007f0434179000 Deferred libflac.so.8 ELF 00007f0434179000-00007f0434200000 Deferred libsndfile.so.1 ELF 00007f0434200000-00007f0434660000 Deferred libcrypto.so.3 ELF 00007f0434661000-00007f0434666000 Deferred libx11-xcb.so.1 ELF 00007f0434666000-00007f043467f000 Deferred winealsa.so ELF 00007f043467f000-00007f043468a000 Deferred libogg.so.0 ELF 00007f043468a000-00007f0434706000 Deferred libpulsecommon-17.0.so ELF 00007f0434706000-00007f0434758000 Deferred libpulse.so.0 ELF 00007f0434758000-00007f043476d000 Deferred winepulse.so ELF 00007f043476d000-00007f0434815000 Deferred libssl.so.3 ELF 00007f0434815000-00007f04348b5000 Deferred libcups.so.2 ELF 00007f043490b000-00007f0434913000 Deferred libxfixes.so.3 ELF 00007f0434913000-00007f0434920000 Deferred libxcursor.so.1 ELF 00007f0434920000-00007f0434934000 Deferred libxi.so.6 ELF 00007f0434934000-00007f0434a7c000 Deferred libx11.so.6 ELF 00007f0434a7c000-00007f0434b0d000 Deferred winex11.so ELF 00007f0434b0d000-00007f0434c4b000 Deferred opengl32.so ELF 00007f0434c4b000-00007f0434c5b000 Deferred libffi.so.8 ELF 00007f0434c5f000-00007f0434c64000 Deferred libxcomposite.so.1 ELF 00007f0434c64000-00007f0434c71000 Deferred libxrandr.so.2 ELF 00007f0434c71000-00007f0434c7e000 Deferred libxrender.so.1 ELF 00007f0434c7e000-00007f0434c85000 Deferred libxxf86vm.so.1 ELF 00007f0434c85000-00007f0434cb1000 Deferred libxcb.so.1 ELF 00007f0434cb1000-00007f0434cc5000 Deferred libxext.so.6 ELF 00007f0434cc5000-00007f0434dff000 Deferred libp11-kit.so.0 ELF 00007f0434e00000-00007f0434e05000 Deferred libxinerama.so.1 ELF 00007f0434e05000-00007f0434e0b000 Deferred libxau.so.6 ELF 00007f0434e0d000-00007f0434e13000 Deferred ws2_32.so ELF 00007f0434e13000-00007f0434e19000 Deferred winspool.so ELF 00007f0435061000-00007f043508e000 Deferred libexpat.so.1 ELF 00007f043508e000-00007f04350dc000 Deferred libfontconfig.so.1 ELF 00007f04350dc000-00007f0435124000 Deferred libpcre.so.1 ELF 00007f0435124000-00007f0435147000 Deferred libbrotlicommon.so.1 ELF 00007f0435147000-00007f043516b000 Deferred libgraphite2.so.3 ELF 00007f043516b000-00007f04352a5000 Deferred libglib-2.0.so.0 ELF 00007f04352a5000-00007f04352b2000 Deferred libbrotlidec.so.1 ELF 00007f04352b2000-00007f04353bb000 Deferred libharfbuzz.so.0 ELF 00007f04353bb000-00007f04353f5000 Deferred libpng16.so.16 ELF 00007f04353f5000-00007f0435409000 Deferred libbz2.so.1 ELF 00007f0435409000-00007f04354ca000 Deferred libfreetype.so.6 ELF 00007f04354ca000-00007f0435688000 Deferred win32u.so ELF 00007f0435988000-00007f0435b00000 Dwarf libwine.so.1 ELF 00007f0435e81000-00007f0435f64000 Deferred libm.so.6 ELF 00007f0435fbb000-00007f0435fd6000 Deferred libz.so.1 ELF 00007f0435fd6000-00007f0436000000 Deferred liblzma.so.5 ELF 00007f0436226000-00007f0436247000 Deferred libgcc_s.so.1 ELF 00007f0436247000-00007f0436262000 Deferred libunwind.so.8 ELF 00007f0436262000-00007f043632d000 Deferred ntdll.so ELF 00007f0436342000-00007f043637b000 Deferred ld-linux-x86-64.so.2 Threads: process tid prio name (all IDs are in hex) 00000038 services.exe 0000003c 0 00000040 0 wine_rpcrt4_server 0000004c 0 wine_rpcrt4_io 00000078 0 wine_rpcrt4_io 000000b0 0 wine_rpcrt4_io 000000c8 0 wine_rpcrt4_io 000000e0 0 wine_rpcrt4_io 00000044 winedevice.exe 00000048 0 00000054 0 00000058 0 wine_sechost_service 00000064 0 00000068 0 0000006c 0 000000d4 0 0000005c explorer.exe 00000060 0 00000098 0 0000009c 0 wine_rpcrt4_server 00000070 winedevice.exe 00000074 0 0000007c 0 00000080 0 wine_sechost_service 00000084 0 00000088 0 0000008c 0 00000090 0 00000094 0 000000a8 plugplay.exe 000000ac 0 000000b4 0 000000b8 0 wine_sechost_service 000000bc 0 wine_rpcrt4_server 000000c0 svchost.exe 000000c4 0 000000cc 0 000000d0 0 wine_sechost_service 000000d8 rpcss.exe 000000dc 0 000000e4 0 000000e8 0 wine_sechost_service 000000ec 0 wine_rpcrt4_server 000000f0 0 wine_rpcrt4_server 000000f4 0 wine_rpcrt4_io 00000104 Boxedwine_console.exe 00000108 0 00000288 0 dxvk-submit 0000028c 0 dxvk-queue 00000290 0 dxvk-cs 00000294 0 dxvk-frame 00000298 -2 dxvk-shader-l 0000029c -2 dxvk-shader-n 000002a0 -2 dxvk-shader-h 000002a4 -2 dxvk-shader-h 000002b0 0 0000010c conhost.exe 00000110 0 000002a8 (D) Z:\run\user\1000\doc\ee5c4c3c\Boxedwine_console.exe 000002ac 0 000002bc 0 <== 000002c8 0 000002e0 0 000002e4 0 000002ec 0 000002f0 0 000002fc 0 00000300 0 00000308 0 0000030c 0 00000310 0 00000314 0 00000318 0 00000320 0 00000324 0 00000328 0 0000032c 0 00000334 0 00000338 0 0000033c 0 00000340 0 00000344 0 winealsa_midi_notify 000002b4 conhost.exe 000002b8 0 System information: Wine build: wine-8.0.2 Platform: x86_64 Version: Windows 7 Host system: Linux Host version: 6.1.0-21-amd64 ```

In case you need to test with this specific game to replicate, I am maintaining a page on my private server with a special UI to help myself with testing of Boxedwine web in general: https://hlb0.octt.eu.org/Misc/BoxedWine/. (I'm trying to collect as many different Wine filesystems and working apps on there so that I can rapidly verify is some things work or not, and I've done these tests on there.)

danoon2 commented 1 month ago

"Direct3D initialization failed, game cannot be played."

The web version definitely does not support 3d graphics. So far we haven't found a way to map OpenGL to WebGL and Wine converts Direct3D to OpenGL.

Looking at https://en.touhouwiki.net/wiki/Embodiment_of_Scarlet_Devil It seems like that game required 3D so it won't work on the web build. But I am happy to hear that it works on the Windows build.

For 2d games, the web build will work if GDI rendering is enabled in Wine, which the web build tries to do. Starting in Wine 6 ,how GDI is set changed which explain "Unable to find DirectDrawRenderer in user.reg" if you were trying to use Wine 6 the web build.

danoon2 commented 1 month ago

Since you are using Wine 6, I assume you are building from source.

Recently I started caching more files to the host file system (not web build). Previously if an app or wine opened a file for writing, I would copy it from the zip file system to the host file system and open it. Now I do that for reads as well. This does something interesting beside improving start up times, it also allows you to see what files are necessary to build a custom file system. You can just zip up the local root directory and use that as a web file system. I did this for a dotnet 2 proof of concept based on the Wine 6 filesystem and result was a custom file system only 30MB.

https://boxedwine.org/dotnet2/boxedwine.html?app=SolitaireDotNet2&p=Solitaire.exe

andrigamerita commented 1 month ago

@danoon2 Thanks for the explanation. So the OpenGL support must be implemented first for this and other games to work.. in theory I guess software rendering could be used, but that's just an hypotetical, since it would be so slow to be unplayable due to the interpreted emulation. Kind of a shame because this specific game doesn't really use 3D graphics, it's all 2D, but the developer used DirectX and now we're stuck with it.

About Wine 6.0, no, I didn't compile from source! I took the ZIP directly downloaded from the desktop launcher (the version without Mono and Gecko), and I was surprised to see that it actually works on web, albeit slowly both in loading (big ZIP) and execution (a bit slower than 5.0 I reckon). Some programs only work on there, like the latest version of the foobar2000 music player (which is unusable on web anyways because it runs too slow, even just PCM audio is crackly despite it being uncompressed, oh well, I tried). I will surely try out the file logging feature by the way, that could indeed be very useful to create small app-specific packages.

kungfooman commented 1 month ago

At the end of the day, we need to generate either WebGL or WebGPU calls and luckily this work has already been done: https://github.com/ptitSeb/gl4es

The only way to circumvent something like gl4es is by implementing a pure GLES renderer for each game individually (often games come with renderer_dx7.dll, renderer_opengl1.dll and then just go for a simple pass-through for your custom renderer DLL).

I tested around the last days mostly with @ptitSeb's box86 to emulate old GL1 games on a Raspberry Pi 4 and it works surprisingly well. It would be amazing to have an easy-to-debug dev environment like that inside a web browser too if these projects could work together somehow :pray:

kevodwyer commented 1 month ago

I work on the web build and am aware of gl4es and some years back attempted to integrate it. I got some simple GL programs to work I raised an issue against emscripten against one of the issues encountered at the time, but nothing came of it.

kungfooman commented 1 month ago

@kevodwyer Wow, too cool! I will try it tomorrow with Call of Duty 1 Demo on archive.org, would be nice to get it even half-broken to work for further testing lol

I assume you mean this issue? https://github.com/emscripten-core/emscripten/issues/12082

kungfooman commented 1 month ago

So I tested CoDSP.exe with your gl4es for boxedwine version, but now it lacks ddraw.dll, which a newer boxedwine version offers and I couldn't figure out how to merge the required stuff :cry:

@kevodwyer Would there be any chance to link to your source code? Just found it: https://github.com/danoon2/Boxedwine/tree/emscripten/use-gl4es

kevodwyer commented 1 month ago

The experiment I performed is at a dead-end and very out-of-date. It was enough to prove that it is possible, but I don't have the skills in OpenGL, gl4es or emscripten internals to take it any further.