Skip to content

Commit

Permalink
Merge branch 'carbon' into w2c
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxHwoy committed Nov 11, 2023
2 parents 14629d4 + 2ad4669 commit d3b5702
Show file tree
Hide file tree
Showing 16 changed files with 321 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ nunit-*.xml
[Rr]eleasePS/
dlldata.c

# Version Files
version.hpp

# Benchmark Results
BenchmarkDotNet.Artifacts/

Expand Down
44 changes: 24 additions & 20 deletions src/hyperlib/assets/textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,43 @@ namespace hyper
switch (texture->blend_type)
{
case texture::alpha_blend_type::blend:
this->alpha_blend_src = D3DBLEND_SRCALPHA;
this->alpha_blend_dest = D3DBLEND_INVSRCALPHA;
this->alpha_blend_src = ::D3DBLEND_SRCALPHA;
this->alpha_blend_dest = ::D3DBLEND_INVSRCALPHA;
break;

case texture::alpha_blend_type::additive:
this->alpha_blend_src = D3DBLEND_SRCALPHA;
this->alpha_blend_dest = D3DBLEND_ONE;
this->alpha_blend_src = ::D3DBLEND_SRCALPHA;
this->alpha_blend_dest = ::D3DBLEND_ONE;
this->is_additive_blend = true;
this->colour_write_alpha = true;
break;

case texture::alpha_blend_type::subtractive:
this->alpha_blend_src = D3DBLEND_ZERO;
this->alpha_blend_dest = D3DBLEND_INVSRCCOLOR;
this->alpha_blend_src = ::D3DBLEND_ZERO;
this->alpha_blend_dest = ::D3DBLEND_INVSRCCOLOR;
break;

case texture::alpha_blend_type::overbright:
this->alpha_blend_src = D3DBLEND_SRCALPHA;
this->alpha_blend_dest = D3DBLEND_INVSRCALPHA;
this->alpha_blend_src = ::D3DBLEND_SRCALPHA;
this->alpha_blend_dest = ::D3DBLEND_INVSRCALPHA;
break;

case texture::alpha_blend_type::dest_blend:
this->alpha_blend_src = D3DBLEND_DESTALPHA;
this->alpha_blend_dest = D3DBLEND_INVDESTALPHA;
this->alpha_blend_src = ::D3DBLEND_DESTALPHA;
this->alpha_blend_dest = ::D3DBLEND_INVDESTALPHA;
break;

case texture::alpha_blend_type::dest_additive:
this->alpha_blend_src = D3DBLEND_DESTALPHA;
this->alpha_blend_dest = D3DBLEND_ONE;
this->alpha_blend_src = ::D3DBLEND_DESTALPHA;
this->alpha_blend_dest = ::D3DBLEND_ONE;
break;
}
}
else
{
this->z_write_enabled = true;
this->alpha_blend_src = D3DBLEND_ONE;
this->alpha_blend_dest = D3DBLEND_ZERO;
this->alpha_blend_src = ::D3DBLEND_ONE;
this->alpha_blend_dest = ::D3DBLEND_ZERO;

if (!this->alpha_test_enabled && (texture->flags & texture::bit_flags::disable_culling) != texture::bit_flags::disable_culling)
{
Expand All @@ -72,24 +72,28 @@ namespace hyper

if ((texture->tilable_uv & texture::tileable_type::u_mirror) == texture::tileable_type::u_mirror)
{
this->texture_address_u = D3DTADDRESS_MIRROR;
this->texture_address_u = ::D3DTADDRESS_MIRROR;
}
else
{
this->texture_address_u = (texture->tilable_uv & texture::tileable_type::u_repeat) == texture::tileable_type::u_repeat ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP;
this->texture_address_u = (texture->tilable_uv & texture::tileable_type::u_repeat) == texture::tileable_type::u_repeat
? ::D3DTADDRESS_WRAP
: ::D3DTADDRESS_CLAMP;
}

if ((texture->tilable_uv & texture::tileable_type::v_mirror) == texture::tileable_type::v_mirror)
{
this->texture_address_v = D3DTADDRESS_MIRROR;
this->texture_address_v = ::D3DTADDRESS_MIRROR;
}
else
{
this->texture_address_v = (texture->tilable_uv & texture::tileable_type::v_repeat) == texture::tileable_type::v_repeat ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP;
this->texture_address_v = (texture->tilable_uv & texture::tileable_type::v_repeat) == texture::tileable_type::v_repeat
? ::D3DTADDRESS_WRAP
: ::D3DTADDRESS_CLAMP;
}

this->bias_level = texture->bias_level & 3;
this->alpha_test_ref = 11u; // #TODO
this->alpha_test_ref = 11u; // #TODO ?

if (class_key == hashing::bin_const("Tree Leaves") || class_key == hashing::bin_const("Tree Cards") || class_key == hashing::bin_const("MultiPass Blend"))
{
Expand All @@ -99,7 +103,7 @@ namespace hyper

bool is_barrier = class_key == hashing::bin_const("Barrier Mask")
#if defined(CHECK_BARRIER_STRINGS)
|| ::strncmp(reinterpret_cast<const char*>(texture->name), "SFX_TRACKBARRIER", 16u)
|| !::strncmp(reinterpret_cast<const char*>(texture->name), "SFX_TRACKBARRIER", 16u)
#endif
;

Expand Down
2 changes: 1 addition & 1 deletion src/hyperlib/renderer/flare_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace hyper

void flare_pool::ctor(flare_pool* pool)
{
new (pool) flare_pool(0x80u); // by default, flare pool is initialized to 0x80 flares
new (pool) flare_pool(0x200u);
}

void flare_pool::dtor(flare_pool* pool)
Expand Down
24 changes: 24 additions & 0 deletions src/hyperlib/streamer/sections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ namespace hyper
}
}

void visible_section::manager::disable_all_groups()
{
::memset(this->enabled_groups, 0, sizeof(this->enabled_groups));
}

bool visible_section::manager::loader(chunk* block)
{
if (block->id() == block_id::visible_section_manager)
Expand Down Expand Up @@ -488,4 +493,23 @@ namespace hyper

return extra_width;
}

auto visible_section::manager::get_group_info(const char* group_name) -> const group_info*
{
size_t length = string::length(group_name);

for (size_t i = 0u; i < visible_section::manager::group_info_table.length(); ++i)
{
const group_info& info = visible_section::manager::group_info_table[i];

size_t namesz = string::length(info.selection_set_name);

if (namesz <= length && !::_strnicmp(info.selection_set_name, group_name, namesz))
{
return &info;
}
}

return nullptr;
}
}
6 changes: 6 additions & 0 deletions src/hyperlib/streamer/sections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ namespace hyper

void disable_group(std::uint32_t key);

void disable_all_groups();

bool loader(chunk* block);

bool unloader(chunk* block);
Expand All @@ -337,6 +339,8 @@ namespace hyper
public:
static auto get_distance_outside(const boundary* bound, const vector2& position, float extra_width) -> float;

static auto get_group_info(const char* group_name) -> const group_info*;

public:
linked_list<boundary> drivable_boundary_list;
linked_list<boundary> non_drivable_boundary_list;
Expand Down Expand Up @@ -370,6 +374,8 @@ namespace hyper
static inline std::uint32_t& current_zone_number = *reinterpret_cast<std::uint32_t*>(0x00A71C1C);

static inline geometry::model*& zone_boundary_model = *reinterpret_cast<geometry::model**>(0x00B69BE8);

static inline array<group_info, 5u> group_info_table = array<group_info, 5u>(0x00A72C30);
};
};

Expand Down
13 changes: 13 additions & 0 deletions src/hyperlib/streamer/track_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

namespace hyper
{
void track_path::manager::disable_all_barriers()
{
for (std::uint32_t i = 0u; i < this->barrier_count; ++i)
{
this->barriers[i].enabled = false;
}
}

void track_path::manager::enable_barriers(const char* barrier_name)
{
call_function<void(__thiscall*)(track_path::manager*, const char*)>(0x007A2390)(this, barrier_name);
}

auto track_path::manager::find_zone(const vector2* position, zone::type type, const zone* prev) -> zone*
{
if (position == nullptr)
Expand Down
4 changes: 4 additions & 0 deletions src/hyperlib/streamer/track_path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ namespace hyper
struct manager
{
public:
void disable_all_barriers();

void enable_barriers(const char* barrier_name);

auto find_zone(const vector2* position, zone::type type, const zone* prev) -> zone*;

public:
Expand Down
1 change: 0 additions & 1 deletion src/hyperlib/version.hpp

This file was deleted.

52 changes: 52 additions & 0 deletions src/hyperlib/world/world.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <hyperlib/assets/scenery.hpp>
#include <hyperlib/streamer/sections.hpp>
#include <hyperlib/streamer/track_path.hpp>
#include <hyperlib/world/world.hpp>

namespace hyper
Expand All @@ -19,4 +22,53 @@ namespace hyper
{
call_function<void(__cdecl*)()>(0x007AF8F0)();
}

void world::enable_barrier_scenery_group(const char* name, bool flip_artwork)
{
if (visible_section::manager::get_group_info(name) != nullptr)
{
std::uint32_t key = hashing::bin(name);

visible_section::manager::instance.enable_group(key);

scenery::group::enable(key, flip_artwork);

track_path::manager::instance.enable_barriers(name);
}
}

void world::disable_all_scenery_groups()
{
for (const scenery::group* i = scenery::group::list.begin(); i != scenery::group::list.end(); i = i->next())
{
if (scenery::group::enabled_table[i->group_number])
{
i->disable_rendering();

scenery::group::enabled_table[i->group_number] = 0;
}
}
}

void world::init_topology_and_scenery_groups()
{
for (const char* group : world::permanent_scenery_groups)
{
if (scenery::group::find(hashing::bin(group)) != nullptr)
{
world::enable_barrier_scenery_group(group, false);
}
}
}

void world::redo_topology_and_scenery_groups()
{
track_path::manager::instance.disable_all_barriers();

visible_section::manager::instance.disable_all_groups();

world::disable_all_scenery_groups();

world::init_topology_and_scenery_groups();
}
}
16 changes: 16 additions & 0 deletions src/hyperlib/world/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,21 @@ namespace hyper
static void init_visible_zones(geometry::model*& boundary_model);

static void notify_sky_loader();

static void enable_barrier_scenery_group(const char* name, bool flip_artwork);

static void disable_all_scenery_groups();

static void init_topology_and_scenery_groups();

static void redo_topology_and_scenery_groups();

private:
static inline const char* permanent_scenery_groups[] =
{
"SCENERY_GROUP_DOOR",
"SCENERY_GROUP_CHRISTMAS",
"SCENERY_GROUP_HALLOWEEN_DISABLE",
};
};
}
6 changes: 4 additions & 2 deletions src/hyperlinked/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#pragma warning (disable : 6031)

#undef CONSOLEON
#undef RUN_TESTS
#if defined(_DEBUG) && !defined(ABOMINATOR)
#define CONSOLEON
#define RUN_TESTS
#endif

#if defined(RUN_TESTS)
#include <hyperlinked/tests.hpp>
Expand Down
4 changes: 4 additions & 0 deletions src/hyperlinked/patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <hyperlinked/patches/assets/loader.hpp>
#include <hyperlinked/patches/assets/scenery.hpp>
#include <hyperlinked/patches/assets/textures.hpp>
#include <hyperlinked/patches/assets/world_anim.hpp>

#include <hyperlinked/patches/renderer/camera.hpp>
Expand All @@ -21,6 +22,7 @@
#include <hyperlinked/patches/streamer/streamer.hpp>

#include <hyperlinked/patches/world/collision.hpp>
#include <hyperlinked/patches/world/world.hpp>

namespace hyper
{
Expand All @@ -32,6 +34,7 @@ namespace hyper

loader_patches::init();
scenery_patches::init();
texture_patches::init();
world_anim_patches::init();

// camera_patches::init();
Expand All @@ -47,5 +50,6 @@ namespace hyper
streamer_patches::init();

collision_patches::init();
world_patches::init();
}
}
46 changes: 46 additions & 0 deletions src/hyperlinked/patches/assets/textures.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <hyperlib/assets/textures.hpp>
#include <hyperlinked/patches/assets/textures.hpp>

namespace hyper
{
__declspec(naked) void detour_render_state_init()
{
__asm
{
// [esp + 0x00] is 'return address'
// [esp + 0x04] is 'texture'
// ecx contains pointer to texture::render_state

// esp is auto-managed, non-incremental
// ebp is auto-managed, restored on function return

push eax; // 'texture' is now at [esp + 0x08]
push ebx; // 'texture' is now at [esp + 0x0C]
push ecx; // 'texture' is now at [esp + 0x10]
push edx; // 'texture' is now at [esp + 0x14]
push esi; // 'texture' is now at [esp + 0x18]
push edi; // 'texture' is now at [esp + 0x1C]

push [esp + 0x1C]; // repush 'texture'

call texture::render_state::initialize; // call custom initialize

// no need to restore esp since 'initialize' is a __thiscall

pop edi; // restore saved register
pop esi; // restore saved register
pop edx; // restore saved register
pop ecx; // restore saved register
pop ebx; // restore saved register
pop eax; // restore saved register

retn 4; // return immediately to caller function, not back to RenderState::Init; note that this is a __thiscall
}
}

void texture_patches::init()
{
// RenderState::Init
hook::jump(0x0073B9E0, &detour_render_state_init);
}
}
Loading

0 comments on commit d3b5702

Please sign in to comment.