Changed DataLoadOrderPatch to be 1 by default.

Replaced most of NULL with nullptr, since VS2010 supports it.
Some code edits to MiscOps.hpp and ScriptUtils.hpp.
This commit is contained in:
NovaRain
2019-06-24 12:25:32 +08:00
parent b1e78bb61c
commit c18828b61b
7 changed files with 40 additions and 38 deletions
+2 -2
View File
@@ -225,7 +225,7 @@ UseFileSystemOverride=0
;Set to 1 to use the modified data load order for the engine to find game data ;Set to 1 to use the modified data load order for the engine to find game data
;Original: patchXXX.dat > critter_patches > critter_dat > f2_res_patches > f2_res_dat > master_patches > master_dat ;Original: patchXXX.dat > critter_patches > critter_dat > f2_res_patches > f2_res_dat > master_patches > master_dat
;Modified: master_patches > critter_patches > patchXXX.dat > critter_dat > f2_res_patches > f2_res_dat > master_dat ;Modified: master_patches > critter_patches > patchXXX.dat > critter_dat > f2_res_patches > f2_res_dat > master_dat
DataLoadOrderPatch=0 DataLoadOrderPatch=1
;To change the default and starting player models, uncomment the next four lines. ;To change the default and starting player models, uncomment the next four lines.
;The default models can also be changed ingame via script ;The default models can also be changed ingame via script
@@ -390,7 +390,7 @@ AIBestWeaponFix=0
;Set to 1 to fix NPCs not taking chem_primary_desire in AI.txt as drug use preference when using drugs in their inventory ;Set to 1 to fix NPCs not taking chem_primary_desire in AI.txt as drug use preference when using drugs in their inventory
AIDrugUsePerfFix=0 AIDrugUsePerfFix=0
;Allows the use of tiles over 80*36 in size. sfall will just split and resave them at startup ;Allows the use of tiles over 80x36 in size. sfall will just split and resave them at startup
;Set to 1 to check all tiles on started (slow) ;Set to 1 to check all tiles on started (slow)
;Set to 2 if you provide a XLtiles.lst file in art\tiles\ containing a list of the tile ids that need checking ;Set to 2 if you provide a XLtiles.lst file in art\tiles\ containing a list of the tile ids that need checking
AllowLargeTiles=0 AllowLargeTiles=0
+1 -1
View File
@@ -738,7 +738,7 @@ char* GetProtoPtr(long pid) {
char AnimCodeByWeapon(TGameObj* weapon) { char AnimCodeByWeapon(TGameObj* weapon) {
if (weapon != nullptr) { if (weapon != nullptr) {
char* proto = GetProtoPtr(weapon->pid); char* proto = GetProtoPtr(weapon->pid);
if (proto && *(int*)(proto + 32) == item_type_weapon) { if (proto != nullptr && *(int*)(proto + 32) == item_type_weapon) {
return (char)(*(int*)(proto + 36)); return (char)(*(int*)(proto + 36));
} }
} }
+1 -1
View File
@@ -1698,7 +1698,7 @@ sScriptProgram* GetGlobalScriptProgram(DWORD scriptPtr) {
for (std::vector<sGlobalScript>::iterator it = globalScripts.begin(); it != globalScripts.end(); it++) { for (std::vector<sGlobalScript>::iterator it = globalScripts.begin(); it != globalScripts.end(); it++) {
if (it->prog.ptr == scriptPtr) return &it->prog; if (it->prog.ptr == scriptPtr) return &it->prog;
} }
return NULL; return nullptr;
} }
bool _stdcall isGameScript(const char* filename) { bool _stdcall isGameScript(const char* filename) {
+2 -4
View File
@@ -987,11 +987,10 @@ static void _stdcall get_proto_data2() {
&offsetArg = opHandler.arg(1); &offsetArg = opHandler.arg(1);
if (pidArg.isInt() && offsetArg.isInt()) { // argument validation if (pidArg.isInt() && offsetArg.isInt()) { // argument validation
char* protoPtr; char* protoPtr;
char* *protoPtrRef = &protoPtr;
int pid = pidArg.asInt(); int pid = pidArg.asInt();
int result; int result;
__asm { __asm {
mov edx, protoPtrRef; lea edx, protoPtr;
mov eax, pid; mov eax, pid;
call proto_ptr_; call proto_ptr_;
mov result, eax; mov result, eax;
@@ -1018,11 +1017,10 @@ static void _stdcall set_proto_data2() {
&valueArg = opHandler.arg(2); &valueArg = opHandler.arg(2);
if (pidArg.isInt() && offsetArg.isInt() && valueArg.isInt()) { // argument validation if (pidArg.isInt() && offsetArg.isInt() && valueArg.isInt()) { // argument validation
char* protoPtr; char* protoPtr;
char* *protoPtrRef = &protoPtr;
int pid = pidArg.asInt(); int pid = pidArg.asInt();
int result; int result;
__asm { __asm {
mov edx, protoPtrRef; lea edx, protoPtr;
mov eax, pid; mov eax, pid;
call proto_ptr_; call proto_ptr_;
mov result, eax; mov result, eax;
+21 -17
View File
@@ -341,10 +341,10 @@ end:
} }
} }
static int _stdcall str_to_int_internal(const char* str) { static int _stdcall str_to_int_internal(const char* str) {
return (int)strtol(str, (char**)NULL, 0); // auto-determine radix return static_cast<int>(strtol(str, (char**)nullptr, 0)); // auto-determine radix
} }
static DWORD _stdcall str_to_flt_internal(const char* str) { static DWORD _stdcall str_to_flt_internal(const char* str) {
float f=(float)atof(str); float f = static_cast<float>(atof(str));
return *(DWORD*)&f; return *(DWORD*)&f;
} }
static void __declspec(naked) str_to_int() { static void __declspec(naked) str_to_int() {
@@ -423,9 +423,9 @@ char* _stdcall mysubstr(char* str, int pos, int length) {
length = srclen - pos + length; length = srclen - pos + length;
if (pos >= srclen) if (pos >= srclen)
length = 0; length = 0;
else if (length+pos > srclen) else if (length + pos > srclen)
length = srclen-pos; length = srclen - pos;
newstr = new char[length+1]; newstr = new char[length + 1];
if (length > 0) if (length > 0)
memcpy(newstr, &str[pos], length); memcpy(newstr, &str[pos], length);
newstr[length] = '\0'; newstr[length] = '\0';
@@ -435,22 +435,22 @@ char* _stdcall mysubstr(char* str, int pos, int length) {
static DWORD _stdcall mystrlen(char* str) { static DWORD _stdcall mystrlen(char* str) {
return strlen(str); return strlen(str);
} }
static char* sprintfbuf = NULL; static char* sprintfbuf = nullptr;
static char* _stdcall mysprintf(char* format, DWORD value, DWORD valueType) { static char* _stdcall mysprintf(char* format, DWORD value, DWORD valueType) {
valueType = valueType & 0xFFFF; // use lower 2 bytes valueType = valueType & 0xFFFF; // use lower 2 bytes
int fmtlen = strlen(format); int fmtlen = strlen(format);
int buflen = fmtlen + 1; int buflen = fmtlen + 1;
for (int i=0; i<fmtlen; i++) { for (int i = 0; i < fmtlen; i++) {
if (format[i] == '%') if (format[i] == '%')
buflen++; // will possibly be escaped, need space for that buflen++; // will possibly be escaped, need space for that
} }
// parse format to make it safe // parse format to make it safe
char* newfmt = new char[buflen]; char* newfmt = new char[buflen];
byte mode = 0; byte mode = 0;
int j=0; int j = 0;
char c, specifier; char c, specifier;
bool hasDigits = false; bool hasDigits = false;
for (int i=0; i<fmtlen; i++) { for (int i = 0; i < fmtlen; i++) {
c = format[i]; c = format[i];
switch (mode) { switch (mode) {
case 0: // prefix case 0: // prefix
@@ -460,12 +460,14 @@ static char* _stdcall mysprintf(char* format, DWORD value, DWORD valueType) {
break; break;
case 1: // definition case 1: // definition
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
if (c == 'h' || c == 'l' || c == 'j' || c == 'z' || c == 't' || c == 'L') // ignore sub-specifiers if (c == 'h' || c == 'l' || c == 'j' || c == 'z' || c == 't' || c == 'L') { // ignore sub-specifiers
continue; continue;
if (c == 's' && valueType != VAR_TYPE_STR2 && valueType != VAR_TYPE_STR) // don't allow to treat non-string values as string pointers }
if (c == 's' && valueType != VAR_TYPE_STR2 && valueType != VAR_TYPE_STR) { // don't allow to treat non-string values as string pointers
c = 'd'; c = 'd';
else if (c == 'n') // don't allow "n" specifier } else if (c == 'n') { // don't allow "n" specifier
c = 'd'; c = 'd';
}
specifier = c; specifier = c;
mode = 2; mode = 2;
} else if (c == '%') { } else if (c == '%') {
@@ -479,8 +481,9 @@ static char* _stdcall mysprintf(char* format, DWORD value, DWORD valueType) {
default: default:
if (c == '%') { // don't allow more than one specifier if (c == '%') { // don't allow more than one specifier
newfmt[j++] = '%'; // escape it newfmt[j++] = '%'; // escape it
if (format[i+1] == '%') if (format[i + 1] == '%') {
i++; // skip already escaped i++; // skip already escaped
}
} }
break; break;
} }
@@ -497,9 +500,10 @@ static char* _stdcall mysprintf(char* format, DWORD value, DWORD valueType) {
} else { } else {
buflen = j + 30; // numbers buflen = j + 30; // numbers
} }
if (sprintfbuf) if (sprintfbuf) {
delete[] sprintfbuf; delete[] sprintfbuf;
sprintfbuf = new char[buflen+1]; }
sprintfbuf = new char[buflen + 1];
if (valueType == VAR_TYPE_FLOAT) { if (valueType == VAR_TYPE_FLOAT) {
_snprintf(sprintfbuf, buflen, newfmt, *(float*)(&value)); _snprintf(sprintfbuf, buflen, newfmt, *(float*)(&value));
} else { } else {
@@ -684,8 +688,8 @@ notstring:
} }
static DWORD _stdcall GetValueType(DWORD datatype) { static DWORD _stdcall GetValueType(DWORD datatype) {
datatype&=0xffff; datatype &= 0xFFFF;
switch(datatype) { switch (datatype) {
case VAR_TYPE_STR: case VAR_TYPE_STR:
case VAR_TYPE_STR2: case VAR_TYPE_STR2:
return DATATYPE_STR; return DATATYPE_STR;
+12 -12
View File
@@ -90,7 +90,7 @@ static void __declspec(naked) load_page_offsets(void) {
//------------------------------------------ //------------------------------------------
static void CreateButtons() { static void CreateButtons() {
DWORD winRef = *(DWORD*)_lsgwin; DWORD winRef = *ptr_lsgwin;
// left button -10 | X | Y | W | H |HOn |HOff |BDown |BUp |PicUp |PicDown |? |ButType // left button -10 | X | Y | W | H |HOn |HOff |BDown |BUp |PicUp |PicDown |? |ButType
WinRegisterButton(winRef, 100, 60, 24, 20, -1, 0x500, 0x54B, 0x14B, 0, 0, 0, 32); WinRegisterButton(winRef, 100, 60, 24, 20, -1, 0x500, 0x54B, 0x14B, 0, 0, 0, 32);
// left button -100 // left button -100
@@ -114,12 +114,12 @@ static void __declspec(naked) create_page_buttons(void) {
//------------------------------------------------------ //------------------------------------------------------
void SetPageNum() { void SetPageNum() {
DWORD WinRef = *(DWORD*)_lsgwin; // load/save winref DWORD winRef = *ptr_lsgwin; // load/save winref
if (WinRef == NULL) { if (winRef == 0) {
return; return;
} }
WINinfo *SaveLoadWin = GetWinStruct(WinRef); WINinfo *SaveLoadWin = GetWinStruct(winRef);
if (SaveLoadWin->surface == NULL) { if (SaveLoadWin->surface == nullptr) {
return; return;
} }
@@ -162,7 +162,7 @@ void SetPageNum() {
} }
PrintText(TempText, ConsoleGold, 170 - TxtWidth / 2, 64, TxtWidth, SaveLoadWin->width, SaveLoadWin->surface); PrintText(TempText, ConsoleGold, 170 - TxtWidth / 2, 64, TxtWidth, SaveLoadWin->width, SaveLoadWin->surface);
RedrawWin(WinRef); RedrawWin(winRef);
} }
button = check_buttons(); button = check_buttons();
@@ -198,7 +198,7 @@ void SetPageNum() {
LSPageOffset = tempPageOffset; LSPageOffset = tempPageOffset;
} }
SaveLoadWin = NULL; SaveLoadWin = nullptr;
} }
//------------------------------------------ //------------------------------------------
@@ -259,12 +259,12 @@ CheckUp:
//------------------------------------------ //------------------------------------------
void DrawPageText() { void DrawPageText() {
int WinRef = *(DWORD*)_lsgwin; // load/save winref DWORD winRef = *ptr_lsgwin; // load/save winref
if (WinRef == NULL) { if (winRef == 0) {
return; return;
} }
WINinfo *SaveLoadWin = GetWinStruct(WinRef); WINinfo *SaveLoadWin = GetWinStruct(winRef);
if (SaveLoadWin->surface == NULL) { if (SaveLoadWin->surface == nullptr) {
return; return;
} }
@@ -319,7 +319,7 @@ void DrawPageText() {
TxtWidth = GetTextWidth(TempText); TxtWidth = GetTextWidth(TempText);
PrintText(TempText, Colour, 228 - TxtWidth / 2, 64, TxtWidth, SaveLoadWin->width, SaveLoadWin->surface); PrintText(TempText, Colour, 228 - TxtWidth / 2, 64, TxtWidth, SaveLoadWin->width, SaveLoadWin->surface);
SaveLoadWin = NULL; SaveLoadWin = nullptr;
} }
//------------------------------------------ //------------------------------------------
+1 -1
View File
@@ -815,7 +815,7 @@ static void DllMain2() {
dlogr(" Done", DL_INIT); dlogr(" Done", DL_INIT);
//} //}
if (GetPrivateProfileIntA("Misc", "DataLoadOrderPatch", 0, ini)) { if (GetPrivateProfileIntA("Misc", "DataLoadOrderPatch", 1, ini)) {
dlog("Applying data load order patch.", DL_INIT); dlog("Applying data load order patch.", DL_INIT);
MakeCall(0x444259, game_init_databases_hack1); MakeCall(0x444259, game_init_databases_hack1);
MakeCall(0x4442F1, game_init_databases_hack2); MakeCall(0x4442F1, game_init_databases_hack2);