Mod script compiler vs Unity's .NET framwork

Discuss coding questions, pull requests, and implementation details.
Post Reply
jimfcarroll
Posts: 102
Joined: Tue Feb 12, 2019 12:55 am

Mod script compiler vs Unity's .NET framwork

Post by jimfcarroll »

I'm really confused by something I'm seeing with the setup of my development environment. I'm using Unity 2018.2.11f1. The default "scripting runtime version" set in the Player settings is .NET 3.5 (equivalent). The System class in .NET 3.5 doesn't contain Tuple. The lowest .NET version where System has Tuple is .NET 4.0 Framework. When I bring up a file from Unity in Visual Studio I can't add a Tuple<T1,T2> unless I declare I'm using DaggerfallWorkshop.Utility (that is, it's not good enough to simply declare using System ).

HOWEVER, when I run DFU in Unity and load a Mod that uses Tuple<> but also declares using DaggerfallWorkshop.Utility AND using System I get the error that "Tuple is an ambiguous reference between System<> and DaggerfallWorkshop.Utility.Tuple<>" AS IF .NET 4.0 (or greater) is the basis of the Mod dynamic compilation.

This is an issue, for example, in the Vibrant Wind Mod here: https://github.com/TheLacus/vibrantwind ... ion.cs#L36

Any suggestions on what I'm doing wrong?

Thanks
Jim

jimfcarroll
Posts: 102
Joined: Tue Feb 12, 2019 12:55 am

Re: Mod script compiler vs Unity's .NET framwork

Post by jimfcarroll »

I've spent about 2 full days (one weekend and a box of wine shot) trying to work this out and I think I finally know what's going on.

This line:

https://github.com/jimfcarroll/daggerfa ... ler.cs#L51

... behaves completely differently when you run DFU from the player in the Unity IDE, as opposed to a compiled version. It adds ALL of the Unity IDE dependencies to the list of DLLs to run the application against which, because of that line, also adds them to the compile command for scripts. So you get MULTIPLE .NET frameworks.

As an example: when running in the player, the Vibrant Wind mod ends up with 111 dependent assemblies (almost all of which are DLLs) but when you build and run the app in a separate process space that same line generates 71 assemblies.

I can't be the only one that has this problem, though maybe I'm the only one (EDIT: dumb enough) that expects the Play button in Unity itself to behave consistently.

User avatar
TheLacus
Posts: 1305
Joined: Wed Sep 14, 2016 6:22 pm

Re: Mod script compiler vs Unity's .NET framwork

Post by TheLacus »

That's an interesting discovery, i never noticed that. I will try to investigate this issue but i don't think there is a clear way to solve this - except for blacklisting known assemblies. It shouldn't be a big issue anyway, but i agree is a bit annoying now that you pointed it out. Hopefully it only affects only a few edge cases like the example above.

jimfcarroll
Posts: 102
Joined: Tue Feb 12, 2019 12:55 am

Re: Mod script compiler vs Unity's .NET framwork

Post by jimfcarroll »

I was a bit surprised to see that the entire .NET framework was given to mod developers anyway. Once I realized that I was thinking about writing a MOD called "Send me a Bitcoin or 2 and I'll decrypt your files." :twisted:

Anyway, has there been any thought to sandboxing mods?

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Mod script compiler vs Unity's .NET framwork

Post by Interkarma »

jimfcarroll wrote: Mon Sep 23, 2019 1:42 pm Anyway, has there been any thought to sandboxing mods?
I take the same stance as Cities Skylines on this matter:

https://skylines.paradoxwikis.com/Moddi ... iderations
The code in Mods for Cities: Skylines is not executed in a sandbox.
While we trust the gaming community to know how to behave and not upload malicious mods that will intentionally cause damage to users, what is uploaded on the Workshop cannot be controlled.
Like with any files acquired from the internet, caution is recommended when something looks very suspicious.
Any mods in Released Mods here are curated and tested by this community and should be safe. But keep in mind that mods are created by community members and may or may not have code available for review like the core project. There is always an elevated risk with downloading any kind of executable from the Internet. We also have no control over what is created by the greater community and uploaded to sites like Nexus.

Overall, users will need to exercise their own security practices with DFU as with any other game or Internet use in general.

Meatbagwammo
Posts: 1
Joined: Tue Oct 01, 2019 11:02 pm

Re: Mod script compiler vs Unity's .NET framwork

Post by Meatbagwammo »

Sorry to bump but I'm having this error after I cloned the DFU project from github.

Here are the errors I get:

Code: Select all

Assets\Game\Addons\ModSupport\ModSettings\ModSettings.cs(107,16): error CS0104: 'Tuple<,>' is an ambiguous reference between 'DaggerfallWorkshop.Utility.Tuple<T1, T2>' and 'System.Tuple<T1, T2>'

Assets\Game\Addons\ModSupport\ModSettings\ModSettings.cs(117,16): error CS0104: 'Tuple<,>' is an ambiguous reference between 'DaggerfallWorkshop.Utility.Tuple<T1, T2>' and 'System.Tuple<T1, T2>'

Assets\Game\Addons\ModSupport\ModSettings\ModSettingsTypes.cs(521,36): error CS0104: 'Tuple<,>' is an ambiguous reference between 'DaggerfallWorkshop.Utility.Tuple<T1, T2>' and 'System.Tuple<T1, T2>'

Assets\Game\Addons\ModSupport\ModSettings\ModSettingsTypes.cs(567,38): error CS0104: 'Tuple<,>' is an ambiguous reference between 'DaggerfallWorkshop.Utility.Tuple<T1, T2>' and 'System.Tuple<T1, T2>'

Assets\Scripts\Game\UserInterface\MultiTextBox.cs(192,16): error CS0104: 'Tuple<,>' is an ambiguous reference between 'DaggerfallWorkshop.Utility.Tuple<T1, T2>' and 'System.Tuple<T1, T2>'

Assets\Scripts\Game\UserInterface\MultiTextBox.cs(224,16): error CS0104: 'Tuple<,>' is an ambiguous reference between 'DaggerfallWorkshop.Utility.Tuple<T1, T2>' and 'System.Tuple<T1, T2>'
Just for example the line that the first error is referring to is this:

Code: Select all

	public Tuple<int, int> GetTupleInt(string section, string name)
        {
            return GetValue<Tuple<int, int>>(section, name);
        }
Now as I'm writing this I'm wondering if changing "Tuple" to "DaggerfallWorkshop.Utility.Tuple" or "System.Tuple" would fix the issue. But I'm not sure if that would effect building mods or not.

Anyway, I'll try to see which one works but figure I should post here just in case neither works.

EDIT:
So I tried using both ""DaggerfallWorkshop.Utility.Tuple" and "System.Tuple" in the lines that were throwing errors and both end up causing more issues. I get more errors for other Tuples in the scripts and then some errors in other files. I can copy all the errors I get if needed.

jimfcarroll
Posts: 102
Joined: Tue Feb 12, 2019 12:55 am

Re: Mod script compiler vs Unity's .NET framwork

Post by jimfcarroll »

First, make sure you're not using a newer version of Unity than the one the project files are from (2018.2.21f1).

Second make sure you have the .NET framework set to 3.5 and NOT 4.x. (Edit->Project Settings->Player->Scripting Runtime Version)

Third: GOTO "First"; // What can possibly go wrong?

Post Reply