mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Refactored some code of DataLoadOrderPatch to work with new ExtraPatches. Removed MultiPatches from ddraw.ini, now it's always enabled. Minor edits to MiscPatches.cpp and Arrays.cpp. Updated version number.
108 lines
2.6 KiB
C++
108 lines
2.6 KiB
C++
/*
|
|
* sfall
|
|
* Copyright (C) 2008-2018 The sfall team
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "..\main.h"
|
|
#include "..\FalloutEngine\Fallout2.h"
|
|
#include "LoadGameHook.h"
|
|
|
|
#include "Objects.h"
|
|
|
|
namespace sfall
|
|
{
|
|
|
|
static int unjamTimeState;
|
|
static int maxCountProto = 512;
|
|
|
|
long Objects::uniqueID = UniqueID::Start; // saving to sfallgv.sav
|
|
|
|
// Assigns a new unique identifier to an object if it has not been previously assigned
|
|
// the identifier is saved with the object in the saved game and this can used in various script
|
|
long Objects::SetObjectUniqueID(fo::GameObject* obj) {
|
|
if (obj->id > UniqueID::Start || obj == fo::var::obj_dude) return obj->id; // dude id = 18000
|
|
|
|
if ((DWORD)uniqueID >= UniqueID::End) uniqueID = UniqueID::Start;
|
|
obj->id = ++uniqueID;
|
|
return uniqueID;
|
|
}
|
|
|
|
void Objects::SetAutoUnjamLockTime(DWORD time) {
|
|
if (!unjamTimeState) {
|
|
BlockCall(0x4A364A); // disable auto unjam at midnight
|
|
}
|
|
|
|
if (time > 0) {
|
|
SafeWrite8(0x4831D9, (BYTE)time);
|
|
if (unjamTimeState == 2) {
|
|
SafeWrite8(0x4831DA, 0x7C);
|
|
}
|
|
unjamTimeState = 1;
|
|
} else {
|
|
SafeWrite8(0x4831DA, 0xEB); // disable auto unjam
|
|
unjamTimeState = 2;
|
|
}
|
|
}
|
|
|
|
void RestoreObjUnjamAllLocks() {
|
|
if (unjamTimeState) {
|
|
SafeWrite8(0x4A364A, 0xE8);
|
|
SafeWrite32(0x4A364B, 0xFFFF9E69);
|
|
SafeWrite8(0x4831DA, 0x7C);
|
|
SafeWrite8(0x4831D9, 24);
|
|
unjamTimeState = 0;
|
|
}
|
|
}
|
|
|
|
static void __declspec(naked) proto_ptr_hack() {
|
|
__asm {
|
|
mov ecx, maxCountProto;
|
|
cmp ecx, 4096;
|
|
jae skip;
|
|
cmp eax, ecx;
|
|
jb end;
|
|
add ecx, 256;
|
|
mov maxCountProto, ecx;
|
|
skip:
|
|
cmp eax, ecx;
|
|
end:
|
|
retn;
|
|
}
|
|
}
|
|
|
|
void Objects::LoadProtoAutoMaxLimit() {
|
|
if (maxCountProto != -1) {
|
|
MakeCall(0x4A21B2, proto_ptr_hack);
|
|
}
|
|
}
|
|
|
|
void Objects::init() {
|
|
LoadGameHook::OnGameReset() += []() {
|
|
RestoreObjUnjamAllLocks();
|
|
};
|
|
|
|
int maxlimit = GetConfigInt("Misc", "LoadProtoMaxLimit", -1);
|
|
if (maxlimit != -1) {
|
|
maxCountProto = -1;
|
|
if (maxlimit > 512) {
|
|
if (maxlimit > 4096) maxlimit = 4096;
|
|
SafeWrite32(0x4A21B3, maxlimit);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|