diff --git a/lib/libimhex/include/hex/data_processor/attribute.hpp b/lib/libimhex/include/hex/data_processor/attribute.hpp index f0575042f..f0848858d 100644 --- a/lib/libimhex/include/hex/data_processor/attribute.hpp +++ b/lib/libimhex/include/hex/data_processor/attribute.hpp @@ -40,7 +40,16 @@ namespace hex::dp { [[nodiscard]] Node *getParentNode() const { return this->m_parentNode; } - [[nodiscard]] std::optional> &getOutputData() { return this->m_outputData; } + [[nodiscard]] std::vector& getOutputData() { + if (!this->m_outputData.empty()) + return this->m_outputData; + else + return this->m_defaultData; + } + + void clearOutputData() { this->m_outputData.clear(); } + + [[nodiscard]] std::vector& getDefaultData() { return this->m_defaultData; } static void setIdCounter(int id) { if (id > Attribute::s_idCounter) @@ -55,7 +64,8 @@ namespace hex::dp { std::map m_connectedAttributes; Node *m_parentNode = nullptr; - std::optional> m_outputData; + std::vector m_outputData; + std::vector m_defaultData; friend class Node; void setParentNode(Node *node) { this->m_parentNode = node; } diff --git a/lib/libimhex/include/hex/data_processor/node.hpp b/lib/libimhex/include/hex/data_processor/node.hpp index 734b23bb0..66f2ddf82 100644 --- a/lib/libimhex/include/hex/data_processor/node.hpp +++ b/lib/libimhex/include/hex/data_processor/node.hpp @@ -53,7 +53,7 @@ namespace hex::dp { void resetOutputData() { for (auto &attribute : this->m_attributes) - attribute.getOutputData().reset(); + attribute.clearOutputData(); } void resetProcessedInputs() { @@ -73,9 +73,9 @@ namespace hex::dp { Node::s_idCounter = id; } - std::vector getBufferOnInput(u32 index); - i128 getIntegerOnInput(u32 index); - long double getFloatOnInput(u32 index); + const std::vector& getBufferOnInput(u32 index); + const i128& getIntegerOnInput(u32 index); + const long double& getFloatOnInput(u32 index); void setBufferOnOutput(u32 index, const std::vector &data); void setIntegerOnOutput(u32 index, i128 integer); @@ -91,11 +91,15 @@ namespace hex::dp { static int s_idCounter; - Attribute *getConnectedInputAttribute(u32 index) { + Attribute& getAttribute(u32 index) { if (index >= this->getAttributes().size()) throw std::runtime_error("Attribute index out of bounds!"); - auto &connectedAttribute = this->getAttributes()[index].getConnectedAttributes(); + return this->getAttributes()[index]; + } + + Attribute *getConnectedInputAttribute(u32 index) { + const auto &connectedAttribute = this->getAttribute(index).getConnectedAttributes(); if (connectedAttribute.empty()) return nullptr; diff --git a/lib/libimhex/source/data_processor/node.cpp b/lib/libimhex/source/data_processor/node.cpp index b116238fc..b55baa33f 100644 --- a/lib/libimhex/source/data_processor/node.cpp +++ b/lib/libimhex/source/data_processor/node.cpp @@ -14,7 +14,7 @@ namespace hex::dp { attr.setParentNode(this); } - std::vector Node::getBufferOnInput(u32 index) { + const std::vector& Node::getBufferOnInput(u32 index) { auto attribute = this->getConnectedInputAttribute(index); if (attribute == nullptr) @@ -28,58 +28,62 @@ namespace hex::dp { auto &outputData = attribute->getOutputData(); - if (!outputData.has_value()) + if (outputData.empty()) throwNodeError("No data available at connected attribute"); - return outputData.value(); + return outputData; } - i128 Node::getIntegerOnInput(u32 index) { + const i128& Node::getIntegerOnInput(u32 index) { auto attribute = this->getConnectedInputAttribute(index); - if (attribute == nullptr) - throwNodeError(hex::format("Nothing connected to input '{0}'", LangEntry(this->m_attributes[index].getUnlocalizedName()))); + auto &outputData = [&] -> std::vector& { + if (attribute != nullptr) { + if (attribute->getType() != Attribute::Type::Integer) + throwNodeError("Tried to read integer from non-integer attribute"); - if (attribute->getType() != Attribute::Type::Integer) - throwNodeError("Tried to read integer from non-integer attribute"); + markInputProcessed(index); + attribute->getParentNode()->process(); - markInputProcessed(index); - attribute->getParentNode()->process(); + return attribute->getOutputData(); + } else { + return this->getAttribute(index).getOutputData(); + } + }(); - auto &outputData = attribute->getOutputData(); - - if (!outputData.has_value()) + if (outputData.empty()) throwNodeError("No data available at connected attribute"); - if (outputData->size() < sizeof(u64)) + if (outputData.size() < sizeof(i128)) throwNodeError("Not enough data provided for integer"); - return *reinterpret_cast(outputData->data()); + return *reinterpret_cast(outputData.data()); } - long double Node::getFloatOnInput(u32 index) { + const long double& Node::getFloatOnInput(u32 index) { auto attribute = this->getConnectedInputAttribute(index); - if (attribute == nullptr) - throwNodeError(hex::format("Nothing connected to input '{0}'", LangEntry(this->m_attributes[index].getUnlocalizedName()))); + auto &outputData = [&] -> std::vector& { + if (attribute != nullptr) { + if (attribute->getType() != Attribute::Type::Float) + throwNodeError("Tried to read integer from non-float attribute"); - if (attribute->getType() != Attribute::Type::Float) - throwNodeError("Tried to read float from non-float attribute"); + markInputProcessed(index); + attribute->getParentNode()->process(); - markInputProcessed(index); - attribute->getParentNode()->process(); + return attribute->getOutputData(); + } else { + return this->getAttribute(index).getOutputData(); + } + }(); - auto &outputData = attribute->getOutputData(); - - if (!outputData.has_value()) + if (outputData.empty()) throwNodeError("No data available at connected attribute"); - if (outputData->size() < sizeof(long double)) + if (outputData.size() < sizeof(long double)) throwNodeError("Not enough data provided for float"); - long double result = 0; - std::memcpy(&result, outputData->data(), sizeof(long double)); - return result; + return *reinterpret_cast(outputData.data()); } void Node::setBufferOnOutput(u32 index, const std::vector &data) { diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index 7e02a1620..1ec58bfe7 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -234,7 +234,7 @@ namespace hex::plugin::builtin { void process() override { this->m_value.reset(); - auto input = this->getIntegerOnInput(0); + const auto &input = this->getIntegerOnInput(0); this->m_value = input; } @@ -258,7 +258,7 @@ namespace hex::plugin::builtin { void process() override { this->m_value.reset(); - auto input = this->getFloatOnInput(0); + const auto &input = this->getFloatOnInput(0); this->m_value = input; } @@ -347,7 +347,7 @@ namespace hex::plugin::builtin { } void process() override { - auto input = this->getBufferOnInput(0); + const auto &input = this->getBufferOnInput(0); this->m_value = hex::encodeByteString(input); } @@ -362,7 +362,7 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto input = this->getBufferOnInput(0); + const auto &input = this->getBufferOnInput(0); std::vector output = input; for (auto &byte : output) @@ -377,8 +377,8 @@ namespace hex::plugin::builtin { 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); + const auto &inputA = this->getBufferOnInput(0); + const auto &inputB = this->getBufferOnInput(1); std::vector output(std::min(inputA.size(), inputB.size()), 0x00); @@ -394,8 +394,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getBufferOnInput(0); - auto inputB = this->getBufferOnInput(1); + const auto &inputA = this->getBufferOnInput(0); + const auto &inputB = this->getBufferOnInput(1); std::vector output(std::min(inputA.size(), inputB.size()), 0x00); @@ -411,8 +411,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getBufferOnInput(0); - auto inputB = this->getBufferOnInput(1); + const auto &inputA = this->getBufferOnInput(0); + const auto &inputB = this->getBufferOnInput(1); std::vector output(std::min(inputA.size(), inputB.size()), 0x00); @@ -428,8 +428,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getBufferOnInput(0); - auto inputB = this->getBufferOnInput(1); + const auto &inputA = this->getBufferOnInput(0); + const auto &inputB = this->getBufferOnInput(1); std::vector output(std::min(inputA.size(), inputB.size()), 0x00); @@ -445,8 +445,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto address = this->getIntegerOnInput(0); - auto size = this->getIntegerOnInput(1); + const auto &address = this->getIntegerOnInput(0); + const auto &size = this->getIntegerOnInput(1); std::vector data; data.resize(size); @@ -462,8 +462,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto address = this->getIntegerOnInput(0); - auto data = this->getBufferOnInput(1); + const auto &address = this->getIntegerOnInput(0); + const auto &data = this->getBufferOnInput(1); this->setOverlayData(address, data); } @@ -508,7 +508,7 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto input = this->getIntegerOnInput(0); + const auto &input = this->getIntegerOnInput(0); std::vector output(sizeof(input), 0x00); std::memcpy(output.data(), &input, sizeof(input)); @@ -522,7 +522,7 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto input = this->getBufferOnInput(0); + const auto &input = this->getBufferOnInput(0); i64 output = 0; if (input.empty() || input.size() > sizeof(output)) @@ -539,7 +539,7 @@ namespace hex::plugin::builtin { 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); + const auto &input = this->getFloatOnInput(0); std::vector output(sizeof(input), 0x00); std::memcpy(output.data(), &input, sizeof(input)); @@ -553,7 +553,7 @@ namespace hex::plugin::builtin { 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); + const auto &input = this->getBufferOnInput(0); float output = 0; if (input.empty() || input.size() != sizeof(output)) @@ -570,8 +570,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); auto output = inputA + inputB; @@ -584,8 +584,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); auto output = inputA - inputB; @@ -598,8 +598,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); auto output = inputA * inputB; @@ -612,8 +612,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); if (inputB == 0) throwNodeError("Division by zero"); @@ -629,8 +629,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); if (inputB == 0) throwNodeError("Division by zero"); @@ -646,7 +646,7 @@ namespace hex::plugin::builtin { 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); + const auto &input = this->getBufferOnInput(0); double output = std::reduce(input.begin(), input.end(), double(0)) / double(input.size()); @@ -681,7 +681,7 @@ namespace hex::plugin::builtin { 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); + const auto &input = this->getFloatOnInput(0); this->setIntegerOnOutput(1, std::ceil(input)); } @@ -692,7 +692,7 @@ namespace hex::plugin::builtin { 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); + const auto &input = this->getFloatOnInput(0); this->setIntegerOnOutput(1, std::floor(input)); } @@ -703,7 +703,7 @@ namespace hex::plugin::builtin { 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); + const auto &input = this->getFloatOnInput(0); this->setIntegerOnOutput(1, std::round(input)); } @@ -714,10 +714,10 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto inputA = this->getBufferOnInput(0); - auto inputB = this->getBufferOnInput(1); + const auto &inputA = this->getBufferOnInput(0); + const auto &inputB = this->getBufferOnInput(1); - auto &output = inputA; + auto output = inputA; std::copy(inputB.begin(), inputB.end(), std::back_inserter(output)); this->setBufferOnOutput(2, output); @@ -729,9 +729,9 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto input = this->getBufferOnInput(0); - auto from = this->getIntegerOnInput(1); - auto to = this->getIntegerOnInput(2); + const auto &input = this->getBufferOnInput(0); + const auto &from = this->getIntegerOnInput(1); + const auto &to = this->getIntegerOnInput(2); if (from < 0 || static_cast(from) >= input.size()) throwNodeError("'from' input out of range"); @@ -749,8 +749,8 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto buffer = this->getBufferOnInput(0); - auto count = this->getIntegerOnInput(1); + const auto &buffer = this->getBufferOnInput(0); + const auto &count = this->getIntegerOnInput(1); std::vector output; output.resize(buffer.size() * count); @@ -768,8 +768,8 @@ namespace hex::plugin::builtin { void process() override { auto buffer = this->getBufferOnInput(0); - auto patch = this->getBufferOnInput(1); - auto address = this->getIntegerOnInput(2); + const auto &patch = this->getBufferOnInput(1); + const auto &address = this->getIntegerOnInput(2); if (address < 0 || static_cast(address) >= buffer.size()) throwNodeError("Address out of range"); @@ -788,7 +788,7 @@ namespace hex::plugin::builtin { 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); + const auto &buffer = this->getBufferOnInput(0); this->setIntegerOnOutput(1, buffer.size()); } @@ -803,9 +803,9 @@ namespace hex::plugin::builtin { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { } void process() override { - auto cond = this->getIntegerOnInput(0); - auto trueData = this->getBufferOnInput(1); - auto falseData = this->getBufferOnInput(2); + const auto &cond = this->getIntegerOnInput(0); + const auto &trueData = this->getBufferOnInput(1); + const auto &falseData = this->getBufferOnInput(2); if (cond != 0) this->setBufferOnOutput(3, trueData); @@ -822,8 +822,8 @@ namespace hex::plugin::builtin { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); this->setIntegerOnOutput(2, inputA == inputB); } @@ -836,7 +836,7 @@ namespace hex::plugin::builtin { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { } void process() override { - auto input = this->getIntegerOnInput(0); + const auto &input = this->getIntegerOnInput(0); this->setIntegerOnOutput(1, !input); } @@ -850,8 +850,8 @@ namespace hex::plugin::builtin { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); this->setIntegerOnOutput(2, inputA > inputB); } @@ -865,8 +865,8 @@ namespace hex::plugin::builtin { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); this->setIntegerOnOutput(2, inputA < inputB); } @@ -880,8 +880,8 @@ namespace hex::plugin::builtin { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); this->setIntegerOnOutput(2, inputA && inputB); } @@ -895,8 +895,8 @@ namespace hex::plugin::builtin { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { } void process() override { - auto inputA = this->getIntegerOnInput(0); - auto inputB = this->getIntegerOnInput(1); + const auto &inputA = this->getIntegerOnInput(0); + const auto &inputB = this->getIntegerOnInput(1); this->setIntegerOnOutput(2, inputA || inputB); } @@ -919,10 +919,10 @@ namespace hex::plugin::builtin { } void process() override { - auto key = this->getBufferOnInput(0); - auto iv = this->getBufferOnInput(1); - auto nonce = this->getBufferOnInput(2); - auto input = this->getBufferOnInput(3); + const auto &key = this->getBufferOnInput(0); + const auto &iv = this->getBufferOnInput(1); + const auto &nonce = this->getBufferOnInput(2); + const auto &input = this->getBufferOnInput(3); if (key.empty()) throwNodeError("Key cannot be empty"); @@ -963,7 +963,7 @@ namespace hex::plugin::builtin { 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") }) { } void process() override { - auto input = this->getBufferOnInput(0); + const auto &input = this->getBufferOnInput(0); auto output = crypt::decode64(input); @@ -1066,7 +1066,7 @@ namespace hex::plugin::builtin { } void process() override { - auto rawData = this->getBufferOnInput(0); + const auto &rawData = this->getBufferOnInput(0); this->m_texture = ImGui::Texture(rawData.data(), rawData.size()); } @@ -1091,9 +1091,9 @@ namespace hex::plugin::builtin { 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 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()) @@ -1139,7 +1139,7 @@ namespace hex::plugin::builtin { } void process() override { - auto buffer = this->getBufferOnInput(0); + const auto &buffer = this->getBufferOnInput(0); this->m_counts.fill(0x00); for (const auto &byte : buffer) { @@ -1385,17 +1385,17 @@ namespace hex::plugin::builtin { if (auto input = this->findInput(attribute.getUnlocalizedName()); input != nullptr) { switch (attribute.getType()) { case dp::Attribute::Type::Integer: { - auto value = this->getIntegerOnInput(*index); + const auto &value = this->getIntegerOnInput(*index); input->setValue(value); break; } case dp::Attribute::Type::Float: { - auto value = this->getFloatOnInput(*index); + const auto &value = this->getFloatOnInput(*index); input->setValue(value); break; } case dp::Attribute::Type::Buffer: { - auto value = this->getBufferOnInput(*index); + const auto &value = this->getBufferOnInput(*index); input->setValue(value); break; } diff --git a/plugins/builtin/source/content/views/view_data_processor.cpp b/plugins/builtin/source/content/views/view_data_processor.cpp index db0cee856..66d548c4b 100644 --- a/plugins/builtin/source/content/views/view_data_processor.cpp +++ b/plugins/builtin/source/content/views/view_data_processor.cpp @@ -383,7 +383,8 @@ namespace hex::plugin::builtin { for (auto &attribute : node->getAttributes()) { ImNodesPinShape pinShape; - switch (attribute.getType()) { + auto attributeType = attribute.getType(); + switch (attributeType) { default: case dp::Attribute::Type::Integer: pinShape = ImNodesPinShape_Circle; @@ -398,7 +399,38 @@ namespace hex::plugin::builtin { if (attribute.getIOType() == dp::Attribute::IOType::In) { ImNodes::BeginInputAttribute(attribute.getId(), pinShape); - ImGui::TextUnformatted(LangEntry(attribute.getUnlocalizedName())); + + if (attribute.getConnectedAttributes().empty() && attributeType != dp::Attribute::Type::Buffer) { + auto &defaultValue = attribute.getDefaultData(); + + ImGui::PushItemWidth(100_scaled); + if (attributeType == dp::Attribute::Type::Integer) { + defaultValue.resize(sizeof(i128)); + + auto value = i64(*reinterpret_cast(defaultValue.data())); + if (ImGui::InputScalar(LangEntry(attribute.getUnlocalizedName()), ImGuiDataType_S64, &value)) { + std::fill(defaultValue.begin(), defaultValue.end(), 0x00); + + i128 writeValue = value; + std::memcpy(defaultValue.data(), &writeValue, sizeof(writeValue)); + } + } else if (attributeType == dp::Attribute::Type::Float) { + defaultValue.resize(sizeof(long double)); + + auto value = double(*reinterpret_cast(defaultValue.data())); + if (ImGui::InputScalar(LangEntry(attribute.getUnlocalizedName()), ImGuiDataType_Double, &value)) { + std::fill(defaultValue.begin(), defaultValue.end(), 0x00); + + long double writeValue = value; + std::memcpy(defaultValue.data(), &writeValue, sizeof(writeValue)); + } + } + ImGui::PopItemWidth(); + + } else { + ImGui::TextUnformatted(LangEntry(attribute.getUnlocalizedName())); + } + ImNodes::EndInputAttribute(); } else if (attribute.getIOType() == dp::Attribute::IOType::Out) { ImNodes::BeginOutputAttribute(attribute.getId(), ImNodesPinShape(pinShape + 1));