Skip to content

Commit

Permalink
EntityApi Test
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamguxiang committed Feb 8, 2023
1 parent 4d6192f commit 5667b27
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 44 deletions.
2 changes: 1 addition & 1 deletion LiteLoader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ file(
# third-party source files
file(GLOB_RECURSE THIRD_PARTY_SRC_FILES ${PROJECT_SOURCE_DIR}/third-party/src/*)

add_library(LiteLoader SHARED ${SRC_FILES} ${THIRD_PARTY_SRC_FILES})
add_library(LiteLoader SHARED ${SRC_FILES} ${THIRD_PARTY_SRC_FILES} "include/llapi/mod/CustomActor.h")

# Replace Compile Flag /EHsc to /EHa
string(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
Expand Down
1 change: 1 addition & 0 deletions LiteLoader/include/llapi/GlobalServiceAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class LevelStorage;
class BlockDefinitionGroup;
class ItemRegistryRef;
class Recipes;
class ActorInfoRegistry;
#ifdef LITELOADER_EXPORTS
template <typename T>
LIAPI inline T* Global = nullptr;
Expand Down
66 changes: 64 additions & 2 deletions LiteLoader/include/llapi/ModAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
#include "llapi/mc/Recipes.hpp"
#include "llapi/mc/ItemInstance.hpp"
#include "llapi/mod/CustomRecipe.h"
#include "llapi/mc/ActorFactory.hpp"
#include "llapi/mc/ActorFactoryData.hpp"
#include "llapi/mc/ActorMapping.hpp"
#include "llapi/mc/ActorInfoRegistry.hpp"
typedef std::unordered_map<std::string, ActorFactoryData> ActorDataMap;
typedef std::unordered_map<ActorType, ActorMapping> ActorMappingMap;


namespace ll {
namespace mod {
// Register Block
Expand Down Expand Up @@ -63,13 +71,67 @@ static void registerShapelessRecipe(std::string recipeId) {
}

template <class T>
requires std::is_base_of<CustomFurnaceRecipe, T>::value
requires std::is_base_of<CustomFurnaceRecipe, T>::value
static void registerFurnaceRecipe() {
SharedPtr<T> FurnaceRecipe = SharedPtr<T>::make();
return Global<Recipes>->addFurnaceRecipeAuxData(FurnaceRecipe->getInput(), FurnaceRecipe->getResult(),
FurnaceRecipe->getTags());
}

namespace ActorRegistry {

ActorDataMap& GetActorDataRegistry() {
return SymCall("?GetActorDataRegistry@@YAAEAV?$unordered_map@V?$basic_string"
"@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UActorFactoryData@@U?$ha"
"sh@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$"
"equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@"
"@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$a"
"llocator@D@2@@std@@UActorFactoryData@@@std@@@2@@std@@XZ",
ActorDataMap&)();
}

ActorMappingMap& GetActorMappingMap() {
return *(std::unordered_map<ActorType, ActorMapping>*)dlsym_real(
"?ENTITY_TYPE_MAP@@3V?$unordered_map@W4ActorType@@UActorMapping@@U?$hash@W4ActorType@@@std@@U?$equal_to@"
"W4ActorType@@@4@V?$allocator@U?$pair@$$CBW4ActorType@@UActorMapping@@@std@@@4@@std@@A");
}


template <typename T>
__declspec(noinline)
static std::unique_ptr<Actor> _actorFromClass(
class ActorDefinitionGroup* definitions, struct ActorDefinitionIdentifier const& definitionName,
class EntityContext& context) {
return std::make_unique<T>(definitions, definitionName, context);
}

template <typename T, ActorType Type>
void _registerActorData(const std::string& fullName, bool allowSummon, std::optional<int> experimental,
float walkAnimSpeed = 0.0f) {
ActorFactoryData afd;
afd.mIdentifier = ActorDefinitionIdentifier(fullName);
afd.mBaseIdentifier = ActorDefinitionIdentifier();
afd.mAllowSummon = allowSummon;
afd.mFactory = _actorFromClass<T>;
afd.mExperimentIndex = experimental;
afd.mActorType = Type;
afd.mWalkAnimSpeed = walkAnimSpeed;
GetActorDataRegistry()[fullName] = afd;
}


}

#include <llapi/mc/ResourceLocation.hpp>

template <typename T,ActorType Type>
static void registerActor(const std::string& typeName, bool allowSummon, bool hasSpawnEgg) {
ActorRegistry::_registerActorData<T, Type>(typeName, allowSummon, 0, 0.5);
Global<ActorInfoRegistry>->registerActorInfo(
ActorInfo((int)Type, ActorDefinitionIdentifier(typeName), hasSpawnEgg, allowSummon, 0));
//ActorFactory::registerEntityMapping(Type, false, &ActorRegistry::_actorFromClass<T>, 0);
}

} // namespace mod
} // namespace ll
} // namespace ll

52 changes: 32 additions & 20 deletions LiteLoader/include/llapi/mc/Actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Actor {

#define AFTER_EXTRA
// Add new members to class
char filler[0x5B8];

public:
enum class InitializationMethod;

Expand Down Expand Up @@ -154,6 +156,8 @@ class Actor {
* @hash 979365551
*/
virtual void outOfWorld();

protected:
/**
* @vftbl 10
* @symbol ?reloadHardcoded@Actor@@MEAAXW4InitializationMethod@1@AEBVVariantParameterList@@@Z
Expand Down Expand Up @@ -190,6 +194,8 @@ class Actor {
* @hash 1099438822
*/
virtual void _doInitialMove();

public:
/**
* @vftbl 16
* @hash 1676995139
Expand Down Expand Up @@ -349,7 +355,7 @@ class Actor {
* @vftbl 42
* @hash -147616318
*/
virtual void __unk_vfn_42();
virtual bool breaksFallingBlocks() const;
/**
* @vftbl 43
* @symbol ?blockedByShield@Actor@@UEAAXAEBVActorDamageSource@@AEAV1@@Z
Expand Down Expand Up @@ -474,7 +480,7 @@ class Actor {
* @vftbl 63
* @hash -96891855
*/
virtual void __unk_vfn_63();
virtual bool canExistInPeaceful() const;
/**
* @vftbl 64
* @symbol ?setNameTagVisible@Actor@@UEAAX_N@Z
Expand Down Expand Up @@ -515,7 +521,7 @@ class Actor {
* @vftbl 70
* @hash -63575907
*/
virtual void __unk_vfn_70();
virtual bool getAlwaysShowNameTag() const;
/**
* @vftbl 71
* @symbol ?setScoreTag@Actor@@UEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
Expand Down Expand Up @@ -598,7 +604,7 @@ class Actor {
* @vftbl 84
* @hash -31252672
*/
virtual void __unk_vfn_84();
virtual bool canSeeInvisible() const;
/**
* @vftbl 85
* @symbol ?canSee@Actor@@UEBA_NAEBV1@@Z
Expand All @@ -615,7 +621,7 @@ class Actor {
* @vftbl 87
* @hash -35939469
*/
virtual void __unk_vfn_87();
virtual bool canInteractWithOtherEntitiesInGame() const;
/**
* @vftbl 88
* @symbol ?isSkyLit@Actor@@UEAA_NM@Z
Expand All @@ -632,7 +638,7 @@ class Actor {
* @vftbl 90
* @hash -6317605
*/
virtual void __unk_vfn_90();
virtual bool interactPreventDefault();
/**
* @vftbl 91
* @symbol ?playerTouch@Actor@@UEAAXAEAVPlayer@@@Z
Expand Down Expand Up @@ -679,7 +685,7 @@ class Actor {
* @vftbl 98
* @hash -6386797
*/
virtual void __unk_vfn_98();
virtual bool isFishable() const;
/**
* @vftbl 99
* @symbol ?isSleeping@Actor@@UEBA_NXZ
Expand All @@ -696,7 +702,7 @@ class Actor {
* @vftbl 101
* @hash 1428946562
*/
virtual void __unk_vfn_101();
virtual bool isShootable();
/**
* @vftbl 102
* @symbol ?setSneaking@Actor@@UEAAX_N@Z
Expand Down Expand Up @@ -737,7 +743,7 @@ class Actor {
* @vftbl 108
* @hash 1435411209
*/
virtual void __unk_vfn_108();
virtual bool isCreativeModeAllowed();
/**
* @vftbl 109
* @symbol ?isSurfaceMob@Actor@@UEBA_NXZ
Expand All @@ -748,12 +754,12 @@ class Actor {
* @vftbl 110
* @hash 1456652192
*/
virtual void __unk_vfn_110();
virtual bool isTargetable() const;
/**
* @vftbl 111
* @hash 1450118353
*/
virtual void __unk_vfn_111();
virtual bool isLocalPlayer() const;
/**
* @vftbl 112
* @symbol ?isRemotePlayer@Actor@@UEBA_NXZ
Expand All @@ -764,7 +770,7 @@ class Actor {
* @vftbl 113
* @hash 1459422755
*/
virtual void __unk_vfn_113();
virtual bool isPlayer() const;
/**
* @vftbl 114
* @symbol ?isAffectedByWaterBottle@Actor@@UEBA_NXZ
Expand Down Expand Up @@ -1183,7 +1189,7 @@ class Actor {
* @vftbl 183
* @hash 1602074556
*/
virtual void __unk_vfn_183();
virtual void changeDimension(class ChangeDimensionPacket const&);
/**
* @vftbl 184
* @symbol ?changeDimension@Actor@@UEAAXV?$AutomaticID@VDimension@@H@@@Z
Expand Down Expand Up @@ -1266,7 +1272,7 @@ class Actor {
* @vftbl 197
* @hash 1692150047
*/
virtual void __unk_vfn_197();
virtual bool isLeashableType();
/**
* @vftbl 198
* @symbol ?tickLeash@Actor@@UEAAXXZ
Expand Down Expand Up @@ -1415,12 +1421,12 @@ class Actor {
* @vftbl 222
* @hash -1937633230
*/
virtual void __unk_vfn_222();
virtual bool hasOutputSignal(unsigned char) const;
/**
* @vftbl 223
* @hash -1919411709
*/
virtual void __unk_vfn_223();
virtual int getOutputSignal() const;
/**
* @vftbl 224
* @symbol ?getDebugText@Actor@@UEAAXAEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@Z
Expand Down Expand Up @@ -1551,7 +1557,7 @@ class Actor {
* @vftbl 245
* @hash -1918058621
*/
virtual void __unk_vfn_245();
virtual void renderDebugServerState(class Options const&);
/**
* @vftbl 246
* @symbol ?reloadLootTable@Actor@@UEAAXXZ
Expand All @@ -1568,7 +1574,7 @@ class Actor {
* @vftbl 248
* @hash -511059482
*/
virtual void __unk_vfn_248();
virtual float getDeletionDelayTimeSeconds() const;
/**
* @vftbl 249
* @symbol ?kill@Actor@@UEAAXXZ
Expand Down Expand Up @@ -1647,6 +1653,8 @@ class Actor {
* @hash -1071764522
*/
virtual void doWaterSplashEffect();

protected:
/**
* @vftbl 262
* @symbol ?_shouldProvideFeedbackOnHandContainerItemSet@Actor@@MEBA_NW4HandSlot@@AEBVItemStack@@@Z
Expand Down Expand Up @@ -1675,7 +1683,7 @@ class Actor {
* @vftbl 266
* @hash -1809581902
*/
virtual void __unk_vfn_266();
virtual bool canMakeStepSound() const;
/**
* @vftbl 267
* @symbol ?_hurt@Actor@@MEAA_NAEBVActorDamageSource@@M_N1@Z
Expand Down Expand Up @@ -1722,7 +1730,7 @@ class Actor {
* @vftbl 274
* @hash -1775342433
*/
virtual void __unk_vfn_274();
virtual bool _makeFlySound() const;
/**
* @vftbl 275
* @symbol ?checkInsideBlocks@Actor@@MEAAXM@Z
Expand Down Expand Up @@ -1753,12 +1761,16 @@ class Actor {
* @hash 879538883
*/
virtual void _removePassenger(struct ActorUniqueID const &, bool, bool, bool);

private:
/**
* @vftbl 280
* @symbol ?_onSizeUpdated@Actor@@EEAAXXZ
* @hash -653470336
*/
virtual void _onSizeUpdated();

public:
#ifdef ENABLE_VIRTUAL_FAKESYMBOL_ACTOR
/**
* @symbol ?_doAutoAttackOnTouch@Actor@@EEAAXAEAV1@@Z
Expand Down
17 changes: 16 additions & 1 deletion LiteLoader/include/llapi/mc/ActorFactoryData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include "../Global.h"

#define BEFORE_EXTRA

#include "ActorDefinitionIdentifier.hpp"
#include "ActorDefinitionGroup.hpp"
#include "EntityContext.hpp"
#include <optional>
using ActorFactoryFunction = std::unique_ptr<Actor>(*)(ActorDefinitionGroup*, const ActorDefinitionIdentifier&,class EntityContext&);
#undef BEFORE_EXTRA

/**
Expand All @@ -18,6 +22,17 @@
struct ActorFactoryData {

#define AFTER_EXTRA
#define DISABLE_CONSTRUCTOR_PREVENTION_ACTORFACTORYDATA
public:
ActorDefinitionIdentifier mIdentifier;
ActorDefinitionIdentifier mBaseIdentifier;
bool mAllowSummon;
ActorFactoryFunction mFactory;
std::optional<int> mExperimentIndex;
ActorType mActorType;
float mWalkAnimSpeed;
bool unk384 = false;


#undef AFTER_EXTRA
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_ACTORFACTORYDATA
Expand Down
20 changes: 18 additions & 2 deletions LiteLoader/include/llapi/mc/ActorInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define BEFORE_EXTRA
// Include Headers or Declare Types Here

#include "ActorDefinitionIdentifier.hpp"
#undef BEFORE_EXTRA

/**
Expand All @@ -19,7 +19,23 @@
struct ActorInfo {

#define AFTER_EXTRA
// Add Member There
// Add Member There
#define DISABLE_CONSTRUCTOR_PREVENTION_ACTORINFO
public:
unsigned int mRuntimeId;
ActorDefinitionIdentifier mIdentifier;
ActorDefinitionIdentifier mBaseIdentifier;
bool mHasSpawnEgg;
bool mIsSummonable;
std::optional<int> mExperimentIndex;

ActorInfo(unsigned int a1, ActorDefinitionIdentifier a2, bool a3, bool a4, std::optional<int> a5)
: mRuntimeId(a1)
, mIdentifier(a2)
, mBaseIdentifier(ActorDefinitionIdentifier())
, mHasSpawnEgg(a3)
, mIsSummonable(a4)
, mExperimentIndex(a5){};

#undef AFTER_EXTRA
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_ACTORINFO
Expand Down
Loading

0 comments on commit 5667b27

Please sign in to comment.