#include "offline_shop_state.h" #include #include #include "Poly.h" #include "python_gameplay_modules.h" #include "player_settings.h" #include "eter_ui/PythonWindow.h" #include #include #include "skill_description.h" #include "skill_constants.h" #include "ava2_text_file_loader.h" #include #include "python_native_modules.h" #include "python_runtime.h" #include "nonplayer_data.h" #include "shared/common/PythonUtils.h" #include "eter_resource/ResourceManager.h" #include "eter_image/GrpImage.h" #include "eter_image/GrpImageInstance.h" #include "eter_image/MarkManager.h" #include "eter_render/TextTailManager.h" #include "eter_render/CRenderTarget.h" #include "eter_effect/EffectManager.h" #include "eter_effect/FlyingManager.h" #include "eter_net/PythonExchange.h" #include "eter_net/PythonSafeBox.h" #include "eter_net/PythonNetworkStream.h" #include "python_sash.h" #include "python_manager_bank.h" #include "python_app.h" #include #include #include #include #include #include #include namespace ava2 { namespace { SkillDescriptions skillDescriptions; // CPythonSkill state the original keeps outside SSkillData (PythonSkill.cpp / GameType.cpp). const char* const kImagePath="d:/ymir work/ui/"; // g_strImagePath const uint32_t kSkillIndexRiding=130; // c_iSkillIndex_Riding (PythonPlayerModule.cpp) // LocaleService_GetCodePage() == MULTI_LOCALE_CODE; no locale.cfg/LocaleService port yet, so its // initial value. Only RegisterSkill's "%dname" style keys read it. const int kLocaleCodePage=949; std::string s_skillPathName; // m_strPathName uint32_t s_timeIncreaseSkillNumber=0; // SSkillData::ms_dwTimeIncreaseSkillNumber (read only by commented-out code) // __RegisterGradeIconImage / __RegisterNormalIconImage, called at RegisterSkillDesc's icon step. // m_PathNameMap is keyed by the raw, case-sensitive job column. void register_skill_icons(uint32_t id,SkillDescription& data,const std::string& job,const std::string& icon) { static const std::map pathNames={{"WARRIOR","warrior"},{"ASSASSIN","assassin"},{"SURA","sura"}, {"SHAMAN","shaman"},{"PASSIVE","passive"},{"SUPPORT","common/support"},{"GUILD","common/guild"},{"HORSE","common/horse"}}; auto grade=[&](const char* header) { for(int j=0;jsecond.c_str()); switch(data.type) { case skill_constants::SKILL_TYPE_ACTIVE:grade(header);break; case skill_constants::SKILL_TYPE_SUPPORT:case skill_constants::SKILL_TYPE_GUILD:case skill_constants::SKILL_TYPE_HORSE:normal(header);break; } } } } // namespace bool LoadSkillTable(const std::string& path,bool cheonma) { try { return skillDescriptions.loadTable(ReadPackedText(path),cheonma); } catch(const std::exception&) {return false;} } void ResetSkillDescriptions() { skillDescriptions.records.clear(); } // CPythonPlayer::__GetSkillType: unknown skill index -> 0 (not SKILL_TYPE_ACTIVE). int GetSkillTypeById(uint32_t id) { auto* data=skillDescriptions.find(id);return data?data->type:0; } const SkillDescription* FindSkillDescription(uint32_t id) { return skillDescriptions.find(id); } bool LoadSkillDescriptions(const std::string& path) { try { return skillDescriptions.load(ReadPackedText(path),register_skill_icons); } catch(const std::exception&) { return false; } } namespace { PyObject* nonplayer_load(PyObject*,PyObject* args) { const char* path; if(!PyArg_ParseTuple(args,"s",&path)) return nullptr; try { NonPlayerData::Instance().load(ReadPackedText(path)); } catch(const std::exception&) {} Py_RETURN_NONE; // Original Python wrapper does not return loader success. } PyObject* nonplayer_name(PyObject*,PyObject* args) { int vnum;if(!PyArg_ParseTuple(args,"i",&vnum)) return nullptr; auto* mob=NonPlayerData::Instance().get(uint32_t(vnum));return PyString_FromString(mob?mob->name.c_str():""); } template PyObject* nonplayer_value(PyObject*,PyObject* args) { int vnum;if(!PyArg_ParseTuple(args,"i",&vnum)) return nullptr; const auto* m=NonPlayerData::Instance().get(uint32_t(vnum)); if constexpr(Field==4) return m?Py_BuildValue("ii",m->damageMin,m->damageMax):Py_BuildValue("ii",0,0); else if constexpr(Field==14) return m?Py_BuildValue("ii",m->goldMin,m->goldMax):Py_BuildValue("ii",0,0); else if constexpr(Field==6) return PyFloat_FromDouble(m?m->damageMultiply:0); else { long long value=0; if(m) switch(Field) { case 0:value=m->event;break;case 1:value=m->hp;break;case 2:value=m->raceFlags;break;case 3:value=m->level;break; case 5:value=m->exp;break;case 7:value=m->st;break;case 8:value=m->dx;break;case 9:value=m->type==2;break; case 10:value=m->regenCycle;break;case 11:value=m->regenPercent;break;case 12:value=m->goldMin;break;case 13:value=m->goldMax;break; case 15:value=m->monsterColor;break; } return PyInt_FromLong(static_cast(value)); } } template PyObject* nonplayer_vid(PyObject*,PyObject* args) { int vid;if(!PyArg_ParseTuple(args,"i",&vid)) return nullptr; const auto* actor=NetworkActorManager::Instance().GetActorData(uint32_t(vid)); const auto* mob=actor?NonPlayerData::Instance().get(actor->m_dwRace):nullptr; if constexpr(Field==0) return PyInt_FromLong(mob?mob->event:0); if constexpr(Field==1) return PyInt_FromLong(mob?mob->level:-1); if constexpr(Field==2) return PyInt_FromLong(mob?mob->rank:-1); return PyInt_FromLong(mob?mob->vnum:-1); } PyObject* nonplayer_search(PyObject*,PyObject* args) { const char* query;if(!PyArg_ParseTuple(args,"s",&query)) return nullptr; std::string prefix(query);PyObject* list=PyList_New(0);if(!list) return nullptr; for(const auto& entry:NonPlayerData::Instance().all()) { const auto& mob=entry.second;if(mob.type!=0 && mob.type!=2) continue; std::string name=mob.name; for(char& c:name) c=static_cast(std::tolower(static_cast(c))); if(name.compare(0,prefix.size(),prefix)) continue; PyObject* value=PyInt_FromLong(mob.vnum); if(!value || PyList_Append(list,value)<0) { Py_XDECREF(value);Py_DECREF(list);return nullptr; } Py_DECREF(value); } return list; } // nonplayerGetMobResist (nonplayer.GetResist): CPythonNonPlayer::GetMobResist returns the signed // cResists entry as a DWORD, 0 without a table or for resistNum >= MOB_RESISTS_MAX_NUM. PyObject* nonplayer_GetResist(PyObject*,PyObject* poArgs) { int race; if (!PyTuple_GetInteger(poArgs, 0, &race)) return Py_BuildException(); int resistArg; if (!PyTuple_GetInteger(poArgs, 1, &resistArg)) return Py_BuildException(); const uint8_t resistNum = uint8_t(resistArg); const auto* c_pTable = NonPlayerData::Instance().get(uint32_t(race)); uint32_t value = 0; if (c_pTable && resistNum < 11) value = uint32_t(int32_t(c_pTable->resists[resistNum])); return Py_BuildValue("i", int(value)); } PyObject* nonplayer_resist(PyObject*,PyObject* args) { int vnum,index;if(!PyArg_ParseTuple(args,"ii",&vnum,&index)) return nullptr; const auto* m=NonPlayerData::Instance().get(uint32_t(vnum)); return PyInt_FromLong(m&&index>=0&&index<11?m->resists[index]:0); } } void initNonPlayer() { NonPlayerData::Instance().clear(); static PyMethodDef methods[] = { {"GetEventType", nonplayer_value<0>, METH_VARARGS, nullptr}, {"GetEventTypeByVID", nonplayer_vid<0>, METH_VARARGS, nullptr}, {"GetLevelByVID", nonplayer_vid<1>, METH_VARARGS, nullptr}, {"GetGradeByVID", nonplayer_vid<2>, METH_VARARGS, nullptr}, {"GetMonsterName", nonplayer_name, METH_VARARGS, nullptr}, {"GetMonsterColor", nonplayer_value<15>, METH_VARARGS, nullptr}, {"GetRaceNumByVID", nonplayer_vid<3>, METH_VARARGS, nullptr}, {"GetMonsterMaxHP", nonplayer_value<1>, METH_VARARGS, nullptr}, {"GetMonsterRaceFlag", nonplayer_value<2>, METH_VARARGS, nullptr}, {"GetMonsterLevel", nonplayer_value<3>, METH_VARARGS, nullptr}, {"GetMonsterDamage", nonplayer_value<4>, METH_VARARGS, nullptr}, {"GetMonsterExp", nonplayer_value<5>, METH_VARARGS, nullptr}, {"GetMonsterDamageMultiply", nonplayer_value<6>, METH_VARARGS, nullptr}, {"GetMonsterST", nonplayer_value<7>, METH_VARARGS, nullptr}, {"GetMonsterDX", nonplayer_value<8>, METH_VARARGS, nullptr}, {"IsMonsterStone", nonplayer_value<9>, METH_VARARGS, nullptr}, {"GetMobRegenCycle", nonplayer_value<10>, METH_VARARGS, nullptr}, {"GetMobRegenPercent", nonplayer_value<11>, METH_VARARGS, nullptr}, {"GetMobGoldMin", nonplayer_value<12>, METH_VARARGS, nullptr}, {"GetMobGoldMax", nonplayer_value<13>, METH_VARARGS, nullptr}, {"GetResist", nonplayer_GetResist, METH_VARARGS, nullptr}, {"LoadNonPlayerData", nonplayer_load, METH_VARARGS, nullptr}, {"GetMonsterPrice", nonplayer_value<14>, METH_VARARGS, nullptr}, {"GetMobsByName", nonplayer_search, METH_VARARGS, nullptr}, {"GetMonsterLevel", nonplayer_value<3>, METH_VARARGS, nullptr}, {"GetMonsterRaceFlag", nonplayer_value<2>, METH_VARARGS, nullptr}, {"IsMonsterStone", nonplayer_value<9>, METH_VARARGS, nullptr}, {"GetMonsterDamage", nonplayer_value<4>, METH_VARARGS, nullptr}, {"GetMonsterExp", nonplayer_value<5>, METH_VARARGS, nullptr}, {"GetMonsterDamageMultiply", nonplayer_value<6>, METH_VARARGS, nullptr}, {"GetMonsterST", nonplayer_value<7>, METH_VARARGS, nullptr}, {"GetMonsterDX", nonplayer_value<8>, METH_VARARGS, nullptr}, {"IsMonsterStone", nonplayer_value<9>, METH_VARARGS, nullptr}, {"GetMonsterResist", nonplayer_resist, METH_VARARGS, nullptr}, {"GetMonsterMaxHP", nonplayer_value<1>, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("nonplayer", methods); PyModule_AddIntConstant(module, "ON_CLICK_EVENT_NONE", 0); PyModule_AddIntConstant(module, "ON_CLICK_EVENT_BATTLE", 1); PyModule_AddIntConstant(module, "ON_CLICK_EVENT_SHOP", 2); PyModule_AddIntConstant(module, "ON_CLICK_EVENT_TALK", 3); PyModule_AddIntConstant(module, "ON_CLICK_EVENT_VEHICLE", 4); PyModule_AddIntConstant(module, "PAWN", 0); PyModule_AddIntConstant(module, "S_PAWN", 1); PyModule_AddIntConstant(module, "KNIGHT", 2); PyModule_AddIntConstant(module, "S_KNIGHT", 3); PyModule_AddIntConstant(module, "BOSS", 4); PyModule_AddIntConstant(module, "KING", 5); PyModule_AddIntConstant(module, "MOB_RESIST_SWORD", 0); PyModule_AddIntConstant(module, "MOB_RESIST_TWOHAND", 1); PyModule_AddIntConstant(module, "MOB_RESIST_DAGGER", 2); PyModule_AddIntConstant(module, "MOB_RESIST_BELL", 3); PyModule_AddIntConstant(module, "MOB_RESIST_FAN", 4); PyModule_AddIntConstant(module, "MOB_RESIST_BOW", 5); PyModule_AddIntConstant(module, "MOB_RESIST_FIRE", 6); PyModule_AddIntConstant(module, "MOB_RESIST_ELECT", 7); PyModule_AddIntConstant(module, "MOB_RESIST_MAGIC", 8); PyModule_AddIntConstant(module, "MOB_RESIST_WIND", 9); PyModule_AddIntConstant(module, "MOB_RESIST_POISON", 10); PyModule_AddIntConstant(module, "MOB_RESIST_MAX_NUM", 11); } static PyObject* exchange_InitTrading(PyObject*, PyObject*) { CPythonExchange::Instance().End(); Py_RETURN_NONE; } static PyObject* exchange_isTrading(PyObject*, PyObject*) { return PyInt_FromLong(CPythonExchange::Instance().isTrading() ? 1 : 0); } static PyObject* exchange_GetElkFromSelf(PyObject*, PyObject*) { return PyLong_FromLongLong(CPythonExchange::Instance().GetElkFromSelf()); } static PyObject* exchange_GetElkFromTarget(PyObject*, PyObject*) { return PyLong_FromLongLong(CPythonExchange::Instance().GetElkFromTarget()); } static PyObject* exchange_GetItemVnumFromSelf(PyObject*, PyObject* args) { int pos = 0; if (!PyArg_ParseTuple(args, "i", &pos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemVnumFromSelf(pos)); } static PyObject* exchange_GetItemVnumFromTarget(PyObject*, PyObject* args) { int pos = 0; if (!PyArg_ParseTuple(args, "i", &pos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemVnumFromTarget(pos)); } static PyObject* exchange_GetItemCountFromSelf(PyObject*, PyObject* args) { int pos = 0; if (!PyArg_ParseTuple(args, "i", &pos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemCountFromSelf(pos)); } static PyObject* exchange_GetItemCountFromTarget(PyObject*, PyObject* args) { int pos = 0; if (!PyArg_ParseTuple(args, "i", &pos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemCountFromTarget(pos)); } static PyObject* exchange_GetAcceptFromSelf(PyObject*, PyObject*) { return PyInt_FromLong(CPythonExchange::Instance().GetAcceptFromSelf() ? 1 : 0); } static PyObject* exchange_GetAcceptFromTarget(PyObject*, PyObject*) { return PyInt_FromLong(CPythonExchange::Instance().GetAcceptFromTarget() ? 1 : 0); } static PyObject* exchange_GetNameFromSelf(PyObject*, PyObject*) { return PyString_FromString(CPythonExchange::Instance().GetNameFromSelf()); } static PyObject* exchange_GetNameFromTarget(PyObject*, PyObject*) { return PyString_FromString(CPythonExchange::Instance().GetNameFromTarget()); } static PyObject* exchange_GetLevelFromSelf(PyObject*, PyObject*) { return PyInt_FromLong(CPythonExchange::Instance().GetLevelFromSelf()); } static PyObject* exchange_GetLevelFromTarget(PyObject*, PyObject*) { return PyInt_FromLong(CPythonExchange::Instance().GetLevelFromTarget()); } static PyObject* exchange_GetItemMetinSocketFromSelf(PyObject*, PyObject* args) { int pos = 0, socketPos = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &socketPos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemMetinSocketFromSelf(pos, socketPos)); } static PyObject* exchange_GetItemMetinSocketFromTarget(PyObject*, PyObject* args) { int pos = 0, socketPos = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &socketPos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemMetinSocketFromTarget(pos, socketPos)); } static PyObject* exchange_GetItemAttributeFromSelf(PyObject*, PyObject* args) { int pos = 0, attrPos = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &attrPos)) return Py_BuildValue("ii", 0, 0); uint8_t type = 0; int16_t val = 0; CPythonExchange::Instance().GetItemAttributeFromSelf(pos, attrPos, &type, &val); return Py_BuildValue("ii", type, val); } static PyObject* exchange_GetItemAttributeFromTarget(PyObject*, PyObject* args) { int pos = 0, attrPos = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &attrPos)) return Py_BuildValue("ii", 0, 0); uint8_t type = 0; int16_t val = 0; CPythonExchange::Instance().GetItemAttributeFromTarget(pos, attrPos, &type, &val); return Py_BuildValue("ii", type, val); } static PyObject* exchange_GetItemRandomAttributeFromSelf(PyObject*, PyObject* args) { int pos = 0, attrPos = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &attrPos)) return Py_BuildValue("ii", 0, 0); uint8_t type = 0; int16_t val = 0; CPythonExchange::Instance().GetItemRandomAttributeFromSelf(pos, attrPos, &type, &val); return Py_BuildValue("ii", type, val); } static PyObject* exchange_GetItemRandomAttributeFromTarget(PyObject*, PyObject* args) { int pos = 0, attrPos = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &attrPos)) return Py_BuildValue("ii", 0, 0); uint8_t type = 0; int16_t val = 0; CPythonExchange::Instance().GetItemRandomAttributeFromTarget(pos, attrPos, &type, &val); return Py_BuildValue("ii", type, val); } static PyObject* exchange_GetElkMode(PyObject*, PyObject*) { return PyBool_FromLong(CPythonExchange::Instance().GetElkMode() ? 1 : 0); } static PyObject* exchange_SetElkMode(PyObject*, PyObject* args) { int mode = 0; if (PyArg_ParseTuple(args, "i", &mode)) { CPythonExchange::Instance().SetElkMode(mode != 0); } Py_RETURN_NONE; } static PyObject* exchange_GetItemNewName(PyObject*, PyObject* args) { int pos = 0, bSelf = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &bSelf)) return PyString_FromString("^"); return PyString_FromString(CPythonExchange::Instance().GetItemNewName(pos, bSelf != 0)); } static PyObject* exchange_GetItemElementGradeFromSelf(PyObject*, PyObject* args) { int pos = 0; if (!PyArg_ParseTuple(args, "i", &pos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemElementGradeFromSelf(pos)); } static PyObject* exchange_GetItemElementAttackFromSelf(PyObject*, PyObject* args) { int pos = 0, idx = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &idx)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemElementAttackFromSelf(pos, idx)); } static PyObject* exchange_GetItemElementTypeFromSelf(PyObject*, PyObject* args) { int pos = 0; if (!PyArg_ParseTuple(args, "i", &pos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemElementTypeFromSelf(pos)); } static PyObject* exchange_GetItemElementValueFromSelf(PyObject*, PyObject* args) { int pos = 0, idx = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &idx)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemElementValueFromSelf(pos, idx)); } static PyObject* exchange_GetItemElementGradeFromTarget(PyObject*, PyObject* args) { int pos = 0; if (!PyArg_ParseTuple(args, "i", &pos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemElementGradeFromTarget(pos)); } static PyObject* exchange_GetItemElementAttackFromTarget(PyObject*, PyObject* args) { int pos = 0, idx = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &idx)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemElementAttackFromTarget(pos, idx)); } static PyObject* exchange_GetItemElementTypeFromTarget(PyObject*, PyObject* args) { int pos = 0; if (!PyArg_ParseTuple(args, "i", &pos)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemElementTypeFromTarget(pos)); } static PyObject* exchange_GetItemElementValueFromTarget(PyObject*, PyObject* args) { int pos = 0, idx = 0; if (!PyArg_ParseTuple(args, "ii", &pos, &idx)) return PyInt_FromLong(0); return PyInt_FromLong(CPythonExchange::Instance().GetItemElementValueFromTarget(pos, idx)); } void initTrade() { static PyMethodDef methods[] = { {"InitTrading", exchange_InitTrading, METH_VARARGS, nullptr}, {"isTrading", exchange_isTrading, METH_VARARGS, nullptr}, {"GetElkFromSelf", exchange_GetElkFromSelf, METH_VARARGS, nullptr}, {"GetElkFromTarget", exchange_GetElkFromTarget, METH_VARARGS, nullptr}, {"GetItemVnumFromSelf", exchange_GetItemVnumFromSelf, METH_VARARGS, nullptr}, {"GetItemVnumFromTarget", exchange_GetItemVnumFromTarget, METH_VARARGS, nullptr}, {"GetItemCountFromSelf", exchange_GetItemCountFromSelf, METH_VARARGS, nullptr}, {"GetItemCountFromTarget", exchange_GetItemCountFromTarget, METH_VARARGS, nullptr}, {"GetAcceptFromSelf", exchange_GetAcceptFromSelf, METH_VARARGS, nullptr}, {"GetAcceptFromTarget", exchange_GetAcceptFromTarget, METH_VARARGS, nullptr}, {"GetNameFromSelf", exchange_GetNameFromSelf, METH_VARARGS, nullptr}, {"GetNameFromTarget", exchange_GetNameFromTarget, METH_VARARGS, nullptr}, {"GetLevelFromSelf", exchange_GetLevelFromSelf, METH_VARARGS, nullptr}, {"GetLevelFromTarget", exchange_GetLevelFromTarget, METH_VARARGS, nullptr}, {"GetItemMetinSocketFromTarget", exchange_GetItemMetinSocketFromTarget, METH_VARARGS, nullptr}, {"GetItemMetinSocketFromSelf", exchange_GetItemMetinSocketFromSelf, METH_VARARGS, nullptr}, {"GetItemAttributeFromTarget", exchange_GetItemAttributeFromTarget, METH_VARARGS, nullptr}, {"GetItemAttributeFromSelf", exchange_GetItemAttributeFromSelf, METH_VARARGS, nullptr}, {"GetItemRandomAttributeFromTarget", exchange_GetItemRandomAttributeFromTarget, METH_VARARGS, nullptr}, {"GetItemRandomAttributeFromSelf", exchange_GetItemRandomAttributeFromSelf, METH_VARARGS, nullptr}, {"GetElkMode", exchange_GetElkMode, METH_VARARGS, nullptr}, {"SetElkMode", exchange_SetElkMode, METH_VARARGS, nullptr}, {"GetItemNewName", exchange_GetItemNewName, METH_VARARGS, nullptr}, {"GetItemElementGradeFromTarget", exchange_GetItemElementGradeFromTarget, METH_VARARGS, nullptr}, {"GetItemElementAttackFromTarget", exchange_GetItemElementAttackFromTarget, METH_VARARGS, nullptr}, {"GetItemElementTypeFromTarget", exchange_GetItemElementTypeFromTarget, METH_VARARGS, nullptr}, {"GetItemElementValueFromTarget", exchange_GetItemElementValueFromTarget, METH_VARARGS, nullptr}, {"GetItemElementGradeFromSelf", exchange_GetItemElementGradeFromSelf, METH_VARARGS, nullptr}, {"GetItemElementAttackFromSelf", exchange_GetItemElementAttackFromSelf, METH_VARARGS, nullptr}, {"GetItemElementTypeFromSelf", exchange_GetItemElementTypeFromSelf, METH_VARARGS, nullptr}, {"GetItemElementValueFromSelf", exchange_GetItemElementValueFromSelf, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("exchange", methods); PyModule_AddIntConstant(module, "EXCHANGE_ITEM_MAX_NUM", 12); } static PyObject* texttail_clear(PyObject*, PyObject*) { TextTailManager::Instance().Clear(); Py_RETURN_NONE; } static PyObject* texttail_update_all(PyObject*, PyObject*) { TextTailManager::Instance().UpdateAllTextTail(); Py_RETURN_NONE; } static PyObject* texttail_update_showing(PyObject*, PyObject*) { TextTailManager::Instance().UpdateShowingTextTail(); Py_RETURN_NONE; } static PyObject* texttail_render(PyObject*, PyObject*) { TextTailManager::Instance().Render(nullptr, nullptr); Py_RETURN_NONE; } static PyObject* texttail_show_character(PyObject*, PyObject* args) { int vid = 0; if (PyArg_ParseTuple(args, "i", &vid)) { TextTailManager::Instance().ShowCharacterTextTail(static_cast(vid)); } Py_RETURN_NONE; } static PyObject* texttail_show_item(PyObject*, PyObject* args) { int vid = 0; if (PyArg_ParseTuple(args, "i", &vid)) { TextTailManager::Instance().ShowItemTextTail(static_cast(vid)); } Py_RETURN_NONE; } static PyObject* texttail_get_position(PyObject*, PyObject* args) { int vid = 0; if (!PyArg_ParseTuple(args, "i", &vid)) return nullptr; float x = 0.0f, y = 0.0f, z = 0.0f; TextTailManager::Instance().GetTextTailPosition(static_cast(vid), x, y, z); return Py_BuildValue("fff", x, y, z); } static PyObject* texttail_is_chat(PyObject*, PyObject* args) { int vid = 0; if (!PyArg_ParseTuple(args, "i", &vid)) return nullptr; return Py_BuildValue("i", TextTailManager::Instance().IsChatTextTail(static_cast(vid)) ? 1 : 0); } static PyObject* texttail_arrange(PyObject*, PyObject*) { TextTailManager::Instance().ArrangeTextTail(); Py_RETURN_NONE; } static PyObject* texttail_hide_all(PyObject*, PyObject*) { TextTailManager::Instance().HideAllTextTail(); Py_RETURN_NONE; } static PyObject* texttail_show_all(PyObject*, PyObject*) { TextTailManager::Instance().ShowAllTextTail(); Py_RETURN_NONE; } static PyObject* texttail_pick(PyObject*, PyObject* args) { int x = 0, y = 0; if (!PyArg_ParseTuple(args, "ii", &x, &y)) return nullptr; int picked = TextTailManager::Instance().Pick(x, y); return Py_BuildValue("i", picked); } static PyObject* texttail_select_item_name(PyObject*, PyObject* args) { int vid = 0; if (PyArg_ParseTuple(args, "i", &vid)) { TextTailManager::Instance().SelectItemName(static_cast(vid)); } Py_RETURN_NONE; } static PyObject* texttail_enable_pk_title(PyObject*, PyObject* args) { int flag = 0; if (PyArg_ParseTuple(args, "i", &flag)) { TextTailManager::Instance().EnablePKTitle(flag != 0); } Py_RETURN_NONE; } static PyObject* texttail_register_character(PyObject*, PyObject* args) { int guildID = 0, vid = 0; if (PyArg_ParseTuple(args, "ii", &guildID, &vid)) { TextTailManager::Instance().RegisterCharacterTextTail(guildID, vid); } Py_RETURN_NONE; } static PyObject* texttail_register_chat(PyObject*, PyObject* args) { int vid = 0; const char* text = nullptr; if (PyArg_ParseTuple(args, "is", &vid, &text)) { TextTailManager::Instance().RegisterChatTail(vid, text ? text : ""); } Py_RETURN_NONE; } static PyObject* texttail_register_info(PyObject*, PyObject* args) { int vid = 0; const char* text = nullptr; if (PyArg_ParseTuple(args, "is", &vid, &text)) { TextTailManager::Instance().RegisterInfoTail(vid, text ? text : ""); } Py_RETURN_NONE; } static PyObject* texttail_attach_title(PyObject*, PyObject* args) { int vid = 0; const char* title = nullptr; float r = 1.0f, g = 0.8f, b = 0.0f; if (PyArg_ParseTuple(args, "isfff", &vid, &title, &r, &g, &b)) { uint32_t color = (0xFF << 24) | (static_cast(r * 255.0f) << 16) | (static_cast(g * 255.0f) << 8) | static_cast(b * 255.0f); TextTailManager::Instance().AttachTitle(vid, title ? title : "", color); } Py_RETURN_NONE; } static PyObject* texttail_attach_level(PyObject*, PyObject* args) { int vid = 0; const char* levelStr = nullptr; float r = 0.6f, g = 1.0f, b = 0.2f; if (PyArg_ParseTuple(args, "is|fff", &vid, &levelStr, &r, &g, &b)) { uint32_t color = (0xFF << 24) | (static_cast(r * 255.0f) << 16) | (static_cast(g * 255.0f) << 8) | static_cast(b * 255.0f); TextTailManager::Instance().AttachLevel(vid, levelStr ? levelStr : "", color); } Py_RETURN_NONE; } static PyObject* texttail_detach_title(PyObject*, PyObject* args) { int vid = 0; if (PyArg_ParseTuple(args, "i", &vid)) { TextTailManager::Instance().DetachTitle(vid); } Py_RETURN_NONE; } static PyObject* texttail_detach_level(PyObject*, PyObject* args) { int vid = 0; if (PyArg_ParseTuple(args, "i", &vid)) { TextTailManager::Instance().DetachLevel(vid); } Py_RETURN_NONE; } static PyObject* texttail_register_item(PyObject*, PyObject* args) { int vid = 0; const char* text = nullptr; int ownerTime = 0; const char* ownerName = ""; if (PyArg_ParseTuple(args, "is|is", &vid, &text, &ownerTime, &ownerName)) { TextTailManager::Instance().RegisterItemTextTail(vid, text ? text : "", 0.0f, 0.0f, 0.0f, ownerTime, ownerName ? ownerName : ""); } Py_RETURN_NONE; } void initTextTail() { // Use the same FreeType font path as UI text, preserving the Retina render // scale. SDL_RenderDebugText's fixed bitmap font is only a host fallback. // One reused instance per callback: text tails paint several labels per actor per frame. static auto fontFor=[](UI::CGraphicTextInstance& text,int& lastSize,float scale) { const int size=int(12 * scale); if(size!=lastSize){lastSize=size;text.SetFontName(("Tahoma:" + std::to_string(size)).c_str());} }; TextTailManager::Instance().SetTextPainter( [](float x,float y,const std::string& value,uint32_t color,float scale,bool outline) { static UI::CGraphicTextInstance text;static int lastSize=-1; fontFor(text,lastSize,scale); text.SetValue(value.c_str()); text.SetFontColor(color); text.SetPosition(x,y); text.SetOutline(outline); text.Render(); }, [](const std::string& value,float scale) { static UI::CGraphicTextInstance text;static int lastSize=-1; fontFor(text,lastSize,scale); text.SetValue(value.c_str()); int width=0; text.GetTextSize(&width,nullptr); return float(width); }); static PyMethodDef methods[] = { {"Clear", texttail_clear, METH_VARARGS, nullptr}, {"UpdateAllTextTail", texttail_update_all, METH_VARARGS, nullptr}, {"UpdateShowingTextTail", texttail_update_showing, METH_VARARGS, nullptr}, {"Render", texttail_render, METH_VARARGS, nullptr}, {"ShowCharacterTextTail", texttail_show_character, METH_VARARGS, nullptr}, {"ShowItemTextTail", texttail_show_item, METH_VARARGS, nullptr}, {"GetPosition", texttail_get_position, METH_VARARGS, nullptr}, {"IsChat", texttail_is_chat, METH_VARARGS, nullptr}, {"ArrangeTextTail", texttail_arrange, METH_VARARGS, nullptr}, {"HideAllTextTail", texttail_hide_all, METH_VARARGS, nullptr}, {"ShowAllTextTail", texttail_show_all, METH_VARARGS, nullptr}, {"Pick", texttail_pick, METH_VARARGS, nullptr}, {"SelectItemName", texttail_select_item_name, METH_VARARGS, nullptr}, {"EnablePKTitle", texttail_enable_pk_title, METH_VARARGS, nullptr}, {"RegisterCharacterTextTail", texttail_register_character, METH_VARARGS, nullptr}, {"RegisterChatTail", texttail_register_chat, METH_VARARGS, nullptr}, {"RegisterInfoTail", texttail_register_info, METH_VARARGS, nullptr}, {"AttachTitle", texttail_attach_title, METH_VARARGS, nullptr}, {"AttachLevel", texttail_attach_level, METH_VARARGS, nullptr}, {"DetachTitle", texttail_detach_title, METH_VARARGS, nullptr}, {"DetachLevel", texttail_detach_level, METH_VARARGS, nullptr}, {"RegisterItemTextTail", texttail_register_item, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("textTail", methods); } static PyObject* profiler_push(PyObject*, PyObject* args) { char* szName = nullptr; if (!PyTuple_GetString(args, 0, &szName)) return Py_BuildException(); return Py_BuildNone(); } static PyObject* profiler_pop(PyObject*, PyObject* args) { char* szName = nullptr; if (!PyTuple_GetString(args, 0, &szName)) return Py_BuildException(); return Py_BuildNone(); } void initProfiler() { static PyMethodDef methods[] = { {"Push", profiler_push, METH_VARARGS, nullptr}, {"Pop", profiler_pop, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; Py_InitModule("profiler", methods); } static PyObject* effect_RegisterEffect(PyObject*, PyObject* args) { const char* filename = nullptr; if (!PyArg_ParseTuple(args, "s", &filename)) { return nullptr; } uint32_t id = 0; ava2::EffectManager::Instance().RegisterEffect(filename, &id); Py_RETURN_NONE; } static PyObject* effect_CreateEffect(PyObject*, PyObject* args) { uint32_t instId = 0; Py_ssize_t size = PyTuple_Size(args); if (size == 1) { const char* filename = nullptr; if (PyArg_ParseTuple(args, "s", &filename)) { instId = ava2::EffectManager::Instance().CreateEffect(filename); } else { PyErr_Clear(); uint32_t id = 0; if (PyArg_ParseTuple(args, "I", &id)) { instId = ava2::EffectManager::Instance().CreateEffect(id); } } } else if (size == 4) { const char* filename = nullptr; float x = 0.0f, y = 0.0f, z = 0.0f; if (PyArg_ParseTuple(args, "sfff", &filename, &x, &y, &z)) { instId = ava2::EffectManager::Instance().CreateEffect(filename, x, y, z); } } return PyInt_FromLong(instId); } static PyObject* effect_DeleteEffect(PyObject*, PyObject* args) { uint32_t index = 0; if (!PyArg_ParseTuple(args, "I", &index)) { return nullptr; } ava2::EffectManager::Instance().DestroyEffectInstance(index); Py_RETURN_NONE; } static PyObject* effect_SetPosition(PyObject*, PyObject* args) { uint32_t index = 0; float x = 0.0f, y = 0.0f, z = 0.0f; if (!PyArg_ParseTuple(args, "Ifff", &index, &x, &y, &z)) { return nullptr; } ava2::EffectManager::Instance().SetEffectInstancePosition(index, x, y, z); Py_RETURN_NONE; } static PyObject* effect_RegisterIndexedFlyData(PyObject*, PyObject* args) { int index = 0; int flyType = 0; char* filename = nullptr; if (PyTuple_Size(args) >= 3) { if (!PyTuple_GetInteger(args, 0, &index) || !PyTuple_GetInteger(args, 1, &flyType) || !PyTuple_GetString(args, 2, &filename)) { return Py_BuildException(); } } else if (!PyArg_ParseTuple(args, "ii|s", &index, &flyType, &filename)) { return nullptr; } ava2::FlyingManager::Instance().RegisterIndexedFlyData(uint32_t(index), uint8_t(flyType), filename ? filename : ""); Py_RETURN_NONE; } static PyObject* effect_Update(PyObject*, PyObject*) { ava2::EffectManager::Instance().Update(ava2::GetGameFrameDelta()); Py_RETURN_NONE; } static PyObject* effect_Render(PyObject*, PyObject*) { Py_RETURN_NONE; } void initeffect() { static PyMethodDef methods[] = { {"RegisterEffect", effect_RegisterEffect, METH_VARARGS, nullptr}, {"CreateEffect", effect_CreateEffect, METH_VARARGS, nullptr}, {"DeleteEffect", effect_DeleteEffect, METH_VARARGS, nullptr}, {"SetPosition", effect_SetPosition, METH_VARARGS, nullptr}, {"RegisterIndexedFlyData", effect_RegisterIndexedFlyData, METH_VARARGS, nullptr}, {"Update", effect_Update, METH_VARARGS, nullptr}, {"Render", effect_Render, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("effect", methods); PyModule_AddIntConstant(module, "INDEX_FLY_TYPE_NORMAL", ava2::FlyingManager::INDEX_FLY_TYPE_NORMAL); PyModule_AddIntConstant(module, "INDEX_FLY_TYPE_FIRE_CRACKER", ava2::FlyingManager::INDEX_FLY_TYPE_FIRE_CRACKER); PyModule_AddIntConstant(module, "INDEX_FLY_TYPE_AUTO_FIRE", ava2::FlyingManager::INDEX_FLY_TYPE_AUTO_FIRE); PyModule_AddIntConstant(module, "FLY_NONE", ava2::FlyingManager::FLY_NONE); PyModule_AddIntConstant(module, "FLY_EXP", ava2::FlyingManager::FLY_EXP); PyModule_AddIntConstant(module, "FLY_HP_MEDIUM", ava2::FlyingManager::FLY_HP_MEDIUM); PyModule_AddIntConstant(module, "FLY_HP_BIG", ava2::FlyingManager::FLY_HP_BIG); PyModule_AddIntConstant(module, "FLY_SP_SMALL", ava2::FlyingManager::FLY_SP_SMALL); PyModule_AddIntConstant(module, "FLY_SP_MEDIUM", ava2::FlyingManager::FLY_SP_MEDIUM); PyModule_AddIntConstant(module, "FLY_SP_BIG", ava2::FlyingManager::FLY_SP_BIG); PyModule_AddIntConstant(module, "FLY_FIREWORK1", ava2::FlyingManager::FLY_FIREWORK1); PyModule_AddIntConstant(module, "FLY_FIREWORK2", ava2::FlyingManager::FLY_FIREWORK2); PyModule_AddIntConstant(module, "FLY_FIREWORK3", ava2::FlyingManager::FLY_FIREWORK3); PyModule_AddIntConstant(module, "FLY_FIREWORK4", ava2::FlyingManager::FLY_FIREWORK4); PyModule_AddIntConstant(module, "FLY_FIREWORK5", ava2::FlyingManager::FLY_FIREWORK5); PyModule_AddIntConstant(module, "FLY_FIREWORK6", ava2::FlyingManager::FLY_FIREWORK6); PyModule_AddIntConstant(module, "FLY_FIREWORK_XMAS", ava2::FlyingManager::FLY_FIREWORK_XMAS); PyModule_AddIntConstant(module, "FLY_CHAIN_LIGHTNING", ava2::FlyingManager::FLY_CHAIN_LIGHTNING); PyModule_AddIntConstant(module, "FLY_HP_SMALL", ava2::FlyingManager::FLY_HP_SMALL); PyModule_AddIntConstant(module, "FLY_SKILL_MUYEONG", ava2::FlyingManager::FLY_SKILL_MUYEONG); PyModule_AddIntConstant(module, "FLY_QUIVER_ATTACK_NORMAL", ava2::FlyingManager::FLY_QUIVER_ATTACK_NORMAL); PyModule_AddIntConstant(module, "FLY_CONQUEROR_EXP", ava2::FlyingManager::FLY_CONQUEROR_EXP); } static PyObject* fly_Update(PyObject*, PyObject*) { static float flyingTime = 0.0f; flyingTime += ava2::GetGameFrameDelta(); ava2::FlyingManager::Instance().Update(ava2::GetGameFrameDelta(), flyingTime); Py_RETURN_NONE; } static PyObject* fly_Render(PyObject*, PyObject*) { Py_RETURN_NONE; } void initfly() { static PyMethodDef methods[] = { {"Update", fly_Update, METH_VARARGS, nullptr}, {"Render", fly_Render, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("fly", methods); } namespace { std::array event_center{}; PyObject* event_mgr_update(PyObject*,PyObject* args) { float x,y,z;if(!PyArg_ParseTuple(args,"fff",&x,&y,&z)) return nullptr; // Original CGameEventManager::Update is empty; SetCenterPosition negates Y. event_center={x,-y,z};Py_RETURN_NONE; } } std::array GetGameEventCenter() { return event_center; } void initeventmgr() { event_center={}; static PyMethodDef methods[] = {{"Update",event_mgr_update,METH_VARARGS,nullptr},{nullptr,nullptr,0,nullptr}}; Py_InitModule("eventMgr",methods); } namespace { bool shopOpenState=false; uint8_t shopTabCount=1; std::array shopTabNames{}; std::array shopTabCoins{}; std::array shopItems{}; PyObject* shop_open(PyObject*,PyObject*) { shopOpenState=true;Py_RETURN_NONE; } PyObject* shop_close(PyObject*,PyObject*) { shopOpenState=false;Py_RETURN_NONE; } PyObject* shop_is_open(PyObject*,PyObject*) { return PyInt_FromLong(shopOpenState); } PyObject* shop_clear(PyObject*,PyObject*) { ClearShopState();Py_RETURN_NONE; } PyObject* shop_item_field(PyObject* args,unsigned field) { int index=0;if(!PyArg_ParseTuple(args,"i",&index))return nullptr; const uint32_t position=static_cast(index); const uint8_t tab=static_cast(position/40); if(tab>=3)return PyInt_FromLong(0); const auto& item=shopItems[tab*40+position%40]; if(field==2)return PyLong_FromLongLong(item.price); const uint32_t value=field==0?item.vnum:field==1?item.count:field==3?item.buyVnum:item.buyCount; return PyInt_FromLong(std::bit_cast(value)); } PyObject* shop_item_id(PyObject*,PyObject* args) { return shop_item_field(args,0); } PyObject* shop_item_count(PyObject*,PyObject* args) { return shop_item_field(args,1); } PyObject* shop_item_price(PyObject*,PyObject* args) { return shop_item_field(args,2); } PyObject* shop_item_buy_vnum(PyObject*,PyObject* args) { return shop_item_field(args,3); } PyObject* shop_item_buy_count(PyObject*,PyObject* args) { return shop_item_field(args,4); } PyObject* shop_item_detail(PyObject* args,unsigned kind) { int index=0,field=0;if(!PyArg_ParseTuple(args,"ii",&index,&field))return nullptr; const uint32_t position=static_cast(index); const uint8_t tab=static_cast(position/40); if(tab>=3)return kind==0?PyInt_FromLong(0):Py_BuildValue("(ii)",0,0); const auto& item=shopItems[tab*40+position%40]; if(kind==0) { // Original indexes unchecked; avoid reading outside the record. return PyInt_FromLong(field>=0&&field<8?item.sockets[field]:0); } if(field<0||field>=(kind==1?15:7))return Py_BuildValue("(ii)",0,0); const auto attribute=kind==1?item.attributes[field]:item.gloveAttributes[field]; return Py_BuildValue("(ii)",attribute.first,attribute.second); } PyObject* shop_item_socket(PyObject*,PyObject* args) { return shop_item_detail(args,0); } PyObject* shop_item_attribute(PyObject*,PyObject* args) { return shop_item_detail(args,1); } PyObject* shop_item_glove(PyObject*,PyObject* args) { return shop_item_detail(args,2); } PyObject* shop_tab_count(PyObject*,PyObject*) { return PyInt_FromLong(shopTabCount); } PyObject* shop_tab_name(PyObject*,PyObject* args) { int index=0;if(!PyArg_ParseTuple(args,"i",&index))return nullptr; const auto tab=static_cast(index); if(tab>=shopTabCount)Py_RETURN_NONE; return PyString_FromString(shopTabNames[tab].c_str()); } PyObject* shop_tab_coin(PyObject*,PyObject* args) { int index=0;if(!PyArg_ParseTuple(args,"i",&index))return nullptr; const auto tab=static_cast(index); return PyInt_FromLong(tab(index/40); if(tab<3)shopItems[tab*40+index%40]=item; } bool SetShopTabCount(unsigned count) { if(count>3)return false;shopTabCount=count;return true; } void SetShopTab(unsigned index,const std::string& name,unsigned coin) { if(index>=shopTabCount)return; shopTabNames[index]=name;shopTabCoins[index]=static_cast(coin); } static PyObject* shop_GetOfflineShopItemTransmutation(PyObject*, PyObject*) { return Py_BuildValue("i", 0); } static PyObject* shop_GetItemElements(PyObject*, PyObject*) { return Py_BuildValue("iiii", 0, 0, 0, 0); } void initshop() { static PyMethodDef methods[] = { {"Open", shop_open, METH_VARARGS, nullptr}, {"Close", shop_close, METH_VARARGS, nullptr}, {"Clear", shop_clear, METH_VARARGS, nullptr}, {"IsOpen", shop_is_open, METH_VARARGS, nullptr}, {"GetItemID", shop_item_id, METH_VARARGS, nullptr}, {"GetItemCount", shop_item_count, METH_VARARGS, nullptr}, {"GetItemPrice", shop_item_price, METH_VARARGS, nullptr}, {"GetItemMetinSocket", shop_item_socket, METH_VARARGS, nullptr}, {"GetItemAttribute", shop_item_attribute, METH_VARARGS, nullptr}, {"GetTabCount", shop_tab_count, METH_VARARGS, nullptr}, {"GetTabName", shop_tab_name, METH_VARARGS, nullptr}, {"GetTabCoinType", shop_tab_coin, METH_VARARGS, nullptr}, {"GetVnumBuy", shop_item_buy_vnum, METH_VARARGS, nullptr}, {"GetCountBuy", shop_item_buy_count, METH_VARARGS, nullptr}, {"GetItemRandomAttribute", shop_item_glove, METH_VARARGS, nullptr}, {"GetOfflineShopItemTransmutation", shop_GetOfflineShopItemTransmutation, METH_VARARGS, nullptr}, {"GetItemElements", shop_GetItemElements, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("shop", methods); PyModule_AddIntConstant(module, "SHOP_SLOT_COUNT", 40); PyModule_AddIntConstant(module, "SHOP_COIN_TYPE_GOLD", 0); PyModule_AddIntConstant(module, "SHOP_COIN_TYPE_SECONDARY_COIN", 1); PyModule_AddIntConstant(module, "SHOP_COIN_TYPE_COMBAT_ZONE", 2); PyModule_AddIntConstant(module, "OFFLINE_SHOP_SLOT_COUNT", 80); InitOfflineShopMethods(); } namespace { static const SkillDescription* require_skill(int id,const char* method) { auto* data=skillDescriptions.find(uint32_t(id)); if(!data)PyErr_Format(PyExc_RuntimeError,"skill.%s - Failed to find skill by %d",method,id); return data; } // CGraphicImage* as Python sees it: the cross-platform image handle, 0 for NULL. CGraphicImage* skill_image(const std::string& file) { if(file.empty())return nullptr; auto* resource=CResourceManager::Instance().GetResourcePointer(file.c_str()); return resource&&resource->IsType(CGraphicImage::Type())?static_cast(resource):nullptr; } PyObject* image_handle(const std::string& file) { return PyInt_FromLong(long(GrpRegisterImageHandle(skill_image(file)))); } PyObject* image_instance_handle(const std::string& file) { CGraphicImageInstance* instance=CGraphicImageInstance::New(); instance->SetImagePointer(skill_image(file)); return PyInt_FromLong(long(GrpRegisterImageInstanceHandle(instance))); } int clamp_grade(int grade) { return grade<0?0:grade>=skill_constants::SKILL_GRADE_COUNT?skill_constants::SKILL_GRADE_COUNT-1:grade; } // CPythonSkill::GetSkillDataByName: first skill (by index) whose name matches. const SkillDescription* skill_by_name(const std::string& name) { for(const auto& [id,data]:skillDescriptions.records)if(data.name==name)return &data; return nullptr; } // CPythonSkill::RegisterSkill: a per-skill CTextFileLoader file. std::map::insert keeps an // existing entry; the time-increase number is still updated. bool register_skill_file(uint32_t index,const std::string& fileName) { std::string text; try { text=ReadPackedText(fileName); } catch(const std::exception&) { return false; } TextFileLoader loader; if(!loader.load(text))return false; loader.setTop(); const std::string cp=std::to_string(kLocaleCodePage); SkillDescription data;data.skillIndex=index;data.type=skill_constants::SKILL_TYPE_ACTIVE; std::string type; if(!loader.tokenString("type",&type))return false; ava2Lowers(type); auto typeIt=SkillDescriptions::typeMap().find(type); if(typeIt==SkillDescriptions::typeMap().end())return false; data.type=typeIt->second; if(auto* tokens=loader.tokenVector("attribute")) for(const auto& token:*tokens) { const auto& names=SkillDescriptions::attributeNames(); for(size_t bit=0;bitsecond; } if(!loader.tokenString(cp+"name",&data.name)&&!loader.tokenString("name",&data.name))return false; if(!loader.tokenString(cp+"description",&data.description))loader.tokenString("description",&data.description); if(!loader.tokenString("iconfilename",&data.iconFileName))return false; const auto* conditions=loader.tokenVector(cp+"conditiondata"); if(!conditions)conditions=loader.tokenVector("conditiondata"); if(conditions)data.conditions=*conditions; const auto* affects=loader.tokenVector(cp+"affectdata"); if(!affects)affects=loader.tokenVector("affectdata"); if(affects) { data.affects.clear(); for(size_t i=0;isize()/3;++i)data.affects.push_back({(*affects)[i*3],(*affects)[i*3+1],(*affects)[i*3+2]}); } if(const auto* grades=loader.tokenVector(cp+"gradedata")) for(size_t i=0;i(skill_constants::SKILL_GRADE_COUNT,grades->size()/2);++i) { data.gradeNames[i]=(*grades)[i*2]; data.gradeImageFiles[i]=kImagePath+(*grades)[i*2+1]; } loader.tokenString("cooltimeformula",&data.cooldownFormula); loader.tokenString("targetcountformula",&data.targetCountFormula); loader.tokenString("motionloopcountformula",&data.motionLoopCountFormula); loader.tokenString("needspformula",&data.needSPFormula); loader.tokenString("continuationspformula",&data.continuationSPFormula); int value; if(loader.tokenInteger("range",&value))data.targetRange=uint32_t(value); if(loader.tokenInteger("maxlevel",&value))data.maxLevel=uint8_t(value); if(loader.tokenInteger("leveluppoint",&value))data.levelUpPoint=uint8_t(value); data.motion=loader.tokenInteger("motionindex",&value)?uint16_t(value):0; data.motionForMe=loader.tokenInteger("motionindexforme",&value)?uint16_t(value):0; data.iconFileName=kImagePath+data.iconFileName; data.imageFile=data.iconFileName; const bool timeIncrease=(data.attributes&(1u<<15))!=0; // SKILL_ATTRIBUTE_TIME_INCREASE_SKILL skillDescriptions.records.insert({index,std::move(data)}); if(timeIncrease)s_timeIncreaseSkillNumber=index; return true; } // CPythonSkill::TEST: dumps every skill as a skilldesc-style row to test.txt in the working directory. void dump_skill_test() { std::FILE* file=std::fopen("test.txt","w"); if(!file)return; // the original fprintf()s through a NULL FILE* std::map attributeMap; for(size_t bit=0;biti)line+=data.conditions[i];} line+="\t"+joined(attributeMap,data.attributes); line+="\t"+joined(SkillDescriptions::weaponMap(),data.needWeapon); line+="\t"; std::string iconName=data.iconFileName; const int pos=int(iconName.find_last_of('/')); if(pos>0)iconName=iconName.substr(pos+1,iconName.size()-pos-4-1); line+=iconName; line+="\t"+std::to_string(data.motion); line+="\t"; if(data.motionForMe>1)line+=std::to_string(data.motionForMe); for(size_t i=0;i<3;++i) { line+="\t"; if(data.affects.size()>i)line+=data.affects[i].description+"\t"+data.affects[i].minFormula+"\t"+data.affects[i].maxFormula; } std::fprintf(file,"%s\n",line.c_str()); } std::fclose(file); } PyObject* skill_SetPathName(PyObject*,PyObject* args) { char* path;if(!PyTuple_GetString(args,0,&path))return Py_BadArgument(); s_skillPathName=path;Py_RETURN_NONE; } PyObject* skill_RegisterSkill(PyObject*,PyObject* args) { int index;char* fileName; if(!PyTuple_GetInteger(args,0,&index)||!PyTuple_GetString(args,1,&fileName))return Py_BadArgument(); const std::string full=s_skillPathName+fileName; if(!register_skill_file(uint32_t(index),full)) { PyErr_Format(PyExc_RuntimeError,"skill.RegisterSkill - Failed to find skill data file : %d, %s",index,full.c_str()); return nullptr; } Py_RETURN_NONE; } PyObject* skill_ClearSkillData(PyObject*,PyObject*) { s_timeIncreaseSkillNumber=0;Py_RETURN_NONE; } PyObject* skill_TEST(PyObject*,PyObject*) { dump_skill_test();Py_RETURN_NONE; } // The skill argument every lookup below starts with; Py_BadArgument on a non-int. const SkillDescription* skill_arg(PyObject* args,const char* method) { int id;if(!PyTuple_GetInteger(args,0,&id))return Py_BadArgument(),nullptr; return require_skill(id,method); } // No AVA2 loader ever sets SSkillData::isRequirement, strRequireSkillName, byRequireSkillLevel or // RequireStatDataVector (constructor: FALSE / "" / 0 / empty), so the requirement branches below // reduce to their constructor-state results; CPythonPlayer is never consulted. PyObject* skill_IsSkillRequirement(PyObject*,PyObject* args) { if(!skill_arg(args,"IsSkillRequirement"))return nullptr; return PyInt_FromLong(0); } PyObject* skill_GetSkillRequirementData(PyObject*,PyObject* args) { auto* data=skill_arg(args,"GetSkillRequirementData");if(!data)return nullptr; auto* required=skill_by_name(""); // strRequireSkillName // Original: Py_BuildValue("si", 0, "None", 0) -> (None,
); the address is 0 here. if(!required)return Py_BuildValue("Oi",Py_None,0); // ceil(byRequireSkillLevel / max(1, byLevelUpPoint)) with byRequireSkillLevel == 0. return Py_BuildValue("si","",int(std::ceil(0.0f/float(std::max(1,required->levelUpPoint))))); } PyObject* skill_GetSkillRequireStatCount(PyObject*,PyObject* args) { if(!skill_arg(args,"GetSkillRequireStatCount"))return nullptr; return PyInt_FromLong(0); } PyObject* skill_GetSkillRequireStatData(PyObject*,PyObject* args) { int id,stat; if(!PyTuple_GetInteger(args,0,&id)||!PyTuple_GetInteger(args,1,&stat))return Py_BadArgument(); if(!require_skill(id,"GetSkillRequireStatData"))return nullptr; return Py_BuildValue("ii",0,0); // iStatIndex >= RequireStatDataVector.size() for every index } PyObject* skill_CanLevelUpSkill(PyObject*,PyObject* args) { int id,level; if(!PyTuple_GetInteger(args,0,&id)||!PyTuple_GetInteger(args,1,&level))return Py_BadArgument(); auto* data=require_skill(id,"CanLevelUpSkill");if(!data)return nullptr; if(level>=data->maxLevel)return PyInt_FromLong(0); if(data->attributes&(1u<<18))return PyInt_FromLong(0); // SKILL_ATTRIBUTE_CANNOT_LEVEL_UP return PyInt_FromLong(1); } PyObject* skill_IsLevelUpSkill(PyObject*,PyObject* args) { if(!skill_arg(args,"IsLevelUpSkill"))return nullptr; return PyInt_FromLong(1); } PyObject* skill_CheckRequirementSueccess(PyObject*,PyObject* args) { if(!skill_arg(args,"CheckRequirementSueccess"))return nullptr; return PyInt_FromLong(1); } PyObject* skill_GetNeedCharacterLevel(PyObject*,PyObject* args) { if(!skill_arg(args,"GetNeedCharacterLevel"))return nullptr; return PyInt_FromLong(0); // no POINT_LEVEL entry in an empty RequireStatDataVector } PyObject* skill_CanUseSkill(PyObject*,PyObject* args) { auto* data=skill_arg(args,"CanUseSkill");if(!data)return nullptr; return PyInt_FromLong((data->attributes&(1u<<17))==0); // IsCanUseSkill: !SKILL_ATTRIBUTE_PASSIVE } PyObject* skill_GetIconName(PyObject*,PyObject* args) { int id;if(!PyTuple_GetInteger(args,0,&id))return Py_BadArgument(); auto* data=skillDescriptions.find(uint32_t(id)); return PyString_FromString(data?data->iconFileName.c_str():""); } PyObject* skill_GetIconImage(PyObject*,PyObject* args) { int id;if(!PyTuple_GetInteger(args,0,&id))return Py_BadArgument(); auto* data=skillDescriptions.find(uint32_t(id)); if(!data)return PyInt_FromLong(0); // 0 instead of an exception return image_handle(data->imageFile); } PyObject* skill_GetIconImageNew(PyObject*,PyObject* args) { int id,grade; if(!PyTuple_GetInteger(args,0,&id)||!PyTuple_GetInteger(args,1,&grade))return Py_BadArgument(); auto* data=skillDescriptions.find(uint32_t(id)); if(!data)return PyInt_FromLong(0); return image_handle(data->gradeImageFiles[clamp_grade(grade)]); } PyObject* skill_GetIconInstance(PyObject*,PyObject* args) { auto* data=skill_arg(args,"GetIconInstance");if(!data)return nullptr; return image_instance_handle(data->imageFile); } PyObject* skill_GetIconInstanceNew(PyObject*,PyObject* args) { int id,grade; if(!PyTuple_GetInteger(args,0,&id)||!PyTuple_GetInteger(args,1,&grade))return Py_BadArgument(); auto* data=require_skill(id,"GetIconInstanceNew");if(!data)return nullptr; return image_instance_handle(data->gradeImageFiles[clamp_grade(grade)]); } PyObject* skill_DeleteIconInstance(PyObject*,PyObject* args) { int handle;if(!PyTuple_GetInteger(args,0,&handle))return Py_BadArgument(); // Unknown handles are ignored (the original deletes whatever the int points at). CGraphicImageInstance::Delete(GrpReleaseImageInstanceHandle(uint32_t(handle))); Py_RETURN_NONE; } PyObject* skill_GetGradeData(PyObject*,PyObject* args) { int id,grade; if(!PyTuple_GetInteger(args,0,&id)||!PyTuple_GetInteger(args,1,&grade))return Py_BadArgument(); auto* data=require_skill(id,"GetGradeData");if(!data)return nullptr; if(grade<0||grade>=skill_constants::SKILL_GRADE_COUNT) { // The format prints the skill index (the grade argument is unused). PyErr_Format(PyExc_RuntimeError,"Strange grade index [%d]",id);return nullptr; } // Py_BuildValue("i", GradeData[i]) passes the TGradeData struct through varargs; "i" reads its // first four bytes, the start of the MSVC x86 std::string strName: the inline buffer for names // shorter than 16 bytes (bytes past the terminator read as 0 here) or a heap pointer (0 here). const std::string& name=data->gradeNames[grade]; uint32_t value=0; if(name.size()<16)for(size_t i=0;i<4&&i(value)); } // ENABLE_NEW_PET_SYSTEM: any image resource by file name. PyObject* skill_GetIconImageNewEx(PyObject*,PyObject* args) { char* file;if(!PyTuple_GetString(args,0,&file))return Py_BadArgument(); return image_handle(file); } static PyObject* skill_name(PyObject*,PyObject* args) { int id,grade=-1;if(!PyArg_ParseTuple(args,"i|i",&id,&grade))return nullptr; auto* data=skillDescriptions.find(uint32_t(id)); if(!data)return PyString_FromString("NoneSkill"); return PyString_FromString((grade>=0&&grade<3?data->gradeNames[grade]:data->name).c_str()); } static PyObject* skill_description(PyObject*,PyObject* args) { int id;if(!PyArg_ParseTuple(args,"i",&id))return nullptr; auto* data=require_skill(id,"GetSkillDescription");if(!data)return nullptr; return PyString_FromString(data->description.c_str()); } static PyObject* skill_type(PyObject*,PyObject* args) { int id;if(!PyArg_ParseTuple(args,"i",&id))return nullptr; auto* data=require_skill(id,"GetSkillType");if(!data)return nullptr; return PyInt_FromLong(data->type); } static PyObject* skill_condition_count(PyObject*,PyObject* args) { int id;if(!PyArg_ParseTuple(args,"i",&id))return nullptr; auto* data=require_skill(id,"GetSkillConditionDescriptionCount");if(!data)return nullptr; return PyInt_FromLong(data->conditions.size()); } static PyObject* skill_condition(PyObject*,PyObject* args) { int id,index;if(!PyArg_ParseTuple(args,"ii",&id,&index))return nullptr; auto* data=require_skill(id,"GetSkillConditionDescription");if(!data)return nullptr; if(uint32_t(index)>=data->conditions.size())Py_RETURN_NONE; return PyString_FromString(data->conditions[index].c_str()); } static PyObject* skill_metadata(PyObject* args,int field,const char* method) { int id;if(!PyArg_ParseTuple(args,"i",&id))return nullptr; auto* data=require_skill(id,method);if(!data)return nullptr; return PyInt_FromLong(field==0?data->maxLevel:field==1?data->levelLimit:field==2?data->levelUpPoint:data->affects.size()); } static PyObject* skill_max_level(PyObject*,PyObject* args) {return skill_metadata(args,0,"GetSkillMaxLevel");} static PyObject* skill_level_limit(PyObject*,PyObject* args) {return skill_metadata(args,1,"GetSkillLevelLimit");} static PyObject* skill_level_up(PyObject*,PyObject* args) {return skill_metadata(args,2,"GetSkillLevelUpPoint");} static PyObject* skill_affect_count(PyObject*,PyObject* args) {return skill_metadata(args,3,"GetSkillAffectDescriptionCount");} static float skill_formula(const std::string& formula,float level) { if(formula.empty())return 0; CPoly poly;poly.SetStr(formula);if(!poly.Analyze())return 0; static const std::map points={ {"chain",0},{"HR",204},{"LV",1},{"Level",1},{"MaxHP",6},{"MaxSP",8}, {"MinMWEP",200},{"MaxMWEP",201},{"MinWEP",200},{"MaxWEP",201},{"MinATK",29},{"MaxATK",30}, {"ATKSPD",17},{"AttackPower",29},{"AtkMin",29},{"AtkMax",30},{"DefencePower",20},{"DEF",20}, {"MWEP",22},{"MagicAttackPower",22},{"INT",15},{"STR",12},{"DEX",14},{"CON",13}, {"minatk",29},{"maxatk",30},{"minmtk",200},{"maxmtk",201},{"maxhp",6},{"maxsp",8},{"odef",20}, {"minwep",200},{"maxwep",201},{"minmwep",202},{"maxmwep",203},{"lv",1},{"ar",204},{"iq",15},{"str",12},{"dex",14},{"con",13}}; for(unsigned i=0;isecond))); else if(name.rfind("JeungJi",0)!=0)return 0; // Original leaves unknown state uninitialized; deterministic rejection. if(name=="ar")value/=100.0f;} poly.SetVar(name,value); } return poly.Eval(); } static std::string format_skill_affect(const SkillAffectDescription& affect,float level) { float low=std::fabs(skill_formula(affect.minFormula,level)); float high=std::fabs(skill_formula(affect.maxFormula,level)); if(affect.description.find("%.0f")!=std::string::npos){low=std::floor(low);high=std::floor(high);} // Original supplies two doubles to printf; reject incompatible conversions // rather than reading missing varargs or permitting a write conversion. static const std::regex conversion(R"(%[-+ #0]*[0-9]*(\.[0-9]*)?f)"); unsigned count=0; for(size_t i=0;i2) throw std::runtime_error("unsupported skill description format"); i+=match.length(); } char text[66]{};std::snprintf(text,sizeof(text),affect.description.c_str(),double(low),double(high)); return std::string(text).substr(0,65); } static PyObject* skill_new_affect_count(PyObject*,PyObject* args) { int id;if(!PyArg_ParseTuple(args,"i",&id))return nullptr; if(!require_skill(id,"GetNewAffectDataCount"))return nullptr; // Original RegisterSkillDesc clears this vector and neither active loader populates it. return PyInt_FromLong(0); } static PyObject* skill_new_affect(PyObject*,PyObject* args) { int id,index;float level;if(!PyArg_ParseTuple(args,"iif",&id,&index,&level))return nullptr; if(!require_skill(id,"GetNewAffectData"))return nullptr; PyErr_Format(PyExc_RuntimeError,"skill.GetNewAffectData - Strange AffectIndex %d",index);return nullptr; } static PyObject* skill_affect_description(PyObject*,PyObject* args) { int id,index;float level;if(!PyArg_ParseTuple(args,"iif",&id,&index,&level))return nullptr; auto* data=require_skill(id,"GetSkillAffectDescription");if(!data)return nullptr; if(uint32_t(index)>=data->affects.size())Py_RETURN_NONE; try {auto text=format_skill_affect(data->affects[index],level);return PyString_FromString(text.c_str());} catch(const std::exception& e){PyErr_SetString(PyExc_RuntimeError,e.what());return nullptr;} } static PyObject* skill_formula_get(PyObject* args,int field,const char* method) { int id;float level;if(!PyArg_ParseTuple(args,"if",&id,&level))return nullptr; auto* data=require_skill(id,method);if(!data)return nullptr; const auto& formula=field==0?data->cooldownFormula:field==1?data->needSPFormula:field==2?data->continuationSPFormula:data->durationFormula; float value=skill_formula(formula,level); if(!std::isfinite(value))return PyInt_FromLong(0); double wrapped=std::fmod(std::trunc(double(value)),4294967296.0); if(wrapped<0)wrapped+=4294967296.0; return PyInt_FromLong(std::bit_cast(uint32_t(wrapped))); } static PyObject* skill_cooldown(PyObject*,PyObject* a){return skill_formula_get(a,0,"GetSkillCoolTime");} static PyObject* skill_sp(PyObject*,PyObject* a){return skill_formula_get(a,1,"GetSkillNeedSP");} static PyObject* skill_cont_sp(PyObject*,PyObject* a){return skill_formula_get(a,2,"GetSkillContinuationSP");} static PyObject* skill_duration(PyObject*,PyObject* a){return skill_formula_get(a,3,"GetDuration");} static PyObject* skill_flag(PyObject* args,uint32_t flag,const char* method) { int id;if(!PyArg_ParseTuple(args,"i",&id))return nullptr; auto* data=require_skill(id,method);if(!data)return nullptr; return PyInt_FromLong((data->attributes&flag)!=0); } static PyObject* skill_IsToggleSkill(PyObject*,PyObject* args) { return skill_flag(args,1u<<1,"IsToggleSkill"); } static PyObject* skill_IsStandingSkill(PyObject*,PyObject* args) { return skill_flag(args,1u<<6,"IsStandingSkill"); } static PyObject* skill_IsUseHPSkill(PyObject*,PyObject* args) { return skill_flag(args,1u<<4,"IsUseHPSkill"); } } // namespace float EvaluateSkillFormula(const std::string& formula,float level) {return skill_formula(formula,level);} static PyObject* skill_LoadSkillData(PyObject*, PyObject*) { return Py_BuildNone(); } void initskill() { static PyMethodDef methods[] = { {"SetPathName", skill_SetPathName, METH_VARARGS, nullptr}, {"RegisterSkill", skill_RegisterSkill, METH_VARARGS, nullptr}, {"LoadSkillData", skill_LoadSkillData, METH_VARARGS, nullptr}, {"ClearSkillData", skill_ClearSkillData, METH_VARARGS, nullptr}, {"GetSkillName", skill_name, METH_VARARGS, nullptr}, {"GetSkillDescription", skill_description, METH_VARARGS, nullptr}, {"GetSkillType", skill_type, METH_VARARGS, nullptr}, {"GetSkillConditionDescriptionCount", skill_condition_count, METH_VARARGS, nullptr}, {"GetSkillConditionDescription", skill_condition, METH_VARARGS, nullptr}, {"GetSkillAffectDescriptionCount", skill_affect_count, METH_VARARGS, nullptr}, {"GetSkillAffectDescription", skill_affect_description, METH_VARARGS, nullptr}, {"GetSkillCoolTime", skill_cooldown, METH_VARARGS, nullptr}, {"GetSkillNeedSP", skill_sp, METH_VARARGS, nullptr}, {"GetSkillContinuationSP", skill_cont_sp, METH_VARARGS, nullptr}, {"GetSkillMaxLevel", skill_max_level, METH_VARARGS, nullptr}, {"GetSkillLevelUpPoint", skill_level_up, METH_VARARGS, nullptr}, {"GetSkillLevelLimit", skill_level_limit, METH_VARARGS, nullptr}, {"IsSkillRequirement", skill_IsSkillRequirement, METH_VARARGS, nullptr}, {"GetSkillRequirementData", skill_GetSkillRequirementData, METH_VARARGS, nullptr}, {"GetSkillRequireStatCount", skill_GetSkillRequireStatCount, METH_VARARGS, nullptr}, {"GetSkillRequireStatData", skill_GetSkillRequireStatData, METH_VARARGS, nullptr}, {"CanLevelUpSkill", skill_CanLevelUpSkill, METH_VARARGS, nullptr}, {"IsLevelUpSkill", skill_IsLevelUpSkill, METH_VARARGS, nullptr}, {"CheckRequirementSueccess", skill_CheckRequirementSueccess, METH_VARARGS, nullptr}, {"GetNeedCharacterLevel", skill_GetNeedCharacterLevel, METH_VARARGS, nullptr}, {"IsToggleSkill", skill_IsToggleSkill, METH_VARARGS, nullptr}, {"IsUseHPSkill", skill_IsUseHPSkill, METH_VARARGS, nullptr}, {"IsStandingSkill", skill_IsStandingSkill, METH_VARARGS, nullptr}, {"CanUseSkill", skill_CanUseSkill, METH_VARARGS, nullptr}, {"GetIconName", skill_GetIconName, METH_VARARGS, nullptr}, {"GetIconImage", skill_GetIconImage, METH_VARARGS, nullptr}, {"GetIconImageNew", skill_GetIconImageNew, METH_VARARGS, nullptr}, {"GetIconInstance", skill_GetIconInstance, METH_VARARGS, nullptr}, {"GetIconInstanceNew", skill_GetIconInstanceNew, METH_VARARGS, nullptr}, {"DeleteIconInstance", skill_DeleteIconInstance, METH_VARARGS, nullptr}, {"GetGradeData", skill_GetGradeData, METH_VARARGS, nullptr}, {"GetIconImageNewEx", skill_GetIconImageNewEx, METH_VARARGS, nullptr}, {"GetNewAffectDataCount", skill_new_affect_count, METH_VARARGS, nullptr}, {"GetNewAffectData", skill_new_affect, METH_VARARGS, nullptr}, {"GetDuration", skill_duration, METH_VARARGS, nullptr}, {"TEST", skill_TEST, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("skill", methods); PyModule_AddIntConstant(module, "SKILL_TYPE_NONE", skill_constants::SKILL_TYPE_NONE); PyModule_AddIntConstant(module, "SKILL_TYPE_ACTIVE", skill_constants::SKILL_TYPE_ACTIVE); PyModule_AddIntConstant(module, "SKILL_TYPE_SUPPORT", skill_constants::SKILL_TYPE_SUPPORT); PyModule_AddIntConstant(module, "SKILL_TYPE_GUILD", skill_constants::SKILL_TYPE_GUILD); PyModule_AddIntConstant(module, "SKILL_TYPE_HORSE", skill_constants::SKILL_TYPE_HORSE); PyModule_AddIntConstant(module, "SKILL_TYPE_MAX_NUM", skill_constants::SKILL_TYPE_MAX_NUM); PyModule_AddIntConstant(module, "SKILL_GRADE_COUNT", skill_constants::SKILL_GRADE_COUNT); PyModule_AddIntConstant(module, "SKILL_GRADE_STEP_COUNT", skill_constants::SKILL_GRADE_STEP_COUNT); PyModule_AddIntConstant(module, "SKILL_GRADEGAP", skill_constants::SKILL_GRADEGAP); PyModule_AddIntConstant(module, "SKILL_EFFECT_COUNT", skill_constants::SKILL_EFFECT_COUNT); } namespace { static PyObject* sash_SendCloseRequest(PyObject*, PyObject*) { PythonNetworkStream::Instance().SendSashClosePacket(); return Py_BuildNone(); } static PyObject* sash_Add(PyObject*, PyObject* args) { uint8_t bPos = 0; TItemPos tPos; int win = 0, cell = 0, pos = 0; if (!PyTuple_GetInteger(args, 0, &win) || !PyTuple_GetInteger(args, 1, &cell) || !PyTuple_GetInteger(args, 2, &pos)) return Py_BuildException(); tPos.window_type = static_cast(win); tPos.cell = static_cast(cell); bPos = static_cast(pos); PythonNetworkStream::Instance().SendSashAddPacket(tPos, bPos); return Py_BuildNone(); } static PyObject* sash_Remove(PyObject*, PyObject* args) { int pos = 0; if (!PyTuple_GetInteger(args, 0, &pos)) return Py_BuildException(); PythonNetworkStream::Instance().SendSashRemovePacket(static_cast(pos)); return Py_BuildNone(); } static PyObject* sash_GetPrice(PyObject*, PyObject*) { return Py_BuildValue("i", CPythonSash::Instance().GetPrice()); } static PyObject* sash_GetAttachedItem(PyObject*, PyObject* args) { int pos = 0; if (!PyTuple_GetInteger(args, 0, &pos)) return Py_BuildException(); uint8_t bHere = 0; uint16_t wCell = 0; bool bGet = CPythonSash::Instance().GetAttachedItem(static_cast(pos), bHere, wCell); if (!bGet) { bHere = 0; wCell = 0; } return Py_BuildValue("ii", static_cast(bHere), static_cast(wCell)); } static PyObject* sash_GetResultItem(PyObject*, PyObject*) { uint32_t dwItemVnum = 0, dwMinAbs = 0, dwMaxAbs = 0; CPythonSash::Instance().GetResultItem(dwItemVnum, dwMinAbs, dwMaxAbs); return Py_BuildValue("iii", dwItemVnum, dwMinAbs, dwMaxAbs); } static PyObject* sash_SendRefineRequest(PyObject*, PyObject*) { uint8_t bHere = 0; uint16_t wCell = 0; bool bGet = CPythonSash::Instance().GetAttachedItem(1, bHere, wCell); if (bGet && bHere) { PythonNetworkStream::Instance().SendSashRefinePacket(); } return Py_BuildNone(); } class CServerStateChecker { public: static CServerStateChecker& Instance() { static CServerStateChecker s; return s; } struct TChannel { uint32_t uServerIndex = 0; std::string szAddr; uint32_t uPort = 0; }; PyObject* m_poWnd = nullptr; std::vector m_channels; void Create(PyObject* poWnd) { m_poWnd = poWnd; } void AddChannel(uint32_t serverIdx, const std::string& addr, uint32_t port) { m_channels.push_back({serverIdx, addr, port}); } void Request() { if (m_poWnd) { for (const auto& ch : m_channels) { PyObject* res = PyObject_CallMethod(m_poWnd, const_cast("NotifyChannelState"), const_cast("(ii)"), ch.uServerIndex, 1); Py_XDECREF(res); } } } void Update() {} void Initialize() { m_channels.clear(); m_poWnd = nullptr; } }; static PyObject* ServerStateChecker_Create(PyObject*, PyObject* args) { PyObject* poWnd = nullptr; if (!PyTuple_GetObject(args, 0, &poWnd)) return Py_BadArgument(); CServerStateChecker::Instance().Create(poWnd); return Py_BuildNone(); } static PyObject* ServerStateChecker_Update(PyObject*, PyObject*) { CServerStateChecker::Instance().Update(); return Py_BuildNone(); } static PyObject* ServerStateChecker_Request(PyObject*, PyObject*) { CServerStateChecker::Instance().Request(); return Py_BuildNone(); } static PyObject* ServerStateChecker_AddChannel(PyObject*, PyObject* args) { int nServerIndex = 0, nPort = 0; char* szAddr = nullptr; if (!PyTuple_GetInteger(args, 0, &nServerIndex) || !PyTuple_GetString(args, 1, &szAddr) || !PyTuple_GetInteger(args, 2, &nPort)) return Py_BuildException(); CServerStateChecker::Instance().AddChannel(nServerIndex, szAddr ? szAddr : "", nPort); return Py_BuildNone(); } static PyObject* ServerStateChecker_Initialize(PyObject*, PyObject*) { CServerStateChecker::Instance().Initialize(); return Py_BuildNone(); } static PyObject* playerLoad_RegisterSkill(PyObject*, PyObject* args) { uint8_t bRaceIndex = 0, bSkillGroupIndex = 0, bEmpireIndex = 0; if (!PyTuple_GetByte(args, 0, &bRaceIndex) || !PyTuple_GetByte(args, 1, &bSkillGroupIndex) || !PyTuple_GetByte(args, 2, &bEmpireIndex)) return Py_BuildException(); RegisterPlayerSkills(bRaceIndex, bSkillGroupIndex, bEmpireIndex); return Py_BuildNone(); } static PyObject* bankLoadLogs(PyObject*, PyObject* args) { int id = 0; if (!PyTuple_GetInteger(args, 0, &id)) return Py_BuildException(); TAccountBank p = CPythonManagerBank::Instance().BINARY_LoadLogs_Account(id); PyObject* res = PyTuple_New(5); PyTuple_SetItem(res, 0, Py_BuildValue("i", p.user_action)); PyTuple_SetItem(res, 1, Py_BuildValue("i", p.user_money)); PyTuple_SetItem(res, 2, Py_BuildValue("s", p.user_datetime)); PyTuple_SetItem(res, 3, Py_BuildValue("s", p.user_ip)); PyTuple_SetItem(res, 4, Py_BuildValue("s", p.user_recvmoney)); return res; } } // namespace void initSash() { static PyMethodDef methods[] = { {"SendCloseRequest", sash_SendCloseRequest, METH_VARARGS, nullptr}, {"Add", sash_Add, METH_VARARGS, nullptr}, {"Remove", sash_Remove, METH_VARARGS, nullptr}, {"GetPrice", sash_GetPrice, METH_VARARGS, nullptr}, {"GetAttachedItem", sash_GetAttachedItem, METH_VARARGS, nullptr}, {"GetResultItem", sash_GetResultItem, METH_VARARGS, nullptr}, {"SendRefineRequest", sash_SendRefineRequest, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("sash", methods); PyModule_AddIntConstant(module, "ABSORPTION_SOCKET", 0); PyModule_AddIntConstant(module, "ABSORBED_SOCKET", 1); PyModule_AddIntConstant(module, "CLEAN_ATTR_VALUE0", 7); PyModule_AddIntConstant(module, "WINDOW_MAX_MATERIALS", 2); PyModule_AddIntConstant(module, "CLEAN_ATTR_VALUE_FIELD", 0); PyModule_AddIntConstant(module, "LIMIT_RANGE", 1000); } void initServerStateChecker() { static PyMethodDef methods[] = { {"Create", ServerStateChecker_Create, METH_VARARGS, nullptr}, {"Update", ServerStateChecker_Update, METH_VARARGS, nullptr}, {"Request", ServerStateChecker_Request, METH_VARARGS, nullptr}, {"AddChannel", ServerStateChecker_AddChannel, METH_VARARGS, nullptr}, {"Initialize", ServerStateChecker_Initialize, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; Py_InitModule("ServerStateChecker", methods); } void initPlayerSettingsModule() { static PyMethodDef methods[] = { {"RegisterSkill", playerLoad_RegisterSkill, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; Py_InitModule("playerLoad", methods); } // wiki module: CPythonWiki port in src/python_wiki.cpp. static PyObject* combatZone_IsRunning(PyObject*, PyObject*) { return PyBool_FromLong(0); } static PyObject* combatZone_GetRankings(PyObject*, PyObject*) { return Py_BuildValue("iiii", 0, 0, 0, 0); } static PyObject* combatZone_GetDay(PyObject*, PyObject*) { return Py_BuildValue("iiii", 0, 0, 0, 0); } static PyObject* combatZone_SendCombatZoneRequestActionPacket(PyObject*, PyObject*) { Py_RETURN_NONE; } static PyObject* combatZone_GetDayActivate(PyObject*, PyObject*) { return PyBool_FromLong(0); } void initCombatZoneSystem() { static PyMethodDef methods[] = { {"IsRunning", combatZone_IsRunning, METH_VARARGS, nullptr}, {"GetRankings", combatZone_GetRankings, METH_VARARGS, nullptr}, {"GetDay", combatZone_GetDay, METH_VARARGS, nullptr}, {"SendCombatZoneRequestActionPacket", combatZone_SendCombatZoneRequestActionPacket, METH_VARARGS, nullptr}, {"GetDayActivate", combatZone_GetDayActivate, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("combat_zone", methods); if (!module) return; PyModule_AddIntConstant(module, "COMBAT_ZONE_MAX_ROWS_RANKING", 11); PyModule_AddIntConstant(module, "COMBAT_ZONE_EMPTY_DATA", 999); PyModule_AddIntConstant(module, "COMBAT_ZONE_ACTION_OPEN_RANKING", 1); PyModule_AddIntConstant(module, "COMBAT_ZONE_ACTION_CHANGE_PAGE_RANKING", 2); PyModule_AddIntConstant(module, "COMBAT_ZONE_ACTION_PARTICIPATE", 3); PyModule_AddIntConstant(module, "COMBAT_ZONE_ACTION_LEAVE", 4); PyModule_AddIntConstant(module, "COMBAT_ZONE_ACTION_REQUEST_POTION", 5); PyModule_AddIntConstant(module, "COMBAT_ZONE_TYPE_RANKING_WEEKLY", 1); PyModule_AddIntConstant(module, "COMBAT_ZONE_TYPE_RANKING_ALL", 2); PyModule_AddIntConstant(module, "COMBAT_ZONE_ICON_SLOT", 27125); PyModule_AddIntConstant(module, "COMBAT_ZONE_ICON_SLOT_COUNT", 3); } void initBankManager() { static PyMethodDef methods[] = { {"Append", bankLoadLogs, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; Py_InitModule("managerBankLogs", methods); } static PyObject* safebox_GetCurrentSafeboxSize(PyObject*, PyObject*) { return PyInt_FromLong(CPythonSafeBox::Instance().GetCurrentSafeBoxSize()); } static PyObject* safebox_GetItemID(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return PyInt_FromLong(0); uint32_t vnum = 0; CPythonSafeBox::Instance().GetSlotItemID(slot, &vnum); return PyInt_FromLong(vnum); } static PyObject* safebox_GetItemCount(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return PyInt_FromLong(0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetItemDataPtr(slot, &pItem) || !pItem) return PyInt_FromLong(0); return PyInt_FromLong(pItem->count); } static PyObject* safebox_GetItemFlags(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return PyInt_FromLong(0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetItemDataPtr(slot, &pItem) || !pItem) return PyInt_FromLong(0); return PyInt_FromLong(pItem->flags); } static PyObject* safebox_GetItemMetinSocket(PyObject*, PyObject* args) { int slot = 0, socketIdx = 0; if (!PyArg_ParseTuple(args, "ii", &slot, &socketIdx)) return PyInt_FromLong(0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetItemDataPtr(slot, &pItem) || !pItem || socketIdx < 0 || socketIdx >= static_cast(ITEM_SOCKET_SLOT_MAX_NUM)) { return PyInt_FromLong(0); } return PyInt_FromLong(pItem->alSockets[socketIdx]); } static PyObject* safebox_GetItemAttribute(PyObject*, PyObject* args) { int slot = 0, attrIdx = 0; if (!PyArg_ParseTuple(args, "ii", &slot, &attrIdx)) return Py_BuildValue("ii", 0, 0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetItemDataPtr(slot, &pItem) || !pItem || attrIdx < 0 || attrIdx >= static_cast(ITEM_ATTRIBUTE_SLOT_MAX_NUM)) { return Py_BuildValue("ii", 0, 0); } return Py_BuildValue("ii", pItem->aAttr[attrIdx].bType, pItem->aAttr[attrIdx].sValue); } static PyObject* safebox_GetItemRandomAttribute(PyObject*, PyObject* args) { int slot = 0, attrIdx = 0; if (!PyArg_ParseTuple(args, "ii", &slot, &attrIdx)) return Py_BuildValue("ii", 0, 0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetItemDataPtr(slot, &pItem) || !pItem || attrIdx < 0 || attrIdx >= static_cast(GLOVE_ATTR_MAX_NUM)) { return Py_BuildValue("ii", 0, 0); } return Py_BuildValue("ii", pItem->randomAttr[attrIdx].bType, pItem->randomAttr[attrIdx].sValue); } static PyObject* safebox_GetMoney(PyObject*, PyObject*) { return PyInt_FromLong(CPythonSafeBox::Instance().GetMoney()); } static PyObject* safebox_GetMallItemID(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return PyInt_FromLong(0); uint32_t vnum = 0; CPythonSafeBox::Instance().GetSlotMallItemID(slot, &vnum); return PyInt_FromLong(vnum); } static PyObject* safebox_GetMallItemCount(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return PyInt_FromLong(0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetMallItemDataPtr(slot, &pItem) || !pItem) return PyInt_FromLong(0); return PyInt_FromLong(pItem->count); } static PyObject* safebox_GetMallItemMetinSocket(PyObject*, PyObject* args) { int slot = 0, socketIdx = 0; if (!PyArg_ParseTuple(args, "ii", &slot, &socketIdx)) return PyInt_FromLong(0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetMallItemDataPtr(slot, &pItem) || !pItem || socketIdx < 0 || socketIdx >= static_cast(ITEM_SOCKET_SLOT_MAX_NUM)) { return PyInt_FromLong(0); } return PyInt_FromLong(pItem->alSockets[socketIdx]); } static PyObject* safebox_GetMallItemAttribute(PyObject*, PyObject* args) { int slot = 0, attrIdx = 0; if (!PyArg_ParseTuple(args, "ii", &slot, &attrIdx)) return Py_BuildValue("ii", 0, 0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetMallItemDataPtr(slot, &pItem) || !pItem || attrIdx < 0 || attrIdx >= static_cast(ITEM_ATTRIBUTE_SLOT_MAX_NUM)) { return Py_BuildValue("ii", 0, 0); } return Py_BuildValue("ii", pItem->aAttr[attrIdx].bType, pItem->aAttr[attrIdx].sValue); } static PyObject* safebox_GetMallItemRandomAttribute(PyObject*, PyObject* args) { int slot = 0, attrIdx = 0; if (!PyArg_ParseTuple(args, "ii", &slot, &attrIdx)) return Py_BuildValue("ii", 0, 0); const TItemData* pItem = nullptr; if (!CPythonSafeBox::Instance().GetMallItemDataPtr(slot, &pItem) || !pItem || attrIdx < 0 || attrIdx >= static_cast(GLOVE_ATTR_MAX_NUM)) { return Py_BuildValue("ii", 0, 0); } return Py_BuildValue("ii", pItem->randomAttr[attrIdx].bType, pItem->randomAttr[attrIdx].sValue); } static PyObject* safebox_GetMallSize(PyObject*, PyObject*) { return PyInt_FromLong(CPythonSafeBox::Instance().GetMallSize()); } static PyObject* safebox_GetItemNewName(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return PyString_FromString("^"); const TItemData* pItem = nullptr; if (CPythonSafeBox::Instance().GetItemDataPtr(slot, &pItem) && pItem) { return PyString_FromString(pItem->name); } return PyString_FromString("^"); } static PyObject* safebox_GetItemBind(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return PyInt_FromLong(0); const TItemData* pItem = nullptr; if (CPythonSafeBox::Instance().GetItemDataPtr(slot, &pItem) && pItem) { return PyInt_FromLong(pItem->bind); } return PyInt_FromLong(0); } static PyObject* safebox_GetMallItemBind(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return PyInt_FromLong(0); const TItemData* pItem = nullptr; if (CPythonSafeBox::Instance().GetMallItemDataPtr(slot, &pItem) && pItem) { return PyInt_FromLong(pItem->bind); } return PyInt_FromLong(0); } static PyObject* safebox_GetElements(PyObject*, PyObject* args) { int slot = 0; if (!PyArg_ParseTuple(args, "i", &slot)) return Py_BuildValue("iiii", 0, 0, 0, 0); const TItemData* pItem = nullptr; if (CPythonSafeBox::Instance().GetItemDataPtr(slot, &pItem) && pItem && pItem->grade_element > 0) { uint8_t g = pItem->grade_element; return Py_BuildValue("iiii", g, pItem->attack_element[g - 1], pItem->element_type_bonus, pItem->elements_value_bonus[g - 1]); } return Py_BuildValue("iiii", 0, 0, 0, 0); } void initsafebox() { static PyMethodDef methods[] = { {"GetCurrentSafeboxSize", safebox_GetCurrentSafeboxSize, METH_VARARGS, nullptr}, {"GetItemID", safebox_GetItemID, METH_VARARGS, nullptr}, {"GetItemCount", safebox_GetItemCount, METH_VARARGS, nullptr}, {"GetItemFlags", safebox_GetItemFlags, METH_VARARGS, nullptr}, {"GetItemMetinSocket", safebox_GetItemMetinSocket, METH_VARARGS, nullptr}, {"GetItemAttribute", safebox_GetItemAttribute, METH_VARARGS, nullptr}, {"GetItemRandomAttribute", safebox_GetItemRandomAttribute, METH_VARARGS, nullptr}, {"GetMoney", safebox_GetMoney, METH_VARARGS, nullptr}, {"GetMallItemID", safebox_GetMallItemID, METH_VARARGS, nullptr}, {"GetMallItemCount", safebox_GetMallItemCount, METH_VARARGS, nullptr}, {"GetMallItemMetinSocket", safebox_GetMallItemMetinSocket, METH_VARARGS, nullptr}, {"GetMallItemAttribute", safebox_GetMallItemAttribute, METH_VARARGS, nullptr}, {"GetMallItemRandomAttribute", safebox_GetMallItemRandomAttribute, METH_VARARGS, nullptr}, {"GetMallSize", safebox_GetMallSize, METH_VARARGS, nullptr}, {"GetItemNewName", safebox_GetItemNewName, METH_VARARGS, nullptr}, {"GetItemBind", safebox_GetItemBind, METH_VARARGS, nullptr}, {"GetMallItemBind", safebox_GetMallItemBind, METH_VARARGS, nullptr}, {"GetElements", safebox_GetElements, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("safebox", methods); PyModule_AddIntConstant(module, "SAFEBOX_SLOT_X_COUNT", 5); PyModule_AddIntConstant(module, "SAFEBOX_SLOT_Y_COUNT", 9); PyModule_AddIntConstant(module, "SAFEBOX_PAGE_SIZE", 45); } namespace { static PyObject* renderTarget_SelectModel(PyObject*, PyObject* args) { int idx = 0; int modelVnum = 0; if (PyArg_ParseTuple(args, "ii", &idx, &modelVnum)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SelectModel((uint32_t)modelVnum); } Py_RETURN_NONE; } static PyObject* renderTarget_SetVisibility(PyObject*, PyObject* args) { int idx = 0; PyObject* bVis = nullptr; if (PyArg_ParseTuple(args, "iO", &idx, &bVis)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetVisibility(PyObject_IsTrue(bVis)); } Py_RETURN_NONE; } static PyObject* renderTarget_SetBackground(PyObject*, PyObject* args) { int idx = 0; char* path = nullptr; if (PyArg_ParseTuple(args, "is", &idx, &path)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target && path) target->SetBackground(path); } Py_RETURN_NONE; } static PyObject* renderTarget_SetArmor(PyObject*, PyObject* args) { int idx = 0; int armorVnum = 0; if (PyArg_ParseTuple(args, "ii", &idx, &armorVnum)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetArmor((uint32_t)armorVnum); } Py_RETURN_NONE; } static PyObject* renderTarget_SetWeapon(PyObject*, PyObject* args) { int idx = 0; int weaponVnum = 0; if (PyArg_ParseTuple(args, "ii", &idx, &weaponVnum)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetWeapon((uint32_t)weaponVnum); } Py_RETURN_NONE; } static PyObject* renderTarget_SetHair(PyObject*, PyObject* args) { int idx = 0; int hairVnum = 0; if (!PyTuple_GetInteger(args, 0, &idx) || !PyTuple_GetInteger(args, 1, &hairVnum)) { return Py_BadArgument(); } bool isValue = false; PyTuple_GetBoolean(args, 2, &isValue); if (!isValue) { long val = 0; if (ava2::GetItemValue(hairVnum, 3, &val)) { hairVnum = static_cast(val); } } auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetHair(static_cast(hairVnum)); Py_RETURN_NONE; } static PyObject* renderTarget_SetAcce(PyObject*, PyObject* args) { int idx = 0; int acceVnum = 0; if (PyArg_ParseTuple(args, "ii", &idx, &acceVnum)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetAcce((uint32_t)acceVnum); } Py_RETURN_NONE; } static PyObject* renderTarget_SetRotation(PyObject*, PyObject* args) { int idx = 0; float rot = 0.0f; if (PyArg_ParseTuple(args, "if", &idx, &rot)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetRotation(rot); } Py_RETURN_NONE; } static PyObject* renderTarget_GetFreeIndex(PyObject*, PyObject* args) { int minIdx = 0, maxIdx = 0; if (!PyTuple_GetInteger(args, 0, &minIdx) || !PyTuple_GetInteger(args, 1, &maxIdx)) { return Py_BadArgument(); } for (int j = minIdx; j < maxIdx; ++j) { if (!ava2::CRenderTargetManager::Instance().GetRenderTarget(j)) { return Py_BuildValue("i", j); } } return Py_BuildValue("i", minIdx + 20); } static PyObject* renderTarget_IsShow(PyObject*, PyObject* args) { int idx = 0; if (!PyTuple_GetInteger(args, 0, &idx)) return Py_BadArgument(); auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); return Py_BuildValue("i", target ? (target->IsShow() ? 1 : 0) : 0); } static PyObject* renderTarget_Zoom(PyObject*, PyObject* args) { int idx = 0; int direction = 0; if (PyTuple_Size(args) >= 2 && PyTuple_GetInteger(args, 1, &direction)) { if (!PyTuple_GetInteger(args, 0, &idx)) return Py_BadArgument(); auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target && target->IsReady()) { const float fRatio = 1.0f + ava2::GetCameraZoomSpeed() * static_cast(direction); target->Zoom(fRatio); } Py_RETURN_NONE; } float ratio = 1.0f; if (PyArg_ParseTuple(args, "if", &idx, &ratio)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target && target->IsReady()) target->Zoom(ratio); Py_RETURN_NONE; } return Py_BadArgument(); } static PyObject* renderTarget_SetScale(PyObject*, PyObject* args) { int idx = 0; float scale = 1.0f; if (!PyTuple_GetInteger(args, 0, &idx) || !PyTuple_GetFloat(args, 1, &scale)) { return Py_BadArgument(); } auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetScale(scale); Py_RETURN_NONE; } static PyObject* renderTarget_RotateEyeAroundTarget(PyObject*, PyObject* args) { int idx = 0; float pitch = 0.0f, roll = 0.0f; if (!PyTuple_GetInteger(args, 0, &idx) || !PyTuple_GetFloat(args, 1, &pitch) || !PyTuple_GetFloat(args, 2, &roll)) { return Py_BadArgument(); } auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target && target->IsReady()) { target->RotateEyeAroundTarget(pitch, roll); } Py_RETURN_NONE; } static PyObject* renderTarget_SetModelV3Eye(PyObject*, PyObject* args) { int idx = 0; float x = 0.0f, y = 0.0f, z = 0.0f; if (!PyTuple_GetInteger(args, 0, &idx) || !PyTuple_GetFloat(args, 1, &x) || !PyTuple_GetFloat(args, 2, &y) || !PyTuple_GetFloat(args, 3, &z)) { return Py_BadArgument(); } auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetModelV3Eye(x, y, z); Py_RETURN_NONE; } static PyObject* renderTarget_SetModelV3Target(PyObject*, PyObject* args) { int idx = 0; float x = 0.0f, y = 0.0f, z = 0.0f; if (!PyTuple_GetInteger(args, 0, &idx) || !PyTuple_GetFloat(args, 1, &x) || !PyTuple_GetFloat(args, 2, &y) || !PyTuple_GetFloat(args, 3, &z)) { return Py_BadArgument(); } auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetModelV3Target(x, y, z); Py_RETURN_NONE; } static PyObject* renderTarget_SetMount(PyObject*, PyObject* args) { int idx = 0, mount = 0; if (PyArg_ParseTuple(args, "ii", &idx, &mount)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); (void)target; } Py_RETURN_NONE; } static PyObject* renderTarget_ResetModel(PyObject*, PyObject* args) { int idx = 0; if (PyArg_ParseTuple(args, "i", &idx)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->ResetModel(); } Py_RETURN_NONE; } static PyObject* renderTarget_SetModelRender(PyObject*, PyObject* args) { int idx = 0; PyObject* bStatus = nullptr; if (PyArg_ParseTuple(args, "iO", &idx, &bStatus)) { auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target) target->SetModelStatus(PyObject_IsTrue(bStatus)); } Py_RETURN_NONE; } static PyObject* renderTarget_AddAffect(PyObject*, PyObject* args) { int idx = 0, effect = 0; if (!PyArg_ParseTuple(args, "ii", &idx, &effect)) return Py_BadArgument(); Py_RETURN_NONE; } static PyObject* renderTarget_RemoveAffect(PyObject*, PyObject* args) { int idx = 0, effect = 0; if (!PyArg_ParseTuple(args, "ii", &idx, &effect)) return Py_BadArgument(); Py_RETURN_NONE; } static PyObject* renderTarget_ClearAffect(PyObject*, PyObject* args) { int idx = 0; if (!PyArg_ParseTuple(args, "i", &idx)) return Py_BadArgument(); Py_RETURN_NONE; } static PyObject* renderTarget_SetMotionIndex(PyObject*, PyObject* args) { int idx = 0, motion = 0; if (!PyTuple_GetInteger(args, 0, &idx) || !PyTuple_GetInteger(args, 1, &motion)) { return Py_BadArgument(); } auto target = ava2::CRenderTargetManager::Instance().GetRenderTarget(idx); if (target && target->IsReady()) { target->SetMotionIndex(motion); return Py_BuildValue("i", 1); } Py_RETURN_NONE; } static PyObject* renderTarget_SetShining(PyObject*, PyObject* args) { int idx = 0, pos = 0, item = 0; if (!PyArg_ParseTuple(args, "iii", &idx, &pos, &item)) return Py_BadArgument(); Py_RETURN_NONE; } static PyObject* renderTarget_Destroy(PyObject*, PyObject* args) { int idx = 0; if (PyTuple_Size(args) > 0 && PyArg_ParseTuple(args, "i", &idx)) { ava2::CRenderTargetManager::Instance().DestroyRenderTarget(idx); } else { PyErr_Clear(); for (int i = 0; i < 1000; ++i) { ava2::CRenderTargetManager::Instance().DestroyRenderTarget(i); } } Py_RETURN_NONE; } } // namespace void initRenderTarget() { static PyMethodDef methods[] = { {"SelectModel", renderTarget_SelectModel, METH_VARARGS, nullptr}, {"SetVisibility", renderTarget_SetVisibility, METH_VARARGS, nullptr}, {"SetBackground", renderTarget_SetBackground, METH_VARARGS, nullptr}, {"SetArmor", renderTarget_SetArmor, METH_VARARGS, nullptr}, {"SetWeapon", renderTarget_SetWeapon, METH_VARARGS, nullptr}, {"SetHair", renderTarget_SetHair, METH_VARARGS, nullptr}, {"SetRotation", renderTarget_SetRotation, METH_VARARGS, nullptr}, {"SetAcce", renderTarget_SetAcce, METH_VARARGS, nullptr}, {"SetMount", renderTarget_SetMount, METH_VARARGS, nullptr}, {"ResetModel", renderTarget_ResetModel, METH_VARARGS, nullptr}, {"Destroy", renderTarget_Destroy, METH_VARARGS, nullptr}, {"SetModelV3Eye", renderTarget_SetModelV3Eye, METH_VARARGS, nullptr}, {"SetModelV3Target", renderTarget_SetModelV3Target, METH_VARARGS, nullptr}, {"GetFreeIndex", renderTarget_GetFreeIndex, METH_VARARGS, nullptr}, {"SetModelRender", renderTarget_SetModelRender, METH_VARARGS, nullptr}, {"AddAffect", renderTarget_AddAffect, METH_VARARGS, nullptr}, {"RemoveAffect", renderTarget_RemoveAffect, METH_VARARGS, nullptr}, {"ClearAffect", renderTarget_ClearAffect, METH_VARARGS, nullptr}, {"IsShow", renderTarget_IsShow, METH_VARARGS, nullptr}, {"Zoom", renderTarget_Zoom, METH_VARARGS, nullptr}, {"SetScale", renderTarget_SetScale, METH_VARARGS, nullptr}, {"RotateEyeAroundTarget", renderTarget_RotateEyeAroundTarget, METH_VARARGS, nullptr}, {"SetMotionIndex", renderTarget_SetMotionIndex, METH_VARARGS, nullptr}, {"SetShining", renderTarget_SetShining, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("renderTarget", methods); } void initudp() { static PyMethodDef methods[] = { {nullptr, nullptr, 0, nullptr} }; auto* module = Py_InitModule("udp", methods); } static PyObject* importMgrGetModule(PyObject*, PyObject* args) { char* name = nullptr; if (!PyTuple_GetString(args, 0, &name)) return Py_BuildException(); return Py_BuildValue("s", name); } void initModuleNameManager() { static PyMethodDef s_methods[] = { {"getModule", importMgrGetModule, METH_VARARGS, nullptr}, {nullptr, nullptr, 0, nullptr} }; Py_InitModule("impMgr", s_methods); } } // namespace ava2