Skip to content

Commit

Permalink
recruitable eop units and more
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 17, 2023
1 parent af42136 commit 95d183d
Show file tree
Hide file tree
Showing 30 changed files with 2,553 additions and 2,259 deletions.
570 changes: 556 additions & 14 deletions M2TWEOP Code/M2TWEOP library/Injects.cpp

Large diffs are not rendered by default.

122 changes: 121 additions & 1 deletion M2TWEOP Code/M2TWEOP library/Injects.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ class toBattleLoaded



//select worldpkgdesc from db
class toReadGameDBsAtGameStart
:public AATemplate
{
Expand All @@ -530,6 +529,8 @@ class toReadGameDBsAtGameStart





//draw parts of stratmodels
class toDrawPartsOfStratObjects
:public AATemplate
Expand Down Expand Up @@ -670,6 +671,18 @@ class mercenaryMovepointsGetGeneral
};


class onGameInitialized
:public AATemplate
{
public:
onGameInitialized(MemWork* mem, LPVOID adr, int ver);
~onGameInitialized();

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

class onGameConsoleCommandFromConsole
:public AATemplate
Expand Down Expand Up @@ -792,6 +805,19 @@ class OnCreateUnit
LPVOID funcAddress;
};

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

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

class OnCreateMercUnit
:public AATemplate
{
Expand Down Expand Up @@ -819,6 +845,58 @@ class OnCreateUnitWrapper
LPVOID funcAddress;
};

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

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

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

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

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

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

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

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

class OnCreateMercUnitCheck
:public AATemplate
{
Expand Down Expand Up @@ -969,6 +1047,48 @@ class recruitEOPunit
LPVOID funcAddress;
};

//create eop unit
class recruitEOPunit2
:public AATemplate
{
public:
recruitEOPunit2(MemWork* mem, LPVOID addr, int ver);
~recruitEOPunit2();

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

//create eop unit
class loadRecruitQueue
:public AATemplate
{
public:
loadRecruitQueue(MemWork* mem, LPVOID addr, int ver);
~loadRecruitQueue();

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

//create eop unit
class loadRecruitQueue2
:public AATemplate
{
public:
loadRecruitQueue2(MemWork* mem, LPVOID addr, int ver);
~loadRecruitQueue2();

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

//create eop unit
class recruitEOPMercunit
:public AATemplate
Expand Down
19 changes: 16 additions & 3 deletions M2TWEOP Code/M2TWEOP library/eopBuildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "fastFunctsHelpers.h"
#include "fastFuncts.h"
#include "smallFuncs.h"

#include <cstdio>
namespace eopBuildings
Expand Down Expand Up @@ -170,7 +171,7 @@ namespace eopBuildings
{
DWORD funcPointer = (DWORD)0x008A955B; //I dont think this does anything but not 100% sure, havent checked disk version as I do not think this is needed
DWORD EDBpointer = dataOffsets::offsets.edbDataStart; //for some reason this is included, not sure if needed
BuildingLvlCapability* cap = new BuildingLvlCapability; //allocating memory
BuildingLvlCapability* cap = reinterpret_cast<BuildingLvlCapability*>(fastFuncts::allocateGameMem(0x20));
buildingLevel* eoplevel = &entry->buildingLevel[level];
cap->capabilityType = 0; //always 0 for normal capabilities
if (bonus)
Expand All @@ -197,9 +198,9 @@ namespace eopBuildings

}

NOINLINE EOP_EXPORT void addBuildingPool(edbEntry* entry, int level, int eduIndex, float initialSize, float gainPerTurn, float maxSize, int32_t exp)
NOINLINE EOP_EXPORT void addBuildingPool(edbEntry* entry, int level, int eduIndex, float initialSize, float gainPerTurn, float maxSize, int32_t exp, const char* condition)
{
recruitPool* pool = new recruitPool;
recruitPool* pool = reinterpret_cast<recruitPool*>(fastFuncts::allocateGameMem(0x20));
buildingLevel* eoplevel = &entry->buildingLevel[level];
pool->capabilityType = 5; //5 means normal unit, there are some other for agents I havent added yet
pool->capabilityLvlorExp = exp; //for units this always is xp, for agents this can be agent
Expand All @@ -209,6 +210,18 @@ namespace eopBuildings
pool->maxSize = maxSize;
pool->buildingLevelCondition = nullptr;
pool->nextPool = nullptr;
auto fakeText = std::make_shared<fakeTextInput>(fakeTextInput(condition, 0));
auto rawText = fakeText.get();
const auto makeConditionFunc = reinterpret_cast<DWORD*>(0x008A7510);
auto conditionPtr = &pool->buildingLevelCondition;
_asm
{
push 3
push conditionPtr
push fakeText
mov eax, makeConditionFunc
call eax
}
if (eoplevel->recruitPools != nullptr)
{
pool->nextPool = eoplevel->recruitPools; //always insert at start of pools
Expand Down
2 changes: 1 addition & 1 deletion M2TWEOP Code/M2TWEOP library/eopBuildings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace eopBuildings
NOINLINE EOP_EXPORT void setBuildingLocalizedDescr(edbEntry* entry, const char* newName, int level, int facnum);
NOINLINE EOP_EXPORT void setBuildingLocalizedDescrShort(edbEntry* entry, const char* newName, int level, int facnum);
NOINLINE EOP_EXPORT void addBuildingCapability(edbEntry* entry, int level, int capability, int16_t value, bool bonus);
NOINLINE EOP_EXPORT void addBuildingPool(edbEntry* entry, int level, int eduIndex, float initialSize, float gainPerTurn, float maxSize, int32_t exp);
NOINLINE EOP_EXPORT void addBuildingPool(edbEntry* entry, int level, int eduIndex, float initialSize, float gainPerTurn, float maxSize, int32_t exp, const char* condition);
NOINLINE EOP_EXPORT void removeBuildingCapability(edbEntry* entry, int level, int index);
NOINLINE EOP_EXPORT void removeBuildingPool(edbEntry* entry, int level, int index);
NOINLINE EOP_EXPORT BuildingLvlCapability* getBuildingCapability(edbEntry* entry, int level, int index);
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 @@ -52,6 +52,7 @@ void codes::initCodes(int gameVer)
offsets.createUnitFunc = 0x008edf60;
offsets.addUnitToArmyFunc = 0x00719380;
offsets.setBodyguard = 0x00598f10;
offsets.makeConditionFunc = 0x00874920;

offsets.killCharStratMapFunc = 0x00592900;
offsets.killUnitStratMapFunc = 0x007417e0;
Expand Down Expand Up @@ -131,6 +132,7 @@ void codes::initCodes(int gameVer)
offsets.createUnitFunc = 0x008ee9e0;
offsets.addUnitToArmyFunc = 0x00719ab0;
offsets.setBodyguard = 0x00599400;
offsets.makeConditionFunc = 0x00875310;


offsets.killCharStratMapFunc = 0x00592e00;
Expand Down
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/functionsOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class codes
DWORD deleteFortFuncTwo = NULL;
DWORD createFortFunc = NULL;
DWORD mercEOPValue = NULL;
DWORD makeConditionFunc = NULL;
}offsets;

static void initCodes(int gameVer);
Expand Down
54 changes: 53 additions & 1 deletion M2TWEOP Code/M2TWEOP library/managerF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ void managerF::doPachs()
toRecruitEOPunit->Enable();
f1 << "Done" << endl;

f1 << "Start applying recruit eop unit patch" << endl;
recruitEOPunit2* toRecruitEOPunit2 = new recruitEOPunit2(mem, (LPVOID)patchesForGame::recruitEOPunit2, globals::dataS.gamever);
toRecruitEOPunit2->SetNewCode();
toRecruitEOPunit2->Enable();
f1 << "Done" << endl;

f1 << "Start applying recruit merc eop unit patch" << endl;
recruitEOPMercunit* torecruitEOPMercunit = new recruitEOPMercunit(mem, (LPVOID)patchesForGame::recruitEOPMercunit, globals::dataS.gamever);
torecruitEOPMercunit->SetNewCode();
Expand Down Expand Up @@ -146,6 +152,7 @@ void managerF::doPachs()
ed->Enable();
f1 << "Done" << endl;


f1 << "Start applying OnChangePassedTurnsCount patch" << endl;

toChangePassedTurnsCount* tcptc = new toChangePassedTurnsCount(mem, (LPVOID)patchesForGame::onChangeTurnNum, globals::dataS.gamever);
Expand Down Expand Up @@ -348,7 +355,7 @@ void managerF::doPachs()
//f1 << "Start applying toReadGameDBsAtGameStart patch" << endl;
//toReadGameDBsAtGameStart* toReadGameDbsAtStart = new toReadGameDBsAtGameStart(mem, (LPVOID)patchesForGame::toReadGameDbsAtStart, globals::dataS.gamever);
//toReadGameDbsAtStart->SetlReadCode();
//toReadGameDbsAtStart->Enable();
//totoReadGameDBsAtGameStartDbsAtStart->Enable();

//f1 << "Done" << endl;

Expand Down Expand Up @@ -396,6 +403,11 @@ void managerF::doPachs()
cityConversionLvlSetter->Enable();
f1 << "Done" << endl;

f1 << "Start applying toGameInitialize patch" << endl;
onGameInitialized* toGameInitialize = new onGameInitialized(mem, (LPVOID)patchesForGame::onGameInit, globals::dataS.gamever);
toGameInitialize->SetNewCode();
toGameInitialize->Enable();
f1 << "Done" << endl;


f1 << "Start applying mercenaryMovepointsGetGeneral patch" << endl;
Expand Down Expand Up @@ -464,6 +476,11 @@ void managerF::doPachs()
onCreateUnit->Enable();
f1 << "Done" << endl;

f1 << "Start applying toFindUnit patch" << endl;
OnFindUnit*toFindUnit = new OnFindUnit(mem, (LPVOID)patchesForGame::onFindUnit, globals::dataS.gamever);
toFindUnit->SetNewCode();
toFindUnit->Enable();
f1 << "Done" << endl;

f1 << "Start applying toCreateMercUnit patch" << endl;
OnCreateMercUnit* toCreateMercUnit = new OnCreateMercUnit(mem, (LPVOID)patchesForGame::OnCreateMercUnit, globals::dataS.gamever);
Expand All @@ -477,6 +494,41 @@ void managerF::doPachs()
toCreateUnitWrapper->Enable();
f1 << "Done" << endl;

f1 << "Start applying OnFindUnitStrings patch" << endl;
OnFindUnitStrings* toFindUnitStrings = new OnFindUnitStrings(mem, (LPVOID)patchesForGame::OnCreateUnitWrapper, globals::dataS.gamever); //its same func as unit wrapper on purpose not error
toFindUnitStrings->SetNewCode();
toFindUnitStrings->Enable();
f1 << "Done" << endl;

f1 << "Start applying OnFindUnitStrings patch" << endl;
OnFindUnitStrings2* toFindUnitStrings2 = new OnFindUnitStrings2(mem, (LPVOID)patchesForGame::OnCreateUnitWrapper, globals::dataS.gamever); //its same func as unit wrapper on purpose not error
toFindUnitStrings2->SetNewCode();
toFindUnitStrings2->Enable();
f1 << "Done" << endl;

f1 << "Start applying OnGetRecruitPoolUnitEntry patch" << endl;
OnGetRecruitPoolUnitEntry* toGetRecruitPoolUnitEntry = new OnGetRecruitPoolUnitEntry(mem, (LPVOID)patchesForGame::OnGetRecruitPoolUnitEntry, globals::dataS.gamever);
toGetRecruitPoolUnitEntry->SetNewCode();
toGetRecruitPoolUnitEntry->Enable();
f1 << "Done" << endl;

f1 << "Start applying toLoadRecruitQueue patch" << endl;
loadRecruitQueue* toLoadRecruitQueue = new loadRecruitQueue(mem, (LPVOID)patchesForGame::OnGetRecruitPoolUnitEntry, globals::dataS.gamever);
toLoadRecruitQueue->SetNewCode();
toLoadRecruitQueue->Enable();
f1 << "Done" << endl;

f1 << "Start applying toLoadRecruitQueue2 patch" << endl;
loadRecruitQueue2* toLoadRecruitQueue2 = new loadRecruitQueue2(mem, (LPVOID)patchesForGame::OnGetRecruitPoolUnitEntry, globals::dataS.gamever);
toLoadRecruitQueue2->SetNewCode();
toLoadRecruitQueue2->Enable();
f1 << "Done" << endl;

f1 << "Start applying OnGetRecruitPoolUnitEntry2 patch" << endl;
OnGetRecruitPoolUnitEntry2* toGetRecruitPoolUnitEntry2 = new OnGetRecruitPoolUnitEntry2(mem, (LPVOID)patchesForGame::OnGetRecruitPoolUnitEntry, globals::dataS.gamever);
toGetRecruitPoolUnitEntry2->SetNewCode();
toGetRecruitPoolUnitEntry2->Enable();
f1 << "Done" << endl;

f1 << "Start applying toCreateMercUnitCheck patch" << endl;
OnCreateMercUnitCheck* toCreateMercUnitCheck = new OnCreateMercUnitCheck(mem, (LPVOID)patchesForGame::OnCreateMercUnitCheck, globals::dataS.gamever);
Expand Down
Loading

0 comments on commit 95d183d

Please sign in to comment.