A small plugin to open URL in a browser, made for AGS 3.6.0 and beyond.
(the plugin uses SDL2, so if you are using a previous version of ags, you have to add SDL2 somewhere)agsappopenurl_windows.zip (https://github.com/ericoporto/agsappopenurl/releases/download/v.0.2.0/agsappopenurl_windows.zip) |
agsappopenurl_linux.tar.gz (https://github.com/ericoporto/agsappopenurl/releases/download/v.0.2.0/agsappopenurl_linux.tar.gz) |
agsappopenurl_macos.zip (https://github.com/ericoporto/agsappopenurl/releases/download/v.0.2.0/agsappopenurl_macos.zip)
You call it like this:
AppOpenURL(eAUrlProto_https, "itch.io");
And it should open the itch website in a browser tab.
The idea is to use this plugin instead of the agsshell plugin - for safety reasons and better cross-platform support. In Linux and Windows It uses SDL2 behind the scenes, so it can't run in older versions of AGS.
(well you would have to add SDL2 somewhere if using an old ags version)- v.0.2.0 - macOS builds of the plugin no longer depends on SDL2.
- v.0.1.0 - first release!
Quote from: eri0o on Sun 26/02/2023 19:49:20It uses SDL2 behind the scenes, so it can't run in older versions of AGS.
I think it should be possible to load SDL if it was not loaded yet, and thus support both engine with SDL and one without?
theoretically yes, but hopefully people can move to ags 3.6.0. But like, if SDL2.dll is on the same directory it should work already, at least on Windows.
And I had made a mistake on the original release, but made a quick fix and reuploaded things.
Works fine, many thanks for this! ;-D
(Well it works unless you're stupid like me and accidentally put the full URL inside the ""...)
That's good! For now I am logging the messages that says why something fails - perhaps I could span error messages, at least until some logging feature makes into the Editor.
I believe until next weekend I can make some prebuilt binaries to be available beyond the Windows one and then need to setup CI in the project to automate the builds of the plugin.
I am forcing the protocol selection through enum to enforce using it to open webpages, and maybe if someone makes a case for other specific protocol we may allow or not - of course there's nothing blocking someone from modifying the plugin source to do whatever.
As you predicted there is no delay whilst the page loads as per AGS Shell, so people should definitely add a Wait command to avoid multiple tabs of a page opening from a single click (or use some other method of avoiding this happening).
I had pondered whether it would be good to force the link to open in the Steam client itself, but not sure how useful that would be in truth as the main use is probably linking to the Steam Page from a demo, which is quite likely to have been opened from the Steam client anyway.
Ahn, maybe I totally misunderstood the question you sent me. Is the delay in the plugin something we want or not? :-\
About the Steam mention, does this need some special Steam specific protocol (steam:// ??) or is just a link to the store steampowered website?
Quote from: CaptainD on Mon 27/02/2023 17:01:40As you predicted there is no delay whilst the page loads as per AGS Shell, so people should definitely add a Wait command to avoid multiple tabs of a page opening from a single click (or use some other method of avoiding this happening).
Why would this happen in the first place? Button's click event is only sent once per click, same is for object interaction events. So I'd imagine such behavior may occur only if you call the function in repeatedly_execute, where you check for mouse button down state?
@eriOo - no confusion apart from any I've caused, it works exactly as you described whereas the Shell command only worked once the previous request had been fully processed by the browser. CW has me bang to rights, in this particular instance I have code in Repeatedly_Execute which is why I need to add the Wait() command.
Basically, your mod does exactly what it says on the tin, just a weird thing I'm doing in that particular room causing the issue I mentioned. Thanks again!
Hey! I am re-releasing this plug-in.
Added new download links at the top, now Linux and macOS builds are also included!
I have added a CI environment to my repository, hopefully with automated builds means anything that comes up will be easy to fix and produce a new release.
Edit: seconds after I noticed I made a small mistake in the code in the original version... I have remade the release and re-re-released! It only took me 50 commits in 6 hours to get this right 8-)
Would it be possible to use the plugin to make an http request and get the result, instead of showing the page?
Something like: String str = AppOpenURL(eAUrlProto_https, "itch.io");
No, this would be an entirely different plugin. It would be something based in libcurl and need to be an unblocking request. I have thought about this in the past, what exactly you are trying to accomplish?
Quote from: eri0o on Tue 14/03/2023 14:34:26I have thought about this in the past, what exactly you are trying to accomplish?
I wanted to create an online hi-score chart.
I would create an API to post the score, like https:/// something.com/postscore.php?score=XXXX&user=USER (PUT possibly, not GET). This will be called when the user completes the game.
Then, the game can call another API to get the top 10, like https:// something.com/gethiscore.php (result can be in CSV or json, not sure what is better). And the game will show the best scores.
Of course, once you have the curl, you can use it for many other things (loading user-generated levels for example). Or simply ask the server if there is a new version of the game.
I'm thinking that I can implement the online high score chart with the current plugin. I can simply use:
AppOpenURL(eAUrlProto_https, "mysite.com/score.php?score=12121&user=USER");
this will post the score and show the current chart on the browser tab. I won't be able to show the chart in a game room, only on the browser, but it should be fine.
Do you see problems if I pass some parameters in get in AppOpenURL?
I encountered a bug with the Mac version of this plug-in (works fine with the Windows version). The error did mention trying to find a SDL library, which I think it built into the version of the AGS shell I create (currently built from 3.6.1 Patch 3). I will need to get the specific error I encountered to see if it makes more sense why it is not working.
Quote from: eri0o on Sun 26/02/2023 19:49:20A small plugin to open URL in a browser, made for AGS 3.6.0 and beyond. (the plugin uses SDL2, so if you are using a previous version of ags, you have to add SDL2 somewhere)
The idea is to use this plugin instead of the agsshell plugin - for safety reasons and better cross-platform support. It uses SDL2 behind the scenes, so it can't run in older versions of AGS. (well you would have to add SDL2 somewhere if using an old ags version)
Spoiler
Uhm, I don't have time to actually run and test right now, but just to explain something. The way this plugin works currently for actually opening the browser is using a function in SDL2. I can reimplement it here though to avoid using it but just to explain that the necessary function is not in the plugin itself but in the SDL2 shared library. That function is not used by AGS - I actually wanted to add it to AGS itself but people were worried about it so I didn't.
Anyway now the Windows version of AGS uses the SDL2.dll and the Linux version also just uses the libsdl2.so (or something similarly named).
On macOS though, the first port had the SDL2 framework binary inside AGS and it was necessary to run a command to fix the rpath for AGS to look for the SDL2 framework in the bundle instead of the system. Now despite explaining this many times, essentially no one seemed to understand, and people made games that ran on their manchines but wouldn't run on people's PC. At the time the SDL2 version of AGS (3.6.0) was shaping up for release Apple also had the Apple Silicon (ARM) macOS Machines going. And at that time the SDL2 prebuilt framework was still Intel only.
So I did a change in the macOS projects, and the CMake macOS project just builds SDL2 as a static library and links it - it's possible that an unused function disappears later - I am not super sure here because SDL2 has a weird dynapi thing, but this may be something that is happening.
Now the Xcode project I don't remember what was eventually settled, I believe it's currently including the SDL2 framework inside of it, but would need to check. The macOS Makefile project dynamically links to SDL2 - you just brew install all dependencies and later if you want to make a bundle from the Makefile build you have to manually copy the things in the bundle and adjust the rpath of them.
I know that the iOS Xcode project I made it build from SDL2 source because the framework just wasn't compatible with multiple targets (iPad, iPhone, simulator, tvOS, ...), so building from source was the way and the iOS Xcode project is linking to it statically.
Anyway, of course having the error message would be helpful. Ah, you can add the plugin to the Xcode project and ensure it links to it at build time.
I am looking into building the AGS macOS port in the CI instead - like beyond checking that it's all building like it currently is but to make actual AGS macOS binary releases people can use - and this was a good reminder to think on how this should be done.
Edit: actually forgot one thing, if this is really the issue and you need to quickly fix, I believe SDL2 supports having the statically linked library and having a shared library available, it has something inside that will make it redirect the calls for the static library to the shared one.
Spoiler
@edenwaith I wrote a version of the plugin that doesn't depend on SDL2 in macOS, can you test it ?
It's here: https://cirrus-ci.com/task/6084764296282112
If it works for you I am going to rewrite for Linux and Windows too and rerelease the plugin. Thanks!
NOTE: in the link above I hardcoded the encoding as ASCII, I am trying to figure it out if I can figure the encoding of the AGS game from the plugin API somehow.
The build in the CI newer after this is using UTF-8 as encoding. I am trying to figure if there's some way to figure this from the game. I noticed the SDL version instead assumes arbitrary encodings so it may be useful to reimplement this myself anyway.
I ended up fixing the issues and CW pointed me how to detect encoding. Created a new release, just waiting the CI builds to happen...
Thanks for the quick turn around! I probably should create some new Mac shells, built from 3.6.2. I tend to create a build using CMake, but I've also created a build using Xcode, and that one includes the SDL2.framework, instead of just building it into the binary (that's what I'm assuming is happening).
You mentioned having to fix rpath, something I've been digging into quite a bit lately in trying to figure out how to get dylibs to work with AGS on the Mac, and ensuring that the libraries are found and linked properly.
Here is the errors I'm seeing from my debugging info when the game launches and is trying to load up the libagsappopenurl.dylib on an Intel-based Mac:
Lookup Dir: '/Users/username/Programs/Mac/MyGame.app/Contents/Resources/'
libname 'agsappopenurl' | libfile 'libagsappopenurl.dylib'
Try library path: libagsappopenurl.dylib
dlopen error: dlopen(libagsappopenurl.dylib, 1): Library not loaded: @rpath/libSDL2-2.0.dylib
Referenced from: /Users/username/Programs/Mac/MyGame.app/Contents/Resources/libagsappopenurl.dylib
Reason: image not found
Try library path: ./libagsappopenurl.dylib
dlopen error: dlopen(./libagsappopenurl.dylib, 1): Library not loaded: @rpath/libSDL2-2.0.dylib
Referenced from: /Users/username/Programs/Mac/MyGame.app/Contents/Resources/libagsappopenurl.dylib
Reason: image not found
Try library path: /Users/username/Programs/Mac/MyGame.app/Contents/Resources/libagsappopenurl.dylib
dlopen error: dlopen(/Users/username/Programs/Mac/MyGame.app/Contents/Resources/libagsappopenurl.dylib, 1): Library not loaded: @rpath/libSDL2-2.0.dylib
Referenced from: /Users/username/Programs/Mac/MyGame.app/Contents/Resources/libagsappopenurl.dylib
Reason: image not found
Plugin 'agsappopenurl' could not be loaded (expected 'libagsappopenurl.dylib'), trying built-in plugins...
Placeholder functions for the plugin 'agsappopenurl' found.
Quote from: eri0o on Wed 21/08/2024 19:50:55Spoiler
@edenwaith I wrote a version of the plugin that doesn't depend on SDL2 in macOS, can you test it ?
It's here: https://cirrus-ci.com/task/6084764296282112
If it works for you I am going to rewrite for Linux and Windows too and rerelease the plugin. Thanks!
NOTE: in the link above I hardcoded the encoding as ASCII, I am trying to figure it out if I can figure the encoding of the AGS game from the plugin API somehow.
The build in the CI newer after this is using UTF-8 as encoding. I am trying to figure if there's some way to figure this from the game. I noticed the SDL version instead assumes arbitrary encodings so it may be useful to reimplement this myself anyway.
I ended up fixing the issues and CW pointed me how to detect encoding. Created a new release, just waiting the CI builds to happen...
Sorry, is this error from which version of the lib?
@edenwaith the build is here: https://cirrus-ci.com/task/4644872416657408
But the Linux and Windows builds are still scheduled to happen in the pipeline before they make into the release (they run in community clusters from the Google Cloud and take a little to happen). Can you try using that? It should work (I test in my m2 Sonoma)
Anyway, if you have this problem in other plugin you just place the library inside the bundle and use the
install_name_tool -add_rpath command to fix the rpath to match. (I don't have more computer time today to play with it to be able to explain better right now)
Edit: the pipeline finished building the release is here: https://github.com/ericoporto/agsappopenurl/releases/tag/v.0.2.0
@eri0o I created a Universal Binary of v0.2.0 of your plug-in and popped it into a Mac version of an AGS game. I tested out the functionality and it WORKS!
Thank you again for your amazing quick turn around and responsiveness. I'm very happy that this now works well for the Mac, and now it has no dependencies on the SDL library.
@edenwaith I thought I was correctly building my plugin on CI for both Intel and Arm, what do you mean by creating an Universal Binary of the plugin? If there's any issue at all I would like to fix. If I can save others from having to build from source I would like to do that. Thanks :)