-
Notifications
You must be signed in to change notification settings - Fork 0
/
nhttp.cpp
74 lines (64 loc) · 2.38 KB
/
nhttp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <cstdlib.h>
#include <nhttp.h>
#include <nwc24.h>
#include <patch.h>
#include <personal_data.h>
#include <rvl.h>
#include <setting.h>
namespace demae::NHTTP {
/*
* AlterHTTPGetHeaders is inserted where HTTPGet attempts to create the X-APPVER
* header. That header however has been replaced by X-WiiNo and our Wii Number.
*/
int AlterHTTPGETHeaders(int *connection, const char *key, const char *value) {
// Add Wii Number
int res = nhttp::NHTTPAddHeaderField(connection, key, value);
if (res != 0)
return 0;
// Attempt and load personal data
PersonalData::PersonalData pd{};
PersonalData::LoadPersonalData(&pd);
// First request (webApi_documentRequest) does not have pd.dat loaded at
// request time. We don't need it so this isn't an issue.
if (pd.address != nullptr) {
res = nhttp::NHTTPAddHeaderField(connection, "X-Address", pd.address);
if (res != 0)
return 0;
res =
nhttp::NHTTPAddHeaderField(connection, "X-PostalCode", pd.postal_code);
if (res != 0)
return 0;
if (cstdlib::strlen(pd.apartment_number) != 0) {
res = nhttp::NHTTPAddHeaderField(connection, "X-AptNumber", pd.apartment_number);
if (res != 0)
return 0;
}
}
// Now country code
char *country_code = static_cast<char *>(cstdlib::malloc(4));
cstdlib::sprintf(country_code, "%d", sc::GetCountry());
return nhttp::NHTTPAddHeaderField(connection, "X-WiiCountryCode",
country_code);
}
/*
* AlterPOSTRequestHeaders adds extra request headers to a POST request.
*/
int AlterPOSTRequestHeaders(int *connection, const char *key,
const char *value) {
int res = nhttp::NHTTPAddHeaderField(connection, key, value);
if (res != 0)
return res;
// Add country code
char *country_code = static_cast<char *>(cstdlib::malloc(4));
cstdlib::sprintf(country_code, "%d", sc::GetCountry());
return nhttp::NHTTPAddHeaderField(connection, "X-WiiCountryCode",
country_code);
}
DEMAE_DEFINE_PATCH = {
Patch::WriteFunctionCall(0x8002ce98, AlterHTTPGETHeaders),
Patch::WriteFunctionCall(0x8002ca98, AlterPOSTRequestHeaders),
// Overwrite X-APPVER header.
Patch::WriteString(0x802d6300, "X-WiiNo\0"),
// Change pointer to header value to the one with the Wii Number.
Patch::WriteU32(0x804706dc, 0x800017F0)};
} // namespace demae::NHTTP