Skip to content

Commit c6da97c

Browse files
authored
Implement DamageSource and EntityDamageSource (#49)
* DamageSource and EntityDamageSource with a lot of non-matching * clean up random shit from ida * more of clean up * remove clion header again * update state of some functions
1 parent 4809d3b commit c6da97c

7 files changed

Lines changed: 184 additions & 33 deletions

File tree

data/mcswitch_functions.csv

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6674,7 +6674,7 @@ Address,Quality,Size,Name
66746674
0x00000071000f4234,U,000016,_ZN12DamageSource12bypassArmourEv
66756675
0x00000071000f4244,U,000016,
66766676
0x00000071000f4254,U,000012,
6677-
0x00000071000f4260,U,000012,
6677+
0x00000071000f4260,O,000012,_ZN18EntityDamageSource9setThornsEv
66786678
0x00000071000f426c,U,000012,
66796679
0x00000071000f4278,U,000164,
66806680
0x00000071000f431c,U,000120,_ZN12DamageSource12CreateThornsENSt3__110shared_ptrI6EntityEE
@@ -6691,25 +6691,25 @@ Address,Quality,Size,Name
66916691
0x00000071000f4a7c,U,000008,_ZN12DamageSource11isExplosionEv
66926692
0x00000071000f4a84,U,000008,
66936693
0x00000071000f4a8c,U,000012,
6694-
0x00000071000f4a98,U,000008,
6694+
0x00000071000f4a98,O,000008,_ZNK12DamageSource12isProjectileEv
66956695
0x00000071000f4aa0,U,000008,
66966696
0x00000071000f4aa8,U,000008,
6697-
0x00000071000f4ab0,U,000008,_ZNK12DamageSource13isBypassInvulEv
6697+
0x00000071000f4ab0,O,000008,_ZNK12DamageSource13isBypassInvulEv
66986698
0x00000071000f4ab8,U,000008,
6699-
0x00000071000f4ac0,U,000092,_ZN12DamageSourceC1Ev
6700-
0x00000071000f4b1c,U,000012,_ZN12DamageSource15getDirectEntityEv
6701-
0x00000071000f4b28,U,000008,_ZN12DamageSource9getEntityEv
6702-
0x00000071000f4b30,U,000008,_ZN12DamageSource20scalesWithDifficultyEv
6699+
0x00000071000f4ac0,O,000092,_ZN12DamageSourceC1EN21ClientboundChatPacket18EChatPacketMessageES1_
6700+
0x00000071000f4b1c,O,000012,_ZN12DamageSource15getDirectEntityEv
6701+
0x00000071000f4b28,O,000008,_ZN12DamageSource9getEntityEv
6702+
0x00000071000f4b30,O,000008,_ZN12DamageSource20scalesWithDifficultyEv
67036703
0x00000071000f4b38,U,000008,
67046704
0x00000071000f4b40,U,000300,
67056705
0x00000071000f4c6c,U,000216,_ZNSt3__120__shared_ptr_pointerIP32ClientboundDamageIndicatorPacketNS_14default_deleteIS1_EENS_9allocatorIS1_EEEC_gen
6706-
0x00000071000f4d44,U,000304,_ZN12DamageSource21getDeathMessagePacketENSt3__110shared_ptrI12LivingEntityE
6706+
0x00000071000f4d44,U,000304,_ZN12DamageSource21getDeathMessagePacketENSt3__110shared_ptrI12LivingEntityEE
67076707
0x00000071000f4e74,U,000008,_ZN12DamageSource6isFireEv
67086708
0x00000071000f4e7c,U,000008,
67096709
0x00000071000f4e84,U,000160,
6710-
0x00000071000f4f24,U,000052,_ZN12DamageSource4copyEv
6710+
0x00000071000f4f24,M,000052,_ZN12DamageSource4copyEv
67116711
0x00000071000f4f58,U,000044,_ZN12DamageSourceC_gen
6712-
0x00000071000f4f84,U,000008,_ZN12DamageSource17getSourcePositionEv
6712+
0x00000071000f4f84,O,000008,_ZN12DamageSource17getSourcePositionEv
67136713
0x00000071000f4f8c,U,000004,_ZN12DamageSource19GetBaseDamageSourceEv
67146714
0x00000071000f4f90,U,000068,_ZN15DataInputStreamC1EP11InputStream
67156715
0x00000071000f4fd4,U,000020,_ZN9DataInputC1Ev
@@ -8293,8 +8293,8 @@ Address,Quality,Size,Name
82938293
0x000000710012a808,O,000036,_ZN8CoalItemD0Ev
82948294
0x000000710012a82c,U,000036,_ZN10CocoaBlockD0Ev
82958295
0x000000710012a850,U,000036,_ZN12ColoredBlockD0Ev
8296-
0x000000710012a874,U,000004,_ZN12DamageSourceD2Ev
8297-
0x000000710012a878,U,000036,_ZN12DamageSourceD0Ev
8296+
0x000000710012a874,O,000004,_ZN12DamageSourceD2Ev
8297+
0x000000710012a878,O,000036,_ZN12DamageSourceD0Ev
82988298
0x000000710012a89c,U,000012,
82998299
0x000000710012a8a8,U,000036,_ZN18CommandBlockEntityD0Ev
83008300
0x000000710012a8cc,O,000004,_ZN12GenericStatsD2Ev
@@ -10116,15 +10116,15 @@ Address,Quality,Size,Name
1011610116
0x000000710015b160,U,000036,_ZN6Entity15stopCurrentLerpEv
1011710117
0x000000710015b184,U,000092,
1011810118
0x000000710015b1e0,U,000008,_ZN6Entity18getFireImmuneTicksEv
10119-
0x000000710015b1e8,U,000144,_ZN18EntityDamageSourceC_gen
10120-
0x000000710015b278,U,000012,
10119+
0x000000710015b1e8,O,000144,_ZN18EntityDamageSourceC1EN21ClientboundChatPacket18EChatPacketMessageES1_NSt3__110shared_ptrI6EntityEE
10120+
0x000000710015b278,O,000012,_ZN12DamageSource8setMagicEv
1012110121
0x000000710015b284,U,000008,
10122-
0x000000710015b28c,U,000028,
10123-
0x000000710015b2a8,U,000824,
10124-
0x000000710015b5e0,U,000076,
10125-
0x000000710015b62c,U,000052,
10122+
0x000000710015b28c,M,000028,_ZN18EntityDamageSource9getEntityEv
10123+
0x000000710015b2a8,U,000824,_ZN18EntityDamageSource21getDeathMessagePacketENSt3__110shared_ptrI12LivingEntityEE
10124+
0x000000710015b5e0,M,000076,_ZN18EntityDamageSource20scalesWithDifficultyEv
10125+
0x000000710015b62c,M,000052,_ZN18EntityDamageSource4copyEv
1012610126
0x000000710015b660,U,000084,_ZN18EntityDamageSourceC_gen2
10127-
0x000000710015b6b4,U,000016,
10127+
0x000000710015b6b4,M,000016,_ZN18EntityDamageSource17getSourcePositionEv
1012810128
0x000000710015b6c4,U,000048,_ZN21EntityDataSerializers25BYTE_EntityDataSerializerC_gen
1012910129
0x000000710015b6f4,U,000040,_ZN20EntityDataSerializerIhEC_gen
1013010130
0x000000710015b71c,U,000020,
@@ -13055,8 +13055,8 @@ Address,Quality,Size,Name
1305513055
0x00000071001cf3f8,O,000024,_ZN20KnockbackEnchantment10getMaxCostEi
1305613056
0x00000071001cf410,O,000008,_ZN20KnockbackEnchantment11getMaxLevelEv
1305713057
0x00000071001cf418,O,000036,_ZN4ItemD0Ev
13058-
0x00000071001cf43c,U,000052,_ZN18EntityDamageSourceC_gen3
13059-
0x00000071001cf470,U,000036,_ZN18EntityDamageSourceD0Ev
13058+
0x00000071001cf43c,M,000052,_ZN18EntityDamageSourceD1Ev
13059+
0x00000071001cf470,O,000036,_ZN18EntityDamageSourceD0Ev
1306013060
0x00000071001cf494,U,000052,_ZN26IndirectEntityDamageSourceD2Ev
1306113061
0x00000071001cf4c8,U,000036,_ZN26IndirectEntityDamageSourceD0Ev
1306213062
0x00000071001cf4ec,O,000040,_ZN13GetInfoPacketD2Ev
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "net/minecraft/world/damagesource/DamageSource.h"
2+
#include "net/minecraft/world/food/FoodConstants.h"
3+
4+
DamageSource::DamageSource(ClientboundChatPacket::EChatPacketMessage unk0,
5+
ClientboundChatPacket::EChatPacketMessage unk1) {
6+
this->field_0xa = false;
7+
this->mBypassInvul = false;
8+
this->mBypassArmour = false;
9+
this->mExhaustion = FoodConstants::ExhaustionAttack();
10+
this->mIsFireSource = false;
11+
this->mIsExplosion = false;
12+
this->mScalesWithDifficulty = false;
13+
this->mIsThorns = false;
14+
this->mIsProjectile = false;
15+
this->field_0x15 = false;
16+
this->field_0x18 = unk0;
17+
this->field_0x1a = unk1;
18+
}
19+
std::shared_ptr<Entity> DamageSource::getDirectEntity() {
20+
return this->getEntity();
21+
}
22+
std::shared_ptr<Entity> DamageSource::getEntity() {
23+
return nullptr;
24+
}
25+
bool DamageSource::scalesWithDifficulty() {
26+
return this->mScalesWithDifficulty;
27+
}
28+
Vec3* DamageSource::getSourcePosition() {
29+
return nullptr;
30+
}
31+
// NON_MATCHING | Score: 10
32+
// stop whining about std::shared_ptr<Entity> mEntity offset.
33+
// also why is target using 'orr', but current is using 'mov'??
34+
DamageSource* DamageSource::copy() {
35+
return new DamageSource(*this);
36+
}
37+
DamageSource* DamageSource::setMagic() {
38+
this->mIsMagic = true;
39+
return this;
40+
}
41+
bool DamageSource::isBypassInvul() const {
42+
return this->mBypassInvul;
43+
}
44+
bool DamageSource::isFire() const {
45+
return this->mIsFireSource;
46+
}
47+
bool DamageSource::isProjectile() const {
48+
return this->mIsProjectile;
49+
}
50+
bool DamageSource::isExplosion() const {
51+
return this->mIsExplosion;
52+
}
Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,48 @@
11
#pragma once
22

3-
#include "net/minecraft/core/Direction.h"
43
#include "net/minecraft/world/entity/Entity.h"
54
#include <memory>
65

6+
class EntityDamageSource;
77
class DamageSource {
88
public:
99
static DamageSource* BYPASS_ARMOUR; // this name is wrong
1010
static DamageSource* IN_FIRE;
1111
static DamageSource* WITHER;
1212

13-
static DamageSource* CreateThorns(std::shared_ptr<Entity>);
13+
static DamageSource* CreateThorns(std::shared_ptr<Entity> entity);
1414

15-
virtual ~DamageSource();
16-
virtual Direction* getDirectionEntity();
17-
virtual Entity* getEntity();
18-
virtual void scalesWithDifficulty();
19-
virtual void getDeathMessagePacket(std::shared_ptr<LivingEntity>);
20-
virtual void getSourcePosition();
21-
virtual void copy();
15+
DamageSource(ClientboundChatPacket::EChatPacketMessage, ClientboundChatPacket::EChatPacketMessage);
16+
virtual ~DamageSource() = default;
17+
18+
virtual std::shared_ptr<Entity> getDirectEntity();
19+
virtual std::shared_ptr<Entity> getEntity();
20+
virtual bool scalesWithDifficulty();
21+
virtual std::shared_ptr<ClientboundChatPacket>
22+
getDeathMessagePacket(std::shared_ptr<LivingEntity> entity);
23+
virtual Vec3* getSourcePosition();
24+
virtual DamageSource* copy();
2225
virtual void GetBaseDamageSource();
2326

27+
DamageSource* setMagic();
28+
2429
bool isBypassInvul() const;
2530
bool isFire() const;
26-
bool isProjectile() const;
2731
bool isExplosion() const;
32+
bool isProjectile() const;
33+
34+
protected:
35+
bool mBypassArmour;
36+
bool mBypassInvul;
37+
bool field_0xa;
38+
float mExhaustion;
39+
bool mIsFireSource;
40+
bool mIsExplosion;
41+
bool mScalesWithDifficulty;
42+
bool mIsThorns;
43+
bool mIsProjectile;
44+
bool field_0x15;
45+
ClientboundChatPacket::EChatPacketMessage field_0x18;
46+
ClientboundChatPacket::EChatPacketMessage field_0x1a;
47+
bool mIsMagic;
2848
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "net/minecraft/world/damagesource/EntityDamageSource.h"
2+
3+
// there's some wild shit going on with std::shared_ptr<Entity> mEntity
4+
// it's getting referenced by 0x28 instead of 0x20
5+
// i already tried using `unsigned short` for `EChatPacketMessage` enum, it fixes EntityDamageSource, but then
6+
// it breaks DamageSource constructor
7+
// i wish i knew why...
8+
9+
// NON_MATCHING | Score: 25 (lower is better)
10+
// mEntity is located at 0x28 instead of 0x20, read above
11+
EntityDamageSource::EntityDamageSource(ClientboundChatPacket::EChatPacketMessage unk0,
12+
ClientboundChatPacket::EChatPacketMessage unk1,
13+
std::shared_ptr<Entity> entity)
14+
: DamageSource(unk0, unk1) {
15+
this->mEntity = entity;
16+
this->field_0x30 = false;
17+
}
18+
19+
// NON_MATCHING | Score: 10 (lower is better)
20+
// mEntity is located at 0x28 instead of 0x20, read above
21+
EntityDamageSource::~EntityDamageSource() {}
22+
23+
// NON_MATCHING | Score: 15 (lower is better)
24+
// mEntity is located at 0x28 instead of 0x20, read above
25+
std::shared_ptr<Entity> EntityDamageSource::getEntity() {
26+
return this->mEntity;
27+
}
28+
29+
// NON_MATCHING | Score: 10 (lower is better)
30+
// mEntity is located at 0x28 instead of 0x20, read above
31+
bool EntityDamageSource::scalesWithDifficulty() {
32+
return this->mEntity && this->mEntity->isType(eLivingEntity) && !this->mEntity->isType(ePlayer);
33+
}
34+
// NON_MATCHING | Score: 10 (lower is better)
35+
// mEntity is located at 0x28 instead of 0x20 and Vec3::newTemp is at wrong address
36+
Vec3* EntityDamageSource::getSourcePosition() {
37+
return Vec3::newTemp(this->mEntity->mX, this->mEntity->mY, this->mEntity->mZ);
38+
}
39+
// NON_MATCHING | Score: 5 (lower is better)
40+
// continue pulling 2 extra bytes offset out of your ass
41+
DamageSource* EntityDamageSource::copy() {
42+
return new EntityDamageSource(*this);
43+
}
44+
45+
EntityDamageSource* EntityDamageSource::setThorns() {
46+
this->mIsThorns = true;
47+
return this;
48+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include "net/minecraft/world/damagesource/DamageSource.h"
4+
#include "net/minecraft/world/entity/Entity.h"
5+
#include <memory>
6+
7+
class EntityDamageSource : public DamageSource {
8+
public:
9+
EntityDamageSource(ClientboundChatPacket::EChatPacketMessage, ClientboundChatPacket::EChatPacketMessage,
10+
std::shared_ptr<Entity> entity);
11+
~EntityDamageSource() override;
12+
13+
std::shared_ptr<Entity> getEntity() override;
14+
bool scalesWithDifficulty() override;
15+
std::shared_ptr<ClientboundChatPacket>
16+
getDeathMessagePacket(std::shared_ptr<LivingEntity> entity) override;
17+
Vec3* getSourcePosition() override;
18+
DamageSource* copy() override;
19+
20+
EntityDamageSource* setThorns();
21+
22+
private:
23+
std::shared_ptr<Entity> mEntity;
24+
bool field_0x30;
25+
};

src/Minecraft.World/net/minecraft/world/enchantment/enchantments/ProtectionEnchantment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ int ProtectionEnchantment::getDamageProtection(int level, const DamageSource* so
4444
return level * 2;
4545
} else if (this->mType == FALL && source == DamageSource::BYPASS_ARMOUR) {
4646
return level * 3;
47-
} else if (this->mType == EXPLOSION && source->isExplosion()) {
47+
} else if (this->mType == PROJECTILE && source->isProjectile()) {
4848
return level * 2;
4949
} else {
50-
return this->mType == PROJECTILE && source->isProjectile() ? level * 2 : 0;
50+
return this->mType == EXPLOSION && source->isExplosion() ? level * 2 : 0;
5151
}
5252
}
5353
bool ProtectionEnchantment::checkCompatibility(const Enchantment* other) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
class FoodConstants {
4+
public:
5+
static float ExhaustionAttack();
6+
};

0 commit comments

Comments
 (0)