Hello, I’ll try and keep this as brief as possible:
I am building a sort of modding system for a certain aspect of my game.
It basically allows the common user to write some C# code which will be used to give access to certain elements of the game at certain times. Like giving the host of a multiplayer server the ability to decide what map to load with what parameters etc…
I already have the assembly loading working. It’s quite neat and not very complicated XD
But now I’ve come to the point where it would be very nice if I could give the “user” some access to assemblies such as System
and UnityEngine
.
I could of course include the dll’s in the ReferenceAssemblies
property of the CompilerParameters
, but that would give them access to possibly harmful functionality, such as reflection, Instantiation, Destroy as well as many others…
How would I limit the assembly references to only certain namespaces, such as System.IO
and System.Collections
, without giving access to System.Reflection
?
Now for the posting of some possibly relevant code:
//Excuse the UnityScript... I find it quicker to do things in
//Create compiler parameters
var params:CompilerParameters = new CompilerParameters();
params.GenerateExecutable = false;
params.GenerateInMemory = false;
//Add assembly reference
params.ReferencedAssemblies.Add("System.dll");
//I wish I could put System.IO in here instead of System.dll
//Create provider and load/compile assembly
var provider:CodeDomProvider = new CodeDomProvider.CreateProvider("CSharp");
var results:CompilerResults = provider.CompileAssemblyFromFile(params, path);
I hope this is even possible
Thank you,
Benproductions1
EDIT:
I forgot to add: Is it possible to add: Is it possible to add the current Assmbly to that list? So I could inherit a class etc., or do I have to make my own assembly and include that in the project? (Not that it’s hard, just a minor pain XD)