path = "tests/test_core.cpp"
with open(path, "r", encoding="utf-8") as f:
    c = f.read()

target = '''    std::cout << "  -> Visual Tool Code Patching (.text bypass & clean restore) OK" << std::endl;
}'''

repl = '''    // 4. Kiểm chứng Fallback to Heap Mode khi Code Patch không tìm thấy hoặc bị từ chối
    VisualModsEngine visualFallback(sim);
    visualFallback.SetCameraAddress(sim.CameraAddress());
    visualFallback.SetZoomClampAddress(0); // Không có địa chỉ clamp hợp lệ
    CHECK(visualFallback.ApplyZoomCodePatch(8.0f), "ApplyZoomCodePatch phai fallback sang Heap Mode thanh cong");
    CHECK(!visualFallback.IsCodePatchActive(), "Code patch phai giu false khi khong co clamp hop le");
    CHECK(visualFallback.IsZoomActive(), "Zoom tren Heap van phai ACTIVE de nguoi choi khong bi gian doan");
    float heapMaxDist = 0.0f;
    CHECK(sim.ReadValue<float>(sim.CameraAddress() + 0x34, heapMaxDist), "doc maxDistance tren heap");
    CHECK(std::fabs(heapMaxDist - 360.0f) < 0.01f, "Heap maxDistance van duoc no troi len 8x = 360");

    std::cout << "  -> Visual Tool Code Patching (.text bypass, clean restore & heap fallback) OK" << std::endl;
}'''

if target in c:
    c = c.replace(target, repl, 1)
    with open(path, "w", encoding="utf-8") as f:
        f.write(c)
    print("Successfully added Fallback testcase to TestVisualToolCodePatching.")
else:
    print("Target not found in test_core.cpp")
