Skip to content

Commit

Permalink
添加实体朝向相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
HalcyonAlcedo committed May 18, 2021
1 parent 118e5b3 commit 236b7d8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace Base {
//可设置参数
string ModName = "LuaScript";
string ModAuthor = "Alcedo";
string ModVersion = "v1.2.1 Dev";
long long ModBuild = 121005181015;
string ModVersion = "v1.2.1 Beta";
long long ModBuild = 121005181559;
string Version = "421470";
}
#pragma endregion
Expand Down
36 changes: 33 additions & 3 deletions Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,13 @@ namespace Component {
Base::Vector3 Coordinate;
Base::Vector3 Size;
Base::Vector3 Action;
float Angle;
EntityProperties(
Base::Vector3 Coordinate = Base::Vector3(),
Base::Vector3 Size = Base::Vector3(),
Base::Vector3 Action = Base::Vector3())
:Coordinate(Coordinate), Size(Size), Action(Action) {
Base::Vector3 Action = Base::Vector3(),
float Angle = 0)
:Coordinate(Coordinate), Size(Size), Action(Action), Angle(Angle) {
};
};
static EntityProperties GetEntityProperties(string ptr) {
Expand Down Expand Up @@ -844,7 +846,13 @@ namespace Component {
*(float*)(Ptr + 0x184),
*(float*)(Ptr + 0x188)
),
Action
Action,
Base::Calculation::QuaternionToAngle(Base::Vector4(
*(float*)(Ptr + 0x174),
*(float*)(Ptr + 0x178),
*(float*)(Ptr + 0x17C),
*(float*)(Ptr + 0x180)
))
);
}
return EntityProperties();
Expand Down Expand Up @@ -879,6 +887,28 @@ namespace Component {
*offsetPtr<float>(ActionPlot, 0x10c) = ActionFrame;
}
}
static void SetEntityAngle(string ptr, float angle) {
long long Ptr = 0;
sscanf_s(ptr.c_str(), "%p", &Ptr, sizeof(long long));
void* EntityAddress = (double*)Ptr;
if (EntityAddress != nullptr) {
Base::Vector4 quaternion = Base::Calculation::AngleToQuaternion(angle);
*offsetPtr<float>((undefined(*)())Ptr, 0x174) = quaternion.x;
*offsetPtr<float>((undefined(*)())Ptr, 0x17C) = quaternion.z;
}
}
static void SetEntityAimCoordinate(string ptr, Base::Vector2 aim) {
long long Ptr = 0;
sscanf_s(ptr.c_str(), "%p", &Ptr, sizeof(long long));
void* EntityAddress = (double*)Ptr;
if (EntityAddress != nullptr) {
float direction_x = (aim.x - *(float*)(Ptr + 0x180));
float direction_z = (aim.y - *(float*)(Ptr + 0x188));
float aim_angle = std::atan(direction_x / direction_z);
aim_angle = aim_angle + sign(direction_x) * (1 - sign(direction_z)) * M_PI / 2;
SetEntityAngle(ptr,aim_angle);//设置角度
}
}
#pragma endregion
#pragma region GetMonstersName_CN
static string GetMonstersName_CN(int id) {
Expand Down
21 changes: 21 additions & 0 deletions LuaScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ static int Game_Entity_GetEntityProperties(lua_State* pL) {
lua_settable(pL, -3);
lua_settable(pL, -3);

lua_pushstring(pL, "Angle");
lua_pushnumber(pL, entityProperties.Angle);
lua_settable(pL, -3);

return 1;
}
static int Game_Entity_SetEntityCoordinate(lua_State* pL) {
Expand All @@ -967,6 +971,19 @@ static int Game_Entity_SetEntityActionFrame(lua_State* pL) {
Component::SetEntityActionFrame(entity, nowFrame);
return 0;
}
static int Game_Entity_SetEntityAngle(lua_State* pL) {
string entity = "0x" + (string)lua_tostring(pL, 1);
float angle = (float)lua_tonumber(pL, 2);
Component::SetEntityAngle(entity, angle);
return 0;
}
static int Game_Entity_SetEntityAimCoordinate(lua_State* pL) {
string entity = "0x" + (string)lua_tostring(pL, 1);
float x = (float)lua_tonumber(pL, 2);
float z = (float)lua_tonumber(pL, 3);
Component::SetEntityAimCoordinate(entity, Base::Vector2(x,z));
return 0;
}
#pragma endregion
#pragma region SystemFun
static int System_Keyboard_CheckKey(lua_State* pL) {
Expand Down Expand Up @@ -1689,6 +1706,10 @@ int Lua_Main(string LuaFile)
lua_register(L, "Game_Entity_SetEntitySize", Game_Entity_SetEntitySize);
//设置实体当前动作帧
lua_register(L, "Game_Entity_SetEntityActionFrame", Game_Entity_SetEntityActionFrame);
//设置实体朝向角度
lua_register(L, "Game_Entity_SetEntityAngle", Game_Entity_SetEntityAngle);
//将实体朝向指定的坐标
lua_register(L, "Game_Entity_SetEntityAimCoordinate", Game_Entity_SetEntityAimCoordinate);
#pragma endregion

#pragma endregion
Expand Down

0 comments on commit 236b7d8

Please sign in to comment.