Beispiel #1
0
        public string ApplyManagedPatch(IManagedPatch patch)
        {
            if (_currentActivePatchInfos.Any(pi => pi.Name == patch.PatchDefinition.Name))
            {
                return string.Format("{0} Already applied", patch.PatchDefinition.Name);
            }

            if (_appliedPatchInfos == null)
            {
                _appliedPatchInfos = new List<AppliedPatchInfo>();
            }

            _appliedPatchInfos.Add(
                new AppliedPatchInfo(patch.PatchDefinition.Name, patch.PatchDefinition.Version, PatchCategory.Internal)
             );

            patch.Inject(_assembly.MainModule);

            return string.Format("{0} Applied", patch.PatchDefinition.Name);
        }
        private void DrawPatchUI(IManagedPatch patch, int indent = 5)
        {
            var isActive = patch.IsActive;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(indent);

            var title = patch.Name;

            if (PatchManager.IsWaitingForLoad(patch.Id))
            {
                title += " (loading)";
            }
            else if (isActive)
            {
                title += " (active)";
            }
            var tooltip = patch.Id + "\n";

            if (!string.IsNullOrEmpty(patch.Description))
            {
                tooltip += "Description: " + patch.Description + "\n";
            }
            tooltip += "Patch Type: " + patch.GetType().Name;
            if (GUILayout.Button(new GUIContent(title, tooltip), isActive ? patchTitleActive : patchTitleInactive))
            {
                if (PatchManager.TryGetFilePathForPatch(patch.Id, out var path))
                {
                    EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(path));
                }
                else
                {
                    Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "Clicked " + patch.Id + ". File location is unknown.\nGroup: " + patch.Group + "\nName: " + patch.Name + "\nDescription: " + patch.Description);
                }
            }

            if (!isActive)
            {
                if (GUILayout.Button("Activate", GUILayout.Width(100)))
                {
                    patch.EnablePatch();
                    ToggleSelection();
                }
            }
            else
            {
                if (GUILayout.Button("Deactivate", GUILayout.Width(100)))
                {
                    patch.DisablePatch();
                    ToggleSelection();
                }
            }

            async void ToggleSelection()
            {
                var sel = Selection.activeObject;

                Selection.activeObject = null;
                if (!sel)
                {
                    return;
                }
                await Task.Delay(10);

                InternalEditorUtility.RepaintAllViews();
                Selection.activeObject = sel;
            }

            EditorGUILayout.EndHorizontal();
        }