Skip to content

Interacting with FO engine

Vlad edited this page Mar 8, 2017 · 2 revisions

Inline assembly

It is discouraged to use inline assembly (__asm {} blocks) for any kind of logic, but legacy sfall code already contains a lot of those, so the following tips may be helpful. When writing inline assembly, please follow these guidelines to properly interact with engine.

Variables

Use FO_VAR_* macro constants instead of fo::var::*! This is related to how Visual C++ compiler treats your statements. Example: mov eax, [FO_VAR_dude_obj + 0x64] - because FO_VAR_* are preprocessor macros, they will be simply replaced with a numeric literal and your code will compile as expected. mov eax, [fo::var::dude_obj + 0x64] - in this case dude_obj is a constant reference variable (basically a pointer) and has it's own address, so the compiler will generate the wrong code (getting address of the pointer variable itself and then adding 0x64 to it).

Enums

Inline assembly doesn't play very nice with enums. In particular it doesn't understand enums in namespaces. mov eax, fo::STAT_gender - will not work, compile error.

Possible solutions:

  • Add this line using fo::STAT_gender; at the start of your function, if you only use this one constant.
  • Add this line using namespace fo; at the start of your function.
  • Add this line using namespace fo; at the beginning of your .cpp file (not .h file!), right after namespace opening bracket. Do this only when you use those enums a lot in this file. Example:
namespace sfall
{
using namespace fo; // HERE
Clone this wiki locally