RSNetAuditModule.cpp
Click a line number to link it. Shift-click to select a range.
| 1 | // Copyright (c) 2026 Reignance Studios. MIT License, see LICENSE. |
| 2 | |
| 3 | #include "Framework/Notifications/NotificationManager.h" |
| 4 | #include "HAL/IConsoleManager.h" |
| 5 | #include "HAL/PlatformProcess.h" |
| 6 | #include "Modules/ModuleManager.h" |
| 7 | #include "RSNetAuditRunner.h" |
| 8 | #include "ToolMenus.h" |
| 9 | #include "Widgets/Notifications/SNotificationList.h" |
| 10 | |
| 11 | #define LOCTEXT_NAMESPACE "RSNetAudit" |
| 12 | |
| 13 | class FRSNetAuditModule : public IModuleInterface |
| 14 | { |
| 15 | public: |
| 16 | virtual void StartupModule() override |
| 17 | { |
| 18 | UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateRaw(this, &FRSNetAuditModule::RegisterMenus)); |
| 19 | } |
| 20 | |
| 21 | virtual void ShutdownModule() override |
| 22 | { |
| 23 | UToolMenus::UnRegisterStartupCallback(this); |
| 24 | UToolMenus::UnregisterOwner(this); |
| 25 | } |
| 26 | |
| 27 | static void RunFromEditor() |
| 28 | { |
| 29 | const FRSAuditResult Result = FRSNetAuditRunner::Run(FRSAuditOptions()); |
| 30 | |
| 31 | FNotificationInfo Info(FText::Format( |
| 32 | LOCTEXT("Done", "GAS Net Audit: {0} errors, {1} warnings, {2} info"), |
| 33 | Result.Count(ERSAuditSeverity::Error), |
| 34 | Result.Count(ERSAuditSeverity::Warning), |
| 35 | Result.Count(ERSAuditSeverity::Info))); |
| 36 | Info.ExpireDuration = 8.f; |
| 37 | Info.bUseSuccessFailIcons = true; |
| 38 | const FString HtmlPath = Result.HtmlPath; |
| 39 | Info.Hyperlink = FSimpleDelegate::CreateLambda([HtmlPath]() |
| 40 | { |
| 41 | FPlatformProcess::LaunchFileInDefaultExternalApplication(*HtmlPath); |
| 42 | }); |
| 43 | Info.HyperlinkText = LOCTEXT("OpenReport", "Open report"); |
| 44 | |
| 45 | if (TSharedPtr<SNotificationItem> Item = FSlateNotificationManager::Get().AddNotification(Info)) |
| 46 | { |
| 47 | Item->SetCompletionState(Result.Count(ERSAuditSeverity::Error) > 0 ? SNotificationItem::CS_Fail : SNotificationItem::CS_Success); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | void RegisterMenus() |
| 53 | { |
| 54 | FToolMenuOwnerScoped OwnerScoped(this); |
| 55 | UToolMenu* Menu = UToolMenus::Get()->ExtendMenu(TEXT("LevelEditor.MainMenu.Tools")); |
| 56 | // The (Name, Label) overload is 5.4+; setting Label works on 5.3 too. |
| 57 | FToolMenuSection& Section = Menu->FindOrAddSection(TEXT("RSNetAudit")); |
| 58 | Section.Label = LOCTEXT("Section", "Multiplayer"); |
| 59 | Section.AddMenuEntry( |
| 60 | TEXT("RunGASNetAudit"), |
| 61 | LOCTEXT("Run", "Run GAS Net Audit"), |
| 62 | LOCTEXT("RunTip", "Scan abilities, PlayerStates and AttributeSets for multiplayer mistakes and open a report."), |
| 63 | FSlateIcon(), |
| 64 | FUIAction(FExecuteAction::CreateStatic(&FRSNetAuditModule::RunFromEditor))); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | static FAutoConsoleCommand GRSNetAuditCommand( |
| 69 | TEXT("RSNetAudit.Run"), |
| 70 | TEXT("Runs the GAS Net Audit and writes a report to Saved/RSNetAudit."), |
| 71 | FConsoleCommandDelegate::CreateStatic(&FRSNetAuditModule::RunFromEditor)); |
| 72 | |
| 73 | #undef LOCTEXT_NAMESPACE |
| 74 | |
| 75 | IMPLEMENT_MODULE(FRSNetAuditModule, RSNetAudit) |