Jump to content
Quboid

Implementing optional cross-mod features

5 posts in this topic Last Reply

Highlighted Posts

Posted:
Last Online:  
 

I have a mod in development that includes a debug panel that shows the item Move It is currently hovering over. It has a button to load that item in the ModTools scene explorer, which works beautifully. But if the user doesn't have ModTools installed, they get this System.Reflection.ReflectionTypeLoadExection exception when the level loads and the mod doesn't run:

Quote

The Mod C:\Users\[Redacted]\AppData\Local\Colossal Order\Cities_Skylines\Addons\Mods\MITE [MITE.dll] has caused an error [ModException]

Details:
System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 
  at Harmony.HarmonyInstance.PatchAll (System.Reflection.Assembly assembly) [0x00000] in <filename unknown>:0 
  at MITE.MITE.OnLevelLoaded (LoadMode loadMode) [0x00000] in <filename unknown>:0 
  at LoadingWrapper.OnLevelLoaded (UpdateMode mode) [0x00000] in <filename unknown>:0 

The mod uses Harmony, but not for the debug panel's ModTools button.

All the code that uses the ModTools reference is in one file, that isn't called by any of the rest of the code (as in, this class is never instantiated). If it uses anything to do with ModTools, the error occurs. So (with this as my entire debug-panel-ModTools-button file; SceneExplorer is a ModTools class), loading the game throws the exception:

using ModTools;

namespace MITE
{
    class ModToolsTest
    {
        public SceneExplorer scene;
    }
}

Whereas this does not throw any exception:

using ModTools;

namespace MITE
{
    class ModToolsTest
    {
        public int scene;
    }
}

Could it be a compiler or project configuration error? I have a reference to 000_ModTools.dll. Or is this a limitation of Harmony?

Share this post


Link to post
Share on other sites
Posted:
Last Online:  
 

I was trying to help you with this, but didn't know you were using Harmony. Harmony causes this issue when you call PatchAll.

Here is what happens when you call it: https://github.com/pardeike/Harmony/blob/master/Harmony/HarmonyInstance.cs#L103-L115

It checks every single type/class of your assembly, also the one that requires ModTools.

Workarounds:

  • Use Reflection to call ModTools methods (so that the ModTools assembly is not referenced at all)
  • Write a replacement for PatchAll that doesn't load all types in your assembly

Reflection is the safest solution, especially if the integration with ModTools is basic.

Share this post


Link to post
Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    Yes, I made a lot of progress thanks to you. I didn't appreciate the importance of Harmony at the time because I was combining source code and getting other errors. I don't have plans beyond basic integration at this time so reflection should work, since the problem isn't just a fixable error in my code.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    I was thinking how useful it would be to have something similar to an eyedropper tool. When I was working with the CSUE/CSUR roads, there were 150+ roads and I didn't have an easy way to figure out which roads were where. I wound up having to do something similar by opening up modtools to see what prefab I was selecting w MoveIt. Would be cool to have an eyedropper mod where you just select anything on the map, and then you can identify it and plop it. Kind of like FindIt!, but a simple point and click version.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     
    23 minutes ago, AmiPolizeiFunk said:

    I was thinking how useful it would be to have something similar to an eyedropper tool. When I was working with the CSUE/CSUR roads, there were 150+ roads and I didn't have an easy way to figure out which roads were where. I wound up having to do something similar by opening up modtools to see what prefab I was selecting w MoveIt. Would be cool to have an eyedropper mod where you just select anything on the map, and then you can identify it and plop it. Kind of like FindIt!, but a simple point and click version.

    Sure that's possible.

    Share this post


    Link to post
    Share on other sites

    Sign In or register to comment...

    To comment in reply, you must be a community member

    Sign In  

    Already have an account? Sign in here.

    Sign In Now

    Create an Account  

    Sign up to join our friendly community. It's easy!  

    Register a New Account


    ×

    Thank You for the Continued Support!

    Simtropolis depends on donations to fund site maintenance costs.
    Without your support, we just would not be in our 24th year online!  You really help make this a great community. *:thumb:

    But we still need your support to stay online. If you're able to, please consider a donation to help us stay up and running. This helps sustain a platform where we can share our community creations for years to come.

    Make a Donation, Get a Gift!

    Expand your city with the best from the Simtropolis Exchange.
    Make a Donation and get one or all three discs today!

    STEX Collections

    By way of a "Thank You" gift, we'd like to send you our STEX Collector's DVD. It's some of the best buildings, lots, maps and mods collected for you over the years. Check out the STEX Collections for more info.

    Each donation helps keep Simtropolis online, open and free!

    Thank you for reading and enjoy the site!

    More About STEX Collections