Skip to content

Commit

Permalink
fix some strat model stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Sep 17, 2024
1 parent 799c8f2 commit 49eea0a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
17 changes: 10 additions & 7 deletions M2TWEOP Code/M2TWEOP library/Injects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,10 +1236,10 @@ toResourcesReadModels::toResourcesReadModels(MemWork* mem, LPVOID adr, int ver)
:AATemplate(mem), funcAdress(adr)
{
if (ver == 2)//steam
m_adress = 0x008e432d;
m_adress = 0x0044F4EF;

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

toResourcesReadModels::~toResourcesReadModels()
Expand All @@ -1250,8 +1250,9 @@ void toResourcesReadModels::SetOriginaResModelsCode()
{
Assembler* a = new Assembler();

a->add(eax, 0x1);
a->cmp(eax, 0x1c);
a->push(0);
a->push(0);
a->push(0);

a->ret();
m_originalBytes = (unsigned char*)a->make();
Expand All @@ -1272,9 +1273,10 @@ void toResourcesReadModels::SetlResModelsCode()

a->popf();
a->popad();

a->add(eax, 0x1);
a->cmp(eax, 0x1c);

a->push(0);
a->push(0);
a->push(0);

a->ret();
m_cheatBytes = (unsigned char*)a->make();
Expand Down Expand Up @@ -1326,6 +1328,7 @@ void toCharReadModels::SetNewCode()
a->push(ebp);
a->push(esi);
a->push(edi);
a->mov(dword_ptr(esp, 0x10), 0);

a->ret();
m_cheatBytes = (unsigned char*)a->make();
Expand Down
12 changes: 6 additions & 6 deletions M2TWEOP Code/M2TWEOP library/managerF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ void managerF::execPatches()

f1 << "Done" << '\n';

f1 << "Start applying models load patch #1" << '\n';
toStartReadModels* readModelsStart = new toStartReadModels(mem, (LPVOID)stratModelsChange::disableChecker, globals::dataS.gameVersion);
readModelsStart->SetlStReadModelsCode();
readModelsStart->Enable();

f1 << "Done" << '\n';
//f1 << "Start applying models load patch #1" << '\n';
//toStartReadModels* readModelsStart = new toStartReadModels(mem, (LPVOID)stratModelsChange::disableChecker, globals::dataS.gameVersion);
//readModelsStart->SetlStReadModelsCode();
//readModelsStart->Enable();
//
//f1 << "Done" << '\n';


f1 << "Start applying unical strat models patch" << '\n';
Expand Down
6 changes: 6 additions & 0 deletions M2TWEOP Code/M2TWEOP library/patchesForGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ void __stdcall patchesForGame::afterCampaignMapLoaded()

void __stdcall patchesForGame::onNewGameStart()
{
stratModelsChange::disableChecker();
minorSettlementDb::clear();
eopSettlementDataDb::get()->clearData();
gameEvents::onNewGameStart();
Expand Down Expand Up @@ -1995,6 +1996,7 @@ void __fastcall patchesForGame::onLoadSaveFile(UNICODE_STRING**& savePath)
}
files = techFuncs::loadGameLoadArchive(files, savePath);
minorSettlementDb::clear();
stratModelsChange::disableChecker();
eopSettlementDataDb::get()->onGameLoad(files);
eopCharacterDataDb::get()->onGameLoad(files);
gameEvents::onLoadGamePl(&files);
Expand Down Expand Up @@ -2057,7 +2059,9 @@ void __stdcall patchesForGame::unicalStratModsRead()
f1 << "unicalStratModsRead" << endl;
f1.close();
#endif
gameHelpers::logStringGame("Loading strat models...");
stratModelsChange::loadModels();
gameHelpers::logStringGame("Strat models loaded");
}

void __stdcall patchesForGame::loadCharStratModels()
Expand All @@ -2068,7 +2072,9 @@ void __stdcall patchesForGame::loadCharStratModels()
f1 << "loadCharStratModels" << endl;
f1.close();
#endif
gameHelpers::logStringGame("Loading strat characters models...");
stratModelsChange::loadCharModels();
gameHelpers::logStringGame("Strat character models loaded");
}


Expand Down
35 changes: 18 additions & 17 deletions M2TWEOP Code/M2TWEOP library/stratModelsChange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,30 @@ namespace stratModelsChange
{
}

bool modelsLoaded = false;
bool MODELS_LOADED = false;
bool CHAR_MODELS_LOADED = false;
void __stdcall disableChecker()
{
modelsLoaded = false;
MODELS_LOADED = false;
CHAR_MODELS_LOADED = false;
}
void loadModels()
{
if (modelsLoaded == true)
return;
//if (MODELS_LOADED == true)
// return;

// ReSharper disable once CppUseElementsView
for (const auto& [index, record] : stratModels)
{
record->modelP = loadModel(record->path, record->isSettlement);
}
modelsLoaded = true;
MODELS_LOADED = true;
changeModelsNeededNow = modelsChangeStatus::needChange;
}

void loadCharModels() //rebuild character CAS entries to be sure no pointers were cleaned up
{
if (modelsLoaded == true)return;

for (stratModelCharacterRecord* modRec : characterStratModels)
for (const stratModelCharacterRecord* modRec : characterStratModels)
{
*modRec->entry = *buildCharacterCas(modRec->skeletonname, modRec->caspath, modRec->shadowcaspath, modRec->modelId, modRec->texturepath, modRec->scale);
}
Expand Down Expand Up @@ -233,7 +234,7 @@ namespace stratModelsChange
{
if (!gen || !model)
return;
const size_t stringsize = strlen(model);
const size_t stringSize = strlen(model);
for (UINT32 i = 0; i < stratModelCharacterChangeList.size(); i++)
{
if (stratModelCharacterChangeList[i]->gen == gen)
Expand All @@ -245,7 +246,7 @@ namespace stratModelsChange
}
auto* rec = new stratModelCharacterRecordChange();
rec->gen = gen;
const auto modelNameCopy = new char[stringsize];
const auto modelNameCopy = new char[stringSize];
strcpy(modelNameCopy, model);
rec->modelId = modelNameCopy;
stratModelCharacterChangeList.push_back(rec);
Expand All @@ -260,14 +261,14 @@ namespace stratModelsChange
if (gen == nullptr) { //maybe captain dont exist anymore
return;
}
stratModelArrayEntry* modelentry = findCharacterStratModel(model); //get eop strat model from vector
if (modelentry == nullptr) {
modelentry = getStratModelEntry(model); //get vanilla strat model from 255 array
stratModelArrayEntry* entry = findCharacterStratModel(model); //get eop strat model from vector
if (entry == nullptr) {
entry = getStratModelEntry(model); //get vanilla strat model from 255 array
}
if (modelentry == nullptr) {
if (entry == nullptr) {
return;
}
const size_t stringsize = strlen(model);
const size_t stringSize = strlen(model);

const auto characterFacEntry = new genMod; //make new descr character faction entry
*characterFacEntry = *gen->genType; //get data of old entry and copy it in
Expand All @@ -280,10 +281,10 @@ namespace stratModelsChange
{
if (&characterFacEntry->stratInfo->stratModelsArray[i] != nullptr)
{
const auto modelNameCopy = new char[stringsize];
const auto modelNameCopy = new char[stringSize];
strcpy(modelNameCopy, model);
characterFacEntry->stratInfo->stratModelsArray[i].modelName = modelNameCopy;
characterFacEntry->stratInfo->stratModelsArray[i].stratModelEntry = modelentry;
characterFacEntry->stratInfo->stratModelsArray[i].stratModelEntry = entry;
}
}

Expand Down

0 comments on commit 49eea0a

Please sign in to comment.