Skip to content
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
26 changes: 16 additions & 10 deletions src/environment_enhancements/ComponentInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "UnityEngine/Material.hpp"

#include "System/Collections/Generic/List_1.hpp"
#include "System/Array.hpp"

#include "Zenject/DiContainer.hpp"

Expand All @@ -48,6 +49,8 @@

#include "sombrero/shared/linq_functional.hpp"

#include "beatsaber-hook/shared/utils/il2cpp-utils-boxing.hpp"

using namespace GlobalNamespace;
using namespace Chroma;
using namespace Sombrero::Linq::Functional;
Expand Down Expand Up @@ -76,12 +79,13 @@ GameObjectInfo const& Chroma::ComponentInitializer::InitializeComponents(UnityEn

if (auto lightsWithIds = il2cpp_utils::try_cast<LightWithIds>(rootComp)) {
if (lightsWithIds.value()->lightWithIds) {
auto* enumerator = lightsWithIds.value()->lightWithIds->GetEnumerator();
while (enumerator->i___System__Collections__IEnumerator()->MoveNext()) {
auto* light = enumerator->get_Current();
LightIdRegisterer::MarkForTableRegister(light->i___GlobalNamespace__ILightWithId());
auto enumerator = il2cpp_utils::Unbox<System::Array::InternalEnumerator_1<ILightWithId*>>(
reinterpret_cast<Il2CppObject*>(lightsWithIds.value()->lightWithIds->GetEnumerator()));
while (enumerator.MoveNext()) {
auto* light = enumerator.get_Current();
LightIdRegisterer::MarkForTableRegister(light);
}
enumerator->i___System__IDisposable()->Dispose();
enumerator.Dispose();
}
}

Expand Down Expand Up @@ -357,18 +361,20 @@ static void InitializeLights(rapidjson::Value const& data, std::span<UnityEngine
continue;
}

auto* enumerator = castedLights.value()->lightWithIds->GetEnumerator();
// TODO: Casting and method calling safety
auto enumerator = il2cpp_utils::Unbox<System::Array::InternalEnumerator_1<ILightWithId*>>(
reinterpret_cast<Il2CppObject*>(castedLights.value()->lightWithIds->GetEnumerator()));

// MEMORY LEAK YAY
// TODO: Fix
// auto dispose = bs_hook::Disposable(enumerator->i_IDisposable());

while (enumerator->i___System__Collections__IEnumerator()->MoveNext()) {
auto* e = enumerator->get_Current();
lightWithIds.emplace_back(e->i___GlobalNamespace__ILightWithId());
while (enumerator.MoveNext()) {
auto* e = enumerator.get_Current();
lightWithIds.emplace_back(e);
}

enumerator->i___System__IDisposable()->Dispose();
enumerator.Dispose();
} else if (auto castedMonoLight = il2cpp_utils::try_cast<LightWithIdMonoBehaviour>(comp)) {
lightWithIds.emplace_back(castedMonoLight.value()->i___GlobalNamespace__ILightWithId());
}
Expand Down
2 changes: 1 addition & 1 deletion src/environment_enhancements/MaterialsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ MaterialInfo Chroma::MaterialsManager::CreateMaterialInfo(rapidjson::Value const

// stupid janky fix to the fact that they changed simplelit shader in 1.38

if (shaderType == ShaderType::Standard || shaderType == ShaderType::BTSPillar && (!shaderKeywords || shaderKeywords.size() == 0)) {
if ((shaderType == ShaderType::Standard || shaderType == ShaderType::BTSPillar) && (shaderKeywords && shaderKeywords.size() == 0)) {

shaderKeywords = ArrayW<StringW>(nullptr);

Expand Down
25 changes: 2 additions & 23 deletions src/hooks/colorizer/LightSwitchEventEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@

#include "colorizer/LightColorizer.hpp"

#include <vector>
#include <optional>
#include "custom-json-data/shared/CustomBeatmapData.h"
#include "System/Collections/IEnumerator.hpp"
#include "custom-types/shared/coroutine.hpp"
#include "UnityEngine/Color.hpp"
#include "UnityEngine/WaitForEndOfFrame.hpp"
#include "GlobalNamespace/ILightWithId.hpp"
#include "GlobalNamespace/BeatmapCallbacksController.hpp"
#include "GlobalNamespace/CallbacksInTime.hpp"
#include "System/Collections/Generic/Dictionary_2.hpp"
#include "UnityEngine/GameObject.hpp"
#include "hooks/LightSwitchEventEffect.hpp"
#include "lighting/LightIDTableManager.hpp"

using namespace CustomJSONData;
using namespace Chroma;
Expand All @@ -27,17 +18,6 @@ using namespace custom_types::Helpers;

BeatmapCallbacksController* beatmapCallbacksController;

custom_types::Helpers::Coroutine WaitThenStartLight(LightSwitchEventEffect* instance, BasicBeatmapEventType eventType) {
co_yield reinterpret_cast<IEnumerator*>(CRASH_UNLESS(WaitForEndOfFrame::New_ctor()));

auto* newEffect = instance->get_gameObject()->AddComponent<ChromaLightSwitchEventEffect*>();
newEffect->CopyValues(instance);

IL2CPP_CATCH_HANDLER(Object::Destroy(instance);)

co_return;
}

MAKE_HOOK_MATCH(LightSwitchEventEffect_Start, &LightSwitchEventEffect::Start, void, LightSwitchEventEffect* self) {
static auto* ChromaLightSwitchEventEffectKlass = classof(ChromaLightSwitchEventEffect*);

Expand All @@ -51,9 +31,8 @@ MAKE_HOOK_MATCH(LightSwitchEventEffect_Start, &LightSwitchEventEffect::Start, vo
return;
}

auto coro = custom_types::Helpers::CoroutineHelper::New(WaitThenStartLight(self, self->_event));

self->StartCoroutine(coro);
auto* newEffect = self->get_gameObject()->AddComponent<ChromaLightSwitchEventEffect*>();
newEffect->CopyValues(self);
}

MAKE_HOOK_MATCH(BeatmapCallbacksController_ManualUpdate, &BeatmapCallbacksController::ManualUpdate, void,
Expand Down
Loading