Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.meta
scripts/LICENSE.txt
*.sln
.vs
Expand Down
7 changes: 7 additions & 0 deletions LICENSE.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "com.testpackage.unity-native-tool",
"displayName": "Unity Native Tool",
"version": "0.0.1",
"unity": "2018.1",
"description": "Tool for unloading native DLLs in the editor",
"keywords": [
"native",
"c++",
"dll"
],
"category": "Unity",
"type": "tool",
"author": {
"name": "John Doe",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, that's not my name :)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nor an email

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can I find them? they're not in your public profile.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can live without that unless that's somehow mandatory

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove the author field if you want it to stay anonymous? (fyi John Doe is just a placeholder name)

"email": "john.doe@example.com",
"url": "https://github.com/mcpiroman/UnityNativeTool/"
},
"repository": {
"type": "git",
"url": "git@github.com:mcpiroman/UnityNativeTool.git",
"revision": "6c6b17c36b33c72754d0bf2ee7e7236a68e10665"
}

}
7 changes: 7 additions & 0 deletions package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions scripts/Attributes.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions scripts/Detour.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions scripts/DllLoadException.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions scripts/DllManipulator.ReflectionData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 35 additions & 25 deletions scripts/DllManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ public partial class DllManipulator
public const string DLL_PATH_PATTERN_ASSETS_MACRO = "{assets}";
public const string DLL_PATH_PATTERN_PROJECT_MACRO = "{proj}";
private const string CRASH_FILE_NAME_PREFIX = "unityNativeCrash_";
public static readonly string[] DEFAULT_ASSEMBLY_NAMES = {"Assembly-CSharp"
#if UNITY_EDITOR
, "Assembly-CSharp-Editor"
#endif
};
public static readonly string[] INTERNAL_ASSEMBLY_NAMES = {"MCpiroman.UnityNativeTool"
Comment thread
rogerbarton marked this conversation as resolved.
Outdated
#if UNITY_EDITOR
, "MCpiroman.UnityNativeTool.Editor"
#endif
};
public static readonly string[] IGNORED_ASSEMBLY_PREFIXES = { "UnityEngine.", "UnityEditor.", "Unity.", "com.unity.", "Mono." , "nunit."};


public static DllManipulatorOptions Options { get; set; }
private static int _unityMainThreadId;
Expand Down Expand Up @@ -47,20 +59,18 @@ internal static void Initialize(int unityMainThreadId, string assetsPath)

LowLevelPluginManager.ResetStubPlugin();

Assembly[] assemblies;
if (Options.assemblyPaths.Length == 0)
IEnumerable<string> assemblyPathsTemp = Options.assemblyNames;
if (!assemblyPathsTemp.Any())
assemblyPathsTemp = DEFAULT_ASSEMBLY_NAMES;

assemblyPathsTemp = assemblyPathsTemp.Concat(INTERNAL_ASSEMBLY_NAMES);

var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var assemblies = allAssemblies.Where(a => !a.IsDynamic && assemblyPathsTemp.Any(p => p == Path.ChangeExtension(a.ManifestModule.Name, null))).ToArray();
Comment thread
rogerbarton marked this conversation as resolved.
Outdated
var missingAssemblies = assemblyPathsTemp.Except(assemblies.Select(a => Path.ChangeExtension(a.ManifestModule.Name, null)));
foreach (var assembly in missingAssemblies)
{
assemblies = new[] { Assembly.GetExecutingAssembly() };
}
else
{
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
assemblies = allAssemblies.Where(a => !a.IsDynamic && Options.assemblyPaths.Any(p => p == PathUtils.NormallizeSystemAssemblyPath(a.Location))).ToArray();
var missingAssemblies = Options.assemblyPaths.Except(assemblies.Select(a => PathUtils.NormallizeSystemAssemblyPath(a.Location)));
foreach (var assemblyPath in missingAssemblies)
{
Debug.LogError($"Could not find assembly at path {assemblyPath}");
}
Debug.LogError($"Could not find assembly: {assembly}");
}

foreach (var assembly in assemblies)
Expand Down Expand Up @@ -608,34 +618,34 @@ private static void WriteNativeCrashLog(NativeFunction nativeFunction, object[]

private static IntPtr SysLoadDll(string filepath)
{
#if UNITY_STANDALONE_WIN
return PInvokes_Windows.LoadLibrary(filepath);
#elif UNITY_STANDALONE_LINUX
#if UNITY_STANDALONE_LINUX
return PInvokes_Linux.dlopen(filepath, (int)Options.posixDlopenFlags);
#elif UNITY_STANDALONE_OSX
return PInvokes_Osx.dlopen(filepath, (int)Options.posixDlopenFlags);
#else // UNITY_STANDALONE_WIN

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the way it was somehow bad? I understand the addition of || UNITY_EDITOR_XXX (which should also go there), but not the commented else. I mean, if for any reason the running platform happens not to be listed here, the code should not even compile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though it might be useful in some cases as there's quite a lot of platforms. But then it probably makes most sense to leave it as #elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN as this is what is directly supported. I will change it to that.

return PInvokes_Windows.LoadLibrary(filepath);
#endif
}

private static bool SysUnloadDll(IntPtr libHandle)
{
#if UNITY_STANDALONE_WIN
return PInvokes_Windows.FreeLibrary(libHandle);
#elif UNITY_STANDALONE_LINUX
#if UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX
return PInvokes_Linux.dlclose(libHandle) == 0;
#elif UNITY_STANDALONE_OSX
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
return PInvokes_Osx.dlclose(libHandle) == 0;
#else // UNITY_STANDALONE_WIN
return PInvokes_Windows.FreeLibrary(libHandle);
#endif
}

private static IntPtr SysGetDllProcAddress(IntPtr libHandle, string symbol)
{
#if UNITY_STANDALONE_WIN
return PInvokes_Windows.GetProcAddress(libHandle, symbol);
#elif UNITY_STANDALONE_LINUX
#if UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX
return PInvokes_Linux.dlsym(libHandle, symbol);
#elif UNITY_STANDALONE_OSX
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
return PInvokes_Osx.dlsym(libHandle, symbol);
#else // UNITY_STANDALONE_WIN
return PInvokes_Windows.GetProcAddress(libHandle, symbol);
#endif
}
}
Expand All @@ -644,7 +654,7 @@ private static IntPtr SysGetDllProcAddress(IntPtr libHandle, string symbol)
public class DllManipulatorOptions
{
public string dllPathPattern;
public string[] assemblyPaths; //empty means only executing assembly
public List<string> assemblyNames; // empty means only default assemblies
public DllLoadingMode loadingMode;
public PosixDlopenFlags posixDlopenFlags;
public bool threadSafe;
Expand Down
11 changes: 11 additions & 0 deletions scripts/DllManipulator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions scripts/DllManipulatorScript.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Linq;
Expand All @@ -14,14 +15,14 @@ public class DllManipulatorScript : MonoBehaviour
public DllManipulatorOptions Options = new DllManipulatorOptions()
{
dllPathPattern =
#if UNITY_STANDALONE_WIN
"{assets}/Plugins/__{name}.dll",
#elif UNITY_STANDALONE_LINUX
#if UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX
"{assets}/Plugins/__{name}.so",
#elif UNITY_STANDALONE_OSX
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
"{assets}/Plugins/__{name}.dylib",
#else // UNITY_STANDALONE_WIN Windows fallback
"{assets}/Plugins/__{name}.dll",
#endif
assemblyPaths = new string[0],
assemblyNames = new List<string>(),
loadingMode = DllLoadingMode.Lazy,
posixDlopenFlags = PosixDlopenFlags.Lazy,
threadSafe = false,
Expand Down
11 changes: 11 additions & 0 deletions scripts/DllManipulatorScript.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions scripts/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading