Added sfall_func7 and sfall_func8 new opcodes

Added 3 new attrType values to "get_window_attribute" function.
Minor code edits.
This commit is contained in:
NovaRain
2020-12-22 17:03:01 +08:00
parent 9052396de5
commit e0e300a91e
9 changed files with 54 additions and 23 deletions
@@ -340,6 +340,10 @@ There are several changes in this version of sslc which may result in problems f
=== Changelog === === Changelog ===
================= =================
> sfall 4.2.9
- added support for additional universal opcodes sfall_func7 and sfall_func8
- fixed a compilation error when the script has a UTF-8 BOM
> sfall 4.2.7 > sfall 4.2.7
- added ability to declare local variables anywhere in the procedure body - added ability to declare local variables anywhere in the procedure body
+3
View File
@@ -286,8 +286,11 @@
#define get_flags(obj) sfall_func1("get_flags", obj) #define get_flags(obj) sfall_func1("get_flags", obj)
#define get_ini_section(file, sect) sfall_func2("get_ini_section", file, sect) #define get_ini_section(file, sect) sfall_func2("get_ini_section", file, sect)
#define get_ini_sections(file) sfall_func1("get_ini_sections", file) #define get_ini_sections(file) sfall_func1("get_ini_sections", file)
#define get_interface_rect(winType) sfall_func2("get_window_attribute", winType, -1)
#define get_interface_x(winType) sfall_func2("get_window_attribute", winType, 1) #define get_interface_x(winType) sfall_func2("get_window_attribute", winType, 1)
#define get_interface_y(winType) sfall_func2("get_window_attribute", winType, 2) #define get_interface_y(winType) sfall_func2("get_window_attribute", winType, 2)
#define get_interface_width(winType) sfall_func2("get_window_attribute", winType, 3)
#define get_interface_height(winType) sfall_func2("get_window_attribute", winType, 4)
#define get_inven_ap_cost sfall_func0("get_inven_ap_cost") #define get_inven_ap_cost sfall_func0("get_inven_ap_cost")
#define get_map_enter_position sfall_func0("get_map_enter_position") #define get_map_enter_position sfall_func0("get_map_enter_position")
#define get_metarule_table sfall_func0("get_metarule_table") #define get_metarule_table sfall_func0("get_metarule_table")
+4 -1
View File
@@ -381,7 +381,7 @@ Some utility/math functions are available:
> any sfall_funcX(string funcName, ...) > any sfall_funcX(string funcName, ...)
- these opcodes allows to use additional scripting functions, that do not require new opcode - these opcodes allows to use additional scripting functions, that do not require new opcode
- first argument is always function name (string) - first argument is always function name (string)
- there are 7 versions of this opcode for different number of additional arguments (for convenience) - there are 9 versions of this opcode for different number of additional arguments (for convenience)
- opcodes have return value, but it is not necessary to use it - opcodes have return value, but it is not necessary to use it
@@ -666,6 +666,9 @@ optional argument:
- winType: the type number of the interface window (see WINTYPE_* constants in sfall.h) - winType: the type number of the interface window (see WINTYPE_* constants in sfall.h)
- attrType: 0 - checks and returns a value of 1 if the specified interface window is created by the game (same as without the argument) - attrType: 0 - checks and returns a value of 1 if the specified interface window is created by the game (same as without the argument)
1 - X position, 2 - Y position (relative to the top-left corner of the game screen) 1 - X position, 2 - Y position (relative to the top-left corner of the game screen)
3 - interface width size, 4 - interface height size
-1 - returns an associative array of keys (left, top, right, bottom) and values that define the position of the window rectangle
(use standard syntax to access array values, e.g. winRect.top, winRect.bottom)
- returns -1 if the specified attribute cannot be obtained - returns -1 if the specified attribute cannot be obtained
> void sfall_func2("set_town_title", int areaID, string title) > void sfall_func2("set_town_title", int areaID, string title)
@@ -362,6 +362,9 @@
0x827f - div operator (unsigned integer division) 0x827f - div operator (unsigned integer division)
0x8280 - any sfall_func7(string funcName, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
0x8281 - any sfall_func8(string funcName, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
* These functions require AllowUnsafeScripting to be enabled in ddraw.ini * These functions require AllowUnsafeScripting to be enabled in ddraw.ini
+10 -14
View File
@@ -1089,8 +1089,8 @@ void __cdecl BufToBuf(BYTE* src, long width, long height, long src_width, BYTE*
size_t blockCount = width / 64; // 64 bytes size_t blockCount = width / 64; // 64 bytes
size_t remainder = width % 64; size_t remainder = width % 64;
size_t remainderD = remainder / 4; size_t sizeD = remainder >> 2;
size_t remainderB = remainder % 4; size_t sizeB = remainder & 3;
size_t s_pitch = src_width - width; size_t s_pitch = src_width - width;
size_t d_pitch = dst_width - width; size_t d_pitch = dst_width - width;
@@ -1126,9 +1126,9 @@ void __cdecl BufToBuf(BYTE* src, long width, long height, long src_width, BYTE*
dec ecx; // blockCount dec ecx; // blockCount
jnz copyBlock; jnz copyBlock;
// copies the remaining bytes // copies the remaining bytes
mov ecx, remainderD; mov ecx, sizeD;
rep movsd; rep movsd;
mov ecx, remainderB; mov ecx, sizeB;
rep movsb; rep movsb;
add esi, ebx; // s_pitch add esi, ebx; // s_pitch
add edi, edx; // d_pitch add edi, edx; // d_pitch
@@ -1137,9 +1137,9 @@ void __cdecl BufToBuf(BYTE* src, long width, long height, long src_width, BYTE*
emms; emms;
jmp end; jmp end;
copySmall: // copies the small size data copySmall: // copies the small size data
mov ecx, remainderD; mov ecx, sizeD;
rep movsd; rep movsd;
mov ecx, remainderB; mov ecx, sizeB;
rep movsb; rep movsb;
add esi, ebx; // s_pitch add esi, ebx; // s_pitch
add edi, edx; // d_pitch add edi, edx; // d_pitch
@@ -1153,8 +1153,8 @@ end:
void __cdecl TransBufToBuf(BYTE* src, long width, long height, long src_width, BYTE* dst, long dst_width) { void __cdecl TransBufToBuf(BYTE* src, long width, long height, long src_width, BYTE* dst, long dst_width) {
if (height <= 0 || width <= 0) return; if (height <= 0 || width <= 0) return;
size_t blockCount = width / 8; size_t blockCount = width >> 3;
size_t lastBytes = width % 8; size_t lastBytes = width & 7;
size_t s_pitch = src_width - width; size_t s_pitch = src_width - width;
size_t d_pitch = dst_width - width; size_t d_pitch = dst_width - width;
@@ -1589,13 +1589,9 @@ void WinFillRect(long winID, long x, long y, long width, long height, BYTE index
// Fills the specified interface window with index color 0 (black color) // Fills the specified interface window with index color 0 (black color)
void ClearWindow(long winID, bool refresh) { void ClearWindow(long winID, bool refresh) {
WINinfo* win = GNWFind(winID); WINinfo* win = GNWFind(winID);
BYTE* surf = win->surface; std::memset(win->surface, 0, win->width * win->height);
for (long i = 0; i < win->height; i++) {
std::memset(surf, 0, win->width);
surf += win->width;
}
if (refresh) { if (refresh) {
GNWWinRefresh(win, &win->rect, 0); GNWWinRefresh(win, &win->rect, nullptr);
} }
} }
+7 -3
View File
@@ -1337,7 +1337,7 @@ static void __fastcall sf_GNW_win_refresh(WINinfo* win, RECT* updateRect, BYTE*
mov edx, ds:[_screen_buffer]; mov edx, ds:[_screen_buffer];
call refresh_all_; call refresh_all_;
} }
int w = updateRect->right - updateRect->left + 1; int w = (updateRect->right - updateRect->left) + 1;
if (*ptr_mouse_is_hidden || !MouseIn(updateRect->left, updateRect->top, updateRect->right, updateRect->bottom)) { if (*ptr_mouse_is_hidden || !MouseIn(updateRect->left, updateRect->top, updateRect->right, updateRect->bottom)) {
/*__asm { /*__asm {
@@ -1346,7 +1346,9 @@ static void __fastcall sf_GNW_win_refresh(WINinfo* win, RECT* updateRect, BYTE*
call GNW_button_refresh_; call GNW_button_refresh_;
}*/ }*/
int h = (updateRect->bottom - updateRect->top) + 1; int h = (updateRect->bottom - updateRect->top) + 1;
UpdateDDSurface(GetBuffer(), w, h, w, updateRect); // update the entire rectangle area UpdateDDSurface(GetBuffer(), w, h, w, updateRect); // update the entire rectangle area
} else { } else {
MouseShow(); // for updating background cursor area MouseShow(); // for updating background cursor area
RECT mouseRect; RECT mouseRect;
@@ -1364,8 +1366,10 @@ static void __fastcall sf_GNW_win_refresh(WINinfo* win, RECT* updateRect, BYTE*
mov edx, rects; mov edx, rects;
call GNW_button_refresh_; call GNW_button_refresh_;
}*/ }*/
int wRect = (rects->wRect.right - rects->wRect.left) + 1; int wRect = (rects->wRect.right - rects->wRect.left) + 1;
int hRect = (rects->wRect.bottom - rects->wRect.top) + 1; int hRect = (rects->wRect.bottom - rects->wRect.top) + 1;
UpdateDDSurface(&GetBuffer()[rects->wRect.left - updateRect->left] + (rects->wRect.top - updateRect->top) * w, wRect, hRect, w, &rects->wRect); UpdateDDSurface(&GetBuffer()[rects->wRect.left - updateRect->left] + (rects->wRect.top - updateRect->top) * w, wRect, hRect, w, &rects->wRect);
RectList* next = rects->nextRect; RectList* next = rects->nextRect;
@@ -1403,7 +1407,7 @@ static void __fastcall sf_GNW_win_refresh(WINinfo* win, RECT* updateRect, BYTE*
} }
int widthFrom = win->width; int widthFrom = win->width;
int toWidth = (toBuffer) ? updateRect->right - updateRect->left + 1 : Gfx_GetGameWidthRes(); int toWidth = (toBuffer) ? (updateRect->right - updateRect->left) + 1 : Gfx_GetGameWidthRes();
WinClip(win, &rects, toBuffer); WinClip(win, &rects, toBuffer);
@@ -1414,7 +1418,7 @@ static void __fastcall sf_GNW_win_refresh(WINinfo* win, RECT* updateRect, BYTE*
int height = (crect.bottom - crect.top) + 1;; // for current rectangle int height = (crect.bottom - crect.top) + 1;; // for current rectangle
BYTE* surface; BYTE* surface;
if (win->wID) { if (win->wID > 0) {
__asm { __asm {
mov eax, win; mov eax, win;
mov edx, currRect; mov edx, currRect;
+4 -1
View File
@@ -2080,12 +2080,15 @@ void ScriptExtender_Init() {
opcodes[0x279] = op_sfall_metarule3; opcodes[0x279] = op_sfall_metarule3;
opcodes[0x27a] = op_sfall_metarule4; opcodes[0x27a] = op_sfall_metarule4;
opcodes[0x27b] = op_sfall_metarule5; opcodes[0x27b] = op_sfall_metarule5;
opcodes[0x27c] = op_sfall_metarule6; // if you need more arguments - use arrays opcodes[0x27c] = op_sfall_metarule6;
opcodes[0x27d] = op_register_hook_proc_spec; opcodes[0x27d] = op_register_hook_proc_spec;
opcodes[0x27e] = op_reg_anim_callback; opcodes[0x27e] = op_reg_anim_callback;
opcodes[0x27f] = op_div; // div operator opcodes[0x27f] = op_div; // div operator
opcodes[0x280] = op_sfall_metarule7;
opcodes[0x281] = op_sfall_metarule8; // if you need more arguments - use arrays
InitOpcodeMetaTable(); InitOpcodeMetaTable();
InitMetaruleTable(); InitMetaruleTable();
} }
+17 -4
View File
@@ -712,7 +712,7 @@ static void mf_interface_art_draw() {
if (win && (int)win != -1) { if (win && (int)win != -1) {
result = InterfaceDrawImage(opHandler, win, "interface_art_draw"); result = InterfaceDrawImage(opHandler, win, "interface_art_draw");
} else { } else {
opHandler.printOpcodeError("interface_art_draw() - the game interface window is not created or invalid value for the interface."); opHandler.printOpcodeError("interface_art_draw() - the game interface window is not created or invalid window type number.");
} }
opHandler.setReturn(result); opHandler.setReturn(result);
} }
@@ -795,15 +795,28 @@ static void mf_get_window_attribute() {
} }
long result = 0; long result = 0;
switch (opHandler.arg(1).rawValue()) { switch (opHandler.arg(1).rawValue()) {
case -1: // rectangle map.left map.top map.right map.bottom
result = CreateTempArray(-1, 0); // associative
setArray(result, ScriptValue("left").rawValue(), VAR_TYPE_STR, win->rect.x, VAR_TYPE_INT, 0);
setArray(result, ScriptValue("top").rawValue(), VAR_TYPE_STR, win->rect.y, VAR_TYPE_INT, 0);
setArray(result, ScriptValue("right").rawValue(), VAR_TYPE_STR, win->rect.offx, VAR_TYPE_INT, 0);
setArray(result, ScriptValue("bottom").rawValue(), VAR_TYPE_STR, win->rect.offy, VAR_TYPE_INT, 0);
break;
case 0: // check if window exists case 0: // check if window exists
result = 1; result = 1;
break; break;
case 1: // x case 1:
result = win->rect.x; result = win->rect.x;
break; break;
case 2: // y case 2:
result = win->rect.y; result = win->rect.y;
break; break;
case 3:
result = win->width;
break;
case 4:
result = win->height;
break;
} }
opHandler.setReturn(result); opHandler.setReturn(result);
} }
@@ -811,7 +824,7 @@ static void mf_get_window_attribute() {
static void mf_interface_print() { // same as vanilla PrintRect static void mf_interface_print() { // same as vanilla PrintRect
WINinfo* win = Interface_GetWindow(opHandler.arg(1).rawValue()); WINinfo* win = Interface_GetWindow(opHandler.arg(1).rawValue());
if (win == nullptr || (int)win == -1) { if (win == nullptr || (int)win == -1) {
opHandler.printOpcodeError("interface_print() - the game interface window is not created or invalid value for the interface."); opHandler.printOpcodeError("interface_print() - the game interface window is not created or invalid window type number.");
opHandler.setReturn(-1); opHandler.setReturn(-1);
return; return;
} }
+2
View File
@@ -261,5 +261,7 @@ metaruleOpcode(3, 4)
metaruleOpcode(4, 5) metaruleOpcode(4, 5)
metaruleOpcode(5, 6) metaruleOpcode(5, 6)
metaruleOpcode(6, 7) metaruleOpcode(6, 7)
metaruleOpcode(7, 8)
metaruleOpcode(8, 9)
#undef metaruleOpcode #undef metaruleOpcode