Code refactoring in main.cpp (from MiscPatches in 4.x)

Updated compiler document.
This commit is contained in:
NovaRain
2020-01-08 16:59:07 +08:00
parent c652982a06
commit aafc030f8e
4 changed files with 128 additions and 106 deletions
+12 -3
View File
@@ -82,6 +82,14 @@ old:
X := value2;
> To assign values, you can use the alternative assignment operator from C/Java instead of Pascal syntax.
new:
x = 5;
old:
x := 5;
> Multiple variable decleration: Multiple variables can be declared on one line, seperated by commas. This is an alterative to the ugly begin/end block, or the bulky single variable per line style.
new:
@@ -102,7 +110,7 @@ old:
NOTE: if your expression starts with a constant (eg. 2+2), enclose it in parentheses, otherwise compiler will be confused and give you errors.
> hexadecimal numerical constants: Simply prefix a number with 0x to create a hexadecimal. The numbers 0 to 9 and a-f are allowed in the number. The number may not have a decimal point.
> Hexadecimal numerical constants: Simply prefix a number with 0x to create a hexadecimal. The numbers 0 to 9 and a-f are allowed in the number. The number may not have a decimal point.
new:
a := 0x1000;
@@ -162,7 +170,7 @@ new:
end
old
i := 0;
while i<5 do begin
while (i < 5) do begin
display_msg("i = "+i);
i++;
end
@@ -334,7 +342,8 @@ There are several changes in this version of sslc which may result in problems f
> sfall 4.2.3
- fixed compiler giving "assignment operator expected" error when a variable-like macro is not being defined properly
- added new logical operators 'AndAlso', 'OrElse' for short-circuit evaluation of logical expressions
- added new logical operators "AndAlso", "OrElse" for short-circuit evaluation of logical expressions
- added an alternative (C/Java-style) assignment operator "="
> sfall 4.2.2
- added support for new opcode "reg_anim_callback"
+24
View File
@@ -360,6 +360,30 @@ enum AttackType : long
ATKTYPE_PIERCINGKICK = 19
};
enum KillType : long
{
KILL_TYPE_men = 0,
KILL_TYPE_women = 1,
KILL_TYPE_children = 2,
KILL_TYPE_super_mutant = 3,
KILL_TYPE_ghoul = 4,
KILL_TYPE_brahmin = 5,
KILL_TYPE_radscorpion = 6,
KILL_TYPE_rat = 7,
KILL_TYPE_floater = 8,
KILL_TYPE_centaur = 9,
KILL_TYPE_robot = 10,
KILL_TYPE_dog = 11,
KILL_TYPE_manti = 12,
KILL_TYPE_deathclaw = 13,
KILL_TYPE_plant = 14,
KILL_TYPE_gecko = 15,
KILL_TYPE_alien = 16,
KILL_TYPE_giant_ant = 17,
KILL_TYPE_big_bad_boss = 18,
KILL_TYPE_count
};
#define PLAYER_ID (18000)
#define OBJFLAG_CAN_WEAR_ITEMS (0xF000000)
+3 -3
View File
@@ -649,7 +649,7 @@ void InventoryReset() {
}
void InventoryInit() {
long weightWidth = 135;
long widthWeight = 135;
sizeLimitMode = GetConfigInt("Misc", "CritterInvSizeLimitMode", 0);
if (sizeLimitMode > 0 && sizeLimitMode <= 7) {
@@ -683,7 +683,7 @@ void InventoryInit() {
SafeWrite32(0x4725F9, 0x9C + 0x0C);
SafeWrite8(0x472606, 0x10 + 0x0C);
SafeWrite8(0x472638, 0); // x offset position
weightWidth = 150;
widthWeight = 150;
// Display item size when examining
HookCall(0x472FFE, inven_obj_examine_func_hook);
@@ -701,7 +701,7 @@ void InventoryInit() {
}
}
// Adjust the max text width of the total weight display on the inventory screen
SafeWrite32(0x472632, weightWidth);
SafeWrite32(0x472632, widthWeight);
if (GetConfigInt("Misc", "SuperStimExploitFix", 0)) {
Translate("sfall", "SuperStimExploitMsg", "You cannot use a super stim on someone who is not injured!", SuperStimMsg);
+55 -66
View File
@@ -135,15 +135,15 @@ size_t Translate(const char* section, const char* setting, const char* defaultVa
return iniGetString(section, setting, defaultValue, buffer, bufSize, translationIni);
}
static char mapName[65];
static char configName[65];
static char patchName[65];
static char versionString[65];
static char mapName[65] = {};
static char configName[65] = {};
static char patchName[65] = {};
static char versionString[65] = {};
static char startMaleModelName[65];
char defaultMaleModelName[65];
static char startFemaleModelName[65];
char defaultFemaleModelName[65];
static char startMaleModelName[65] = {};
char defaultMaleModelName[65] = {};
static char startFemaleModelName[65] = {};
char defaultFemaleModelName[65] = {};
static const char* musicOverridePath = "data\\sound\\music\\";
@@ -186,14 +186,13 @@ c15:
}
}
static void __declspec(naked) ReloadHook() {
static void __declspec(naked) intface_item_reload_hook() {
__asm {
push eax;
push ebx;
push edx;
mov eax, dword ptr ds:[_obj_dude];
call register_clear_;
xor eax, eax;
test eax, eax;
jnz fail;
inc eax;
call register_begin_;
xor edx, edx;
@@ -202,18 +201,17 @@ static void __declspec(naked) ReloadHook() {
dec ebx;
call register_object_animate_;
call register_end_;
pop edx;
pop ebx;
fail:
pop eax;
jmp gsound_play_sfx_file_;
}
}
static void __declspec(naked) ScienceCritterCheckHook() {
static void __declspec(naked) action_use_skill_on_hook_science() {
__asm {
cmp esi, ds:[_obj_dude];
jne end;
mov eax, 10;
mov eax, KILL_TYPE_robot;
retn;
end:
jmp critter_kill_count_type_;
@@ -250,36 +248,36 @@ static void __declspec(naked) op_obj_can_see_obj_hook() {
static void __declspec(naked) register_object_take_out_hack() {
__asm {
push ecx
push eax
mov ecx, edx // ID1
mov edx, [eax+0x1C] // cur_rot
inc edx
push edx // ID3
xor ebx, ebx // ID2
mov edx, [eax+0x20] // fid
and edx, 0xFFF // Index
xor eax, eax
inc eax // Obj_Type
call art_id_
xor ebx, ebx
dec ebx
xchg edx, eax
pop eax
call register_object_change_fid_
pop ecx
xor eax, eax
retn
push ecx;
push eax;
mov ecx, edx; // ID1
mov edx, [eax + 0x1C]; // cur_rot
inc edx;
push edx; // ID3
xor ebx, ebx; // ID2
mov edx, [eax + 0x20]; // fid
and edx, 0xFFF; // Index
xor eax, eax;
inc eax; // Obj_Type CRITTER
call art_id_;
mov edx, eax;
xor ebx, ebx;
dec ebx; // delay -1
pop eax; // critter
call register_object_change_fid_;
pop ecx;
xor eax, eax;
retn;
}
}
static void __declspec(naked) gdAddOptionStr_hack() {
__asm {
mov ecx, ds:[_gdNumOptions]
add ecx, '1'
push ecx
push 0x4458FA
retn
mov ecx, ds:[_gdNumOptions];
add ecx, '1';
push ecx;
mov ecx, 0x4458FA;
jmp ecx;
}
}
@@ -309,7 +307,7 @@ static void __declspec(naked) display_stats_hook() {
}
static void DllMain2() {
DWORD tmp;
long tmp;
dlogr("In DllMain2", DL_MAIN);
dlogr("Running BugFixesInit().", DL_INIT);
@@ -347,27 +345,23 @@ static void DllMain2() {
dlogr("Running SpeedPatchInit().", DL_INIT);
SpeedPatchInit();
startMaleModelName[64] = 0;
if (GetConfigString("Misc", "MaleStartModel", "", startMaleModelName, 64)) {
dlog("Applying male start model patch.", DL_INIT);
SafeWrite32(0x418B88, (DWORD)&startMaleModelName);
dlogr(" Done", DL_INIT);
}
startFemaleModelName[64] = 0;
if (GetConfigString("Misc", "FemaleStartModel", "", startFemaleModelName, 64)) {
dlog("Applying female start model patch.", DL_INIT);
SafeWrite32(0x418BAB, (DWORD)&startFemaleModelName);
dlogr(" Done", DL_INIT);
}
defaultMaleModelName[64] = 0;
GetConfigString("Misc", "MaleDefaultModel", "hmjmps", defaultMaleModelName, 64);
dlog("Applying male model patch.", DL_INIT);
SafeWrite32(0x418B50, (DWORD)&defaultMaleModelName);
dlogr(" Done", DL_INIT);
defaultFemaleModelName[64] = 0;
GetConfigString("Misc", "FemaleDefaultModel", "hfjmps", defaultFemaleModelName, 64);
dlog("Applying female model patch.", DL_INIT);
SafeWrite32(0x418B6D, (DWORD)&defaultFemaleModelName);
@@ -465,21 +459,18 @@ static void DllMain2() {
dlogr("Running HeroAppearanceModInit().", DL_INIT);
HeroAppearanceModInit();
mapName[64] = 0;
if (GetConfigString("Misc", "StartingMap", "", mapName, 64)) {
dlog("Applying starting map patch.", DL_INIT);
SafeWrite32(0x480AAA, (DWORD)&mapName);
dlogr(" Done", DL_INIT);
}
versionString[64] = 0;
if (GetConfigString("Misc", "VersionString", "", versionString, 64)) {
dlog("Applying version string patch.", DL_INIT);
SafeWrite32(0x4B4588, (DWORD)&versionString);
dlogr(" Done", DL_INIT);
}
configName[64] = 0;
if (GetConfigString("Misc", "ConfigFile", "", configName, 64)) {
dlog("Applying config file patch.", DL_INIT);
SafeWrite32(0x444BA5, (DWORD)&configName);
@@ -487,7 +478,6 @@ static void DllMain2() {
dlogr(" Done", DL_INIT);
}
patchName[64] = 0;
if (GetConfigString("Misc", "PatchFile", "", patchName, 64)) {
dlog("Applying patch file patch.", DL_INIT);
SafeWrite32(0x444323, (DWORD)&patchName);
@@ -524,9 +514,9 @@ static void DllMain2() {
if (GetConfigInt("Misc", "AdditionalWeaponAnims", 0)) {
dlog("Applying additional weapon animations patch.", DL_INIT);
SafeWrite8(0x419320, 0x12);
HookCall(0x4194CC, WeaponAnimHook);
HookCall(0x451648, WeaponAnimHook);
SafeWrite8(0x419320, 18); // art_get_code_
HookCall(0x4194CC, WeaponAnimHook); // art_get_name_
HookCall(0x451648, WeaponAnimHook); // gsnd_build_character_sfx_name_
HookCall(0x451671, WeaponAnimHook);
dlogr(" Done", DL_INIT);
}
@@ -539,7 +529,7 @@ static void DllMain2() {
if (GetConfigInt("Misc", "PlayIdleAnimOnReload", 0)) {
dlog("Applying idle anim on reload patch.", DL_INIT);
HookCall(0x460B8C, ReloadHook);
HookCall(0x460B8C, intface_item_reload_hook);
dlogr(" Done", DL_INIT);
}
@@ -568,7 +558,7 @@ static void DllMain2() {
switch (GetConfigInt("Misc", "ScienceOnCritters", 0)) {
case 1:
HookCall(0x41276E, ScienceCritterCheckHook);
HookCall(0x41276E, action_use_skill_on_hook_science);
break;
case 2:
SafeWrite8(0x41276A, 0xEB);
@@ -645,16 +635,18 @@ static void DllMain2() {
}
// phobos2077:
DWORD addrs[2] = {0x45F9DE, 0x45FB33};
DWORD addrs[] = {
0x45F9DE, 0x45FB33,
0x447DF4, 0x447EB6,
0x499B99, 0x499DA8
};
SimplePatch<WORD>(addrs, 2, "Misc", "CombatPanelAnimDelay", 1000, 0, 65535);
addrs[0] = 0x447DF4; addrs[1] = 0x447EB6;
SimplePatch<BYTE>(addrs, 2, "Misc", "DialogPanelAnimDelay", 33, 0, 255);
addrs[0] = 0x499B99; addrs[1] = 0x499DA8;
SimplePatch<BYTE>(addrs, 2, "Misc", "PipboyTimeAnimDelay", 50, 0, 127);
SimplePatch<BYTE>(&addrs[2], 2, "Misc", "DialogPanelAnimDelay", 33, 0, 255);
SimplePatch<BYTE>(&addrs[4], 2, "Misc", "PipboyTimeAnimDelay", 50, 0, 127);
if (GetConfigInt("Misc", "EnableMusicInDialogue", 0)) {
dlog("Applying music in dialogue patch.", DL_INIT);
SafeWrite8(0x44525B, 0x0);
SafeWrite8(0x44525B, 0);
//BlockCall(0x450627);
dlogr(" Done", DL_INIT);
}
@@ -713,8 +705,7 @@ static void DllMain2() {
dlogr(" Done", DL_INIT);
}
int time = GetConfigInt("Misc", "CorpseDeleteTime", 6); // time in days
if (time != 6) {
if (int time = GetConfigInt("Misc", "CorpseDeleteTime", 6) != 6) { // time in days
dlog("Applying corpse deletion time patch.", DL_INIT);
if (time <= 0) {
time = 12; // hours
@@ -755,9 +746,7 @@ static void DllMain2() {
}
static void _stdcall OnExit() {
if (scriptDialog != nullptr) {
delete[] scriptDialog;
}
if (scriptDialog) delete[] scriptDialog;
GraphicsExit();
MoviesExit();
SpeedPatchExit();