Skip to content

Commit

Permalink
Excluded barter mode for ItemCounterDefaultMax
Browse files Browse the repository at this point in the history
Renamed GetCurrentLoops function to "GetLoopFlags".
Minor edits to document/code.
  • Loading branch information
NovaRain committed Jul 10, 2019
1 parent e43762b commit ce19262
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion artifacts/ddraw.ini
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ StackEmptyWeapons=0
;If the amount of ammo boxes in the inventory is less than or equal to the reserve, only one box will be used
ReloadReserve=-1

;Set to 1 to change the counter in the 'Move Items' window to start at the maximum number of items
;Set to 1 to change the counter in the 'Move Items' window to start with maximum number except in the barter screen
ItemCounterDefaultMax=0

;Set to 1 to leave the music playing in dialogue with talking heads
Expand Down
2 changes: 1 addition & 1 deletion sfall/BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ static void __declspec(naked) process_rads_hook() {
__asm {
push eax; // death message for DialogOut
call display_print_;
call GetCurrentLoops;
call GetLoopFlags;
test eax, PIPBOY;
jz skip;
mov eax, 1;
Expand Down
18 changes: 10 additions & 8 deletions sfall/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ static DDSURFACEDESC surfaceDesc;
static DDSURFACEDESC movieDesc;

static DWORD palette[256];
//static bool paletteInit = false;

static DWORD gWidth;
static DWORD gHeight;

static int ScrollWindowKey;
static bool windowIsInit;
static bool windowInit = false;
static DWORD windowLeft = 0;
static DWORD windowTop = 0;

Expand Down Expand Up @@ -388,7 +389,8 @@ static void Present() {
if (ScrollWindowKey != 0 && ((ScrollWindowKey > 0 && KeyDown((BYTE)ScrollWindowKey))
|| (ScrollWindowKey == -1 && (KeyDown(DIK_LCONTROL) || KeyDown(DIK_RCONTROL)))
|| (ScrollWindowKey == -2 && (KeyDown(DIK_LMENU) || KeyDown(DIK_RMENU)))
|| (ScrollWindowKey == -3 && (KeyDown(DIK_LSHIFT) || KeyDown(DIK_RSHIFT))))) {
|| (ScrollWindowKey == -3 && (KeyDown(DIK_LSHIFT) || KeyDown(DIK_RSHIFT)))))
{
int winx, winy;
GetMouse(&winx, &winy);
windowLeft += winx;
Expand Down Expand Up @@ -474,8 +476,8 @@ void RefreshGraphics() {
}
for (int d = shadersSize - 1; d >= 0; d--) {
if (!shaders[d].Effect || !shaders[d].Active) continue;
if (shaders[d].mode2 && !(shaders[d].mode2 & GetCurrentLoops())) continue;
if (shaders[d].mode & GetCurrentLoops()) continue;
if (shaders[d].mode2 && !(shaders[d].mode2 & GetLoopFlags())) continue;
if (shaders[d].mode & GetLoopFlags()) continue;

if (shaders[d].ehTicks) shaders[d].Effect->SetInt(shaders[d].ehTicks, GetTickCount());
UINT passes;
Expand Down Expand Up @@ -624,7 +626,7 @@ class FakePalette2 : IDirectDrawPalette {
HRESULT _stdcall Initialize(LPDIRECTDRAW, DWORD, LPPALETTEENTRY) { UNUSEDFUNCTION; }

HRESULT _stdcall SetEntries(DWORD, DWORD b, DWORD c, LPPALETTEENTRY destPal) {
if (!windowIsInit || c == 0 || b + c > 256) return DDERR_INVALIDPARAMS;
if (!windowInit || c == 0 || b + c > 256) return DDERR_INVALIDPARAMS;

CopyMemory(&palette[b], destPal, c * 4);
if (GPUBlt) {
Expand All @@ -638,8 +640,8 @@ class FakePalette2 : IDirectDrawPalette {
} else {
for (DWORD i = b; i < b + c; i++) { // swap color R <> B
//palette[i]&=0x00ffffff;
BYTE clr = *(BYTE*)((DWORD)&palette[i]);
*(BYTE*)((DWORD)&palette[i]) = *(BYTE*)((DWORD)&palette[i] + 2);
BYTE clr = *(BYTE*)((DWORD)&palette[i]); // B
*(BYTE*)((DWORD)&palette[i]) = *(BYTE*)((DWORD)&palette[i] + 2); // R
*(BYTE*)((DWORD)&palette[i] + 2) = clr;
}
}
Expand Down Expand Up @@ -1061,7 +1063,7 @@ HRESULT _stdcall FakeDirectDrawCreate2(void*, IDirectDraw** b, void*) {

static __declspec(naked) void game_init_hook() {
__asm {
mov windowIsInit, 1;
mov windowInit, 1;
jmp palette_init_;
}
}
Expand Down
14 changes: 12 additions & 2 deletions sfall/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TGameObj* GetActiveItem() {
}

void InventoryKeyPressedHook(DWORD dxKey, bool pressed, DWORD vKey) {
if (pressed && reloadWeaponKey && dxKey == reloadWeaponKey && IsMapLoaded() && (GetCurrentLoops() & ~(COMBAT | PCOMBAT)) == 0) {
if (pressed && reloadWeaponKey && dxKey == reloadWeaponKey && IsMapLoaded() && (GetLoopFlags() & ~(COMBAT | PCOMBAT)) == 0) {
DWORD maxAmmo, curAmmo;
TGameObj* item = GetActiveItem();
__asm {
Expand Down Expand Up @@ -707,6 +707,16 @@ static void __declspec(naked) do_move_timer_hook() {
}
}

static void __declspec(naked) do_move_timer_hack() {
__asm {
mov ebx, 1;
call GetLoopFlags;
test eax, BARTER;
cmovz ebx, ebp; // set max when not in barter
retn;
}
}

static int invenApCost, invenApCostDef;
static char invenApQPReduction;
static const DWORD inven_ap_cost_Ret = 0x46E812;
Expand Down Expand Up @@ -832,7 +842,7 @@ void InventoryInit() {
}

if (GetPrivateProfileIntA("Misc", "ItemCounterDefaultMax", 0, ini)) {
BlockCall(0x4768A3); // mov ebx, 1
MakeCall(0x4768A3, do_move_timer_hack);
}

// Move items from bag/backpack to the main inventory list by dragging them on the character portrait (similar to Fallout 1 behavior)
Expand Down
2 changes: 1 addition & 1 deletion sfall/LoadGameHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ DWORD InDialog() {
return (InLoop & DIALOG) ? 1 : 0;
}

DWORD GetCurrentLoops() {
DWORD GetLoopFlags() {
return InLoop;
}

Expand Down
2 changes: 1 addition & 1 deletion sfall/LoadGameHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ DWORD InDialog();
#define BARTER (1<<17) // 0x20000
#define RESERVED (1<<31)

DWORD GetCurrentLoops();
DWORD GetLoopFlags();
4 changes: 2 additions & 2 deletions sfall/ScriptExtender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ static void __declspec(naked) queue_add_hack() {
pop edx;
pop ecx;
end:
xor edi, edi; // fix: don't set "Used" flag for critter objects
xor edi, edi; // fix: don't set "Used" flag for non-item objects
retn;
}
}
Expand Down Expand Up @@ -1372,7 +1372,7 @@ void ScriptExtenderSetup() {
// Fix mapper bug by reassigning object IDs to critters (for unvisited maps)
MakeCall(0x482E6B, map_load_file_hack);
SafeWrite8(0x482E71, 0x85); // jz > jnz
// Additionally fix object IDs for queue events
// Additionally fix object IDs for queued events
MakeCall(0x4A25BA, queue_add_hack);

arraysBehavior = GetPrivateProfileIntA("Misc", "arraysBehavior", 1, ini);
Expand Down
4 changes: 2 additions & 2 deletions sfall/ScriptOps/InterfaceOp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,14 @@ static void sf_set_cursor_mode() {

static void sf_display_stats() {
// calling the function outside of inventory screen will crash the game
if (GetCurrentLoops() & INVENTORY) {
if (GetLoopFlags() & INVENTORY) {
__asm call display_stats_;
}
}

static void sf_inventory_redraw() {
int mode;
DWORD loopFlag = GetCurrentLoops();
DWORD loopFlag = GetLoopFlags();
if (loopFlag & INVENTORY) {
mode = 0;
} else if (loopFlag & INTFACEUSE) {
Expand Down
2 changes: 1 addition & 1 deletion sfall/ScriptOps/ObjectsOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ static void sf_get_obj_under_cursor() {
}

static void sf_get_loot_object() {
opHandler.setReturn((GetCurrentLoops() & INTFACELOOT) ? LoadGameHook_LootTarget : 0, DATATYPE_INT);
opHandler.setReturn((GetLoopFlags() & INTFACELOOT) ? LoadGameHook_LootTarget : 0, DATATYPE_INT);
}

static void sf_get_object_data() {
Expand Down
2 changes: 1 addition & 1 deletion sfall/ScriptOps/WorldmapOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void __declspec(naked) GetGameMode() {
push ecx;
push edx;
push eax;
call GetCurrentLoops;
call GetLoopFlags;
mov edx, eax;
pop eax;
_RET_VAL_INT2(ecx);
Expand Down
2 changes: 1 addition & 1 deletion sfall/SpeedPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static DWORD _stdcall FakeGetTickCount() {

// Multiply the tick count difference by the multiplier
if (enabled && !slideShow
&& !(GetCurrentLoops() & (INVENTORY | INTFACEUSE | INTFACELOOT | DIALOG)))
&& !(GetLoopFlags() & (INVENTORY | INTFACEUSE | INTFACELOOT | DIALOG)))
{
elapsed *= multi;
tickCountFraction += modf(elapsed, &elapsed);
Expand Down

0 comments on commit ce19262

Please sign in to comment.