From 24c0cc10a11ebf59af7e59b72882b4e88d11c555 Mon Sep 17 00:00:00 2001 From: iTrooz_ Date: Thu, 27 Oct 2022 13:21:54 +0200 Subject: [PATCH] sys: Load Tips from a local file instead of querying an API (#797) * store tips locally * C++ random implementation * show one different tip per day * fix json conversion to string * put tips.json in builtin romfs --- main/source/init/tasks.cpp | 13 ----------- plugins/builtin/romfs/tips.json | 23 +++++++++++++++++++ .../builtin/source/content/welcome_screen.cpp | 14 +++++++++-- 3 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 plugins/builtin/romfs/tips.json diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index 53a7aa654..03a7ede26 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -45,18 +45,6 @@ namespace hex::init { return true; } - static bool downloadInformation() { - hex::Net net; - - auto tip = net.getString(ImHexApiURL + "/tip"s, 200).get(); - if (tip.code != 200) - return false; - - ImHexApi::System::impl::addInitArgument("tip-of-the-day", tip.body); - - return true; - } - bool createDirectories() { bool result = true; @@ -319,7 +307,6 @@ namespace hex::init { { "Loading settings", loadSettings, false }, { "Loading plugins", loadPlugins, false }, { "Checking for updates", checkForUpdates, true }, - { "Downloading information", downloadInformation, true }, { "Loading fonts", loadFonts, true }, }; } diff --git a/plugins/builtin/romfs/tips.json b/plugins/builtin/romfs/tips.json new file mode 100644 index 000000000..e17ea73e3 --- /dev/null +++ b/plugins/builtin/romfs/tips.json @@ -0,0 +1,23 @@ +[ + { + "name" : "ImHex", + "tips" : [ + "Try pressing CTRL + Shift + P to open the command palette!", + "The data processor allows pre-processing of the binary input data before it's displayed without modifying the original data.", + "Take a closer look at the Splash screen :)", + "Check out the WerWolv/ImHex-Patterns repository for pre-made patterns and more!", + "ImHex can be easily extended with plugins through its API." + ] + }, + { + "name" : "Reverse Engineering", + "tips" : [ + "Reverse Engineering a foreign file format becomes a lot easier if you know some values that should be stored in there.", + "Ghidra, binwalk, Unicorn, x86dbg, DetectItEasy, Dependencies and CheatEngine are other fantastic and free reverse engineering tools!", + "ALWAYS read the documentation if there is one. It will save you a lot of time.", + "Tools are what you make of them, practice makes perfect.", + "Looking for patterns and repeating structures in binary data is always a good start.", + "The entropy graph is an easy way to quickly figure out where interesting data is stored and if the data is encrypted or compressed." + ] + } +] diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index d9cc3660e..be5f3d7a7 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace hex::plugin::builtin { @@ -549,8 +550,17 @@ namespace hex::plugin::builtin { } } - if (ImHexApi::System::getInitArguments().contains("tip-of-the-day")) { - s_tipOfTheDay = ImHexApi::System::getInitArguments()["tip-of-the-day"]; + auto tipsData = romfs::get("tips.json"); + if(tipsData.valid()){ + auto tipsCategories = nlohmann::json::parse(tipsData.string()); + + auto now = std::chrono::system_clock::now(); + auto days_since_epoch = std::chrono::duration_cast(now.time_since_epoch()); + std::mt19937 random(days_since_epoch.count()); + + auto chosenCategory = tipsCategories[random()%tipsCategories.size()]["tips"]; + auto chosenTip = chosenCategory[random()%chosenCategory.size()]; + s_tipOfTheDay = chosenTip.get(); bool showTipOfTheDay = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1); if (showTipOfTheDay)