Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mortuus17 · Jun 09, 2020 at 04:31 AM · dllassemblyloading filemodifyassemblies

IL2CPP mod support

I have some very basic mod support that loads DLLs from a specific folder as Assemblies and inspects it's types. If it finds an "IMod", it calls it's respective Awake() method. I will spare you the code, since it needs to un-/subscribe to the Appdomain.CurrentDomain.AssemblyLoad event, check for other assembly references etc. - and it works in the editor either way. However it does not work with an IL2CPP built standalone player.

Do I need to do some extra steps? Is it even possible?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Bunny83 · Jun 09, 2020 at 10:19 AM

No, it's not possible. IL2CPP is an AOT platform (Ahead Of Time compilation). So when you build your game / application all your managed IL code will be converted to native C++ code and compiled into native code. So at runtime of your game there is no mono / .NET environment. Some reflection methods still work which can be inferred at compiletime by the cross compiler. However anything that requires dynamic code generation does not work.


However it should still be possible to use native OS calls (like LoadLibrary, GetProcAddress, ...) to load native DLLs manually. However designing a proper interop interface and get all communication between your game and your mod / plugin working can be tricky. Of course your mod / plugin has to be written in native code as well (probably with a C style interface). So mods has to be written in something like C, C++ or any other programming language which generates native code libraries.


Depending on the level of modding support you want to offer it's probably better to just integrate a scripting language / environment like LUA into your game. It also helps with security issues for both sides (so you can better protect core parts of your game and also make it much harder for your community to spread malicious code).


If you really want to load managed assemblies at runtime you can't use IL2CPP and have to stick with Mono as backend.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mortuus17 · Jun 09, 2020 at 04:39 PM 0
Share

Just like expected - what a bummer.

I want mod support along the lines of Cities Skylines, where you'd reference a C# dll (and Unity DLLs), which are now distributed with the "backup" folder in an IL2CPP build, and are thus able to extend the code base, having access to AAAALLLLL of the types and functionality of the game itself.

So my guess is that a scripting language wouldn't be powerful enough, because it would be limited to what kinds of mods I can think of myself.

1) I guess everything is possible but how difficult would it be to have a "second program" running alongside the game that is a .NET AppDomain ("$$anonymous$$odDomain"), which calls into the native code? Isn't this the fundamental way $$anonymous$$ono-games worked before/still work today?

2) Is it not possible to magically IL2CPP that bod-boi mod code, generating DLLs (keeping all types and such of course) which could then get loaded in, even if it can only happen in a game launcher type application?

3) Otherwise - how would someone who knows C++ link their code to my game? What is the equivalent of adding a reference to Assembly-CSharp to the "mod project", which enables you to see the types, with an IL2CPP build?

But either way your answer was invaluable - thank you. Even mentioning malicious code? Seems like you're able to read my $$anonymous$$d... But - as said - I BELIEVE (I know nothing in that regard), that a scripting language is limited in regards to functionality. EDIT: If it isn't clear, I basically want modders to simply comile a DLL and place it into the designated folder. Furthermore, the game should detect these mods and manage them in an options menu.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

127 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keep assemblies in separated dll instead of GameAssembly.dll 0 Answers

Can/should mcs.rsp files be used to reference my own class libraries? 0 Answers

Compile Error (CS0246) appears for every script in the project. 0 Answers

Why does Assembly-CSharp reference UnityEditor.dll 0 Answers

in Unity 5, how can I get/set an asset's AssetBundle assignment via scripting? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges