RayCarrot / RayCarrot.RCP.Metro

Rayman Control Panel (4.0.0 and above)
https://raym.app/rcp
MIT License
102 stars 5 forks source link

Want to include rayman arena network init patch? #3

Closed zZeck closed 1 year ago

zZeck commented 2 years ago

I made it.

Inspired by this issue.

I can probably make a PR for this repo, if you do want it.

RayCarrot commented 2 years ago

Hi! Can you please explain exactly what your patch does, why it's needed and what is required for it to work?

zZeck commented 2 years ago

Why and What: Rayman Arena normally has no way to control which network adapter it uses. And, its code for guessing and binding to an ip + port is a mess. It actually has two pieces of code, both broken in different ways. I pop up a list of adapters to pick, and patch both broken routines to to return the IP of the adapter chosen. This allows people to use virtual LANs software like Hamachi to play online.

Details: The first broken code guesses at which adapter is most likely the "main" one by comparing adapter IP against a list of IP masks, looking for things like 192.168.x.x for example. This is bizarre. Naturally, many virtual LAN adapters use IP addresses do not happen to match any of these patterns.

The second piece of code tries to get the IP for the domain "localhost". The problem is, a domain can correspond to multiple IPs. So you end up getting the IP back for whatever window's DNS happens to have configured as first. This probably isn't going to be the IP of your virtual LAN adapter.

You can actually see via a tool like sysinternals Process Explorer, that with the right machine setup, Arena will bind to TWO different ips. If you have an adapter that matches one of the patterns it looks for, some code will end up using that address. Then if your primary adapter, the one window's DNS will have setup fo localhost, is different one, another set of ports is bound to that. One set of binding happens right after you select your character in multiplayer. Another set happens when you try to start hosting a game. Probably two different coders worked on the lobby code, vs the actual game netcode.

How to Use: My patch is just a dll that needs loaded into the Rayman Arena process somehow. I happen to personally use The Ultimate Asi Loader, because it seemed most convenient. In the arena directory, make a directory named plugins, and put my patch asi (.asi files are really just .dll files) in it. Then choose one of the dlls from The Ultimate Asi Loader, and put that in the arena directory itself. Those dlls run some code on load, to load any asis from the plugins directory. They also forward all functions the dlls should have, into calls to the corresponding real function in the real windows dll with that name. That way everything still works normally.

RayCarrot commented 2 years ago

Thanks for the detailed description! I'm currently busy with a few other projects, but when I get back to working on the next RCP update I can look into adding this as a utility. I haven't had a chance to try it out yet, but from my understanding you're creating a window with a selection, right? Perhaps this selection can be integrated into RCP directly, with it then saving the value somewhere for your patch to read from (or something similar)?

zZeck commented 2 years ago

I can make it save the selection to a file, and not pop up the window if there is a saved choice that matches an existing adapter. Might be a bit before I do that. Busy as well right now. Thought about adding that when I first released it, but wasn't sure if it would get much use.

Here is a video someone made. You can see the window pop up for choosing an adapter.

zZeck commented 2 years ago

My patch is updated now finally. It looks in the rayman arena directory for arenaPatch.cfg and reads from it the network adapter name. If it finds a matching adapter, it will be used without prompting the user.

RayCarrot commented 2 years ago

Hi again and sorry for such a late reply! In the latest beta (and soon to be final release) I've added a new "patcher" feature (basically a sort of mod loader). Moving forward I'm going to try and have game file modifications made by RCP use this new system as it allows them to easily be reverted and such. I'm thinking for your network patch that this might be a good way to go? If you make a patch for it I can upload it as one of the downloadable patches in RCP, thus making it available directly in the patcher window for Rayman Arena.

zZeck commented 2 years ago

No worries. I've been and continue to be occupied with various projects.

This patch needs dll injection to load, since it runs code to open up a network select menu on the first run, and read the config file on runs after that.

The patch has expanded, since it now includes discord presence support as well, which runs in its own thread.

What would I need to do?

RayCarrot commented 2 years ago

Assuming it just needs to add or replace files in the game directory you can create a patch in RCP by going to Utilities > Patch Creator, choose Rayman Arena as the game and create a new patch. There you specify the patch metadata and add the files (either from a folder or one by one). Once created you'll have a .gp patch file which can be added in the patcher dialog (in the games drop-down menu). You can upload this file here and I can upload it to be listed as a downloadable patch (like what you can currently see for Rayman 2 and 3 which each has a downloadable patch).

zZeck commented 2 years ago

Would it be acceptable to bundle something like an ASI loader dll then, to get the game to do the dll injection? Normally I think asi loader expects the injected dlls to be in a subdirectory. There are probably other dll injectors that could replace a dll the game uses, and might be able to load my dll from the game root. Maybe asi loader can be configured to do that. Not sure.

zZeck commented 2 years ago

Or is the patch system able to move a directory too? Then I could have it move a plugins directory for asi loader, with my dll in it, and move the asi dll into the root.

RayCarrot commented 2 years ago

You can't move existing files, but you can add files in new directories and deleting existing files which would essentially result in the same thing. If you leave the source path empty in the creator it will delete the file at the destination path rather than add/replace the file.

RayCarrot commented 1 year ago

Just checking in here - any progress on creating the patch in RCP?

zZeck commented 1 year ago

Sorry. I do mean to get back to this. Been occupied with other projects. Dunno if you saw the rayman arena decompilation, but that's one of them. I think I'll probably get back to this later this week. though, since you've reminded me. XD

zZeck commented 1 year ago

Did I do this right? Put the gp file in a zip so I could upload it to github. Has the asi loader dinput8.dll, and then puts my patch .asi into /plugins. arenaMultiplayerPatch.zip

RayCarrot commented 1 year ago

The patch has now been added. Thanks!