Skip to content

Commit

Permalink
Show info in title
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhenjianYang committed Sep 30, 2020
1 parent 8e018ce commit a98e6e3
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
2 changes: 2 additions & 0 deletions solution/ed_voice/ed_voice.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<ClInclude Include="..\..\src\ed_voice\utils\module_info.h" />
<ClInclude Include="..\..\src\ed_voice\utils\section_info.h" />
<ClInclude Include="..\..\src\ed_voice\utils\str.h" />
<ClInclude Include="..\..\src\ed_voice\utils\win_title.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\ed_voice\asm\asm_sora.cpp" />
Expand Down Expand Up @@ -77,6 +78,7 @@
<ClCompile Include="..\..\src\ed_voice\utils\mem.cpp" />
<ClCompile Include="..\..\src\ed_voice\utils\mem_matcher.cpp" />
<ClCompile Include="..\..\src\ed_voice\utils\module_info.cpp" />
<ClCompile Include="..\..\src\ed_voice\utils\win_title.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{720642e1-0cc3-46a0-812e-6dec5119391f}</ProjectGuid>
Expand Down
6 changes: 6 additions & 0 deletions solution/ed_voice/ed_voice.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
<ClInclude Include="..\..\src\ed_voice\core\rnd_voice.h">
<Filter>src\core</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ed_voice\utils\win_title.h">
<Filter>src\utils</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\ed_voice\ed_voice.cpp">
Expand Down Expand Up @@ -213,5 +216,8 @@
<ClCompile Include="..\..\src\ed_voice\asm\asm_sora.cpp">
<Filter>src\asm</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ed_voice\utils\win_title.cpp">
<Filter>src\utils</Filter>
</ClCompile>
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion src/ed_voice/core/load_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DEFINE_CONFIG(disable_text_se, DisableTextSe, 1, "# (Voiced lines only) Disable
DEFINE_CONFIG(disable_dialog_se, DisableDialogSe, 1, "# (Voiced lines only) Disable dialog closing SE.");
DEFINE_CONFIG(disable_ao_ori_voice, DisableAoOriVoice, 1,
"# (AO only) Disable original scenario voice. (Play evo voice only)");
DEFINE_CONFIG(show_info, ShwoInfo, 1, "# Show information of SoraVoice (Lite) in the title bar.");

static std::string Trim(const std::string& s) {
if (s.empty()) {
Expand Down Expand Up @@ -65,6 +66,7 @@ bool core::LoadConfig(Config* config, const char* filename) {
SET_TO_DEFAULT(config, disable_text_se);
SET_TO_DEFAULT(config, disable_dialog_se);
SET_TO_DEFAULT(config, disable_ao_ori_voice);
SET_TO_DEFAULT(config, show_info);

std::ifstream ifs(filename, std::ios::in);
if (!ifs) {
Expand All @@ -84,6 +86,7 @@ bool core::LoadConfig(Config* config, const char* filename) {
SET_CONFIG(config, disable_text_se, name, value);
SET_CONFIG(config, disable_dialog_se, name, value);
SET_CONFIG(config, disable_ao_ori_voice, name, value);
SET_CONFIG(config, show_info, name, value);
}

return true;
Expand All @@ -98,7 +101,7 @@ bool core::SaveConfig(const Config* config, const char* filename, const Info* in
ofs << "# " << kSoraVoice << " " << kBuildDate << "\n";
ofs << "# " << kUrl << "\n" << "\n" << "\n";


OUTPUT_CONFIG(ofs, config, show_info);
OUTPUT_CONFIG(ofs, config, volume);
OUTPUT_CONFIG(ofs, config, disable_text_se);
OUTPUT_CONFIG(ofs, config, disable_dialog_se);
Expand Down
15 changes: 15 additions & 0 deletions src/ed_voice/core/sora_voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include "core/voice_id_mapping.h"
#include "global/global.h"
#include "player/player.h"
#include "utils/build_date.h"
#include "utils/create_dsound.h"
#include "utils/log.h"
#include "utils/win_title.h"

namespace {
enum {
Expand All @@ -30,6 +32,8 @@ constexpr char kAttrOgg[] = ".ogg";
constexpr char kAttrWav[] = ".wav";
constexpr char kConfigFilename[] = "voice/ed_voice.ini";
constexpr std::size_t kAoRndVoiceDelayMs = 1000;

constexpr const char* kInfo[] = { " - SoraVoice (Lite) ", kBuildDate };
}

namespace {
Expand Down Expand Up @@ -115,6 +119,17 @@ SoraVoiceImpl::SoraVoiceImpl(const std::string& title, const std::string& built_
memset(sigs_, 0, sizeof(*sigs_));
is_valid_ = true;

if (config_->show_info) {
std::string win_title = utils::GetWinTitle(*global.addrs.pHwnd);
LOG("Window title: %s", title.c_str());
for (auto info : kInfo) {
win_title.append(info);
}
if (utils::SetWinTitle(*global.addrs.pHwnd, win_title)) {
LOG("New window title: %s", win_title.c_str());
}
}

if (info_->game == GameAo) {
LOG("Play random voice for ao...");
player_->Play(core::GetRandomVoice(), nullptr, kAoRndVoiceDelayMs);
Expand Down
1 change: 1 addition & 0 deletions src/ed_voice/global/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ typedef struct Config {
int disable_text_se;
int disable_dialog_se;
int disable_ao_ori_voice;
int show_info;
} Config;

#endif // __GLOBAL_CONFIG_H__
17 changes: 17 additions & 0 deletions src/ed_voice/utils/win_title.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "win_title.h"

#include <Windows.h>

namespace {
constexpr int kMaxTitleLen = 255;
}

std::string utils::GetWinTitle(void* hwnd) {
char buff[kMaxTitleLen + 1];
GetWindowTextA((HWND)hwnd, buff, sizeof(buff));
return std::string(buff);
}

bool utils::SetWinTitle(void* hwnd, const std::string& title) {
return SetWindowTextA((HWND)hwnd, title.c_str());
}
11 changes: 11 additions & 0 deletions src/ed_voice/utils/win_title.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __UTILS_WIN_TITLE_H__
#define __UTILS_WIN_TITLE_H__

#include <string>

namespace utils {
std::string GetWinTitle(void* hwnd);
bool SetWinTitle(void* hwnd, const std::string& title);
} // namespace utils

#endif // __UTILS_WIN_TITLE_H__

0 comments on commit a98e6e3

Please sign in to comment.