Skip to content

Commit 5642557

Browse files
committed
fixed "unknown item" when trying to get item name by reading name from game memory, added player Velocity field
1 parent 7c229ac commit 5642557

File tree

5 files changed

+84
-14
lines changed

5 files changed

+84
-14
lines changed

Sources/Player/Inventory.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,14 @@ static int l_Inventory_Slot_class_index(lua_State *L)
103103
lua_pushinteger(L, Minecraft::GetItemData(slotIndex));
104104
break;
105105
case hash("ItemName"): {
106-
auto itemsList = Minecraft::GetItemList();
107106
u32 itemID = Minecraft::GetItemID(slotIndex);
108-
u32 currItemID;
109-
bool found = false;
110-
for (auto item : itemsList) {
111-
CTRPF::Process::Read32(item.idAddress, currItemID);
112-
if (currItemID == itemID) {
113-
lua_pushstring(L, item.name.c_str());
114-
found = true;
115-
break;
116-
}
107+
if (itemID == 0) {
108+
lua_pushstring(L, "empty_slot");
109+
} else {
110+
int *itemAddr = (int*)itemID;
111+
char *itemNameIDAddr = (char*)*(itemAddr + 6);
112+
lua_pushstring(L, itemNameIDAddr);
117113
}
118-
if (!found)
119-
lua_pushstring(L, "Unknown Item");
120114
break;
121115
}
122116
default:

Sources/Player/Player.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,53 @@ static const luaL_Reg player_position_methods[] =
6464

6565
// ----------------------------------------------------------------------------
6666

67+
//$Game.LocalPlayer.Velocity
68+
69+
/*
70+
- Gets local player velocity
71+
## return: number
72+
## return: number
73+
## return: number
74+
### Game.LocalPlayer.Velocity.get
75+
*/
76+
static int l_Player_Velocity_get(lua_State *L)
77+
{
78+
float x = Minecraft::GetVelocityX();
79+
float y = Minecraft::GetVelocityY();
80+
float z = Minecraft::GetVelocityZ();
81+
lua_pushnumber(L, x);
82+
lua_pushnumber(L, y);
83+
lua_pushnumber(L, z);
84+
return 1;
85+
}
86+
87+
/*
88+
- Sets player velocity
89+
## x: number
90+
## y: number
91+
## z: number
92+
### Game.LocalPlayer.Velocity.set
93+
*/
94+
static int l_Player_Velocity_set(lua_State *L)
95+
{
96+
float x = luaL_checknumber(L, 1);
97+
float y = luaL_checknumber(L, 2);
98+
float z = luaL_checknumber(L, 3);
99+
Minecraft::SetVelocityX(x);
100+
Minecraft::SetVelocityY(y);
101+
Minecraft::SetVelocityZ(z);
102+
return 0;
103+
}
104+
105+
static const luaL_Reg player_velocity_methods[] =
106+
{
107+
{"get", l_Player_Velocity_get},
108+
{"set", l_Player_Velocity_set},
109+
{NULL, NULL}
110+
};
111+
112+
// ----------------------------------------------------------------------------
113+
67114
/*
68115
=Game.LocalPlayer.OnGround = false
69116
=Game.LocalPlayer.Sneaking = false
@@ -293,6 +340,7 @@ bool Core::Game::RegisterLocalPlayerModule(lua_State *L)
293340
lua_newtable(L); // LocalPlayer
294341

295342
luaC_register_field(L, player_position_methods, "Position");
343+
luaC_register_field(L, player_velocity_methods, "Velocity");
296344
Core::Game::LocalPlayer::RegisterCameraModule(L);
297345
Core::Game::LocalPlayer::RegisterInventoryModule(L);
298346

Sources/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#define IS_TARGET_ID(id) ((id) == 0x00040000001B8700LL || (id) == 0x000400000017CA00LL || (id) == 0x000400000017FD00LL)
2929

3030
#define PLUGIN_VERSION_MAJOR 0
31-
#define PLUGIN_VERSION_MINOR 7
32-
#define PLUGIN_VERSION_PATCH 3
31+
#define PLUGIN_VERSION_MINOR 8
32+
#define PLUGIN_VERSION_PATCH 0
3333
#define PLUGIN_FOLDER "sdmc:/Minecraft 3DS"
3434
#define LOG_FILE PLUGIN_FOLDER"/log.txt"
3535
#define CONFIG_FILE PLUGIN_FOLDER"/config.txt"

api_docs.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ function Game.LocalPlayer.Position.get() end
212212
---@param z number
213213
function Game.LocalPlayer.Position.set(x, y, z) end
214214

215+
Game.LocalPlayer.Velocity = {}
216+
217+
---Gets local player velocity
218+
---@return number
219+
---@return number
220+
---@return number
221+
function Game.LocalPlayer.Velocity.get() end
222+
223+
---Sets player velocity
224+
---@param x number
225+
---@param y number
226+
---@param z number
227+
function Game.LocalPlayer.Velocity.set(x, y, z) end
228+
215229
Game.LocalPlayer.OnGround = false
216230

217231
Game.LocalPlayer.Sneaking = false
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
local Gamepad = Game.Gamepad
2+
local Debug = Game.Debug
3+
4+
Game.Event.OnKeyPressed:Connect(function ()
5+
if Gamepad.isPressed(Gamepad.KeyCodes.DPADDOWN) then
6+
if Game.World.Loaded then
7+
local playerHand = Game.LocalPlayer.Inventory.Slots["hand"]
8+
local itemIDHex = string.format("%X", playerHand.ItemID)
9+
Debug.message("ItemID: "..itemIDHex)
10+
Debug.message("Item Name: "..playerHand.ItemName)
11+
Debug.message("Item Data: "..playerHand.ItemData)
12+
end
13+
end
14+
end)

0 commit comments

Comments
 (0)