Code edits to ScriptExtender.cpp/SpeedPatch.cpp

Minor edits to some files.
This commit is contained in:
NovaRain
2021-11-08 13:45:35 +08:00
parent d4f011913c
commit 09813aeb86
7 changed files with 59 additions and 56 deletions
+3 -3
View File
@@ -26,7 +26,7 @@ UseCommandLine=0
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[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
;The speeds corresponding to each slot in percent. (i.e. 100 is normal speed)
@@ -620,9 +620,9 @@ AttackComplexFix=0
;Note that enabling this option may cause unexpected results with some existing game scripts
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
;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
;Set to 1 to fix the issue with the division operator treating negative integers as unsigned
+1 -1
View File
@@ -46,7 +46,7 @@ static std::string getString(const char* section, const char* setting, const cha
static std::vector<std::string> getList(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter, const char* iniFile) {
auto 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;
}
+3 -3
View File
@@ -430,6 +430,7 @@ void __fastcall SetSelfObject(fo::Program* script, fo::GameObject* obj) {
// loads script from .int file into a ScriptProgram struct, filling script pointer and proc lookup table
void InitScriptProgram(ScriptProgram &prog, const char* fileName, bool fullPath) {
prog.initialized = false;
fo::Program* scriptPtr = (fullPath)
? fo::func::allocateProgram(fileName)
: fo::func::loadProgram(fileName);
@@ -441,14 +442,13 @@ void InitScriptProgram(ScriptProgram &prog, const char* fileName, bool fullPath)
for (int i = 0; i < fo::Scripts::ScriptProc::count; ++i) {
prog.procLookup[i] = fo::func::interpretFindProcedure(prog.ptr, procTable[i]);
}
prog.initialized = false;
} else {
prog.ptr = nullptr;
}
}
void RunScriptProgram(ScriptProgram &prog) {
if (!prog.initialized) {
if (!prog.initialized && prog.ptr) {
fo::func::runProgram(prog.ptr);
fo::func::interpret(prog.ptr, -1);
prog.initialized = true;
@@ -565,8 +565,8 @@ static void PrepareGlobalScriptsListByMask() {
}
}
fo::func::db_free_file_list(&filenames, 0);
globalScripts.reserve(globalScriptFilesList.size());
}
globalScripts.reserve(globalScriptFilesList.size());
}
// this runs before the game was loaded/started
+6 -3
View File
@@ -176,6 +176,8 @@ void TimerInit() {
GetLocalTime(&time);
SystemTimeToFileTime(&time, (FILETIME*)&startTime);
if (!modKey[0]) return;
speed = new SpeedCfg[10];
char buf[2], spKey[10] = "SpeedKey#";
@@ -189,9 +191,12 @@ void TimerInit() {
}
void SpeedPatch::init() {
int init = IniReader::GetConfigInt("Speed", "SpeedMultiInitial", 100);
if (IniReader::GetConfigInt("Speed", "Enable", 0)) {
modKey[0] = IniReader::GetConfigInt("Input", "SpeedModKey", 0);
int init = IniReader::GetConfigInt("Speed", "SpeedMultiInitial", 100);
toggleKey = IniReader::GetConfigInt("Input", "SpeedToggleKey", 0);
}
if (init == 100 && !modKey[0]) return;
dlog("Applying speed patch.", DL_INIT);
@@ -214,7 +219,6 @@ void SpeedPatch::init() {
}
multi = init / 100.0f;
toggleKey = IniReader::GetConfigInt("Input", "SpeedToggleKey", 0);
getTickCountOffs = (DWORD)&FakeGetTickCount;
getLocalTimeOffs = (DWORD)&FakeGetLocalTime;
@@ -227,7 +231,6 @@ void SpeedPatch::init() {
TimerInit();
dlogr(" Done", DL_INIT);
}
}
void SpeedPatch::exit() {
+3 -3
View File
@@ -24,9 +24,9 @@ static __declspec(noinline) void __stdcall SafeWriteFunc(BYTE code, DWORD addr,
*((BYTE*)addr) = code;
*((DWORD*)(addr + 1)) = data;
for (size_t i = 0; i < len; i++) {
*((BYTE*)(addrMem + i)) = CodeType::Nop;
}
do {
*((BYTE*)addrMem++) = CodeType::Nop;
} while (--len);
VirtualProtect((void*)addr, protectLen, oldProtect, &oldProtect);
CheckConflict(addr, protectLen);
+9 -9
View File
@@ -29,15 +29,7 @@ std::string trim(const std::string& str) {
return str.substr(first, (last - first + 1));
}
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'*/);
}
void strtrim(char* str) {
void trim(char* str) {
if (str[0] == 0) return;
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
const char* strfind(const char* source, const char* word) {
if (source == 0 || word == 0 || *word == 0) return 0;
+2 -2
View File
@@ -29,12 +29,12 @@ std::vector<std::string> split(const std::string &s, char delim);
std::string trim(const std::string& str);
void trim(char* str);
void ToLowerCase(std::string& line);
bool isSpace(char c);
void strtrim(char* str);
const char* strfind(const char* source, const char* word);
void StrNormalizePath(char* path);