mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Minor refactoring of ScriptValue and some script function handlers.
This commit is contained in:
+2
-3
@@ -335,10 +335,9 @@ const char* _stdcall GetSfallTypeName(DWORD dataType) {
|
||||
}
|
||||
|
||||
DWORD _stdcall getSfallTypeByScriptType(DWORD varType) {
|
||||
varType &= 0xffff;
|
||||
switch (varType) {
|
||||
case VAR_TYPE_STR:
|
||||
switch (varType & 0xFFFF) {
|
||||
case VAR_TYPE_STR2:
|
||||
case VAR_TYPE_STR:
|
||||
return DATATYPE_STR;
|
||||
case VAR_TYPE_FLOAT:
|
||||
return DATATYPE_FLOAT;
|
||||
|
||||
+15
-12
@@ -39,7 +39,7 @@
|
||||
static DWORD _stdcall HandleMapUpdateForScripts(const DWORD procId);
|
||||
|
||||
// variables for new opcodes
|
||||
#define OP_MAX_ARGUMENTS (10)
|
||||
#define OP_MAX_ARGUMENTS (8)
|
||||
|
||||
// masks for argument validation
|
||||
#define DATATYPE_MASK_INT (1 << DATATYPE_INT)
|
||||
@@ -156,10 +156,14 @@ public:
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
const char* String() const {
|
||||
const char* strValue() const {
|
||||
return _val.str;
|
||||
}
|
||||
|
||||
float floatValue() const {
|
||||
return _val.f;
|
||||
}
|
||||
|
||||
SfallDataType type() const {
|
||||
return _type;
|
||||
}
|
||||
@@ -333,12 +337,11 @@ public:
|
||||
// process return value
|
||||
if (hasReturn) {
|
||||
if (_ret.type() == DATATYPE_NONE) {
|
||||
// if no value was set in handler, force return 0 to avoid stack error
|
||||
_ret = ScriptValue(0);
|
||||
_ret = ScriptValue(0); // if no value was set in handler, force return 0 to avoid stack error
|
||||
}
|
||||
DWORD rawResult = _ret.rawValue();
|
||||
if (_ret.type() == DATATYPE_STR) {
|
||||
rawResult = InterpretAddString(program, _ret.asString());
|
||||
rawResult = InterpretAddString(program, _ret.strValue());
|
||||
}
|
||||
InterpretPushLong(program, rawResult);
|
||||
InterpretPushShort(program, getScriptTypeBySfallType(_ret.type()));
|
||||
@@ -604,7 +607,7 @@ static void SetGlobalVarFunc() {
|
||||
|
||||
if ((varArg.isInt() || varArg.isString()) && (valArg.isInt() || valArg.isFloat())) {
|
||||
if (varArg.isString()) {
|
||||
if (SetGlobalVar2(varArg.String(), valArg.rawValue())) {
|
||||
if (SetGlobalVar2(varArg.strValue(), valArg.rawValue())) {
|
||||
opHandler.printOpcodeError("set_sfall_global() - The name of the global variable must consist of 8 characters.");
|
||||
}
|
||||
} else {
|
||||
@@ -645,7 +648,7 @@ static void GetGlobalVarIntFunc() {
|
||||
|
||||
if (varArg.isInt() || varArg.isString()) {
|
||||
if (varArg.isString()) {
|
||||
const char* var = varArg.String();
|
||||
const char* var = varArg.strValue();
|
||||
if (strlen(var) != 8) {
|
||||
opHandler.printOpcodeError("get_sfall_global_int() - The name of the global variable must consist of 8 characters.");
|
||||
} else {
|
||||
@@ -671,7 +674,7 @@ static void GetGlobalVarFloatFunc() {
|
||||
|
||||
if (varArg.isInt() || varArg.isString()) {
|
||||
if (varArg.isString()) {
|
||||
const char* var = varArg.String();
|
||||
const char* var = varArg.strValue();
|
||||
if (strlen(var) != 8) {
|
||||
opHandler.printOpcodeError("get_sfall_global_float() - The name of the global variable must consist of 8 characters.");
|
||||
} else {
|
||||
@@ -1326,10 +1329,10 @@ void ScriptExtenderSetup() {
|
||||
dlogr(" Unsafe opcodes disabled.", DL_SCRIPT);
|
||||
}
|
||||
|
||||
SafeWrite32(0x46E370, 0x300); //Maximum number of allowed opcodes
|
||||
SafeWrite32(0x46ce34, (DWORD)opcodes); //cmp check to make sure opcode exists
|
||||
SafeWrite32(0x46ce6c, (DWORD)opcodes); //call that actually jumps to the opcode
|
||||
SafeWrite32(0x46e390, (DWORD)opcodes); //mov that writes to the opcode
|
||||
SafeWrite32(0x46E370, 0x300); // Maximum number of allowed opcodes
|
||||
SafeWrite32(0x46CE34, (DWORD)opcodes); // cmp check to make sure opcode exists
|
||||
SafeWrite32(0x46CE6C, (DWORD)opcodes); // call that actually jumps to the opcode
|
||||
SafeWrite32(0x46E390, (DWORD)opcodes); // mov that writes to the opcode
|
||||
|
||||
opcodes[0x156] = ReadByte;
|
||||
opcodes[0x157] = ReadShort;
|
||||
|
||||
@@ -257,16 +257,16 @@ next:
|
||||
|
||||
mov ecx, eax;
|
||||
mov eax, 3;
|
||||
push 1;
|
||||
mov al, ds:[0x006AB718];
|
||||
push eax;
|
||||
push 0;
|
||||
push eax;
|
||||
push 0x74;
|
||||
mov ecx, 0xC0;
|
||||
mov eax, esi;
|
||||
xor ebx, ebx;
|
||||
xor edx, edx;
|
||||
push 1; // arg10
|
||||
mov al, byte ptr ds:[0x6AB718];
|
||||
push eax; // a9
|
||||
push 0; // *DisplayText
|
||||
push eax; // ColorIndex
|
||||
push 0x74; // y
|
||||
mov ecx, 0xC0; // x
|
||||
mov eax, esi; // text
|
||||
xor ebx, ebx; // ?
|
||||
xor edx, edx; // ?
|
||||
call dialog_out_;
|
||||
//xor eax, eax;
|
||||
end:
|
||||
|
||||
@@ -82,13 +82,13 @@ static void sf_test() {
|
||||
|
||||
// returns current contents of metarule table
|
||||
static void sf_get_metarule_table() {
|
||||
DWORD arr = TempArray(metaruleTable.size(), 0);
|
||||
DWORD arrId = TempArray(metaruleTable.size(), 0);
|
||||
int i = 0;
|
||||
for (MetaruleTableType::iterator it = metaruleTable.begin(); it != metaruleTable.end(); it++) {
|
||||
arrays[arr].val[i].set(it->first.c_str());
|
||||
arrays[arrId].val[i].set(it->first.c_str());
|
||||
i++;
|
||||
}
|
||||
opHandler.setReturn(arr, DATATYPE_INT);
|
||||
opHandler.setReturn(arrId, DATATYPE_INT);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -155,8 +155,8 @@ static bool ValidateMetaruleArguments(const SfallMetarule* metaruleInfo) {
|
||||
metaruleInfo->name,
|
||||
argCount,
|
||||
metaruleInfo->minArgs,
|
||||
metaruleInfo->maxArgs);
|
||||
|
||||
metaruleInfo->maxArgs
|
||||
);
|
||||
return false;
|
||||
} else {
|
||||
// check if metadata is available for this handler
|
||||
@@ -174,7 +174,7 @@ static bool ValidateMetaruleArguments(const SfallMetarule* metaruleInfo) {
|
||||
static void _stdcall op_sfall_metarule_handler() {
|
||||
const ScriptValue &nameArg = opHandler.arg(0);
|
||||
if (nameArg.isString()) {
|
||||
const char* name = nameArg.asString();
|
||||
const char* name = nameArg.strValue();
|
||||
MetaruleTableType::iterator lookup = metaruleTable.find(name);
|
||||
if (lookup != metaruleTable.end()) {
|
||||
currentMetarule = lookup->second;
|
||||
|
||||
@@ -1673,7 +1673,7 @@ static void sf_set_ini_setting() {
|
||||
const ScriptValue &argVal = opHandler.arg(1);
|
||||
|
||||
if (argVal.isInt()) {
|
||||
_itoa_s(argVal.asInt(), IniStrBuffer, 10);
|
||||
_itoa_s(argVal.rawValue(), IniStrBuffer, 10);
|
||||
} else {
|
||||
strcpy_s(IniStrBuffer, argVal.asString());
|
||||
}
|
||||
|
||||
@@ -520,8 +520,8 @@ static void _stdcall op_obj_is_carrying_obj2() {
|
||||
&itemObjArg = opHandler.arg(1);
|
||||
|
||||
if (invenObjArg.isInt() && itemObjArg.isInt()) {
|
||||
TGameObj *invenObj = (TGameObj*)invenObjArg.asObject(),
|
||||
*itemObj = (TGameObj*)itemObjArg.asObject();
|
||||
TGameObj *invenObj = invenObjArg.asObject(),
|
||||
*itemObj = itemObjArg.asObject();
|
||||
if (invenObj != nullptr && itemObj != nullptr) {
|
||||
for (int i = 0; i < invenObj->invenCount; i++) {
|
||||
if (invenObj->invenTablePtr[i].object == itemObj) {
|
||||
|
||||
@@ -71,7 +71,7 @@ end:
|
||||
static void funcAbs2() {
|
||||
const ScriptValue &value = opHandler.arg(0);
|
||||
if (value.isInt()) {
|
||||
opHandler.setReturn(abs(value.asInt()));
|
||||
opHandler.setReturn(abs((int)value.rawValue()));
|
||||
} else {
|
||||
opHandler.setReturn(abs(value.asFloat()));
|
||||
}
|
||||
@@ -723,7 +723,7 @@ static void funcPow2() {
|
||||
float result = 0.0;
|
||||
if (!base.isString() && !power.isString()) {
|
||||
if (power.isFloat())
|
||||
result = pow(base.asFloat(), power.asFloat());
|
||||
result = pow(base.asFloat(), power.floatValue());
|
||||
else
|
||||
result = pow(base.asFloat(), power.asInt());
|
||||
|
||||
@@ -784,27 +784,28 @@ static void __declspec(naked) funcRound() {
|
||||
*/
|
||||
|
||||
// TODO: move to FalloutEngine module
|
||||
static const DWORD game_msg_files[] =
|
||||
{ 0x56D368 // COMBAT
|
||||
, 0x56D510 // AI
|
||||
, 0x56D754 // SCRNAME
|
||||
, 0x58E940 // MISC
|
||||
, 0x58EA98 // CUSTOM
|
||||
, 0x59E814 // INVENTRY
|
||||
, 0x59E980 // ITEM
|
||||
, 0x613D28 // LSGAME
|
||||
, 0x631D48 // MAP
|
||||
, 0x6637E8 // OPTIONS
|
||||
, 0x6642D4 // PERK
|
||||
, 0x664348 // PIPBOY
|
||||
, 0x664410 // QUESTS
|
||||
, 0x6647FC // PROTO
|
||||
, 0x667724 // SCRIPT
|
||||
, 0x668080 // SKILL
|
||||
, 0x6680F8 // SKILLDEX
|
||||
, 0x66817C // STAT
|
||||
, 0x66BE38 // TRAIT
|
||||
, 0x672FB0 }; // WORLDMAP
|
||||
static const DWORD game_msg_files[] = {
|
||||
0x56D368, // COMBAT
|
||||
0x56D510, // AI
|
||||
0x56D754, // SCRNAME
|
||||
0x58E940, // MISC
|
||||
0x58EA98, // CUSTOM
|
||||
0x59E814, // INVENTRY
|
||||
0x59E980, // ITEM
|
||||
0x613D28, // LSGAME
|
||||
0x631D48, // MAP
|
||||
0x6637E8, // OPTIONS
|
||||
0x6642D4, // PERK
|
||||
0x664348, // PIPBOY
|
||||
0x664410, // QUESTS
|
||||
0x6647FC, // PROTO
|
||||
0x667724, // SCRIPT
|
||||
0x668080, // SKILL
|
||||
0x6680F8, // SKILLDEX
|
||||
0x66817C, // STAT
|
||||
0x66BE38, // TRAIT
|
||||
0x672FB0, // WORLDMAP
|
||||
};
|
||||
|
||||
// TODO: move to FalloutEngine
|
||||
static const DWORD* proto_msg_files = (DWORD*)0x006647AC;
|
||||
|
||||
Reference in New Issue
Block a user