Skip to content

Commit

Permalink
add setting descr_character model entries
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 28, 2024
1 parent ea95996 commit 8abd73d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 8 deletions.
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/dataOffsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void dataOffsets::initDataOffsets(int gameVer)
offsets.modelRigidCounts = 0x1B15EB4;
offsets.groundMoveCosts = 0x01602188;
offsets.expandedBinTable = 0x2C70760;
offsets.descrCharacter = 0x01861788;

offsets.audioEnable = reinterpret_cast<bool*>(0x01639f1d);
offsets.audioMaster_vol = reinterpret_cast<int*>(0x01639f60);
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 @@ -18,6 +18,7 @@ class dataOffsets
DWORD battleCursorCoords = NULL;
DWORD groundMoveCosts = NULL;
DWORD expandedBinTable = NULL;
DWORD descrCharacter = NULL;
DWORD customTiles = NULL;
DWORD battleCamera = NULL;
DWORD battlePerimeters = NULL;
Expand Down
20 changes: 20 additions & 0 deletions M2TWEOP Code/M2TWEOP library/realGameTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,26 @@ inline bool operator ==(int a, characterTypeStrat b)
return static_cast<characterTypeStrat>(a) == b;
}

inline bool operator >= (int a, characterTypeStrat b)
{
return static_cast<characterTypeStrat>(a) >= b;
}

inline bool operator > (int a, characterTypeStrat b)
{
return static_cast<characterTypeStrat>(a) > b;
}

inline bool operator <= (int a, characterTypeStrat b)
{
return static_cast<characterTypeStrat>(a) <= b;
}

inline bool operator < (int a, characterTypeStrat b)
{
return static_cast<characterTypeStrat>(a) < b;
}

inline bool operator !=(int a, characterTypeStrat b)
{
return static_cast<characterTypeStrat>(a) != b;
Expand Down
7 changes: 2 additions & 5 deletions M2TWEOP Code/M2TWEOP library/stratModelsChange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ namespace stratModelsChange
if (gen == nullptr) { //maybe captain dont exist anymore
return;
}
stratModelArrayEntry* entry = findCharacterStratModel(model); //get eop strat model from vector
if (entry == nullptr) {
entry = getStratModelEntry(model); //get vanilla strat model from 255 array
}
stratModelArrayEntry* entry = findCharacterStratModel(model);
if (entry == nullptr) {
return;
}
Expand Down Expand Up @@ -290,7 +287,7 @@ namespace stratModelsChange
return newRec->entry;
}
}
return nullptr;
return getStratModelEntry(modelId);
}

stratModelArrayEntry* getStratModelEntry(const char* name) //find vanilla model from array at offset
Expand Down
3 changes: 1 addition & 2 deletions M2TWEOP Code/M2TWEOP library/types/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ struct genMod {
char* rebelPortrait;
int rebelPortraitHash;
struct eduOfficer* battleMod;
bool actions[34];
char pad[2];
void* actions;
};

struct descrCharacterEntry
Expand Down
39 changes: 39 additions & 0 deletions M2TWEOP Code/M2TWEOP library/types/faction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "campaignAi.h"
#include "gameUi.h"
#include "cultures.h"
#include "stratModelsChange.h"

enum
{
Expand Down Expand Up @@ -95,6 +96,28 @@ void factionRecord::setCulture(const int Id)
facCulture = &culturesDb->cultures[Id];
}

void factionRecord::setFactionStratModel(const std::string& model, const int characterType, const int level)
{
if (characterType < 0 || characterType >= characterTypeStrat::invalid || level < 0 || level > 10)
return;
stratModelArrayEntry* entry = stratModelsChange::findCharacterStratModel(model.c_str());
if (!entry)
{
gameHelpers::logStringGame("factionRecord.setFactionStratModel: model not found: " + model);
return;
}
const auto descrCharacterPtr = reinterpret_cast<descrCharacterArray*>(dataOffsets::offsets.descrCharacter);
const auto charTypeEntry = &descrCharacterPtr->entries[characterType];
const auto factionEntry = charTypeEntry->ptrsToDescrCharacterFactionEntries[id];
if (level >= factionEntry->modelCount)
{
gameHelpers::logStringGame("factionRecord.setFactionStratModel: level out of bounds. Need add more levels to vanilla entry to set this level.");
return;
}
const auto levelEntry = &factionEntry->stratInfo->stratModelsArray[level];
levelEntry->stratModelEntry = entry;
}

stringWithHash* LOOKUP_STRING_LABEL = new stringWithHash();

characterRecord* factionStruct::getCharacterByLabel(const std::string& label)
Expand Down Expand Up @@ -1778,6 +1801,7 @@ namespace factionHelpers
@tfield int hordeMinNamedCharacters
@tfield int hordeMaxPercentArmyStack
@tfield int cultureID
@tfield setFactionStratModel setFactionStratModel
@table factionRecord
*/
Expand Down Expand Up @@ -1819,5 +1843,20 @@ namespace factionHelpers
types.factionRecord.set("hordeUnitPerSettlementPop", &factionRecord::hordeUnitPerSettlementPop);
types.factionRecord.set("hordeMinNamedCharacters", &factionRecord::hordeMinNamedCharacters);
types.factionRecord.set("hordeMaxPercentArmyStack", &factionRecord::hordeMaxPercentArmyStack);


/***
Set the strat model a character uses for a character type at a specific level. You can only set levels up to the amount defined in the vanilla descr_character entry. If using eop models only set after loading those (after campaign load).
@function factionRecord:setFactionStratModel
@tparam string model
@tparam int characterType
@tparam int level
@usage
factionRec:setFactionStratModel("arnor_general", characterType.general, 0)
*/
types.factionRecord.set_function("setFactionStratModel", &factionRecord::setFactionStratModel);



}
}
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/types/faction.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ struct factionRecord { /* see descr_sm_factions.txt */
char pad_00DD[3]; //0x00DD
int getCultureId();
void setCulture(int Id);
void setFactionStratModel(const std::string& model, int characterType, int level);
};

class eopFactionData
Expand Down
2 changes: 1 addition & 1 deletion M2TWEOP Code/M2TWEOP library/types/gameHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ namespace gameHelpers
logStringGame("M2TWEOP.copyFile: File not found: " + file);
return;
}
std::filesystem::copy(file, to, std::filesystem::copy_options::overwrite_existing);
std::filesystem::copy(file, to, std::filesystem::copy_options::overwrite_existing | std::filesystem::copy_options::recursive);
}

UNICODE_STRING*** getHashedUniString(void* stringTable, const std::string& key)
Expand Down

0 comments on commit 8abd73d

Please sign in to comment.