Skip to content
Permalink
Browse files

lua crash-proof, zoom with scroll, alt highlight kind of works with z…

…oom, packets broken
  • Loading branch information...
qndel committed Sep 15, 2018
1 parent da8da64 commit 2137ebd43f7a9d7d9813452ff403ba1b1a2ee9a6
BIN +3.34 KB (100%) Infernity.zip
Binary file not shown.
@@ -348,22 +348,49 @@ void AddItemToDrawQueue(int x, int y, int id) {
int rarity = GetItemRarity(id);
std::string name(plr[myplr]._pName);
std::string itemName(textOnGround);

lootFilterData lfd = luaLootFilter(name, plr[myplr]._pClass, itemName, it->_itype, (int)it->_iLoc, rarity, GetItemColor(id));
if (lfd.show == false) { return; }
int centerXOffset = GetTextWidth((char*)lfd.name.c_str()) ;
if (zoomflag) {

int targetHeight = GLOBAL_HEIGHT - GLOBAL_HEIGHT * globalScrollZoom / 200;
int targetWidth = GLOBAL_WIDTH - GLOBAL_WIDTH * globalScrollZoom / 200;
int widthDiff = GLOBAL_WIDTH - targetWidth;
int heightDiff = GLOBAL_HEIGHT - targetHeight;

//x += widthDiff/4;
//y += widthDiff/4;
std::stringstream ss;



int distToCenterX = abs(ScreenWidth/2-x);
int distToCenterY = abs(ScreenHeight / 2 - y);
if (x <= ScreenWidth / 2) {
x = ScreenWidth / 2 - distToCenterX - distToCenterX * (globalScrollZoom) / 100;
}
else {
x = ScreenWidth / 2 + distToCenterX + distToCenterX * (globalScrollZoom) / 100;
}

if (y <= ScreenHeight / 2) {
y = ScreenHeight / 2 - distToCenterY - distToCenterY * (globalScrollZoom) / 100;
}
else {
y = ScreenHeight / 2 + distToCenterY + distToCenterY * (globalScrollZoom) / 100;
}

x -= centerXOffset / 2 + 20;
y -= 193;
}
else {


x -= centerXOffset + 20;
y -= 0;

}
drawQ.push_back(drawingQueue(x, y, GetTextWidth((char*)lfd.name.c_str()), 13, it->_ix, it->_iy, id, lfd.color2, lfd.name, 1, lfd.r, lfd.g,lfd.b));

//ss << x << " " << y << " ";

//NetSendCmdString(1 << myplr, ss.str().c_str());
//x += x globalScrollZoom / 100;
//y += y * globalScrollZoom / 100;
drawQ.push_back(drawingQueue(x, y, GetTextWidth((char*)lfd.name.c_str()), 13, it->_ix, it->_iy, id, lfd.color2, lfd.name, 1, lfd.r, lfd.g,lfd.b));
}

void HighlightItemsNameOnMap()
@@ -3265,12 +3265,14 @@ void __cdecl DrawSpellBook()
v5 = v4 >> 6;
v12 = v4 >> 6;
GetDamageAmt(v2, &sel, &v11);
sel = sel*CalculateSpellPower(myplr)/100;
v11 = v11*CalculateSpellPower(myplr) / 100;
if ( sel == -1 )
if (sel == -1) {
sprintf(tempstr, "Mana: %i Dam: n/a", v5);
else
}
else {
sel = sel * CalculateSpellPower(myplr, v2, v7) / 100;
v11 = v11 * CalculateSpellPower(myplr, v2, v7) / 100;
sprintf(tempstr, "Mana: %i Dam: %i - %i", v5, sel, v11);
}
if ( v2 == SPL_BONESPIRIT )
sprintf(tempstr, "Mana: %i Dam: 1/8 tgt hp", v12);
PrintSBookStr(10, v8, 0, tempstr, 0);
@@ -652,10 +652,12 @@ void __cdecl CheckCursMove()
LABEL_10:
if ( MouseY >= (352 + GetHeightDiff()) && track_isscrolling() )
v1 = (352+GetHeightDiff());
if ( !zoomflag )
if ( true) // !zoomflag
{
v0 >>= 1;
v1 >>= 1;
//v0 >>= 1;
//v1 >>= 1;
v0 -= v0 * globalScrollZoom / 200;
v1 -= v1 * globalScrollZoom / 200;
}
v2 = v0 - ScrollInfo._sxoff;
v3 = v1 - ScrollInfo._syoff;
@@ -675,7 +677,9 @@ void __cdecl CheckCursMove()
v4 = v3 >> 5;
v5 = v3 & 0x1F;
v76 = v2 & 0x3F;
v6 = (v2 >> 6) + (v3 >> 5) + ViewX - (zoomflag != 0 ? ScreenWidth/64 : ScreenWidth/128);
//v6 = (v2 >> 6) + (v3 >> 5) + ViewX - (zoomflag != 0 ? ScreenWidth/64 : ScreenWidth/128);
int zoomStuff = ScreenWidth / 64 - ScreenWidth * globalScrollZoom / 12800;
v6 = (v2 >> 6) + (v3 >> 5) + ViewX - zoomStuff;
v7 = v76 >> 1;
v8 = v4 + ViewY - (v2 >> 6);
if ( v5 < v76 >> 1 )
@@ -1293,7 +1297,6 @@ void __cdecl CheckCursMove()
// 4B8CC1: using guessed type char pcursobj;
// 4B8CC2: using guessed type char pcursplr;
// 4B8CCC: using guessed type int dword_4B8CCC;
// 52569C: using guessed type int zoomflag;
// 52575C: using guessed type int doomflag;
// 5BB1ED: using guessed type char leveltype;
// 69BD04: using guessed type int questlog;
@@ -14,7 +14,6 @@ int glSeedTbl[NUMLEVELS];
int gbRunGame; // weak
int glMid3Seed[NUMLEVELS];
int gbRunGameResult; // weak
int zoomflag; // weak
int gbProcessPlayers; // weak
int glEndSeed[NUMLEVELS];
int dword_5256E8; // weak
@@ -235,7 +234,6 @@ void __fastcall run_game_loop(int uMsg)
void __fastcall start_game(int uMsg)
{
cineflag = 0;
zoomflag = 1;
InitCursor();
InitLightTable();
LoadDebugGFX();
@@ -247,7 +245,6 @@ void __fastcall start_game(int uMsg)
sgbMouseDown = 0;
track_repeat_walk(0);
}
// 52569C: using guessed type int zoomflag;
// 525718: using guessed type char cineflag;
// 525748: using guessed type char sgbMouseDown;

@@ -764,6 +761,26 @@ LRESULT __stdcall GM_Game(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
return 0;
}


if (uMsg == WM_MOUSEWHEEL)
{
if ((short)HIWORD(wParam) < 0)
{
if (globalScrollZoom > 0) {
globalScrollZoom -= 5;
}
}
else
{
if (globalScrollZoom < 100) {
globalScrollZoom += 5;
}
}
return 0;
}


if ( uMsg != WM_RBUTTONUP )
{
if ( uMsg == WM_CAPTURECHANGED )
@@ -1863,7 +1880,6 @@ void __fastcall PressChar(int vkey)
}
case 'Z':
case 'z':
zoomflag = zoomflag == 0;
return;
#ifdef _DEBUG
case ')':
@@ -1971,14 +1987,6 @@ void __fastcall PressChar(int vkey)
}
}
}
// 4B84DC: using guessed type int dropGoldFlag;
// 4B8968: using guessed type int sbookflag;
// 4B8C98: using guessed type int spselflag;
// 52569C: using guessed type int zoomflag;
// 525740: using guessed type int PauseMode;
// 52575C: using guessed type int doomflag;
// 69BD04: using guessed type int questlog;
// 6AA705: using guessed type char stextflag;

void __cdecl LoadLvlGFX()
{
@@ -14,7 +14,6 @@ extern int glSeedTbl[NUMLEVELS];
extern int gbRunGame; // weak
extern int glMid3Seed[NUMLEVELS];
extern int gbRunGameResult; // weak
extern int zoomflag; // weak
extern int gbProcessPlayers; // weak
extern int glEndSeed[NUMLEVELS];
extern int dword_5256E8; // weak
@@ -15,6 +15,7 @@ char gbBackBuf; // weak
char gbEmulate; // weak
HMODULE ghDiabMod; // idb
int currentGameState=0;
int globalScrollZoom = 0;
void setGameState(int state) {
currentGameState = state;
lpDDSPrimary->UpdateOverlayDisplay(state);
@@ -1901,7 +1901,7 @@ void PrintDebugInfo() {
std::stringstream ss;
int isActivated = -1;
if (pcursmonst != -1) { isActivated = monster[pcursmonst].isActivated; }
ss << "debuginfo: " << MouseX << " " << MouseY << " " << (int)plr[myplr]._pSplLvl[plr[myplr]._pRSpell] << " " << (int)plr[myplr]._pISplLvlAdd;
ss << "debuginfo: " << MouseX << " " << MouseY << " " << globalScrollZoom;
if (played == false) {
PlaySFX(num++);
played = true;
@@ -2016,6 +2016,46 @@ void DrawXpBar()
}
}
}
bool AreAffixesGoodForItem(int i, char affix) {
std::set<char> uselessAffixes;
uselessAffixes.insert(IPL_DUR);
uselessAffixes.insert(IPL_INDESTRUCTIBLE);

switch (item[i]._itype) {
case ITYPE_SWORD:
case ITYPE_AXE:
case ITYPE_STAFF:
case ITYPE_MACE:
uselessAffixes.insert(IPL_ACP);
uselessAffixes.insert(IPL_LIGHT_ARROWS);
uselessAffixes.insert(IPL_FIRE_ARROWS);
break;
case ITYPE_BOW:
uselessAffixes.insert(IPL_ACP);
uselessAffixes.insert(IPL_LIGHTDAM);
uselessAffixes.insert(IPL_FIREDAM);

break;
case ITYPE_SHIELD:
uselessAffixes.insert(IPL_LIGHT_ARROWS);
uselessAffixes.insert(IPL_FIRE_ARROWS);
break;
case ITYPE_LARMOR:
case ITYPE_HELM:
case ITYPE_MARMOR:
case ITYPE_HARMOR:
break;
case ITYPE_RING:
case ITYPE_AMULET:
uselessAffixes.insert(IPL_ACP);
break;
default:
break;
}
return uselessAffixes.find(affix) == uselessAffixes.end();
}


bool AreAffixesGood(char p1, char p2) {
if (p1 == p2) { return false; }
map<int, set<int> > sadAffix;
@@ -2038,6 +2078,7 @@ bool AreAffixesGood(char p1, char p2) {

sadAffix[IPL_GETHIT] = { IPL_GETHIT_CURSE };
sadAffix[IPL_LIFE] = { IPL_LIFE_CURSE };
sadAffix[IPL_ACP] = { IPL_ACP_CURSE};
sadAffix[IPL_MANA] = { IPL_MANA_CURSE };
sadAffix[IPL_DUR_CURSE] = { IPL_DUR,IPL_INDESTRUCTIBLE };
sadAffix[IPL_TOHIT_DAMP_CURSE] = { IPL_TOHIT_CURSE,IPL_TOHIT,IPL_TOHIT_DAMP,IPL_DAMP };
@@ -2068,7 +2109,8 @@ void GenerateRareUniqueAffix(int i, int x, int y, int minlvl, int maxlvl, std::s
for (auto f : powers) {
if (!AreAffixesGood(f, PL_UPrefix[prefIter].PLPower)) { allGood = false; break; }
}
if (PL_UPrefix[prefIter].PLMinLvl >= minlvl && PL_UPrefix[prefIter].PLMinLvl <= maxlvl && PL_UPrefix[prefIter].PLOk && allGood==true)
bool affixGood = AreAffixesGoodForItem(i, PL_UPrefix[prefIter].PLPower);
if (PL_UPrefix[prefIter].PLMinLvl >= minlvl && PL_UPrefix[prefIter].PLMinLvl <= maxlvl && PL_UPrefix[prefIter].PLOk && allGood==true && affixGood==true)
{
pref[local_pref_iter++] = prefIter;
if (PL_Prefix[prefIter].PLDouble) {
@@ -2103,7 +2145,8 @@ void GenerateRareUniqueAffix(int i, int x, int y, int minlvl, int maxlvl, std::s
for (auto f : powers) {
if (!AreAffixesGood(f, PL_USuffix[sufIter].PLPower)) { allGood = false; break; }
}
if (PL_USuffix[sufIter].PLMinLvl >= minlvl && PL_USuffix[sufIter].PLMinLvl <= maxlvl && PL_Suffix[sufIter].PLOk && allGood==true)
bool affixGood = AreAffixesGoodForItem(i, PL_USuffix[sufIter].PLPower);
if (PL_USuffix[sufIter].PLMinLvl >= minlvl && PL_USuffix[sufIter].PLMinLvl <= maxlvl && PL_Suffix[sufIter].PLOk && allGood==true && affixGood==true)
{
suf[local_suf_iter++] = sufIter;
if (PL_USuffix[sufIter].PLDouble) {
@@ -2147,7 +2190,8 @@ void GenerateRareAffix(int i,int x, int y, int minlvl, int maxlvl, char prefPowe
do {
bool prefGood = AreAffixesGood(prefPower, PL_UPrefix[prefIter].PLPower);
bool sufGood = AreAffixesGood(sufPower, PL_UPrefix[prefIter].PLPower);
if (PL_UPrefix[prefIter].PLMinLvl >= minlvl && PL_UPrefix[prefIter].PLMinLvl <= maxlvl && PL_UPrefix[prefIter].PLOk && prefGood && sufGood)
bool affixGood = AreAffixesGoodForItem(i, PL_UPrefix[prefIter].PLPower);
if (PL_UPrefix[prefIter].PLMinLvl >= minlvl && PL_UPrefix[prefIter].PLMinLvl <= maxlvl && PL_UPrefix[prefIter].PLOk && prefGood && sufGood && affixGood)
{
pref[local_pref_iter++] = prefIter;
if (PL_Prefix[prefIter].PLDouble) {
@@ -2180,7 +2224,8 @@ void GenerateRareAffix(int i,int x, int y, int minlvl, int maxlvl, char prefPowe
do {
bool prefGood = AreAffixesGood(prefPower, PL_USuffix[sufIter].PLPower);
bool sufGood = AreAffixesGood(sufPower, PL_USuffix[sufIter].PLPower);
if (PL_USuffix[sufIter].PLMinLvl >= minlvl && PL_USuffix[sufIter].PLMinLvl <= maxlvl && PL_Suffix[sufIter].PLOk && prefGood && sufGood)
bool affixGood = AreAffixesGoodForItem(i, PL_USuffix[sufIter].PLPower);
if (PL_USuffix[sufIter].PLMinLvl >= minlvl && PL_USuffix[sufIter].PLMinLvl <= maxlvl && PL_Suffix[sufIter].PLOk && prefGood && sufGood && affixGood)
{
suf[local_suf_iter++] = sufIter;
if (PL_USuffix[sufIter].PLDouble) {
@@ -78,7 +78,7 @@ void ReloadConfig();
bool CanPutToBelt(int miscId);
int FreeSlotOnBelt();
bool CanRun(int pnum);
int CalculateSpellPower(int pnum);
int CalculateSpellPower(int pnum, int spell, int spellType);
int MonstersInCombat(int pnum);
int GetTextWidth(char* s);
void PrintDebugInfo();
@@ -111,7 +111,7 @@ extern int currentGameState;
void setGameState(int state);
void fatalLua(const char* message);
void LuaInit();

void DrawGame(int StartX, int StartY, bool isTown);

extern std::map<std::string, bool> BoolConfig;
extern std::map<std::string, int> IntConfig;
@@ -128,6 +128,7 @@ extern int HighlightedItemCol;
extern bool ShouldHighlightItems;
extern lua_State* L;
extern bool lootFilterBroken;
extern int globalScrollZoom;

// try versioning struct size
#define countof( a ) __crt_countof( a )
@@ -650,27 +650,7 @@ void __cdecl SetDungeonMicros()
while ( (signed int)v8 < (signed int)dpiece_defs_map_2[0][16] ); /* check */
gendung_418D91();
gendung_4192C2();
if ( zoomflag )
{
scr_pix_width = 640;
scr_pix_height = 352;
dword_5C2FF8 = 10;
dword_5C2FFC = 11;
}
else
{
scr_pix_width = 384;
scr_pix_height = 224;
dword_5C2FF8 = 6;
dword_5C2FFC = 7;
}
}
// 52569C: using guessed type int zoomflag;
// 5BB1ED: using guessed type char leveltype;
// 5C2FF8: using guessed type int dword_5C2FF8;
// 5C2FFC: using guessed type int dword_5C2FFC;
// 5C3000: using guessed type int scr_pix_width;
// 5C3004: using guessed type int scr_pix_height;

void __cdecl DRLG_InitTrans()
{
@@ -108,7 +108,7 @@ const PLStruct PL_Prefix[84] =

const PLStruct PL_UPrefix[] =
{
{ "Tin", IPL_TOHIT_CURSE, 6, 10, 3, PLT_WEAP | PLT_BOW | PLT_MISC, 0, 1, 0, 0, 0, -3 },
{ "Tin", IPL_TOHIT_CURSE, 6, 10, 3, PLT_WEAP | PLT_BOW | PLT_MISC, 0, 1, 0, 0, 0, -3 },
{ "Brass", IPL_TOHIT_CURSE, 1, 5, 1, PLT_WEAP | PLT_BOW | PLT_MISC, 0, 1, 0, 0, 0, -2 },
{ "Bronze", IPL_TOHIT, 1, 5, 1, PLT_WEAP | PLT_BOW | PLT_MISC, 0, 1, 1, 100, 500, 2 },
{ "Iron", IPL_TOHIT, 6, 10, 4, PLT_WEAP | PLT_BOW | PLT_MISC, 0, 1, 1, 600, 1000, 3 },
@@ -509,7 +509,7 @@ void __fastcall LoadPlayer(int i)
}

if (SaveVersion <= 3) {
for (int ii = 0; ii < 100; ++ii) {
for (int ii = 0; ii < MAX_STASH_TABS; ++ii) {
strcpy(plr[i].StashNames[ii], "Click to rename");
plr[i].StashNumInv[ii] = 0;
for (int j = 0; j < 40; ++j) {

0 comments on commit 2137ebd

Please sign in to comment.
You can’t perform that action at this time.