From 75e6d7c8ab466655f563963a3e4ec2edc6a4e1de Mon Sep 17 00:00:00 2001 From: a Date: Mon, 21 Aug 2023 06:58:55 +0300 Subject: [PATCH] (RIN forum) add initial hotfix by ce20fdf2 * + revert the change to SetProduct() and SetGameDescription() * + less verbose return in Steam_GameServer::BSecure() * + add missing note in ReadMe about libssq --- README.md | 15 + Readme_release.txt | 18 + dll/local_storage.cpp | 36 + dll/local_storage.h | 1 + dll/net.proto | 2 + dll/network.cpp | 96 + dll/network.h | 8 +- dll/settings.cpp | 30 + dll/settings.h | 43 + dll/settings_parser.cpp | 146 +- dll/source_query.cpp | 267 ++ dll/source_query.h | 28 + dll/steam_friends.h | 91 +- dll/steam_gameserver.cpp | 105 +- dll/steam_gameserver.h | 12 +- dll/steam_http.cpp | 34 + dll/steam_http.h | 2 + dll/steam_matchmaking.h | 126 +- dll/steam_matchmaking_servers.cpp | 299 +- dll/steam_matchmaking_servers.h | 14 + dll/steam_ugc.h | 42 +- dll/steam_user.h | 12 + .../account_avatar.EXAMPLE.jpg | Bin 0 -> 3409 bytes .../account_avatar_default.EXAMPLE.jpg | Bin 0 -> 3409 bytes .../disable_account_avatar.EXAMPLE.txt | 1 + .../disable_lan_only.EXAMPLE.txt | 1 + ...erlay_achievement_notification.EXAMPLE.txt | 1 + .../disable_source_query.EXAMPLE.txt | 1 + .../http_online.EXAMPLE.txt | 1 + .../steam_settings.EXAMPLE/mods.EXAMPLE.json | 31 + .../subscribed_groups_clans.EXAMPLE.txt | 1 + overlay_experimental/steam_overlay.cpp | 169 +- overlay_experimental/steam_overlay.h | 2 +- .../steam_overlay_translations.h | 3140 +++++++++++++++++ scripts/steamclient_loader.sh | 97 +- sdk_includes/isteamgameserverstats.h | 2 +- sdk_includes/isteaminventory.h | 2 +- sdk_includes/isteammasterserverupdater.h | 2 +- stb/stb_image_resize.h | 2634 ++++++++++++++ 39 files changed, 7356 insertions(+), 156 deletions(-) create mode 100644 dll/source_query.cpp create mode 100644 dll/source_query.h create mode 100644 files_example/steam_settings.EXAMPLE/account_avatar.EXAMPLE.jpg create mode 100644 files_example/steam_settings.EXAMPLE/account_avatar_default.EXAMPLE.jpg create mode 100644 files_example/steam_settings.EXAMPLE/disable_account_avatar.EXAMPLE.txt create mode 100644 files_example/steam_settings.EXAMPLE/disable_lan_only.EXAMPLE.txt create mode 100644 files_example/steam_settings.EXAMPLE/disable_overlay_achievement_notification.EXAMPLE.txt create mode 100644 files_example/steam_settings.EXAMPLE/disable_source_query.EXAMPLE.txt create mode 100644 files_example/steam_settings.EXAMPLE/http_online.EXAMPLE.txt create mode 100644 files_example/steam_settings.EXAMPLE/mods.EXAMPLE.json create mode 100644 files_example/steam_settings.EXAMPLE/subscribed_groups_clans.EXAMPLE.txt create mode 100644 overlay_experimental/steam_overlay_translations.h create mode 100644 stb/stb_image_resize.h diff --git a/README.md b/README.md index ae276b89..79a4079c 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,21 @@ cd vcpkg ./bootstrap-vcpkg.bat ./vcpkg install protobuf --triplet x86-windows-static ./vcpkg install protobuf --triplet x64-windows-static + +./vcpkg install curl --triplet x86-windows-static +./vcpkg install curl --triplet x64-windows-static + +cd.. +git clone https://github.com/BinaryAlien/libssq.git +cd libssq +mkdir build32 +:: -G source: https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html +cmake -G "Visual Studio 17 2022" -A Win32 -S . -B "build32" +cmake --build build32 --config Release +mkdir build64 +cmake -G "Visual Studio 17 2022" -A x64 -S . -B "build64" +cmake --build build64 --config Release + cd .. git clone https://gitlab.com/Mr_Goldberg/goldberg_emulator.git cd goldberg_emulator diff --git a/Readme_release.txt b/Readme_release.txt index 2a02c1c1..62519a4c 100644 --- a/Readme_release.txt +++ b/Readme_release.txt @@ -56,6 +56,11 @@ Subscribed Groups: Some games like payday 2 check which groups you are subscribed in and unlock things based on that. You can provide a list of subscribed groups to the game with a steam_settings\subscribed_groups.txt file. See steam_settings.EXAMPLE\subscribed_groups.EXAMPLE.txt for an example for payday 2. +Subscribed Groups (Clans): +Some games like counter-strike check which groups you are subscribed in and allow you to choose a group clan. You can provide a list of subscribed group ids, names, and tags to the game with a subscribed_groups_clans.txt file placed in the Goldberg SteamEmu Saves\settings or in steam_settings folder. +Group ids must be valid and can be obtained by pasting '/memberslistxml/?xml=1' at the end of a Steam group page. Double tabs that are used as seperators must not be removed. +See steam_settings.EXAMPLE\subscribed_groups_clans.EXAMPLE.txt for an example. + App paths: Some rare games might need to be provided one or more paths to app ids. For example the path to where a dlc is installed. This sets the paths returned by the Steam_Apps::GetAppInstallDir function. See steam_settings.EXAMPLE\app_paths.EXAMPLE.txt for an example. @@ -65,6 +70,7 @@ Note that paths are treated as relative paths from where the steam_api dll is lo Mods: Put your mods in the steam_settings\mods\ folder. The steam_settings folder must be placed right beside my emulator dll. Mod folders must be a number corresponding to the file id of the mod. +Some games may require extra information about a mod. This information can be passed to the game by using a mods.EXAMPLE.txt file and mod_images folder stored in the steam_settings folder. See the steam_settings.EXAMPLE folder for an example. Steam appid: @@ -123,6 +129,18 @@ For example this url: https://en.wikipedia.org/wiki/Main_Page Would be: steam_settings\http\en.wikipedia.org\wiki\Main_Page The Main_Page file would contain the data returned by the steamHTTP api when it tries to access: https://en.wikipedia.org/wiki/Main_Page An example that was made for payday 2 can be found in steam_settings.EXAMPLE +To allow external downloads which will be stored in this steam_settings\http folder copy the http_online file from the example folder to the steam_settings folder with .EXAMPLE removed from the file name. + +Avatar: +Copy a PNG or JPG image to your Goldberg SteamEmu Saves\settings or steam_settings folder and name it account_avatar +You can also set a default profile picture for users who are missing one by copying a similar file called account_avatar_default +For games that do not work with avatars you can place a disable_account_avatar.txt file into the steam_settings folder. +You can find examples in steam_settings.EXAMPLE + +Server browser: +Create a text file called serverbrowser.txt with a list of ips in the Goldberg SteamEmu Saves\7\remote folder. +serverbrowser_favorites.txt and serverbrowser_history.txt are also stored in this folder. +Best to keep amount of servers to a low since server browser is not threaded yet and will cause the game to freeze for a bit while refreshing. Support for CPY steam_api(64).dll cracks: See the build in the experimental folder. diff --git a/dll/local_storage.cpp b/dll/local_storage.cpp index f6ab1fc5..0f2bb570 100644 --- a/dll/local_storage.cpp +++ b/dll/local_storage.cpp @@ -30,6 +30,9 @@ #define STB_IMAGE_WRITE_STATIC #include "../stb/stb_image_write.h" +#define STB_IMAGE_RESIZE_IMPLEMENTATION +#include "../stb/stb_image_resize.h" + struct File_Data { std::string name; }; @@ -161,6 +164,11 @@ std::vector Local_Storage::load_image(std::string const& image_pa return std::vector(); } +std::string Local_Storage::load_image_resized(std::string const& image_path, std::string const& image_data, int resolution) +{ + return ""; +} + bool Local_Storage::save_screenshot(std::string const& image_path, uint8_t* img_ptr, int32_t width, int32_t height, int32_t channels) { return false; @@ -783,6 +791,34 @@ std::vector Local_Storage::load_image(std::string const& image_pa return res; } +std::string Local_Storage::load_image_resized(std::string const& image_path, std::string const& image_data, int resolution) +{ + int width, height; + char *resized_img = (char *)malloc(sizeof(char) * 184 * 184 * 4); + unsigned char* img; + + if (image_path.length() > 0) + { + img = stbi_load(image_path.c_str(), &width, &height, nullptr, 4); + + if (img != nullptr) + { + stbir_resize_uint8(img, width, height, NULL, (unsigned char *)resized_img, resolution, resolution, NULL, 4); + stbi_image_free(img); + } + } + else if (image_data.length() > 0) + { + stbir_resize_uint8((unsigned char *)image_data.c_str(), 184, 184, NULL, (unsigned char *)resized_img, resolution, resolution, NULL, 4); + } + + std::string resized_image(resized_img, resolution * resolution * 4); + free(resized_img); + + reset_LastError(); + return resized_image; +} + bool Local_Storage::save_screenshot(std::string const& image_path, uint8_t* img_ptr, int32_t width, int32_t height, int32_t channels) { std::string screenshot_path = std::move(save_directory + appid + screenshots_folder + PATH_SEPARATOR); diff --git a/dll/local_storage.h b/dll/local_storage.h index ddb1c338..dd6d454b 100644 --- a/dll/local_storage.h +++ b/dll/local_storage.h @@ -85,6 +85,7 @@ public: bool write_json_file(std::string folder, std::string const& file, nlohmann::json const& json); std::vector load_image(std::string const& image_path); + static std::string load_image_resized(std::string const& image_path, std::string const& image_data, int resolution); bool save_screenshot(std::string const& image_path, uint8_t* img_ptr, int32_t width, int32_t height, int32_t channels); }; diff --git a/dll/net.proto b/dll/net.proto index 32e78529..a5522404 100644 --- a/dll/net.proto +++ b/dll/net.proto @@ -169,6 +169,7 @@ message Gameserver { uint32 appid = 35; bool offline = 48; + uint32 type = 49; } message Friend { @@ -177,6 +178,7 @@ message Friend { map rich_presence = 3; uint32 appid = 4; uint64 lobby_id = 5; + bytes avatar = 6; } message Auth_Ticket { diff --git a/dll/network.cpp b/dll/network.cpp index c7323c67..cd7c6a42 100644 --- a/dll/network.cpp +++ b/dll/network.cpp @@ -16,6 +16,7 @@ . */ #include "network.h" +#include "dll.h" #define MAX_BROADCASTS 16 static int number_broadcasts = -1; @@ -839,6 +840,12 @@ Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set PRINT_DEBUG("TCP: could not initialize %i\n", get_last_error()); } + if (curl_global_init(CURL_GLOBAL_NOTHING) == 0) { + PRINT_DEBUG("CURL successful\n"); + } else { + PRINT_DEBUG("CURL: could not initialize\n"); + } + if (is_socket_valid(udp_socket) && is_socket_valid(tcp_socket)) { PRINT_DEBUG("Networking initialized successfully on udp: %u tcp: %u \n", udp_port, tcp_port); enabled = true; @@ -862,6 +869,8 @@ Networking::~Networking() kill_socket(udp_socket); kill_socket(tcp_socket); + + curl_global_cleanup(); } Common_Message Networking::create_announce(bool request) @@ -930,6 +939,22 @@ void Networking::Run() char data[MAX_UDP_SIZE]; int len; + if (query_alive && is_socket_valid(query_socket)) { + PRINT_DEBUG("RECV QUERY\n"); + Steam_Client* client = get_steam_client(); + sockaddr_in addr; + addr.sin_family = AF_INET; + + while ((len = receive_packet(query_socket, &ip_port, data, sizeof(data))) >= 0) { + client->steam_gameserver->HandleIncomingPacket(data, len, htonl(ip_port.ip), htons(ip_port.port)); + len = client->steam_gameserver->GetNextOutgoingPacket(data, sizeof(data), &ip_port.ip, &ip_port.port); + + addr.sin_addr.s_addr = htonl(ip_port.ip); + addr.sin_port = htons(ip_port.port); + sendto(query_socket, data, len, 0, (sockaddr*)&addr, sizeof(addr)); + } + } + PRINT_DEBUG("RECV UDP\n"); while((len = receive_packet(udp_socket, &ip_port, data, sizeof(data))) >= 0) { PRINT_DEBUG("recv %i %hhu.%hhu.%hhu.%hhu:%hu\n", len, ((unsigned char *)&ip_port.ip)[0], ((unsigned char *)&ip_port.ip)[1], ((unsigned char *)&ip_port.ip)[2], ((unsigned char *)&ip_port.ip)[3], htons(ip_port.port)); @@ -1288,3 +1313,74 @@ uint32 Networking::getOwnIP() { return own_ip; } + +void Networking::startQuery(IP_PORT ip_port) +{ + if (ip_port.port <= 1024) + return; + + if (!query_alive) + { + if (ip_port.port == MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE) + { + PRINT_DEBUG("Source Query in Shared Mode\n"); + return; + } + + int retry = 0; + constexpr auto max_retry = 10; + + while (retry++ < max_retry) + { + query_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (is_socket_valid(query_socket)) + break; + if (retry > max_retry) + { + reset_last_error(); + return; + } + } + retry = 0; + + sockaddr_in addr; + addr.sin_addr.s_addr = htonl(ip_port.ip); + addr.sin_port = htons(ip_port.port); + addr.sin_family = AF_INET; + + while (retry++ < max_retry) + { + int res = bind(query_socket, (sockaddr*)&addr, sizeof(sockaddr_in)); + if (res == 0) + { + set_socket_nonblocking(query_socket); + break; + } + + if (retry >= max_retry) + { + kill_socket(query_socket); + query_socket = -1; + reset_last_error(); + return; + } + } + + char str_ip[16]; + inet_ntop(AF_INET, &(addr.sin_addr), str_ip, 16); + + PRINT_DEBUG("Started query server on %s:%d\n", str_ip, htons(addr.sin_port)); + } + query_alive = true; +} + +void Networking::shutDownQuery() +{ + query_alive = false; + kill_socket(query_socket); +} + +bool Networking::isQueryAlive() +{ + return query_alive; +} diff --git a/dll/network.h b/dll/network.h index 72e9f399..f370a4bc 100644 --- a/dll/network.h +++ b/dll/network.h @@ -19,6 +19,7 @@ #define NETWORK_INCLUDE #include "base.h" +#include inline bool protobuf_message_equal(const google::protobuf::MessageLite& msg_a, const google::protobuf::MessageLite& msg_b) { @@ -90,8 +91,9 @@ struct Connection { class Networking { bool enabled = false; + bool query_alive; std::chrono::high_resolution_clock::time_point last_run; - sock_t udp_socket, tcp_socket; + sock_t query_socket, udp_socket, tcp_socket; uint16 udp_port, tcp_port; uint32 own_ip; std::vector connections; @@ -137,6 +139,10 @@ public: bool setCallback(Callback_Ids id, CSteamID steam_id, void (*message_callback)(void *object, Common_Message *msg), void *object); uint32 getIP(CSteamID id); uint32 getOwnIP(); + + void startQuery(IP_PORT ip_port); + void shutDownQuery(); + bool isQueryAlive(); }; #endif diff --git a/dll/settings.cpp b/dll/settings.cpp index f347c0a1..f695ed57 100644 --- a/dll/settings.cpp +++ b/dll/settings.cpp @@ -138,6 +138,36 @@ void Settings::addMod(PublishedFileId_t id, std::string title, std::string path) mods.push_back(new_entry); } +void Settings::addModDetails(PublishedFileId_t id, Mod_entry details) +{ + auto f = std::find_if(mods.begin(), mods.end(), [&id](Mod_entry const& item) { return item.id == id; }); + if (f != mods.end()) { + f->previewURL = details.previewURL; + f->fileType = details.fileType; + f->description = details.description; + f->steamIDOwner = details.steamIDOwner; + f->timeCreated = details.timeCreated; + f->timeUpdated = details.timeUpdated; + f->timeAddedToUserList = details.timeAddedToUserList; + f->visibility = details.visibility; + f->banned = details.banned; + f->acceptedForUse = details.acceptedForUse; + f->tagsTruncated = details.tagsTruncated; + f->tags = details.tags; + f->handleFile = details.handleFile; + f->handlePreviewFile = details.handlePreviewFile; + f->primaryFileName = details.primaryFileName; + f->primaryFileSize = details.primaryFileSize; + f->previewFileName = details.previewFileName; + f->previewFileSize = details.previewFileSize; + f->workshopItemURL = details.workshopItemURL; + f->votesUp = details.votesUp; + f->votesDown = details.votesDown; + f->score = details.score; + f->numChildren = details.numChildren; + } +} + Mod_entry Settings::getMod(PublishedFileId_t id) { auto f = std::find_if(mods.begin(), mods.end(), [&id](Mod_entry const& item) { return item.id == id; }); diff --git a/dll/settings.h b/dll/settings.h index a7b2aa92..c9ab366d 100644 --- a/dll/settings.h +++ b/dll/settings.h @@ -32,6 +32,33 @@ struct Mod_entry { PublishedFileId_t id; std::string title; std::string path; + + std::string previewURL; + EWorkshopFileType fileType; + std::string description; + uint64 steamIDOwner; + uint32 timeCreated; + uint32 timeUpdated; + uint32 timeAddedToUserList; + ERemoteStoragePublishedFileVisibility visibility; + bool banned; + bool acceptedForUse; + bool tagsTruncated; + std::string tags; + // file/url information + UGCHandle_t handleFile = k_UGCHandleInvalid; + UGCHandle_t handlePreviewFile = k_UGCHandleInvalid; + std::string primaryFileName; + int32 primaryFileSize; + std::string previewFileName; + int32 previewFileSize; + std::string workshopItemURL; + // voting information + uint32 votesUp; + uint32 votesDown; + float score; + // collection details + uint32 numChildren; }; struct Leaderboard_config { @@ -65,6 +92,12 @@ struct Controller_Settings { std::map, std::string>>> action_set_layers; }; +struct Group_Clans { + CSteamID id; + std::string name; + std::string tag; +}; + class Settings { CSteamID steam_id; CGameID game_id; @@ -119,6 +152,7 @@ public: //mod stuff void addMod(PublishedFileId_t id, std::string title, std::string path); + void addModDetails(PublishedFileId_t id, Mod_entry details); Mod_entry getMod(PublishedFileId_t id); bool isModInstalled(PublishedFileId_t id); std::set modSet(); @@ -138,10 +172,12 @@ public: //subscribed lobby/group ids std::set subscribed_groups; + std::vector subscribed_groups_clans; //images std::map images; int add_image(std::string data, uint32 width, uint32 height); + bool disable_account_avatar = false; //controller struct Controller_Settings controller_settings; @@ -150,8 +186,12 @@ public: //networking bool disable_networking = false; + //gameserver source query + bool disable_source_query = false; + //overlay bool disable_overlay = false; + bool disable_overlay_achievement_notification = false; //app build id int build_id = 10; @@ -167,6 +207,9 @@ public: //warn people who use local save bool warn_local_save = false; + + //steamhttp external download support + bool http_online = false; }; #endif diff --git a/dll/settings_parser.cpp b/dll/settings_parser.cpp index 22dad2ed..c42aed2f 100644 --- a/dll/settings_parser.cpp +++ b/dll/settings_parser.cpp @@ -42,6 +42,46 @@ static void load_custom_broadcasts(std::string broadcasts_filepath, std::setsubscribed_groups_clans.push_back(nclan); + settings_server->subscribed_groups_clans.push_back(nclan); + PRINT_DEBUG("Added clan %s\n", clan_name.c_str()); + } catch (...) {} + } + } +} + template static void split_string(const std::string &s, char delim, Out result) { std::stringstream ss(s); @@ -296,9 +336,13 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s } bool steam_offline_mode = false; + bool steamhttp_online_mode = false; bool disable_networking = false; bool disable_overlay = false; + bool disable_overlay_achievement_notification = false; bool disable_lobby_creation = false; + bool disable_source_query = false; + bool disable_account_avatar = false; int build_id = 10; bool warn_forced = false; @@ -311,12 +355,20 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s PRINT_DEBUG("steam settings path %s\n", p.c_str()); if (p == "offline.txt") { steam_offline_mode = true; + } else if (p == "http_online.txt") { + steamhttp_online_mode = true; } else if (p == "disable_networking.txt") { disable_networking = true; } else if (p == "disable_overlay.txt") { disable_overlay = true; + } else if (p == "disable_overlay_achievement_notification.txt") { + disable_overlay_achievement_notification = true; } else if (p == "disable_lobby_creation.txt") { disable_lobby_creation = true; + } else if (p == "disable_source_query.txt") { + disable_source_query = true; + } else if (p == "disable_account_avatar.txt") { + disable_account_avatar = true; } else if (p == "force_language.txt") { int len = Local_Storage::get_file_data(steam_settings_path + "force_language.txt", language, sizeof(language) - 1); if (len > 0) { @@ -363,8 +415,14 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s settings_server->disable_networking = disable_networking; settings_client->disable_overlay = disable_overlay; settings_server->disable_overlay = disable_overlay; + settings_client->disable_overlay_achievement_notification = disable_overlay_achievement_notification; + settings_server->disable_overlay_achievement_notification = disable_overlay_achievement_notification; settings_client->disable_lobby_creation = disable_lobby_creation; settings_server->disable_lobby_creation = disable_lobby_creation; + settings_client->disable_source_query = disable_source_query; + settings_server->disable_source_query = disable_source_query; + settings_client->disable_account_avatar = disable_account_avatar; + settings_server->disable_account_avatar = disable_account_avatar; settings_client->build_id = build_id; settings_server->build_id = build_id; settings_client->warn_forced = warn_forced; @@ -373,6 +431,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s settings_server->warn_local_save = local_save; settings_client->supported_languages = supported_languages; settings_server->supported_languages = supported_languages; + settings_client->http_online = steamhttp_online_mode; + settings_server->http_online = steamhttp_online_mode; { std::string dlc_config_path = Local_Storage::get_game_settings_path() + "DLC.txt"; @@ -606,16 +666,86 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s } } + load_subscribed_groups_clans(local_storage->get_global_settings_path() + "subscribed_groups_clans.txt", settings_client, settings_server); + load_subscribed_groups_clans(Local_Storage::get_game_settings_path() + "subscribed_groups_clans.txt", settings_client, settings_server); + { std::string mod_path = Local_Storage::get_game_settings_path() + "mods"; - std::vector paths = Local_Storage::get_filenames_path(mod_path); - for (auto & p: paths) { - PRINT_DEBUG("mod directory %s\n", p.c_str()); - try { - PublishedFileId_t id = std::stoull(p); - settings_client->addMod(id, p, mod_path + PATH_SEPARATOR + p); - settings_server->addMod(id, p, mod_path + PATH_SEPARATOR + p); - } catch (...) {} + nlohmann::json mod_items = nlohmann::json::object(); + static constexpr auto mods_json_file = "mods.json"; + std::string mods_json_path = Local_Storage::get_game_settings_path() + mods_json_file; + if (local_storage->load_json(mods_json_path, mod_items)) { + for (auto mod = mod_items.begin(); mod != mod_items.end(); ++mod) { + try { + Mod_entry newMod; + newMod.id = std::stoull(mod.key()); + newMod.title = mod.value().value("title", std::string(mod.key())); + newMod.path = mod_path + PATH_SEPARATOR + std::string(mod.key()); + newMod.fileType = k_EWorkshopFileTypeCommunity; + newMod.description = mod.value().value("description", std::string("")); + newMod.steamIDOwner = mod.value().value("steam_id_owner", (uint64)0); + newMod.timeCreated = mod.value().value("time_created", (uint32)1554997000); + newMod.timeUpdated = mod.value().value("time_updated", (uint32)1554997000); + newMod.timeAddedToUserList = mod.value().value("time_added", (uint32)1554997000); + newMod.visibility = k_ERemoteStoragePublishedFileVisibilityPublic; + newMod.banned = false; + newMod.acceptedForUse = true; + newMod.tagsTruncated = false; + newMod.tags = mod.value().value("tags", std::string("")); + newMod.primaryFileName = mod.value().value("primary_filename", std::string("")); + newMod.primaryFileSize = mod.value().value("primary_filesize", (int32)1000000); + newMod.previewFileName = mod.value().value("preview_filename", std::string("")); + newMod.previewFileSize = mod.value().value("preview_filesize", (int32)1000000); + newMod.workshopItemURL = mod.value().value("workshop_item_url", std::string("")); + newMod.votesUp = mod.value().value("upvotes", (uint32)1); + newMod.votesDown = mod.value().value("downvotes", (uint32)0); + newMod.score = 1.0f; + newMod.numChildren = mod.value().value("num_children", (uint32)0); + newMod.previewURL = "file://" + Local_Storage::get_game_settings_path() + "mod_images/" + newMod.previewFileName; + settings_client->addMod(newMod.id, newMod.title, newMod.path); + settings_server->addMod(newMod.id, newMod.title, newMod.path); + settings_client->addModDetails(newMod.id, newMod); + settings_server->addModDetails(newMod.id, newMod); + } catch (std::exception& e) { + PRINT_DEBUG("MODLOADER ERROR: %s\n", e.what()); + } + } + } else { + std::vector paths = Local_Storage::get_filenames_path(mod_path); + for (auto & p: paths) { + PRINT_DEBUG("mod directory %s\n", p.c_str()); + try { + Mod_entry newMod; + newMod.id = std::stoull(p); + newMod.title = p; + newMod.path = mod_path + PATH_SEPARATOR + p; + newMod.fileType = k_EWorkshopFileTypeCommunity; + newMod.description = ""; + newMod.steamIDOwner = (uint64)0; + newMod.timeCreated = (uint32)1554997000; + newMod.timeUpdated = (uint32)1554997000; + newMod.timeAddedToUserList = (uint32)1554997000; + newMod.visibility = k_ERemoteStoragePublishedFileVisibilityPublic; + newMod.banned = false; + newMod.acceptedForUse = true; + newMod.tagsTruncated = false; + newMod.tags = ""; + newMod.primaryFileName = ""; + newMod.primaryFileSize = (int32)1000000; + newMod.previewFileName = ""; + newMod.previewFileSize = (int32)1000000; + newMod.workshopItemURL = ""; + newMod.votesUp = (uint32)1; + newMod.votesDown = (uint32)0; + newMod.score = 1.0f; + newMod.numChildren = (uint32)0; + newMod.previewURL = ""; + settings_client->addMod(newMod.id, newMod.title, newMod.path); + settings_server->addMod(newMod.id, newMod.title, newMod.path); + settings_client->addModDetails(newMod.id, newMod); + settings_server->addModDetails(newMod.id, newMod); + } catch (...) {} + } } } diff --git a/dll/source_query.cpp b/dll/source_query.cpp new file mode 100644 index 00000000..cae53ef4 --- /dev/null +++ b/dll/source_query.cpp @@ -0,0 +1,267 @@ +/* Copyright (C) 2019 Mr Goldberg, , Nemirtingas + This file is part of the Goldberg Emulator + + The Goldberg Emulator is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The Goldberg Emulator is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the Goldberg Emulator; if not, see + . */ + +#include "source_query.h" +#include "dll.h" + +using lock_t = std::lock_guard; + +enum class source_query_magic : uint32_t +{ + simple = 0xFFFFFFFFul, + multi = 0xFFFFFFFEul, // <--- TODO ? +}; + +enum class source_query_header : uint8_t +{ + A2S_INFO = 'T', + A2S_PLAYER = 'U', + A2S_RULES = 'V', +}; + +enum class source_response_header : uint8_t +{ + A2S_CHALLENGE = 'A', + A2S_INFO = 'I', + A2S_PLAYER = 'D', + A2S_RULES = 'E', +}; + +enum class source_server_type : uint8_t +{ + dedicated = 'd', + non_dedicated = 'i', + source_tc = 'p', +}; + +enum class source_server_env : uint8_t +{ + linux = 'l', + windows = 'w', + old_mac = 'm', + mac = 'o', +}; + +enum class source_server_visibility : uint8_t +{ + _public = 0, + _private = 1, +}; + +enum class source_server_vac : uint8_t +{ + unsecured = 0, + secured = 1, +}; + +enum source_server_extra_flag : uint8_t +{ + none = 0x00, + gameid = 0x01, + steamid = 0x10, + keywords = 0x20, + spectator = 0x40, + port = 0x80, +}; + +#if defined(STEAM_WIN32) +static constexpr source_server_env my_server_env = source_server_env::windows; +#else +static constexpr source_server_env my_server_env = source_server_env::linux; +#endif + +#pragma pack(push) +#pragma pack(1) + +constexpr char a2s_info_payload[] = "Source Engine Query"; +constexpr size_t a2s_info_payload_size = sizeof(a2s_info_payload); + +struct source_query_data +{ + source_query_magic magic; + source_query_header header; + union + { + char a2s_info_payload[a2s_info_payload_size]; + uint32_t challenge; + }; +}; + +static constexpr size_t source_query_header_size = sizeof(source_query_magic) + sizeof(source_query_header); +static constexpr size_t a2s_query_info_size = source_query_header_size + sizeof(source_query_data::a2s_info_payload); +static constexpr size_t a2s_query_challenge_size = source_query_header_size + sizeof(source_query_data::challenge); + +#pragma pack(pop) + +void serialize_response(std::vector& buffer, const void* _data, size_t len) +{ + const uint8_t* data = reinterpret_cast(_data); + + buffer.insert(buffer.end(), data, data + len); +} + +template +void serialize_response(std::vector& buffer, T const& v) +{ + uint8_t const* data = reinterpret_cast(&v); + serialize_response(buffer, data, sizeof(T)); +} + +template<> +void serialize_response(std::vector& buffer, std::string const& v) +{ + uint8_t const* str = reinterpret_cast(v.c_str()); + serialize_response(buffer, str, v.length()+1); +} + +template +void serialize_response(std::vector & buffer, char(&str)[N]) +{ + serialize_response(buffer, reinterpret_cast(str), N); +} + +void get_challenge(std::vector &challenge_buff) +{ + // TODO: generate the challenge id + serialize_response(challenge_buff, source_query_magic::simple); + serialize_response(challenge_buff, source_response_header::A2S_CHALLENGE); + serialize_response(challenge_buff, static_cast(0x00112233ul)); +} + +std::vector Source_Query::handle_source_query(const void* buffer, size_t len, Gameserver const& gs) +{ + std::vector output_buffer; + + if (len < source_query_header_size) // its not at least 5 bytes long (0xFF 0xFF 0xFF 0xFF 0x??) + return output_buffer; + + source_query_data const& query = *reinterpret_cast(buffer); + + // || gs.max_player_count() == 0 + if (gs.offline() || query.magic != source_query_magic::simple) + return output_buffer; + + switch (query.header) + { + case source_query_header::A2S_INFO: + if (len >= a2s_query_info_size && !strncmp(query.a2s_info_payload, a2s_info_payload, a2s_info_payload_size)) + { + std::vector> const& players = *get_steam_client()->steam_gameserver->get_players(); + + serialize_response(output_buffer, source_query_magic::simple); + serialize_response(output_buffer, source_response_header::A2S_INFO); + serialize_response(output_buffer, static_cast(2)); + serialize_response(output_buffer, gs.server_name()); + serialize_response(output_buffer, gs.map_name()); + serialize_response(output_buffer, gs.mod_dir()); + serialize_response(output_buffer, gs.product()); + serialize_response(output_buffer, static_cast(gs.appid())); + serialize_response(output_buffer, static_cast(players.size())); + serialize_response(output_buffer, static_cast(gs.max_player_count())); + serialize_response(output_buffer, static_cast(gs.bot_player_count())); + serialize_response(output_buffer, (gs.dedicated_server() ? source_server_type::dedicated : source_server_type::non_dedicated));; + serialize_response(output_buffer, my_server_env); + serialize_response(output_buffer, (gs.password_protected() ? source_server_visibility::_private : source_server_visibility::_public)); + serialize_response(output_buffer, (gs.secure() ? source_server_vac::secured : source_server_vac::unsecured)); + serialize_response(output_buffer, std::to_string(gs.version())); + + uint8_t flags = source_server_extra_flag::none; + + if (gs.port() != 0) + flags |= source_server_extra_flag::port; + + if (gs.spectator_port() != 0) + flags |= source_server_extra_flag::spectator; + + if(CGameID(gs.appid()).IsValid()) + flags |= source_server_extra_flag::gameid; + + if (flags != source_server_extra_flag::none) + serialize_response(output_buffer, flags); + + if (flags & source_server_extra_flag::port) + serialize_response(output_buffer, static_cast(gs.port())); + + // add steamid + + if (flags & source_server_extra_flag::spectator) + { + serialize_response(output_buffer, static_cast(gs.spectator_port())); + serialize_response(output_buffer, gs.spectator_server_name()); + } + + // keywords + + if (flags & source_server_extra_flag::gameid) + serialize_response(output_buffer, CGameID(gs.appid()).ToUint64()); + + } + break; + + case source_query_header::A2S_PLAYER: + if (len >= a2s_query_challenge_size) + { + if (query.challenge == 0xFFFFFFFFul) + { + get_challenge(output_buffer); + } + else if (query.challenge == 0x00112233ul) + { + std::vector> const& players = *get_steam_client()->steam_gameserver->get_players(); + + serialize_response(output_buffer, source_query_magic::simple); + serialize_response(output_buffer, source_response_header::A2S_PLAYER); + serialize_response(output_buffer, static_cast(players.size())); // num_players + + for (int i = 0; i < players.size(); ++i) + { + serialize_response(output_buffer, static_cast(i)); // player index + serialize_response(output_buffer, players[i].second.name); // player name + serialize_response(output_buffer, players[i].second.score); // player score + serialize_response(output_buffer, static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - players[i].second.join_time).count())); + } + + } + } + break; + + case source_query_header::A2S_RULES: + if (len >= a2s_query_challenge_size) + { + if (query.challenge == 0xFFFFFFFFul) + { + get_challenge(output_buffer); + } + else if (query.challenge == 0x00112233ul) + { + auto values = gs.values(); + + serialize_response(output_buffer, source_query_magic::simple); + serialize_response(output_buffer, source_response_header::A2S_RULES); + serialize_response(output_buffer, static_cast(values.size())); + + for (auto const& i : values) + { + serialize_response(output_buffer, i.first); + serialize_response(output_buffer, i.second); + } + } + } + break; + } + return output_buffer; +} diff --git a/dll/source_query.h b/dll/source_query.h new file mode 100644 index 00000000..5f9742a7 --- /dev/null +++ b/dll/source_query.h @@ -0,0 +1,28 @@ +/* Copyright (C) 2019 Mr Goldberg + This file is part of the Goldberg Emulator + + The Goldberg Emulator is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + The Goldberg Emulator is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the Goldberg Emulator; if not, see + . */ + +#include "base.h" + +class Source_Query +{ + Source_Query () = delete; + ~Source_Query() = delete; + +public: + static std::vector handle_source_query(const void* buffer, size_t len, Gameserver const& gs); +}; + diff --git a/dll/steam_friends.h b/dll/steam_friends.h index 5f28c95f..736b74e4 100644 --- a/dll/steam_friends.h +++ b/dll/steam_friends.h @@ -102,12 +102,83 @@ struct Avatar_Numbers add_friend_avatars(CSteamID id) return avatar_ids->second; } - //TODO: get real image data from self/other peers struct Avatar_Numbers avatar_numbers; std::string small_avatar(32 * 32 * 4, 0); std::string medium_avatar(64 * 64 * 4, 0); std::string large_avatar(184 * 184 * 4, 0); + if (!(settings->disable_account_avatar) && (id == settings->get_local_steam_id())) { + std::string file_path; + unsigned long long file_size; + + for (int i = 0; i < 3; i++) { + std::string file_name; + if (i == 0) file_name = "account_avatar.png"; + if (i == 1) file_name = "account_avatar.jpg"; + if (i == 2) file_name = "account_avatar.jpeg"; + file_path = Local_Storage::get_game_settings_path() + file_name; + file_size = file_size_(file_path); + if (file_size) break; + } + + if (!file_size) { + for (int i = 0; i < 3; i++) { + std::string file_name; + if (i == 0) file_name = "account_avatar.png"; + if (i == 1) file_name = "account_avatar.jpg"; + if (i == 2) file_name = "account_avatar.jpeg"; + file_path = Local_Storage::get_user_appdata_path() + "/settings/" + file_name; + file_size = file_size_(file_path); + if (file_size) break; + } + } + + // no else statement here for default or else this breaks default images for friends + if (file_size) { + small_avatar = Local_Storage::load_image_resized(file_path, "", 32); + medium_avatar = Local_Storage::load_image_resized(file_path, "", 64); + large_avatar = Local_Storage::load_image_resized(file_path, "", 184); + } + } else if (!(settings->disable_account_avatar)) { + Friend *f = find_friend(id); + if (f && (large_avatar.compare(f->avatar()) != 0)) { + large_avatar = f->avatar(); + medium_avatar = Local_Storage::load_image_resized("", f->avatar(), 64); + small_avatar = Local_Storage::load_image_resized("", f->avatar(), 32); + } else { + std::string file_path; + unsigned long long file_size; + + for (int i = 0; i < 3; i++) { + std::string file_name; + if (i == 0) file_name = "account_avatar_default.png"; + if (i == 1) file_name = "account_avatar_default.jpg"; + if (i == 2) file_name = "account_avatar_default.jpeg"; + file_path = Local_Storage::get_game_settings_path() + file_name; + file_size = file_size_(file_path); + if (file_size) break; + } + + if (!file_size) { + for (int i = 0; i < 3; i++) { + std::string file_name; + if (i == 0) file_name = "account_avatar_default.png"; + if (i == 1) file_name = "account_avatar_default.jpg"; + if (i == 2) file_name = "account_avatar_default.jpeg"; + file_path = Local_Storage::get_user_appdata_path() + "/settings/" + file_name; + file_size = file_size_(file_path); + if (file_size) break; + } + } + + if (file_size) { + small_avatar = Local_Storage::load_image_resized(file_path, "", 32); + medium_avatar = Local_Storage::load_image_resized(file_path, "", 64); + large_avatar = Local_Storage::load_image_resized(file_path, "", 184); + } + } + } + avatar_numbers.smallest = settings->add_image(small_avatar, 32, 32); avatar_numbers.medium = settings->add_image(medium_avatar, 64, 64); avatar_numbers.large = settings->add_image(large_avatar, 184, 184); @@ -441,24 +512,37 @@ bool HasFriend( CSteamID steamIDFriend, EFriendFlags eFriendFlags ) int GetClanCount() { PRINT_DEBUG("Steam_Friends::GetClanCount\n"); - return 0; + int counter = 0; + for (auto &c : settings->subscribed_groups_clans) counter++; + return counter; } CSteamID GetClanByIndex( int iClan ) { PRINT_DEBUG("Steam_Friends::GetClanByIndex\n"); + int counter = 0; + for (auto &c : settings->subscribed_groups_clans) { + if (counter == iClan) return c.id; + counter++; + } return k_steamIDNil; } const char *GetClanName( CSteamID steamIDClan ) { PRINT_DEBUG("Steam_Friends::GetClanName\n"); + for (auto &c : settings->subscribed_groups_clans) { + if (c.id.ConvertToUint64() == steamIDClan.ConvertToUint64()) return c.name.c_str(); + } return ""; } const char *GetClanTag( CSteamID steamIDClan ) { PRINT_DEBUG("Steam_Friends::GetClanTag\n"); + for (auto &c : settings->subscribed_groups_clans) { + if (c.id.ConvertToUint64() == steamIDClan.ConvertToUint64()) return c.tag.c_str(); + } return ""; } @@ -1101,6 +1185,9 @@ void Callback(Common_Message *msg) f->set_name(settings->get_local_name()); f->set_appid(settings->get_local_game_id().AppID()); f->set_lobby_id(settings->get_lobby().ConvertToUint64()); + int avatar_number = GetLargeFriendAvatar(settings->get_local_steam_id()); + if (settings->images[avatar_number].data.length() > 0) f->set_avatar(settings->images[avatar_number].data); + else f->set_avatar(""); msg_.set_allocated_friend_(f); network->sendTo(&msg_, true); } diff --git a/dll/steam_gameserver.cpp b/dll/steam_gameserver.cpp index 1a8609da..597651c5 100644 --- a/dll/steam_gameserver.cpp +++ b/dll/steam_gameserver.cpp @@ -16,6 +16,7 @@ . */ #include "steam_gameserver.h" +#include "source_query.h" #define SEND_SERVER_RATE 5.0 @@ -33,6 +34,11 @@ Steam_GameServer::~Steam_GameServer() delete ticket_manager; } +std::vector>* Steam_GameServer::get_players() +{ + return &players; +} + // // Basic server data. These properties, if set, must be set before before calling LogOn. They // may not be changed after logged in. @@ -61,6 +67,10 @@ bool Steam_GameServer::InitGameServer( uint32 unIP, uint16 usGamePort, uint16 us server_data.set_port(usGamePort); server_data.set_query_port(usQueryPort); server_data.set_offline(false); + + if (!settings->disable_source_query) + network->startQuery({ unIP, usQueryPort }); + if (!settings->get_local_game_id().AppID()) settings->set_game_id(CGameID(nGameAppId)); //TODO: flags should be k_unServerFlag flags = unFlags; @@ -78,6 +88,8 @@ void Steam_GameServer::SetProduct( const char *pszProduct ) { PRINT_DEBUG("SetProduct\n"); std::lock_guard lock(global_mutex); + // pszGameDescription should be used instead of pszProduct for accurate information + // Example: 'Counter-Strike: Source' instead of 'cstrike' server_data.set_product(pszProduct); } @@ -89,6 +101,7 @@ void Steam_GameServer::SetGameDescription( const char *pszGameDescription ) PRINT_DEBUG("SetGameDescription\n"); std::lock_guard lock(global_mutex); server_data.set_game_description(pszGameDescription); + //server_data.set_product(pszGameDescription); } @@ -183,8 +196,13 @@ bool Steam_GameServer::BSecure() { PRINT_DEBUG("BSecure\n"); std::lock_guard lock(global_mutex); - if (!policy_response_called) return false; - return !!(flags & k_unServerFlagSecure); + if (!policy_response_called) { + server_data.set_secure(0); + return false; + } + const bool res = !!(flags & k_unServerFlagSecure); + server_data.set_secure(res); + return res; } CSteamID Steam_GameServer::GetSteamID() @@ -351,7 +369,18 @@ bool Steam_GameServer::SendUserConnectAndAuthenticate( uint32 unIPClient, const PRINT_DEBUG("SendUserConnectAndAuthenticate %u %u\n", unIPClient, cubAuthBlobSize); std::lock_guard lock(global_mutex); - return ticket_manager->SendUserConnectAndAuthenticate(unIPClient, pvAuthBlob, cubAuthBlobSize, pSteamIDUser); + bool res = ticket_manager->SendUserConnectAndAuthenticate(unIPClient, pvAuthBlob, cubAuthBlobSize, pSteamIDUser); + + if (res) { + std::pair infos; + infos.first = *pSteamIDUser; + infos.second.join_time = std::chrono::steady_clock::now(); + infos.second.score = 0; + infos.second.name = "unnamed"; + players.emplace_back(std::move(infos)); + } + + return res; } void Steam_GameServer::SendUserConnectAndAuthenticate( CSteamID steamIDUser, uint32 unIPClient, void *pvAuthBlob, uint32 cubAuthBlobSize ) @@ -368,7 +397,15 @@ CSteamID Steam_GameServer::CreateUnauthenticatedUserConnection() PRINT_DEBUG("CreateUnauthenticatedUserConnection\n"); std::lock_guard lock(global_mutex); - return ticket_manager->fakeUser(); + CSteamID bot_id = ticket_manager->fakeUser(); + std::pair infos; + infos.first = bot_id; + infos.second.join_time = std::chrono::steady_clock::now(); + infos.second.score = 0; + infos.second.name = "unnamed"; + players.emplace_back(std::move(infos)); + + return bot_id; } @@ -380,6 +417,16 @@ void Steam_GameServer::SendUserDisconnect( CSteamID steamIDUser ) PRINT_DEBUG("SendUserDisconnect\n"); std::lock_guard lock(global_mutex); + auto player_it = std::find_if(players.begin(), players.end(), [&steamIDUser](std::pair& player) + { + return player.first == steamIDUser; + }); + + if (player_it != players.end()) + { + players.erase(player_it); + } + ticket_manager->endAuth(steamIDUser); } @@ -392,7 +439,21 @@ void Steam_GameServer::SendUserDisconnect( CSteamID steamIDUser ) bool Steam_GameServer::BUpdateUserData( CSteamID steamIDUser, const char *pchPlayerName, uint32 uScore ) { PRINT_DEBUG("BUpdateUserData %llu %s %u\n", steamIDUser.ConvertToUint64(), pchPlayerName, uScore); - return true; + + auto player_it = std::find_if(players.begin(), players.end(), [&steamIDUser](std::pair& player) + { + return player.first == steamIDUser; + }); + + if (player_it != players.end()) + { + if (pchPlayerName != nullptr) + player_it->second.name = pchPlayerName; + + player_it->second.score = uScore; + return true; + } + return false; } // You shouldn't need to call this as it is called internally by SteamGameServer_Init() and can only be called once. @@ -503,6 +564,13 @@ EBeginAuthSessionResult Steam_GameServer::BeginAuthSession( const void *pAuthTic PRINT_DEBUG("Steam_GameServer::BeginAuthSession %i %llu\n", cbAuthTicket, steamID.ConvertToUint64()); std::lock_guard lock(global_mutex); + std::pair infos; + infos.first = steamID; + infos.second.join_time = std::chrono::steady_clock::now(); + infos.second.score = 0; + infos.second.name = "unnamed"; + players.emplace_back(std::move(infos)); + return ticket_manager->beginAuth(pAuthTicket, cbAuthTicket, steamID ); } @@ -513,6 +581,16 @@ void Steam_GameServer::EndAuthSession( CSteamID steamID ) PRINT_DEBUG("Steam_GameServer::EndAuthSession %llu\n", steamID.ConvertToUint64()); std::lock_guard lock(global_mutex); + auto player_it = std::find_if(players.begin(), players.end(), [&steamID](std::pair& player) + { + return player.first == steamID; + }); + + if (player_it != players.end()) + { + players.erase(player_it); + } + ticket_manager->endAuth(steamID); } @@ -608,6 +686,18 @@ bool Steam_GameServer::HandleIncomingPacket( const void *pData, int cbData, uint { PRINT_DEBUG("HandleIncomingPacket %i %X %i\n", cbData, srcIP, srcPort); std::lock_guard lock(global_mutex); + if (settings->disable_source_query) return true; + + Gameserver_Outgoing_Packet packet; + packet.data = std::move(Source_Query::handle_source_query(pData, cbData, server_data)); + if (packet.data.empty()) + return false; + + + packet.ip = srcIP; + packet.port = srcPort; + + outgoing_packets.emplace_back(std::move(packet)); return true; } @@ -620,6 +710,7 @@ int Steam_GameServer::GetNextOutgoingPacket( void *pOut, int cbMaxOut, uint32 *p { PRINT_DEBUG("GetNextOutgoingPacket\n"); std::lock_guard lock(global_mutex); + if (settings->disable_source_query) return 0; if (outgoing_packets.size() == 0) return 0; if (outgoing_packets.back().data.size() < cbMaxOut) cbMaxOut = outgoing_packets.back().data.size(); @@ -743,6 +834,10 @@ void Steam_GameServer::RunCallbacks() msg.set_allocated_gameserver(new Gameserver(server_data)); msg.mutable_gameserver()->set_offline(true); network->sendToAllIndividuals(&msg, true); + // Shutdown Source Query + network->shutDownQuery(); + // And empty the queue if needed + outgoing_packets.clear(); } } } diff --git a/dll/steam_gameserver.h b/dll/steam_gameserver.h index 6cd9b708..9a963264 100644 --- a/dll/steam_gameserver.h +++ b/dll/steam_gameserver.h @@ -22,12 +22,18 @@ //----------------------------------------------------------------------------- struct Gameserver_Outgoing_Packet { - std::string data; + std::vector data; uint32 ip; uint16 port; }; +struct Gameserver_Player_Info_t { + std::chrono::steady_clock::time_point join_time; + std::string name; + uint32 score; +}; + class Steam_GameServer : public ISteamGameServer004, public ISteamGameServer005, @@ -50,6 +56,7 @@ public ISteamGameServer bool logged_in = false; bool call_servers_disconnected = false; Gameserver server_data; + std::vector> players; uint32 flags; bool policy_response_called; @@ -62,6 +69,9 @@ public: Steam_GameServer(class Settings *settings, class Networking *network, class SteamCallBacks *callbacks); ~Steam_GameServer(); + + std::vector>* get_players(); + // // Basic server data. These properties, if set, must be set before before calling LogOn. They // may not be changed after logged in. diff --git a/dll/steam_http.cpp b/dll/steam_http.cpp index 71bf5414..8205ed15 100644 --- a/dll/steam_http.cpp +++ b/dll/steam_http.cpp @@ -58,6 +58,40 @@ HTTPRequestHandle Steam_HTTP::CreateHTTPRequest( EHTTPMethod eHTTPRequestMethod, long long read = Local_Storage::get_file_data(file_path, (char *)request.response.data(), file_size, 0); if (read < 0) read = 0; if (read != file_size) request.response.resize(read); + } else if (!settings->disable_networking && settings->http_online) { + std::lock_guard lock(global_mutex); + + std::size_t url_directory = file_path.rfind("/"); + std::string directory_path; + std::string file_name; + if (url_directory != std::string::npos) { + directory_path = file_path.substr(0, url_directory); + file_name = file_path.substr(url_directory); + } + Local_Storage::store_file_data(directory_path, file_name, (char *)"", sizeof("")); + +#if defined(STEAM_WIN32) + FILE *hfile = fopen(file_path.c_str(), "wb"); +#else + FILE *hfile = fopen(file_path.c_str(), "w"); +#endif + CURL *chttp = curl_easy_init(); + curl_easy_setopt(chttp, CURLOPT_URL, url.c_str()); + curl_easy_setopt(chttp, CURLOPT_WRITEDATA, (void *)hfile); + curl_easy_setopt(chttp, CURLOPT_TIMEOUT, 60L); + curl_easy_setopt(chttp, CURLOPT_NOSIGNAL, 1L); + curl_easy_setopt(chttp, CURLOPT_USE_SSL, CURLUSESSL_TRY); + curl_easy_perform(chttp); + curl_easy_cleanup(chttp); + fclose(hfile); + + file_size = file_size_(file_path); + if (file_size) { + request.response.resize(file_size); + long long read = Local_Storage::get_file_data(file_path, (char *)request.response.data(), file_size, 0); + if (read < 0) read = 0; + if (read != file_size) request.response.resize(read); + } } } diff --git a/dll/steam_http.h b/dll/steam_http.h index 7e33f2ce..df70959c 100644 --- a/dll/steam_http.h +++ b/dll/steam_http.h @@ -16,6 +16,8 @@ . */ #include "base.h" +#include "common_includes.h" +#include struct Steam_Http_Request { diff --git a/dll/steam_matchmaking.h b/dll/steam_matchmaking.h index 94bd026b..4b4e811e 100644 --- a/dll/steam_matchmaking.h +++ b/dll/steam_matchmaking.h @@ -343,6 +343,16 @@ static Lobby_Member *get_lobby_member(Lobby *lobby, CSteamID user_id) int GetFavoriteGameCount() { PRINT_DEBUG("GetFavoriteGameCount\n"); + std::string file_path = Local_Storage::get_user_appdata_path() + "/7/" + Local_Storage::remote_storage_folder + "/serverbrowser_favorites.txt"; + unsigned long long file_size = file_size_(file_path); + if (file_size) { + std::string list; + list.resize(file_size); + Local_Storage::get_file_data(file_path, (char *)list.data(), file_size, 0); + auto list_lines = std::count(list.begin(), list.end(), '\n'); + list_lines += (!list.empty() && list.back() != '\n'); + return list_lines; + } return 0; } @@ -363,8 +373,72 @@ bool GetFavoriteGame( int iGame, AppId_t *pnAppID, uint32 *pnIP, uint16 *pnConnP int AddFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 nConnPort, uint16 nQueryPort, uint32 unFlags, uint32 rTime32LastPlayedOnServer ) { PRINT_DEBUG("AddFavoriteGame %lu %lu %hu %hu %lu %lu\n", nAppID, nIP, nConnPort, nQueryPort, unFlags, rTime32LastPlayedOnServer); - //TODO: what should this return? - return 0; + + std::string file_path; + unsigned long long file_size; + + if (unFlags == 1) { + file_path = Local_Storage::get_user_appdata_path() + "/7/" + Local_Storage::remote_storage_folder + "/serverbrowser_favorites.txt"; + file_size = file_size_(file_path); + } + else if (unFlags == 2) { + file_path = Local_Storage::get_user_appdata_path() + "/7/" + Local_Storage::remote_storage_folder + "/serverbrowser_history.txt"; + file_size = file_size_(file_path); + } + else { + return 0; + } + + unsigned char ip[4]; + ip[0] = nIP & 0xFF; + ip[1] = (nIP >> 8) & 0xFF; + ip[2] = (nIP >> 16) & 0xFF; + ip[3] = (nIP >> 24) & 0xFF; + char newip[24]; + snprintf(newip, sizeof(newip), "%d.%d.%d.%d:%d\n", ip[3], ip[2], ip[1], ip[0], nConnPort); + std::string newip_string; + newip_string.append(newip); + + if (file_size) { + std::string list; + list.resize(file_size); + Local_Storage::get_file_data(file_path, (char *)list.data(), file_size, 0); + auto list_lines = std::count(list.begin(), list.end(), '\n'); + list_lines += (!list.empty() && list.back() != '\n'); + + std::size_t find_ip = list.find(newip_string); + if (find_ip == std::string::npos) { + list.append(newip_string); + list.append("\n"); + + std::size_t file_directory = file_path.rfind("/"); + std::string directory_path; + std::string file_name; + if (file_directory != std::string::npos) { + directory_path = file_path.substr(0, file_directory); + file_name = file_path.substr(file_directory); + } + Local_Storage::store_file_data(directory_path, file_name, (char *)list.data(), list.size()); + + return ++list_lines; + } + + return list_lines; + } + else { + newip_string.append("\n"); + + std::size_t file_directory = file_path.rfind("/"); + std::string directory_path; + std::string file_name; + if (file_directory != std::string::npos) { + directory_path = file_path.substr(0, file_directory); + file_name = file_path.substr(file_directory); + } + Local_Storage::store_file_data(directory_path, file_name, (char *)newip_string.data(), newip_string.size()); + + return 1; + } } @@ -372,6 +446,54 @@ int AddFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 nConnPort, uint16 nQuery bool RemoveFavoriteGame( AppId_t nAppID, uint32 nIP, uint16 nConnPort, uint16 nQueryPort, uint32 unFlags ) { PRINT_DEBUG("RemoveFavoriteGame\n"); + + std::string file_path; + unsigned long long file_size; + + if (unFlags == 1) { + file_path = Local_Storage::get_user_appdata_path() + "/7/" + Local_Storage::remote_storage_folder + "/serverbrowser_favorites.txt"; + file_size = file_size_(file_path); + } + else if (unFlags == 2) { + file_path = Local_Storage::get_user_appdata_path() + "/7/" + Local_Storage::remote_storage_folder + "/serverbrowser_history.txt"; + file_size = file_size_(file_path); + } + else { + return false; + } + + if (file_size) { + std::string list; + list.resize(file_size); + Local_Storage::get_file_data(file_path, (char *)list.data(), file_size, 0); + + unsigned char ip[4]; + ip[0] = nIP & 0xFF; + ip[1] = (nIP >> 8) & 0xFF; + ip[2] = (nIP >> 16) & 0xFF; + ip[3] = (nIP >> 24) & 0xFF; + char newip[24]; + snprintf((char *)newip, sizeof(newip), "%d.%d.%d.%d:%d\n", ip[3], ip[2], ip[1], ip[0], nConnPort); + std::string newip_string; + newip_string.append(newip); + + std::size_t list_ip = list.find(newip_string); + if (list_ip != std::string::npos) { + list.erase(list_ip, newip_string.length()); + + std::size_t file_directory = file_path.rfind("/"); + std::string directory_path; + std::string file_name; + if (file_directory != std::string::npos) { + directory_path = file_path.substr(0, file_directory); + file_name = file_path.substr(file_directory); + } + Local_Storage::store_file_data(directory_path, file_name, (char *)list.data(), list.size()); + + return true; + } + } + return false; } diff --git a/dll/steam_matchmaking_servers.cpp b/dll/steam_matchmaking_servers.cpp index 23441f35..941fa058 100644 --- a/dll/steam_matchmaking_servers.cpp +++ b/dll/steam_matchmaking_servers.cpp @@ -35,19 +35,9 @@ Steam_Matchmaking_Servers::Steam_Matchmaking_Servers(class Settings *settings, c static int server_list_request; -// Request a new list of servers of a particular type. These calls each correspond to one of the EMatchMakingType values. -// Each call allocates a new asynchronous request object. -// Request object must be released by calling ReleaseRequest( hServerListRequest ) -HServerListRequest Steam_Matchmaking_Servers::RequestInternetServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) +HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse, EMatchMakingType type) { - PRINT_DEBUG("RequestInternetServerList\n"); - //TODO - return RequestLANServerList(iApp, pRequestServersResponse); -} - -HServerListRequest Steam_Matchmaking_Servers::RequestLANServerList( AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse ) -{ - PRINT_DEBUG("RequestLANServerList %u\n", iApp); + PRINT_DEBUG("RequestServerList %u\n", iApp); std::lock_guard lock(global_mutex); struct Steam_Matchmaking_Request request; request.appid = iApp; @@ -55,40 +45,135 @@ HServerListRequest Steam_Matchmaking_Servers::RequestLANServerList( AppId_t iApp request.old_callbacks = NULL; request.cancelled = false; request.completed = false; + request.type = type; requests.push_back(request); ++server_list_request; requests[requests.size() - 1].id = (void *)server_list_request; HServerListRequest id = requests[requests.size() - 1].id; PRINT_DEBUG("request id: %p\n", id); + + if (type == eLANServer) return id; + + if (type == eFriendsServer) { + for (auto &g : gameservers_friends) { + if (g.source_id != settings->get_local_steam_id().ConvertToUint64()) { + Gameserver server; + server.set_ip(g.ip); + server.set_port(g.port); + server.set_query_port(g.port); + server.set_appid(iApp); + + struct Steam_Matchmaking_Servers_Gameserver g2; + g2.last_recv = std::chrono::high_resolution_clock::now(); + g2.server = server; + g2.type = type; + gameservers.push_back(g2); + PRINT_DEBUG("SERVER ADDED\n"); + } + } + return id; + } + + std::string file_path; + unsigned long long file_size; + if (type == eInternetServer || type == eSpectatorServer) { + file_path = Local_Storage::get_user_appdata_path() + "/7/" + Local_Storage::remote_storage_folder + "/serverbrowser.txt"; + file_size = file_size_(file_path); + } else if (type == eFavoritesServer) { + file_path = Local_Storage::get_user_appdata_path() + "/7/" + Local_Storage::remote_storage_folder + "/serverbrowser_favorites.txt"; + file_size = file_size_(file_path); + } else if (type == eHistoryServer) { + file_path = Local_Storage::get_user_appdata_path() + "/7/" + Local_Storage::remote_storage_folder + "/serverbrowser_history.txt"; + file_size = file_size_(file_path); + } + + std::string list; + if (file_size) { + list.resize(file_size); + Local_Storage::get_file_data(file_path, (char *)list.data(), file_size, 0); + } else { + return id; + } + + std::istringstream list_ss (list); + std::string list_ip; + while (std::getline(list_ss, list_ip)) { + if (list_ip.length() < 0) continue; + + unsigned int byte4, byte3, byte2, byte1, byte0; + uint32 ip_int; + uint16 port_int; + char newip[24]; + if (sscanf(list_ip.c_str(), "%u.%u.%u.%u:%u", &byte3, &byte2, &byte1, &byte0, &byte4) == 5) { + ip_int = (byte3 << 24) + (byte2 << 16) + (byte1 << 8) + byte0; + port_int = byte4; + + unsigned char ip_tmp[4]; + ip_tmp[0] = ip_int & 0xFF; + ip_tmp[1] = (ip_int >> 8) & 0xFF; + ip_tmp[2] = (ip_int >> 16) & 0xFF; + ip_tmp[3] = (ip_int >> 24) & 0xFF; + snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip_tmp[3], ip_tmp[2], ip_tmp[1], ip_tmp[0]); + } else { + continue; + } + + Gameserver server; + server.set_ip(ip_int); + server.set_port(port_int); + server.set_query_port(port_int); + server.set_appid(iApp); + + struct Steam_Matchmaking_Servers_Gameserver g; + g.last_recv = std::chrono::high_resolution_clock::now(); + g.server = server; + g.type = type; + gameservers.push_back(g); + PRINT_DEBUG("SERVER ADDED\n"); + + list_ip = ""; + } + return id; } +// Request a new list of servers of a particular type. These calls each correspond to one of the EMatchMakingType values. +// Each call allocates a new asynchronous request object. +// Request object must be released by calling ReleaseRequest( hServerListRequest ) +HServerListRequest Steam_Matchmaking_Servers::RequestInternetServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) +{ + PRINT_DEBUG("RequestInternetServerList\n"); + return RequestServerList(iApp, pRequestServersResponse, eInternetServer); +} + +HServerListRequest Steam_Matchmaking_Servers::RequestLANServerList( AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse ) +{ + PRINT_DEBUG("RequestLANServerList\n"); + return RequestServerList(iApp, pRequestServersResponse, eLANServer); +} + HServerListRequest Steam_Matchmaking_Servers::RequestFriendsServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("RequestFriendsServerList\n"); - //TODO - return RequestLANServerList(iApp, pRequestServersResponse); + return RequestServerList(iApp, pRequestServersResponse, eFriendsServer); } HServerListRequest Steam_Matchmaking_Servers::RequestFavoritesServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("RequestFavoritesServerList\n"); - //TODO - return RequestLANServerList(iApp, pRequestServersResponse); + return RequestServerList(iApp, pRequestServersResponse, eFavoritesServer); } HServerListRequest Steam_Matchmaking_Servers::RequestHistoryServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("RequestHistoryServerList\n"); - //TODO - return RequestLANServerList(iApp, pRequestServersResponse); + return RequestServerList(iApp, pRequestServersResponse, eHistoryServer); } HServerListRequest Steam_Matchmaking_Servers::RequestSpectatorServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("RequestSpectatorServerList\n"); - //TODO - return RequestLANServerList(iApp, pRequestServersResponse); + return RequestServerList(iApp, pRequestServersResponse, eSpectatorServer); } void Steam_Matchmaking_Servers::RequestOldServerList(AppId_t iApp, ISteamMatchmakingServerListResponse001 *pRequestServersResponse, EMatchMakingType type) @@ -110,6 +195,7 @@ void Steam_Matchmaking_Servers::RequestOldServerList(AppId_t iApp, ISteamMatchma request.old_callbacks = pRequestServersResponse; request.cancelled = false; request.completed = false; + request.type = type; requests.push_back(request); requests[requests.size() - 1].id = (void *)type; } @@ -250,13 +336,70 @@ void Steam_Matchmaking_Servers::ReleaseRequest( HServerListRequest hServerListRe void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *server) { + long long latency = 10; + if (!(g->ip() < 0) && !(g->query_port() < 0)) { + unsigned char ip[4]; + char newip[24]; + ip[0] = g->ip() & 0xFF; + ip[1] = (g->ip() >> 8) & 0xFF; + ip[2] = (g->ip() >> 16) & 0xFF; + ip[3] = (g->ip() >> 24) & 0xFF; + snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); + + SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port()); + if (ssq != NULL && ssq_server_eok(ssq)) { + ssq_server_timeout(ssq, SSQ_TIMEOUT_RECV, 1200); + ssq_server_timeout(ssq, SSQ_TIMEOUT_SEND, 1200); + + std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); + A2S_INFO *ssq_a2s_info = ssq_info(ssq); + std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); + latency = std::chrono::duration_cast(t2 - t1).count(); + + if (ssq_server_eok(ssq)) { + if (ssq_info_has_steamid(ssq_a2s_info)) g->set_id(ssq_a2s_info->steamid); + g->set_game_description(ssq_a2s_info->game); + g->set_mod_dir(ssq_a2s_info->folder); + if (ssq_a2s_info->server_type == A2S_SERVER_TYPE_DEDICATED) g->set_dedicated_server(true); + else if (ssq_a2s_info->server_type == A2S_SERVER_TYPE_STV_RELAY) g->set_dedicated_server(true); + else g->set_dedicated_server(false); + g->set_max_player_count(ssq_a2s_info->max_players); + g->set_bot_player_count(ssq_a2s_info->bots); + g->set_server_name(ssq_a2s_info->name); + g->set_map_name(ssq_a2s_info->map); + if (ssq_a2s_info->visibility) g->set_password_protected(true); + else g->set_password_protected(false); + if (ssq_info_has_stv(ssq_a2s_info)) { + g->set_spectator_port(ssq_a2s_info->stv_port); + g->set_spectator_server_name(ssq_a2s_info->stv_name); + } + //g->set_tags(ssq_a2s_info->keywords); + //g->set_gamedata(); + //g->set_region(); + g->set_product(ssq_a2s_info->game); + if (ssq_a2s_info->vac) g->set_secure(true); + else g->set_secure(false); + g->set_num_players(ssq_a2s_info->players); + g->set_version(std::stoull(ssq_a2s_info->version, NULL, 0)); + if (ssq_info_has_port(ssq_a2s_info)) g->set_port(ssq_a2s_info->port); + if (ssq_info_has_gameid(ssq_a2s_info)) g->set_appid(ssq_a2s_info->gameid); + else g->set_appid(ssq_a2s_info->id); + g->set_offline(false); + } + + if (ssq_a2s_info != NULL) ssq_info_free(ssq_a2s_info); + } + + if (ssq != NULL) ssq_server_free(ssq); + } + uint16 query_port = g->query_port(); if (g->query_port() == 0xFFFF) { query_port = g->port(); } server->m_NetAdr.Init(g->ip(), query_port, g->port()); - server->m_nPing = 10; //TODO + server->m_nPing = latency; server->m_bHadSuccessfulResponse = true; server->m_bDoNotRefresh = false; strncpy(server->m_szGameDir, g->mod_dir().c_str(), k_cbMaxGameServerGameDir - 1); @@ -283,6 +426,74 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t * server->m_szGameTags[k_cbMaxGameServerTags - 1] = 0; } +void Steam_Matchmaking_Servers::server_details_players(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r) +{ + if (!(g->ip() < 0) && !(g->query_port() < 0)) { + unsigned char ip[4]; + char newip[24]; + ip[0] = g->ip() & 0xFF; + ip[1] = (g->ip() >> 8) & 0xFF; + ip[2] = (g->ip() >> 16) & 0xFF; + ip[3] = (g->ip() >> 24) & 0xFF; + snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); + + SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port()); + if (ssq != NULL && ssq_server_eok(ssq)) { + ssq_server_timeout(ssq, SSQ_TIMEOUT_RECV, 1200); + ssq_server_timeout(ssq, SSQ_TIMEOUT_SEND, 1200); + + uint8_t ssq_a2s_player_count; + A2S_PLAYER *ssq_a2s_player = ssq_player(ssq, &ssq_a2s_player_count); + + if (ssq_server_eok(ssq)) { + for (int i = 0; i < ssq_a2s_player_count; i++) { + r->players_response->AddPlayerToList(ssq_a2s_player[i].name, ssq_a2s_player[i].score, ssq_a2s_player[i].duration); + } + } + + if (ssq_a2s_player != NULL) ssq_player_free(ssq_a2s_player, ssq_a2s_player_count); + } + + if (ssq != NULL) ssq_server_free(ssq); + } + + PRINT_DEBUG("server_details_players %llu\n", g->id()); +} + +void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r) +{ + if (!(g->ip() < 0) && !(g->query_port() < 0)) { + unsigned char ip[4]; + char newip[24]; + ip[0] = g->ip() & 0xFF; + ip[1] = (g->ip() >> 8) & 0xFF; + ip[2] = (g->ip() >> 16) & 0xFF; + ip[3] = (g->ip() >> 24) & 0xFF; + snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); + + SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port()); + if (ssq != NULL && ssq_server_eok(ssq)) { + ssq_server_timeout(ssq, SSQ_TIMEOUT_RECV, 1200); + ssq_server_timeout(ssq, SSQ_TIMEOUT_SEND, 1200); + + uint16_t ssq_a2s_rules_count; + A2S_RULES *ssq_a2s_rules = ssq_rules(ssq, &ssq_a2s_rules_count); + + if (ssq_server_eok(ssq)) { + for (int i = 0; i < ssq_a2s_rules_count; i++) { + r->rules_response->RulesResponded(ssq_a2s_rules[i].name, ssq_a2s_rules[i].value); + } + } + + if (ssq_a2s_rules != NULL) ssq_rules_free(ssq_a2s_rules, ssq_a2s_rules_count); + } + + if (ssq != NULL) ssq_server_free(ssq); + } + + PRINT_DEBUG("server_details_rules %llu\n", g->id()); +} + // Get details on a given server in the list, you can get the valid range of index // values by calling GetServerCount(). You will also receive index values in // ISteamMatchmakingServerListResponse::ServerResponded() callbacks @@ -477,7 +688,7 @@ void Steam_Matchmaking_Servers::RunCallbacks() r.gameservers_filtered.clear(); for (auto &g : gameservers) { PRINT_DEBUG("game_server_check %u %u\n", g.server.appid(), r.appid); - if (g.server.appid() == r.appid) { + if ((g.server.appid() == r.appid) && (g.type == r.type)) { PRINT_DEBUG("REQUESTS server found\n"); r.gameservers_filtered.push_back(g); } @@ -545,31 +756,27 @@ void Steam_Matchmaking_Servers::RunCallbacks() if (query_port == r.port && g.server.ip() == r.ip) { if (r.rules_response) { - int number_rules = g.server.values().size(); - PRINT_DEBUG("rules: %lu\n", number_rules); - auto rule = g.server.values().begin(); - for (int i = 0; i < number_rules; ++i) { - PRINT_DEBUG("RULE %s %s\n", rule->first.c_str(), rule->second.c_str()); - r.rules_response->RulesResponded(rule->first.c_str(), rule->second.c_str()); - ++rule; - } - + server_details_rules(&(g.server), &r); r.rules_response->RulesRefreshComplete(); r.rules_response = NULL; } + if (r.players_response) { + server_details_players(&(g.server), &r); + r.players_response->PlayersRefreshComplete(); + r.players_response = NULL; + } + if (r.ping_response) { gameserveritem_t server; server_details(&(g.server), &server); r.ping_response->ServerResponded(server); r.ping_response = NULL; } - //TODO: players response } } if (r.rules_response) r.rules_response->RulesRefreshComplete(); - //TODO: player response if (r.players_response) r.players_response->PlayersRefreshComplete(); if (r.ping_response) r.ping_response->ServerFailedToRespond(); } @@ -577,12 +784,13 @@ void Steam_Matchmaking_Servers::RunCallbacks() void Steam_Matchmaking_Servers::Callback(Common_Message *msg) { - if (msg->has_gameserver()) { + if (msg->has_gameserver() && msg->gameserver().type() != eFriendsServer) { PRINT_DEBUG("got SERVER %llu, offline:%u\n", msg->gameserver().id(), msg->gameserver().offline()); if (msg->gameserver().offline()) { for (auto &g : gameservers) { if (g.server.id() == msg->gameserver().id()) { g.last_recv = std::chrono::high_resolution_clock::time_point(); + g.type = eLANServer; } } } else { @@ -592,6 +800,7 @@ void Steam_Matchmaking_Servers::Callback(Common_Message *msg) g.last_recv = std::chrono::high_resolution_clock::now(); g.server = msg->gameserver(); g.server.set_ip(msg->source_ip()); + g.type = eLANServer; already = true; } } @@ -601,9 +810,31 @@ void Steam_Matchmaking_Servers::Callback(Common_Message *msg) g.last_recv = std::chrono::high_resolution_clock::now(); g.server = msg->gameserver(); g.server.set_ip(msg->source_ip()); + g.type = eLANServer; gameservers.push_back(g); PRINT_DEBUG("SERVER ADDED\n"); } } } + + if (msg->has_gameserver() && msg->gameserver().type() == eFriendsServer) { + bool addserver = true; + for (auto &g : gameservers_friends) { + if (g.source_id == msg->source_id()) { + g.ip = msg->gameserver().ip(); + g.port = msg->gameserver().port(); + g.last_recv = std::chrono::high_resolution_clock::now(); + addserver = false; + } + } + + if (addserver) { + struct Steam_Matchmaking_Servers_Gameserver_Friends gameserver_friend; + gameserver_friend.source_id = msg->source_id(); + gameserver_friend.ip = msg->gameserver().ip(); + gameserver_friend.port = msg->gameserver().port(); + gameserver_friend.last_recv = std::chrono::high_resolution_clock::now(); + gameservers_friends.push_back(gameserver_friend); + } + } } diff --git a/dll/steam_matchmaking_servers.h b/dll/steam_matchmaking_servers.h index 21a643fa..91248893 100644 --- a/dll/steam_matchmaking_servers.h +++ b/dll/steam_matchmaking_servers.h @@ -16,6 +16,7 @@ . */ #include "base.h" +#include #define SERVER_TIMEOUT 10.0 #define DIRECT_IP_DELAY 0.05 @@ -31,9 +32,17 @@ struct Steam_Matchmaking_Servers_Direct_IP_Request { ISteamMatchmakingPingResponse *ping_response = NULL; }; +struct Steam_Matchmaking_Servers_Gameserver_Friends { + uint64 source_id; + uint32 ip; + uint16 port; + std::chrono::high_resolution_clock::time_point last_recv; +}; + struct Steam_Matchmaking_Servers_Gameserver { Gameserver server; std::chrono::high_resolution_clock::time_point last_recv; + EMatchMakingType type; }; struct Steam_Matchmaking_Request { @@ -43,6 +52,7 @@ struct Steam_Matchmaking_Request { ISteamMatchmakingServerListResponse001 *old_callbacks; bool completed, cancelled, released; std::vector gameservers_filtered; + EMatchMakingType type; }; class Steam_Matchmaking_Servers : public ISteamMatchmakingServers, @@ -52,8 +62,10 @@ public ISteamMatchmakingServers001 class Networking *network; std::vector gameservers; + std::vector gameservers_friends; std::vector requests; std::vector direct_ip_requests; + HServerListRequest RequestServerList(AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse, EMatchMakingType type); void RequestOldServerList(AppId_t iApp, ISteamMatchmakingServerListResponse001 *pRequestServersResponse, EMatchMakingType type); public: Steam_Matchmaking_Servers(class Settings *settings, class Networking *network); @@ -222,4 +234,6 @@ public: void RunCallbacks(); void Callback(Common_Message *msg); void server_details(Gameserver *g, gameserveritem_t *server); + void server_details_players(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r); + void server_details_rules(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r); }; diff --git a/dll/steam_ugc.h b/dll/steam_ugc.h index b1ada44f..53171dcd 100644 --- a/dll/steam_ugc.h +++ b/dll/steam_ugc.h @@ -69,11 +69,28 @@ void set_details(PublishedFileId_t id, SteamUGCDetails_t *pDetails) if (settings->isModInstalled(id)) { pDetails->m_eResult = k_EResultOK; pDetails->m_nPublishedFileId = id; - pDetails->m_eFileType = k_EWorkshopFileTypeCommunity; pDetails->m_nCreatorAppID = settings->get_local_game_id().AppID(); pDetails->m_nConsumerAppID = settings->get_local_game_id().AppID(); - snprintf(pDetails->m_rgchTitle, sizeof(pDetails->m_rgchDescription), "%s", settings->getMod(id).title.c_str()); - //TODO + snprintf(pDetails->m_rgchTitle, k_cchPublishedDocumentTitleMax, "%s", settings->getMod(id).title.c_str()); + pDetails->m_eFileType = settings->getMod(id).fileType; + snprintf(pDetails->m_rgchDescription, k_cchPublishedDocumentDescriptionMax, "%s", settings->getMod(id).description.c_str()); + pDetails->m_ulSteamIDOwner = settings->get_local_steam_id().ConvertToUint64(); + pDetails->m_rtimeCreated = settings->getMod(id).timeCreated; + pDetails->m_rtimeUpdated = settings->getMod(id).timeUpdated; + pDetails->m_rtimeAddedToUserList = settings->getMod(id).timeAddedToUserList; + pDetails->m_eVisibility = settings->getMod(id).visibility; + pDetails->m_bBanned = settings->getMod(id).banned; + pDetails->m_bAcceptedForUse = settings->getMod(id).acceptedForUse; + pDetails->m_bTagsTruncated = settings->getMod(id).tagsTruncated; + snprintf(pDetails->m_rgchTags, k_cchTagListMax, "%s", settings->getMod(id).tags.c_str()); + snprintf(pDetails->m_pchFileName, k_cchFilenameMax, "%s", settings->getMod(id).primaryFileName.c_str()); + pDetails->m_nFileSize = settings->getMod(id).primaryFileSize; + pDetails->m_nPreviewFileSize = settings->getMod(id).previewFileSize; + snprintf(pDetails->m_rgchURL, k_cchPublishedFileURLMax, "%s", settings->getMod(id).workshopItemURL.c_str()); + pDetails->m_unVotesUp = settings->getMod(id).votesUp; + pDetails->m_unVotesDown = settings->getMod(id).votesDown; + pDetails->m_flScore = settings->getMod(id).score; + //pDetails->m_unNumChildren = settings->getMod(id).numChildren; } else { pDetails->m_nPublishedFileId = id; pDetails->m_eResult = k_EResultFail; @@ -205,7 +222,18 @@ bool GetQueryUGCTagDisplayName( UGCQueryHandle_t handle, uint32 index, uint32 in bool GetQueryUGCPreviewURL( UGCQueryHandle_t handle, uint32 index, STEAM_OUT_STRING_COUNT(cchURLSize) char *pchURL, uint32 cchURLSize ) { PRINT_DEBUG("Steam_UGC::GetQueryUGCPreviewURL\n"); + std::lock_guard lock(global_mutex); //TODO: escape simulator tries downloading this url and unsubscribes if it fails + + auto request = std::find_if(ugc_queries.begin(), ugc_queries.end(), [&handle](struct UGC_query const& item) { return item.handle == handle; }); + if ((ugc_queries.end() != request) && !(index >= request->results.size())) { + auto it = request->results.begin(); + uint32 it2 = (uint32)*it; + PRINT_DEBUG("Steam_UGC:GetQueryUGCPreviewURL: %u %s\n", it2, settings->getMod(it2).previewURL.c_str()); + snprintf(pchURL, cchURLSize, "%s", settings->getMod(it2).previewURL.c_str()); + return true; + } + return false; } @@ -600,13 +628,13 @@ bool RemoveItemPreview( UGCUpdateHandle_t handle, uint32 index ) bool AddContentDescriptor( UGCUpdateHandle_t handle, EUGCContentDescriptorID descid ) { - PRINT_DEBUG("Steam_UGC::AddContentDescriptor %llu %u\n", handle, index); + PRINT_DEBUG("Steam_UGC::AddContentDescriptor %llu %u\n", handle, descid); return false; } bool RemoveContentDescriptor( UGCUpdateHandle_t handle, EUGCContentDescriptorID descid ) { - PRINT_DEBUG("Steam_UGC::RemoveContentDescriptor %llu %u\n", handle, index); + PRINT_DEBUG("Steam_UGC::RemoveContentDescriptor %llu %u\n", handle, descid); return false; } @@ -743,8 +771,8 @@ bool GetItemInstallInfo( PublishedFileId_t nPublishedFileID, uint64 *punSizeOnDi return false; } - if (punSizeOnDisk) *punSizeOnDisk = 1000000; - if (punTimeStamp) *punTimeStamp = 1554997000; + if (punSizeOnDisk) *punSizeOnDisk = settings->getMod(nPublishedFileID).primaryFileSize; + if (punTimeStamp) *punTimeStamp = settings->getMod(nPublishedFileID).timeCreated; if (pchFolder && cchFolderSize) { snprintf(pchFolder, cchFolderSize, "%s", settings->getMod(nPublishedFileID).path.c_str()); } diff --git a/dll/steam_user.h b/dll/steam_user.h index 07c93e2f..0a03a78f 100644 --- a/dll/steam_user.h +++ b/dll/steam_user.h @@ -375,6 +375,18 @@ bool BIsBehindNAT() void AdvertiseGame( CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer ) { PRINT_DEBUG("AdvertiseGame\n"); + std::lock_guard lock(global_mutex); + Gameserver *server = new Gameserver(); + server->set_id(steamIDGameServer.ConvertToUint64()); + server->set_ip(unIPServer); + server->set_port(usPortServer); + server->set_query_port(usPortServer); + server->set_appid(settings->get_local_game_id().ToUint64()); + server->set_type(eFriendsServer); + Common_Message msg; + msg.set_allocated_gameserver(server); + msg.set_source_id(settings->get_local_steam_id().ConvertToUint64()); + network->sendToAllIndividuals(&msg, true); } // Requests a ticket encrypted with an app specific shared key diff --git a/files_example/steam_settings.EXAMPLE/account_avatar.EXAMPLE.jpg b/files_example/steam_settings.EXAMPLE/account_avatar.EXAMPLE.jpg new file mode 100644 index 0000000000000000000000000000000000000000..aa490cb4ea49d648b7d333c98c8f2acd01695589 GIT binary patch literal 3409 zcmd^>do+~m9>I(WdrhTpE(&xMjvATkawxg`!@CF1AausY4+u z(#DbN5R(vUmo`btA@@rS#&rxc?|$ulc87ib*=MiTI_s?SyzBR_^{(H$zR&Y{e&65w zKJZ)k1CTgqY-$WpC;(8%1z-XA+Q^z_aLB@XAIZyI!{@k%7b$q>_8lbhsi33&UL@0l zCZvOwG!s(rSG&}U=bg)NG*aw_sNGNf%Jm9463>S`MmHFju_cWfc6k(WhKI2?|EC#)k7 z){$jpWXb>WfFA=%Jg5K_Xp}M#l0=~;QE)v_L?DGxzYOrtff7O^>&4+k2y2iRN+p00 z3XK-RpoN7o8077GdoL&Ve%{04lG3vB3TEY#y84EvjZMwZTH9W?zv+0} z`L4IGe_(KEcw}^pGc`RkJ2%f=;4O2Z0Qy%fJ{fXIAa&pYj&>BS%zK#oh^?W_Sx7z~^; zU|_h19-#qw_dqS|7Ct|Klf7uXD1iK-iH}g6ZPx!|N^9ohduHhx?|aPj1KqZC`qirj zD%~;pcVN&&e=ev}6-1FU(R3JG&7a^0LwtO@L+Jyki9Ro=q6(sX@&VC`_J_iu6&j#; zAXP|0sz9{*llqR|5+`d4`||hOd#5CP9lKF}GEtoFUpK2;tiPdz(Yk3P7j@4-%Ct|{ z*taUyy}|c#Kdz$7z>~*u@>!CfRL{lj-)3U%Kimw1#u4;@I%RBa&ci9N0N3^V0(BglcG>7gih5XdBp7<5zsrgtgB2n427yv? z)Z~52;7Me~sR|6soM$_!GfFfdTfP(>0DUZm!H98Qd%mNNCG%Dn5h>u*BsUm-q5z{ziNp$N{3g35ceF&;@!85U7<;bD{i*v73Dsv9}YXr+{+t^&>PJiKN2(6Z5DPTJ5}V+gGS{G zKj3RIA=1;Db>gvS(vzXJ2{GH@J{xWr~_3;^hjrQxWYU?XkUNP?c8gHi*9Fa*mTU+O_WeXzH}jqFG>b~P5JJOlg*Op z=&l2iC;HoTR7QOJ-T`t}%;zXw>6&cQWm8_~2V3y*R{Gfdvt=EEb1pEbY2(J-@c&dy#rMGew!x!0z<;_rcbUa-!e!ILhZm=S`KJaPe zmbd9Z;iWmv*+}rR8#SfuEIsy0Fh^5d!E!}_T zbs_GeRG%P=GY^Z2}pr{>tb3^h`-tBiR-tEBoNH#BXv6;&tq`;imoODyB(# z=Jj-Zm3sVR zG0Hz6pR{sw&AK-(mrXrWU8}FqEJYB{y$EOj+Zw+lZbz-TLnDnF?G~2T)#&G)_@k`7 z4!F^zc)##2)a$|37F?85TpWQxbhrx*gi+aYeSUKF&XWm{tIv+^1x4@a@P~hW(M|8- z2$~BwtZ2#K+VhJ!a)ugl+$e~nZ4om>9*k|=siu4pH}4)#8Do8Nq6p5XP`P5PUT4)M zQC4x=xy^Qm$FzgzQl87#-c2`<6>=j9)ko|t%%%43nJnjvR;mg_m0{4Ai+)P=p-{}I zT;p@iexhA-)=FQ3)z+hz1}qS|5#M+ru8p%@CGvaGmCygh z2~b{E53ABFnJIEd2jT`j>2}Q+sk3?IbEoE)77oLp2k8O=aw=Hdwdo+~m9>I(WdrhTpE(&xMjvATkawxg`!@CF1AausY4+u z(#DbN5R(vUmo`btA@@rS#&rxc?|$ulc87ib*=MiTI_s?SyzBR_^{(H$zR&Y{e&65w zKJZ)k1CTgqY-$WpC;(8%1z-XA+Q^z_aLB@XAIZyI!{@k%7b$q>_8lbhsi33&UL@0l zCZvOwG!s(rSG&}U=bg)NG*aw_sNGNf%Jm9463>S`MmHFju_cWfc6k(WhKI2?|EC#)k7 z){$jpWXb>WfFA=%Jg5K_Xp}M#l0=~;QE)v_L?DGxzYOrtff7O^>&4+k2y2iRN+p00 z3XK-RpoN7o8077GdoL&Ve%{04lG3vB3TEY#y84EvjZMwZTH9W?zv+0} z`L4IGe_(KEcw}^pGc`RkJ2%f=;4O2Z0Qy%fJ{fXIAa&pYj&>BS%zK#oh^?W_Sx7z~^; zU|_h19-#qw_dqS|7Ct|Klf7uXD1iK-iH}g6ZPx!|N^9ohduHhx?|aPj1KqZC`qirj zD%~;pcVN&&e=ev}6-1FU(R3JG&7a^0LwtO@L+Jyki9Ro=q6(sX@&VC`_J_iu6&j#; zAXP|0sz9{*llqR|5+`d4`||hOd#5CP9lKF}GEtoFUpK2;tiPdz(Yk3P7j@4-%Ct|{ z*taUyy}|c#Kdz$7z>~*u@>!CfRL{lj-)3U%Kimw1#u4;@I%RBa&ci9N0N3^V0(BglcG>7gih5XdBp7<5zsrgtgB2n427yv? z)Z~52;7Me~sR|6soM$_!GfFfdTfP(>0DUZm!H98Qd%mNNCG%Dn5h>u*BsUm-q5z{ziNp$N{3g35ceF&;@!85U7<;bD{i*v73Dsv9}YXr+{+t^&>PJiKN2(6Z5DPTJ5}V+gGS{G zKj3RIA=1;Db>gvS(vzXJ2{GH@J{xWr~_3;^hjrQxWYU?XkUNP?c8gHi*9Fa*mTU+O_WeXzH}jqFG>b~P5JJOlg*Op z=&l2iC;HoTR7QOJ-T`t}%;zXw>6&cQWm8_~2V3y*R{Gfdvt=EEb1pEbY2(J-@c&dy#rMGew!x!0z<;_rcbUa-!e!ILhZm=S`KJaPe zmbd9Z;iWmv*+}rR8#SfuEIsy0Fh^5d!E!}_T zbs_GeRG%P=GY^Z2}pr{>tb3^h`-tBiR-tEBoNH#BXv6;&tq`;imoODyB(# z=Jj-Zm3sVR zG0Hz6pR{sw&AK-(mrXrWU8}FqEJYB{y$EOj+Zw+lZbz-TLnDnF?G~2T)#&G)_@k`7 z4!F^zc)##2)a$|37F?85TpWQxbhrx*gi+aYeSUKF&XWm{tIv+^1x4@a@P~hW(M|8- z2$~BwtZ2#K+VhJ!a)ugl+$e~nZ4om>9*k|=siu4pH}4)#8Do8Nq6p5XP`P5PUT4)M zQC4x=xy^Qm$FzgzQl87#-c2`<6>=j9)ko|t%%%43nJnjvR;mg_m0{4Ai+)P=p-{}I zT;p@iexhA-)=FQ3)z+hz1}qS|5#M+ru8p%@CGvaGmCygh z2~b{E53ABFnJIEd2jT`j>2}Q+sk3?IbEoE)77oLp2k8O=aw=Hdw lock(notifications_mutex); - int id = find_free_notification_id(notifications); - if (id != 0) - { - Notification notif; - notif.id = id; - notif.type = notification_type_achievement; - // Load achievement image - notif.message = ach["displayName"].get() + "\n" + ach["description"].get(); - notif.start_time = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); - notifications.emplace_back(notif); - have_notifications = true; + if (!settings->disable_overlay_achievement_notification) { + int id = find_free_notification_id(notifications); + if (id != 0) + { + Notification notif; + notif.id = id; + notif.type = notification_type_achievement; + // Load achievement image + notif.message = ach["displayName"].get() + "\n" + ach["description"].get(); + notif.start_time = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()); + notifications.emplace_back(notif); + have_notifications = true; + } + else + PRINT_DEBUG("No more free id to create a notification window\n"); } - else - PRINT_DEBUG("No more free id to create a notification window\n"); std::string ach_name = ach.value("name", ""); for (auto &a : achievements) { @@ -453,7 +456,11 @@ void Steam_Overlay::AddInviteNotification(std::pair(std::chrono::system_clock::now().time_since_epoch()); notifications.emplace_back(notif); have_notifications = true; @@ -495,7 +502,7 @@ void Steam_Overlay::BuildContextMenu(Friend const& frd, friend_window_state& sta { bool close_popup = false; - if (ImGui::Button("Chat")) + if (ImGui::Button(translationChat[current_language])) { state.window_state |= window_state_show; close_popup = true; @@ -503,13 +510,20 @@ void Steam_Overlay::BuildContextMenu(Friend const& frd, friend_window_state& sta // If we have the same appid, activate the invite/join buttons if (settings->get_local_game_id().AppID() == frd.appid()) { - if (i_have_lobby && ImGui::Button("Invite###PopupInvite")) + std::string translationInvite_tmp; + std::string translationJoin_tmp; + translationInvite_tmp.append(translationInvite[current_language]); + translationInvite_tmp.append("##PopupInvite"); + translationJoin_tmp.append(translationJoin[current_language]); + translationJoin_tmp.append("##PopupInvite"); + + if (i_have_lobby && ImGui::Button(translationInvite_tmp.c_str())) { state.window_state |= window_state_invite; has_friend_action.push(frd); close_popup = true; } - if (state.joinable && ImGui::Button("Join###PopupJoin")) + if (state.joinable && ImGui::Button(translationJoin_tmp.c_str())) { state.window_state |= window_state_join; has_friend_action.push(frd); @@ -554,15 +568,15 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st // Fill this with the chat box and maybe the invitation if (state.window_state & (window_state_lobby_invite | window_state_rich_invite)) { - ImGui::LabelText("##label", "%s invited you to join the game.", frd.name().c_str()); + ImGui::LabelText("##label", translationInvitedYouToJoinTheGame[current_language], frd.name().c_str(), frd.appid()); ImGui::SameLine(); - if (ImGui::Button("Accept")) + if (ImGui::Button(translationAccept[current_language])) { state.window_state |= window_state_join; this->has_friend_action.push(frd); } ImGui::SameLine(); - if (ImGui::Button("Refuse")) + if (ImGui::Button(translationRefuse[current_language])) { state.window_state &= ~(window_state_lobby_invite | window_state_rich_invite); } @@ -591,7 +605,7 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st // |------------------------------| float wnd_width = ImGui::GetWindowContentRegionWidth(); ImGuiStyle &style = ImGui::GetStyle(); - wnd_width -= ImGui::CalcTextSize("Send").x + style.FramePadding.x * 2 + style.ItemSpacing.x + 1; + wnd_width -= ImGui::CalcTextSize(translationSend[current_language]).x + style.FramePadding.x * 2 + style.ItemSpacing.x + 1; ImGui::PushItemWidth(wnd_width); if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue)) @@ -603,7 +617,7 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st ImGui::SameLine(); - if (ImGui::Button("Send")) + if (ImGui::Button(translationSend[current_language])) { send_chat_msg = true; } @@ -677,7 +691,7 @@ void Steam_Overlay::BuildNotifications(int width, int height) case notification_type_invite: { ImGui::TextWrapped("%s", it->message.c_str()); - if (ImGui::Button("Join")) + if (ImGui::Button(translationJoin[current_language])) { it->frd->second.window_state |= window_state_join; friend_actions_temp.push(it->frd->first); @@ -727,6 +741,43 @@ void Steam_Overlay::CreateFonts() font_builder.AddText(x.title.c_str()); font_builder.AddText(x.description.c_str()); } + for (int i = 0; i < TRANSLATION_NUMBER_OF_LANGUAGES; i++) { + font_builder.AddText(translationChat[i]); + font_builder.AddText(translationInvite[i]); + font_builder.AddText(translationJoin[i]); + font_builder.AddText(translationInvitedYouToJoinTheGame[i]); + font_builder.AddText(translationAccept[i]); + font_builder.AddText(translationRefuse[i]); + font_builder.AddText(translationSend[i]); + font_builder.AddText(translationSteamOverlay[i]); + font_builder.AddText(translationUserPlaying[i]); + font_builder.AddText(translationRenderer[i]); + font_builder.AddText(translationShowAchievements[i]); + font_builder.AddText(translationSettings[i]); + font_builder.AddText(translationFriends[i]); + font_builder.AddText(translationAchievementWindow[i]); + font_builder.AddText(translationListOfAchievements[i]); + font_builder.AddText(translationAchievements[i]); + font_builder.AddText(translationHiddenAchievement[i]); + font_builder.AddText(translationAchievedOn[i]); + font_builder.AddText(translationNotAchieved[i]); + font_builder.AddText(translationGlobalSettingsWindow[i]); + font_builder.AddText(translationGlobalSettingsWindowDescription[i]); + font_builder.AddText(translationUsername[i]); + font_builder.AddText(translationLanguage[i]); + font_builder.AddText(translationSelectedLanguage[i]); + font_builder.AddText(translationRestartTheGameToApply[i]); + font_builder.AddText(translationSave[i]); + font_builder.AddText(translationWarning[i]); + font_builder.AddText(translationWarningWarningWarning[i]); + font_builder.AddText(translationWarningDescription1[i]); + font_builder.AddText(translationWarningDescription2[i]); + font_builder.AddText(translationWarningDescription3[i]); + font_builder.AddText(translationWarningDescription4[i]); + font_builder.AddText(translationSteamOverlayURL[i]); + font_builder.AddText(translationClose[i]); + font_builder.AddText(translationPlaying[i]); + } font_builder.AddRanges(Fonts->GetGlyphRangesDefault()); @@ -799,31 +850,31 @@ void Steam_Overlay::OverlayProc() bool show = true; - if (ImGui::Begin("SteamOverlay", &show, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus)) + if (ImGui::Begin(translationSteamOverlay[current_language], &show, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus)) { - ImGui::LabelText("##label", "Username: %s(%llu) playing %u", + ImGui::LabelText("##label", translationUserPlaying[current_language], settings->get_local_name(), settings->get_local_steam_id().ConvertToUint64(), settings->get_local_game_id().AppID()); ImGui::SameLine(); - ImGui::LabelText("##label", "Renderer: %s", (_renderer == nullptr ? "Unknown" : _renderer->GetLibraryName().c_str())); + ImGui::LabelText("##label", translationRenderer[current_language], (_renderer == nullptr ? "Unknown" : _renderer->GetLibraryName().c_str())); ImGui::Spacing(); - if (ImGui::Button("Show Achievements")) { + if (ImGui::Button(translationShowAchievements[current_language])) { show_achievements = true; } ImGui::SameLine(); - if (ImGui::Button("Settings")) { + if (ImGui::Button(translationSettings[current_language])) { show_settings = true; } ImGui::Spacing(); ImGui::Spacing(); - ImGui::LabelText("##label", "Friends"); + ImGui::LabelText("##label", translationFriends[current_language]); std::lock_guard lock(overlay_mutex); if (!friends.empty()) @@ -851,9 +902,9 @@ void Steam_Overlay::OverlayProc() if (show_achievements && achievements.size()) { ImGui::SetNextWindowSizeConstraints(ImVec2(ImGui::GetFontSize() * 32, ImGui::GetFontSize() * 32), ImVec2(8192, 8192)); bool show = show_achievements; - if (ImGui::Begin("Achievement Window", &show)) { - ImGui::Text("List of achievements"); - ImGui::BeginChild("Achievements"); + if (ImGui::Begin(translationAchievementWindow[current_language], &show)) { + ImGui::Text(translationListOfAchievements[current_language]); + ImGui::BeginChild(translationAchievements[current_language]); for (auto & x : achievements) { bool achieved = x.achieved; bool hidden = x.hidden && !achieved; @@ -861,7 +912,7 @@ void Steam_Overlay::OverlayProc() ImGui::Separator(); ImGui::Text("%s", x.title.c_str()); if (hidden) { - ImGui::Text("hidden achievement"); + ImGui::Text(translationHiddenAchievement[current_language]); } else { ImGui::TextWrapped("%s", x.description.c_str()); } @@ -871,9 +922,9 @@ void Steam_Overlay::OverlayProc() time_t unlock_time = (time_t)x.unlock_time; std::strftime(buffer, 80, "%Y-%m-%d at %H:%M:%S", std::localtime(&unlock_time)); - ImGui::TextColored(ImVec4(0, 255, 0, 255), "achieved on %s", buffer); + ImGui::TextColored(ImVec4(0, 255, 0, 255), translationAchievedOn[current_language], buffer); } else { - ImGui::TextColored(ImVec4(255, 0, 0, 255), "not achieved"); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationNotAchieved[current_language]); } ImGui::Separator(); } @@ -884,37 +935,37 @@ void Steam_Overlay::OverlayProc() } if (show_settings) { - if (ImGui::Begin("Global Settings Window", &show_settings)) { - ImGui::Text("These are global emulator settings and will apply to all games."); + if (ImGui::Begin(translationGlobalSettingsWindow[current_language], &show_settings)) { + ImGui::Text(translationGlobalSettingsWindowDescription[current_language]); ImGui::Separator(); - ImGui::Text("Username:"); + ImGui::Text(translationUsername[current_language]); ImGui::SameLine(); ImGui::InputText("##username", username_text, sizeof(username_text), disable_forced ? ImGuiInputTextFlags_ReadOnly : 0); ImGui::Separator(); - ImGui::Text("Language:"); + ImGui::Text(translationLanguage[current_language]); if (ImGui::ListBox("##language", ¤t_language, valid_languages, sizeof(valid_languages) / sizeof(char *), 7)) { } - ImGui::Text("Selected Language: %s", valid_languages[current_language]); + ImGui::Text(translationSelectedLanguage[current_language], valid_languages[current_language]); ImGui::Separator(); if (!disable_forced) { - ImGui::Text("You may have to restart the game for these to apply."); - if (ImGui::Button("Save")) { + ImGui::Text(translationRestartTheGameToApply[current_language]); + if (ImGui::Button(translationSave[current_language])) { save_settings = true; show_settings = false; } } else { - ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); - ImGui::TextWrapped("Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work."); - ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]); + ImGui::TextWrapped(translationWarningDescription1[current_language]); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]); } } @@ -925,13 +976,13 @@ void Steam_Overlay::OverlayProc() if (url.size()) { bool show = true; if (ImGui::Begin(URL_WINDOW_NAME, &show)) { - ImGui::Text("The game tried to get the steam overlay to open this url:"); + ImGui::Text(translationSteamOverlayURL[current_language]); ImGui::Spacing(); ImGui::PushItemWidth(ImGui::CalcTextSize(url.c_str()).x + 20); ImGui::InputText("##url_copy", (char *)url.data(), url.size(), ImGuiInputTextFlags_ReadOnly); ImGui::PopItemWidth(); ImGui::Spacing(); - if (ImGui::Button("Close") || !show) + if (ImGui::Button(translationClose[current_language]) || !show) show_url = ""; // ImGui::SetWindowSize(ImVec2(ImGui::CalcTextSize(url.c_str()).x + 10, 0)); } @@ -942,21 +993,21 @@ void Steam_Overlay::OverlayProc() if (show_warning) { ImGui::SetNextWindowSizeConstraints(ImVec2(ImGui::GetFontSize() * 32, ImGui::GetFontSize() * 32), ImVec2(8192, 8192)); ImGui::SetNextWindowFocus(); - if (ImGui::Begin("WARNING", &show_warning)) { + if (ImGui::Begin(translationWarning[current_language], &show_warning)) { if (appid == 0) { - ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); - ImGui::TextWrapped("AppID is 0, please create a steam_appid.txt with the right appid and restart the game."); - ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]); + ImGui::TextWrapped(translationWarningDescription2[current_language]); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]); } if (local_save) { - ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); - ImGui::TextWrapped("local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this."); - ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]); + ImGui::TextWrapped(translationWarningDescription3[current_language]); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]); } if (warning_forced) { - ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); - ImGui::TextWrapped("Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings."); - ImGui::TextColored(ImVec4(255, 0, 0, 255), "WARNING WARNING WARNING"); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]); + ImGui::TextWrapped(translationWarningDescription4[current_language]); + ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]); } } ImGui::End(); @@ -994,7 +1045,7 @@ void Steam_Overlay::Callback(Common_Message *msg) friend_info->second.window_state |= window_state_need_attention; } - AddMessageNotification(friend_info->first.name() + " says: " + steam_message.message()); + AddMessageNotification(friend_info->first.name() + ": " + steam_message.message()); NotifyUser(friend_info->second); } } diff --git a/overlay_experimental/steam_overlay.h b/overlay_experimental/steam_overlay.h index ca33e04d..50f25fda 100644 --- a/overlay_experimental/steam_overlay.h +++ b/overlay_experimental/steam_overlay.h @@ -61,7 +61,7 @@ struct Notification static constexpr float r = 0.16; static constexpr float g = 0.29; static constexpr float b = 0.48; - static constexpr float max_alpha = 0.5f; + static constexpr float max_alpha = 1.0f; int id; uint8 type; diff --git a/overlay_experimental/steam_overlay_translations.h b/overlay_experimental/steam_overlay_translations.h new file mode 100644 index 00000000..f42f822f --- /dev/null +++ b/overlay_experimental/steam_overlay_translations.h @@ -0,0 +1,3140 @@ + +const int TRANSLATION_NUMBER_OF_LANGUAGES = 29; +const int TRANSLATION_BUFFER_SIZE = 256; + +// C:\Program Files (x86)\Steam\tenfoot\resource\localization\tenfoot_*.txt +// Friends_Indicator_Chat +const char translationChat[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Chat", + + // 1 - Arabic + "Chat", + + // 2 - Bulgarian + "Чат", + + // 3 - Simplified Chinese + "èŠå¤©", + + // 4 - Traditional Chinese + "èŠå¤©", + + // 5 - Czech + "Konverzace", + + // 6 - Danish + "Chat", + + // 7 - Dutch + "Chatten", + + // 8 - Finnish + "Chat", + + // 9 - French + "Chat", + + // 10 - German + "Chat", + + // 11 - Greek + "Συνομιλία", + + // 12 - Hungarian + "Csevegés", + + // 13 - Italian + "Chat", + + // 14 - Japanese + "ãƒãƒ£ãƒƒãƒˆ", + + // 15 - Korean + "채팅", + + // 16 - Norwegian + "Prat", + + // 17 - Polish + "Czat", + + // 18 - Portuguese + "Chat", + + // 19 - Brazilian Portuguese + "Conversa", + + // 20 - Romanian + "DiscuÈ›ie", + + // 21 - Russian + "Чат", + + // 22 - Spanish + "Chat", + + // 23 - Latin American + "Chat", + + // 24 - Swedish + "Chatt", + + // 25 - Thai + "à¹à¸Šà¹‡à¸•", + + // 26 - Turkish + "Sohbet", + + // 27 - Ukrainian + "Чат", + + // 28 - Vietnamese + "Trò chuyện" +}; + +// C:\Program Files (x86)\Steam\tenfoot\resource\localization\tenfoot_*.txt +// Friends_ProfileDetails_Action_InviteToGame +const char translationInvite[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Invite to Game", + + // 1 - Arabic + "Invite to Game", + + // 2 - Bulgarian + "Покана към игра", + + // 3 - Simplified Chinese + "邀请加入游æˆ", + + // 4 - Traditional Chinese + "邀請至éŠæˆ²", + + // 5 - Czech + "Pozvat do hry", + + // 6 - Danish + "Inviter til spil", + + // 7 - Dutch + "Uitnodigen om mee te spelen", + + // 8 - Finnish + "Kutsu peliin", + + // 9 - French + "Inviter à jouer", + + // 10 - German + "Zu Spiel einladen", + + // 11 - Greek + "ΠÏόσκληση σε παιχνίδι", + + // 12 - Hungarian + "Meghívás játékra", + + // 13 - Italian + "Invita a giocare", + + // 14 - Japanese + "ゲームã«æ‹›å¾…", + + // 15 - Korean + "게임 초대", + + // 16 - Norwegian + "Inviter til spill", + + // 17 - Polish + "ZaproÅ› do gry", + + // 18 - Portuguese + "Convidar para jogar", + + // 19 - Brazilian Portuguese + "Convidar para partida", + + // 20 - Romanian + "Invită la joc", + + // 21 - Russian + "ПриглаÑить в игру", + + // 22 - Spanish + "Invitar a la partida", + + // 23 - Latin American + "Invitar a la partida", + + // 24 - Swedish + "Bjud in till spel", + + // 25 - Thai + "เชิà¸à¹€à¸‚้าร่วมเà¸à¸¡", + + // 26 - Turkish + "Oyuna Davet Et", + + // 27 - Ukrainian + "ЗапроÑити у гру", + + // 28 - Vietnamese + "Má»i vào trò chÆ¡i" +}; + +// C:\Program Files (x86)\Steam\tenfoot\resource\localization\tenfoot_*.txt +// friends_chat_accept_game_invite +const char translationJoin[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Accept Game Invite", + + // 1 - Arabic + "Accept Game Invite", + + // 2 - Bulgarian + "Приемане на игрална покана", + + // 3 - Simplified Chinese + "接å—游æˆé‚€è¯·", + + // 4 - Traditional Chinese + "接å—éŠæˆ²é‚€è«‹", + + // 5 - Czech + "PÅ™ijmout pozvánku do hry", + + // 6 - Danish + "Accepter spilinvitation", + + // 7 - Dutch + "Speluitnodiging accepteren", + + // 8 - Finnish + "Hyväksy pelikutsu", + + // 9 - French + "Accepter l'invitation au jeu", + + // 10 - German + "Spieleinladung annehmen", + + // 11 - Greek + "Αποδοχή Ï€Ïόσκλησης παιχνιδιοÏ", + + // 12 - Hungarian + "Játék-meghívás elfogadása", + + // 13 - Italian + "Accetta invito a giocare", + + // 14 - Japanese + "ゲーム招待ã®æ‰¿èª", + + // 15 - Korean + "게임 초대 수ë½", + + // 16 - Norwegian + "Godta spill-invitasjon", + + // 17 - Polish + "Przyjmij zaproszenie do gry", + + // 18 - Portuguese + "Aceitar convite", + + // 19 - Brazilian Portuguese + "Aceitar convite para partida", + + // 20 - Romanian + "Acceptă invitaÈ›ia la joc", + + // 21 - Russian + "ПринÑÑ‚ÑŒ приглашение в игру", + + // 22 - Spanish + "Aceptar invitación a partida", + + // 23 - Latin American + "Aceptar invitación a partida", + + // 24 - Swedish + "Acceptera spelinbjudan", + + // 25 - Thai + "ยอมรับคำเชิà¸à¸£à¹ˆà¸§à¸¡à¹€à¸à¸¡", + + // 26 - Turkish + "Oyun Davetini Kabul Et", + + // 27 - Ukrainian + "ПрийнÑти Ð·Ð°Ð¿Ñ€Ð¾ÑˆÐµÐ½Ð½Ñ Ð´Ð¾ гри", + + // 28 - Vietnamese + "Nhập lá»i má»i" +}; + +// C:\Program Files (x86)\Steam\tenfoot\resource\localization\tenfoot_*.txt +// friends_chat_game_invite_details +const char translationInvitedYouToJoinTheGame[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "%s has invited you to play GAME_ID_%d", + + // 1 - Arabic + "%s has invited you to play GAME_ID_%d", + + // 2 - Bulgarian + "%s Ви покани да играете GAME_ID_%d", + + // 3 - Simplified Chinese + "%s 已邀请您玩 GAME_ID_%d", + + // 4 - Traditional Chinese + "%s 邀請您一åŒéŠçŽ© GAME_ID_%d", + + // 5 - Czech + "%s Vás pozval do hry GAME_ID_%d", + + // 6 - Danish + "%s har inviteret dig til at spille GAME_ID_%d", + + // 7 - Dutch + "%s heeft je uitgenodigd om GAME_ID_%d te spelen", + + // 8 - Finnish + "%s on kutsunut sinut pelaamaan peliä GAME_ID_%d", + + // 9 - French + "%s vous a invité à jouer à GAME_ID_%d", + + // 10 - German + "%s hat Sie eingeladen, GAME_ID_%d zu spielen", + + // 11 - Greek + "Ο %s σας Ï€Ïοσκάλεσε να παίξετε GAME_ID_%d", + + // 12 - Hungarian + "%s játszani hívott a(z) GAME_ID_%d játékba.", + + // 13 - Italian + "%s ti ha invitato a giocare a GAME_ID_%d", + + // 14 - Japanese + "%s ãŒã‚ãªãŸã‚’ GAME_ID_%d ã®ãƒ—レイã«æ‹›å¾…ã—ã¦ã„ã¾ã™", + + // 15 - Korean + "%së‹˜ì´ GAME_ID_%d ê²Œìž„ì„ í•˜ìžê³  초대했습니다.", + + // 16 - Norwegian + "%s har invitert deg til Ã¥ spille GAME_ID_%d", + + // 17 - Polish + "%s zaprasza ciÄ™ do gry w GAME_ID_%d", + + // 18 - Portuguese + "%s convidou-te para jogar GAME_ID_%d", + + // 19 - Brazilian Portuguese + "%s convidou você para jogar GAME_ID_%d", + + // 20 - Romanian + "%s te-a invitat să jucaÈ›i GAME_ID_%d", + + // 21 - Russian + "%s приглашает Ð²Ð°Ñ Ð² GAME_ID_%d", + + // 22 - Spanish + "%s te ha invitado a jugar a GAME_ID_%d", + + // 23 - Latin American + "%s te invitó a jugar GAME_ID_%d", + + // 24 - Swedish + "%s har bjudit in dig att spela GAME_ID_%d", + + // 25 - Thai + "%s ได้เชิà¸à¸„ุณเล่น GAME_ID_%d", + + // 26 - Turkish + "%s sizi GAME_ID_%d oynamaya davet etti", + + // 27 - Ukrainian + "%s запроÑив Ð²Ð°Ñ Ð¿Ð¾Ð³Ñ€Ð°Ñ‚Ð¸ у GAME_ID_%d", + + // 28 - Vietnamese + "%s má»i bạn chÆ¡i GAME_ID_%d" +}; + +// C:\Program Files (x86)\Steam\tenfoot\resource\localization\tenfoot_*.txt +// Broadcast_Notification_Accept_Request +const char translationAccept[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Accept", + + // 1 - Arabic + "Accept", + + // 2 - Bulgarian + "Приемане", + + // 3 - Simplified Chinese + "接å—", + + // 4 - Traditional Chinese + "接å—", + + // 5 - Czech + "Schválit", + + // 6 - Danish + "Accepter", + + // 7 - Dutch + "Accepteren", + + // 8 - Finnish + "Hyväksy", + + // 9 - French + "Accepter", + + // 10 - German + "Annehmen", + + // 11 - Greek + "Αποδοχή", + + // 12 - Hungarian + "Elfogad", + + // 13 - Italian + "Accetta", + + // 14 - Japanese + "承èª", + + // 15 - Korean + "수ë½", + + // 16 - Norwegian + "Godta", + + // 17 - Polish + "Akceptuj", + + // 18 - Portuguese + "Aceitar", + + // 19 - Brazilian Portuguese + "Aceitar", + + // 20 - Romanian + "Acceptă", + + // 21 - Russian + "ПринÑÑ‚ÑŒ", + + // 22 - Spanish + "Aceptar", + + // 23 - Latin American + "Aceptar", + + // 24 - Swedish + "Acceptera", + + // 25 - Thai + "ยอมรับ", + + // 26 - Turkish + "Kabul Et", + + // 27 - Ukrainian + "ПрийнÑти", + + // 28 - Vietnamese + "Äồng ý" +}; + +// C:\Program Files (x86)\Steam\tenfoot\resource\localization\tenfoot_*.txt +// Broadcast_Notification_Ignore_Request +const char translationRefuse[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Ignore", + + // 1 - Arabic + "Ignore", + + // 2 - Bulgarian + "Игнориране", + + // 3 - Simplified Chinese + "忽略", + + // 4 - Traditional Chinese + "忽略", + + // 5 - Czech + "Odmítnout", + + // 6 - Danish + "Ignorer", + + // 7 - Dutch + "Negeren", + + // 8 - Finnish + "Hylkää", + + // 9 - French + "Ignorer", + + // 10 - German + "Ignorieren", + + // 11 - Greek + "Αγνόηση", + + // 12 - Hungarian + "MellÅ‘z", + + // 13 - Italian + "Ignora", + + // 14 - Japanese + "無視", + + // 15 - Korean + "무시", + + // 16 - Norwegian + "Ignorer", + + // 17 - Polish + "Ignoruj", + + // 18 - Portuguese + "Ignorar", + + // 19 - Brazilian Portuguese + "Ignorar", + + // 20 - Romanian + "Ignoră", + + // 21 - Russian + "Отклонить", + + // 22 - Spanish + "Ignorar", + + // 23 - Latin American + "Ignorar", + + // 24 - Swedish + "Ignorera", + + // 25 - Thai + "ละเว้น", + + // 26 - Turkish + "Yok say", + + // 27 - Ukrainian + "Відхилити", + + // 28 - Vietnamese + "Phá»›t lá»" +}; + +// C:\Program Files (x86)\Steam\tenfoot\resource\localization\tenfoot_*.txt +// Friends_ProfileDetails_Action_SendMessage +const char translationSend[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Send Message", + + // 1 - Arabic + "Send Message", + + // 2 - Bulgarian + "Изпращане на Ñъобщение", + + // 3 - Simplified Chinese + "å‘é€æ¶ˆæ¯", + + // 4 - Traditional Chinese + "傳é€è¨Šæ¯", + + // 5 - Czech + "Odeslat zprávu", + + // 6 - Danish + "Send besked", + + // 7 - Dutch + "Bericht verzenden", + + // 8 - Finnish + "Lähetä viesti", + + // 9 - French + "Envoyer un message", + + // 10 - German + "Nachricht senden", + + // 11 - Greek + "Αποστολή μηνÏματος", + + // 12 - Hungarian + "Ãœzenet küldése", + + // 13 - Italian + "Invia un messaggio", + + // 14 - Japanese + "メッセージをé€ä¿¡", + + // 15 - Korean + "메시지 보내기", + + // 16 - Norwegian + "Send melding", + + // 17 - Polish + "WyÅ›lij wiadomość", + + // 18 - Portuguese + "Enviar mensagem", + + // 19 - Brazilian Portuguese + "Enviar mensagem", + + // 20 - Romanian + "Trimite Mesaj", + + // 21 - Russian + "Отправить Ñообщение", + + // 22 - Spanish + "Enviar mensaje", + + // 23 - Latin American + "Enviar mensaje", + + // 24 - Swedish + "Skicka meddelande", + + // 25 - Thai + "ส่งข้อความ", + + // 26 - Turkish + "Ä°leti Gönder", + + // 27 - Ukrainian + "ÐадіÑлати повідомленнÑ", + + // 28 - Vietnamese + "Gá»­i thông Ä‘iệp" +}; + +// C:\Program Files (x86)\Steam\tenfoot\resource\localization\tenfoot_*.txt +// SettingsInGame_Enable & SettingsInGame_Overlay +const char translationSteamOverlay[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Steam Overlay", + + // 1 - Arabic + "Steam Overlay", + + // 2 - Bulgarian + "Steam Ñлой", + + // 3 - Simplified Chinese + u8"Steam ç•Œé¢", + + // 4 - Traditional Chinese + "Steam 內嵌介é¢", + + // 5 - Czech + "PÅ™ekrytí služby Steam", + + // 6 - Danish + "Steam-overlayet", + + // 7 - Dutch + "Steam-overlay", + + // 8 - Finnish + "Steam-yhteisönäkymä", + + // 9 - French + "L'overlay Steam", + + // 10 - German + "Steam Overlay", + + // 11 - Greek + "Επικάλυψης Steam", + + // 12 - Hungarian + "Steam Ãtfedés", + + // 13 - Italian + "L'Overlay di Steam", + + // 14 - Japanese + "Steam オーãƒãƒ¼ãƒ¬ã‚¤", + + // 15 - Korean + "Steam 오버레ì´", + + // 16 - Norwegian + "Steam-overlegg", + + // 17 - Polish + "NakÅ‚adkÄ™ Steam", + + // 18 - Portuguese + "Painel Steam", + + // 19 - Brazilian Portuguese + "Painel Steam", + + // 20 - Romanian + "Interfață suplimentară Steam", + + // 21 - Russian + "Оверлей Steam", + + // 22 - Spanish + "Interfaz de Steam", + + // 23 - Latin American + "Interfaz de Steam", + + // 24 - Swedish + "Steams överlägg", + + // 25 - Thai + "โอเวอร์เลย์ Steam", + + // 26 - Turkish + "Steam Arayüz", + + // 27 - Ukrainian + "Оверлей Steam", + + // 28 - Vietnamese + "Lá»›p phủ Steam" +}; + +const char translationUserPlaying[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Username: %s(%llu) playing %u", + + // 1 - Arabic + "Username: %s(%llu) playing %u", + + // 2 - Bulgarian + "Username: %s(%llu) playing %u", + + // 3 - Simplified Chinese + "Username: %s(%llu) playing %u", + + // 4 - Traditional Chinese + "Username: %s(%llu) playing %u", + + // 5 - Czech + "Uživatel: %s(%llu) hraje %u", + + // 6 - Danish + "Username: %s(%llu) playing %u", + + // 7 - Dutch + "Username: %s(%llu) playing %u", + + // 8 - Finnish + "Username: %s(%llu) playing %u", + + // 9 - French + "Username: %s(%llu) playing %u", + + // 10 - German + "Username: %s(%llu) playing %u", + + // 11 - Greek + "Username: %s(%llu) playing %u", + + // 12 - Hungarian + "Username: %s(%llu) playing %u", + + // 13 - Italian + "Username: %s(%llu) playing %u", + + // 14 - Japanese + "Username: %s(%llu) playing %u", + + // 15 - Korean + "Username: %s(%llu) playing %u", + + // 16 - Norwegian + "Username: %s(%llu) playing %u", + + // 17 - Polish + "Username: %s(%llu) playing %u", + + // 18 - Portuguese + "Username: %s(%llu) playing %u", + + // 19 - Brazilian Portuguese + "Username: %s(%llu) playing %u", + + // 20 - Romanian + "Username: %s(%llu) playing %u", + + // 21 - Russian + "Username: %s(%llu) playing %u", + + // 22 - Spanish + "Username: %s(%llu) playing %u", + + // 23 - Latin American + "Username: %s(%llu) playing %u", + + // 24 - Swedish + "Username: %s(%llu) playing %u", + + // 25 - Thai + "Username: %s(%llu) playing %u", + + // 26 - Turkish + "Username: %s(%llu) playing %u", + + // 27 - Ukrainian + "Username: %s(%llu) playing %u", + + // 28 - Vietnamese + "Username: %s(%llu) playing %u" +}; + +const char translationRenderer[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Renderer: %s", + + // 1 - Arabic + "Renderer: %s", + + // 2 - Bulgarian + "Renderer: %s", + + // 3 - Simplified Chinese + "Renderer: %s", + + // 4 - Traditional Chinese + "Renderer: %s", + + // 5 - Czech + "VykreslovaÄ: %s", + + // 6 - Danish + "Renderer: %s", + + // 7 - Dutch + "Renderer: %s", + + // 8 - Finnish + "Renderer: %s", + + // 9 - French + "Renderer: %s", + + // 10 - German + "Renderer: %s", + + // 11 - Greek + "Renderer: %s", + + // 12 - Hungarian + "Renderer: %s", + + // 13 - Italian + "Renderer: %s", + + // 14 - Japanese + "Renderer: %s", + + // 15 - Korean + "Renderer: %s", + + // 16 - Norwegian + "Renderer: %s", + + // 17 - Polish + "Renderer: %s", + + // 18 - Portuguese + "Renderer: %s", + + // 19 - Brazilian Portuguese + "Renderer: %s", + + // 20 - Romanian + "Renderer: %s", + + // 21 - Russian + "Renderer: %s", + + // 22 - Spanish + "Renderer: %s", + + // 23 - Latin American + "Renderer: %s", + + // 24 - Swedish + "Renderer: %s", + + // 25 - Thai + "Renderer: %s", + + // 26 - Turkish + "Renderer: %s", + + // 27 - Ukrainian + "Renderer: %s", + + // 28 - Vietnamese + "Renderer: %s" +}; + +const char translationShowAchievements[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Show Achievements", + + // 1 - Arabic + "Show Achievements", + + // 2 - Bulgarian + "Show Achievements", + + // 3 - Simplified Chinese + "Show Achievements", + + // 4 - Traditional Chinese + "Show Achievements", + + // 5 - Czech + "Zobrazit achievementy", + + // 6 - Danish + "Show Achievements", + + // 7 - Dutch + "Show Achievements", + + // 8 - Finnish + "Show Achievements", + + // 9 - French + "Show Achievements", + + // 10 - German + "Show Achievements", + + // 11 - Greek + "Show Achievements", + + // 12 - Hungarian + "Show Achievements", + + // 13 - Italian + "Show Achievements", + + // 14 - Japanese + "Show Achievements", + + // 15 - Korean + "Show Achievements", + + // 16 - Norwegian + "Show Achievements", + + // 17 - Polish + "Show Achievements", + + // 18 - Portuguese + "Show Achievements", + + // 19 - Brazilian Portuguese + "Show Achievements", + + // 20 - Romanian + "Show Achievements", + + // 21 - Russian + "Show Achievements", + + // 22 - Spanish + "Show Achievements", + + // 23 - Latin American + "Show Achievements", + + // 24 - Swedish + "Show Achievements", + + // 25 - Thai + "Show Achievements", + + // 26 - Turkish + "Show Achievements", + + // 27 - Ukrainian + "Show Achievements", + + // 28 - Vietnamese + "Show Achievements" +}; + +// C:\Program Files (x86)\Steam\resource\overlay_*.txt +// steam_menu_friends_settings +const char translationSettings[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Settings", + + // 1 - Arabic + "Settings", + + // 2 - Bulgarian + "ÐаÑтройки", + + // 3 - Simplified Chinese + "设置", + + // 4 - Traditional Chinese + "設定", + + // 5 - Czech + "Nastavení", + + // 6 - Danish + "Indstillinger", + + // 7 - Dutch + "Instellingen", + + // 8 - Finnish + "Asetukset", + + // 9 - French + "Paramètres", + + // 10 - German + "Einstellungen", + + // 11 - Greek + "Ρυθμίσεις", + + // 12 - Hungarian + "Beállítások", + + // 13 - Italian + "Impostazioni", + + // 14 - Japanese + "設定", + + // 15 - Korean + "설정", + + // 16 - Norwegian + "Innstillinger", + + // 17 - Polish + "Ustawienia", + + // 18 - Portuguese + "Definições", + + // 19 - Brazilian Portuguese + "Configurações", + + // 20 - Romanian + "Setări", + + // 21 - Russian + "ÐаÑтройки", + + // 22 - Spanish + "Parámetros", + + // 23 - Latin American + "Parámetros", + + // 24 - Swedish + "Inställningar", + + // 25 - Thai + "à¸à¸²à¸£à¸•à¸±à¹‰à¸‡à¸„่า", + + // 26 - Turkish + "Ayarlar", + + // 27 - Ukrainian + "ÐалаштуваннÑ", + + // 28 - Vietnamese + "Thiết lập" +}; + +// C:\Program Files (x86)\Steam\resource\overlay_*.txt +// steam_menu_friends_view +const char translationFriends[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Friends", + + // 1 - Arabic + "Friends", + + // 2 - Bulgarian + "ПриÑтели", + + // 3 - Simplified Chinese + "好å‹", + + // 4 - Traditional Chinese + "好å‹", + + // 5 - Czech + "Přátelé", + + // 6 - Danish + "Venner", + + // 7 - Dutch + "Vrienden", + + // 8 - Finnish + "Kaverit", + + // 9 - French + "Contacts", + + // 10 - German + "Freunde", + + // 11 - Greek + "Φίλοι", + + // 12 - Hungarian + "Barátok", + + // 13 - Italian + "Amici", + + // 14 - Japanese + "フレンド", + + // 15 - Korean + "친구", + + // 16 - Norwegian + "Venner", + + // 17 - Polish + "Znajomi", + + // 18 - Portuguese + "Amigos", + + // 19 - Brazilian Portuguese + "Amigos", + + // 20 - Romanian + "Prieteni", + + // 21 - Russian + "ДрузьÑ", + + // 22 - Spanish + "Amigos", + + // 23 - Latin American + "Amigos", + + // 24 - Swedish + "Vänner", + + // 25 - Thai + "เพื่อน", + + // 26 - Turkish + "ArkadaÅŸlar", + + // 27 - Ukrainian + "Друзі", + + // 28 - Vietnamese + "Bạn bè" +}; + +const char translationAchievementWindow[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Achievement Window", + + // 1 - Arabic + "Achievement Window", + + // 2 - Bulgarian + "Achievement Window", + + // 3 - Simplified Chinese + "Achievement Window", + + // 4 - Traditional Chinese + "Achievement Window", + + // 5 - Czech + "Okno achievementů", + + // 6 - Danish + "Achievement Window", + + // 7 - Dutch + "Achievement Window", + + // 8 - Finnish + "Achievement Window", + + // 9 - French + "Achievement Window", + + // 10 - German + "Achievement Window", + + // 11 - Greek + "Achievement Window", + + // 12 - Hungarian + "Achievement Window", + + // 13 - Italian + "Achievement Window", + + // 14 - Japanese + "Achievement Window", + + // 15 - Korean + "Achievement Window", + + // 16 - Norwegian + "Achievement Window", + + // 17 - Polish + "Achievement Window", + + // 18 - Portuguese + "Achievement Window", + + // 19 - Brazilian Portuguese + "Achievement Window", + + // 20 - Romanian + "Achievement Window", + + // 21 - Russian + "Achievement Window", + + // 22 - Spanish + "Achievement Window", + + // 23 - Latin American + "Achievement Window", + + // 24 - Swedish + "Achievement Window", + + // 25 - Thai + "Achievement Window", + + // 26 - Turkish + "Achievement Window", + + // 27 - Ukrainian + "Achievement Window", + + // 28 - Vietnamese + "Achievement Window" +}; + +const char translationListOfAchievements[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "List of achievements", + + // 1 - Arabic + "List of achievements", + + // 2 - Bulgarian + "List of achievements", + + // 3 - Simplified Chinese + "List of achievements", + + // 4 - Traditional Chinese + "List of achievements", + + // 5 - Czech + "Seznam achievementů", + + // 6 - Danish + "List of achievements", + + // 7 - Dutch + "List of achievements", + + // 8 - Finnish + "List of achievements", + + // 9 - French + "List of achievements", + + // 10 - German + "List of achievements", + + // 11 - Greek + "List of achievements", + + // 12 - Hungarian + "List of achievements", + + // 13 - Italian + "List of achievements", + + // 14 - Japanese + "List of achievements", + + // 15 - Korean + "List of achievements", + + // 16 - Norwegian + "List of achievements", + + // 17 - Polish + "List of achievements", + + // 18 - Portuguese + "List of achievements", + + // 19 - Brazilian Portuguese + "List of achievements", + + // 20 - Romanian + "List of achievements", + + // 21 - Russian + "List of achievements", + + // 22 - Spanish + "List of achievements", + + // 23 - Latin American + "List of achievements", + + // 24 - Swedish + "List of achievements", + + // 25 - Thai + "List of achievements", + + // 26 - Turkish + "List of achievements", + + // 27 - Ukrainian + "List of achievements", + + // 28 - Vietnamese + "List of achievements" +}; + +const char translationAchievements[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Achievements", + + // 1 - Arabic + "Achievements", + + // 2 - Bulgarian + "Achievements", + + // 3 - Simplified Chinese + "Achievements", + + // 4 - Traditional Chinese + "Achievements", + + // 5 - Czech + "Achievementy", + + // 6 - Danish + "Achievements", + + // 7 - Dutch + "Achievements", + + // 8 - Finnish + "Achievements", + + // 9 - French + "Achievements", + + // 10 - German + "Achievements", + + // 11 - Greek + "Achievements", + + // 12 - Hungarian + "Achievements", + + // 13 - Italian + "Achievements", + + // 14 - Japanese + "Achievements", + + // 15 - Korean + "Achievements", + + // 16 - Norwegian + "Achievements", + + // 17 - Polish + "Achievements", + + // 18 - Portuguese + "Achievements", + + // 19 - Brazilian Portuguese + "Achievements", + + // 20 - Romanian + "Achievements", + + // 21 - Russian + "Achievements", + + // 22 - Spanish + "Achievements", + + // 23 - Latin American + "Achievements", + + // 24 - Swedish + "Achievements", + + // 25 - Thai + "Achievements", + + // 26 - Turkish + "Achievements", + + // 27 - Ukrainian + "Achievements", + + // 28 - Vietnamese + "Achievements" +}; + +const char translationHiddenAchievement[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "hidden achievement", + + // 1 - Arabic + "hidden achievement", + + // 2 - Bulgarian + "hidden achievement", + + // 3 - Simplified Chinese + "hidden achievement", + + // 4 - Traditional Chinese + "hidden achievement", + + // 5 - Czech + "Skrytý achievement", + + // 6 - Danish + "hidden achievement", + + // 7 - Dutch + "hidden achievement", + + // 8 - Finnish + "hidden achievement", + + // 9 - French + "hidden achievement", + + // 10 - German + "hidden achievement", + + // 11 - Greek + "hidden achievement", + + // 12 - Hungarian + "hidden achievement", + + // 13 - Italian + "hidden achievement", + + // 14 - Japanese + "hidden achievement", + + // 15 - Korean + "hidden achievement", + + // 16 - Norwegian + "hidden achievement", + + // 17 - Polish + "hidden achievement", + + // 18 - Portuguese + "hidden achievement", + + // 19 - Brazilian Portuguese + "hidden achievement", + + // 20 - Romanian + "hidden achievement", + + // 21 - Russian + "hidden achievement", + + // 22 - Spanish + "hidden achievement", + + // 23 - Latin American + "hidden achievement", + + // 24 - Swedish + "hidden achievement", + + // 25 - Thai + "hidden achievement", + + // 26 - Turkish + "hidden achievement", + + // 27 - Ukrainian + "hidden achievement", + + // 28 - Vietnamese + "hidden achievement" +}; + +const char translationAchievedOn[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "achieved on %s", + + // 1 - Arabic + "achieved on %s", + + // 2 - Bulgarian + "achieved on %s", + + // 3 - Simplified Chinese + "achieved on %s", + + // 4 - Traditional Chinese + "achieved on %s", + + // 5 - Czech + "odemÄeno %s", + + // 6 - Danish + "achieved on %s", + + // 7 - Dutch + "achieved on %s", + + // 8 - Finnish + "achieved on %s", + + // 9 - French + "achieved on %s", + + // 10 - German + "achieved on %s", + + // 11 - Greek + "achieved on %s", + + // 12 - Hungarian + "achieved on %s", + + // 13 - Italian + "achieved on %s", + + // 14 - Japanese + "achieved on %s", + + // 15 - Korean + "achieved on %s", + + // 16 - Norwegian + "achieved on %s", + + // 17 - Polish + "achieved on %s", + + // 18 - Portuguese + "achieved on %s", + + // 19 - Brazilian Portuguese + "achieved on %s", + + // 20 - Romanian + "achieved on %s", + + // 21 - Russian + "achieved on %s", + + // 22 - Spanish + "achieved on %s", + + // 23 - Latin American + "achieved on %s", + + // 24 - Swedish + "achieved on %s", + + // 25 - Thai + "achieved on %s", + + // 26 - Turkish + "achieved on %s", + + // 27 - Ukrainian + "achieved on %s", + + // 28 - Vietnamese + "achieved on %s" +}; + +const char translationNotAchieved[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "not achieved", + + // 1 - Arabic + "not achieved", + + // 2 - Bulgarian + "not achieved", + + // 3 - Simplified Chinese + "not achieved", + + // 4 - Traditional Chinese + "not achieved", + + // 5 - Czech + "uzamÄeno", + + // 6 - Danish + "not achieved", + + // 7 - Dutch + "not achieved", + + // 8 - Finnish + "not achieved", + + // 9 - French + "not achieved", + + // 10 - German + "not achieved", + + // 11 - Greek + "not achieved", + + // 12 - Hungarian + "not achieved", + + // 13 - Italian + "not achieved", + + // 14 - Japanese + "not achieved", + + // 15 - Korean + "not achieved", + + // 16 - Norwegian + "not achieved", + + // 17 - Polish + "not achieved", + + // 18 - Portuguese + "not achieved", + + // 19 - Brazilian Portuguese + "not achieved", + + // 20 - Romanian + "not achieved", + + // 21 - Russian + "not achieved", + + // 22 - Spanish + "not achieved", + + // 23 - Latin American + "not achieved", + + // 24 - Swedish + "not achieved", + + // 25 - Thai + "not achieved", + + // 26 - Turkish + "not achieved", + + // 27 - Ukrainian + "not achieved", + + // 28 - Vietnamese + "not achieved" +}; + +const char translationGlobalSettingsWindow[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Global Settings Window", + + // 1 - Arabic + "Global Settings Window", + + // 2 - Bulgarian + "Global Settings Window", + + // 3 - Simplified Chinese + "Global Settings Window", + + // 4 - Traditional Chinese + "Global Settings Window", + + // 5 - Czech + "Okno globálních nastavení", + + // 6 - Danish + "Global Settings Window", + + // 7 - Dutch + "Global Settings Window", + + // 8 - Finnish + "Global Settings Window", + + // 9 - French + "Global Settings Window", + + // 10 - German + "Global Settings Window", + + // 11 - Greek + "Global Settings Window", + + // 12 - Hungarian + "Global Settings Window", + + // 13 - Italian + "Global Settings Window", + + // 14 - Japanese + "Global Settings Window", + + // 15 - Korean + "Global Settings Window", + + // 16 - Norwegian + "Global Settings Window", + + // 17 - Polish + "Global Settings Window", + + // 18 - Portuguese + "Global Settings Window", + + // 19 - Brazilian Portuguese + "Global Settings Window", + + // 20 - Romanian + "Global Settings Window", + + // 21 - Russian + "Global Settings Window", + + // 22 - Spanish + "Global Settings Window", + + // 23 - Latin American + "Global Settings Window", + + // 24 - Swedish + "Global Settings Window", + + // 25 - Thai + "Global Settings Window", + + // 26 - Turkish + "Global Settings Window", + + // 27 - Ukrainian + "Global Settings Window", + + // 28 - Vietnamese + "Global Settings Window" +}; + +const char translationGlobalSettingsWindowDescription[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "These are global emulator settings and will apply to all games.", + + // 1 - Arabic + "These are global emulator settings and will apply to all games.", + + // 2 - Bulgarian + "These are global emulator settings and will apply to all games.", + + // 3 - Simplified Chinese + "These are global emulator settings and will apply to all games.", + + // 4 - Traditional Chinese + "These are global emulator settings and will apply to all games.", + + // 5 - Czech + "Toto jsou globální nastavení emulátoru a budou platit pro vÅ¡echny hry.", + + // 6 - Danish + "These are global emulator settings and will apply to all games.", + + // 7 - Dutch + "These are global emulator settings and will apply to all games.", + + // 8 - Finnish + "These are global emulator settings and will apply to all games.", + + // 9 - French + "These are global emulator settings and will apply to all games.", + + // 10 - German + "These are global emulator settings and will apply to all games.", + + // 11 - Greek + "These are global emulator settings and will apply to all games.", + + // 12 - Hungarian + "These are global emulator settings and will apply to all games.", + + // 13 - Italian + "These are global emulator settings and will apply to all games.", + + // 14 - Japanese + "These are global emulator settings and will apply to all games.", + + // 15 - Korean + "These are global emulator settings and will apply to all games.", + + // 16 - Norwegian + "These are global emulator settings and will apply to all games.", + + // 17 - Polish + "These are global emulator settings and will apply to all games.", + + // 18 - Portuguese + "These are global emulator settings and will apply to all games.", + + // 19 - Brazilian Portuguese + "These are global emulator settings and will apply to all games.", + + // 20 - Romanian + "These are global emulator settings and will apply to all games.", + + // 21 - Russian + "These are global emulator settings and will apply to all games.", + + // 22 - Spanish + "These are global emulator settings and will apply to all games.", + + // 23 - Latin American + "These are global emulator settings and will apply to all games.", + + // 24 - Swedish + "These are global emulator settings and will apply to all games.", + + // 25 - Thai + "These are global emulator settings and will apply to all games.", + + // 26 - Turkish + "These are global emulator settings and will apply to all games.", + + // 27 - Ukrainian + "These are global emulator settings and will apply to all games.", + + // 28 - Vietnamese + "These are global emulator settings and will apply to all games." +}; + +const char translationUsername[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Username:", + + // 1 - Arabic + "Username:", + + // 2 - Bulgarian + "Username:", + + // 3 - Simplified Chinese + "Username:", + + // 4 - Traditional Chinese + "Username:", + + // 5 - Czech + "Uživatelské jméno:", + + // 6 - Danish + "Username:", + + // 7 - Dutch + "Username:", + + // 8 - Finnish + "Username:", + + // 9 - French + "Username:", + + // 10 - German + "Username:", + + // 11 - Greek + "Username:", + + // 12 - Hungarian + "Username:", + + // 13 - Italian + "Username:", + + // 14 - Japanese + "Username:", + + // 15 - Korean + "Username:", + + // 16 - Norwegian + "Username:", + + // 17 - Polish + "Username:", + + // 18 - Portuguese + "Username:", + + // 19 - Brazilian Portuguese + "Username:", + + // 20 - Romanian + "Username:", + + // 21 - Russian + "Username:", + + // 22 - Spanish + "Username:", + + // 23 - Latin American + "Username:", + + // 24 - Swedish + "Username:", + + // 25 - Thai + "Username:", + + // 26 - Turkish + "Username:", + + // 27 - Ukrainian + "Username:", + + // 28 - Vietnamese + "Username:" +}; + +const char translationLanguage[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Language:", + + // 1 - Arabic + "Language:", + + // 2 - Bulgarian + "Language:", + + // 3 - Simplified Chinese + "Language:", + + // 4 - Traditional Chinese + "Language:", + + // 5 - Czech + "Jazyk:", + + // 6 - Danish + "Language:", + + // 7 - Dutch + "Language:", + + // 8 - Finnish + "Language:", + + // 9 - French + "Language:", + + // 10 - German + "Language:", + + // 11 - Greek + "Language:", + + // 12 - Hungarian + "Language:", + + // 13 - Italian + "Language:", + + // 14 - Japanese + "Language:", + + // 15 - Korean + "Language:", + + // 16 - Norwegian + "Language:", + + // 17 - Polish + "Language:", + + // 18 - Portuguese + "Language:", + + // 19 - Brazilian Portuguese + "Language:", + + // 20 - Romanian + "Language:", + + // 21 - Russian + "Language:", + + // 22 - Spanish + "Language:", + + // 23 - Latin American + "Language:", + + // 24 - Swedish + "Language:", + + // 25 - Thai + "Language:", + + // 26 - Turkish + "Language:", + + // 27 - Ukrainian + "Language:", + + // 28 - Vietnamese + "Language:" +}; + +const char translationSelectedLanguage[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Selected Language: %s", + + // 1 - Arabic + "Selected Language: %s", + + // 2 - Bulgarian + "Selected Language: %s", + + // 3 - Simplified Chinese + "Selected Language: %s", + + // 4 - Traditional Chinese + "Selected Language: %s", + + // 5 - Czech + "Zvolený jazyk: %s", + + // 6 - Danish + "Selected Language: %s", + + // 7 - Dutch + "Selected Language: %s", + + // 8 - Finnish + "Selected Language: %s", + + // 9 - French + "Selected Language: %s", + + // 10 - German + "Selected Language: %s", + + // 11 - Greek + "Selected Language: %s", + + // 12 - Hungarian + "Selected Language: %s", + + // 13 - Italian + "Selected Language: %s", + + // 14 - Japanese + "Selected Language: %s", + + // 15 - Korean + "Selected Language: %s", + + // 16 - Norwegian + "Selected Language: %s", + + // 17 - Polish + "Selected Language: %s", + + // 18 - Portuguese + "Selected Language: %s", + + // 19 - Brazilian Portuguese + "Selected Language: %s", + + // 20 - Romanian + "Selected Language: %s", + + // 21 - Russian + "Selected Language: %s", + + // 22 - Spanish + "Selected Language: %s", + + // 23 - Latin American + "Selected Language: %s", + + // 24 - Swedish + "Selected Language: %s", + + // 25 - Thai + "Selected Language: %s", + + // 26 - Turkish + "Selected Language: %s", + + // 27 - Ukrainian + "Selected Language: %s", + + // 28 - Vietnamese + "Selected Language: %s" +}; + +const char translationRestartTheGameToApply[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "You may have to restart the game for these to apply.", + + // 1 - Arabic + "You may have to restart the game for these to apply.", + + // 2 - Bulgarian + "You may have to restart the game for these to apply.", + + // 3 - Simplified Chinese + "You may have to restart the game for these to apply.", + + // 4 - Traditional Chinese + "You may have to restart the game for these to apply.", + + // 5 - Czech + "Pro uplatnÄ›ní zmÄ›n může být nutné restartovat hru.", + + // 6 - Danish + "You may have to restart the game for these to apply.", + + // 7 - Dutch + "You may have to restart the game for these to apply.", + + // 8 - Finnish + "You may have to restart the game for these to apply.", + + // 9 - French + "You may have to restart the game for these to apply.", + + // 10 - German + "You may have to restart the game for these to apply.", + + // 11 - Greek + "You may have to restart the game for these to apply.", + + // 12 - Hungarian + "You may have to restart the game for these to apply.", + + // 13 - Italian + "You may have to restart the game for these to apply.", + + // 14 - Japanese + "You may have to restart the game for these to apply.", + + // 15 - Korean + "You may have to restart the game for these to apply.", + + // 16 - Norwegian + "You may have to restart the game for these to apply.", + + // 17 - Polish + "You may have to restart the game for these to apply.", + + // 18 - Portuguese + "You may have to restart the game for these to apply.", + + // 19 - Brazilian Portuguese + "You may have to restart the game for these to apply.", + + // 20 - Romanian + "You may have to restart the game for these to apply.", + + // 21 - Russian + "You may have to restart the game for these to apply.", + + // 22 - Spanish + "You may have to restart the game for these to apply.", + + // 23 - Latin American + "You may have to restart the game for these to apply.", + + // 24 - Swedish + "You may have to restart the game for these to apply.", + + // 25 - Thai + "You may have to restart the game for these to apply.", + + // 26 - Turkish + "You may have to restart the game for these to apply.", + + // 27 - Ukrainian + "You may have to restart the game for these to apply.", + + // 28 - Vietnamese + "You may have to restart the game for these to apply." +}; + +const char translationSave[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Save", + + // 1 - Arabic + "Save", + + // 2 - Bulgarian + "Save", + + // 3 - Simplified Chinese + "Save", + + // 4 - Traditional Chinese + "Save", + + // 5 - Czech + "Uložit", + + // 6 - Danish + "Save", + + // 7 - Dutch + "Save", + + // 8 - Finnish + "Save", + + // 9 - French + "Save", + + // 10 - German + "Save", + + // 11 - Greek + "Save", + + // 12 - Hungarian + "Save", + + // 13 - Italian + "Save", + + // 14 - Japanese + "Save", + + // 15 - Korean + "Save", + + // 16 - Norwegian + "Save", + + // 17 - Polish + "Save", + + // 18 - Portuguese + "Save", + + // 19 - Brazilian Portuguese + "Save", + + // 20 - Romanian + "Save", + + // 21 - Russian + "Save", + + // 22 - Spanish + "Save", + + // 23 - Latin American + "Save", + + // 24 - Swedish + "Save", + + // 25 - Thai + "Save", + + // 26 - Turkish + "Save", + + // 27 - Ukrainian + "Save", + + // 28 - Vietnamese + "Save" +}; + +const char translationWarning[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "WARNING", + + // 1 - Arabic + "WARNING", + + // 2 - Bulgarian + "WARNING", + + // 3 - Simplified Chinese + "WARNING", + + // 4 - Traditional Chinese + "WARNING", + + // 5 - Czech + "VAROVÃNÃ", + + // 6 - Danish + "WARNING", + + // 7 - Dutch + "WARNING", + + // 8 - Finnish + "WARNING", + + // 9 - French + "WARNING", + + // 10 - German + "WARNING", + + // 11 - Greek + "WARNING", + + // 12 - Hungarian + "WARNING", + + // 13 - Italian + "WARNING", + + // 14 - Japanese + "WARNING", + + // 15 - Korean + "WARNING", + + // 16 - Norwegian + "WARNING", + + // 17 - Polish + "WARNING", + + // 18 - Portuguese + "WARNING", + + // 19 - Brazilian Portuguese + "WARNING", + + // 20 - Romanian + "WARNING", + + // 21 - Russian + "WARNING", + + // 22 - Spanish + "WARNING", + + // 23 - Latin American + "WARNING", + + // 24 - Swedish + "WARNING", + + // 25 - Thai + "WARNING", + + // 26 - Turkish + "WARNING", + + // 27 - Ukrainian + "WARNING", + + // 28 - Vietnamese + "WARNING" +}; + +const char translationWarningWarningWarning[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "WARNING WARNING WARNING", + + // 1 - Arabic + "WARNING WARNING WARNING", + + // 2 - Bulgarian + "WARNING WARNING WARNING", + + // 3 - Simplified Chinese + "WARNING WARNING WARNING", + + // 4 - Traditional Chinese + "WARNING WARNING WARNING", + + // 5 - Czech + "VAROVÃNà VAROVÃNà VAROVÃNÃ", + + // 6 - Danish + "WARNING WARNING WARNING", + + // 7 - Dutch + "WARNING WARNING WARNING", + + // 8 - Finnish + "WARNING WARNING WARNING", + + // 9 - French + "WARNING WARNING WARNING", + + // 10 - German + "WARNING WARNING WARNING", + + // 11 - Greek + "WARNING WARNING WARNING", + + // 12 - Hungarian + "WARNING WARNING WARNING", + + // 13 - Italian + "WARNING WARNING WARNING", + + // 14 - Japanese + "WARNING WARNING WARNING", + + // 15 - Korean + "WARNING WARNING WARNING", + + // 16 - Norwegian + "WARNING WARNING WARNING", + + // 17 - Polish + "WARNING WARNING WARNING", + + // 18 - Portuguese + "WARNING WARNING WARNING", + + // 19 - Brazilian Portuguese + "WARNING WARNING WARNING", + + // 20 - Romanian + "WARNING WARNING WARNING", + + // 21 - Russian + "WARNING WARNING WARNING", + + // 22 - Spanish + "WARNING WARNING WARNING", + + // 23 - Latin American + "WARNING WARNING WARNING", + + // 24 - Swedish + "WARNING WARNING WARNING", + + // 25 - Thai + "WARNING WARNING WARNING", + + // 26 - Turkish + "WARNING WARNING WARNING", + + // 27 - Ukrainian + "WARNING WARNING WARNING", + + // 28 - Vietnamese + "WARNING WARNING WARNING" +}; + +const char translationWarningDescription1[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 1 - Arabic + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 2 - Bulgarian + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 3 - Simplified Chinese + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 4 - Traditional Chinese + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 5 - Czech + "Byly zjiÅ¡tÄ›ny soubory steam_settings/force_*.txt. Pokud chcete, aby toto menu fungovalo, odstraňte je.", + + // 6 - Danish + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 7 - Dutch + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 8 - Finnish + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 9 - French + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 10 - German + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 11 - Greek + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 12 - Hungarian + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 13 - Italian + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 14 - Japanese + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 15 - Korean + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 16 - Norwegian + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 17 - Polish + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 18 - Portuguese + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 19 - Brazilian Portuguese + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 20 - Romanian + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 21 - Russian + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 22 - Spanish + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 23 - Latin American + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 24 - Swedish + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 25 - Thai + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 26 - Turkish + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 27 - Ukrainian + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work.", + + // 28 - Vietnamese + "Some steam_settings/force_*.txt files have been detected. Please delete them if you want this menu to work." +}; + +const char translationWarningDescription2[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 1 - Arabic + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 2 - Bulgarian + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 3 - Simplified Chinese + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 4 - Traditional Chinese + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 5 - Czech + "AppID je 0, vytvoÅ™te, prosím, steam_appid.txt se správným appid a restartujte hru.", + + // 6 - Danish + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 7 - Dutch + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 8 - Finnish + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 9 - French + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 10 - German + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 11 - Greek + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 12 - Hungarian + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 13 - Italian + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 14 - Japanese + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 15 - Korean + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 16 - Norwegian + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 17 - Polish + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 18 - Portuguese + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 19 - Brazilian Portuguese + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 20 - Romanian + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 21 - Russian + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 22 - Spanish + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 23 - Latin American + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 24 - Swedish + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 25 - Thai + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 26 - Turkish + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 27 - Ukrainian + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game.", + + // 28 - Vietnamese + "AppID is 0, please create a steam_appid.txt with the right appid and restart the game." +}; + +const char translationWarningDescription3[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 1 - Arabic + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 2 - Bulgarian + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 3 - Simplified Chinese + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 4 - Traditional Chinese + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 5 - Czech + "ZjiÅ¡tÄ›n local_save.txt, emulátor ukládá lokálnÄ› do složky hry. Pokud to nechcete, odstraňte ho.", + + // 6 - Danish + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 7 - Dutch + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 8 - Finnish + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 9 - French + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 10 - German + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 11 - Greek + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 12 - Hungarian + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 13 - Italian + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 14 - Japanese + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 15 - Korean + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 16 - Norwegian + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 17 - Polish + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 18 - Portuguese + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 19 - Brazilian Portuguese + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 20 - Romanian + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 21 - Russian + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 22 - Spanish + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 23 - Latin American + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 24 - Swedish + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 25 - Thai + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 26 - Turkish + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 27 - Ukrainian + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this.", + + // 28 - Vietnamese + "local_save.txt detected, the emu is saving locally to the game folder. Please delete it if you don't want this." +}; + +const char translationWarningDescription4[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 1 - Arabic + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 2 - Bulgarian + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 3 - Simplified Chinese + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 4 - Traditional Chinese + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 5 - Czech + "Byly zjiÅ¡tÄ›ny soubory steam_settings/force_*.txt. NÄ›která nastavení nebude možné uložit.", + + // 6 - Danish + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 7 - Dutch + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 8 - Finnish + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 9 - French + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 10 - German + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 11 - Greek + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 12 - Hungarian + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 13 - Italian + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 14 - Japanese + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 15 - Korean + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 16 - Norwegian + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 17 - Polish + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 18 - Portuguese + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 19 - Brazilian Portuguese + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 20 - Romanian + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 21 - Russian + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 22 - Spanish + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 23 - Latin American + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 24 - Swedish + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 25 - Thai + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 26 - Turkish + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 27 - Ukrainian + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings.", + + // 28 - Vietnamese + "Some steam_settings/force_*.txt files have been detected. You will not be able to save some settings." +}; + +const char translationSteamOverlayURL[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "The game tried to get the steam overlay to open this url:", + + // 1 - Arabic + "The game tried to get the steam overlay to open this url:", + + // 2 - Bulgarian + "The game tried to get the steam overlay to open this url:", + + // 3 - Simplified Chinese + "The game tried to get the steam overlay to open this url:", + + // 4 - Traditional Chinese + "The game tried to get the steam overlay to open this url:", + + // 5 - Czech + "Hra se pokusila otevřít v rozhraní pÅ™ekrytí služby Steam tuto webovou adresu:", + + // 6 - Danish + "The game tried to get the steam overlay to open this url:", + + // 7 - Dutch + "The game tried to get the steam overlay to open this url:", + + // 8 - Finnish + "The game tried to get the steam overlay to open this url:", + + // 9 - French + "The game tried to get the steam overlay to open this url:", + + // 10 - German + "The game tried to get the steam overlay to open this url:", + + // 11 - Greek + "The game tried to get the steam overlay to open this url:", + + // 12 - Hungarian + "The game tried to get the steam overlay to open this url:", + + // 13 - Italian + "The game tried to get the steam overlay to open this url:", + + // 14 - Japanese + "The game tried to get the steam overlay to open this url:", + + // 15 - Korean + "The game tried to get the steam overlay to open this url:", + + // 16 - Norwegian + "The game tried to get the steam overlay to open this url:", + + // 17 - Polish + "The game tried to get the steam overlay to open this url:", + + // 18 - Portuguese + "The game tried to get the steam overlay to open this url:", + + // 19 - Brazilian Portuguese + "The game tried to get the steam overlay to open this url:", + + // 20 - Romanian + "The game tried to get the steam overlay to open this url:", + + // 21 - Russian + "The game tried to get the steam overlay to open this url:", + + // 22 - Spanish + "The game tried to get the steam overlay to open this url:", + + // 23 - Latin American + "The game tried to get the steam overlay to open this url:", + + // 24 - Swedish + "The game tried to get the steam overlay to open this url:", + + // 25 - Thai + "The game tried to get the steam overlay to open this url:", + + // 26 - Turkish + "The game tried to get the steam overlay to open this url:", + + // 27 - Ukrainian + "The game tried to get the steam overlay to open this url:", + + // 28 - Vietnamese + "The game tried to get the steam overlay to open this url:" +}; + +// C:\Program Files (x86)\Steam\resource\vgui_*.txt +// vgui_close +const char translationClose[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + "Close", + + // 1 - Arabic + "Close", + + // 2 - Bulgarian + "ЗатварÑне", + + // 3 - Simplified Chinese + "关闭", + + // 4 - Traditional Chinese + "關閉", + + // 5 - Czech + "Zavřít", + + // 6 - Danish + "Luk", + + // 7 - Dutch + "Sluiten", + + // 8 - Finnish + "Sulje", + + // 9 - French + "Fermer", + + // 10 - German + "Schliessen", + + // 11 - Greek + "ΚΛΕΙΣΙΜΟ", + + // 12 - Hungarian + "Bezárás", + + // 13 - Italian + "Chiudi", + + // 14 - Japanese + "é–‰ã˜ã‚‹", + + // 15 - Korean + "닫기", + + // 16 - Norwegian + "Lukk", + + // 17 - Polish + "Zamknij", + + // 18 - Portuguese + "Fechar", + + // 19 - Brazilian Portuguese + "Fechar", + + // 20 - Romanian + "ÃŽnchide", + + // 21 - Russian + "Закрыть", + + // 22 - Spanish + "Cerrar", + + // 23 - Latin American + "Cerrar", + + // 24 - Swedish + "Stäng", + + // 25 - Thai + "ปิด", + + // 26 - Turkish + "Kapat", + + // 27 - Ukrainian + "Закрити", + + // 28 - Vietnamese + "Äóng" +}; + +const char translationPlaying[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { + // 0 - English + " playing ", + + // 1 - Arabic + " playing ", + + // 2 - Bulgarian + " playing ", + + // 3 - Simplified Chinese + " playing ", + + // 4 - Traditional Chinese + " playing ", + + // 5 - Czech + " hraje ", + + // 6 - Danish + " playing ", + + // 7 - Dutch + " playing ", + + // 8 - Finnish + " playing ", + + // 9 - French + " playing ", + + // 10 - German + " playing ", + + // 11 - Greek + " playing ", + + // 12 - Hungarian + " playing ", + + // 13 - Italian + " playing ", + + // 14 - Japanese + " playing ", + + // 15 - Korean + " playing ", + + // 16 - Norwegian + " playing ", + + // 17 - Polish + " playing ", + + // 18 - Portuguese + " playing ", + + // 19 - Brazilian Portuguese + " playing ", + + // 20 - Romanian + " playing ", + + // 21 - Russian + " playing ", + + // 22 - Spanish + " playing ", + + // 23 - Latin American + " playing ", + + // 24 - Swedish + " playing ", + + // 25 - Thai + " playing ", + + // 26 - Turkish + " playing ", + + // 27 - Ukrainian + " playing ", + + // 28 - Vietnamese + " playing " +}; diff --git a/scripts/steamclient_loader.sh b/scripts/steamclient_loader.sh index 53074e4c..c770a924 100755 --- a/scripts/steamclient_loader.sh +++ b/scripts/steamclient_loader.sh @@ -1,36 +1,67 @@ -#!/bin/bash -APP_NAME="bin/test_executable" -APP_ID=480 -APP_PATH=$(dirname "$0") -CONFIG_PATH=$(dirname "$0") -#path to steam-runtime/run.sh -STEAM_RUNTIME="" +#!/bin/sh +EXE="./hl2.sh" +EXE_RUN_DIR="$(dirname ${0})" +EXE_COMMAND_LINE="-steam -game cstrike" +APP_ID=240 +STEAM_CLIENT_SO=steamclient.so +STEAM_CLIENT64_SO=steamclient64.so +#STEAM_RUNTIME="./steam_runtime/run.sh" -CUR_DIR=$(pwd) -cd "$CONFIG_PATH" -mkdir -p ~/.steam/sdk64 -mkdir -p ~/.steam/sdk32 -#make a backup of original files -mv ~/.steam/steam.pid ~/.steam/steam.pid.orig || true -mv ~/.steam/sdk64/steamclient.so ~/.steam/sdk64/steamclient.so.orig || true -mv ~/.steam/sdk32/steamclient.so ~/.steam/sdk32/steamclient.so.orig || true -#copy our files -cp x86/steamclient.so ~/.steam/sdk32/steamclient.so -cp x86_64/steamclient.so ~/.steam/sdk64/steamclient.so -echo $BASHPID > ~/.steam/steam.pid -cd "$APP_PATH" -if [ -z "$STEAM_RUNTIME" ] -then -SteamAppPath="$APP_PATH" SteamAppId=$APP_ID SteamGameId=$APP_ID "$APP_NAME" -else -SteamAppPath="$APP_PATH" SteamAppId=$APP_ID SteamGameId=$APP_ID "$STEAM_RUNTIME" "$APP_NAME" +if [ ! -d ~/.steam/sdk32 ]; then + mkdir -p ~/.steam/sdk32 +fi +if [ ! -d ~/.steam/sdk64 ]; then + mkdir -p ~/.steam/sdk64 +fi + +if [ ! -f ${STEAM_CLIENT_SO} ]; then + echo "Couldn't find the requested STEAM_CLIENT_SO." + exit +fi +if [ ! -f ${STEAM_CLIENT64_SO} ]; then + echo "Couldn't find the requested STEAM_CLIENT64_SO." + exit +fi + +# for system failure assume orig files are still good +if [ -f ~/.steam/steam.pid.orig ]; then + mv -f ~/.steam/steam.pid.orig ~/.steam/steam.pid +fi +if [ -f ~/.steam/sdk32/steamclient.so.orig ]; then + mv -f ~/.steam/sdk32/steamclient.so.orig ~/.steam/sdk32/steamclient.so +fi +if [ -f ~/.steam/sdk64/steamclient.so.orig ]; then + mv -f ~/.steam/sdk64/steamclient.so.orig ~/.steam/sdk64/steamclient.so +fi + +if [ -f ~/.steam/steam.pid ]; then + mv -f ~/.steam/steam.pid ~/.steam/steam.pid.orig +fi +if [ -f ~/.steam/sdk32/steamclient.so ]; then + mv -f ~/.steam/sdk32/steamclient.so ~/.steam/sdk32/steamclient.so.orig +fi +if [ -f ~/.steam/sdk64/steamclient.so ]; then + mv -f ~/.steam/sdk64/steamclient.so ~/.steam/sdk64/steamclient.so.orig +fi + +cp ${STEAM_CLIENT_SO} ~/.steam/sdk32/steamclient.so +cp ${STEAM_CLIENT64_SO} ~/.steam/sdk64/steamclient.so +echo ${$} > ~/.steam/steam.pid + +cd ${EXE_RUN_DIR} +if [ -z ${STEAM_RUNTIME} ]; then + SteamAppPath=${EXE_RUN_DIR} SteamAppId=${APP_ID} SteamGameId=${APP_ID} ${EXE} ${EXE_COMMAND_LINE} +else + SteamAppPath=${EXE_RUN_DIR} SteamAppId=${APP_ID} SteamGameId=${APP_ID} ${STEAM_RUNTIME} ${EXE} ${EXE_COMMAND_LINE} +fi + +if [ -f ~/.steam/steam.pid.orig ]; then + mv -f ~/.steam/steam.pid.orig ~/.steam/steam.pid +fi +if [ -f ~/.steam/sdk32/steamclient.so.orig ]; then + mv -f ~/.steam/sdk32/steamclient.so.orig ~/.steam/sdk32/steamclient.so +fi +if [ -f ~/.steam/sdk64/steamclient.so.orig ]; then + mv -f ~/.steam/sdk64/steamclient.so.orig ~/.steam/sdk64/steamclient.so fi -cd "$CUR_DIR" -#restore original -rm -f ~/.steam/steam.pid -rm -f ~/.steam/sdk64/steamclient.so -rm -f ~/.steam/sdk32/steamclient.so -mv ~/.steam/steam.pid.orig ~/.steam/steam.pid -mv ~/.steam/sdk64/steamclient.so.orig ~/.steam/sdk64/steamclient.so || true -mv ~/.steam/sdk32/steamclient.so.orig ~/.steam/sdk32/steamclient.so || true diff --git a/sdk_includes/isteamgameserverstats.h b/sdk_includes/isteamgameserverstats.h index bfa17ce4..8e41d437 100644 --- a/sdk_includes/isteamgameserverstats.h +++ b/sdk_includes/isteamgameserverstats.h @@ -1,4 +1,4 @@ -//====== Copyright © Valve Corporation, All rights reserved. ======= +//====== Copyright © Valve Corporation, All rights reserved. ======= // // Purpose: interface for game servers to steam stats and achievements // diff --git a/sdk_includes/isteaminventory.h b/sdk_includes/isteaminventory.h index 68e562ca..bdfc5446 100644 --- a/sdk_includes/isteaminventory.h +++ b/sdk_includes/isteaminventory.h @@ -1,4 +1,4 @@ -//====== Copyright © 1996-2014 Valve Corporation, All rights reserved. ======= +//====== Copyright © 1996-2014 Valve Corporation, All rights reserved. ======= // // Purpose: interface to Steam Inventory // diff --git a/sdk_includes/isteammasterserverupdater.h b/sdk_includes/isteammasterserverupdater.h index 9ea09a8b..08a4d2ad 100644 --- a/sdk_includes/isteammasterserverupdater.h +++ b/sdk_includes/isteammasterserverupdater.h @@ -1,4 +1,4 @@ -//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. ======= +//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. ======= // // Purpose: interface to steam for retrieving list of game servers // diff --git a/stb/stb_image_resize.h b/stb/stb_image_resize.h new file mode 100644 index 00000000..ef9e6fe8 --- /dev/null +++ b/stb/stb_image_resize.h @@ -0,0 +1,2634 @@ +/* stb_image_resize - v0.97 - public domain image resizing + by Jorge L Rodriguez (@VinoBS) - 2014 + http://github.com/nothings/stb + + Written with emphasis on usability, portability, and efficiency. (No + SIMD or threads, so it be easily outperformed by libs that use those.) + Only scaling and translation is supported, no rotations or shears. + Easy API downsamples w/Mitchell filter, upsamples w/cubic interpolation. + + COMPILING & LINKING + In one C/C++ file that #includes this file, do this: + #define STB_IMAGE_RESIZE_IMPLEMENTATION + before the #include. That will create the implementation in that file. + + QUICKSTART + stbir_resize_uint8( input_pixels , in_w , in_h , 0, + output_pixels, out_w, out_h, 0, num_channels) + stbir_resize_float(...) + stbir_resize_uint8_srgb( input_pixels , in_w , in_h , 0, + output_pixels, out_w, out_h, 0, + num_channels , alpha_chan , 0) + stbir_resize_uint8_srgb_edgemode( + input_pixels , in_w , in_h , 0, + output_pixels, out_w, out_h, 0, + num_channels , alpha_chan , 0, STBIR_EDGE_CLAMP) + // WRAP/REFLECT/ZERO + + FULL API + See the "header file" section of the source for API documentation. + + ADDITIONAL DOCUMENTATION + + SRGB & FLOATING POINT REPRESENTATION + The sRGB functions presume IEEE floating point. If you do not have + IEEE floating point, define STBIR_NON_IEEE_FLOAT. This will use + a slower implementation. + + MEMORY ALLOCATION + The resize functions here perform a single memory allocation using + malloc. To control the memory allocation, before the #include that + triggers the implementation, do: + + #define STBIR_MALLOC(size,context) ... + #define STBIR_FREE(ptr,context) ... + + Each resize function makes exactly one call to malloc/free, so to use + temp memory, store the temp memory in the context and return that. + + ASSERT + Define STBIR_ASSERT(boolval) to override assert() and not use assert.h + + OPTIMIZATION + Define STBIR_SATURATE_INT to compute clamp values in-range using + integer operations instead of float operations. This may be faster + on some platforms. + + DEFAULT FILTERS + For functions which don't provide explicit control over what filters + to use, you can change the compile-time defaults with + + #define STBIR_DEFAULT_FILTER_UPSAMPLE STBIR_FILTER_something + #define STBIR_DEFAULT_FILTER_DOWNSAMPLE STBIR_FILTER_something + + See stbir_filter in the header-file section for the list of filters. + + NEW FILTERS + A number of 1D filter kernels are used. For a list of + supported filters see the stbir_filter enum. To add a new filter, + write a filter function and add it to stbir__filter_info_table. + + PROGRESS + For interactive use with slow resize operations, you can install + a progress-report callback: + + #define STBIR_PROGRESS_REPORT(val) some_func(val) + + The parameter val is a float which goes from 0 to 1 as progress is made. + + For example: + + static void my_progress_report(float progress); + #define STBIR_PROGRESS_REPORT(val) my_progress_report(val) + + #define STB_IMAGE_RESIZE_IMPLEMENTATION + #include "stb_image_resize.h" + + static void my_progress_report(float progress) + { + printf("Progress: %f%%\n", progress*100); + } + + MAX CHANNELS + If your image has more than 64 channels, define STBIR_MAX_CHANNELS + to the max you'll have. + + ALPHA CHANNEL + Most of the resizing functions provide the ability to control how + the alpha channel of an image is processed. The important things + to know about this: + + 1. The best mathematically-behaved version of alpha to use is + called "premultiplied alpha", in which the other color channels + have had the alpha value multiplied in. If you use premultiplied + alpha, linear filtering (such as image resampling done by this + library, or performed in texture units on GPUs) does the "right + thing". While premultiplied alpha is standard in the movie CGI + industry, it is still uncommon in the videogame/real-time world. + + If you linearly filter non-premultiplied alpha, strange effects + occur. (For example, the 50/50 average of 99% transparent bright green + and 1% transparent black produces 50% transparent dark green when + non-premultiplied, whereas premultiplied it produces 50% + transparent near-black. The former introduces green energy + that doesn't exist in the source image.) + + 2. Artists should not edit premultiplied-alpha images; artists + want non-premultiplied alpha images. Thus, art tools generally output + non-premultiplied alpha images. + + 3. You will get best results in most cases by converting images + to premultiplied alpha before processing them mathematically. + + 4. If you pass the flag STBIR_FLAG_ALPHA_PREMULTIPLIED, the + resizer does not do anything special for the alpha channel; + it is resampled identically to other channels. This produces + the correct results for premultiplied-alpha images, but produces + less-than-ideal results for non-premultiplied-alpha images. + + 5. If you do not pass the flag STBIR_FLAG_ALPHA_PREMULTIPLIED, + then the resizer weights the contribution of input pixels + based on their alpha values, or, equivalently, it multiplies + the alpha value into the color channels, resamples, then divides + by the resultant alpha value. Input pixels which have alpha=0 do + not contribute at all to output pixels unless _all_ of the input + pixels affecting that output pixel have alpha=0, in which case + the result for that pixel is the same as it would be without + STBIR_FLAG_ALPHA_PREMULTIPLIED. However, this is only true for + input images in integer formats. For input images in float format, + input pixels with alpha=0 have no effect, and output pixels + which have alpha=0 will be 0 in all channels. (For float images, + you can manually achieve the same result by adding a tiny epsilon + value to the alpha channel of every image, and then subtracting + or clamping it at the end.) + + 6. You can suppress the behavior described in #5 and make + all-0-alpha pixels have 0 in all channels by #defining + STBIR_NO_ALPHA_EPSILON. + + 7. You can separately control whether the alpha channel is + interpreted as linear or affected by the colorspace. By default + it is linear; you almost never want to apply the colorspace. + (For example, graphics hardware does not apply sRGB conversion + to the alpha channel.) + + CONTRIBUTORS + Jorge L Rodriguez: Implementation + Sean Barrett: API design, optimizations + Aras Pranckevicius: bugfix + Nathan Reed: warning fixes + + REVISIONS + 0.97 (2020-02-02) fixed warning + 0.96 (2019-03-04) fixed warnings + 0.95 (2017-07-23) fixed warnings + 0.94 (2017-03-18) fixed warnings + 0.93 (2017-03-03) fixed bug with certain combinations of heights + 0.92 (2017-01-02) fix integer overflow on large (>2GB) images + 0.91 (2016-04-02) fix warnings; fix handling of subpixel regions + 0.90 (2014-09-17) first released version + + LICENSE + See end of file for license information. + + TODO + Don't decode all of the image data when only processing a partial tile + Don't use full-width decode buffers when only processing a partial tile + When processing wide images, break processing into tiles so data fits in L1 cache + Installable filters? + Resize that respects alpha test coverage + (Reference code: FloatImage::alphaTestCoverage and FloatImage::scaleAlphaToCoverage: + https://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvimage/FloatImage.cpp ) +*/ + +#ifndef STBIR_INCLUDE_STB_IMAGE_RESIZE_H +#define STBIR_INCLUDE_STB_IMAGE_RESIZE_H + +#ifdef _MSC_VER +typedef unsigned char stbir_uint8; +typedef unsigned short stbir_uint16; +typedef unsigned int stbir_uint32; +#else +#include +typedef uint8_t stbir_uint8; +typedef uint16_t stbir_uint16; +typedef uint32_t stbir_uint32; +#endif + +#ifndef STBIRDEF +#ifdef STB_IMAGE_RESIZE_STATIC +#define STBIRDEF static +#else +#ifdef __cplusplus +#define STBIRDEF extern "C" +#else +#define STBIRDEF extern +#endif +#endif +#endif + +////////////////////////////////////////////////////////////////////////////// +// +// Easy-to-use API: +// +// * "input pixels" points to an array of image data with 'num_channels' channels (e.g. RGB=3, RGBA=4) +// * input_w is input image width (x-axis), input_h is input image height (y-axis) +// * stride is the offset between successive rows of image data in memory, in bytes. you can +// specify 0 to mean packed continuously in memory +// * alpha channel is treated identically to other channels. +// * colorspace is linear or sRGB as specified by function name +// * returned result is 1 for success or 0 in case of an error. +// #define STBIR_ASSERT() to trigger an assert on parameter validation errors. +// * Memory required grows approximately linearly with input and output size, but with +// discontinuities at input_w == output_w and input_h == output_h. +// * These functions use a "default" resampling filter defined at compile time. To change the filter, +// you can change the compile-time defaults by #defining STBIR_DEFAULT_FILTER_UPSAMPLE +// and STBIR_DEFAULT_FILTER_DOWNSAMPLE, or you can use the medium-complexity API. + +STBIRDEF int stbir_resize_uint8( const unsigned char *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels); + +STBIRDEF int stbir_resize_float( const float *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + float *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels); + + +// The following functions interpret image data as gamma-corrected sRGB. +// Specify STBIR_ALPHA_CHANNEL_NONE if you have no alpha channel, +// or otherwise provide the index of the alpha channel. Flags value +// of 0 will probably do the right thing if you're not sure what +// the flags mean. + +#define STBIR_ALPHA_CHANNEL_NONE -1 + +// Set this flag if your texture has premultiplied alpha. Otherwise, stbir will +// use alpha-weighted resampling (effectively premultiplying, resampling, +// then unpremultiplying). +#define STBIR_FLAG_ALPHA_PREMULTIPLIED (1 << 0) +// The specified alpha channel should be handled as gamma-corrected value even +// when doing sRGB operations. +#define STBIR_FLAG_ALPHA_USES_COLORSPACE (1 << 1) + +STBIRDEF int stbir_resize_uint8_srgb(const unsigned char *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags); + + +typedef enum +{ + STBIR_EDGE_CLAMP = 1, + STBIR_EDGE_REFLECT = 2, + STBIR_EDGE_WRAP = 3, + STBIR_EDGE_ZERO = 4, +} stbir_edge; + +// This function adds the ability to specify how requests to sample off the edge of the image are handled. +STBIRDEF int stbir_resize_uint8_srgb_edgemode(const unsigned char *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_wrap_mode); + +////////////////////////////////////////////////////////////////////////////// +// +// Medium-complexity API +// +// This extends the easy-to-use API as follows: +// +// * Alpha-channel can be processed separately +// * If alpha_channel is not STBIR_ALPHA_CHANNEL_NONE +// * Alpha channel will not be gamma corrected (unless flags&STBIR_FLAG_GAMMA_CORRECT) +// * Filters will be weighted by alpha channel (unless flags&STBIR_FLAG_ALPHA_PREMULTIPLIED) +// * Filter can be selected explicitly +// * uint16 image type +// * sRGB colorspace available for all types +// * context parameter for passing to STBIR_MALLOC + +typedef enum +{ + STBIR_FILTER_DEFAULT = 0, // use same filter type that easy-to-use API chooses + STBIR_FILTER_BOX = 1, // A trapezoid w/1-pixel wide ramps, same result as box for integer scale ratios + STBIR_FILTER_TRIANGLE = 2, // On upsampling, produces same results as bilinear texture filtering + STBIR_FILTER_CUBICBSPLINE = 3, // The cubic b-spline (aka Mitchell-Netrevalli with B=1,C=0), gaussian-esque + STBIR_FILTER_CATMULLROM = 4, // An interpolating cubic spline + STBIR_FILTER_MITCHELL = 5, // Mitchell-Netrevalli filter with B=1/3, C=1/3 +} stbir_filter; + +typedef enum +{ + STBIR_COLORSPACE_LINEAR, + STBIR_COLORSPACE_SRGB, + + STBIR_MAX_COLORSPACES, +} stbir_colorspace; + +// The following functions are all identical except for the type of the image data + +STBIRDEF int stbir_resize_uint8_generic( const unsigned char *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_wrap_mode, stbir_filter filter, stbir_colorspace space, + void *alloc_context); + +STBIRDEF int stbir_resize_uint16_generic(const stbir_uint16 *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + stbir_uint16 *output_pixels , int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_wrap_mode, stbir_filter filter, stbir_colorspace space, + void *alloc_context); + +STBIRDEF int stbir_resize_float_generic( const float *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + float *output_pixels , int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_wrap_mode, stbir_filter filter, stbir_colorspace space, + void *alloc_context); + + + +////////////////////////////////////////////////////////////////////////////// +// +// Full-complexity API +// +// This extends the medium API as follows: +// +// * uint32 image type +// * not typesafe +// * separate filter types for each axis +// * separate edge modes for each axis +// * can specify scale explicitly for subpixel correctness +// * can specify image source tile using texture coordinates + +typedef enum +{ + STBIR_TYPE_UINT8 , + STBIR_TYPE_UINT16, + STBIR_TYPE_UINT32, + STBIR_TYPE_FLOAT , + + STBIR_MAX_TYPES +} stbir_datatype; + +STBIRDEF int stbir_resize( const void *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + stbir_datatype datatype, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_mode_horizontal, stbir_edge edge_mode_vertical, + stbir_filter filter_horizontal, stbir_filter filter_vertical, + stbir_colorspace space, void *alloc_context); + +STBIRDEF int stbir_resize_subpixel(const void *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + stbir_datatype datatype, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_mode_horizontal, stbir_edge edge_mode_vertical, + stbir_filter filter_horizontal, stbir_filter filter_vertical, + stbir_colorspace space, void *alloc_context, + float x_scale, float y_scale, + float x_offset, float y_offset); + +STBIRDEF int stbir_resize_region( const void *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + stbir_datatype datatype, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_mode_horizontal, stbir_edge edge_mode_vertical, + stbir_filter filter_horizontal, stbir_filter filter_vertical, + stbir_colorspace space, void *alloc_context, + float s0, float t0, float s1, float t1); +// (s0, t0) & (s1, t1) are the top-left and bottom right corner (uv addressing style: [0, 1]x[0, 1]) of a region of the input image to use. + +// +// +//// end header file ///////////////////////////////////////////////////// +#endif // STBIR_INCLUDE_STB_IMAGE_RESIZE_H + + + + + +#ifdef STB_IMAGE_RESIZE_IMPLEMENTATION + +#ifndef STBIR_ASSERT +#include +#define STBIR_ASSERT(x) assert(x) +#endif + +// For memset +#include + +#include + +#ifndef STBIR_MALLOC +#include +// use comma operator to evaluate c, to avoid "unused parameter" warnings +#define STBIR_MALLOC(size,c) ((void)(c), malloc(size)) +#define STBIR_FREE(ptr,c) ((void)(c), free(ptr)) +#endif + +#ifndef _MSC_VER +#ifdef __cplusplus +#define stbir__inline inline +#else +#define stbir__inline +#endif +#else +#define stbir__inline __forceinline +#endif + + +// should produce compiler error if size is wrong +typedef unsigned char stbir__validate_uint32[sizeof(stbir_uint32) == 4 ? 1 : -1]; + +#ifdef _MSC_VER +#define STBIR__NOTUSED(v) (void)(v) +#else +#define STBIR__NOTUSED(v) (void)sizeof(v) +#endif + +#define STBIR__ARRAY_SIZE(a) (sizeof((a))/sizeof((a)[0])) + +#ifndef STBIR_DEFAULT_FILTER_UPSAMPLE +#define STBIR_DEFAULT_FILTER_UPSAMPLE STBIR_FILTER_CATMULLROM +#endif + +#ifndef STBIR_DEFAULT_FILTER_DOWNSAMPLE +#define STBIR_DEFAULT_FILTER_DOWNSAMPLE STBIR_FILTER_MITCHELL +#endif + +#ifndef STBIR_PROGRESS_REPORT +#define STBIR_PROGRESS_REPORT(float_0_to_1) +#endif + +#ifndef STBIR_MAX_CHANNELS +#define STBIR_MAX_CHANNELS 64 +#endif + +#if STBIR_MAX_CHANNELS > 65536 +#error "Too many channels; STBIR_MAX_CHANNELS must be no more than 65536." +// because we store the indices in 16-bit variables +#endif + +// This value is added to alpha just before premultiplication to avoid +// zeroing out color values. It is equivalent to 2^-80. If you don't want +// that behavior (it may interfere if you have floating point images with +// very small alpha values) then you can define STBIR_NO_ALPHA_EPSILON to +// disable it. +#ifndef STBIR_ALPHA_EPSILON +#define STBIR_ALPHA_EPSILON ((float)1 / (1 << 20) / (1 << 20) / (1 << 20) / (1 << 20)) +#endif + + + +#ifdef _MSC_VER +#define STBIR__UNUSED_PARAM(v) (void)(v) +#else +#define STBIR__UNUSED_PARAM(v) (void)sizeof(v) +#endif + +// must match stbir_datatype +static unsigned char stbir__type_size[] = { + 1, // STBIR_TYPE_UINT8 + 2, // STBIR_TYPE_UINT16 + 4, // STBIR_TYPE_UINT32 + 4, // STBIR_TYPE_FLOAT +}; + +// Kernel function centered at 0 +typedef float (stbir__kernel_fn)(float x, float scale); +typedef float (stbir__support_fn)(float scale); + +typedef struct +{ + stbir__kernel_fn* kernel; + stbir__support_fn* support; +} stbir__filter_info; + +// When upsampling, the contributors are which source pixels contribute. +// When downsampling, the contributors are which destination pixels are contributed to. +typedef struct +{ + int n0; // First contributing pixel + int n1; // Last contributing pixel +} stbir__contributors; + +typedef struct +{ + const void* input_data; + int input_w; + int input_h; + int input_stride_bytes; + + void* output_data; + int output_w; + int output_h; + int output_stride_bytes; + + float s0, t0, s1, t1; + + float horizontal_shift; // Units: output pixels + float vertical_shift; // Units: output pixels + float horizontal_scale; + float vertical_scale; + + int channels; + int alpha_channel; + stbir_uint32 flags; + stbir_datatype type; + stbir_filter horizontal_filter; + stbir_filter vertical_filter; + stbir_edge edge_horizontal; + stbir_edge edge_vertical; + stbir_colorspace colorspace; + + stbir__contributors* horizontal_contributors; + float* horizontal_coefficients; + + stbir__contributors* vertical_contributors; + float* vertical_coefficients; + + int decode_buffer_pixels; + float* decode_buffer; + + float* horizontal_buffer; + + // cache these because ceil/floor are inexplicably showing up in profile + int horizontal_coefficient_width; + int vertical_coefficient_width; + int horizontal_filter_pixel_width; + int vertical_filter_pixel_width; + int horizontal_filter_pixel_margin; + int vertical_filter_pixel_margin; + int horizontal_num_contributors; + int vertical_num_contributors; + + int ring_buffer_length_bytes; // The length of an individual entry in the ring buffer. The total number of ring buffers is stbir__get_filter_pixel_width(filter) + int ring_buffer_num_entries; // Total number of entries in the ring buffer. + int ring_buffer_first_scanline; + int ring_buffer_last_scanline; + int ring_buffer_begin_index; // first_scanline is at this index in the ring buffer + float* ring_buffer; + + float* encode_buffer; // A temporary buffer to store floats so we don't lose precision while we do multiply-adds. + + int horizontal_contributors_size; + int horizontal_coefficients_size; + int vertical_contributors_size; + int vertical_coefficients_size; + int decode_buffer_size; + int horizontal_buffer_size; + int ring_buffer_size; + int encode_buffer_size; +} stbir__info; + + +static const float stbir__max_uint8_as_float = 255.0f; +static const float stbir__max_uint16_as_float = 65535.0f; +static const double stbir__max_uint32_as_float = 4294967295.0; + + +static stbir__inline int stbir__min(int a, int b) +{ + return a < b ? a : b; +} + +static stbir__inline float stbir__saturate(float x) +{ + if (x < 0) + return 0; + + if (x > 1) + return 1; + + return x; +} + +#ifdef STBIR_SATURATE_INT +static stbir__inline stbir_uint8 stbir__saturate8(int x) +{ + if ((unsigned int) x <= 255) + return x; + + if (x < 0) + return 0; + + return 255; +} + +static stbir__inline stbir_uint16 stbir__saturate16(int x) +{ + if ((unsigned int) x <= 65535) + return x; + + if (x < 0) + return 0; + + return 65535; +} +#endif + +static float stbir__srgb_uchar_to_linear_float[256] = { + 0.000000f, 0.000304f, 0.000607f, 0.000911f, 0.001214f, 0.001518f, 0.001821f, 0.002125f, 0.002428f, 0.002732f, 0.003035f, + 0.003347f, 0.003677f, 0.004025f, 0.004391f, 0.004777f, 0.005182f, 0.005605f, 0.006049f, 0.006512f, 0.006995f, 0.007499f, + 0.008023f, 0.008568f, 0.009134f, 0.009721f, 0.010330f, 0.010960f, 0.011612f, 0.012286f, 0.012983f, 0.013702f, 0.014444f, + 0.015209f, 0.015996f, 0.016807f, 0.017642f, 0.018500f, 0.019382f, 0.020289f, 0.021219f, 0.022174f, 0.023153f, 0.024158f, + 0.025187f, 0.026241f, 0.027321f, 0.028426f, 0.029557f, 0.030713f, 0.031896f, 0.033105f, 0.034340f, 0.035601f, 0.036889f, + 0.038204f, 0.039546f, 0.040915f, 0.042311f, 0.043735f, 0.045186f, 0.046665f, 0.048172f, 0.049707f, 0.051269f, 0.052861f, + 0.054480f, 0.056128f, 0.057805f, 0.059511f, 0.061246f, 0.063010f, 0.064803f, 0.066626f, 0.068478f, 0.070360f, 0.072272f, + 0.074214f, 0.076185f, 0.078187f, 0.080220f, 0.082283f, 0.084376f, 0.086500f, 0.088656f, 0.090842f, 0.093059f, 0.095307f, + 0.097587f, 0.099899f, 0.102242f, 0.104616f, 0.107023f, 0.109462f, 0.111932f, 0.114435f, 0.116971f, 0.119538f, 0.122139f, + 0.124772f, 0.127438f, 0.130136f, 0.132868f, 0.135633f, 0.138432f, 0.141263f, 0.144128f, 0.147027f, 0.149960f, 0.152926f, + 0.155926f, 0.158961f, 0.162029f, 0.165132f, 0.168269f, 0.171441f, 0.174647f, 0.177888f, 0.181164f, 0.184475f, 0.187821f, + 0.191202f, 0.194618f, 0.198069f, 0.201556f, 0.205079f, 0.208637f, 0.212231f, 0.215861f, 0.219526f, 0.223228f, 0.226966f, + 0.230740f, 0.234551f, 0.238398f, 0.242281f, 0.246201f, 0.250158f, 0.254152f, 0.258183f, 0.262251f, 0.266356f, 0.270498f, + 0.274677f, 0.278894f, 0.283149f, 0.287441f, 0.291771f, 0.296138f, 0.300544f, 0.304987f, 0.309469f, 0.313989f, 0.318547f, + 0.323143f, 0.327778f, 0.332452f, 0.337164f, 0.341914f, 0.346704f, 0.351533f, 0.356400f, 0.361307f, 0.366253f, 0.371238f, + 0.376262f, 0.381326f, 0.386430f, 0.391573f, 0.396755f, 0.401978f, 0.407240f, 0.412543f, 0.417885f, 0.423268f, 0.428691f, + 0.434154f, 0.439657f, 0.445201f, 0.450786f, 0.456411f, 0.462077f, 0.467784f, 0.473532f, 0.479320f, 0.485150f, 0.491021f, + 0.496933f, 0.502887f, 0.508881f, 0.514918f, 0.520996f, 0.527115f, 0.533276f, 0.539480f, 0.545725f, 0.552011f, 0.558340f, + 0.564712f, 0.571125f, 0.577581f, 0.584078f, 0.590619f, 0.597202f, 0.603827f, 0.610496f, 0.617207f, 0.623960f, 0.630757f, + 0.637597f, 0.644480f, 0.651406f, 0.658375f, 0.665387f, 0.672443f, 0.679543f, 0.686685f, 0.693872f, 0.701102f, 0.708376f, + 0.715694f, 0.723055f, 0.730461f, 0.737911f, 0.745404f, 0.752942f, 0.760525f, 0.768151f, 0.775822f, 0.783538f, 0.791298f, + 0.799103f, 0.806952f, 0.814847f, 0.822786f, 0.830770f, 0.838799f, 0.846873f, 0.854993f, 0.863157f, 0.871367f, 0.879622f, + 0.887923f, 0.896269f, 0.904661f, 0.913099f, 0.921582f, 0.930111f, 0.938686f, 0.947307f, 0.955974f, 0.964686f, 0.973445f, + 0.982251f, 0.991102f, 1.0f +}; + +static float stbir__srgb_to_linear(float f) +{ + if (f <= 0.04045f) + return f / 12.92f; + else + return (float)pow((f + 0.055f) / 1.055f, 2.4f); +} + +static float stbir__linear_to_srgb(float f) +{ + if (f <= 0.0031308f) + return f * 12.92f; + else + return 1.055f * (float)pow(f, 1 / 2.4f) - 0.055f; +} + +#ifndef STBIR_NON_IEEE_FLOAT +// From https://gist.github.com/rygorous/2203834 + +typedef union +{ + stbir_uint32 u; + float f; +} stbir__FP32; + +static const stbir_uint32 fp32_to_srgb8_tab4[104] = { + 0x0073000d, 0x007a000d, 0x0080000d, 0x0087000d, 0x008d000d, 0x0094000d, 0x009a000d, 0x00a1000d, + 0x00a7001a, 0x00b4001a, 0x00c1001a, 0x00ce001a, 0x00da001a, 0x00e7001a, 0x00f4001a, 0x0101001a, + 0x010e0033, 0x01280033, 0x01410033, 0x015b0033, 0x01750033, 0x018f0033, 0x01a80033, 0x01c20033, + 0x01dc0067, 0x020f0067, 0x02430067, 0x02760067, 0x02aa0067, 0x02dd0067, 0x03110067, 0x03440067, + 0x037800ce, 0x03df00ce, 0x044600ce, 0x04ad00ce, 0x051400ce, 0x057b00c5, 0x05dd00bc, 0x063b00b5, + 0x06970158, 0x07420142, 0x07e30130, 0x087b0120, 0x090b0112, 0x09940106, 0x0a1700fc, 0x0a9500f2, + 0x0b0f01cb, 0x0bf401ae, 0x0ccb0195, 0x0d950180, 0x0e56016e, 0x0f0d015e, 0x0fbc0150, 0x10630143, + 0x11070264, 0x1238023e, 0x1357021d, 0x14660201, 0x156601e9, 0x165a01d3, 0x174401c0, 0x182401af, + 0x18fe0331, 0x1a9602fe, 0x1c1502d2, 0x1d7e02ad, 0x1ed4028d, 0x201a0270, 0x21520256, 0x227d0240, + 0x239f0443, 0x25c003fe, 0x27bf03c4, 0x29a10392, 0x2b6a0367, 0x2d1d0341, 0x2ebe031f, 0x304d0300, + 0x31d105b0, 0x34a80555, 0x37520507, 0x39d504c5, 0x3c37048b, 0x3e7c0458, 0x40a8042a, 0x42bd0401, + 0x44c20798, 0x488e071e, 0x4c1c06b6, 0x4f76065d, 0x52a50610, 0x55ac05cc, 0x5892058f, 0x5b590559, + 0x5e0c0a23, 0x631c0980, 0x67db08f6, 0x6c55087f, 0x70940818, 0x74a007bd, 0x787d076c, 0x7c330723, +}; + +static stbir_uint8 stbir__linear_to_srgb_uchar(float in) +{ + static const stbir__FP32 almostone = { 0x3f7fffff }; // 1-eps + static const stbir__FP32 minval = { (127-13) << 23 }; + stbir_uint32 tab,bias,scale,t; + stbir__FP32 f; + + // Clamp to [2^(-13), 1-eps]; these two values map to 0 and 1, respectively. + // The tests are carefully written so that NaNs map to 0, same as in the reference + // implementation. + if (!(in > minval.f)) // written this way to catch NaNs + in = minval.f; + if (in > almostone.f) + in = almostone.f; + + // Do the table lookup and unpack bias, scale + f.f = in; + tab = fp32_to_srgb8_tab4[(f.u - minval.u) >> 20]; + bias = (tab >> 16) << 9; + scale = tab & 0xffff; + + // Grab next-highest mantissa bits and perform linear interpolation + t = (f.u >> 12) & 0xff; + return (unsigned char) ((bias + scale*t) >> 16); +} + +#else +// sRGB transition values, scaled by 1<<28 +static int stbir__srgb_offset_to_linear_scaled[256] = +{ + 0, 40738, 122216, 203693, 285170, 366648, 448125, 529603, + 611080, 692557, 774035, 855852, 942009, 1033024, 1128971, 1229926, + 1335959, 1447142, 1563542, 1685229, 1812268, 1944725, 2082664, 2226148, + 2375238, 2529996, 2690481, 2856753, 3028870, 3206888, 3390865, 3580856, + 3776916, 3979100, 4187460, 4402049, 4622919, 4850123, 5083710, 5323731, + 5570236, 5823273, 6082892, 6349140, 6622065, 6901714, 7188133, 7481369, + 7781466, 8088471, 8402427, 8723380, 9051372, 9386448, 9728650, 10078021, + 10434603, 10798439, 11169569, 11548036, 11933879, 12327139, 12727857, 13136073, + 13551826, 13975156, 14406100, 14844697, 15290987, 15745007, 16206795, 16676389, + 17153826, 17639142, 18132374, 18633560, 19142734, 19659934, 20185196, 20718552, + 21260042, 21809696, 22367554, 22933648, 23508010, 24090680, 24681686, 25281066, + 25888850, 26505076, 27129772, 27762974, 28404716, 29055026, 29713942, 30381490, + 31057708, 31742624, 32436272, 33138682, 33849884, 34569912, 35298800, 36036568, + 36783260, 37538896, 38303512, 39077136, 39859796, 40651528, 41452360, 42262316, + 43081432, 43909732, 44747252, 45594016, 46450052, 47315392, 48190064, 49074096, + 49967516, 50870356, 51782636, 52704392, 53635648, 54576432, 55526772, 56486700, + 57456236, 58435408, 59424248, 60422780, 61431036, 62449032, 63476804, 64514376, + 65561776, 66619028, 67686160, 68763192, 69850160, 70947088, 72053992, 73170912, + 74297864, 75434880, 76581976, 77739184, 78906536, 80084040, 81271736, 82469648, + 83677792, 84896192, 86124888, 87363888, 88613232, 89872928, 91143016, 92423512, + 93714432, 95015816, 96327688, 97650056, 98982952, 100326408, 101680440, 103045072, + 104420320, 105806224, 107202800, 108610064, 110028048, 111456776, 112896264, 114346544, + 115807632, 117279552, 118762328, 120255976, 121760536, 123276016, 124802440, 126339832, + 127888216, 129447616, 131018048, 132599544, 134192112, 135795792, 137410592, 139036528, + 140673648, 142321952, 143981456, 145652208, 147334208, 149027488, 150732064, 152447968, + 154175200, 155913792, 157663776, 159425168, 161197984, 162982240, 164777968, 166585184, + 168403904, 170234160, 172075968, 173929344, 175794320, 177670896, 179559120, 181458992, + 183370528, 185293776, 187228736, 189175424, 191133888, 193104112, 195086128, 197079968, + 199085648, 201103184, 203132592, 205173888, 207227120, 209292272, 211369392, 213458480, + 215559568, 217672656, 219797792, 221934976, 224084240, 226245600, 228419056, 230604656, + 232802400, 235012320, 237234432, 239468736, 241715280, 243974080, 246245120, 248528464, + 250824112, 253132064, 255452368, 257785040, 260130080, 262487520, 264857376, 267239664, +}; + +static stbir_uint8 stbir__linear_to_srgb_uchar(float f) +{ + int x = (int) (f * (1 << 28)); // has headroom so you don't need to clamp + int v = 0; + int i; + + // Refine the guess with a short binary search. + i = v + 128; if (x >= stbir__srgb_offset_to_linear_scaled[i]) v = i; + i = v + 64; if (x >= stbir__srgb_offset_to_linear_scaled[i]) v = i; + i = v + 32; if (x >= stbir__srgb_offset_to_linear_scaled[i]) v = i; + i = v + 16; if (x >= stbir__srgb_offset_to_linear_scaled[i]) v = i; + i = v + 8; if (x >= stbir__srgb_offset_to_linear_scaled[i]) v = i; + i = v + 4; if (x >= stbir__srgb_offset_to_linear_scaled[i]) v = i; + i = v + 2; if (x >= stbir__srgb_offset_to_linear_scaled[i]) v = i; + i = v + 1; if (x >= stbir__srgb_offset_to_linear_scaled[i]) v = i; + + return (stbir_uint8) v; +} +#endif + +static float stbir__filter_trapezoid(float x, float scale) +{ + float halfscale = scale / 2; + float t = 0.5f + halfscale; + STBIR_ASSERT(scale <= 1); + + x = (float)fabs(x); + + if (x >= t) + return 0; + else + { + float r = 0.5f - halfscale; + if (x <= r) + return 1; + else + return (t - x) / scale; + } +} + +static float stbir__support_trapezoid(float scale) +{ + STBIR_ASSERT(scale <= 1); + return 0.5f + scale / 2; +} + +static float stbir__filter_triangle(float x, float s) +{ + STBIR__UNUSED_PARAM(s); + + x = (float)fabs(x); + + if (x <= 1.0f) + return 1 - x; + else + return 0; +} + +static float stbir__filter_cubic(float x, float s) +{ + STBIR__UNUSED_PARAM(s); + + x = (float)fabs(x); + + if (x < 1.0f) + return (4 + x*x*(3*x - 6))/6; + else if (x < 2.0f) + return (8 + x*(-12 + x*(6 - x)))/6; + + return (0.0f); +} + +static float stbir__filter_catmullrom(float x, float s) +{ + STBIR__UNUSED_PARAM(s); + + x = (float)fabs(x); + + if (x < 1.0f) + return 1 - x*x*(2.5f - 1.5f*x); + else if (x < 2.0f) + return 2 - x*(4 + x*(0.5f*x - 2.5f)); + + return (0.0f); +} + +static float stbir__filter_mitchell(float x, float s) +{ + STBIR__UNUSED_PARAM(s); + + x = (float)fabs(x); + + if (x < 1.0f) + return (16 + x*x*(21 * x - 36))/18; + else if (x < 2.0f) + return (32 + x*(-60 + x*(36 - 7*x)))/18; + + return (0.0f); +} + +static float stbir__support_zero(float s) +{ + STBIR__UNUSED_PARAM(s); + return 0; +} + +static float stbir__support_one(float s) +{ + STBIR__UNUSED_PARAM(s); + return 1; +} + +static float stbir__support_two(float s) +{ + STBIR__UNUSED_PARAM(s); + return 2; +} + +static stbir__filter_info stbir__filter_info_table[] = { + { NULL, stbir__support_zero }, + { stbir__filter_trapezoid, stbir__support_trapezoid }, + { stbir__filter_triangle, stbir__support_one }, + { stbir__filter_cubic, stbir__support_two }, + { stbir__filter_catmullrom, stbir__support_two }, + { stbir__filter_mitchell, stbir__support_two }, +}; + +stbir__inline static int stbir__use_upsampling(float ratio) +{ + return ratio > 1; +} + +stbir__inline static int stbir__use_width_upsampling(stbir__info* stbir_info) +{ + return stbir__use_upsampling(stbir_info->horizontal_scale); +} + +stbir__inline static int stbir__use_height_upsampling(stbir__info* stbir_info) +{ + return stbir__use_upsampling(stbir_info->vertical_scale); +} + +// This is the maximum number of input samples that can affect an output sample +// with the given filter +static int stbir__get_filter_pixel_width(stbir_filter filter, float scale) +{ + STBIR_ASSERT(filter != 0); + STBIR_ASSERT(filter < STBIR__ARRAY_SIZE(stbir__filter_info_table)); + + if (stbir__use_upsampling(scale)) + return (int)ceil(stbir__filter_info_table[filter].support(1/scale) * 2); + else + return (int)ceil(stbir__filter_info_table[filter].support(scale) * 2 / scale); +} + +// This is how much to expand buffers to account for filters seeking outside +// the image boundaries. +static int stbir__get_filter_pixel_margin(stbir_filter filter, float scale) +{ + return stbir__get_filter_pixel_width(filter, scale) / 2; +} + +static int stbir__get_coefficient_width(stbir_filter filter, float scale) +{ + if (stbir__use_upsampling(scale)) + return (int)ceil(stbir__filter_info_table[filter].support(1 / scale) * 2); + else + return (int)ceil(stbir__filter_info_table[filter].support(scale) * 2); +} + +static int stbir__get_contributors(float scale, stbir_filter filter, int input_size, int output_size) +{ + if (stbir__use_upsampling(scale)) + return output_size; + else + return (input_size + stbir__get_filter_pixel_margin(filter, scale) * 2); +} + +static int stbir__get_total_horizontal_coefficients(stbir__info* info) +{ + return info->horizontal_num_contributors + * stbir__get_coefficient_width (info->horizontal_filter, info->horizontal_scale); +} + +static int stbir__get_total_vertical_coefficients(stbir__info* info) +{ + return info->vertical_num_contributors + * stbir__get_coefficient_width (info->vertical_filter, info->vertical_scale); +} + +static stbir__contributors* stbir__get_contributor(stbir__contributors* contributors, int n) +{ + return &contributors[n]; +} + +// For perf reasons this code is duplicated in stbir__resample_horizontal_upsample/downsample, +// if you change it here change it there too. +static float* stbir__get_coefficient(float* coefficients, stbir_filter filter, float scale, int n, int c) +{ + int width = stbir__get_coefficient_width(filter, scale); + return &coefficients[width*n + c]; +} + +static int stbir__edge_wrap_slow(stbir_edge edge, int n, int max) +{ + switch (edge) + { + case STBIR_EDGE_ZERO: + return 0; // we'll decode the wrong pixel here, and then overwrite with 0s later + + case STBIR_EDGE_CLAMP: + if (n < 0) + return 0; + + if (n >= max) + return max - 1; + + return n; // NOTREACHED + + case STBIR_EDGE_REFLECT: + { + if (n < 0) + { + if (n < max) + return -n; + else + return max - 1; + } + + if (n >= max) + { + int max2 = max * 2; + if (n >= max2) + return 0; + else + return max2 - n - 1; + } + + return n; // NOTREACHED + } + + case STBIR_EDGE_WRAP: + if (n >= 0) + return (n % max); + else + { + int m = (-n) % max; + + if (m != 0) + m = max - m; + + return (m); + } + // NOTREACHED + + default: + STBIR_ASSERT(!"Unimplemented edge type"); + return 0; + } +} + +stbir__inline static int stbir__edge_wrap(stbir_edge edge, int n, int max) +{ + // avoid per-pixel switch + if (n >= 0 && n < max) + return n; + return stbir__edge_wrap_slow(edge, n, max); +} + +// What input pixels contribute to this output pixel? +static void stbir__calculate_sample_range_upsample(int n, float out_filter_radius, float scale_ratio, float out_shift, int* in_first_pixel, int* in_last_pixel, float* in_center_of_out) +{ + float out_pixel_center = (float)n + 0.5f; + float out_pixel_influence_lowerbound = out_pixel_center - out_filter_radius; + float out_pixel_influence_upperbound = out_pixel_center + out_filter_radius; + + float in_pixel_influence_lowerbound = (out_pixel_influence_lowerbound + out_shift) / scale_ratio; + float in_pixel_influence_upperbound = (out_pixel_influence_upperbound + out_shift) / scale_ratio; + + *in_center_of_out = (out_pixel_center + out_shift) / scale_ratio; + *in_first_pixel = (int)(floor(in_pixel_influence_lowerbound + 0.5)); + *in_last_pixel = (int)(floor(in_pixel_influence_upperbound - 0.5)); +} + +// What output pixels does this input pixel contribute to? +static void stbir__calculate_sample_range_downsample(int n, float in_pixels_radius, float scale_ratio, float out_shift, int* out_first_pixel, int* out_last_pixel, float* out_center_of_in) +{ + float in_pixel_center = (float)n + 0.5f; + float in_pixel_influence_lowerbound = in_pixel_center - in_pixels_radius; + float in_pixel_influence_upperbound = in_pixel_center + in_pixels_radius; + + float out_pixel_influence_lowerbound = in_pixel_influence_lowerbound * scale_ratio - out_shift; + float out_pixel_influence_upperbound = in_pixel_influence_upperbound * scale_ratio - out_shift; + + *out_center_of_in = in_pixel_center * scale_ratio - out_shift; + *out_first_pixel = (int)(floor(out_pixel_influence_lowerbound + 0.5)); + *out_last_pixel = (int)(floor(out_pixel_influence_upperbound - 0.5)); +} + +static void stbir__calculate_coefficients_upsample(stbir_filter filter, float scale, int in_first_pixel, int in_last_pixel, float in_center_of_out, stbir__contributors* contributor, float* coefficient_group) +{ + int i; + float total_filter = 0; + float filter_scale; + + STBIR_ASSERT(in_last_pixel - in_first_pixel <= (int)ceil(stbir__filter_info_table[filter].support(1/scale) * 2)); // Taken directly from stbir__get_coefficient_width() which we can't call because we don't know if we're horizontal or vertical. + + contributor->n0 = in_first_pixel; + contributor->n1 = in_last_pixel; + + STBIR_ASSERT(contributor->n1 >= contributor->n0); + + for (i = 0; i <= in_last_pixel - in_first_pixel; i++) + { + float in_pixel_center = (float)(i + in_first_pixel) + 0.5f; + coefficient_group[i] = stbir__filter_info_table[filter].kernel(in_center_of_out - in_pixel_center, 1 / scale); + + // If the coefficient is zero, skip it. (Don't do the <0 check here, we want the influence of those outside pixels.) + if (i == 0 && !coefficient_group[i]) + { + contributor->n0 = ++in_first_pixel; + i--; + continue; + } + + total_filter += coefficient_group[i]; + } + + // NOTE(fg): Not actually true in general, nor is there any reason to expect it should be. + // It would be true in exact math but is at best approximately true in floating-point math, + // and it would not make sense to try and put actual bounds on this here because it depends + // on the image aspect ratio which can get pretty extreme. + //STBIR_ASSERT(stbir__filter_info_table[filter].kernel((float)(in_last_pixel + 1) + 0.5f - in_center_of_out, 1/scale) == 0); + + STBIR_ASSERT(total_filter > 0.9); + STBIR_ASSERT(total_filter < 1.1f); // Make sure it's not way off. + + // Make sure the sum of all coefficients is 1. + filter_scale = 1 / total_filter; + + for (i = 0; i <= in_last_pixel - in_first_pixel; i++) + coefficient_group[i] *= filter_scale; + + for (i = in_last_pixel - in_first_pixel; i >= 0; i--) + { + if (coefficient_group[i]) + break; + + // This line has no weight. We can skip it. + contributor->n1 = contributor->n0 + i - 1; + } +} + +static void stbir__calculate_coefficients_downsample(stbir_filter filter, float scale_ratio, int out_first_pixel, int out_last_pixel, float out_center_of_in, stbir__contributors* contributor, float* coefficient_group) +{ + int i; + + STBIR_ASSERT(out_last_pixel - out_first_pixel <= (int)ceil(stbir__filter_info_table[filter].support(scale_ratio) * 2)); // Taken directly from stbir__get_coefficient_width() which we can't call because we don't know if we're horizontal or vertical. + + contributor->n0 = out_first_pixel; + contributor->n1 = out_last_pixel; + + STBIR_ASSERT(contributor->n1 >= contributor->n0); + + for (i = 0; i <= out_last_pixel - out_first_pixel; i++) + { + float out_pixel_center = (float)(i + out_first_pixel) + 0.5f; + float x = out_pixel_center - out_center_of_in; + coefficient_group[i] = stbir__filter_info_table[filter].kernel(x, scale_ratio) * scale_ratio; + } + + // NOTE(fg): Not actually true in general, nor is there any reason to expect it should be. + // It would be true in exact math but is at best approximately true in floating-point math, + // and it would not make sense to try and put actual bounds on this here because it depends + // on the image aspect ratio which can get pretty extreme. + //STBIR_ASSERT(stbir__filter_info_table[filter].kernel((float)(out_last_pixel + 1) + 0.5f - out_center_of_in, scale_ratio) == 0); + + for (i = out_last_pixel - out_first_pixel; i >= 0; i--) + { + if (coefficient_group[i]) + break; + + // This line has no weight. We can skip it. + contributor->n1 = contributor->n0 + i - 1; + } +} + +static void stbir__normalize_downsample_coefficients(stbir__contributors* contributors, float* coefficients, stbir_filter filter, float scale_ratio, int input_size, int output_size) +{ + int num_contributors = stbir__get_contributors(scale_ratio, filter, input_size, output_size); + int num_coefficients = stbir__get_coefficient_width(filter, scale_ratio); + int i, j; + int skip; + + for (i = 0; i < output_size; i++) + { + float scale; + float total = 0; + + for (j = 0; j < num_contributors; j++) + { + if (i >= contributors[j].n0 && i <= contributors[j].n1) + { + float coefficient = *stbir__get_coefficient(coefficients, filter, scale_ratio, j, i - contributors[j].n0); + total += coefficient; + } + else if (i < contributors[j].n0) + break; + } + + STBIR_ASSERT(total > 0.9f); + STBIR_ASSERT(total < 1.1f); + + scale = 1 / total; + + for (j = 0; j < num_contributors; j++) + { + if (i >= contributors[j].n0 && i <= contributors[j].n1) + *stbir__get_coefficient(coefficients, filter, scale_ratio, j, i - contributors[j].n0) *= scale; + else if (i < contributors[j].n0) + break; + } + } + + // Optimize: Skip zero coefficients and contributions outside of image bounds. + // Do this after normalizing because normalization depends on the n0/n1 values. + for (j = 0; j < num_contributors; j++) + { + int range, max, width; + + skip = 0; + while (*stbir__get_coefficient(coefficients, filter, scale_ratio, j, skip) == 0) + skip++; + + contributors[j].n0 += skip; + + while (contributors[j].n0 < 0) + { + contributors[j].n0++; + skip++; + } + + range = contributors[j].n1 - contributors[j].n0 + 1; + max = stbir__min(num_coefficients, range); + + width = stbir__get_coefficient_width(filter, scale_ratio); + for (i = 0; i < max; i++) + { + if (i + skip >= width) + break; + + *stbir__get_coefficient(coefficients, filter, scale_ratio, j, i) = *stbir__get_coefficient(coefficients, filter, scale_ratio, j, i + skip); + } + + continue; + } + + // Using min to avoid writing into invalid pixels. + for (i = 0; i < num_contributors; i++) + contributors[i].n1 = stbir__min(contributors[i].n1, output_size - 1); +} + +// Each scan line uses the same kernel values so we should calculate the kernel +// values once and then we can use them for every scan line. +static void stbir__calculate_filters(stbir__contributors* contributors, float* coefficients, stbir_filter filter, float scale_ratio, float shift, int input_size, int output_size) +{ + int n; + int total_contributors = stbir__get_contributors(scale_ratio, filter, input_size, output_size); + + if (stbir__use_upsampling(scale_ratio)) + { + float out_pixels_radius = stbir__filter_info_table[filter].support(1 / scale_ratio) * scale_ratio; + + // Looping through out pixels + for (n = 0; n < total_contributors; n++) + { + float in_center_of_out; // Center of the current out pixel in the in pixel space + int in_first_pixel, in_last_pixel; + + stbir__calculate_sample_range_upsample(n, out_pixels_radius, scale_ratio, shift, &in_first_pixel, &in_last_pixel, &in_center_of_out); + + stbir__calculate_coefficients_upsample(filter, scale_ratio, in_first_pixel, in_last_pixel, in_center_of_out, stbir__get_contributor(contributors, n), stbir__get_coefficient(coefficients, filter, scale_ratio, n, 0)); + } + } + else + { + float in_pixels_radius = stbir__filter_info_table[filter].support(scale_ratio) / scale_ratio; + + // Looping through in pixels + for (n = 0; n < total_contributors; n++) + { + float out_center_of_in; // Center of the current out pixel in the in pixel space + int out_first_pixel, out_last_pixel; + int n_adjusted = n - stbir__get_filter_pixel_margin(filter, scale_ratio); + + stbir__calculate_sample_range_downsample(n_adjusted, in_pixels_radius, scale_ratio, shift, &out_first_pixel, &out_last_pixel, &out_center_of_in); + + stbir__calculate_coefficients_downsample(filter, scale_ratio, out_first_pixel, out_last_pixel, out_center_of_in, stbir__get_contributor(contributors, n), stbir__get_coefficient(coefficients, filter, scale_ratio, n, 0)); + } + + stbir__normalize_downsample_coefficients(contributors, coefficients, filter, scale_ratio, input_size, output_size); + } +} + +static float* stbir__get_decode_buffer(stbir__info* stbir_info) +{ + // The 0 index of the decode buffer starts after the margin. This makes + // it okay to use negative indexes on the decode buffer. + return &stbir_info->decode_buffer[stbir_info->horizontal_filter_pixel_margin * stbir_info->channels]; +} + +#define STBIR__DECODE(type, colorspace) ((int)(type) * (STBIR_MAX_COLORSPACES) + (int)(colorspace)) + +static void stbir__decode_scanline(stbir__info* stbir_info, int n) +{ + int c; + int channels = stbir_info->channels; + int alpha_channel = stbir_info->alpha_channel; + int type = stbir_info->type; + int colorspace = stbir_info->colorspace; + int input_w = stbir_info->input_w; + size_t input_stride_bytes = stbir_info->input_stride_bytes; + float* decode_buffer = stbir__get_decode_buffer(stbir_info); + stbir_edge edge_horizontal = stbir_info->edge_horizontal; + stbir_edge edge_vertical = stbir_info->edge_vertical; + size_t in_buffer_row_offset = stbir__edge_wrap(edge_vertical, n, stbir_info->input_h) * input_stride_bytes; + const void* input_data = (char *) stbir_info->input_data + in_buffer_row_offset; + int max_x = input_w + stbir_info->horizontal_filter_pixel_margin; + int decode = STBIR__DECODE(type, colorspace); + + int x = -stbir_info->horizontal_filter_pixel_margin; + + // special handling for STBIR_EDGE_ZERO because it needs to return an item that doesn't appear in the input, + // and we want to avoid paying overhead on every pixel if not STBIR_EDGE_ZERO + if (edge_vertical == STBIR_EDGE_ZERO && (n < 0 || n >= stbir_info->input_h)) + { + for (; x < max_x; x++) + for (c = 0; c < channels; c++) + decode_buffer[x*channels + c] = 0; + return; + } + + switch (decode) + { + case STBIR__DECODE(STBIR_TYPE_UINT8, STBIR_COLORSPACE_LINEAR): + for (; x < max_x; x++) + { + int decode_pixel_index = x * channels; + int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels; + for (c = 0; c < channels; c++) + decode_buffer[decode_pixel_index + c] = ((float)((const unsigned char*)input_data)[input_pixel_index + c]) / stbir__max_uint8_as_float; + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT8, STBIR_COLORSPACE_SRGB): + for (; x < max_x; x++) + { + int decode_pixel_index = x * channels; + int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels; + for (c = 0; c < channels; c++) + decode_buffer[decode_pixel_index + c] = stbir__srgb_uchar_to_linear_float[((const unsigned char*)input_data)[input_pixel_index + c]]; + + if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) + decode_buffer[decode_pixel_index + alpha_channel] = ((float)((const unsigned char*)input_data)[input_pixel_index + alpha_channel]) / stbir__max_uint8_as_float; + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT16, STBIR_COLORSPACE_LINEAR): + for (; x < max_x; x++) + { + int decode_pixel_index = x * channels; + int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels; + for (c = 0; c < channels; c++) + decode_buffer[decode_pixel_index + c] = ((float)((const unsigned short*)input_data)[input_pixel_index + c]) / stbir__max_uint16_as_float; + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT16, STBIR_COLORSPACE_SRGB): + for (; x < max_x; x++) + { + int decode_pixel_index = x * channels; + int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels; + for (c = 0; c < channels; c++) + decode_buffer[decode_pixel_index + c] = stbir__srgb_to_linear(((float)((const unsigned short*)input_data)[input_pixel_index + c]) / stbir__max_uint16_as_float); + + if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) + decode_buffer[decode_pixel_index + alpha_channel] = ((float)((const unsigned short*)input_data)[input_pixel_index + alpha_channel]) / stbir__max_uint16_as_float; + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT32, STBIR_COLORSPACE_LINEAR): + for (; x < max_x; x++) + { + int decode_pixel_index = x * channels; + int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels; + for (c = 0; c < channels; c++) + decode_buffer[decode_pixel_index + c] = (float)(((double)((const unsigned int*)input_data)[input_pixel_index + c]) / stbir__max_uint32_as_float); + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT32, STBIR_COLORSPACE_SRGB): + for (; x < max_x; x++) + { + int decode_pixel_index = x * channels; + int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels; + for (c = 0; c < channels; c++) + decode_buffer[decode_pixel_index + c] = stbir__srgb_to_linear((float)(((double)((const unsigned int*)input_data)[input_pixel_index + c]) / stbir__max_uint32_as_float)); + + if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) + decode_buffer[decode_pixel_index + alpha_channel] = (float)(((double)((const unsigned int*)input_data)[input_pixel_index + alpha_channel]) / stbir__max_uint32_as_float); + } + break; + + case STBIR__DECODE(STBIR_TYPE_FLOAT, STBIR_COLORSPACE_LINEAR): + for (; x < max_x; x++) + { + int decode_pixel_index = x * channels; + int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels; + for (c = 0; c < channels; c++) + decode_buffer[decode_pixel_index + c] = ((const float*)input_data)[input_pixel_index + c]; + } + break; + + case STBIR__DECODE(STBIR_TYPE_FLOAT, STBIR_COLORSPACE_SRGB): + for (; x < max_x; x++) + { + int decode_pixel_index = x * channels; + int input_pixel_index = stbir__edge_wrap(edge_horizontal, x, input_w) * channels; + for (c = 0; c < channels; c++) + decode_buffer[decode_pixel_index + c] = stbir__srgb_to_linear(((const float*)input_data)[input_pixel_index + c]); + + if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) + decode_buffer[decode_pixel_index + alpha_channel] = ((const float*)input_data)[input_pixel_index + alpha_channel]; + } + + break; + + default: + STBIR_ASSERT(!"Unknown type/colorspace/channels combination."); + break; + } + + if (!(stbir_info->flags & STBIR_FLAG_ALPHA_PREMULTIPLIED)) + { + for (x = -stbir_info->horizontal_filter_pixel_margin; x < max_x; x++) + { + int decode_pixel_index = x * channels; + + // If the alpha value is 0 it will clobber the color values. Make sure it's not. + float alpha = decode_buffer[decode_pixel_index + alpha_channel]; +#ifndef STBIR_NO_ALPHA_EPSILON + if (stbir_info->type != STBIR_TYPE_FLOAT) { + alpha += STBIR_ALPHA_EPSILON; + decode_buffer[decode_pixel_index + alpha_channel] = alpha; + } +#endif + for (c = 0; c < channels; c++) + { + if (c == alpha_channel) + continue; + + decode_buffer[decode_pixel_index + c] *= alpha; + } + } + } + + if (edge_horizontal == STBIR_EDGE_ZERO) + { + for (x = -stbir_info->horizontal_filter_pixel_margin; x < 0; x++) + { + for (c = 0; c < channels; c++) + decode_buffer[x*channels + c] = 0; + } + for (x = input_w; x < max_x; x++) + { + for (c = 0; c < channels; c++) + decode_buffer[x*channels + c] = 0; + } + } +} + +static float* stbir__get_ring_buffer_entry(float* ring_buffer, int index, int ring_buffer_length) +{ + return &ring_buffer[index * ring_buffer_length]; +} + +static float* stbir__add_empty_ring_buffer_entry(stbir__info* stbir_info, int n) +{ + int ring_buffer_index; + float* ring_buffer; + + stbir_info->ring_buffer_last_scanline = n; + + if (stbir_info->ring_buffer_begin_index < 0) + { + ring_buffer_index = stbir_info->ring_buffer_begin_index = 0; + stbir_info->ring_buffer_first_scanline = n; + } + else + { + ring_buffer_index = (stbir_info->ring_buffer_begin_index + (stbir_info->ring_buffer_last_scanline - stbir_info->ring_buffer_first_scanline)) % stbir_info->ring_buffer_num_entries; + STBIR_ASSERT(ring_buffer_index != stbir_info->ring_buffer_begin_index); + } + + ring_buffer = stbir__get_ring_buffer_entry(stbir_info->ring_buffer, ring_buffer_index, stbir_info->ring_buffer_length_bytes / sizeof(float)); + memset(ring_buffer, 0, stbir_info->ring_buffer_length_bytes); + + return ring_buffer; +} + + +static void stbir__resample_horizontal_upsample(stbir__info* stbir_info, float* output_buffer) +{ + int x, k; + int output_w = stbir_info->output_w; + int channels = stbir_info->channels; + float* decode_buffer = stbir__get_decode_buffer(stbir_info); + stbir__contributors* horizontal_contributors = stbir_info->horizontal_contributors; + float* horizontal_coefficients = stbir_info->horizontal_coefficients; + int coefficient_width = stbir_info->horizontal_coefficient_width; + + for (x = 0; x < output_w; x++) + { + int n0 = horizontal_contributors[x].n0; + int n1 = horizontal_contributors[x].n1; + + int out_pixel_index = x * channels; + int coefficient_group = coefficient_width * x; + int coefficient_counter = 0; + + STBIR_ASSERT(n1 >= n0); + STBIR_ASSERT(n0 >= -stbir_info->horizontal_filter_pixel_margin); + STBIR_ASSERT(n1 >= -stbir_info->horizontal_filter_pixel_margin); + STBIR_ASSERT(n0 < stbir_info->input_w + stbir_info->horizontal_filter_pixel_margin); + STBIR_ASSERT(n1 < stbir_info->input_w + stbir_info->horizontal_filter_pixel_margin); + + switch (channels) { + case 1: + for (k = n0; k <= n1; k++) + { + int in_pixel_index = k * 1; + float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++]; + STBIR_ASSERT(coefficient != 0); + output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient; + } + break; + case 2: + for (k = n0; k <= n1; k++) + { + int in_pixel_index = k * 2; + float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++]; + STBIR_ASSERT(coefficient != 0); + output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient; + output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient; + } + break; + case 3: + for (k = n0; k <= n1; k++) + { + int in_pixel_index = k * 3; + float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++]; + STBIR_ASSERT(coefficient != 0); + output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient; + output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient; + output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient; + } + break; + case 4: + for (k = n0; k <= n1; k++) + { + int in_pixel_index = k * 4; + float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++]; + STBIR_ASSERT(coefficient != 0); + output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient; + output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient; + output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient; + output_buffer[out_pixel_index + 3] += decode_buffer[in_pixel_index + 3] * coefficient; + } + break; + default: + for (k = n0; k <= n1; k++) + { + int in_pixel_index = k * channels; + float coefficient = horizontal_coefficients[coefficient_group + coefficient_counter++]; + int c; + STBIR_ASSERT(coefficient != 0); + for (c = 0; c < channels; c++) + output_buffer[out_pixel_index + c] += decode_buffer[in_pixel_index + c] * coefficient; + } + break; + } + } +} + +static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, float* output_buffer) +{ + int x, k; + int input_w = stbir_info->input_w; + int channels = stbir_info->channels; + float* decode_buffer = stbir__get_decode_buffer(stbir_info); + stbir__contributors* horizontal_contributors = stbir_info->horizontal_contributors; + float* horizontal_coefficients = stbir_info->horizontal_coefficients; + int coefficient_width = stbir_info->horizontal_coefficient_width; + int filter_pixel_margin = stbir_info->horizontal_filter_pixel_margin; + int max_x = input_w + filter_pixel_margin * 2; + + STBIR_ASSERT(!stbir__use_width_upsampling(stbir_info)); + + switch (channels) { + case 1: + for (x = 0; x < max_x; x++) + { + int n0 = horizontal_contributors[x].n0; + int n1 = horizontal_contributors[x].n1; + + int in_x = x - filter_pixel_margin; + int in_pixel_index = in_x * 1; + int max_n = n1; + int coefficient_group = coefficient_width * x; + + for (k = n0; k <= max_n; k++) + { + int out_pixel_index = k * 1; + float coefficient = horizontal_coefficients[coefficient_group + k - n0]; + output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient; + } + } + break; + + case 2: + for (x = 0; x < max_x; x++) + { + int n0 = horizontal_contributors[x].n0; + int n1 = horizontal_contributors[x].n1; + + int in_x = x - filter_pixel_margin; + int in_pixel_index = in_x * 2; + int max_n = n1; + int coefficient_group = coefficient_width * x; + + for (k = n0; k <= max_n; k++) + { + int out_pixel_index = k * 2; + float coefficient = horizontal_coefficients[coefficient_group + k - n0]; + output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient; + output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient; + } + } + break; + + case 3: + for (x = 0; x < max_x; x++) + { + int n0 = horizontal_contributors[x].n0; + int n1 = horizontal_contributors[x].n1; + + int in_x = x - filter_pixel_margin; + int in_pixel_index = in_x * 3; + int max_n = n1; + int coefficient_group = coefficient_width * x; + + for (k = n0; k <= max_n; k++) + { + int out_pixel_index = k * 3; + float coefficient = horizontal_coefficients[coefficient_group + k - n0]; + output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient; + output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient; + output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient; + } + } + break; + + case 4: + for (x = 0; x < max_x; x++) + { + int n0 = horizontal_contributors[x].n0; + int n1 = horizontal_contributors[x].n1; + + int in_x = x - filter_pixel_margin; + int in_pixel_index = in_x * 4; + int max_n = n1; + int coefficient_group = coefficient_width * x; + + for (k = n0; k <= max_n; k++) + { + int out_pixel_index = k * 4; + float coefficient = horizontal_coefficients[coefficient_group + k - n0]; + output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient; + output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient; + output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient; + output_buffer[out_pixel_index + 3] += decode_buffer[in_pixel_index + 3] * coefficient; + } + } + break; + + default: + for (x = 0; x < max_x; x++) + { + int n0 = horizontal_contributors[x].n0; + int n1 = horizontal_contributors[x].n1; + + int in_x = x - filter_pixel_margin; + int in_pixel_index = in_x * channels; + int max_n = n1; + int coefficient_group = coefficient_width * x; + + for (k = n0; k <= max_n; k++) + { + int c; + int out_pixel_index = k * channels; + float coefficient = horizontal_coefficients[coefficient_group + k - n0]; + for (c = 0; c < channels; c++) + output_buffer[out_pixel_index + c] += decode_buffer[in_pixel_index + c] * coefficient; + } + } + break; + } +} + +static void stbir__decode_and_resample_upsample(stbir__info* stbir_info, int n) +{ + // Decode the nth scanline from the source image into the decode buffer. + stbir__decode_scanline(stbir_info, n); + + // Now resample it into the ring buffer. + if (stbir__use_width_upsampling(stbir_info)) + stbir__resample_horizontal_upsample(stbir_info, stbir__add_empty_ring_buffer_entry(stbir_info, n)); + else + stbir__resample_horizontal_downsample(stbir_info, stbir__add_empty_ring_buffer_entry(stbir_info, n)); + + // Now it's sitting in the ring buffer ready to be used as source for the vertical sampling. +} + +static void stbir__decode_and_resample_downsample(stbir__info* stbir_info, int n) +{ + // Decode the nth scanline from the source image into the decode buffer. + stbir__decode_scanline(stbir_info, n); + + memset(stbir_info->horizontal_buffer, 0, stbir_info->output_w * stbir_info->channels * sizeof(float)); + + // Now resample it into the horizontal buffer. + if (stbir__use_width_upsampling(stbir_info)) + stbir__resample_horizontal_upsample(stbir_info, stbir_info->horizontal_buffer); + else + stbir__resample_horizontal_downsample(stbir_info, stbir_info->horizontal_buffer); + + // Now it's sitting in the horizontal buffer ready to be distributed into the ring buffers. +} + +// Get the specified scan line from the ring buffer. +static float* stbir__get_ring_buffer_scanline(int get_scanline, float* ring_buffer, int begin_index, int first_scanline, int ring_buffer_num_entries, int ring_buffer_length) +{ + int ring_buffer_index = (begin_index + (get_scanline - first_scanline)) % ring_buffer_num_entries; + return stbir__get_ring_buffer_entry(ring_buffer, ring_buffer_index, ring_buffer_length); +} + + +static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void *output_buffer, float *encode_buffer, int channels, int alpha_channel, int decode) +{ + int x; + int n; + int num_nonalpha; + stbir_uint16 nonalpha[STBIR_MAX_CHANNELS]; + + if (!(stbir_info->flags&STBIR_FLAG_ALPHA_PREMULTIPLIED)) + { + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + float alpha = encode_buffer[pixel_index + alpha_channel]; + float reciprocal_alpha = alpha ? 1.0f / alpha : 0; + + // unrolling this produced a 1% slowdown upscaling a large RGBA linear-space image on my machine - stb + for (n = 0; n < channels; n++) + if (n != alpha_channel) + encode_buffer[pixel_index + n] *= reciprocal_alpha; + + // We added in a small epsilon to prevent the color channel from being deleted with zero alpha. + // Because we only add it for integer types, it will automatically be discarded on integer + // conversion, so we don't need to subtract it back out (which would be problematic for + // numeric precision reasons). + } + } + + // build a table of all channels that need colorspace correction, so + // we don't perform colorspace correction on channels that don't need it. + for (x = 0, num_nonalpha = 0; x < channels; ++x) + { + if (x != alpha_channel || (stbir_info->flags & STBIR_FLAG_ALPHA_USES_COLORSPACE)) + { + nonalpha[num_nonalpha++] = (stbir_uint16)x; + } + } + + #define STBIR__ROUND_INT(f) ((int) ((f)+0.5)) + #define STBIR__ROUND_UINT(f) ((stbir_uint32) ((f)+0.5)) + + #ifdef STBIR__SATURATE_INT + #define STBIR__ENCODE_LINEAR8(f) stbir__saturate8 (STBIR__ROUND_INT((f) * stbir__max_uint8_as_float )) + #define STBIR__ENCODE_LINEAR16(f) stbir__saturate16(STBIR__ROUND_INT((f) * stbir__max_uint16_as_float)) + #else + #define STBIR__ENCODE_LINEAR8(f) (unsigned char ) STBIR__ROUND_INT(stbir__saturate(f) * stbir__max_uint8_as_float ) + #define STBIR__ENCODE_LINEAR16(f) (unsigned short) STBIR__ROUND_INT(stbir__saturate(f) * stbir__max_uint16_as_float) + #endif + + switch (decode) + { + case STBIR__DECODE(STBIR_TYPE_UINT8, STBIR_COLORSPACE_LINEAR): + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + for (n = 0; n < channels; n++) + { + int index = pixel_index + n; + ((unsigned char*)output_buffer)[index] = STBIR__ENCODE_LINEAR8(encode_buffer[index]); + } + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT8, STBIR_COLORSPACE_SRGB): + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + for (n = 0; n < num_nonalpha; n++) + { + int index = pixel_index + nonalpha[n]; + ((unsigned char*)output_buffer)[index] = stbir__linear_to_srgb_uchar(encode_buffer[index]); + } + + if (!(stbir_info->flags & STBIR_FLAG_ALPHA_USES_COLORSPACE)) + ((unsigned char *)output_buffer)[pixel_index + alpha_channel] = STBIR__ENCODE_LINEAR8(encode_buffer[pixel_index+alpha_channel]); + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT16, STBIR_COLORSPACE_LINEAR): + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + for (n = 0; n < channels; n++) + { + int index = pixel_index + n; + ((unsigned short*)output_buffer)[index] = STBIR__ENCODE_LINEAR16(encode_buffer[index]); + } + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT16, STBIR_COLORSPACE_SRGB): + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + for (n = 0; n < num_nonalpha; n++) + { + int index = pixel_index + nonalpha[n]; + ((unsigned short*)output_buffer)[index] = (unsigned short)STBIR__ROUND_INT(stbir__linear_to_srgb(stbir__saturate(encode_buffer[index])) * stbir__max_uint16_as_float); + } + + if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) + ((unsigned short*)output_buffer)[pixel_index + alpha_channel] = STBIR__ENCODE_LINEAR16(encode_buffer[pixel_index + alpha_channel]); + } + + break; + + case STBIR__DECODE(STBIR_TYPE_UINT32, STBIR_COLORSPACE_LINEAR): + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + for (n = 0; n < channels; n++) + { + int index = pixel_index + n; + ((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_UINT(((double)stbir__saturate(encode_buffer[index])) * stbir__max_uint32_as_float); + } + } + break; + + case STBIR__DECODE(STBIR_TYPE_UINT32, STBIR_COLORSPACE_SRGB): + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + for (n = 0; n < num_nonalpha; n++) + { + int index = pixel_index + nonalpha[n]; + ((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_UINT(((double)stbir__linear_to_srgb(stbir__saturate(encode_buffer[index]))) * stbir__max_uint32_as_float); + } + + if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) + ((unsigned int*)output_buffer)[pixel_index + alpha_channel] = (unsigned int)STBIR__ROUND_INT(((double)stbir__saturate(encode_buffer[pixel_index + alpha_channel])) * stbir__max_uint32_as_float); + } + break; + + case STBIR__DECODE(STBIR_TYPE_FLOAT, STBIR_COLORSPACE_LINEAR): + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + for (n = 0; n < channels; n++) + { + int index = pixel_index + n; + ((float*)output_buffer)[index] = encode_buffer[index]; + } + } + break; + + case STBIR__DECODE(STBIR_TYPE_FLOAT, STBIR_COLORSPACE_SRGB): + for (x=0; x < num_pixels; ++x) + { + int pixel_index = x*channels; + + for (n = 0; n < num_nonalpha; n++) + { + int index = pixel_index + nonalpha[n]; + ((float*)output_buffer)[index] = stbir__linear_to_srgb(encode_buffer[index]); + } + + if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) + ((float*)output_buffer)[pixel_index + alpha_channel] = encode_buffer[pixel_index + alpha_channel]; + } + break; + + default: + STBIR_ASSERT(!"Unknown type/colorspace/channels combination."); + break; + } +} + +static void stbir__resample_vertical_upsample(stbir__info* stbir_info, int n) +{ + int x, k; + int output_w = stbir_info->output_w; + stbir__contributors* vertical_contributors = stbir_info->vertical_contributors; + float* vertical_coefficients = stbir_info->vertical_coefficients; + int channels = stbir_info->channels; + int alpha_channel = stbir_info->alpha_channel; + int type = stbir_info->type; + int colorspace = stbir_info->colorspace; + int ring_buffer_entries = stbir_info->ring_buffer_num_entries; + void* output_data = stbir_info->output_data; + float* encode_buffer = stbir_info->encode_buffer; + int decode = STBIR__DECODE(type, colorspace); + int coefficient_width = stbir_info->vertical_coefficient_width; + int coefficient_counter; + int contributor = n; + + float* ring_buffer = stbir_info->ring_buffer; + int ring_buffer_begin_index = stbir_info->ring_buffer_begin_index; + int ring_buffer_first_scanline = stbir_info->ring_buffer_first_scanline; + int ring_buffer_length = stbir_info->ring_buffer_length_bytes/sizeof(float); + + int n0,n1, output_row_start; + int coefficient_group = coefficient_width * contributor; + + n0 = vertical_contributors[contributor].n0; + n1 = vertical_contributors[contributor].n1; + + output_row_start = n * stbir_info->output_stride_bytes; + + STBIR_ASSERT(stbir__use_height_upsampling(stbir_info)); + + memset(encode_buffer, 0, output_w * sizeof(float) * channels); + + // I tried reblocking this for better cache usage of encode_buffer + // (using x_outer, k, x_inner), but it lost speed. -- stb + + coefficient_counter = 0; + switch (channels) { + case 1: + for (k = n0; k <= n1; k++) + { + int coefficient_index = coefficient_counter++; + float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length); + float coefficient = vertical_coefficients[coefficient_group + coefficient_index]; + for (x = 0; x < output_w; ++x) + { + int in_pixel_index = x * 1; + encode_buffer[in_pixel_index + 0] += ring_buffer_entry[in_pixel_index + 0] * coefficient; + } + } + break; + case 2: + for (k = n0; k <= n1; k++) + { + int coefficient_index = coefficient_counter++; + float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length); + float coefficient = vertical_coefficients[coefficient_group + coefficient_index]; + for (x = 0; x < output_w; ++x) + { + int in_pixel_index = x * 2; + encode_buffer[in_pixel_index + 0] += ring_buffer_entry[in_pixel_index + 0] * coefficient; + encode_buffer[in_pixel_index + 1] += ring_buffer_entry[in_pixel_index + 1] * coefficient; + } + } + break; + case 3: + for (k = n0; k <= n1; k++) + { + int coefficient_index = coefficient_counter++; + float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length); + float coefficient = vertical_coefficients[coefficient_group + coefficient_index]; + for (x = 0; x < output_w; ++x) + { + int in_pixel_index = x * 3; + encode_buffer[in_pixel_index + 0] += ring_buffer_entry[in_pixel_index + 0] * coefficient; + encode_buffer[in_pixel_index + 1] += ring_buffer_entry[in_pixel_index + 1] * coefficient; + encode_buffer[in_pixel_index + 2] += ring_buffer_entry[in_pixel_index + 2] * coefficient; + } + } + break; + case 4: + for (k = n0; k <= n1; k++) + { + int coefficient_index = coefficient_counter++; + float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length); + float coefficient = vertical_coefficients[coefficient_group + coefficient_index]; + for (x = 0; x < output_w; ++x) + { + int in_pixel_index = x * 4; + encode_buffer[in_pixel_index + 0] += ring_buffer_entry[in_pixel_index + 0] * coefficient; + encode_buffer[in_pixel_index + 1] += ring_buffer_entry[in_pixel_index + 1] * coefficient; + encode_buffer[in_pixel_index + 2] += ring_buffer_entry[in_pixel_index + 2] * coefficient; + encode_buffer[in_pixel_index + 3] += ring_buffer_entry[in_pixel_index + 3] * coefficient; + } + } + break; + default: + for (k = n0; k <= n1; k++) + { + int coefficient_index = coefficient_counter++; + float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length); + float coefficient = vertical_coefficients[coefficient_group + coefficient_index]; + for (x = 0; x < output_w; ++x) + { + int in_pixel_index = x * channels; + int c; + for (c = 0; c < channels; c++) + encode_buffer[in_pixel_index + c] += ring_buffer_entry[in_pixel_index + c] * coefficient; + } + } + break; + } + stbir__encode_scanline(stbir_info, output_w, (char *) output_data + output_row_start, encode_buffer, channels, alpha_channel, decode); +} + +static void stbir__resample_vertical_downsample(stbir__info* stbir_info, int n) +{ + int x, k; + int output_w = stbir_info->output_w; + stbir__contributors* vertical_contributors = stbir_info->vertical_contributors; + float* vertical_coefficients = stbir_info->vertical_coefficients; + int channels = stbir_info->channels; + int ring_buffer_entries = stbir_info->ring_buffer_num_entries; + float* horizontal_buffer = stbir_info->horizontal_buffer; + int coefficient_width = stbir_info->vertical_coefficient_width; + int contributor = n + stbir_info->vertical_filter_pixel_margin; + + float* ring_buffer = stbir_info->ring_buffer; + int ring_buffer_begin_index = stbir_info->ring_buffer_begin_index; + int ring_buffer_first_scanline = stbir_info->ring_buffer_first_scanline; + int ring_buffer_length = stbir_info->ring_buffer_length_bytes/sizeof(float); + int n0,n1; + + n0 = vertical_contributors[contributor].n0; + n1 = vertical_contributors[contributor].n1; + + STBIR_ASSERT(!stbir__use_height_upsampling(stbir_info)); + + for (k = n0; k <= n1; k++) + { + int coefficient_index = k - n0; + int coefficient_group = coefficient_width * contributor; + float coefficient = vertical_coefficients[coefficient_group + coefficient_index]; + + float* ring_buffer_entry = stbir__get_ring_buffer_scanline(k, ring_buffer, ring_buffer_begin_index, ring_buffer_first_scanline, ring_buffer_entries, ring_buffer_length); + + switch (channels) { + case 1: + for (x = 0; x < output_w; x++) + { + int in_pixel_index = x * 1; + ring_buffer_entry[in_pixel_index + 0] += horizontal_buffer[in_pixel_index + 0] * coefficient; + } + break; + case 2: + for (x = 0; x < output_w; x++) + { + int in_pixel_index = x * 2; + ring_buffer_entry[in_pixel_index + 0] += horizontal_buffer[in_pixel_index + 0] * coefficient; + ring_buffer_entry[in_pixel_index + 1] += horizontal_buffer[in_pixel_index + 1] * coefficient; + } + break; + case 3: + for (x = 0; x < output_w; x++) + { + int in_pixel_index = x * 3; + ring_buffer_entry[in_pixel_index + 0] += horizontal_buffer[in_pixel_index + 0] * coefficient; + ring_buffer_entry[in_pixel_index + 1] += horizontal_buffer[in_pixel_index + 1] * coefficient; + ring_buffer_entry[in_pixel_index + 2] += horizontal_buffer[in_pixel_index + 2] * coefficient; + } + break; + case 4: + for (x = 0; x < output_w; x++) + { + int in_pixel_index = x * 4; + ring_buffer_entry[in_pixel_index + 0] += horizontal_buffer[in_pixel_index + 0] * coefficient; + ring_buffer_entry[in_pixel_index + 1] += horizontal_buffer[in_pixel_index + 1] * coefficient; + ring_buffer_entry[in_pixel_index + 2] += horizontal_buffer[in_pixel_index + 2] * coefficient; + ring_buffer_entry[in_pixel_index + 3] += horizontal_buffer[in_pixel_index + 3] * coefficient; + } + break; + default: + for (x = 0; x < output_w; x++) + { + int in_pixel_index = x * channels; + + int c; + for (c = 0; c < channels; c++) + ring_buffer_entry[in_pixel_index + c] += horizontal_buffer[in_pixel_index + c] * coefficient; + } + break; + } + } +} + +static void stbir__buffer_loop_upsample(stbir__info* stbir_info) +{ + int y; + float scale_ratio = stbir_info->vertical_scale; + float out_scanlines_radius = stbir__filter_info_table[stbir_info->vertical_filter].support(1/scale_ratio) * scale_ratio; + + STBIR_ASSERT(stbir__use_height_upsampling(stbir_info)); + + for (y = 0; y < stbir_info->output_h; y++) + { + float in_center_of_out = 0; // Center of the current out scanline in the in scanline space + int in_first_scanline = 0, in_last_scanline = 0; + + stbir__calculate_sample_range_upsample(y, out_scanlines_radius, scale_ratio, stbir_info->vertical_shift, &in_first_scanline, &in_last_scanline, &in_center_of_out); + + STBIR_ASSERT(in_last_scanline - in_first_scanline + 1 <= stbir_info->ring_buffer_num_entries); + + if (stbir_info->ring_buffer_begin_index >= 0) + { + // Get rid of whatever we don't need anymore. + while (in_first_scanline > stbir_info->ring_buffer_first_scanline) + { + if (stbir_info->ring_buffer_first_scanline == stbir_info->ring_buffer_last_scanline) + { + // We just popped the last scanline off the ring buffer. + // Reset it to the empty state. + stbir_info->ring_buffer_begin_index = -1; + stbir_info->ring_buffer_first_scanline = 0; + stbir_info->ring_buffer_last_scanline = 0; + break; + } + else + { + stbir_info->ring_buffer_first_scanline++; + stbir_info->ring_buffer_begin_index = (stbir_info->ring_buffer_begin_index + 1) % stbir_info->ring_buffer_num_entries; + } + } + } + + // Load in new ones. + if (stbir_info->ring_buffer_begin_index < 0) + stbir__decode_and_resample_upsample(stbir_info, in_first_scanline); + + while (in_last_scanline > stbir_info->ring_buffer_last_scanline) + stbir__decode_and_resample_upsample(stbir_info, stbir_info->ring_buffer_last_scanline + 1); + + // Now all buffers should be ready to write a row of vertical sampling. + stbir__resample_vertical_upsample(stbir_info, y); + + STBIR_PROGRESS_REPORT((float)y / stbir_info->output_h); + } +} + +static void stbir__empty_ring_buffer(stbir__info* stbir_info, int first_necessary_scanline) +{ + int output_stride_bytes = stbir_info->output_stride_bytes; + int channels = stbir_info->channels; + int alpha_channel = stbir_info->alpha_channel; + int type = stbir_info->type; + int colorspace = stbir_info->colorspace; + int output_w = stbir_info->output_w; + void* output_data = stbir_info->output_data; + int decode = STBIR__DECODE(type, colorspace); + + float* ring_buffer = stbir_info->ring_buffer; + int ring_buffer_length = stbir_info->ring_buffer_length_bytes/sizeof(float); + + if (stbir_info->ring_buffer_begin_index >= 0) + { + // Get rid of whatever we don't need anymore. + while (first_necessary_scanline > stbir_info->ring_buffer_first_scanline) + { + if (stbir_info->ring_buffer_first_scanline >= 0 && stbir_info->ring_buffer_first_scanline < stbir_info->output_h) + { + int output_row_start = stbir_info->ring_buffer_first_scanline * output_stride_bytes; + float* ring_buffer_entry = stbir__get_ring_buffer_entry(ring_buffer, stbir_info->ring_buffer_begin_index, ring_buffer_length); + stbir__encode_scanline(stbir_info, output_w, (char *) output_data + output_row_start, ring_buffer_entry, channels, alpha_channel, decode); + STBIR_PROGRESS_REPORT((float)stbir_info->ring_buffer_first_scanline / stbir_info->output_h); + } + + if (stbir_info->ring_buffer_first_scanline == stbir_info->ring_buffer_last_scanline) + { + // We just popped the last scanline off the ring buffer. + // Reset it to the empty state. + stbir_info->ring_buffer_begin_index = -1; + stbir_info->ring_buffer_first_scanline = 0; + stbir_info->ring_buffer_last_scanline = 0; + break; + } + else + { + stbir_info->ring_buffer_first_scanline++; + stbir_info->ring_buffer_begin_index = (stbir_info->ring_buffer_begin_index + 1) % stbir_info->ring_buffer_num_entries; + } + } + } +} + +static void stbir__buffer_loop_downsample(stbir__info* stbir_info) +{ + int y; + float scale_ratio = stbir_info->vertical_scale; + int output_h = stbir_info->output_h; + float in_pixels_radius = stbir__filter_info_table[stbir_info->vertical_filter].support(scale_ratio) / scale_ratio; + int pixel_margin = stbir_info->vertical_filter_pixel_margin; + int max_y = stbir_info->input_h + pixel_margin; + + STBIR_ASSERT(!stbir__use_height_upsampling(stbir_info)); + + for (y = -pixel_margin; y < max_y; y++) + { + float out_center_of_in; // Center of the current out scanline in the in scanline space + int out_first_scanline, out_last_scanline; + + stbir__calculate_sample_range_downsample(y, in_pixels_radius, scale_ratio, stbir_info->vertical_shift, &out_first_scanline, &out_last_scanline, &out_center_of_in); + + STBIR_ASSERT(out_last_scanline - out_first_scanline + 1 <= stbir_info->ring_buffer_num_entries); + + if (out_last_scanline < 0 || out_first_scanline >= output_h) + continue; + + stbir__empty_ring_buffer(stbir_info, out_first_scanline); + + stbir__decode_and_resample_downsample(stbir_info, y); + + // Load in new ones. + if (stbir_info->ring_buffer_begin_index < 0) + stbir__add_empty_ring_buffer_entry(stbir_info, out_first_scanline); + + while (out_last_scanline > stbir_info->ring_buffer_last_scanline) + stbir__add_empty_ring_buffer_entry(stbir_info, stbir_info->ring_buffer_last_scanline + 1); + + // Now the horizontal buffer is ready to write to all ring buffer rows. + stbir__resample_vertical_downsample(stbir_info, y); + } + + stbir__empty_ring_buffer(stbir_info, stbir_info->output_h); +} + +static void stbir__setup(stbir__info *info, int input_w, int input_h, int output_w, int output_h, int channels) +{ + info->input_w = input_w; + info->input_h = input_h; + info->output_w = output_w; + info->output_h = output_h; + info->channels = channels; +} + +static void stbir__calculate_transform(stbir__info *info, float s0, float t0, float s1, float t1, float *transform) +{ + info->s0 = s0; + info->t0 = t0; + info->s1 = s1; + info->t1 = t1; + + if (transform) + { + info->horizontal_scale = transform[0]; + info->vertical_scale = transform[1]; + info->horizontal_shift = transform[2]; + info->vertical_shift = transform[3]; + } + else + { + info->horizontal_scale = ((float)info->output_w / info->input_w) / (s1 - s0); + info->vertical_scale = ((float)info->output_h / info->input_h) / (t1 - t0); + + info->horizontal_shift = s0 * info->output_w / (s1 - s0); + info->vertical_shift = t0 * info->output_h / (t1 - t0); + } +} + +static void stbir__choose_filter(stbir__info *info, stbir_filter h_filter, stbir_filter v_filter) +{ + if (h_filter == 0) + h_filter = stbir__use_upsampling(info->horizontal_scale) ? STBIR_DEFAULT_FILTER_UPSAMPLE : STBIR_DEFAULT_FILTER_DOWNSAMPLE; + if (v_filter == 0) + v_filter = stbir__use_upsampling(info->vertical_scale) ? STBIR_DEFAULT_FILTER_UPSAMPLE : STBIR_DEFAULT_FILTER_DOWNSAMPLE; + info->horizontal_filter = h_filter; + info->vertical_filter = v_filter; +} + +static stbir_uint32 stbir__calculate_memory(stbir__info *info) +{ + int pixel_margin = stbir__get_filter_pixel_margin(info->horizontal_filter, info->horizontal_scale); + int filter_height = stbir__get_filter_pixel_width(info->vertical_filter, info->vertical_scale); + + info->horizontal_num_contributors = stbir__get_contributors(info->horizontal_scale, info->horizontal_filter, info->input_w, info->output_w); + info->vertical_num_contributors = stbir__get_contributors(info->vertical_scale , info->vertical_filter , info->input_h, info->output_h); + + // One extra entry because floating point precision problems sometimes cause an extra to be necessary. + info->ring_buffer_num_entries = filter_height + 1; + + info->horizontal_contributors_size = info->horizontal_num_contributors * sizeof(stbir__contributors); + info->horizontal_coefficients_size = stbir__get_total_horizontal_coefficients(info) * sizeof(float); + info->vertical_contributors_size = info->vertical_num_contributors * sizeof(stbir__contributors); + info->vertical_coefficients_size = stbir__get_total_vertical_coefficients(info) * sizeof(float); + info->decode_buffer_size = (info->input_w + pixel_margin * 2) * info->channels * sizeof(float); + info->horizontal_buffer_size = info->output_w * info->channels * sizeof(float); + info->ring_buffer_size = info->output_w * info->channels * info->ring_buffer_num_entries * sizeof(float); + info->encode_buffer_size = info->output_w * info->channels * sizeof(float); + + STBIR_ASSERT(info->horizontal_filter != 0); + STBIR_ASSERT(info->horizontal_filter < STBIR__ARRAY_SIZE(stbir__filter_info_table)); // this now happens too late + STBIR_ASSERT(info->vertical_filter != 0); + STBIR_ASSERT(info->vertical_filter < STBIR__ARRAY_SIZE(stbir__filter_info_table)); // this now happens too late + + if (stbir__use_height_upsampling(info)) + // The horizontal buffer is for when we're downsampling the height and we + // can't output the result of sampling the decode buffer directly into the + // ring buffers. + info->horizontal_buffer_size = 0; + else + // The encode buffer is to retain precision in the height upsampling method + // and isn't used when height downsampling. + info->encode_buffer_size = 0; + + return info->horizontal_contributors_size + info->horizontal_coefficients_size + + info->vertical_contributors_size + info->vertical_coefficients_size + + info->decode_buffer_size + info->horizontal_buffer_size + + info->ring_buffer_size + info->encode_buffer_size; +} + +static int stbir__resize_allocated(stbir__info *info, + const void* input_data, int input_stride_in_bytes, + void* output_data, int output_stride_in_bytes, + int alpha_channel, stbir_uint32 flags, stbir_datatype type, + stbir_edge edge_horizontal, stbir_edge edge_vertical, stbir_colorspace colorspace, + void* tempmem, size_t tempmem_size_in_bytes) +{ + size_t memory_required = stbir__calculate_memory(info); + + int width_stride_input = input_stride_in_bytes ? input_stride_in_bytes : info->channels * info->input_w * stbir__type_size[type]; + int width_stride_output = output_stride_in_bytes ? output_stride_in_bytes : info->channels * info->output_w * stbir__type_size[type]; + +#ifdef STBIR_DEBUG_OVERWRITE_TEST +#define OVERWRITE_ARRAY_SIZE 8 + unsigned char overwrite_output_before_pre[OVERWRITE_ARRAY_SIZE]; + unsigned char overwrite_tempmem_before_pre[OVERWRITE_ARRAY_SIZE]; + unsigned char overwrite_output_after_pre[OVERWRITE_ARRAY_SIZE]; + unsigned char overwrite_tempmem_after_pre[OVERWRITE_ARRAY_SIZE]; + + size_t begin_forbidden = width_stride_output * (info->output_h - 1) + info->output_w * info->channels * stbir__type_size[type]; + memcpy(overwrite_output_before_pre, &((unsigned char*)output_data)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE); + memcpy(overwrite_output_after_pre, &((unsigned char*)output_data)[begin_forbidden], OVERWRITE_ARRAY_SIZE); + memcpy(overwrite_tempmem_before_pre, &((unsigned char*)tempmem)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE); + memcpy(overwrite_tempmem_after_pre, &((unsigned char*)tempmem)[tempmem_size_in_bytes], OVERWRITE_ARRAY_SIZE); +#endif + + STBIR_ASSERT(info->channels >= 0); + STBIR_ASSERT(info->channels <= STBIR_MAX_CHANNELS); + + if (info->channels < 0 || info->channels > STBIR_MAX_CHANNELS) + return 0; + + STBIR_ASSERT(info->horizontal_filter < STBIR__ARRAY_SIZE(stbir__filter_info_table)); + STBIR_ASSERT(info->vertical_filter < STBIR__ARRAY_SIZE(stbir__filter_info_table)); + + if (info->horizontal_filter >= STBIR__ARRAY_SIZE(stbir__filter_info_table)) + return 0; + if (info->vertical_filter >= STBIR__ARRAY_SIZE(stbir__filter_info_table)) + return 0; + + if (alpha_channel < 0) + flags |= STBIR_FLAG_ALPHA_USES_COLORSPACE | STBIR_FLAG_ALPHA_PREMULTIPLIED; + + if (!(flags&STBIR_FLAG_ALPHA_USES_COLORSPACE) || !(flags&STBIR_FLAG_ALPHA_PREMULTIPLIED)) { + STBIR_ASSERT(alpha_channel >= 0 && alpha_channel < info->channels); + } + + if (alpha_channel >= info->channels) + return 0; + + STBIR_ASSERT(tempmem); + + if (!tempmem) + return 0; + + STBIR_ASSERT(tempmem_size_in_bytes >= memory_required); + + if (tempmem_size_in_bytes < memory_required) + return 0; + + memset(tempmem, 0, tempmem_size_in_bytes); + + info->input_data = input_data; + info->input_stride_bytes = width_stride_input; + + info->output_data = output_data; + info->output_stride_bytes = width_stride_output; + + info->alpha_channel = alpha_channel; + info->flags = flags; + info->type = type; + info->edge_horizontal = edge_horizontal; + info->edge_vertical = edge_vertical; + info->colorspace = colorspace; + + info->horizontal_coefficient_width = stbir__get_coefficient_width (info->horizontal_filter, info->horizontal_scale); + info->vertical_coefficient_width = stbir__get_coefficient_width (info->vertical_filter , info->vertical_scale ); + info->horizontal_filter_pixel_width = stbir__get_filter_pixel_width (info->horizontal_filter, info->horizontal_scale); + info->vertical_filter_pixel_width = stbir__get_filter_pixel_width (info->vertical_filter , info->vertical_scale ); + info->horizontal_filter_pixel_margin = stbir__get_filter_pixel_margin(info->horizontal_filter, info->horizontal_scale); + info->vertical_filter_pixel_margin = stbir__get_filter_pixel_margin(info->vertical_filter , info->vertical_scale ); + + info->ring_buffer_length_bytes = info->output_w * info->channels * sizeof(float); + info->decode_buffer_pixels = info->input_w + info->horizontal_filter_pixel_margin * 2; + +#define STBIR__NEXT_MEMPTR(current, newtype) (newtype*)(((unsigned char*)current) + current##_size) + + info->horizontal_contributors = (stbir__contributors *) tempmem; + info->horizontal_coefficients = STBIR__NEXT_MEMPTR(info->horizontal_contributors, float); + info->vertical_contributors = STBIR__NEXT_MEMPTR(info->horizontal_coefficients, stbir__contributors); + info->vertical_coefficients = STBIR__NEXT_MEMPTR(info->vertical_contributors, float); + info->decode_buffer = STBIR__NEXT_MEMPTR(info->vertical_coefficients, float); + + if (stbir__use_height_upsampling(info)) + { + info->horizontal_buffer = NULL; + info->ring_buffer = STBIR__NEXT_MEMPTR(info->decode_buffer, float); + info->encode_buffer = STBIR__NEXT_MEMPTR(info->ring_buffer, float); + + STBIR_ASSERT((size_t)STBIR__NEXT_MEMPTR(info->encode_buffer, unsigned char) == (size_t)tempmem + tempmem_size_in_bytes); + } + else + { + info->horizontal_buffer = STBIR__NEXT_MEMPTR(info->decode_buffer, float); + info->ring_buffer = STBIR__NEXT_MEMPTR(info->horizontal_buffer, float); + info->encode_buffer = NULL; + + STBIR_ASSERT((size_t)STBIR__NEXT_MEMPTR(info->ring_buffer, unsigned char) == (size_t)tempmem + tempmem_size_in_bytes); + } + +#undef STBIR__NEXT_MEMPTR + + // This signals that the ring buffer is empty + info->ring_buffer_begin_index = -1; + + stbir__calculate_filters(info->horizontal_contributors, info->horizontal_coefficients, info->horizontal_filter, info->horizontal_scale, info->horizontal_shift, info->input_w, info->output_w); + stbir__calculate_filters(info->vertical_contributors, info->vertical_coefficients, info->vertical_filter, info->vertical_scale, info->vertical_shift, info->input_h, info->output_h); + + STBIR_PROGRESS_REPORT(0); + + if (stbir__use_height_upsampling(info)) + stbir__buffer_loop_upsample(info); + else + stbir__buffer_loop_downsample(info); + + STBIR_PROGRESS_REPORT(1); + +#ifdef STBIR_DEBUG_OVERWRITE_TEST + STBIR_ASSERT(memcmp(overwrite_output_before_pre, &((unsigned char*)output_data)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE) == 0); + STBIR_ASSERT(memcmp(overwrite_output_after_pre, &((unsigned char*)output_data)[begin_forbidden], OVERWRITE_ARRAY_SIZE) == 0); + STBIR_ASSERT(memcmp(overwrite_tempmem_before_pre, &((unsigned char*)tempmem)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE) == 0); + STBIR_ASSERT(memcmp(overwrite_tempmem_after_pre, &((unsigned char*)tempmem)[tempmem_size_in_bytes], OVERWRITE_ARRAY_SIZE) == 0); +#endif + + return 1; +} + + +static int stbir__resize_arbitrary( + void *alloc_context, + const void* input_data, int input_w, int input_h, int input_stride_in_bytes, + void* output_data, int output_w, int output_h, int output_stride_in_bytes, + float s0, float t0, float s1, float t1, float *transform, + int channels, int alpha_channel, stbir_uint32 flags, stbir_datatype type, + stbir_filter h_filter, stbir_filter v_filter, + stbir_edge edge_horizontal, stbir_edge edge_vertical, stbir_colorspace colorspace) +{ + stbir__info info; + int result; + size_t memory_required; + void* extra_memory; + + stbir__setup(&info, input_w, input_h, output_w, output_h, channels); + stbir__calculate_transform(&info, s0,t0,s1,t1,transform); + stbir__choose_filter(&info, h_filter, v_filter); + memory_required = stbir__calculate_memory(&info); + extra_memory = STBIR_MALLOC(memory_required, alloc_context); + + if (!extra_memory) + return 0; + + result = stbir__resize_allocated(&info, input_data, input_stride_in_bytes, + output_data, output_stride_in_bytes, + alpha_channel, flags, type, + edge_horizontal, edge_vertical, + colorspace, extra_memory, memory_required); + + STBIR_FREE(extra_memory, alloc_context); + + return result; +} + +STBIRDEF int stbir_resize_uint8( const unsigned char *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels) +{ + return stbir__resize_arbitrary(NULL, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,NULL,num_channels,-1,0, STBIR_TYPE_UINT8, STBIR_FILTER_DEFAULT, STBIR_FILTER_DEFAULT, + STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_LINEAR); +} + +STBIRDEF int stbir_resize_float( const float *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + float *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels) +{ + return stbir__resize_arbitrary(NULL, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,NULL,num_channels,-1,0, STBIR_TYPE_FLOAT, STBIR_FILTER_DEFAULT, STBIR_FILTER_DEFAULT, + STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_LINEAR); +} + +STBIRDEF int stbir_resize_uint8_srgb(const unsigned char *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags) +{ + return stbir__resize_arbitrary(NULL, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,NULL,num_channels,alpha_channel,flags, STBIR_TYPE_UINT8, STBIR_FILTER_DEFAULT, STBIR_FILTER_DEFAULT, + STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_COLORSPACE_SRGB); +} + +STBIRDEF int stbir_resize_uint8_srgb_edgemode(const unsigned char *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_wrap_mode) +{ + return stbir__resize_arbitrary(NULL, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,NULL,num_channels,alpha_channel,flags, STBIR_TYPE_UINT8, STBIR_FILTER_DEFAULT, STBIR_FILTER_DEFAULT, + edge_wrap_mode, edge_wrap_mode, STBIR_COLORSPACE_SRGB); +} + +STBIRDEF int stbir_resize_uint8_generic( const unsigned char *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + unsigned char *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_wrap_mode, stbir_filter filter, stbir_colorspace space, + void *alloc_context) +{ + return stbir__resize_arbitrary(alloc_context, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,NULL,num_channels,alpha_channel,flags, STBIR_TYPE_UINT8, filter, filter, + edge_wrap_mode, edge_wrap_mode, space); +} + +STBIRDEF int stbir_resize_uint16_generic(const stbir_uint16 *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + stbir_uint16 *output_pixels , int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_wrap_mode, stbir_filter filter, stbir_colorspace space, + void *alloc_context) +{ + return stbir__resize_arbitrary(alloc_context, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,NULL,num_channels,alpha_channel,flags, STBIR_TYPE_UINT16, filter, filter, + edge_wrap_mode, edge_wrap_mode, space); +} + + +STBIRDEF int stbir_resize_float_generic( const float *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + float *output_pixels , int output_w, int output_h, int output_stride_in_bytes, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_wrap_mode, stbir_filter filter, stbir_colorspace space, + void *alloc_context) +{ + return stbir__resize_arbitrary(alloc_context, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,NULL,num_channels,alpha_channel,flags, STBIR_TYPE_FLOAT, filter, filter, + edge_wrap_mode, edge_wrap_mode, space); +} + + +STBIRDEF int stbir_resize( const void *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + stbir_datatype datatype, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_mode_horizontal, stbir_edge edge_mode_vertical, + stbir_filter filter_horizontal, stbir_filter filter_vertical, + stbir_colorspace space, void *alloc_context) +{ + return stbir__resize_arbitrary(alloc_context, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,NULL,num_channels,alpha_channel,flags, datatype, filter_horizontal, filter_vertical, + edge_mode_horizontal, edge_mode_vertical, space); +} + + +STBIRDEF int stbir_resize_subpixel(const void *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + stbir_datatype datatype, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_mode_horizontal, stbir_edge edge_mode_vertical, + stbir_filter filter_horizontal, stbir_filter filter_vertical, + stbir_colorspace space, void *alloc_context, + float x_scale, float y_scale, + float x_offset, float y_offset) +{ + float transform[4]; + transform[0] = x_scale; + transform[1] = y_scale; + transform[2] = x_offset; + transform[3] = y_offset; + return stbir__resize_arbitrary(alloc_context, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + 0,0,1,1,transform,num_channels,alpha_channel,flags, datatype, filter_horizontal, filter_vertical, + edge_mode_horizontal, edge_mode_vertical, space); +} + +STBIRDEF int stbir_resize_region( const void *input_pixels , int input_w , int input_h , int input_stride_in_bytes, + void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, + stbir_datatype datatype, + int num_channels, int alpha_channel, int flags, + stbir_edge edge_mode_horizontal, stbir_edge edge_mode_vertical, + stbir_filter filter_horizontal, stbir_filter filter_vertical, + stbir_colorspace space, void *alloc_context, + float s0, float t0, float s1, float t1) +{ + return stbir__resize_arbitrary(alloc_context, input_pixels, input_w, input_h, input_stride_in_bytes, + output_pixels, output_w, output_h, output_stride_in_bytes, + s0,t0,s1,t1,NULL,num_channels,alpha_channel,flags, datatype, filter_horizontal, filter_vertical, + edge_mode_horizontal, edge_mode_vertical, space); +} + +#endif // STB_IMAGE_RESIZE_IMPLEMENTATION + +/* +------------------------------------------------------------------------------ +This software is available under 2 licenses -- choose whichever you prefer. +------------------------------------------------------------------------------ +ALTERNATIVE A - MIT License +Copyright (c) 2017 Sean Barrett +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------------ +ALTERNATIVE B - Public Domain (www.unlicense.org) +This is free and unencumbered software released into the public domain. +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------ +*/