Skip to content

Commit 6bafb3b

Browse files
committed
Merge branch 'main' into carbon
2 parents 6ede831 + 44b5185 commit 6bafb3b

9 files changed

Lines changed: 147 additions & 0 deletions

File tree

src/hyperlib/streamer/sections.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ namespace hyper
306306
}
307307
}
308308

309+
void visible_section::manager::disable_all_groups()
310+
{
311+
::memset(this->enabled_groups, 0, sizeof(this->enabled_groups));
312+
}
313+
309314
bool visible_section::manager::loader(chunk* block)
310315
{
311316
if (block->id() == block_id::visible_section_manager)
@@ -488,4 +493,21 @@ namespace hyper
488493

489494
return extra_width;
490495
}
496+
497+
auto visible_section::manager::get_group_info(const char* group_name) -> const group_info*
498+
{
499+
size_t length = string::length(group_name);
500+
501+
for (size_t i = 0u; i < visible_section::manager::group_info_table.length(); ++i)
502+
{
503+
const group_info& info = visible_section::manager::group_info_table[i];
504+
505+
if (string::length(info.selection_set_name) == length && !::_strnicmp(info.selection_set_name, group_name, length))
506+
{
507+
return &info;
508+
}
509+
}
510+
511+
return nullptr;
512+
}
491513
}

src/hyperlib/streamer/sections.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ namespace hyper
325325

326326
void disable_group(std::uint32_t key);
327327

328+
void disable_all_groups();
329+
328330
bool loader(chunk* block);
329331

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

342+
static auto get_group_info(const char* group_name) -> const group_info*;
343+
340344
public:
341345
linked_list<boundary> drivable_boundary_list;
342346
linked_list<boundary> non_drivable_boundary_list;
@@ -370,6 +374,8 @@ namespace hyper
370374
static inline std::uint32_t& current_zone_number = *reinterpret_cast<std::uint32_t*>(0x00A71C1C);
371375

372376
static inline geometry::model*& zone_boundary_model = *reinterpret_cast<geometry::model**>(0x00B69BE8);
377+
378+
static inline array<group_info, 5u> group_info_table = array<group_info, 5u>(0x00A72C30);
373379
};
374380
};
375381

src/hyperlib/streamer/track_path.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
namespace hyper
44
{
5+
void track_path::manager::disable_all_barriers()
6+
{
7+
for (std::uint32_t i = 0u; i < this->barrier_count; ++i)
8+
{
9+
this->barriers[i].enabled = false;
10+
}
11+
}
12+
13+
void track_path::manager::enable_barriers(const char* barrier_name)
14+
{
15+
call_function<void(__thiscall*)(track_path::manager*, const char*)>(0x007A2390)(this, barrier_name);
16+
}
17+
518
auto track_path::manager::find_zone(const vector2* position, zone::type type, const zone* prev) -> zone*
619
{
720
if (position == nullptr)

src/hyperlib/streamer/track_path.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ namespace hyper
7676
struct manager
7777
{
7878
public:
79+
void disable_all_barriers();
80+
81+
void enable_barriers(const char* barrier_name);
82+
7983
auto find_zone(const vector2* position, zone::type type, const zone* prev) -> zone*;
8084

8185
public:

src/hyperlib/world/world.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#include <hyperlib/assets/scenery.hpp>
2+
#include <hyperlib/streamer/sections.hpp>
3+
#include <hyperlib/streamer/track_path.hpp>
14
#include <hyperlib/world/world.hpp>
25

36
namespace hyper
@@ -19,4 +22,45 @@ namespace hyper
1922
{
2023
call_function<void(__cdecl*)()>(0x007AF8F0)();
2124
}
25+
26+
void world::enable_barrier_scenery_group(const char* name, bool flip_artwork)
27+
{
28+
if (visible_section::manager::get_group_info(name) != nullptr)
29+
{
30+
std::uint32_t key = hashing::bin(name);
31+
32+
visible_section::manager::instance.enable_group(key);
33+
34+
scenery::group::enable(key, flip_artwork);
35+
36+
track_path::manager::instance.enable_barriers(name);
37+
}
38+
}
39+
40+
void world::disable_all_scenery_groups()
41+
{
42+
for (const scenery::group* i = scenery::group::list.begin(); i != scenery::group::list.end(); i = i->next())
43+
{
44+
if (scenery::group::enabled_table[i->group_number])
45+
{
46+
i->disable_rendering();
47+
48+
scenery::group::enabled_table[i->group_number] = 0;
49+
}
50+
}
51+
}
52+
53+
void world::redo_topology_and_scenery_groups()
54+
{
55+
track_path::manager::instance.disable_all_barriers();
56+
57+
visible_section::manager::instance.disable_all_groups();
58+
59+
world::disable_all_scenery_groups();
60+
61+
if (scenery::group::find(hashing::bin_const("SCENERY_GROUP_DOOR")) != nullptr)
62+
{
63+
world::enable_barrier_scenery_group("SCENERY_GROUP_DOOR", false);
64+
}
65+
}
2266
}

src/hyperlib/world/world.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@ namespace hyper
1313
static void init_visible_zones(geometry::model*& boundary_model);
1414

1515
static void notify_sky_loader();
16+
17+
static void enable_barrier_scenery_group(const char* name, bool flip_artwork);
18+
19+
static void disable_all_scenery_groups();
20+
21+
static void redo_topology_and_scenery_groups();
1622
};
1723
}

src/hyperlinked/patches.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <hyperlinked/patches/streamer/streamer.hpp>
2323

2424
#include <hyperlinked/patches/world/collision.hpp>
25+
#include <hyperlinked/patches/world/world.hpp>
2526

2627
namespace hyper
2728
{
@@ -49,5 +50,6 @@ namespace hyper
4950
streamer_patches::init();
5051

5152
collision_patches::init();
53+
world_patches::init();
5254
}
5355
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <hyperlib/world/world.hpp>
2+
#include <hyperlinked/patches/world/world.hpp>
3+
4+
namespace hyper
5+
{
6+
__declspec(naked) void detour_redo_topology_and_scenery_groups()
7+
{
8+
__asm
9+
{
10+
// [esp + 0x00] is 'return address'
11+
12+
// esp is auto-managed, non-incremental
13+
// ebp is auto-managed, restored on function return
14+
15+
push eax; // 'return address' is now at [esp + 0x04]
16+
push ebx; // 'return address' is now at [esp + 0x08]
17+
push ecx; // 'return address' is now at [esp + 0x0C]
18+
push edx; // 'return address' is now at [esp + 0x10]
19+
push esi; // 'return address' is now at [esp + 0x14]
20+
push edi; // 'return address' is now at [esp + 0x18]
21+
22+
call world::redo_topology_and_scenery_groups; // call custom redo_topology_and_scenery_groups
23+
24+
pop edi; // restore saved register
25+
pop esi; // restore saved register
26+
pop edx; // restore saved register
27+
pop ecx; // restore saved register
28+
pop ebx; // restore saved register
29+
pop eax; // restore saved register
30+
31+
retn; // return immediately to caller function, not back to RedoTopologyAndSceneryGroups
32+
}
33+
}
34+
35+
void world_patches::init()
36+
{
37+
// RedoTopologyAndSceneryGroups
38+
hook::jump(0x006A8AD0, &detour_redo_topology_and_scenery_groups);
39+
}
40+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
namespace hyper
4+
{
5+
class world_patches final
6+
{
7+
public:
8+
static void init();
9+
};
10+
}

0 commit comments

Comments
 (0)