Skip to content

Commit

Permalink
H3.TextColor updated for HD 5.0R C81
Browse files Browse the repository at this point in the history
Some minor H3API updates
  • Loading branch information
RoseKavalier committed Mar 28, 2020
1 parent ff01897 commit 011003a
Show file tree
Hide file tree
Showing 18 changed files with 655 additions and 172 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -29,3 +29,5 @@
H3.Plugin.Template/bin/Release/H3.Plugin.Template.vsix
*.user
*.ncb
*.cs
*.enc
2 changes: 1 addition & 1 deletion H3.TextColor/H3.TextColor.vcxproj
Expand Up @@ -58,7 +58,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>PLUGIN_NAME="$(ProjectName)";WIN32;_DEBUG;_WINDOWS;_USRDLL;H3TEXTCOLOR_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)H3API\lib;$(ProjectDir)include;$(ProjectDir)src</AdditionalIncludeDirectories>
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
Expand Down
10 changes: 10 additions & 0 deletions H3.TextColor/H3.TextColor.vcxproj.user
Expand Up @@ -3,4 +3,14 @@
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>C:\Heroes3\SoD turbo1 HD.exe</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>C:\Heroes3\</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommand>C:\Heroes3\SoD turbo1 HD.exe</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>C:\Heroes3\</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
2 changes: 0 additions & 2 deletions H3.TextColor/include/Hooks.h
Expand Up @@ -15,6 +15,4 @@ extern PatcherInstance *_PI;
// * installs all TextColor hooks
void Hooks_init(PatcherInstance *pi);

extern "C" __declspec(dllexport) h3::H3Plugin::TextColor::H3TextColorInformation *GetTextColor_();

#endif /* #define _HOOKS_H_ */
80 changes: 55 additions & 25 deletions H3.TextColor/src/Hooks.cpp
Expand Up @@ -2,6 +2,9 @@

using namespace h3;

// HDMOD version as of latest update
constexpr DWORD HDMOD_VERSION = 5000281;

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -82,6 +85,7 @@ static class H3TextColor : public H3TextColorInformation

H3Plugin::TextColor::H3TextColorInformation * GetTextColor_()
{
#pragma _H3_EXPORT_
return &InternalTextColor;
}

Expand Down Expand Up @@ -212,6 +216,16 @@ _LHF_(DirectDrawCharColor)
return EXEC_DEFAULT;
}

// * Sets the correct color to use while using Direct Draw
_LHF_(DirectDrawCharColor_5000281)
{
const INT32 color = CharColors[CurrentPosition];
if (color != NO_COLOR)
c->ebx = color;
return EXEC_DEFAULT;
}


// * Sets the correct color to use while using True Stretchable mode
_LHF_(TrueStretchModeDrawCharColor)
{
Expand All @@ -237,19 +251,7 @@ _LHF_(ParseText) // 0x4B5255
PCHAR current = TextParser.Begin();
INT32 currentColor = NO_COLOR;

// * resets vector data
// * I wouldn't recommend this but these are
// * integers and so there's nothing forgotten in limbo
struct VectorReset
{
int _init;
int begin;
int end;
int capacity;

void reset() { end = begin; }
};
reinterpret_cast<VectorReset*>(&CharColors)->reset();
CharColors.RemoveAll();

for (INT i = 0; i < len; i++, current++)
{
Expand Down Expand Up @@ -301,12 +303,34 @@ _LHF_(ParseText) // 0x4B5255
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

// * handles all 32-bit color drawing as of HD 5.0 RC81
void DirectDrawHook_5000281(PatcherInstance *pi)
{
///////////////////////////////////////////////////////////////////////////////
// Needle: 54 12 00 00
///////////////////////////////////////////////////////////////////////////////
UINT8 needle[] = {
0x54, 0x12, 0x00, 0x00 // MOV EDX,DWORD PTR DS:[EDI+1254]
};
///////////////////////////////////////////////////////////////////////////////
// Expected code: 8B 2C 82
///////////////////////////////////////////////////////////////////////////////
UINT8 needle_sought[] = {
0x8B, 0x1C, 0x82 // MOV EBX,DWORD PTR DS:[EAX*4+EDX]
};

H3DLL HD_TC2("HD_TC2.dll");

DWORD address = HD_TC2.NeedleSearchAround(needle, 0x20, needle_sought);
if (address)
pi->WriteLoHook(address + sizeof(needle_sought), DirectDrawCharColor_5000281);
}

// * Finds where to install @TrueModeDrawCharColor
// * hook within _hd3_.dll
void TrueColorHook(PatcherInstance *pi)
void TrueColorHook_legacy(PatcherInstance *pi)
{
H3DLL _HD3_DLL;
_HD3_DLL.GetDLLInfo("_hd3_.dll");
H3DLL _HD3_DLL("_hd3_.dll");

///////////////////////////////////////////////////////////////////////////////
// Needle: 68 00 04 00 00 B8 92 74 61 00
Expand All @@ -327,7 +351,7 @@ void TrueColorHook(PatcherInstance *pi)
pi->WriteLoHook(address, TrueModeDrawCharColor);
}

void DirectDrawHook(PatcherInstance *pi)
void DirectDrawHook_legacy(PatcherInstance *pi)
{
///////////////////////////////////////////////////////////////////////////////
// Needle: 54 12 00 00
Expand All @@ -342,8 +366,7 @@ void DirectDrawHook(PatcherInstance *pi)
0x8B, 0x2C, 0x82 // MOV EBP,DWORD PTR DS:[EAX*4+EDX]
};

H3DLL HD_TC2;
HD_TC2.GetDLLInfo("HD_TC2.dll");
H3DLL HD_TC2("HD_TC2.dll");

DWORD address = HD_TC2.NeedleSearchAround(needle, 0x20, needle_sought);
if (address)
Expand All @@ -352,10 +375,9 @@ void DirectDrawHook(PatcherInstance *pi)

// * Finds where to install @TrueStretchModeDrawCharColor
// * hook within HD_MCR.dll
void TrueStretchModeColorHook(PatcherInstance *pi)
void TrueStretchModeColorHook_legacy(PatcherInstance *pi)
{
H3DLL HD_MCR_DLL;
HD_MCR_DLL.GetDLLInfo("HD_MCR.dll");
H3DLL HD_MCR_DLL("HD_MCR.dll");

///////////////////////////////////////////////////////////////////////////////
// Needle: 68 00 04 00 00 B8 92 74 61 00
Expand Down Expand Up @@ -444,9 +466,17 @@ _LHF_(MainHook)

if (InternalTextColor.mode == InternalTextColor.CM_888)
{
TrueColorHook(_PI);
TrueStretchModeColorHook(_PI);
DirectDrawHook(_PI);
DWORD hdmodVersion = _P->VarGetValue("HD.Version.Dword", 0u);
if (hdmodVersion >= HDMOD_VERSION)
{
DirectDrawHook_5000281(_PI); // covers all 32-bit drawing modes
}
else
{
TrueColorHook_legacy(_PI);
TrueStretchModeColorHook_legacy(_PI);
DirectDrawHook_legacy(_PI);
}
}
else
_PI->WriteLoHook(0x4B4F74, DrawCharColor);
Expand Down
8 changes: 6 additions & 2 deletions H3API/lib/h3api/H3Base/H3Base.cpp
Expand Up @@ -202,7 +202,11 @@ namespace h3
char buffer[64];

// * work with positives
int m = Abs(num);
INT64 m;
if (num != INT_MIN)
m = Abs(num);
else
m = INT64(INT_MAX) + 1;

// * if smaller than specified value, print regular number
if (m < RN_MIN_VALUE)
Expand All @@ -223,7 +227,7 @@ namespace h3
int d = power = 0;
while (m >= 1000)
{
d = m;
d = int(m);
m /= 1000;
power++;
}
Expand Down
24 changes: 18 additions & 6 deletions H3API/lib/h3api/H3Base/H3Base.hpp
Expand Up @@ -142,6 +142,18 @@ typedef DWORD *PDWORD;
typedef const char *LPCSTR;
typedef void *PVOID;

#ifndef _H3_DECLARE_
// * forward-defines a struct, pointer to struct and reference to struct
#define _H3_DECLARE_(NAME) struct NAME; typedef struct NAME *P ## NAME; typedef struct NAME &R ## NAME;
#endif

#ifndef _H3_EXPORT_
// * exports a function without name mangling
// * to use, type the following within a function's definition:
// * #pragma _H3_EXPORT_
#define _H3_EXPORT_ comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
#endif

#ifndef ArraySize
// * returns number of elements in an array
#define ArraySize(arr) (sizeof(arr) / sizeof((arr)[0]))
Expand Down Expand Up @@ -528,12 +540,12 @@ namespace h3
GameVersion m_version;
public:
_H3API_ H3Version();
GameVersion version() const;
BOOL roe() const;
BOOL sod() const;
BOOL hota() const;
BOOL era() const;
BOOL wog() const;
_H3API_ GameVersion version() const;
_H3API_ BOOL roe() const;
_H3API_ BOOL sod() const;
_H3API_ BOOL hota() const;
_H3API_ BOOL era() const;
_H3API_ BOOL wog() const;
};

// * heap realloc using H3 assets
Expand Down
45 changes: 25 additions & 20 deletions H3API/lib/h3api/H3BinaryItems/H3BinaryItems.hpp
Expand Up @@ -20,29 +20,29 @@
namespace h3
{
// * forward declarations
_H3_DECLARE_(H3ARGB888);
_H3_DECLARE_(H3RGB888);
_H3_DECLARE_(H3RGB555);
_H3_DECLARE_(H3RGB565);
_H3_DECLARE_(H3HSV);
_H3_DECLARE_(H3BinTreeList);
_H3_DECLARE_(H3BinaryTreeNode);
_H3_DECLARE_(H3BinaryItem);
_H3_DECLARE_(H3WavFile);
_H3_DECLARE_(H3ColumnTextFile);
_H3_DECLARE_(H3TextFile);
_H3_DECLARE_(H3Palette565);
_H3_DECLARE_(H3Palette888);
_H3_DECLARE_(H3Font);
_H3_DECLARE_(H3LoadedPCX);
_H3_DECLARE_(H3LoadedPCX16);
_H3_DECLARE_(H3LoadedPCX24);
_H3_DECLARE_(H3DefFrame);
_H3_DECLARE_(H3DefGroup);
_H3_DECLARE_(H3LoadedDEF);

struct H3ARGB888;
typedef UINT16 RGB555;
typedef UINT16 RGB565;
struct H3BinaryItem;
struct H3BinaryTreeNode;
struct H3BinTreeList;
struct H3WavFile;
struct H3ColumnTextFile;
struct H3TextFile;
struct H3RGB888;
struct H3RGB555;
struct H3RGB565;
struct H3Palette565;
struct H3Font;
struct H3Palette888;
struct H3LoadedPCX;
struct H3LoadedPCX16;
struct H3LoadedPCX24;
struct H3DefFrame;
struct H3DefGroup;
struct H3LoadedDEF;
struct H3HSV;

#pragma pack(push, 1)

Expand Down Expand Up @@ -141,6 +141,11 @@ namespace h3
_H3API_ VOID Darken(UINT8 amount);
_H3API_ VOID Lighten(UINT8 amount);
_H3API_ VOID GrayScale();

enum eColors : RGB565
{
H3Highlight = 0xF6EF
};
};

struct H3HSV
Expand Down
19 changes: 18 additions & 1 deletion H3API/lib/h3api/H3Defines/H3Defines.cpp
Expand Up @@ -18,6 +18,14 @@ namespace h3
{
return StrAt(0x6A75D4 + 4 * level);
}
_H3API_ LPCSTR h3_PrimarySkillName(INT id)
{
return StrAt(0x6A53F8 + 4 * id);
}
_H3API_ LPCSTR h3_MagicSchoolName(INT school)
{
return StrAt(0x6A5338 + 8 * (4 + school));
}
_H3API_ LPCSTR h3_ObjectName(INT id)
{
return StrAt(0x6A7A54 + 4 * id);
Expand All @@ -30,6 +38,10 @@ namespace h3
{
return StrAt(0x6A7588 + 4 * type);
}
_H3API_ LPCSTR h3_CastleName(INT type)
{
return StrAt(0x6A755C + 4 * type);
}
_H3API_ LPCSTR h3_TerrainName(INT type)
{
return StrAt(0x6A5EEC + 4 * type);
Expand Down Expand Up @@ -64,7 +76,7 @@ namespace h3
}
_H3API_ H3SecondarySkillInfo& h3_SecondarySkillsInfo(int skill)
{
return (*(H3SecondarySkillInfo**)(0x67DCF0))[skill];
return (*(H3SecondarySkillInfo**)0x67DCF0)[skill];
}
_H3API_ H3GlobalObjectSettings& P_ObjectSettings(int id)
{
Expand Down Expand Up @@ -108,6 +120,11 @@ namespace h3
return StrAt(PtrAt(0x4D92B7 + 3) + 4 * id);
}

_H3API_ H3TownCreatureTypes& P_TownCreatureTypes(int town)
{
return (*(H3TownCreatureTypes**)(0x47AB00 + 3))[town];
}

#ifdef _H3API_DONT_USE_MACROS_
_H3API_ H3String & h3_DataPath()
{
Expand Down

0 comments on commit 011003a

Please sign in to comment.