Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow combination of zip files with rayjs executable #5

Closed
EzzypooOfNazareth opened this issue Jan 17, 2024 · 6 comments

Comments

@EzzypooOfNazareth
Copy link

Feature request:

Love2d has a method for creating distributable files without exposing the underlying code. Their method involves combining a .zip or .love file into the project using the built in copy methods available on mac/windows/linux. I very much think this is a possibility for rayjs and would allow users to create exes without have js files adjacent to the rayjs executable. I attempted this method myself with rayjs and windows, however it was unable to find the js files.

The command I used to test
cmd /c copy /b rayjs.exe+main.js TestGame.exe

Love2d's distribution documentation

@mode777
Copy link
Owner

mode777 commented Jan 17, 2024

Hi @EzzypooOfNazareth , I actually thought about it a lot, even checked their code. However I couldn't figure out how Löve does this. If somebody has a hint, please let me know.

@EzzypooOfNazareth
Copy link
Author

EzzypooOfNazareth commented Jan 17, 2024

@mode777 I tried doing some digging around, as well as some research into the copy command, and from what I gather I think this is a (at least somewhat accurate) run-through of how love2d handles archive files.

  1. It looks like the copy commands copies a binary into the exe itself. This binary can be parsed using a library like physfs.
  2. When love starts its bootup process, it checks whether the file is an archive, or a .lua file and copies that into a temporary memory location (looks like the bulk of that process is done here as well as in love.cpp and boot.lua)
  3. If the file is an archive then it uses physfs to read the temporary storage in memory and parses it into the correct format for the lua runtime.

Seems like this might be a huge undertaking to get it to work in a stable way on multiple operating systems. I'm by far no expert in this kind of coding, but I'll try and help in whatever way I can.

@jcnmsg
Copy link

jcnmsg commented Jan 20, 2024

It's fairly trivial to do this on Linux using makeself. Shouldn't be too hard to replicate on Windows using powershell and 7zip but I don't have a Windows machine ready at the moment. I've edited this comment because I originally suggested using shareutils as well but it was too convoluted and the final user would have to have it installed on their system for it to work.

Just bundle the final game directory containing rayjs and main.js with makeself ./game mygame "Final game" ./rayjs. You can safely distribute the resulting file and run it by double clicking or ./mygame on your terminal.

Let me hear your thoughts!

@EzzypooOfNazareth
Copy link
Author

I did several attempts with makeself on windows through cygwin. Wasn't able to get it to work, but I do think this could be a good approach, I'm going to try playing around more with makeself and some alternatives and see if I can find something that works.

@jcnmsg
Copy link

jcnmsg commented Jan 22, 2024

I don't think you'll be able to use makeself on Windows, as it is intended for Unix-like systems only. I fiddled a little bit on my Windows machine and was able to compile an executable using NSIS.

  1. Zip your game directory into a normal zip file (in my case, release.zip);
  2. Create a installer.nsi script as follows:
Outfile "MyGame.exe"
SilentInstall silent

Section
SetOutPath $TEMP
File ".\release.zip"
    nsExec::Exec '"powershell" -WindowStyle hidden -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -Path $TEMP\release.zip -Destination $TEMP"'
    nsExec::Exec '"powershell" -NoProfile -ExecutionPolicy Bypass -WindowStyle hidden -Command "$TEMP\release\rayjs.exe"'
SectionEnd
  1. Run via powershell: makensis installer.nsi

If you run the resulting MyGame.exe, it will auto-extract your game contents to a temporary folder, typically C:\Users\$UserName\AppData\Local\Temp and run rayjs.exe automatically.

I don't know how to hide the raylib console, it's always present on Windows for some reason. On linux I just added the --nox11 as a makeself parameter and it was gone when I launched rayjs. Just updated the script to hide both powershell consoles that might have flashed blue before as well as raylib's console.

@mode777
Copy link
Owner

mode777 commented Feb 5, 2024

Sorry for the delay. I actually thought about this a lot and I think it would be a nice feature to have. Ideally having this functionality built in the actual executable so you can generate these on the fly. However, other than Löve2D, raylib cannot run on zip-files. Even if we can fuse the main.js with the rayjs.exe we still need assets and other scripts to bundle as well. Love can use a zip file as a virtual file system, while I don't think that would be straightforward to add. While it would be possible to implement this in rayjs, I am trying to stick as close to raylib API as possible. So by now I don't think this will be possible.

@mode777 mode777 closed this as completed Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants