forked from jankowskib/D2Ex2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExDeathMessage.cpp
132 lines (111 loc) · 4.18 KB
/
ExDeathMessage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*==========================================================
* D2Ex2
* https://github.com/lolet/D2Ex2
* ==========================================================
* Copyright (c) 2011-2014 Bartosz Jankowski
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ==========================================================
*/
#include "stdAfx.h"
#include "ExDeathMessage.h"
#include "ExScreen.h"
/*
Replacement for original death message (You have died...)
Current function adds a respawn timer
Needs a serverside stuff to avoid hack possibility
Original function address (1.13d): 0x6FAC8BB0, called from: 0x6FACD7AA <- Simple 5 bytes 0xE8 patch
*/
void ExDeathMessage::Draw()
{
static DWORD nRespawnTimer = 0;
static char gLocaleFolder[5];
UnitAny* pPlayerUnit = D2Funcs.D2CLIENT_GetPlayer();
if (!pPlayerUnit)
return;
int nCurrentMode = pPlayerUnit->dwMode;
if (!(pPlayerUnit->dwFlags & 0x10000)) // the unit is dead
{
nRespawnTimer = 0;
return;
}
if (nCurrentMode != PLAYER_MODE_DEAD)
return;
if (!gLocaleFolder[0])
D2Funcs.D2LANG_GetLocaleFolder(gLocaleFolder, 0);
if (!*D2Vars.D2CLIENT_CellDeathInst)
{
ostringstream sPath;
sPath << "DATA\\LOCAL\\UI\\" << gLocaleFolder << "\\youdiedinst";
*D2Vars.D2CLIENT_CellDeathInst = D2Funcs.D2WIN_LoadCellFile(sPath.str().c_str(), 0);
}
if (!*D2Vars.D2CLIENT_CellDeathHC)
{
ostringstream sPath;
sPath << "DATA\\LOCAL\\UI\\" << gLocaleFolder << "\\youdiedhardcore";
*D2Vars.D2CLIENT_CellDeathHC = D2Funcs.D2WIN_LoadCellFile(sPath.str().c_str(), 0);
}
CellFile* pCellDeathInst = *D2Vars.D2CLIENT_CellDeathInst;
CellFile* pCellDeathHC = *D2Vars.D2CLIENT_CellDeathHC;
int nDrawYpos = *D2Vars.D2CLIENT_ScreenHeight / 2 - 94;
D2Funcs.D2WIN_DrawCellFile(pCellDeathHC, *D2Vars.D2CLIENT_ScreenViewWidth / 2, nDrawYpos, 1, DRAW_MODE_NORMAL, COL_RED);
nDrawYpos += 48;
if (!nRespawnTimer)
{
DEBUGMSG("Setting Respawn time on %d s", gRespawnTime)
nRespawnTimer = GetTickCount() + (gRespawnTime * 1000);
}
if (nRespawnTimer > GetTickCount())
{
D2Funcs.D2WIN_SetTextSize(2);
wostringstream wTimerStr;
unsigned int nTime = (nRespawnTimer - GetTickCount()) / 1000;
wTimerStr << "Time to respawn: " << nTime;
int xPosTimer = *D2Vars.D2CLIENT_ScreenViewWidth / 2 - D2Funcs.D2WIN_GetTextWidth(wTimerStr.str().c_str()) / 2;
D2Funcs.D2WIN_DrawText(wTimerStr.str().c_str(), xPosTimer, nDrawYpos, COL_RED, 1);
}
else
{
D2Funcs.D2WIN_DrawCellFile(pCellDeathInst, *D2Vars.D2CLIENT_ScreenViewWidth / 2, nDrawYpos, 1, DRAW_MODE_NORMAL, COL_RED);
}
if ((*D2Vars.D2LAUNCH_BnData)->CharFlags & 4)
{
wchar_t wGoldLost[256];
wchar_t* strGoldLost = D2Funcs.D2LANG_GetLocaleText(5096); // Your deeds...
nDrawYpos += 48;
D2Funcs.D2WIN_SetTextSize(2);
int goldstrlen = D2Funcs.D2WIN_GetTextWidth(wGoldLost);
D2Funcs.D2WIN_DrawText(wGoldLost, *D2Vars.D2CLIENT_ScreenViewWidth / 2 - goldstrlen / 2, nDrawYpos, COL_RED, 1);
}
else
{
int nGoldLost = D2Funcs.D2COMMON_GetStatSigned(pPlayerUnit, 175, 0);
if (nGoldLost)
{
wchar_t wGoldLost[256];
wchar_t* strGoldLost = D2Funcs.D2LANG_GetLocaleText(5094); // Death takes its %d...
swprintf_s(wGoldLost, 256, strGoldLost, nGoldLost);
nDrawYpos += 48;
D2Funcs.D2WIN_SetTextSize(2);
int goldstrlen = D2Funcs.D2WIN_GetTextWidth(wGoldLost);
D2Funcs.D2WIN_DrawText(wGoldLost, *D2Vars.D2CLIENT_ScreenViewWidth / 2 - goldstrlen / 2, nDrawYpos, COL_RED, 1);
}
if (*D2Vars.D2CLIENT_ServerDifficulty)
{
D2Funcs.D2WIN_SetTextSize(2);
wchar_t* strLostExp = D2Funcs.D2LANG_GetLocaleText(5095); // You have lost exp...
int xPosLostExp = *D2Vars.D2CLIENT_ScreenViewWidth / 2 - D2Funcs.D2WIN_GetTextWidth(strLostExp) / 2;
D2Funcs.D2WIN_DrawText(strLostExp, xPosLostExp, nDrawYpos + 48, 1, 1);
}
}
}