Well let’s start this off with a good old question that a lot of beginner programmers especially those who work around creating servers ask. “can I just send specific functions over sockets?”. and usually its either a “No” or “if you create a specific assembly for them”.
well, sometimes people are really stupid (like me) and don’t want to do that. we want all our code in one file and for it all to just ‘work’ well… that doesn’t work right?
well, it does, theoretically at least. and the use cases for this would be rather nice for example in games sending mods to clients, mod creators don’t want to have 3 separate assemblies, just for their mods.
so how do we do it?
well simple, but actually not…
and I 'v came across the idea as I was in the shower after working with System.Reflection.Metadata witch-like the rest of the reflection library lets you look at assemblies guts. but a more low level, with the usual method of reflection you can’t really extract a lot out of them, you can of course but its much slower and much harder, and then you get stuck with a dynamic assembly that might not properly work over the internet.
with a more low-level approach, we can fully dissect the assembly, in a semi-fast manner.
Using MetadataReader alongside System.Reflection.PortableExecutable.PEReader we can get all the nice juicy stuff about a given Assembly. with this, we can do a bit of high to low transitioning by Getting our MethodInfo and then the MethodInfo.MetadataToken we can get the raw metadata definition of that function. alongside a bit of IL Reflection (which is the hardest part) we can extract all the referenced Functions and Types thus allowing us to build a nice large list of all the things we need to pack in order to send a compressed version of this function or better yet functions and types through our socket.
But we need to first build this assembly we plan on sending. with the help of Dynamic Assembly Generation we can push all the metadata types into one assembly, first building the types than the members, and then finally the functions.
A Basic IL Types, Fields and Method reference Extractor.
of course, you would need to do quite a bit of work to get something like this to work.
but it would be an interesting way of Sandboxing mods from game servers.
Well, I might start a project to create something like this soon. any thoughts?