mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Code edits to ScriptExtender.cpp/SpeedPatch.cpp
Minor edits to some files.
This commit is contained in:
+3
-3
@@ -11,7 +11,7 @@ UseCommandLine=0
|
|||||||
|
|
||||||
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
[Speed]
|
[Speed]
|
||||||
;Set to 0 to disable everything in this section
|
;Set to 1 to enable options related to the game speed adjustment (SpeedMulti#, SpeedKey#, SpeedModKey, and SpeedToggleKey)
|
||||||
Enable=1
|
Enable=1
|
||||||
|
|
||||||
;The speeds corresponding to each slot in percent. (i.e. 100 is normal speed)
|
;The speeds corresponding to each slot in percent. (i.e. 100 is normal speed)
|
||||||
@@ -615,9 +615,9 @@ AttackComplexFix=0
|
|||||||
;Note that enabling this option may cause unexpected results with some existing game scripts
|
;Note that enabling this option may cause unexpected results with some existing game scripts
|
||||||
CreateObjectSidFix=0
|
CreateObjectSidFix=0
|
||||||
|
|
||||||
;Set to 1 to make grave type containers in the open state run the 'use_p_proc' procedure of attached script when being used
|
;Set to 1 to fix the execution of the 'use_p_proc' procedure for grave type containers when they are in the open state
|
||||||
;By default, using open graves does not run the 'use_p_proc' procedure of attached script like other containers
|
;By default, using open graves does not run the 'use_p_proc' procedure of attached script like other containers
|
||||||
;Note that enabling this option will cause problems for many existing graves
|
;Note that enabling this option will cause problems for existing grave scripts
|
||||||
GraveUseProcFix=0
|
GraveUseProcFix=0
|
||||||
|
|
||||||
;Set to 1 to fix the issue with the division operator treating negative integers as unsigned
|
;Set to 1 to fix the issue with the division operator treating negative integers as unsigned
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ static std::string __stdcall getString(const char* section, const char* setting,
|
|||||||
|
|
||||||
static std::vector<std::string> __stdcall getList(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter, const char* iniFile) {
|
static std::vector<std::string> __stdcall getList(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter, const char* iniFile) {
|
||||||
std::vector<std::string> list = split(getString(section, setting, defaultValue, bufSize, iniFile), delimiter);
|
std::vector<std::string> list = split(getString(section, setting, defaultValue, bufSize, iniFile), delimiter);
|
||||||
std::transform(list.cbegin(), list.cend(), list.begin(), trim);
|
std::transform(list.cbegin(), list.cend(), list.begin(), (std::string (*)(const std::string&))trim);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -948,6 +948,7 @@ end:
|
|||||||
|
|
||||||
// loads script from .int file into a ScriptProgram struct, filling script pointer and proc lookup table
|
// loads script from .int file into a ScriptProgram struct, filling script pointer and proc lookup table
|
||||||
void InitScriptProgram(ScriptProgram &prog, const char* fileName) {
|
void InitScriptProgram(ScriptProgram &prog, const char* fileName) {
|
||||||
|
prog.initialized = false;
|
||||||
fo::Program* scriptPtr = fo::func::loadProgram(fileName);
|
fo::Program* scriptPtr = fo::func::loadProgram(fileName);
|
||||||
|
|
||||||
if (scriptPtr) {
|
if (scriptPtr) {
|
||||||
@@ -957,14 +958,13 @@ void InitScriptProgram(ScriptProgram &prog, const char* fileName) {
|
|||||||
for (int i = 0; i < fo::Scripts::ScriptProc::count; ++i) {
|
for (int i = 0; i < fo::Scripts::ScriptProc::count; ++i) {
|
||||||
prog.procLookup[i] = fo::func::interpretFindProcedure(prog.ptr, procTable[i]);
|
prog.procLookup[i] = fo::func::interpretFindProcedure(prog.ptr, procTable[i]);
|
||||||
}
|
}
|
||||||
prog.initialized = false;
|
|
||||||
} else {
|
} else {
|
||||||
prog.ptr = nullptr;
|
prog.ptr = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunScriptProgram(ScriptProgram &prog) {
|
void RunScriptProgram(ScriptProgram &prog) {
|
||||||
if (!prog.initialized) {
|
if (!prog.initialized && prog.ptr) {
|
||||||
fo::func::runProgram(prog.ptr);
|
fo::func::runProgram(prog.ptr);
|
||||||
fo::func::interpret(prog.ptr, -1);
|
fo::func::interpret(prog.ptr, -1);
|
||||||
prog.initialized = true;
|
prog.initialized = true;
|
||||||
|
|||||||
@@ -176,6 +176,8 @@ void TimerInit() {
|
|||||||
GetLocalTime(&time);
|
GetLocalTime(&time);
|
||||||
SystemTimeToFileTime(&time, (FILETIME*)&startTime);
|
SystemTimeToFileTime(&time, (FILETIME*)&startTime);
|
||||||
|
|
||||||
|
if (!modKey[0]) return;
|
||||||
|
|
||||||
speed = new SpeedCfg[10];
|
speed = new SpeedCfg[10];
|
||||||
|
|
||||||
char buf[2], spKey[10] = "SpeedKey#";
|
char buf[2], spKey[10] = "SpeedKey#";
|
||||||
@@ -189,45 +191,46 @@ void TimerInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpeedPatch_Init() {
|
void SpeedPatch_Init() {
|
||||||
|
int init = GetConfigInt("Speed", "SpeedMultiInitial", 100);
|
||||||
|
|
||||||
if (GetConfigInt("Speed", "Enable", 0)) {
|
if (GetConfigInt("Speed", "Enable", 0)) {
|
||||||
modKey[0] = GetConfigInt("Input", "SpeedModKey", 0);
|
modKey[0] = GetConfigInt("Input", "SpeedModKey", 0);
|
||||||
int init = GetConfigInt("Speed", "SpeedMultiInitial", 100);
|
|
||||||
if (init == 100 && !modKey[0]) return;
|
|
||||||
|
|
||||||
dlog("Applying speed patch.", DL_INIT);
|
|
||||||
|
|
||||||
switch (modKey[0]) {
|
|
||||||
case -1:
|
|
||||||
modKey[0] = DIK_LCONTROL;
|
|
||||||
modKey[1] = DIK_RCONTROL;
|
|
||||||
break;
|
|
||||||
case -2:
|
|
||||||
modKey[0] = DIK_LMENU;
|
|
||||||
modKey[1] = DIK_RMENU;
|
|
||||||
break;
|
|
||||||
case -3:
|
|
||||||
modKey[0] = DIK_LSHIFT;
|
|
||||||
modKey[1] = DIK_RSHIFT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
modKey[1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
multi = init / 100.0f;
|
|
||||||
toggleKey = GetConfigInt("Input", "SpeedToggleKey", 0);
|
toggleKey = GetConfigInt("Input", "SpeedToggleKey", 0);
|
||||||
|
|
||||||
getTickCountOffs = (DWORD)&FakeGetTickCount;
|
|
||||||
getLocalTimeOffs = (DWORD)&FakeGetLocalTime;
|
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(offsets) / 4; i++) {
|
|
||||||
SafeWrite32(offsets[i], (DWORD)&getTickCountOffs);
|
|
||||||
}
|
|
||||||
SafeWrite32(0x4FDF58, (DWORD)&getLocalTimeOffs);
|
|
||||||
HookCall(0x4A433E, scripts_check_state_hook);
|
|
||||||
|
|
||||||
TimerInit();
|
|
||||||
dlogr(" Done", DL_INIT);
|
|
||||||
}
|
}
|
||||||
|
if (init == 100 && !modKey[0]) return;
|
||||||
|
|
||||||
|
dlog("Applying speed patch.", DL_INIT);
|
||||||
|
|
||||||
|
switch (modKey[0]) {
|
||||||
|
case -1:
|
||||||
|
modKey[0] = DIK_LCONTROL;
|
||||||
|
modKey[1] = DIK_RCONTROL;
|
||||||
|
break;
|
||||||
|
case -2:
|
||||||
|
modKey[0] = DIK_LMENU;
|
||||||
|
modKey[1] = DIK_RMENU;
|
||||||
|
break;
|
||||||
|
case -3:
|
||||||
|
modKey[0] = DIK_LSHIFT;
|
||||||
|
modKey[1] = DIK_RSHIFT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
modKey[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
multi = init / 100.0f;
|
||||||
|
|
||||||
|
getTickCountOffs = (DWORD)&FakeGetTickCount;
|
||||||
|
getLocalTimeOffs = (DWORD)&FakeGetLocalTime;
|
||||||
|
|
||||||
|
for (int i = 0; i < sizeof(offsets) / 4; i++) {
|
||||||
|
SafeWrite32(offsets[i], (DWORD)&getTickCountOffs);
|
||||||
|
}
|
||||||
|
SafeWrite32(0x4FDF58, (DWORD)&getLocalTimeOffs);
|
||||||
|
HookCall(0x4A433E, scripts_check_state_hook);
|
||||||
|
|
||||||
|
TimerInit();
|
||||||
|
dlogr(" Done", DL_INIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedPatch_Exit() {
|
void SpeedPatch_Exit() {
|
||||||
|
|||||||
+3
-3
@@ -22,9 +22,9 @@ static __declspec(noinline) void __stdcall SafeWriteFunc(BYTE code, DWORD addr,
|
|||||||
*((BYTE*)addr) = code;
|
*((BYTE*)addr) = code;
|
||||||
*((DWORD*)(addr + 1)) = data;
|
*((DWORD*)(addr + 1)) = data;
|
||||||
|
|
||||||
for (size_t i = 0; i < len; i++) {
|
do {
|
||||||
*((BYTE*)(addrMem + i)) = CodeType::Nop;
|
*((BYTE*)addrMem++) = CodeType::Nop;
|
||||||
}
|
} while (--len);
|
||||||
VirtualProtect((void*)addr, protectLen, oldProtect, &oldProtect);
|
VirtualProtect((void*)addr, protectLen, oldProtect, &oldProtect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -29,15 +29,7 @@ std::string trim(const std::string& str) {
|
|||||||
return str.substr(first, (last - first + 1));
|
return str.substr(first, (last - first + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToLowerCase(std::string& line) {
|
void trim(char* str) {
|
||||||
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSpace(char c) {
|
|
||||||
return (c == ' ' || c == '\t' /*|| c == '\n' || c == '\r'*/);
|
|
||||||
}
|
|
||||||
|
|
||||||
void strtrim(char* str) {
|
|
||||||
if (str[0] == 0) return;
|
if (str[0] == 0) return;
|
||||||
int len = strlen(str) - 1;
|
int len = strlen(str) - 1;
|
||||||
|
|
||||||
@@ -55,6 +47,14 @@ void strtrim(char* str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ToLowerCase(std::string& line) {
|
||||||
|
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSpace(char c) {
|
||||||
|
return (c == ' ' || c == '\t' /*|| c == '\n' || c == '\r'*/);
|
||||||
|
}
|
||||||
|
|
||||||
// returns position, find word must be lowercase
|
// returns position, find word must be lowercase
|
||||||
const char* strfind(const char* source, const char* word) {
|
const char* strfind(const char* source, const char* word) {
|
||||||
if (source == 0 || word == 0 || *word == 0) return 0;
|
if (source == 0 || word == 0 || *word == 0) return 0;
|
||||||
|
|||||||
+2
-2
@@ -29,12 +29,12 @@ std::vector<std::string> split(const std::string &s, char delim);
|
|||||||
|
|
||||||
std::string trim(const std::string& str);
|
std::string trim(const std::string& str);
|
||||||
|
|
||||||
|
void trim(char* str);
|
||||||
|
|
||||||
void ToLowerCase(std::string& line);
|
void ToLowerCase(std::string& line);
|
||||||
|
|
||||||
bool isSpace(char c);
|
bool isSpace(char c);
|
||||||
|
|
||||||
void strtrim(char* str);
|
|
||||||
|
|
||||||
const char* strfind(const char* source, const char* word);
|
const char* strfind(const char* source, const char* word);
|
||||||
|
|
||||||
void StrNormalizePath(char* path);
|
void StrNormalizePath(char* path);
|
||||||
|
|||||||
Reference in New Issue
Block a user