diff --git a/d2char.c b/d2char.c index e341b8d..6ce46bc 100644 --- a/d2char.c +++ b/d2char.c @@ -35,4 +35,95 @@ int isExpansion(D2CharHeader* c) { int isLadder(D2CharHeader* c) { return c->charStatus & D2S_CHARSTATUS_LADDER; +} + +int getCurrentAct(D2CharHeader* c) { + if(isExpansion(c)) { + return c->charProgress % 5; + } else { + return c->charProgress % 4; + } +} + +int isFemale(D2CharHeader* c) { + return (c->charClass == D2S_CHARCLASS_AMAZON || + c->charClass == D2S_CHARCLASS_ASSASSIN || + c->charClass == D2S_CHARCLASS_SORCERESS); +} + +// Returns static string from library memory, no need to free +const char* getCharacterTitle(D2CharHeader* c) { + int tier; + if(isExpansion(c)) { + // Expansion + tier = c->charProgress / 5; + if(isHardcore(c)) { + // Expansion Hardcore + switch(tier) { + case 0: + return D2S_CHARPROGRESS_TIER0_NAME; + break; + case 1: + return D2S_CHARPROGRESS_EXPANSION_TIER1_NAME_HARDCORE; + break; + case 2: + return D2S_CHARPROGRESS_EXPANSION_TIER2_NAME_HARDCORE; + break; + case 3: + return D2S_CHARPROGRESS_EXPANSION_TIER3_NAME_HARDCORE; + break; + } + } else { + // Expansion Softcore + switch(tier) { + case 0: + return D2S_CHARPROGRESS_TIER0_NAME; + break; + case 1: + return D2S_CHARPROGRESS_EXPANSION_TIER1_NAME; + break; + case 2: + return D2S_CHARPROGRESS_EXPANSION_TIER2_NAME; + break; + case 3: + return isFemale(c) ? D2S_CHARPROGRESS_EXPANSION_TIER3_NAME_F : D2S_CHARPROGRESS_EXPANSION_TIER3_NAME_M; + break; + } + } + } else { + // Classic + if(isHardcore(c)) { + // Classic Hardcore + switch(tier) { + case 0: + return D2S_CHARPROGRESS_TIER0_NAME; + break; + case 1: + return isFemale(c) ? D2S_CHARPROGRESS_CLASSIC_TIER1_NAME_HARDCORE_F : D2S_CHARPROGRESS_CLASSIC_TIER1_NAME_HARDCORE_M; + break; + case 2: + return isFemale(c) ? D2S_CHARPROGRESS_CLASSIC_TIER2_NAME_HARDCORE_F : D2S_CHARPROGRESS_CLASSIC_TIER2_NAME_HARDCORE_M; + break; + case 3: + return isFemale(c) ? D2S_CHARPROGRESS_CLASSIC_TIER3_NAME_HARDCORE_F : D2S_CHARPROGRESS_CLASSIC_TIER3_NAME_HARDCORE_M; + break; + } + } else { + // Classic Softcore + switch(tier) { + case 0: + return D2S_CHARPROGRESS_TIER0_NAME; + break; + case 1: + return isFemale(c) ? D2S_CHARPROGRESS_CLASSIC_TIER1_NAME_F : D2S_CHARPROGRESS_CLASSIC_TIER1_NAME_M; + break; + case 2: + return isFemale(c) ? D2S_CHARPROGRESS_CLASSIC_TIER2_NAME_F : D2S_CHARPROGRESS_CLASSIC_TIER2_NAME_M; + break; + case 3: + return isFemale(c) ? D2S_CHARPROGRESS_CLASSIC_TIER3_NAME_F : D2S_CHARPROGRESS_CLASSIC_TIER3_NAME_M; + break; + } + } + } } \ No newline at end of file diff --git a/d2char.h b/d2char.h index a0ed17f..8dc572c 100644 --- a/d2char.h +++ b/d2char.h @@ -21,15 +21,6 @@ #define D2S_CHARSTATUS_EXPANSION 0x20 #define D2S_CHARSTATUS_LADDER 0x40 -#define D2S_CHARPROGRESS_CLASSIC_TIER0 3 -#define D2S_CHARPROGRESS_CLASSIC_TIER1 -#define D2S_CHARPROGRESS_CLASSIC_TIER2 -#define D2S_CHARPROGRESS_CLASSIC_TIER3 -#define D2S_CHARPROGRESS_EXPANSION_TIER0 -#define D2S_CHARPROGRESS_EXPANSION_TIER1 -#define D2S_CHARPROGRESS_EXPANSION_TIER2 -#define D2S_CHARPROGRESS_EXPANSION_TIER3 - enum D2Version { VER_106 = 71, VER_107 = 87, @@ -49,6 +40,14 @@ enum D2CharClass { D2S_CHARCLASS_ASSASSIN = 0x06 }; +enum D2Acts { + D2S_ACT1 = 0, + D2S_ACT2 = 1, + D2S_ACT3 = 2, + D2S_ACT4 = 3, + D2S_ACT5 = 4 +}; + typedef struct __attribute__((packed)){ uint32_t signature; uint32_t versionID; diff --git a/d2strings.h b/d2strings.h index 0400615..d052f53 100644 --- a/d2strings.h +++ b/d2strings.h @@ -1,29 +1,24 @@ #ifndef D2STRINGS_H #define D2STRINGS_H -const char* D2S_CHARPROGRESS_CLASSIC_TIER0_NAME_M = ""; +const char* D2S_CHARPROGRESS_TIER0_NAME = ""; const char* D2S_CHARPROGRESS_CLASSIC_TIER1_NAME_M = "Sir"; const char* D2S_CHARPROGRESS_CLASSIC_TIER2_NAME_M = "Lord"; const char* D2S_CHARPROGRESS_CLASSIC_TIER3_NAME_M = "Baron"; -const char* D2S_CHARPROGRESS_CLASSIC_TIER0_NAME_HARDCORE_M = ""; const char* D2S_CHARPROGRESS_CLASSIC_TIER1_NAME_HARDCORE_M = "Count"; const char* D2S_CHARPROGRESS_CLASSIC_TIER2_NAME_HARDCORE_M = "Duke"; const char* D2S_CHARPROGRESS_CLASSIC_TIER3_NAME_HARDCORE_M = "King"; -const char* D2S_CHARPROGRESS_CLASSIC_TIER0_NAME_F = ""; const char* D2S_CHARPROGRESS_CLASSIC_TIER1_NAME_F = "Dame"; const char* D2S_CHARPROGRESS_CLASSIC_TIER2_NAME_F = "Lady"; const char* D2S_CHARPROGRESS_CLASSIC_TIER3_NAME_F = "Baroness"; -const char* D2S_CHARPROGRESS_CLASSIC_TIER0_NAME_HARDCORE_F = ""; const char* D2S_CHARPROGRESS_CLASSIC_TIER1_NAME_HARDCORE_F = "Countess"; const char* D2S_CHARPROGRESS_CLASSIC_TIER2_NAME_HARDCORE_F = "Duchess"; const char* D2S_CHARPROGRESS_CLASSIC_TIER3_NAME_HARDCORE_F = "Queen"; -const char* D2S_CHARPROGRESS_EXPANSION_TIER0_NAME = ""; const char* D2S_CHARPROGRESS_EXPANSION_TIER1_NAME = "Slayer"; const char* D2S_CHARPROGRESS_EXPANSION_TIER2_NAME = "Champion"; const char* D2S_CHARPROGRESS_EXPANSION_TIER3_NAME_M = "Patriarch"; const char* D2S_CHARPROGRESS_EXPANSION_TIER3_NAME_F = "Matriarch"; -const char* D2S_CHARPROGRESS_EXPANSION_TIER0_NAME_HARDCORE = ""; const char* D2S_CHARPROGRESS_EXPANSION_TIER1_NAME_HARDCORE = "Destroyer"; const char* D2S_CHARPROGRESS_EXPANSION_TIER2_NAME_HARDCORE = "Conqueror"; const char* D2S_CHARPROGRESS_EXPANSION_TIER3_NAME_HARDCORE = "Guardian";