Skip to content

Commit

Permalink
Merge pull request #184 from akemimadoka/fix-multiple-clip
Browse files Browse the repository at this point in the history
支持读取具有多个 Clip 的 TextBlock
  • Loading branch information
chinosk6 authored Apr 28, 2024
2 parents eaa72d1 + eb20c28 commit ba46680
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ on:
- 'utils/**'
jobs:
build:
runs-on: windows-2019
runs-on: windows-2022

steps:
- name: checkout
Expand Down
4 changes: 2 additions & 2 deletions generate.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
conan install . -if build -s build_type=Release --build missing
utils\bin\premake5 %* vs2019
conan install . -if build -s build_type=Release -s compiler.version=16 --build missing
utils\bin\premake5 %* vs2022
17 changes: 9 additions & 8 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,13 +1214,14 @@ namespace
}

const auto clipList = il2cpp_symbols::read_field(textTrack, StoryTimelineTrackDataClass_ClipListField);
il2cpp_symbols::iterate_list(clipList, [&](int32_t dummy, void* clipData) {
assert(dummy == 0);
il2cpp_symbols::iterate_list(clipList, [&](int32_t clipIndex, void* clipData) {
StoryTimelineClipDataClass = il2cpp_symbols::get_class_from_instance(clipData);
if (StoryTimelineTextClipDataClass == StoryTimelineClipDataClass)
{
il2cpp_symbols::write_field(clipData, StoryTimelineTextClipDataClass_NameField, il2cpp_symbols::NewWStr(clip->Name));
il2cpp_symbols::write_field(clipData, StoryTimelineTextClipDataClass_TextField, il2cpp_symbols::NewWStr(clip->Text));
assert(clipIndex >= 0);
const auto& curClip = clipIndex == 0 ? *clip : (*clip->Siblings)[clipIndex - 1];
il2cpp_symbols::write_field(clipData, StoryTimelineTextClipDataClass_NameField, il2cpp_symbols::NewWStr(curClip.Name));
il2cpp_symbols::write_field(clipData, StoryTimelineTextClipDataClass_TextField, il2cpp_symbols::NewWStr(curClip.Text));
const auto choiceDataList = il2cpp_symbols::read_field(clipData, StoryTimelineTextClipDataClass_ChoiceDataList);
if (choiceDataList)
{
Expand All @@ -1231,8 +1232,8 @@ namespace
StoryTimelineTextClipDataClass_ChoiceDataClass_TextField = il2cpp_class_get_field_from_name(StoryTimelineTextClipDataClass_ChoiceDataClass, "Text");
}

if (j < clip->ChoiceDataList.size()) {
il2cpp_symbols::write_field(choiceData, StoryTimelineTextClipDataClass_ChoiceDataClass_TextField, il2cpp_symbols::NewWStr(clip->ChoiceDataList[j]));
if (j < curClip.ChoiceDataList.size()) {
il2cpp_symbols::write_field(choiceData, StoryTimelineTextClipDataClass_ChoiceDataClass_TextField, il2cpp_symbols::NewWStr(curClip.ChoiceDataList[j]));
}
else {
printf("[ERROR] Exception occurred while loading story text in ChoiceDataList. storyId: %llu, block: %d, listIndex: %d\n", storyId, i, j);
Expand All @@ -1250,8 +1251,8 @@ namespace
StoryTimelineTextClipDataClass_ColorTextInfoClass_TextField = il2cpp_class_get_field_from_name(StoryTimelineTextClipDataClass_ColorTextInfoClass, "Text");
}

if (j < clip->ColorTextInfoList.size()) {
il2cpp_symbols::write_field(colorTextInfo, StoryTimelineTextClipDataClass_ColorTextInfoClass_TextField, il2cpp_symbols::NewWStr(clip->ColorTextInfoList[j]));
if (j < curClip.ColorTextInfoList.size()) {
il2cpp_symbols::write_field(colorTextInfo, StoryTimelineTextClipDataClass_ColorTextInfoClass_TextField, il2cpp_symbols::NewWStr(curClip.ColorTextInfoList[j]));
}
else {
printf("[ERROR] Exception occurred while loading story text in ChoiceDataList. storyId: %llu, block: %d, listIndex: %d\n", storyId, i, j);
Expand Down
1 change: 1 addition & 0 deletions src/local/local.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace local
std::wstring Text;
std::vector<std::wstring> ChoiceDataList;
std::vector<std::wstring> ColorTextInfoList;
std::optional<std::vector<StoryTextBlock>> Siblings;
};

struct StoryTextData
Expand Down
40 changes: 27 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,20 +885,34 @@ std::pair<std::unordered_map<std::size_t, local::StoryTextData>, std::unordered_
}
else
{
local::StoryTextBlock textBlock;
textBlock.Name = utility::conversions::to_string_t(block["Name"].GetString());
textBlock.Text = utility::conversions::to_string_t(block["Text"].GetString());
const auto& choiceDataList = block["ChoiceDataList"].GetArray();
for (const auto& choiceData : choiceDataList)
const auto readTextBlock = [&](this auto&& self, const rapidjson::Value& block) -> local::StoryTextBlock
{
textBlock.ChoiceDataList.emplace_back(utility::conversions::to_string_t(choiceData.GetString()));
}
const auto& colorTextInfoList = block["ColorTextInfoList"].GetArray();
for (const auto& colorTextInfo : colorTextInfoList)
{
textBlock.ColorTextInfoList.emplace_back(utility::conversions::to_string_t(colorTextInfo.GetString()));
}
data.TextBlockList.emplace_back(std::move(textBlock));
local::StoryTextBlock textBlock;
textBlock.Name = utility::conversions::to_string_t(block["Name"].GetString());
textBlock.Text = utility::conversions::to_string_t(block["Text"].GetString());
const auto& choiceDataList = block["ChoiceDataList"].GetArray();
for (const auto& choiceData : choiceDataList)
{
textBlock.ChoiceDataList.emplace_back(utility::conversions::to_string_t(choiceData.GetString()));
}
const auto& colorTextInfoList = block["ColorTextInfoList"].GetArray();
for (const auto& colorTextInfo : colorTextInfoList)
{
textBlock.ColorTextInfoList.emplace_back(utility::conversions::to_string_t(colorTextInfo.GetString()));
}
if (const auto iter = block.FindMember("Siblings"); iter != block.MemberEnd())
{
textBlock.Siblings.emplace();
const auto siblings = iter->value.GetArray();
textBlock.Siblings->reserve(siblings.Size());
for (const auto& sibling : siblings)
{
textBlock.Siblings->emplace_back(self(sibling));
}
}
return textBlock;
};
data.TextBlockList.emplace_back(readTextBlock(block));
}
}

Expand Down

0 comments on commit ba46680

Please sign in to comment.