Added "reg_anim_callback" script function(opcode)

Updated documents.
This commit is contained in:
NovaRain
2019-11-14 13:02:10 +08:00
parent 6a566087ca
commit 83c3d6b1a8
8 changed files with 76 additions and 23 deletions
@@ -218,6 +218,9 @@ Some additional reg_anim_* functions were introduced. They all work in the same
> void reg_anim_turn_towards(object, tile/target, delay)
- makes object change its direction to face given tile num or target object.
> void reg_anim_callback(procedure proc)
- registers the given procedure and executes it after previously registered animations are finished.
> int metarule2_explosions(int arg1, int arg2, int arg3)
was made as a dirty easy hack to allow dynamically change some explosion parameters (ranged attack). All changed parameters are reset to vanilla state automatically after each attack action. Following macros are available in sfall.h:
@@ -358,6 +358,7 @@
0x827c - any sfall_func6(string funcName, arg1, arg2, arg3, arg4, arg5, arg6)
0x827d - void register_hook_proc_spec(int hook, procedure proc)
0x827e - void reg_anim_callback(procedure proc)
* These functions require AllowUnsafeScripting to be enabled in ddraw.ini
+1 -1
View File
@@ -314,7 +314,7 @@ artNotExist:
push artDbgMsg;
call debug_printf_;
add esp, 8;
BREAKPOINT; // break program
int 3; // break program
retn;
}
}
+39
View File
@@ -602,6 +602,7 @@ const DWORD register_clear_ = 0x413C4C;
const DWORD register_end_ = 0x413CCC;
const DWORD register_object_animate_ = 0x4149D0;
const DWORD register_object_animate_and_hide_ = 0x414B7C;
const DWORD register_object_call_ = 0x414E98;
const DWORD register_object_change_fid_ = 0x41518C;
const DWORD register_object_funset_ = 0x4150A8;
const DWORD register_object_light_ = 0x415334;
@@ -663,6 +664,7 @@ const DWORD text_curr_ = 0x4D58D4;
const DWORD text_font_ = 0x4D58DC;
const DWORD text_object_create_ = 0x4B036C;
const DWORD tile_coord_ = 0x4B1674;
const DWORD tile_dir_ = 0x4B1ABC;
const DWORD tile_num_ = 0x4B1754;
const DWORD tile_num_in_direction_ = 0x4B1A6C;
const DWORD tile_refresh_display_ = 0x4B12D8;
@@ -854,6 +856,15 @@ long GetScriptLocalVars(long sid) {
return (script) ? script->num_local_vars : 0;
}
void __fastcall RegisterObjectCall(long* target, long* source, void* func, long delay) {
__asm {
mov eax, ecx;
mov ebx, func;
mov ecx, delay;
call register_object_call_;
}
}
long __fastcall ScrGetLocalVar(long sid, long varId, long* value) {
__asm {
mov ebx, value;
@@ -1094,6 +1105,26 @@ long __stdcall TraitLevel(long traitID) {
}
}
void __fastcall make_straight_path_func_wrapper(TGameObj* objFrom, DWORD tileFrom, DWORD tileTo, void* rotationPtr, DWORD* result, long flags, void* func) {
__asm {
push func;
push flags;
push result;
mov eax, ecx;
mov ebx, tileTo;
mov ecx, rotationPtr;
call make_straight_path_func_;
}
}
TGameObj* __fastcall obj_blocking_at_wrapper(TGameObj* obj, DWORD tile, DWORD elevation, void* func) {
__asm {
mov eax, ecx;
mov ebx, elevation;
call func;
}
}
long __stdcall QueueFindFirst(TGameObj* object, long qType) {
__asm {
mov edx, qType;
@@ -1158,6 +1189,14 @@ long __fastcall TileNumInDirection(long tile, long rotation, long distance) {
}
}
long __stdcall TileDir(long scrTile, long dstTile) {
__asm {
mov edx, dstTile;
mov eax, scrTile;
call tile_dir_;
}
}
long __stdcall ItemWAnimWeap(TGameObj* item, DWORD hitMode) {
__asm {
mov edx, hitMode;
+10
View File
@@ -844,6 +844,7 @@ extern const DWORD register_clear_;
extern const DWORD register_end_;
extern const DWORD register_object_animate_; // int aObj<eax>, int aAnim<edx>, int delay<ebx>
extern const DWORD register_object_animate_and_hide_; // int aObj<eax>, int aAnim<edx>, int delay<ebx>
extern const DWORD register_object_call_;
extern const DWORD register_object_change_fid_; // int aObj<eax>, int aFid<edx>, int aDelay<ebx>
extern const DWORD register_object_funset_; // int aObj<eax>, int ???<edx>, int aDelay<ebx> - not really sure what this does
extern const DWORD register_object_light_; // <eax>(int aObj<eax>, int aRadius<edx>, int aDelay<ebx>)
@@ -905,6 +906,7 @@ extern const DWORD text_curr_;
extern const DWORD text_font_;
extern const DWORD text_object_create_;
extern const DWORD tile_coord_; // eax - tilenum, edx (int*) - x, ebx (int*) - y
extern const DWORD tile_dir_;
extern const DWORD tile_num_;
extern const DWORD tile_num_in_direction_;
extern const DWORD tile_refresh_display_;
@@ -1023,6 +1025,8 @@ long __stdcall ScrPtr(long scriptId, TScript** scriptPtr);
// Returns the number of local variables of the object script
long GetScriptLocalVars(long sid);
void __fastcall RegisterObjectCall(long* target, long* source, void* func, long delay);
long __fastcall ScrGetLocalVar(long sid, long varId, long* value);
long __fastcall ScrSetLocalVar(long sid, long varId, long value);
@@ -1097,6 +1101,10 @@ long __stdcall TraitLevel(long traitID);
long __stdcall QueueFindFirst(TGameObj* object, long qType);
void __fastcall make_straight_path_func_wrapper(TGameObj* objFrom, DWORD tileFrom, DWORD tileTo, void* rotationPtr, DWORD* result, long flags, void* func);
TGameObj* __fastcall obj_blocking_at_wrapper(TGameObj* obj, DWORD tile, DWORD elevation, void* func);
TGameObj* __stdcall ObjFindFirst();
TGameObj* __stdcall ObjFindFirstAtTile(long elevation, long tileNum);
@@ -1115,6 +1123,8 @@ TGameObj* __fastcall ObjBlockingAt(TGameObj* object, long tile, long elevation);
long __fastcall TileNumInDirection(long tile, long rotation, long distance);
long __stdcall TileDir(long scrTile, long dstTile);
// for the backported AmmoCostHook from 4.x
long __stdcall ItemWAnimWeap(TGameObj* item, DWORD hitMode);
long __stdcall ItemWComputeAmmoCost(TGameObj* item, DWORD* rounds);
+1
View File
@@ -1595,6 +1595,7 @@ void ScriptExtenderInit() {
opcodes[0x27c] = op_sfall_metarule6; // if you need more arguments - use arrays
opcodes[0x27d] = register_hook_proc_spec;
opcodes[0x27e] = op_reg_anim_callback;
InitOpcodeMetaTable();
InitMetaruleTable();
+19
View File
@@ -171,6 +171,25 @@ end:
_OP_END
}
static void _stdcall op_reg_anim_callback2() {
const ScriptValue &procArg = opHandler.arg(0);
if (procArg.isInt()) {
RegisterObjectCall(
reinterpret_cast<long*>(opHandler.program()),
reinterpret_cast<long*>(procArg.rawValue()), // callback procedure
reinterpret_cast<void*>(executeProcedure_),
-1
);
} else {
OpcodeInvalidArgs("reg_anim_callback");
}
}
static void __declspec(naked) op_reg_anim_callback() {
_WRAP_OPCODE(op_reg_anim_callback2, 1, 0)
}
static void __declspec(naked) op_explosions_metarule() {
_OP_BEGIN(ebp)
_GET_ARG_R32(ebp, ebx, esi) // arg3
-20
View File
@@ -333,26 +333,6 @@ end:
}
}
static TGameObj* __fastcall obj_blocking_at_wrapper(TGameObj* obj, DWORD tile, DWORD elevation, void* func) {
__asm {
mov eax, ecx;
mov ebx, elevation;
call func;
}
}
static void __fastcall make_straight_path_func_wrapper(TGameObj* objFrom, DWORD tileFrom, DWORD tileTo, void* rotationPtr, DWORD* result, long flags, void* func) {
__asm {
push func;
push flags;
push result;
mov eax, ecx;
mov ebx, tileTo;
mov ecx, rotationPtr;
call make_straight_path_func_;
}
}
#define BLOCKING_TYPE_BLOCK (0)
#define BLOCKING_TYPE_SHOOT (1)
#define BLOCKING_TYPE_AI (2)