Skip to content

Commit

Permalink
Add Ext.ExtraData and NRD_StatGetExtraData
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbyte committed Dec 30, 2019
1 parent 0e7adfb commit 946c992
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 3 deletions.
5 changes: 5 additions & 0 deletions APIDocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ If the stat entry does not exist, the stat entry doesn't have an attribute named
Returns the type of the specified stat entry. If the stat entry does not exist, the query fails.
Possible return values: `Character`, `Potion`, `Armor`, `Object`, `Shield`, `Weapon`, `SkillData`, `StatusData`.
### StatGetExtraData
`query NRD_StatGetExtraData([in](STRING)_Key, [out](REAL)_Value)`
Returns the specified key from `Data.txt`. If the key does not exist, the query fails.
# Status functions
Expand Down
30 changes: 30 additions & 0 deletions OsiInterface/Functions/StatFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ namespace osidbg
args[1].String = typeInfo->Name.Str;
return true;
}

bool StatGetExtraData(OsiArgumentDesc & args)
{
auto key = args[0].String;
auto & value = args[1].Float;

auto stats = gOsirisProxy->GetLibraryManager().GetStats();
if (stats == nullptr || stats->ExtraData == nullptr) {
OsiError("RPGStats not available");
return false;
}

auto extraData = stats->ExtraData->Properties.Find(key);
if (extraData != nullptr) {
value = *extraData;
return true;
} else {
return false;
}
}
}

void CustomFunctionLibrary::RegisterStatFunctions()
Expand Down Expand Up @@ -170,6 +190,16 @@ namespace osidbg
&func::StatGetType
);
functionMgr.Register(std::move(getStatType));

auto getExtraData = std::make_unique<CustomQuery>(
"NRD_StatGetExtraData",
std::vector<CustomFunctionParam>{
{ "Key", ValueType::String, FunctionArgumentDirection::In },
{ "Value", ValueType::Real, FunctionArgumentDirection::Out },
},
&func::StatGetExtraData
);
functionMgr.Register(std::move(getExtraData));
}

}
82 changes: 79 additions & 3 deletions OsiInterface/GameDefinitions/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,51 @@ namespace osidbg
CRPGStats_Modifier * GetAttributeInfo(const char * name, int * attributeIndex) const;
};

struct CRPGStats_ExtraData
{
FixedStringMapBase<float> Properties;
};

struct CRPGStats_Object_Property
{
void * VMT;
FixedString SomeHashedText;
};

struct CDivinityStats_Object_Property_Data : public CRPGStats_Object_Property
{
uint32_t Unkn;
uint8_t PropertyContext;
uint8_t _Pad1[3];
void * ConditionBlockPtr;
};

struct CRPGStats_Object_Property_List
{
CNamedElementManager<CRPGStats_Object_Property> Properties;
FixedString FS1;
uint8_t Unknown;
uint8_t _Pad[7];
};

struct CDivinityStats_Condition
{
void * ScriptCheckBlock;
FixedString Id;
};

struct CRPGStats_Conditions_Manager
{
FixedStringMapBase<CDivinityStats_Condition *> Conditions;
uint8_t _Pad1[4];
ObjectSet<STDString> Strs;
};

struct CRPGStats_ItemType_Manager : public CNamedElementManager<uint64_t>
{
uint64_t Unknown;
};

struct CRPGStatsManager
{
CNamedElementManager<RPGEnumeration> modifierValueList;
Expand All @@ -484,11 +529,42 @@ namespace osidbg
CNamedElementManager<uint64_t> deltaMods;
CNamedElementManager<uint64_t> treasureSubtables;
CNamedElementManager<uint64_t> treasureTables;
CNamedElementManager<uint64_t> itemTypes;
uint64_t unknown[46];
CRPGStats_ItemType_Manager itemTypes;
FixedStringMapBase<CRPGStats_Object_Property_List> PropertyLists;
uint8_t _Pad1[4];
CRPGStats_Conditions_Manager ConditionsManager;
STDWString WStr1;
uint64_t Unkn1[5];
CRPGStats_ExtraData * ExtraData;
FixedStringRefMap<void *> RefMap1;
FixedStringRefMap<void *> RefMap2;
FixedStringMapBase<FixedString> FSMap1;
uint8_t _Pad2[4];
FixedStringMapBase<int> FSMapInt1;
uint8_t _Pad3[4];
FixedStringMapBase<int> FSMapInt2;
uint8_t _Pad4[4];
FixedStringMapBase<int> FSMapInt3;
uint8_t _Pad5[4];
FixedStringMapBase<void *> FSMap2;
uint64_t Unkn2[7];
ObjectSet<FixedString> ModifierFSSet;
ObjectSet<uint64_t> AttributeFlags;
uint64_t unknown2[165];
uint64_t unknown2[140];
void * EquipmentSetManager;
void * SkillSetManager;
uint64_t Unkn3;
void * ItemCombinationManager;
uint64_t Unkn4;
FixedString FS1;
FixedStringMapBase<uint64_t> FSMapUInt64;
uint8_t _Pad6[4];
uint64_t Unkn5;
PrimitiveSet<void *> DataBufferSet;
uint64_t Unkn6;
void * DivinityStats;
void * CritSection;
uint64_t Unkn7[5];

ModifierList * GetTypeInfo(CRPGStats_Object * object);
RPGEnumeration * GetAttributeInfo(CRPGStats_Object * object, const char * attributeName, int & attributeIndex);
Expand Down
27 changes: 27 additions & 0 deletions OsiInterface/Lua/LuaBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ namespace osidbg
}



char const * const LuaStatsExtraDataProxy::MetatableName = "LuaStatsExtraDataProxy";

int LuaStatsExtraDataProxy::LuaIndex(lua_State * L)
{
auto stats = gOsirisProxy->GetLibraryManager().GetStats();
if (stats == nullptr || stats->ExtraData == nullptr) return luaL_error(L, "Stats not available");

auto key = luaL_checkstring(L, 2);
auto extraData = stats->ExtraData->Properties.Find(key);
if (extraData != nullptr) {
lua_pushnumber(L, *extraData);
return 1;
} else {
return 0;
}
}


LuaExtensionLibrary::LuaExtensionLibrary()
{
}
Expand All @@ -252,6 +271,7 @@ namespace osidbg
LuaHandleProxy<esv::Item>::RegisterMetatable(L);
LuaStatusHandleProxy::RegisterMetatable(L);
LuaHandleProxy<CDivinityStats_Character>::RegisterMetatable(L);
LuaStatsExtraDataProxy::RegisterMetatable(L);
RegisterNameResolverMetatable(L);
CreateNameResolver(L);
}
Expand Down Expand Up @@ -412,6 +432,13 @@ math.randomseed = function ()
end
)";
LoadScript(sandbox, "sandbox");

auto L = state_;
lua_getglobal(L, "Ext"); // stack: Ext
lua_pushstring(L, "ExtraData"); // stack: Ext, "ExtraData"
LuaStatsExtraDataProxy::New(L); // stack: Ext, "ExtraData", ExtraDataProxy
lua_settable(L, -3); // stack: Ext
lua_pop(L, 1); // stack: -
}

LuaState::~LuaState()
Expand Down
8 changes: 8 additions & 0 deletions OsiInterface/Lua/LuaBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ namespace osidbg
ObjectHandle status_;
};

class LuaStatsExtraDataProxy : public LuaUserdata<LuaStatsExtraDataProxy>, public LuaIndexable
{
public:
static char const * const MetatableName;

int LuaIndex(lua_State * L);
};


class LuaExtensionLibrary
{
Expand Down

0 comments on commit 946c992

Please sign in to comment.