public static void ReadGraphicsAsset() { if (graphicsSettingsAsset != null) { return; } var assets = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/GraphicsSettings.asset"); if (assets.Length > 0) { graphicsSettingsAsset = new SerializedObject(assets[0]); } if (graphicsSettingsAsset != null) { includedShaders = graphicsSettingsAsset.FindProperty("m_AlwaysIncludedShaders"); if (includedShaders == null) { Debug.LogError(EditorTools.ConstructError("Couldn't find m_AlwaysIncludedShaders property")); } } else { Debug.LogError(EditorTools.ConstructError("Couldn't find GraphicsSettings asset")); } }
private static void GenerateWhitelistInternal() { #if ACTK_DEBUG sw = Stopwatch.StartNew(); sw.Stop(); Debug.Log("=== Injection Detector Whitelist Build Start ==="); sw.Start(); #endif EditorUtility.DisplayProgressBar(ProgressCaption, "Gathering assemblies", 0); var assembliesInBuild = GetAssembliesInBuild(); if (assembliesInBuild.Length == 0) { Debug.LogError(EditorTools.ConstructError("Can't find any assemblies in build!")); } var assembliesAllowedByUser = GetUserWhiteListAssemblies(); var allAllowedAssemblies = InjectionRoutines.MergeAllowedAssemblies(assembliesInBuild, assembliesAllowedByUser); EditorUtility.DisplayProgressBar(ProgressCaption, "Writing assemblies hashes", 0); WriteAllowedAssemblies(allAllowedAssemblies); #if ACTK_DEBUG sw.Stop(); Debug.Log(ACTkConstants.LogPrefix + "WhiteList build duration: " + sw.ElapsedMilliseconds + " ms."); #endif AssetDatabase.Refresh(); }
private static IEnumerable <AllowedAssembly> LoadAndParseLegacyWhitelist() { var result = new List <AllowedAssembly>(); string[] separator = { InjectionConstants.DataSeparator }; var fs = new FileStream(InjectionConstants.LegacyWhitelistRelativePath, FileMode.Open, FileAccess.Read, FileShare.Read); var br = new BinaryReader(fs); try { var count = br.ReadInt32(); for (var i = 0; i < count; i++) { var line = br.ReadString(); line = new string(ObscuredString.Encrypt(line, ACTkConstants.StringKey)); var strArr = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); var stringsCount = strArr.Length; if (stringsCount > 1) { var assemblyName = strArr[0]; var hashes = new int[stringsCount - 1]; for (var j = 1; j < stringsCount; j++) { var parseResult = 0; var success = int.TryParse(strArr[j], out parseResult); if (success) { hashes[j - 1] = parseResult; } else { Debug.LogError(ACTkConstants.LogPrefix + "Could not parse value: " + strArr[j] + ", line:\n" + line); } } result.Add(new AllowedAssembly(assemblyName, hashes)); } else { Debug.LogWarning(EditorTools.ConstructError("Error parsing whitelist file line!")); } } } catch (Exception e) { Debug.LogError(ACTkConstants.LogPrefix + "Error while reading legacy whitelist:\n" + e); } finally { br.Close(); fs.Close(); } return(result); }
public static bool IsScriptingImplementationSupported(ScriptingImplementation implementation, BuildTargetGroup target) { if (InspectorWindowType == null) { Debug.LogError(EditorTools.ConstructError("Couldn't find ModuleManager type!")); return(false); } if (ScriptingImplementationsType == null) { Debug.LogError(EditorTools.ConstructError("Couldn't find IScriptingImplementationsType type!")); return(false); } if (getScriptingImplementationsDelegate == null) { var mi = InspectorWindowType.GetMethod("GetScriptingImplementations", BindingFlags.Static | BindingFlags.NonPublic, Type.DefaultBinder, new [] { BuildTargetGroupType }, null); if (mi == null) { Debug.LogError(EditorTools.ConstructError("Couldn't find GetScriptingImplementations method!")); return(false); } getScriptingImplementationsDelegate = (GetScriptingImplementations)Delegate.CreateDelegate(typeof(GetScriptingImplementations), mi); } var result = getScriptingImplementationsDelegate.Invoke(target); if (result == null) // happens for default platform support module { #if UNITY_2018_1_OR_NEWER return(PlayerSettings.GetDefaultScriptingBackend(target) == implementation); #else return(true); #endif } if (scriptingImplementationsTypeEnabledMethodInfo == null) { scriptingImplementationsTypeEnabledMethodInfo = ScriptingImplementationsType.GetMethod("Enabled", BindingFlags.Public | BindingFlags.Instance); if (scriptingImplementationsTypeEnabledMethodInfo == null) { Debug.LogError(EditorTools.ConstructError("Couldn't find IScriptingImplementations.Enabled() method!")); return(false); } } var enabledImplementations = (ScriptingImplementation[])scriptingImplementationsTypeEnabledMethodInfo.Invoke(result, null); return(Array.IndexOf(enabledImplementations, implementation) != -1); }
private static void SaveInstance(ACTkSettings settingsInstance) { if (!System.IO.Directory.Exists(Directory)) { System.IO.Directory.CreateDirectory(Directory); } try { UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { settingsInstance }, Path, true); } catch (Exception ex) { Debug.LogError(EditorTools.ConstructError("Can't save settings!\n" + ex)); } }
private static Texture2D GetTexture(string fileName, bool icon, bool fromEditor) { Texture2D result; var isDark = EditorGUIUtility.isProSkin; var path = fileName; if (!fromEditor) { path = Path.Combine(EditorTools.GetACTkDirectory(), "Editor/Textures/For" + (isDark ? "Dark/" : "Bright/") + (icon ? "Icons/" : "") + fileName); } if (CachedTextures.ContainsKey(path)) { result = CachedTextures[path]; } else { if (!fromEditor) { result = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D; } else { result = EditorGUIUtility.FindTexture(path); } if (result == null) { Debug.LogError(EditorTools.ConstructError("Some error occurred while looking for image\n" + path)); } else { CachedTextures[path] = result; } } return(result); }
private static void DrawWallHackSection() { using (var changed = new EditorGUI.ChangeCheckScope()) { var fold = GUITools.DrawFoldHeader("WallHack Detector", ACTkEditorPrefsSettings.WallHackFoldout); if (changed.changed) { ACTkEditorPrefsSettings.WallHackFoldout = fold; } } if (!ACTkEditorPrefsSettings.WallHackFoldout) { return; } GUILayout.Space(-3f); using (GUITools.Vertical(GUITools.PanelWithBackground)) { GUILayout.Label( "Wireframe module uses own shader under the hood and it should be included into the build.", EditorStyles.wordWrappedLabel); ReadGraphicsAsset(); if (graphicsSettingsAsset != null && includedShaders != null) { // outputs whole included shaders list, use for debug //EditorGUILayout.PropertyField(includedShaders, true); var shaderIndex = GetWallhackDetectorShaderIndex(); EditorGUI.BeginChangeCheck(); var status = shaderIndex != -1 ? ColorTools.GetGreenString() + ">included" : ColorTools.GetRedString() + ">not included"; GUILayout.Label("Shader status: <color=#" + status + "</color>", GUITools.RichLabel); GUILayout.Space(5f); EditorGUILayout.HelpBox("You don't need to include it if you're not going to use Wireframe module", MessageType.Info, true); GUILayout.Space(5f); if (shaderIndex != -1) { if (GUILayout.Button("Remove shader")) { includedShaders.DeleteArrayElementAtIndex(shaderIndex); includedShaders.DeleteArrayElementAtIndex(shaderIndex); } GUILayout.Space(3); } else { using (GUITools.Horizontal()) { if (GUILayout.Button("Auto Include")) { var shader = Shader.Find(WallHackDetector.WireframeShaderName); if (shader != null) { includedShaders.InsertArrayElementAtIndex(includedShaders.arraySize); var newItem = includedShaders.GetArrayElementAtIndex(includedShaders.arraySize - 1); newItem.objectReferenceValue = shader; } else { Debug.LogError(EditorTools.ConstructError("Can't find " + WallHackDetector.WireframeShaderName + " shader!")); } } if (GUILayout.Button("Include manually (see readme.pdf)")) { #if UNITY_2018_3_OR_NEWER SettingsService.OpenProjectSettings("Project/Graphics"); #else EditorApplication.ExecuteMenuItem("Edit/Project Settings/Graphics"); #endif } } GUILayout.Space(3); } if (EditorGUI.EndChangeCheck()) { graphicsSettingsAsset.ApplyModifiedProperties(); } } else { GUILayout.Label("Can't automatically control " + WallHackDetector.WireframeShaderName + " shader existence at the Always Included Shaders list. Please, manage this manually in Graphics Settings."); if (GUILayout.Button("Open Graphics Settings")) { EditorApplication.ExecuteMenuItem("Edit/Project Settings/Graphics"); } } } }