Skip to content

Commit

Permalink
Fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Jul 30, 2024
2 parents a7e1d4a + c8ac3a8 commit ebb0ce6
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 224 deletions.
54 changes: 27 additions & 27 deletions Source/FileFormat/FileFormat/Novus/ClientDB/ClientDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ namespace ClientDB
for (void* row : _rows)
{
if (row)
delete row;
}
}
delete row;
}
}

void Each(std::function<void(const Storage<T>* storage, const T*)> func)
void Each(std::function<void(const Storage<T>* storage, const T*)> func) const
{
for (T* row : _rows)
{
Expand Down Expand Up @@ -95,10 +95,10 @@ namespace ClientDB
{
u32 maxID = _minID + Count();
if (id < _minID || id > maxID)
return nullptr;
return nullptr;

return _rows[id - _minID];
}
return _rows[id - _minID];
}
bool HasRow(u32 id)
{
const T* row = GetRow(id);
Expand Down Expand Up @@ -135,8 +135,8 @@ namespace ClientDB
memset(_rows.data(), 0, sizeof(T*) * numNewRows);

_minID = newMinID;
}
}
}
}

bool hasRowAtID = _rows[row.id - _minID] != nullptr;
_numRows += 1 * !hasRowAtID;
Expand Down Expand Up @@ -182,7 +182,7 @@ namespace ClientDB
u32 numRows = static_cast<u32>(_rows.size());
return numRows;
}
u32 GetNumRows()
u32 GetNumRows() const
{
return _numRows;
}
Expand Down Expand Up @@ -221,16 +221,16 @@ namespace ClientDB
if (header.version != CURRENT_VERSION)
{
NC_LOG_ERROR("ClientDB::Storage::Read('{0}') - Version mismatch. Got: {1}, Expected: {2}", _name, header.version, CURRENT_VERSION);
return false;
}
return false;
}

u32 maxID = 0;

if (!buffer->GetU32(_minID))
return false;
if (!buffer->GetU32(_minID))
return false;

if (!buffer->GetU32(maxID))
return false;
if (!buffer->GetU32(maxID))
return false;

u32 numRows = maxID - _minID + 1;
_rows.resize(numRows);
Expand All @@ -241,16 +241,16 @@ namespace ClientDB

while (buffer->GetActiveSize() > 0)
{
T* row = new T();
T* row = new T();
if (!row->Read(buffer, stringTable))
{
delete row;
return false;
}
delete row;
return false;
}

if (row->id < _minID || row->id > maxID)
{
NC_LOG_ERROR("ClientDB::Storage::Read('{0}') - Row ID out of bounds. Got: {1} (Min: {2}, Max: {3})", _name, row->id, _minID, maxID);
NC_LOG_ERROR("ClientDB::Storage::Read('{0}') - Row ID out of bounds. Got: {1} (Min: {2}, Max: {3})", _name, row->id, _minID, maxID);

delete row;
continue;
Expand All @@ -260,10 +260,10 @@ namespace ClientDB
_numRows += 1 * !hasRowAtID;

_rows[row->id - _minID] = row;
}
}

return true;
}
return true;
}

bool Write(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable)
{
Expand Down Expand Up @@ -301,9 +301,9 @@ namespace ClientDB
if (!row)
continue;

if (!row->Write(buffer, stringTable))
return false;
}
if (!row->Write(buffer, stringTable))
return false;
}

return true;
}
Expand Down
150 changes: 150 additions & 0 deletions Source/FileFormat/FileFormat/Novus/ClientDB/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Base/Types.h>
#include <Base/Container/StringTable.h>
#include <Base/Math/Color.h>
#include <Base/Math/Geometry.h>
#include <Base/Memory/Bytebuffer.h>

Expand Down Expand Up @@ -770,6 +771,155 @@ namespace ClientDB::Definitions
}
};

struct Light : public Base
{
public:
u16 mapID;
vec3 position;
vec2 fallOff;
u16 lightParamsID[8];

public:
bool Read(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable) override
{
if (!buffer->Get(*this))
return false;

return true;
}
bool Write(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable) override
{
if (!buffer->Put(*this))
return false;

return true;
}
bool WriteStringTable(Novus::Container::StringTableUnsafe& stringTable) override
{
return true;
}
};

struct LightParam : public Base
{
public:
struct Flags
{
u8 highlightSky : 1 = 0;
u8 : 7;
};

public:
Flags flags;
u16 lightSkyboxID;
f32 glow;
f32 waterShallowAlpha;
f32 waterDeepAlpha;
f32 oceanShallowAlpha;
f32 oceanDeepAlpha;

public:
bool Read(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable) override
{
if (!buffer->Get(*this))
return false;

return true;
}
bool Write(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable) override
{
if (!buffer->Put(*this))
return false;

return true;
}
bool WriteStringTable(Novus::Container::StringTableUnsafe& stringTable) override
{
return true;
}
};

struct LightData : public Base
{
public:
u16 lightParamID;
u32 timestamp;
u32 diffuseColor;
u32 ambientColor;
u32 skyTopColor;
u32 skyMiddleColor;
u32 skyBand1Color;
u32 skyBand2Color;
u32 skySmogColor;
u32 skyFogColor;
u32 sunColor;
u32 sunFogColor;
f32 sunFogStrength;
u32 cloudSunColor;
u32 cloudEmissiveColor;
u32 cloudLayer1AmbientColor;
u32 cloudLayer2AmbientColor;
u32 oceanShallowColor;
u32 oceanDeepColor;
u32 riverShallowColor;
u32 riverDeepColor;
u32 shadowColor;
f32 fogEnd;
f32 fogScaler;
f32 fogDensity;
f32 sunFogAngle;
f32 cloudDensity;
u32 fogHeightColor;
u32 endFogColor;
u32 endFogHeightColor;

public:
bool Read(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable) override
{
if (!buffer->Get(*this))
return false;

return true;
}
bool Write(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable) override
{
if (!buffer->Put(*this))
return false;

return true;
}
bool WriteStringTable(Novus::Container::StringTableUnsafe& stringTable) override
{
return true;
}
};

struct LightSkybox : public Base
{
public:
u32 modelHash;

public:
bool Read(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable) override
{
if (!buffer->Get(*this))
return false;

return true;
}
bool Write(std::shared_ptr<Bytebuffer>& buffer, const Novus::Container::StringTableUnsafe& stringTable) override
{
if (!buffer->Put(*this))
return false;

return true;
}
bool WriteStringTable(Novus::Container::StringTableUnsafe& stringTable) override
{
return true;
}
};

// Custom
struct CameraSave : public Base
{
Expand Down
2 changes: 1 addition & 1 deletion Source/FileFormat/FileFormat/Warcraft/Parsers/Wdc3Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace DB2::WDC3
unpackedBits = *reinterpret_cast<u32*>(&unpackedBitsSigned);
}

T result = static_cast<T>(unpackedBits);
T result = *reinterpret_cast<T*>(&unpackedBits);
return result;
}

Expand Down
18 changes: 18 additions & 0 deletions Source/Gameplay/Gameplay.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local mod = Solution.Util.CreateModuleTable("Gameplay", { "base", "network" })

Solution.Util.CreateStaticLib(mod.Name, Solution.Projects.Current.BinDir, mod.Dependencies, function()
local defines = { "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS", "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS" }

Solution.Util.SetLanguage("C++")
Solution.Util.SetCppDialect(20)

local files = Solution.Util.GetFilesForCpp(mod.Path)
Solution.Util.SetFiles(files)
Solution.Util.SetIncludes(mod.Path)
Solution.Util.SetDefines(defines)
end)

Solution.Util.CreateDep(mod.NameLow, mod.Dependencies, function()
Solution.Util.SetIncludes(mod.Path)
Solution.Util.SetLinks(mod.Name)
end)
Empty file.
10 changes: 10 additions & 0 deletions Source/Gameplay/Gameplay/Network/Define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Base/Types.h"

namespace Network
{
enum class ConnectionStatus : u8
{
None,
Connected
};
}
33 changes: 33 additions & 0 deletions Source/Gameplay/Gameplay/Network/GameMessageRouter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "GameMessageRouter.h"

#include "Base/Memory/Bytebuffer.h"

namespace Network
{
GameMessageRouter::GameMessageRouter() { }

void GameMessageRouter::SetMessageHandler(GameOpcode opcode, GameMessageHandler&& handler)
{
_handlers[static_cast<u16>(opcode)] = std::move(handler);
}

bool GameMessageRouter::CallHandler(SocketID socketID, std::shared_ptr<Bytebuffer>& packet)
{
Network::PacketHeader header;
if (!packet->Get(header))
return false;

GameOpcode opcode = static_cast<GameOpcode>(header.opcode);
if (opcode == GameOpcode::Invalid || opcode >= GameOpcode::Count)
return false;

const GameMessageHandler& opcodeHandler = _handlers[static_cast<u16>(header.opcode)];
bool isSmallerThanMinSize = header.size < opcodeHandler.minSize;
bool isLargerThanMaxSize = header.size > opcodeHandler.maxSize && opcodeHandler.maxSize != -1;

if (!opcodeHandler.handler || isSmallerThanMinSize || isLargerThanMaxSize)
return false;

return opcodeHandler.handler(socketID, packet);
}
}
Loading

0 comments on commit ebb0ce6

Please sign in to comment.