Skip to content

Commit

Permalink
txt colors
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Sep 30, 2024
1 parent 6bf1645 commit c536b4d
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 5 deletions.
112 changes: 112 additions & 0 deletions M2TWEOP Code/M2TWEOP library/Injects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5399,6 +5399,118 @@ void onGetDefensesBuilding::SetNewCode()
delete a;
}


onSetKhakiText::onSetKhakiText(MemWork* mem, LPVOID addr, int ver)
:AATemplate(mem), funcAddress(addr)
{
if (ver == 2)//steam
m_adress = 0x00B18307;

else if (ver == 1)//kingdoms
m_adress = 0x00B1DFF7;
}

void onSetKhakiText::SetNewCode()
{
const auto a = new Assembler();
a->push(ecx);
a->push(edx);
a->mov(ecx, eax);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
a->pop(edx);
a->pop(ecx);
a->mov(dword_ptr(edi, 0x4), edx);
a->mov(byte_ptr(edi, 0x8), bl);
a->ret();
m_cheatBytes = static_cast<unsigned char*>(a->make());
delete a;
}


onSetKhakiText2::onSetKhakiText2(MemWork* mem, LPVOID addr, int ver)
:AATemplate(mem), funcAddress(addr)
{
if (ver == 2)//steam
m_adress = 0xB18457;

else if (ver == 1)//kingdoms
m_adress = 0xB1E147;
}

void onSetKhakiText2::SetNewCode()
{
const auto a = new Assembler();
a->push(ecx);
a->push(edx);
a->mov(ecx, eax);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
a->pop(edx);
a->pop(ecx);
a->mov(dword_ptr(edi, 0x4), edx);
a->mov(byte_ptr(edi, 0x8), bl);
a->ret();
m_cheatBytes = static_cast<unsigned char*>(a->make());
delete a;
}


onSetKhakiText3::onSetKhakiText3(MemWork* mem, LPVOID addr, int ver)
:AATemplate(mem), funcAddress(addr)
{
if (ver == 2)//steam
m_adress = 0xB185CC;

else if (ver == 1)//kingdoms
m_adress = 0xB1E2BC;
}

void onSetKhakiText3::SetNewCode()
{
const auto a = new Assembler();
a->push(ecx);
a->push(edx);
a->mov(ecx, eax);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
a->pop(edx);
a->pop(ecx);
a->mov(dword_ptr(edi, 0x4), edx);
a->mov(byte_ptr(edi, 0x8), bl);
a->ret();
m_cheatBytes = static_cast<unsigned char*>(a->make());
delete a;
}


onSetKhakiText4::onSetKhakiText4(MemWork* mem, LPVOID addr, int ver)
:AATemplate(mem), funcAddress(addr)
{
if (ver == 2)//steam
m_adress = 0xB1AA8C;

else if (ver == 1)//kingdoms
m_adress = 0xB2077C;
}

void onSetKhakiText4::SetNewCode()
{
const auto a = new Assembler();
a->mov(dword_ptr(esi, 0x6C), eax);
a->mov(eax, dword_ptr(esp, 0x20));
a->push(ecx);
a->push(edx);
a->mov(ecx, eax);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
a->pop(edx);
a->pop(ecx);
a->ret();
m_cheatBytes = static_cast<unsigned char*>(a->make());
delete a;
}

onIsBuildingTypePresentAtMinLevel::onIsBuildingTypePresentAtMinLevel(MemWork* mem, LPVOID addr, int ver)
:AATemplate(mem), funcAddress(addr)
{
Expand Down
48 changes: 48 additions & 0 deletions M2TWEOP Code/M2TWEOP library/Injects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,54 @@ class onGetDefensesBuilding
LPVOID funcAddress;
};

class onSetKhakiText
:public AATemplate
{
public:
onSetKhakiText(MemWork* mem, LPVOID addr, int ver);
~onSetKhakiText() = default;

void SetNewCode();
private:
LPVOID funcAddress;
};

class onSetKhakiText2
:public AATemplate
{
public:
onSetKhakiText2(MemWork* mem, LPVOID addr, int ver);
~onSetKhakiText2() = default;

void SetNewCode();
private:
LPVOID funcAddress;
};

class onSetKhakiText3
:public AATemplate
{
public:
onSetKhakiText3(MemWork* mem, LPVOID addr, int ver);
~onSetKhakiText3() = default;

void SetNewCode();
private:
LPVOID funcAddress;
};

class onSetKhakiText4
:public AATemplate
{
public:
onSetKhakiText4(MemWork* mem, LPVOID addr, int ver);
~onSetKhakiText4() = default;

void SetNewCode();
private:
LPVOID funcAddress;
};


class onIsBuildingTypePresentAtMinLevel
:public AATemplate
Expand Down
12 changes: 12 additions & 0 deletions M2TWEOP Code/M2TWEOP library/luaPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
@tfield getFactionRecord getFactionRecord
@tfield hideUnknownUnitTooltips hideUnknownUnitTooltips
@tfield handleUnitCards handleUnitCards
@tfield setKhakiTextColor setKhakiTextColor
@tfield getMinorSettlementBalance getMinorSettlementBalance
@table M2TWEOP
*/
Expand Down Expand Up @@ -842,6 +843,17 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
*/
tables.M2TWEOP.set_function("handleUnitCards", &m2tweopOptions::setHandleUnitCards);

/***
Change color of default khaki text.
@function M2TWEOP.setKhakiTextColor
@tparam int r
@tparam int g
@tparam int b
@usage
M2TWEOP.setKhakiTextColor(0,0,0)
*/
tables.M2TWEOP.set_function("setKhakiTextColor", &m2tweopOptions::setKhakiTextColor);

/***
Get modifiers for minor settlements for income and growth.
@function M2TWEOP.getMinorSettlementBalance
Expand Down
24 changes: 24 additions & 0 deletions M2TWEOP Code/M2TWEOP library/managerF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,30 @@ void managerF::execPatches()
toDecideMissionTarget->Enable();
f1 << "Done" << '\n';

f1 << "Start applying onSetKhakiText patch" << '\n';
onSetKhakiText* toSetKhakiText = new onSetKhakiText(mem, (LPVOID)patchesForGame::onSetKhakiText, globals::dataS.gameVersion);
toSetKhakiText->SetNewCode();
toSetKhakiText->Enable();
f1 << "Done" << '\n';

f1 << "Start applying onSetKhakiText2 patch" << '\n';
onSetKhakiText2* toSetKhakiText2 = new onSetKhakiText2(mem, (LPVOID)patchesForGame::onSetKhakiText, globals::dataS.gameVersion);
toSetKhakiText2->SetNewCode();
toSetKhakiText2->Enable();
f1 << "Done" << '\n';

f1 << "Start applying onSetKhakiText3 patch" << '\n';
onSetKhakiText3* toSetKhakiText3 = new onSetKhakiText3(mem, (LPVOID)patchesForGame::onSetKhakiText, globals::dataS.gameVersion);
toSetKhakiText3->SetNewCode();
toSetKhakiText3->Enable();
f1 << "Done" << '\n';

f1 << "Start applying onSetKhakiText4 patch" << '\n';
onSetKhakiText4* toSetKhakiText4 = new onSetKhakiText4(mem, (LPVOID)patchesForGame::onSetKhakiText, globals::dataS.gameVersion);
toSetKhakiText4->SetNewCode();
toSetKhakiText4->Enable();
f1 << "Done" << '\n';

f1 << "Start applying onSetArmyGeneralsUnit patch" << '\n';
onSetArmyGeneralsUnit* toSetArmyGeneralsUnit = new onSetArmyGeneralsUnit(mem, (LPVOID)patchesForGame::onSetArmyGeneralsUnit, globals::dataS.gameVersion);
toSetArmyGeneralsUnit->SetNewCode();
Expand Down
7 changes: 7 additions & 0 deletions M2TWEOP Code/M2TWEOP library/patchesForGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,13 @@ int patchesForGame::onOffMapModelThing(const int culture)
return culture;
}

DWORD* patchesForGame::onSetKhakiText(DWORD* text)
{
if (text && *text == 0xFF807761)
*text = m2tweopOptions::getColor();
return text;
}

int patchesForGame::onAddBuildingCapsAfterConstruction(const settlementStruct* sett, int index)
{
for (int i = 0; i < sett->buildingsQueueArray.buildingsInQueue; i++)
Expand Down
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/patchesForGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class patchesForGame
static void __fastcall getPossibleConstructions(exportDescrBuildings* edb, settlementStruct* sett, void* data, void* caps, void* bonus, bool checkQueue, bool forceTemple);
static int __fastcall onConflictTest(const buildingsQueue* queue, int index);
static int __fastcall onOffMapModelThing(int culture);
static DWORD* __fastcall onSetKhakiText(DWORD* text);
static int __fastcall onAddBuildingCapsAfterConstruction(const settlementStruct* sett, int index);
static building* __fastcall onCheckBuildUpgrade(const settlementStruct* sett, int buildingId);
static void __fastcall onAttachRegionSettlement(settlementStruct* sett, int regionId);
Expand Down
3 changes: 3 additions & 0 deletions M2TWEOP Code/M2TWEOP library/types/gameHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

bool m2tweopOptions::hideUnknownUnitTooltips = true;
bool m2tweopOptions::eopHandleUnitCards = true;
uint8_t m2tweopOptions::khakiTextRed = 0x80;
uint8_t m2tweopOptions::khakiTextGreen = 0x77;
uint8_t m2tweopOptions::khakiTextBlue = 0x61;

scriptCommand::scriptCommand(const char* name) : className(name)
{
Expand Down
5 changes: 5 additions & 0 deletions M2TWEOP Code/M2TWEOP library/types/gameHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,13 @@ class m2tweopOptions
static bool getHideUnknownUnitTooltips() { return hideUnknownUnitTooltips; }
static void setHandleUnitCards(bool value) { eopHandleUnitCards = value; }
static bool getHandleUnitCards() { return eopHandleUnitCards; }
static DWORD getColor() { return (0xFF << 24) | (khakiTextRed << 16) | (khakiTextGreen << 8) | khakiTextBlue; }
static void setKhakiTextColor(const uint8_t red, const uint8_t green, const uint8_t blue) { khakiTextRed = red; khakiTextGreen = green; khakiTextBlue = blue; }
static bool hideUnknownUnitTooltips;
static bool eopHandleUnitCards;
static uint8_t khakiTextRed;
static uint8_t khakiTextGreen;
static uint8_t khakiTextBlue;
};

namespace gameHelpers
Expand Down
10 changes: 5 additions & 5 deletions M2TWEOP DataFiles/eopData/eopScripts/LuaImGuiDocs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ function ImGui.TextUnformatted(text, textEnd) end
function ImGui.Text(text) end

--- Shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();.
---@param colorR number
---@param colorG number
---@param colorB number
---@param colorA number
---@param text string
---@return number colorR
---@return number colorG
---@return number colorB
---@return number colorA
function ImGui.TextColored(text) end
function ImGui.TextColored(colorR, colorG, colorB, colorA, text) end

--- Shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor();.
---@param text string
Expand Down

0 comments on commit c536b4d

Please sign in to comment.