2021-08-29 14:18:45 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
|
|
|
#include <hex/data_processor/node.hpp>
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2022-02-05 22:19:32 +01:00
|
|
|
#include <hex/api/localization.hpp>
|
2021-02-03 11:54:41 +01:00
|
|
|
#include <hex/helpers/crypto.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2022-02-05 22:19:32 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2021-02-03 11:54:41 +01:00
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
#include <content/views/view_data_processor.hpp>
|
|
|
|
|
2022-10-12 12:18:18 +02:00
|
|
|
#include <content/helpers/provider_extra_data.hpp>
|
2022-12-27 22:50:37 +01:00
|
|
|
#include <content/helpers/diagrams.hpp>
|
2022-10-12 12:18:18 +02:00
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
#include <cctype>
|
2022-02-05 22:19:32 +01:00
|
|
|
#include <random>
|
2021-02-04 00:21:53 +01:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
#include <imgui.h>
|
2022-02-06 13:55:15 +01:00
|
|
|
#include <implot.h>
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2021-08-29 14:18:45 +02:00
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
class NodeNullptr : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeNullptr() : Node("hex.builtin.nodes.constants.nullptr.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "") }) { }
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
void process() override {
|
2022-01-24 20:53:17 +01:00
|
|
|
this->setBufferOnOutput(0, {});
|
2021-02-04 00:21:53 +01:00
|
|
|
}
|
2021-02-08 23:17:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBuffer : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeBuffer() : Node("hex.builtin.nodes.constants.buffer.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "") }) { }
|
2021-02-08 23:17:30 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-09-12 21:28:02 +02:00
|
|
|
constexpr static int StepSize = 1, FastStepSize = 10;
|
2021-02-08 23:17:30 +01:00
|
|
|
|
2022-10-26 08:54:08 +02:00
|
|
|
ImGui::PushItemWidth(100_scaled);
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::InputScalar("hex.builtin.nodes.constants.buffer.size"_lang, ImGuiDataType_U32, &this->m_size, &StepSize, &FastStepSize);
|
2021-02-08 23:17:30 +01:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
if (this->m_buffer.size() != this->m_size)
|
|
|
|
this->m_buffer.resize(this->m_size, 0x00);
|
|
|
|
|
|
|
|
this->setBufferOnOutput(0, this->m_buffer);
|
|
|
|
}
|
2021-02-04 00:21:53 +01:00
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void store(nlohmann::json &j) const override {
|
2021-08-29 14:18:45 +02:00
|
|
|
j = nlohmann::json::object();
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
j["size"] = this->m_size;
|
|
|
|
j["data"] = this->m_buffer;
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void load(const nlohmann::json &j) override {
|
2022-02-01 22:09:44 +01:00
|
|
|
this->m_size = j["size"];
|
2021-05-18 18:06:47 +02:00
|
|
|
this->m_buffer = j["data"].get<std::vector<u8>>();
|
|
|
|
}
|
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
private:
|
2021-02-08 23:17:30 +01:00
|
|
|
u32 m_size = 1;
|
|
|
|
std::vector<u8> m_buffer;
|
2021-02-04 00:21:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeString : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeString() : Node("hex.builtin.nodes.constants.string.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "") }) {
|
2022-09-19 11:29:51 +02:00
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawNode() override {
|
2023-01-31 11:39:08 +01:00
|
|
|
ImGui::InputTextMultiline("##string", this->m_value, ImVec2(150_scaled, 0), ImGuiInputTextFlags_AllowTabInput);
|
2021-02-04 00:21:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
2022-10-26 08:54:08 +02:00
|
|
|
this->setBufferOnOutput(0, hex::decodeByteString(this->m_value));
|
2021-02-04 00:21:53 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void store(nlohmann::json &j) const override {
|
2021-08-29 14:18:45 +02:00
|
|
|
j = nlohmann::json::object();
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
j["data"] = this->m_value;
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void load(const nlohmann::json &j) override {
|
2022-07-15 11:37:10 +02:00
|
|
|
this->m_value = j["data"].get<std::string>();
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
private:
|
|
|
|
std::string m_value;
|
|
|
|
};
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
class NodeInteger : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeInteger() : Node("hex.builtin.nodes.constants.int.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-10-26 08:54:08 +02:00
|
|
|
ImGui::PushItemWidth(100_scaled);
|
2022-02-08 21:51:09 +01:00
|
|
|
ImGui::InputHexadecimal("##integer_value", &this->m_value);
|
2021-01-30 22:39:06 +01:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2022-02-08 08:32:10 +01:00
|
|
|
this->setIntegerOnOutput(0, this->m_value);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void store(nlohmann::json &j) const override {
|
2021-08-29 14:18:45 +02:00
|
|
|
j = nlohmann::json::object();
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
j["data"] = this->m_value;
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void load(const nlohmann::json &j) override {
|
2021-05-18 18:06:47 +02:00
|
|
|
this->m_value = j["data"];
|
|
|
|
}
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
private:
|
|
|
|
u64 m_value = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeFloat : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeFloat() : Node("hex.builtin.nodes.constants.float.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-10-26 08:54:08 +02:00
|
|
|
ImGui::PushItemWidth(100_scaled);
|
2021-01-30 22:39:06 +01:00
|
|
|
ImGui::InputScalar("##floatValue", ImGuiDataType_Float, &this->m_value, nullptr, nullptr, "%f", ImGuiInputTextFlags_CharsDecimal);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2022-02-08 08:32:10 +01:00
|
|
|
this->setFloatOnOutput(0, this->m_value);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void store(nlohmann::json &j) const override {
|
2021-08-29 14:18:45 +02:00
|
|
|
j = nlohmann::json::object();
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
j["data"] = this->m_value;
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void load(const nlohmann::json &j) override {
|
2021-05-18 18:06:47 +02:00
|
|
|
this->m_value = j["data"];
|
|
|
|
}
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
private:
|
|
|
|
float m_value = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeRGBA8 : public dp::Node {
|
|
|
|
public:
|
2021-02-13 15:15:32 +01:00
|
|
|
NodeRGBA8() : Node("hex.builtin.nodes.constants.rgba8.header",
|
2022-02-01 22:09:44 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.r"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.g"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.b"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.a") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-10-26 08:54:08 +02:00
|
|
|
ImGui::PushItemWidth(200_scaled);
|
2021-01-30 22:39:06 +01:00
|
|
|
ImGui::ColorPicker4("##colorPicker", &this->m_color.Value.x, ImGuiColorEditFlags_AlphaBar);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2023-02-09 23:07:04 +01:00
|
|
|
this->setBufferOnOutput(0, hex::toBytes<u8>(u8(this->m_color.Value.x * 0xFF)));
|
|
|
|
this->setBufferOnOutput(1, hex::toBytes<u8>(u8(this->m_color.Value.y * 0xFF)));
|
|
|
|
this->setBufferOnOutput(2, hex::toBytes<u8>(u8(this->m_color.Value.z * 0xFF)));
|
|
|
|
this->setBufferOnOutput(3, hex::toBytes<u8>(u8(this->m_color.Value.w * 0xFF)));
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void store(nlohmann::json &j) const override {
|
2021-08-29 14:18:45 +02:00
|
|
|
j = nlohmann::json::object();
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2022-02-01 22:09:44 +01:00
|
|
|
j["data"] = nlohmann::json::object();
|
2021-08-29 14:18:45 +02:00
|
|
|
j["data"]["r"] = this->m_color.Value.x;
|
|
|
|
j["data"]["g"] = this->m_color.Value.y;
|
|
|
|
j["data"]["b"] = this->m_color.Value.z;
|
|
|
|
j["data"]["a"] = this->m_color.Value.w;
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void load(const nlohmann::json &j) override {
|
2021-05-18 18:06:47 +02:00
|
|
|
this->m_color = ImVec4(j["data"]["r"], j["data"]["g"], j["data"]["b"], j["data"]["a"]);
|
|
|
|
}
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
private:
|
|
|
|
ImColor m_color;
|
|
|
|
};
|
|
|
|
|
2021-02-04 12:46:38 +01:00
|
|
|
class NodeComment : public dp::Node {
|
|
|
|
public:
|
2022-01-24 20:53:17 +01:00
|
|
|
NodeComment() : Node("hex.builtin.nodes.constants.comment.header", {}) {
|
2022-08-08 21:23:52 +02:00
|
|
|
|
2021-02-04 12:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawNode() override {
|
2022-08-08 21:23:52 +02:00
|
|
|
ImGui::InputTextMultiline("##string", this->m_comment, scaled(ImVec2(150, 100)));
|
2021-02-04 12:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void store(nlohmann::json &j) const override {
|
2021-08-29 14:18:45 +02:00
|
|
|
j = nlohmann::json::object();
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
j["comment"] = this->m_comment;
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void load(const nlohmann::json &j) override {
|
2022-07-15 11:37:10 +02:00
|
|
|
this->m_comment = j["comment"].get<std::string>();
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 12:46:38 +01:00
|
|
|
private:
|
|
|
|
std::string m_comment;
|
|
|
|
};
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
class NodeDisplayInteger : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeDisplayInteger() : Node("hex.builtin.nodes.display.int.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-10-26 08:54:08 +02:00
|
|
|
ImGui::PushItemWidth(150_scaled);
|
2021-01-30 22:39:06 +01:00
|
|
|
if (this->m_value.has_value())
|
2021-12-31 01:10:06 +01:00
|
|
|
ImGui::TextFormatted("0x{0:X}", this->m_value.value());
|
2021-01-30 22:39:06 +01:00
|
|
|
else
|
|
|
|
ImGui::TextUnformatted("???");
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2021-02-04 01:14:05 +01:00
|
|
|
this->m_value.reset();
|
2021-01-31 16:11:25 +01:00
|
|
|
auto input = this->getIntegerOnInput(0);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->m_value = input;
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-02-04 01:14:05 +01:00
|
|
|
std::optional<u64> m_value;
|
2021-01-30 22:39:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeDisplayFloat : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeDisplayFloat() : Node("hex.builtin.nodes.display.float.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.common.input") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-10-26 08:54:08 +02:00
|
|
|
ImGui::PushItemWidth(150_scaled);
|
2021-01-30 22:39:06 +01:00
|
|
|
if (this->m_value.has_value())
|
2021-12-31 01:10:06 +01:00
|
|
|
ImGui::TextFormatted("{0}", this->m_value.value());
|
2021-01-30 22:39:06 +01:00
|
|
|
else
|
|
|
|
ImGui::TextUnformatted("???");
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2021-02-04 01:14:05 +01:00
|
|
|
this->m_value.reset();
|
2021-01-31 16:11:25 +01:00
|
|
|
auto input = this->getFloatOnInput(0);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->m_value = input;
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-02-04 01:14:05 +01:00
|
|
|
std::optional<float> m_value;
|
2021-01-30 22:39:06 +01:00
|
|
|
};
|
|
|
|
|
2022-10-26 09:07:09 +02:00
|
|
|
class NodeDisplayBuffer : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeDisplayBuffer() : Node("hex.builtin.nodes.display.buffer.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input") }) { }
|
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
static const std::string Header = " Address 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ";
|
|
|
|
|
|
|
|
if (ImGui::BeginChild("##hex_view", scaled(ImVec2(ImGui::CalcTextSize(Header.c_str()).x, 200)), true)) {
|
|
|
|
ImGui::TextUnformatted(Header.c_str());
|
|
|
|
|
|
|
|
auto size = this->m_buffer.size();
|
|
|
|
ImGuiListClipper clipper;
|
|
|
|
|
|
|
|
clipper.Begin((size + 0x0F) / 0x10);
|
|
|
|
|
|
|
|
while (clipper.Step())
|
|
|
|
for (auto y = clipper.DisplayStart; y < clipper.DisplayEnd; y++) {
|
|
|
|
auto lineSize = ((size - y * 0x10) < 0x10) ? size % 0x10 : 0x10;
|
|
|
|
|
|
|
|
std::string line = hex::format(" {:08X}: ", y * 0x10);
|
|
|
|
for (u32 x = 0; x < 0x10; x++) {
|
|
|
|
if (x < lineSize)
|
|
|
|
line += hex::format("{:02X} ", this->m_buffer[y * 0x10 + x]);
|
|
|
|
else
|
|
|
|
line += " ";
|
|
|
|
|
|
|
|
if (x == 7) line += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
line += " ";
|
|
|
|
|
|
|
|
for (u32 x = 0; x < lineSize; x++) {
|
|
|
|
auto c = char(this->m_buffer[y * 0x10 + x]);
|
|
|
|
if (std::isprint(c))
|
|
|
|
line += c;
|
|
|
|
else
|
|
|
|
line += ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TextUnformatted(line.c_str());
|
|
|
|
}
|
|
|
|
clipper.End();
|
|
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
this->m_buffer = this->getBufferOnInput(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<u8> m_buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeDisplayString : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeDisplayString() : Node("hex.builtin.nodes.display.string.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input") }) { }
|
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
constexpr static auto LineLength = 50;
|
|
|
|
if (ImGui::BeginChild("##string_view", scaled(ImVec2(ImGui::CalcTextSize(" ").x * (LineLength + 4), 150)), true)) {
|
|
|
|
std::string_view string = this->m_value;
|
|
|
|
|
|
|
|
ImGuiListClipper clipper;
|
|
|
|
clipper.Begin((string.length() + (LineLength - 1)) / LineLength);
|
|
|
|
|
|
|
|
while (clipper.Step())
|
|
|
|
for (auto i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
|
|
|
auto line = string.substr(i * LineLength, LineLength);
|
|
|
|
ImGui::TextUnformatted("");
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::TextUnformatted(line.data(), line.data() + line.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
clipper.End();
|
|
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
|
|
|
|
|
|
|
this->m_value = hex::encodeByteString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_value;
|
|
|
|
};
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
class NodeBitwiseNOT : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeBitwiseNOT() : Node("hex.builtin.nodes.bitwise.not.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::vector<u8> output = input;
|
2021-01-30 22:39:06 +01:00
|
|
|
for (auto &byte : output)
|
|
|
|
byte = ~byte;
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(1, output);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-10 08:18:06 +01:00
|
|
|
class NodeBitwiseADD : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeBitwiseADD() : Node("hex.builtin.nodes.bitwise.add.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getBufferOnInput(0);
|
|
|
|
auto inputB = this->getBufferOnInput(1);
|
|
|
|
|
|
|
|
std::vector<u8> output(std::min(inputA.size(), inputB.size()), 0x00);
|
|
|
|
|
|
|
|
for (u32 i = 0; i < output.size(); i++)
|
|
|
|
output[i] = inputA[i] + inputB[i];
|
|
|
|
|
|
|
|
this->setBufferOnOutput(2, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
class NodeBitwiseAND : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeBitwiseAND() : Node("hex.builtin.nodes.bitwise.and.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getBufferOnInput(0);
|
|
|
|
auto inputB = this->getBufferOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::vector<u8> output(std::min(inputA.size(), inputB.size()), 0x00);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
for (u32 i = 0; i < output.size(); i++)
|
2021-02-04 01:14:05 +01:00
|
|
|
output[i] = inputA[i] & inputB[i];
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(2, output);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBitwiseOR : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeBitwiseOR() : Node("hex.builtin.nodes.bitwise.or.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getBufferOnInput(0);
|
|
|
|
auto inputB = this->getBufferOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::vector<u8> output(std::min(inputA.size(), inputB.size()), 0x00);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
for (u32 i = 0; i < output.size(); i++)
|
2021-02-04 01:14:05 +01:00
|
|
|
output[i] = inputA[i] | inputB[i];
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(2, output);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBitwiseXOR : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeBitwiseXOR() : Node("hex.builtin.nodes.bitwise.xor.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getBufferOnInput(0);
|
|
|
|
auto inputB = this->getBufferOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::vector<u8> output(std::min(inputA.size(), inputB.size()), 0x00);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
for (u32 i = 0; i < output.size(); i++)
|
2021-02-04 01:14:05 +01:00
|
|
|
output[i] = inputA[i] ^ inputB[i];
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(2, output);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeReadData : public dp::Node {
|
|
|
|
public:
|
2022-01-24 20:53:17 +01:00
|
|
|
NodeReadData() : Node("hex.builtin.nodes.data_access.read.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.read.address"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.read.size"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.data_access.read.data") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto address = this->getIntegerOnInput(0);
|
2022-02-01 22:09:44 +01:00
|
|
|
auto size = this->getIntegerOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
|
|
|
std::vector<u8> data;
|
2021-02-04 01:14:05 +01:00
|
|
|
data.resize(size);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
ImHexApi::Provider::get()->readRaw(address, data.data(), size);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(2, data);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeWriteData : public dp::Node {
|
|
|
|
public:
|
2022-01-24 20:53:17 +01:00
|
|
|
NodeWriteData() : Node("hex.builtin.nodes.data_access.write.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.write.address"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.data_access.write.data") }) { }
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto address = this->getIntegerOnInput(0);
|
2022-02-01 22:09:44 +01:00
|
|
|
auto data = this->getBufferOnInput(1);
|
2021-01-30 22:39:06 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setOverlayData(address, data);
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-18 21:24:33 +02:00
|
|
|
class NodeDataSize : public dp::Node {
|
|
|
|
public:
|
2022-01-24 20:53:17 +01:00
|
|
|
NodeDataSize() : Node("hex.builtin.nodes.data_access.size.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.size.size") }) { }
|
2021-05-18 21:24:33 +02:00
|
|
|
|
|
|
|
void process() override {
|
2021-09-21 02:29:54 +02:00
|
|
|
auto size = ImHexApi::Provider::get()->getActualSize();
|
2021-05-18 21:24:33 +02:00
|
|
|
|
|
|
|
this->setIntegerOnOutput(0, size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-07 22:46:22 +01:00
|
|
|
class NodeDataSelection : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeDataSelection() : Node("hex.builtin.nodes.data_access.selection.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.selection.address"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.selection.size") }) {
|
2022-11-08 21:43:22 +01:00
|
|
|
EventManager::subscribe<EventRegionSelected>(this, [this](const auto ®ion) {
|
2022-02-07 22:46:22 +01:00
|
|
|
this->m_address = region.address;
|
|
|
|
this->m_size = region.size;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
~NodeDataSelection() override {
|
|
|
|
EventManager::unsubscribe<EventRegionSelected>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
this->setIntegerOnOutput(0, this->m_address);
|
|
|
|
this->setIntegerOnOutput(1, this->m_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u64 m_address = 0;
|
|
|
|
size_t m_size = 0;
|
|
|
|
};
|
|
|
|
|
2021-01-31 01:42:29 +01:00
|
|
|
class NodeCastIntegerToBuffer : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeCastIntegerToBuffer() : Node("hex.builtin.nodes.casting.int_to_buffer.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto input = this->getIntegerOnInput(0);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2022-10-12 12:09:51 +02:00
|
|
|
std::vector<u8> output(sizeof(input), 0x00);
|
|
|
|
std::memcpy(output.data(), &input, sizeof(input));
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setBufferOnOutput(1, output);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeCastBufferToInteger : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeCastBufferToInteger() : Node("hex.builtin.nodes.casting.buffer_to_int.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2022-10-12 12:09:51 +02:00
|
|
|
i64 output = 0;
|
|
|
|
if (input.empty() || input.size() > sizeof(output))
|
2022-02-08 08:32:10 +01:00
|
|
|
throwNodeError("Buffer is empty or bigger than 64 bits");
|
|
|
|
|
|
|
|
std::memcpy(&output, input.data(), input.size());
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
this->setIntegerOnOutput(1, output);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-12 12:09:51 +02:00
|
|
|
class NodeCastFloatToBuffer : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeCastFloatToBuffer() : Node("hex.builtin.nodes.casting.float_to_buffer.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getFloatOnInput(0);
|
|
|
|
|
|
|
|
std::vector<u8> output(sizeof(input), 0x00);
|
|
|
|
std::memcpy(output.data(), &input, sizeof(input));
|
|
|
|
|
|
|
|
this->setBufferOnOutput(1, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeCastBufferToFloat : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeCastBufferToFloat() : Node("hex.builtin.nodes.casting.buffer_to_float.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
|
|
|
|
|
|
|
float output = 0;
|
|
|
|
if (input.empty() || input.size() != sizeof(output))
|
|
|
|
throwNodeError("Buffer is empty or not the right size to fit a float");
|
|
|
|
|
|
|
|
std::memcpy(&output, input.data(), input.size());
|
|
|
|
|
|
|
|
this->setFloatOnOutput(1, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-06 14:46:47 +01:00
|
|
|
class NodeArithmeticAdd : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeArithmeticAdd() : Node("hex.builtin.nodes.arithmetic.add.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-03-06 14:46:47 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
|
|
|
|
|
|
|
auto output = inputA + inputB;
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(2, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeArithmeticSubtract : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeArithmeticSubtract() : Node("hex.builtin.nodes.arithmetic.sub.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-03-06 14:46:47 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
|
|
|
|
|
|
|
auto output = inputA - inputB;
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(2, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeArithmeticMultiply : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeArithmeticMultiply() : Node("hex.builtin.nodes.arithmetic.mul.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-03-06 14:46:47 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
|
|
|
|
|
|
|
auto output = inputA * inputB;
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(2, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeArithmeticDivide : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeArithmeticDivide() : Node("hex.builtin.nodes.arithmetic.div.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-03-06 14:46:47 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
|
|
|
|
|
|
|
if (inputB == 0)
|
|
|
|
throwNodeError("Division by zero");
|
|
|
|
|
|
|
|
auto output = inputA / inputB;
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(2, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeArithmeticModulus : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeArithmeticModulus() : Node("hex.builtin.nodes.arithmetic.mod.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-03-06 14:46:47 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
|
|
|
|
|
|
|
if (inputB == 0)
|
|
|
|
throwNodeError("Division by zero");
|
|
|
|
|
|
|
|
auto output = inputA % inputB;
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(2, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-26 09:07:09 +02:00
|
|
|
class NodeArithmeticAverage : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeArithmeticAverage() : Node("hex.builtin.nodes.arithmetic.average.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
|
|
|
|
|
|
|
double output = std::reduce(input.begin(), input.end(), double(0)) / double(input.size());
|
|
|
|
|
|
|
|
this->setFloatOnOutput(1, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeArithmeticMedian : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeArithmeticMedian() : Node("hex.builtin.nodes.arithmetic.median.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
|
|
|
|
|
|
|
u64 medianIndex = input.size() / 2;
|
|
|
|
std::nth_element(input.begin(), input.begin() + medianIndex, input.end());
|
|
|
|
i128 median = 0;
|
|
|
|
|
|
|
|
if (input.size() % 2 == 0) {
|
|
|
|
std::nth_element(input.begin(), input.begin() + medianIndex - 1, input.end());
|
|
|
|
median = (input[medianIndex] + input[medianIndex - 1]) / 2;
|
|
|
|
} else {
|
|
|
|
median = input[medianIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(1, median);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-10 08:18:06 +01:00
|
|
|
class NodeArithmeticCeil : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeArithmeticCeil() : Node("hex.builtin.nodes.arithmetic.ceil.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getFloatOnInput(0);
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(1, std::ceil(input));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeArithmeticFloor : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeArithmeticFloor() : Node("hex.builtin.nodes.arithmetic.floor.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getFloatOnInput(0);
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(1, std::floor(input));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeArithmeticRound : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeArithmeticRound() : Node("hex.builtin.nodes.arithmetic.round.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getFloatOnInput(0);
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(1, std::round(input));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-07 13:44:22 +01:00
|
|
|
class NodeBufferCombine : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeBufferCombine() : Node("hex.builtin.nodes.buffer.combine.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.a"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input.b"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-03-07 13:44:22 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getBufferOnInput(0);
|
|
|
|
auto inputB = this->getBufferOnInput(1);
|
|
|
|
|
|
|
|
auto &output = inputA;
|
|
|
|
std::copy(inputB.begin(), inputB.end(), std::back_inserter(output));
|
|
|
|
|
|
|
|
this->setBufferOnOutput(2, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBufferSlice : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeBufferSlice() : Node("hex.builtin.nodes.buffer.slice.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.buffer.slice.input.buffer"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.buffer.slice.input.from"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.buffer.slice.input.to"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-03-07 13:44:22 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
2022-02-01 22:09:44 +01:00
|
|
|
auto from = this->getIntegerOnInput(1);
|
|
|
|
auto to = this->getIntegerOnInput(2);
|
2021-03-07 13:44:22 +01:00
|
|
|
|
2022-10-26 08:54:08 +02:00
|
|
|
if (from < 0 || static_cast<u128>(from) >= input.size())
|
2021-03-07 13:44:22 +01:00
|
|
|
throwNodeError("'from' input out of range");
|
2022-10-26 08:54:08 +02:00
|
|
|
if (to < 0 || static_cast<u128>(to) >= input.size())
|
2021-03-07 13:44:22 +01:00
|
|
|
throwNodeError("'to' input out of range");
|
2022-02-08 08:32:10 +01:00
|
|
|
if (to <= from)
|
2021-03-07 13:44:22 +01:00
|
|
|
throwNodeError("'to' input needs to be greater than 'from' input");
|
|
|
|
|
2022-10-26 08:54:08 +02:00
|
|
|
this->setBufferOnOutput(3, std::vector(input.begin() + u64(from), input.begin() + u64(to)));
|
2021-03-07 13:44:22 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBufferRepeat : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeBufferRepeat() : Node("hex.builtin.nodes.buffer.repeat.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.buffer.repeat.input.buffer"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.buffer.repeat.input.count"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-03-07 13:44:22 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto buffer = this->getBufferOnInput(0);
|
2022-02-01 22:09:44 +01:00
|
|
|
auto count = this->getIntegerOnInput(1);
|
2021-03-07 13:44:22 +01:00
|
|
|
|
|
|
|
std::vector<u8> output;
|
|
|
|
output.resize(buffer.size() * count);
|
|
|
|
|
|
|
|
for (u32 i = 0; i < count; i++)
|
|
|
|
std::copy(buffer.begin(), buffer.end(), output.begin() + buffer.size() * i);
|
|
|
|
|
|
|
|
this->setBufferOnOutput(2, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-26 09:07:09 +02:00
|
|
|
class NodeBufferPatch : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeBufferPatch() : Node("hex.builtin.nodes.buffer.patch.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.buffer.patch.input.patch"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.common.address"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto buffer = this->getBufferOnInput(0);
|
|
|
|
auto patch = this->getBufferOnInput(1);
|
|
|
|
auto address = this->getIntegerOnInput(2);
|
|
|
|
|
|
|
|
if (address < 0 || static_cast<u128>(address) >= buffer.size())
|
|
|
|
throwNodeError("Address out of range");
|
|
|
|
|
|
|
|
if (address + patch.size() > buffer.size())
|
|
|
|
buffer.resize(address + patch.size());
|
|
|
|
|
|
|
|
std::copy(patch.begin(), patch.end(), buffer.begin() + address);
|
|
|
|
|
|
|
|
this->setBufferOnOutput(3, buffer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-10 08:18:06 +01:00
|
|
|
class NodeBufferSize : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeBufferSize() : Node("hex.builtin.nodes.buffer.size.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.buffer.size.output") }) { }
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto buffer = this->getBufferOnInput(0);
|
|
|
|
|
|
|
|
this->setIntegerOnOutput(1, buffer.size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-31 01:42:29 +01:00
|
|
|
class NodeIf : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeIf() : Node("hex.builtin.nodes.control_flow.if.header",
|
2022-02-01 22:09:44 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.if.condition"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.control_flow.if.true"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.control_flow.if.false"),
|
2022-02-06 13:55:15 +01:00
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
2022-02-01 22:09:44 +01:00
|
|
|
auto cond = this->getIntegerOnInput(0);
|
|
|
|
auto trueData = this->getBufferOnInput(1);
|
2021-01-31 16:11:25 +01:00
|
|
|
auto falseData = this->getBufferOnInput(2);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
if (cond != 0)
|
|
|
|
this->setBufferOnOutput(3, trueData);
|
2021-01-31 01:42:29 +01:00
|
|
|
else
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setBufferOnOutput(3, falseData);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeEquals : public dp::Node {
|
|
|
|
public:
|
2021-02-13 15:15:32 +01:00
|
|
|
NodeEquals() : Node("hex.builtin.nodes.control_flow.equals.header",
|
2022-02-06 13:55:15 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA == inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeNot : public dp::Node {
|
|
|
|
public:
|
2021-02-13 15:15:32 +01:00
|
|
|
NodeNot() : Node("hex.builtin.nodes.control_flow.not.header",
|
2022-02-06 13:55:15 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto input = this->getIntegerOnInput(0);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(1, !input);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeGreaterThan : public dp::Node {
|
|
|
|
public:
|
2021-02-13 15:15:32 +01:00
|
|
|
NodeGreaterThan() : Node("hex.builtin.nodes.control_flow.gt.header",
|
2022-02-06 13:55:15 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA > inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeLessThan : public dp::Node {
|
|
|
|
public:
|
2021-02-13 15:15:32 +01:00
|
|
|
NodeLessThan() : Node("hex.builtin.nodes.control_flow.lt.header",
|
2022-02-06 13:55:15 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA < inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBoolAND : public dp::Node {
|
|
|
|
public:
|
2021-02-13 15:15:32 +01:00
|
|
|
NodeBoolAND() : Node("hex.builtin.nodes.control_flow.and.header",
|
2022-02-06 13:55:15 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA && inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBoolOR : public dp::Node {
|
|
|
|
public:
|
2021-02-13 15:15:32 +01:00
|
|
|
NodeBoolOR() : Node("hex.builtin.nodes.control_flow.or.header",
|
2022-02-06 13:55:15 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-01-31 16:11:25 +01:00
|
|
|
void process() override {
|
|
|
|
auto inputA = this->getIntegerOnInput(0);
|
|
|
|
auto inputB = this->getIntegerOnInput(1);
|
2021-01-31 01:42:29 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
this->setIntegerOnOutput(2, inputA || inputB);
|
2021-01-31 01:42:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
class NodeCryptoAESDecrypt : public dp::Node {
|
|
|
|
public:
|
2021-02-13 15:15:32 +01:00
|
|
|
NodeCryptoAESDecrypt() : Node("hex.builtin.nodes.crypto.aes.header",
|
2022-02-01 22:09:44 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.crypto.aes.key"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.crypto.aes.iv"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.crypto.aes.nonce"),
|
2022-02-06 13:55:15 +01:00
|
|
|
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"),
|
|
|
|
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-10-26 08:54:08 +02:00
|
|
|
ImGui::PushItemWidth(100_scaled);
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::Combo("hex.builtin.nodes.crypto.aes.mode"_lang, &this->m_mode, "ECB\0CBC\0CFB128\0CTR\0GCM\0CCM\0OFB\0");
|
|
|
|
ImGui::Combo("hex.builtin.nodes.crypto.aes.key_length"_lang, &this->m_keyLength, "128 Bits\000192 Bits\000256 Bits\000");
|
2021-02-04 00:21:53 +01:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
2022-02-01 22:09:44 +01:00
|
|
|
auto key = this->getBufferOnInput(0);
|
|
|
|
auto iv = this->getBufferOnInput(1);
|
2021-02-04 00:21:53 +01:00
|
|
|
auto nonce = this->getBufferOnInput(2);
|
|
|
|
auto input = this->getBufferOnInput(3);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
if (key.empty())
|
|
|
|
throwNodeError("Key cannot be empty");
|
2021-02-04 00:21:53 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
if (input.empty())
|
|
|
|
throwNodeError("Input cannot be empty");
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
std::array<u8, 8> ivData = { 0 }, nonceData = { 0 };
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
std::copy(iv.begin(), iv.end(), ivData.begin());
|
|
|
|
std::copy(nonce.begin(), nonce.end(), nonceData.begin());
|
2021-02-04 00:21:53 +01:00
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
auto output = crypt::aesDecrypt(static_cast<crypt::AESMode>(this->m_mode), static_cast<crypt::KeyLength>(this->m_keyLength), key, nonceData, ivData, input);
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
this->setBufferOnOutput(4, output);
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void store(nlohmann::json &j) const override {
|
2021-08-29 14:18:45 +02:00
|
|
|
j = nlohmann::json::object();
|
2021-05-18 18:06:47 +02:00
|
|
|
|
2022-02-01 22:09:44 +01:00
|
|
|
j["data"] = nlohmann::json::object();
|
|
|
|
j["data"]["mode"] = this->m_mode;
|
2021-08-29 14:18:45 +02:00
|
|
|
j["data"]["key_length"] = this->m_keyLength;
|
2021-05-18 18:06:47 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void load(const nlohmann::json &j) override {
|
2022-02-01 22:09:44 +01:00
|
|
|
this->m_mode = j["data"]["mode"];
|
2021-05-18 18:06:47 +02:00
|
|
|
this->m_keyLength = j["data"]["key_length"];
|
|
|
|
}
|
|
|
|
|
2021-02-04 00:21:53 +01:00
|
|
|
private:
|
2022-02-01 22:09:44 +01:00
|
|
|
int m_mode = 0;
|
2021-02-04 00:21:53 +01:00
|
|
|
int m_keyLength = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeDecodingBase64 : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeDecodingBase64() : Node("hex.builtin.nodes.decoding.base64.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
auto output = crypt::decode64(input);
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
this->setBufferOnOutput(1, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeDecodingHex : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeDecodingHex() : Node("hex.builtin.nodes.decoding.hex.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto input = this->getBufferOnInput(0);
|
|
|
|
|
2023-01-31 11:39:08 +01:00
|
|
|
input.erase(std::remove_if(input.begin(), input.end(), [](u8 c) { return std::isspace(c); }), input.end());
|
|
|
|
|
2021-02-04 01:14:05 +01:00
|
|
|
if (input.size() % 2 != 0)
|
|
|
|
throwNodeError("Can't decode odd number of hex characters");
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
std::vector<u8> output;
|
2021-02-04 01:14:05 +01:00
|
|
|
for (u32 i = 0; i < input.size(); i += 2) {
|
2021-02-04 12:46:38 +01:00
|
|
|
char c1 = static_cast<char>(std::tolower(input[i]));
|
|
|
|
char c2 = static_cast<char>(std::tolower(input[i + 1]));
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
if (!std::isxdigit(c1) || !isxdigit(c2))
|
2021-02-04 01:14:05 +01:00
|
|
|
throwNodeError("Can't decode non-hexadecimal character");
|
2021-02-04 00:21:53 +01:00
|
|
|
|
|
|
|
u8 value;
|
|
|
|
if (std::isdigit(c1))
|
|
|
|
value = (c1 - '0') << 4;
|
|
|
|
else
|
|
|
|
value = ((c1 - 'a') + 0x0A) << 4;
|
|
|
|
|
|
|
|
if (std::isdigit(c2))
|
|
|
|
value |= c2 - '0';
|
|
|
|
else
|
|
|
|
value |= (c2 - 'a') + 0x0A;
|
|
|
|
|
|
|
|
output.push_back(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setBufferOnOutput(1, output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-05 22:19:32 +01:00
|
|
|
class NodeVisualizerDigram : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeVisualizerDigram() : Node("hex.builtin.nodes.visualizer.digram.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input") }) { }
|
2022-02-05 22:19:32 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-12-27 22:50:37 +01:00
|
|
|
this->m_digram.draw(scaled({ 200, 200 }));
|
2022-06-03 11:17:41 +02:00
|
|
|
|
2022-10-13 15:14:16 +02:00
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
|
2022-06-03 11:17:41 +02:00
|
|
|
ImGui::BeginTooltip();
|
2022-12-27 22:50:37 +01:00
|
|
|
this->m_digram.draw(scaled({ 600, 600 }));
|
2022-06-03 11:17:41 +02:00
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 22:19:32 +01:00
|
|
|
void process() override {
|
2022-12-27 22:50:37 +01:00
|
|
|
this->m_digram.process(this->getBufferOnInput(0));
|
2022-02-05 22:19:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-12-27 22:50:37 +01:00
|
|
|
DiagramDigram m_digram;
|
2022-02-05 22:19:32 +01:00
|
|
|
};
|
|
|
|
|
2022-02-06 14:44:03 +01:00
|
|
|
class NodeVisualizerLayeredDistribution : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeVisualizerLayeredDistribution() : Node("hex.builtin.nodes.visualizer.layered_dist.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input") }) { }
|
|
|
|
|
|
|
|
void drawNode() override {
|
2022-12-27 22:50:37 +01:00
|
|
|
this->m_layeredDistribution.draw(scaled({ 200, 200 }));
|
2022-10-13 15:14:16 +02:00
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
|
2022-06-03 11:17:41 +02:00
|
|
|
ImGui::BeginTooltip();
|
2022-12-27 22:50:37 +01:00
|
|
|
this->m_layeredDistribution.draw(scaled({ 600, 600 }));
|
2022-06-03 11:17:41 +02:00
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-06 14:44:03 +01:00
|
|
|
void process() override {
|
2022-12-27 22:50:37 +01:00
|
|
|
this->m_layeredDistribution.process(this->getBufferOnInput(0));
|
2022-02-06 14:44:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-12-27 22:50:37 +01:00
|
|
|
DiagramLayeredDistribution m_layeredDistribution;
|
2022-02-06 14:44:03 +01:00
|
|
|
};
|
|
|
|
|
2022-02-06 01:32:15 +01:00
|
|
|
class NodeVisualizerImage : public dp::Node {
|
|
|
|
public:
|
2022-02-06 13:55:15 +01:00
|
|
|
NodeVisualizerImage() : Node("hex.builtin.nodes.visualizer.image.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input") }) { }
|
2022-02-06 01:32:15 +01:00
|
|
|
|
|
|
|
void drawNode() override {
|
2022-09-18 20:38:45 +02:00
|
|
|
ImGui::Image(this->m_texture, scaled(ImVec2(this->m_texture.getAspectRatio() * 200, 200)));
|
2022-10-13 15:14:16 +02:00
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
|
2022-06-03 11:17:41 +02:00
|
|
|
ImGui::BeginTooltip();
|
2022-09-18 20:38:45 +02:00
|
|
|
ImGui::Image(this->m_texture, scaled(ImVec2(this->m_texture.getAspectRatio() * 600, 600)));
|
2022-06-03 11:17:41 +02:00
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
2022-02-06 01:32:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto rawData = this->getBufferOnInput(0);
|
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
this->m_texture = ImGui::Texture(rawData.data(), rawData.size());
|
2022-02-06 01:32:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ImGui::Texture m_texture;
|
|
|
|
};
|
|
|
|
|
2022-10-13 15:13:53 +02:00
|
|
|
class NodeVisualizerImageRGBA : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeVisualizerImageRGBA() : Node("hex.builtin.nodes.visualizer.image_rgba.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.width"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.height") }) { }
|
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::Image(this->m_texture, scaled(ImVec2(this->m_texture.getAspectRatio() * 200, 200)));
|
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
|
|
|
|
ImGui::BeginTooltip();
|
|
|
|
ImGui::Image(this->m_texture, scaled(ImVec2(this->m_texture.getAspectRatio() * 600, 600)));
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
this->m_texture = { };
|
|
|
|
|
|
|
|
const auto rawData = this->getBufferOnInput(0);
|
|
|
|
const auto width = this->getIntegerOnInput(1);
|
|
|
|
const auto height = this->getIntegerOnInput(2);
|
|
|
|
|
|
|
|
const size_t requiredBytes = width * height * 4;
|
|
|
|
if (requiredBytes > rawData.size())
|
|
|
|
throwNodeError(hex::format("Image requires at least {} bytes of data, but only {} bytes are available", requiredBytes, rawData.size()));
|
|
|
|
|
|
|
|
this->m_texture = ImGui::Texture(rawData.data(), rawData.size(), width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ImGui::Texture m_texture;
|
|
|
|
};
|
|
|
|
|
2022-02-06 13:55:15 +01:00
|
|
|
class NodeVisualizerByteDistribution : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeVisualizerByteDistribution() : Node("hex.builtin.nodes.visualizer.byte_distribution.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.input") }) { }
|
|
|
|
|
|
|
|
void drawNode() override {
|
2022-06-03 11:17:41 +02:00
|
|
|
drawPlot(scaled({ 400, 300 }));
|
|
|
|
|
2022-10-13 15:14:16 +02:00
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsKeyDown(ImGuiKey_LeftShift)) {
|
2022-06-03 11:17:41 +02:00
|
|
|
ImGui::BeginTooltip();
|
|
|
|
drawPlot(scaled({ 700, 550 }));
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawPlot(const ImVec2 &viewSize) {
|
2022-08-03 23:32:34 +02:00
|
|
|
if (ImPlot::BeginPlot("##distribution", viewSize, ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect)) {
|
|
|
|
ImPlot::SetupAxes("Address", "Count", ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock | ImPlotAxisFlags_LogScale);
|
|
|
|
ImPlot::SetupAxesLimits(0, 256, 1, double(*std::max_element(this->m_counts.begin(), this->m_counts.end())) * 1.1F, ImGuiCond_Always);
|
|
|
|
|
2022-02-06 14:44:03 +01:00
|
|
|
static auto x = [] {
|
2022-02-06 13:55:15 +01:00
|
|
|
std::array<ImU64, 256> result { 0 };
|
|
|
|
std::iota(result.begin(), result.end(), 0);
|
|
|
|
return result;
|
|
|
|
}();
|
|
|
|
|
2022-02-06 14:44:03 +01:00
|
|
|
|
|
|
|
ImPlot::PlotBars<ImU64>("##bytes", x.data(), this->m_counts.data(), x.size(), 1);
|
2022-02-06 13:55:15 +01:00
|
|
|
|
|
|
|
ImPlot::EndPlot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto buffer = this->getBufferOnInput(0);
|
|
|
|
|
|
|
|
this->m_counts.fill(0x00);
|
|
|
|
for (const auto &byte : buffer) {
|
2022-02-06 14:44:03 +01:00
|
|
|
this->m_counts[byte]++;
|
2022-02-06 13:55:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::array<ImU64, 256> m_counts = { 0 };
|
|
|
|
};
|
|
|
|
|
2022-10-12 12:18:18 +02:00
|
|
|
|
|
|
|
class NodePatternLanguageOutVariable : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodePatternLanguageOutVariable() : Node("hex.builtin.nodes.pattern_language.out_var.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
|
|
|
|
void drawNode() override {
|
2022-10-26 08:54:08 +02:00
|
|
|
ImGui::PushItemWidth(100_scaled);
|
2022-10-12 12:18:18 +02:00
|
|
|
ImGui::InputText("##name", this->m_name);
|
2022-10-12 12:24:54 +02:00
|
|
|
ImGui::PopItemWidth();
|
2022-10-12 12:18:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto &pl = ProviderExtraData::getCurrent().patternLanguage;
|
|
|
|
|
|
|
|
std::scoped_lock lock(pl.runtimeMutex);
|
|
|
|
const auto &outVars = pl.runtime->getOutVariables();
|
|
|
|
|
|
|
|
if (outVars.contains(this->m_name)) {
|
|
|
|
std::visit(overloaded {
|
|
|
|
[](const std::string &) {},
|
|
|
|
[](pl::ptrn::Pattern *) {},
|
|
|
|
[this](auto &&value) {
|
|
|
|
std::vector<u8> buffer(std::min<size_t>(sizeof(value), 8));
|
|
|
|
std::memcpy(buffer.data(), &value, buffer.size());
|
|
|
|
|
|
|
|
this->setBufferOnOutput(0, buffer);
|
|
|
|
}
|
|
|
|
}, outVars.at(this->m_name));
|
|
|
|
} else {
|
|
|
|
throwNodeError(hex::format("Out variable '{}' has not been defined!", this->m_name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
void store(nlohmann::json &j) const override {
|
|
|
|
j = nlohmann::json::object();
|
|
|
|
|
|
|
|
j["name"] = this->m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void load(const nlohmann::json &j) override {
|
|
|
|
this->m_name = j["name"].get<std::string>();
|
|
|
|
}
|
|
|
|
|
2022-10-12 12:18:18 +02:00
|
|
|
private:
|
|
|
|
std::string m_name;
|
|
|
|
};
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
class NodeCustomInput : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeCustomInput() : Node("hex.builtin.nodes.custom.input.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input") }) { }
|
|
|
|
~NodeCustomInput() override = default;
|
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::PushItemWidth(100_scaled);
|
|
|
|
if (ImGui::Combo("##type", &this->m_type, "Integer\0Float\0Buffer\0")) {
|
|
|
|
this->setAttributes({
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::Out, this->getType(), "hex.builtin.nodes.common.input") }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::InputText("##name", this->m_name)) {
|
|
|
|
this->setUnlocalizedTitle(this->m_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setValue(auto value) { this->m_value = std::move(value); }
|
|
|
|
|
|
|
|
const std::string &getName() const { return this->m_name; }
|
|
|
|
dp::Attribute::Type getType() const {
|
|
|
|
switch (this->m_type) {
|
|
|
|
default:
|
|
|
|
case 0: return dp::Attribute::Type::Integer;
|
|
|
|
case 1: return dp::Attribute::Type::Float;
|
|
|
|
case 2: return dp::Attribute::Type::Buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
std::visit(overloaded {
|
|
|
|
[this](i128 value) { this->setIntegerOnOutput(0, value); },
|
|
|
|
[this](long double value) { this->setFloatOnOutput(0, value); },
|
|
|
|
[this](const std::vector<u8> &value) { this->setBufferOnOutput(0, value); }
|
|
|
|
}, this->m_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void store(nlohmann::json &j) const override {
|
|
|
|
j = nlohmann::json::object();
|
|
|
|
|
|
|
|
j["name"] = this->m_name;
|
|
|
|
j["type"] = this->m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void load(const nlohmann::json &j) override {
|
|
|
|
this->m_name = j["name"].get<std::string>();
|
|
|
|
this->m_type = j["type"];
|
2023-02-10 08:18:06 +01:00
|
|
|
|
|
|
|
this->setUnlocalizedTitle(this->m_name);
|
|
|
|
this->setAttributes({
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::Out, this->getType(), "hex.builtin.nodes.common.input") }
|
|
|
|
});
|
2023-02-09 23:07:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_name = LangEntry(this->getUnlocalizedName());
|
|
|
|
int m_type = 0;
|
|
|
|
|
|
|
|
std::variant<i128, long double, std::vector<u8>> m_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeCustomOutput : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeCustomOutput() : Node("hex.builtin.nodes.custom.output.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
|
|
|
|
~NodeCustomOutput() override = default;
|
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
ImGui::PushItemWidth(100_scaled);
|
|
|
|
if (ImGui::Combo("##type", &this->m_type, "Integer\0Float\0Buffer\0")) {
|
|
|
|
this->setAttributes({
|
2023-02-10 08:18:06 +01:00
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, this->getType(), "hex.builtin.nodes.common.output") }
|
2023-02-09 23:07:04 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::InputText("##name", this->m_name)) {
|
|
|
|
this->setUnlocalizedTitle(this->m_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &getName() const { return this->m_name; }
|
|
|
|
dp::Attribute::Type getType() const {
|
|
|
|
switch (this->m_type) {
|
|
|
|
case 0: return dp::Attribute::Type::Integer;
|
|
|
|
case 1: return dp::Attribute::Type::Float;
|
|
|
|
case 2: return dp::Attribute::Type::Buffer;
|
|
|
|
default: return dp::Attribute::Type::Integer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
switch (this->getType()) {
|
|
|
|
case dp::Attribute::Type::Integer: this->m_value = this->getIntegerOnInput(0); break;
|
|
|
|
case dp::Attribute::Type::Float: this->m_value = this->getFloatOnInput(0); break;
|
|
|
|
case dp::Attribute::Type::Buffer: this->m_value = this->getBufferOnInput(0); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& getValue() const { return this->m_value; }
|
|
|
|
|
|
|
|
void store(nlohmann::json &j) const override {
|
|
|
|
j = nlohmann::json::object();
|
|
|
|
|
|
|
|
j["name"] = this->m_name;
|
|
|
|
j["type"] = this->m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void load(const nlohmann::json &j) override {
|
|
|
|
this->m_name = j["name"].get<std::string>();
|
|
|
|
this->m_type = j["type"];
|
2023-02-10 08:18:06 +01:00
|
|
|
|
|
|
|
this->setUnlocalizedTitle(this->m_name);
|
|
|
|
this->setAttributes({
|
|
|
|
{ dp::Attribute(dp::Attribute::IOType::In, this->getType(), "hex.builtin.nodes.common.output") }
|
|
|
|
});
|
2023-02-09 23:07:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_name = LangEntry(this->getUnlocalizedName());
|
|
|
|
int m_type = 0;
|
|
|
|
|
|
|
|
std::variant<i128, long double, std::vector<u8>> m_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeCustom : public dp::Node {
|
|
|
|
public:
|
|
|
|
NodeCustom() : Node("hex.builtin.nodes.custom.custom.header", {}) { }
|
|
|
|
~NodeCustom() override = default;
|
|
|
|
|
|
|
|
void drawNode() override {
|
|
|
|
if (this->m_requiresAttributeUpdate) {
|
|
|
|
this->m_requiresAttributeUpdate = false;
|
|
|
|
this->setAttributes(this->findAttributes());
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::PushItemWidth(200_scaled);
|
|
|
|
|
|
|
|
bool editing = false;
|
|
|
|
if (this->m_editable) {
|
|
|
|
ImGui::InputTextIcon("##name", ICON_VS_SYMBOL_KEY, this->m_name);
|
|
|
|
editing = ImGui::IsItemActive();
|
|
|
|
|
|
|
|
if (ImGui::Button("hex.builtin.nodes.custom.custom.edit"_lang, ImVec2(200_scaled, ImGui::GetTextLineHeightWithSpacing()))) {
|
2023-02-10 08:18:06 +01:00
|
|
|
auto &data = ProviderExtraData::getCurrent().dataProcessor;
|
|
|
|
data.workspaceStack.push_back(&this->m_workspace);
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
this->m_requiresAttributeUpdate = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this->setUnlocalizedTitle(this->m_name);
|
|
|
|
|
|
|
|
if (this->getAttributes().empty()) {
|
|
|
|
ImGui::TextUnformatted("hex.builtin.nodes.custom.custom.edit_hint"_lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->m_editable = ImGui::GetIO().KeyShift || editing;
|
|
|
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void process() override {
|
|
|
|
auto indexFromId = [this](u32 id) -> std::optional<u32> {
|
|
|
|
const auto &attributes = this->getAttributes();
|
|
|
|
for (u32 i = 0; i < attributes.size(); i++)
|
|
|
|
if (u32(attributes[i].getId()) == id)
|
|
|
|
return i;
|
|
|
|
return std::nullopt;
|
|
|
|
};
|
|
|
|
|
2023-02-10 11:22:11 +01:00
|
|
|
auto prevContext = ImNodes::GetCurrentContext();
|
|
|
|
ImNodes::SetCurrentContext(this->m_workspace.context.get());
|
|
|
|
ON_SCOPE_EXIT { ImNodes::SetCurrentContext(prevContext); };
|
|
|
|
|
2023-02-09 23:07:04 +01:00
|
|
|
// Forward inputs to input nodes values
|
|
|
|
for (auto &attribute : this->getAttributes()) {
|
|
|
|
auto index = indexFromId(attribute.getId());
|
|
|
|
if (!index.has_value())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (auto input = this->findInput(attribute.getUnlocalizedName()); input != nullptr) {
|
|
|
|
switch (attribute.getType()) {
|
|
|
|
case dp::Attribute::Type::Integer: {
|
|
|
|
auto value = this->getIntegerOnInput(*index);
|
|
|
|
input->setValue(value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case dp::Attribute::Type::Float: {
|
|
|
|
auto value = this->getFloatOnInput(*index);
|
|
|
|
input->setValue(value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case dp::Attribute::Type::Buffer: {
|
|
|
|
auto value = this->getBufferOnInput(*index);
|
|
|
|
input->setValue(value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process all nodes in our workspace
|
|
|
|
for (auto &endNode : this->m_workspace.endNodes) {
|
|
|
|
endNode->resetOutputData();
|
|
|
|
|
|
|
|
for (auto &node : this->m_workspace.nodes)
|
|
|
|
node->resetProcessedInputs();
|
|
|
|
|
|
|
|
endNode->process();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forward output node values to outputs
|
|
|
|
for (auto &attribute : this->getAttributes()) {
|
|
|
|
auto index = indexFromId(attribute.getId());
|
|
|
|
if (!index.has_value())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (auto output = this->findOutput(attribute.getUnlocalizedName()); output != nullptr) {
|
|
|
|
switch (attribute.getType()) {
|
|
|
|
case dp::Attribute::Type::Integer: {
|
|
|
|
auto value = std::get<i128>(output->getValue());
|
|
|
|
this->setIntegerOnOutput(*index, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case dp::Attribute::Type::Float: {
|
|
|
|
auto value = std::get<long double>(output->getValue());
|
|
|
|
this->setFloatOnOutput(*index, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case dp::Attribute::Type::Buffer: {
|
|
|
|
auto value = std::get<std::vector<u8>>(output->getValue());
|
|
|
|
this->setBufferOnOutput(*index, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void store(nlohmann::json &j) const override {
|
|
|
|
j = nlohmann::json::object();
|
|
|
|
|
|
|
|
j["nodes"] = ViewDataProcessor::saveNodes(this->m_workspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
void load(const nlohmann::json &j) override {
|
|
|
|
ViewDataProcessor::loadNodes(this->m_workspace, j["nodes"]);
|
|
|
|
|
|
|
|
this->m_name = LangEntry(this->getUnlocalizedTitle()).get();
|
|
|
|
this->m_requiresAttributeUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<dp::Attribute> findAttributes() {
|
|
|
|
std::vector<dp::Attribute> result;
|
|
|
|
|
|
|
|
for (auto &node : this->m_workspace.nodes) {
|
|
|
|
if (auto *inputNode = dynamic_cast<NodeCustomInput*>(node.get()); inputNode != nullptr)
|
|
|
|
result.emplace_back(dp::Attribute::IOType::In, inputNode->getType(), inputNode->getName());
|
|
|
|
else if (auto *outputNode = dynamic_cast<NodeCustomOutput*>(node.get()); outputNode != nullptr)
|
|
|
|
result.emplace_back(dp::Attribute::IOType::Out, outputNode->getType(), outputNode->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeCustomInput* findInput(const std::string &name) {
|
|
|
|
for (auto &node : this->m_workspace.nodes) {
|
|
|
|
if (auto *inputNode = dynamic_cast<NodeCustomInput*>(node.get()); inputNode != nullptr && inputNode->getName() == name)
|
|
|
|
return inputNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeCustomOutput* findOutput(const std::string &name) {
|
|
|
|
for (auto &node : this->m_workspace.nodes) {
|
|
|
|
if (auto *outputNode = dynamic_cast<NodeCustomOutput*>(node.get()); outputNode != nullptr && outputNode->getName() == name)
|
|
|
|
return outputNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_name = "hex.builtin.nodes.custom.custom.header"_lang;
|
|
|
|
|
|
|
|
bool m_editable = false;
|
|
|
|
|
|
|
|
bool m_requiresAttributeUpdate = false;
|
|
|
|
ProviderExtraData::Data::DataProcessor::Workspace m_workspace;
|
|
|
|
};
|
|
|
|
|
2021-01-30 22:39:06 +01:00
|
|
|
void registerDataProcessorNodes() {
|
2021-02-13 15:15:32 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeInteger>("hex.builtin.nodes.constants", "hex.builtin.nodes.constants.int");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeFloat>("hex.builtin.nodes.constants", "hex.builtin.nodes.constants.float");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeNullptr>("hex.builtin.nodes.constants", "hex.builtin.nodes.constants.nullptr");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBuffer>("hex.builtin.nodes.constants", "hex.builtin.nodes.constants.buffer");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeString>("hex.builtin.nodes.constants", "hex.builtin.nodes.constants.string");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeRGBA8>("hex.builtin.nodes.constants", "hex.builtin.nodes.constants.rgba8");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeComment>("hex.builtin.nodes.constants", "hex.builtin.nodes.constants.comment");
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDisplayInteger>("hex.builtin.nodes.display", "hex.builtin.nodes.display.int");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDisplayFloat>("hex.builtin.nodes.display", "hex.builtin.nodes.display.float");
|
2022-10-26 09:07:09 +02:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDisplayBuffer>("hex.builtin.nodes.display", "hex.builtin.nodes.display.buffer");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDisplayString>("hex.builtin.nodes.display", "hex.builtin.nodes.display.string");
|
2021-02-13 15:15:32 +01:00
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeReadData>("hex.builtin.nodes.data_access", "hex.builtin.nodes.data_access.read");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeWriteData>("hex.builtin.nodes.data_access", "hex.builtin.nodes.data_access.write");
|
2021-05-18 21:24:33 +02:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDataSize>("hex.builtin.nodes.data_access", "hex.builtin.nodes.data_access.size");
|
2022-02-07 22:46:22 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDataSelection>("hex.builtin.nodes.data_access", "hex.builtin.nodes.data_access.selection");
|
2021-02-13 15:15:32 +01:00
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCastIntegerToBuffer>("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.int_to_buffer");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCastBufferToInteger>("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.buffer_to_int");
|
2022-10-12 12:09:51 +02:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCastFloatToBuffer>("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.float_to_buffer");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCastBufferToFloat>("hex.builtin.nodes.casting", "hex.builtin.nodes.casting.buffer_to_float");
|
2021-02-13 15:15:32 +01:00
|
|
|
|
2021-03-06 14:46:47 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticAdd>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.add");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticSubtract>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.sub");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticMultiply>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.mul");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticDivide>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.div");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticModulus>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.mod");
|
2022-10-26 09:07:09 +02:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticAverage>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.average");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticMedian>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.median");
|
2023-02-10 08:18:06 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticCeil>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.ceil");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticFloor>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.floor");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeArithmeticRound>("hex.builtin.nodes.arithmetic", "hex.builtin.nodes.arithmetic.round");
|
2021-03-06 14:46:47 +01:00
|
|
|
|
2021-03-07 13:44:22 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBufferCombine>("hex.builtin.nodes.buffer", "hex.builtin.nodes.buffer.combine");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBufferSlice>("hex.builtin.nodes.buffer", "hex.builtin.nodes.buffer.slice");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBufferRepeat>("hex.builtin.nodes.buffer", "hex.builtin.nodes.buffer.repeat");
|
2022-10-26 09:07:09 +02:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBufferPatch>("hex.builtin.nodes.buffer", "hex.builtin.nodes.buffer.patch");
|
2023-02-10 08:18:06 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBufferSize>("hex.builtin.nodes.buffer", "hex.builtin.nodes.buffer.size");
|
2021-03-07 13:44:22 +01:00
|
|
|
|
2021-02-13 15:15:32 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeIf>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.if");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeEquals>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.equals");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeNot>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.not");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeGreaterThan>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.gt");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeLessThan>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.lt");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBoolAND>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.and");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBoolOR>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.or");
|
|
|
|
|
2023-02-10 08:18:06 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseADD>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.add");
|
2021-02-13 15:15:32 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseAND>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.and");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseOR>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.or");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseXOR>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.xor");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeBitwiseNOT>("hex.builtin.nodes.bitwise", "hex.builtin.nodes.bitwise.not");
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDecodingBase64>("hex.builtin.nodes.decoding", "hex.builtin.nodes.decoding.base64");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeDecodingHex>("hex.builtin.nodes.decoding", "hex.builtin.nodes.decoding.hex");
|
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCryptoAESDecrypt>("hex.builtin.nodes.crypto", "hex.builtin.nodes.crypto.aes");
|
2022-02-05 22:19:32 +01:00
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeVisualizerDigram>("hex.builtin.nodes.visualizer", "hex.builtin.nodes.visualizer.digram");
|
2022-02-06 14:44:03 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeVisualizerLayeredDistribution>("hex.builtin.nodes.visualizer", "hex.builtin.nodes.visualizer.layered_dist");
|
2022-02-06 01:32:15 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeVisualizerImage>("hex.builtin.nodes.visualizer", "hex.builtin.nodes.visualizer.image");
|
2022-10-13 15:13:53 +02:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeVisualizerImageRGBA>("hex.builtin.nodes.visualizer", "hex.builtin.nodes.visualizer.image_rgba");
|
2022-02-06 13:55:15 +01:00
|
|
|
ContentRegistry::DataProcessorNode::add<NodeVisualizerByteDistribution>("hex.builtin.nodes.visualizer", "hex.builtin.nodes.visualizer.byte_distribution");
|
2022-10-12 12:18:18 +02:00
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodePatternLanguageOutVariable>("hex.builtin.nodes.pattern_language", "hex.builtin.nodes.pattern_language.out_var");
|
2023-02-09 23:07:04 +01:00
|
|
|
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCustom>("hex.builtin.nodes.custom", "hex.builtin.nodes.custom.custom");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCustomInput>("hex.builtin.nodes.custom", "hex.builtin.nodes.custom.input");
|
|
|
|
ContentRegistry::DataProcessorNode::add<NodeCustomOutput>("hex.builtin.nodes.custom", "hex.builtin.nodes.custom.output");
|
2021-01-30 22:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|