### Compile Magic.cpp to Magic.asm Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt Basic compilation example: generates Magic.asm in the same directory. ```bash ./ss Magic.cpp ``` -------------------------------- ### SetObjectFadeOut (0x26) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Adds a fade-out effect to an object. The object starts at 100% opacity and decreases by 100%/fraction every frames frames. The object is destroyed when opacity reaches 0. This also sets the OF_MIXER flag. ```APIDOC ## [SYSCALL] SetObjectFadeOut ### Description Adds a fade-out effect to an object. The object starts at 100% opacity and decreases by 100%/fraction every frames frames. The object is destroyed when opacity reaches 0. This also sets the OF_MIXER flag. ### Method SYSCALL ### Endpoint SetObjectFadeOut (objectHandle, fraction, frames) ### Parameters - **objectHandle** (handle) - Required - Handle of the object. - **fraction** (integer) - Required - Denominator of the fade fraction (e.g., 16 means 1/16 per step). - **frames** (integer) - Required - Number of frames between each fade step. ``` -------------------------------- ### 声明外部函数 extern void InitializeBattle (int, int) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 在函数外使用此语法声明外部函数,参数名不是必须的。该函数仅能通过异步方式(asynccall)调用。 ```cpp extern void InitializeBattle (int, int); ``` -------------------------------- ### 异步调用 asynccall InitializeBattle (0, 0) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 必须使用asynccall调用外部函数。和任何异步调用相同,即使目标函数存在返回值,返回值也将被忽略。 ```cpp asynccall InitializeBattle (0, 0); ``` -------------------------------- ### 使用 #include 导入其他文件内容 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt #include 支持双引号或尖括号两种写法。编译器仅检测朴素的循环嵌套(同一文件名被 #include 两次),对复杂情况无能为力。当 use_exe_memory_io = 0 时,无需手动 #include "sg2lang.h",编译器会自动导入;从 0.9.9 起,若 script_memory_io_file 为空则不会自动导入任何文件。 ```sango2 script #include "文件名" ``` ```sango2 script #include <文件名> ``` -------------------------------- ### 不支持的直接调用 InitializeBattle (0, 0) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 若InitializeBattle函数在外部则发生错误,必须使用asynccall调用。 ```cpp InitializeBattle (0, 0); // 若InitializeBattle函数在外部则发生错误 ``` -------------------------------- ### PromptWithFace (dir, strFaceShapePath, strPrompt) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Displays a dialog box with a specified face shape file path and prompt text. The face shape path is used instead of a general portrait. ```APIDOC ## [SYSCALL] PromptWithFace (dir, strFaceShapePath, strPrompt) ### Description Displays a dialog box with a specified face shape file path and prompt text. The face shape path is used instead of a general portrait. ### Method SYSCALL ### Endpoint PromptWithFace (dir, strFaceShapePath, strPrompt) ### Parameters #### Arguments - **dir** (int) - Required - Direction (same as Prompt) - **strFaceShapePath** (string) - Required - Path to face shape file - **strPrompt** (string) - Required - Prompt text ### Response No return value. ``` -------------------------------- ### SYSCALL_TABLE.txt 系统调用声明示例 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt SYSCALL_TABLE.txt 每行由4部分组成:编号、参数个数、返回值类型(0-无,1-整型,2-浮点,3-字符串)、函数名。此例声明了编号为0x10,有5个参数,有整型返回值,名字为 CreateObjectRaw 的函数。 ```text 0x10 5 1 CreateObjectRaw ``` -------------------------------- ### PromptWithFace1 (dir, strFaceShapePath, strPrompt) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Enhanced version of PromptWithFace. Displays a dialog box with a specified face shape file path and prompt text. ```APIDOC ## [SYSCALL] PromptWithFace1 (dir, strFaceShapePath, strPrompt) ### Description Enhanced version of PromptWithFace. Displays a dialog box with a specified face shape file path and prompt text. ### Method SYSCALL ### Endpoint PromptWithFace1 (dir, strFaceShapePath, strPrompt) ### Parameters #### Arguments - **dir** (int) - Required - Direction (same as Prompt) - **strFaceShapePath** (string) - Required - Path to face shape file - **strPrompt** (string) - Required - Prompt text ### Response No return value. ``` -------------------------------- ### Disassemble with sg2dasm2: ./sg2dasm2 .so Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt Run the disassembler on a .so file. It generates an asm file with the same name as the source .so file. Ensure config/SYSCALL_TABLE.txt and config/INTV_TABLE.txt are correct for your game version, or delete them to avoid misleading comments. ```bash ./sg2dasm2 <源文件名>.so ``` -------------------------------- ### AllowBattleOperation (popMenu) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Allows magic casting, battlefield operations, and sets background brightness to 100%. If popMenu is true, a menu is displayed. Used after surrender or before battle to exit battlefield or show menu. ```APIDOC ## AllowBattleOperation (popMenu) ### Description Allows magic casting, battlefield operations, and sets background brightness to 100%. If popMenu is true, a menu is displayed. Used after surrender or before battle to exit battlefield or show menu. ### Method SYSCALL 0x114 ### Parameters - **popMenu** (boolean) - Required - If true, pops up a menu. ``` -------------------------------- ### 异步调用函数 asynccall Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 使用 asynccall 关键字可让函数与后续代码同时执行(类似 CALLBS)。被调函数返回值无意义,必须单独成行,不能包含在表达式中;最多支持 10 个参数,且不能以异步方式调用系统调用或系统指令。从 v0.9.8 起可跨 so 使用。 ```sango2 script asynccall Sol13LongSpcSmokeFade(smoke); ``` ```sango2 script int return_value = asynccall GetValue(); ``` -------------------------------- ### 使用 sg2decomp.exe 反编译 .so 文件 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 反编译器 sg2decomp.exe 的调用方式。默认输出 <源文件名>.decompiled.cpp,默认模式为 structured;失败时尝试 while(1) { switch (...) {}} 或 goto。可用 --mode 指定 structured、goto 或 lossless,用 --report 指定诊断报告文件。 ```text sg2decomp.exe <源文件名>.so [-o <输出文件名>.cpp] [--mode structured|goto|lossless] ``` -------------------------------- ### Prompt1 (dir, pGeneral, strPrompt) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Enhanced version of Prompt with additional functionality. Displays a dialog box with direction, general portrait, and prompt text. ```APIDOC ## [SYSCALL] Prompt1 (dir, pGeneral, strPrompt) ### Description Enhanced version of Prompt with additional functionality. Displays a dialog box with direction, general portrait, and prompt text. ### Method SYSCALL ### Endpoint Prompt1 (dir, pGeneral, strPrompt) ### Parameters #### Arguments - **dir** (int) - Required - Direction (same as Prompt) - **pGeneral** (objectHandle) - Required - General object handle for portrait - **strPrompt** (string) - Required - Prompt text ### Response No return value. ``` -------------------------------- ### Prompt (dir, pGeneral, strPrompt) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Displays a dialog box with a specified direction, general portrait, and prompt text. The direction parameter controls the popup position and portrait alignment. ```APIDOC ## [SYSCALL] Prompt (dir, pGeneral, strPrompt) ### Description Displays a dialog box with a specified direction, general portrait, and prompt text. The direction parameter controls the popup position and portrait alignment. ### Method SYSCALL ### Endpoint Prompt (dir, pGeneral, strPrompt) ### Parameters #### Arguments - **dir** (int) - Required - Direction: 0 (bottom, left portrait), 1 (top, left portrait), 2 (bottom, left portrait forced), 3 (bottom, right portrait forced) - **pGeneral** (objectHandle) - Required - General object handle for portrait - **strPrompt** (string) - Required - Prompt text ### Response No return value. ``` -------------------------------- ### CreateObjectRaw (x, y, z, nDir, dwSequence) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Creates a new object with specified coordinates, direction, and sequence. Returns the object handle or NULL on failure. ```APIDOC ## [SYSCALL] CreateObjectRaw (x, y, z, nDir, dwSequence) ### Description Creates a new object with specified coordinates, direction, and sequence. Returns the object handle or NULL on failure. ### Method SYSCALL ### Endpoint CreateObjectRaw (x, y, z, nDir, dwSequence) ### Parameters #### Arguments - **x** (int) - Required - X coordinate (high 2 bits as integer part) - **y** (int) - Required - Y coordinate (high 2 bits as integer part) - **z** (int) - Required - Z coordinate (high 2 bits as integer part) - **nDir** (int) - Required - Direction - **dwSequence** (int) - Required - Sequence number ### Response Returns objectHandle, or NULL if failed. ``` -------------------------------- ### CreateShadowObject (0x23) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Creates a shadow object (Things.ini ID 1012) that mimics the parent object's appearance and position. The shadow fades out over time based on the fraction and frames parameters. ```APIDOC ## [SYSCALL] CreateShadowObject ### Description Creates a shadow object (Things.ini ID 1012) that mimics the parent object's appearance and position. The shadow fades out over time based on the fraction and frames parameters. ### Method SYSCALL ### Endpoint CreateShadowObject(pFatherObject, fraction, frames) returns shadowObjectHandle ### Parameters - **pFatherObject** (handle) - Required - Handle of the parent object. - **fraction** (integer) - Required - Denominator of the fade fraction (e.g., 16 means 1/16 per step). - **frames** (integer) - Required - Number of frames between each fade step. ### Returns - **shadowObjectHandle** (handle) - Handle of the newly created shadow object. ### Notes - The shadow object has the same x/y/z/nDir as the parent. - The shadow is destroyed when its opacity reaches 0. ``` -------------------------------- ### 编写 naked 底层函数 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 完全用底层方法编写的函数需在返回值类型后加入 naked 标识符,函数体应只包含一个外面不再套大括号的 __asm{} 块。示例展示了如何用底层指令实现 GetByte 函数。 ```sango2 script int naked function GetByte (int address) __asm { PUSHARG address PUSH INTV_ARRAY_BASE SUB PUSH 2 SAR PUSHINVR 0 // data0 = array_base[(address - array_base)] PUSHARG address PUSH INTV_ARRAY_BASE SUB PUSH 0x03 AND PUSH 3 SHL SAR PUSH 0xFF AND // result = (data0 >> ((address - array_base) % 4 * 8)) & 0xFF; RETVAL 1 } ``` -------------------------------- ### Compile Magic.cpp with -a to also generate Magic.so Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt Using the -a option generates both Magic.asm and Magic.so in one step. ```bash ./ss Magic.cpp -a ``` -------------------------------- ### Compile with ss.exe: ./ss [] [-auto/-a] Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt Invoke the compiler from the command line. The second filename always specifies the target asm file, not the .so or .cds file. Use -auto or -a to also generate a .so file, which requires sg2asm.exe in the current directory or PATH. ```bash ./ss <源文件名> [<目标asm文件名>] [-auto / -a] ``` -------------------------------- ### PromptWithMessageIndex (dir, pGeneral, nMessageIndex) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Displays a dialog box with a specified direction, general portrait, and a message from message.ini identified by index. ```APIDOC ## [SYSCALL] PromptWithMessageIndex (dir, pGeneral, nMessageIndex) ### Description Displays a dialog box with a specified direction, general portrait, and a message from message.ini identified by index. ### Method SYSCALL ### Endpoint PromptWithMessageIndex (dir, pGeneral, nMessageIndex) ### Parameters #### Arguments - **dir** (int) - Required - Direction (same as Prompt) - **pGeneral** (objectHandle) - Required - General object handle for portrait - **nMessageIndex** (int) - Required - Index of the message in message.ini ### Response No return value. ``` -------------------------------- ### ApproachObjectTowards (objectHandle, targetHandle, nSpeed) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Moves an object towards a target object at a specified speed (vector length) per frame. ```APIDOC ## [SYSCALL] ApproachObjectTowards (objectHandle, targetHandle, nSpeed) ### Description Moves an object towards a target object at a specified speed (vector length) per frame. ### Method SYSCALL ### Endpoint ApproachObjectTowards (objectHandle, targetHandle, nSpeed) ### Parameters #### Arguments - **objectHandle** (objectHandle) - Required - Handle of the object to move - **targetHandle** (objectHandle) - Required - Handle of the target object - **nSpeed** (int) - Required - Speed (vector length) per frame ### Response No return value. ``` -------------------------------- ### BatchLoadShape (path) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Loads all shape files matching a wildcard pattern. The path uses double backslashes as separators and omits the .shp extension. ```APIDOC ## [SYSCALL] BatchLoadShape (path) ### Description Loads all shape files matching a wildcard pattern. The path uses double backslashes as separators and omits the .shp extension. ### Method SYSCALL ### Endpoint BatchLoadShape (path) ### Parameters #### Arguments - **path** (string) - Required - Wildcard path, e.g., "magic\\000\\*" ### Response No return value. ``` -------------------------------- ### 反汇编命令:./sg2decomp <源文件名>.so Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 在命令行中运行反编译器,对指定的 .so 文件进行反汇编。默认生成 <源文件名>.decompiled.cpp 文件,可用 -o 指定输出文件名。 ```bash ./sg2decomp <源文件名>.so ``` -------------------------------- ### 编写底层代码 __asm 语句块 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 当编译器不支持某些内容或需要严格控制效率时,可直接编写底层代码,用 __asm{} 语句块括起来。编译器会自动替换字符串常量和局部变量名,因此无需关心编号细节。编译器不对底层代码进行任何检查,需格外小心。 ```sango2 script __asm { PUSHSTR "Sol13LongSpcSmokeFade" PUSHARG smoke PUSH 0 PUSH 0 PUSH 0 CALLBS } ``` -------------------------------- ### CreateObjectByReference (referenceObject, dwSequence, nDir, zOffset) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Creates a new object using the coordinates of a reference object with a z-axis offset. Returns the object handle or NULL on failure. ```APIDOC ## [SYSCALL] CreateObjectByReference (referenceObject, dwSequence, nDir, zOffset) ### Description Creates a new object using the coordinates of a reference object with a z-axis offset. Returns the object handle or NULL on failure. ### Method SYSCALL ### Endpoint CreateObjectByReference (referenceObject, dwSequence, nDir, zOffset) ### Parameters #### Arguments - **referenceObject** (objectHandle) - Required - Reference object handle - **dwSequence** (int) - Required - Sequence number - **nDir** (int) - Required - Direction - **zOffset** (int) - Required - Z-axis offset from reference object ### Response Returns objectHandle, or NULL if failed. ``` -------------------------------- ### 使用 #define 宏定义替换代码内容 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt #define 执行简单粗暴的字符串替换,常用于定义常量。行末不需要分号,除非分号本身是替换内容的一部分。示例将 OBJECT_LIST_ROOT 替换为 (SangoObject**) 0x4A64A0。 ```sango2 script #define OBJECT_LIST_ROOT (SangoObject**) 0x4A64A0 ``` -------------------------------- ### 使用预设变量 intv 替代 GetIntv 调用 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 当 config/INTV_TABLE.txt 中定义了预设变量名时,可直接用变量名(如 intvAttackerMajor)代替 GetIntv(2) 读取值,也可直接赋值(如 intvCurrentYear = 200;)。暂不支持数组形式的 intv,需使用 GetIntv/SetIntv 存取。 ```text intvPeriod 0x00 intvAttackerMajor 0x02 intvDefenderMajor 0x03 intvMagicAttackValue 0x04 ``` ```sango2 script intvCurrentYear = 200; ``` -------------------------------- ### PromptWithMessageIndex1 (dir, pGeneral, nMessageIndex) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Enhanced version of PromptWithMessageIndex. Displays a dialog box with a specified direction, general portrait, and a message from message.ini. ```APIDOC ## [SYSCALL] PromptWithMessageIndex1 (dir, pGeneral, nMessageIndex) ### Description Enhanced version of PromptWithMessageIndex. Displays a dialog box with a specified direction, general portrait, and a message from message.ini. ### Method SYSCALL ### Endpoint PromptWithMessageIndex1 (dir, pGeneral, nMessageIndex) ### Parameters #### Arguments - **dir** (int) - Required - Direction (same as Prompt) - **pGeneral** (objectHandle) - Required - General object handle for portrait - **nMessageIndex** (int) - Required - Index of the message in message.ini ### Response No return value. ``` -------------------------------- ### 使用函数指针 SangoObject* objptr = GetObjectByHandle(intvAttackerMajor) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 调用了EXE中的0x421A80函数,参数为intvAttackerMajor,返回值储存在objptr局部变量中。 ```cpp SangoObject* objptr = GetObjectByHandle(intvAttackerMajor); ``` -------------------------------- ### BattleXToScreenX (battleX) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Converts a battlefield X coordinate to a screen X coordinate. Only integer values are returned. ```APIDOC ## BattleXToScreenX (battleX) ### Description Converts a battlefield X coordinate to a screen X coordinate. Only integer values are returned. ### Method SYSCALL 0x103 ### Parameters - **battleX** (integer) - Required - Battlefield X coordinate. ### Returns - **screenX** (integer) - Screen X coordinate. ``` -------------------------------- ### CreateSoldier (isLeft, battleX, battleY) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Creates a soldier at the specified battlefield coordinates. By default, creates a low-level soldier. If using 1.05+ or with script support patch, adding 0x10000 to battleX creates a high-level soldier. The soldier type matches the current type of the side. ```APIDOC ## CreateSoldier (isLeft, battleX, battleY) ### Description Creates a soldier at the specified battlefield coordinates. By default, creates a low-level soldier. If using 1.05+ or with script support patch, adding 0x10000 to battleX creates a high-level soldier. The soldier type matches the current type of the side. ### Method SYSCALL 0x119 ### Parameters - **isLeft** (boolean) - Required - True for left side, false for right side. - **battleX** (integer) - Required - Battlefield X coordinate. Add 0x10000 for high-level soldier. - **battleY** (integer) - Required - Battlefield Y coordinate. ### Returns - **soldierHandle** (handle) - Handle of the created soldier. ``` -------------------------------- ### Compile Magic.cpp to Custom.asm with -a Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt The second filename always specifies the target asm file. This command generates Custom.asm and Custom.so. ```bash ./ss Magic.cpp Custom.asm -a ``` -------------------------------- ### CreateShadowObject1 (0x24) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Creates a shadow object similar to CreateShadowObject, but with an additional parameter to set the direction (nDir). ```APIDOC ## [SYSCALL] CreateShadowObject1 ### Description Creates a shadow object similar to CreateShadowObject, but with an additional parameter to set the direction (nDir). ### Method SYSCALL ### Endpoint CreateShadowObject1(pFatherObject, fraction, frames, nDir) returns shadowObjectHandle ### Parameters - **pFatherObject** (handle) - Required - Handle of the parent object. - **fraction** (integer) - Required - Denominator of the fade fraction. - **frames** (integer) - Required - Number of frames between each fade step. - **nDir** (integer) - Required - Direction value for the shadow object. ### Returns - **shadowObjectHandle** (handle) - Handle of the newly created shadow object. ``` -------------------------------- ### ScreenXToBattleX (screenX) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Converts a screen X coordinate to a battlefield X coordinate. ```APIDOC ## ScreenXToBattleX (screenX) ### Description Converts a screen X coordinate to a battlefield X coordinate. ### Method SYSCALL 0x108 ### Parameters - **screenX** (integer) - Required - Screen X coordinate. ### Returns - **battleX** (integer) - Battlefield X coordinate. ``` -------------------------------- ### SetObjectLayer (objectHandle, nLayer) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the stacking order of the object. Default is -1. If set to a positive number, the object is placed behind all other battlefield objects (but still in front of the background). Smaller numbers are further back. 0 makes it invisible (but not destroyed). The value is a short (WORD) and must be <= 32767. ```APIDOC ## SetObjectLayer (objectHandle, nLayer) ### Description Sets the stacking order of the object. Default is -1. If set to a positive number, the object is placed behind all other battlefield objects (but still in front of the background). Smaller numbers are further back. 0 makes it invisible (but not destroyed). The value is a short (WORD) and must be <= 32767. ### Method SYSCALL 0x31 ### Parameters - **objectHandle** (handle) - Required - Handle of the object. - **nLayer** (integer) - Required - Layer value (short, <= 32767). ``` -------------------------------- ### 使用系统指令 GetIntv 获取预设变量 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 系统指令可以像调用函数一样正常调用,并可在表达式中使用。此例通过 GetIntv(INTV_ATTACKER_MAJOR) 获取攻击方武将信息。 ```c int attackerMajor = GetIntv(INTV_ATTACKER_MAJOR); ``` -------------------------------- ### SetObjectDir (objectHandle, nDir) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the direction of the object. Direction 0 is right (positive x-axis), 64 points to background (positive y-axis), 128 is left. The direction is cyclic with 256 as full rotation. ```APIDOC ## SetObjectDir (objectHandle, nDir) ### Description Sets the direction of the object. Direction 0 is right (positive x-axis), 64 points to background (positive y-axis), 128 is left. The direction is cyclic with 256 as full rotation. ### Method SYSCALL 0x30 ### Parameters - **objectHandle** (handle) - Required - Handle of the object. - **nDir** (integer) - Required - Direction value (0-255). ``` -------------------------------- ### GetObjectSequence (objectHandle) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Retrieves the sequence value of a magic object, as defined in things.ini. ```APIDOC ## GetObjectSequence (objectHandle) ### Description Retrieves the sequence value of a magic object, as defined in things.ini. ### Method SYSCALL 0x2D ### Parameters - **objectHandle** (handle) - Required - Handle of the object. ### Returns - **sequence** (integer) - The sequence value. ``` -------------------------------- ### STRUCT_TABLE.txt 结构体定义示例(SOLDIER_INFO) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 在 config/STRUCT_TABLE.txt 中定义结构体,格式为名称、大小、成员偏移量、成员名和类型。编译器会将全大写+下划线的名称自动转化为骆驼式命名法(如 SOLDIER_INFO 变为 SoldierInfo)。 ```text SOLDIER_INFO 0x48 00000000 pGeneral GENERAL * 00000004 field_4 int 00000008 x1 int 0000000C y1 int 00000010 x2 int 00000014 y2 int 00000018 pObject SANGO_OBJECT * (......) end ``` -------------------------------- ### 指针取值示例:SangoObject* firstObject = *(pObjectListRoot); Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 通过 * 运算符取得 0x4A64A0 内存地址处的值,并赋值给 firstObject。 ```c SangoObject* firstObject = *(pObjectListRoot); ``` -------------------------------- ### MoveObjectTo (objectHandle, targetHandle, nSpeed) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Alias for ApproachObjectTowards. Moves an object towards a target object at a specified speed. ```APIDOC ## [SYSCALL] MoveObjectTo (objectHandle, targetHandle, nSpeed) ### Description Alias for ApproachObjectTowards. Moves an object towards a target object at a specified speed. ### Method SYSCALL ### Endpoint MoveObjectTo (objectHandle, targetHandle, nSpeed) ### Parameters #### Arguments - **objectHandle** (objectHandle) - Required - Handle of the object to move - **targetHandle** (objectHandle) - Required - Handle of the target object - **nSpeed** (int) - Required - Speed (vector length) per frame ### Response No return value. ``` -------------------------------- ### 使用 handle 类型获取士兵物件 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt handle 类型是一种整型,用于指代图形物件。此例通过 GetScriptLinkedObject() 取得一个士兵的物件。 ```c int attackerSoldier = GetScriptLinkedObject(); ``` -------------------------------- ### BattleYToScreenY (battleY) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Converts a battlefield Y coordinate to a screen Y coordinate. Note: X and Y conversion functions are not interchangeable. ```APIDOC ## BattleYToScreenY (battleY) ### Description Converts a battlefield Y coordinate to a screen Y coordinate. Note: X and Y conversion functions are not interchangeable. ### Method SYSCALL 0x104 ### Parameters - **battleY** (integer) - Required - Battlefield Y coordinate. ### Returns - **screenY** (integer) - Screen Y coordinate. ``` -------------------------------- ### SetObjectBrightness (0x27) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the brightness (or opacity) of an object. This is the official brightness setter. ```APIDOC ## [SYSCALL] SetObjectBrightness ### Description Sets the brightness (or opacity) of an object. This is the official brightness setter. ### Method SYSCALL ### Endpoint SetObjectBrightness (objectHandle, nBrightness) ### Parameters - **objectHandle** (handle) - Required - Handle of the object. - **nBrightness** (integer) - Required - Brightness value. ``` -------------------------------- ### ScreenYToBattleY (screenY) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Converts a screen Y coordinate to a battlefield Y coordinate. Note: X and Y conversion functions are not interchangeable. ```APIDOC ## ScreenYToBattleY (screenY) ### Description Converts a screen Y coordinate to a battlefield Y coordinate. Note: X and Y conversion functions are not interchangeable. ### Method SYSCALL 0x109 ### Parameters - **screenY** (integer) - Required - Screen Y coordinate. ### Returns - **battleY** (integer) - Battlefield Y coordinate. ``` -------------------------------- ### GetCameraX () Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Retrieves the camera X coordinate. ```APIDOC ## GetCameraX () ### Description Retrieves the camera X coordinate. ### Method SYSCALL 0x111 ### Parameters None. ### Returns - **cameraX** (integer) - Camera X coordinate. ``` -------------------------------- ### EnablePlayMagic () Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Allows the enemy to cast magic skills. This clears the flag at 4A6660. ```APIDOC ## EnablePlayMagic () ### Description Allows the enemy to cast magic skills. This clears the flag at 4A6660. ### Method SYSCALL 0x110 ### Parameters None. ``` -------------------------------- ### SetCallbackProcedure (objectHandle, callbackFuncCallsign) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the callback procedure for a magic object. When the object hits a target, the specified callback function (identified by its Script callsign) is invoked to determine damage. ```APIDOC ## SetCallbackProcedure (objectHandle, callbackFuncCallsign) ### Description Sets the callback procedure for a magic object. When the object hits a target, the specified callback function (identified by its Script callsign) is invoked to determine damage. ### Method SYSCALL 0x2C ### Parameters - **objectHandle** (handle) - Required - Handle of the magic object. - **callbackFuncCallsign** (integer) - Required - Script callsign of the callback function (e.g., 610 for 鬼哭). ### Remarks - The callback is triggered when the object hits a target, based on flags OF_ENEMYFORCE, OF_ENEMYGENERAL, OF_MYFORCE, OF_MYGENERAL. - Flags can be combined (OF_ATTACKENEMY, OF_ATTACKMY, OF_ATTACKALL). ``` -------------------------------- ### 使用 [] 和 . 运算符访问内嵌结构体数组元素 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 通过 pBattleUserInfo->pSoldierInfo[100] 获取第100个 SoldierInfo 结构体,再用 . 运算符访问其 pObject 成员。 ```c SangoObject* obj = pBattleUserInfo->pSoldierInfo[100].pObject; ``` -------------------------------- ### IsObjectExist (objectHandle) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Checks if the object corresponding to the given handle exists. Returns true if exists, false otherwise. ```APIDOC ## [SYSCALL] IsObjectExist (objectHandle) ### Description Checks if the object corresponding to the given handle exists. Returns true if exists, false otherwise. ### Method SYSCALL ### Endpoint IsObjectExist (objectHandle) ### Parameters #### Arguments - **objectHandle** (objectHandle) - Required - Handle of the object to check ### Response Returns true if exists, false if not exists. ``` -------------------------------- ### 设置命令行编码为 GBK (chcp 936) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 编译错误信息由 GBK 编码的中文输出。如果代码页被指定为 UTF-8 或其他编码,请在命令行中输入 chcp 936 来指定系统命令行所使用的编码。 ```batch chcp 936 ``` -------------------------------- ### 使用 -> 运算符访问结构体成员 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 通过指针访问结构体成员,例如取得 SoldierInfo* 指针指向的结构体中 x1 成员的值。 ```c int x1 = pSoldierInfo->x1; ``` -------------------------------- ### SetSXString (dir, index, string) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the replacement string for the %SX% placeholder in dialog prompts. Typically used with GetGeneralName to insert general names into prompt text. ```APIDOC ## [SYSCALL] SetSXString (dir, index, string) ### Description Sets the replacement string for the %SX% placeholder in dialog prompts. Typically used with GetGeneralName to insert general names into prompt text. ### Method SYSCALL ### Endpoint SetSXString (dir, index, string) ### Parameters #### Arguments - **dir** (int) - Required - Direction (same as Prompt) - **index** (int) - Required - Index of the placeholder (e.g., 1 for %S1%) - **string** (string) - Required - Replacement string ### Response No return value. ``` -------------------------------- ### SetViewCamera (x, y) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the camera position (view) to the specified coordinates. ```APIDOC ## SetViewCamera (x, y) ### Description Sets the camera position (view) to the specified coordinates. ### Method SYSCALL 0x100 ### Parameters - **x** (integer) - Required - Camera X coordinate. - **y** (integer) - Required - Camera Y coordinate. ``` -------------------------------- ### SetCameraByReference (objectHandle, xOffset, yOffset) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the camera position relative to an object's coordinates, i.e., aligns to (object.x + xOffset, object.y + yOffset). ```APIDOC ## SetCameraByReference (objectHandle, xOffset, yOffset) ### Description Sets the camera position relative to an object's coordinates, i.e., aligns to (object.x + xOffset, object.y + yOffset). ### Method SYSCALL 0x10F ### Parameters - **objectHandle** (handle) - Required - Handle of the reference object. - **xOffset** (integer) - Required - X offset from the object. - **yOffset** (integer) - Required - Y offset from the object. ``` -------------------------------- ### STRUCT_TABLE.txt 内嵌结构体与数组定义(BATTLE_USER_INFO) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 定义包含内嵌结构体(MAJOR_INFO)和结构体数组(SOLDIER_INFO 200 dup)的结构体。数组长度用 dup 关键字表示。 ```text BATTLE_USER_INFO 0x38F8 00000000 pMajorInfo MAJOR_INFO 00000048 pGeneral GENERAL * 0000004C nGatherTick int (...) 000000B0 field_B0 int 000000B4 pSoldierInfo SOLDIER_INFO 200 dup 000038F4 dwPadding int end ``` -------------------------------- ### GetRandomSoldierHandleFromAlive (isLeft) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Retrieves the handle of a random alive soldier from the specified side. The parameter is isLeft, not isRight. ```APIDOC ## GetRandomSoldierHandleFromAlive (isLeft) ### Description Retrieves the handle of a random alive soldier from the specified side. The parameter is isLeft, not isRight. ### Method SYSCALL 0x10D ### Parameters - **isLeft** (boolean) - Required - True for left side, false for right side. ### Returns - **soldierHandle** (handle) - Handle of a random alive soldier. ### Aliases - GetRandomSoldierFromAlive (isLeft) ``` -------------------------------- ### SetObjectLife (0x1F) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the remaining life of an object. Life decreases by 1 each frame and the object is destroyed when it reaches 0. If the initial life is 0, the object has infinite life and will not be destroyed automatically. ```APIDOC ## [SYSCALL] SetObjectLife ### Description Sets the remaining life of an object. Life decreases by 1 each frame and the object is destroyed when it reaches 0. If the initial life is 0, the object has infinite life and will not be destroyed automatically. ### Method SYSCALL ### Endpoint SetObjectLife (objectHandle, nLife) ### Parameters - **objectHandle** (handle) - Required - Handle of the object. - **nLife** (integer) - Required - Initial life value. 0 means infinite life. ``` -------------------------------- ### GetObjectDir (objectHandle) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Returns the direction of the specified object. ```APIDOC ## [SYSCALL] GetObjectDir (objectHandle) ### Description Returns the direction of the specified object. ### Method SYSCALL ### Endpoint GetObjectDir (objectHandle) ### Parameters #### Arguments - **objectHandle** (objectHandle) - Required - Handle of the object ### Response Returns nDir (int). ``` -------------------------------- ### 变量声明示例:int x = 1, y, z; Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 声明三个 int 型变量 x, y, z,并将 x 初始化为 1。支持声明时直接赋值。 ```c int x = 1, y, z; ``` -------------------------------- ### GetObjectBattleX (objectHandle) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Retrieves the battlefield X coordinate of an object. Note: This is the first part of the poorly named GetObjectXY; use with GetObjectBattleY. ```APIDOC ## GetObjectBattleX (objectHandle) ### Description Retrieves the battlefield X coordinate of an object. Note: This is the first part of the poorly named GetObjectXY; use with GetObjectBattleY. ### Method SYSCALL 0x101 ### Parameters - **objectHandle** (handle) - Required - Handle of the object. ### Returns - **battleX** (integer) - Battlefield X coordinate. ``` -------------------------------- ### 字符串连接示例:string output = "i = " + ((string) i) + "; %k%%e%" Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 使用 + 运算符连接字符串,将整型 i 转换为字符串后拼接。字符串之间可以比较,+ 运算符可用于连接两个字符串。 ```c string output = "i = " + ((string) i) + "; %k%%e%" ``` -------------------------------- ### GetObjectScreenX (objectHandle) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Retrieves the screen X coordinate of an object. This works for all objects, despite the original name GetMajorScreenX. ```APIDOC ## GetObjectScreenX (objectHandle) ### Description Retrieves the screen X coordinate of an object. This works for all objects, despite the original name GetMajorScreenX. ### Method SYSCALL 0x105 ### Parameters - **objectHandle** (handle) - Required - Handle of the object. ### Returns - **screenX** (integer) - Screen X coordinate. ``` -------------------------------- ### 定义函数指针 SangoObject* (*GetObjectByHandle) (int handle) = 0x421A80 Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 定义了一个名为GetObjectByHandle的函数指针,该函数有1个整型参数,返回值为SangoObject*指针类型。函数指针指向EXE中的0x421A80函数。 ```cpp SangoObject* (*GetObjectByHandle) (int handle) = 0x421A80; ``` -------------------------------- ### SetCallbackContext (objectHandle, i, value) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Stores a value in the object's callback context slot (index 0-2). This context can be used to pass data to the callback function, but can also store any arbitrary data. ```APIDOC ## SetCallbackContext (objectHandle, i, value) ### Description Stores a value in the object's callback context slot (index 0-2). This context can be used to pass data to the callback function, but can also store any arbitrary data. ### Method SYSCALL 0x2E ### Parameters - **objectHandle** (handle) - Required - Handle of the object. - **i** (integer) - Required - Index of the context slot (0-2). - **value** (integer) - Required - Value to store. ### Aliases - SetObjectContext (objectHandle, i, value) ``` -------------------------------- ### 定义全局变量数组 int g_Interceptors[60] Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 全局变量应在函数外定义,定义格式与局部变量完全相同,但不支持在定义时赋值。数组长度只能是常整型。 ```cpp int g_Interceptors[60]; ``` -------------------------------- ### SetObjectDrawingFileItem (0x1C) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Loads a shape from a specified path and sets it as the object's drawing file item, causing the object to always display that shape. This is typically used for magic objects to change their appearance dynamically. ```APIDOC ## [SYSCALL] SetObjectDrawingFileItem ### Description Loads a shape from a specified path and sets it as the object's drawing file item, causing the object to always display that shape. This is typically used for magic objects to change their appearance dynamically. ### Method SYSCALL ### Endpoint SetObjectDrawingFileItem (objectHandle, strShape) ### Parameters - **objectHandle** (handle) - Required - Handle of the object. - **strShape** (string) - Required - Path to the shape to load (e.g., "major//body//RDW10001"). ### Notes - The object will always display the specified shape and lose animation. - Commonly used on magic objects to change appearance. ``` -------------------------------- ### 指针声明示例:SangoObject** pObjectListRoot = (SangoObject**) 0x4A64A0; Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/Userguide_CN.txt 声明一个指向 SangoObject 指针的指针,并初始化为内存地址 0x4A64A0。指针类型本质上是一种整型类型,可以和整型互相转化。 ```c SangoObject** pObjectListRoot = (SangoObject**) 0x4A64A0; ``` -------------------------------- ### SetObjectTarget (objectHandle, targetHandle) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Sets the target object for the magic object (used with OF_TARGET flag). When the object hits the target, it plays the OAF_DEATH sequence. Note: This function is untested and not used by original magic skills. ```APIDOC ## SetObjectTarget (objectHandle, targetHandle) ### Description Sets the target object for the magic object (used with OF_TARGET flag). When the object hits the target, it plays the OAF_DEATH sequence. Note: This function is untested and not used by original magic skills. ### Method SYSCALL 0x10E ### Parameters - **objectHandle** (handle) - Required - Handle of the magic object. - **targetHandle** (handle) - Required - Handle of the target object. ``` -------------------------------- ### GetForceHandle (battleX, battleY) Source: https://github.com/allenzhoukp/sango2sspseudocompiler/blob/master/magic_inst.txt Retrieves the handle of the soldier or general at the specified battlefield coordinates. This works for both soldiers and generals. ```APIDOC ## GetForceHandle (battleX, battleY) ### Description Retrieves the handle of the soldier or general at the specified battlefield coordinates. This works for both soldiers and generals. ### Method SYSCALL 0x113 ### Parameters - **battleX** (integer) - Required - Battlefield X coordinate. - **battleY** (integer) - Required - Battlefield Y coordinate. ### Returns - **forceHandle** (handle) - Handle of the force at the given coordinates. ### Aliases - GetForceHandleByXY (battleX, battleY) ```