gpt4 book ai didi

C - 在非结构或 union 中请求成员 ‘x’

转载 作者:行者123 更新时间:2023-11-30 16:38:27 30 4
gpt4 key购买 nike

上下文:我正在尝试对一款名为 Grand Theft Auto V 的游戏进行一些修改。

我正在使用GET_ENTITY_COORDS获取游戏中实体坐标的函数:

static Inline struct Vector3 GET_ENTITY_COORDS(Entity entity, BOOL alive) {
args[0] = entity;
args[1] = alive;
invokeNative(0x3FEF770D40960D5A);
struct Vector3 vector3 = { *(float*)&rets[0], *(float*)&rets[1], *(float*)&rets[2] };
return vector3;
}

这应该返回xPos , yPoszPos .

<小时/>

现在这是我目前正在努力解决的代码:

#include "gta.h"

void invokeNative_s(u64 hash) {
struct Native_s** g_Natives = (struct Native_s**)NativeTableAddress;
struct Native_s* Natives = g_Natives[hash & 0xFF];
while (Natives != 0) {
for (unsigned int i = 0; i < Natives->NativeCount; i++) {
if (Natives->NativeHashes[i] == hash) {
((void(*)(struct NativeArg_s*))Natives->NativeFunctions[i])((struct NativeArg_s*)FreeSpaceAddress);
return;
}
}
Natives = Natives->LastNativeTable;
}
}

struct gtaVars_s {
BOOL init;
int frameCount;
};

static struct gtaVars_s *gtaVars = (struct gtaVars_s*)FreeSpaceAddress+0x100;

BOOL nativeHook() {
if (!gtaVars->init) {
nativeArg->ArgValues = args;
nativeArg->ReturnValue = rets;
gtaVars->frameCount = 0;
gtaVars->init = TRUE;
}

int newFrameCount = GET_FRAME_COUNT();
if (gtaVars->frameCount < newFrameCount) {
gtaVars->frameCount = newFrameCount;

Ped pedID = PLAYER_PED_ID();
Player playerID = PLAYER_ID();

/* define player coords */
Vector3 playerCoords = GET_ENTITY_COORDS(pedID, 1);
char waterRadius = 10;

SET_SUPER_JUMP_THIS_FRAME(playerID);
SET_PLAYER_INVINCIBLE(playerID, TRUE);

if (IS_CONTROL_JUST_PRESSED(0, Button_Tpad)) {
// teleport to beach
SET_ENTITY_COORDS(pedID, -1374.881, -1398.835, 6.141, FALSE, FALSE, FALSE, TRUE);

// set water
MODIFY_WATER(playerCoords.x, playerCoords.y, waterRadius, 10);
MODIFY_WATER(playerCoords.x+2, playerCoords.y, waterRadius, 10);
MODIFY_WATER(playerCoords.x, playerCoords.y+2, waterRadius, 10);
MODIFY_WATER(playerCoords.x+2, playerCoords.y+2, waterRadius, 10);
MODIFY_WATER(playerCoords.x+4, playerCoords.y, waterRadius, 10);
MODIFY_WATER(playerCoords.x, playerCoords.y+4, waterRadius, 10);
MODIFY_WATER(playerCoords.x+4, playerCoords.y+4, waterRadius, 10);
MODIFY_WATER(playerCoords.x+6, playerCoords.y, waterRadius, 10);
MODIFY_WATER(playerCoords.x, playerCoords.y+6, waterRadius, 10);
MODIFY_WATER(playerCoords.x+6, playerCoords.y+6, waterRadius, 10);
MODIFY_WATER(playerCoords.x+8, playerCoords.y, waterRadius, 10);
MODIFY_WATER(playerCoords.x, playerCoords.y+8, waterRadius, 10);
MODIFY_WATER(playerCoords.x+8, playerCoords.y+8, waterRadius, 10);
}
}

return TRUE;
}

但是我从 GET_ENTITY_COORDS 收到多个错误即使我在脚本中定义了上面的函数,它仍然可以运行:

source/gta.c:42:3: error: unknown type name ‘Vector3’
Vector3 playerCoords = GET_ENTITY_COORDS(pedID, 1);
^
source/gta.c:42:26: error: incompatible types when initializing type ‘int’ using type ‘struct Vector3’
Vector3 playerCoords = GET_ENTITY_COORDS(pedID, 1);
^
source/gta.c:53:29: error: request for member ‘x’ in something not a structure or union

有谁知道这个错误的原因是什么,以及如何修复它?我将非常感激,因为我已经为此苦苦挣扎了好几天,并且希望看到它得到解决,提前谢谢您。

最佳答案

如您的一些代码片段所示Vector3的用法如下:

static Inline struct Vector3 GET_ENTITY_COORDS

因此,既然这是有效的,这意味着它被定义为(在某些我们看不到的代码中)struct,而不是定义为 typedef struct(这将允许在没有 struct 关键字的情况下使用它)。

您的错误是在将变量声明为 Vector3 时出现的:

Vector3 playerCoords = GET_ENTITY_COORDS(pedID, 1);

应该是

struct Vector3 playerCoords = GET_ENTITY_COORDS(pedID, 1);

其余的错误只是该错误的结果。解析器此时丢失。

关于C - 在非结构或 union 中请求成员 ‘x’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47480829/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com