Skip to content

Instantly share code, notes, and snippets.

@Langerz82
Last active December 18, 2019 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Langerz82/a9d98abcc164dc000d15bec2b89b3469 to your computer and use it in GitHub Desktop.
Save Langerz82/a9d98abcc164dc000d15bec2b89b3469 to your computer and use it in GitHub Desktop.
diff --git a/Diablo.vcxproj b/Diablo.vcxproj
index dcdb974..261b9a8 100644
--- a/Diablo.vcxproj
+++ b/Diablo.vcxproj
@@ -198,6 +197,7 @@
<ClCompile Include="Source\towners.cpp" />
<ClCompile Include="Source\track.cpp" />
<ClCompile Include="Source\trigs.cpp" />
+ <ClCompile Include="Source\util.cpp" />
<ClCompile Include="Source\wave.cpp" />
<ClCompile Include="Source\render.cpp" />
</ItemGroup>
@@ -278,6 +278,7 @@
<ClInclude Include="Source\towners.h" />
<ClInclude Include="Source\track.h" />
<ClInclude Include="Source\trigs.h" />
+ <ClInclude Include="Source\util.h" />
<ClInclude Include="Source\wave.h" />
<ClInclude Include="Source\render.h" />
<ClInclude Include="structs.h" />
diff --git a/Diablo.vcxproj.filters b/Diablo.vcxproj.filters
index 5fb895a..5215669 100644
--- a/Diablo.vcxproj.filters
+++ b/Diablo.vcxproj.filters
@@ -229,6 +229,9 @@
<ClCompile Include="3rdParty\PKWare\implode.cpp">
<Filter>PKWare</Filter>
</ClCompile>
+ <ClCompile Include="Source\util.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="Diablo.ico">
@@ -463,5 +466,8 @@
<ClInclude Include="3rdParty\PKWare\pkware.h">
<Filter>PKWare</Filter>
</ClInclude>
+ <ClInclude Include="Source\util.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/Source/control.cpp b/Source/control.cpp
index 8b84617..15b4ee1 100644
--- a/Source/control.cpp
+++ b/Source/control.cpp
@@ -1469,8 +1469,8 @@ void __cdecl InitControlPan()
char v4; // al
unsigned char *v5; // eax
- v0 = WorkingWidth * 144;// 0x16800;
- if (gbMaxPlayers != 1)
+ //v0 = WorkingWidth * 144;// 0x16800;
+ //if (gbMaxPlayers != 1)
v0 = WorkingWidth * 288;// 0x2D000;
pBtmBuff = DiabloAllocPtr(v0);
memset(pBtmBuff, 0, v0);
@@ -1494,8 +1494,8 @@ void __cdecl InitControlPan()
pStatusPanel = 0;
mem_free_dbg(v2);
talkflag = 0;
- if ( gbMaxPlayers != 1 )
- {
+ //if ( gbMaxPlayers != 1 )
+ //{
pTalkPanel = LoadFileInMem("CtrlPan\\TalkPanl.CEL", 0);
CelDecodeRect((char *)pBtmBuff, 0, 287, ScreenWidth, (char *)pTalkPanel, 1, 640);
v3 = pTalkPanel;
@@ -1509,7 +1509,7 @@ void __cdecl InitControlPan()
talkbtndown[1] = 0;
sgszTalkMsg[0] = 0;
talkbtndown[2] = 0;
- }
+ //}
panelflag = 0;
lvlbtndown = 0;
pPanelButtons = LoadFileInMem("CtrlPan\\Panel8bu.CEL", 0);
@@ -3920,12 +3920,14 @@ void __cdecl control_reset_talk_msg()
while ( v1 < 4 );
if ( !msgcmd_add_server_cmd_W(sgszTalkMsg) )
NetSendCmdString(v0, sgszTalkMsg);
+
+ RecvCmdString(sgszTalkMsg);
}
void __cdecl control_type_message()
{
- if ( gbMaxPlayers != 1 )
- {
+ //if ( gbMaxPlayers != 1 )
+ //{
sgszTalkMsg[0] = 0;
talkflag = 1;
frame = 1;
@@ -3935,7 +3937,7 @@ void __cdecl control_type_message()
sgbPlrTalkTbl = 144;
drawpanflag = 255;
sgbTalkSavePos = sgbNextTalkSave;
- }
+ //}
}
// 4B84CC: using guessed type char sgbNextTalkSave;
// 4B84CD: using guessed type char sgbTalkSavePos;
@@ -3960,7 +3962,7 @@ int __fastcall control_talk_last_key(int a1)
signed int v3; // eax
v1 = a1;
- if ( gbMaxPlayers == 1 || !talkflag || (unsigned int)a1 < VK_SPACE )
+ if ( /*gbMaxPlayers == 1 ||*/ !talkflag || (unsigned int)a1 < VK_SPACE )
return 0;
v3 = strlen(sgszTalkMsg);
if ( v3 < 78 )
@@ -3978,7 +3980,7 @@ int __fastcall control_presskeys(int a1)
signed int v1; // eax
char v2; // cl
- if ( gbMaxPlayers != 1 && talkflag )
+ if ( /*gbMaxPlayers != 1 &&*/ talkflag )
{
switch ( a1 )
{
diff --git a/Source/items.cpp b/Source/items.cpp
index 3282548..5a83d87 100644
--- a/Source/items.cpp
+++ b/Source/items.cpp
@@ -1085,7 +1085,8 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx)
if ( plr[p]._pLightRad != lrad && p == myplr )
{
- ChangeLightRadius(plr[p]._plid, lrad);
+ if (plr[p]._pCheatLight < lrad)
+ ChangeLightRadius(plr[p]._plid, lrad);
int pvid = plr[p]._pvid;
if ( lrad >= 10 )
@@ -1094,7 +1095,8 @@ void __fastcall CalcPlrItemVals(int p, BOOL Loadgfx)
}
else
{
- ChangeVisionRadius(pvid, 10);
+ if (plr[p]._pCheatLight < lrad)
+ ChangeVisionRadius(pvid, 10);
}
plr[p]._pLightRad = lrad;
diff --git a/Source/msg.cpp b/Source/msg.cpp
index 539ebfa..49760a0 100644
--- a/Source/msg.cpp
+++ b/Source/msg.cpp
@@ -23,6 +23,7 @@ int msg_err_timer; // weak
const int msg_inf = 0x7F800000; // weak
+
struct msg_cpp_init
{
msg_cpp_init()
@@ -1391,6 +1392,43 @@ void __fastcall NetSendCmdString(int a1, const char *pszStr)
multi_send_msg_packet(v3, &cmd.bCmd, dwStrLen + 2);
}
+
+
+void __fastcall RecvCmdString(const char *pszStr)
+{
+ if (!GetConfigBoolVariable("cheats"))
+ return;
+
+ std::string str(pszStr);
+ std::vector<std::string> v = Explode(" ", str);
+
+ if (v.size() == 1)
+ {
+
+ }
+ else if (v.size() == 2)
+ {
+
+ }
+ else if (v.size() == 3)
+ {
+ if (strcmp(v[0].c_str(), "player") == 0)
+ {
+ if (strcmp(v[1].c_str(), "light") == 0)
+ {
+ int val = atoi(v[2].c_str());
+ if (val <= 0 || val > 15)
+ return;
+ plr[myplr]._pCheatLight = val;
+ plr[myplr]._pLightRad = val;
+ plr[myplr]._plid = -1;
+ plr[myplr]._plid = AddLight(plr[myplr].WorldX, plr[0].WorldY, val);
+ ChangeVisionRadius(plr[myplr]._plid, val);
+ }
+ }
+ }
+}
+
void __fastcall RemovePlrPortal(int pnum)
{
memset(&PortalsAndQuestsStuff.portal[pnum], -1, sizeof(DPortal));
diff --git a/Source/msg.h b/Source/msg.h
index a4c7d88..2bd96a7 100644
--- a/Source/msg.h
+++ b/Source/msg.h
@@ -67,6 +67,8 @@ void __fastcall NetSendCmdDelItem(BOOL bHiPri, unsigned char bLoc);
void __fastcall NetSendCmdDItem(unsigned char bHiPri, int ii);
void __fastcall NetSendCmdDamage(BOOL bHiPri, unsigned char bPlr, unsigned int dwDam);
void __fastcall NetSendCmdString(int a1, const char *pszStr);
+void __fastcall RecvCmdString(const char *pszStr);
+
void __fastcall RemovePlrPortal(int pnum);
int __fastcall ParseCmd(int pnum, TCmd *pCmd);
void __fastcall DeltaImportData(unsigned char cmd, int recv_offset);
diff --git a/Source/player.cpp b/Source/player.cpp
index 02e9927..bd55eec 100644
--- a/Source/player.cpp
+++ b/Source/player.cpp
@@ -970,6 +970,9 @@ void __fastcall CreatePlayer(int pnum, char c)
plr[pnum].NewSpellHotkeys[i] = -1;
plr[pnum].NewSpellTHotkeys[i] = -1;
}
+
+ plr[pnum]._pCheatLight = 0;
+
SetRndSeed(0);
}
@@ -1192,12 +1195,19 @@ void __fastcall InitPlayer(int pnum, BOOL FirstTime)
plr[pnum].destAction = -1;
if (pnum == myplr) {
- plr[pnum]._plid = AddLight(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum]._pLightRad);
+ if (plr[pnum]._pCheatLight < plr[pnum]._pLightRad)
+ plr[pnum]._plid = AddLight(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum]._pLightRad);
+ else
+ plr[pnum]._plid = AddLight(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum]._pCheatLight);
}
else {
plr[pnum]._plid = -1;
}
- plr[pnum]._pvid = AddVision(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum]._pLightRad, pnum == myplr);
+
+ if (plr[pnum]._pCheatLight < plr[pnum]._pLightRad)
+ plr[pnum]._pvid = AddVision(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum]._pLightRad, pnum == myplr);
+ else
+ plr[pnum]._pvid = AddVision(plr[pnum].WorldX, plr[pnum].WorldY, plr[pnum]._pCheatLight, pnum == myplr);
}
if (plr[pnum]._pClass == PC_WARRIOR) {
diff --git a/structs.h b/structs.h
index cec5911..b617781 100644
--- a/structs.h
+++ b/structs.h
@@ -584,6 +584,7 @@ struct PlayerStruct
unsigned char *_pDData;
unsigned char *_pBData;
unsigned int version;
+ unsigned int _pCheatLight;
};
struct PlayerStruct2 :PlayerStruct
diff --git a/types.h b/types.h
index ebf72d3..5baea33 100644
--- a/types.h
+++ b/types.h
@@ -19,6 +19,9 @@
#include <shlobj.h>
#include <shellapi.h>
+#include <vector>
+
+
#ifdef __GNUC__
#include <ctype.h>
#endif
@@ -130,5 +133,6 @@
#include "Source/trigs.h"
#include "Source/wave.h"
#include "Source/render.h" // linked last, likely .s/.asm
+#include "Source/util.h"
#endif
diff --git a/Source/util.cpp b/Source/util.cpp
new file mode 100644
index 0000000..ccbc856
--- /dev/null
+++ b/Source/util.cpp
@@ -0,0 +1,33 @@
+#include "util.h"
+
+std::vector<std::string> Explode(const std::string &delimiter, const std::string &str)
+{
+ std::vector<std::string> arr;
+
+ int strleng = str.length();
+ int delleng = delimiter.length();
+ if (delleng == 0)
+ return arr;//no change
+
+ int i = 0;
+ int k = 0;
+ while (i<strleng)
+ {
+ int j = 0;
+ while (i + j<strleng && j<delleng && str[i + j] == delimiter[j])
+ j++;
+ if (j == delleng)//found delimiter
+ {
+ arr.push_back(str.substr(k, i - k));
+ i += delleng;
+ k = i;
+ }
+ else
+ {
+ i++;
+ }
+ }
+ arr.push_back(str.substr(k, i - k));
+ return arr;
+}
+
diff --git a/Source/util.h b/Source/util.h
new file mode 100644
index 0000000..d2d0795
--- /dev/null
+++ b/Source/util.h
@@ -0,0 +1,13 @@
+//HEADER_GOES_HERE
+// http://www.zedwood.com/article/cpp-explode-function
+
+#ifndef __UTIL_H__
+#define __UTIL_H__
+
+#include <vector>
+#include <string>
+
+std::vector<std::string> Explode(const std::string &delimiter, const std::string &explodeme);
+
+#endif /* __UTIL_H__ */
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment