add proxy support for resource downloads

- Added ProxyPPC module to prepend proxy prefix to resource URLs
- Modified MusicAsset_Download in resources.c to use proxy
- Re-added legacy texture pack proxy code from ClassiCube-PPC1.3.7rev4

(Compiles  on PowerMac G4 1.24GHz + ATI Radeon 9000 Pro)
This commit is contained in:
2025-12-23 16:15:47 +02:00
parent f8c1b2ac49
commit 66f0e40881
4 changed files with 95 additions and 16 deletions

59
src/ProxyPPC.c Normal file
View File

@@ -0,0 +1,59 @@
#include <string.h>
#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;
}
}

11
src/ProxyPPC.h Normal file
View File

@@ -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

View File

@@ -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) {

View File

@@ -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) {