From f4ec811163354e328e116b738caea70bfc8e33a6 Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Wed, 6 Nov 2024 23:58:23 +0300 Subject: [PATCH] feat: Added Daedalus class + sqParseTable moved to nonut::CustomTypes as SqDict + fix: Removed Python constructors for ItemGround and DamageDescription classes (so it's unable to make new objects in the scripts) --- g2o/__init__.py | 1 + g2o/daedalus.py | 15 ++++++++++ src/NoNut/core/CustomTypes.cpp | 29 +++++++++++++++++++ src/NoNut/core/CustomTypes.h | 10 ++++++- src/bind.cpp | 11 +++++-- src/classes/py/Daedalus.h | 20 +++++++++++++ src/classes/py/DamageDescription.h | 1 - src/classes/py/ItemGround.h | 1 - src/classes/sq/Daedalus.cpp | 23 +++++++++++++++ src/classes/sq/Daedalus.h | 27 +++++++++++++++++ src/classes/sq/DamageDescription.cpp | 14 --------- src/classes/sq/DamageDescription.h | 3 +- src/classes/sq/ItemGround.cpp | 15 ---------- src/classes/sq/ItemGround.h | 3 +- src/events/sqevents.cpp | 1 - src/events/sqevents_anticheat.cpp | 1 - src/events/sqevents_general.cpp | 14 ++++----- src/events/sqevents_npc.cpp | 1 - src/sqcontainers.cpp | 43 ---------------------------- src/sqcontainers.h | 6 ---- 20 files changed, 141 insertions(+), 98 deletions(-) create mode 100644 g2o/daedalus.py create mode 100644 src/classes/py/Daedalus.h create mode 100644 src/classes/sq/Daedalus.cpp create mode 100644 src/classes/sq/Daedalus.h delete mode 100644 src/sqcontainers.cpp delete mode 100644 src/sqcontainers.h diff --git a/g2o/__init__.py b/g2o/__init__.py index fd31941..abaf0ad 100644 --- a/g2o/__init__.py +++ b/g2o/__init__.py @@ -9,5 +9,6 @@ from g2o.events import removeEvent from g2o.packets import Packet from g2o.damage import DamageDescription from g2o.items import ItemGround +from g2o.daedalus import Daedalus from sqg2oconst import * \ No newline at end of file diff --git a/g2o/daedalus.py b/g2o/daedalus.py new file mode 100644 index 0000000..c897ec5 --- /dev/null +++ b/g2o/daedalus.py @@ -0,0 +1,15 @@ +import sqg2o + +class Daedalus: + + @staticmethod + def index(value : str) -> int: + return sqg2o.Daedalus.index(value) + + @staticmethod + def symbol(value : str) -> dict: + return sqg2o.Daedalus.symbol(value) + + @staticmethod + def instance(value : str) -> dict: + return sqg2o.Daedalus.instance(value) \ No newline at end of file diff --git a/src/NoNut/core/CustomTypes.cpp b/src/NoNut/core/CustomTypes.cpp index 60f8b4d..b7392ce 100644 --- a/src/NoNut/core/CustomTypes.cpp +++ b/src/NoNut/core/CustomTypes.cpp @@ -108,4 +108,33 @@ namespace nonut GET_SLOT(y, Float); GET_SLOT(z, Float); } + + void SqDict::convert(SQObject object) + { + Sqrat::Table tab = Sqrat::Table(object); + Sqrat::Object::iterator tabIterator; + int i = 0; + + while (tab.Next(tabIterator)) + { + HSQOBJECT key = tabIterator.getKey(); + HSQOBJECT value = tabIterator.getValue(); + + if (key._type != OT_STRING) + continue; + + if (value._type == OT_STRING) + data[sq_objtostring(&key)] = sq_objtostring(&value); + else if (value._type == OT_INTEGER) + data[sq_objtostring(&key)] = sq_objtointeger(&value); + else if (value._type == OT_FLOAT) + data[sq_objtostring(&key)] = sq_objtofloat(&value); + else if (value._type == OT_TABLE) + { + SqDict result = SqDict(); + result.convert(object); + data[sq_objtostring(&key)] = result.data; + } + } + } } diff --git a/src/NoNut/core/CustomTypes.h b/src/NoNut/core/CustomTypes.h index 07a6769..2bd004f 100644 --- a/src/NoNut/core/CustomTypes.h +++ b/src/NoNut/core/CustomTypes.h @@ -2,9 +2,11 @@ #define NONUT_G2O_SHARED_CUSTOM_TYPES_H #include - +#include #include "Utils.h" +namespace py = pybind11; + namespace nonut { struct GameTime : CustomType @@ -164,5 +166,11 @@ namespace nonut return std::make_tuple(name, x, y, z); } }; + + struct SqDict : CustomType + { + void convert(SQObject object) override; + py::dict data{}; + }; } #endif // NONUT_G2O_SHARED_CUSTOM_TYPES_H diff --git a/src/bind.cpp b/src/bind.cpp index f242c65..8add2b1 100644 --- a/src/bind.cpp +++ b/src/bind.cpp @@ -2,6 +2,7 @@ #include "classes/py/Packet.h" #include "classes/py/DamageDescription.h" #include "classes/py/ItemGround.h" +#include "classes/py/Daedalus.h" #include namespace py = pybind11; @@ -39,8 +40,6 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) { // ------------------------------------------------------------------------- py::class_(m, "DamageDescription") - .def(py::init<>()) - .def("__del__", &PyDamageDescription::del) .def_property_readonly("item_instance", &PyDamageDescription::getItemInstance) @@ -54,7 +53,6 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) { // ------------------------------------------------------------------------- py::class_(m, "ItemGround") - .def(py::init<>()) .def("__del__", &PyItemGround::del) .def("getPosition", &PyItemGround::getPosition) @@ -66,4 +64,11 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) { .def_property_readonly("world", &PyItemGround::getWorld) .def_property("virtualWorld", &PyItemGround::getVirtualWorld, &PyItemGround::setVirtualWorld, py::return_value_policy::reference_internal); + +// ------------------------------------------------------------------------- + + py::class_(m, "Daedalus") + .def_static("index", &PyDaedalus::index) + .def_static("symbol", &PyDaedalus::symbol) + .def_static("instance", &PyDaedalus::instance); } \ No newline at end of file diff --git a/src/classes/py/Daedalus.h b/src/classes/py/Daedalus.h new file mode 100644 index 0000000..e4cc1df --- /dev/null +++ b/src/classes/py/Daedalus.h @@ -0,0 +1,20 @@ +#ifndef _PYDAEDALUS_H_ +#define _PYDAEDALUS_H_ + +#include +#include +#include +namespace py = pybind11; + +class PyDaedalus +{ + +public: + + //static nonut::Int index(nonut::String value) { return nonut::Daedalus::get()->index(value); } + static nonut::Int index(nonut::String value) { std::cout << nonut::Daedalus::get()->index(value) << std::endl;return 5; } + static py::dict symbol(nonut::String value) { return nonut::Daedalus::get()->symbol(value).data; } + static py::dict instance(nonut::String value) { return nonut::Daedalus::get()->instance(value).data; } +}; + +#endif \ No newline at end of file diff --git a/src/classes/py/DamageDescription.h b/src/classes/py/DamageDescription.h index c20dc63..7ead0d6 100644 --- a/src/classes/py/DamageDescription.h +++ b/src/classes/py/DamageDescription.h @@ -9,7 +9,6 @@ private: nonut::DamageDescription *sqobj; public: - PyDamageDescription() { sqobj = new nonut::DamageDescription(); }; PyDamageDescription(SQObject obj) { sqobj = new nonut::DamageDescription(obj); } nonut::Int getFlags() { return sqobj->flags; } diff --git a/src/classes/py/ItemGround.h b/src/classes/py/ItemGround.h index af3e20e..0423619 100644 --- a/src/classes/py/ItemGround.h +++ b/src/classes/py/ItemGround.h @@ -12,7 +12,6 @@ private: nonut::ItemGround *sqobj; public: - PyItemGround() { sqobj = new nonut::ItemGround(); }; PyItemGround(SQObject obj) { sqobj = new nonut::ItemGround(obj); } py::tuple getPosition() { return py::make_tuple(sqobj->getPosition().toTuple()); } diff --git a/src/classes/sq/Daedalus.cpp b/src/classes/sq/Daedalus.cpp new file mode 100644 index 0000000..d954258 --- /dev/null +++ b/src/classes/sq/Daedalus.cpp @@ -0,0 +1,23 @@ +#include +#include "Daedalus.h" + +namespace nonut +{ + Daedalus* Daedalus::get() + { + if (inst == nullptr) + { + inst = new Daedalus(); + } + return inst; + } + + Daedalus::Daedalus() : + StaticClass("Daedalus"), + + METHOD_CTOR(index), + METHOD_CTOR(symbol), + METHOD_CTOR(instance) + { + } +} diff --git a/src/classes/sq/Daedalus.h b/src/classes/sq/Daedalus.h new file mode 100644 index 0000000..bb80d5d --- /dev/null +++ b/src/classes/sq/Daedalus.h @@ -0,0 +1,27 @@ +#ifndef _DAEDALUS_H_ +#define _DAEDALUS_H_ +#include + +#include +#include + +namespace nonut +{ + class Daedalus : public StaticClass + { + public: + static Daedalus* get(); + + Function index; + Function symbol; + Function instance; + + private: + + static inline Daedalus* inst = nullptr; + + Daedalus(); + }; +} +#endif + diff --git a/src/classes/sq/DamageDescription.cpp b/src/classes/sq/DamageDescription.cpp index 62e3194..20500fd 100644 --- a/src/classes/sq/DamageDescription.cpp +++ b/src/classes/sq/DamageDescription.cpp @@ -3,20 +3,6 @@ namespace nonut { - DamageDescription::DamageDescription() : - Class("DamageDescription"), - - PROPERTY_CTOR(flags), - PROPERTY_CTOR(damage), - PROPERTY_CTOR(item_instance), - PROPERTY_CTOR(distance), - PROPERTY_CTOR(spell_id), - PROPERTY_CTOR(spell_level), - PROPERTY_CTOR(node) - { - classCtor(); - } - DamageDescription::DamageDescription(SQObject object) : Class("DamageDescription", object), diff --git a/src/classes/sq/DamageDescription.h b/src/classes/sq/DamageDescription.h index dfa7550..1f31071 100644 --- a/src/classes/sq/DamageDescription.h +++ b/src/classes/sq/DamageDescription.h @@ -10,8 +10,7 @@ namespace nonut class DamageDescription : public Class { public: - DamageDescription(); - explicit DamageDescription(SQObject object); + DamageDescription(SQObject object); Property flags; Property damage; diff --git a/src/classes/sq/ItemGround.cpp b/src/classes/sq/ItemGround.cpp index deaa0d5..f21dc36 100644 --- a/src/classes/sq/ItemGround.cpp +++ b/src/classes/sq/ItemGround.cpp @@ -3,21 +3,6 @@ namespace nonut { - ItemGround::ItemGround() : - Class("ItemGround"), - - METHOD_CTOR(getPosition), - METHOD_CTOR(getRotation), - - PROPERTY_CTOR(id), - PROPERTY_CTOR(instance), - PROPERTY_CTOR(amount), - PROPERTY_CTOR(world), - PROPERTY_CTOR(virtualWorld) - { - classCtor(); - } - ItemGround::ItemGround(SQObject object) : Class("ItemGround", object), diff --git a/src/classes/sq/ItemGround.h b/src/classes/sq/ItemGround.h index 5c02c7d..29343b1 100644 --- a/src/classes/sq/ItemGround.h +++ b/src/classes/sq/ItemGround.h @@ -10,8 +10,7 @@ namespace nonut class ItemGround : public Class { public: - ItemGround(); - explicit ItemGround(SQObject object); + ItemGround(SQObject object); Function getPosition; Function getRotation; diff --git a/src/events/sqevents.cpp b/src/events/sqevents.cpp index e95ac3c..e4b4ed3 100644 --- a/src/events/sqevents.cpp +++ b/src/events/sqevents.cpp @@ -1,7 +1,6 @@ #include #include #include "sqevents.h" -#include "sqcontainers.h" namespace py = pybind11; using namespace pybind11::literals; diff --git a/src/events/sqevents_anticheat.cpp b/src/events/sqevents_anticheat.cpp index 67b1c5a..dc96e6f 100644 --- a/src/events/sqevents_anticheat.cpp +++ b/src/events/sqevents_anticheat.cpp @@ -1,7 +1,6 @@ #include #include #include "NoNut/core/Utils.h" -#include "sqcontainers.h" #include "sqevents.h" SQInteger sq_onPlayerUseCheat(HSQUIRRELVM vm) diff --git a/src/events/sqevents_general.cpp b/src/events/sqevents_general.cpp index 8dfe20a..b838f1c 100644 --- a/src/events/sqevents_general.cpp +++ b/src/events/sqevents_general.cpp @@ -1,7 +1,7 @@ #include #include #include "NoNut/core/Utils.h" -#include "sqcontainers.h" +#include "NoNut/core/CustomTypes.h" #include "sqevents.h" namespace py = pybind11; @@ -45,10 +45,10 @@ SQInteger sq_onBan(HSQUIRRELVM vm) { HSQOBJECT obj; nonut::sqGetValue(vm, 2, &obj); - Sqrat::Table banData = Sqrat::Table(obj, vm); - py::dict kwargs = sqParseTable(banData); - callEvent("onBan", kwargs); + nonut::SqDict dictData; + dictData.convert(obj); + callEvent("onBan", dictData.data); return 0; } @@ -57,10 +57,10 @@ SQInteger sq_onUnban(HSQUIRRELVM vm) { HSQOBJECT obj; nonut::sqGetValue(vm, 2, &obj); - Sqrat::Table banData = Sqrat::Table(obj, vm); - py::dict kwargs = sqParseTable(banData); - callEvent("onUnban", kwargs); + nonut::SqDict dictData; + dictData.convert(obj); + callEvent("onUnban", dictData.data); return 0; } \ No newline at end of file diff --git a/src/events/sqevents_npc.cpp b/src/events/sqevents_npc.cpp index 4ce28aa..ae7e5a7 100644 --- a/src/events/sqevents_npc.cpp +++ b/src/events/sqevents_npc.cpp @@ -1,7 +1,6 @@ #include #include #include "NoNut/core/Utils.h" -#include "sqcontainers.h" #include "sqevents.h" SQInteger sq_onNpcActionFinished(HSQUIRRELVM vm) diff --git a/src/sqcontainers.cpp b/src/sqcontainers.cpp deleted file mode 100644 index 2c0a898..0000000 --- a/src/sqcontainers.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include "sqcontainers.h" - -namespace py = pybind11; -using namespace pybind11::literals; - -py::dict sqParseTable(Sqrat::Table tab) -{ - py::dict result; - Sqrat::Object::iterator tabIterator; - int i = 0; - - while (tab.Next(tabIterator)) - { - HSQOBJECT key = tabIterator.getKey(); - HSQOBJECT value = tabIterator.getValue(); - - if (key._type != OT_STRING) - continue; - - switch(value._type) - { - case OT_STRING: - result[sq_objtostring(&key)] = sq_objtostring(&value); - break; - case OT_INTEGER: - result[sq_objtostring(&key)] = sq_objtointeger(&value); - break; - case OT_FLOAT: - result[sq_objtostring(&key)] = sq_objtofloat(&value); - break; - case OT_TABLE: - result[sq_objtostring(&key)] = sqParseTable(Sqrat::Table(value)); - break; - - default: - continue; - } - } - - return result; -} \ No newline at end of file diff --git a/src/sqcontainers.h b/src/sqcontainers.h deleted file mode 100644 index e2a58fb..0000000 --- a/src/sqcontainers.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace py = pybind11; -using namespace pybind11::literals; - -py::dict sqParseTable(Sqrat::Table); \ No newline at end of file