mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Refactored code in Books.cpp.
Increased the maximum number of books in BooksFile to 50. Moved scattered Cpp11_emu.h includes from various cpp files to main.h.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
; Allows to reassign books to different object PIDs, text messages.
|
||||
; Maximum 30 books are allowed (25 if overrideVanilla is 0)
|
||||
; Allows to reassign books to different object PIDs, text messages, and skills.
|
||||
; Maximum 50 books are allowed
|
||||
|
||||
[main]
|
||||
; total number of books in this file
|
||||
count=5
|
||||
count=1
|
||||
|
||||
; set to 1 to override all vanilla books, so you will have to define ALL books in this file;
|
||||
; otherwise only new books are defined here
|
||||
; set to 1 to override all vanilla books, so you will have to define ALL the necessary books in this file;
|
||||
; otherwise only new books are defined here. To just override the text/skill of a vanilla book,
|
||||
; specify its PID in the new book and set the parameters
|
||||
overrideVanilla=0
|
||||
|
||||
; count starts from 1
|
||||
|
||||
+61
-56
@@ -16,13 +16,14 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include "Books.h"
|
||||
|
||||
static int BooksCount=0;
|
||||
static const int BooksMax=30;
|
||||
static int BooksCount = 0;
|
||||
static const int BooksMax = 50;
|
||||
static char iniBooks[MAX_PATH];
|
||||
|
||||
struct sBook {
|
||||
@@ -31,10 +32,10 @@ struct sBook {
|
||||
DWORD skill;
|
||||
};
|
||||
|
||||
static sBook books[BooksMax];
|
||||
static sBook* books = nullptr;
|
||||
|
||||
static sBook* _stdcall FindBook(DWORD pid) {
|
||||
for (int i=0; i<BooksCount; i++) {
|
||||
static sBook* __fastcall FindBook(DWORD pid) {
|
||||
for (int i = BooksCount; i >= 0; i--) {
|
||||
if (books[i].bookPid == pid) {
|
||||
return &books[i];
|
||||
}
|
||||
@@ -45,72 +46,76 @@ static sBook* _stdcall FindBook(DWORD pid) {
|
||||
static const DWORD obj_use_book_hook_back = 0x49BA5A;
|
||||
static void __declspec(naked) obj_use_book_hook() {
|
||||
__asm {
|
||||
push eax
|
||||
mov edi, -1;
|
||||
mov ecx, eax;
|
||||
call FindBook;
|
||||
test eax, eax
|
||||
jnz found
|
||||
mov edi, -1
|
||||
jmp end;
|
||||
found:
|
||||
mov edi, [eax+4];
|
||||
mov ecx, [eax+8];
|
||||
end:
|
||||
jmp obj_use_book_hook_back;
|
||||
test eax, eax;
|
||||
cmovnz edi, [eax + 4]; // msgID
|
||||
cmovnz ecx, [eax + 8]; // skill
|
||||
jmp obj_use_book_hook_back;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadVanillaBooks() {
|
||||
int i = BooksCount;
|
||||
static void LoadVanillaBooks() {
|
||||
// book of science
|
||||
books[i+0].bookPid = 73;
|
||||
books[i+0].msgID = 802;
|
||||
books[i+0].skill = 12;
|
||||
books[0].bookPid = 73;
|
||||
books[0].msgID = 802;
|
||||
books[0].skill = 12;
|
||||
// Dean's electronics
|
||||
books[i+1].bookPid = 76;
|
||||
books[i+1].msgID = 803;
|
||||
books[i+1].skill = 13;
|
||||
books[1].bookPid = 76;
|
||||
books[1].msgID = 803;
|
||||
books[1].skill = 13;
|
||||
// First Aid
|
||||
books[i+2].bookPid = 80;
|
||||
books[i+2].msgID = 804;
|
||||
books[i+2].skill = 6;
|
||||
books[2].bookPid = 80;
|
||||
books[2].msgID = 804;
|
||||
books[2].skill = 6;
|
||||
// Guns & Bullets
|
||||
books[i+3].bookPid = 102;
|
||||
books[i+3].msgID = 805;
|
||||
books[i+3].skill = 0;
|
||||
books[3].bookPid = 102;
|
||||
books[3].msgID = 805;
|
||||
books[3].skill = 0;
|
||||
// Scouts Handbook
|
||||
books[i+4].bookPid = 86;
|
||||
books[i+4].msgID = 806;
|
||||
books[i+4].skill = 17;
|
||||
BooksCount += 5;
|
||||
books[4].bookPid = 86;
|
||||
books[4].msgID = 806;
|
||||
books[4].skill = 17;
|
||||
}
|
||||
|
||||
void BooksInit() {
|
||||
char buf[MAX_PATH-3];
|
||||
GetPrivateProfileString("Misc", "BooksFile", "", buf, MAX_PATH, ini);
|
||||
if (strlen(buf)>0) {
|
||||
sprintf(iniBooks, ".\\%s", buf);
|
||||
char buf[MAX_PATH - 3];
|
||||
GetPrivateProfileString("Misc", "BooksFile", "", buf, MAX_PATH - 3, ini);
|
||||
if (strlen(buf) > 0) {
|
||||
dlog("Applying books patch...", DL_INIT);
|
||||
memset(books,0,sizeof(sBook)*BooksCount);
|
||||
sprintf(iniBooks, ".\\%s", buf);
|
||||
|
||||
int i, n = 0, count;
|
||||
if (GetPrivateProfileIntA("main", "overrideVanilla", 0, iniBooks) == 0) {
|
||||
LoadVanillaBooks();
|
||||
}
|
||||
count = GetPrivateProfileIntA("main", "count", 0, iniBooks);
|
||||
bool includeVanilla = (GetPrivateProfileIntA("main", "overrideVanilla", 0, iniBooks) == 0);
|
||||
if (includeVanilla) BooksCount = 5;
|
||||
|
||||
char section[4];
|
||||
for (i=1; i<=count; i++) {
|
||||
_itoa_s(i, section, 10);
|
||||
if (BooksCount >= BooksMax) break;
|
||||
if (books[BooksCount].bookPid = GetPrivateProfileIntA(section, "PID", 0, iniBooks)) {
|
||||
books[BooksCount].msgID = GetPrivateProfileIntA(section, "TextID", 0, iniBooks);
|
||||
books[BooksCount].skill = GetPrivateProfileIntA(section, "Skill", 0, iniBooks);
|
||||
n++;
|
||||
BooksCount++;
|
||||
int count = max(0, GetPrivateProfileIntA("main", "count", 0, iniBooks));
|
||||
if (count > BooksMax) count = BooksMax;
|
||||
|
||||
int n = 0;
|
||||
if (count > 0) {
|
||||
books = new sBook[BooksCount + count];
|
||||
|
||||
if (includeVanilla) LoadVanillaBooks();
|
||||
|
||||
char section[4];
|
||||
for (int i = 1; i <= count; i++) {
|
||||
_itoa_s(i, section, 10);
|
||||
if (books[BooksCount].bookPid = GetPrivateProfileIntA(section, "PID", 0, iniBooks)) {
|
||||
books[BooksCount].msgID = GetPrivateProfileIntA(section, "TextID", 0, iniBooks);
|
||||
books[BooksCount].skill = GetPrivateProfileIntA(section, "Skill", 0, iniBooks);
|
||||
BooksCount++;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
BooksCount--; // set to last index
|
||||
|
||||
MakeJump(0x49B9FB, obj_use_book_hook);
|
||||
}
|
||||
|
||||
MakeJump(0x49B9FB, obj_use_book_hook);
|
||||
dlog_f(" (%d/%d books) Done\n", DL_INIT, n, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BooksExit() {
|
||||
if (books) delete[] books;
|
||||
}
|
||||
|
||||
+2
-1
@@ -18,4 +18,5 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
void BooksInit();
|
||||
void BooksInit();
|
||||
void BooksExit();
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
|
||||
#include "FalloutEngine.h"
|
||||
#include "FileSystem.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
extern void GetSavePath(char* buf, char* ftype);
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
#include "HeroAppearance.h"
|
||||
#include "Message.h"
|
||||
#include "ScriptExtender.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
bool appModEnabled = false; // check if Appearance mod enabled for script fuctions
|
||||
|
||||
|
||||
@@ -26,9 +26,6 @@
|
||||
#include "input.h"
|
||||
#include "Inventory.h"
|
||||
#include "LoadGameHook.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
static DWORD sizeLimitMode;
|
||||
static DWORD invSizeMaxLimit;
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
#include "FalloutEngine.h"
|
||||
#include "HeroAppearance.h"
|
||||
#include "PartyControl.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
static DWORD Mode;
|
||||
static int IsControllingNPC = 0;
|
||||
|
||||
@@ -35,9 +35,6 @@
|
||||
#include "Logging.h"
|
||||
#include "ScriptExtender.h"
|
||||
#include "version.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
static DWORD _stdcall HandleMapUpdateForScripts(const DWORD procId);
|
||||
|
||||
|
||||
@@ -22,9 +22,6 @@
|
||||
|
||||
#include "Inventory.h"
|
||||
#include "ScriptExtender.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
//script control functions
|
||||
|
||||
|
||||
@@ -42,9 +42,6 @@
|
||||
#include "input.h"
|
||||
#include "LoadGameHook.h"
|
||||
#include "Version.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
typedef HRESULT (_stdcall *DDrawCreateProc)(void*, IDirectDraw**, void*);
|
||||
typedef IDirect3D9* (_stdcall *D3DCreateProc)(UINT version);
|
||||
|
||||
+1
-3
@@ -61,9 +61,6 @@
|
||||
#include "Tiles.h"
|
||||
#include "timer.h"
|
||||
#include "version.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
ddrawDll ddraw;
|
||||
|
||||
@@ -1517,6 +1514,7 @@ static void _stdcall OnExit() {
|
||||
}
|
||||
ClearReadExtraGameMsgFiles();
|
||||
ConsoleExit();
|
||||
BooksExit();
|
||||
AnimationsAtOnceExit();
|
||||
HeroAppearanceModExit();
|
||||
MoviesExit();
|
||||
|
||||
+4
-1
@@ -22,6 +22,9 @@
|
||||
#include <Windows.h>
|
||||
#include "SafeWrite.h"
|
||||
#include "Logging.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
struct ddrawDll {
|
||||
HMODULE dll;
|
||||
@@ -94,4 +97,4 @@ T SimplePatch(DWORD *addrs, int numAddrs, const char* iniSection, const char* in
|
||||
dlogr(" Done", DL_INIT);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,6 @@
|
||||
#include "Graphics.h"
|
||||
#include "Logging.h"
|
||||
#include "movies.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
static DWORD MoviePtrs[MaxMovies];
|
||||
char MoviePaths[MaxMovies * 65];
|
||||
|
||||
@@ -26,9 +26,6 @@
|
||||
#include "FalloutEngine.h"
|
||||
#include "Knockback.h"
|
||||
#include "ScriptExtender.h"
|
||||
#if (_MSC_VER < 1600)
|
||||
#include "Cpp11_emu.h"
|
||||
#endif
|
||||
|
||||
struct SkillInfo {
|
||||
const char* name;
|
||||
|
||||
Reference in New Issue
Block a user