Skip to content

Commit

Permalink
Merge pull request #58 from bayaraa/dev
Browse files Browse the repository at this point in the history
Dev to Master
  • Loading branch information
bayaraa authored Apr 29, 2023
2 parents 4b726bb + 32961f6 commit 5cdb983
Show file tree
Hide file tree
Showing 25 changed files with 335 additions and 156 deletions.
37 changes: 21 additions & 16 deletions d2gl/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,27 @@ void checkCompatibilityMode()
char msg[128] = { 0 };
sprintf_s(msg, "Please disable the '%s' compatibility mode for game executable and then try to start the game again.", str);
MessageBoxA(NULL, msg, "Compatibility mode detected!", MB_OK);
error_log("Compatibility mode '%s' detected!", str);
break;
}
str = strtok_s(NULL, " ", &context);
}
}
}

void checkDPIAwareness()
{
bool setDpiAware = SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
if (!setDpiAware) {
HRESULT result = SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
setDpiAware = result == S_OK || result == E_ACCESSDENIED;
}
if (!setDpiAware)
SetProcessDPIAware();
}

void dllAttach(HMODULE hmodule)
{
std::string command_line = GetCommandLineA();
helpers::strToLower(command_line);

if (command_line.find("-w ") != std::string::npos || command_line.find("-w") == command_line.length() - 2)
return;

if (command_line.find("d2vidtst") != std::string::npos) {
App.video_test = true;
return;
}

if (command_line.find("-w") != std::string::npos)
return;

bool flag_3dfx = command_line.find("-3dfx") != std::string::npos;
flag_3dfx = !flag_3dfx ? *d2::video_mode == 4 : flag_3dfx;

Expand All @@ -80,16 +70,31 @@ void dllAttach(HMODULE hmodule)

logInit();

auto ini_pos = command_line.find("-config ");
if (ini_pos != std::string::npos) {
std::string custom_ini = "";
for (size_t i = ini_pos + 8; i < command_line.length(); i++) {
if (command_line.at(i) == ' ')
break;
custom_ini += command_line.at(i);
}
custom_ini.erase(std::remove(custom_ini.begin(), custom_ini.end(), ' '), custom_ini.end());
if (custom_ini.length() > 0) {
App.ini_file = "d2gl_" + custom_ini + ".ini";
trace_log("Custom config file: %s", App.ini_file.c_str());
}
}

if (helpers::getVersion() == Version::Unknown) {
MessageBoxA(NULL, "Game version is not supported!", "Unsupported version!", MB_OK | MB_ICONERROR);
error_log("Game version is not supported!");
exit(1);
}
trace_log("Game version %s detected.", helpers::getVersionString().c_str());
trace_log("Diablo 2 LoD version %s detected.", helpers::getVersionString().c_str());

timeBeginPeriod(1);
checkCompatibilityMode();
checkDPIAwareness();
win32::setDPIAwareness();
App.hmodule = hmodule;

option::loadIni();
Expand Down
3 changes: 2 additions & 1 deletion d2gl/src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct D2GLApp {
glm::ivec2 offset = { 0, 0 };
glm::uvec2 size = { 800, 600 };
glm::vec2 scale = { 1.0f, 1.0f };
glm::bvec2 stretched = { false, false };
} viewport;

struct {
Expand All @@ -90,7 +91,7 @@ struct D2GLApp {
bool locked = false;
glm::vec2 scale = { 1.0f, 1.0f };
glm::vec2 unscale = { 1.0f, 1.0f };
bool no_lock = false;
bool unlock = false;
} cursor;

Select<glm::uvec2> resolutions = {};
Expand Down
6 changes: 6 additions & 0 deletions d2gl/src/d2/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ void initHooks()
no_intro.add(PatchType::Swap, getOffset((DLL_D2LAUNCH), (0x24F84), (0x27AD0), (0x1E288), (0x1E194), (0x1E2B8), (0x1E174), (0x1E36C), (0x2D4CFC)), 4, 0x00000000);
no_intro.toggle(App.skip_intro);

if (isVer(V_113d)) {
Patch multiple_instance = Patch();
multiple_instance.add(PatchType::Swap, getOffset((DLL_D2GFX), (), (), (), (), (), (), (0xB6B0), ()), 2, 0xEB450000);
multiple_instance.toggle(true);
}

Patch game_loop = Patch();
game_loop.add(PatchType::Call, getOffset((DLL_D2CLIENT), (0x9B3D, 0xE87A5F0B), (0xA2A2, 0xE8B51B0C), (0x89A2F, 0xE84A37F8), (0x3356F, 0xE85E9CFD), (0x7D1BF, 0xE84801F9), (0x44E2F, 0xE81A85FC), (0x45E7F, 0xE8E473FC), (0x4F256, 0xE8E5550C)), 5, (uintptr_t)gameDrawBeginStub);
game_loop.add(PatchType::Auto, getOffset((DLL_D2CLIENT, 0x5333DB3B), (0x865AC, 0x33ED894C), (0x81B7C, 0x33DB894C), (0xA35F6), (0x669F6), (0x90156), (0xC39E6), (0x1D3E6), (0x56EE1, 0x8BEC83EC)), isVerMax(V_110) ? 6 : 5, (uintptr_t)uiDrawBeginStub);
Expand Down
19 changes: 16 additions & 3 deletions d2gl/src/d2/funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ bool isUnitDead(UnitAny* unit)
return unit && (d2::getUnitFlag(unit) & 0x10000);
}

wchar_t* getPlayerName(UnitAny* unit)
{
return (wchar_t*)(isVer(V_109d) ? unit->v109.pPlayerData->szName : unit->v110.pPlayerData->szName);
}

MonsterType getMonsterType(UnitAny* unit)
{
if (isVer(V_109d)) {
Expand Down Expand Up @@ -137,6 +142,14 @@ ItemQuality getItemQuality(UnitAny* unit)
return isVer(V_109d) ? unit->v109.pItemData->dwQuality : unit->v110.pItemData->dwQuality;
}

bool isMercUnit(UnitAny* unit)
{
if (unit->dwType != d2::UnitType::Monster || isVer(V_109d))
return false;

return unit->v110.dwClassId == MERC_A1 || unit->v110.dwClassId == MERC_A2 || unit->v110.dwClassId == MERC_A3 || unit->v110.dwClassId == MERC_A4 || unit->v110.dwClassId == MERC_A5;
}

CellFile* getCellFile(CellContext* cell)
{
if (isVerMin(V_113c))
Expand Down Expand Up @@ -194,7 +207,7 @@ void __stdcall drawImageHooked(CellContext* cell, int x, int y, uint32_t gamma,
if (App.hd_cursor && App.game.draw_stage >= DrawStage::Cursor)
return;

if (modules::HDText::Instance().drawImage(cell, x, y, gamma, draw_mode)) {
if (modules::HDText::Instance().drawImage(cell, x, y, draw_mode)) {
const auto pos = modules::MotionPrediction::Instance().drawImage(x, y, D2DrawFn::Image, gamma, draw_mode);
drawImage(cell, pos.x, pos.y, gamma, draw_mode, palette);
}
Expand All @@ -208,7 +221,7 @@ void __stdcall drawPerspectiveImageHooked(CellContext* cell, int x, int y, uint3

void __stdcall drawShiftedImageHooked(CellContext* cell, int x, int y, uint32_t gamma, int draw_mode, int global_palette_shift)
{
if (modules::HDText::Instance().drawShiftedImage(cell, x, y, gamma, draw_mode)) {
if (modules::HDText::Instance().drawShiftedImage(cell, x, y)) {
auto pos = modules::MotionPrediction::Instance().drawImage(x, y, D2DrawFn::ShiftedImage);
drawShiftedImage(cell, pos.x, pos.y, gamma, draw_mode, global_palette_shift);
}
Expand Down Expand Up @@ -318,7 +331,7 @@ void __fastcall drawFramedTextHooked(const wchar_t* str, int x, int y, uint32_t
void __fastcall drawRectangledTextHooked(const wchar_t* str, int x, int y, uint32_t rect_color, uint32_t rect_transparency, uint32_t color)
{
const auto pos = modules::MotionPrediction::Instance().drawText(str, x, y, D2DrawFn::RectangledText);
if (!modules::HDText::Instance().drawRectangledText(str, pos.x, pos.y, rect_color, rect_transparency, color))
if (!modules::HDText::Instance().drawRectangledText(str, pos.x, pos.y, rect_transparency, color))
drawRectangledText(str, pos.x, pos.y, rect_color, rect_transparency, color);
}

Expand Down
5 changes: 5 additions & 0 deletions d2gl/src/d2/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ bool isEscMenuOpen();

UnitAny* getPlayerUnit();
UnitAny* findUnit(uint32_t type_id);

DWORD getUnitID(UnitAny* unit);
DWORD getUnitFlag(UnitAny* unit);
Path* getUnitPath(UnitAny* unit);
StaticPath* getUnitStaticPath(UnitAny* unit);
uint32_t getUnitStat(UnitAny* unit, uint32_t stat);
UnitAny* getSelectedItem();

bool isUnitDead(UnitAny* unit);
wchar_t* getPlayerName(UnitAny* unit);
MonsterType getMonsterType(UnitAny* unit);
wchar_t* getMonsterName(UnitAny* unit);

ItemQuality getItemQuality(UnitAny* unit);
bool isMercUnit(UnitAny* unit);

CellFile* getCellFile(CellContext* cell);
DWORD getCellNo(CellContext* cell);
Expand Down
14 changes: 12 additions & 2 deletions d2gl/src/d2/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ enum class UnitType {
Count,
};

#define MERC_A1 0x010f
#define MERC_A2 0x0152
#define MERC_A3 0x0167
#define MERC_A4 0x0420 // PD2
#define MERC_A5 0x0231

enum class ItemQuality {
None,
Inferior,
Expand Down Expand Up @@ -208,6 +214,10 @@ struct StaticPath {
DWORD dwFlags;
};

struct PlayerData {
char szName[16];
};

struct MonStatsTxt {
DWORD _1[19];
BYTE bAlign;
Expand Down Expand Up @@ -286,7 +296,7 @@ struct UnitAny {
DWORD dwUnitId;
DWORD dwMode;
union {
void* pPlayerData;
PlayerData* pPlayerData;
ItemData* pItemData;
MonsterData110* pMonsterData;
void* pObjectData;
Expand Down Expand Up @@ -327,7 +337,7 @@ struct UnitAny {
};
DWORD _3[13];
union {
void* pPlayerData;
PlayerData* pPlayerData;
ItemData* pItemData;
MonsterData109* pMonsterData;
void* pObjectData;
Expand Down
8 changes: 1 addition & 7 deletions d2gl/src/graphic/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ inline void CommandBuffer::next()
m_count++;
}

void CommandBuffer::pushCommand(CommandType type)
void CommandBuffer::pushCommand(CommandType type, uint32_t index)
{
m_command->type = type;
next();
}

void CommandBuffer::setBlendState(uint32_t index)
{
m_command->type = CommandType::SetBlendState;
m_command->index = index;
next();
}
Expand Down
9 changes: 4 additions & 5 deletions d2gl/src/graphic/command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct TexData {
struct TexUpdateQueue {
uint32_t count = 0;
uint32_t data_offset = 0;
std::array<TexData, 3072> tex_data = {};
std::array<TexData, 4096> tex_data = {};
};

enum class UBOType {
Expand All @@ -49,7 +49,7 @@ struct UBOData {

struct UBOUpdateQueue {
uint32_t count = 0;
std::array<UBOData, 8> data;
std::array<UBOData, 16> data;
};

struct GameTexUpdate {
Expand All @@ -66,7 +66,7 @@ struct HDTextMasking {
class CommandBuffer {
uint32_t m_count = 0;
Command* m_command = nullptr;
std::array<Command, 512> m_commands;
std::array<Command, 2048> m_commands;

UBOUpdateQueue m_ubo_update_queue;
TexUpdateQueue m_tex_update_queue;
Expand All @@ -92,8 +92,7 @@ class CommandBuffer {
void reset();
void next();

void pushCommand(CommandType type);
void setBlendState(uint32_t index);
void pushCommand(CommandType type, uint32_t index = 0);
void drawIndexed(uint32_t start, uint32_t count);
void resize();

Expand Down
Loading

0 comments on commit 5cdb983

Please sign in to comment.