mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
base64: restore bundled & update tmxlite to use bundled version
This commit is contained in:
@@ -27,6 +27,8 @@ if (MSVC)
|
||||
target_compile_definitions(tmxlite PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
target_link_libraries(tmxlite base64::base64)
|
||||
|
||||
if (USE_BUNDLED_PUGIXML)
|
||||
target_link_libraries(tmxlite pugixml::static)
|
||||
else()
|
||||
|
||||
@@ -25,30 +25,6 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
base64_decode
|
||||
|
||||
Copyright (C) 2004-2008 René Nyffenegger
|
||||
This source code is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be misrepresented; you must not
|
||||
claim that you wrote the original source code. If you use this source code
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original source code.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
||||
*********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tmxlite/detail/Android.hpp>
|
||||
@@ -66,72 +42,6 @@ namespace tmx
|
||||
//using inline here just to supress unused warnings on gcc
|
||||
bool decompress(const char* source, std::vector<unsigned char>& dest, std::size_t inSize, std::size_t expectedSize);
|
||||
|
||||
static inline std::string base64_decode(std::string const& encoded_string)
|
||||
{
|
||||
static const std::string base64_chars =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
|
||||
std::function<bool(unsigned char)> is_base64 =
|
||||
[](unsigned char c)->bool
|
||||
{
|
||||
return (isalnum(c) || (c == '+') || (c == '/'));
|
||||
};
|
||||
|
||||
auto in_len = encoded_string.size();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int in_ = 0;
|
||||
unsigned char char_array_4[4], char_array_3[3];
|
||||
std::string ret;
|
||||
|
||||
while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
|
||||
{
|
||||
char_array_4[i++] = encoded_string[in_]; in_++;
|
||||
if (i == 4)
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
char_array_4[i] = static_cast<unsigned char>(base64_chars.find(char_array_4[i]));
|
||||
}
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (i = 0; (i < 3); i++)
|
||||
{
|
||||
ret += char_array_3[i];
|
||||
}
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i)
|
||||
{
|
||||
for (j = i; j < 4; j++)
|
||||
{
|
||||
char_array_4[j] = 0;
|
||||
}
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
{
|
||||
char_array_4[j] = static_cast<unsigned char>(base64_chars.find(char_array_4[j]));
|
||||
}
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (j = 0; (j < i - 1); j++)
|
||||
{
|
||||
ret += char_array_3[j];
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline Colour colourFromString(std::string str)
|
||||
{
|
||||
//removes preceding #
|
||||
@@ -164,7 +74,7 @@ namespace tmx
|
||||
}
|
||||
|
||||
static inline std::string resolveFilePath(std::string path, const std::string& workingDir)
|
||||
{
|
||||
{
|
||||
static const std::string match("../");
|
||||
std::size_t result = path.find(match);
|
||||
std::size_t count = 0;
|
||||
@@ -186,12 +96,12 @@ namespace tmx
|
||||
outPath = outPath.substr(0, result);
|
||||
}
|
||||
}
|
||||
// this does only work on windows
|
||||
// this does only work on windows
|
||||
#ifndef __ANDROID__
|
||||
return outPath + '/' + path;
|
||||
#endif
|
||||
|
||||
// todo: make resolveFilePath work with subfolders on
|
||||
// todo: make resolveFilePath work with subfolders on
|
||||
// android - currently only the root folder is working
|
||||
|
||||
#ifdef __ANDROID__
|
||||
@@ -223,4 +133,4 @@ namespace tmx
|
||||
|
||||
return searchFunc('/', path);
|
||||
}
|
||||
} //namespacec tmx
|
||||
} //namespacec tmx
|
||||
|
||||
@@ -26,15 +26,13 @@ source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
#ifdef USE_ZSTD
|
||||
#include <zstd.h>
|
||||
# include <zstd.h>
|
||||
#endif
|
||||
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
#include <tmxlite/TileLayer.hpp>
|
||||
#include <tmxlite/detail/Log.hpp>
|
||||
|
||||
#include "base64.h"
|
||||
#include "tmxlite/FreeFuncs.hpp"
|
||||
#include "tmxlite/TileLayer.hpp"
|
||||
#include "tmxlite/detail/Log.hpp"
|
||||
#include <sstream>
|
||||
|
||||
using namespace tmx;
|
||||
@@ -134,7 +132,7 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
|
||||
{
|
||||
std::size_t dataSize = dataString.length() * sizeof(unsigned char);
|
||||
std::size_t result = ZSTD_decompress(byteData.data(), expectedSize, &dataString[0], dataSize);
|
||||
|
||||
|
||||
if (ZSTD_isError(result))
|
||||
{
|
||||
std::string err = ZSTD_getErrorName(result);
|
||||
@@ -220,7 +218,7 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
|
||||
createTiles(IDs, chunk.tiles);
|
||||
m_chunks.push_back(chunk);
|
||||
dataCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,7 +323,7 @@ void TileLayer::createTiles(const std::vector<std::uint32_t>& IDs, std::vector<T
|
||||
{
|
||||
//LOG(IDs.size() != m_tileCount, "Layer tile count does not match expected size. Found: "
|
||||
// + std::to_string(IDs.size()) + ", expected: " + std::to_string(m_tileCount));
|
||||
|
||||
|
||||
static const std::uint32_t mask = 0xf0000000;
|
||||
for (const auto& id : IDs)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user