Skip to content

Commit

Permalink
Merge branch 'development' into development-patches
Browse files Browse the repository at this point in the history
  • Loading branch information
pnill authored Jun 3, 2020
2 parents 37bd2ff + 773a582 commit 992d79d
Show file tree
Hide file tree
Showing 26 changed files with 1,514 additions and 522 deletions.
19 changes: 17 additions & 2 deletions xlive/H2MOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ bool __cdecl OnMapLoad(game_engine_settings* engine_settings)
H2Tweaks::setFOV(H2Config_field_of_view);
H2Tweaks::setCrosshairPos(H2Config_crosshair_offset);
H2Tweaks::setVehicleFOV(H2Config_vehicle_field_of_view);

ScriptEngine::sqOnMapLoad();

if (h2mod->GetMapType() == scnr_type::MainMenu)
Expand Down Expand Up @@ -902,11 +902,15 @@ bool __cdecl OnMapLoad(game_engine_settings* engine_settings)
b_GunGame = false;
}

if (b_XboxTick) {
engine_settings->tickrate = XboxTick::setTickRate(false);
b_XboxTick = false;
}

UIRankPatch();
H2Tweaks::setHz();
H2Tweaks::toggleAiMp(false);
H2Tweaks::toggleUncappedCampaignCinematics(false);
engine_settings->tickrate = XboxTick::setTickRate(false);

return result;
}
Expand Down Expand Up @@ -1676,6 +1680,15 @@ void __cdecl game_mode_engine_draw_team_indicators()
p_game_mode_engine_draw_team_indicators();
}

bool __cdecl game_is_minimized_hook()
{
// if xbox tickrate is set, use the built in frame limiter
if (b_XboxTick)
return true;

// otherwise never use this frame limiter
return false;
}

void H2MOD::ApplyUnitHooks()
{
Expand Down Expand Up @@ -1752,6 +1765,8 @@ void H2MOD::ApplyHooks() {
LOG_TRACE_GAME("Applying client hooks...");
/* These hooks are only built for the client, don't enable them on the server! */

PatchCall(h2mod->GetAddress(0x288B5), game_is_minimized_hook);

p_verify_game_version_on_join = (verify_game_version_on_join)DetourFunc(h2mod->GetAddress<BYTE*>(0x1B4C14), (BYTE*)VerifyGameVersionOnJoin, 5);

p_verify_executable_version = (verify_executable_version)DetourFunc(h2mod->GetAddress<BYTE*>(0x1B4C32), (BYTE*)VerifyExecutableVersion, 8);
Expand Down
23 changes: 11 additions & 12 deletions xlive/H2MOD/Modules/Accounts/AccountLogin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static int InterpretMasterLogin(char* response_content, char* prev_login_token)
return result;
}

bool HandleGuiLogin(char* ltoken, char* identifier, char* password, DWORD* out_master_login_interpret_result) {
bool HandleGuiLogin(char* ltoken, char* identifier, char* password, int* out_master_login_interpret_result) {

bool result = false;
char* rtn_result = 0;
Expand Down Expand Up @@ -427,14 +427,14 @@ bool HandleGuiLogin(char* ltoken, char* identifier, char* password, DWORD* out_m
free(escaped_user_password);

int master_login_interpret_result = -1;
int rtn_code = MasterHttpResponse("https://cartographer.online/login2", http_request_body_build, rtn_result);
int master_http_response_result = MasterHttpResponse("https://cartographer.online/login2", http_request_body_build, rtn_result);

for (int i = strlen(http_request_body_build) - 1; i >= 0; i--) {
http_request_body_build[i] = 0;
}
free(http_request_body_build);

if (rtn_code == 0) {
if (master_http_response_result == 0) {
master_login_interpret_result = InterpretMasterLogin(rtn_result, ltoken);
if (master_login_interpret_result > 0) {
result = true;
Expand All @@ -447,7 +447,6 @@ bool HandleGuiLogin(char* ltoken, char* identifier, char* password, DWORD* out_m
addDebugText(NotificationPlayerText);

if (master_login_interpret_result == ERROR_CODE_INVALID_LOGIN_TOKEN) {

char* username = 0;
for (int i = 0; i < H2AccountCount; i++) {
if (H2AccountBufferLoginToken[i] && strcmp(H2AccountBufferLoginToken[i], ltoken) == 0) {
Expand All @@ -461,14 +460,14 @@ bool HandleGuiLogin(char* ltoken, char* identifier, char* password, DWORD* out_m
snprintf(login_identifier, strlen(username) + 1, username);
}
}
else {
if (!H2IsDediServer) {
char* login_identifier = H2CustomLanguageGetLabel(CMLabelMenuId_AccountEdit, 1);
SecureZeroMemory(login_identifier, strlen(login_identifier));
}
if (master_login_interpret_result == SUCCESS_CODE_MACHINE_SERIAL_INSUFFICIENT) {
result = false;
}
}
else {
if (!H2IsDediServer) {
char* login_identifier = H2CustomLanguageGetLabel(CMLabelMenuId_AccountEdit, 1);
SecureZeroMemory(login_identifier, strlen(login_identifier));
}
if (master_login_interpret_result == SUCCESS_CODE_MACHINE_SERIAL_INSUFFICIENT) {
result = false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion xlive/H2MOD/Modules/Accounts/AccountLogin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const int ERROR_CODE_MACHINE_SERIAL_INSUFFICIENT = -13;
const int SUCCESS_CODE_MACHINE_SERIAL_INSUFFICIENT = 7;

void UpdateConnectionStatus();
bool HandleGuiLogin(char* token, char* identifier, char* password, DWORD* master_login_interpret_result);
bool HandleGuiLogin(char* token, char* identifier, char* password, int* master_login_interpret_result);
char ConfigureUserDetails(char* username, char* login_token, unsigned long long xuid, unsigned long saddr, unsigned long xnaddr, char* abEnet, char* abOnline, bool onlineSignIn);

extern bool AccountEdit_remember;
2 changes: 1 addition & 1 deletion xlive/H2MOD/Modules/CustomMenu/CustomMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3890,7 +3890,7 @@ __declspec(naked) void sub_2111ab_CMLTD_nak_AccountEdit() {//__thiscall
}
}

static DWORD master_login_code;
static int master_login_code;
static HANDLE hThreadLogin = INVALID_HANDLE_VALUE;

void xbox_live_task_progress_callback(DWORD a1)
Expand Down
10 changes: 2 additions & 8 deletions xlive/H2MOD/Modules/MainMenu/Ranks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

void UIRankPatch() {

if (H2IsDediServer)
return;

if (!tags::get_cache_header()->is_main_menu()) //If not on mainmenu, returns
if (h2mod->GetMapType() != MainMenu || h2mod->Server)
return;

BYTE PlayerLevel = -1; //eventually this will pull level from webserver
Expand All @@ -27,7 +24,6 @@ void UIRankPatch() {
//Tag : ui\player_skins\pcr_2.skin
const DWORD TagOffsetPostGameCarnage2 = 0x00485F50; //Property : Bitmap Buttons


const BYTE pSkinChunkSize = 0x38; //Property size per chunk
const int pSkinChunkIndex = 2; //Property chunk index number (2 represents rank field)
const BYTE xDefOffset = 0x0C; //Definition : Horizontal position on mainmenu
Expand All @@ -46,16 +42,14 @@ void UIRankPatch() {
const DWORD RankIconSM = 0xE4EC02CA; //Bitmap Datum Index
const DWORD RankIconSMOff = 0x00476D3C; //Property : Bitmap


const BYTE RankChunkSize = 0x74; //Property size per chunk
int RankChunkIndex; //Property chunk index number (0-49)
const BYTE WidthDefOff = 0x04; //Definition : Width
const WORD WidthValue = 0x0020; //Value : 32 (decimal)
const BYTE HeightDefOff = 0x06; //Definition : Height
const WORD HeightValue = 0x0020; //Value : 32 (decimal)


//Sets Pregame Lobby
//Sets Pregame Lobby
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPreGameLobby + (pSkinChunkIndex * pSkinChunkSize) + yDefOffset], yValuePGL);
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPreGameLobby + (pSkinChunkIndex * pSkinChunkSize) + bitmOffset], RankIconSM);
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPreGameLobby + (pSkinChunkIndex * pSkinChunkSize) + xDefOffset], xValuePGL);
Expand Down
51 changes: 19 additions & 32 deletions xlive/H2MOD/Modules/Networking/CustomPackets/CustomPackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,35 @@ void __stdcall observer_channel_send_message(network_observer* pnetwork_observer
return p_observer_channel_send_message(pnetwork_observer, unk_index, observer_index, send_out_of_band, type, size, buffer);
}


void register_packet_impl(void *packetObject, int type, char* name, int a4, int size1, int size2, void* write_packet_method, void* read_packet_method, void* a9)
void register_packet_impl(void *packetObject, int type, char* name, int a4, int size1, int size2, void* write_packet_method, void* read_packet_method, void* unk_callback)
{
typedef void(__thiscall* register_packet_type)(void *packetObject, int type, char* name, int a4, int size1, int size2, void* write_packet_method, void* read_packet_method, void* a9);
typedef void(__thiscall* register_packet_type)(void *, int, char*, int, int, int, void*, void*, void*);
auto register_packet = reinterpret_cast<register_packet_type>(h2mod->GetAddress(0x1E81D6, 0x1CA199));
return register_packet(packetObject, type, name, a4, size1, size2, write_packet_method, read_packet_method, a9);
}

char* getNetworkChannelData(int channel_index)
{
return *h2mod->GetAddress<char**>(0x4FADBC, 0x525274) + 248 * channel_index;
return register_packet(packetObject, type, name, a4, size1, size2, write_packet_method, read_packet_method, unk_callback);
}

const char* getNetworkMessageName(int enumVal)
{
return network_message_name[enumVal];
}

bool getNetworkAddressFromNetworkChannel(char* network_channel, network_address* out_addr)
{
typedef bool(__thiscall* get_network_address_from_network_channel)(char*, network_address*);
auto p_get_network_address_from_network_channel = reinterpret_cast<get_network_address_from_network_channel>(h2mod->GetAddress(0x1BA543, 0x1C9364));
return p_get_network_address_from_network_channel(network_channel, out_addr);
}

void __cdecl encode_map_file_name_packet(bitstream* stream, int a2, s_custom_map_filename* data)
{
stream->data_encode_string("map-file-name", (int)&data->file_name, 32);
stream->data_encode_string("map-file-name", &data->file_name, ARRAYSIZE(data->file_name));
}
bool __cdecl decode_map_file_name_packet(bitstream* stream, int a2, s_custom_map_filename* data)
{
stream->data_decode_string("map-file-name", (int)&data->file_name, 32);
stream->data_decode_string("map-file-name", &data->file_name, ARRAYSIZE(data->file_name));
return stream->packet_is_valid() == false;
}

void __cdecl encode_request_map_filename_packet(bitstream* stream, int a2, s_request_map_filename* data)
{
stream->data_encode_bits("user-identifier", &data->user_identifier, 64);
stream->data_encode_bits("user-identifier", &data->user_identifier, player_identifier_size_bits);
}
bool __cdecl decode_request_map_filename_packet(bitstream* stream, int a2, s_request_map_filename* data)
{
stream->data_decode_bits("user-identifier", (int)&data->user_identifier, 64);
stream->data_decode_bits("user-identifier", &data->user_identifier, player_identifier_size_bits);
return stream->packet_is_valid() == false;
}

Expand Down Expand Up @@ -135,11 +122,11 @@ void __stdcall handle_out_of_band_message_hook(void *thisx, network_address* add
if (map_filename.size() > 0)
{
data.is_custom_map = true;
wcsncpy_s(data.file_name, map_filename.c_str(), 32);
wcsncpy_s(data.file_name, map_filename.c_str(), ARRAYSIZE(data.file_name));
}
LOG_TRACE_NETWORK(L"[H2MOD-CustomPackets] sending map file name packet to XUID: {}, peer index: {}, map name: {}", received_data->user_identifier, peer_index, map_filename.c_str());
observer_channel_send_message(session->network_observer_ptr, session->unk_index, session->peer_observer_channels[peer_index].observer_index, true,
observer_channel_send_message(session->network_observer_ptr, session->unk_index, session->peer_observer_channels[peer_index].observer_index, network_observer::network_message_send_protocol::out_of_band,
map_file_name, sizeof(s_custom_map_filename), &data);
}
Expand Down Expand Up @@ -194,10 +181,9 @@ void __stdcall handle_channel_message_hook(void *thisx, int network_channel_inde
This handles received in-band data
*/

char* network_channel = getNetworkChannelData(network_channel_index);
network_address addr;
SecureZeroMemory(&addr, sizeof(network_address));
getNetworkAddressFromNetworkChannel(network_channel, &addr);
network_channel* peer_network_channel = network_channel::getNetworkChannel(network_channel_index);
peer_network_channel->getNetworkAddressFromNetworkChannel(&addr);

switch (message_type)
{
Expand Down Expand Up @@ -240,7 +226,8 @@ void __stdcall handle_channel_message_hook(void *thisx, int network_channel_inde
{
s_request_map_filename* received_data = (s_request_map_filename*)packet;
LOG_TRACE_NETWORK("[H2MOD-CustomPackets] received on handle_channel_message_hook request-map-filename from XUID: {}", received_data->user_identifier);
if (*(int*)(network_channel + 0x54) == 5 && getNetworkAddressFromNetworkChannel(network_channel, &addr))
if (peer_network_channel->channel_state == network_channel::e_channel_state::unk_state_5
&& peer_network_channel->getNetworkAddressFromNetworkChannel(&addr))
{
LOG_TRACE_NETWORK(" - network address: {:x}", ntohl(addr.address.ipv4));

Expand All @@ -255,14 +242,14 @@ void __stdcall handle_channel_message_hook(void *thisx, int network_channel_inde
mapManager->getMapFilename(map_filename);
if (map_filename.size() > 0)
{
wcsncpy_s(data.file_name, map_filename.c_str(), 32);
wcsncpy_s(data.file_name, map_filename.c_str(), ARRAYSIZE(data.file_name));

LOG_TRACE_NETWORK(L"[H2MOD-CustomPackets] sending map file name packet to XUID: {}, peer index: {}, map name: {}", received_data->user_identifier, peer_index, map_filename.c_str());

network_observer* observer = session->network_observer_ptr;
peer_observer_channel* observer_channel = NetworkSession::getPeerObserverChannel(peer_index);

observer->sendNetworkMessage(session->unk_index, observer_channel->observer_index, false, custom_map_filename, sizeof(s_custom_map_filename), &data);
observer->sendNetworkMessage(session->unk_index, observer_channel->observer_index, network_observer::e_network_message_send_protocol::in_band, custom_map_filename, sizeof(s_custom_map_filename), &data);
}
else
{
Expand All @@ -276,7 +263,7 @@ void __stdcall handle_channel_message_hook(void *thisx, int network_channel_inde

case custom_map_filename:
{
if (*(int*)(network_channel + 0x54) == 5)
if (peer_network_channel->channel_state == network_channel::e_channel_state::unk_state_5)
{
s_custom_map_filename* received_data = (s_custom_map_filename*)packet;
mapManager->setMapFileNameToDownload(received_data->file_name);
Expand All @@ -302,7 +289,7 @@ void __stdcall handle_channel_message_hook(void *thisx, int network_channel_inde

case team_change:
{
if (*(int*)(network_channel + 0x54) == 5)
if (peer_network_channel->channel_state == network_channel::e_channel_state::unk_state_5)
{
s_team_change* received_data = (s_team_change*)packet;
h2mod->set_local_team_index(0, received_data->team_index);
Expand Down Expand Up @@ -331,7 +318,7 @@ void CustomPackets::sendRequestMapFilename()
peer_observer_channel* observer_channel = NetworkSession::getPeerObserverChannel(session->session_host_peer_index);

if (observer_channel->field_1) {
observer->sendNetworkMessage(session->unk_index, observer_channel->observer_index, false, request_map_filename, sizeof(s_request_map_filename), &data);
observer->sendNetworkMessage(session->unk_index, observer_channel->observer_index, network_observer::e_network_message_send_protocol::in_band, request_map_filename, sizeof(s_request_map_filename), &data);

LOG_TRACE_NETWORK("[H2MOD-CustomPackets] Sending map name request info: session host peer index: {}, observer index {}, observer bool unk: {}, unk index: {}",
session->session_host_peer_index,
Expand All @@ -356,7 +343,7 @@ void CustomPackets::sendTeamChange(int peerIndex, int teamIndex)
if (peerIndex != -1 && peerIndex != session->local_peer_index)
{
if (observer_channel->field_1) {
observer->sendNetworkMessage(session->unk_index, observer_channel->observer_index, false, team_change, sizeof(s_team_change), &data);
observer->sendNetworkMessage(session->unk_index, observer_channel->observer_index, network_observer::e_network_message_send_protocol::in_band, team_change, sizeof(s_team_change), &data);
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions xlive/H2MOD/Modules/Networking/CustomPackets/CustomPackets.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "..\NetworkSession/NetworkSession.h"
#include "..\NetworkSession\NetworkSession.h"

#define player_identifier_size_bits CHAR_BIT * sizeof(XUID)

enum e_network_message_types
{
Expand Down Expand Up @@ -53,6 +55,7 @@ enum e_network_message_types
game_results,
text_chat,
test,

//custom packets bellow
request_map_filename,
custom_map_filename,
Expand Down Expand Up @@ -113,6 +116,7 @@ static const char* network_message_name[] = {
"game_results",
"text_chat",
"test"

//custom packets bellow
"request_map_filename"
"map_file_name"
Expand Down Expand Up @@ -162,8 +166,8 @@ struct s_text_chat
#pragma pack(pop)

const char* getNetworkMessageName(int enumVal);

void register_packet_impl(void *, int, char*, int, int, int, void*, void*, void*);

namespace CustomPackets
{
void ApplyGamePatches();
Expand Down
Loading

0 comments on commit 992d79d

Please sign in to comment.