CTR-ModSDK icon indicating copy to clipboard operation
CTR-ModSDK copied to clipboard

Online client: build using MinGW and CMake

Open iwanb opened this issue 1 year ago • 6 comments

This adds support to build the client using CMake and MinGW, so it can be cross-built on Linux. I re-used the nix setup that was done for the server (fun to see nix in this project!). I tested the built client, using MinGW. I don't have Windows/VisualStudio to build it on Windows.

I would like to look into porting the client to Linux and porting the memory map to PINE, but I thought it would be better if I can build and test the Windows one first, to compare and make sure I don't break things.

Most of the CMake file is from https://github.com/CTR-tools/CTR-ModSDK/pull/131

I had to do two changes to the client, one is to add #include <psapi.h> which seems harmless.

The second one is to change OpenFileMapping to OpenFileMappingW. This seems to be what's documented, but I'm not familiar with the Windows APIs so I'm not sure why it was needed (I assume for wide-char support) and whether it's fine for the Windows build. https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-openfilemappingw

iwanb avatar Jun 19 '24 20:06 iwanb

I have confirmed it builds successfully on Visual Studio 2022 and detects Duckstation on Windows just fine like before. 😀

Build started...
1>------ Build started: Project: Client, Configuration: Release x64 ------
1>callbacks.c
1>compress.c
1>host.c
1>list.c
1>packet.c
1>peer.c
1>protocol.c
1>unix.c
1>win32.c
1>CL_main.c
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(132,21): warning C4244: '=': conversion from 'unsigned short' to 'unsigned char', possible loss of data
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(62,20): warning C4133: 'initializing': incompatible types - from 'enet_uint8 *' to 'SG_Header *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(71,28): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageRooms *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(118,35): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageClientStatus *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(165,27): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageName *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(180,21): warning C4133: 'initializing': incompatible types - from 'char *' to 'Gamepad *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(192,28): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageTrack *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(213,32): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageCharacter *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(257,30): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_EverythingKart *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(289,20): warning C4133: 'initializing': incompatible types - from 'char *' to 'Gamepad *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(329,30): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageEndRace *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(337,20): warning C4133: 'initializing': incompatible types - from 'char *' to 'Gamepad *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(1048,20): warning C4018: '<': signed/unsigned mismatch
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(1064,41): warning C4133: 'function': incompatible types - from 'TCHAR [260]' to 'LPSTR'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(1130,10): warning C4133: 'function': incompatible types - from 'FILE *' to 'const char *const '
1>Generating code
1>Previous IPDB not found, fall back to full compilation.
1>All 114 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
1>Finished generating code
1>Client.vcxproj -> C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\x64\Release\Client.exe
1>Done building project "Client.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 6:06 AM and took 06.639 seconds ==========

FRDS avatar Jun 19 '24 23:06 FRDS

Tested again, this time with really running it. 🏁

You could add artefacts to the CI by adding to .github/workflows/main.yml:

      - name: Build Server Release Mingw2 GCC
        run: nix build -L --keep-going '.?submodules=1#online-server.release.mingw32.gcc' -o ${{ runner.temp }}/result/online-server.release.mingw32.gcc
+      - name: Build Client Release Mingw2 GCC
+        run: nix build -L --keep-going '.?submodules=1#online-client.release.mingw32.gcc' -o ${{ runner.temp }}/result/online-client.release.mingw32.gcc
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: online-server-windows
          path: |
            ${{ runner.temp }}/result/online-server.release.mingw32.gcc/bin
+            ${{ runner.temp }}/result/online-client.release.mingw32.gcc/bin

Yes I thought about doing that. On my machine I used the mingw64 build though. Not sure what is preferable?

iwanb avatar Jun 25 '24 18:06 iwanb

mingw64 build though.

Sorry, only yesterday I learned that the online client does not need to be built in 32 bits (PC port of the game needs)

Use the 64 one, that's what they're providing for users.

PedroHLC avatar Jun 25 '24 19:06 PedroHLC

I've updated it to build the new cpp and PINE based client. It needed a couple harmless changes, but I'm not 100% sure about the needed change in decompile/General/AltMods/OnlineCTR/global.h.

I could use the client (using wine) against the native linux Duckstation, but on linux duckstation uses a unix socket for pine while the client uses TCP so I had to proxy that using socat, running this on top of the client:

socat -d TCP-LISTEN:28011,fork UNIX-CONNECT:/run/user/1000/duckstation.sock

@TheUbMunster

iwanb avatar Jul 16 '24 20:07 iwanb

I'm not sure about global.h, as that static assert stuff wasn't mine.

TheUbMunster avatar Jul 16 '24 22:07 TheUbMunster

I'm not sure about global.h, as that static assert stuff wasn't mine.

looks right to me, it's inside the GCC/Clang pre-processor-branch, and if it detects window.h (so it has to be Mingw's GCC and not Linux's GCC) then it does the same thing it does on MSVC.

PedroHLC avatar Jul 19 '24 17:07 PedroHLC