[General] Modernize handling of client script local variables in packets

Disable placeholder handling of client script member variables.
pull/593/head
David Cernat 5 years ago
parent 3e95034b57
commit 5e6218ad6d

@ -213,6 +213,7 @@ public:
{"OnWorldKillCount", Callback<unsigned short>()},
{"OnWorldMap", Callback<unsigned short>()},
{"OnWorldWeather", Callback<unsigned short>()},
{"OnClientScriptLocal", Callback<unsigned short, const char*>()},
{"OnClientScriptGlobal", Callback<unsigned short>()},
{"OnMpNumIncrement", Callback<int>()},
{"OnRequestDataFileList", Callback<>()},

@ -12,6 +12,13 @@ namespace mwmp
{
BPP_INIT(ID_CLIENT_SCRIPT_LOCAL)
}
void Do(ObjectPacket& packet, Player& player, BaseObjectList& objectList) override
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str());
Script::Call<Script::CallbackIdentity("OnClientScriptLocal")>(player.getId(), objectList.cell.getDescription().c_str());
}
};
}

@ -959,22 +959,7 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore)
{
for (const auto &baseObject : baseObjects)
{
std::string valueAsString;
std::string variableTypeAsString;
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT || baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG)
{
variableTypeAsString = baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT ? "short" : "long";
valueAsString = std::to_string(baseObject.clientVariable.intValue);
}
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{
variableTypeAsString = "float";
valueAsString = std::to_string(baseObject.clientVariable.floatValue);
}
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i, index: %i, type %s, value: %s", baseObject.refId.c_str(),
baseObject.refNum, baseObject.mpNum, baseObject.index, variableTypeAsString.c_str(), valueAsString.c_str());
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
MWWorld::Ptr ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum);
@ -983,18 +968,36 @@ void ObjectList::setClientLocals(MWWorld::CellStore* cellStore)
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Found %s %i-%i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT)
ptrFound.getRefData().getLocals().mShorts.at(baseObject.index) = baseObject.clientVariable.intValue;
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG)
ptrFound.getRefData().getLocals().mLongs.at(baseObject.index) = baseObject.clientVariable.intValue;
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
ptrFound.getRefData().getLocals().mFloats.at(baseObject.index) = baseObject.clientVariable.floatValue;
for (const auto& clientLocal : baseObject.clientLocals)
{
std::string valueAsString;
std::string variableTypeAsString;
if (clientLocal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientLocal.variableType == mwmp::VARIABLE_TYPE::LONG)
{
variableTypeAsString = clientLocal.variableType == mwmp::VARIABLE_TYPE::SHORT ? "short" : "long";
valueAsString = std::to_string(clientLocal.intValue);
}
else if (clientLocal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{
variableTypeAsString = "float";
valueAsString = std::to_string(clientLocal.floatValue);
}
if (clientLocal.variableType == mwmp::VARIABLE_TYPE::SHORT)
ptrFound.getRefData().getLocals().mShorts.at(clientLocal.internalIndex) = clientLocal.intValue;
else if (clientLocal.variableType == mwmp::VARIABLE_TYPE::LONG)
ptrFound.getRefData().getLocals().mLongs.at(clientLocal.internalIndex) = clientLocal.intValue;
else if (clientLocal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
ptrFound.getRefData().getLocals().mFloats.at(clientLocal.internalIndex) = clientLocal.floatValue;
}
}
}
}
void ObjectList::setMemberShorts()
{
/*
for (const auto &baseObject : baseObjects)
{
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s, index: %i, shortVal: %i", baseObject.refId.c_str(),
@ -1016,6 +1019,7 @@ void ObjectList::setMemberShorts()
ptrFound.getRefData().getLocals().mShorts.at(baseObject.index) = baseObject.shortVal;;
}
}
*/
}
void ObjectList::playMusic()
@ -1283,35 +1287,41 @@ void ObjectList::addVideoPlay(std::string filename, bool allowSkipping)
addBaseObject(baseObject);
}
void ObjectList::addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value, mwmp::VARIABLE_TYPE variableType)
void ObjectList::addClientScriptLocal(const MWWorld::Ptr& ptr, int internalIndex, int value, mwmp::VARIABLE_TYPE variableType)
{
cell = *ptr.getCell()->getCell();
mwmp::BaseObject baseObject = getBaseObjectFromPtr(ptr);
baseObject.clientVariable.index = index;
baseObject.clientVariable.variableType = variableType;
baseObject.clientVariable.intValue = value;
ClientVariable clientLocal;
clientLocal.internalIndex = internalIndex;
clientLocal.variableType = variableType;
clientLocal.intValue = value;
baseObject.clientLocals.push_back(clientLocal);
addBaseObject(baseObject);
}
void ObjectList::addClientScriptLocal(const MWWorld::Ptr& ptr, int index, float value)
void ObjectList::addClientScriptLocal(const MWWorld::Ptr& ptr, int internalIndex, float value)
{
cell = *ptr.getCell()->getCell();
mwmp::BaseObject baseObject = getBaseObjectFromPtr(ptr);
baseObject.clientVariable.index = index;
baseObject.clientVariable.variableType = mwmp::VARIABLE_TYPE::FLOAT;
baseObject.clientVariable.floatValue = value;
ClientVariable clientLocal;
clientLocal.internalIndex = internalIndex;
clientLocal.variableType = mwmp::VARIABLE_TYPE::FLOAT;
clientLocal.floatValue = value;
baseObject.clientLocals.push_back(clientLocal);
addBaseObject(baseObject);
}
void ObjectList::addScriptMemberShort(std::string refId, int index, int shortVal)
{
/*
mwmp::BaseObject baseObject;
baseObject.refId = refId;
baseObject.index = index;
baseObject.shortVal = shortVal;
addBaseObject(baseObject);
*/
}
void ObjectList::sendObjectActivate()
@ -1438,22 +1448,26 @@ void ObjectList::sendClientScriptLocal()
for (const auto &baseObject : baseObjects)
{
std::string valueAsString;
std::string variableTypeAsString;
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT || baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG)
for (const auto& clientLocal : baseObject.clientLocals)
{
variableTypeAsString = baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT ? "short" : "long";
valueAsString = std::to_string(baseObject.clientVariable.intValue);
}
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{
variableTypeAsString = "float";
valueAsString = std::to_string(baseObject.clientVariable.floatValue);
}
std::string valueAsString;
std::string variableTypeAsString;
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i, index: %i, type %s, value: %s", baseObject.refId.c_str(),
baseObject.refNum, baseObject.mpNum, baseObject.clientVariable.index, variableTypeAsString.c_str(), valueAsString.c_str());
if (clientLocal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientLocal.variableType == mwmp::VARIABLE_TYPE::LONG)
{
variableTypeAsString = clientLocal.variableType == mwmp::VARIABLE_TYPE::SHORT ? "short" : "long";
valueAsString = std::to_string(clientLocal.intValue);
}
else if (clientLocal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
{
variableTypeAsString = "float";
valueAsString = std::to_string(clientLocal.floatValue);
}
LOG_APPEND(TimedLog::LOG_VERBOSE, "- type %s, value: %s", variableTypeAsString.c_str(), valueAsString.c_str());
}
}
mwmp::Main::get().getNetworking()->getObjectPacket(ID_CLIENT_SCRIPT_LOCAL)->setObjectList(this);
@ -1462,6 +1476,7 @@ void ObjectList::sendClientScriptLocal()
void ObjectList::sendScriptMemberShort()
{
/*
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Sending ID_SCRIPT_MEMBER_SHORT");
for (const auto &baseObject : baseObjects)
@ -1470,6 +1485,7 @@ void ObjectList::sendScriptMemberShort()
mwmp::Main::get().getNetworking()->getObjectPacket(ID_SCRIPT_MEMBER_SHORT)->setObjectList(this);
mwmp::Main::get().getNetworking()->getObjectPacket(ID_SCRIPT_MEMBER_SHORT)->Send();
*/
}
void ObjectList::sendContainer()

@ -70,8 +70,8 @@ namespace mwmp
void addDoorState(const MWWorld::Ptr& ptr, MWWorld::DoorState state);
void addMusicPlay(std::string filename);
void addVideoPlay(std::string filename, bool allowSkipping);
void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, int value, mwmp::VARIABLE_TYPE variableType);
void addClientScriptLocal(const MWWorld::Ptr& ptr, int index, float value);
void addClientScriptLocal(const MWWorld::Ptr& ptr, int internalIndex, int value, mwmp::VARIABLE_TYPE variableType);
void addClientScriptLocal(const MWWorld::Ptr& ptr, int internalIndex, float value);
void addScriptMemberShort(std::string refId, int index, int shortVal);
void sendObjectActivate();

@ -63,12 +63,6 @@ namespace mwmp
std::string animGroup;
int animMode;
ClientVariable clientVariable;
int index;
int shortVal;
float floatVal;
bool isDisarmed;
bool droppedByPlayer;
@ -84,6 +78,7 @@ namespace mwmp
bool hasContainer;
std::vector<ClientVariable> clientLocals;
std::vector<ContainerItem> containerItems;
unsigned int containerItemCount;

@ -30,7 +30,7 @@ namespace mwmp
struct ClientVariable
{
std::string id;
int index;
int internalIndex;
char variableType;

@ -12,11 +12,28 @@ PacketClientScriptLocal::PacketClientScriptLocal(RakNet::RakPeerInterface *peer)
void PacketClientScriptLocal::Object(BaseObject &baseObject, bool send)
{
ObjectPacket::Object(baseObject, send);
RW(baseObject.clientVariable.index, send);
RW(baseObject.clientVariable.variableType, send);
if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::SHORT || baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::LONG)
RW(baseObject.clientVariable.intValue, send);
else if (baseObject.clientVariable.variableType == mwmp::VARIABLE_TYPE::FLOAT)
RW(baseObject.clientVariable.floatValue, send);
uint32_t clientLocalsCount;
if (send)
clientLocalsCount = static_cast<uint32_t>(baseObject.clientLocals.size());
RW(clientLocalsCount, send);
if (!send)
{
baseObject.clientLocals.clear();
baseObject.clientLocals.resize(clientLocalsCount);
}
for (auto&& clientLocal : baseObject.clientLocals)
{
RW(clientLocal.internalIndex, send);
RW(clientLocal.variableType, send);
if (clientLocal.variableType == mwmp::VARIABLE_TYPE::SHORT || clientLocal.variableType == mwmp::VARIABLE_TYPE::LONG)
RW(clientLocal.intValue, send);
else if (clientLocal.variableType == mwmp::VARIABLE_TYPE::FLOAT)
RW(clientLocal.floatValue, send);
}
}

@ -10,7 +10,7 @@ PacketScriptMemberShort::PacketScriptMemberShort(RakNet::RakPeerInterface *peer)
void PacketScriptMemberShort::Object(BaseObject &baseObject, bool send)
{
RW(baseObject.refId, send);
RW(baseObject.index, send);
RW(baseObject.shortVal, send);
//RW(baseObject.refId, send);
//RW(baseObject.index, send);
//RW(baseObject.shortVal, send);
}

Loading…
Cancel
Save