1
0
mirror of synced 2024-11-12 02:00:52 +01:00

nodes: Improve precision of values passed between nodes

This commit is contained in:
WerWolv 2022-10-26 08:54:08 +02:00
parent f67c9735c5
commit 0c5e72ab6a
3 changed files with 32 additions and 32 deletions

View File

@ -104,12 +104,12 @@ namespace hex::dp {
} }
std::vector<u8> getBufferOnInput(u32 index); std::vector<u8> getBufferOnInput(u32 index);
i64 getIntegerOnInput(u32 index); i128 getIntegerOnInput(u32 index);
float getFloatOnInput(u32 index); long double getFloatOnInput(u32 index);
void setBufferOnOutput(u32 index, const std::vector<u8> &data); void setBufferOnOutput(u32 index, const std::vector<u8> &data);
void setIntegerOnOutput(u32 index, i64 integer); void setIntegerOnOutput(u32 index, i128 integer);
void setFloatOnOutput(u32 index, float floatingPoint); void setFloatOnOutput(u32 index, long double floatingPoint);
void setOverlayData(u64 address, const std::vector<u8> &data); void setOverlayData(u64 address, const std::vector<u8> &data);
}; };

View File

@ -34,7 +34,7 @@ namespace hex::dp {
return outputData.value(); return outputData.value();
} }
i64 Node::getIntegerOnInput(u32 index) { i128 Node::getIntegerOnInput(u32 index) {
auto attribute = this->getConnectedInputAttribute(index); auto attribute = this->getConnectedInputAttribute(index);
if (attribute == nullptr) if (attribute == nullptr)
@ -57,7 +57,7 @@ namespace hex::dp {
return *reinterpret_cast<i64 *>(outputData->data()); return *reinterpret_cast<i64 *>(outputData->data());
} }
float Node::getFloatOnInput(u32 index) { long double Node::getFloatOnInput(u32 index) {
auto attribute = this->getConnectedInputAttribute(index); auto attribute = this->getConnectedInputAttribute(index);
if (attribute == nullptr) if (attribute == nullptr)
@ -74,11 +74,11 @@ namespace hex::dp {
if (!outputData.has_value()) if (!outputData.has_value())
throwNodeError("No data available at connected attribute"); throwNodeError("No data available at connected attribute");
if (outputData->size() < sizeof(float)) if (outputData->size() < sizeof(long double))
throwNodeError("Not enough data provided for float"); throwNodeError("Not enough data provided for float");
float result = 0; long double result = 0;
std::memcpy(&result, outputData->data(), sizeof(float)); std::memcpy(&result, outputData->data(), sizeof(long double));
return result; return result;
} }
@ -94,7 +94,7 @@ namespace hex::dp {
attribute.getOutputData() = data; attribute.getOutputData() = data;
} }
void Node::setIntegerOnOutput(u32 index, i64 integer) { void Node::setIntegerOnOutput(u32 index, i128 integer) {
if (index >= this->getAttributes().size()) if (index >= this->getAttributes().size())
throwNodeError("Attribute index out of bounds!"); throwNodeError("Attribute index out of bounds!");
@ -103,13 +103,13 @@ namespace hex::dp {
if (attribute.getIOType() != Attribute::IOType::Out) if (attribute.getIOType() != Attribute::IOType::Out)
throwNodeError("Tried to set output data of an input attribute!"); throwNodeError("Tried to set output data of an input attribute!");
std::vector<u8> buffer(sizeof(u64), 0); std::vector<u8> buffer(sizeof(integer), 0);
std::memcpy(buffer.data(), &integer, sizeof(u64)); std::memcpy(buffer.data(), &integer, sizeof(integer));
attribute.getOutputData() = buffer; attribute.getOutputData() = buffer;
} }
void Node::setFloatOnOutput(u32 index, float floatingPoint) { void Node::setFloatOnOutput(u32 index, long double floatingPoint) {
if (index >= this->getAttributes().size()) if (index >= this->getAttributes().size())
throwNodeError("Attribute index out of bounds!"); throwNodeError("Attribute index out of bounds!");
@ -118,8 +118,8 @@ namespace hex::dp {
if (attribute.getIOType() != Attribute::IOType::Out) if (attribute.getIOType() != Attribute::IOType::Out)
throwNodeError("Tried to set output data of an input attribute!"); throwNodeError("Tried to set output data of an input attribute!");
std::vector<u8> buffer(sizeof(float), 0); std::vector<u8> buffer(sizeof(floatingPoint), 0);
std::memcpy(buffer.data(), &floatingPoint, sizeof(float)); std::memcpy(buffer.data(), &floatingPoint, sizeof(floatingPoint));
attribute.getOutputData() = buffer; attribute.getOutputData() = buffer;
} }

View File

@ -37,7 +37,7 @@ namespace hex::plugin::builtin {
void drawNode() override { void drawNode() override {
constexpr static int StepSize = 1, FastStepSize = 10; constexpr static int StepSize = 1, FastStepSize = 10;
ImGui::PushItemWidth(100); ImGui::PushItemWidth(100_scaled);
ImGui::InputScalar("hex.builtin.nodes.constants.buffer.size"_lang, ImGuiDataType_U32, &this->m_size, &StepSize, &FastStepSize); ImGui::InputScalar("hex.builtin.nodes.constants.buffer.size"_lang, ImGuiDataType_U32, &this->m_size, &StepSize, &FastStepSize);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
@ -73,13 +73,13 @@ namespace hex::plugin::builtin {
} }
void drawNode() override { void drawNode() override {
ImGui::PushItemWidth(100); ImGui::PushItemWidth(100_scaled);
ImGui::InputTextIcon("##string", ICON_VS_SYMBOL_KEY, this->m_value); ImGui::InputTextIcon("##string", ICON_VS_SYMBOL_KEY, this->m_value);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
void process() override { void process() override {
this->setBufferOnOutput(0, { this->m_value.begin(), this->m_value.end() }); this->setBufferOnOutput(0, hex::decodeByteString(this->m_value));
} }
void store(nlohmann::json &j) override { void store(nlohmann::json &j) override {
@ -101,7 +101,7 @@ namespace hex::plugin::builtin {
NodeInteger() : Node("hex.builtin.nodes.constants.int.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "") }) { } NodeInteger() : Node("hex.builtin.nodes.constants.int.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "") }) { }
void drawNode() override { void drawNode() override {
ImGui::PushItemWidth(100); ImGui::PushItemWidth(100_scaled);
ImGui::InputHexadecimal("##integer_value", &this->m_value); ImGui::InputHexadecimal("##integer_value", &this->m_value);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
@ -129,7 +129,7 @@ namespace hex::plugin::builtin {
NodeFloat() : Node("hex.builtin.nodes.constants.float.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "") }) { } NodeFloat() : Node("hex.builtin.nodes.constants.float.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Float, "") }) { }
void drawNode() override { void drawNode() override {
ImGui::PushItemWidth(100); ImGui::PushItemWidth(100_scaled);
ImGui::InputScalar("##floatValue", ImGuiDataType_Float, &this->m_value, nullptr, nullptr, "%f", ImGuiInputTextFlags_CharsDecimal); ImGui::InputScalar("##floatValue", ImGuiDataType_Float, &this->m_value, nullptr, nullptr, "%f", ImGuiInputTextFlags_CharsDecimal);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
@ -161,16 +161,16 @@ namespace hex::plugin::builtin {
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.a") }) { } dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.constants.rgba8.output.a") }) { }
void drawNode() override { void drawNode() override {
ImGui::PushItemWidth(200); ImGui::PushItemWidth(200_scaled);
ImGui::ColorPicker4("##colorPicker", &this->m_color.Value.x, ImGuiColorEditFlags_AlphaBar); ImGui::ColorPicker4("##colorPicker", &this->m_color.Value.x, ImGuiColorEditFlags_AlphaBar);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
void process() override { void process() override {
this->setBufferOnOutput(0, hex::toBytes<u64>(this->m_color.Value.x * 0xFF)); this->setBufferOnOutput(0, hex::toBytes<u8>(this->m_color.Value.x * 0xFF));
this->setBufferOnOutput(1, hex::toBytes<u64>(this->m_color.Value.y * 0xFF)); this->setBufferOnOutput(1, hex::toBytes<u8>(this->m_color.Value.y * 0xFF));
this->setBufferOnOutput(2, hex::toBytes<u64>(this->m_color.Value.z * 0xFF)); this->setBufferOnOutput(2, hex::toBytes<u8>(this->m_color.Value.z * 0xFF));
this->setBufferOnOutput(3, hex::toBytes<u64>(this->m_color.Value.w * 0xFF)); this->setBufferOnOutput(3, hex::toBytes<u8>(this->m_color.Value.w * 0xFF));
} }
void store(nlohmann::json &j) override { void store(nlohmann::json &j) override {
@ -224,7 +224,7 @@ namespace hex::plugin::builtin {
NodeDisplayInteger() : Node("hex.builtin.nodes.display.int.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input") }) { } NodeDisplayInteger() : Node("hex.builtin.nodes.display.int.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input") }) { }
void drawNode() override { void drawNode() override {
ImGui::PushItemWidth(150); ImGui::PushItemWidth(150_scaled);
if (this->m_value.has_value()) if (this->m_value.has_value())
ImGui::TextFormatted("0x{0:X}", this->m_value.value()); ImGui::TextFormatted("0x{0:X}", this->m_value.value());
else else
@ -248,7 +248,7 @@ namespace hex::plugin::builtin {
NodeDisplayFloat() : Node("hex.builtin.nodes.display.float.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.common.input") }) { } NodeDisplayFloat() : Node("hex.builtin.nodes.display.float.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Float, "hex.builtin.nodes.common.input") }) { }
void drawNode() override { void drawNode() override {
ImGui::PushItemWidth(150); ImGui::PushItemWidth(150_scaled);
if (this->m_value.has_value()) if (this->m_value.has_value())
ImGui::TextFormatted("{0}", this->m_value.value()); ImGui::TextFormatted("{0}", this->m_value.value());
else else
@ -559,14 +559,14 @@ namespace hex::plugin::builtin {
auto from = this->getIntegerOnInput(1); auto from = this->getIntegerOnInput(1);
auto to = this->getIntegerOnInput(2); auto to = this->getIntegerOnInput(2);
if (from < 0 || static_cast<u64>(from) >= input.size()) if (from < 0 || static_cast<u128>(from) >= input.size())
throwNodeError("'from' input out of range"); throwNodeError("'from' input out of range");
if (to < 0 || static_cast<u64>(from) >= input.size()) if (to < 0 || static_cast<u128>(to) >= input.size())
throwNodeError("'to' input out of range"); throwNodeError("'to' input out of range");
if (to <= from) if (to <= from)
throwNodeError("'to' input needs to be greater than 'from' input"); throwNodeError("'to' input needs to be greater than 'from' input");
this->setBufferOnOutput(3, std::vector(input.begin() + from, input.begin() + to)); this->setBufferOnOutput(3, std::vector(input.begin() + u64(from), input.begin() + u64(to)));
} }
}; };
@ -706,7 +706,7 @@ namespace hex::plugin::builtin {
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { } dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
void drawNode() override { void drawNode() override {
ImGui::PushItemWidth(100); ImGui::PushItemWidth(100_scaled);
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.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"); ImGui::Combo("hex.builtin.nodes.crypto.aes.key_length"_lang, &this->m_keyLength, "128 Bits\000192 Bits\000256 Bits\000");
ImGui::PopItemWidth(); ImGui::PopItemWidth();
@ -1089,7 +1089,7 @@ namespace hex::plugin::builtin {
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") }) { } 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 { void drawNode() override {
ImGui::PushItemWidth(100); ImGui::PushItemWidth(100_scaled);
ImGui::InputText("##name", this->m_name); ImGui::InputText("##name", this->m_name);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }