diff --git a/SourceX/DiabloUI/selgame.cpp b/SourceX/DiabloUI/selgame.cpp index 7b0f64637..0550a3a7f 100644 --- a/SourceX/DiabloUI/selgame.cpp +++ b/SourceX/DiabloUI/selgame.cpp @@ -246,7 +246,21 @@ void selgame_Diff_Select(int value) nDifficulty = value; if (!selhero_isMultiPlayer) { + // This is part of a dangerous hack to enable difficulty selection in single-player. + // FIXME: Dialogs should not refer to each other's variables. + + // We're in the selhero loop instead of the selgame one. + // Free the selgame data and flag the end of the selhero loop. selhero_endMenu = true; + + // We only call FreeVectors because ArtBackground.Unload() + // will be called by selheroFree(). + selgame_FreeVectors(); + + // We must clear the InitList because selhero's loop will perform + // one more iteration after this function exits. + UiInitList_clear(); + return; } diff --git a/SourceX/DiabloUI/selhero.cpp b/SourceX/DiabloUI/selhero.cpp index 964ece242..aa20e47f5 100644 --- a/SourceX/DiabloUI/selhero.cpp +++ b/SourceX/DiabloUI/selhero.cpp @@ -88,6 +88,7 @@ void selhero_Free() selhero_FreeDlgItems(); selhero_FreeListItems(); + UnloadScrollBar(); bUIElementsLoaded = false; } @@ -457,7 +458,17 @@ void selhero_Load_Select(int value) if (vecSelHeroDlgItems[value]->m_value == 0) { selhero_result = SELHERO_CONTINUE; return; - } else if (!selhero_isMultiPlayer) { + } + + if (!selhero_isMultiPlayer) { + // This is part of a dangerous hack to enable difficulty selection in single-player. + // FIXME: Dialogs should not refer to each other's variables. + + // We disable `selhero_endMenu` and replace the background and art + // and the item list with the difficulty selection ones. + // + // This means selhero's render loop will render selgame's items, + // which happens to work because the render loops are similar. selhero_endMenu = false; selhero_Free(); LoadBackgroundArt("ui_art\\selgame.pcx"); @@ -530,8 +541,6 @@ static void UiSelHeroDialog( *dlgresult = selhero_result; snprintf(*name, sizeof(*name), selhero_heroInfo.name); - - UnloadScrollBar(); } void UiSelHeroSingDialog(