Skip to content

Commit b85d7c4

Browse files
committed
CRoom fixes for 2024.6
- Fixes CRoom misalignment for 2024.6+ runners - Bumps version to 3.4.3
1 parent ebdccf4 commit b85d7c4

File tree

5 files changed

+123
-27
lines changed

5 files changed

+123
-27
lines changed

ExamplePlugin/include/YYToolkit/Shared.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,33 @@ RValue* YYObjectBase::FindOrAllocValue(
493493

494494
return &this->InternalGetYYVarRef(variable_hash);
495495
}
496+
497+
CRoomInternal& YYTK::CRoom::GetMembers()
498+
{
499+
YYTKInterface* module_interface = GetYYTKInterface();
500+
501+
// Return the more likely thing.
502+
if (!module_interface)
503+
return this->WithBackgrounds.Internals;
504+
505+
size_t bg_color_idx = 0;
506+
AurieStatus last_status = module_interface->GetBuiltinVariableIndex(
507+
"background_color",
508+
bg_color_idx
509+
);
510+
511+
// This lookup will fail in newer runners where backgrounds were removed
512+
if (!AurieSuccess(last_status))
513+
{
514+
// Note: We have to craft the pointer manually here, since
515+
// bool alignment prevents us from just having a struct (it'd get aligned to sizeof(PVOID)).
516+
517+
// Don't ask why it's from m_Color and not from m_ShowColor, it doesn't make sense
518+
// and I can't figure out why it works - it just does.
519+
return *reinterpret_cast<CRoomInternal*>(&this->m_Color);
520+
}
521+
522+
return this->WithBackgrounds.Internals;
523+
}
524+
496525
#endif // YYTK_DEFINE_INTERNAL

ExamplePlugin/include/YYToolkit/Shared.hpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#define YYTK_MAJOR 3
1111
#define YYTK_MINOR 4
12-
#define YYTK_PATCH 0
12+
#define YYTK_PATCH 3
1313

1414
#ifndef YYTK_CPP_VERSION
1515
#ifndef _MSVC_LANG
@@ -2251,19 +2251,9 @@ namespace YYTK
22512251
static_assert(sizeof(CArrayStructure<int>) == 0x10);
22522252
#endif // _WIN64
22532253

2254-
// Seems to be mostly stable, some elements at the end are however omitted
2255-
struct CRoom
2254+
struct CRoomInternal
22562255
{
2257-
int32_t m_LastTile;
2258-
CRoom* m_InstanceHandle;
2259-
const char* m_Caption;
2260-
int32_t m_Speed;
2261-
int32_t m_Width;
2262-
int32_t m_Height;
2263-
bool m_Persistent;
2264-
uint32_t m_Color;
2265-
bool m_ShowColor;
2266-
CBackGM* m_Backgrounds[8];
2256+
// CBackGM* m_Backgrounds[8];
22672257
bool m_EnableViews;
22682258
bool m_ClearScreen;
22692259
bool m_ClearDisplayBuffer;
@@ -2301,6 +2291,35 @@ namespace YYTK
23012291
int32_t m_EffectLayerIdCount;
23022292
int32_t m_EffectLayerIdMax;
23032293
};
2294+
2295+
// Seems to be mostly stable, some elements at the end are however omitted
2296+
struct CRoom
2297+
{
2298+
int32_t m_LastTile;
2299+
CRoom* m_InstanceHandle;
2300+
const char* m_Caption;
2301+
int32_t m_Speed;
2302+
int32_t m_Width;
2303+
int32_t m_Height;
2304+
bool m_Persistent;
2305+
uint32_t m_Color;
2306+
bool m_ShowColor;
2307+
private:
2308+
2309+
// Last confirmed use in 2023.8, might be later even
2310+
struct
2311+
{
2312+
CBackGM* Backgrounds[8];
2313+
CRoomInternal Internals;
2314+
} WithBackgrounds;
2315+
2316+
// 2024.6 (first confirmed use) has Backgrounds removed.
2317+
// CRoomInternal cannot be properly aligned (due to bool having 1-byte alignment),
2318+
// so GetMembers() crafts the pointer manually instead of having a defined struct here.
2319+
2320+
public:
2321+
CRoomInternal& GetMembers();
2322+
};
23042323
#ifdef _WIN64
23052324
static_assert(sizeof(CRoom) == 0x218);
23062325
#endif // _WIN64

YYToolkit/source/YYTK/Module Interface/Interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ namespace YYTK
16461646

16471647
// Loop all active instances in the room
16481648
for (
1649-
CInstance* inst = current_room->m_ActiveInstances.m_First;
1649+
CInstance* inst = current_room->GetMembers().m_ActiveInstances.m_First;
16501650
inst != nullptr;
16511651
inst = inst->GetMembers().m_Flink
16521652
)

YYToolkit/source/YYTK/Shared.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,33 @@ RValue* YYObjectBase::FindOrAllocValue(
493493

494494
return &this->InternalGetYYVarRef(variable_hash);
495495
}
496+
497+
CRoomInternal& YYTK::CRoom::GetMembers()
498+
{
499+
YYTKInterface* module_interface = GetYYTKInterface();
500+
501+
// Return the more likely thing.
502+
if (!module_interface)
503+
return this->WithBackgrounds.Internals;
504+
505+
size_t bg_color_idx = 0;
506+
AurieStatus last_status = module_interface->GetBuiltinVariableIndex(
507+
"background_color",
508+
bg_color_idx
509+
);
510+
511+
// This lookup will fail in newer runners where backgrounds were removed
512+
if (!AurieSuccess(last_status))
513+
{
514+
// Note: We have to craft the pointer manually here, since
515+
// bool alignment prevents us from just having a struct (it'd get aligned to sizeof(PVOID)).
516+
517+
// Don't ask why it's from m_Color and not from m_ShowColor, it doesn't make sense
518+
// and I can't figure out why it works - it just does.
519+
return *reinterpret_cast<CRoomInternal*>(&this->m_Color);
520+
}
521+
522+
return this->WithBackgrounds.Internals;
523+
}
524+
496525
#endif // YYTK_DEFINE_INTERNAL

YYToolkit/source/YYTK/Shared.hpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#define YYTK_MAJOR 3
1111
#define YYTK_MINOR 4
12-
#define YYTK_PATCH 2
12+
#define YYTK_PATCH 3
1313

1414
#ifndef YYTK_CPP_VERSION
1515
#ifndef _MSVC_LANG
@@ -2251,19 +2251,9 @@ namespace YYTK
22512251
static_assert(sizeof(CArrayStructure<int>) == 0x10);
22522252
#endif // _WIN64
22532253

2254-
// Seems to be mostly stable, some elements at the end are however omitted
2255-
struct CRoom
2254+
struct CRoomInternal
22562255
{
2257-
int32_t m_LastTile;
2258-
CRoom* m_InstanceHandle;
2259-
const char* m_Caption;
2260-
int32_t m_Speed;
2261-
int32_t m_Width;
2262-
int32_t m_Height;
2263-
bool m_Persistent;
2264-
uint32_t m_Color;
2265-
bool m_ShowColor;
2266-
CBackGM* m_Backgrounds[8];
2256+
// CBackGM* m_Backgrounds[8];
22672257
bool m_EnableViews;
22682258
bool m_ClearScreen;
22692259
bool m_ClearDisplayBuffer;
@@ -2301,6 +2291,35 @@ namespace YYTK
23012291
int32_t m_EffectLayerIdCount;
23022292
int32_t m_EffectLayerIdMax;
23032293
};
2294+
2295+
// Seems to be mostly stable, some elements at the end are however omitted
2296+
struct CRoom
2297+
{
2298+
int32_t m_LastTile;
2299+
CRoom* m_InstanceHandle;
2300+
const char* m_Caption;
2301+
int32_t m_Speed;
2302+
int32_t m_Width;
2303+
int32_t m_Height;
2304+
bool m_Persistent;
2305+
uint32_t m_Color;
2306+
bool m_ShowColor;
2307+
private:
2308+
2309+
// Last confirmed use in 2023.8, might be later even
2310+
struct
2311+
{
2312+
CBackGM* Backgrounds[8];
2313+
CRoomInternal Internals;
2314+
} WithBackgrounds;
2315+
2316+
// 2024.6 (first confirmed use) has Backgrounds removed.
2317+
// CRoomInternal cannot be properly aligned (due to bool having 1-byte alignment),
2318+
// so GetMembers() crafts the pointer manually instead of having a defined struct here.
2319+
2320+
public:
2321+
CRoomInternal& GetMembers();
2322+
};
23042323
#ifdef _WIN64
23052324
static_assert(sizeof(CRoom) == 0x218);
23062325
#endif // _WIN64

0 commit comments

Comments
 (0)