General AMF cleanup (#663)

* General AMF cleanup

Proper memory management as well as style cleanup

* General optimizations

Fix AMFArray so values are properly deleted when you leave the scope it was created in.
Add bounds check for deletion so you don't double delete.
Remove all AMFdeletions that are contained in an array since the array now manages its own memory and deletes it when it is no longer needed.

* Better tests and fix de-serialize

Fix de-serialize to be correct and implement a test to check this

* Update AMFDeserializeTests.cpp

* Update AMFFormat.cpp
This commit is contained in:
David Markowitz
2022-07-21 22:26:09 -07:00
committed by GitHub
parent 5523b6aafc
commit 6a38b67ed5
16 changed files with 303 additions and 389 deletions

View File

@@ -9,8 +9,6 @@ void BankInteractServer::OnUse(Entity* self, Entity* user)
args.InsertValue("state", bank);
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", &args);
delete bank;
}
void BankInteractServer::OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1,
@@ -19,13 +17,10 @@ void BankInteractServer::OnFireEventServerSide(Entity *self, Entity *sender, std
if (args == "ToggleBank")
{
AMFArrayValue args;
AMFFalseValue* amfFalse = new AMFFalseValue();
args.InsertValue("visible", amfFalse);
args.InsertValue("visible", new AMFFalseValue());
GameMessages::SendUIMessageServerToSingleClient(sender, sender->GetSystemAddress(), "ToggleBank", &args);
delete amfFalse;
GameMessages::SendNotifyClientObject(self->GetObjectID(), u"CloseBank", 0, 0, LWOOBJID_EMPTY, "", sender->GetSystemAddress());
}
}

View File

@@ -8,5 +8,4 @@ void MailBoxServer::OnUse(Entity* self, Entity* user) {
AMFArrayValue args;
args.InsertValue("state", value);
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", &args);
delete value;
}

View File

@@ -13,21 +13,6 @@ void NsLegoClubDoor::OnStartup(Entity* self)
args = {};
/**
{ {0,{
{"image", "textures/ui/zone_thumnails/Nimbus_Station.dds"},
{"caption", "%[UI_CHOICE_NS]"}, -- "%[LOC_STRING]" is the format for sending localization tokens to the choice box
{"identifier", "zoneID_1200"},
{"tooltipText", "%[UI_CHOICE_NS_HOVER]"}
}},
{1,{
{"image", "textures/ui/zone_thumnails/Nexus_Tower.dds"},
{"caption", "%[UI_CHOICE_NT]"},
{"identifier", "zoneID_1900"},
{"tooltipText", "%[UI_CHOICE_NT_HOVER]"}
} } }
*/
AMFStringValue* callbackClient = new AMFStringValue();
callbackClient->SetStringValue(std::to_string(self->GetObjectID()));
args.InsertValue("callbackClient", callbackClient);
@@ -97,12 +82,6 @@ void NsLegoClubDoor::OnUse(Entity* self, Entity* user)
if (CheckChoice(self, player))
{
/**
{ {"callbackClient", self},
{"strIdentifier", "choiceDoor"},
{"title", "%[UI_CHOICE_DESTINATION]"},
{"options", choiceOptions} }
*/
AMFArrayValue* multiArgs = new AMFArrayValue();
AMFStringValue* callbackClient = new AMFStringValue();
@@ -120,19 +99,9 @@ void NsLegoClubDoor::OnUse(Entity* self, Entity* user)
multiArgs->InsertValue("options", options);
GameMessages::SendUIMessageServerToSingleClient(player, player->GetSystemAddress(), "QueueChoiceBox", multiArgs);
delete multiArgs;
delete callbackClient;
delete strIdentifier;
delete title;
}
else if (self->GetVar<int32_t>(u"currentZone") != m_ChoiceZoneID)
{
/**
{ {"state", "Lobby"},
{"context", {{"user", msg.user}, {"callbackObj", self},
{"HelpVisible", "show" }, {"type", "Lego_Club_Valid"}} }}
*/
AMFArrayValue* multiArgs = new AMFArrayValue();
AMFStringValue* state = new AMFStringValue();
@@ -160,14 +129,6 @@ void NsLegoClubDoor::OnUse(Entity* self, Entity* user)
multiArgs->InsertValue("context", context);
GameMessages::SendUIMessageServerToSingleClient(player, player->GetSystemAddress(), "pushGameState", multiArgs);
delete multiArgs;
delete state;
delete context;
delete user;
delete callbackObj;
delete helpVisible;
delete type;
}
else
{

View File

@@ -24,7 +24,6 @@ void PropertyBankInteract::OnUse(Entity *self, Entity *user) {
args.InsertValue("state", value);
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", &args);
delete value;
GameMessages::SendNotifyClientObject(self->GetObjectID(), u"OpenBank", 0, 0, LWOOBJID_EMPTY,
"", user->GetSystemAddress());
@@ -34,13 +33,10 @@ void PropertyBankInteract::OnFireEventServerSide(Entity *self, Entity *sender, s
int32_t param2, int32_t param3) {
if (args == "ToggleBank") {
AMFArrayValue amfArgs;
auto* amfFalse = new AMFFalseValue();
amfArgs.InsertValue("visible", amfFalse);
amfArgs.InsertValue("visible", new AMFFalseValue());
GameMessages::SendUIMessageServerToSingleClient(sender, sender->GetSystemAddress(), "ToggleBank", &amfArgs);
delete amfFalse;
GameMessages::SendNotifyClientObject(self->GetObjectID(), u"CloseBank", 0, 0, LWOOBJID_EMPTY,
"", sender->GetSystemAddress());
}

View File

@@ -18,24 +18,18 @@ void StoryBoxInteractServer::OnUse(Entity* self, Entity* user) {
args.InsertValue("state", state);
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "pushGameState", &args);
delete state;
}
user->AddCallbackTimer(0.1f, [user, customText] () {
AMFArrayValue args;
auto* visiable = new AMFTrueValue();
auto* text = new AMFStringValue();
text->SetStringValue(customText);
args.InsertValue("visible", visiable);
args.InsertValue("visible", new AMFTrueValue());
args.InsertValue("text", text);
GameMessages::SendUIMessageServerToSingleClient(user, user->GetSystemAddress(), "ToggleStoryBox", &args);
delete visiable;
delete text;
});
return;