Browse Source

Fix menu audio

Ui code is moved to the correct file so that it is initialized after the
audio. This also rebases effects.cpp on the upstream as this fixes some
issues we where having. WinMain has also been rebased.
pull/17/head
Anders Jenbo 7 years ago
parent
commit
1fd31b7df5
  1. 4
      CMakeLists.txt
  2. 2111
      Source/effects.cpp
  3. 8
      Source/effects.h
  4. 1
      Source/init.h
  5. 80
      Stub/diablo.cpp
  6. 580
      Stub/diabloui.cpp
  7. 1342
      Stub/effects.cpp
  8. 569
      Stub/init.cpp
  9. 31
      Stub/sdlrender.cpp
  10. 48
      Stub/sound.cpp

4
CMakeLists.txt

@ -48,7 +48,7 @@ set(SOURCES
Source/drlg_l2.cpp
Source/drlg_l3.cpp
Source/drlg_l4.cpp
# Source/effects.cpp
Source/effects.cpp
Source/encrypt.cpp
Source/engine.cpp
Source/error.cpp
@ -103,7 +103,6 @@ set(ORIGINAL_SOURCES
Source/capture.cpp
Source/appfat.cpp
Source/dthread.cpp
Source/effects.cpp
Source/dx.cpp
Source/fault.cpp
Source/init.cpp
@ -134,7 +133,6 @@ set(STUB_SOURCES
Stub/miniwin_msg_sdl.cpp
Stub/storm_net.cpp
Stub/validate.cpp
Stub/effects.cpp
Stub/sdlrender.cpp
Stub/diablo.cpp
Stub/gamemenu.cpp

2111
Source/effects.cpp

File diff suppressed because it is too large Load Diff

8
Source/effects.h

@ -2,13 +2,11 @@
#ifndef __EFFECTS_H__
#define __EFFECTS_H__
extern int effects_cpp_init_value; // weak
extern int sfxdelay; // weak
extern int sfxdnum;
extern void *sfx_stream;
extern TSFX *sfx_data_cur;
void __cdecl effects_cpp_init();
BOOL __fastcall effect_is_playing(int nSFX);
void __cdecl sfx_stop();
void __fastcall InitMonsterSND(int monst);
@ -25,17 +23,15 @@ void __cdecl sound_stop();
void __cdecl sound_update();
void __cdecl effects_cleanup_sfx();
void __cdecl stream_update();
void __fastcall priv_sound_init(int bLoadMask);
void __fastcall priv_sound_init(UCHAR bLoadMask);
void __cdecl sound_init();
void __stdcall effects_play_sound(char *snd_file);
/* rdata */
extern const int effects_inf; // weak
extern const int effects_inf; // weak
extern const char monster_action_sounds[]; // idb
/* data */
extern TSFX sgSFX[NUM_SFX];
#endif /* __EFFECTS_H__ */

1
Source/init.h

@ -41,5 +41,6 @@ extern const int init_inf; // weak
extern char gszVersionNumber[260];
extern char gszProductName[260];
extern int SelectedItem;
#endif /* __INIT_H__ */

80
Stub/diablo.cpp

@ -295,70 +295,76 @@ bool __cdecl diablo_get_not_running()
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
DUMMY();
HINSTANCE v4; // esi
char Filename[260]; // [esp+8h] [ebp-10Ch]
char value_name[8]; // [esp+10Ch] [ebp-8h]
{
HINSTANCE hInst;
int nData;
char szFileName[MAX_PATH];
BOOL bNoEvent;
v4 = hInstance;
hInst = hInstance;
#ifndef DEBUGGER
diablo_reload_process(hInstance);
#endif
ghInst = v4;
if ( RestrictedTest() )
ghInst = hInst;
if (RestrictedTest())
ErrOkDlg(IDD_DIALOG10, 0, "C:\\Src\\Diablo\\Source\\DIABLO.CPP", 877);
if ( ReadOnlyTest() )
{
if ( !GetModuleFileName(ghInst, Filename, 0x104u) )
*Filename = '\0';
DirErrorDlg(Filename);
if (ReadOnlyTest()) {
if (!GetModuleFileName(ghInst, szFileName, sizeof(szFileName)))
szFileName[0] = '\0';
DirErrorDlg(szFileName);
}
ShowCursor(FALSE);
srand(GetTickCount());
InitHash();
exception_get_filter();
if ( !diablo_find_window("DIABLO") && diablo_get_not_running() )
{
bNoEvent = diablo_get_not_running();
if (!diablo_find_window("DIABLO") && bNoEvent) {
#ifdef _DEBUG
//SFileEnableDirectAccess(TRUE);
#endif
diablo_init_screen();
diablo_parse_flags(lpCmdLine);
init_create_window(nCmdShow);// My code calls a function inside here...
init_create_window(nCmdShow);
sound_init();
UiInitialize();
#ifdef _DEBUG
if ( showintrodebug )
play_movie("gendata\\logo.smk", 1);
#else
play_movie("gendata\\logo.smk", 1);
if (showintrodebug)
#endif
strcpy(value_name, "Intro");
if ( !SRegLoadValue("Diablo", value_name, 0, (int *)&hInstance) )
hInstance = (HINSTANCE)1;
if ( hInstance )
play_movie("gendata\\diablo1.smk", 1);
SRegSaveValue("Diablo", value_name, 0, 0);
#ifdef _DEBUG
if ( showintrodebug )
play_movie("gendata\\logo.smk", TRUE);
{
char szValueName[] = "Intro";
if (!SRegLoadValue("Diablo", szValueName, 0, &nData))
nData = 1;
if (nData)
play_movie("gendata\\diablo1.smk", TRUE);
SRegSaveValue("Diablo", szValueName, 0, 0);
}
#ifdef _DEBUG
if (showintrodebug) {
#endif
UiTitleDialog(7);
BlackPalette();//Here is the start?
BlackPalette();
#ifdef _DEBUG
}
#else
UiTitleDialog(7);
BlackPalette();
#endif
mainmenu_loop();
UiDestroy();
SaveGamma();
if ( ghMainWnd )
{
#ifndef FASTER
if (ghMainWnd) {
Sleep(300);
#endif
DestroyWindow(ghMainWnd);
}
}
return 0;
return FALSE;
}
void __fastcall diablo_parse_flags(char *args)

580
Stub/diabloui.cpp

@ -2,6 +2,10 @@
#include "../types.h"
#include "stubs.h"
int menu = 0;
int SelectedItem = 0;
int SelectedItemMax = 0;
int MenuItem[10] = { 5, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
void __cdecl UiDestroy()
{
@ -14,9 +18,575 @@ BOOL __stdcall UiTitleDialog(int a1)
return TRUE;
}
void __cdecl UiInitialize()
void LoadCharNamesintoMemory(int start, int end)
{
DUMMY();
PkPlayerStruct pkplr;
int unused;
void *CharFile;
char *p_hero_names = *hero_names; // Not sure if this is correct
memset(hero_names, 0, 0x140u);
while (start != end) {
CharFile = pfile_open_save_archive(&unused, start);
if (CharFile) {
if (pfile_read_hero(CharFile, &pkplr)) {
strcpy(p_hero_names, pkplr.pName);
printf("Player Strength %d\n", (int)pkplr.pBaseStr);
UnPackPlayer(&pkplr, 0, 0);
pfile_archive_contains_game(CharFile);
}
pfile_SFileCloseArchive(CharFile);
}
p_hero_names += 32;
start++;
}
// memcpy(shero_names, hero_names, sizeof(hero_names));
}
void SetMenu(int MenuId)
{
effects_play_sound("sfx\\items\\titlslct.wav");
void *tmp = pPcxTitleImage;
pPcxTitleImage = NULL;
mem_free_dbg(tmp);
TitleImageLoaded = false;
menu = MenuId;
SelectedItem = 0;
SelectedItemMax = MenuItem[MenuId] - 1;
}
void ExitDiablo()
{
printf("Exiting Diablo\n");
SDL_Quit();
exit(0);
}
void UiInitialize() // I anticipate to move this later.
{
SDL_SetRelativeMouseMode(SDL_TRUE);
// WNDPROC saveProc;
snd_init(0);
music_start(5);
int timestart = 0;
signed int NewHeroNameIndex = 0;
SetMenu(0);
SDL_Event event;
int x, y;
bool quit = false;
int CharsLoaded = 0;
int HeroPortrait = 3;
printf("Main Menu Init\n");
if (!window) {
SdlDiabloMainWindow();
}
ClearScreenBuffer();
const Uint8 *state = SDL_GetKeyboardState(NULL);
// static std::deque<MSG> message_queue;
while (!quit) {
DrawMouse();
PaletteFadeIn(32);
if (menu == 0) {
SDL_RenderDiabloMainPage();
}
if (menu == 2) {
if (CharsLoaded == 0) {
LoadCharNamesintoMemory(0, 7);
// LoadHeroStats();
CharsLoaded = 1;
}
SDL_RenderDiabloSinglePlayerPage();
gbMaxPlayers = 1;
DrawMouse();
ConstantButtons();
}
if (menu == 3) {
CreateHeroMenu();
DrawNewHeroKartinka(HeroPortrait, 1);
ConstantButtons();
DrawMouse();
}
int m4Loaded = 0;
if (menu == 4) {
DrawNewHeroKartinka(HeroPortrait, 0);
RenderDefaultStats(HeroPortrait);
RenderUndecidedHeroName();
ConstantButtons();
DrawMouse();
}
if (menu == 5) {
DrawPreGameOptions(HeroPortrait, 1);
RenderDefaultStats(HeroPortrait);
ConstantButtons();
DrawMouse();
}
if (menu == 6) {
DrawPreGameDifficultySelection(HeroPortrait, 1);
RenderDefaultStats(HeroPortrait);
ConstantButtons();
DrawMouse();
}
if (menu == 10) {
ShowCredts();
}
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
if (menu != 0) {
SetMenu(0);
break;
}
quit = true;
ExitDiablo();
break;
case SDLK_BACKSPACE:
if (NewHeroNameIndex > 0) {
HeroUndecidedName[NewHeroNameIndex - 1] = 0;
--NewHeroNameIndex;
}
break;
case SDLK_UP:
SelectedItem--;
if (SelectedItem < 0) {
SelectedItem = 0;
}
effects_play_sound("sfx\\items\\titlemov.wav");
break;
case SDLK_DOWN:
SelectedItem++;
if (SelectedItem > SelectedItemMax) {
SelectedItem = SelectedItemMax;
}
effects_play_sound("sfx\\items\\titlemov.wav");
break;
case SDLK_RETURN:
default:
char letter = event.key.keysym.sym;
if (int(letter) > 96 && int(letter) < 123 || int(letter) == 32)
if (NewHeroNameIndex < 17) {
HeroUndecidedName[NewHeroNameIndex] = letter;
NewHeroNameIndex++;
}
break;
}
case SDL_KEYUP:
break;
default:
break;
}
if (event.type == SDL_QUIT) {
quit = true;
ExitDiablo();
}
if (event.type == SDL_MOUSEMOTION) {
// Get the mouse offsets
MouseX = event.motion.x;
MouseY = event.motion.y;
}
// If a key was pressed
if (event.type == SDL_MOUSEBUTTONDOWN /*&& event.button.clicks == 2*/) {
if (event.button.button == SDL_BUTTON_LEFT) {
x = event.button.x;
y = event.button.y;
printf("X %d , Y %d\n", x, y);
if (menu == 0) {
int ClickListStart = 230;
int sizeOfBox = 72;
int WidthOfBox = 430;
int ClickListEnd = 343;
if ((x > ClickListStart) && (y > ClickListStart) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + sizeOfBox)) { // Single clicked
printf("SinglePlayer Diablo\n");
SetMenu(2);
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox) + sizeOfBox)) { // MultiBox clicked
printf("MultiPlayer Diablo\n");
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 2)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 2) + sizeOfBox)) { // Reply Intro clicked
printf("Credits\n");
SetMenu(10);
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 4)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 4) + sizeOfBox)) { // ShowCredits clicked
quit = true;
ExitDiablo();
}
} // End of this Menu0
if (menu == 2) { // Yes, I know. Skipped 1 and I going to hell for it.
// int x = 440;
// int y = 430;
int ClickListStart = 315;
int sizeOfBox = 30;
int WidthOfBox = 400;
int ClickListEnd = 343;
int CreateHeroY = 555;
int CreateHeroX = 305;
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
// Render Clicks
if (TotalPlayers >= 1 && (x > ClickListStart) && (y > ClickListStart) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + sizeOfBox)) { // MultiBox clicked
strcpy(chr_name_str, hero_names[0]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 2 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox) + sizeOfBox)) { // MultiBox clicked
printf("Player 2 Diablo\n");
strcpy(chr_name_str, hero_names[1]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 3 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 2)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 2) + sizeOfBox)) { // MultiBox clicked
printf("Player 3 Diablo\n");
strcpy(chr_name_str, hero_names[2]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 4 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 3)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 3) + sizeOfBox)) { // MultiBox clicked
printf("Player 4 Diablo\n");
strcpy(chr_name_str, hero_names[3]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 5 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 4)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 4) + sizeOfBox)) { // MultiBox clicked
printf("Player 5 Diablo\n");
strcpy(chr_name_str, hero_names[4]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 6 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 5)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 5) + sizeOfBox)) { // MultiBox clicked
printf("Player 6 Diablo\n");
strcpy(chr_name_str, hero_names[5]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
HeroPortrait = 3;
printf("Cancel\n\n\n");
SetMenu(0);
}
if ((x > CreateHeroX) && (y > CreateHeroY) && (x < CreateHeroX + WidthOfBox) && (y < CreateHeroY + sizeOfBox)) {
printf("Clicked Create Hero Box\n");
SetMenu(3);
}
}
if (menu == 3) {
// SinglePlayerMenuItemsLoaded = 0;
printf("\n\nmenu3 X%d Y%d \n ", x, y);
int WarriorSelectBoxY = 430;
int WarriorSelectBoxW = 100;
int WarriorSelectBoxS = 100;
int RogueSelectBoxX = 450;
int RogueSelectBoxY = 392;
int SorcerorSelectBoxX = 383;
int SorcerorSelectBoxY = 365;
int CreateHeroOkBoxX = 330;
int CreateHeroOkBoxY = 441;
int CreateHeroCanBBoxX = 445;
int CreateHeroCanBBoxY = 473;
// int x = 280;
// int y = 430;
SDL_Rect WarriorSelectBox;
WarriorSelectBox.y = 350;
WarriorSelectBox.x = 280;
WarriorSelectBox.w = WarriorSelectBox.x + 100;
WarriorSelectBox.h = WarriorSelectBox.y + 30;
SDL_Rect RogueSelectBox;
RogueSelectBox.y = 392;
RogueSelectBox.x = 280;
RogueSelectBox.w = RogueSelectBox.x + 100;
RogueSelectBox.h = RogueSelectBox.y + 30;
// X450 Y 392 ;
SDL_Rect SorcerorSelectBox;
SorcerorSelectBox.y = 428;
SorcerorSelectBox.x = 280;
SorcerorSelectBox.w = SorcerorSelectBox.x + 100;
SorcerorSelectBox.h = SorcerorSelectBox.y + 30;
// X 447 Y 428
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
if ((x > WarriorSelectBox.x) && (y > WarriorSelectBox.y) && (x < WarriorSelectBox.w) && (y < WarriorSelectBox.h)) {
printf(" warrior I was hit\n\n\n");
HeroPortrait = 0;
HeroChosen = 0;
SetMenu(4);
}
if ((x > RogueSelectBox.x) && (y > RogueSelectBox.y) && (x < RogueSelectBox.w) && (y < RogueSelectBox.h)) {
printf(" rogue I was hit\n\n\n");
HeroPortrait = 1;
HeroChosen = 1;
SetMenu(4);
}
if ((x > SorcerorSelectBox.x) && (y > SorcerorSelectBox.y) && (x < SorcerorSelectBox.w) && (y < SorcerorSelectBox.h)) {
HeroPortrait = 2;
printf("sorceror I was hit\n\n\n");
HeroChosen = 2;
SetMenu(4);
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
HeroPortrait = 3;
printf("Cancel\n\n\n");
--menu;
}
}
if (menu == 4) {
printf("sozdat geroya");
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
// X 549 , Y 551
SDL_Rect ClickOkBox;
ClickOkBox.y = 550;
ClickOkBox.x = 550;
ClickOkBox.w = ClickOkBox.x + 30;
ClickOkBox.h = ClickOkBox.y + 30;
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
memset(HeroUndecidedName, 0, 17);
NewHeroNameIndex = 0;
printf("Cancel\n\n\n");
HeroPortrait = 3;
SetMenu(3);
}
if ((x > ClickOkBox.x) && (y > ClickOkBox.y) && (x < ClickOkBox.w) && (y < ClickOkBox.h)) {
printf("Ok\n");
CreateSinglePlayerChar = 1;
const char *test_name = HeroUndecidedName;
printf("%s\n", test_name);
break;
}
}
clock_t start, end;
double cpu_time_used;
if (menu == 5) {
if (timestart == 0) {
start = clock();
timestart = 1;
}
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("TIEM DELAY %f\n", cpu_time_used);
int CreateHeroOkBoxX = 330;
int CreateHeroOkBoxY = 441;
int CreateHeroCanBBoxX = 445;
int CreateHeroCanBBoxY = 473;
SDL_Rect NewGameBox;
NewGameBox.y = 350;
NewGameBox.x = 280;
NewGameBox.w = NewGameBox.x + 300;
NewGameBox.h = NewGameBox.y + 30;
SDL_Rect LoadGameBox;
LoadGameBox.y = 392;
LoadGameBox.x = 280;
LoadGameBox.w = LoadGameBox.x + 300;
LoadGameBox.h = LoadGameBox.y + 30;
// X450 Y 392 ;
SDL_Rect SorcerorSelectBox;
SorcerorSelectBox.y = 428;
SorcerorSelectBox.x = 280;
SorcerorSelectBox.w = SorcerorSelectBox.x + 100;
SorcerorSelectBox.h = SorcerorSelectBox.y + 30;
// X 447 Y 428
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
if (cpu_time_used > 0.5 && (x > NewGameBox.x) && (y > NewGameBox.y) && (x < NewGameBox.w) && (y < NewGameBox.h)) {
printf(" New Game I was hit\n\n\n");
SetMenu(6);
cpu_time_used = 0;
timestart = 0;
start = 0;
}
if (cpu_time_used > 0.5 && (x > LoadGameBox.x) && (y > LoadGameBox.y) && (x < LoadGameBox.w) && (y < LoadGameBox.h)) {
printf(" Load Game I was hit\n\n\n");
break;
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
HeroPortrait = 3;
timestart = 0;
cpu_time_used = 0;
start = 0;
end = 0;
cpu_time_used = 0;
printf("Cancel\n\n\n");
SetMenu(2); // Return back to select hero menu.
}
}
if (menu == 6) {
// Choose difficulty
if (timestart == 0) {
start = clock();
timestart = 1;
}
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
int CreateHeroOkBoxX = 330;
int CreateHeroOkBoxY = 441;
int CreateHeroCanBBoxX = 445;
int CreateHeroCanBBoxY = 473;
// int x = 280;
// int y = 430;
SDL_Rect NormalSelectBox;
NormalSelectBox.y = 350;
NormalSelectBox.x = 280;
NormalSelectBox.w = NormalSelectBox.x + 300;
NormalSelectBox.h = NormalSelectBox.y + 30;
SDL_Rect NightmareSelectBox;
NightmareSelectBox.y = 392;
NightmareSelectBox.x = 280;
NightmareSelectBox.w = NightmareSelectBox.x + 300;
NightmareSelectBox.h = NightmareSelectBox.y + 30;
// X450 Y 392 ;
SDL_Rect HellSelectBox;
HellSelectBox.y = 428;
HellSelectBox.x = 280;
HellSelectBox.w = HellSelectBox.x + 300;
HellSelectBox.h = HellSelectBox.y + 30;
// X 447 Y 428
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
if (cpu_time_used > 0.5 && (x > NormalSelectBox.x) && (y > NormalSelectBox.y) && (x < NormalSelectBox.w) && (y < NormalSelectBox.h)) {
StartNewGame = 1;
gnDifficulty = DIFF_NORMAL;
break;
}
if (cpu_time_used > 0.5 && (x > NightmareSelectBox.x) && (y > NightmareSelectBox.y) && (x < NightmareSelectBox.w) && (y < NightmareSelectBox.h)) {
StartNewGame = 1;
gnDifficulty = DIFF_NIGHTMARE;
break;
}
if (cpu_time_used > 1 && (x > HellSelectBox.x) && (y > HellSelectBox.y) && (x < HellSelectBox.w) && (y < HellSelectBox.h)) {
gnDifficulty = DIFF_HELL;
StartNewGame = 1;
break;
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
HeroPortrait = 3;
timestart = 0;
cpu_time_used = 0;
start = 0;
end = 0;
cpu_time_used = 0;
printf("Cancel\n\n\n");
--menu;
}
}
}
}
}
}
}
static std::vector<_uiheroinfo> hero_infos;
@ -58,7 +628,7 @@ BOOL __stdcall UiSelHeroSingDialog(BOOL(__stdcall *fninfo)(BOOL(__stdcall *fninf
// I like this.
*difficulty = gnDifficulty ;
if (StartNewGame) {
const char *hero_name = chr_name_str;
@ -74,7 +644,7 @@ BOOL __stdcall UiSelHeroSingDialog(BOOL(__stdcall *fninfo)(BOOL(__stdcall *fninf
*dlgresult = 2; // This means load game
printf("Difficulty : %d \n",* difficulty);
}
}
@ -200,4 +770,4 @@ int __stdcall UiSelectProvider(int a1, _SNETPROGRAMDATA *client_info, _SNETPLAYE
int __stdcall UiCreatePlayerDescription(_uiheroinfo *info, int mode, char *desc)
{
UNIMPLEMENTED();
}
}

1342
Stub/effects.cpp

File diff suppressed because it is too large Load Diff

569
Stub/init.cpp

@ -19,8 +19,6 @@ char HeroUndecidedName[17] = { 0 };
bool StartNewGame;
bool CreateSinglePlayerChar;
int HeroChosen = 0;
int menu = 0;
int SelectedItem = 0;
/**
* Case insensitive search for a file name in a directory.
@ -71,10 +69,6 @@ void __fastcall init_create_window(int nCmdShow)
init_archives();
gmenu_init_menu();
SDL_Diablo_UI();
// SDL_ShowCursor(SDL_DISABLE);
// SDL_SetWindowSize(window, 1920,1080); //2560x1440
SDL_SetRelativeMouseMode(SDL_TRUE);
}
LRESULT __stdcall MainWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
@ -103,34 +97,6 @@ void GetAvailableHeroes()
{
}
void LoadCharNamesintoMemory(int start, int end)
{
PkPlayerStruct pkplr;
int unused;
void *CharFile;
char *p_hero_names = *hero_names; // Not sure if this is correct
memset(hero_names, 0, 0x140u);
while (start != end) {
CharFile = pfile_open_save_archive(&unused, start);
if (CharFile) {
if (pfile_read_hero(CharFile, &pkplr)) {
strcpy(p_hero_names, pkplr.pName);
printf("Player Strength %d\n", (int)pkplr.pBaseStr);
UnPackPlayer(&pkplr, 0, 0);
pfile_archive_contains_game(CharFile);
}
pfile_SFileCloseArchive(CharFile);
}
p_hero_names += 32;
start++;
}
// memcpy(shero_names, hero_names, sizeof(hero_names));
}
void HideCursor()
{
Uint8 l_data[1];
@ -142,538 +108,3 @@ void HideCursor()
SDL_Cursor *g_cursor = SDL_CreateCursor(l_data, l_mask, 1, 1, 0, 0);
SDL_SetCursor(g_cursor);
}
void SetMenu(int MenuId)
{
void *tmp = pPcxTitleImage;
pPcxTitleImage = NULL;
mem_free_dbg(tmp);
TitleImageLoaded = false;
menu = MenuId;
SelectedItem = 0;
}
void ExitDiablo()
{
printf("Exiting Diablo\n");
SDL_Quit();
exit(0);
}
void SDL_Diablo_UI() // I anticipate to move this later.
{
// WNDPROC saveProc;
snd_init(0);
music_start(5);
int timestart = 0;
signed int NewHeroNameIndex = 0;
SetMenu(0);
SDL_Event event;
int x, y;
bool quit = false;
int CharsLoaded = 0;
int HeroPortrait = 3;
printf("Main Menu Init\n");
// SDL_ShowCursor(SDL_DISABLE);//Doesn't really work... Use HideCursor() instead.
if (!window) {
SdlDiabloMainWindow();
}
ClearScreenBuffer();
const Uint8 *state = SDL_GetKeyboardState(NULL);
// static std::deque<MSG> message_queue;
while (!quit) {
DrawMouse();
PaletteFadeIn(32);
if (menu == 0) {
SDL_RenderDiabloMainPage();
}
if (menu == 2) {
if (CharsLoaded == 0) {
LoadCharNamesintoMemory(0, 7);
// LoadHeroStats();
CharsLoaded = 1;
}
SDL_RenderDiabloSinglePlayerPage();
gbMaxPlayers = 1;
DrawMouse();
ConstantButtons();
}
if (menu == 3) {
CreateHeroMenu();
DrawNewHeroKartinka(HeroPortrait, 1);
ConstantButtons();
DrawMouse();
}
int m4Loaded = 0;
if (menu == 4) {
DrawNewHeroKartinka(HeroPortrait, 0);
RenderDefaultStats(HeroPortrait);
RenderUndecidedHeroName();
ConstantButtons();
DrawMouse();
}
if (menu == 5) {
DrawPreGameOptions(HeroPortrait, 1);
RenderDefaultStats(HeroPortrait);
ConstantButtons();
DrawMouse();
}
if (menu == 6) {
DrawPreGameDifficultySelection(HeroPortrait, 1);
RenderDefaultStats(HeroPortrait);
ConstantButtons();
DrawMouse();
}
if (menu == 10) {
ShowCredts();
}
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
if (menu != 0) {
SetMenu(0);
break;
}
quit = true;
ExitDiablo();
break;
case SDLK_BACKSPACE:
if (NewHeroNameIndex > 0) {
HeroUndecidedName[NewHeroNameIndex - 1] = 0;
--NewHeroNameIndex;
}
break;
case SDLK_UP:
SelectedItem--;
break;
case SDLK_DOWN:
SelectedItem++;
break;
case SDLK_RETURN:
default:
char letter = event.key.keysym.sym;
if (int(letter) > 96 && int(letter) < 123 || int(letter) == 32)
if (NewHeroNameIndex < 17) {
HeroUndecidedName[NewHeroNameIndex] = letter;
NewHeroNameIndex++;
}
break;
}
case SDL_KEYUP:
break;
default:
break;
}
if (event.type == SDL_QUIT) {
quit = true;
ExitDiablo();
}
if (event.type == SDL_MOUSEMOTION) {
// Get the mouse offsets
MouseX = event.motion.x;
MouseY = event.motion.y;
}
// If a key was pressed
if (event.type == SDL_MOUSEBUTTONDOWN /*&& event.button.clicks == 2*/) {
if (event.button.button == SDL_BUTTON_LEFT) {
x = event.button.x;
y = event.button.y;
printf("X %d , Y %d\n", x, y);
if (menu == 0) {
int ClickListStart = 230;
int sizeOfBox = 72;
int WidthOfBox = 430;
int ClickListEnd = 343;
if ((x > ClickListStart) && (y > ClickListStart) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + sizeOfBox)) { // Single clicked
printf("SinglePlayer Diablo\n");
SetMenu(2);
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox) + sizeOfBox)) { // MultiBox clicked
printf("MultiPlayer Diablo\n");
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 2)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 2) + sizeOfBox)) { // Reply Intro clicked
printf("Credits\n");
SetMenu(10);
}
if ((x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 4)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 4) + sizeOfBox)) { // ShowCredits clicked
quit = true;
ExitDiablo();
}
} // End of this Menu0
if (menu == 2) { // Yes, I know. Skipped 1 and I going to hell for it.
// int x = 440;
// int y = 430;
int ClickListStart = 315;
int sizeOfBox = 30;
int WidthOfBox = 400;
int ClickListEnd = 343;
int CreateHeroY = 555;
int CreateHeroX = 305;
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
// Render Clicks
if (TotalPlayers >= 1 && (x > ClickListStart) && (y > ClickListStart) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + sizeOfBox)) { // MultiBox clicked
strcpy(chr_name_str, hero_names[0]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 2 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox) + sizeOfBox)) { // MultiBox clicked
printf("Player 2 Diablo\n");
strcpy(chr_name_str, hero_names[1]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 3 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 2)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 2) + sizeOfBox)) { // MultiBox clicked
printf("Player 3 Diablo\n");
strcpy(chr_name_str, hero_names[2]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 4 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 3)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 3) + sizeOfBox)) { // MultiBox clicked
printf("Player 4 Diablo\n");
effects_play_sound("Sfx\\Items\\Titlslct.wav");
strcpy(chr_name_str, hero_names[3]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 5 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 4)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 4) + sizeOfBox)) { // MultiBox clicked
printf("Player 5 Diablo\n");
effects_play_sound("Sfx\\Items\\Titlslct.wav");
strcpy(chr_name_str, hero_names[4]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if (TotalPlayers >= 6 && (x > ClickListStart) && (y > ClickListStart + (sizeOfBox * 5)) && (x < ClickListStart + WidthOfBox) && (y < ClickListStart + (sizeOfBox * 5) + sizeOfBox)) { // MultiBox clicked
printf("Player 6 Diablo\n");
effects_play_sound("Sfx\\Items\\Titlslct.wav");
strcpy(chr_name_str, hero_names[5]);
printf("Player %s\n", chr_name_str);
SetMenu(5);
// break;
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
HeroPortrait = 3;
printf("Cancel\n\n\n");
SetMenu(0);
}
if ((x > CreateHeroX) && (y > CreateHeroY) && (x < CreateHeroX + WidthOfBox) && (y < CreateHeroY + sizeOfBox)) {
printf("Clicked Create Hero Box\n");
SetMenu(3);
}
}
if (menu == 3) {
// SinglePlayerMenuItemsLoaded = 0;
printf("\n\nmenu3 X%d Y%d \n ", x, y);
int WarriorSelectBoxY = 430;
int WarriorSelectBoxW = 100;
int WarriorSelectBoxS = 100;
int RogueSelectBoxX = 450;
int RogueSelectBoxY = 392;
int SorcerorSelectBoxX = 383;
int SorcerorSelectBoxY = 365;
int CreateHeroOkBoxX = 330;
int CreateHeroOkBoxY = 441;
int CreateHeroCanBBoxX = 445;
int CreateHeroCanBBoxY = 473;
// int x = 280;
// int y = 430;
SDL_Rect WarriorSelectBox;
WarriorSelectBox.y = 350;
WarriorSelectBox.x = 280;
WarriorSelectBox.w = WarriorSelectBox.x + 100;
WarriorSelectBox.h = WarriorSelectBox.y + 30;
SDL_Rect RogueSelectBox;
RogueSelectBox.y = 392;
RogueSelectBox.x = 280;
RogueSelectBox.w = RogueSelectBox.x + 100;
RogueSelectBox.h = RogueSelectBox.y + 30;
// X450 Y 392 ;
SDL_Rect SorcerorSelectBox;
SorcerorSelectBox.y = 428;
SorcerorSelectBox.x = 280;
SorcerorSelectBox.w = SorcerorSelectBox.x + 100;
SorcerorSelectBox.h = SorcerorSelectBox.y + 30;
// X 447 Y 428
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
if ((x > WarriorSelectBox.x) && (y > WarriorSelectBox.y) && (x < WarriorSelectBox.w) && (y < WarriorSelectBox.h)) {
printf(" warrior I was hit\n\n\n");
HeroPortrait = 0;
HeroChosen = 0;
SetMenu(4);
}
if ((x > RogueSelectBox.x) && (y > RogueSelectBox.y) && (x < RogueSelectBox.w) && (y < RogueSelectBox.h)) {
printf(" rogue I was hit\n\n\n");
HeroPortrait = 1;
HeroChosen = 1;
SetMenu(4);
}
if ((x > SorcerorSelectBox.x) && (y > SorcerorSelectBox.y) && (x < SorcerorSelectBox.w) && (y < SorcerorSelectBox.h)) {
HeroPortrait = 2;
printf("sorceror I was hit\n\n\n");
HeroChosen = 2;
SetMenu(4);
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
HeroPortrait = 3;
printf("Cancel\n\n\n");
--menu;
}
}
if (menu == 4) {
printf("sozdat geroya");
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
// X 549 , Y 551
SDL_Rect ClickOkBox;
ClickOkBox.y = 550;
ClickOkBox.x = 550;
ClickOkBox.w = ClickOkBox.x + 30;
ClickOkBox.h = ClickOkBox.y + 30;
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
memset(HeroUndecidedName, 0, 17);
NewHeroNameIndex = 0;
printf("Cancel\n\n\n");
HeroPortrait = 3;
SetMenu(3);
}
if ((x > ClickOkBox.x) && (y > ClickOkBox.y) && (x < ClickOkBox.w) && (y < ClickOkBox.h)) {
printf("Ok\n");
CreateSinglePlayerChar = 1;
const char *test_name = HeroUndecidedName;
printf("%s\n", test_name);
break;
}
}
clock_t start, end;
double cpu_time_used;
if (menu == 5) {
if (timestart == 0) {
start = clock();
timestart = 1;
}
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("TIEM DELAY %f\n", cpu_time_used);
int CreateHeroOkBoxX = 330;
int CreateHeroOkBoxY = 441;
int CreateHeroCanBBoxX = 445;
int CreateHeroCanBBoxY = 473;
SDL_Rect NewGameBox;
NewGameBox.y = 350;
NewGameBox.x = 280;
NewGameBox.w = NewGameBox.x + 300;
NewGameBox.h = NewGameBox.y + 30;
SDL_Rect LoadGameBox;
LoadGameBox.y = 392;
LoadGameBox.x = 280;
LoadGameBox.w = LoadGameBox.x + 300;
LoadGameBox.h = LoadGameBox.y + 30;
// X450 Y 392 ;
SDL_Rect SorcerorSelectBox;
SorcerorSelectBox.y = 428;
SorcerorSelectBox.x = 280;
SorcerorSelectBox.w = SorcerorSelectBox.x + 100;
SorcerorSelectBox.h = SorcerorSelectBox.y + 30;
// X 447 Y 428
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
if (cpu_time_used > 0.5 && (x > NewGameBox.x) && (y > NewGameBox.y) && (x < NewGameBox.w) && (y < NewGameBox.h)) {
printf(" New Game I was hit\n\n\n");
SetMenu(6);
cpu_time_used = 0;
timestart = 0;
start = 0;
}
if (cpu_time_used > 0.5 && (x > LoadGameBox.x) && (y > LoadGameBox.y) && (x < LoadGameBox.w) && (y < LoadGameBox.h)) {
printf(" Load Game I was hit\n\n\n");
break;
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
HeroPortrait = 3;
timestart = 0;
cpu_time_used = 0;
start = 0;
end = 0;
cpu_time_used = 0;
printf("Cancel\n\n\n");
SetMenu(2); // Return back to select hero menu.
}
}
if (menu == 6) {
// Choose difficulty
if (timestart == 0) {
start = clock();
timestart = 1;
}
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
int CreateHeroOkBoxX = 330;
int CreateHeroOkBoxY = 441;
int CreateHeroCanBBoxX = 445;
int CreateHeroCanBBoxY = 473;
// int x = 280;
// int y = 430;
SDL_Rect NormalSelectBox;
NormalSelectBox.y = 350;
NormalSelectBox.x = 280;
NormalSelectBox.w = NormalSelectBox.x + 300;
NormalSelectBox.h = NormalSelectBox.y + 30;
SDL_Rect NightmareSelectBox;
NightmareSelectBox.y = 392;
NightmareSelectBox.x = 280;
NightmareSelectBox.w = NightmareSelectBox.x + 300;
NightmareSelectBox.h = NightmareSelectBox.y + 30;
// X450 Y 392 ;
SDL_Rect HellSelectBox;
HellSelectBox.y = 428;
HellSelectBox.x = 280;
HellSelectBox.w = HellSelectBox.x + 300;
HellSelectBox.h = HellSelectBox.y + 30;
// X 447 Y 428
SDL_Rect CreateHeroCancelBox;
CreateHeroCancelBox.y = 550;
CreateHeroCancelBox.x = 675;
CreateHeroCancelBox.w = CreateHeroCancelBox.x + 100;
CreateHeroCancelBox.h = CreateHeroCancelBox.y + 30;
if (cpu_time_used > 0.5 && (x > NormalSelectBox.x) && (y > NormalSelectBox.y) && (x < NormalSelectBox.w) && (y < NormalSelectBox.h)) {
StartNewGame = 1;
gnDifficulty = DIFF_NORMAL;
break;
}
if (cpu_time_used > 0.5 && (x > NightmareSelectBox.x) && (y > NightmareSelectBox.y) && (x < NightmareSelectBox.w) && (y < NightmareSelectBox.h)) {
StartNewGame = 1;
gnDifficulty = DIFF_NIGHTMARE;
break;
}
if (cpu_time_used > 1 && (x > HellSelectBox.x) && (y > HellSelectBox.y) && (x < HellSelectBox.w) && (y < HellSelectBox.h)) {
gnDifficulty = DIFF_HELL;
StartNewGame = 1;
break;
}
if ((x > CreateHeroCancelBox.x) && (y > CreateHeroCancelBox.y) && (x < CreateHeroCancelBox.w) && (y < CreateHeroCancelBox.h)) {
HeroPortrait = 3;
timestart = 0;
cpu_time_used = 0;
start = 0;
end = 0;
cpu_time_used = 0;
printf("Cancel\n\n\n");
--menu;
}
}
}
}
}
}
}

31
Stub/sdlrender.cpp

@ -852,8 +852,13 @@ void SDL_RenderDiabloMainPage()
Pentframe = 0;
}
int menuTop = 192;
int PentPositionX = GetCenter(42);
int PentPositionY = 192;
int PentPositionY = menuTop + SelectedItem * 43;
if (SelectedItem > 1) {
PentPositionY -= 1; // "Multi Player" and "Replay Intro" has a smaller gap then other items
}
DrawArtWithMask(PentPositionX - 234, PentPositionY, 42, 42, Pentframe, 250, MenuPentegram);
DrawArtWithMask(PentPositionX + 234, PentPositionY, 42, 42, Pentframe, 250, MenuPentegram);
@ -863,22 +868,14 @@ void SDL_RenderDiabloMainPage()
RenderDiabloLogo();
// print_title_str_large();
int x = GetCenter(GetPCXFontWidth(MENIITEMS[0], pFont)) - 1;
int y = 192;
DrawPCXString(x, y, gdwFontWidth, gdwFontHeight, MENIITEMS[0], pFont, pPcxFontImage);
x = GetCenter(GetPCXFontWidth(MENIITEMS[1], pFont)) - 1;
y += 43;
DrawPCXString(x, y, gdwFontWidth, gdwFontHeight, MENIITEMS[1], pFont, pPcxFontImage);
x = GetCenter(GetPCXFontWidth(MENIITEMS[2], pFont)) - 1;
y += 42;
DrawPCXString(x, y, gdwFontWidth, gdwFontHeight, MENIITEMS[2], pFont, pPcxFontImage);
x = GetCenter(GetPCXFontWidth(MENIITEMS[3], pFont)) - 1;
y += 43;
DrawPCXString(x, y, gdwFontWidth, gdwFontHeight, MENIITEMS[3], pFont, pPcxFontImage);
x = GetCenter(GetPCXFontWidth(MENIITEMS[4], pFont)) - 1;
y += 43;
DrawPCXString(x, y, gdwFontWidth, gdwFontHeight, MENIITEMS[4], pFont, pPcxFontImage);
for (int i = 0; i < 5; i++) {
int x = GetCenter(GetPCXFontWidth(MENIITEMS[i], pFont)) - 1;
int y = menuTop + i * 43;
if (i == 1) {
y -= 1; // "Multi Player" and "Replay Intro" has a smaller gap then other items
}
DrawPCXString(x, y, gdwFontWidth, gdwFontHeight, MENIITEMS[i], pFont, pPcxFontImage);
}
DrawPCXString(17, 444, gdwFont3Width, gdwFont3Height, gszProductName, pFont16, pPcxFont3Image);

48
Stub/sound.cpp

@ -25,22 +25,22 @@ Mix_Music *gMusic = NULL;
Mix_Chunk *sample;
Mix_Music *music;
char *sgszMusicTracks[6] = {"Music\\DTowne.wav", "Music\\DLvlA.wav", "Music\\DLvlB.wav",
"Music\\DLvlC.wav", "Music\\DLvlD.wav", "Music\\Dintro.wav"};
char *sgszMusicTracks[6] = { "Music\\DTowne.wav", "Music\\DLvlA.wav", "Music\\DLvlB.wav",
"Music\\DLvlC.wav", "Music\\DLvlD.wav", "Music\\Dintro.wav" };
void __fastcall snd_init(HWND hWnd)
{
DUMMY();
/* for some reason function __fastcall snd_init seems to be used twice at this time*/
/* for some reason function __fastcall snd_init seems to be used twice at this time*/
printf("\nSND INIT\n");
// Initialize SDL.
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
printf("ERROR : %s\n\n", SDL_GetError());
}
/* following function Mix_AllocateChannels allocates the number of channels of simultaneously played sounds.*/
printf("Opened %i sound channels\n\n", Mix_AllocateChannels(channels));
/* for example following possible channels:
/* following function Mix_AllocateChannels allocates the number of channels of simultaneously played sounds.*/
printf("Opened %i sound channels\n\n", Mix_AllocateChannels(channels));
/* for example following possible channels:
1. music is playing
2. walking at the same time (walking sound)
3. reading a quest book at the same time
@ -111,7 +111,6 @@ void __fastcall music_start(int nTrack)
// This is a hack.... I don't like it .
// If you know this better than I , please help clean it up.
//Mix_OpenAudio(44100, AUDIO_S16LSB, 1, 1024); //No need to Mix_OpenAudio. Already done in the function __fastcall snd_init
//Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 1024);
@ -162,18 +161,16 @@ BOOL __fastcall snd_playing(TSnd *pSnd)
{
printf("snd_playing \n");
return false;
// DUMMY();
// UNIMPLEMENTED();
}
//
void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
{
Mix_PlayChannel(-1, (Mix_Chunk*)pSnd, 0);
Mix_PlayChannel(-1, (Mix_Chunk *)pSnd, 0);
}
void __fastcall snd_stop_snd(TSnd *pSnd)
@ -182,10 +179,6 @@ void __fastcall snd_stop_snd(TSnd *pSnd)
Mix_HaltMusic();
}
void *MSFXBuffer;
TSnd *__fastcall sound_file_load(char *path)
{
@ -194,24 +187,19 @@ TSnd *__fastcall sound_file_load(char *path)
int nrread;
void *file;
//This opens the file and reads it, makes Mix_chunk pointer to it.
//Once this is done the pointer is stored TSnd Struct
//This opens the file and reads it, makes Mix_chunk pointer to it.
//Once this is done the pointer is stored TSnd Struct
SFileOpenFile(path, &file);
bytestoread = (int)SFileGetFileSize((HANDLE)file, 0);
MSFXBuffer = DiabloAllocPtr(bytestoread);
SFileReadFile(file, (char *)MSFXBuffer, bytestoread, (unsigned long *)&nrread, 0);
SDL_RWops *rw = SDL_RWFromMem(MSFXBuffer, bytestoread);
Mix_Chunk *SoundFX = Mix_LoadWAV_RW(rw, 1);
bytestoread = (int)SFileGetFileSize((HANDLE)file, 0);
MSFXBuffer = DiabloAllocPtr(bytestoread);
SFileReadFile(file, (char *)MSFXBuffer, bytestoread, (unsigned long *)&nrread, 0);
SDL_RWops *rw = SDL_RWFromMem(MSFXBuffer, bytestoread);
Mix_Chunk *SoundFX = Mix_LoadWAV_RW(rw, 1);
return (TSnd*)SoundFX;
return (TSnd *)SoundFX;
// printf("Sound_File_Load %s\n", path);
// printf("Sound_File_Load %s\n", path);
// UNIMPLEMENTED();
}

Loading…
Cancel
Save