Skip to content

Commit c5a6140

Browse files
committed
Add basic TextureReplacement UI options.
1 parent 2bd0567 commit c5a6140

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

UI/GameSettingsScreen.cpp

+74
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,12 @@ void DeveloperToolsScreen::CreateViews() {
10841084
list->Add(new ItemHeader(dev->T("Language")));
10851085
list->Add(new Choice(dev->T("Load language ini")))->OnClick.Handle(this, &DeveloperToolsScreen::OnLoadLanguageIni);
10861086
list->Add(new Choice(dev->T("Save language ini")))->OnClick.Handle(this, &DeveloperToolsScreen::OnSaveLanguageIni);
1087+
list->Add(new ItemHeader(dev->T("Texture Replacement")));
1088+
list->Add(new CheckBox(&g_Config.bSaveNewTextures, dev->T("Save new textures")));
1089+
list->Add(new CheckBox(&g_Config.bReplaceTextures, dev->T("Replace textures")));
1090+
#if !defined(MOBILE_DEVICE)
1091+
list->Add(new Choice(dev->T("Create/Open textures.ini file for current game")))->OnClick.Handle(this, &DeveloperToolsScreen::OnOpenTexturesIniFile);
1092+
#endif
10871093
list->Add(new ItemHeader(""));
10881094
list->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
10891095
}
@@ -1137,6 +1143,74 @@ UI::EventReturn DeveloperToolsScreen::OnLoadLanguageIni(UI::EventParams &e) {
11371143
return UI::EVENT_DONE;
11381144
}
11391145

1146+
UI::EventReturn DeveloperToolsScreen::OnOpenTexturesIniFile(UI::EventParams &e) {
1147+
std::string gameID = g_paramSFO.GetValueString("DISC_ID");
1148+
std::string texturesDirectory = GetSysDirectory(DIRECTORY_TEXTURES) + gameID + "/";
1149+
bool enabled_ = !gameID.empty();
1150+
if (enabled_) {
1151+
if (!File::Exists(texturesDirectory)) {
1152+
File::CreateFullPath(texturesDirectory);
1153+
}
1154+
if (!File::Exists(texturesDirectory + "textures.ini")) {
1155+
FILE *f = File::OpenCFile(texturesDirectory + "textures.ini", "wb");
1156+
if (f) {
1157+
fwrite("\xEF\xBB\xBF", 0, 3, f);
1158+
fclose(f);
1159+
}
1160+
}
1161+
enabled_ = File::Exists(texturesDirectory + "textures.ini");
1162+
}
1163+
if (enabled_) {
1164+
std::string texturesIniFile;
1165+
#if defined(_WIN32)
1166+
texturesIniFile = texturesDirectory + "textures.ini";
1167+
// Can't rely on a .txt file extension to auto-open in the right editor,
1168+
// so let's find notepad
1169+
wchar_t notepad_path[MAX_PATH + 1];
1170+
GetSystemDirectory(notepad_path, MAX_PATH);
1171+
wcscat(notepad_path, L"\\notepad.exe");
1172+
1173+
wchar_t ini_path[MAX_PATH + 1] = { 0 };
1174+
wcsncpy(ini_path, ConvertUTF8ToWString(texturesIniFile).c_str(), MAX_PATH);
1175+
// Flip any slashes...
1176+
for (size_t i = 0; i < wcslen(ini_path); i++) {
1177+
if (ini_path[i] == '/')
1178+
ini_path[i] = '\\';
1179+
}
1180+
1181+
// One for the space, one for the null.
1182+
wchar_t command_line[MAX_PATH * 2 + 1 + 1];
1183+
wsprintf(command_line, L"%s %s", notepad_path, ini_path);
1184+
1185+
STARTUPINFO si;
1186+
memset(&si, 0, sizeof(si));
1187+
si.cb = sizeof(si);
1188+
si.wShowWindow = SW_SHOW;
1189+
PROCESS_INFORMATION pi;
1190+
memset(&pi, 0, sizeof(pi));
1191+
UINT retval = CreateProcess(0, command_line, 0, 0, 0, 0, 0, 0, &si, &pi);
1192+
if (!retval) {
1193+
ERROR_LOG(COMMON, "Failed creating notepad process");
1194+
}
1195+
CloseHandle(pi.hThread);
1196+
CloseHandle(pi.hProcess);
1197+
#elif !defined(MOBILE_DEVICE)
1198+
#if defined(__APPLE__)
1199+
texturesIniFile = "open ";
1200+
#else
1201+
texturesIniFile = "xdg-open ";
1202+
#endif
1203+
texturesIniFile.append(texturesDirectory + "textures.ini";);
1204+
NOTICE_LOG(BOOT, "Launching %s", texturesIniFile.c_str());
1205+
int retval = system(texturesIniFile.c_str());
1206+
if (retval != 0) {
1207+
ERROR_LOG(COMMON, "Failed to launch textures.ini file");
1208+
}
1209+
#endif
1210+
}
1211+
return UI::EVENT_DONE;
1212+
}
1213+
11401214
UI::EventReturn DeveloperToolsScreen::OnLogConfig(UI::EventParams &e) {
11411215
screenManager()->push(new LogConfigScreen());
11421216
return UI::EVENT_DONE;

UI/GameSettingsScreen.h

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class DeveloperToolsScreen : public UIDialogScreenWithBackground {
127127
UI::EventReturn OnLoggingChanged(UI::EventParams &e);
128128
UI::EventReturn OnLoadLanguageIni(UI::EventParams &e);
129129
UI::EventReturn OnSaveLanguageIni(UI::EventParams &e);
130+
UI::EventReturn OnOpenTexturesIniFile(UI::EventParams &e);
130131
UI::EventReturn OnLogConfig(UI::EventParams &e);
131132
UI::EventReturn OnJitAffectingSetting(UI::EventParams &e);
132133
};

0 commit comments

Comments
 (0)