Skip to content

Commit

Permalink
break hidden resources limit
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 4, 2024
1 parent 10533a9 commit 5ad1b2e
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 0 deletions.
188 changes: 188 additions & 0 deletions M2TWEOP Code/M2TWEOP library/Injects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5541,6 +5541,194 @@ void onSetKhakiText5::SetNewCode()
delete a;
}


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

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

void onSetRegionHiddenResources2::SetNewCode()
{
const auto a = new Assembler();
a->pop(edx);
a->push(ecx);
a->push(edx);
a->push(ebx);
a->mov(ecx, edx);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
a->pop(ebx);
a->pop(edx);
a->pop(ecx);
a->cmp(eax, ebx);
a->ret();
m_cheatBytes = static_cast<unsigned char*>(a->make());
delete a;
}


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

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

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


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

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

void onHiddenResourceCheck::SetNewCode()
{
const auto a = new Assembler();
a->pop(esi);
a->mov(edx, eax);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
if (m_adress == 0x609E54)
a->mov(ecx, 0x609E84);
else
a->mov(ecx, 0x609AD4);
a->jmp(ecx);
a->ret();
m_cheatBytes = static_cast<unsigned char*>(a->make());
delete a;
}

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

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

void onHiddenResourceCheck2::SetNewCode()
{
const auto a = new Assembler();
a->pop(esi);
a->mov(ecx, edx);
a->mov(edx, eax);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
if (m_adress == 0x609F52)
a->mov(ecx, 0x609F81);
else
a->mov(ecx, 0x609BD1);
a->jmp(ecx);
a->ret();
m_cheatBytes = static_cast<unsigned char*>(a->make());
delete a;
}


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

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

void onSetRegionHiddenResources::SetNewCode()
{
const auto a = new Assembler();
const auto label = a->newLabel();
a->push(eax);
a->mov(edx, esi);
a->mov(ecx, eax);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
a->cmp(eax, 0);
a->pop(eax);
a->jbe(label);
if (m_adress == 0x8D964B)
a->mov(eax, 0x008D9677);
else
a->mov(eax, 0x008D8C17);
a->jmp(eax);
a->bind(label);
a->mov(ecx, eax);
a->mov(edx, eax);
a->and_(eax, 0x1F);
a->ret();
m_cheatBytes = static_cast<unsigned char*>(a->make());
delete a;
}


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

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

void onReadHiddenResources::SetNewCode()
{
const auto a = new Assembler();
const auto label = a->newLabel();
a->push(ecx);
a->push(edx);
a->push(eax);
a->mov(edx, ecx);
a->mov(ecx, esi);
a->mov(eax, reinterpret_cast<DWORD>(funcAddress));
a->call(eax);
a->cmp(eax, 0);
a->pop(eax);
a->pop(edx);
a->pop(ecx);
a->jbe(label);
if (m_adress == 0x8AD0AD)
a->mov(eax, 0x8AD0CA);
else
a->mov(eax, 0x8AC6DA);
a->jmp(eax);
a->bind(label);
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
72 changes: 72 additions & 0 deletions M2TWEOP Code/M2TWEOP library/Injects.h
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,78 @@ class onSetKhakiText5
LPVOID funcAddress;
};

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

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

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

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

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

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

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

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

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

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

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

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


class onIsBuildingTypePresentAtMinLevel
:public AATemplate
Expand Down
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/dataOffsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void dataOffsets::initDataOffsets(int gameVer)
offsets.descrRebels = 0x16673F0;
offsets.eventManager = 0x16F0BC8;
offsets.uiStratUiV2 = 0x2CB62FC;
offsets.currentRegion = 0x18FD970;


offsets.fortVtbl = 0x13362F4;
Expand Down Expand Up @@ -192,6 +193,7 @@ void dataOffsets::initDataOffsets(int gameVer)
offsets.ltgdConfig = 0x01605134;
offsets.descrRebels = 0x161F518;
offsets.eventManager = 0x16A7A30;
offsets.currentRegion = 0x18B4800;
offsets.uiStratUiV2 = 0x2C6D1B0;

offsets.audioEnable = reinterpret_cast<bool*>(0x01639f1d);
Expand Down
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/dataOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class dataOffsets
DWORD cultureDatabase = NULL;
DWORD loadGameHandler = NULL;
DWORD selectedEra = NULL;
DWORD currentRegion = NULL;
DWORD campaignDb = NULL;
DWORD campaignDbExtra = NULL;
DWORD groupLabels = NULL;
Expand Down
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/functionsOffsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ void codes::initCodes(int gameVer)
offsets.createBuildingSett = 0x5FAB60;
offsets.buildQueueConflictTest = 0x5EB100;
offsets.removeBuildingSelection = 0x5FA3A0;
offsets.getNextWord = 0xD4F060;
}


Expand Down Expand Up @@ -660,5 +661,6 @@ void codes::initCodes(int gameVer)
offsets.createBuildingSett = 0x005FAF50;
offsets.buildQueueConflictTest = 0x005EB560;
offsets.removeBuildingSelection = 0x005FA790;
offsets.getNextWord = 0xD493C0;
}
}
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/functionsOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class codes
DWORD switchArmyFaction = NULL;
DWORD changeCharacterTileStuff = NULL;
DWORD initPlaceCharacter = NULL;
DWORD getNextWord = NULL;
DWORD getResidenceCharacterNum = NULL;
DWORD getResidenceCharacterAtIndex = NULL;
DWORD removeSieges = NULL;
Expand Down
36 changes: 36 additions & 0 deletions M2TWEOP Code/M2TWEOP library/managerF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,42 @@ void managerF::execPatches()
toSetKhakiText5->Enable();
f1 << "Done" << '\n';

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

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

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

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

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

f1 << "Start applying toHiddenResourceCheck2 patch" << '\n';
onHiddenResourceCheck2* toHiddenResourceCheck2 = new onHiddenResourceCheck2(mem, (LPVOID)patchesForGame::onCheckHiddenResource, globals::dataS.gameVersion);
toHiddenResourceCheck2->SetNewCode();
toHiddenResourceCheck2->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
Loading

0 comments on commit 5ad1b2e

Please sign in to comment.