gist/ed_parseedict.c

190 lines
5.1 KiB
C

// this isn't a compilable code
// provided just for reference
// don't believe Ghidra output
bool __regparm3 SuckOutClassname(char *szInputStream,edict_t *pEdict)
{
int iVar1;
bool bVar2;
int iVar3;
char *data;
int in_GS_OFFSET;
KeyValueData kvd;
bool szKeyName [256];
iVar1 = *(int *)(in_GS_OFFSET + 0x14);
kvd.szClassName = (char *)0x0;
kvd.szValue = "";
kvd.fHandled = 0;
kvd.szKeyName = szKeyName;
do {
data = COM_Parse(szInputStream);
if ((data == (char *)0x0) || (com_token[0] == '}')) {
bVar2 = false;
goto LAB_000d4d0f;
}
Q_strncpy(szKeyName,com_token,0xff);
szKeyName[255] = false;
szInputStream = COM_Parse(data);
if (szInputStream == (char *)0x0) break;
iVar3 = Q_strcmp(szKeyName,"classname");
} while (iVar3 != 0);
kvd.szValue = com_token;
(*gEntityInterface.pfnKeyValue)(pEdict,&kvd);
if (kvd.fHandled == 0) {
/* WARNING: Subroutine does not return */
Host_Error("SuckOutClassname: parse error");
}
bVar2 = true;
LAB_000d4d0f:
if (iVar1 == *(int *)(in_GS_OFFSET + 0x14)) {
return bVar2;
}
/* WARNING: Subroutine does not return */
__stack_chk_fail();
}
char * ED_ParseEdict(char *data,edict_t *ent)
{
bool bVar1;
char *pcVar2;
if (sv.edicts != ent) {
Q_memset(&ent->v,0,0x2a4);
}
(ent->v).pContainingEntity = ent;
bVar1 = SuckOutClassname(data,ent);
if (!bVar1) {
ent->serialnumber = ent->serialnumber + 1;
ent->free = true;
return data;
}
pcVar2 = ED_ParseEdict(data,ent);
return pcVar2;
}
char * __regparm3 ED_ParseEdict(char *data,edict_t *ent)
{
bool bVar1;
code *pcVar2;
char *data_00;
int iVar3;
char *pcVar4;
int in_GS_OFFSET;
float fVar5;
KeyValueData kvd;
char keyname [256];
int local_20;
local_20 = *(int *)(in_GS_OFFSET + 0x14);
pcVar2 = (code *)GetEntityInit(pr_strings + (ent->v).classname);
if (pcVar2 == (code *)0x0) {
pcVar2 = (code *)GetEntityInit("custom");
if (pcVar2 == (code *)0x0) {
Con_DPrintf("Can\'t init %s\n",pr_strings + (ent->v).classname);
bVar1 = false;
}
else {
(*pcVar2)(&ent->v);
kvd.szClassName = "custom";
kvd.szKeyName = "customclass";
kvd.fHandled = 0;
kvd.szValue = pr_strings + (ent->v).classname;
(*gEntityInterface.pfnKeyValue)(ent,&kvd);
bVar1 = true;
}
}
else {
(*pcVar2)(&ent->v);
bVar1 = true;
}
LAB_000d4de0:
data_00 = COM_Parse(data);
if (com_token[0] == '}') {
if (!bVar1) {
ent->serialnumber = ent->serialnumber + 1;
ent->free = true;
}
if (local_20 == *(int *)(in_GS_OFFSET + 0x14)) {
return data_00;
}
/* WARNING: Subroutine does not return */
__stack_chk_fail();
}
if (data_00 == (char *)0x0) {
/* WARNING: Subroutine does not return */
Sys_Error("ED_ParseEntity: EOF without closing brace");
}
Q_strncpy(keyname,com_token,0xff);
keyname[255] = '\0';
iVar3 = Q_strlen(keyname);
if ((iVar3 != 0) && (keyname[iVar3 + -1] == ' ')) {
pcVar4 = keyname + iVar3 + -1;
do {
*pcVar4 = '\0';
if (keyname == pcVar4) break;
pcVar4 = pcVar4 + -1;
} while (*pcVar4 == ' ');
}
data = COM_Parse(data_00);
if (data == (char *)0x0) {
/* WARNING: Subroutine does not return */
Host_Error("ED_ParseEntity: EOF without closing brace");
}
if (com_token[0] == '}') {
/* WARNING: Subroutine does not return */
Host_Error("ED_ParseEntity: closing brace without data");
}
if (pr_strings + (ent->v).classname != (char *)0x0) goto code_r0x000d4e7a;
goto LAB_000d4e93;
code_r0x000d4e7a:
iVar3 = Q_strcmp(pr_strings + (ent->v).classname,com_token);
if (iVar3 != 0) {
LAB_000d4e93:
iVar3 = Q_strcmp(keyname,"angle");
if (iVar3 == 0) {
/* Begin: lexical_block_0 - Disjoint */
fVar5 = Q_atof(com_token);
if (fVar5 < 0.0) {
if ((int)fVar5 == -1) {
com_token[0] = '-';
com_token[1] = '9';
com_token[2] = '0';
com_token[3] = ' ';
/* Begin: inline int snprintf(char * __s, size_t __n, char * __fmt, ...) */
com_token[4] = '0';
com_token[5] = ' ';
com_token[6] = '0';
com_token[7] = '\0';
}
else {
com_token[0] = '9';
com_token[1] = '0';
com_token[2] = ' ';
com_token[3] = '0';
/* Begin: inline int snprintf(char * __s, size_t __n, char * __fmt, ...) */
com_token[4] = ' ';
com_token[5] = '0';
com_token[6] = '\0';
}
}
else {
/* Begin: inline int snprintf(char * __s, size_t __n, char * __fmt, ...) */
__snprintf_chk(com_token,0x800,1,0x800,"%f %f %f",(double)(ent->v).angles[0],(double)fVar5,
(double)(ent->v).angles[2]);
}
Q_strcpy(keyname,"angles");
}
kvd.szValue = com_token;
kvd.szClassName = pr_strings + (ent->v).classname;
kvd.fHandled = 0;
kvd.szKeyName = keyname;
(*gEntityInterface.pfnKeyValue)(ent,&kvd);
}
goto LAB_000d4de0;
}