Skip to content

Commit

Permalink
Merge pull request #15 from mir-diablo-ii-tools/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
IAmTrial authored Mar 23, 2021
2 parents 8486f96 + bd926c2 commit 504b021
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 102 deletions.
8 changes: 4 additions & 4 deletions SlashGaming-Diablo-II-Free-Resolution/resource/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ SLASH_ICON ICON "slashgaming_game_loader.ico"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,0,1,0
PRODUCTVERSION 3,0,1,0
FILEVERSION 3,0,1,1
PRODUCTVERSION 3,0,1,1
FILEFLAGSMASK 0x3fL // VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS 0x1L // VS_FF_DEBUG|VS_FF_PRIVATEBUILD|VS_FF_PRERELEASE
Expand All @@ -71,7 +71,7 @@ VS_VERSION_INFO VERSIONINFO
{
BLOCK "040904E4" // Lang=US English, CharSet=Windows Multilingual
{
VALUE "Build", "2021-03-21\0"
VALUE "Build", "2021-03-23\0"
VALUE "Comments", "Licensed under Affero GPL v3+.\0"
VALUE "CompanyName", "SlashGaming\0"
VALUE "Developer", "Mir Drualga\0"
Expand All @@ -81,7 +81,7 @@ VS_VERSION_INFO VERSIONINFO
VALUE "LegalTrademarks", "All rights reserved.\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "Diablo II Free Resolution\0"
VALUE "ProductVersion", "3.0.1.0\0"
VALUE "ProductVersion", "3.0.1.1\0"
VALUE "SpecialBuild", "\0"
VALUE "Support", "reddit.com/r/SlashDiablo\0"
} // BLOCK "040904E4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,26 @@
* alter software behavior.
*/

constexpr bool kIsAssetsPathCustomizable = true;
/**
* If true, allow the user to configure the asset paths. Useful for
* debugging purposes or for customization-centric users.
*/
constexpr bool kIsAssetsPathCustomizable = false;

/**
* If true, a custom MPQ will be used to store the additional assets
* required. Set to false if running a mod where it will be stored in
* Patch_D2.mpq instead.
*/
constexpr bool kIsLoadCustomMpq = true;

/**
* If true, the inventory arrangement sources from 800x600 entries in
* calculations. Otherwise, sources from 640x480 entries.
*
* Warning: Setting this value to true will make inventory slots for
* heights less than 600 display incorrect.
*/
constexpr bool kIsSourceInventoryArrange800 = false;

#endif // SGD2FR_COMPILE_TIME_SWITCH_HPP_
78 changes: 63 additions & 15 deletions SlashGaming-Diablo-II-Free-Resolution/src/helper/game_resolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,21 @@ struct Ipv4ResolutionTableEntryCompareKey {
}
};

static constexpr std::tuple resolution_640x480 = std::make_tuple(640, 480);
static constexpr std::tuple resolution_800x600 = std::make_tuple(800, 600);

const std::vector<std::tuple<int, int>>& GetResolutionsFromIpV4(
std::string_view ipv4_address
) {
// Warning: This needs to be sorted lexicographically!
static const ::std::array<
Ipv4ResolutionTableEntry,
3
4
> kSortedIpv4ResolutionTable = {{

// evnt.slashdiablo.net
Ipv4ResolutionTableEntry(
"207.252.75.177",
{
resolution_640x480,
resolution_800x600,
kResolution640x480,
kResolution800x600,
std::make_tuple(1068, 600)
}
),
Expand All @@ -114,8 +111,18 @@ const std::vector<std::tuple<int, int>>& GetResolutionsFromIpV4(
Ipv4ResolutionTableEntry(
"209.222.25.91",
{
resolution_640x480,
resolution_800x600,
kResolution640x480,
kResolution800x600,
std::make_tuple(1068, 600)
}
),

// Project Diablo 2
Ipv4ResolutionTableEntry(
"35.225.107.249",
{
kResolution640x480,
kResolution800x600,
std::make_tuple(1068, 600)
}
),
Expand All @@ -124,16 +131,16 @@ const std::vector<std::tuple<int, int>>& GetResolutionsFromIpV4(
Ipv4ResolutionTableEntry(
"95.179.228.126",
{
resolution_640x480,
resolution_800x600,
kResolution640x480,
kResolution800x600,
std::make_tuple(1068, 600)
}
),
}};

static const std::vector default_resolutions = {
resolution_640x480,
resolution_800x600
kResolution640x480,
kResolution800x600
};

::std::pair search_range = ::std::equal_range(
Expand Down Expand Up @@ -231,7 +238,7 @@ const std::vector<std::tuple<int, int>>& GetNonCrashingIngameResolutions() {
} // namespace

std::size_t GetMinConfigResolutionId() {
return GetNonCrashingIngameResolutions().at(0) == resolution_640x480
return GetNonCrashingIngameResolutions().at(0) == kResolution640x480
? 0
: 1;
}
Expand All @@ -241,7 +248,7 @@ std::size_t GetMaxConfigResolutionId() {
}

std::size_t GetMinIngameResolutionId() {
return GetNonCrashingIngameResolutions().at(0) == resolution_640x480
return GetNonCrashingIngameResolutions().at(0) == kResolution640x480
? 0
: 2;
}
Expand All @@ -256,7 +263,7 @@ std::size_t GetNumIngameResolutions() {

std::tuple<int, int> GetIngameResolutionFromId(std::size_t id) {
if (id == 0) {
return resolution_640x480;
return kResolution640x480;
} else if (id == 1) {
return config::GetMainMenuResolution();
}
Expand Down Expand Up @@ -318,4 +325,45 @@ ::std::tuple<int, int> GetVideoModeDisplayResolution() {
}
}

unsigned int GetSourceInventoryArrangeMode() {
static constexpr unsigned int kDefaultSourceInventoryArrangeMode =
(kIsSourceInventoryArrange800)
? 1
: 0;

unsigned int resolution_mode = ::d2::d2gfx::GetResolutionMode();

::std::tuple<int, int> current_resolution = GetIngameResolutionFromId(
resolution_mode
);

if (current_resolution == kResolution640x480) {
return 0;
} else if (current_resolution == kResolution800x600) {
return 1;
} else {
return kDefaultSourceInventoryArrangeMode;
}
}

const ::std::tuple<int, int>& GetSourceInventoryArrangeResolution() {
unsigned int resolution_mode = ::d2::d2gfx::GetResolutionMode();

::std::tuple<int, int> current_resolution = GetIngameResolutionFromId(
resolution_mode
);

if (current_resolution == kResolution640x480) {
return kResolution640x480;
} else if (current_resolution == kResolution800x600) {
return kResolution800x600;
}

if constexpr (kIsSourceInventoryArrange800) {
return kResolution800x600;
} else {
return kResolution640x480;
}
}

} // namespace sgd2fr
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@
#include <cstddef>
#include <tuple>

#include "../compile_time_switch.hpp"

namespace sgd2fr {

constexpr const ::std::tuple<int, int> kResolution640x480(640, 480);
constexpr const ::std::tuple<int, int> kResolution800x600(800, 600);

std::size_t GetMinConfigResolutionId();
std::size_t GetMaxConfigResolutionId();

Expand All @@ -67,6 +72,10 @@ bool IsStandardResolution(const std::tuple<int, int>& width_and_height);
*/
::std::tuple<int, int> GetVideoModeDisplayResolution();

unsigned int GetSourceInventoryArrangeMode();

const ::std::tuple<int, int>& GetSourceInventoryArrangeResolution();

} // namespace sgd2fr

#endif // SGD2FR_HELPER_GAME_RESOLUTION_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,19 @@
#include "game_resolution.hpp"

namespace sgd2fr {
namespace {

} // namespace

void RealignPositionFromCenter(
unsigned int inventory_arrange_mode,
d2::PositionalRectangle_Wrapper out_position_wrapper
) {
std::tuple width_and_height = GetIngameResolutionFromId(
std::tuple current_resolution = GetIngameResolutionFromId(
d2::d2gfx::GetResolutionMode()
);

std::tuple<int, int> source_width_and_height;
if (inventory_arrange_mode == 1) {
source_width_and_height = GetIngameResolutionFromId(2);
} else {
source_width_and_height = GetIngameResolutionFromId(0);
}
const std::tuple<int, int>& source_resolution =
GetSourceInventoryArrangeResolution();

int source_width = std::get<0>(source_width_and_height);
int source_height = std::get<1>(source_width_and_height);
int source_width = std::get<0>(source_resolution);
int source_height = std::get<1>(source_resolution);

// Set left and right values.
int dist_from_rect_left_to_display_center = out_position_wrapper.GetLeft()
Expand All @@ -78,7 +70,7 @@ void RealignPositionFromCenter(
- out_position_wrapper.GetLeft();

out_position_wrapper.SetLeft(
(std::get<0>(width_and_height) / 2)
(std::get<0>(current_resolution) / 2)
+ dist_from_rect_left_to_display_center
);

Expand All @@ -94,7 +86,7 @@ void RealignPositionFromCenter(
- out_position_wrapper.GetTop();

out_position_wrapper.SetTop(
(std::get<1>(width_and_height) / 2)
(std::get<1>(current_resolution) / 2)
+ dist_from_rect_top_to_display_center
);

Expand All @@ -103,6 +95,51 @@ void RealignPositionFromCenter(
);
}

void RealignPositionFromBottomCenter(
d2::PositionalRectangle_Wrapper out_position_wrapper
) {
std::tuple current_resolution = GetIngameResolutionFromId(
d2::d2gfx::GetResolutionMode()
);

const std::tuple<int, int>& source_resolution =
GetSourceInventoryArrangeResolution();

int source_width = std::get<0>(source_resolution);
int source_height = std::get<1>(source_resolution);

// Set left and right values.
int dist_from_rect_left_to_display_center = out_position_wrapper.GetLeft()
- (source_width / 2);

int rectangle_width = out_position_wrapper.GetRight()
- out_position_wrapper.GetLeft();

out_position_wrapper.SetLeft(
(std::get<0>(current_resolution) / 2)
+ dist_from_rect_left_to_display_center
);

out_position_wrapper.SetRight(
out_position_wrapper.GetLeft() + rectangle_width
);

// Set top and bottom values.
int dist_from_rect_top_to_display_bottom =
source_height - out_position_wrapper.GetTop();

int rectangle_height = out_position_wrapper.GetBottom()
- out_position_wrapper.GetTop();

out_position_wrapper.SetTop(
std::get<1>(current_resolution)
- dist_from_rect_top_to_display_bottom
);

out_position_wrapper.SetBottom(
out_position_wrapper.GetTop() + rectangle_height
);
}

} // namespace sgd2fr

Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@
namespace sgd2fr {

void RealignPositionFromCenter(
unsigned int inventory_arrange_mode,
d2::PositionalRectangle_Wrapper out_position_wrapper
::d2::PositionalRectangle_Wrapper out_position_wrapper
);

void RealignPositionFromBottomCenter(
::d2::PositionalRectangle_Wrapper out_position_wrapper
);

} // namespace sgd2fr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ void __cdecl Sgd2fr_D2Common_GetGlobalBeltRecord(
) {
// Original code, copies the values of the specified Global Belt Slot
// into the output Belt Slot.
unsigned int source_inventory_arrange_mode = (inventory_arrange_mode < 2)
? inventory_arrange_mode
: 0;
unsigned int source_inventory_arrange_mode =
GetSourceInventoryArrangeMode();

d2::BeltRecord_View global_belt_txt_view(d2::d2common::GetGlobalBeltsTxt());
d2::BeltRecord_View global_belt_record_view(
Expand Down
Loading

0 comments on commit 504b021

Please sign in to comment.