diff --git a/src/ProxyPPC.c b/src/ProxyPPC.c new file mode 100644 index 0000000..609576d --- /dev/null +++ b/src/ProxyPPC.c @@ -0,0 +1,59 @@ +#include +#include "ProxyPPC.h" + +int HasProxyPrefix(const cc_string* url) { + const char* proxyPrefix = PROXY_PREFIX; + int prefixLen = strlen(proxyPrefix); + int i; + + if (url->length < prefixLen) return 0; + + for (i = 0; i < prefixLen; i++) { + if (url->buffer[i] != proxyPrefix[i]) { + return 0; + } + } + return 1; +} + +void RemoveProxyPrefix(cc_string* url) { + int prefixLen, newLength; + + if (!url || url->length == 0) return; + + if (HasProxyPrefix(url)) { + const char* proxyPrefix = PROXY_PREFIX; + prefixLen = strlen(proxyPrefix); + newLength = url->length - prefixLen; + + if (newLength > 0) { + memmove(url->buffer, url->buffer + prefixLen, newLength); + } + url->buffer[newLength] = '\0'; + url->length = newLength; + } +} + +void ApplyProxyPPC(cc_string* url) { + int prefixLen, newLength; + + if (!url || url->length == 0) return; + + if (HasProxyPrefix(url)) return; + + { + const char* proxyPrefix = PROXY_PREFIX; + prefixLen = strlen(proxyPrefix); + newLength = url->length + prefixLen; + + if (newLength + 1 > url->capacity) { + return; + } + + memmove(url->buffer + prefixLen, url->buffer, url->length + 1); + + memcpy(url->buffer, proxyPrefix, prefixLen); + + url->length = newLength; + } +} \ No newline at end of file diff --git a/src/ProxyPPC.h b/src/ProxyPPC.h new file mode 100644 index 0000000..9bfc984 --- /dev/null +++ b/src/ProxyPPC.h @@ -0,0 +1,11 @@ +#ifndef PROXY_PPC_H +#define PROXY_PPC_H +#include "String.h" + +#define PROXY_PREFIX "http://ppcproxy.andreiixe.website/?url=" + +void ApplyProxyPPC(cc_string* url); +int HasProxyPrefix(const cc_string* url); +void RemoveProxyPrefix(cc_string* url); + +#endif // PROXY_PPC_H \ No newline at end of file diff --git a/src/Resources.c b/src/Resources.c index a906cea..9fa5799 100644 --- a/src/Resources.c +++ b/src/Resources.c @@ -333,13 +333,20 @@ static void MusicAssets_CountMissing(void) { /*########################################################################################################################* *-----------------------------------------------------Music asset fetching -----------------------------------------------* *#########################################################################################################################*/ -CC_NOINLINE static int MusicAsset_Download(const char* hash) { - cc_string url; char urlBuffer[URL_MAX_SIZE]; +#include "ProxyPPC.h" - String_InitArray(url, urlBuffer); - String_Format3(&url, "https://resources.download.minecraft.net/%r%r/%c", - &hash[0], &hash[1], hash); - return Http_AsyncGetData(&url, 0); +CC_NOINLINE static int MusicAsset_Download(const char* hash) { + cc_string url; + char urlBuffer[256]; + + String_InitArray(url, urlBuffer); + + String_Format3(&url, "https://resources.download.minecraft.net/%r%r/%c", + &hash[0], &hash[1], hash); + + ApplyProxyPPC(&url); + + return Http_AsyncGetData(&url, 0); } static void MusicAssets_DownloadAssets(void) { diff --git a/src/TexturePack.c b/src/TexturePack.c index e61c7eb..73d782c 100644 --- a/src/TexturePack.c +++ b/src/TexturePack.c @@ -676,19 +676,21 @@ void TexturePack_CheckPending(void) { } /* Asynchronously downloads the given texture pack */ -static void DownloadAsync(const cc_string* url) { - cc_string etag = String_Empty; - cc_string time = String_Empty; - - /* Only retrieve etag/last-modified headers if the file exists */ - /* This inconsistency can occur if user deleted some cached files */ - if (IsCached(url)) { - time = GetCachedLastModified(url); - etag = GetCachedETag(url); - } +#include "ProxyPPC.h" +static void DownloadAsync(cc_string* url) { + cc_string etag = String_Empty; + cc_string time = String_Empty; + /*Proxy From ProxyPPC.h*/ + ApplyProxyPPC(url); + if (IsCached(url)) { + time = GetCachedLastModified(url); + etag = GetCachedETag(url); + } Http_TryCancel(TexturePack_ReqID); TexturePack_ReqID = Http_AsyncGetDataEx(url, HTTP_FLAG_PRIORITY, &time, &etag, NULL); + Http_TryCancel(TexturePack_ReqID); + TexturePack_ReqID = Http_AsyncGetDataEx(url, HTTP_FLAG_PRIORITY, &time, &etag, NULL); } void TexturePack_Extract(const cc_string* url) {