Duke4.net Forums: Hardcoded actors in vanilla Duke3D v1.5? - Duke4.net Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Hardcoded actors in vanilla Duke3D v1.5?

User is offline   n4ud6464 

#1

When playing around with game.con, I noticed that the behavior of some actors cannot be changed no matter what I tried.
For example, this works:

useractor notenemy RUBBERCAN WEAK state breakobject enda

(Garbage cans now use code from the breakobject state)

However, this doesn't work:

useractor notenemy TOILET WEAK state breakobject enda

The state assignment is ignored and toilets follow what looks like hardcoded behavior when hit: change sprite to TOILETBROKE, play GLASS_BREAKING sound, etc..

Is there any way at all to assign custom code to such actors in vanilla Duke3D 1.5 (not eDuke)? Is there a lookup table in the EXE somewhere that has a list of such actors (which makes it ignore game.con code) that can be patched out?

Thanks for any info on this!

This post has been edited by n4ud6464: 13 December 2021 - 05:26 PM

1

User is online   Danukem 

  • Duke Plus Developer

#2

There are many sprites that have hardcoded behavior. Scripted actors are actually the minority in the vanilla game.

https://wiki.eduke32.com/wiki/Statnum

You can put additional code on any sprite using EVENT_GAME regardless of its statnum, which is quite useful. But if you want to completely replace hardcoded behavior, the better option is to make your own tile that is an actor and have the hardcoded tile swap to yours at map load time by changing their picnum. You can do that in EVENT_LOADACTOR
1

User is offline   n4ud6464 

#3

Edit: Thanks to Danukem for the info above as well! I was writing this while they posted. As I understand, EVENT_GAME is an eDuke addition, correct? I'm trying to override hardcoded behavior in vanilla Duke.


To answer my own questions after looking thru some Duke3D source code, a whole bunch of actors ARE hardcoded in various places in the EXE, and it IS possible to assign custom code to them in game.con (instead of the hardcoded stuff) but it's quite annoying - there aren't any lookup tables for these but rather huge switch statements scattered thoughout. So it's either recompiling the source or hex editing some x86 machine code. I went with the latter and here's an example of how I got toilets to execute custom breaking code in game.con:

As above, I added
useractor notenemy TOILET WEAK state breakobject enda
to my game.con where the breakobject state has some code that I want destroying the toilet to execute. This is normally ignored by the game in favor of a hardcoded sequence - I want to patch this hardcoded sequence out.

Two switch statements are responsible for giving TOILET actor hardcoded behavior:
- GAME.C \ spawn() : Assigns specific tags to the actor. If not patched out, actor is not interactive except thru hardcoded sequences.
- SECTOR.C \ checkhitsprite(): The hardcoded sequence itself. If not patched out, overrides any game.con code.

In DUKE3D.EXE v1.5:
spawn() switching code is somewhere around 0x7e800-0x7f000
checkhitsprite() switching code is somewhere around 0xc2000-0xc2800

In these blocks, we want to look for a comparison opcode followed by the ID of the actor we're interested in. TOILET is sprite #569, or 0x239. So we look for hex 66 3D 39 02 and change it to 66 3D FF FF (now the switch statement is looking for sprite with ID -1 instead of the TOILET). Do this for both functions, and toilets now execute game.con code when broken!

Hopefully someone finds this haxx useful!

This post has been edited by n4ud6464: 13 December 2021 - 09:27 PM

2

User is online   Danukem 

  • Duke Plus Developer

#4

Sorry I missed the line in your first post where you specified you were interested in the original DOS Duke only.

What happens if instead of hacking the exe, you make a NEWTOILET actor with the code you want (defined on new tile number with copied art), then use
useractor notenemy TOILET cactor NEWTOILET enda

1

User is offline   n4ud6464 

#5

It looks like it would be ignored as well.

(I'm heading off to bed, so I didn't try actually defining a new actor with copied art, but I did this, which I think would have the same effect:
useractor notenemy RUBBERCAN WEAK state breakobject enda
useractor notenemy TOILET cactor RUBBERCAN enda

where breakobject has my custom code)

In the unmodified EXE, toilets are completely unchanged (all hardcoded as usual).
In modified EXE, they turn into trashcans as expected.

If you think actually defining a new actor would get different results, please let me know and I'll actually try that tomorrow.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


All copyrights and trademarks not owned by Voidpoint, LLC are the sole property of their respective owners. Play Ion Fury! ;) © Voidpoint, LLC

Enter your sign in name and password


Sign in options