Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lei Chabolan committed Sep 12, 2022
2 parents b8710ba + d1b2858 commit 458670a
Show file tree
Hide file tree
Showing 11 changed files with 464 additions and 206 deletions.
4 changes: 2 additions & 2 deletions TemplePlus/critter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ uint32_t LegacyCritterSystem::HasMet(objHndl critter, objHndl otherCritter) {
return addresses.HasMet(critter, otherCritter);
}

uint32_t LegacyCritterSystem::AddFollower(objHndl npc, objHndl pc, int unkFlag, bool asAiFollower) {
return addresses.AddFollower(npc, pc, unkFlag, asAiFollower);
uint32_t LegacyCritterSystem::AddFollower(objHndl npc, objHndl pc, int forcedFollower, bool asAiFollower) {
return addresses.AddFollower(npc, pc, forcedFollower, asAiFollower);
}

bool LegacyCritterSystem::FollowerAtMax(){
Expand Down
11 changes: 8 additions & 3 deletions TemplePlus/fixes/generalfixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@

struct TigTextStyle;

// fixes size_colossal (was misspelled as size_clossal)
class SizeColossalFix : public TempleFix {

class HexFixes : public TempleFix {
public:

void apply() override {

// fixes size_colossal (was misspelled as size_clossal)
writeHex(0x10278078, "73 69 7A 65 5F 63 6F 6C 6F 73 73 61 6C");

// fixes Orb of Golden Death infinite Earth Elementals
writeHex(0x101034D9, "C1 E0 10"); // was 08, a wrong shift (looks like a typo error, all the others are shifted by 0x10: radMenuEntry.d20ActionData1 = (invIdxFromCondArg2 << 16) | [spellIdx]
}
} sizeColossalFix;
} hexFixes;

// Makes Kukri Proficiency Martial
class KukriFix : public TempleFix {
Expand Down
1 change: 1 addition & 0 deletions TemplePlus/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ objHndl InventorySystem::FindMatchingStackableItem(objHndl receiver, objHndl ite
auto itemSpell = itemObj->GetSpell(obj_f_item_spell_idx, 0);
auto invenItemSpell = invenItemObj->GetSpell(obj_f_item_spell_idx, 0);
if (itemSpell.spellLevel != invenItemSpell.spellLevel
|| itemSpell.spellEnum != invenItemSpell.spellEnum // Temple+: added this for automated scribed scrolls (who all use the same proto)
|| (itemObj->type == obj_t_scroll
&& spellSys.IsArcaneSpellClass(itemSpell.classCode)
!= spellSys.IsArcaneSpellClass(invenItemSpell.classCode) ))
Expand Down
24 changes: 17 additions & 7 deletions TemplePlus/spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ uint32_t LegacySpellSystem::spellRegistryCopy(uint32_t spellEnum, SpellEntry* sp
return spellEntryRegistry.copy(spellEnum, spellEntry);
}

void LegacySpellSystem::DoForSpellEntries(void(*cb)(SpellEntry & spellEntry)){
void LegacySpellSystem::DoForSpellEntries( const std::function<void (SpellEntry & )> &cb){
for (auto it : spellEntryRegistry) {
cb(*it.data);
}
Expand All @@ -882,10 +882,8 @@ int LegacySpellSystem::CopyLearnableSpells(objHndl& handle, int spellClass, std:

for (auto it : spellEntryRegistry) {
auto spEntry = it.data;
// new spells from supplemental materials are generally added above enum 802 in Temple+
if (spEntry->spellEnum > SPELL_ENUM_MAX_VANILLA) {
if (!config.nonCoreMaterials)
continue;
if (IsNonCore(spEntry->spellEnum) && !config.nonCoreMaterials) {
continue;
}
if (GetSpellLevelBySpellClass(spEntry->spellEnum, spellClass) >= 0) {
entries.push_back(*spEntry);
Expand Down Expand Up @@ -1414,7 +1412,7 @@ void LegacySpellSystem::SpellPacketSetCasterLevel(SpellPacketBody* spellPkt) con
}

// item spell
else if (spellPkt->invIdx != 255 && (spellPkt->spellEnum < NORMAL_SPELL_RANGE || spellPkt->spellEnum > SPELL_LIKE_ABILITY_RANGE)){
else if (spellPkt->invIdx != 255 && !IsMonsterSpell(spellPkt->spellEnum)){
spellPkt->casterLevel = 0;
logger->info("Critter {} is casting item spell {} at base caster_level {}.", casterName, spellName, 0);
}
Expand All @@ -1436,7 +1434,7 @@ void LegacySpellSystem::SpellPacketSetCasterLevel(SpellPacketBody* spellPkt) con
}
else{ // domain spell
if (spellPkt->spellClass == Domain_Special){ // domain special (usually used for monsters)
if (spellPkt->invIdx != 255 && (spellPkt->spellEnum < NORMAL_SPELL_RANGE || spellPkt->spellEnum > SPELL_LIKE_ABILITY_RANGE)) {
if (spellPkt->invIdx != 255 && !IsMonsterSpell(spellPkt->spellEnum)) {
spellPkt->casterLevel = 0;
logger->info("Critter {} is casting item spell {} at base caster_level {}.", casterName, spellName, 0);
}
Expand Down Expand Up @@ -2902,6 +2900,12 @@ int LegacySpellSystem::GetSpellSchool(int spellEnum){
return spEntry.spellSchoolEnum;
}

bool LegacySpellSystem::IsMonsterSpell(int spellEnum)
{
return spellEnum >= NORMAL_SPELL_RANGE
&& spellEnum <= SPELL_LIKE_ABILITY_RANGE;
}

bool LegacySpellSystem::IsSpellLike(int spellEnum){
return (spellEnum >= NORMAL_SPELL_RANGE
&& spellEnum <= SPELL_LIKE_ABILITY_RANGE) || spellEnum >= CLASS_SPELL_LIKE_ABILITY_START;
Expand All @@ -2922,6 +2926,12 @@ bool LegacySpellSystem::IsNewSlotDesignator(int spellEnum)
return false;
}

// Non-Core spells will be added in the expanded range
bool LegacySpellSystem::IsNonCore(int spellEnum)
{
return (spellEnum > SPELL_ENUM_MAX_VANILLA);
}

int LegacySpellSystem::GetSpellLevelBySpellClass(int spellEnum, int spellClass, objHndl handle){

if (IsLabel(spellEnum))
Expand Down
5 changes: 3 additions & 2 deletions TemplePlus/spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ struct LegacySpellSystem : temple::AddressTable

uint32_t spellRegistryCopy(uint32_t spellEnum, SpellEntry* spellEntry);

void DoForSpellEntries( void(__cdecl*cb)(SpellEntry & spellEntry));
void DoForSpellEntries( const std::function<void(SpellEntry &)> &cb);

int CopyLearnableSpells(objHndl & handle, int spellClass, std::vector<SpellEntry> & entries);
uint32_t ConfigSpellTargetting(PickerArgs* pickerArgs, SpellPacketBody* spellPacketBody);
Expand Down Expand Up @@ -224,10 +224,11 @@ struct LegacySpellSystem : temple::AddressTable
These are not interruptible via Ready vs. Spell, and
do not automatically show up in the console as [ACTOR] casts [SPELL]!
*/
static bool IsMonsterSpell(int spellEnum);
static bool IsSpellLike(int spellEnum);
static bool IsLabel(int spellEnum); // check if it is a hardcoded "label" enum (used in the GUI etc)
static bool IsNewSlotDesignator(int spellEnum); // check if it is a hardcoded "new slot" designator (used for sorting) enums 1605-1614

static bool IsNonCore(int spellEnum);

int GetSpellLevelBySpellClass(int spellEnum, int spellClass, objHndl handle = objHndl::null); // returns -1 if not available for spell class
bool SpellHasMultiSelection(int spellEnum);
Expand Down
36 changes: 36 additions & 0 deletions TemplePlus/spell_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "float_line.h"
#include "action_sequence.h"
#include "ai.h"
#include <party.h>
#include <ui/ui_systems.h>
#include <ui/ui_legacysystems.h>


void PyPerformTouchAttack_PatchedCallToHitProcessing(D20Actn * pd20A, D20Actn d20A, uint32_t savedesi, uint32_t retaddr, PyObject * pyObjCaller, PyObject * pyTupleArgs);
Expand Down Expand Up @@ -76,8 +79,13 @@ class SpellConditionFixes : public TempleFix {

static int SpellResistance_SpellResistanceMod(DispatcherCallbackArgs args);

static int SuggestionOnAdd(DispatcherCallbackArgs args);

void apply() override {

// Fix for when summoned Balor from skull casts suggestion
replaceFunction(0x100D01D0, SuggestionOnAdd);

// Magic Circle Taking Damage - didn't check that attacker is not null
replaceFunction(0x100C8D60, MagicCirclePreventDamage);

Expand Down Expand Up @@ -1468,3 +1476,31 @@ int SpellConditionFixes::SpellResistance_SpellResistanceMod(DispatcherCallbackAr
return 0;
}

int SpellConditionFixes::SuggestionOnAdd(DispatcherCallbackArgs args)
{
auto spellId = args.GetCondArg(0);
auto duration = args.GetCondArg(1);
auto arg2 = args.GetCondArg(2); // is 0...

if (!conds.AddTo(args.objHndCaller, "Charmed", { spellId, duration, arg2 })) {
logger->error("d20_mods_spells.c / _begin_spell_suggestion(): unable to add condition");
}
floatSys.FloatSpellLine(args.objHndCaller, 20018, FloatLineColor::Red); // Charmed!
auto partyLeader = party.GetConsciousPartyLeader();
SpellPacketBody pkt(spellId);
if (party.IsInParty(pkt.caster)) {
if (party.ObjIsAIFollower(pkt.caster)) {
critterSys.AddFollower(args.objHndCaller, /*partyLeader*/ pkt.caster, 1, 1);
}
else {
critterSys.AddFollower(args.objHndCaller, pkt.caster, 1, 0);
uiSystems->GetParty().Update();
}
}
else {
critterSys.AddFollower(args.objHndCaller, pkt.caster, 1, 1);
}
args.SetCondArg(2, 1);
return 0;
}

Loading

0 comments on commit 458670a

Please sign in to comment.