Skip to content

A Roslyn compiler to access internals/privates for Unity. In other words, you can access to any internals/privates in other assemblies, without reflection. Let's say, "Open sesame!"

License

Notifications You must be signed in to change notification settings

mob-sakai/OpenSesameCompilerForUnity

Repository files navigation

Open Sesame Compiler For Unity

⚠️ NOTE: This project has been integrated into CSharpCompilerSettingsForUnity. We are NOT continuing development in this repository. ⚠️





A custom Roslyn compiler and editor extension to access internals/privates for Unity.
In other words, you can access to any internals/privates in other assemblies, without reflection.

Let's say, "Open sesame!"

PRs Welcome

<< Description | Installation | Usage | Contributing >>

What's new? See changelog

Do you want to receive notifications for new releases? Watch this repo

Support me on GitHub!

become_a_sponsor_on_github





Description

Then Ali Baba climbed down and went to the door concealed among the bushes, and said, "Open, Sesame!" and it flew open.

This package allows to access to any internals/privates in other assemblies, without reflection.

For details about IgnoresAccessChecksToAttribute, see No InternalsVisibleTo, no problem – bypassing C# visibility rules with Roslyn.

Features

  • Easy to use
    • this package is out of the box.
  • Allow to access to any internal/private elements (types/members) in other assemblies, without reflection
    • Create instance
    • Get/set fields or properties
    • Call method
    • Create extension method that contains private access
    • etc.
  • Processes only AssemblyDefinitionFile you configured
  • Add/remove the scripting define symbols for each AssemblyDefinitionFiles
  • Support C#8
  • Support .Net 3.5, .Net 4.x and .Net Standard 2.0
  • dotnet is not required
  • Publish as dll
    • Published dll works without this package.
  • Portable mode
    • Without publishing, make the assembly available to access to internals/privates in other assemblies, even in projects that do not have this package installed.
    • The best option when distributing as a package.

NOTE: Unsupported Features

  • Set/get value into readonly field
    • Use reflection
  • IDE support





Installation

Requirement

  • Unity 2018.3 or later

Using OpenUPM

This package is available on OpenUPM. You can install it via openupm-cli.

openupm add com.coffee.open-sesame-compiler

Using Git

Find the manifest.json file in the Packages directory in your project and edit it to look like this:

{
  "dependencies": {
    "com.coffee.open-sesame-compiler": "https://github.com/mob-sakai/OpenSesameCompilerForUnity.git",
    ...
  },
}

To update the package, change suffix #{version} to the target version.

  • e.g. "com.coffee.open-sesame-compiler": "https://github.com/mob-sakai/OpenSesameCompilerForUnity.git#1.0.0",

Or, use UpmGitExtension to install and update the package.





Usage

  1. Select a AssemblyDefinitionFile in project view
  2. Configure setting for the assembly in inspector view:
    • Open Sesame: Use OpenSesameCompiler instead of default csc to compile this assembly. In other words, allow this assembly to access to internals/privates to other assemblies without reflection.
    • Settings: how/hide the detail settings for this assembly.
      • Modify Symbols: When compiling this assembly, add/remove semicolon separated symbols. Symbols starting with '!' will be removed.
        NOTE: This feature is available even when 'Open Sesame' is disabled
      • Portable Mode: Make this assembly available to access in internals/privates to other assemblies, even in projects that do not have Open Sesame Compiler package installed.
    • Publish: Publish this assembly as dll to the parent directory.
    • Help: Open help page on browser.
  3. Enjoy!





Demo

  1. Clone demo branch in this repo and open it with Unity 2018.3 or later
git clone -b demo https://github.com/mob-sakai/OpenSesameCompilerForUnity.git
  1. The project has some inaccessible compilation errors
  2. Do not worry, they are proper errors.
    The demo project access to internals/privates:
// EditorApplication.CallDelayed is an internal-static method in UnityEditor assembly.
EditorApplication.CallDelayed(() => Debug.Log("delayed"), 1);
  1. Select Assets/Tests/Coffee.OpenSesame.Test.asmdef in project view and activate 'Open Sesame' in inspector view
  2. Run all edit mode tests in test runner view (Windows > General > Test Runner).
    The compilation error is gone, but some tests that depend on symbols will not pass.
[Test]
public void DefineSymbols()
{
    const string log = "OSC_TEST is defined.";
    LogAssert.Expect(LogType.Log, log);
#if OSC_TEST // <- not defined!
    Debug.Log(log);
#endif
}

[Test]
public void RemoveSymbols()
{
    const string log = "TRACE is not defined.";
    LogAssert.Expect(LogType.Log, log);
#if !TRACE // <- defined automatically by Unity!
    Debug.Log(log);
#endif
}
  1. Enable symbols to modify scripting define symbols for this assembly.
    Then edit Modify Symbols to OSC_TEST;!TRACE. This means "add OSC_TEST symbol and remove TRACE symbol for this assembly."
  2. All tests pass!

For more details, see the article 1 (Japanese) and the article 2 (Japanese).





Contributing

Issues

Issues are very valuable to this project.

  • Ideas are a valuable source of contributions others can make
  • Problems show where this project is lacking
  • With a question you show where contributors can improve the user experience

Pull Requests

Pull requests are, a great way to get your ideas into this repository.
See CONTRIBUTING.md.

Support

This is an open source project that I am developing in my spare time.
If you like it, please support me.
With your support, I can spend more time on development. :)






License

  • MIT

Author

mob-sakai

See Also

Special Thanks

  • Special thanks to @pCYSl5EDgo, your ideas contributed to improve this package.

About

A Roslyn compiler to access internals/privates for Unity. In other words, you can access to any internals/privates in other assemblies, without reflection. Let's say, "Open sesame!"

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages