Skip to content

Commit

Permalink
fix radar issue, fix fs not mount
Browse files Browse the repository at this point in the history
  • Loading branch information
GEEKiDoS committed Dec 20, 2024
1 parent 8eb5a51 commit bc6a195
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 41 deletions.
18 changes: 13 additions & 5 deletions src/client/component/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ namespace filesystem
file::file(std::string name)
: name_(std::move(name))
{
auto file = avs2::fs_open(name_.data(), 1, 420);

avs2::stat stat = { 0 };
avs2::fs_lstat(name.data(), &stat);

if (stat.filesize <= 0)
{
this->valid_ = false;
return;
}

auto file = avs2::fs_open(name_.data(), 1, 420);
avs2::fs_fstat(file, &stat);

if (stat.filesize <= 0)
{
this->valid_ = false;
avs2::fs_close(file);
return;
}
Expand All @@ -33,7 +41,7 @@ namespace filesystem
auto _ = gsl::finally([=] {
utils::memory::free(buffer);
avs2::fs_close(file);
});
});

if (size >= 0)
{
Expand Down Expand Up @@ -82,7 +90,7 @@ namespace filesystem
if (g == launcher::game::iidx)
data_dir /= "iidx";
else if (g == launcher::game::sdvx)
data_dir /= "iidx";
data_dir /= "sdvx";
else if (g == launcher::game::gitadora)
data_dir /= "gitadora";

Expand All @@ -92,7 +100,7 @@ namespace filesystem
printf("warning: data dir %s not exists\n", abs_data_path.data());

if (!utils::flags::has_flag("disable_ifs_hook"))
init(std::filesystem::exists(data_dir) ? nullptr : abs_data_path.data());
init(std::filesystem::exists(data_dir) ? abs_data_path.data() : nullptr);

avs2::fs_mount("/laochan", abs_data_path.data(), "fs", const_cast<char*>("vf=1,posix=1"));
}
Expand Down
1 change: 0 additions & 1 deletion src/client/component/iidx/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ namespace iidx::analyze
}

results[i] = ((radar[i] - last_threshold) / (threshold - last_threshold)) * radar_thresholds[preset][j][6] + radar_thresholds[preset][j][7];
results[i] *= 2.f;
break;
}
}
Expand Down
43 changes: 27 additions & 16 deletions src/client/component/iidx/omnimix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@ namespace iidx::omnimix
csd_t* csd_load_hook(csd_t* result, const char* name)
{
result->pad = 0;
result->id = 0;

int folder;
sscanf_s(name, "%d/%d.%*s", &folder, &result->id);
snprintf(result->path, 256, "/ac_mount/sound/%s", name);

if (!filesystem::exists(result->path))
{
snprintf(result->path, 256, "/data/sound/%s", name);
}
if (filesystem::exists(result->path))
return result;

if (!filesystem::exists(result->path))
{
printf("libutil: CSDLoad::CSDLoad sound file not found: %s\n", name);
}
snprintf(result->path, 256, "/data/sound/%s", name);

int folder;
sscanf_s(name, "%d/%d.%*s", &folder, &result->id);
if (filesystem::exists(result->path))
return result;

result->id = 0;

printf("libutil: CSDLoad::CSDLoad sound file not found: %s\n", name);
return result;
}

Expand Down Expand Up @@ -170,17 +170,28 @@ namespace iidx::omnimix
{
auto& music = music_data->musics[i];

if (music.song_id / 1000 == 80)
bool had_data = false;
for (size_t j = 0; j < 10; j++)
{
if (music.note_count[j])
{
had_data = true;
break;
}
}

if (had_data)
continue;

csd_t csd;
csd_load(&csd, utils::string::va("%d/%d.1", music.song_id, music.song_id));
auto id = music.song_id;

filesystem::file chart_file{ csd.path };
csd_t csd;
csd_load(&csd, utils::string::va("%d/%d.1", id, id));

if (!chart_file.exists())
if (!csd.id)
continue;

filesystem::file chart_file{ csd.path };
auto& data = chart_file.get_buffer();

for (int j = 0; j < 10; j++)
Expand Down
41 changes: 22 additions & 19 deletions src/client/component/iidx/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,17 @@ namespace iidx::overlay
if (iter != analyze_datas.end())
return &iter->second[diff];

std::string target = utils::string::va("/data/sound/%d/%d.1", id, id);
csd_t csd;
csd_load(&csd, utils::string::va("%d/%d.1", id, id));

// mount downloaded data before analyze
auto require_mount = id / 1000 == 80 && !filesystem::exists(target.data());
auto require_mount = !csd.id;
if (require_mount)
{
std::string ifs = utils::string::va("/data/sound/%d.ifs", id);
std::string ifs = utils::string::va("/ac_mount/sound/%d.ifs", id);

if (!filesystem::exists(ifs))
ifs = utils::string::va("/ac_mount/sound/%d.ifs", id);
ifs = utils::string::va("/data/sound/%d.ifs", id);

if (!filesystem::exists(ifs))
ifs = utils::string::va("/dl_fs3/sound/%d.ifs", id);
Expand All @@ -150,41 +151,43 @@ namespace iidx::overlay
avs2::fs_mount(utils::string::va("/data/sound/%d", id), ifs.data(), "imagefs", nullptr);
}

csd_t csd;
csd_load(&csd, utils::string::va("%d/%d.1", id, id));
if (!csd.id)
return nullptr;

filesystem::file chart_file{ csd.path };

if (!chart_file.exists())
return nullptr;

auto& data = chart_file.get_buffer();
std::vector<analyze::chart_analyze_data_t> datas;

for (int i = 0; i < 10; i++)
{
auto offset = *reinterpret_cast<const uint32_t*>(data.data() + i * 8);
auto size = *reinterpret_cast<const uint32_t*>(data.data() + i * 8 + 4);

if (!offset || !size) continue;
{
auto m = analyze::map_chart(i);

std::vector<event_t> events;
events.resize(size / sizeof(event_t));
std::memcpy(events.data(), data.data() + offset, size);
auto offset = *reinterpret_cast<const uint32_t*>(data.data() + m * 8);
auto size = *reinterpret_cast<const uint32_t*>(data.data() + m * 8 + 4);

analyze::chart_analyze_data_t analyze_data;
analyze::analyze_chart(events, analyze_data, true);
memset(&analyze_data, 0, sizeof(analyze::chart_analyze_data_t));

if (offset && size)
{
std::vector<event_t> events;
events.resize(size / sizeof(event_t));
std::memcpy(events.data(), data.data() + offset, size);

analyze::analyze_chart(events, analyze_data, true);
}

datas.push_back(analyze_data);
}

analyze_datas.emplace(id, datas);

if (require_mount)
{
avs2::fs_umount(utils::string::va("/data/sound/%d", id));
}

analyze_datas.emplace(id, datas);
return &analyze_datas[id][diff];
}

Expand Down

0 comments on commit bc6a195

Please sign in to comment.