Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightgrid support for custom maps (SP) #1025

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/component/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ namespace gui
public:
void* load_import(const std::string& library, const std::string& function) override
{
if (function == "D3D11CreateDevice" && !game::environment::is_dedi())
if (function == "D3D11CreateDevice" && (!game::environment::is_dedi() && !game::environment::is_sp()))
{
return d3d11_create_device_stub;
}
Expand Down
44 changes: 22 additions & 22 deletions src/client/component/map_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ namespace map_patches
};

//WEAK game::symbol<bool(const game::GfxLightGrid* lightGrid, const game::GfxLightGridEntry* entry, int cornerIndex, const unsigned int* pos, const float* samplePos)> R_IsValidLightGridSample{ 0x0, 0x6D7E40 };
WEAK game::symbol<void(float*)> Vec3Normalize{ 0x0, 0x68D20 };
WEAK game::symbol<int(int, float const* const, float const* const, struct game::Bounds const*, unsigned int, int)> SV_BrushModelSightTrace{ 0x0, 0x3370A0 };
WEAK game::symbol<void(float*)> Vec3Normalize{ 0x5E090, 0x68D20 };
WEAK game::symbol<int(int, float const* const, float const* const, struct game::Bounds const*, unsigned int, int)> SV_BrushModelSightTrace{ 0x19F830, 0x3370A0 };

game::symbol<game::ComWorld> comWorld{ 0x0, 0xA97C0E0 };
game::symbol<game::GfxWorld*> s_world{ 0x0, 0xE973AE0 };
game::symbol<game::ComWorld*> comWorld{ 0xECA078, 0x10B4528 };
game::symbol<game::GfxWorld*> s_world{ 0xF7A2BE0, 0xE973AE0 };

game::dvar_t* r_lightGridNonCompressed;

Expand Down Expand Up @@ -181,14 +181,16 @@ namespace map_patches
return true;
if (!newPrimaryLightEnvIndex)
return false;
if (comWorld->primaryLightEnvs[oldPrimaryLightEnvIndex].numIndices == 1
&& comWorld->primaryLightEnvs[oldPrimaryLightEnvIndex].primaryLightIndices[0] >= 2048

auto comWorld_ptr = *comWorld;
if (comWorld_ptr->primaryLightEnvs[oldPrimaryLightEnvIndex].numIndices == 1
&& comWorld_ptr->primaryLightEnvs[oldPrimaryLightEnvIndex].primaryLightIndices[0] >= 2048
- (*s_world)->lastSunPrimaryLightIndex)
{
return true;
}
if (comWorld->primaryLightEnvs[newPrimaryLightEnvIndex].numIndices == 1
&& comWorld->primaryLightEnvs[newPrimaryLightEnvIndex].primaryLightIndices[0] >= 2048
if (comWorld_ptr->primaryLightEnvs[newPrimaryLightEnvIndex].numIndices == 1
&& comWorld_ptr->primaryLightEnvs[newPrimaryLightEnvIndex].primaryLightIndices[0] >= 2048
- (*s_world)->lastSunPrimaryLightIndex)
{
return false;
Expand Down Expand Up @@ -535,7 +537,7 @@ namespace map_patches

bool effect_callback = false;
auto address = _ReturnAddress();
if (address == (void*)0x6D6EE5_b)
if (address == (void*)SELECT_VALUE(0x5BF0B5_b, 0x6D6EE5_b))
{
effect_callback = true;
//return primaryLightIndex;
Expand Down Expand Up @@ -906,27 +908,25 @@ namespace map_patches
public:
void post_unpack() override
{
if (game::environment::is_sp())
{
return;
}

// skip fx name prefix checks
utils::hook::set<uint8_t>(0x2F377D_b, 0xEB); // createfx parse
utils::hook::set<uint8_t>(0x4444E0_b, 0xEB); // scr_loadfx
if (game::environment::is_mp())
{
utils::hook::set<uint8_t>(0x2F377D_b, 0xEB); // createfx parse
utils::hook::set<uint8_t>(0x4444E0_b, 0xEB); // scr_loadfx

// patch iw6 leafTable decoding
r_decode_light_grid_block_hook.create(0x69E7D0_b, r_decode_light_grid_block_stub);
// patch iw6 leafTable decoding
r_decode_light_grid_block_hook.create(0x69E7D0_b, r_decode_light_grid_block_stub);
}

r_lightGridNonCompressed = dvars::register_bool("r_lightGridNonCompressed", false, game::DVAR_FLAG_REPLICATED, "Use old lightgrid data, if available.");

r_lightgrid_lookup_hook.create(0x6D8120_b, r_lightgrid_lookup_stub);
r_lightgrid_lookup_hook.create(SELECT_VALUE(0x5C02F0_b, 0x6D8120_b), r_lightgrid_lookup_stub);

r_get_lightgrid_colors_from_indices_hook.create(0x6D66A0_b, r_get_lightgrid_colors_from_indices_stub);
r_get_lightgrid_colors_from_indices_hook.create(SELECT_VALUE(0x5BE870_b, 0x6D66A0_b), r_get_lightgrid_colors_from_indices_stub);

r_get_lightgrid_average_color_hook.create(0x6D65E0_b, r_get_lightgrid_average_color_stub);
r_get_lightgrid_average_color_hook.create(SELECT_VALUE(0x5BE7B0_b, 0x6D65E0_b), r_get_lightgrid_average_color_stub);

r_get_lighting_info_for_effects_hook.create(0x6D6D50_b, r_get_lighting_info_for_effects_stub);
r_get_lighting_info_for_effects_hook.create(SELECT_VALUE(0x5BEF20_b, 0x6D6D50_b), r_get_lighting_info_for_effects_stub);
}
};
}
Expand Down
6 changes: 5 additions & 1 deletion src/common/utils/nt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ namespace utils::nt
std::vector<PIMAGE_SECTION_HEADER> headers;

auto nt_headers = this->get_nt_headers();
if (!nt_headers)
{
return headers;
}

auto section = IMAGE_FIRST_SECTION(nt_headers);

for (uint16_t i = 0; i < nt_headers->FileHeader.NumberOfSections; ++i, ++section)
Expand Down Expand Up @@ -135,7 +140,6 @@ namespace utils::nt
return { name };
}


std::filesystem::path library::get_folder() const
{
if (!this->is_valid()) return {};
Expand Down
Loading