From 50da7029695295e171693dcf91295c2aa632a600 Mon Sep 17 00:00:00 2001 From: anatoliy_savchak Date: Sat, 4 Jul 2020 23:18:37 +0300 Subject: [PATCH] dispatch_stat and create_history_dc_roll New Python API: * tpdp.dispatch_stat * tpdp.create_history_dc_roll --- TemplePlus/bonus.cpp | 11 +++++++++++ TemplePlus/bonus.h | 2 ++ TemplePlus/python/python_dispatcher.cpp | 19 ++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/TemplePlus/bonus.cpp b/TemplePlus/bonus.cpp index 4f9d92077..5e4e6165c 100644 --- a/TemplePlus/bonus.cpp +++ b/TemplePlus/bonus.cpp @@ -3,6 +3,7 @@ #include "bonus.h" #include "tig/tig_mes.h" #include "util/fixes.h" +#include int(__cdecl *OrgBonusInit)(); @@ -195,6 +196,16 @@ uint32_t BonusSystem::bonusSetOverallCap(uint32_t bonFlags, BonusList* bonList, return bonList->SetOverallCap(bonFlags, newCap, newCapType, bonMesLineNum, capDescr); } +char* BonusSystem::CacheCustomText(std::string& text) +{ + auto textId = ElfHash::Hash(text); + auto textCache = customBonusStrings.find(textId); + if (textCache == customBonusStrings.end()) { + bonusSys.customBonusStrings[textId] = text; + } + return (char*)customBonusStrings[textId].c_str(); +} + BonusSystem::BonusSystem() { rebase(_bonusPrintString,0x100E6740); diff --git a/TemplePlus/bonus.h b/TemplePlus/bonus.h index e72ff10f8..f9511bbc5 100644 --- a/TemplePlus/bonus.h +++ b/TemplePlus/bonus.h @@ -24,6 +24,8 @@ struct BonusSystem : temple::AddressTable void (__cdecl *_bonusPrintString)(BonusList *bonlist, uint32_t bonIdx, int32_t *bonValueOut, char *strBonusOut, char *strCapOut); int32_t(__cdecl * _getOverallBonus)(BonusList* bonList); + char* CacheCustomText(std::string& text); + MesHandle * bonusMesHandle; //102E45A8 MesHandle bonusMesNew; BonusSystem(); diff --git a/TemplePlus/python/python_dispatcher.cpp b/TemplePlus/python/python_dispatcher.cpp index 0e8fbbc6a..3eb757e48 100644 --- a/TemplePlus/python/python_dispatcher.cpp +++ b/TemplePlus/python/python_dispatcher.cpp @@ -31,6 +31,7 @@ #include "rng.h" #include "float_line.h" #include "history.h" +#include "bonus.h" namespace py = pybind11; @@ -165,6 +166,15 @@ PYBIND11_EMBEDDED_MODULE(tpdp, m) { return skillLevel; }); + m.def("dispatch_stat", [](objHndl obj, uint32_t stat, BonusList& bonList)-> int { + DispIoBonusList evtObjAbScore; + evtObjAbScore.flags |= 1; // effect unknown?? + evtObjAbScore.bonlist = bonList; + auto result = dispatch.Dispatch10AbilityScoreLevelGet(obj, (Stat)stat, &evtObjAbScore); + bonList = evtObjAbScore.bonlist; + return result; + }); + m.def("create_history_type6_opposed_check", [](objHndl performer, objHndl defender, int performerRoll, int defenderRoll , BonusList& performerBonList, BonusList& defenderBonList, uint32_t combatMesLineTitle, uint32_t combatMesLineResult, uint32_t flag)-> int { @@ -173,7 +183,14 @@ PYBIND11_EMBEDDED_MODULE(tpdp, m) { return rollHistId; }); - #pragma region Basic Dispatcher stuff + m.def("create_history_dc_roll", [](objHndl performer, int dc, Dice& dice, int roll, std::string& text, BonusList& bonlist)-> int + { + auto ptext = bonusSys.CacheCustomText(text); + auto rollHistId = histSys.RollHistoryType4Add(performer, dc, ptext, dice.ToPacked(), roll, (BonusList*)&bonlist); + return rollHistId; + }); + +#pragma region Basic Dispatcher stuff py::class_(m, "ModifierSpec") .def(py::init())