Skip to content

Commit

Permalink
Minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyPL committed Oct 9, 2024
1 parent 057e0d2 commit 7b8881b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion payload/import/mkw/net/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class NetController
case JoinType::WorldwideBattle:
case JoinType::FriendWorldwideVersusRace:
case JoinType::FriendWorldwideBattle: {
return true;
return false;
}
case JoinType::ContinentalVersusRace:
case JoinType::ContinentalBattle:
Expand Down
33 changes: 25 additions & 8 deletions payload/wwfcSecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#include "import/mkw/net/selectHandler.hpp"
#include "import/mkw/net/userHandler.hpp"
#include "import/mkw/registry.hpp"
#include "import/mkw/system/raceConfig.hpp"
#include "import/mkw/system/system.hpp"
#include "wwfcLog.hpp"
#include "wwfcPatch.hpp"

namespace wwfc::Security
Expand Down Expand Up @@ -238,7 +236,6 @@ static bool IsHeaderPacketDataValid(
const void* /* packet */, u8 /* packetSize */, u8 /* playerAid */
)
{
// This packet is validated by the function 'IsRacePacketValid'
return true;
}

Expand All @@ -253,6 +250,10 @@ static bool IsMatchHeaderPacketDataValid(
const MatchHeaderHandler::Packet* matchHeaderPacket =
reinterpret_cast<const MatchHeaderHandler::Packet*>(packet);

if (!NetController::Instance()->inVanillaRaceScene()) {
return true;
}

RaceConfig::Scenario* scenario = &RaceConfig::Instance()->raceScenario();

for (size_t n = 0;
Expand Down Expand Up @@ -281,6 +282,21 @@ static bool IsMatchHeaderPacketDataValid(
}
}

MatchHeaderHandler::Packet::Course currentCourse =
matchHeaderPacket->course;
if (currentCourse != MatchHeaderHandler::Packet::Course::None) {
Course course = static_cast<Course>(currentCourse);
if (scenario->isOnlineVersusRace()) {
if (!IsRaceCourse(course)) {
return false;
}
} else /* if (scenario->isOnlineBattle()) */ {
if (!IsBattleCourse(course)) {
return false;
}
}
}

return true;
}

Expand Down Expand Up @@ -479,8 +495,9 @@ IsItemPacketDataValid(const void* packet, u8 packetSize, u8 /* playerAid */)
return true;
}

static bool
IsEventPacketDataValid(const void* packet, u8 packetSize, u8 playerAid)
static bool IsEventPacketDataValid(
const void* packet, u8 packetSize, u8 /* playerAid */
)
{
using namespace mkw::System;

Expand All @@ -496,15 +513,15 @@ IsEventPacketDataValid(const void* packet, u8 packetSize, u8 playerAid)
// Always ensure that the packet does not contain any invalid item
// objects, as this can cause a buffer overflow to occur.
if (eventPacket->containsInvalidItemObject()) {
return false;
return true;
}

if (!NetController::Instance()->inVanillaMatch()) {
return true;
}

if (!eventPacket->isValid(packetSize, playerAid)) {
return false;
if (!eventPacket->isValid(packetSize)) {
return true;
}

return true;
Expand Down

0 comments on commit 7b8881b

Please sign in to comment.