private void OnGUI() { if (whitelist == null) { whitelist = new List <AllowedAssembly>(); LoadAndParseWhitelist(); } var tmpStyle = new GUIStyle(EditorStyles.largeLabel) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold }; GUILayout.Label("User-defined Whitelist of Assemblies trusted by Injection Detector", tmpStyle); scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); var whitelistUpdated = false; var count = whitelist.Count; if (count > 0) { for (var i = 0; i < count; i++) { var assembly = whitelist[i]; using (GUITools.Horizontal()) { GUILayout.Label(assembly.ToString()); if (GUILayout.Button(new GUIContent("-", "Remove Assembly from Whitelist"), GUILayout.Width(30))) { whitelist.Remove(assembly); whitelistUpdated = true; break; } } } } else { tmpStyle = new GUIStyle(EditorStyles.largeLabel) { alignment = TextAnchor.MiddleCenter }; GUILayout.Label("- no Assemblies added so far (use buttons below to add) -", tmpStyle); } if (manualAssemblyWhitelisting) { manualAssemblyWhitelistingName = EditorGUILayout.TextField(manualAssemblyWhitelistingName); using (GUITools.Horizontal()) { if (GUILayout.Button("Save")) { try { if (manualAssemblyWhitelistingName.StartsWith("Cause:")) { throw new Exception("Please remove Cause: from the assembly name!"); } var assName = new AssemblyName(manualAssemblyWhitelistingName.Trim()); var res = TryWhitelistAssemblyName(assName, true); if (res != WhitelistingResult.Exists) { whitelistUpdated = true; } manualAssemblyWhitelisting = false; manualAssemblyWhitelistingName = InitialCustomName; } catch (Exception error) { ShowNotification(new GUIContent(error.Message)); } GUI.FocusControl(""); } if (GUILayout.Button("Cancel")) { manualAssemblyWhitelisting = false; manualAssemblyWhitelistingName = InitialCustomName; GUI.FocusControl(""); } } } EditorGUILayout.EndScrollView(); using (GUITools.Horizontal()) { GUILayout.Space(20); if (GUILayout.Button("Add Assembly")) { var assemblyPath = EditorUtility.OpenFilePanel("Choose an Assembly to add", "", "dll"); if (!string.IsNullOrEmpty(assemblyPath)) { whitelistUpdated |= TryWhitelistAssemblies(new[] { assemblyPath }, true); } } if (GUILayout.Button("Add Assemblies from filterFolder")) { var selectedFolder = EditorUtility.OpenFolderPanel("Choose a filterFolder with Assemblies", "", ""); if (!string.IsNullOrEmpty(selectedFolder)) { var libraries = EditorTools.FindLibrariesAt(selectedFolder); whitelistUpdated |= TryWhitelistAssemblies(libraries); } } if (!manualAssemblyWhitelisting) { if (GUILayout.Button("Add Assembly manually")) { manualAssemblyWhitelisting = true; } } if (count > 0) { if (GUILayout.Button("Clear")) { if (EditorUtility.DisplayDialog("Please confirm", "Are you sure you wish to completely clear your Injection Detector whitelist?", "Yes", "No")) { whitelist.Clear(); whitelistUpdated = true; } } } GUILayout.Space(20); } GUILayout.Space(20); if (whitelistUpdated) { WriteWhitelist(); } }
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(ACTkConstants.LogPrefix + "Can't find " + WallHackDetector.WireframeShaderName + " shader! Please report this to the " + ACTkEditorConstants.SupportEmail + " including your Unity version number."); } } 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"); } } } }
private void DrawRecordsPages() { recordsTotalPages = Math.Max(1, (int)Math.Ceiling((double)filteredRecords.Count / RecordsPerPage)); if (recordsCurrentPage < 0) { recordsCurrentPage = 0; } if (recordsCurrentPage + 1 > recordsTotalPages) { recordsCurrentPage = recordsTotalPages - 1; } var fromRecord = recordsCurrentPage * RecordsPerPage; var toRecord = fromRecord + Math.Min(RecordsPerPage, filteredRecords.Count - fromRecord); if (recordsTotalPages > 1) { GUILayout.Label("Prefs " + fromRecord + " - " + toRecord + " from " + filteredRecords.Count); } scrollPosition = GUILayout.BeginScrollView(scrollPosition); for (var i = fromRecord; i < toRecord; i++) { bool recordRemoved; DrawRecord(i, out recordRemoved); if (recordRemoved) { break; } } GUILayout.EndScrollView(); if (recordsTotalPages <= 1) { return; } GUILayout.Space(5); using (GUITools.Horizontal()) { GUILayout.FlexibleSpace(); GUI.enabled = recordsCurrentPage > 0; if (GUILayout.Button("<<", GUILayout.Width(50))) { RemoveNotification(); recordsCurrentPage = 0; scrollPosition = Vector2.zero; } if (GUILayout.Button("<", GUILayout.Width(50))) { RemoveNotification(); recordsCurrentPage--; scrollPosition = Vector2.zero; } GUI.enabled = true; GUILayout.Label(recordsCurrentPage + 1 + " of " + recordsTotalPages, GUITools.CenteredLabel, GUILayout.Width(100)); GUI.enabled = recordsCurrentPage < recordsTotalPages - 1; if (GUILayout.Button(">", GUILayout.Width(50))) { RemoveNotification(); recordsCurrentPage++; scrollPosition = Vector2.zero; } if (GUILayout.Button(">>", GUILayout.Width(50))) { RemoveNotification(); recordsCurrentPage = recordsTotalPages - 1; scrollPosition = Vector2.zero; } GUI.enabled = true; GUILayout.FlexibleSpace(); } }
protected void DrawRecord(int recordIndex, out bool recordRemoved) { recordRemoved = false; var record = filteredRecords[recordIndex]; GUITools.Separator(); using (GUITools.Horizontal(GUITools.PanelWithBackground)) { if (GUILayout.Button(new GUIContent("X", "Delete this pref."), GUITools.CompactButton, GUILayout.Width(20))) { record.Delete(); allRecords.Remove(record); filteredRecords.Remove(record); recordRemoved = true; return; } GUI.enabled = (record.dirtyValue || record.dirtyKey) && record.prefType != PrefsRecord.PrefsType.Unknown; if (GUILayout.Button(new GUIContent("S", "Save changes in this pref."), GUITools.CompactButton, GUILayout.Width(20))) { record.Save(); GUIUtility.keyboardControl = 0; } GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; if (record.Obscured) { GUI.enabled &= record.obscuredType == ObscuredPrefs.DataType.String || record.obscuredType == ObscuredPrefs.DataType.Int || record.obscuredType == ObscuredPrefs.DataType.Float; if (GUILayout.Button(new GUIContent("D", "Decrypt this pref using ObscuredPrefs"), GUITools.CompactButton, GUILayout.Width(25))) { record.Decrypt(); GUIUtility.keyboardControl = 0; } } else { if (GUILayout.Button(new GUIContent("E", "Encrypt this pref using ObscuredPrefs"), GUITools.CompactButton, GUILayout.Width(25))) { record.Encrypt(); GUIUtility.keyboardControl = 0; } } GUI.enabled = true; if (GUILayout.Button(new GUIContent("...", "Other operations"), GUITools.CompactButton, GUILayout.Width(25))) { ShowOtherMenu(record); } var guiColor = GUI.color; if (record.Obscured) { GUI.color = obscuredColor; } GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; if (record.Obscured && !(record.obscuredType == ObscuredPrefs.DataType.String || record.obscuredType == ObscuredPrefs.DataType.Int || record.obscuredType == ObscuredPrefs.DataType.Float)) { GUI.enabled = false; EditorGUILayout.TextField(record.Key, GUILayout.MaxWidth(200), GUILayout.MinWidth(50)); GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; } else { record.Key = EditorGUILayout.TextField(record.Key, GUILayout.MaxWidth(200), GUILayout.MinWidth(50)); } if ((record.prefType == PrefsRecord.PrefsType.String && !record.Obscured) || (record.Obscured && record.obscuredType == ObscuredPrefs.DataType.String)) { // to avoid TextMeshGenerator error because of too much characters if (record.StringValue.Length > 16382) { GUI.enabled = false; EditorGUILayout.TextField(StringTooLong, GUILayout.MinWidth(150)); GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; } else { record.StringValue = EditorGUILayout.TextField(record.StringValue, GUILayout.MinWidth(150)); } } else if (record.prefType == PrefsRecord.PrefsType.Int || (record.Obscured && record.obscuredType == ObscuredPrefs.DataType.Int)) { record.IntValue = EditorGUILayout.IntField(record.IntValue, GUILayout.MinWidth(150)); } else if (record.prefType == PrefsRecord.PrefsType.Float || (record.Obscured && record.obscuredType == ObscuredPrefs.DataType.Float)) { record.FloatValue = EditorGUILayout.FloatField(record.FloatValue, GUILayout.MinWidth(150)); } else if (record.Obscured) { GUI.enabled = false; EditorGUILayout.TextField(UnsupportedValueDescription, GUILayout.MinWidth(150)); GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; } else { GUI.enabled = false; EditorGUILayout.TextField(UnknownValueDescription, GUILayout.MinWidth(150)); GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; } GUI.color = guiColor; GUI.enabled = true; EditorGUILayout.LabelField(record.DisplayType, GUILayout.Width(70)); } }
// ------------------------------------------------------------------- // GUI // ------------------------------------------------------------------- private void OnGUI() { if (allRecords == null) { allRecords = new List <PrefsRecord>(); } if (filteredRecords == null) { filteredRecords = new List <PrefsRecord>(); } using (GUITools.Horizontal(GUITools.Toolbar)) { if (GUILayout.Button(new GUIContent("+", "Create new prefs record."), EditorStyles.toolbarButton, GUILayout.Width(20))) { addingNewRecord = true; } if (GUILayout.Button(new GUIContent("Refresh", "Re-read and re-parse all prefs."), EditorStyles.toolbarButton, GUILayout.Width(50))) { RefreshData(); GUIUtility.keyboardControl = 0; scrollPosition = Vector2.zero; recordsCurrentPage = 0; } EditorGUI.BeginChangeCheck(); sortingType = (SortingType)EditorGUILayout.EnumPopup(sortingType, EditorStyles.toolbarDropDown, GUILayout.Width(110)); if (EditorGUI.EndChangeCheck()) { ApplySorting(); } GUILayout.Space(10); EditorGUI.BeginChangeCheck(); searchPattern = GUITools.SearchToolbar(searchPattern); if (EditorGUI.EndChangeCheck()) { ApplyFiltering(); } } if (addingNewRecord) { using (GUITools.Horizontal(GUITools.PanelWithBackground)) { string[] types = { "String", "Int", "Float" }; newRecordType = EditorGUILayout.Popup(newRecordType, types, GUILayout.Width(50)); newRecordEncrypted = GUILayout.Toggle(newRecordEncrypted, new GUIContent("E", "Create new pref as encrypted ObscuredPref?"), GUITools.CompactButton, GUILayout.Width(25)); var guiColor = GUI.color; if (newRecordEncrypted) { GUI.color = obscuredColor; } GUILayout.Label("Key:", GUILayout.ExpandWidth(false)); newRecordKey = EditorGUILayout.TextField(newRecordKey); GUILayout.Label("Value:", GUILayout.ExpandWidth(false)); if (newRecordType == 0) { newRecordStringValue = EditorGUILayout.TextField(newRecordStringValue); } else if (newRecordType == 1) { newRecordIntValue = EditorGUILayout.IntField(newRecordIntValue); } else { newRecordFloatValue = EditorGUILayout.FloatField(newRecordFloatValue); } GUI.color = guiColor; if (GUILayout.Button("OK", GUITools.CompactButton, GUILayout.Width(30))) { if (string.IsNullOrEmpty(newRecordKey) || (newRecordType == 0 && string.IsNullOrEmpty(newRecordStringValue)) || (newRecordType == 1 && newRecordIntValue == 0) || (newRecordType == 2 && Math.Abs(newRecordFloatValue) < 0.00000001f)) { ShowNotification(new GUIContent("Please fill in the pref first!")); } else { PrefsRecord newRecord; if (newRecordType == 0) { newRecord = new PrefsRecord(newRecordKey, newRecordStringValue, newRecordEncrypted); } else if (newRecordType == 1) { newRecord = new PrefsRecord(newRecordKey, newRecordIntValue, newRecordEncrypted); } else { newRecord = new PrefsRecord(newRecordKey, newRecordFloatValue, newRecordEncrypted); } if (newRecord.Save()) { allRecords.Add(newRecord); ApplySorting(); CloseNewRecordPanel(); } } } if (GUILayout.Button("Cancel", GUITools.CompactButton, GUILayout.Width(60))) { CloseNewRecordPanel(); } } } using (GUITools.Vertical(GUITools.PanelWithBackground)) { GUILayout.Space(5); DrawRecordsPages(); GUILayout.Space(5); GUI.enabled = filteredRecords.Count > 0; using (GUITools.Horizontal()) { if (GUILayout.Button("Encrypt ALL", GUITools.CompactButton)) { if (EditorUtility.DisplayDialog("Obscure ALL prefs in list?", "This will apply obscuration to ALL unobscured prefs in the list.\nAre you sure you wish to do this?", "Yep", "Oh, no!")) { foreach (var record in filteredRecords) { record.Encrypt(); } GUIUtility.keyboardControl = 0; ApplySorting(); } } if (GUILayout.Button("Decrypt ALL", GUITools.CompactButton)) { if (EditorUtility.DisplayDialog("UnObscure ALL prefs in list?", "This will remove obscuration from ALL obscured prefs in the list if possible.\nAre you sure you wish to do this?", "Yep", "Oh, no!")) { foreach (var record in filteredRecords) { record.Decrypt(); } GUIUtility.keyboardControl = 0; ApplySorting(); } } if (GUILayout.Button("Save ALL", GUITools.CompactButton)) { if (EditorUtility.DisplayDialog("Save changes to ALL prefs in list?", "Are you sure you wish to save changes to ALL prefs in the list? This can't be undone!", "Yep", "Oh, no!")) { foreach (var record in filteredRecords) { record.Save(); } GUIUtility.keyboardControl = 0; ApplySorting(); } } if (GUILayout.Button("Delete ALL", GUITools.CompactButton)) { if (EditorUtility.DisplayDialog("Delete ALL prefs in list?", "Are you sure you wish to delete the ALL prefs in the list? This can't be undone!", "Yep", "Oh, no!")) { foreach (var record in filteredRecords) { record.Delete(); } RefreshData(); GUIUtility.keyboardControl = 0; } } } GUI.enabled = true; } }