mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Code refactoring for opcodes/functions
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include "..\..\ScriptExtender.h"
|
||||
#include "..\Arrays.h"
|
||||
#include "..\OpcodeContext.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include "Arrays.h"
|
||||
|
||||
@@ -55,8 +54,14 @@ void sf_get_array(OpcodeContext& ctx) {
|
||||
);
|
||||
} else if (ctx.arg(0).isString()) {
|
||||
if (ctx.arg(1).isInt()) {
|
||||
const char* str = Substring(ctx.arg(0).strValue(), ctx.arg(1).rawValue(), 1);
|
||||
ctx.setReturn(str); // returns char of string
|
||||
size_t index = ctx.arg(1).rawValue();
|
||||
if (index < strlen(ctx.arg(0).strValue())) {
|
||||
wchar_t c = ((unsigned char*)ctx.arg(0).strValue())[index];
|
||||
((wchar_t*)ScriptExtender::gTextBuffer)[0] = c;
|
||||
} else {
|
||||
ScriptExtender::gTextBuffer[0] = '\0';
|
||||
}
|
||||
ctx.setReturn(ScriptExtender::gTextBuffer); // returns char of string
|
||||
} else {
|
||||
ctx.printOpcodeError("%s() - index must be numeric when used on a string.", ctx.getOpcodeName());
|
||||
}
|
||||
|
||||
@@ -34,37 +34,35 @@ namespace script
|
||||
|
||||
void __declspec(naked) op_set_global_script_repeat() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
mov ecx, eax;
|
||||
_GET_ARG_INT(end);
|
||||
mov edx, eax; // frames
|
||||
call SetGlobalScriptRepeat; // ecx - script
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_global_script_type() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
mov ecx, eax;
|
||||
_GET_ARG_INT(end);
|
||||
mov edx, eax; // type
|
||||
call SetGlobalScriptType; // ecx - script
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_available_global_script_types() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, availableGlobalScriptTypes;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,12 +105,12 @@ void sf_get_sfall_global_float(OpcodeContext& ctx) {
|
||||
|
||||
void __declspec(naked) op_get_sfall_arg() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call HookScripts::GetHSArg;
|
||||
mov edx, eax;
|
||||
mov eax, ebx;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -144,35 +142,33 @@ void sf_set_sfall_arg(OpcodeContext& ctx) {
|
||||
|
||||
void __declspec(naked) op_set_sfall_return() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call HookScripts::SetHSReturn;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_init_hook() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, initingHookScripts;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_self() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
mov ecx, eax;
|
||||
_GET_ARG_INT(end);
|
||||
mov edx, eax; // object
|
||||
call SetSelfObject; // ecx - script
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,13 +32,11 @@ namespace script
|
||||
|
||||
void __declspec(naked) op_graphics_funcs_available() {
|
||||
__asm {
|
||||
push ecx;
|
||||
cmp Graphics::mode, 3;
|
||||
seta dl;
|
||||
and edx, 0xFF;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,36 +81,36 @@ result:
|
||||
|
||||
void __declspec(naked) op_free_shader() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call FreeShader;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_activate_shader() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call ActivateShader;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_deactivate_shader() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call DeactivateShader;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -405,12 +403,12 @@ end:
|
||||
|
||||
void __declspec(naked) op_get_shader_version() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call GetShaderVersion;
|
||||
mov edx, eax;
|
||||
mov eax, ebx;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -452,12 +450,12 @@ end:
|
||||
|
||||
void __declspec(naked) op_force_graphics_refresh() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call ForceGraphicsRefresh;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,11 +34,9 @@ namespace script
|
||||
|
||||
void __declspec(naked) op_input_funcs_available() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, 1; // They're always available from 2.9 on
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +46,7 @@ void sf_key_pressed(OpcodeContext& ctx) {
|
||||
|
||||
void __declspec(naked) op_tap_key() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
test eax, eax;
|
||||
jl end;
|
||||
@@ -57,30 +55,26 @@ void __declspec(naked) op_tap_key() {
|
||||
push eax;
|
||||
call TapKey;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_mouse_x() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_mouse_x_];
|
||||
add edx, ds:[FO_VAR_mouse_hotx];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_mouse_y() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_mouse_y_];
|
||||
add edx, ds:[FO_VAR_mouse_hoty];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,35 +89,29 @@ void sf_get_mouse_buttons(OpcodeContext& ctx) {
|
||||
|
||||
void __declspec(naked) op_get_window_under_mouse() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_last_button_winID];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_screen_width() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_scr_size + 8]; // _scr_size.offx
|
||||
sub edx, ds:[FO_VAR_scr_size]; // _scr_size.x
|
||||
inc edx;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_screen_height() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_scr_size + 12]; // _scr_size.offy
|
||||
sub edx, ds:[FO_VAR_scr_size + 4]; // _scr_size.y
|
||||
inc edx;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,42 +139,34 @@ void sf_create_message_window(OpcodeContext &ctx) {
|
||||
|
||||
void __declspec(naked) op_get_viewport_x() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_wmWorldOffsetX];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_viewport_y() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_wmWorldOffsetY];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_viewport_x() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ds:[FO_VAR_wmWorldOffsetX], eax;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_viewport_y() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ds:[FO_VAR_wmWorldOffsetY], eax;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,10 +250,10 @@ static void __fastcall CallOffsetInternal(fo::Program* script, DWORD func) {
|
||||
|
||||
void __declspec(naked) op_call_offset() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
mov ecx, eax;
|
||||
call CallOffsetInternal; // edx - func
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,20 +86,19 @@ void sf_get_year(OpcodeContext& ctx) {
|
||||
|
||||
void __declspec(naked) op_game_loaded() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
push eax; // script
|
||||
call ScriptHasLoaded;
|
||||
movzx edx, al;
|
||||
mov eax, ebx;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_pipboy_available() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
cmp eax, 0;
|
||||
jl end;
|
||||
@@ -107,12 +106,10 @@ void __declspec(naked) op_set_pipboy_available() {
|
||||
jg end;
|
||||
mov byte ptr ds:[FO_VAR_gmovie_played_list][0x3], al;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Kill counters
|
||||
void __declspec(naked) op_get_kill_counter() {
|
||||
__asm {
|
||||
@@ -131,7 +128,6 @@ void __declspec(naked) op_get_kill_counter() {
|
||||
mov edx, ds:[FO_VAR_pc_kill_counts+eax*4];
|
||||
jmp end;
|
||||
fail:
|
||||
|
||||
xor edx, edx;
|
||||
end:
|
||||
mov eax, ecx
|
||||
@@ -287,11 +283,9 @@ end:
|
||||
|
||||
void __declspec(naked) op_active_hand() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, dword ptr ds:[FO_VAR_itemCurrentItem];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,11 +298,9 @@ void __declspec(naked) op_toggle_active_hand() {
|
||||
|
||||
void __declspec(naked) op_eax_available() {
|
||||
__asm {
|
||||
push ecx;
|
||||
xor edx, edx
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,36 +472,34 @@ void sf_get_ini_string(OpcodeContext& ctx) {
|
||||
|
||||
void __declspec(naked) op_get_uptime() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call GetTickCount;
|
||||
mov edx, eax;
|
||||
mov eax, ebx;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_car_current_town() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ds:[FO_VAR_carCurrentArea], eax;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_hp_per_level_mod() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax; // allowed -/+127
|
||||
push 0x4AFBC1;
|
||||
call SafeWrite8;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -620,43 +610,35 @@ void sf_reset_critical_table(OpcodeContext& ctx) {
|
||||
|
||||
void __declspec(naked) op_set_unspent_ap_bonus() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov Stats::standardApAcBonus, eax;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_unspent_ap_bonus() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, Stats::standardApAcBonus;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_unspent_ap_perk_bonus() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov Stats::extraApAcBonus, eax;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_unspent_ap_perk_bonus() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, Stats::extraApAcBonus;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,55 +682,53 @@ void __declspec(naked) op_nb_create_char() {
|
||||
|
||||
void __declspec(naked) op_hero_select_win() { // for opening the appearance selection window
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(fail);
|
||||
push eax;
|
||||
call HeroSelectWindow;
|
||||
fail:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_hero_style() { // for setting the hero style/appearance takes an 1 int
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(fail);
|
||||
push eax;
|
||||
call SetHeroStyle;
|
||||
fail:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_hero_race() { // for setting the hero race takes an 1 int
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(fail);
|
||||
push eax;
|
||||
call SetHeroRace;
|
||||
fail:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_light_level() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_ambient_light];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_refresh_pc_art() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call RefreshPCArt;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -800,12 +780,12 @@ end:
|
||||
|
||||
void __declspec(naked) op_stop_sfall_sound() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call StopSfallSound;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -846,41 +826,38 @@ end:
|
||||
|
||||
void __declspec(naked) op_modified_ini() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, modifiedIni;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_force_aimed_shots() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call ForceAimedShots;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_disable_aimed_shots() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call DisableAimedShots;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_mark_movie_played() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
test eax, eax;
|
||||
jl end;
|
||||
@@ -888,7 +865,6 @@ void __declspec(naked) op_mark_movie_played() {
|
||||
jge end;
|
||||
mov byte ptr ds:[eax + FO_VAR_gmovie_played_list], 1;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -949,12 +925,12 @@ end:
|
||||
|
||||
void __declspec(naked) op_block_combat() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call AIBlockCombat;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -989,22 +965,20 @@ void __declspec(naked) op_tile_under_cursor() {
|
||||
|
||||
void __declspec(naked) op_gdialog_get_barter_mod() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, dword ptr ds:[FO_VAR_gdBarterMod];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_inven_ap_cost() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ecx, eax;
|
||||
call Inventory::SetInvenApCost;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,36 +30,32 @@ namespace script
|
||||
|
||||
void __declspec(naked) op_get_perk_owed() {
|
||||
__asm {
|
||||
push ecx;
|
||||
movzx edx, byte ptr ds:[FO_VAR_free_perk];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_perk_owed() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
and eax, 0xFF;
|
||||
cmp eax, 250;
|
||||
jg end;
|
||||
mov byte ptr ds:[FO_VAR_free_perk], al;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_perk_freq() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call SetPerkFreq;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -248,27 +244,27 @@ end:
|
||||
|
||||
void __declspec(naked) op_hide_real_perks() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call IgnoreDefaultPerks;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_show_real_perks() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call RestoreDefaultPerks;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_clear_selectable_perks() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call ClearSelectablePerks;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -305,71 +301,68 @@ void sf_has_fake_trait_npc(OpcodeContext& ctx) {
|
||||
|
||||
void __declspec(naked) op_perk_add_mode() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
call AddPerkMode;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_remove_trait() {
|
||||
__asm {
|
||||
push ecx;
|
||||
_GET_ARG_INT(end);
|
||||
test eax, eax;
|
||||
jl end;
|
||||
mov edx, -1;
|
||||
cmp eax, ds:[FO_VAR_pc_trait];
|
||||
jne next;
|
||||
mov ecx, ds:[FO_VAR_pc_trait2];
|
||||
mov ds:[FO_VAR_pc_trait], ecx;
|
||||
mov esi, ds:[FO_VAR_pc_trait2];
|
||||
mov ds:[FO_VAR_pc_trait], esi;
|
||||
mov ds:[FO_VAR_pc_trait2], edx;
|
||||
end:
|
||||
pop ecx;
|
||||
retn;
|
||||
next:
|
||||
cmp eax, ds:[FO_VAR_pc_trait2];
|
||||
jne end;
|
||||
mov ds:[FO_VAR_pc_trait2], edx;
|
||||
pop ecx;
|
||||
end:
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_pyromaniac_mod() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
push 0x424AB6;
|
||||
call SafeWrite8;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_apply_heaveho_fix() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call ApplyHeaveHoFix;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_swiftlearner_mod() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
push 0x4AFAE2;
|
||||
call SafeWrite32;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -398,12 +391,12 @@ static void __fastcall SetPerkLevelMod(long mod) {
|
||||
|
||||
void __declspec(naked) op_set_perk_level_mod() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ecx, eax;
|
||||
call SetPerkLevelMod;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,30 +236,28 @@ end:
|
||||
|
||||
void __declspec(naked) op_set_available_skill_points() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov edx, eax;
|
||||
xor eax, eax;
|
||||
call fo::funcoffs::stat_pc_set_;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_available_skill_points() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, dword ptr ds:[FO_VAR_curr_pc_stat];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_mod_skill_points_per_level() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ecx, 100;
|
||||
cmp eax, ecx;
|
||||
@@ -272,7 +270,7 @@ void __declspec(naked) op_mod_skill_points_per_level() {
|
||||
push 0x43C27A;
|
||||
call SafeWrite8;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -356,7 +354,7 @@ end:
|
||||
|
||||
void __declspec(naked) op_set_pickpocket_max() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ecx, 100;
|
||||
cmp eax, ecx;
|
||||
@@ -366,14 +364,14 @@ void __declspec(naked) op_set_pickpocket_max() {
|
||||
push 0xFFFFFFFF;
|
||||
call SetPickpocketMax;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_hit_chance_max() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ecx, 100;
|
||||
cmp eax, ecx;
|
||||
@@ -383,7 +381,7 @@ void __declspec(naked) op_set_hit_chance_max() {
|
||||
push 0xFFFFFFFF;
|
||||
call SetHitChanceMax;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
@@ -578,20 +576,20 @@ end:
|
||||
|
||||
void __declspec(naked) op_set_base_skill_mod() { // same as set_skill_max
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
push eax;
|
||||
push 0xFFFFFFFF;
|
||||
call SetSkillMax;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_set_skill_max() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
_GET_ARG_INT(end);
|
||||
mov ecx, 300;
|
||||
cmp eax, ecx;
|
||||
@@ -600,7 +598,7 @@ void __declspec(naked) op_set_skill_max() {
|
||||
push 0xFFFFFFFF;
|
||||
call SetSkillMax;
|
||||
end:
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ void sf_string_split(OpcodeContext& ctx) {
|
||||
ctx.setReturn(StringSplit(ctx.arg(0).strValue(), ctx.arg(1).strValue()));
|
||||
}
|
||||
|
||||
char* Substring(const char* str, int startPos, int length) {
|
||||
static char* SubString(const char* str, int startPos, int length) {
|
||||
int len = strlen(str);
|
||||
|
||||
if (startPos < 0) {
|
||||
@@ -218,7 +218,7 @@ char* Substring(const char* str, int startPos, int length) {
|
||||
|
||||
void sf_substr(OpcodeContext& ctx) {
|
||||
const char* str = ctx.arg(0).strValue();
|
||||
if (*str != '\0') str = Substring(str, ctx.arg(1).rawValue(), ctx.arg(2).rawValue());
|
||||
if (*str != '\0') str = SubString(str, ctx.arg(1).rawValue(), ctx.arg(2).rawValue());
|
||||
ctx.setReturn(str);
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ void sf_string_compare(OpcodeContext& ctx) {
|
||||
}
|
||||
|
||||
// A safer version of sprintf for using in user scripts.
|
||||
static char* _stdcall sprintf_lite(const char* format, ScriptValue value) {
|
||||
static char* sprintf_lite(const char* format, ScriptValue value) {
|
||||
int fmtlen = strlen(format);
|
||||
int buflen = fmtlen + 1;
|
||||
for (int i = 0; i < fmtlen; i++) {
|
||||
|
||||
@@ -23,8 +23,6 @@ namespace sfall
|
||||
namespace script
|
||||
{
|
||||
|
||||
char* Substring(const char* str, int startPos, int length);
|
||||
|
||||
class OpcodeContext;
|
||||
|
||||
void sf_sqrt(OpcodeContext&);
|
||||
|
||||
@@ -88,45 +88,41 @@ void sf_force_encounter(OpcodeContext& cxt) {
|
||||
// world_map_functions
|
||||
void __declspec(naked) op_in_world_map() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call InWorldMap;
|
||||
mov edx, eax;
|
||||
mov eax, ebx;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_game_mode() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov esi, ecx;
|
||||
call GetLoopFlags;
|
||||
mov edx, eax;
|
||||
mov eax, ebx;
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
mov ecx, esi;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_world_map_x_pos() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_world_xpos];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_get_world_map_y_pos() {
|
||||
__asm {
|
||||
push ecx;
|
||||
mov edx, ds:[FO_VAR_world_ypos];
|
||||
_RET_VAL_INT;
|
||||
pop ecx;
|
||||
retn;
|
||||
_J_RET_VAL_TYPE(VAR_TYPE_INT);
|
||||
// retn;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,23 +119,37 @@ bool OpcodeContext::validateArguments(const OpcodeArgumentType argTypes[], const
|
||||
// exception is when type set to
|
||||
if (actualType == DataType::NONE) break;
|
||||
auto argType = argTypes[i];
|
||||
if (argType == ARG_ANY) continue;
|
||||
if ((argType == ARG_INT || argType == ARG_OBJECT) && !(actualType == DataType::INT)) {
|
||||
switch (argType) {
|
||||
case ARG_ANY:
|
||||
continue;
|
||||
case ARG_INT:
|
||||
case ARG_OBJECT:
|
||||
if (actualType != DataType::INT) {
|
||||
printOpcodeError("%s() - argument #%d is not an integer.", opcodeName, ++i);
|
||||
return false;
|
||||
} else if (argType == ARG_NUMBER && !(actualType == DataType::INT || actualType == DataType::FLOAT)) {
|
||||
printOpcodeError("%s() - argument #%d is not a number.", opcodeName, ++i);
|
||||
return false;
|
||||
} else if (argType == ARG_STRING && !(actualType == DataType::STR)) {
|
||||
printOpcodeError("%s() - argument #%d is not a string.", opcodeName, ++i);
|
||||
return false;
|
||||
} else if (argType == ARG_OBJECT && arg(i).rawValue() == 0) {
|
||||
printOpcodeError("%s() - argument #%d is null.", opcodeName, ++i);
|
||||
return false;
|
||||
} else if (argType == ARG_INTSTR && !(actualType == DataType::INT || actualType == DataType::STR)) {
|
||||
}
|
||||
break;
|
||||
case ARG_STRING:
|
||||
if (actualType != DataType::STR) {
|
||||
printOpcodeError("%s() - argument #%d is not a string.", opcodeName, ++i);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ARG_INTSTR:
|
||||
if (actualType != DataType::STR && actualType != DataType::INT) {
|
||||
printOpcodeError("%s() - argument #%d is not an integer or a string.", opcodeName, ++i);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ARG_NUMBER:
|
||||
if (actualType != DataType::FLOAT && actualType != DataType::INT) {
|
||||
printOpcodeError("%s() - argument #%d is not a number.", opcodeName, ++i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,10 +39,10 @@ typedef void(*ScriptingFunctionHandler)(OpcodeContext&);
|
||||
enum OpcodeArgumentType {
|
||||
ARG_ANY = 0, // no validation (default)
|
||||
ARG_INT, // integer only
|
||||
ARG_NUMBER, // float OR integer
|
||||
ARG_STRING, // string only
|
||||
ARG_OBJECT, // integer that is not 0
|
||||
ARG_INTSTR // integer OR string
|
||||
ARG_STRING, // string only
|
||||
ARG_INTSTR, // integer OR string
|
||||
ARG_NUMBER, // float OR integer
|
||||
};
|
||||
|
||||
typedef struct SfallOpcodeInfo {
|
||||
|
||||
@@ -434,16 +434,20 @@ void StartingStatePatches() {
|
||||
SafeWrite32(0x4A336C, date);
|
||||
dlogr(" Done", DL_INIT);
|
||||
}
|
||||
date = GetConfigInt("Misc", "StartMonth", -1);
|
||||
if (date >= 0) {
|
||||
if (date > 11) date = 11;
|
||||
int month = GetConfigInt("Misc", "StartMonth", -1);
|
||||
if (month >= 0) {
|
||||
if (month > 11) month = 11;
|
||||
dlog("Applying starting month patch.", DL_INIT);
|
||||
SafeWrite32(0x4A3382, date);
|
||||
SafeWrite32(0x4A3382, month);
|
||||
dlogr(" Done", DL_INIT);
|
||||
}
|
||||
date = GetConfigInt("Misc", "StartDay", -1);
|
||||
if (date >= 0) {
|
||||
if (date > 30) date = 30;
|
||||
if (month == 1 && date > 28) { // for February
|
||||
date = 28; // set 29th day
|
||||
} else if (date > 30) {
|
||||
date = 30; // set 31st day
|
||||
}
|
||||
dlog("Applying starting day patch.", DL_INIT);
|
||||
SafeWrite8(0x4A3356, static_cast<BYTE>(date));
|
||||
dlogr(" Done", DL_INIT);
|
||||
|
||||
Reference in New Issue
Block a user