Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor improvements #11

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Some minor improvements #11

wants to merge 6 commits into from

Conversation

Quit
Copy link
Contributor

@Quit Quit commented Dec 8, 2018

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.

@TBBle
Copy link

TBBle commented Jan 6, 2019

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.

@Quit
Copy link
Contributor Author

Quit commented Jan 6, 2019

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.

@TBBle
Copy link

TBBle commented Jan 6, 2019

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.

@Quit
Copy link
Contributor Author

Quit commented Jan 6, 2019

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.

@TBBle
Copy link

TBBle commented Jan 29, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants