Skip to content

Commit

Permalink
Merge branch 'main' into sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Zbizu authored Jan 26, 2025
2 parents 479d765 + 92d6605 commit 07cf903
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 84 deletions.
2 changes: 1 addition & 1 deletion modules/game_textmessage/textmessage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function displayMessage(mode, text)
if msgtype == MessageSettings.loot then
local coloredText = ItemsDatabase.setColorLootMessage(text)
label:setColoredText(coloredText)
local getTabServerLog = modules.game_console.consoleTabBar:getTabPanel(modules.game_console.getTab("Server Log"))
local getTabServerLog = modules.game_console.consoleTabBar:getTabPanel(modules.game_console.serverTab)
if getTabServerLog then
getTabServerLog:getChildById('consoleBuffer'):getLastChild():setColoredText(coloredText)
end
Expand Down
117 changes: 77 additions & 40 deletions src/client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@
#include <framework/graphics/graphics.h>
#include <framework/graphics/shadermanager.h>
#include <framework/platform/platformwindow.h>
#include <framework/core/asyncdispatcher.h>

#include <algorithm>

MapView::MapView() : m_lightView(std::make_unique<LightView>(Size())), m_pool(g_drawPool.get(DrawPoolType::MAP))
{
m_floors.resize(g_gameConfig.getMapMaxZ() + 1);
m_floorThreads.resize(g_asyncDispatcher.get_thread_count());
for (auto& thread : m_floorThreads)
thread.resize(m_floors.size());

setVisibleDimension(Size(15, 11));
}
Expand Down Expand Up @@ -292,21 +296,21 @@ void MapView::updateVisibleTiles()

m_lockedFirstVisibleFloor = m_floorViewMode == LOCKED ? m_posInfo.camera.z : -1;

const uint8_t prevFirstVisibleFloor = m_cachedFirstVisibleFloor;
const auto prevFirstVisibleFloor = m_cachedFirstVisibleFloor;

if (m_lastCameraPosition != m_posInfo.camera) {
if (m_lastCameraPosition.z != m_posInfo.camera.z) {
onFloorChange(m_posInfo.camera.z, m_lastCameraPosition.z);
}

const uint8_t cachedFirstVisibleFloor = calcFirstVisibleFloor(m_floorViewMode != ALWAYS);
const auto cachedFirstVisibleFloor = calcFirstVisibleFloor(m_floorViewMode != ALWAYS);
m_cachedFirstVisibleFloor = cachedFirstVisibleFloor;
m_cachedLastVisibleFloor = std::max<uint8_t>(cachedFirstVisibleFloor, calcLastVisibleFloor());

m_floorMin = m_floorMax = m_posInfo.camera.z;
}

uint8_t cachedFirstVisibleFloor = m_cachedFirstVisibleFloor;
auto cachedFirstVisibleFloor = m_cachedFirstVisibleFloor;
if (m_floorViewMode == ALWAYS_WITH_TRANSPARENCY || canFloorFade()) {
cachedFirstVisibleFloor = calcFirstVisibleFloor(false);
}
Expand Down Expand Up @@ -340,52 +344,82 @@ void MapView::updateVisibleTiles()
// cache visible tiles in draw order
// draw from last floor (the lower) to first floor (the higher)
const uint32_t numDiagonals = m_drawDimension.width() + m_drawDimension.height() - 1;
for (int_fast32_t iz = m_cachedLastVisibleFloor; iz >= cachedFirstVisibleFloor; --iz) {
auto& floor = m_floors[iz].cachedVisibleTiles;

// loop through / diagonals beginning at top left and going to top right
for (uint_fast32_t diagonal = 0; diagonal < numDiagonals; ++diagonal) {
// loop current diagonal tiles
const uint32_t advance = std::max<uint32_t >(diagonal - m_drawDimension.height(), 0);
for (int iy = diagonal - advance, ix = advance; iy >= 0 && ix < m_drawDimension.width(); --iy, ++ix) {
// position on current floor
//TODO: check position limits
Position tilePos = m_posInfo.camera.translated(ix - m_virtualCenterOffset.x, iy - m_virtualCenterOffset.y);
// adjust tilePos to the wanted floor
tilePos.coveredUp(m_posInfo.camera.z - iz);
if (const auto& tile = g_map.getTile(tilePos)) {
// skip tiles that have nothing
if (!tile->isDrawable())
continue;

bool addTile = true;

if (checkIsCovered) {
// skip tiles that are completely behind another tile
if (tile->isCompletelyCovered(m_cachedFirstVisibleFloor, m_resetCoveredCache)) {

auto processDiagonalRange = [&](std::vector<FloorData>& floors, uint32_t start, uint32_t end) {
for (int_fast32_t iz = m_cachedLastVisibleFloor; iz >= cachedFirstVisibleFloor; --iz) {
auto& floor = floors[iz].cachedVisibleTiles;

for (uint_fast32_t diagonal = start; diagonal < end; ++diagonal) {
const auto advance = (static_cast<size_t>(diagonal) >= m_drawDimension.height()) ? diagonal - m_drawDimension.height() : 0;

Check warning on line 353 in src/client/mapview.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

comparison of integer expressions of different signedness: ‘uint_fast32_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]

Check warning on line 353 in src/client/mapview.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

comparison of integer expressions of different signedness: ‘uint_fast32_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
for (int iy = diagonal - advance, ix = advance; iy >= 0 && ix < m_drawDimension.width(); --iy, ++ix) {
auto tilePos = m_posInfo.camera.translated(ix - m_virtualCenterOffset.x, iy - m_virtualCenterOffset.y);
tilePos.coveredUp(m_posInfo.camera.z - iz);

if (const auto& tile = g_map.getTile(tilePos)) {
if (!tile->isDrawable()) continue;

bool addTile = true;

if (checkIsCovered && tile->isCompletelyCovered(m_cachedFirstVisibleFloor, m_resetCoveredCache)) {
if (m_floorViewMode != ALWAYS_WITH_TRANSPARENCY || (tilePos.z < m_posInfo.camera.z && tile->isCovered(m_cachedFirstVisibleFloor))) {
addTile = false;
}
}
}

if (addTile) {
floor.tiles.emplace_back(tile);
tile->onAddInMapView();
}
if (addTile) {
floor.tiles.emplace_back(tile);
tile->onAddInMapView();
}

if (isDrawingLights() && tile->canShade())
floor.shades.emplace_back(tile);
if (isDrawingLights() && tile->canShade()) {
floor.shades.emplace_back(tile);
}

if (addTile || !floor.shades.empty()) {
if (iz < m_floorMin)
m_floorMin = iz;
else if (iz > m_floorMax)
m_floorMax = iz;
if (addTile || !floor.shades.empty()) {
if (iz < m_floorMin)
m_floorMin = iz;
else if (iz > m_floorMax)
m_floorMax = iz;
}
}
}
}
}
};

if (m_multithreading) {
static const int numThreads = g_asyncDispatcher.get_thread_count();
static BS::multi_future<void> tasks(numThreads);
tasks.clear();

const auto chunkSize = (numDiagonals + numThreads - 1) / numThreads;

for (auto i = 0; i < numThreads; ++i) {
const auto start = i * chunkSize;
const auto end = start + chunkSize;

for (auto& floor : m_floorThreads[i])
floor.cachedVisibleTiles.clear();

tasks.emplace_back(g_asyncDispatcher.submit_task([=, this] {
processDiagonalRange(m_floorThreads[i], start, end);
}));
}

tasks.wait();

for (auto fi = 0; fi < m_floors.size(); ++fi) {

Check warning on line 411 in src/client/mapview.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<MapView::FloorData>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]

Check warning on line 411 in src/client/mapview.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<MapView::FloorData>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
auto& floor = m_floors[fi];
floor.cachedVisibleTiles.clear();

for (auto i = 0; i < numThreads; ++i) {
auto& floorThread = m_floorThreads[i][fi];
floor.cachedVisibleTiles.tiles.insert(floor.cachedVisibleTiles.tiles.end(), std::make_move_iterator(floorThread.cachedVisibleTiles.tiles.begin()), std::make_move_iterator(floorThread.cachedVisibleTiles.tiles.end()));
floor.cachedVisibleTiles.shades.insert(floor.cachedVisibleTiles.tiles.end(), std::make_move_iterator(floorThread.cachedVisibleTiles.shades.begin()), std::make_move_iterator(floorThread.cachedVisibleTiles.shades.end()));
}
}
} else {
processDiagonalRange(m_floors, 0, numDiagonals);
}

m_updateVisibleTiles = false;
Expand Down Expand Up @@ -415,9 +449,12 @@ void MapView::updateGeometry(const Size& visibleDimension)
{
float scaleFactor = m_antiAliasingMode == ANTIALIASING_SMOOTH_RETRO ? 2.f : 1.f;

size_t maxAwareRange = std::max<size_t>(visibleDimension.width(), visibleDimension.height());
auto maxAwareRange = std::max<size_t>(visibleDimension.width(), visibleDimension.height());

const auto optimize = maxAwareRange > 115;

m_pool->agroup(maxAwareRange > 115);
m_pool->agroup(optimize);
m_multithreading = optimize;
while (maxAwareRange > 100) {
maxAwareRange /= 2;
scaleFactor /= 2;
Expand Down
3 changes: 3 additions & 0 deletions src/client/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,15 @@ class MapView final : public LuaObject
bool m_forceDrawViewportEdge{ false };
bool m_drawHighlightTarget{ false };
bool m_shiftPressed{ false };
bool m_multithreading{ false };

FadeType m_fadeType{ FadeType::NONE$ };

AntialiasingMode m_antiAliasingMode{ ANTIALIASING_DISABLED };

std::vector<FloorData> m_floors;
std::vector<std::vector<FloorData>> m_floorThreads;

std::vector<TilePtr> m_foregroundTiles;

PainterShaderProgramPtr m_shader;
Expand Down
6 changes: 4 additions & 2 deletions src/framework/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#pragma once
#include <obfuscate.h>

// APPEARANCES
#define BYTES_IN_SPRITE_SHEET 384 * 384 * 4
Expand All @@ -35,8 +36,9 @@
// You can compile it once and use this executable to only encrypt client files once with command --encrypt which will be using password below.
#define ENABLE_ENCRYPTION_BUILDER 0
// for security reasons make sure you are using password with at last 100+ characters
#define ENCRYPTION_PASSWORD "SET_YOUR_PASSWORD_HERE"
#define ENCRYPTION_HEADER "SET_YOUR_HEADER_HERE"
#define ENCRYPTION_PASSWORD AY_OBFUSCATE("SET_YOUR_PASSWORD_HERE")
// do not insert special characters in the header (ONLY UPPERCASE LETTERS, LOWERCASE LETTERS AND NUMBERS) | example: #define ENCRYPTION_HEADER AY_OBFUSCATE("21UsO5ARfRnIScs415BNMab")
#define ENCRYPTION_HEADER AY_OBFUSCATE("SET_YOUR_HEADER_HERE")

// DISCORD RPC (https://discord.com/developers/applications)
// Note: Only for VSSolution, doesn't work with CMAKE
Expand Down
4 changes: 2 additions & 2 deletions src/framework/core/filestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ FileStream::~FileStream()
close();
}

void FileStream::cache(bool /*useEnc*/)
void FileStream::cache(bool useEnc)

Check warning on line 64 in src/framework/core/filestream.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

unused parameter ‘useEnc’ [-Wunused-parameter]

Check warning on line 64 in src/framework/core/filestream.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

unused parameter ‘useEnc’ [-Wunused-parameter]
{
m_caching = true;

Expand Down Expand Up @@ -472,4 +472,4 @@ void FileStream::throwError(const std::string_view message, const bool physfsErr
if (physfsError)
completeMessage += ": "s + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
throw Exception(completeMessage);
}
}
47 changes: 12 additions & 35 deletions src/framework/core/resourcemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ std::string ResourceManager::readFileContents(const std::string& fileName)
{
const std::string fullPath = resolvePath(fileName);

if (fullPath.find(g_resources.getByteStrings(0)) != std::string::npos) {
if (fullPath.find(AY_OBFUSCATE("/downloads")) != std::string::npos) {
const auto dfile = g_http.getFile(fullPath.substr(10));
if (dfile)
return std::string(dfile->response.begin(), dfile->response.end());
Expand All @@ -225,21 +225,20 @@ std::string ResourceManager::readFileContents(const std::string& fileName)
PHYSFS_close(file);

#if ENABLE_ENCRYPTION == 1
bool hasHeader = false;
if (buffer.size() >= std::string(ENCRYPTION_HEADER).size() &&
buffer.substr(0, std::string(ENCRYPTION_HEADER).size()) == std::string(ENCRYPTION_HEADER)) {
hasHeader = true;
}

if (g_game.getFeature(Otc::GameAllowCustomBotScripts)) {
if (fullPath.find(g_resources.getByteStrings(1)) != std::string::npos && !hasHeader) {
return buffer;
}
}
const auto headerSize = std::string(ENCRYPTION_HEADER).size();
const bool hasHeader = (buffer.size() >= headerSize &&
buffer.compare(0, headerSize, ENCRYPTION_HEADER) == 0);

if (hasHeader) {
buffer = buffer.substr(std::string(ENCRYPTION_HEADER).size());
buffer = buffer.substr(headerSize);
buffer = decrypt(buffer);
} else {
if (fullPath.find(std::string(AY_OBFUSCATE("/bot/"))) != std::string::npos) {
if (g_game.getFeature(Otc::GameAllowCustomBotScripts)) {
return buffer;
}
return "";
}
}
#endif

Expand Down Expand Up @@ -759,25 +758,3 @@ std::unordered_map<std::string, std::string> ResourceManager::decompressArchive(
std::unordered_map<std::string, std::string> ret;
return ret;
}

std::string ResourceManager::decodificateStrings(const std::vector<unsigned char>& bytes) {
std::string result;
for (const unsigned char c : bytes) {
result.push_back(c ^ 0xAA);
}
return result;
}

// used to obfuscate vulnerable strings (provisional)
std::string ResourceManager::getByteStrings(const size_t line) {
const std::vector<std::vector<unsigned char>> strTable = {
{0x85, 0xCE, 0xC5, 0xDD, 0xC4, 0xC6, 0xC5, 0xCB, 0xCE, 0xD9}, // "/downloads"
{0x85, 0xC8, 0xC5, 0xDE, 0x85}, // "/bot/"
{0xE6, 0xC3, 0xC4, 0xC2, 0xCB, 0x8A, 0xCE, 0xCF, 0x8A, 0xD8, 0xCF, 0xDE, 0xC5, 0xD8, 0xC4, 0xC5, 0x8A, 0xC3, 0xC4, 0xDC, 0xCB, 0xC6, 0xC3, 0xCE, 0xCB}, // "Linha de retorno invalida"
};

if (line < strTable.size()) {
return decodificateStrings(strTable[line]);
}
return decodificateStrings(strTable[2]);
}
2 changes: 0 additions & 2 deletions src/framework/core/resourcemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ class ResourceManager
bool launchCorrect(const std::vector<std::string>& args);
std::string createArchive(const std::unordered_map<std::string, std::string>& files);
std::unordered_map<std::string, std::string> decompressArchive(std::string dataOrPath);
std::string decodificateStrings(const std::vector<unsigned char>& bytes);
std::string getByteStrings(size_t line);

std::string getBinaryPath() { return m_binaryPath.string(); }

Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern "C" {
#if ENABLE_ENCRYPTION == 1 && ENABLE_ENCRYPTION_BUILDER == 1
if (std::find(args.begin(), args.end(), "--encrypt") != args.end()) {
g_lua.init();
g_resources.runEncryption(args.size() >= 3 ? args[2] : ENCRYPTION_PASSWORD);
g_resources.runEncryption(args.size() >= 3 ? args[2] : std::string(ENCRYPTION_PASSWORD));
std::cout << "Encryption complete" << std::endl;
#ifdef WIN32
MessageBoxA(NULL, "Encryption complete", "Success", 0);
Expand Down Expand Up @@ -124,4 +124,4 @@ extern "C" {
}
#ifdef ANDROID
}
#endif
#endif
1 change: 1 addition & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cpp-httplib",
"discord-rpc",
"liblzma",
"libobfuscate",
"libogg",
"libvorbis",
"nlohmann-json",
Expand Down

0 comments on commit 07cf903

Please sign in to comment.