multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.42k stars 437 forks source link

WASM #2981

Closed CrosRoad95 closed 12 months ago

CrosRoad95 commented 1 year ago

Is your feature request related to a problem? Please describe.

First of all why i need wasm, why do we need wasm in mta: there is a lot of proposals from players to add to mta some feature, in general it is cool to have support for certain things, but on the other hand supporting it by mta staff will be limited. Instead, a responsibility could be moved to to players. someone can use it to create library that adds support for xyz file because single server need it - no more waiting for mta team to review, test

so, i spent ( again ) couple of last days on figuring out how wasm could be integrated with mta. After some research, checking multiple wasm libraries i found one that took my attetion: https://github.com/wasm3/wasm3 it's main adventages is that seems to be well tested, is small, supports all platforms mta supports, and it is just runtime, nothing else, compiles in 1.7second. So i conducted a sample experiment i tried to integrate it with mta. From documentation i can read that it support wasm specification and few extensions.

My few conclusions are that wasm3 library seems to be pretty good choice for mta, it has it's own issues such as it is intepreted but not jit compiled but on the other hand we could call exports from background threads. It is possible to bind lua function to wasm and call lua from wasm, wasm from lua. It is also possible to contain .wasm files whichin resource so for example all io operations are executed with resource privilages. However it has disadventages. found that most of wasm files from the internet are not working, suprisingly c# file that is the biggest is working best. Probably it need to be compiled properly, recompiled with wasm3 specific toolchain. I also tried to hack module by attempting to call/read arbitrary addesses and lib doing pretty good job of notyfing use that he is doing out of bound access.

It may require a bit more research what is actually possible, how different things should be done, but from my short experience it is dueable to write entire client and server in typescript then compile it to .wasm also, binding wasm->lua->c++ is not super efficient, mta may provide a namespace with functions mapped directly to c++

I was creating api based on javascript, chrome wasm api. Address that user getting in lua is always aligned close to zero, in example below "textPtr" is a pointer like 0x1000 so user wont know what is actual address of variable

Describe the solution you'd like

/

Describe alternatives you've considered

/

Additional context

branch: https://github.com/CrosRoad95/mtasa-blue/tree/feature/wasm3 test resource: [wasm.zip](https://github.com/multitheftauto/mtasa-blue/files/11335366/wasm.zip) ts project that compiles to web assembly: [ts.zip](https://github.com/multitheftauto/mtasa-blue/files/11335371/ts.zip) ![image](https://user-images.githubusercontent.com/22455534/234652030-c1ff2ec7-5232-4963-aa3e-ece59d35a4e8.png) I personally would like to use it in slipe-server as a way to have c# both client and server side

Security Policy

CrosRoad95 commented 1 year ago

waiting for feedback, decision how it can be added or not added at all till the end of year otherwise i'm closing this feature request with denied decision