IPA icon indicating copy to clipboard operation
IPA copied to clipboard

Some minor improvements

Open Quit opened this issue 7 years ago • 5 comments

Since I've started digging around in the IPA code, I've decided to make a few small life improvements.

  • Add --ipa-console command line argument to force-show the console. I've encountered a game where Screen.fullScreen was always true, no matter what I've done (-screen-fullscreen 0, setting it in the settings) because the game likely sets it by itself. Therefore, even though it becomes windowed later on, I had no console - this switch is overriding the fullscreen check. Name is a bit odd to avoid collisions with any legitimate --console command that games might use.
  • Improved the plugin check.
    • Abstract classes are now ignored.
    • Classes with non-empty constructors (e.g. CompositePlugin) are also ignored. They can't be constructed, currently, and would throw an Activator exception in any case.
    • Improved the check for IPlugin, allowing inheritance.
  • Logging the .NET version over Console.WriteLine. Since Unity now supports three major frameworks (.NET 2.0/3.5, .NET 4.6, .NET Standard 2.0), developing plugins can become a lot easier if one knows that framework is supported. The check successfully detects those three versions, but cannot differentiate between .NET 2.0 and .NET 2.0 subset, although I think that's an unlikely case. In case the version cannot be determined, or an exception occurs, there's a fallback that might not be as useful.

My Visual Studio settings might have accidentally re-formatted the code (CTRL-K, CTRL-D'd) in files that I've touched, although I've tried to minimize the impact. If it's not an issue, I'd follow up with a PR that cleans up/reformats all files in the project.

Quit avatar Dec 08 '18 13:12 Quit

Without f6eeb84, it seems that plugins implementing IEnhancedPlugin don't work. I tried listing both interfaces, but I suspect the compiler sees that IEnhancedPlugin implements IPlugin and (sensibly) removes it from the type-list.

TBBle avatar Jan 06 '19 16:01 TBBle

I could have sworn that something like this was the case, but it seems like GetInterface(string) actually returns all implemented interfaces, including transitive ones. I've used the following to test it:

        private static object PluginCheck(Type type) => new
        {
            GetInterface = type.GetInterface("IPlugin") != null,
            AssignableFrom = typeof(IPlugin).IsAssignableFrom(type),
            IsAbstract = !type.IsAbstract,
            IsInterface = !type.IsInterface,
            GetConstructor = type.GetConstructor(Type.EmptyTypes) != null
        };

which implements all checks in both the old version (GetInterface("IPlugin") != null) as well as my new one (see above). Creating four classes A : IPlugin, AH : IEnhancedPlugin, B : A and BH : AH and running the method above on all of the types returned true for every single check.

The only thing that my code is doing slightly different is a stronger validation of IPlugin. The old check could throw an exception if the game, or your library, happened to have an IPlugin interface as well, as it only checked the name, not the original assembly/namespace.

So long story short, the old and the new check should both work properly with IEnhancedPlugin, as long as that interface implements IPlugin. Mine is a tad stricter about it.

Quit avatar Jan 06 '19 16:01 Quit

Well, it's definitely not working for me. My (near-trivial) code's at https://github.com/TBBle/SakuraClicker_NewEngine_Mod/blob/master/LogFrameworkVersionPlugin.cs and changing that IPlugin to IEnhancedPlugin causes IPA 3.4.1 from to stop loading it.

Edit: To be clear, I didn't check that this pull request fixes the issue, and it's also possible I'm doing something wrong with my project setup.

TBBle avatar Jan 06 '19 17:01 TBBle

Your filter is likely wrong. You can set it to null if you don't care about which executable is running it, but in any case, it's the extensionless name. If the filter doesn't match, the only method invoked will be the constructor of your plugin.

So I don't see how any of my commits would help you with that issue... or if it does, I've accidentally broken the filter mechanics.

Quit avatar Jan 06 '19 17:01 Quit

Ah, yeah, it's probably the extensionless name oversight. Sorry for the noise, I'll come back if there does turn out to be a real problem here.

TBBle avatar Jan 29 '19 13:01 TBBle