Skip to content

Commit

Permalink
Added|Deh Reader: Support [CODEPTR] DeHackEd patches
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 12, 2012
1 parent e1603af commit ff670e9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 36 deletions.
1 change: 1 addition & 0 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -259,6 +259,7 @@ enum {
DD_PLUGIN_HOMEURL,
DD_PLUGIN_DOCSURL,
DD_DMU_VERSION, ///< Used in the exchange of DMU API versions.
DD_DEF_ACTION,

// Non-integer/special values for Set/Get
DD_TRANSLATIONTABLES_ADDRESS,
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/def_main.h
Expand Up @@ -85,6 +85,7 @@ int Def_GetMobjNumForName(const char* name);
const char* Def_GetMobjName(int num);
int Def_GetStateNum(const char* id);
const char* Def_GetStateName(state_t* state);
int Def_GetActionNum(const char* id);
int Def_GetSpriteNum(const char* name);
int Def_GetModelNum(const char* id);
int Def_GetMusicNum(const char* id);
Expand Down
20 changes: 20 additions & 0 deletions doomsday/engine/portable/src/def_main.c
Expand Up @@ -347,6 +347,23 @@ acfnptr_t Def_GetActionPtr(const char* name)
return 0;
}

int Def_GetActionNum(const char* name)
{
if(name && name[0] && DD_GameLoaded())
{
// Action links are provided by the game, who owns the actual action functions.
actionlink_t* links = (actionlink_t*) gx.GetVariable(DD_ACTION_LINK);
actionlink_t* linkIt;
for(linkIt = links; linkIt && linkIt->name; linkIt++)
{
actionlink_t* link = linkIt;
if(!stricmp(name, link->name))
return linkIt - links;
}
}
return -1; // Not found.
}

ded_mapinfo_t* Def_GetMapInfo(const Uri* uri)
{
int i;
Expand Down Expand Up @@ -1731,6 +1748,9 @@ int Def_Get(int type, const char* id, void* out)
case DD_DEF_STATE:
return Def_GetStateNum(id);

case DD_DEF_ACTION:
return Def_GetActionNum(id);

case DD_DEF_SPRITE:
return Def_GetSpriteNum(id);

Expand Down
80 changes: 44 additions & 36 deletions doomsday/plugins/dehread/src/dehmain.c
Expand Up @@ -1968,49 +1968,57 @@ static int parsePars(int dummy)

static int parseCodePtr(int dummy)
{
LPrintf("Warning: [CodePtr] patches not supported.\n");
return skipToNextLine();

/* int result;
int result;

LPrintf ("[CodePtr]\n");
DENG_UNUSED(dummy);

while ((result = GetLine()) == 1)
{
if (!strnicmp ("Frame", Line1, 5) && isspace(Line1[5]))
{
int frame = atoi (Line1 + 5);
while((result = GetLine()) == 1)
{
if(!strnicmp("Frame", Line1, 5) && isspace(Line1[5]))
{
int stateNum = atoi(Line1 + 5);
ded_state_t* def;
char buff[32];

if (frame < 0 || frame >= NUMSTATES)
{
Printf (PRINT_HIGH, "Frame %d out of range\n", frame);
}
else
{
int i = 0;
char *data;
if(stateNum < 0 && stateNum >= ded->count.states.num)
{
LPrintf("State %d out of range (Create more State defs!)\n", stateNum);
continue;
}
def = &ded->states[stateNum];

parseToken (Line2);
// Skip the assignment operator.
parseToken(Line2);

if ((com_token[0] == 'A' || com_token[0] == 'a') && com_token[1] == '_')
data = com_token + 2;
else
data = com_token;
// Compose the action name.
if((com_token[0] == 'A' || com_token[0] == 'a') && com_token[1] == '_')
strncpy(buff, com_token, 32);
else
dd_snprintf(buff, 32, "A_%s", com_token);

while (CodePtrs[i].name && stricmp (CodePtrs[i].name, data))
i++;
// Is this a known action?
if(!stricmp(buff, "A_NULL"))
{
strcpy(def->action, "NULL");
#if _DEBUG
VERBOSE2( LPrintf("State \"%s\" (#%i) Action is now \"NULL\".\n", def->id, (int)stateNum) )
#endif
}
else if(Def_Get(DD_DEF_ACTION, buff, 0) >= 0)
{
strcpy(def->action, buff);
#if _DEBUG
VERBOSE2( LPrintf("State \"%s\" (#%i) Action is now \"%s\".\n", def->id, (int)stateNum, def->action) )
#endif
}
else
{
LPrintf("Unknown action \"%s\".\n", buff);
}
}
}

if (CodePtrs[i].name) {
states[frame].action.acp1 = CodePtrs[i].func.acp1;
DPrintf ("Frame %d set to %s\n", frame, CodePtrs[i].name);
} else {
states[frame].action.acp1 = NULL;
DPrintf ("Unknown code pointer: %s\n", com_token);
}
}
}
}
return result; */
return result;
}

static void replaceInString(char* haystack, size_t len, const char* needle,
Expand Down

0 comments on commit ff670e9

Please sign in to comment.