Reverted the change for ResetState() in 993555

* reason: the skills didn't get initialized properly if loading a save
from the main menu before starting any game. And some inits in 3.8
also require running ResetState() before any game, so reverting is
probably the easiest solution before I break more stuff.

Backported some code setup from 4.x for Combat.cpp & Skills.cpp.
This commit is contained in:
NovaRain
2020-04-04 18:06:04 +08:00
parent 4c78ba595c
commit e404684f58
6 changed files with 68 additions and 46 deletions
+3 -4
View File
@@ -3168,16 +3168,15 @@ void BugFixesInit()
MakeCall(0x45C376, op_use_obj_on_obj_hack, 1);
MakeCall(0x456A92, op_use_obj_hack, 1);
// Fix pickup_obj/drop_obj/use_obj functions, change them to get pointer from script.self instead of script.target
// script.target contains an incorrect pointer, which may vary depending on the situations in the game
dlog("Applying pickup_obj/drop_obj/use_obj fix.", DL_INIT);
const DWORD ScriptTargetAddr[] = {
0x456554, // op_pickup_obj_
0x456600, // op_drop_obj_
0x456A6D, // op_use_obj_
0x456AA4 // op_use_obj_
};
// Fix pickup_obj/drop_obj/use_obj functions, change them to get pointer from script.self instead of script.target
// script.target contains an incorrect pointer, which may vary depending on the situations in the game
dlog("Applying pickup_obj/drop_obj/use_obj fix.", DL_INIT);
for (int i = 0; i < sizeof(ScriptTargetAddr) / 4; i++) {
SafeWrite8(ScriptTargetAddr[i], 0x34); // script.target > script.self
}
+1 -2
View File
@@ -512,8 +512,7 @@ static void CombatProcFix() {
}
void Combat_OnGameLoad() {
baseHitChance.maximum = 95;
baseHitChance.mod = 0;
baseHitChance.SetDefault();
mTargets.clear();
mAttackers.clear();
mWeapons.clear();
+13
View File
@@ -22,6 +22,19 @@ struct ChanceModifier {
long id;
int maximum;
int mod;
ChanceModifier() : id(0), maximum(95), mod(0) {}
ChanceModifier(long _id, int max, int _mod) {
id = _id;
maximum = max;
mod = _mod;
}
void SetDefault() {
maximum = 95;
mod = 0;
}
};
void __stdcall SetBlockCombat(long toggle);
+22 -25
View File
@@ -86,32 +86,29 @@ void ClearLoopFlag(LoopFlag flag) {
inLoop &= ~flag;
}
static void _stdcall ResetState(DWORD onLoad) { // OnGameReset
if (gameLoaded) { // prevent resetting when a new game has not been started (loading saved games from main menu)
if (GraphicsMode > 3) Graphics_OnGameLoad();
ForceGraphicsRefresh(0); // disable refresh
LoadOrder_OnGameLoad();
Interface_OnGameLoad();
RestoreObjUnjamAllLocks();
Worldmap_OnGameLoad();
Stats_OnGameLoad();
PerksReset();
Combat_OnGameLoad();
Skills_OnGameLoad();
FileSystemReset();
WipeSounds();
InventoryReset();
PartyControl_OnGameLoad();
ResetExplosionRadius();
BarBoxes_OnGameLoad();
ScriptExtender_OnGameLoad();
if (isDebug) {
char* str = (onLoad) ? "on Load" : "on Exit";
DebugPrintf("\n[SFALL: State reset %s]", str);
}
}
static void _stdcall ResetState(DWORD onLoad) { // OnGameReset & OnBeforeGameStart
if (GraphicsMode > 3) Graphics_OnGameLoad();
ForceGraphicsRefresh(0); // disable refresh
LoadOrder_OnGameLoad();
Interface_OnGameLoad();
RestoreObjUnjamAllLocks();
Worldmap_OnGameLoad();
Stats_OnGameLoad();
PerksReset();
Combat_OnGameLoad();
Skills_OnGameLoad();
FileSystemReset();
WipeSounds();
InventoryReset();
PartyControl_OnGameLoad();
ResetExplosionRadius();
BarBoxes_OnGameLoad();
ScriptExtender_OnGameLoad();
inLoop = 0;
gameLoaded = false;
if (isDebug) {
char* str = (onLoad) ? "on Load" : "on Exit";
DebugPrintf("\n[SFALL: State reset %s]", str);
}
}
void GetSavePath(char* buf, char* ftype) {
+8 -5
View File
@@ -1739,11 +1739,14 @@ void ScriptExtenderInit() {
MakeJump(0x4A67F0, ExecMapScriptsHack);
HookCall(0x4A26D6, HandleTimedEventScripts); // queue_process_
MakeCall(0x4C1C67, TimedEventNextTime); // wmGameTimeIncrement_
MakeCall(0x4A3E1C, TimedEventNextTime); // script_chk_timed_events_
MakeCall(0x499AFA, TimedEventNextTime); // TimedRest_
MakeCall(0x499CD7, TimedEventNextTime);
MakeCall(0x499E2B, TimedEventNextTime);
const DWORD qNextTimeAddr[] = {
0x4C1C67, // wmGameTimeIncrement_
0x4A3E1C, // script_chk_timed_events_
0x499AFA, 0x499CD7, 0x499E2B // TimedRest_
};
for (int i = 0; i < sizeof(qNextTimeAddr) / 4; i++) {
MakeCall(qNextTimeAddr[i], TimedEventNextTime);
}
HookCall(0x4A3E08, script_chk_timed_events_hook);
// this patch makes it possible to export variables from sfall global scripts
+21 -10
View File
@@ -46,7 +46,20 @@ struct SkillInfo {
struct SkillModifier {
long id;
int maximum;
int mod;
//int mod;
SkillModifier() : id(0), maximum(300)/*, mod(0)*/ {}
SkillModifier(long id, int max) {
this->id = id;
maximum = max;
//mod = _mod;
}
void SetDefault() {
maximum = 300;
//mod = 0;
}
};
static std::vector<SkillModifier> skillMaxMods;
@@ -283,11 +296,11 @@ void _stdcall SetSkillMax(TGameObj* critter, int maximum) {
return;
}
}
SkillModifier cm;
cm.id = id;
cm.maximum = maximum;
cm.mod = 0;
skillMaxMods.push_back(cm);
SkillModifier sm;
sm.id = id;
sm.maximum = maximum;
//sm.mod = 0;
skillMaxMods.push_back(sm);
}
void _stdcall SetPickpocketMax(TGameObj* critter, DWORD maximum, DWORD mod) {
@@ -314,12 +327,10 @@ void _stdcall SetPickpocketMax(TGameObj* critter, DWORD maximum, DWORD mod) {
void Skills_OnGameLoad() {
pickpocketMods.clear();
basePickpocket.maximum = 95;
basePickpocket.mod = 0;
basePickpocket.SetDefault();
skillMaxMods.clear();
baseSkillMax.maximum = 300;
baseSkillMax.mod = 0;
baseSkillMax.SetDefault();
}
void SkillsInit() {