Skip to content

Commit

Permalink
Work around Unity's APIUpdaterHelper breaking on the GetName bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinVR committed Mar 27, 2021
1 parent 65b1d4c commit 6bc0b1a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Assets/UdonSharp/Editor/UdonSharpEditorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ void InjectEvent(System.Type behaviourType, string eventName)

harmony.Patch(buildAssetbundlesMethod, preBuildHarmonyMethod, postBuildHarmonyMethod);

// Patch a workaround for errors in Unity's APIUpdaterHelper when in a Japanese locale
MethodInfo findTypeInLoadedAssemblies = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.Scripting.Compilers.APIUpdaterHelper").GetMethod("FindTypeInLoadedAssemblies", BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo injectedFindType = typeof(InjectedMethods).GetMethod(nameof(InjectedMethods.FindTypeInLoadedAssembliesPrefix), BindingFlags.Public | BindingFlags.Static);
HarmonyMethod injectedFindTypeHarmonyMethod = new HarmonyMethod(injectedFindType);

harmony.Patch(findTypeInLoadedAssemblies, injectedFindTypeHarmonyMethod);

#if ODIN_INSPECTOR_3
try
{
Expand Down Expand Up @@ -363,6 +370,40 @@ public static void PostBuildAssetBundles()
_skipSceneOpen = false;
}

public static bool FindTypeInLoadedAssembliesPrefix(Func<System.Type, bool> predicate, ref System.Type __result)
{
__result = AppDomain.CurrentDomain.GetAssemblies()
.Where(assembly => !assembly.IsDynamic && !string.IsNullOrEmpty(assembly.Location) && !assembly.Location.StartsWith("data") && !IsIgnoredAssembly(assembly.GetName()))
.SelectMany(GetValidTypesIn)
.FirstOrDefault(predicate);

return false;
}

static IEnumerable<System.Type> GetValidTypesIn(System.Reflection.Assembly assembly)
{
Type[] types;

try
{
types = assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
types = e.Types;
}

return types.Where(e => e != null);
}

static string[] _ignoredAssemblies = { "^UnityScript$", "^System\\..*", "^mscorlib$" };

static bool IsIgnoredAssembly(AssemblyName assemblyName)
{
string name = assemblyName.Name;
return _ignoredAssemblies.Any(candidate => System.Text.RegularExpressions.Regex.IsMatch(name, candidate));
}

#if ODIN_INSPECTOR_3
public static void OdinInspectorOverride()
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/UdonSharp/Editor/UdonSharpRuntimeLogWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static void HandleLogError(string errorStr, string logPrefix, string prePrefix)
{
if (errorStr.StartsWith("ExecutionEngineException: String conversion error: Illegal byte sequence encounted in the input.")) // Nice typo Mono
{
Debug.LogError("[<color=#FF00FF>UdonSharp</color>] ExecutionEngineException detected! This means you have hit a bug in Mono. To fix this, move your project to a path without any unicode characters.");
Debug.LogError("ExecutionEngineException detected! This means you have hit a bug in Mono. To fix this, move your project to a path without any unicode characters.");
return;
}

Expand Down

0 comments on commit 6bc0b1a

Please sign in to comment.