Created
March 1, 2024 08:07
-
-
Save TheSillyDoggo/89c3014bbd1d15654f4011f28a1e4863 to your computer and use it in GitHub Desktop.
concurrent http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void myCCHttpClientSend(CCHttpClient* tis, cocos2d::extension::CCHttpRequest* req) { | |
//cocos2d::extension::CCHttpClient::send(req); | |
log::info("url: {}", req->getUrl()); | |
log::info("request body: {}\ntag: {}\nuser data: {}", req->getRequestData(), req->getTag(), req->getUserData()); | |
req->retain(); | |
auto r = web::AsyncWebRequest(); | |
r.bodyRaw(req->getRequestData()); | |
auto v = req->getHeaders(); | |
for (size_t i = 0; i < v.size(); i++) | |
{ | |
r.header(v[i]); | |
} | |
if (req->getRequestType() == CCHttpRequest::HttpRequestType::kHttpGet) | |
r.method("GET"); | |
if (req->getRequestType() == CCHttpRequest::HttpRequestType::kHttpDelete) | |
r.method("DELETE"); | |
if (req->getRequestType() == CCHttpRequest::HttpRequestType::kHttpPost) | |
r.method("POST"); | |
if (req->getRequestType() == CCHttpRequest::HttpRequestType::kHttpPut) | |
r.method("PUT"); | |
auto resp = r.fetch(req->getUrl()); | |
resp.text().then([req, resp](std::string const& catgirl) { | |
log::info("success"); | |
log::info("heres the response :3 {}", catgirl); | |
CCObject *pTarget = req->getTarget(); | |
SEL_HttpResponse pSelector = req->getSelector(); | |
if (pTarget && pSelector) | |
{ | |
CCHttpResponse *response = new CCHttpResponse(req); | |
gd::vector<char> charVector(catgirl.begin(), catgirl.end()); | |
response->setResponseData(&charVector); | |
response->setSucceed(catgirl != "-1"); | |
response->setResponseCode(200); | |
(pTarget->*pSelector)(CCHttpClient::getInstance(), response); | |
} | |
req->release(); | |
}) | |
.expect([req](std::string const& error) { | |
log::info("failure: {}", error); | |
CCHttpResponse *response = new CCHttpResponse(req); | |
gd::vector<char> charVector(error.begin(), error.end()); | |
response->setResponseData(&charVector); | |
response->setSucceed(false); | |
response->setResponseCode(-1); | |
CCObject *pTarget = req->getTarget(); | |
SEL_HttpResponse pSelector = req->getSelector(); | |
(pTarget->*pSelector)(CCHttpClient::getInstance(), response); | |
req->release(); | |
}); | |
} | |
$execute { | |
Mod::get()->hook( | |
reinterpret_cast<void*>( | |
geode::addresser::getNonVirtual( | |
geode::modifier::Resolve<cocos2d::extension::CCHttpRequest*>::func(&CCHttpClient::send) | |
) | |
), | |
&myCCHttpClientSend, | |
"cocos2d::extension::CCHttpClient::send", | |
tulip::hook::TulipConvention::Thiscall | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment