├── Diablo.ico ├── DiabloWeb.rc ├── titlemov.mp3 ├── Source ├── capture.cpp ├── capture.h ├── pfile_ex.h ├── spelldat.h ├── misdat.h ├── textdat.h ├── track.h ├── objdat.h ├── tmsg.h ├── render.h ├── monstdat.h ├── msgcmd.h ├── dead.h ├── itemdat.h ├── codec.h ├── error.h ├── dthread.h ├── pack.h ├── spells.h ├── zlib │ ├── inffast.h │ ├── uncompr.c │ ├── compress.c │ └── inftrees.h ├── interfac.h ├── ui │ ├── network.h │ ├── selhero.h │ ├── okbox.cpp │ ├── titlescreen.cpp │ ├── yesno.cpp │ ├── dialog.h │ ├── diabloui.h │ ├── main_menu.cpp │ └── event.h ├── help.h ├── doom.h ├── rmpq │ ├── locale.h │ ├── locale.cpp │ ├── checksum.h │ ├── adpcm │ │ └── adpcm.h │ ├── archive.h │ └── common.h ├── init.h ├── plrmsg.h ├── encrypt.h ├── net │ ├── abstract_net.cpp │ ├── websocket.h │ ├── loopback.h │ ├── abstract_net.h │ ├── websocket_browser.hpp │ ├── base.h │ ├── loopback.cpp │ └── websocket.cpp ├── setmaps.h ├── sync.h ├── sha.h ├── minitext.h ├── dx.h ├── trace.cpp ├── portal.h ├── cursor.h ├── nthread.h ├── debug.h ├── storm │ ├── storm.cpp │ ├── smpq.cpp │ ├── sreg.cpp │ ├── sbmp.cpp │ └── snet.cpp ├── automap.h ├── loadsave.h ├── effects.h ├── palette.h ├── wave.h ├── sound.h ├── track.cpp ├── towners.h ├── appfat.h ├── tmsg.cpp ├── gamemenu.h ├── trigs.h ├── path.h ├── asm_trans_rect.inc ├── gmenu.h ├── town.h ├── mpqapi.h ├── quests.h ├── libsmacker │ ├── smk_bitstream.h │ ├── smk_malloc.h │ ├── README │ ├── smk_bitstream.c │ ├── smk_hufftree.h │ └── smacker.h ├── init.cpp ├── themes.h ├── inv.h ├── lighting.h ├── trace.h ├── msgcmd.cpp ├── doom.cpp ├── pfile.h ├── drlg_l4.h ├── drlg_l1.h ├── multi.h ├── dthread.cpp ├── dead.cpp ├── drlg_l3.h ├── scrollrt.h ├── sha.cpp ├── gendung.h ├── appfat.cpp ├── plrmsg.cpp ├── codec.cpp ├── encrypt.cpp ├── stores.h └── portal.cpp ├── mpqcmp ├── shine │ ├── l3bitstream.h │ ├── l3mdct.h │ ├── l3loop.h │ ├── l3subband.h │ ├── reservoir.h │ ├── tables.h │ ├── huffman.h │ ├── bitstream.h │ ├── mult_noarch_gcc.h │ ├── mult_mips_gcc.h │ ├── bitstream.c │ ├── mult_sarm_gcc.h │ └── reservoir.c └── wave.cpp ├── module-post.js ├── resource.h ├── LICENSE ├── Server.vcxproj.filters ├── .clang-format ├── README.md └── DiabloWeb.sln /Diablo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d07RiV/devilution/HEAD/Diablo.ico -------------------------------------------------------------------------------- /DiabloWeb.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d07RiV/devilution/HEAD/DiabloWeb.rc -------------------------------------------------------------------------------- /titlemov.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/d07RiV/devilution/HEAD/titlemov.mp3 -------------------------------------------------------------------------------- /Source/capture.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | 3 | void CaptureScreen() 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /Source/capture.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __CAPTURE_H__ 3 | #define __CAPTURE_H__ 4 | 5 | void CaptureScreen(); 6 | 7 | #endif /* __CAPTURE_H__ */ 8 | -------------------------------------------------------------------------------- /Source/pfile_ex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // split this because significantly increases compile time 4 | std::vector<_uiheroinfo> pfile_ui_set_hero_infos(); 5 | -------------------------------------------------------------------------------- /mpqcmp/shine/l3bitstream.h: -------------------------------------------------------------------------------- 1 | #ifndef shine_BITSTREAM_H 2 | #define shine_BITSTREAM_H 3 | 4 | void shine_format_bitstream(shine_global_config *config); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /Source/spelldat.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __SPELLDAT_H__ 3 | #define __SPELLDAT_H__ 4 | 5 | extern SpellData spelldata[MAX_SPELLS]; 6 | 7 | #endif /* __SPELLDAT_H__ */ 8 | -------------------------------------------------------------------------------- /mpqcmp/shine/l3mdct.h: -------------------------------------------------------------------------------- 1 | #ifndef shine_MDCT_H 2 | #define shine_MDCT_H 3 | 4 | void shine_mdct_initialise(); 5 | void shine_mdct_sub(shine_global_config *config, int stride); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /Source/misdat.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __MISDAT_H__ 3 | #define __MISDAT_H__ 4 | 5 | extern MissileData missiledata[68]; 6 | extern MisFileData misfiledata[47]; 7 | 8 | #endif /* __MISDAT_H__ */ 9 | -------------------------------------------------------------------------------- /Source/textdat.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __TEXTDAT_H__ 3 | #define __TEXTDAT_H__ 4 | 5 | extern const TextDataStruct alltext[259]; 6 | extern const DWORD gdwAllTextEntries; 7 | 8 | #endif /* __TEXTDAT_H__ */ 9 | -------------------------------------------------------------------------------- /mpqcmp/shine/l3loop.h: -------------------------------------------------------------------------------- 1 | #ifndef L3LOOP_H 2 | #define L3LOOP_H 3 | 4 | void shine_loop_initialise(shine_global_config *config); 5 | 6 | void shine_iteration_loop(shine_global_config *config); 7 | 8 | #endif 9 | 10 | -------------------------------------------------------------------------------- /Source/track.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __TRACK_H__ 3 | #define __TRACK_H__ 4 | 5 | void track_process(); 6 | void track_repeat_walk(BOOL rep); 7 | BOOL track_isscrolling(); 8 | 9 | #endif /* __TRACK_H__ */ 10 | -------------------------------------------------------------------------------- /module-post.js: -------------------------------------------------------------------------------- 1 | Module['ready'] = new Promise(function (resolve, reject) { 2 | delete Module['then'] 3 | Module['onAbort'] = function (what) { 4 | reject(what) 5 | } 6 | addOnPostRun(function () { 7 | resolve(Module) 8 | }) 9 | }); 10 | -------------------------------------------------------------------------------- /Source/objdat.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __OBJDAT_H__ 3 | #define __OBJDAT_H__ 4 | 5 | extern int ObjTypeConv[113]; 6 | extern ObjDataStruct AllObjects[99]; 7 | extern const char *ObjMasterLoadList[56]; 8 | 9 | #endif /* __OBJDAT_H__ */ 10 | -------------------------------------------------------------------------------- /Source/tmsg.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __TMSG_H__ 3 | #define __TMSG_H__ 4 | 5 | int tmsg_get(BYTE *pbMsg, DWORD dwMaxLen); 6 | void tmsg_add(BYTE *pbMsg, BYTE bLen); 7 | void tmsg_start(); 8 | void *tmsg_cleanup(); 9 | 10 | #endif /* __TMSG_H__ */ 11 | -------------------------------------------------------------------------------- /Source/render.h: -------------------------------------------------------------------------------- 1 | #ifndef __RENDER_H__ 2 | #define __RENDER_H__ 3 | 4 | void RenderTile( BYTE *pBuff ); 5 | #define drawUpperScreen(p) RenderTile(p) 6 | #define drawLowerScreen(p) RenderTile(p) 7 | void world_draw_black_tile( BYTE *pBuff ); 8 | 9 | #endif /* __RENDER_H__ */ 10 | -------------------------------------------------------------------------------- /Source/monstdat.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __MONSTDAT_H__ 3 | #define __MONSTDAT_H__ 4 | 5 | extern MonsterData monsterdata[112]; 6 | extern char MonstConvTbl[128]; 7 | extern BYTE MonstAvailTbl[112]; 8 | extern UniqMonstStruct UniqMonst[98]; 9 | 10 | #endif /* __MONSTDAT_H__ */ 11 | -------------------------------------------------------------------------------- /Source/msgcmd.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __MSGCMD_H__ 3 | #define __MSGCMD_H__ 4 | 5 | void msgcmd_cmd_cleanup(); 6 | void msgcmd_send_chat(); 7 | BOOL msgcmd_add_server_cmd_W(const char *chat_message); 8 | void msgcmd_add_server_cmd(const char *command); 9 | 10 | #endif /* __MSGCMD_H__ */ 11 | -------------------------------------------------------------------------------- /mpqcmp/shine/l3subband.h: -------------------------------------------------------------------------------- 1 | #ifndef L3SUBBAND_H 2 | #define L3SUBBAND_H 3 | 4 | #include 5 | 6 | void shine_subband_initialise( shine_global_config *config ); 7 | void shine_window_filter_subband(int16_t **buffer, int32_t s[SBLIMIT], int k, shine_global_config *config, int stride); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /Source/dead.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DEAD_H__ 3 | #define __DEAD_H__ 4 | 5 | extern int spurtndx; 6 | extern DeadStruct dead[MAXDEAD]; 7 | extern int stonendx; 8 | 9 | void InitDead(); 10 | void AddDead(int dx, int dy, char dv, int ddir); 11 | void SetDead(); 12 | 13 | #endif /* __DEAD_H__ */ 14 | -------------------------------------------------------------------------------- /Source/itemdat.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __ITEMDAT_H__ 3 | #define __ITEMDAT_H__ 4 | 5 | extern ItemDataStruct AllItemsList[157]; 6 | extern const PLStruct PL_Prefix[84]; 7 | extern const PLStruct PL_Suffix[96]; 8 | extern const UItemStruct UniqueItemList[91]; 9 | 10 | #endif /* __ITEMDAT_H__ */ 11 | -------------------------------------------------------------------------------- /mpqcmp/shine/reservoir.h: -------------------------------------------------------------------------------- 1 | #ifndef RESERVOIR_H 2 | #define RESERVOIR_H 3 | 4 | void shine_ResvFrameBegin(int frameLength, shine_global_config *config); 5 | int shine_max_reservoir_bits (double *pe, shine_global_config *config); 6 | void shine_ResvAdjust (gr_info *gi, shine_global_config *config ); 7 | void shine_ResvFrameEnd (shine_global_config *config ); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /Source/codec.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __CODEC_H__ 3 | #define __CODEC_H__ 4 | 5 | int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword); 6 | void codec_init_key(int unused, char *pszPassword); 7 | DWORD codec_get_encoded_len(DWORD dwSrcBytes); 8 | void codec_encode(BYTE *pbSrcDst, DWORD size, int size_64, char *pszPassword); 9 | 10 | #endif /* __CODEC_H__ */ 11 | -------------------------------------------------------------------------------- /mpqcmp/shine/tables.h: -------------------------------------------------------------------------------- 1 | #ifndef TABLES_H 2 | #define TABLES_H 3 | 4 | #include "types.h" 5 | 6 | extern const int shine_slen1_tab[16]; 7 | extern const int shine_slen2_tab[16]; 8 | 9 | extern const int samplerates[9]; 10 | extern const int bitrates[16][4]; 11 | 12 | extern const int shine_scale_fact_band_index[9][23]; 13 | extern const int32_t shine_enwindow[]; 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /Source/error.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __ERROR_H__ 3 | #define __ERROR_H__ 4 | 5 | extern char msgtable[MAX_SEND_STR_LEN]; 6 | extern char msgdelay; 7 | extern char msgflag; 8 | extern char msgcnt; 9 | 10 | void InitDiabloMsg(char e); 11 | void ClrDiabloMsg(); 12 | void DrawDiabloMsg(); 13 | 14 | /* data */ 15 | extern const char *MsgStrings[44]; 16 | 17 | #endif /* __ERROR_H__ */ 18 | -------------------------------------------------------------------------------- /Source/dthread.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DTHREAD_H__ 3 | #define __DTHREAD_H__ 4 | 5 | extern unsigned int glpDThreadId; 6 | extern BOOLEAN dthread_running; 7 | 8 | void dthread_remove_player(int pnum); 9 | void dthread_send_delta(int pnum, char cmd, void *pbSrc, int dwLen); 10 | void dthread_start(); 11 | void dthread_loop(); 12 | void dthread_cleanup(); 13 | 14 | /* data */ 15 | 16 | #endif /* __DTHREAD_H__ */ 17 | -------------------------------------------------------------------------------- /Source/pack.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __PACK_H__ 3 | #define __PACK_H__ 4 | 5 | void PackPlayer(PkPlayerStruct *pPack, int pnum, BOOL manashield); 6 | void PackItem(PkItemStruct *id, ItemStruct *is); 7 | void VerifyGoldSeeds(PlayerStruct *pPlayer); 8 | void UnPackPlayer(PkPlayerStruct *pPack, int pnum, BOOL killok); 9 | void UnPackItem(PkItemStruct *is, ItemStruct *id); 10 | 11 | /* rdata */ 12 | 13 | #endif /* __PACK_H__ */ 14 | -------------------------------------------------------------------------------- /Source/spells.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __SPELLS_H__ 3 | #define __SPELLS_H__ 4 | 5 | int GetManaAmount(int id, int sn); 6 | void UseMana(int id, int sn); 7 | BOOL CheckSpell(int id, int sn, char st, BOOL manaonly); 8 | void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int caster, int spllvl); 9 | void DoResurrect(int pnum, int rid); 10 | void PlacePlayer(int pnum); 11 | void DoHealOther(int pnum, int rid); 12 | 13 | #endif /* __SPELLS_H__ */ 14 | -------------------------------------------------------------------------------- /Source/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by DiabloWeb.rc 4 | // 5 | #define IDI_ICON1 102 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 103 12 | #define _APS_NEXT_COMMAND_VALUE 40002 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /Source/interfac.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __INTERFAC_H__ 3 | #define __INTERFAC_H__ 4 | 5 | extern int progress_id; 6 | 7 | BOOL IncProgress(); 8 | void DrawCutscene(); 9 | void DrawProgress(int screen_x, int screen_y, int progress_id); 10 | void ShowProgress(unsigned int uMsg); 11 | void FreeInterface(); 12 | void InitCutscene(unsigned int uMsg); 13 | 14 | /* rdata */ 15 | 16 | extern const BYTE progress_bar_colours[3]; 17 | extern const int progress_bar_screen_pos[3][2]; 18 | 19 | #endif /* __INTERFAC_H__ */ 20 | -------------------------------------------------------------------------------- /Source/ui/network.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dialog.h" 4 | #include 5 | #include 6 | 7 | class NetworkState : public DialogState { 8 | public: 9 | virtual void onClosed() {} 10 | virtual void onGameList(const std::vector>& games) {} 11 | virtual void onJoinAccept(int player, uint64_t init_info) {} 12 | virtual void onJoinReject(int reason) {} 13 | }; 14 | 15 | GameStatePtr get_network_state(const char* name, const char* game, int difficulty); 16 | 17 | void start_multiplayer(); 18 | -------------------------------------------------------------------------------- /Source/help.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __HELP_H__ 3 | #define __HELP_H__ 4 | 5 | extern int help_select_line; 6 | extern int dword_634494; 7 | extern int helpflag; 8 | extern int displayinghelp[22]; 9 | extern int HelpTop; 10 | 11 | void InitHelp(); 12 | void DrawHelp(); 13 | void DrawHelpLine(int always_0, int help_line_nr, char *text, char color); 14 | void DisplayHelp(); 15 | void HelpScrollUp(); 16 | void HelpScrollDown(); 17 | 18 | /* rdata */ 19 | extern const char gszHelpText[]; 20 | 21 | #endif /* __HELP_H__ */ 22 | -------------------------------------------------------------------------------- /Source/doom.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DOOM_H__ 3 | #define __DOOM_H__ 4 | 5 | extern int doom_quest_time; 6 | extern int doom_stars_drawn; 7 | extern BYTE *pDoomCel; 8 | extern int doomflag; 9 | extern int DoomQuestState; 10 | 11 | /* 12 | void doom_reset_state(); 13 | void doom_play_movie(); 14 | */ 15 | int doom_get_frame_from_time(); 16 | void doom_alloc_cel(); 17 | void doom_cleanup(); 18 | void doom_load_graphics(); 19 | void doom_init(); 20 | void doom_close(); 21 | void doom_draw(); 22 | 23 | #endif /* __DOOM_H__ */ 24 | -------------------------------------------------------------------------------- /Source/rmpq/locale.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mpq { 6 | 7 | namespace Locale { 8 | 9 | enum : uint16_t { 10 | Neutral = 0x0000, 11 | Chinese = 0x0404, 12 | Czech = 0x0405, 13 | German = 0x0407, 14 | English = 0x0409, 15 | Spanish = 0x040A, 16 | French = 0x040C, 17 | Italian = 0x0410, 18 | Japanese = 0x0411, 19 | Korean = 0x0412, 20 | Polish = 0x0415, 21 | Portuguese = 0x0416, 22 | Russian = 0x0419, 23 | EnglishUK = 0x0809, 24 | }; 25 | 26 | char const* toString(uint16_t); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Source/init.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __INIT_H__ 3 | #define __INIT_H__ 4 | 5 | extern _SNETVERSIONDATA fileinfo; 6 | extern int gbActive; 7 | extern HANDLE diabdat_mpq; 8 | 9 | /* rdata */ 10 | 11 | /* data */ 12 | 13 | extern char gszVersionNumber[MAX_PATH]; 14 | extern char gszProductName[MAX_PATH]; 15 | extern uint32_t gdwProductVersion; 16 | 17 | void set_client_version(int v0, int v1, int v2); 18 | 19 | void api_current_save_id(int id); 20 | 21 | void api_open_keyboard(int x0, int y0, int x1, int y1, int len); 22 | void api_close_keyboard(); 23 | 24 | #endif /* __INIT_H__ */ 25 | -------------------------------------------------------------------------------- /Source/plrmsg.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __PLRMSG_H__ 3 | #define __PLRMSG_H__ 4 | 5 | extern _plrmsg plr_msgs[PMSG_COUNT]; 6 | 7 | void plrmsg_delay(BOOL delay); 8 | char *ErrorPlrMsg(const char *pszMsg); 9 | size_t __cdecl EventPlrMsg(const char *pszFmt, ...); 10 | void SendPlrMsg(int pnum, const char *pszStr); 11 | void ClearPlrMsg(); 12 | void InitPlrMsg(); 13 | void DrawPlrMsg(); 14 | void PrintPlrMsg(DWORD x, DWORD y, DWORD width, const char *str, BYTE col); 15 | 16 | /* rdata */ 17 | 18 | extern const char text_color_from_player_num[MAX_PLRS + 1]; 19 | 20 | #endif /* __PLRMSG_H__ */ 21 | -------------------------------------------------------------------------------- /Source/encrypt.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __ENCRYPT_H__ 3 | #define __ENCRYPT_H__ 4 | 5 | extern DWORD hashtable[1280]; 6 | 7 | void Decrypt(void *block, DWORD size, DWORD key); 8 | void Encrypt(void *block, DWORD size, DWORD key); 9 | DWORD Hash(const char *s, int type); 10 | void InitHash(); 11 | int PkwareCompress(void *buf, int size); 12 | unsigned int __cdecl PkwareBufferRead(char *buf, unsigned int *size, void *param); 13 | void __cdecl PkwareBufferWrite(char *buf, unsigned int *size, void *param); 14 | void PkwareDecompress(void *param, int recv_size, int dwMaxBytes); 15 | 16 | #endif /* __ENCRYPT_H__ */ 17 | -------------------------------------------------------------------------------- /Source/net/abstract_net.cpp: -------------------------------------------------------------------------------- 1 | #include "abstract_net.h" 2 | #include "loopback.h" 3 | #include "websocket.h" 4 | 5 | namespace net { 6 | 7 | abstract_net::~abstract_net() 8 | { 9 | } 10 | 11 | std::unique_ptr abstract_net::make_net(provider_t provider, const char* param) { 12 | if (provider == provider_t::LOOPBACK) { 13 | return std::make_unique(); 14 | } else if (provider == provider_t::WEBSOCKET) { 15 | return std::make_unique(); 16 | } else { 17 | ERROR_MSG("unknown provider type"); 18 | return std::make_unique(); 19 | } 20 | } 21 | 22 | } // namespace net 23 | -------------------------------------------------------------------------------- /Source/setmaps.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __SETMAPS_H__ 3 | #define __SETMAPS_H__ 4 | 5 | int ObjIndex(int x, int y); 6 | void AddSKingObjs(); 7 | void AddSChamObjs(); 8 | void AddVileObjs(); 9 | void DRLG_SetMapTrans(const char *sFileName); 10 | void LoadSetMap(); 11 | 12 | /* rdata */ 13 | extern BYTE SkelKingTrans1[8]; 14 | extern BYTE SkelKingTrans2[8]; 15 | extern BYTE SkelKingTrans3[20]; 16 | extern BYTE SkelKingTrans4[28]; 17 | extern BYTE SkelChamTrans1[20]; 18 | extern BYTE SkelChamTrans2[8]; 19 | extern BYTE SkelChamTrans3[36]; 20 | extern const char *quest_level_names[]; 21 | 22 | #endif /* __SETMAPS_H__ */ 23 | -------------------------------------------------------------------------------- /Source/sync.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __SYNC_H__ 3 | #define __SYNC_H__ 4 | 5 | extern WORD sync_word_6AA708[MAXMONSTERS]; 6 | extern int sgnMonsters; 7 | extern WORD sgwLRU[MAXMONSTERS]; 8 | extern int sgnSyncItem; 9 | 10 | DWORD sync_all_monsters(const BYTE *pbBuf, DWORD dwMaxLen); 11 | void sync_one_monster(); 12 | BOOL sync_monster_active(TSyncMonster *p); 13 | void sync_monster_pos(TSyncMonster *p, int ndx); 14 | BOOL sync_monster_active2(TSyncMonster *p); 15 | void SyncPlrInv(TSyncHeader *pHdr); 16 | DWORD sync_update(int pnum, const BYTE *pbBuf); 17 | void sync_monster(int pnum, const TSyncMonster *p); 18 | void sync_init(); 19 | 20 | #endif /* __SYNC_H__ */ 21 | -------------------------------------------------------------------------------- /Source/sha.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __SHA_H__ 3 | #define __SHA_H__ 4 | 5 | /* 6 | * Define the SHA1 circular left shift macro 7 | */ 8 | #define SHA1CircularShift(bits, word) \ 9 | (((word) << (bits)) | ((word) >> (32 - (bits)))) 10 | #define SHA1HashSize 20 11 | 12 | //sha 13 | 14 | void SHA1Clear(); 15 | void SHA1Result(int n, char Message_Digest[SHA1HashSize]); 16 | void SHA1Calculate(int n, const char *data, char Message_Digest[SHA1HashSize]); 17 | void SHA1Input(SHA1Context *context, const char *message_array, int len); 18 | void SHA1ProcessMessageBlock(SHA1Context *context); 19 | void SHA1Reset(int n); 20 | void SHA1Init(SHA1Context *context); 21 | 22 | #endif /* __SHA_H__ */ 23 | -------------------------------------------------------------------------------- /Source/minitext.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __MINITEXT_H__ 3 | #define __MINITEXT_H__ 4 | 5 | extern int qtexty; 6 | extern const char *qtextptr; 7 | extern int qtextSpd; 8 | extern BOOLEAN qtextflag; 9 | extern int scrolltexty; 10 | extern BYTE *pMedTextCels; 11 | extern BYTE *pTextBoxCels; 12 | 13 | void FreeQuestText(); 14 | void InitQuestText(); 15 | void InitQTextMsg(int m); 16 | void DrawQTextBack(); 17 | void PrintQTextChr(int sx, int sy, BYTE *pCelBuff, int nCel); 18 | void DrawQText(); 19 | 20 | /* rdata */ 21 | 22 | extern const BYTE mfontframe[127]; 23 | extern const BYTE mfontkern[56]; 24 | 25 | /* data */ 26 | 27 | extern int qscroll_spd_tbl[9]; 28 | 29 | #endif /* __MINITEXT_H__ */ 30 | -------------------------------------------------------------------------------- /Source/net/websocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "base.h" 7 | 8 | class websocket_impl; 9 | 10 | namespace net { 11 | 12 | class websocket_client : public base { 13 | public: 14 | websocket_client(); 15 | ~websocket_client(); 16 | 17 | void create(std::string name, std::string passwd, uint32_t difficulty) override; 18 | void join(std::string name, std::string passwd) override; 19 | 20 | void poll() override; 21 | void send(const packet& pkt) override; 22 | 23 | private: 24 | uint32_t cookie_; 25 | bool closed_ = false; 26 | std::unique_ptr impl_; 27 | void handle_packet(const uint8_t* data, size_t size); 28 | }; 29 | 30 | } // namespace net 31 | -------------------------------------------------------------------------------- /Source/dx.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DX_H__ 3 | #define __DX_H__ 4 | 5 | extern BYTE *gpBuffer; 6 | extern char gbBackBuf; 7 | extern char gbEmulate; 8 | extern BOOL use_offscreen; 9 | 10 | void dx_init(); 11 | void lock_buf(BYTE idx); 12 | void unlock_buf(BYTE idx); 13 | void dx_cleanup(); 14 | 15 | BOOL draw_lock( int* ysize ); 16 | void draw_unlock(); 17 | void draw_flush(); 18 | void draw_blit(DWORD dwX, DWORD dwY, DWORD dwWdt, DWORD dwHgt); 19 | 20 | void draw_clip_text(int x0, int y0, int x1, int y1); 21 | void draw_text(int x, int y, const char* text, int color); 22 | void draw_belt(int* items); 23 | 24 | void _SetCursorPos(DWORD x, DWORD y); 25 | 26 | /* data */ 27 | 28 | #endif /* __DX_H__ */ 29 | -------------------------------------------------------------------------------- /Source/trace.cpp: -------------------------------------------------------------------------------- 1 | #include "trace.h" 2 | 3 | #ifdef EMSCRIPTEN 4 | 5 | #include 6 | EM_JS(void, trace_push, (const char* ptr), { 7 | var end = HEAPU8.indexOf(0, ptr); 8 | var text = String.fromCharCode.apply(null, HEAPU8.subarray(ptr, end)); 9 | console.log(text); 10 | self.WASM_TRACE = self.WASM_TRACE || []; 11 | self.WASM_TRACE.push(text); 12 | }) 13 | EM_JS(void, trace_pop, (), { 14 | if (self.WASM_TRACE) { 15 | self.WASM_TRACE.pop(); 16 | } 17 | }) 18 | 19 | #else 20 | 21 | void trace_push(const char* ptr) {} 22 | void trace_pop() {} 23 | 24 | #endif 25 | 26 | __Trace::Guard::Guard(const char* name, const std::string& args) { 27 | trace_push((name + args).c_str()); 28 | } 29 | __Trace::Guard::~Guard() { 30 | trace_pop(); 31 | } 32 | -------------------------------------------------------------------------------- /Source/portal.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __PORTAL_H__ 3 | #define __PORTAL_H__ 4 | 5 | extern PortalStruct portal[MAXPORTAL]; 6 | extern int portalindex; 7 | 8 | void InitPortals(); 9 | void SetPortalStats(int i, BOOL o, int x, int y, int lvl, int lvltype); 10 | void AddWarpMissile(int i, int x, int y); 11 | void SyncPortals(); 12 | void AddInTownPortal(int i); 13 | void ActivatePortal(int i, int x, int y, int lvl, int lvltype, BOOL sp); 14 | void DeactivatePortal(int i); 15 | BOOL PortalOnLevel(int i); 16 | void RemovePortalMissile(int id); 17 | void SetCurrentPortal(int p); 18 | void GetPortalLevel(); 19 | void GetPortalLvlPos(); 20 | BOOL PosOkPortal(int lvl, int x, int y); 21 | 22 | /* rdata */ 23 | extern int WarpDropX[MAXPORTAL]; 24 | extern int WarpDropY[MAXPORTAL]; 25 | 26 | #endif /* __PORTAL_H__ */ 27 | -------------------------------------------------------------------------------- /Source/rmpq/locale.cpp: -------------------------------------------------------------------------------- 1 | #include "locale.h" 2 | 3 | namespace mpq { 4 | 5 | char const* Locale::toString(uint16_t locale) { 6 | switch (locale) { 7 | case Neutral: 8 | return "Neutral"; 9 | case Chinese: 10 | return "Chinese"; 11 | case Czech: 12 | return "Czech"; 13 | case German: 14 | return "German"; 15 | case English: 16 | return "English"; 17 | case Spanish: 18 | return "Spanish"; 19 | case French: 20 | return "French"; 21 | case Italian: 22 | return "Italian"; 23 | case Japanese: 24 | return "Japanese"; 25 | case Korean: 26 | return "Korean"; 27 | case Polish: 28 | return "Polish"; 29 | case Portuguese: 30 | return "Portuguese"; 31 | case Russian: 32 | return "Russian"; 33 | case EnglishUK: 34 | return "English (UK)"; 35 | default: 36 | return "Unknown"; 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Source/rmpq/checksum.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | uint32_t update_crc(uint32_t crc, void const* vbuf, uint32_t length); 6 | uint32_t crc32(void const* buf, uint32_t length); 7 | uint32_t crc32(std::string const& str); 8 | 9 | class MD5 { 10 | uint8_t buffer[64]; 11 | uint32_t digest[4]; 12 | uint64_t length; 13 | uint32_t bufSize; 14 | void run(); 15 | public: 16 | enum { DIGEST_SIZE = 16 }; 17 | 18 | MD5(); 19 | void process(void const* buf, uint32_t size); 20 | void finish(void* digest); 21 | 22 | static std::string format(void const* digest); 23 | 24 | static void checksum(void const* buf, uint32_t size, void* digest) { 25 | MD5 md5; 26 | md5.process(buf, size); 27 | md5.finish(digest); 28 | } 29 | }; 30 | 31 | uint64_t jenkins(void const* buf, uint32_t length); 32 | uint32_t hashlittle(void const* buf, uint32_t length, uint32_t initval); 33 | -------------------------------------------------------------------------------- /Source/cursor.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __CURSOR_H__ 3 | #define __CURSOR_H__ 4 | 5 | extern int cursH; 6 | extern int icursH28; 7 | extern int cursW; 8 | extern int pcursmonst; 9 | extern int icursW28; 10 | extern BYTE *pCursCels; 11 | extern int icursH; 12 | extern char pcursinvitem; 13 | extern int icursW; 14 | extern char pcursitem; 15 | extern char pcursobj; 16 | extern char pcursplr; 17 | extern int cursmx; 18 | extern int cursmy; 19 | extern int pcurstemp; 20 | extern int pcurs; 21 | 22 | void InitCursor(); 23 | void FreeCursor(); 24 | void SetICursor(int i); 25 | void SetCursor_(int i); 26 | void NewCursor(int i); 27 | void InitLevelCursor(); 28 | void CheckTown(); 29 | void CheckRportal(); 30 | void CheckCursMove(); 31 | 32 | /* rdata */ 33 | extern const int InvItemWidth[180]; 34 | extern const int InvItemHeight[180]; 35 | 36 | #endif /* __CURSOR_H__ */ 37 | -------------------------------------------------------------------------------- /Source/nthread.h: -------------------------------------------------------------------------------- 1 | #ifndef __NTHREAD_H__ 2 | #define __NTHREAD_H__ 3 | 4 | extern BYTE sgbNetUpdateRate; 5 | extern DWORD gdwMsgLenTbl[MAX_PLRS]; 6 | extern DWORD gdwDeltaBytesSec; 7 | extern BOOLEAN nthread_should_run; 8 | extern DWORD gdwTurnsInTransit; 9 | extern int glpMsgTbl[MAX_PLRS]; 10 | extern unsigned int glpNThreadId; 11 | extern int turn_upper_bit; 12 | extern BOOLEAN sgbThreadIsRunning; 13 | extern DWORD gdwLargestMsgSize; 14 | extern DWORD gdwNormalMsgSize; 15 | extern int last_tick; 16 | 17 | void nthread_terminate_game(const char *pszFcn); 18 | DWORD nthread_send_and_recv_turn(DWORD cur_turn, int turn_delta); 19 | BOOL nthread_recv_turns(BOOL *pfSendAsync); 20 | void nthread_set_turn_upper_bit(); 21 | void nthread_start(BOOL set_turn_upper_bit); 22 | void nthread_cleanup(); 23 | void nthread_loop(); 24 | BOOL nthread_has_500ms_passed(BOOL unused); 25 | 26 | /* rdata */ 27 | 28 | #endif /* __NTHREAD_H__ */ 29 | -------------------------------------------------------------------------------- /Source/debug.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DEBUG_H__ 3 | #define __DEBUG_H__ 4 | 5 | extern BYTE *pSquareCel; 6 | extern char dMonsDbg[NUMLEVELS][MAXDUNX][MAXDUNY]; 7 | extern char dFlagDbg[NUMLEVELS][MAXDUNX][MAXDUNY]; 8 | 9 | void LoadDebugGFX(); 10 | void FreeDebugGFX(); 11 | #ifdef _DEBUG 12 | void init_seed_desync(); 13 | void seed_desync_index_get(); 14 | void seed_desync_index_set(); 15 | void seed_desync_check(int seed); 16 | #endif 17 | void CheckDungeonClear(); 18 | #ifdef _DEBUG 19 | void GiveGoldCheat(); 20 | void StoresCheat(); 21 | void TakeGoldCheat(); 22 | void MaxSpellsCheat(); 23 | void SetSpellLevelCheat(char spl, int spllvl); 24 | void SetAllSpellsCheat(); 25 | void PrintDebugPlayer(BOOL bNextPlayer); 26 | void PrintDebugQuest(); 27 | void PrintDebugMonster(int m); 28 | void GetDebugMonster(); 29 | void NextDebugMonster(); 30 | #endif 31 | 32 | #endif /* __DEBUG_H__ */ 33 | -------------------------------------------------------------------------------- /Source/storm/storm.cpp: -------------------------------------------------------------------------------- 1 | #include "../diablo.h" 2 | #include "storm.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | void* SMemAlloc(unsigned int amount, const char *logfilename, int logline, int defaultValue) { 9 | // fprintf(stderr, "%s: %d (%s:%d)\n", __FUNCTION__, amount, logfilename, logline); 10 | assert(amount != -1u); 11 | return malloc(amount); 12 | } 13 | 14 | BOOL SMemFree(void *location, const char *logfilename, int logline, char defaultValue) { 15 | // fprintf(stderr, "%s: (%s:%d)\n", __FUNCTION__, logfilename, logline); 16 | assert(location); 17 | free(location); 18 | return true; 19 | } 20 | 21 | DWORD nLastError = 0; 22 | 23 | DWORD SErrGetLastError() { 24 | return nLastError; 25 | } 26 | 27 | void SErrSetLastError(DWORD dwErrCode) { 28 | nLastError = dwErrCode; 29 | } 30 | 31 | int SStrCopy(char *dest, const char *src, int max_length) { 32 | strncpy(dest, src, max_length); 33 | return strlen(dest); 34 | } 35 | -------------------------------------------------------------------------------- /Source/ui/selhero.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include "dialog.h" 5 | 6 | const int MIN_NIGHTMARE_LEVEL = 20; 7 | const int MIN_HELL_LEVEL = 30; 8 | 9 | class SelectBaseDialog : public DialogState { 10 | public: 11 | SelectBaseDialog(const char* title); 12 | 13 | void setStats(const _uiheroinfo* info); 14 | 15 | void onActivate() override; 16 | }; 17 | 18 | GameStatePtr select_hero_dialog(const std::vector<_uiheroinfo>& heroInfos, std::function&& next); 19 | GameStatePtr select_class_dialog(std::function&& next); 20 | GameStatePtr select_diff_dialog(const _uiheroinfo& info, const char* title, std::function&& next); 21 | GameStatePtr select_string_dialog(const _uiheroinfo& info, const char* title, const char* subtitle, std::function&& next); 22 | GameStatePtr select_twoopt_dialog(const _uiheroinfo* info, const char* title, const char* subtitle, const char* opt1, const char* opt2, std::function&& next); 23 | -------------------------------------------------------------------------------- /mpqcmp/shine/huffman.h: -------------------------------------------------------------------------------- 1 | #define HUFFBITS uint16_t 2 | #define HTN 34 3 | #define MXOFF 250 4 | 5 | struct huffcodetab { 6 | unsigned int xlen; /*max. x-index+ */ 7 | unsigned int ylen; /*max. y-index+ */ 8 | unsigned int linbits; /*number of linbits */ 9 | unsigned int linmax; /*max number to be stored in linbits */ 10 | const HUFFBITS *table; /*pointer to array[xlen][ylen] */ 11 | const unsigned char *hlen; /*pointer to array[xlen][ylen] */ 12 | }; 13 | 14 | extern const struct huffcodetab shine_huffman_table[HTN];/* global memory block */ 15 | /* array of all huffcodtable headers */ 16 | /* 0..31 Huffman code table 0..31 */ 17 | /* 32,33 count1-tables */ 18 | 19 | 20 | -------------------------------------------------------------------------------- /Source/automap.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __AUTOMAP_H__ 3 | #define __AUTOMAP_H__ 4 | 5 | extern WORD automaptype[512]; 6 | extern BOOL automapflag; 7 | extern char AmShiftTab[32]; 8 | extern BOOLEAN automapview[DMAXX][DMAXY]; 9 | extern int AutoMapScale; 10 | extern int AutoMapXOfs; 11 | extern int AutoMapYOfs; 12 | extern int AutoMapPosBits; 13 | extern int AutoMapXPos; 14 | extern int AutoMapYPos; 15 | extern int AMPlayerX; 16 | extern int AMPlayerY; 17 | 18 | void InitAutomapOnce(); 19 | void InitAutomap(); 20 | void StartAutomap(); 21 | void AutomapUp(); 22 | void AutomapDown(); 23 | void AutomapLeft(); 24 | void AutomapRight(); 25 | void AutomapZoomIn(); 26 | void AutomapZoomOut(); 27 | void DrawAutomap(); 28 | void DrawAutomapType(int screen_x, int screen_y, WORD automap_type); 29 | void DrawAutomapPlr(); 30 | WORD GetAutomapType(int x, int y, BOOL view); 31 | void DrawAutomapGame(); 32 | void SetAutomapView(int x, int y); 33 | void AutomapZoomReset(); 34 | 35 | #endif /* __AUTOMAP_H__ */ 36 | -------------------------------------------------------------------------------- /Source/loadsave.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __LOADSAVE_H__ 3 | #define __LOADSAVE_H__ 4 | 5 | extern BYTE *tbuff; 6 | 7 | void LoadGame(BOOL firstflag); 8 | char BLoad(); 9 | int WLoad(); 10 | int ILoad(); 11 | BOOL OLoad(); 12 | void LoadPlayer(int i); 13 | void LoadMonster(int i); 14 | void LoadMissile(int i); 15 | void LoadObject(int i); 16 | void LoadItem(int i); 17 | void LoadPremium(int i); 18 | void LoadQuest(int i); 19 | void LoadLighting(int i); 20 | void LoadVision(int i); 21 | void LoadPortal(int i); 22 | void SaveGame(); 23 | void BSave(char v); 24 | void WSave(int v); 25 | void ISave(int v); 26 | void OSave(BOOL v); 27 | void SavePlayer(int i); 28 | void SaveMonster(int i); 29 | void SaveMissile(int i); 30 | void SaveObject(int i); 31 | void SaveItem(int i); 32 | void SavePremium(int i); 33 | void SaveQuest(int i); 34 | void SaveLighting(int i); 35 | void SaveVision(int i); 36 | void SavePortal(int i); 37 | void SaveLevel(); 38 | void LoadLevel(); 39 | 40 | #endif /* __LOADSAVE_H__ */ 41 | -------------------------------------------------------------------------------- /Source/effects.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __EFFECTS_H__ 3 | #define __EFFECTS_H__ 4 | 5 | extern int sfxdelay; 6 | extern int sfxdnum; 7 | extern TSFX *sfx_data_cur; 8 | 9 | BOOL effect_is_playing(int nSFX); 10 | void sfx_stop(); 11 | void InitMonsterSND(int monst); 12 | void FreeEffects(); 13 | void PlayEffect(int i, int mode); 14 | BOOL calc_snd_position(int x, int y, int *plVolume, int *plPan); 15 | void PlaySFX(int psfx); 16 | void PlaySFX_priv(TSFX *pSFX, BOOL loc, int x, int y); 17 | void stream_play(TSFX *pSFX, int lVolume, int lPan); 18 | int RndSFX(int psfx); 19 | void PlaySfxLoc(int psfx, int x, int y); 20 | void FreeMonsterSnd(); 21 | void sound_stop(); 22 | void sound_update(); 23 | void effects_update(); 24 | void effects_cleanup_sfx(); 25 | void stream_update(); 26 | void priv_sound_init(BYTE bLoadMask); 27 | void sound_init(); 28 | void effects_play_sound(const char *snd_file); 29 | 30 | /* rdata */ 31 | 32 | extern const char monster_action_sounds[]; 33 | 34 | /* data */ 35 | 36 | #endif /* __EFFECTS_H__ */ 37 | -------------------------------------------------------------------------------- /Source/palette.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __PALETTE_H__ 3 | #define __PALETTE_H__ 4 | 5 | extern PALETTEENTRY system_palette[256]; 6 | 7 | void SaveGamma(); 8 | void palette_init(); 9 | void LoadGamma(); 10 | void LoadSysPal(); 11 | void LoadPalette(const char *pszFileName); 12 | void LoadRndLvlPal(int l); 13 | void ResetPal(); 14 | void IncreaseGamma(); 15 | void palette_update(); 16 | void ApplyGamma(PALETTEENTRY *dst, PALETTEENTRY *src, int n); 17 | void DecreaseGamma(); 18 | int UpdateGamma(int gamma); 19 | void BlackPalette(); 20 | void SetFadeLevel(DWORD fadeval); 21 | void PaletteFadeIn(int fr); 22 | void PaletteFadeOut(int fr); 23 | void palette_update_caves(); 24 | void palette_update_quest_palette(int n); 25 | BOOL palette_get_colour_cycling(); 26 | BOOL palette_set_color_cycling(BOOL enabled); 27 | 28 | void set_palette(PALETTEENTRY *pal); 29 | void get_palette(PALETTEENTRY *pal); 30 | 31 | /* rdata */ 32 | 33 | /* data */ 34 | 35 | extern int gamma_correction; 36 | extern BOOL color_cycling_enabled; 37 | 38 | #endif /* __PALETTE_H__ */ 39 | -------------------------------------------------------------------------------- /Source/wave.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __WAVE_H__ 3 | #define __WAVE_H__ 4 | 5 | BOOL WCloseFile(HANDLE file); 6 | LONG WGetFileSize(HANDLE hsFile, DWORD *lpFileSizeHigh); 7 | void WGetFileArchive(HANDLE hsFile, DWORD *retry, const char *FileName); 8 | BOOL WOpenFile(const char *FileName, HANDLE *phsFile, BOOL mayNotExist); 9 | void WReadFile(HANDLE hsFile, LPVOID buf, DWORD to_read); 10 | int WSetFilePointer(HANDLE file1, int offset, HANDLE file2, int whence); 11 | BOOL LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx); 12 | void *AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos); 13 | void FreeMemFile(MEMFILE *pMemFile); 14 | BOOL ReadWaveFile(MEMFILE *pMemFile, WAVEFORMATEX *pwfx, CKINFO *chunk); 15 | BOOL ReadMemFile(MEMFILE *pMemFile, void *lpBuf, size_t length); 16 | void FillMemFile(MEMFILE *pMemFile); 17 | int SeekMemFile(MEMFILE *pMemFile, ULONG lDist, DWORD dwMethod); 18 | BOOL ReadWaveSection(MEMFILE *pMemFile, DWORD id, CKINFO *chunk); 19 | BYTE *LoadWaveFile(HANDLE hsFile, WAVEFORMATEX *pwfx, CKINFO *chunk); 20 | 21 | #endif /* __WAVE_H__ */ 22 | -------------------------------------------------------------------------------- /mpqcmp/shine/bitstream.h: -------------------------------------------------------------------------------- 1 | #ifndef BITSTREAM_H 2 | #define BITSTREAM_H 3 | 4 | typedef struct bit_stream_struc { 5 | unsigned char *data; /* Processed data */ 6 | int data_size; /* Total data size */ 7 | int data_position; /* Data position */ 8 | unsigned int cache; /* bit stream cache */ 9 | int cache_bits; /* free bits in cache */ 10 | } bitstream_t; 11 | 12 | /* "bit_stream.h" Definitions */ 13 | 14 | #define MINIMUM 4 /* Minimum size of the buffer in bytes */ 15 | #define MAX_LENGTH 32 /* Maximum length of word written or 16 | read from bit stream */ 17 | 18 | #define BUFFER_SIZE 4096 19 | 20 | #define MIN(A, B) ((A) < (B) ? (A) : (B)) 21 | #define MAX(A, B) ((A) > (B) ? (A) : (B)) 22 | 23 | void shine_open_bit_stream(bitstream_t *bs,const int size); 24 | void shine_close_bit_stream(bitstream_t *bs); 25 | void shine_putbits(bitstream_t *bs,unsigned int val, unsigned int N); 26 | int shine_get_bits_count(bitstream_t *bs); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /mpqcmp/shine/mult_noarch_gcc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef mul 4 | #define mul(a,b) (int32_t) ( ( ((int64_t) a) * ((int64_t) b) ) >>32 ) 5 | #endif 6 | 7 | #ifndef muls 8 | #define muls(a,b) (int32_t) ( ( ((int64_t) a) * ((int64_t) b) ) >>31 ) 9 | #endif 10 | 11 | #ifndef mulr 12 | #define mulr(a,b) (int32_t) ( ( ( ((int64_t) a) * ((int64_t) b)) + 0x80000000LL ) >>32 ) 13 | #endif 14 | 15 | #ifndef mulsr 16 | #define mulsr(a,b) (int32_t) ( ( ( ((int64_t) a) * ((int64_t) b)) + 0x40000000LL ) >>31 ) 17 | #endif 18 | 19 | #ifndef mul0 20 | #define mul0(hi,lo,a,b) ((hi) = mul((a), (b))) 21 | #define muladd(hi,lo,a,b) ((hi) += mul((a), (b))) 22 | #define mulsub(hi,lo,a,b) ((hi) -= mul((a), (b))) 23 | #define mulz(hi,lo) 24 | #endif 25 | 26 | #ifndef cmuls 27 | #define cmuls(dre, dim, are, aim, bre, bim) \ 28 | do { \ 29 | int32_t tre; \ 30 | (tre) = (int32_t) (((int64_t) (are) * (int64_t) (bre) - (int64_t) (aim) * (int64_t) (bim)) >> 31); \ 31 | (dim) = (int32_t) (((int64_t) (are) * (int64_t) (bim) + (int64_t) (aim) * (int64_t) (bre)) >> 31); \ 32 | (dre) = tre; \ 33 | } while (0) 34 | #endif 35 | -------------------------------------------------------------------------------- /Source/sound.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __SOUND_H__ 3 | #define __SOUND_H__ 4 | 5 | extern BOOLEAN gbSndInited; 6 | extern int sgnMusicTrack; 7 | 8 | void snd_update(BOOL bStopAll); 9 | void snd_stop_snd(TSnd *pSnd); 10 | BOOL snd_playing(TSnd *pSnd); 11 | void snd_play_snd(TSnd *pSnd, int lVolume, int lPan); 12 | TSnd *sound_file_load(const char *path); 13 | TSnd *sound_from_buffer(const uint8_t* buffer, unsigned long size, int channels, int depth, int rate); 14 | void sound_file_cleanup(TSnd *sound_file); 15 | void snd_init(); 16 | void sound_load_volume(const char *value_name, int *value); 17 | void sound_cleanup(); 18 | void sound_store_volume(const char *key, int value); 19 | void music_stop(); 20 | void music_start(int nTrack); 21 | void sound_disable_music(BOOL disable); 22 | void sound_reset(TSnd* pSnd); 23 | int sound_get_or_set_music_volume(int volume); 24 | int sound_get_or_set_sound_volume(int volume); 25 | 26 | /* rdata */ 27 | 28 | /* data */ 29 | 30 | extern BOOLEAN gbMusicOn; 31 | extern BOOLEAN gbSoundOn; 32 | extern BOOLEAN gbDupSounds; 33 | extern char unk_volume[4][2]; 34 | 35 | #endif /* __SOUND_H__ */ 36 | -------------------------------------------------------------------------------- /Source/track.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | #include "storm/storm.h" 3 | 4 | static BYTE sgbIsScrolling; 5 | static DWORD sgdwLastWalk; 6 | static BOOL sgbIsWalking; 7 | 8 | void track_process() 9 | { 10 | if (!sgbIsWalking) 11 | return; 12 | 13 | if (cursmx < 0 || cursmx >= MAXDUNX - 1 || cursmy < 0 || cursmy >= MAXDUNY - 1) 14 | return; 15 | 16 | if (plr[myplr]._pVar8 <= 6 && plr[myplr]._pmode != PM_STAND) 17 | return; 18 | 19 | if (cursmx != plr[myplr]._ptargx || cursmy != plr[myplr]._ptargy) { 20 | DWORD tick = _GetTickCount(); 21 | if ((int)(tick - sgdwLastWalk) >= 300) { 22 | sgdwLastWalk = tick; 23 | NetSendCmdLoc(TRUE, CMD_WALKXY, cursmx, cursmy); 24 | if (!sgbIsScrolling) 25 | sgbIsScrolling = 1; 26 | } 27 | } 28 | } 29 | 30 | void track_repeat_walk(BOOL rep) 31 | { 32 | if (sgbIsWalking == rep) 33 | return; 34 | 35 | sgbIsWalking = rep; 36 | if (rep) { 37 | sgbIsScrolling = 0; 38 | sgdwLastWalk = _GetTickCount() - 50; 39 | NetSendCmdLoc(TRUE, CMD_WALKXY, cursmx, cursmy); 40 | } else if (sgbIsScrolling) { 41 | sgbIsScrolling = 0; 42 | } 43 | } 44 | 45 | BOOL track_isscrolling() 46 | { 47 | return sgbIsScrolling; 48 | } 49 | -------------------------------------------------------------------------------- /Source/towners.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __TOWNERS_H__ 3 | #define __TOWNERS_H__ 4 | 5 | extern TownerStruct towner[16]; 6 | 7 | int GetActiveTowner(int t); 8 | void SetTownerGPtrs(BYTE *pData, BYTE **pAnim); 9 | void NewTownerAnim(int tnum, BYTE *pAnim, int numFrames, int Delay); 10 | void InitTownerInfo(int i, int w, int sel, int t, int x, int y, int ao, int tp); 11 | void InitQstSnds(int i); 12 | void InitSmith(); 13 | void InitBarOwner(); 14 | void InitTownDead(); 15 | void InitWitch(); 16 | void InitBarmaid(); 17 | void InitBoy(); 18 | void InitHealer(); 19 | void InitTeller(); 20 | void InitDrunk(); 21 | void InitCows(); 22 | void InitTowners(); 23 | void FreeTownerGFX(); 24 | void TownCtrlMsg(int i); 25 | void TownBlackSmith(); 26 | void TownBarOwner(); 27 | void TownDead(); 28 | void TownHealer(); 29 | void TownStory(); 30 | void TownDrunk(); 31 | void TownBoy(); 32 | void TownWitch(); 33 | void TownBarMaid(); 34 | void TownCow(); 35 | void ProcessTowners(); 36 | ItemStruct *PlrHasItem(int pnum, int item, int *i); 37 | void TownerTalk(int first, int t); 38 | void TalkToTowner(int p, int t); 39 | void CowSFX(int pnum); 40 | 41 | /* data */ 42 | 43 | extern QuestTalkData Qtalklist[11]; 44 | 45 | #endif /* __TOWNERS_H__ */ 46 | -------------------------------------------------------------------------------- /Source/appfat.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __APPFAT_H__ 3 | #define __APPFAT_H__ 4 | 5 | extern char sz_error_buf[256]; 6 | extern int terminating; 7 | extern int cleanup_thread_id; 8 | 9 | void TriggerBreak(); 10 | char *GetErrorStr(DWORD error_code); 11 | char *TraceLastError(); 12 | void __cdecl app_fatal(const char *pszFmt, ...); 13 | void __cdecl DrawDlg(const char *pszFmt, ...); 14 | #ifdef _DEBUG 15 | void assert_fail(int nLineNo, const char *pszFile, const char *pszFail); 16 | #endif 17 | void ErrDlg(int template_id, DWORD error_code, const char *log_file_path, int log_line_nr); 18 | void ErrMsg(const char* text, const char *log_file_path, int log_line_nr); 19 | void TextDlg(HWND hDlg, char *text); 20 | void ErrOkDlg(int template_id, DWORD error_code, const char *log_file_path, int log_line_nr); 21 | void FileErrDlg(const char *error); 22 | void DiskFreeDlg(const char *error); 23 | BOOL InsertCDDlg(); 24 | void DirErrorDlg(const char *error); 25 | 26 | #define DS_ERROR(code) ErrDlg(0, (code), __FILE__, __LINE__) 27 | #define DX_ERROR(code) ErrDlg(0, (code), __FILE__, __LINE__) 28 | #define ERROR_DLG(tmpl, code) ErrDlg((tmpl), (code), __FILE__, __LINE__) 29 | #define ERROR_MSG(text) ErrMsg((text), __FILE__, __LINE__) 30 | 31 | #endif /* __APPFAT_H__ */ 32 | -------------------------------------------------------------------------------- /Source/tmsg.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | 3 | static TMsg *sgpTimedMsgHead; 4 | 5 | int tmsg_get(BYTE *pbMsg, DWORD dwMaxLen) 6 | { 7 | int len; 8 | TMsg *head; 9 | 10 | if (!sgpTimedMsgHead) 11 | return 0; 12 | 13 | if ((int)(sgpTimedMsgHead->hdr.dwTime - _GetTickCount()) >= 0) 14 | return 0; 15 | head = sgpTimedMsgHead; 16 | sgpTimedMsgHead = head->hdr.pNext; 17 | len = head->hdr.bLen; 18 | // BUGFIX: ignores dwMaxLen 19 | memcpy(pbMsg, head->body, len); 20 | mem_free_dbg(head); 21 | return len; 22 | } 23 | 24 | void tmsg_add(BYTE *pbMsg, BYTE bLen) 25 | { 26 | TMsg **tail; 27 | 28 | TMsg *msg = (TMsg *)DiabloAllocPtr(bLen + sizeof(*msg)); 29 | msg->hdr.pNext = NULL; 30 | msg->hdr.dwTime = _GetTickCount() + 500; 31 | msg->hdr.bLen = bLen; 32 | memcpy(msg->body, pbMsg, bLen); 33 | for (tail = &sgpTimedMsgHead; *tail; tail = &(*tail)->hdr.pNext) { 34 | ; 35 | } 36 | *tail = msg; 37 | } 38 | 39 | void tmsg_start() 40 | { 41 | /// ASSERT: assert(! sgpTimedMsgHead); 42 | } 43 | 44 | void *tmsg_cleanup() 45 | { 46 | TMsg *next; 47 | 48 | while (sgpTimedMsgHead) { 49 | next = sgpTimedMsgHead->hdr.pNext; 50 | MemFreeDbg(sgpTimedMsgHead); 51 | sgpTimedMsgHead = next; 52 | } 53 | return sgpTimedMsgHead; 54 | } 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /Server.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Source/net/loopback.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../diablo.h" 7 | #include "abstract_net.h" 8 | 9 | namespace net { 10 | 11 | class loopback : public abstract_net { 12 | private: 13 | std::deque> message_queue; 14 | std::vector message_last; 15 | const int plr_single = 0; 16 | 17 | public: 18 | void create(std::string addrstr, std::string passwd, uint32_t difficulty) override; 19 | void join(std::string addrstr, std::string passwd) override; 20 | bool SNetReceiveMessage(int* sender, char** data, int* size) override; 21 | bool SNetSendMessage(int dest, void* data, unsigned int size) override; 22 | bool SNetReceiveTurns(char** data, DWORD* size, DWORD* status) override; 23 | bool SNetSendTurn(char* data, unsigned int size) override; 24 | int SNetGetProviderCaps(struct _SNETCAPS* caps) override; 25 | bool SNetRegisterEventHandler(event_type evtype, SEVTHANDLER func) override; 26 | bool SNetUnregisterEventHandler(event_type evtype, SEVTHANDLER func) override; 27 | bool SNetLeaveGame(int type) override; 28 | bool SNetDropPlayer(int playerid, DWORD flags) override; 29 | bool SNetGetOwnerTurnsWaiting(DWORD* turns) override; 30 | bool SNetGetTurnsInTransit(int* turns) override; 31 | }; 32 | 33 | } // namespace net 34 | -------------------------------------------------------------------------------- /Source/gamemenu.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __GAMEMENU_H__ 3 | #define __GAMEMENU_H__ 4 | 5 | void gamemenu_previous(); 6 | void gamemenu_enable_single(TMenuItem *pMenuItems); 7 | void gamemenu_enable_multi(TMenuItem *pMenuItems); 8 | void gamemenu_off(); 9 | void gamemenu_handle_previous(); 10 | void j_gamemenu_previous(BOOL bActivate); 11 | void gamemenu_new_game(BOOL bActivate); 12 | void gamemenu_quit_game(BOOL bActivate); 13 | void gamemenu_load_game(BOOL bActivate); 14 | void gamemenu_save_game(BOOL bActivate); 15 | void gamemenu_restart_town(BOOL bActivate); 16 | void gamemenu_options(BOOL bActivate); 17 | void gamemenu_get_music(); 18 | void gamemenu_sound_music_toggle(const char **names, TMenuItem *menu_item, int gamma); 19 | void gamemenu_get_sound(); 20 | void gamemenu_get_color_cycling(); 21 | void gamemenu_get_gamma(); 22 | void gamemenu_music_volume(BOOL bActivate); 23 | int gamemenu_slider_music_sound(TMenuItem *menu_item); 24 | void gamemenu_sound_volume(BOOL bActivate); 25 | void gamemenu_gamma(BOOL bActivate); 26 | int gamemenu_slider_gamma(); 27 | void gamemenu_color_cycling(BOOL bActivate); 28 | 29 | /* rdata */ 30 | extern const char *music_toggle_names[]; 31 | extern const char *sound_toggle_names[]; 32 | extern const char *color_cycling_toggle_names[]; 33 | 34 | #endif /* __GAMEMENU_H__ */ 35 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | { 2 | BasedOnStyle: LLVM, 3 | Language: Cpp, 4 | 5 | AlignAfterOpenBracket: Align, 6 | AlignConsecutiveAssignments: false, 7 | AlignConsecutiveDeclarations: false, 8 | AlignEscapedNewlines: false, 9 | AlignOperands: false, 10 | AlignTrailingComments: false, 11 | AlwaysBreakAfterReturnType: None, 12 | AlwaysBreakBeforeMultilineStrings: false, 13 | AlwaysBreakTemplateDeclarations: true, 14 | BreakBeforeBinaryOperators: None, 15 | BreakBeforeTernaryOperators: false, 16 | CompactNamespaces: false, 17 | ConstructorInitializerAllOnOneLineOrOnePerLine: true, 18 | FixNamespaceComments: true, 19 | IndentCaseLabels: false, 20 | NamespaceIndentation: None, 21 | PointerAlignment: Left, 22 | SortIncludes: false, 23 | SortUsingDeclarations: false, 24 | SpaceAfterCStyleCast: true, 25 | SpaceAfterTemplateKeyword: false, 26 | SpaceBeforeAssignmentOperators: true, 27 | SpaceBeforeParens: ControlStatements, 28 | SpaceInEmptyParentheses: false, 29 | SpacesInAngles: false, 30 | SpacesInCStyleCastParentheses: false, 31 | SpacesInSquareBrackets: false, 32 | Standard: Cpp11, 33 | ColumnLimit: 0, 34 | 35 | BreakBeforeBraces: Attach, 36 | BreakConstructorInitializers: BeforeComma, 37 | IndentWidth: 2, 38 | Cpp11BracedListStyle: true, 39 | SpacesInParentheses: false, 40 | TabWidth: 2, 41 | UseTab: Never, 42 | } -------------------------------------------------------------------------------- /Source/trigs.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __TRIGS_H__ 3 | #define __TRIGS_H__ 4 | 5 | extern BOOL townwarps[3]; 6 | extern BOOL trigflag; 7 | extern int numtrigs; 8 | extern TriggerStruct trigs[MAXTRIGGERS]; 9 | extern int TWarpFrom; 10 | 11 | void InitNoTriggers(); 12 | void InitTownTriggers(); 13 | void InitL1Triggers(); 14 | void InitL2Triggers(); 15 | void InitL3Triggers(); 16 | void InitL4Triggers(); 17 | void InitSKingTriggers(); 18 | void InitSChambTriggers(); 19 | void InitPWaterTriggers(); 20 | void InitVPTriggers(); 21 | BOOL ForceTownTrig(); 22 | BOOL ForceL1Trig(); 23 | BOOL ForceL2Trig(); 24 | BOOL ForceL3Trig(); 25 | BOOL ForceL4Trig(); 26 | void Freeupstairs(); 27 | BOOL ForceSKingTrig(); 28 | BOOL ForceSChambTrig(); 29 | BOOL ForcePWaterTrig(); 30 | void CheckTrigForce(); 31 | void CheckTriggers(); 32 | 33 | /* rdata */ 34 | 35 | extern int TownDownList[11]; 36 | extern int TownWarp1List[13]; 37 | extern int L1UpList[12]; 38 | extern int L1DownList[10]; 39 | extern int L2UpList[3]; 40 | extern int L2DownList[5]; 41 | extern int L2TWarpUpList[3]; 42 | extern int L3UpList[15]; 43 | extern int L3DownList[9]; 44 | extern int L3TWarpUpList[14]; 45 | extern int L4UpList[4]; 46 | extern int L4DownList[6]; 47 | extern int L4TWarpUpList[4]; 48 | extern int L4PentaList[33]; 49 | 50 | #endif /* __TRIGS_H__ */ 51 | -------------------------------------------------------------------------------- /Source/ui/okbox.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "dialog.h" 3 | 4 | class OkDialog : public DialogState { 5 | public: 6 | OkDialog(const char* text, std::function&& next, bool background) 7 | : next_(next) 8 | , background_(background) 9 | { 10 | addItem({{0, 0, 640, 480}, ControlType::Image, 0, 0, "", &ArtBackground}); 11 | addItem({{140, 199, 540, 376}, ControlType::Text, ControlFlags::Medium | ControlFlags::WordWrap, 0, text}); 12 | addItem({{230, 407, 410, 449}, ControlType::List, ControlFlags::Center | ControlFlags::Big | ControlFlags::Gold, 0, "OK"}); 13 | addItem({{125, 0, 515, 154}, ControlType::Image, 0, -60, "", &ArtLogos[LOGO_MED]}); 14 | } 15 | 16 | void onActivate() override { 17 | LoadBackgroundArt(background_ ? "ui_art\\swmmenu.pcx" : "ui_art\\black.pcx"); 18 | } 19 | 20 | void onInput(int) override { 21 | UiPlaySelectSound(); 22 | next_(); 23 | } 24 | 25 | private: 26 | bool background_; 27 | std::function next_; 28 | }; 29 | 30 | GameStatePtr get_ok_dialog(const char* text, std::function&& next, bool background) { 31 | return new OkDialog(text, std::move(next), background); 32 | } 33 | 34 | GameStatePtr get_ok_dialog(const char* text, GameStatePtr next, bool background) { 35 | return new OkDialog(text, [next]() { 36 | GameState::activate(next); 37 | }, background); 38 | } 39 | -------------------------------------------------------------------------------- /Source/path.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __PATH_H__ 3 | #define __PATH_H__ 4 | 5 | extern PATHNODE path_nodes[MAXPATHNODES]; 6 | extern int gdwCurPathStep; 7 | extern int gdwCurNodes; 8 | extern int pnode_vals[25]; 9 | extern PATHNODE *pnode_ptr; 10 | extern PATHNODE *pnode_tblptr[MAXPATHNODES]; 11 | extern PATHNODE *path_2_nodes; 12 | extern PATHNODE path_unusednodes[MAXPATHNODES]; 13 | 14 | int FindPath(BOOL (*PosOk)(int, int, int), int PosOkArg, int sx, int sy, int dx, int dy, char *path); 15 | int path_get_h_cost(int sx, int sy, int dx, int dy); 16 | int path_check_equal(PATHNODE *pPath, int dx, int dy); 17 | PATHNODE *GetNextPath(); 18 | BOOL path_solid_pieces(PATHNODE *pPath, int dx, int dy); 19 | BOOL path_get_path(BOOL (*PosOk)(int, int, int), int PosOkArg, PATHNODE *pPath, int x, int y); 20 | BOOL path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy); 21 | PATHNODE *path_get_node1(int dx, int dy); 22 | PATHNODE *path_get_node2(int dx, int dy); 23 | void path_next_node(PATHNODE *pPath); 24 | void path_set_coords(PATHNODE *pPath); 25 | void path_push_active_step(PATHNODE *pPath); 26 | PATHNODE *path_pop_active_step(); 27 | PATHNODE *path_new_step(); 28 | 29 | /* rdata */ 30 | 31 | extern const char pathxdir[8]; 32 | extern const char pathydir[8]; 33 | 34 | /* data */ 35 | extern char path_directions[9]; 36 | 37 | #endif /* __PATH_H__ */ 38 | -------------------------------------------------------------------------------- /Source/ui/titlescreen.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "dialog.h" 3 | #include 4 | 5 | class TitleDialog : public DialogState { 6 | public: 7 | TitleDialog() { 8 | addItem({{0, 0, 640, 480}, ControlType::Image, 0, 0, "", &ArtBackground}); 9 | addItem({{45, 182, 595, 398}, ControlType::Image, 0, -60, "", &ArtLogos[LOGO_BIG]}); 10 | addItem({{49, 410, 599, 436}, ControlType::Text, ControlFlags::Medium | ControlFlags::Center, 0, "Copyright \xA9 1996-2001 Blizzard Entertainment"}); 11 | cursor = false; 12 | } 13 | 14 | void onActivate() override { 15 | UiFadeReset(); 16 | LoadBackgroundArt("ui_art\\title.pcx"); 17 | } 18 | 19 | void onKey(const KeyEvent& e) override { 20 | if (e.action == KeyEvent::Press) { 21 | activate(get_main_menu_dialog()); 22 | } 23 | } 24 | 25 | void onMouse(const MouseEvent& e) override { 26 | if (e.action == MouseEvent::Press) { 27 | activate( get_main_menu_dialog() ); 28 | } 29 | } 30 | 31 | void onRender(unsigned int time) override { 32 | DialogState::onRender(time); 33 | if (!firstFrame_) { 34 | firstFrame_ = time; 35 | } 36 | if (time - firstFrame_ > 7000) { 37 | activate( get_main_menu_dialog() ); 38 | } 39 | } 40 | 41 | private: 42 | unsigned int firstFrame_ = 0; 43 | }; 44 | 45 | GameStatePtr get_title_dialog() { 46 | return new TitleDialog(); 47 | } 48 | -------------------------------------------------------------------------------- /Source/rmpq/adpcm/adpcm.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************************/ 2 | /* adpcm.h Copyright (c) Ladislav Zezula 2003 */ 3 | /*---------------------------------------------------------------------------*/ 4 | /* Header file for adpcm decompress functions */ 5 | /*---------------------------------------------------------------------------*/ 6 | /* Date Ver Who Comment */ 7 | /* -------- ---- --- ------- */ 8 | /* 31.03.03 1.00 Lad The first version of adpcm.h */ 9 | /*****************************************************************************/ 10 | 11 | #ifndef __ADPCM_H__ 12 | #define __ADPCM_H__ 13 | 14 | //----------------------------------------------------------------------------- 15 | // Defines 16 | 17 | #define MAX_ADPCM_CHANNEL_COUNT 2 18 | #define INITIAL_ADPCM_STEP_INDEX 0x2C 19 | 20 | //----------------------------------------------------------------------------- 21 | // Public functions 22 | 23 | int CompressADPCM (void * pvOutBuffer, int dwOutLength, void * pvInBuffer, int dwInLength, int nCmpType, int ChannelCount); 24 | int DecompressADPCM(void * pvOutBuffer, int dwOutLength, void * pvInBuffer, int dwInLength, int ChannelCount); 25 | 26 | #endif // __ADPCM_H__ 27 | -------------------------------------------------------------------------------- /Source/ui/yesno.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "dialog.h" 3 | 4 | class YesNoDialog : public DialogState { 5 | public: 6 | YesNoDialog(const char *title, const char *text, std::function&& next) : 7 | next_(std::move(next)) 8 | { 9 | addItem({{0, 0, 640, 480}, ControlType::Image, 0, 0, "", &ArtBackground}); 10 | addItem({{24, 161, 614, 196}, ControlType::Text, ControlFlags::Center | ControlFlags::Big, 0, title}); 11 | addItem({{120, 236, 520, 404}, ControlType::Text, ControlFlags::Medium | ControlFlags::WordWrap, 0, text}); 12 | addItem({{230, 390, 410, 425}, ControlType::List, ControlFlags::Center | ControlFlags::Big | ControlFlags::Gold, 0, "Yes"}); 13 | addItem({{230, 426, 410, 461}, ControlType::List, ControlFlags::Center | ControlFlags::Big | ControlFlags::Gold, 1, "No"}); 14 | addItem({{125, 0, 515, 154}, ControlType::Image, 0, -60, "", &ArtLogos[LOGO_MED]}); 15 | } 16 | 17 | void onActivate() override { 18 | LoadBackgroundArt("ui_art\\black.pcx"); 19 | } 20 | 21 | void onCancel() override { 22 | next_(false); 23 | } 24 | 25 | void onInput(int value) override { 26 | UiPlaySelectSound(); 27 | next_(value == 0); 28 | } 29 | 30 | private: 31 | std::function next_; 32 | }; 33 | 34 | GameStatePtr get_yesno_dialog(const char* title, const char* text, std::function&& next) { 35 | return new YesNoDialog(title, text, std::move(next)); 36 | } 37 | -------------------------------------------------------------------------------- /Source/asm_trans_rect.inc: -------------------------------------------------------------------------------- 1 | /* Draws a half-transparent rectangle by blacking out odd pixels on odd lines, 2 | * even pixels on even lines. 3 | * 4 | * TRANS_RECT_X = x offset of upper-left corner 5 | * TRANS_RECT_Y = y offset of upper-left corner 6 | * TRANS_RECT_WIDTH = width of rectangle 7 | * TRANS_RECT_HEIGHT = height of rectangle 8 | */ 9 | 10 | #if !defined(TRANS_RECT_X) || !defined(TRANS_RECT_Y) || !defined(TRANS_RECT_WIDTH) || !defined(TRANS_RECT_HEIGHT) 11 | #error ASM_TRANS_RECT: Parameter not set 12 | #endif 13 | 14 | { 15 | int row, col; 16 | BYTE *pix = &gpBuffer[SCREENXY(TRANS_RECT_X, TRANS_RECT_Y + TRANS_RECT_HEIGHT - 1)]; 17 | for (row = TRANS_RECT_HEIGHT >> 1; row != 0; row--) { 18 | for (col = TRANS_RECT_WIDTH >> 1; col != 0; col--) { 19 | *pix++ = 0; 20 | pix++; 21 | } 22 | #if (TRANS_RECT_WIDTH & 1) 23 | *pix++ = 0; 24 | #endif 25 | pix -= BUFFER_WIDTH + TRANS_RECT_WIDTH; 26 | for (col = TRANS_RECT_WIDTH >> 1; col != 0; col--) { 27 | pix++; 28 | *pix++ = 0; 29 | } 30 | pix -= BUFFER_WIDTH + (TRANS_RECT_WIDTH & ~1); 31 | } 32 | #if (TRANS_RECT_HEIGHT & 1) 33 | for (col = TRANS_RECT_WIDTH >> 1; col != 0; col--) { 34 | *pix++ = 0; 35 | pix++; 36 | } 37 | #if (TRANS_RECT_WIDTH & 1) 38 | *pix++ = 0; 39 | #endif 40 | #endif 41 | } 42 | 43 | #undef TRANS_RECT_Y 44 | #undef TRANS_RECT_X 45 | #undef TRANS_RECT_WIDTH 46 | #undef TRANS_RECT_HEIGHT 47 | -------------------------------------------------------------------------------- /Source/net/abstract_net.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../diablo.h" 8 | #include "../storm/storm.h" 9 | 10 | namespace net { 11 | 12 | enum class provider_t { 13 | LOOPBACK, 14 | WEBSOCKET, 15 | }; 16 | 17 | class abstract_net { 18 | public: 19 | virtual void create(std::string name, std::string passwd, uint32_t difficulty) = 0; 20 | virtual void join(std::string name, std::string passwd) = 0; 21 | virtual void poll() {} 22 | 23 | virtual bool SNetReceiveMessage(int* sender, char** data, int* size) = 0; 24 | virtual bool SNetSendMessage(int dest, void* data, unsigned int size) = 0; 25 | virtual bool SNetReceiveTurns(char** data, DWORD* size, DWORD* status) = 0; 26 | virtual bool SNetSendTurn(char* data, unsigned int size) = 0; 27 | virtual int SNetGetProviderCaps(struct _SNETCAPS* caps) = 0; 28 | virtual bool SNetRegisterEventHandler(event_type evtype, SEVTHANDLER func) = 0; 29 | virtual bool SNetUnregisterEventHandler(event_type evtype, SEVTHANDLER func) = 0; 30 | virtual bool SNetLeaveGame(int type) = 0; 31 | virtual bool SNetDropPlayer(int playerid, DWORD flags) = 0; 32 | virtual bool SNetGetOwnerTurnsWaiting(DWORD* turns) = 0; 33 | virtual bool SNetGetTurnsInTransit(int* turns) = 0; 34 | virtual ~abstract_net(); 35 | 36 | static std::unique_ptr make_net(provider_t provider, const char* param); 37 | }; 38 | 39 | } // namespace net 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Devilution for Web 2 | 3 | This is a fork of the original Devilution project, made for https://github.com/d07RiV/diabloweb 4 | 5 | It has been stripped down from all dependencies (Storm.dll, DiabloUI.dll, DirectDraw/DirectSound and Windows), and can be built as a Windows app (using WinAPI and DirectSound) or compiled for web using Emscripten. 6 | It should be fairly easy to port to other platforms as all non-portable functionality is isolated to a few files (search for EMSCRIPTEN in code). Correct behavior is not guaranteed, as I had to modify many parts of the code in the process. Network functionality is completely broken currently, but I plan on attempting to restore it. 7 | 8 | To run it normally, simply build the solution (tested in VS2017, but should work with other versions as well) and set the starting directory to somewhere that contains SPAWN.MPQ or DIABDAT.MPQ (depending on whether SPAWN was defined in options). 9 | 10 | To compile it to WASM/JSCC (jscc is an extension I'm using for javascript glue files so they don't mix with regular JS in my webpack config), simply run `node build.js`, it should automatically build only the modified files. Requires [Emscripten](https://emscripten.org/docs/getting_started/downloads.html) installed. 11 | 12 | The source code in this repository is for non-commerical use only. If you use the source code you may not charge others for access to it or any derivative work thereof. 13 | 14 | Original readme can be found in https://github.com/diasurgical/devilution 15 | -------------------------------------------------------------------------------- /Source/gmenu.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __GMENU_H__ 3 | #define __GMENU_H__ 4 | 5 | extern BYTE *optbar_cel; 6 | extern BOOLEAN mouseNavigation; 7 | extern BYTE *PentSpin_cel; 8 | extern BYTE *BigTGold_cel; 9 | extern int dword_634474; 10 | extern char byte_634478; 11 | extern void (*dword_63447C)(TMenuItem *); 12 | extern TMenuItem *sgpCurrentMenu; 13 | extern BYTE *option_cel; 14 | extern int sgCurrentMenuIdx; 15 | 16 | void gmenu_draw_pause(); 17 | void gmenu_print_text(int x, int y, const char *pszStr); 18 | void FreeGMenu(); 19 | void gmenu_init_menu(); 20 | BOOL gmenu_exception(); 21 | void gmenu_call_proc(TMenuItem *pItem, void (*gmFunc)(TMenuItem *)); 22 | void gmenu_up_down(BOOL isDown); 23 | void gmenu_draw(); 24 | void gmenu_draw_menu_item(TMenuItem *pItem, int y); 25 | void gmenu_clear_buffer(int x, int y, int width, int height); 26 | int gmenu_get_lfont(TMenuItem *pItem); 27 | BOOL gmenu_presskeys(int vkey); 28 | void gmenu_left_right(BOOL isRight); 29 | BOOL gmenu_on_mouse_move(); 30 | BOOLEAN gmenu_valid_mouse_pos(int *plOffset); 31 | BOOL gmenu_left_mouse(BOOL isDown); 32 | void gmenu_enable(TMenuItem *pMenuItem, BOOL enable); 33 | void gmenu_slider_set(TMenuItem *pItem, int min, int max, int gamma); 34 | int gmenu_slider_get(TMenuItem *pItem, int min, int max); 35 | void gmenu_slider_steps(TMenuItem *pItem, int dwTicks); 36 | 37 | /* rdata */ 38 | 39 | extern const BYTE lfontframe[127]; 40 | extern const BYTE lfontkern[56]; 41 | 42 | #endif /* __GMENU_H__ */ 43 | -------------------------------------------------------------------------------- /Source/town.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __TOWN_H__ 3 | #define __TOWN_H__ 4 | 5 | void town_clear_upper_buf(BYTE *pBuff); 6 | void town_clear_low_buf(BYTE *pBuff); 7 | void town_special_lower(BYTE *pBuff, int nCel); 8 | void town_special_upper(BYTE *pBuff, int nCel); 9 | void town_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int sy); 10 | void town_draw_clipped_town(BYTE *pBuff, int sx, int sy, int dx, int dy, int eflag); 11 | void town_draw_lower(int x, int y, int sx, int sy, int chunks, int eflag); 12 | void town_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipChunks, int CelSkip, int sx, int sy); 13 | void town_draw_clipped_town_2(BYTE *pBuff, int sx, int sy, int skipChunks, int CelSkip, int dx, int dy, int eflag); 14 | void town_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, int eflag); 15 | void town_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int sx, int sy); 16 | void town_draw_town_all(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int sx, int sy, int eflag); 17 | void town_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, int eflag); 18 | void T_DrawGame(int x, int y); 19 | void T_DrawZoom(int x, int y); 20 | void T_DrawView(int StartX, int StartY); 21 | void SetTownMicros(); 22 | void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h); 23 | void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t); 24 | void T_Pass3(); 25 | void CreateTown(int entry); 26 | 27 | #endif /* __TOWN_H__ */ 28 | -------------------------------------------------------------------------------- /Source/mpqapi.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __MPQAPI_H__ 3 | #define __MPQAPI_H__ 4 | 5 | extern char mpq_buf[4096]; 6 | extern BOOL save_archive_modified; 7 | extern BOOLEAN save_archive_open; 8 | 9 | void mpqapi_xor_buf(char *pbData); 10 | void mpqapi_remove_hash_entry(const char *pszName); 11 | void mpqapi_alloc_block(int block_offset, int block_size); 12 | _BLOCKENTRY *mpqapi_new_block(int *block_index); 13 | int FetchHandle(const char *pszName); 14 | int mpqapi_get_hash_index(short index, int hash_a, int hash_b, int locale); 15 | void mpqapi_remove_hash_entries(BOOL( *fnGetName)(DWORD, char *)); 16 | BOOL mpqapi_write_file(const char *pszName, const BYTE *pbData, DWORD dwLen); 17 | _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_index); 18 | BOOL mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, DWORD dwLen, _BLOCKENTRY *pBlk); 19 | int mpqapi_find_free_block(int size, int *block_size); 20 | void mpqapi_rename(char *pszOld, char *pszNew); 21 | BOOL mpqapi_has_file(const char *pszName); 22 | BOOL OpenMPQ(const char *pszArchive, BOOL hidden, DWORD dwChar); 23 | BOOL ParseMPQHeader(_FILEHEADER *pHdr, DWORD *pdwNextFileStart); 24 | void CloseMPQ(const char *pszArchive, BOOL bFree, DWORD dwChar); 25 | BOOL mpqapi_flush_and_close(const char *pszArchive, BOOL bFree, DWORD dwChar); 26 | BOOL WriteMPQHeader(); 27 | BOOL mpqapi_write_block_table(); 28 | BOOL mpqapi_write_hash_table(); 29 | BOOL mpqapi_can_seek(); 30 | 31 | /* rdata */ 32 | 33 | /* data */ 34 | 35 | #endif /* __MPQAPI_H__ */ 36 | -------------------------------------------------------------------------------- /mpqcmp/shine/mult_mips_gcc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define mul(a,b) \ 4 | ({ \ 5 | register int32_t res; \ 6 | __asm__ __volatile__("mult %0, %1" : : "r" (a), "r" (b)); \ 7 | __asm__ __volatile__("mfhi %0" : "=r" (res)); \ 8 | res; \ 9 | }) 10 | 11 | #define mul0(hi,lo,a,b) \ 12 | __asm__ __volatile__("mult %0, %1" : : "r" (a), "r" (b)) 13 | 14 | #define muladd(hi,lo,a,b) \ 15 | __asm__ __volatile__("madd %0, %1" : : "r" (a), "r" (b)) 16 | 17 | #define mulsub(hi,lo,a,b) \ 18 | __asm__ __volatile__("msub %0, %1" : : "r" (a), "r" (b)) 19 | 20 | #define mulz(hi,lo) \ 21 | do { \ 22 | register int32_t t; \ 23 | __asm__ __volatile__("mfhi %0" : "=r" (t)); \ 24 | (hi) = t; \ 25 | } while (0) 26 | 27 | #define cmuls(dre, dim, are, aim, bre, bim) \ 28 | do { \ 29 | register int32_t t1, t2, tre; \ 30 | __asm__ __volatile__("mult %0, %1" : : "r" (are), "r" (bre)); \ 31 | __asm__ __volatile__("msub %0, %1" : : "r" (aim), "r" (bim)); \ 32 | __asm__ __volatile__("mfhi %0; mflo %1" : "=r" (t1), "=r" (t2)); \ 33 | tre = (t1 << 1) | ((uint32_t)t2 >> 31); \ 34 | __asm__ __volatile__("mult %0, %1" : : "r" (are), "r" (bim)); \ 35 | __asm__ __volatile__("madd %0, %1" : : "r" (bre), "r" (aim)); \ 36 | dre = tre; \ 37 | __asm__ __volatile__("mfhi %0; mflo %1" : "=r" (t1), "=r" (t2)); \ 38 | dim = (t1 << 1) | ((uint32_t)t2 >> 31); \ 39 | } while (0) 40 | 41 | #if __mips_isa_rev >= 2 42 | static inline uint32_t SWAB32(uint32_t x) 43 | { 44 | __asm__( 45 | " wsbh %0, %1 \n" 46 | " rotr %0, %0, 16 \n" 47 | : "=r" (x) : "r" (x)); 48 | return x; 49 | } 50 | #define SWAB32 SWAB32 51 | #endif 52 | -------------------------------------------------------------------------------- /Source/net/websocket_browser.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../../Server/packet.hpp" 5 | #include "../trace.h" 6 | 7 | EM_JS(void, api_websocket_send, (const void* ptr, int size), { 8 | self.DApi.websocket_send(HEAPU8.subarray(ptr, ptr + size)); 9 | }); 10 | EM_JS(int, api_websocket_closed, (), { 11 | return self.DApi.websocket_closed(); 12 | }); 13 | 14 | class websocket_impl; 15 | 16 | static websocket_impl* impl_ = nullptr; 17 | 18 | class websocket_impl { 19 | public: 20 | websocket_impl() { 21 | impl_ = this; 22 | } 23 | ~websocket_impl() { 24 | impl_ = nullptr; 25 | } 26 | 27 | void send(const packet& p) { 28 | size_t size = p.size(); 29 | pkt_.resize(size); 30 | p.serialize(pkt_.data()); 31 | api_websocket_send(pkt_.data(), pkt_.size()); 32 | } 33 | 34 | bool is_closed() { 35 | return api_websocket_closed();; 36 | } 37 | 38 | void receive(std::function handler) { 39 | for (auto& pkt : pending_) { 40 | handler(pkt.data(), pkt.size()); 41 | } 42 | pending_.clear(); 43 | } 44 | 45 | void* alloc_packet(int size) { 46 | pending_.emplace_back((size_t) size); 47 | return pending_.back().data(); 48 | } 49 | 50 | private: 51 | std::vector pkt_; 52 | std::vector> pending_; 53 | }; 54 | 55 | extern "C" { 56 | 57 | EMSCRIPTEN_KEEPALIVE 58 | void* DApi_AllocPacket(int size) { 59 | if (impl_) { 60 | return impl_->alloc_packet(size); 61 | } else { 62 | return nullptr; 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Source/quests.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __QUESTS_H__ 3 | #define __QUESTS_H__ 4 | 5 | extern int qtopline; 6 | extern BOOL questlog; 7 | extern BYTE *pQLogCel; 8 | extern QuestStruct quests[MAXQUESTS]; 9 | extern int qline; 10 | extern int qlist[MAXQUESTS]; 11 | extern int numqlines; 12 | extern int WaterDone; 13 | extern int ReturnLvlY; 14 | extern int ReturnLvlX; 15 | extern int ReturnLvlT; 16 | extern int ALLQUESTS; 17 | extern int ReturnLvl; 18 | 19 | void InitQuests(); 20 | void CheckQuests(); 21 | BOOL ForceQuests(); 22 | BOOL QuestStatus(int i); 23 | void CheckQuestKill(int m, BOOL sendmsg); 24 | void DrawButcher(); 25 | void DrawSkelKing(int q, int x, int y); 26 | void DrawWarLord(int x, int y); 27 | void DrawSChamber(int q, int x, int y); 28 | void DrawLTBanner(int x, int y); 29 | void DrawBlind(int x, int y); 30 | void DrawBlood(int x, int y); 31 | void DRLG_CheckQuests(int x, int y); 32 | void SetReturnLvlPos(); 33 | void GetReturnLvlPos(); 34 | void ResyncMPQuests(); 35 | void ResyncQuests(); 36 | void PrintQLString(int x, int y, BOOL cjustflag, const char *str, int col); 37 | void DrawQuestLog(); 38 | void StartQuestlog(); 39 | void QuestlogUp(); 40 | void QuestlogDown(); 41 | void QuestlogEnter(); 42 | void QuestlogESC(); 43 | void SetMultiQuest(int q, int s, int l, int v1); 44 | 45 | /* rdata */ 46 | extern QuestData questlist[MAXQUESTS]; 47 | extern char questxoff[7]; 48 | extern char questyoff[7]; 49 | extern const char *questtrigstr[5]; 50 | extern int QuestGroup1[3]; 51 | extern int QuestGroup2[3]; 52 | extern int QuestGroup3[3]; 53 | extern int QuestGroup4[2]; 54 | 55 | #endif /* __QUESTS_H__ */ 56 | -------------------------------------------------------------------------------- /Source/libsmacker/smk_bitstream.h: -------------------------------------------------------------------------------- 1 | /** 2 | libsmacker - A C library for decoding .smk Smacker Video files 3 | Copyright (C) 2012-2017 Greg Kennedy 4 | 5 | See smacker.h for more information. 6 | 7 | smk_bitstream.h 8 | SMK bitstream structure. Presents a block of raw bytes one 9 | bit at a time, and protects against over-read. 10 | */ 11 | 12 | #ifndef SMK_BITSTREAM_H 13 | #define SMK_BITSTREAM_H 14 | 15 | /** Bitstream structure, Forward declaration */ 16 | struct smk_bit_t; 17 | 18 | /* BITSTREAM Functions */ 19 | /** Initialize a bitstream */ 20 | struct smk_bit_t* smk_bs_init(const unsigned char* b, const unsigned long size); 21 | 22 | /** This macro checks return code from _smk_bs_read_1 and 23 | jumps to error label if problems occur. */ 24 | #define smk_bs_read_1(t,uc) \ 25 | { \ 26 | if ((char)(uc = _smk_bs_read_1(t)) < 0) \ 27 | { \ 28 | fprintf(stderr, "libsmacker::smk_bs_read_1(" #t ", " #uc ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ 29 | goto error; \ 30 | } \ 31 | } 32 | /** Read a single bit from the bitstream, and advance. 33 | Returns -1 on error. */ 34 | char _smk_bs_read_1(struct smk_bit_t* bs); 35 | 36 | /** This macro checks return code from _smk_bs_read_8 and 37 | jumps to error label if problems occur. */ 38 | #define smk_bs_read_8(t,s) \ 39 | { \ 40 | if ((short)(s = _smk_bs_read_8(t)) < 0) \ 41 | { \ 42 | fprintf(stderr, "libsmacker::smk_bs_read_8(" #t ", " #s ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ 43 | goto error; \ 44 | } \ 45 | } 46 | /** Read eight bits from the bitstream (one byte), and advance. 47 | Returns -1 on error. */ 48 | short _smk_bs_read_8(struct smk_bit_t* bs); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Source/init.cpp: -------------------------------------------------------------------------------- 1 | #ifndef EMSCRIPTEN 2 | #include 3 | #include 4 | #else 5 | #include 6 | #endif 7 | #include "diablo.h" 8 | #include "storm/storm.h" 9 | #include "ui/diabloui.h" 10 | #include "ui/common.h" 11 | 12 | _SNETVERSIONDATA fileinfo; 13 | int gbActive; 14 | HANDLE diabdat_mpq; 15 | 16 | uint32_t gdwProductVersion = (1 << 16); 17 | 18 | char gszVersionNumber[MAX_PATH] = "Version 1.0.0"; 19 | char gszProductName[MAX_PATH] = "DiabloWeb v1.0.0"; 20 | 21 | void set_client_version(int v0, int v1, int v2) { 22 | gdwProductVersion = (v0 << 16) | (v1 << 8) | v2; 23 | sprintf(gszVersionNumber, "Version %d.%d.%d", v0, v1, v2); 24 | sprintf(gszProductName, "DiabloWeb v%d.%d.%d", v0, v1, v2); 25 | } 26 | 27 | void api_current_save_id(int id) { 28 | #ifdef EMSCRIPTEN 29 | EM_ASM_({ 30 | self.DApi.current_save_id($0); 31 | }, id); 32 | #endif 33 | } 34 | 35 | 36 | #ifdef EMSCRIPTEN 37 | #include 38 | EM_JS(void, _api_open_keyboard, (int x0, int y0, int x1, int y1, int len), { 39 | self.DApi.open_keyboard(x0, y0, x1, y1, len); 40 | }); 41 | EM_JS(void, _api_close_keyboard, (), { 42 | self.DApi.close_keyboard(); 43 | }); 44 | int _hasKeyboard = 0; 45 | void api_open_keyboard(int x0, int y0, int x1, int y1, int len) { 46 | if (_GetTickCount() > _hasKeyboard + 1000) { 47 | _api_open_keyboard(x0, y0, x1, y1, len); 48 | _hasKeyboard = _GetTickCount(); 49 | } 50 | } 51 | void api_close_keyboard() { 52 | _api_close_keyboard(); 53 | _hasKeyboard = 0; 54 | } 55 | #else 56 | void api_open_keyboard(int x0, int y0, int x1, int y1, int len) { 57 | } 58 | void api_close_keyboard() { 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /Source/themes.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __THEMES_H__ 3 | #define __THEMES_H__ 4 | 5 | extern int numthemes; 6 | extern BOOL armorFlag; 7 | extern BOOL ThemeGoodIn[4]; 8 | extern BOOL weaponFlag; 9 | extern BOOL treasureFlag; 10 | extern BOOL mFountainFlag; 11 | extern BOOL cauldronFlag; 12 | extern BOOL tFountainFlag; 13 | extern int zharlib; 14 | extern int themex; 15 | extern int themey; 16 | extern int themeVar1; 17 | extern ThemeStruct themes[MAXTHEMES]; 18 | extern BOOL pFountainFlag; 19 | extern BOOL bFountainFlag; 20 | extern BOOL bCrossFlag; 21 | 22 | BOOL TFit_Shrine(int i); 23 | BOOL TFit_Obj5(int t); 24 | BOOL TFit_SkelRoom(int t); 25 | BOOL TFit_GoatShrine(int t); 26 | BOOL CheckThemeObj3(int xp, int yp, int t, int f); 27 | BOOL TFit_Obj3(int t); 28 | BOOL CheckThemeReqs(int t); 29 | BOOL SpecialThemeFit(int i, int t); 30 | BOOL CheckThemeRoom(int tv); 31 | void InitThemes(); 32 | void HoldThemeRooms(); 33 | void PlaceThemeMonsts(int t, int f); 34 | void Theme_Barrel(int t); 35 | void Theme_Shrine(int t); 36 | void Theme_MonstPit(int t); 37 | void Theme_SkelRoom(int t); 38 | void Theme_Treasure(int t); 39 | void Theme_Library(int t); 40 | void Theme_Torture(int t); 41 | void Theme_BloodFountain(int t); 42 | void Theme_Decap(int t); 43 | void Theme_PurifyingFountain(int t); 44 | void Theme_ArmorStand(int t); 45 | void Theme_GoatShrine(int t); 46 | void Theme_Cauldron(int t); 47 | void Theme_MurkyFountain(int t); 48 | void Theme_TearFountain(int t); 49 | void Theme_BrnCross(int t); 50 | void Theme_WeaponRack(int t); 51 | void UpdateL4Trans(); 52 | void CreateThemeRooms(); 53 | 54 | /* rdata */ 55 | 56 | extern int ThemeGood[4]; 57 | extern int trm5x[25]; 58 | extern int trm5y[25]; 59 | extern int trm3x[9]; 60 | extern int trm3y[9]; 61 | 62 | #endif /* __THEMES_H__ */ 63 | -------------------------------------------------------------------------------- /Source/inv.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __INV_H__ 3 | #define __INV_H__ 4 | 5 | extern BOOL invflag; 6 | extern BOOL drawsbarflag; 7 | 8 | void FreeInvGFX(); 9 | void InitInv(); 10 | void InvDrawSlotBack(int X, int Y, int W, int H); 11 | void DrawInv(); 12 | void DrawInvBelt(); 13 | BOOL AutoPlace(int pnum, int ii, int sx, int sy, BOOL saveflag); 14 | BOOL SpecialAutoPlace(int pnum, int ii, int sx, int sy, BOOL saveflag); 15 | BOOL GoldAutoPlace(int pnum); 16 | BOOL WeaponAutoPlace(int pnum); 17 | int SwapItem(ItemStruct *a, ItemStruct *b); 18 | void CheckInvPaste(int pnum, int mx, int my); 19 | void CheckInvSwap(int pnum, BYTE bLoc, int idx, WORD wCI, int seed, BOOL bId); 20 | void CheckInvCut(int pnum, int mx, int my); 21 | void inv_update_rem_item(int pnum, BYTE iv); 22 | void RemoveInvItem(int pnum, int iv); 23 | void RemoveSpdBarItem(int pnum, int iv); 24 | void CheckInvItem(); 25 | void CheckInvScrn(); 26 | void CheckItemStats(int pnum); 27 | void CheckBookLevel(int pnum); 28 | void CheckQuestItem(int pnum); 29 | void InvGetItem(int pnum, int ii); 30 | void AutoGetItem(int pnum, int ii); 31 | int FindGetItem(int idx, WORD ci, int iseed); 32 | void SyncGetItem(int x, int y, int idx, WORD ci, int iseed); 33 | BOOL CanPut(int x, int y); 34 | BOOL TryInvPut(); 35 | void DrawInvMsg(const char *msg); 36 | int InvPutItem(int pnum, int x, int y); 37 | int SyncPutItem(int pnum, int x, int y, int idx, WORD icreateinfo, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, DWORD ibuff); 38 | char CheckInvHLight(); 39 | void RemoveScroll(int pnum); 40 | BOOL UseScroll(); 41 | void UseStaffCharge(int pnum); 42 | BOOL UseStaff(); 43 | void StartGoldDrop(); 44 | BOOL UseInvItem(int pnum, int cii); 45 | void DoTelekinesis(); 46 | int CalculateGold(int pnum); 47 | BOOL DropItemBeforeTrig(); 48 | 49 | /* data */ 50 | 51 | extern int AP2x2Tbl[10]; 52 | 53 | #endif /* __INV_H__ */ 54 | -------------------------------------------------------------------------------- /Source/lighting.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __LIGHTING_H__ 3 | #define __LIGHTING_H__ 4 | 5 | extern LightListStruct VisionList[MAXVISION]; 6 | extern BYTE lightactive[MAXLIGHTS]; 7 | extern LightListStruct LightList[MAXLIGHTS]; 8 | extern int numlights; 9 | extern BYTE lightradius[16][128]; 10 | extern BOOL dovision; 11 | extern int numvision; 12 | extern char lightmax; 13 | extern BOOL dolighting; 14 | extern BYTE lightblock[8][8][16][16]; 15 | extern int visionid; 16 | extern BYTE *pLightTbl; 17 | extern BOOL lightflag; 18 | 19 | void RotateRadius(int *x, int *y, int *dx, int *dy, int *lx, int *ly, int *bx, int *by); 20 | void DoLighting(int nXPos, int nYPos, int nRadius, int Lnum); 21 | void DoUnLight(int nXPos, int nYPos, int nRadius); 22 | void DoUnVision(int nXPos, int nYPos, int nRadius); 23 | void DoVision(int nXPos, int nYPos, int nRadius, BOOL doautomap, BOOL visible); 24 | void FreeLightTable(); 25 | void InitLightTable(); 26 | void MakeLightTable(); 27 | #ifdef _DEBUG 28 | void ToggleLighting_2(); 29 | void ToggleLighting(); 30 | #endif 31 | void InitLightMax(); 32 | void InitLighting(); 33 | int AddLight(int x, int y, int r); 34 | void AddUnLight(int i); 35 | void ChangeLightRadius(int i, int r); 36 | void ChangeLightXY(int i, int x, int y); 37 | void ChangeLightOff(int i, int x, int y); 38 | void ChangeLight(int i, int x, int y, int r); 39 | void ProcessLightList(); 40 | void SavePreLighting(); 41 | void InitVision(); 42 | int AddVision(int x, int y, int r, BOOL mine); 43 | void ChangeVisionRadius(int id, int r); 44 | void ChangeVisionXY(int id, int x, int y); 45 | void ProcessVisionList(); 46 | void lighting_color_cycling(); 47 | 48 | /* rdata */ 49 | 50 | extern char CrawlTable[2749]; 51 | extern char *pCrawlTable[19]; 52 | extern BYTE vCrawlTable[23][30]; 53 | extern BYTE byte_49463C[18][18]; 54 | extern BYTE RadiusAdj[23]; 55 | 56 | #endif /* __LIGHTING_H__ */ 57 | -------------------------------------------------------------------------------- /Source/trace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace __Trace { 6 | 7 | static struct __null_type {} __null_value; 8 | 9 | template 10 | std::string _to_string(const char* prefix, T value) { 11 | return prefix + std::to_string(value); 12 | } 13 | 14 | template<> 15 | inline std::string _to_string(const char* prefix, const char* value) { 16 | std::string str(prefix); 17 | str.push_back('"'); 18 | str.append(value); 19 | str.push_back('"'); 20 | return str; 21 | } 22 | 23 | template<> 24 | inline std::string _to_string(const char* prefix, char* value) { 25 | std::string str(prefix); 26 | str.push_back('"'); 27 | str.append(value); 28 | str.push_back('"'); 29 | return str; 30 | } 31 | 32 | template<> 33 | inline std::string _to_string(const char* prefix, __null_type) { 34 | return ""; 35 | } 36 | 37 | inline const char* _to_string(const char* prefix) { 38 | return ""; 39 | } 40 | 41 | struct Guard { 42 | Guard(const char* name, const std::string& args); 43 | ~Guard(); 44 | }; 45 | 46 | } 47 | 48 | #define __EXPAND(x) x 49 | #define __ARG(...) __Trace::_to_string("\n\t" #__VA_ARGS__ " = ", ## __VA_ARGS__) 50 | #define __STRINGIFY(x) #x 51 | #define __CONCAT(x, y) x ## y 52 | #define __TOSTRING(x) __STRINGIFY(x) 53 | #define __VAR_NAME(x) __CONCAT(__trace_, x) 54 | #define __LOG_STACK(args) __Trace::Guard __VAR_NAME(__LINE__)(__FILE__ ":" __TOSTRING(__LINE__), args) 55 | #define __LOG_STACK_ARGS(a, b, c, d, e, f, g, h, i, j, ...) __LOG_STACK(__ARG(a) + __ARG(b) + __ARG(c) + __ARG(d) + __ARG(e) + __ARG(f) + __ARG(g) + __ARG(h) + __ARG(i) + __ARG(j)) 56 | #define LOG_STACK(...) __EXPAND(__LOG_STACK_ARGS(__VA_ARGS__, __Trace::__null_value, \ 57 | __Trace::__null_value, __Trace::__null_value, __Trace::__null_value, __Trace::__null_value, __Trace::__null_value, \ 58 | __Trace::__null_value, __Trace::__null_value, __Trace::__null_value, __Trace::__null_value, __Trace::__null_value)) 59 | -------------------------------------------------------------------------------- /Source/ui/dialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include 5 | 6 | enum class ControlType { 7 | Text, 8 | Image, 9 | Button, 10 | List, 11 | Edit, 12 | }; 13 | 14 | namespace ControlFlags { 15 | enum { 16 | Small = 0x0001, 17 | Medium = 0x0002, 18 | Big = 0x0004, 19 | Huge = 0x0008, 20 | Center = 0x0010, 21 | Right = 0x0020, 22 | VCenter = 0x0040, 23 | Silver = 0x0080, 24 | Gold = 0x0100, 25 | Small1 = 0x0200, 26 | Small2 = 0x0400, 27 | List = 0x0800, 28 | Disabled = 0x1000, 29 | Hidden = 0x2000, 30 | WordWrap = 0x4000, 31 | }; 32 | } 33 | 34 | class DialogState : public GameState { 35 | public: 36 | struct Item { 37 | RECT rect; 38 | ControlType type; 39 | int flags; 40 | int value; 41 | std::string text; 42 | Art* image; 43 | }; 44 | 45 | protected: 46 | int addItem(Item&& item) { 47 | items.emplace_back(std::move(item)); 48 | if (item.type == ControlType::List && selected < 0) { 49 | selected = item.value; 50 | } 51 | return (int) items.size() - 1; 52 | } 53 | 54 | std::vector items; 55 | enum : int { SELECT_NONE = std::numeric_limits::min() }; 56 | int selected = SELECT_NONE; 57 | bool wraps = true; 58 | bool cursor = true; 59 | bool doubleclick = false; 60 | 61 | virtual void onCancel(){}; 62 | virtual void onInput(int id){}; 63 | virtual void onFocus(int value){}; 64 | 65 | virtual void onActivate() override; 66 | virtual void onDeactivate() override; 67 | 68 | virtual void onRender(unsigned int time) override; 69 | virtual void onMouse(const MouseEvent& e) override; 70 | virtual void onKey(const KeyEvent& e) override; 71 | virtual void onChar(char chr) override; 72 | virtual void onText(const char* text, int flags) override; 73 | 74 | virtual void renderExtra(unsigned int time){}; 75 | 76 | private: 77 | DWORD prevClick_ = 0; 78 | void setFocus_(int index, bool wrap); 79 | }; 80 | -------------------------------------------------------------------------------- /Source/msgcmd.cpp: -------------------------------------------------------------------------------- 1 | #include // for placement new 2 | #include // for offsetof 3 | #include // for typeid 4 | #include "storm/storm.h" 5 | 6 | #include "diablo.h" 7 | #include "list.h" 8 | 9 | #define COMMAND_LEN 128 10 | 11 | // static float msgcmd_init_cpp_value = 0x7F800000; 12 | 13 | struct EXTERNMESSAGE { 14 | LIST_LINK(EXTERNMESSAGE) 15 | m_Link; 16 | char command[COMMAND_LEN]; 17 | void *operator new(size_t n, DWORD extralen, int flags) 18 | { 19 | return SMemAlloc(n + extralen, (char *)OBJECT_NAME(EXTERNMESSAGE), SLOG_OBJECT, flags | (1 << 3)); 20 | } 21 | void operator delete(void *address, DWORD extralen, int flags) 22 | { 23 | } 24 | void operator delete(void *address) 25 | { 26 | } 27 | void *Delete(DWORD flags); 28 | }; 29 | 30 | void *EXTERNMESSAGE::Delete(DWORD flags) 31 | { 32 | // BUGFIX: this is already called by m_Link's destructor 33 | m_Link.Unlink(); 34 | this->~EXTERNMESSAGE(); 35 | if ((flags & 0x1)) { 36 | SMemFree(this, "delete", SLOG_FUNCTION, 0); 37 | } 38 | return this; 39 | } 40 | 41 | static TList sgChat_Cmd; 42 | 43 | void msgcmd_cmd_cleanup() 44 | { 45 | sgChat_Cmd.DeleteAll(); 46 | } 47 | 48 | void msgcmd_send_chat() 49 | { 50 | DWORD tick; 51 | struct EXTERNMESSAGE *msg = sgChat_Cmd.Head(); 52 | 53 | if (msg) { 54 | static DWORD sgdwMsgCmdTimer; 55 | tick = _GetTickCount(); 56 | if (tick - sgdwMsgCmdTimer >= 2000) { 57 | sgdwMsgCmdTimer = tick; 58 | SNetSendServerChatCommand(msg->command); 59 | sgChat_Cmd.Remove(msg); 60 | } 61 | } 62 | } 63 | 64 | BOOL msgcmd_add_server_cmd_W(const char *chat_message) 65 | { 66 | if (chat_message[0] != '/') 67 | return FALSE; 68 | msgcmd_add_server_cmd(chat_message); 69 | return TRUE; 70 | } 71 | 72 | void msgcmd_add_server_cmd(const char *command) 73 | { 74 | size_t len = strlen(command); 75 | if (len && ++len <= COMMAND_LEN) { 76 | struct EXTERNMESSAGE *msg = sgChat_Cmd.Create(); 77 | memcpy(msg->command, command, len); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Source/doom.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | 3 | int doom_quest_time; 4 | int doom_stars_drawn; 5 | BYTE *pDoomCel; 6 | BOOL doomflag; 7 | int DoomQuestState; 8 | 9 | /* 10 | void doom_reset_state() 11 | { 12 | if (DoomQuestState <= 0) { 13 | DoomQuestState = 0; 14 | } 15 | } 16 | 17 | void doom_play_movie() 18 | { 19 | if (DoomQuestState < 36001) { 20 | DoomQuestState++; 21 | if (DoomQuestState == 36001) { 22 | PlayInGameMovie("gendata\\doom.smk"); 23 | DoomQuestState++; 24 | } 25 | } 26 | } 27 | */ 28 | 29 | int doom_get_frame_from_time() 30 | { 31 | if (DoomQuestState == 36001) { 32 | return 31; 33 | } 34 | 35 | return DoomQuestState / 1200; 36 | } 37 | 38 | void doom_alloc_cel() 39 | { 40 | pDoomCel = DiabloAllocPtr(229376); 41 | } 42 | 43 | void doom_cleanup() 44 | { 45 | MemFreeDbg(pDoomCel); 46 | } 47 | 48 | void doom_load_graphics() 49 | { 50 | if (doom_quest_time == 31) { 51 | strcpy(tempstr, "Items\\Map\\MapZDoom.CEL"); 52 | } else if (doom_quest_time < 10) { 53 | sprintf(tempstr, "Items\\Map\\MapZ000%i.CEL", doom_quest_time); 54 | } else { 55 | sprintf(tempstr, "Items\\Map\\MapZ00%i.CEL", doom_quest_time); 56 | } 57 | LoadFileWithMem(tempstr, pDoomCel); 58 | } 59 | 60 | void doom_init() 61 | { 62 | doomflag = TRUE; 63 | doom_alloc_cel(); 64 | doom_quest_time = doom_get_frame_from_time() == 31 ? 31 : 0; 65 | doom_load_graphics(); 66 | } 67 | 68 | void doom_close() 69 | { 70 | if (doomflag) { 71 | doomflag = FALSE; 72 | doom_cleanup(); 73 | } 74 | } 75 | 76 | void doom_draw() 77 | { 78 | if (!doomflag) { 79 | return; 80 | } 81 | 82 | if (doom_quest_time != 31) { 83 | doom_stars_drawn++; 84 | if (doom_stars_drawn >= 5) { 85 | doom_stars_drawn = 0; 86 | doom_quest_time++; 87 | if (doom_quest_time > doom_get_frame_from_time()) { 88 | doom_quest_time = 0; 89 | } 90 | doom_load_graphics(); 91 | } 92 | } 93 | 94 | CelDecodeOnly(SCREEN_X, PANEL_Y - 1, pDoomCel, 1, SCREEN_WIDTH); 95 | } 96 | -------------------------------------------------------------------------------- /Source/pfile.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __PFILE_H__ 3 | #define __PFILE_H__ 4 | 5 | extern BOOL gbValidSaveFile; 6 | extern char gszHero[16]; 7 | 8 | void pfile_init_save_directory(); 9 | void pfile_check_available_space(char *pszDir); 10 | void pfile_write_hero(); 11 | DWORD pfile_get_save_num_from_name(const char *name); 12 | void pfile_encode_hero(const PkPlayerStruct *pPack); 13 | BOOL pfile_open_archive(BOOL update, DWORD save_num); 14 | void pfile_get_save_path(char *pszBuf, DWORD dwBufSize, DWORD save_num); 15 | void pfile_flush(BOOL is_single_player, DWORD save_num); 16 | BOOL pfile_create_player_description(char *dst, DWORD len); 17 | BOOL pfile_rename_hero(const char *name_1, const char *name_2); 18 | void pfile_flush_W(); 19 | void game_2_ui_player(const PlayerStruct *p, _uiheroinfo *heroinfo, BOOL bHasSaveFile); 20 | BYTE game_2_ui_class(const PlayerStruct *p); 21 | BOOL pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack); 22 | HANDLE pfile_open_save_archive(BOOL *showFixedMsg, DWORD save_num); 23 | void pfile_SFileCloseArchive(HANDLE hsArchive); 24 | BOOL pfile_archive_contains_game(HANDLE hsArchive, DWORD save_num); 25 | BOOL pfile_ui_set_class_stats(unsigned int player_class_nr, _uidefaultstats *class_stats); 26 | char pfile_get_player_class(unsigned int player_class_nr); 27 | BOOL pfile_ui_save_create(_uiheroinfo *heroinfo); 28 | BOOL pfile_get_file_name(DWORD lvl, char *dst); 29 | BOOL pfile_delete_save(_uiheroinfo *hero_info); 30 | void pfile_read_player_from_save(); 31 | void GetTempLevelNames(char *szTemp); 32 | void GetPermLevelNames(char *szPerm); 33 | void pfile_get_game_name(char *dst); 34 | void pfile_remove_temp_files(); 35 | BOOL GetTempSaveNames(DWORD dwIndex, char *szTemp); 36 | void pfile_rename_temp_to_perm(); 37 | BOOL GetPermSaveNames(DWORD dwIndex, char *szPerm); 38 | void pfile_write_save_file(const char *pszName, BYTE *pbData, DWORD dwLen, DWORD qwLen); 39 | void pfile_strcpy(char *dst, const char *src); 40 | BYTE *pfile_read(const char *pszName, DWORD *pdwLen); 41 | void pfile_update(BOOL force_save); 42 | 43 | /* rdata */ 44 | 45 | #endif /* __PFILE_H__ */ 46 | -------------------------------------------------------------------------------- /Source/rmpq/archive.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "file.h" 4 | #include "locale.h" 5 | #include "common.h" 6 | 7 | #include 8 | 9 | namespace mpq { 10 | 11 | namespace FileFlags { 12 | enum { 13 | CompressPkWare = 0x00000100, 14 | CompressMulti = 0x00000200, 15 | Compressed = 0x0000FF00, 16 | Encrypted = 0x00010000, 17 | FixSeed = 0x00020000, 18 | PatchFile = 0x00100000, 19 | SingleUnit = 0x01000000, 20 | DummyFile = 0x02000000, 21 | SectorCrc = 0x04000000, 22 | Exists = 0x80000000, 23 | }; 24 | } 25 | 26 | class ListFile; 27 | 28 | class Archive : public FileLoader { 29 | public: 30 | Archive(File file); 31 | 32 | void listFiles(File list); 33 | 34 | size_t getMaxFiles() const; 35 | bool fileExists(size_t index) const; 36 | bool testFile(size_t index); 37 | 38 | bool fileExists(char const* name) const; 39 | bool fileExists(char const* name, uint16_t locale) const; 40 | 41 | MPQHashEntry const& hashEntry(size_t index) { 42 | return hashTable_[index]; 43 | } 44 | 45 | virtual File load(char const* name) override; 46 | File load(char const* name, uint16_t locale); 47 | File load(size_t index); 48 | 49 | intptr_t findNextFile(char const* name, intptr_t from = -1) const; 50 | intptr_t findFile(char const* name) const; 51 | intptr_t findFile(char const* name, uint16_t locale) const; 52 | 53 | size_t getFileSize(size_t index) const; 54 | size_t getFileCSize(size_t index) const; 55 | 56 | char const* getFileName(size_t index) const; 57 | 58 | void loadListFile(); 59 | 60 | size_t unknowns() const { 61 | return unknowns_; 62 | } 63 | 64 | File load_(size_t index, uint32_t key, bool keyValid); 65 | 66 | private: 67 | File file_; 68 | size_t offset_; 69 | size_t blockSize_; 70 | MPQHeader header_; 71 | std::vector hashTable_; 72 | std::unordered_map quickTable_; 73 | std::vector blockTable_; 74 | std::vector hiBlockTable_; 75 | mutable std::vector names_; 76 | mutable size_t unknowns_; 77 | std::vector buffer_; 78 | 79 | void addName_(char const* name); 80 | }; 81 | 82 | } 83 | -------------------------------------------------------------------------------- /Source/drlg_l4.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DRLG_L4_H__ 3 | #define __DRLG_L4_H__ 4 | 5 | extern int diabquad1x; 6 | extern int diabquad1y; 7 | extern int diabquad3x; 8 | extern int diabquad3y; 9 | extern int diabquad2x; 10 | extern int diabquad2y; 11 | extern int diabquad4x; 12 | extern int diabquad4y; 13 | extern BOOL hallok[20]; 14 | extern int l4holdx; 15 | extern int l4holdy; 16 | extern int SP4x1; 17 | extern int SP4x2; 18 | extern int SP4y1; 19 | extern int SP4y2; 20 | extern BYTE L4dungeon[80][80]; 21 | extern BYTE dung[20][20]; 22 | //int dword_52A4DC; 23 | 24 | void DRLG_LoadL4SP(); 25 | void DRLG_FreeL4SP(); 26 | void DRLG_L4SetSPRoom(int rx1, int ry1); 27 | void L4SaveQuads(); 28 | void DRLG_L4SetRoom(BYTE *pSetPiece, int rx1, int ry1); 29 | void DRLG_LoadDiabQuads(BOOL preflag); 30 | BOOL IsDURWall(char d); 31 | BOOL IsDLLWall(char dd); 32 | void L4FixRim(); 33 | void DRLG_L4GeneralFix(); 34 | void CreateL4Dungeon(DWORD rseed, int entry); 35 | void DRLG_L4(int entry); 36 | void DRLG_L4Shadows(); 37 | void InitL4Dungeon(); 38 | void L4makeDmt(); 39 | void L4AddWall(); 40 | int L4HWallOk(int i, int j); 41 | int L4VWallOk(int i, int j); 42 | void L4HorizWall(int i, int j, int dx); 43 | void L4VertWall(int i, int j, int dy); 44 | void L4tileFix(); 45 | void DRLG_L4Subs(); 46 | void L4makeDungeon(); 47 | void uShape(); 48 | long GetArea(); 49 | void L4firstRoom(); 50 | void L4drawRoom(int x, int y, int width, int height); 51 | void L4roomGen(int x, int y, int w, int h, int dir); 52 | BOOL L4checkRoom(int x, int y, int width, int height); 53 | BOOL DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir); 54 | void DRLG_L4FloodTVal(); 55 | void DRLG_L4FTVR(int i, int j, int x, int y, int d); 56 | void DRLG_L4TransFix(); 57 | void DRLG_L4Corners(); 58 | void DRLG_L4Pass3(); 59 | 60 | /* rdata */ 61 | extern const BYTE L4ConvTbl[16]; 62 | extern const BYTE L4USTAIRS[42]; 63 | extern const BYTE L4TWARP[42]; 64 | extern const BYTE L4DSTAIRS[52]; 65 | extern const BYTE L4PENTA[52]; 66 | extern const BYTE L4PENTA2[52]; 67 | extern const BYTE L4BTYPES[140]; 68 | 69 | #endif /* __DRLG_L4_H__ */ 70 | -------------------------------------------------------------------------------- /Source/zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | 20 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 21 | enough memory, Z_BUF_ERROR if there was not enough room in the output 22 | buffer, or Z_DATA_ERROR if the input data was corrupted. 23 | */ 24 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 25 | Bytef *dest; 26 | uLongf *destLen; 27 | const Bytef *source; 28 | uLong sourceLen; 29 | { 30 | z_stream stream; 31 | int err; 32 | 33 | stream.next_in = (z_const Bytef *)source; 34 | stream.avail_in = (uInt)sourceLen; 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | 45 | err = inflateInit(&stream); 46 | if (err != Z_OK) return err; 47 | 48 | err = inflate(&stream, Z_FINISH); 49 | if (err != Z_STREAM_END) { 50 | inflateEnd(&stream); 51 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 52 | return Z_DATA_ERROR; 53 | return err; 54 | } 55 | *destLen = stream.total_out; 56 | 57 | err = inflateEnd(&stream); 58 | return err; 59 | } 60 | -------------------------------------------------------------------------------- /Source/libsmacker/smk_malloc.h: -------------------------------------------------------------------------------- 1 | /** 2 | libsmacker - A C library for decoding .smk Smacker Video files 3 | Copyright (C) 2012-2017 Greg Kennedy 4 | 5 | See smacker.h for more information. 6 | 7 | smk_malloc.h 8 | "Safe" implementations of malloc and free. 9 | Verbose implementation of assert. 10 | */ 11 | 12 | #ifndef SMK_MALLOC_H 13 | #define SMK_MALLOC_H 14 | 15 | /* calloc */ 16 | #include 17 | /* fprintf */ 18 | #include 19 | 20 | /* Error messages from calloc */ 21 | #include 22 | #include 23 | 24 | /** 25 | Verbose assert: 26 | branches to an error block if pointer is null 27 | */ 28 | #define smk_assert(p) \ 29 | { \ 30 | if (!p) \ 31 | { \ 32 | fprintf(stderr, "libsmacker::smk_assert(" #p "): ERROR: NULL POINTER at line %lu, file %s\n", (unsigned long)__LINE__, __FILE__); \ 33 | goto error; \ 34 | } \ 35 | } 36 | 37 | /** 38 | Safe free: attempts to prevent double-free by setting pointer to NULL. 39 | Optionally warns on attempts to free a NULL pointer. 40 | */ 41 | #define smk_free(p) \ 42 | { \ 43 | if (p) \ 44 | { \ 45 | free(p); \ 46 | p = NULL; \ 47 | } \ 48 | /* else \ 49 | { \ 50 | fprintf(stderr, "libsmacker::smk_free(" #p ") - Warning: attempt to free NULL pointer (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ 51 | } */ \ 52 | } 53 | 54 | /** 55 | Safe malloc: exits if calloc() returns NULL. 56 | Also initializes blocks to 0. 57 | Optionally warns on attempts to malloc over an existing pointer. 58 | Ideally, one should not exit() in a library. However, if you cannot 59 | calloc(), you probably have bigger problems. 60 | */ 61 | #define smk_malloc(p, x) \ 62 | { \ 63 | /* if (p) \ 64 | { \ 65 | fprintf(stderr, "libsmacker::smk_malloc(" #p ", %lu) - Warning: freeing non-NULL pointer before calloc (file: %s, line: %lu)\n", (unsigned long) (x), __FILE__, (unsigned long)__LINE__); \ 66 | free(p); \ 67 | } */ \ 68 | p = calloc(1, x); \ 69 | if (!p) \ 70 | { \ 71 | fprintf(stderr, "libsmacker::smk_malloc(" #p ", %lu) - ERROR: calloc() returned NULL (file: %s, line: %lu)\n\tReason: [%d] %s\n", \ 72 | (unsigned long) (x), __FILE__, (unsigned long)__LINE__, errno, strerror(errno)); \ 73 | exit(EXIT_FAILURE); \ 74 | } \ 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /Source/drlg_l1.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DRLG_L1_H__ 3 | #define __DRLG_L1_H__ 4 | 5 | extern BYTE L5dungeon[80][80]; 6 | extern BYTE L5dflags[DMAXX][DMAXY]; 7 | extern BOOL setloadflag; 8 | extern int HR1; 9 | extern int HR2; 10 | extern int HR3; 11 | extern int VR1; 12 | extern int VR2; 13 | extern int VR3; 14 | extern BYTE *pSetPiece; 15 | 16 | void DRLG_Init_Globals(); 17 | void LoadL1Dungeon(const char *sFileName, int vx, int vy); 18 | void DRLG_L1Floor(); 19 | void DRLG_L1Pass3(); 20 | void DRLG_InitL1Vals(); 21 | void LoadPreL1Dungeon(const char *sFileName, int vx, int vy); 22 | void CreateL5Dungeon(DWORD rseed, int entry); 23 | void DRLG_LoadL1SP(); 24 | void DRLG_FreeL1SP(); 25 | void DRLG_L5(int entry); 26 | void DRLG_PlaceDoor(int x, int y); 27 | void DRLG_L1Shadows(); 28 | int DRLG_PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int noquad, int ldir); 29 | void InitL5Dungeon(); 30 | void L5ClearFlags(); 31 | void L5firstRoom(); 32 | void L5drawRoom(int x, int y, int w, int h); 33 | void L5roomGen(int x, int y, int w, int h, int dir); 34 | BOOL L5checkRoom(int x, int y, int width, int height); 35 | int L5GetArea(); 36 | void L5makeDungeon(); 37 | void L5makeDmt(); 38 | void L5AddWall(); 39 | int L5HWallOk(int i, int j); 40 | int L5VWallOk(int i, int j); 41 | void L5HorizWall(int i, int j, char p, int dx); 42 | void L5VertWall(int i, int j, char p, int dy); 43 | void L5tileFix(); 44 | void DRLG_L5Subs(); 45 | void L5FillChambers(); 46 | void DRLG_L5GChamber(int sx, int sy, BOOL topflag, BOOL bottomflag, BOOL leftflag, BOOL rightflag); 47 | void DRLG_L5GHall(int x1, int y1, int x2, int y2); 48 | void DRLG_L5SetRoom(int rx1, int ry1); 49 | void DRLG_L5FloodTVal(); 50 | void DRLG_L5FTVR(int i, int j, int x, int y, int d); 51 | void DRLG_L5TransFix(); 52 | void DRLG_L5DirtFix(); 53 | void DRLG_L5CornerFix(); 54 | 55 | /* rdata */ 56 | extern const ShadowStruct SPATS[37]; 57 | extern const BYTE BSTYPES[206]; 58 | extern const BYTE L5BTYPES[206]; 59 | extern const BYTE STAIRSUP[]; 60 | extern const BYTE L5STAIRSUP[]; 61 | extern const BYTE STAIRSDOWN[]; 62 | extern const BYTE LAMPS[]; 63 | extern const BYTE PWATERIN[]; 64 | 65 | /* data */ 66 | extern BYTE L5ConvTbl[16]; 67 | 68 | #endif /* __DRLG_L1_H__ */ 69 | -------------------------------------------------------------------------------- /mpqcmp/shine/bitstream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bit_stream.c package 3 | * Author: Jean-Georges Fritsch, C-Cube Microsystems 4 | * 5 | * This package provides functions to write information to the bit stream. 6 | * 7 | * Removed unused functions. Feb 2001 P.Everett 8 | */ 9 | 10 | #include "types.h" 11 | #include "bitstream.h" 12 | 13 | #if !defined(__APPLE__) && !defined(__FreeBSD__) 14 | #include 15 | #endif 16 | 17 | /* open the device to write the bit stream into it */ 18 | void shine_open_bit_stream(bitstream_t *bs, const int size) 19 | { 20 | bs->data = (unsigned char *)malloc(size*sizeof(unsigned char)); 21 | bs->data_size = size; 22 | bs->data_position = 0; 23 | bs->cache = 0; 24 | bs->cache_bits = 32; 25 | } 26 | 27 | /*close the device containing the bit stream */ 28 | void shine_close_bit_stream(bitstream_t *bs) 29 | { 30 | if (bs->data) 31 | free(bs->data); 32 | } 33 | 34 | /* 35 | * shine_putbits: 36 | * -------- 37 | * write N bits into the bit stream. 38 | * bs = bit stream structure 39 | * val = value to write into the buffer 40 | * N = number of bits of val 41 | */ 42 | void shine_putbits(bitstream_t *bs, unsigned int val, unsigned int N) 43 | { 44 | #ifdef DEBUG 45 | if (N > 32) 46 | printf("Cannot write more than 32 bits at a time.\n"); 47 | if (N < 32 && (val >> N) != 0) 48 | printf("Upper bits (higher than %d) are not all zeros.\n", N); 49 | #endif 50 | 51 | if (bs->cache_bits > (int) N) { 52 | bs->cache_bits -= N; 53 | bs->cache |= val << bs->cache_bits; 54 | } else { 55 | if (bs->data_position + (int) sizeof(unsigned int) >= bs->data_size) { 56 | bs->data = (unsigned char *)realloc(bs->data, bs->data_size + (bs->data_size / 2)); 57 | bs->data_size += (bs->data_size / 2); 58 | } 59 | 60 | N -= bs->cache_bits; 61 | bs->cache |= val >> N; 62 | #ifdef SHINE_BIG_ENDIAN 63 | *(unsigned int*)(bs->data + bs->data_position) = bs->cache; 64 | #else 65 | *(unsigned int*)(bs->data + bs->data_position) = SWAB32(bs->cache); 66 | #endif 67 | bs->data_position += sizeof(unsigned int); 68 | bs->cache_bits = 32 - N; 69 | if (N != 0) 70 | bs->cache = val << bs->cache_bits; 71 | else 72 | bs->cache = 0; 73 | } 74 | } 75 | 76 | int shine_get_bits_count(bitstream_t *bs) 77 | { 78 | return bs->data_position * 8 + 32 - bs->cache_bits; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /Source/multi.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __MULTI_H__ 3 | #define __MULTI_H__ 4 | 5 | extern BOOLEAN gbSomebodyWonGameKludge; 6 | extern char szPlayerDescript[128]; 7 | extern WORD sgwPackPlrOffsetTbl[MAX_PLRS]; 8 | extern PkPlayerStruct netplr[MAX_PLRS]; 9 | extern BOOL gbShouldValidatePackage; 10 | extern BYTE gbActivePlayers; 11 | extern BOOLEAN gbGameDestroyed; 12 | extern char byte_678640; 13 | extern BYTE gbMaxPlayers; 14 | extern char szPlayerName[128]; 15 | extern BYTE gbDeltaSender; 16 | extern int player_state[MAX_PLRS]; 17 | 18 | #ifdef _DEBUG 19 | void __cdecl dumphist(const char *pszFmt, ...); 20 | #endif 21 | void multi_msg_add(BYTE *pbMsg, BYTE bLen); 22 | void NetSendLoPri(BYTE *pbMsg, BYTE bLen); 23 | void multi_copy_packet(TBuffer *pBuf, void *packet, BYTE size); 24 | void multi_send_packet(void *packet, BYTE dwSize); 25 | void NetRecvPlrData(TPkt *pkt); 26 | void NetSendHiPri(BYTE *pbMsg, BYTE bLen); 27 | BYTE *multi_recv_packet(TBuffer *pBuf, BYTE *body, int *size); 28 | void multi_send_msg_packet(int pmask, BYTE *src, BYTE len); 29 | void multi_msg_countdown(); 30 | void multi_parse_turn(int pnum, int turn); 31 | void multi_handle_turn_upper_bit(int pnum); 32 | void multi_player_left(int pnum, int reason); 33 | void multi_clear_left_tbl(); 34 | void multi_player_left_msg(int pnum, int left); 35 | void multi_net_ping(); 36 | int multi_handle_delta(); 37 | int multi_check_pkt_valid(TBuffer *pBuf); 38 | void multi_mon_seeds(); 39 | void multi_begin_timeout(); 40 | void multi_check_drop_player(); 41 | void multi_process_network_packets(); 42 | void multi_handle_all_packets(int pnum, BYTE *pData, int nSize); 43 | void multi_process_tmsgs(); 44 | void multi_send_zero_packet(DWORD pnum, char identifier, void *pbSrc, DWORD dwLen); 45 | void NetClose(); 46 | void multi_event_handler(BOOL add); 47 | void multi_handle_events(_SNETEVENT *pEvt); 48 | void buffer_init(TBuffer *pBuf); 49 | void multi_send_pinfo(int pnum, char cmd); 50 | int InitLevelType(int l); 51 | void SetupLocalCoords(); 52 | void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, BOOL recv); 53 | 54 | void NetInit_Difficulty(int diff); 55 | void NetInit_Start(); 56 | void NetInit_Mid(); 57 | void NetInit_Finish(); 58 | bool NetInit_NeedSync(); 59 | 60 | /* rdata */ 61 | 62 | extern const int event_types[3]; 63 | 64 | #endif /* __MULTI_H__ */ 65 | -------------------------------------------------------------------------------- /Source/net/base.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../diablo.h" 10 | #include "abstract_net.h" 11 | 12 | #include "../../Server/packet.hpp" 13 | 14 | #define PS_CONNECTED 0x10000 15 | #define PS_TURN_ARRIVED 0x20000 16 | #define PS_ACTIVE 0x40000 17 | 18 | const uint8_t PLR_BROADCAST = 0xFF; 19 | 20 | namespace net { 21 | 22 | class base : public abstract_net { 23 | public: 24 | virtual bool SNetReceiveMessage(int* sender, char** data, int* size); 25 | virtual bool SNetSendMessage(int dest, void* data, unsigned int size); 26 | virtual bool SNetReceiveTurns(char** data, DWORD* size, 27 | DWORD* status); 28 | virtual bool SNetSendTurn(char* data, unsigned int size); 29 | virtual int SNetGetProviderCaps(struct _SNETCAPS* caps); 30 | virtual bool SNetRegisterEventHandler(event_type evtype, 31 | SEVTHANDLER func); 32 | virtual bool SNetUnregisterEventHandler(event_type evtype, 33 | SEVTHANDLER func); 34 | virtual bool SNetLeaveGame(int type); 35 | virtual bool SNetDropPlayer(int playerid, DWORD flags); 36 | virtual bool SNetGetOwnerTurnsWaiting(DWORD* turns); 37 | virtual bool SNetGetTurnsInTransit(int* turns); 38 | 39 | virtual void send(const packet& pkt) = 0; 40 | 41 | protected: 42 | std::map registered_handlers; 43 | 44 | struct message_t { 45 | int sender; // change int to something else in devilution code later 46 | std::vector payload; 47 | message_t() 48 | : sender(-1), payload({}) {} 49 | message_t(int s, std::vector p) 50 | : sender(s), payload(std::move(p)) {} 51 | }; 52 | 53 | message_t message_last; 54 | std::deque message_queue; 55 | std::array turn_last = {}; 56 | std::array, MAX_PLRS> turn_queue; 57 | std::array connected_table = {}; 58 | 59 | uint8_t plr_self = PLR_BROADCAST; 60 | bool is_creator_ = false; 61 | 62 | template 63 | void handle(const packet_type& pkt); 64 | 65 | void run_event_handler(_SNETEVENT& ev); 66 | 67 | private: 68 | uint8_t get_owner(); 69 | void clear_msg(uint8_t plr); 70 | }; 71 | 72 | } // namespace net 73 | -------------------------------------------------------------------------------- /Source/dthread.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | #include "storm/storm.h" 3 | 4 | unsigned int glpDThreadId; 5 | TMegaPkt *sgpInfoHead; /* may not be right struct */ 6 | BOOLEAN dthread_running; 7 | HANDLE sghWorkToDoEvent; 8 | 9 | DWORD netRemainingBytes = 0; 10 | DWORD netLastCheckTime = 0; 11 | 12 | DWORD& packetSize(TMegaPkt* pkt) { 13 | return *(DWORD *) &pkt->data[4]; 14 | } 15 | 16 | /* rdata */ 17 | static HANDLE sghThread = INVALID_HANDLE_VALUE; 18 | 19 | void dthread_remove_player(int pnum) { 20 | TMegaPkt *pkt; 21 | 22 | for (pkt = sgpInfoHead; pkt; pkt = pkt->pNext) { 23 | if (pkt->dwSpaceLeft == pnum) 24 | pkt->dwSpaceLeft = MAX_PLRS; 25 | } 26 | } 27 | 28 | void dthread_send_delta(int pnum, char cmd, void *pbSrc, int dwLen) { 29 | TMegaPkt *pkt; 30 | TMegaPkt *p; 31 | 32 | if (gbMaxPlayers == 1) { 33 | return; 34 | } 35 | 36 | pkt = (TMegaPkt *) DiabloAllocPtr(dwLen + 20); 37 | pkt->pNext = NULL; 38 | pkt->dwSpaceLeft = pnum; 39 | pkt->data[0] = cmd; 40 | packetSize(pkt) = dwLen; 41 | memcpy(&pkt->data[8], pbSrc, dwLen); 42 | p = (TMegaPkt *) &sgpInfoHead; 43 | while (p->pNext) { 44 | p = p->pNext; 45 | } 46 | p->pNext = pkt; 47 | } 48 | 49 | void dthread_start() { 50 | if (gbMaxPlayers == 1) { 51 | return; 52 | } 53 | 54 | netRemainingBytes = gdwDeltaBytesSec; 55 | netLastCheckTime = _GetTickCount(); 56 | dthread_running = TRUE; 57 | } 58 | 59 | void dthread_loop() { 60 | TMegaPkt *pkt; 61 | 62 | if (!dthread_running) { 63 | return; 64 | } 65 | 66 | netRemainingBytes += (_GetTickCount() - netLastCheckTime) * (gdwDeltaBytesSec / 1000); 67 | netLastCheckTime = _GetTickCount(); 68 | if (netRemainingBytes > gdwDeltaBytesSec) { 69 | netRemainingBytes = gdwDeltaBytesSec; 70 | } 71 | 72 | while (sgpInfoHead && packetSize(sgpInfoHead) <= netRemainingBytes) { 73 | pkt = sgpInfoHead; 74 | sgpInfoHead = sgpInfoHead->pNext; 75 | 76 | netRemainingBytes -= packetSize(pkt); 77 | 78 | if (pkt->dwSpaceLeft != MAX_PLRS) 79 | multi_send_zero_packet(pkt->dwSpaceLeft, pkt->data[0], &pkt->data[8], packetSize(pkt)); 80 | 81 | mem_free_dbg(pkt); 82 | } 83 | } 84 | 85 | void dthread_cleanup() { 86 | TMegaPkt *tmp; 87 | 88 | if (sghWorkToDoEvent == NULL) { 89 | return; 90 | } 91 | 92 | dthread_running = FALSE; 93 | 94 | while (sgpInfoHead) { 95 | tmp = sgpInfoHead->pNext; 96 | MemFreeDbg(sgpInfoHead); 97 | sgpInfoHead = tmp; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Source/dead.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | 3 | // unused, this was probably for blood boil/burn 4 | int spurtndx; 5 | DeadStruct dead[MAXDEAD]; 6 | int stonendx; 7 | 8 | void InitDead() 9 | { 10 | int mtypes[MAXMONSTERS]; 11 | int i; 12 | int nd; 13 | int mi; 14 | int d; 15 | 16 | for (i = 0; i < MAXMONSTERS; i++) 17 | mtypes[i] = 0; 18 | 19 | nd = 0; 20 | 21 | for (i = 0; i < nummtypes; i++) { 22 | if (!mtypes[Monsters[i].mtype]) { 23 | for (d = 0; d < 8; d++) 24 | dead[nd]._deadData[d] = Monsters[i].Anims[MA_DEATH].Data[d]; 25 | dead[nd]._deadFrame = Monsters[i].Anims[MA_DEATH].Frames; 26 | dead[nd]._deadWidth = Monsters[i].width; 27 | dead[nd]._deadWidth2 = Monsters[i].width2; 28 | dead[nd]._deadtrans = 0; 29 | Monsters[i].mdeadval = nd + 1; 30 | mtypes[Monsters[i].mtype] = nd + 1; 31 | nd++; 32 | } 33 | } 34 | 35 | for (d = 0; d < 8; d++) 36 | dead[nd]._deadData[d] = misfiledata[MFILE_BLODBUR].mAnimData[0]; 37 | dead[nd]._deadFrame = 8; 38 | dead[nd]._deadWidth = 128; 39 | dead[nd]._deadWidth2 = 32; 40 | dead[nd]._deadtrans = 0; 41 | spurtndx = nd + 1; 42 | nd++; 43 | 44 | for (d = 0; d < 8; d++) 45 | dead[nd]._deadData[d] = misfiledata[MFILE_SHATTER1].mAnimData[0]; 46 | dead[nd]._deadFrame = 12; 47 | dead[nd]._deadWidth = 128; 48 | dead[nd]._deadWidth2 = 32; 49 | dead[nd]._deadtrans = 0; 50 | stonendx = nd + 1; 51 | nd++; 52 | 53 | for (i = 0; i < nummonsters; i++) { 54 | mi = monstactive[i]; 55 | if (monster[mi]._uniqtype) { 56 | for (d = 0; d < 8; d++) 57 | dead[nd]._deadData[d] = monster[mi].MType->Anims[MA_DEATH].Data[d]; 58 | dead[nd]._deadFrame = monster[mi].MType->Anims[MA_DEATH].Frames; 59 | dead[nd]._deadWidth = monster[mi].MType->width; 60 | dead[nd]._deadWidth2 = monster[mi].MType->width2; 61 | dead[nd]._deadtrans = monster[mi]._uniqtrans + 4; 62 | monster[mi]._udeadval = nd + 1; 63 | nd++; 64 | } 65 | } 66 | 67 | /// ASSERT: assert(nd <= MAXDEAD); 68 | } 69 | 70 | void AddDead(int dx, int dy, char dv, int ddir) 71 | { 72 | dDead[dx][dy] = (dv & 0x1F) + (ddir << 5); 73 | } 74 | 75 | void SetDead() 76 | { 77 | int mi; 78 | int i; 79 | int dx, dy; 80 | 81 | for (i = 0; i < nummonsters; i++) { 82 | mi = monstactive[i]; 83 | if (monster[mi]._uniqtype) { 84 | for (dx = 0; dx < MAXDUNX; dx++) { 85 | for (dy = 0; dy < MAXDUNY; dy++) { 86 | if ((dDead[dx][dy] & 0x1F) == monster[mi]._udeadval) 87 | ChangeLightXY(monster[mi].mlid, dx, dy); 88 | } 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Source/storm/smpq.cpp: -------------------------------------------------------------------------------- 1 | #define NOMINMAX 2 | #include "storm.h" 3 | #include "../rmpq/archive.h" 4 | #include "../trace.h" 5 | #include "../ui/common.h" 6 | 7 | #include 8 | 9 | BOOL SFileOpenArchive(const char *szMpqName, DWORD dwPriority, DWORD dwFlags, HANDLE *phMpq) { 10 | File file(szMpqName, "rb"); 11 | if (!file) { 12 | return FALSE; 13 | } 14 | mpq::Archive* archive = new mpq::Archive(file); 15 | *phMpq = (HANDLE) archive; 16 | return TRUE; 17 | } 18 | 19 | BOOL SFileCloseArchive(HANDLE hArchive) { 20 | delete ((mpq::Archive*) hArchive); 21 | return TRUE; 22 | } 23 | 24 | BOOL SFileCloseFile(HANDLE hFile) { 25 | delete ((File*) hFile); 26 | return TRUE; 27 | } 28 | 29 | BOOL SFileGetFileArchive(HANDLE hFile, HANDLE *archive) { 30 | //MpqFile* file = (MpqFile*) hFile; 31 | *archive = NULL; 32 | return TRUE; 33 | } 34 | 35 | LONG SFileGetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) { 36 | File* file = (File*) hFile; 37 | uint64_t size = file->size(); 38 | if (lpFileSizeHigh) { 39 | *lpFileSizeHigh = (DWORD) (size >> 32); 40 | } 41 | return (LONG) size; 42 | } 43 | 44 | BOOL SFileOpenFile(const char *filename, HANDLE *phFile) { 45 | return SFileOpenFileEx((HANDLE) diabdat_mpq, filename, 0, phFile); 46 | } 47 | 48 | BOOL SFileOpenFileEx(HANDLE hMpq, const char *szFileName, DWORD dwSearchScope, HANDLE *phFile) { 49 | mpq::Archive* archive = (mpq::Archive*) hMpq; 50 | auto pos = archive->findFile(szFileName); 51 | if (pos < 0) { 52 | SErrSetLastError(ERROR_FILE_NOT_FOUND); 53 | return FALSE; 54 | } 55 | auto file = archive->load_(pos, mpq::hashString(mpq::path_name(szFileName), mpq::HASH_KEY), true); 56 | if (file) { 57 | File* mpqf = new File(file); 58 | *phFile = (HANDLE) mpqf; 59 | return TRUE; 60 | } 61 | SErrSetLastError(ERROR_FILE_CORRUPT); 62 | return FALSE; 63 | } 64 | 65 | BOOL SFileReadFile(HANDLE hFile, void *buffer, DWORD nNumberOfBytesToRead, DWORD *read, LONG *lpDistanceToMoveHigh) { 66 | File* file = (File*) hFile; 67 | auto res = file->read(buffer, nNumberOfBytesToRead); 68 | if (read) { 69 | *read = (DWORD) res; 70 | } 71 | return res != 0; 72 | } 73 | 74 | BOOL SFileSetBasePath(char *) { 75 | return TRUE; 76 | } 77 | 78 | int SFileSetFilePointer(HANDLE hFile, int pos, HANDLE, int origin) { 79 | File* file = (File*) hFile; 80 | file->seek(pos, origin); 81 | return 0; 82 | } 83 | 84 | BOOL SFileGetFileSizeFast(const char* filename, LPDWORD size) { 85 | mpq::Archive* arc = (mpq::Archive*) diabdat_mpq; 86 | auto pos = arc->findFile(filename); 87 | if (pos >= 0) { 88 | *size = arc->getFileSize(pos); 89 | return TRUE; 90 | } 91 | return FALSE; 92 | } 93 | -------------------------------------------------------------------------------- /Source/libsmacker/README: -------------------------------------------------------------------------------- 1 | libsmacker 2 | A C library for decoding .smk Smacker Video files 3 | 4 | version 1.1 5 | 2017-01-27 6 | 7 | (c) Greg Kennedy 2013-2017 8 | http://libsmacker.sourceforge.net 9 | ---- 10 | 11 | --- 12 | Introduction 13 | --- 14 | libsmacker is a cross-platform C library which can be used for decoding Smacker Video files produced by RAD Game Tools. Smacker Video was the king of video middleware in the 1990s, and its 256-color compressed video format was used in over 2600 software titles. 15 | 16 | libsmacker implements the minimum feature set required from smackw32.dll to get an smk off a disk and the frames / audio into a buffer in the correct order. 17 | 18 | --- 19 | License 20 | --- 21 | libsmacker is released under a Creative Commons Attribution Non-Commercial License V2.0. This means, first, that projects using libsmacker must indicate somewhere that they use libsmacker in the code. Also: the Non-Commercial tag means exactly what it suggests: LIBSMACKER MAY NOT BE USED IN ANY COMMERCIAL PROJECT. PERIOD. Non-commercial DOES NOT mean simply "non-profit": commercial includes for-profit, but may also encompass other non-profit activites as well. 22 | 23 | Static- or dynamic-linking against unmodified libsmacker does not automatically re-license your code. If you alter the library code (.c, .h files), your changes become a Derivative Work and are subject to the conditions outlined in the license. Unmodified redistributions of binary libsmacker in your own projects must meet the conditions of this license. 24 | 25 | A human-readable summary of the license is available online: 26 | http://creativecommons.org/licenses/by-nc/2.0/ 27 | 28 | The complete license text is here: 29 | http://creativecommons.org/licenses/by-nc/2.0/legalcode 30 | 31 | --- 32 | Usage 33 | --- 34 | See the webpage for sample code and function documentation. The source package additionally includes a pair of driver programs: 35 | * driver.c - dumps all frames of a file to a bmp/ subdirectory, and all audio as raw streams to out_*.raw files in CWD 36 | * smk2avi.c - converts smk file(s) to AVI files - uncompressed 24-bit color and PCM audio stream. 37 | 38 | Though the libraries are "bulletproofed" the sample apps are not: be cautious if you plan to implement in some critical environment. 39 | 40 | --- 41 | Changelog 42 | --- 43 | 1.1 44 | * Switch to autotools-based build 45 | * Incorporates patches from Dalerank Slim, Gennady Trafimenkov, and Bianca van Schaik 46 | * Performance improvements and code cleanup / safety. 47 | 1.0 48 | * Initial revision 49 | 50 | --- 51 | Contact 52 | --- 53 | Questions/comments: 54 | * by email: kennedy.greg@gmail.com 55 | * by website: http://libsmacker.sourceforge.net 56 | 57 | Enjoy! 58 | -------------------------------------------------------------------------------- /Source/net/loopback.cpp: -------------------------------------------------------------------------------- 1 | #include "loopback.h" 2 | 3 | namespace net { 4 | 5 | void loopback::create(std::string addrstr, std::string passwd, uint32_t difficulty) { 6 | ERROR_MSG("not implemented"); 7 | } 8 | 9 | void loopback::join(std::string addrstr, std::string passwd) { 10 | ERROR_MSG("not implemented"); 11 | } 12 | 13 | bool loopback::SNetReceiveMessage(int* sender, char** data, int* size) { 14 | if (message_queue.empty()) 15 | return false; 16 | message_last = message_queue.front(); 17 | message_queue.pop_front(); 18 | *sender = plr_single; 19 | *size = message_last.size(); 20 | *data = reinterpret_cast(message_last.data()); 21 | return true; 22 | } 23 | 24 | bool loopback::SNetSendMessage(int dest, void* data, unsigned int size) { 25 | if (dest == plr_single || dest == SNPLAYER_ALL) { 26 | auto raw_message = reinterpret_cast(data); 27 | std::vector message(raw_message, raw_message + size); 28 | message_queue.push_back(message); 29 | } 30 | return true; 31 | } 32 | 33 | bool loopback::SNetReceiveTurns(char** data, DWORD* size, DWORD* status) { 34 | // todo: check that this is safe 35 | return true; 36 | } 37 | 38 | bool loopback::SNetSendTurn(char* data, unsigned int size) { 39 | // todo: check that this is safe 40 | return true; 41 | } 42 | 43 | int loopback::SNetGetProviderCaps(struct _SNETCAPS* caps) { 44 | caps->size = 0; // engine writes only ?!? 45 | caps->flags = 0; // unused 46 | caps->maxmessagesize = 512; // capped to 512; underflow if < 24 47 | caps->maxqueuesize = 0; // unused 48 | caps->maxplayers = MAX_PLRS; // capped to 4 49 | caps->bytessec = 1000000; // ? 50 | caps->latencyms = 0; // unused 51 | caps->defaultturnssec = 10; // ? 52 | caps->defaultturnsintransit = 1; // maximum acceptable number 53 | // of turns in queue? 54 | return 1; 55 | } 56 | 57 | bool loopback::SNetRegisterEventHandler(event_type evtype, 58 | SEVTHANDLER func) { 59 | // not called in real singleplayer mode 60 | // not needed in pseudo multiplayer mode (?) 61 | return true; 62 | } 63 | 64 | bool loopback::SNetUnregisterEventHandler(event_type evtype, 65 | SEVTHANDLER func) { 66 | // not called in real singleplayer mode 67 | // not needed in pseudo multiplayer mode (?) 68 | return true; 69 | } 70 | 71 | bool loopback::SNetLeaveGame(int type) { 72 | return true; 73 | } 74 | 75 | bool loopback::SNetDropPlayer(int playerid, DWORD flags) { 76 | return true; 77 | } 78 | 79 | bool loopback::SNetGetOwnerTurnsWaiting(DWORD* turns) { 80 | *turns = 0; 81 | return true; 82 | } 83 | 84 | bool loopback::SNetGetTurnsInTransit(int* turns) { 85 | *turns = 0; 86 | return true; 87 | } 88 | 89 | } // namespace net 90 | -------------------------------------------------------------------------------- /Source/zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (z_const Bytef *)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 79 | (sourceLen >> 25) + 13; 80 | } 81 | -------------------------------------------------------------------------------- /Source/drlg_l3.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DRLG_L3_H__ 3 | #define __DRLG_L3_H__ 4 | 5 | extern BOOLEAN lavapool; 6 | extern int abyssx; 7 | extern int lockoutcnt; 8 | extern BOOLEAN lockout[DMAXX][DMAXY]; 9 | 10 | void AddFenceDoors(); 11 | void FenceDoorFix(); 12 | BOOL DRLG_L3Anvil(); 13 | void FixL3Warp(); 14 | void FixL3HallofHeroes(); 15 | void DRLG_L3LockRec(int x, int y); 16 | BOOL DRLG_L3Lockout(); 17 | void CreateL3Dungeon(DWORD rseed, int entry); 18 | void DRLG_L3(int entry); 19 | void InitL3Dungeon(); 20 | BOOL DRLG_L3FillRoom(int x1, int y1, int x2, int y2); 21 | void DRLG_L3CreateBlock(int x, int y, int obs, int dir); 22 | void DRLG_L3FloorArea(int x1, int y1, int x2, int y2); 23 | void DRLG_L3FillDiags(); 24 | void DRLG_L3FillSingles(); 25 | void DRLG_L3FillStraights(); 26 | void DRLG_L3Edges(); 27 | int DRLG_L3GetFloorArea(); 28 | void DRLG_L3MakeMegas(); 29 | void DRLG_L3River(); 30 | void DRLG_L3Pool(); 31 | BOOL DRLG_L3SpawnEdge(int x, int y, int *totarea); 32 | BOOL DRLG_L3Spawn(int x, int y, int *totarea); 33 | void DRLG_L3PoolFix(); 34 | BOOL DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, BOOL setview, int ldir); 35 | void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper); 36 | void DRLG_L3Wood(); 37 | BOOL WoodVertU(int i, int y); 38 | BOOL WoodVertD(int i, int y); 39 | BOOL WoodHorizL(int x, int j); 40 | BOOL WoodHorizR(int x, int j); 41 | void DRLG_L3Pass3(); 42 | void LoadL3Dungeon(const char *sFileName, int vx, int vy); 43 | void LoadPreL3Dungeon(const char *sFileName, int vx, int vy); 44 | 45 | /* rdata */ 46 | extern const BYTE L3ConvTbl[16]; 47 | extern const BYTE L3UP[20]; 48 | extern const BYTE L3DOWN[20]; 49 | extern const BYTE L3HOLDWARP[20]; 50 | extern const BYTE L3TITE1[34]; 51 | extern const BYTE L3TITE2[34]; 52 | extern const BYTE L3TITE3[34]; 53 | extern const BYTE L3TITE6[42]; 54 | extern const BYTE L3TITE7[42]; 55 | extern const BYTE L3TITE8[20]; 56 | extern const BYTE L3TITE9[20]; 57 | extern const BYTE L3TITE10[20]; 58 | extern const BYTE L3TITE11[20]; 59 | extern const BYTE L3TITE12[6]; 60 | extern const BYTE L3TITE13[6]; 61 | extern const BYTE L3CREV1[6]; 62 | extern const BYTE L3CREV2[6]; 63 | extern const BYTE L3CREV3[6]; 64 | extern const BYTE L3CREV4[6]; 65 | extern const BYTE L3CREV5[6]; 66 | extern const BYTE L3CREV6[6]; 67 | extern const BYTE L3CREV7[6]; 68 | extern const BYTE L3CREV8[6]; 69 | extern const BYTE L3CREV9[6]; 70 | extern const BYTE L3CREV10[6]; 71 | extern const BYTE L3CREV11[6]; 72 | extern const BYTE L3ISLE1[14]; 73 | extern const BYTE L3ISLE2[14]; 74 | extern const BYTE L3ISLE3[14]; 75 | extern const BYTE L3ISLE4[14]; 76 | extern const BYTE L3ISLE5[10]; 77 | extern const BYTE L3XTRA1[4]; 78 | extern const BYTE L3XTRA2[4]; 79 | extern const BYTE L3XTRA3[4]; 80 | extern const BYTE L3XTRA4[4]; 81 | extern const BYTE L3XTRA5[4]; 82 | extern const BYTE L3ANVIL[244]; 83 | 84 | #endif /* __DRLG_L3_H__ */ 85 | -------------------------------------------------------------------------------- /Source/ui/diabloui.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __DIABLOUI_H__ 3 | #define __DIABLOUI_H__ 4 | 5 | struct FontStruct 6 | { 7 | unsigned char fontbin[258]; 8 | HANDLE fonttrans[256]; 9 | BOOL active; 10 | }; 11 | 12 | struct ProfileStruct 13 | { 14 | char *name; 15 | char field_4; 16 | int msg; 17 | int field_C; 18 | }; 19 | 20 | struct ProfFntStruct 21 | { 22 | int size; 23 | char *fontname; 24 | int field_8; 25 | }; 26 | 27 | void UiDestroy(); 28 | BOOL UiTitleDialog( int a1 ); 29 | void UiInitialize(void( *fnSound)(const char *file)); 30 | BOOL UiCopyProtError( int *pdwResult ); 31 | void UiAppActivate( BOOL bActive ); 32 | BOOL UiValidPlayerName( char *name ); /* check */ 33 | BOOL UiSelHeroMultDialog( BOOL( *fninfo )( BOOL( *fninfofunc )( _uiheroinfo * ) ), BOOL( *fncreate )( _uiheroinfo * ), BOOL( *fnremove )( _uiheroinfo * ), BOOL( *fnstats )( unsigned int, _uidefaultstats * ), int *dlgresult, int *a6, char *name ); 34 | BOOL UiSelHeroSingDialog( BOOL( *fninfo )( BOOL( *fninfofunc )( _uiheroinfo * ) ), BOOL( *fncreate )( _uiheroinfo * ), BOOL( *fnremove )( _uiheroinfo * ), BOOL( *fnstats )( unsigned int, _uidefaultstats * ), int *dlgresult, char *name, int *difficulty ); 35 | BOOL UiCreditsDialog( int a1 ); 36 | BOOL UiMainMenuDialog( char *name, int *pdwResult, void( *fnSound )( char *file ), int a4 ); 37 | BOOL UiProgressDialog( HWND window, const char *msg, int enable, int( *fnfunc )( ), int rate ); 38 | int UiProfileGetString(); 39 | void __cdecl UiProfileCallback(); 40 | void __cdecl UiProfileDraw(); 41 | BOOL UiCategoryCallback( int a1, int a2, int a3, int a4, int a5, DWORD *a6, DWORD *a7 ); 42 | BOOL UiGetDataCallback( int game_type, int data_code, void *a3, int a4, int a5 ); 43 | BOOL UiAuthCallback( int a1, char *a2, char *a3, char a4, char *a5, CHAR* lpBuffer, int cchBufferMax ); 44 | BOOL UiSoundCallback( int a1, int type, int a3 ); 45 | void UiMessageBoxCallback( HWND hWnd, char *lpText, const CHAR* lpCaption, UINT uType ); 46 | BOOL UiDrawDescCallback( int arg0, DWORD color, CHAR* lpString, char *a4, int a5, UINT align, time_t a7, HDC *a8 ); 47 | BOOL UiCreateGameCallback( int a1, int a2, int a3, int a4, int a5, int a6 ); 48 | BOOL UiArtCallback( int game_type, unsigned int art_code, PALETTEENTRY *pPalette, BYTE *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *pdwHeight, DWORD *pdwBpp ); 49 | int UiSelectGame( int a1, _SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info, _SNETUIDATA *ui_info, _SNETVERSIONDATA *file_info, int *a6 ); 50 | int UiSelectProvider( int a1, _SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info, _SNETUIDATA *ui_info, _SNETVERSIONDATA *file_info, int *type ); 51 | BOOL UiCreatePlayerDescription( _uiheroinfo *info, int mode, char *desc ); 52 | void UiSetupPlayerInfo( char *infostr, _uiheroinfo *pInfo, int type ); 53 | void UiCreateGameCriteria( _uiheroinfo *pInfo, char *str ); 54 | BOOL UiGetDefaultStats( int pclass, _uidefaultstats *pStats ); 55 | BOOL UiBetaDisclaimer( int a1 ); 56 | 57 | #endif /* __DIABLOUI_H__ */ 58 | -------------------------------------------------------------------------------- /DiabloWeb.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.705 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DiabloWeb", "DiabloWeb.vcxproj", "{18DEBFEE-847E-415A-815C-B692AF276104}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server.vcxproj", "{7A9567DE-9C44-4627-9F13-EF8183101D7B}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpqcmp", "mpqcmp.vcxproj", "{9DA5A2DF-F692-4083-91E3-BDFBD3D85878}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|x64 = Debug|x64 15 | Debug|x86 = Debug|x86 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {18DEBFEE-847E-415A-815C-B692AF276104}.Debug|x64.ActiveCfg = Debug|x64 21 | {18DEBFEE-847E-415A-815C-B692AF276104}.Debug|x64.Build.0 = Debug|x64 22 | {18DEBFEE-847E-415A-815C-B692AF276104}.Debug|x86.ActiveCfg = Debug|Win32 23 | {18DEBFEE-847E-415A-815C-B692AF276104}.Debug|x86.Build.0 = Debug|Win32 24 | {18DEBFEE-847E-415A-815C-B692AF276104}.Release|x64.ActiveCfg = Release|x64 25 | {18DEBFEE-847E-415A-815C-B692AF276104}.Release|x64.Build.0 = Release|x64 26 | {18DEBFEE-847E-415A-815C-B692AF276104}.Release|x86.ActiveCfg = Release|Win32 27 | {18DEBFEE-847E-415A-815C-B692AF276104}.Release|x86.Build.0 = Release|Win32 28 | {7A9567DE-9C44-4627-9F13-EF8183101D7B}.Debug|x64.ActiveCfg = Debug|x64 29 | {7A9567DE-9C44-4627-9F13-EF8183101D7B}.Debug|x64.Build.0 = Debug|x64 30 | {7A9567DE-9C44-4627-9F13-EF8183101D7B}.Debug|x86.ActiveCfg = Debug|Win32 31 | {7A9567DE-9C44-4627-9F13-EF8183101D7B}.Debug|x86.Build.0 = Debug|Win32 32 | {7A9567DE-9C44-4627-9F13-EF8183101D7B}.Release|x64.ActiveCfg = Release|x64 33 | {7A9567DE-9C44-4627-9F13-EF8183101D7B}.Release|x64.Build.0 = Release|x64 34 | {7A9567DE-9C44-4627-9F13-EF8183101D7B}.Release|x86.ActiveCfg = Release|Win32 35 | {7A9567DE-9C44-4627-9F13-EF8183101D7B}.Release|x86.Build.0 = Release|Win32 36 | {9DA5A2DF-F692-4083-91E3-BDFBD3D85878}.Debug|x64.ActiveCfg = Debug|x64 37 | {9DA5A2DF-F692-4083-91E3-BDFBD3D85878}.Debug|x64.Build.0 = Debug|x64 38 | {9DA5A2DF-F692-4083-91E3-BDFBD3D85878}.Debug|x86.ActiveCfg = Debug|Win32 39 | {9DA5A2DF-F692-4083-91E3-BDFBD3D85878}.Debug|x86.Build.0 = Debug|Win32 40 | {9DA5A2DF-F692-4083-91E3-BDFBD3D85878}.Release|x64.ActiveCfg = Release|x64 41 | {9DA5A2DF-F692-4083-91E3-BDFBD3D85878}.Release|x64.Build.0 = Release|x64 42 | {9DA5A2DF-F692-4083-91E3-BDFBD3D85878}.Release|x86.ActiveCfg = Release|Win32 43 | {9DA5A2DF-F692-4083-91E3-BDFBD3D85878}.Release|x86.Build.0 = Release|Win32 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {1E395333-5602-4A50-8582-31FBC19F6EE6} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /mpqcmp/shine/mult_sarm_gcc.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Fractional multiply */ 4 | #if __ARM_ARCH >= 6 5 | #define mul(x,y) \ 6 | ({ \ 7 | register int32_t result; \ 8 | asm ("smmul %0, %2, %1" : "=r" (result) : "r" (x), "r" (y)); \ 9 | result ;\ 10 | }) 11 | #else 12 | #define mul(x,y) \ 13 | ({ \ 14 | register int32_t result; \ 15 | asm ("smull r3, %0, %2, %1" : "=r" (result) : "r" (x), "r" (y) : "r3"); \ 16 | result ; \ 17 | }) 18 | #endif 19 | 20 | /* Fractional multiply with single bit left shift. */ 21 | #define muls(x,y) \ 22 | ({ \ 23 | register int32_t result; \ 24 | asm ( \ 25 | "smull r3, %0, %2, %1\n\t" \ 26 | "movs r3, r3, lsl #1\n\t" \ 27 | "adc %0, %0, %0" \ 28 | : "=r" (result) : "r" (x), "r" (y) : "r3", "cc" \ 29 | ); \ 30 | result; \ 31 | }) 32 | 33 | 34 | #if __ARM_ARCH >= 6 35 | #define mulr(x,y) \ 36 | ({ \ 37 | register int32_t result; \ 38 | asm ( \ 39 | "smmulr %0, %2, %1" : "=r" (result) : "r" (x), "r" (y) \ 40 | ); \ 41 | result; \ 42 | }) 43 | #else 44 | #define mulr(x,y) \ 45 | ({ \ 46 | register int32_t result; \ 47 | asm ( \ 48 | "smull r3, %0, %2, %1\n\t" \ 49 | "adds r3, r3, #0x80000000\n\t" \ 50 | "adc %0, %0, #0" \ 51 | : "=r" (result) : "r" (x), "r" (y) : "r3", "cc" \ 52 | ); \ 53 | result; \ 54 | }) 55 | #endif 56 | 57 | #define mulsr(x,y) \ 58 | ({ \ 59 | register int32_t result; \ 60 | asm ( \ 61 | "smull r3, %0, %1, %2\n\t" \ 62 | "movs r3, r3, lsl #1\n\t" \ 63 | "adc %0, %0, %0\n\t" \ 64 | "adds r3, r3, #0x80000000\n\t" \ 65 | "adc %0, %0, #0" \ 66 | : "=r" (result) : "r" (x), "r" (y) : "r3", "cc" \ 67 | ); \ 68 | result; \ 69 | }) 70 | 71 | #define mul0(hi,lo,a,b) \ 72 | asm ("smull %0, %1, %2, %3" : "=r" (lo), "=r" (hi) : "r" (a), "r" (b)) 73 | 74 | #define muladd(hi,lo,a,b) \ 75 | asm ("smlal %0, %1, %2, %3" : "+r" (lo), "+r" (hi) : "r" (a), "r" (b)) 76 | 77 | #define mulsub(hi,lo,a,b) \ 78 | asm ("smlal %0, %1, %2, %3" : "+r" (lo), "+r" (hi) : "r" (a), "r" (-(b))) 79 | 80 | #define mulz(hi,lo) 81 | 82 | #define cmuls(dre, dim, are, aim, bre, bim) \ 83 | do { \ 84 | register int32_t tre, tim; \ 85 | asm ( \ 86 | "smull r3, %0, %2, %4\n\t" \ 87 | "smlal r3, %0, %3, %5\n\t" \ 88 | "movs r3, r3, lsl #1\n\t" \ 89 | "adc %0, %0, %0\n\t" \ 90 | "smull r3, %1, %2, %6\n\t" \ 91 | "smlal r3, %1, %4, %3\n\t" \ 92 | "movs r3, r3, lsl #1\n\t" \ 93 | "adc %1, %1, %1\n\t" \ 94 | : "=&r" (tre), "=&r" (tim) \ 95 | : "r" (are), "r" (aim), "r" (bre), "r" (-(bim)), "r" (bim) \ 96 | : "r3", "cc" \ 97 | ); \ 98 | dre = tre; \ 99 | dim = tim; \ 100 | } while (0) 101 | 102 | #if __ARM_ARCH >= 6 103 | static inline uint32_t SWAB32(uint32_t x) 104 | { 105 | asm ("rev %0, %1" : "=r" (x) : "r" (x)); 106 | return x; 107 | } 108 | #define SWAB32 SWAB32 109 | #endif 110 | -------------------------------------------------------------------------------- /Source/storm/sreg.cpp: -------------------------------------------------------------------------------- 1 | #define NOMINMAX 2 | #include "storm.h" 3 | #include 4 | #include 5 | #include "../rmpq/file.h" 6 | 7 | class Registry { 8 | public: 9 | Registry(const char* path) 10 | : path_(path) 11 | { 12 | File f(path); 13 | if (f) { 14 | std::unordered_map* cat = nullptr; 15 | for (auto line : f) { 16 | if (line[0] == '[') { 17 | size_t end = line.find(']'); 18 | if (end != std::string::npos) { 19 | std::string name = line.substr(1, end - 1); 20 | cat = &values[name]; 21 | } 22 | } else if (cat) { 23 | size_t mid = line.find('='); 24 | if (mid != std::string::npos) { 25 | std::string name = line.substr(0, mid); 26 | (*cat)[name] = line.substr(mid + 1); 27 | } 28 | } 29 | } 30 | } 31 | } 32 | 33 | std::unordered_map> values; 34 | 35 | void flush() { 36 | File fo(path_, "wt"); 37 | for (auto& cat : values) { 38 | fo.printf("[%s]\n", cat.first.c_str()); 39 | for (auto& val : cat.second) { 40 | fo.printf("%s=%s\n", val.first.c_str(), val.second.c_str()); 41 | } 42 | } 43 | } 44 | 45 | static Registry& instance() { 46 | static Registry inst("config.ini"); 47 | return inst; 48 | } 49 | 50 | const char* get(const char *keyname, const char *valuename) { 51 | auto it1 = values.find(keyname); 52 | if (it1 != values.end()) { 53 | auto it2 = it1->second.find(valuename); 54 | if (it2 != it1->second.end()) { 55 | return it2->second.c_str(); 56 | } 57 | } 58 | return nullptr; 59 | } 60 | 61 | private: 62 | std::string path_; 63 | }; 64 | 65 | BOOL SRegLoadString(const char *keyname, const char *valuename, BYTE flags, char *buffer, unsigned int buffersize) { 66 | auto value = Registry::instance().get(keyname, valuename); 67 | if (value) { 68 | SStrCopy(buffer, value, buffersize); 69 | return TRUE; 70 | } 71 | return FALSE; 72 | } 73 | 74 | BOOL SRegLoadValue(const char *keyname, const char *valuename, BYTE flags, int *result) { 75 | auto value = Registry::instance().get(keyname, valuename); 76 | if (value) { 77 | *result = atoi(value); 78 | return TRUE; 79 | } 80 | return FALSE; 81 | } 82 | 83 | BOOL SRegSaveString(const char *keyname, const char *valuename, BYTE flags, char *string) { 84 | Registry::instance().values[keyname][valuename] = string; 85 | Registry::instance().flush(); 86 | return TRUE; 87 | } 88 | 89 | BOOL SRegSaveValue(const char *keyname, const char *valuename, BYTE flags, DWORD result) { 90 | Registry::instance().values[keyname][valuename] = std::to_string(result); 91 | Registry::instance().flush(); 92 | return TRUE; 93 | } 94 | 95 | BOOL SRegDeleteValue(const char *keyname, const char *valuename, BYTE flags) { 96 | Registry::instance().values[keyname].erase(valuename); 97 | Registry::instance().flush(); 98 | return TRUE; 99 | } 100 | -------------------------------------------------------------------------------- /Source/libsmacker/smk_bitstream.c: -------------------------------------------------------------------------------- 1 | /** 2 | libsmacker - A C library for decoding .smk Smacker Video files 3 | Copyright (C) 2012-2017 Greg Kennedy 4 | 5 | See smacker.h for more information. 6 | 7 | smk_bitstream.c 8 | Implements a bitstream structure, which can extract and 9 | return a bit at a time from a raw block of bytes. 10 | */ 11 | 12 | #include "smk_bitstream.h" 13 | 14 | /* malloc and friends */ 15 | #include "smk_malloc.h" 16 | 17 | /* 18 | Bitstream structure 19 | Pointer to raw block of data and a size limit. 20 | Maintains internal pointers to byte_num and bit_number. 21 | */ 22 | struct smk_bit_t 23 | { 24 | const unsigned char* buffer; 25 | unsigned long size; 26 | 27 | unsigned long byte_num; 28 | char bit_num; 29 | }; 30 | 31 | /* BITSTREAM Functions */ 32 | struct smk_bit_t* smk_bs_init(const unsigned char* b, const unsigned long size) 33 | { 34 | struct smk_bit_t* ret = NULL; 35 | 36 | /* sanity check */ 37 | smk_assert(b); 38 | 39 | /* allocate a bitstream struct */ 40 | smk_malloc(ret, sizeof(struct smk_bit_t)); 41 | 42 | /* set up the pointer to bitstream, and the size counter */ 43 | ret->buffer = b; 44 | ret->size = size; 45 | 46 | /* point to initial byte: note, smk_malloc already sets these to 0 */ 47 | /* ret->byte_num = 0; 48 | ret->bit_num = 0; */ 49 | 50 | /* return ret or NULL if error : ) */ 51 | error: 52 | return ret; 53 | } 54 | 55 | /* Reads a bit 56 | Returns -1 if error encountered */ 57 | char _smk_bs_read_1(struct smk_bit_t* bs) 58 | { 59 | unsigned char ret = -1; 60 | 61 | /* sanity check */ 62 | smk_assert(bs); 63 | 64 | /* don't die when running out of bits, but signal */ 65 | if (bs->byte_num >= bs->size) 66 | { 67 | fprintf(stderr, "libsmacker::_smk_bs_read_1(bs): ERROR: bitstream (length=%lu) exhausted.\n", bs->size); 68 | goto error; 69 | } 70 | 71 | /* get next bit and return */ 72 | ret = (((bs->buffer[bs->byte_num]) & (1 << bs->bit_num)) != 0); 73 | 74 | /* advance to next bit */ 75 | bs->bit_num ++; 76 | 77 | /* Out of bits in this byte: next! */ 78 | if (bs->bit_num > 7) 79 | { 80 | bs->byte_num ++; 81 | bs->bit_num = 0; 82 | } 83 | 84 | /* return ret, or (default) -1 if error */ 85 | error: 86 | return ret; 87 | } 88 | 89 | /* Reads a byte 90 | Returns -1 if error. */ 91 | short _smk_bs_read_8(struct smk_bit_t* bs) 92 | { 93 | unsigned char ret = -1; 94 | 95 | /* sanity check */ 96 | smk_assert(bs); 97 | 98 | /* don't die when running out of bits, but signal */ 99 | if (bs->byte_num + (bs->bit_num > 0) >= bs->size) 100 | { 101 | fprintf(stderr, "libsmacker::_smk_bs_read_8(bs): ERROR: bitstream (length=%lu) exhausted.\n", bs->size); 102 | goto error; 103 | } 104 | 105 | if (bs->bit_num) 106 | { 107 | /* unaligned read */ 108 | ret = bs->buffer[bs->byte_num] >> bs->bit_num; 109 | bs->byte_num ++; 110 | ret |= (bs->buffer[bs->byte_num] << (8 - bs->bit_num)); 111 | } else { 112 | /* aligned read */ 113 | ret = bs->buffer[bs->byte_num ++]; 114 | } 115 | 116 | /* return ret, or (default) -1 if error */ 117 | error: 118 | return ret; 119 | } 120 | -------------------------------------------------------------------------------- /Source/scrollrt.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __SCROLLRT_H__ 3 | #define __SCROLLRT_H__ 4 | 5 | extern int light_table_index; 6 | extern int PitchTbl[1024]; 7 | extern BYTE *gpBufEnd; 8 | extern DWORD level_cel_block; 9 | extern char arch_draw_type; 10 | extern int cel_transparency_active; 11 | extern int level_piece_id; 12 | extern void (*DrawPlrProc)(int, int, int, int, int, BYTE *, int, int, int, int); 13 | extern int draw_monster_num; 14 | extern BOOL hide_cursor; 15 | 16 | void ClearCursor(); 17 | void DrawMissile(int x, int y, int sx, int sy, int CelSkip, int capChunks, BOOL pre); 18 | void DrawClippedMissile(int x, int y, int sx, int sy, int CelSkip, int capChunks, BOOL pre); 19 | void DrawDeadPlayer(int x, int y, int sx, int sy, int CelSkip, int capChunks, BOOL clipped); 20 | void DrawPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int capChunks); 21 | void DrawClippedPlayer(int pnum, int x, int y, int px, int py, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int capChunks); 22 | void DrawView(int StartX, int StartY); 23 | void DrawGame(int x, int y); 24 | void scrollrt_draw_lower(int x, int y, int sx, int sy, int chunks, int eflag); 25 | void scrollrt_draw_clipped_dungeon(BYTE *pBuff, int sx, int sy, int dx, int dy, int eflag); 26 | void DrawClippedMonster(int x, int y, int mx, int my, int m, int CelSkip, int capChunks); 27 | void DrawClippedObject(int x, int y, int ox, int oy, BOOL pre, int CelSkip, int capChunks); 28 | void scrollrt_draw_clipped_e_flag(BYTE *pBuff, int x, int y, int sx, int sy); 29 | void scrollrt_draw_lower_2(int x, int y, int sx, int sy, int chunks, int skipChunks, int eflag); 30 | void scrollrt_draw_clipped_dungeon_2(BYTE *pBuff, int sx, int sy, int skipChunks, int CelSkip, int dx, int dy, int eflag); 31 | void scrollrt_draw_clipped_e_flag_2(BYTE *pBuff, int x, int y, int skipChunks, int CelSkip, int sx, int sy); 32 | void scrollrt_draw_upper(int x, int y, int sx, int sy, int chunks, int capChunks, int eflag); 33 | void scrollrt_draw_dungeon(BYTE *pBuff, int sx, int sy, int capChunks, int CelCap, int dx, int dy, int eflag); 34 | void DrawMonster(int x, int y, int mx, int my, int m, int CelSkip, int CelCap); 35 | void DrawObject(int x, int y, int ox, int oy, BOOL pre, int CelSkip, int capChunks); 36 | void scrollrt_draw_e_flag(BYTE *pBuff, int x, int y, int capChunks, int CelCap, int sx, int sy); 37 | void DrawZoom(int x, int y); 38 | void ClearScreenBuffer(); 39 | #ifdef _DEBUG 40 | void ScrollView(); 41 | void EnableFrameCount(); 42 | #endif 43 | void scrollrt_draw_game_screen(BOOL draw_cursor); 44 | void scrollrt_draw_cursor_back_buffer(); 45 | void scrollrt_draw_cursor_item(); 46 | void DrawMain(int dwHgt, BOOL draw_desc, BOOL draw_hp, BOOL draw_mana, BOOL draw_sbar, BOOL draw_btn); 47 | #ifdef _DEBUG 48 | void DrawFPS(); 49 | #endif 50 | void DoBlitScreen(DWORD dwX, DWORD dwY, DWORD dwWdt, DWORD dwHgt); 51 | void DrawAndBlit(); 52 | 53 | /* rdata */ 54 | 55 | /* data */ 56 | 57 | /* used in 1.00 debug */ 58 | extern const char *szMonModeAssert[18]; 59 | extern const char *szPlrModeAssert[12]; 60 | 61 | #endif /* __SCROLLRT_H__ */ 62 | -------------------------------------------------------------------------------- /Source/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribtution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /Source/storm/sbmp.cpp: -------------------------------------------------------------------------------- 1 | #include "storm.h" 2 | 3 | static int my_stricmp(const char* a, const char* b) { 4 | for (size_t i = 0; a[i] || b[i]; ++i) { 5 | char pa = tolower((unsigned char) a[i]); 6 | char pb = tolower((unsigned char) b[i]); 7 | if (pa != pb) { 8 | return pa < pb ? -1 : 1; 9 | } 10 | } 11 | return 0; 12 | } 13 | 14 | BOOL SBmpLoadImage(const char* pszFileName, PALETTEENTRY* pPalette, BYTE* pBuffer, DWORD dwBuffersize, DWORD* pdwWidth, DWORD* pdwHeight, DWORD* pdwBpp) { 15 | HANDLE hFile; 16 | size_t size; 17 | PCXHEADER pcxhdr; 18 | BYTE paldata[256][3]; 19 | BYTE *dataPtr, *fileBuffer; 20 | BYTE byte; 21 | 22 | if (pdwWidth) 23 | *pdwWidth = 0; 24 | if (pdwHeight) 25 | *pdwHeight = 0; 26 | if (pdwBpp) 27 | *pdwBpp = 0; 28 | 29 | if (!pszFileName || !*pszFileName) { 30 | return false; 31 | } 32 | 33 | if (pBuffer && !dwBuffersize) { 34 | return false; 35 | } 36 | 37 | if (!pPalette && !pBuffer && !pdwWidth && !pdwHeight) { 38 | return false; 39 | } 40 | 41 | if (!SFileOpenFile(pszFileName, &hFile)) { 42 | return false; 43 | } 44 | 45 | while (strchr(pszFileName, 92)) 46 | pszFileName = strchr(pszFileName, 92) + 1; 47 | 48 | while (strchr(pszFileName + 1, 46)) 49 | pszFileName = strchr(pszFileName, 46); 50 | 51 | // omit all types except PCX 52 | if (!pszFileName || my_stricmp(pszFileName, ".pcx")) { 53 | return false; 54 | } 55 | 56 | if (!SFileReadFile(hFile, &pcxhdr, 128, 0, 0)) { 57 | SFileCloseFile(hFile); 58 | return false; 59 | } 60 | 61 | int width = pcxhdr.Xmax - pcxhdr.Xmin + 1; 62 | int height = pcxhdr.Ymax - pcxhdr.Ymin + 1; 63 | 64 | if (pdwWidth) 65 | *pdwWidth = width; 66 | if (pdwHeight) 67 | *pdwHeight = height; 68 | if (pdwBpp) 69 | *pdwBpp = pcxhdr.BitsPerPixel; 70 | 71 | if (!pBuffer) { 72 | SFileSetFilePointer(hFile, 0, 0, 2); 73 | fileBuffer = NULL; 74 | } else { 75 | size = SFileGetFileSize(hFile, 0) - SFileSetFilePointer(hFile, 0, 0, 1); 76 | fileBuffer = (BYTE *) malloc(size); 77 | } 78 | 79 | if (fileBuffer) { 80 | SFileReadFile(hFile, fileBuffer, size, 0, 0); 81 | dataPtr = fileBuffer; 82 | 83 | for (int j = 0; j < height; j++) { 84 | for (int x = 0; x < width; dataPtr++) { 85 | byte = *dataPtr; 86 | if (byte < 0xC0) { 87 | *pBuffer = byte; 88 | pBuffer++; 89 | x++; 90 | continue; 91 | } 92 | dataPtr++; 93 | 94 | for (int i = 0; i < (byte & 0x3F); i++) { 95 | *pBuffer = *dataPtr; 96 | pBuffer++; 97 | x++; 98 | } 99 | } 100 | } 101 | 102 | free(fileBuffer); 103 | } 104 | 105 | if (pPalette && pcxhdr.BitsPerPixel == 8) { 106 | SFileSetFilePointer(hFile, -768, 0, 1); 107 | SFileReadFile(hFile, paldata, 768, 0, 0); 108 | for (int i = 0; i < 256; i++) { 109 | pPalette[i].peRed = paldata[i][0]; 110 | pPalette[i].peGreen = paldata[i][1]; 111 | pPalette[i].peBlue = paldata[i][2]; 112 | pPalette[i].peFlags = 0; 113 | } 114 | } 115 | 116 | SFileCloseFile(hFile); 117 | 118 | return true; 119 | } 120 | -------------------------------------------------------------------------------- /Source/libsmacker/smk_hufftree.h: -------------------------------------------------------------------------------- 1 | /** 2 | libsmacker - A C library for decoding .smk Smacker Video files 3 | Copyright (C) 2012-2017 Greg Kennedy 4 | 5 | See smacker.h for more information. 6 | 7 | smk_hufftree.h 8 | SMK huffmann trees. There are two types: 9 | - a basic 8-bit tree, and 10 | - a "big" 16-bit tree which includes a cache for recently 11 | searched values. 12 | */ 13 | 14 | #ifndef SMK_HUFFTREE_H 15 | #define SMK_HUFFTREE_H 16 | 17 | #include "smk_bitstream.h" 18 | 19 | /** Tree node structures - Forward declaration */ 20 | struct smk_huff8_t; 21 | struct smk_huff16_t; 22 | 23 | /*********************** 8-BIT HUFF-TREE FUNCTIONS ***********************/ 24 | /** This macro checks return code from _smk_huff8_build and 25 | jumps to error label if problems occur. */ 26 | #define smk_huff8_build(bs,t) \ 27 | { \ 28 | if (!(t = _smk_huff8_build(bs))) \ 29 | { \ 30 | fprintf(stderr, "libsmacker::smk_huff8_build(" #bs ", " #t ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ 31 | goto error; \ 32 | } \ 33 | } 34 | /** Build an 8-bit tree from a bitstream */ 35 | struct smk_huff8_t* _smk_huff8_build(struct smk_bit_t* bs); 36 | 37 | /** This macro checks return code from _smk_huff8_lookup and 38 | jumps to error label if problems occur. */ 39 | #define smk_huff8_lookup(bs,t,s) \ 40 | { \ 41 | if ((short)(s = _smk_huff8_lookup(bs, t)) < 0) \ 42 | { \ 43 | fprintf(stderr, "libsmacker::smk_huff8_lookup(" #bs ", " #t ", " #s ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ 44 | goto error; \ 45 | } \ 46 | } 47 | /** Look up an 8-bit value in the referenced tree by following a bitstream 48 | returns -1 on error */ 49 | short _smk_huff8_lookup(struct smk_bit_t* bs, const struct smk_huff8_t* t); 50 | 51 | /** function to recursively delete an 8-bit huffman tree */ 52 | void smk_huff8_free(struct smk_huff8_t* t); 53 | 54 | /************************ 16-BIT HUFF-TREE FUNCTIONS ************************/ 55 | /** This macro checks return code from _smk_huff16_build and 56 | jumps to error label if problems occur. */ 57 | #define smk_huff16_build(bs,t) \ 58 | { \ 59 | if (!(t = _smk_huff16_build(bs))) \ 60 | { \ 61 | fprintf(stderr, "libsmacker::smk_huff16_build(" #bs ", " #t ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ 62 | goto error; \ 63 | } \ 64 | } 65 | /** Build a 16-bit tree from a bitstream */ 66 | struct smk_huff16_t* _smk_huff16_build(struct smk_bit_t* bs); 67 | 68 | /** This macro checks return code from smk_huff16_lookup and 69 | jumps to error label if problems occur. */ 70 | #define smk_huff16_lookup(bs,t,s) \ 71 | { \ 72 | if ((s = _smk_huff16_lookup(bs, t)) < 0) \ 73 | { \ 74 | fprintf(stderr, "libsmacker::smk_huff16_lookup(" #bs ", " #t ", " #s ") - ERROR (file: %s, line: %lu)\n", __FILE__, (unsigned long)__LINE__); \ 75 | goto error; \ 76 | } \ 77 | } 78 | /** Look up a 16-bit value in the bigtree by following a bitstream 79 | returns -1 on error */ 80 | long _smk_huff16_lookup(struct smk_bit_t* bs, struct smk_huff16_t* big); 81 | 82 | /** Reset the cache in a 16-bit tree */ 83 | void smk_huff16_reset(struct smk_huff16_t* big); 84 | 85 | /** function to recursively delete a 16-bit huffman tree */ 86 | void smk_huff16_free(struct smk_huff16_t* big); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /Source/sha.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | 3 | SHA1Context sgSHA1[3]; 4 | 5 | void SHA1Clear() 6 | { 7 | memset(sgSHA1, 0, sizeof(sgSHA1)); 8 | } 9 | 10 | void SHA1Result(int n, char Message_Digest[SHA1HashSize]) 11 | { 12 | DWORD *Message_Digest_Block; 13 | int i; 14 | 15 | Message_Digest_Block = (DWORD *)Message_Digest; 16 | if (Message_Digest) { 17 | for (i = 0; i < 5; i++) { 18 | *Message_Digest_Block = sgSHA1[n].state[i]; 19 | Message_Digest_Block++; 20 | } 21 | } 22 | } 23 | 24 | void SHA1Calculate(int n, const char *data, char Message_Digest[SHA1HashSize]) 25 | { 26 | SHA1Input(&sgSHA1[n], data, 64); 27 | if (Message_Digest) 28 | SHA1Result(n, Message_Digest); 29 | } 30 | 31 | void SHA1Input(SHA1Context *context, const char *message_array, int len) 32 | { 33 | int i, count; 34 | 35 | count = context->count[0] + 8 * len; 36 | if (count < context->count[0]) 37 | context->count[1]++; 38 | 39 | context->count[0] = count; 40 | context->count[1] += len >> 29; 41 | 42 | for (i = len; i >= 64; i -= 64) { 43 | memcpy(context->buffer, message_array, sizeof(context->buffer)); 44 | SHA1ProcessMessageBlock(context); 45 | message_array += 64; 46 | } 47 | } 48 | 49 | void SHA1ProcessMessageBlock(SHA1Context *context) 50 | { 51 | int i, temp; 52 | int W[80]; 53 | int A, B, C, D, E; 54 | 55 | DWORD *buf = (DWORD *)context->buffer; 56 | for (i = 0; i < 16; i++) 57 | W[i] = buf[i]; 58 | 59 | for (i = 16; i < 80; i++) { 60 | W[i] = W[i - 16] ^ W[i - 14] ^ W[i - 8] ^ W[i - 3]; 61 | } 62 | 63 | A = context->state[0]; 64 | B = context->state[1]; 65 | C = context->state[2]; 66 | D = context->state[3]; 67 | E = context->state[4]; 68 | 69 | for (i = 0; i < 20; i++) { 70 | temp = SHA1CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + W[i] + 0x5A827999; 71 | E = D; 72 | D = C; 73 | C = SHA1CircularShift(30, B); 74 | B = A; 75 | A = temp; 76 | } 77 | 78 | for (i = 20; i < 40; i++) { 79 | temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1; 80 | E = D; 81 | D = C; 82 | C = SHA1CircularShift(30, B); 83 | B = A; 84 | A = temp; 85 | } 86 | 87 | for (i = 40; i < 60; i++) { 88 | temp = SHA1CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC; 89 | E = D; 90 | D = C; 91 | C = SHA1CircularShift(30, B); 92 | B = A; 93 | A = temp; 94 | } 95 | 96 | for (i = 60; i < 80; i++) { 97 | temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6; 98 | E = D; 99 | D = C; 100 | C = SHA1CircularShift(30, B); 101 | B = A; 102 | A = temp; 103 | } 104 | 105 | context->state[0] += A; 106 | context->state[1] += B; 107 | context->state[2] += C; 108 | context->state[3] += D; 109 | context->state[4] += E; 110 | } 111 | 112 | void SHA1Reset(int n) 113 | { 114 | SHA1Init(&sgSHA1[n]); 115 | } 116 | 117 | void SHA1Init(SHA1Context *context) 118 | { 119 | context->count[0] = 0; 120 | context->count[1] = 0; 121 | context->state[0] = 0x67452301; 122 | context->state[1] = 0xEFCDAB89; 123 | context->state[2] = 0x98BADCFE; 124 | context->state[3] = 0x10325476; 125 | context->state[4] = 0xC3D2E1F0; 126 | } 127 | -------------------------------------------------------------------------------- /Source/ui/main_menu.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "dialog.h" 3 | #include "network.h" 4 | 5 | #ifdef SPAWN 6 | #define NO_INTRO "The Diablo introduction cinematic is only available in the full retail version of Diablo. For ordering information call (800) 953-SNOW." 7 | #endif 8 | 9 | enum { 10 | MM_SINGLEPLAYER, 11 | MM_MULTIPLAYER, 12 | MM_REPLAYINTRO, 13 | MM_SHOWCREDITS, 14 | MM_EXITDIABLO, 15 | }; 16 | 17 | int menu_music_track_id = TMUSIC_INTRO; 18 | 19 | void mainmenu_refresh_music() { 20 | music_start(menu_music_track_id); 21 | do { 22 | menu_music_track_id++; 23 | if (menu_music_track_id == NUM_MUSIC) 24 | menu_music_track_id = 0; 25 | } while (!menu_music_track_id || menu_music_track_id == 1); 26 | } 27 | 28 | class MainMenuDialog : public DialogState { 29 | public: 30 | MainMenuDialog() { 31 | addItem({{0, 0, 640, 480}, ControlType::Image, 0, 0, "", &ArtBackground}); 32 | addItem({{64, 192, 574, 235}, ControlType::List, ControlFlags::Huge | ControlFlags::Gold | ControlFlags::Center, MM_SINGLEPLAYER, "Single Player"}); 33 | addItem({{64, 235, 574, 278}, ControlType::List, ControlFlags::Huge | ControlFlags::Gold | ControlFlags::Center, MM_MULTIPLAYER, "Multi Player"}); 34 | addItem({{64, 277, 574, 320}, ControlType::List, ControlFlags::Huge | ControlFlags::Gold | ControlFlags::Center, MM_REPLAYINTRO, "Replay Intro"}); 35 | addItem({{64, 320, 574, 363}, ControlType::List, ControlFlags::Huge | ControlFlags::Gold | ControlFlags::Center, MM_SHOWCREDITS, "Show Credits"}); 36 | addItem({{64, 363, 574, 406}, ControlType::List, ControlFlags::Huge | ControlFlags::Gold | ControlFlags::Center, MM_EXITDIABLO, "Exit Diablo"}); 37 | addItem({{17, 444, 622, 465}, ControlType::Text, ControlFlags::Small, 0, gszProductName}); 38 | addItem({{125, 0, 515, 154}, ControlType::Image, 0, -60, "", &ArtLogos[LOGO_MED]}); 39 | } 40 | 41 | void onActivate() override { 42 | mainmenu_refresh_music(); 43 | #ifdef SPAWN 44 | LoadBackgroundArt("ui_art\\swmmenu.pcx"); 45 | #else 46 | LoadBackgroundArt("ui_art\\mainmenu.pcx"); 47 | #endif 48 | } 49 | 50 | void onKey(const KeyEvent& e) override { 51 | DialogState::onKey(e); 52 | if (e.action == KeyEvent::Press && e.key == KeyCode::ESCAPE) { 53 | GameState::activate(nullptr); 54 | } 55 | } 56 | 57 | void onInput(int index) override { 58 | switch (index) { 59 | case MM_SINGLEPLAYER: 60 | UiPlaySelectSound(); 61 | start_game(false); 62 | break; 63 | case MM_MULTIPLAYER: 64 | UiPlaySelectSound(); 65 | start_multiplayer(); 66 | break; 67 | case MM_REPLAYINTRO: 68 | UiPlaySelectSound(); 69 | #ifndef SPAWN 70 | music_stop(); 71 | GameState::activate(get_video_state("gendata\\diablo1.smk", true, false, 72 | get_main_menu_dialog())); 73 | #else 74 | GameState::activate(get_ok_dialog(NO_INTRO, get_main_menu_dialog(), true)); 75 | #endif 76 | break; 77 | case MM_SHOWCREDITS: 78 | UiPlaySelectSound(); 79 | GameState::activate(get_credits_dialog()); 80 | break; 81 | case MM_EXITDIABLO: 82 | UiPlaySelectSound(); 83 | GameState::activate(nullptr); 84 | break; 85 | } 86 | } 87 | }; 88 | 89 | GameStatePtr get_main_menu_dialog() { 90 | return new MainMenuDialog(); 91 | } 92 | -------------------------------------------------------------------------------- /Source/gendung.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __GENDUNG_H__ 3 | #define __GENDUNG_H__ 4 | 5 | extern WORD level_frame_types[MAXTILES]; 6 | extern int themeCount; 7 | extern BOOLEAN nTransTable[2049]; 8 | //int dword_52D204; 9 | extern int dMonster[MAXDUNX][MAXDUNY]; 10 | extern BYTE dungeon[DMAXX][DMAXY]; 11 | extern char dObject[MAXDUNX][MAXDUNY]; 12 | extern BYTE *pSpeedCels; 13 | extern int nlevel_frames; 14 | extern BYTE pdungeon[DMAXX][DMAXY]; 15 | extern char dDead[MAXDUNX][MAXDUNY]; 16 | extern MICROS dpiece_defs_map_1[MAXDUNX * MAXDUNY]; 17 | extern char dPreLight[MAXDUNX][MAXDUNY]; 18 | extern char TransVal; 19 | extern int MicroTileLen; 20 | extern char dflags[DMAXX][DMAXY]; 21 | extern int dPiece[MAXDUNX][MAXDUNY]; 22 | extern char dLight[MAXDUNX][MAXDUNY]; 23 | extern int setloadflag_2; 24 | extern int tile_defs[MAXTILES]; 25 | extern BYTE *pMegaTiles; 26 | extern BYTE *pLevelPieces; 27 | extern int gnDifficulty; 28 | extern char block_lvid[2049]; 29 | //char byte_5B78EB; 30 | extern char dTransVal[MAXDUNX][MAXDUNY]; 31 | extern BOOLEAN nTrapTable[2049]; 32 | extern BYTE leveltype; 33 | extern BYTE currlevel; 34 | extern BOOLEAN TransList[256]; 35 | extern BOOLEAN nSolidTable[2049]; 36 | extern int level_frame_count[MAXTILES]; 37 | extern ScrollStruct ScrollInfo; 38 | extern BYTE *pDungeonCels; 39 | extern int SpeedFrameTbl[128][16]; 40 | extern THEME_LOC themeLoc[MAXTHEMES]; 41 | extern char dPlayer[MAXDUNX][MAXDUNY]; 42 | extern int dword_5C2FF8; 43 | extern int dword_5C2FFC; 44 | extern int scr_pix_width; 45 | extern int scr_pix_height; 46 | extern char dArch[MAXDUNX][MAXDUNY]; 47 | extern BOOLEAN nBlockTable[2049]; 48 | extern BYTE *pSpecialCels; 49 | extern char dFlags[MAXDUNX][MAXDUNY]; 50 | extern char dItem[MAXDUNX][MAXDUNY]; 51 | extern BYTE setlvlnum; 52 | extern int level_frame_sizes[MAXTILES]; 53 | extern BOOLEAN nMissileTable[2049]; 54 | extern char *pSetPiece_2; 55 | extern char setlvltype; 56 | extern BOOLEAN setlevel; 57 | extern int LvlViewY; 58 | extern int LvlViewX; 59 | extern int dmaxx; 60 | extern int dmaxy; 61 | extern int setpc_h; 62 | extern int setpc_w; 63 | extern int setpc_x; 64 | extern int ViewX; 65 | extern int ViewY; 66 | extern int setpc_y; 67 | extern char dMissile[MAXDUNX][MAXDUNY]; 68 | extern int dminx; 69 | extern int dminy; 70 | extern MICROS dpiece_defs_map_2[MAXDUNX][MAXDUNY]; 71 | 72 | void FillSolidBlockTbls(); 73 | void MakeSpeedCels(); 74 | void SortTiles(int frames); 75 | void SwapTile(int f1, int f2); 76 | int IsometricCoord(int x, int y); 77 | void SetSpeedCels(); 78 | void SetDungeonMicros(); 79 | void DRLG_InitTrans(); 80 | void DRLG_MRectTrans(int x1, int y1, int x2, int y2); 81 | void DRLG_RectTrans(int x1, int y1, int x2, int y2); 82 | void DRLG_CopyTrans(int sx, int sy, int dx, int dy); 83 | void DRLG_ListTrans(int num, BYTE *List); 84 | void DRLG_AreaTrans(int num, BYTE *List); 85 | void DRLG_InitSetPC(); 86 | void DRLG_SetPC(); 87 | void Make_SetPC(int x, int y, int w, int h); 88 | BOOL DRLG_WillThemeRoomFit(int floor, int x, int y, int minSize, int maxSize, int *width, int *height); 89 | void DRLG_CreateThemeRoom(int themeIndex); 90 | void DRLG_PlaceThemeRooms(int minSize, int maxSize, int floor, int freq, int rndSize); 91 | void DRLG_HoldThemeRooms(); 92 | BOOL SkipThemeRoom(int x, int y); 93 | void InitLevels(); 94 | 95 | #endif /* __GENDUNG_H__ */ 96 | -------------------------------------------------------------------------------- /mpqcmp/wave.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Source/rmpq/file.h" 3 | #include 4 | 5 | extern "C" { 6 | #include "shine/layer3.h" 7 | } 8 | 9 | struct chunk_t { 10 | uint32_t offset; 11 | uint32_t size; 12 | }; 13 | 14 | bool ReadWaveSection(File file, uint32_t id, chunk_t& chunk) { 15 | uint32_t hdr[2]; 16 | 17 | while (1) { 18 | if (!file.read(hdr, sizeof hdr)) { 19 | return false; 20 | } 21 | if (hdr[0] == id) { 22 | break; 23 | } 24 | file.seek(hdr[1], SEEK_CUR); 25 | } 26 | 27 | chunk.size = hdr[1]; 28 | chunk.offset = (uint32_t) file.tell(); 29 | return true; 30 | } 31 | 32 | struct format_t { 33 | uint16_t format_tag; 34 | uint16_t channels; 35 | uint32_t samples_per_sec; 36 | uint32_t bytes_per_sec; 37 | uint16_t block_align; 38 | uint16_t bits_per_sample; 39 | }; 40 | 41 | struct mmckinfo_t { 42 | uint32_t ckid; 43 | uint32_t cksize; 44 | uint32_t type; 45 | }; 46 | 47 | bool ReadWaveFile(File file, format_t& fmt, chunk_t& chunk) { 48 | mmckinfo_t hdr; 49 | if (!file.read(&hdr, sizeof hdr)) { 50 | return false; 51 | } 52 | if (hdr.ckid != 0x46464952 || hdr.type != 0x45564157) // 'RIFF' 'WAVE' 53 | { 54 | return false; 55 | } 56 | chunk_t chk; 57 | if (!ReadWaveSection(file, 0x20746D66, chk)) // 'fmt ' 58 | { 59 | return false; 60 | } 61 | if (chk.size < sizeof fmt) { 62 | return false; 63 | } 64 | if (!file.read(&fmt, sizeof fmt)) { 65 | return false; 66 | } 67 | file.seek(chk.size - sizeof fmt, SEEK_CUR); 68 | return ReadWaveSection(file, 0x61746164, chunk); // 'data' 69 | } 70 | 71 | inline size_t round_up(size_t size, size_t mult) { 72 | size_t chk = (size + mult - 1) / mult; 73 | return chk * mult; 74 | } 75 | 76 | size_t write_wave(File dst, File src) { 77 | format_t fmt; 78 | chunk_t chunk; 79 | ReadWaveFile(src, fmt, chunk); 80 | 81 | shine_config_t cfg; 82 | cfg.wave.channels = fmt.channels == 1 ? PCM_MONO : PCM_STEREO; 83 | cfg.wave.samplerate = fmt.samples_per_sec; 84 | cfg.mpeg.mode = fmt.channels == 1 ? MONO : JOINT_STEREO; 85 | cfg.mpeg.bitr = (fmt.samples_per_sec > 20000 && fmt.bits_per_sample == 16 ? 128 : 64); 86 | cfg.mpeg.emph = NONE; 87 | cfg.mpeg.copyright = 0; 88 | cfg.mpeg.original = 1; 89 | 90 | auto t = shine_initialise(&cfg); 91 | size_t spp = (size_t) shine_samples_per_pass(t); 92 | 93 | std::vector raw; 94 | size_t samples = chunk.size / (fmt.bits_per_sample / 8); 95 | size_t block = spp * fmt.channels; 96 | std::vector data(block); 97 | 98 | src.seek(chunk.offset); 99 | size_t total = 0; 100 | for (size_t pos = 0; pos < samples; pos += block) { 101 | size_t have = std::min(block, samples - pos); 102 | if (fmt.bits_per_sample == 8) { 103 | raw.resize(have); 104 | src.read(raw.data(), have); 105 | for (size_t i = 0; i < have; ++i) { 106 | data[i] = int16_t(((int) raw[i] * 65535 / 255) - 32768); 107 | } 108 | } else { 109 | src.read(data.data(), have * 2); 110 | } 111 | for (size_t i = have; i < block; ++i) { 112 | data[i] = 0; 113 | } 114 | 115 | int written; 116 | auto buffer = shine_encode_buffer_interleaved(t, data.data(), &written); 117 | dst.write(buffer, written); 118 | total += written; 119 | } 120 | 121 | return total; 122 | } 123 | -------------------------------------------------------------------------------- /Source/rmpq/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "file.h" 4 | #include "checksum.h" 5 | 6 | namespace mpq { 7 | 8 | inline uint64_t offset64(uint32_t offset, uint16_t offsetHi) { 9 | return uint64_t(offset) | (uint64_t(offsetHi) << 32); 10 | } 11 | 12 | inline uint64_t hashTo64(uint32_t name1, uint32_t name2) { 13 | return uint64_t(name1) | (uint64_t(name2) << 32); 14 | } 15 | 16 | enum { 17 | HASH_OFFSET = 0, 18 | HASH_NAME1 = 1, 19 | HASH_NAME2 = 2, 20 | HASH_KEY = 3, 21 | HASH_ENCRYPT = 4, 22 | HASH_SIZE = 1280 23 | }; 24 | 25 | #pragma pack(push, 1) 26 | struct MPQUserData { 27 | enum { 28 | signature = 0x1B51504D, // MPQ\x1B 29 | }; 30 | uint32_t id; 31 | uint32_t userDataSize; 32 | uint32_t headerOffs; 33 | uint32_t userDataHeader; 34 | }; 35 | struct MPQHeader { 36 | enum { 37 | signature = 0x1A51504D, // MPQ\x1A 38 | size_v1 = 32, 39 | size_v2 = 44, 40 | size_v3 = 68, 41 | size_v4 = 208, 42 | }; 43 | 44 | uint32_t id; 45 | uint32_t headerSize; 46 | uint32_t archiveSize; 47 | uint16_t formatVersion; 48 | uint16_t blockSize; 49 | 50 | uint32_t hashTablePos; 51 | uint32_t blockTablePos; 52 | uint32_t hashTableSize; 53 | uint32_t blockTableSize; 54 | 55 | // v2 56 | uint64_t hiBlockTablePos64; 57 | uint16_t hashTablePosHi; 58 | uint16_t blockTablePosHi; 59 | 60 | // v3 61 | uint64_t archiveSize64; 62 | uint64_t betTablePos64; 63 | uint64_t hetTablePos64; 64 | 65 | // v4 66 | uint64_t hashTableSize64; 67 | uint64_t blockTableSize64; 68 | uint64_t hiBlockTableSize64; 69 | uint64_t hetTableSize64; 70 | uint64_t betTableSize64; 71 | 72 | uint32_t rawChunkSize; 73 | uint8_t md5BlockTable[MD5::DIGEST_SIZE]; 74 | uint8_t md5HashTable[MD5::DIGEST_SIZE]; 75 | uint8_t md5HiBlockTable[MD5::DIGEST_SIZE]; 76 | uint8_t md5BetTable[MD5::DIGEST_SIZE]; 77 | uint8_t md5HetTable[MD5::DIGEST_SIZE]; 78 | uint8_t md5MPQHeader[MD5::DIGEST_SIZE]; 79 | 80 | void upgrade(size_t fileSize); 81 | }; 82 | 83 | struct MPQHashEntry { 84 | enum { 85 | EMPTY = 0xFFFFFFFF, 86 | DELETED = 0xFFFFFFFE, 87 | }; 88 | uint32_t name1; 89 | uint32_t name2; 90 | uint16_t locale; 91 | uint16_t platform; 92 | uint32_t blockIndex; 93 | }; 94 | 95 | struct MPQBlockEntry { 96 | uint32_t filePos; 97 | uint32_t cSize; 98 | uint32_t fSize; 99 | uint32_t flags; 100 | }; 101 | #pragma pack(pop) 102 | 103 | uint32_t hashString(char const* str, uint32_t hashType); 104 | 105 | inline uint64_t hashString64(char const* str) { 106 | return hashTo64(hashString(str, HASH_NAME1), hashString(str, HASH_NAME2)); 107 | } 108 | 109 | void encryptBlock(void* ptr, uint32_t size, uint32_t key); 110 | void decryptBlock(void* ptr, uint32_t size, uint32_t key); 111 | 112 | uint32_t detectTableSeed(uint32_t* blocks, uint32_t offset, uint32_t maxSize); 113 | uint32_t detectFileSeed(uint32_t* data, uint32_t size); 114 | 115 | bool validateHash(void const* buf, uint32_t size, void const* expected); 116 | bool validateHash(File file, void const* expected); 117 | 118 | #define ID_WAVE 0x46464952 119 | bool pkzip_compress(void* in, uint32_t in_size, void* out, uint32_t* out_size); 120 | bool pkzip_decompress(void* in, uint32_t in_size, void* out, uint32_t* out_size); 121 | bool multi_compress(void* in, uint32_t in_size, void* out, uint32_t* out_size, uint8_t mask, void* temp); 122 | bool multi_decompress(void* in, uint32_t in_size, void* out, uint32_t* out_size, void* temp = nullptr); 123 | 124 | const char* path_name(const char* path); 125 | const char* path_ext(const char* path); 126 | 127 | } 128 | -------------------------------------------------------------------------------- /Source/appfat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef EMSCRIPTEN 4 | #include 5 | #include "diablo.h" 6 | 7 | EM_JS( void, exit_error, (const char* err), { 8 | var end = HEAPU8.indexOf( 0, err ); 9 | var text = String.fromCharCode.apply(null, HEAPU8.subarray( err, end )); 10 | self.DApi.exit_error( text ); 11 | }); 12 | EM_JS( void, show_alert, ( const char* err ), { 13 | var end = HEAPU8.indexOf( 0, err ); 14 | var text = String.fromCharCode.apply( null, HEAPU8.subarray( err, end ) ); 15 | self.alert( text ); 16 | }); 17 | 18 | void api_exit_error(const char* err) { 19 | exit_error(err); 20 | exit(1); 21 | } 22 | 23 | void api_show_alert(const char* err) { 24 | show_alert(err); 25 | } 26 | 27 | #else 28 | #include 29 | void api_exit_error(const char* err) { 30 | if (err) { 31 | ShowCursor(TRUE); 32 | MessageBox(NULL, err, "ERROR", MB_TASKMODAL | MB_ICONHAND); 33 | } 34 | __debugbreak(); 35 | exit(1); 36 | } 37 | void api_show_alert(const char* err) { 38 | ShowCursor(TRUE); 39 | MessageBox(NULL, err, "Diablo", MB_TASKMODAL | MB_ICONEXCLAMATION); 40 | } 41 | #endif 42 | 43 | #include "appfat.h" 44 | 45 | char sz_error_buf[256]; 46 | BOOL terminating; 47 | int cleanup_thread_id; 48 | 49 | void TriggerBreak() 50 | { 51 | #ifdef _DEBUG 52 | //__debugbreak(); 53 | #endif 54 | } 55 | 56 | char *GetErrorStr( DWORD error_code ) 57 | { 58 | sprintf( sz_error_buf, "unknown error 0x%08x", (int) error_code ); 59 | return sz_error_buf; 60 | } 61 | 62 | char *TraceLastError() 63 | { 64 | return GetErrorStr( 0 ); 65 | } 66 | 67 | void __cdecl app_fatal( const char *pszFmt, ... ) 68 | { 69 | va_list va; 70 | 71 | va_start( va, pszFmt ); 72 | #ifdef _DEBUG 73 | TriggerBreak(); 74 | #endif 75 | 76 | if ( pszFmt ) 77 | { 78 | char Text[256]; 79 | vsprintf( Text, pszFmt, va ); 80 | va_end( va ); 81 | api_exit_error( Text ); 82 | } 83 | else 84 | { 85 | va_end( va ); 86 | api_exit_error( NULL ); 87 | } 88 | } 89 | 90 | void __cdecl DrawDlg( const char *pszFmt, ... ) 91 | { 92 | char text[256]; 93 | va_list arglist; 94 | 95 | va_start( arglist, pszFmt ); 96 | vsprintf( text, pszFmt, arglist ); 97 | va_end( arglist ); 98 | 99 | api_show_alert( text ); 100 | } 101 | 102 | #ifdef _DEBUG 103 | void assert_fail( int nLineNo, const char *pszFile, const char *pszFail ) 104 | { 105 | app_fatal( "assertion failed (%d:%s)\n%s", nLineNo, pszFile, pszFail ); 106 | } 107 | #endif 108 | 109 | void ErrDlg(int template_id, DWORD error_code, const char *log_file_path, int log_line_nr) { 110 | app_fatal("%s\nat: %s line %d", GetErrorStr(error_code), log_file_path, log_line_nr); 111 | } 112 | void ErrMsg(const char* text, const char *log_file_path, int log_line_nr) { 113 | app_fatal("%s\nat: %s line %d", text, log_file_path, log_line_nr); 114 | } 115 | 116 | void TextDlg( HWND hDlg, char *text ) 117 | { 118 | api_show_alert( text ); 119 | } 120 | 121 | void ErrOkDlg( int template_id, DWORD error_code, const char *log_file_path, int log_line_nr ) 122 | { 123 | char text[256]; 124 | sprintf( text, "%s\nat: %s line %d", GetErrorStr( error_code ), log_file_path, log_line_nr ); 125 | api_show_alert( text ); 126 | } 127 | 128 | void FileErrDlg( const char *error ) 129 | { 130 | app_fatal( "%s", error ); 131 | } 132 | 133 | void DiskFreeDlg(const char *error ) 134 | { 135 | app_fatal( "%s", error ); 136 | } 137 | 138 | BOOL InsertCDDlg() 139 | { 140 | return TRUE; 141 | } 142 | 143 | void DirErrorDlg( char *error ) 144 | { 145 | app_fatal( "%s", error ); 146 | } 147 | -------------------------------------------------------------------------------- /Source/plrmsg.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | 3 | static BYTE plr_msg_slot; 4 | _plrmsg plr_msgs[PMSG_COUNT]; 5 | 6 | const char text_color_from_player_num[MAX_PLRS + 1] = { COL_WHITE, COL_WHITE, COL_WHITE, COL_WHITE, COL_GOLD }; 7 | 8 | void plrmsg_delay(BOOL delay) 9 | { 10 | int i; 11 | _plrmsg *pMsg; 12 | static DWORD plrmsg_ticks; 13 | 14 | if (delay) { 15 | plrmsg_ticks = -_GetTickCount(); 16 | return; 17 | } 18 | 19 | plrmsg_ticks += _GetTickCount(); 20 | pMsg = plr_msgs; 21 | for (i = 0; i < PMSG_COUNT; i++, pMsg++) 22 | pMsg->time += plrmsg_ticks; 23 | } 24 | 25 | char *ErrorPlrMsg(const char *pszMsg) 26 | { 27 | char *result; 28 | _plrmsg *pMsg = &plr_msgs[plr_msg_slot]; 29 | plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1); 30 | pMsg->player = MAX_PLRS; 31 | pMsg->time = _GetTickCount(); 32 | result = strncpy(pMsg->str, pszMsg, sizeof(pMsg->str)); 33 | pMsg->str[sizeof(pMsg->str) - 1] = '\0'; 34 | return result; 35 | } 36 | 37 | size_t __cdecl EventPlrMsg(const char *pszFmt, ...) 38 | { 39 | _plrmsg *pMsg; 40 | va_list va; 41 | 42 | va_start(va, pszFmt); 43 | pMsg = &plr_msgs[plr_msg_slot]; 44 | plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1); 45 | pMsg->player = MAX_PLRS; 46 | pMsg->time = _GetTickCount(); 47 | vsprintf(pMsg->str, pszFmt, va); 48 | va_end(va); 49 | return strlen(pMsg->str); 50 | } 51 | 52 | void SendPlrMsg(int pnum, const char *pszStr) 53 | { 54 | _plrmsg *pMsg = &plr_msgs[plr_msg_slot]; 55 | plr_msg_slot = (plr_msg_slot + 1) & (PMSG_COUNT - 1); 56 | pMsg->player = pnum; 57 | pMsg->time = _GetTickCount(); 58 | strlen(plr[pnum]._pName); /* these are used in debug */ 59 | strlen(pszStr); 60 | sprintf(pMsg->str, "%s (lvl %d): %s", plr[pnum]._pName, plr[pnum]._pLevel, pszStr); 61 | } 62 | 63 | void ClearPlrMsg() 64 | { 65 | int i; 66 | _plrmsg *pMsg = plr_msgs; 67 | DWORD tick = _GetTickCount(); 68 | 69 | for (i = 0; i < PMSG_COUNT; i++, pMsg++) { 70 | if ((int)(tick - pMsg->time) > 10000) 71 | pMsg->str[0] = '\0'; 72 | } 73 | } 74 | 75 | void InitPlrMsg() 76 | { 77 | memset(plr_msgs, 0, sizeof(plr_msgs)); 78 | plr_msg_slot = 0; 79 | } 80 | 81 | void DrawPlrMsg() 82 | { 83 | int i; 84 | DWORD x = 74; 85 | DWORD y = 230; 86 | DWORD width = 620; 87 | _plrmsg *pMsg; 88 | 89 | if (chrflag || questlog) { 90 | if (invflag || sbookflag) 91 | return; 92 | x = 394; 93 | width = 300; 94 | } else if (invflag || sbookflag) 95 | width = 300; 96 | 97 | pMsg = plr_msgs; 98 | for (i = 0; i < 8; i++) { 99 | if (pMsg->str[0]) 100 | PrintPlrMsg(x, y, width, pMsg->str, text_color_from_player_num[pMsg->player]); 101 | pMsg++; 102 | y += 35; 103 | } 104 | } 105 | 106 | void PrintPlrMsg(DWORD x, DWORD y, DWORD width, const char *str, BYTE col) 107 | { 108 | int line = 0; 109 | 110 | while (*str) { 111 | BYTE c; 112 | int screen = PitchTbl[y] + x; 113 | const char *sstr = str; 114 | DWORD len = 0; 115 | const char *endstr = sstr; 116 | 117 | while (1) { 118 | if (*sstr) { 119 | c = gbFontTransTbl[(BYTE)*sstr++]; 120 | c = fontframe[c]; 121 | len += fontkern[c] + 1; 122 | if (!c) // allow wordwrap on blank glyph 123 | endstr = sstr; 124 | else if (len >= width) 125 | break; 126 | } else { 127 | endstr = sstr; 128 | break; 129 | } 130 | } 131 | 132 | while (str < endstr) { 133 | c = gbFontTransTbl[(BYTE)*str++]; 134 | c = fontframe[c]; 135 | if (c) 136 | CPrintString(screen, c, col); 137 | screen += fontkern[c] + 1; 138 | } 139 | 140 | y += 10; 141 | line++; 142 | if (line == 3) 143 | break; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Source/codec.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | 3 | namespace { 4 | 5 | static unsigned int __seed = 0; 6 | void _srand(unsigned int seed) { 7 | __seed = seed; 8 | } 9 | int _rand() { 10 | return int((__seed = __seed * 214013L + 2531011L) >> 16) & 0x7FFF; 11 | } 12 | 13 | } 14 | 15 | struct CodecSignature { 16 | DWORD checksum; 17 | BYTE error; 18 | BYTE last_chunk_size; 19 | WORD unused; 20 | }; 21 | 22 | int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword) 23 | { 24 | char buf[128]; 25 | char dst[SHA1HashSize]; 26 | int i; 27 | CodecSignature *sig; 28 | 29 | codec_init_key(0, pszPassword); 30 | if (size <= 8) 31 | return 0; 32 | size = size - 8; 33 | if (size % 64 != 0) 34 | return 0; 35 | for (i = size; i != 0; pbSrcDst += 64, i -= 64) { 36 | memcpy(buf, pbSrcDst, 64); 37 | SHA1Result(0, dst); 38 | for (int j = 0; j < 64; j++) { 39 | buf[j] ^= dst[j % SHA1HashSize]; 40 | } 41 | SHA1Calculate(0, buf, NULL); 42 | memset(dst, 0, sizeof(dst)); 43 | memcpy(pbSrcDst, buf, 64); 44 | } 45 | 46 | memset(buf, 0, sizeof(buf)); 47 | sig = (CodecSignature *)pbSrcDst; 48 | if (sig->error > 0) { 49 | size = 0; 50 | SHA1Clear(); 51 | } else { 52 | SHA1Result(0, dst); 53 | if (sig->checksum != *(DWORD *)dst) { 54 | memset(dst, 0, sizeof(dst)); 55 | size = 0; 56 | SHA1Clear(); 57 | } else { 58 | size += sig->last_chunk_size - 64; 59 | SHA1Clear(); 60 | } 61 | } 62 | return size; 63 | } 64 | 65 | void codec_init_key(int unused, char *pszPassword) 66 | { 67 | int i, ch, n; 68 | char key[136]; // last 64 bytes are the SHA1 69 | char pw[64]; 70 | char digest[SHA1HashSize]; 71 | char *keyInit; 72 | 73 | _srand(0x7058); 74 | 75 | keyInit = key; 76 | for (i = 0; i < 136; i++) { 77 | *keyInit = _rand(); 78 | keyInit++; 79 | } 80 | ch = 0; 81 | for (i = 0; i < 64; i++) { 82 | if (!pszPassword[ch]) 83 | ch = 0; 84 | pw[i] = pszPassword[ch]; 85 | ch++; 86 | } 87 | SHA1Reset(0); 88 | SHA1Calculate(0, pw, digest); 89 | SHA1Clear(); 90 | for (i = 0; (DWORD)i < 136; i++) 91 | key[i] ^= digest[i % SHA1HashSize]; 92 | memset(pw, 0, sizeof(pw)); 93 | memset(digest, 0, sizeof(digest)); 94 | for (n = 0; n < 3; n++) { 95 | SHA1Reset(n); 96 | SHA1Calculate(n, &key[72], NULL); 97 | } 98 | memset(key, 0, sizeof(key)); 99 | } 100 | 101 | DWORD codec_get_encoded_len(DWORD dwSrcBytes) 102 | { 103 | if (dwSrcBytes % 64 != 0) 104 | dwSrcBytes += 64 - (dwSrcBytes % 64); 105 | return dwSrcBytes + 8; 106 | } 107 | 108 | void codec_encode(BYTE *pbSrcDst, DWORD size, int size_64, char *pszPassword) 109 | { 110 | char buf[128]; 111 | char tmp[SHA1HashSize]; 112 | char dst[SHA1HashSize]; 113 | DWORD chunk; 114 | WORD last_chunk; 115 | CodecSignature *sig; 116 | 117 | if (size_64 != codec_get_encoded_len(size)) 118 | app_fatal("Invalid encode parameters"); 119 | codec_init_key(1, pszPassword); 120 | 121 | last_chunk = 0; 122 | while (size != 0) { 123 | chunk = size < 64 ? size : 64; 124 | memcpy(buf, pbSrcDst, chunk); 125 | if (chunk < 64) 126 | memset(buf + chunk, 0, 64 - chunk); 127 | SHA1Result(0, dst); 128 | SHA1Calculate(0, buf, NULL); 129 | for (int j = 0; j < 64; j++) { 130 | buf[j] ^= dst[j % SHA1HashSize]; 131 | } 132 | memset(dst, 0, sizeof(dst)); 133 | memcpy(pbSrcDst, buf, 64); 134 | last_chunk = chunk; 135 | pbSrcDst += 64; 136 | size -= chunk; 137 | } 138 | memset(buf, 0, sizeof(buf)); 139 | SHA1Result(0, tmp); 140 | sig = (CodecSignature *)pbSrcDst; 141 | sig->error = 0; 142 | sig->unused = 0; 143 | sig->checksum = *(DWORD *)tmp; 144 | sig->last_chunk_size = last_chunk; 145 | SHA1Clear(); 146 | } 147 | -------------------------------------------------------------------------------- /Source/ui/event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #undef XBUTTON1 4 | #undef XBUTTON2 5 | #undef DELETE 6 | 7 | namespace KeyCode { 8 | enum { 9 | LBUTTON = 0x01, 10 | RBUTTON = 0x02, 11 | CANCEL = 0x03, 12 | MBUTTON = 0x04, 13 | XBUTTON1 = 0x05, 14 | XBUTTON2 = 0x06, 15 | 16 | BACK = 0x08, 17 | TAB = 0x09, 18 | 19 | CLEAR = 0x0C, 20 | RETURN = 0x0D, 21 | 22 | SHIFT = 0x10, 23 | CONTROL = 0x11, 24 | MENU = 0x12, 25 | PAUSE = 0x13, 26 | CAPITAL = 0x14, 27 | KANA = 0x15, 28 | HANGUEL = 0x15, 29 | HANGUL = 0x15, 30 | 31 | JUNJA = 0x17, 32 | FINAL = 0x18, 33 | HANJA = 0x19, 34 | KANJI = 0x19, 35 | 36 | ESCAPE = 0x1B, 37 | CONVERT = 0x1C, 38 | NONCONVERT = 0x1D, 39 | ACCEPT = 0x1E, 40 | MODECHANGE = 0x1F, 41 | SPACE = 0x20, 42 | PRIOR = 0x21, 43 | NEXT = 0x22, 44 | END = 0x23, 45 | HOME = 0x24, 46 | LEFT = 0x25, 47 | UP = 0x26, 48 | RIGHT = 0x27, 49 | DOWN = 0x28, 50 | SELECT = 0x29, 51 | PRINT = 0x2A, 52 | EXECUTE = 0x2B, 53 | SNAPSHOT = 0x2C, 54 | INSERT = 0x2D, 55 | DELETE = 0x2E, 56 | HELP = 0x2F, 57 | 58 | LWIN = 0x5B, 59 | RWIN = 0x5C, 60 | APPS = 0x5D, 61 | 62 | SLEEP = 0x5F, 63 | NUMPAD0 = 0x60, 64 | NUMPAD1 = 0x61, 65 | NUMPAD2 = 0x62, 66 | NUMPAD3 = 0x63, 67 | NUMPAD4 = 0x64, 68 | NUMPAD5 = 0x65, 69 | NUMPAD6 = 0x66, 70 | NUMPAD7 = 0x67, 71 | NUMPAD8 = 0x68, 72 | NUMPAD9 = 0x69, 73 | MULTIPLY = 0x6A, 74 | ADD = 0x6B, 75 | SEPARATOR = 0x6C, 76 | SUBTRACT = 0x6D, 77 | DECIMAL = 0x6E, 78 | DIVIDE = 0x6F, 79 | F1 = 0x70, 80 | F2 = 0x71, 81 | F3 = 0x72, 82 | F4 = 0x73, 83 | F5 = 0x74, 84 | F6 = 0x75, 85 | F7 = 0x76, 86 | F8 = 0x77, 87 | F9 = 0x78, 88 | F10 = 0x79, 89 | F11 = 0x7A, 90 | F12 = 0x7B, 91 | F13 = 0x7C, 92 | F14 = 0x7D, 93 | F15 = 0x7E, 94 | F16 = 0x7F, 95 | F17 = 0x80, 96 | F18 = 0x81, 97 | F19 = 0x82, 98 | F20 = 0x83, 99 | F21 = 0x84, 100 | F22 = 0x85, 101 | F23 = 0x86, 102 | F24 = 0x87, 103 | 104 | NUMLOCK = 0x90, 105 | SCROLL = 0x91, 106 | 107 | LSHIFT = 0xA0, 108 | RSHIFT = 0xA1, 109 | LCONTROL = 0xA2, 110 | RCONTROL = 0xA3, 111 | LMENU = 0xA4, 112 | RMENU = 0xA5, 113 | BROWSER_BACK = 0xA6, 114 | BROWSER_FORWARD = 0xA7, 115 | BROWSER_REFRESH = 0xA8, 116 | BROWSER_STOP = 0xA9, 117 | BROWSER_SEARCH = 0xAA, 118 | BROWSER_FAVORITES = 0xAB, 119 | BROWSER_HOME = 0xAC, 120 | VOLUME_MUTE = 0xAD, 121 | VOLUME_DOWN = 0xAE, 122 | VOLUME_UP = 0xAF, 123 | MEDIA_NEXT_TRACK = 0xB0, 124 | MEDIA_PREV_TRACK = 0xB1, 125 | MEDIA_STOP = 0xB2, 126 | MEDIA_PLAY_PAUSE = 0xB3, 127 | LAUNCH_MAIL = 0xB4, 128 | LAUNCH_MEDIA_SELECT = 0xB5, 129 | LAUNCH_APP1 = 0xB6, 130 | LAUNCH_APP2 = 0xB7, 131 | 132 | OEM_1 = 0xBA, 133 | OEM_PLUS = 0xBB, 134 | OEM_MINUS = 0xBC, 135 | OEM_PERIOD = 0xBD, 136 | OEM_2 = 0xBF, 137 | OEM_3 = 0xC0, 138 | 139 | OEM_4 = 0xDB, 140 | OEM_5 = 0xDC, 141 | OEM_6 = 0xDD, 142 | OEM_7 = 0xDE, 143 | OEM_8 = 0xDF, 144 | 145 | OEM_102 = 0xE2, 146 | 147 | PROCESSKEY = 0xE5, 148 | 149 | PACKET = 0xE7, 150 | 151 | ATTN = 0xF6, 152 | CRSEL = 0xF7, 153 | EXSEL = 0xF8, 154 | EREOF = 0xF9, 155 | PLAY = 0xFA, 156 | ZOOM = 0xFB, 157 | NONAME = 0xFC, 158 | PA1 = 0xFD, 159 | OEM_CLEAR = 0xFE, 160 | }; 161 | } 162 | 163 | namespace ModifierKey { 164 | enum { 165 | SHIFT = 0x01, 166 | CONTROL = 0x02, 167 | ALT = 0x04, 168 | TOUCH = 0x08, 169 | }; 170 | } 171 | 172 | struct MouseEvent { 173 | enum Action { 174 | Move, 175 | Press, 176 | Release, 177 | }; 178 | Action action; 179 | int button = 0; 180 | int modifiers = 0; 181 | int x; 182 | int y; 183 | }; 184 | 185 | struct KeyEvent { 186 | enum Action { 187 | Press, 188 | Release, 189 | }; 190 | Action action; 191 | int modifiers = 0; 192 | int key; 193 | }; 194 | -------------------------------------------------------------------------------- /Source/net/websocket.cpp: -------------------------------------------------------------------------------- 1 | #ifndef EMSCRIPTEN 2 | #include "websocket_native.hpp" 3 | #else 4 | #include "websocket_browser.hpp" 5 | #endif 6 | 7 | #include "websocket.h" 8 | #include "../ui/network.h" 9 | #include "../trace.h" 10 | 11 | const uint32_t SERVER_VERSION = 1; 12 | 13 | namespace net { 14 | 15 | websocket_client::websocket_client() 16 | : impl_(std::make_unique()) 17 | { 18 | uint32_t version = gdwProductVersion; 19 | #ifdef SPAWN 20 | version |= 0x80000000; 21 | #endif 22 | impl_->send(client_info_packet(version)); 23 | } 24 | 25 | websocket_client::~websocket_client() = default; 26 | 27 | void websocket_client::create(std::string name, std::string passwd, uint32_t difficulty) { 28 | cookie_ = (uint32_t) time(nullptr); 29 | is_creator_ = true; 30 | impl_->send(client_create_game_packet(cookie_, name, passwd, (uint8_t) difficulty)); 31 | } 32 | 33 | void websocket_client::join(std::string name, std::string passwd) { 34 | cookie_ = (uint32_t) time(nullptr); 35 | is_creator_ = false; 36 | impl_->send(client_join_game_packet(cookie_, name, passwd)); 37 | } 38 | 39 | void websocket_client::poll() { 40 | impl_->receive([this](const uint8_t* data, size_t size) { 41 | handle_packet(data, size); 42 | }); 43 | if (!closed_ && impl_->is_closed()) { 44 | closed_ = true; 45 | NetworkState* net_state = dynamic_cast(GameState::current()); 46 | if (net_state) { 47 | net_state->onClosed(); 48 | } 49 | } 50 | } 51 | 52 | void websocket_client::send(const packet& pkt) { 53 | impl_->send(pkt); 54 | } 55 | 56 | void websocket_client::handle_packet(const uint8_t* data, size_t size) { 57 | try { 58 | buffer_reader reader(data, size); 59 | NetworkState* net_state = dynamic_cast(GameState::current()); 60 | int count = 1; 61 | if (data[0] == 0) { 62 | reader.read(); 63 | count = reader.read(); 64 | } 65 | while (count--) { 66 | PacketType type = reader.read(); 67 | switch (type) { 68 | case PT_SERVER_INFO: { 69 | server_info_packet packet(reader); 70 | if (packet.version != SERVER_VERSION) { 71 | app_fatal("Server version mismatch. Expected %u, received %u.", SERVER_VERSION, packet.version); 72 | } 73 | break; 74 | } 75 | case PT_GAME_LIST: { 76 | server_game_list_packet packet(reader); 77 | break; 78 | } 79 | case PT_JOIN_ACCEPT: { 80 | server_join_accept_packet packet(reader); 81 | if (packet.cookie == cookie_ && net_state) { 82 | // handle first, so we read the init info 83 | handle(packet); 84 | net_state->onJoinAccept(packet.index, packet.init_info); 85 | } else { 86 | // tell the server we don't want this game anymore 87 | send(client_leave_game_packet()); 88 | } 89 | break; 90 | } 91 | case PT_JOIN_REJECT: { 92 | server_join_reject_packet packet(reader); 93 | if (packet.cookie == cookie_ && net_state) { 94 | net_state->onJoinReject(packet.reason); 95 | } 96 | break; 97 | } 98 | case PT_CONNECT: 99 | handle(server_connect_packet(reader)); 100 | break; 101 | case PT_DISCONNECT: 102 | handle(server_disconnect_packet(reader)); 103 | break; 104 | case PT_MESSAGE: 105 | handle(server_message_packet(reader)); 106 | break; 107 | case PT_TURN: 108 | handle(server_turn_packet(reader)); 109 | break; 110 | default: 111 | app_fatal("Unrecognized server message type %d", (int) type); 112 | } 113 | } 114 | if (!reader.done()) { 115 | app_fatal("Invalid server message size"); 116 | } 117 | } catch (parse_error) { 118 | app_fatal("Error parsing server message"); 119 | } 120 | } 121 | 122 | } // namespace net 123 | -------------------------------------------------------------------------------- /Source/encrypt.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | #include "storm/storm.h" 3 | #include "rmpq/pklib/pklib.h" 4 | 5 | DWORD hashtable[1280]; 6 | 7 | void Decrypt(void *block, DWORD size, DWORD key) 8 | { 9 | DWORD *castBlock; 10 | DWORD seed, i; 11 | 12 | castBlock = (DWORD *)block; 13 | seed = 0xEEEEEEEE; 14 | for (i = 0; i < (size >> 2); i++) { 15 | seed += hashtable[0x400 + (key & 0xFF)]; 16 | *castBlock ^= seed + key; 17 | seed += *castBlock + (seed << 5) + 3; 18 | key = ((~key << 0x15) + 0x11111111) | (key >> 0x0B); 19 | castBlock++; 20 | } 21 | } 22 | 23 | void Encrypt(void *block, DWORD size, DWORD key) 24 | { 25 | DWORD *castBlock; 26 | DWORD seed, i, ch; 27 | 28 | castBlock = (DWORD *)block; 29 | seed = 0xEEEEEEEE; 30 | for (i = 0; i < (size >> 2); i++) { 31 | ch = *castBlock; 32 | seed += hashtable[0x400 + (key & 0xFF)]; 33 | *castBlock ^= seed + key; 34 | seed += ch + (seed << 5) + 3; 35 | key = ((~key << 0x15) + 0x11111111) | (key >> 0x0B); 36 | castBlock++; 37 | } 38 | } 39 | 40 | DWORD Hash(const char *s, int type) 41 | { 42 | char ch; 43 | DWORD seed1, seed2; 44 | 45 | seed1 = 0x7FED7FED; 46 | seed2 = 0xEEEEEEEE; 47 | while (s != NULL && *s) { 48 | ch = *s++; 49 | ch = toupper(ch); 50 | seed1 = hashtable[(type << 8) + ch] ^ (seed1 + seed2); 51 | seed2 += ch + seed1 + (seed2 << 5) + 3; 52 | } 53 | return seed1; 54 | } 55 | 56 | void InitHash() 57 | { 58 | DWORD seed, ch; 59 | int i, j; 60 | 61 | seed = 0x00100001; 62 | 63 | for (i = 0; i < 256; i++) { 64 | for (j = 0; j < 5; j++) { 65 | seed = (125 * seed + 3) % 0x2AAAAB; 66 | ch = (seed & 0xFFFF); 67 | seed = (125 * seed + 3) % 0x2AAAAB; 68 | hashtable[i + j * 256] = ch << 16 | (seed & 0xFFFF); 69 | } 70 | } 71 | } 72 | 73 | int PkwareCompress(void *buf, int size) 74 | { 75 | BYTE *srcData, *destData; 76 | char *ptr; 77 | unsigned int destSize, type, dsize; 78 | TDataInfo param; 79 | 80 | srcData = (BYTE *)buf; 81 | ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE); 82 | 83 | destSize = 2 * size; 84 | if (destSize < 8192) 85 | destSize = 8192; 86 | 87 | destData = (BYTE *)DiabloAllocPtr(destSize); 88 | 89 | param.srcData = srcData; 90 | param.srcOffset = 0; 91 | param.destData = destData; 92 | param.destOffset = 0; 93 | param.size = size; 94 | 95 | type = 0; 96 | dsize = 4096; 97 | implode(PkwareBufferRead, PkwareBufferWrite, ptr, ¶m, &type, &dsize); 98 | 99 | if (param.destOffset < size) { 100 | memcpy(srcData, destData, param.destOffset); 101 | size = param.destOffset; 102 | } 103 | 104 | mem_free_dbg(ptr); 105 | mem_free_dbg(destData); 106 | 107 | return size; 108 | } 109 | 110 | unsigned int __cdecl PkwareBufferRead(char *buf, unsigned int *size, void *param) 111 | { 112 | TDataInfo *pInfo; 113 | DWORD sSize; 114 | 115 | pInfo = (TDataInfo *)param; 116 | 117 | if (*size >= pInfo->size - pInfo->srcOffset) { 118 | sSize = pInfo->size - pInfo->srcOffset; 119 | } else { 120 | sSize = *size; 121 | } 122 | 123 | memcpy(buf, pInfo->srcData + pInfo->srcOffset, sSize); 124 | pInfo->srcOffset += sSize; 125 | 126 | return sSize; 127 | } 128 | 129 | void __cdecl PkwareBufferWrite(char *buf, unsigned int *size, void *param) 130 | { 131 | TDataInfo *pInfo; 132 | 133 | pInfo = (TDataInfo *)param; 134 | 135 | memcpy(pInfo->destData + pInfo->destOffset, buf, *size); 136 | pInfo->destOffset += *size; 137 | } 138 | 139 | void PkwareDecompress(void *param, int recv_size, int dwMaxBytes) 140 | { 141 | char *ptr; 142 | BYTE *pbInBuff, *pbOutBuff; 143 | TDataInfo info; 144 | 145 | ptr = (char *)DiabloAllocPtr(CMP_BUFFER_SIZE); 146 | pbInBuff = (BYTE *)param; 147 | pbOutBuff = DiabloAllocPtr(dwMaxBytes); 148 | 149 | info.srcData = pbInBuff; 150 | info.srcOffset = 0; 151 | info.destData = pbOutBuff; 152 | info.destOffset = 0; 153 | info.size = recv_size; 154 | 155 | explode(PkwareBufferRead, PkwareBufferWrite, ptr, &info); 156 | memcpy(pbInBuff, pbOutBuff, info.destOffset); 157 | mem_free_dbg(ptr); 158 | mem_free_dbg(pbOutBuff); 159 | } 160 | -------------------------------------------------------------------------------- /Source/stores.h: -------------------------------------------------------------------------------- 1 | //HEADER_GOES_HERE 2 | #ifndef __STORES_H__ 3 | #define __STORES_H__ 4 | 5 | extern int stextup; 6 | extern int storenumh; 7 | extern int stextlhold; 8 | extern ItemStruct boyitem; 9 | extern int stextshold; 10 | extern ItemStruct premiumitem[6]; 11 | extern BYTE *pSTextBoxCels; 12 | extern int premiumlevel; 13 | extern int talker; 14 | extern STextStruct stext[24]; 15 | extern char stextsize; 16 | extern int stextsmax; 17 | extern int InStoreFlag; 18 | extern ItemStruct storehold[48]; 19 | extern int gossipstart; 20 | extern ItemStruct witchitem[20]; 21 | extern BOOL stextscrl; 22 | extern int numpremium; 23 | extern ItemStruct healitem[20]; 24 | extern ItemStruct golditem; 25 | extern char storehidx[48]; 26 | extern BYTE *pSTextSlidCels; 27 | extern int stextvhold; 28 | extern int stextsel; 29 | extern char stextscrldbtn; 30 | extern int gossipend; 31 | extern BYTE *pSPentSpn2Cels; 32 | extern int stextsval; 33 | extern int boylevel; 34 | extern ItemStruct smithitem[20]; 35 | extern int stextdown; 36 | extern char stextscrlubtn; 37 | extern char stextflag; 38 | 39 | void InitStores(); 40 | void SetupTownStores(); 41 | void FreeStoreMem(); 42 | void DrawSTextBack(); 43 | void PrintSString(int x, int y, BOOL cjustflag, const char *str, char col, int val); 44 | void DrawSLine(int y); 45 | void DrawSArrows(int y1, int y2); 46 | void DrawSTextHelp(); 47 | void ClearSText(int s, int e); 48 | void AddSLine(int y); 49 | void AddSTextVal(int y, int val); 50 | void OffsetSTextY(int y, int yo); 51 | void AddSText(int x, int y, int j, const char *str, char clr, int sel); 52 | void StoreAutoPlace(); 53 | void S_StartSmith(); 54 | void S_ScrollSBuy(int idx); 55 | void PrintStoreItem(ItemStruct *x, int l, char iclr); 56 | void S_StartSBuy(); 57 | void S_ScrollSPBuy(int idx); 58 | BOOL S_StartSPBuy(); 59 | BOOL SmithSellOk(int i); 60 | void S_ScrollSSell(int idx); 61 | void S_StartSSell(); 62 | BOOL SmithRepairOk(int i); 63 | void S_StartSRepair(); 64 | void AddStoreHoldRepair(ItemStruct *itm, int i); 65 | void S_StartWitch(); 66 | void S_ScrollWBuy(int idx); 67 | void S_StartWBuy(); 68 | BOOL WitchSellOk(int i); 69 | void S_StartWSell(); 70 | BOOL WitchRechargeOk(int i); 71 | void AddStoreHoldRecharge(ItemStruct itm, int i); 72 | void S_StartWRecharge(); 73 | void S_StartNoMoney(); 74 | void S_StartNoRoom(); 75 | void S_StartConfirm(); 76 | void S_StartBoy(); 77 | void S_StartBBoy(); 78 | void S_StartHealer(); 79 | void S_ScrollHBuy(int idx); 80 | void S_StartHBuy(); 81 | void S_StartStory(); 82 | BOOL IdItemOk(ItemStruct *i); 83 | void AddStoreHoldId(ItemStruct itm, int i); 84 | void S_StartSIdentify(); 85 | void S_StartIdShow(); 86 | void S_StartTalk(); 87 | void S_StartTavern(); 88 | void S_StartBarMaid(); 89 | void S_StartDrunk(); 90 | void StartStore(char s); 91 | void DrawSText(); 92 | void STextESC(); 93 | void STextUp(); 94 | void STextDown(); 95 | void STextPrior(); 96 | void STextNext(); 97 | void S_SmithEnter(); 98 | void SetGoldCurs(int pnum, int i); 99 | void SetSpdbarGoldCurs(int pnum, int i); 100 | void TakePlrsMoney(int cost); 101 | void SmithBuyItem(); 102 | void S_SBuyEnter(); 103 | void SmithBuyPItem(); 104 | void S_SPBuyEnter(); 105 | BOOL StoreGoldFit(int idx); 106 | void PlaceStoreGold(int v); 107 | void StoreSellItem(); 108 | void S_SSellEnter(); 109 | void SmithRepairItem(); 110 | void S_SRepairEnter(); 111 | void S_WitchEnter(); 112 | void WitchBuyItem(); 113 | void S_WBuyEnter(); 114 | void S_WSellEnter(); 115 | void WitchRechargeItem(); 116 | void S_WRechargeEnter(); 117 | void S_BoyEnter(); 118 | void BoyBuyItem(); 119 | void HealerBuyItem(); 120 | void S_BBuyEnter(); 121 | void StoryIdItem(); 122 | void S_ConfirmEnter(); 123 | void S_HealerEnter(); 124 | void S_HBuyEnter(); 125 | void S_StoryEnter(); 126 | void S_SIDEnter(); 127 | void S_TalkEnter(); 128 | void S_TavernEnter(); 129 | void S_BarmaidEnter(); 130 | void S_DrunkEnter(); 131 | void STextEnter(); 132 | void CheckStoreBtn(); 133 | void ReleaseStoreBtn(); 134 | 135 | /* rdata */ 136 | 137 | extern int SStringY[24]; 138 | extern const char *talkname[9]; 139 | 140 | #endif /* __STORES_H__ */ 141 | -------------------------------------------------------------------------------- /Source/storm/snet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "storm.h" 4 | #include "../net/abstract_net.h" 5 | 6 | static std::shared_ptr dvlnet_inst_single = net::abstract_net::make_net(net::provider_t::LOOPBACK, nullptr); 7 | static std::shared_ptr dvlnet_inst = dvlnet_inst_single; 8 | static std::shared_ptr dvlnet_inst_multi; 9 | 10 | BOOL SNetReceiveMessage(int *senderplayerid, char **data, int *databytes) { 11 | if (!dvlnet_inst->SNetReceiveMessage(senderplayerid, data, databytes)) { 12 | SErrSetLastError(STORM_ERROR_NO_MESSAGES_WAITING); 13 | return false; 14 | } 15 | return true; 16 | } 17 | 18 | BOOL SNetSendMessage(int playerID, void *data, unsigned int databytes) { 19 | return dvlnet_inst->SNetSendMessage(playerID, data, databytes); 20 | } 21 | 22 | BOOL SNetReceiveTurns(int a1, int arraysize, char **arraydata, DWORD *arraydatabytes, 23 | DWORD *arrayplayerstatus) { 24 | if (a1 != 0) 25 | ERROR_MSG("not implemented"); 26 | if (arraysize != MAX_PLRS) 27 | ERROR_MSG("not implemented"); 28 | if (!dvlnet_inst->SNetReceiveTurns(arraydata, arraydatabytes, arrayplayerstatus)) { 29 | SErrSetLastError(STORM_ERROR_NO_MESSAGES_WAITING); 30 | return false; 31 | } 32 | return true; 33 | } 34 | 35 | BOOL SNetSendTurn(char *data, unsigned int databytes) { 36 | return dvlnet_inst->SNetSendTurn(data, databytes); 37 | } 38 | 39 | int SNetGetProviderCaps(struct _SNETCAPS *caps) { 40 | return dvlnet_inst->SNetGetProviderCaps(caps); 41 | } 42 | 43 | BOOL SNetUnregisterEventHandler(int evtype, SEVTHANDLER func) { 44 | return dvlnet_inst->SNetUnregisterEventHandler(*(event_type *) &evtype, func); 45 | } 46 | 47 | BOOL SNetRegisterEventHandler(int evtype, SEVTHANDLER func) { 48 | return dvlnet_inst->SNetRegisterEventHandler(*(event_type *) &evtype, func); 49 | } 50 | 51 | BOOL SNetDestroy() { 52 | return true; 53 | } 54 | 55 | BOOL SNetDropPlayer(int playerid, DWORD flags) { 56 | return dvlnet_inst->SNetDropPlayer(playerid, flags); 57 | } 58 | 59 | BOOL SNetLeaveGame(int type) { 60 | return dvlnet_inst->SNetLeaveGame(type); 61 | } 62 | 63 | BOOL SNetSendServerChatCommand(const char *command) { 64 | return true; 65 | } 66 | 67 | BOOL SNetGetOwnerTurnsWaiting(DWORD *turns) { 68 | return dvlnet_inst->SNetGetOwnerTurnsWaiting(turns); 69 | } 70 | 71 | BOOL SNetGetTurnsInTransit(int *turns) { 72 | return dvlnet_inst->SNetGetTurnsInTransit(turns); 73 | } 74 | 75 | BOOL SNet_HasMultiplayer() { 76 | return dvlnet_inst_multi != nullptr; 77 | } 78 | 79 | void SNet_InitializeProvider(BOOL multiplayer) { 80 | if (multiplayer) { 81 | if (!dvlnet_inst_multi) { 82 | ERROR_MSG("multiplayer not initialized"); 83 | } else { 84 | dvlnet_inst = dvlnet_inst_multi; 85 | } 86 | } else { 87 | dvlnet_inst = dvlnet_inst_single; 88 | } 89 | } 90 | 91 | std::string _name = "", _pass = ""; 92 | 93 | void SNet_CreateGame(const char* name, const char* password, uint32_t difficulty) { 94 | _name = name; 95 | _pass = password; 96 | dvlnet_inst->create(name, password, difficulty); 97 | } 98 | 99 | void SNet_JoinGame(const char* name, const char* password) { 100 | _name = name; 101 | _pass = password; 102 | dvlnet_inst->join(name, password); 103 | } 104 | 105 | BOOL SNetGetGameInfo(int type, void *dst, unsigned int length, unsigned int *byteswritten) { 106 | if (type == GAMEINFO_NAME || type == GAMEINFO_PASSWORD) { 107 | std::string& src = (type == GAMEINFO_NAME ? _name : _pass); 108 | unsigned int count = src.size(); 109 | if (count > length - 1) { 110 | count = length - 1; 111 | } 112 | memcpy(dst, src.data(), count); 113 | ((char*) dst)[count] = 0; 114 | if (byteswritten) { 115 | *byteswritten = count; 116 | } 117 | return TRUE; 118 | } 119 | return FALSE; 120 | } 121 | 122 | void SNet_Poll() { 123 | dvlnet_inst->poll(); 124 | } 125 | 126 | #ifdef EMSCRIPTEN 127 | #include 128 | extern "C" { 129 | EMSCRIPTEN_KEEPALIVE 130 | #endif 131 | void SNet_InitWebsocket() { 132 | dvlnet_inst_multi = net::abstract_net::make_net(net::provider_t::WEBSOCKET, ""); 133 | } 134 | #ifdef EMSCRIPTEN 135 | } 136 | #endif 137 | -------------------------------------------------------------------------------- /Source/libsmacker/smacker.h: -------------------------------------------------------------------------------- 1 | /** 2 | libsmacker - A C library for decoding .smk Smacker Video files 3 | Copyright (C) 2012-2017 Greg Kennedy 4 | 5 | libsmacker is a cross-platform C library which can be used for 6 | decoding Smacker Video files produced by RAD Game Tools. 7 | 8 | This software is released under the following license: 9 | Creative Commons Attribution-NonCommercial 2.0 (CC BY-NC 2.0) 10 | 11 | You are free: 12 | * to Share - to copy, distribute and transmit the work 13 | * to Remix - to adapt the work 14 | 15 | Under the following conditions: 16 | 17 | * Attribution - You must attribute the work in the manner specified by 18 | the author or licensor (but not in any way that suggests that 19 | they endorse you or your use of the work). 20 | * Noncommercial - You may not use this work for commercial purposes. 21 | 22 | This is a human-readable summary of the Legal Code (the full license). 23 | 24 | You should have received a copy of the full license 25 | along with libsmacker. If not, see 26 | . 27 | */ 28 | 29 | #ifndef SMACKER_H 30 | #define SMACKER_H 31 | 32 | /* includes - needed for FILE* here */ 33 | #include 34 | 35 | /** forward-declaration for an struct */ 36 | typedef struct smk_t* smk; 37 | 38 | /** a few defines as return codes from smk_next() */ 39 | #define SMK_DONE 0x00 40 | #define SMK_MORE 0x01 41 | #define SMK_LAST 0x02 42 | #define SMK_ERROR -1 43 | 44 | /** file-processing mode, pass to smk_open_file */ 45 | #define SMK_MODE_DISK 0x00 46 | #define SMK_MODE_MEMORY 0x01 47 | 48 | /** Y-scale meanings */ 49 | #define SMK_FLAG_Y_NONE 0x00 50 | #define SMK_FLAG_Y_INTERLACE 0x01 51 | #define SMK_FLAG_Y_DOUBLE 0x02 52 | 53 | /** track mask and enable bits */ 54 | #define SMK_AUDIO_TRACK_0 0x01 55 | #define SMK_AUDIO_TRACK_1 0x02 56 | #define SMK_AUDIO_TRACK_2 0x04 57 | #define SMK_AUDIO_TRACK_3 0x08 58 | #define SMK_AUDIO_TRACK_4 0x10 59 | #define SMK_AUDIO_TRACK_5 0x20 60 | #define SMK_AUDIO_TRACK_6 0x40 61 | #define SMK_VIDEO_TRACK 0x80 62 | 63 | /* PUBLIC FUNCTIONS */ 64 | #ifdef __cplusplus 65 | extern "C" { 66 | #endif 67 | 68 | /* OPEN OPERATIONS */ 69 | /** open an smk (from a file) */ 70 | smk smk_open_file(const char *filename, const unsigned char mode); 71 | /** open an smk (from a file pointer) */ 72 | smk smk_open_filepointer(FILE* file, const unsigned char mode); 73 | /** read an smk (from a memory buffer) */ 74 | smk smk_open_memory(const unsigned char* buffer, const unsigned long size); 75 | 76 | /* CLOSE OPERATIONS */ 77 | /** close out an smk file and clean up memory */ 78 | void smk_close(smk object); 79 | 80 | /* GET FILE INFO OPERATIONS */ 81 | char smk_info_all(const smk object, unsigned long* frame, unsigned long* frame_count, double* usf); 82 | char smk_info_video(const smk object, unsigned long* w, unsigned long* h, unsigned char* y_scale_mode); 83 | char smk_info_audio(const smk object, unsigned char* track_mask, unsigned char channels[7], unsigned char bitdepth[7], unsigned long audio_rate[7]); 84 | 85 | /* ENABLE/DISABLE Switches */ 86 | char smk_enable_all(smk object, const unsigned char mask); 87 | char smk_enable_video(smk object, const unsigned char enable); 88 | char smk_enable_audio(smk object, const unsigned char track, const unsigned char enable); 89 | 90 | /** Retrieve palette */ 91 | const unsigned char* smk_get_palette(const smk object); 92 | /** Retrieve video frame, as a buffer of size w*h */ 93 | const unsigned char* smk_get_video(const smk object); 94 | /** Retrieve decoded audio chunk, track N */ 95 | const unsigned char *smk_get_audio(const smk object, const unsigned char track); 96 | /** Get size of currently pointed decoded audio chunk, track N */ 97 | unsigned long smk_get_audio_size(const smk object, const unsigned char track); 98 | 99 | /** rewind to first frame and unpack */ 100 | char smk_first(smk object); 101 | /** was the pallet updated this frame */ 102 | unsigned char smk_palette_updated(smk s); 103 | /** advance to next frame and unpack */ 104 | char smk_next(smk object); 105 | /** seek to first keyframe before/at N in an smk */ 106 | char smk_seek_keyframe(smk object, unsigned long frame); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /mpqcmp/shine/reservoir.c: -------------------------------------------------------------------------------- 1 | /* reservoir.c 2 | * Layer3 bit reservoir: Described in C.1.5.4.2.2 of the IS 3 | */ 4 | 5 | #include "types.h" 6 | #include "layer3.h" 7 | #include "l3loop.h" 8 | #include "huffman.h" 9 | #include "bitstream.h" 10 | #include "l3bitstream.h" 11 | #include "reservoir.h" 12 | 13 | /* 14 | * shine_max_reservoir_bits: 15 | * ------------ 16 | * Called at the beginning of each granule to get the max bit 17 | * allowance for the current granule based on reservoir size 18 | * and perceptual entropy. 19 | */ 20 | int shine_max_reservoir_bits (double *pe, shine_global_config *config ) 21 | { 22 | int more_bits, max_bits, add_bits, over_bits; 23 | int mean_bits = config->mean_bits; 24 | 25 | mean_bits /= config->wave.channels; 26 | max_bits = mean_bits; 27 | 28 | if(max_bits>4095) 29 | max_bits = 4095; 30 | if(!config->ResvMax) 31 | return max_bits; 32 | 33 | more_bits = *pe * 3.1 - mean_bits; 34 | add_bits = 0; 35 | if(more_bits>100) 36 | { 37 | int frac = (config->ResvSize * 6) / 10; 38 | 39 | if(fracResvSize - ((config->ResvMax <<3) / 10) - add_bits; 45 | if (over_bits>0) 46 | add_bits += over_bits; 47 | 48 | max_bits += add_bits; 49 | if(max_bits>4095) 50 | max_bits = 4095; 51 | return max_bits; 52 | } 53 | 54 | /* 55 | * shine_ResvAdjust: 56 | * ----------- 57 | * Called after a granule's bit allocation. Readjusts the size of 58 | * the reservoir to reflect the granule's usage. 59 | */ 60 | void shine_ResvAdjust(gr_info *gi, shine_global_config *config ) 61 | { 62 | config->ResvSize += (config->mean_bits / config->wave.channels) - gi->part2_3_length; 63 | } 64 | 65 | /* 66 | * shine_ResvFrameEnd: 67 | * ------------- 68 | * Called after all granules in a frame have been allocated. Makes sure 69 | * that the reservoir size is within limits, possibly by adding stuffing 70 | * bits. Note that stuffing bits are added by increasing a granule's 71 | * part2_3_length. The bitstream formatter will detect this and write the 72 | * appropriate stuffing bits to the bitstream. 73 | */ 74 | void shine_ResvFrameEnd(shine_global_config *config ) 75 | { 76 | gr_info *gi; 77 | int gr, ch, ancillary_pad, stuffingBits; 78 | int over_bits; 79 | shine_side_info_t *l3_side = &config->side_info; 80 | 81 | ancillary_pad = 0; 82 | 83 | /* just in case mean_bits is odd, this is necessary... */ 84 | if((config->wave.channels==2) && (config->mean_bits & 1)) 85 | config->ResvSize += 1; 86 | 87 | over_bits = config->ResvSize - config->ResvMax; 88 | if(over_bits<0) 89 | over_bits = 0; 90 | 91 | config->ResvSize -= over_bits; 92 | stuffingBits = over_bits + ancillary_pad; 93 | 94 | /* we must be byte aligned */ 95 | if((over_bits = config->ResvSize % 8)) 96 | { 97 | stuffingBits += over_bits; 98 | config->ResvSize -= over_bits; 99 | } 100 | 101 | if(stuffingBits) 102 | { 103 | /* 104 | * plan a: put all into the first granule 105 | * This was preferred by someone designing a 106 | * real-time decoder... 107 | */ 108 | gi = (gr_info *) &(l3_side->gr[0].ch[0]); 109 | 110 | if ( gi->part2_3_length + stuffingBits < 4095 ) 111 | gi->part2_3_length += stuffingBits; 112 | else 113 | { 114 | /* plan b: distribute throughout the granules */ 115 | for (gr = 0; gr < config->mpeg.granules_per_frame; gr++ ) 116 | for (ch = 0; ch < config->wave.channels; ch++ ) 117 | { 118 | int extraBits, bitsThisGr; 119 | gr_info *gi = (gr_info *) &(l3_side->gr[gr].ch[ch]); 120 | if (!stuffingBits) 121 | break; 122 | extraBits = 4095 - gi->part2_3_length; 123 | bitsThisGr = extraBits < stuffingBits ? extraBits : stuffingBits; 124 | gi->part2_3_length += bitsThisGr; 125 | stuffingBits -= bitsThisGr; 126 | } 127 | /* 128 | * If any stuffing bits remain, we elect to spill them 129 | * into ancillary data. The bitstream formatter will do this if 130 | * l3side->resvDrain is set 131 | */ 132 | l3_side->resvDrain = stuffingBits; 133 | } 134 | } 135 | } 136 | 137 | 138 | -------------------------------------------------------------------------------- /Source/portal.cpp: -------------------------------------------------------------------------------- 1 | #include "diablo.h" 2 | 3 | PortalStruct portal[MAXPORTAL]; 4 | int portalindex; 5 | 6 | int WarpDropX[MAXPORTAL] = { 57, 59, 61, 63 }; 7 | int WarpDropY[MAXPORTAL] = { 40, 40, 40, 40 }; 8 | 9 | void InitPortals() 10 | { 11 | int i; 12 | 13 | for (i = 0; i < MAXPORTAL; i++) { 14 | if (delta_portal_inited(i)) 15 | portal[i].open = FALSE; 16 | } 17 | } 18 | 19 | void SetPortalStats(int i, BOOL o, int x, int y, int lvl, int lvltype) 20 | { 21 | portal[i].setlvl = FALSE; 22 | portal[i].x = x; 23 | portal[i].y = y; 24 | portal[i].open = o; 25 | portal[i].level = lvl; 26 | portal[i].ltype = lvltype; 27 | } 28 | 29 | void AddWarpMissile(int i, int x, int y) 30 | { 31 | int mi; 32 | 33 | missiledata[MIS_TOWN].mlSFX = -1; 34 | dMissile[x][y] = 0; 35 | mi = AddMissile(0, 0, x, y, 0, MIS_TOWN, 0, i, 0, 0); 36 | 37 | if (mi != -1) { 38 | SetMissDir(mi, 1); 39 | 40 | if (currlevel != 0) 41 | missile[mi]._mlid = AddLight(missile[mi]._mix, missile[mi]._miy, 15); 42 | 43 | missiledata[MIS_TOWN].mlSFX = LS_SENTINEL; 44 | } 45 | } 46 | 47 | void SyncPortals() 48 | { 49 | int i; 50 | 51 | for (i = 0; i < MAXPORTAL; i++) { 52 | if (!portal[i].open) 53 | continue; 54 | if (currlevel == 0) 55 | AddWarpMissile(i, WarpDropX[i], WarpDropY[i]); 56 | else { 57 | int lvl = currlevel; 58 | if (setlevel) 59 | lvl = setlvlnum; 60 | if (portal[i].level == lvl) 61 | AddWarpMissile(i, portal[i].x, portal[i].y); 62 | } 63 | } 64 | } 65 | 66 | void AddInTownPortal(int i) 67 | { 68 | AddWarpMissile(i, WarpDropX[i], WarpDropY[i]); 69 | } 70 | 71 | void ActivatePortal(int i, int x, int y, int lvl, int lvltype, BOOL sp) 72 | { 73 | portal[i].open = TRUE; 74 | 75 | if (lvl != 0) { 76 | portal[i].x = x; 77 | portal[i].y = y; 78 | portal[i].level = lvl; 79 | portal[i].ltype = lvltype; 80 | portal[i].setlvl = sp; 81 | } 82 | } 83 | 84 | void DeactivatePortal(int i) 85 | { 86 | portal[i].open = FALSE; 87 | } 88 | 89 | BOOL PortalOnLevel(int i) 90 | { 91 | if (portal[i].level == currlevel) 92 | return TRUE; 93 | else 94 | return currlevel == 0; 95 | } 96 | 97 | void RemovePortalMissile(int id) 98 | { 99 | int i; 100 | int mi; 101 | 102 | for (i = 0; i < nummissiles; i++) { 103 | mi = missileactive[i]; 104 | if (missile[mi]._mitype == MIS_TOWN && missile[mi]._misource == id) { 105 | dFlags[missile[mi]._mix][missile[mi]._miy] &= ~BFLAG_MISSILE; 106 | dMissile[missile[mi]._mix][missile[mi]._miy] = 0; 107 | 108 | if (portal[id].level) 109 | AddUnLight(missile[mi]._mlid); 110 | 111 | DeleteMissile(mi, i); 112 | } 113 | } 114 | } 115 | 116 | void SetCurrentPortal(int p) 117 | { 118 | portalindex = p; 119 | } 120 | 121 | void GetPortalLevel() 122 | { 123 | if (currlevel) { 124 | setlevel = FALSE; 125 | currlevel = 0; 126 | plr[myplr].plrlevel = 0; 127 | leveltype = DTYPE_TOWN; 128 | } else { 129 | if (portal[portalindex].setlvl) { 130 | setlevel = TRUE; 131 | setlvlnum = portal[portalindex].level; 132 | currlevel = portal[portalindex].level; 133 | plr[myplr].plrlevel = setlvlnum; 134 | leveltype = portal[portalindex].ltype; 135 | } else { 136 | setlevel = FALSE; 137 | currlevel = portal[portalindex].level; 138 | plr[myplr].plrlevel = currlevel; 139 | leveltype = portal[portalindex].ltype; 140 | } 141 | if (portalindex == myplr) { 142 | NetSendCmd(TRUE, CMD_DEACTIVATEPORTAL); 143 | DeactivatePortal(portalindex); 144 | } 145 | } 146 | } 147 | 148 | void GetPortalLvlPos() 149 | { 150 | if (currlevel == 0) { 151 | ViewX = WarpDropX[portalindex] + 1; 152 | ViewY = WarpDropY[portalindex] + 1; 153 | } else { 154 | ViewX = portal[portalindex].x; 155 | ViewY = portal[portalindex].y; 156 | 157 | if (portalindex != myplr) { 158 | ViewX++; 159 | ViewY++; 160 | } 161 | } 162 | } 163 | 164 | BOOL PosOkPortal(int lvl, int x, int y) 165 | { 166 | int i; 167 | 168 | for (i = 0; i < MAXPORTAL; i++) { 169 | if (portal[i].open && portal[i].level == lvl && ((portal[i].x == x && portal[i].y == y) || (portal[i].x == x - 1 && portal[i].y == y - 1))) 170 | return TRUE; 171 | } 172 | return FALSE; 173 | } 174 | --------------------------------------------------------------------------------