Skip to content

Commit

Permalink
Merge pull request #754 from Kantanomo/development-new
Browse files Browse the repository at this point in the history
refactor and remove tag_interface
Berthalamew authored Dec 1, 2024
2 parents 9ce8189 + 3f4f5c2 commit d122ac3
Showing 10 changed files with 77 additions and 102 deletions.
43 changes: 38 additions & 5 deletions xlive/Blam/Engine/cache/cache_files.cpp
Original file line number Diff line number Diff line change
@@ -39,24 +39,56 @@ void cache_files_apply_patches(void)
return;
}

HANDLE* cache_file_handle_get()
{
return Memory::GetAddress<HANDLE*>(0x4AE8A8, 0x4CF128);
}

s_cache_file_memory_globals* cache_file_memory_globals_get(void)
{
return Memory::GetAddress<s_cache_file_memory_globals*>(0x47CD60, 0x4A29C8);
}

bool cache_file_is_loaded()
{
const s_cache_file_memory_globals* cache_file_memory_globals = cache_file_memory_globals_get();

return cache_file_memory_globals->tags_loaded;
}

s_cache_header* cache_files_get_header(void)
{
return Memory::GetAddress<s_cache_header*>(0x47CD68, 0x4A29D0);
s_cache_file_memory_globals* cache_file_memory_globals = cache_file_memory_globals_get();

return &cache_file_memory_globals->header;
}

cache_file_tags_header* cache_files_get_tags_header(void)
{
return tags::get_at_tag_data_offset<cache_file_tags_header>(cache_files_get_header()->tag_offset_mask);
const s_cache_file_memory_globals* cache_file_memory_globals = cache_file_memory_globals_get();

return cache_file_memory_globals->tags_header;
}

cache_file_tag_instance* global_tag_instances_get(void)
{
return *Memory::GetAddress<cache_file_tag_instance**>(0x47CD50, 0x4A29B8);
const s_cache_file_memory_globals* cache_file_memory_globals = cache_file_memory_globals_get();

return cache_file_memory_globals->tags_header->tag_instances;
}

int8* cache_get_tag_data(uint32 offset)
{
const s_cache_file_memory_globals* cache_file_memory_globals = cache_file_memory_globals_get();

return (int8*)(cache_file_memory_globals->tag_cache_base_address + offset);
}

cache_file_tag_instance* cache_get_tag_instance(datum tag_index)
{
const s_cache_file_memory_globals* cache_file_memory_globals = cache_file_memory_globals_get();

return &cache_file_memory_globals->tags_header->tag_instances[DATUM_INDEX_TO_ABSOLUTE_INDEX(tag_index)];
}

tag_iterator* tag_iterator_new(tag_iterator* itr, e_tag_group type)
@@ -79,8 +111,9 @@ void cache_file_map_clear_all_failures(void)

void* __cdecl tag_get_fast(datum tag_index)
{
//return INVOKE(0x239623, 0x217295, tag_get_fast, tag_index);
return tags::get_tag_data() + tags::get_tag_instance(tag_index)->data_offset;
const s_cache_file_memory_globals* cache_file_memory_globals = cache_file_memory_globals_get();

return (void*)(cache_file_memory_globals->tag_cache_base_address + cache_get_tag_instance(tag_index)->data_offset);
}

void __cdecl cache_file_close()
9 changes: 9 additions & 0 deletions xlive/Blam/Engine/cache/cache_files.h
Original file line number Diff line number Diff line change
@@ -140,14 +140,22 @@ ASSERT_STRUCT_SIZE(tag_iterator, 20);

void cache_files_apply_patches(void);

HANDLE* cache_file_handle_get();

s_cache_file_memory_globals* cache_file_memory_globals_get(void);

bool cache_file_is_loaded();

s_cache_header* cache_files_get_header(void);

cache_file_tags_header* cache_files_get_tags_header(void);

cache_file_tag_instance* global_tag_instances_get(void);

int8* cache_get_tag_data(uint32 offset = 0);

cache_file_tag_instance* cache_get_tag_instance(datum tag_index);

tag_iterator* tag_iterator_new(tag_iterator* itr, e_tag_group type);

datum __cdecl tag_iterator_next(tag_iterator* itr);
@@ -157,6 +165,7 @@ void cache_file_map_clear_all_failures(void);
// Get tag data from tag index
void* __cdecl tag_get_fast(datum tag_index);


void __cdecl cache_file_close();

bool __cdecl cache_header_verify(s_cache_header* cache_header);
4 changes: 2 additions & 2 deletions xlive/Blam/Engine/tag_files/tag_block.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "H2MOD/Tags/TagInterface.h"
#include "cache/cache_files.h"

// ### TODO Rename to c_tag_block and refactor

@@ -21,7 +21,7 @@ struct tag_block
{
if (this->data != NONE)
{
uint8* tag_data_table = tags::get_tag_data();
uint8* tag_data_table = (uint8*)cache_get_tag_data();
#ifdef DEBUG
if (LOG_CHECK(tag_data_table))
#endif
20 changes: 10 additions & 10 deletions xlive/Blam/Engine/tag_files/tag_loader/tag_injection_manager.cpp
Original file line number Diff line number Diff line change
@@ -214,7 +214,7 @@ void c_tag_injecting_manager::load_raw_data_from_cache(datum injected_index) con
*g_cache_handle_geometry_block_size = 0x0;

cache_file_tag_instance* tag_info = &this->m_instances[DATUM_INDEX_TO_ABSOLUTE_INDEX(injected_index)];
uint8* tag_data = tags::get_tag_data() + this->m_instances[DATUM_INDEX_TO_ABSOLUTE_INDEX(injected_index)].data_offset;
uint8* tag_data = (uint8*)cache_get_tag_data() + this->m_instances[DATUM_INDEX_TO_ABSOLUTE_INDEX(injected_index)].data_offset;

//fail safe
if (DATUM_INDEX_TO_ABSOLUTE_INDEX(tag_info->tag_index) != DATUM_INDEX_TO_ABSOLUTE_INDEX(injected_index))
@@ -380,7 +380,7 @@ datum c_tag_injecting_manager::get_tag_datum_by_name(e_tag_group group, const ch

if(csstricmp(tag_name, name_buffer) == 0)
{
file_seek_and_read(this->m_active_map_file_handle, this->m_active_map_instance_table_offset + (current_index * sizeof(tags::tag_instance)), sizeof(tags::tag_instance), 1, &temp_instance);
file_seek_and_read(this->m_active_map_file_handle, this->m_active_map_instance_table_offset + (current_index * sizeof(cache_file_tag_instance)), sizeof(cache_file_tag_instance), 1, &temp_instance);
if (temp_instance.group_tag.group == group)
return temp_instance.tag_index;
}
@@ -398,7 +398,7 @@ datum c_tag_injecting_manager::get_tag_datum_by_name(e_tag_group group, const ch

if (csstricmp(tag_name, name_buffer) == 0)
{
file_seek_and_read(this->m_active_map_file_handle, this->m_active_map_instance_table_offset + (current_index * sizeof(tags::tag_instance)), sizeof(tags::tag_instance), 1, &temp_instance);
file_seek_and_read(this->m_active_map_file_handle, this->m_active_map_instance_table_offset + (current_index * sizeof(cache_file_tag_instance)), sizeof(cache_file_tag_instance), 1, &temp_instance);
if (temp_instance.group_tag.group == group)
return temp_instance.tag_index;
}
@@ -681,12 +681,12 @@ void c_tag_injecting_manager::inject_tags()
uint32 injection_offset = this->m_base_tag_data_size + this->m_injectable_used_size;

#if TAG_INJECTION_DEBUG
const uint32 start = (uint32)tags::get_tag_data();
const uint32 start = (uint32)cache_get_tag_data();
const uint32 end = start + this->get_base_map_tag_data_size() + k_injectable_allocation_size;
bool in_range = ((uint32)tags::get_tag_data() + injection_offset) >= start && ((uint32)tags::get_tag_data() + injection_offset) < end;
bool in_range = ((uint32)cache_get_tag_data() + injection_offset) >= start && ((uint32)cache_get_tag_data() + injection_offset) < end;

LOG_DEBUG_GAME("[c_tag_injecting_manager::inject_tags] injection_offset: {:x} is valid: {} start: {:x} end: {:x}",
(uint32)tags::get_tag_data() + injection_offset, in_range, start, end);
(uint32)cache_get_tag_data() + injection_offset, in_range, start, end);
#endif


@@ -711,7 +711,7 @@ void c_tag_injecting_manager::inject_tags()
LOG_DEBUG_GAME("[c_tag_injecting_manager::inject_tags] type: {} injection_offset: {:x} data_size: {:x} tag_name: {} datum: {:x}", tag_class, injection_offset, injection_instance->size, tag_name.get_string(), entry->injected_index);
#endif

entry->loaded_data->copy_tag_data((int8*)(tags::get_tag_data() + injection_offset), injection_offset);
entry->loaded_data->copy_tag_data((int8*)(cache_get_tag_data() + injection_offset), injection_offset);

if(entry->type.group == _tag_group_bitmap || entry->type.group == _tag_group_render_model || entry->type.group == _tag_group_weather_system)
this->load_raw_data_from_cache(entry->injected_index);
@@ -735,10 +735,10 @@ void* c_tag_injecting_manager::extend_tag_block(void* block, uint32 entry_size,
uint32 base_block_total_size = entry_size * basic_block->count;
uint32 new_block_total_size = base_block_total_size + (entry_size * count);

int8* base_block_location = (int8*)(tags::get_tag_data() + basic_block->data);
int8* base_block_location = (int8*)(cache_get_tag_data() + basic_block->data);

uint32 injection_offset = this->m_base_tag_data_size + this->m_injectable_used_size;
int8* injection_location = (int8*)(tags::get_tag_data() + injection_offset);
int8* injection_location = (int8*)(cache_get_tag_data() + injection_offset);

memcpy(injection_location, base_block_location, base_block_total_size);

@@ -748,5 +748,5 @@ void* c_tag_injecting_manager::extend_tag_block(void* block, uint32 entry_size,
this->m_injectable_used_size += new_block_total_size;

// return the location in memory where the first newly added block exists
return (void*)(tags::get_tag_data() + injection_offset + base_block_total_size);
return (void*)(cache_get_tag_data() + injection_offset + base_block_total_size);
}
1 change: 0 additions & 1 deletion xlive/H2MOD/Modules/CustomMenu/CustomMenuGlobals.cpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
#include "CustomMenuGlobals.h"

#include "game/game_globals.h"
#include "H2MOD/Tags/TagInterface.h"

std::chrono::time_point<std::chrono::high_resolution_clock> lastOuterMenuUse;
void* lastOuterMenuFuncPtr = 0;
28 changes: 14 additions & 14 deletions xlive/H2MOD/Modules/MainMenu/Ranks.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "stdafx.h"

#include "cache/cache_files.h"
#include "H2MOD/Modules/OnScreenDebug/OnScreenDebug.h"
#include "H2MOD/Tags/TagInterface.h"



@@ -46,30 +46,30 @@ void UIRankPatch()
const WORD HeightValue = 0x0020; //Value : 32 (decimal)

//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);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPreGameLobby + (pSkinChunkIndex * pSkinChunkSize) + yDefOffset], yValuePGL);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPreGameLobby + (pSkinChunkIndex * pSkinChunkSize) + bitmOffset], RankIconSM);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPreGameLobby + (pSkinChunkIndex * pSkinChunkSize) + xDefOffset], xValuePGL);

//Sets Postgame Carnage Report 1
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPostGameCarnage1 + (pSkinChunkIndex * pSkinChunkSize) + xDefOffset], xValuePCR);
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPostGameCarnage1 + (pSkinChunkIndex * pSkinChunkSize) + yDefOffset], yValuePCR);
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPostGameCarnage1 + (pSkinChunkIndex * pSkinChunkSize) + bitmOffset], RankIconSM);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPostGameCarnage1 + (pSkinChunkIndex * pSkinChunkSize) + xDefOffset], xValuePCR);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPostGameCarnage1 + (pSkinChunkIndex * pSkinChunkSize) + yDefOffset], yValuePCR);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPostGameCarnage1 + (pSkinChunkIndex * pSkinChunkSize) + bitmOffset], RankIconSM);

//Sets Postgame Carnage Report 2
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPostGameCarnage2 + (pSkinChunkIndex * pSkinChunkSize) + xDefOffset], xValuePCR);
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPostGameCarnage2 + (pSkinChunkIndex * pSkinChunkSize) + yDefOffset], yValuePCR);
WriteValue((DWORD)&tags::get_tag_data()[TagOffsetPostGameCarnage2 + (pSkinChunkIndex * pSkinChunkSize) + bitmOffset], RankIconSM);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPostGameCarnage2 + (pSkinChunkIndex * pSkinChunkSize) + xDefOffset], xValuePCR);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPostGameCarnage2 + (pSkinChunkIndex * pSkinChunkSize) + yDefOffset], yValuePCR);
WriteValue((DWORD)&cache_get_tag_data()[TagOffsetPostGameCarnage2 + (pSkinChunkIndex * pSkinChunkSize) + bitmOffset], RankIconSM);

//Sets Ranks
for (RankChunkIndex = 0; RankChunkIndex < 50; RankChunkIndex++)
{
//Setting Rank bitmap size
WriteValue((DWORD)&tags::get_tag_data()[RankIconOff + (RankChunkIndex * RankChunkSize) + WidthDefOff], WidthValue);
WriteValue((DWORD)&tags::get_tag_data()[RankIconOff + (RankChunkIndex * RankChunkSize) + HeightDefOff], HeightValue);
WriteValue((DWORD)&cache_get_tag_data()[RankIconOff + (RankChunkIndex * RankChunkSize) + WidthDefOff], WidthValue);
WriteValue((DWORD)&cache_get_tag_data()[RankIconOff + (RankChunkIndex * RankChunkSize) + HeightDefOff], HeightValue);

//Setting Small Rank bitmap size
WriteValue((DWORD)&tags::get_tag_data()[RankIconSMOff + (RankChunkIndex * RankChunkSize) + WidthDefOff], WidthValue);
WriteValue((DWORD)&tags::get_tag_data()[RankIconSMOff + (RankChunkIndex * RankChunkSize) + HeightDefOff], HeightValue);
WriteValue((DWORD)&cache_get_tag_data()[RankIconSMOff + (RankChunkIndex * RankChunkSize) + WidthDefOff], WidthValue);
WriteValue((DWORD)&cache_get_tag_data()[RankIconSMOff + (RankChunkIndex * RankChunkSize) + HeightDefOff], HeightValue);
}

addDebugText("Rank bitmaps patched.");
9 changes: 4 additions & 5 deletions xlive/H2MOD/Modules/TagFixes/TagFixes.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
#include "units/biped_definitions.h"

#include "H2MOD/Modules/Shell/Config.h"
#include "H2MOD/Tags/TagInterface.h"
#include "objects/light_definitions.h"

// ### TODO Cleanup
@@ -38,11 +37,11 @@ namespace TagFixes
tag_block<int> *shader_post = reinterpret_cast<tag_block<int>*>(shader + 0x20);
if(shader_post->count > 0)
{
auto shader_post_data = tags::get_tag_data() + shader_post->data;
auto shader_post_data = cache_get_tag_data(shader_post->data);
auto shader_post_bitmap = reinterpret_cast<tag_block<int>*>(shader_post_data + 0x4);
if(shader_post_bitmap->count >= bitmap_idx + 1)
{
auto bitmap_data = tags::get_tag_data() + (shader_post_bitmap->data + (bitmap_idx * 0xC));
auto bitmap_data = cache_get_tag_data( (shader_post_bitmap->data + (bitmap_idx * 0xC)));
datum* bitmap = reinterpret_cast<datum*>(bitmap_data);
if(*bitmap == bitmap_to_fix)
*bitmap = NONE;
@@ -79,11 +78,11 @@ namespace TagFixes
tag_block<int> *shadow_pp = reinterpret_cast<tag_block<int>*>(shadow_tag + 0x1C);
if(shadow_pp->count > 0 && shadow_pp->data != NONE)
{
auto shadow_pp_data = tags::get_tag_data() + shadow_pp->data;
auto shadow_pp_data = cache_get_tag_data(shadow_pp->data);
tag_block<int>*shadow_impl_block = reinterpret_cast<tag_block<int>*>(shadow_pp_data);
if(shadow_pp->count > 0 && shadow_impl_block->data != NONE)
{
auto shadow_impl = tags::get_tag_data() + shadow_impl_block->data;
auto shadow_impl = cache_get_tag_data(shadow_impl_block->data);
tag_reference* impl_1 = reinterpret_cast<tag_reference*>(shadow_impl + (0x14A) + 0xFC);
tag_reference* impl_2 = reinterpret_cast<tag_reference*>(shadow_impl + (0x14A*2) + 0xFC);

23 changes: 0 additions & 23 deletions xlive/H2MOD/Tags/TagInterface.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions xlive/H2MOD/Tags/TagInterface.h

This file was deleted.

2 changes: 0 additions & 2 deletions xlive/Project_Cartographer.vcxproj
Original file line number Diff line number Diff line change
@@ -928,7 +928,6 @@
<ClCompile Include="Blam\Engine\interface\screens\screen_xbox_live_task_progress_dialog.cpp" />
<ClCompile Include="H2MOD\Modules\WeaponOffsets\WeaponOffsetConfig.cpp" />
<ClCompile Include="H2MOD\GUI\imgui_integration\WeaponOffsets.cpp" />
<ClCompile Include="H2MOD\Tags\TagInterface.cpp" />
<ClCompile Include="H2MOD\Modules\Shell\ServerConsole.cpp" />
<ClCompile Include="H2MOD\Variants\GraveRobber\GraveRobber.cpp" />
<ClCompile Include="stdafx.cpp">
@@ -1368,7 +1367,6 @@
<ClInclude Include="H2MOD\Modules\TagFixes\TagFixes.h" />
<ClInclude Include="Blam\Engine\interface\screens\screen_xbox_live_task_progress_dialog.h" />
<ClInclude Include="H2MOD\Modules\WeaponOffsets\WeaponOffsetConfig.h" />
<ClInclude Include="H2MOD\Tags\TagInterface.h" />
<ClInclude Include="H2MOD\Variants\GraveRobber\GraveRobber.h" />
<ClInclude Include="H2MOD\Variants\Variants.h" />
<ClInclude Include="resources\version_resource.h" />

0 comments on commit d122ac3

Please sign in to comment.