Browse Source

Merge commit '6d07e15f4ee67ad3cb0636ad7cd70a3ee9d490ff'

Fix itemhold and add pfile def
(https://github.com/diasurgical/devilution/pull/199)
pull/4/head
Dennis Duda 8 years ago
parent
commit
dcf9d3ac88
  1. 47
      Source/pfile.cpp
  2. 2
      Source/pfile.h
  3. 2
      defs.h

47
Source/pfile.cpp

@ -3,7 +3,7 @@
#include "../types.h" #include "../types.h"
int pfile_cpp_init_value; int pfile_cpp_init_value;
char hero_names[320]; char hero_names[MAX_CHARACTERS][PLR_NAME_LEN];
bool gbValidSaveFile; // idb bool gbValidSaveFile; // idb
int save_prev_tc; // weak int save_prev_tc; // weak
@ -91,19 +91,16 @@ int __fastcall pfile_get_save_num_from_name(char *name)
{ {
char *v1; // ebx char *v1; // ebx
unsigned int v2; // esi unsigned int v2; // esi
char *v3; // edi
v1 = name; v1 = name;
v2 = 0; v2 = 0;
v3 = hero_names;
do do
{ {
if ( !_strcmpi(v3, v1) ) if ( !_strcmpi(hero_names[v2], v1) )
break; break;
++v2; ++v2;
v3 += 32;
} }
while ( v2 < 0xA ); while ( v2 < MAX_CHARACTERS );
return v2; return v2;
} }
@ -225,7 +222,7 @@ int __fastcall pfile_create_save_file(char *name_1, char *name_2)
v2 = name_2; v2 = name_2;
v3 = name_1; v3 = name_1;
if ( pfile_get_save_num_from_name(name_2) != 10 ) if ( pfile_get_save_num_from_name(name_2) != MAX_CHARACTERS )
return 0; return 0;
v4 = 0; v4 = 0;
v7 = plr[0]._pName; v7 = plr[0]._pName;
@ -237,9 +234,9 @@ int __fastcall pfile_create_save_file(char *name_1, char *name_2)
return 0; return 0;
} }
v5 = pfile_get_save_num_from_name(v3); v5 = pfile_get_save_num_from_name(v3);
if ( v5 == 10 ) if ( v5 == MAX_CHARACTERS )
return 0; return 0;
SStrCopy(&hero_names[32 * v5], v2, 32); SStrCopy(hero_names[v5], v2, 32);
SStrCopy(plr[v4]._pName, v2, 32); SStrCopy(plr[v4]._pName, v2, 32);
if ( !_strcmpi(chr_name_str, v3) ) if ( !_strcmpi(chr_name_str, v3) )
SStrCopy(chr_name_str, v2, 16); SStrCopy(chr_name_str, v2, 16);
@ -298,7 +295,6 @@ bool __stdcall pfile_ui_set_hero_infos(void (__stdcall *ui_add_hero_info)(_uiher
int v3; // eax int v3; // eax
DWORD v4; // eax DWORD v4; // eax
unsigned int v5; // esi unsigned int v5; // esi
char *v6; // ebx
void *v7; // eax void *v7; // eax
void *v8; // edi void *v8; // edi
//int v9; // eax //int v9; // eax
@ -319,7 +315,7 @@ bool __stdcall pfile_ui_set_hero_infos(void (__stdcall *ui_add_hero_info)(_uiher
save_num = 0; save_num = 0;
do do
{ {
if ( (unsigned int)save_num >= 0xA ) if ( (unsigned int)save_num >= MAX_CHARACTERS )
break; break;
GetSaveDirectory(FileName, 260, (int)lpSrcStr); GetSaveDirectory(FileName, 260, (int)lpSrcStr);
v1 = strrchr(FileName, '\\') + 1; v1 = strrchr(FileName, '\\') + 1;
@ -333,7 +329,7 @@ bool __stdcall pfile_ui_set_hero_infos(void (__stdcall *ui_add_hero_info)(_uiher
pfile_get_save_path(NewFileName, 260, v3); pfile_get_save_path(NewFileName, 260, v3);
if ( OpenFile(NewFileName, &ReOpenBuff, 0x4000u) == -1 ) if ( OpenFile(NewFileName, &ReOpenBuff, 0x4000u) == -1 )
break; break;
if ( (unsigned int)save_num >= 0xA ) if ( (unsigned int)save_num >= MAX_CHARACTERS )
goto LABEL_13; goto LABEL_13;
} }
if ( CopyFileA(FileName, NewFileName, 1) ) if ( CopyFileA(FileName, NewFileName, 1) )
@ -351,11 +347,10 @@ bool __stdcall pfile_ui_set_hero_infos(void (__stdcall *ui_add_hero_info)(_uiher
LABEL_13: LABEL_13:
++lpSrcStr; ++lpSrcStr;
} }
while ( (unsigned int)lpSrcStr < 0xA ); while ( (unsigned int)lpSrcStr < MAX_CHARACTERS );
} }
unused = 1; unused = 1;
v5 = 0; v5 = 0;
v6 = hero_names;
do do
{ {
v7 = pfile_open_save_archive(&unused, v5); v7 = pfile_open_save_archive(&unused, v5);
@ -364,7 +359,7 @@ LABEL_13:
{ {
if ( pfile_read_hero(v7, &pkplr) ) if ( pfile_read_hero(v7, &pkplr) )
{ {
strcpy(v6, pkplr.pName); strcpy(hero_names[v5], pkplr.pName);
UnPackPlayer(&pkplr, 0, 0); UnPackPlayer(&pkplr, 0, 0);
v10 = pfile_archive_contains_game(v8); v10 = pfile_archive_contains_game(v8);
game_2_ui_player(plr, &hero_info, v10); game_2_ui_player(plr, &hero_info, v10);
@ -373,9 +368,8 @@ LABEL_13:
pfile_SFileCloseArchive(v8); pfile_SFileCloseArchive(v8);
} }
++v5; ++v5;
v6 += 32;
} }
while ( v5 < 0xA ); while ( v5 < MAX_CHARACTERS );
return 1; return 1;
} }
// 679660: using guessed type char gbMaxPlayers; // 679660: using guessed type char gbMaxPlayers;
@ -539,33 +533,30 @@ int __fastcall pfile_get_player_class(int player_class_nr)
bool __stdcall pfile_ui_save_create(_uiheroinfo *heroinfo) bool __stdcall pfile_ui_save_create(_uiheroinfo *heroinfo)
{ {
unsigned int v1; // edi unsigned int v1; // edi
char *v2; // eax
//int v3; // eax //int v3; // eax
char v5; // al char v5; // al
PkPlayerStruct pkplr; // [esp+8h] [ebp-4F4h] PkPlayerStruct pkplr; // [esp+8h] [ebp-4F4h]
v1 = pfile_get_save_num_from_name(heroinfo->name); v1 = pfile_get_save_num_from_name(heroinfo->name);
if ( v1 == 10 ) if ( v1 == MAX_CHARACTERS )
{ {
v1 = 0; v1 = 0;
v2 = hero_names;
do do
{ {
if ( !*v2 ) if ( !*hero_names[v1] )
break; break;
++v1; ++v1;
v2 += 32;
} }
while ( v1 < 0xA ); while ( v1 < MAX_CHARACTERS );
if ( v1 == 10 ) if ( v1 == MAX_CHARACTERS )
return 0; return 0;
} }
//_LOBYTE(v3) = pfile_open_archive(0, v1); //_LOBYTE(v3) = pfile_open_archive(0, v1);
if ( !pfile_open_archive(0, v1) ) if ( !pfile_open_archive(0, v1) )
return 0; return 0;
mpqapi_remove_hash_entries(pfile_get_file_name); mpqapi_remove_hash_entries(pfile_get_file_name);
strncpy(&hero_names[32 * v1], heroinfo->name, 0x20u); strncpy(hero_names[v1], heroinfo->name, 0x20u);
hero_names[32 * v1 + 31] = 0; hero_names[v1][31] = 0;
v5 = pfile_get_player_class((unsigned char)heroinfo->heroclass); v5 = pfile_get_player_class((unsigned char)heroinfo->heroclass);
CreatePlayer(0, v5); CreatePlayer(0, v5);
strncpy(plr[0]._pName, heroinfo->name, 0x20u); strncpy(plr[0]._pName, heroinfo->name, 0x20u);
@ -624,9 +615,9 @@ bool __stdcall pfile_delete_save(_uiheroinfo *hero_info)
char FileName[260]; // [esp+0h] [ebp-104h] char FileName[260]; // [esp+0h] [ebp-104h]
v1 = pfile_get_save_num_from_name(hero_info->name); v1 = pfile_get_save_num_from_name(hero_info->name);
if ( v1 < 0xA ) if ( v1 < MAX_CHARACTERS )
{ {
hero_names[32 * v1] = 0; hero_names[v1][0] = 0;
pfile_get_save_path(FileName, 260, v1); pfile_get_save_path(FileName, 260, v1);
DeleteFileA(FileName); DeleteFileA(FileName);
} }

2
Source/pfile.h

@ -3,7 +3,7 @@
#define __PFILE_H__ #define __PFILE_H__
extern int pfile_cpp_init_value; extern int pfile_cpp_init_value;
extern char hero_names[320]; extern char hero_names[MAX_CHARACTERS][PLR_NAME_LEN];
extern bool gbValidSaveFile; // idb extern bool gbValidSaveFile; // idb
extern int save_prev_tc; // weak extern int save_prev_tc; // weak

2
defs.h

@ -41,6 +41,8 @@
// from diablo 2 beta // from diablo 2 beta
#define MAXEXP 2000000000 #define MAXEXP 2000000000
#define PLR_NAME_LEN 32
// Diablo uses a 256 color palette // Diablo uses a 256 color palette
// Entry 0-127 (0x00-0x7F) are level specific // Entry 0-127 (0x00-0x7F) are level specific
// Entry 128-255 (0x80-0xFF) are global // Entry 128-255 (0x80-0xFF) are global

Loading…
Cancel
Save