mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
BarBoxes: Set used count (#180)
* Added BarBoxesCount option to set the number of additional notification boxes to the interface. * Expanded is_iface_tag_active function to check tag value of 0/1/2 (sneak/poisoned/radiated)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#define FO_VAR_art_name 0x56C9E4
|
||||
#define FO_VAR_art_vault_guy_num 0x5108A4
|
||||
#define FO_VAR_art_vault_person_nums 0x5108A8
|
||||
#define FO_VAR_bboxslot 0x5970E0
|
||||
#define FO_VAR_bckgnd 0x5707A4
|
||||
#define FO_VAR_black_palette 0x663FD0
|
||||
#define FO_VAR_BlueColor 0x6A38EF
|
||||
|
||||
+110
-67
@@ -29,70 +29,78 @@ static const DWORD DisplayBoxesRet1 = 0x4615A8;
|
||||
static const DWORD DisplayBoxesRet2 = 0x4615BE;
|
||||
static const DWORD SetIndexBoxRet = 0x4612E8;
|
||||
|
||||
int BarBoxes::boxCount; // total count box
|
||||
static int actualBoxCount;
|
||||
static int sizeBox;
|
||||
|
||||
#define sSize (12)
|
||||
struct sBox {
|
||||
DWORD msg;
|
||||
DWORD colour;
|
||||
void* mem;
|
||||
};
|
||||
static sBox boxes[10];
|
||||
static DWORD boxesEnabled[5];
|
||||
|
||||
#define tSize (28)
|
||||
#define tSize (25)
|
||||
struct tBox {
|
||||
DWORD hasText;
|
||||
bool hasText;
|
||||
DWORD color;
|
||||
char text[tSize - 8];
|
||||
char text[tSize - 5];
|
||||
};
|
||||
static tBox boxText[5];
|
||||
|
||||
static DWORD clrBakup[5];
|
||||
static sBox* boxes;
|
||||
static tBox* boxText;
|
||||
static bool* boxesEnabled;
|
||||
static DWORD* colorBakup;
|
||||
|
||||
static bool setCustomBoxText;
|
||||
|
||||
static const DWORD bboxMemAddr[] = {
|
||||
0x461266, 0x4612AC, 0x461374, 0x4613E8, 0x461479, 0x46148C, 0x4616BB,
|
||||
};
|
||||
|
||||
static void __declspec(naked) DisplayBoxesHook() {
|
||||
static void __declspec(naked) DisplayBoxesHack() {
|
||||
__asm {
|
||||
mov ebx, 0;
|
||||
mov edx, [boxesEnabled];
|
||||
mov ebx, 0;
|
||||
start:
|
||||
mov eax, boxesEnabled[ebx * 4];
|
||||
test eax, eax;
|
||||
jz next;
|
||||
lea eax, [ebx + 5];
|
||||
mov al, byte ptr [edx][ebx];
|
||||
test al, al;
|
||||
jz next;
|
||||
lea eax, [ebx + 5];
|
||||
call fo::funcoffs::add_bar_box_;
|
||||
add esi, eax;
|
||||
add esi, eax;
|
||||
next:
|
||||
inc ebx;
|
||||
cmp ebx, 5;
|
||||
jne start;
|
||||
cmp esi, 1;
|
||||
jle fail;
|
||||
jmp DisplayBoxesRet1;
|
||||
inc ebx;
|
||||
cmp ebx, actualBoxCount;
|
||||
jne start;
|
||||
// engine code
|
||||
cmp esi, 1;
|
||||
jle fail;
|
||||
jmp DisplayBoxesRet1;
|
||||
fail:
|
||||
jmp DisplayBoxesRet2;
|
||||
jmp DisplayBoxesRet2;
|
||||
}
|
||||
}
|
||||
|
||||
static void __declspec(naked) BarBoxesTextHack() {
|
||||
__asm {
|
||||
//mov ecx, [esp + 0x440 - 0x1C];
|
||||
push ecx; // ecx = BoxIndex
|
||||
sub ecx, 5;
|
||||
push ecx; // ecx = BoxIndex
|
||||
sub ecx, 5;
|
||||
imul ecx, tSize;
|
||||
cmp boxText[ecx], 1; // .hasText
|
||||
jnz end;
|
||||
mov esi, [boxText]; // boxText addr
|
||||
cmp byte ptr [esi][ecx], 1; // .hasText
|
||||
jnz end;
|
||||
// get color
|
||||
mov ebx, boxText[ecx + 4]; // .color
|
||||
mov ebx, dword ptr [esi][ecx + 1]; // .color
|
||||
// set text
|
||||
lea eax, [boxText + ecx + 8]; // .text
|
||||
lea eax, [esi + ecx + 5]; // .text
|
||||
// set color
|
||||
pop ecx;
|
||||
pop ecx;
|
||||
imul ecx, sSize;
|
||||
cmp boxes[ecx + 4], 2; // .colour
|
||||
jb skip;
|
||||
mov [esp + 0x440 - 0x20], ebx; // Color
|
||||
mov esi, [boxes]; // boxes addr
|
||||
cmp dword ptr [esi][ecx + 4], 2; // .colour
|
||||
jb skip;
|
||||
mov [esp + 0x440 - 0x20], ebx; // Color
|
||||
skip:
|
||||
retn;
|
||||
end:
|
||||
@@ -110,6 +118,18 @@ static void __declspec(naked) BarBoxesIndexHack() {
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD SizeLoopBoxRet = 0x461477;
|
||||
static const DWORD ExitLoopBoxRet = 0x461498;
|
||||
static void __declspec(naked) BarBoxesSizeHack() {
|
||||
__asm {
|
||||
cmp edx, sizeBox;
|
||||
jz exitLoop;
|
||||
jmp SizeLoopBoxRet;
|
||||
exitLoop:
|
||||
jmp ExitLoopBoxRet;
|
||||
}
|
||||
}
|
||||
|
||||
static void ReconstructBarBoxes() {
|
||||
__asm {
|
||||
call fo::funcoffs::refresh_box_bar_win_;
|
||||
@@ -119,9 +139,9 @@ static void ReconstructBarBoxes() {
|
||||
}
|
||||
|
||||
static void ResetBoxes() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
boxesEnabled[i] = 0;
|
||||
boxes[i + 5].colour = clrBakup[i];
|
||||
for (int i = 0; i < actualBoxCount; i++) {
|
||||
boxesEnabled[i] = false;
|
||||
boxes[i + 5].colour = colorBakup[i];
|
||||
}
|
||||
|
||||
if (!setCustomBoxText) return;
|
||||
@@ -138,7 +158,7 @@ static void ResetBoxes() {
|
||||
void BarBoxes::SetText(int box, const char* text, DWORD color) {
|
||||
boxes[box].colour = color;
|
||||
box -= 5;
|
||||
boxText[box].hasText = 1;
|
||||
boxText[box].hasText = true;
|
||||
strncpy_s(boxText[box].text, text, _TRUNCATE);
|
||||
|
||||
DWORD clr;
|
||||
@@ -163,10 +183,10 @@ void BarBoxes::SetText(int box, const char* text, DWORD color) {
|
||||
}
|
||||
boxText[box].color = clr;
|
||||
|
||||
int enabled[5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
bool* enabled = new bool[actualBoxCount];
|
||||
for (int i = 0; i < actualBoxCount; i++) {
|
||||
enabled[i] = boxesEnabled[i];
|
||||
boxesEnabled[i] = 0;
|
||||
boxesEnabled[i] = false;
|
||||
}
|
||||
|
||||
if (!setCustomBoxText) {
|
||||
@@ -177,59 +197,82 @@ void BarBoxes::SetText(int box, const char* text, DWORD color) {
|
||||
|
||||
ReconstructBarBoxes();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int i = 0; i < actualBoxCount; i++) {
|
||||
boxesEnabled[i] = enabled[i];
|
||||
}
|
||||
delete[] enabled;
|
||||
|
||||
__asm call fo::funcoffs::refresh_box_bar_win_;
|
||||
}
|
||||
|
||||
void BarBoxes::init() {
|
||||
SafeWriteBatch<DWORD>((DWORD)boxes + 8, bboxMemAddr); //.mem
|
||||
SafeWrite32(0x4612FE, (DWORD)boxes + 4); //.colour
|
||||
SafeWrite32(0x46133C, (DWORD)boxes); //.msg
|
||||
|
||||
int size = sSize * 10;
|
||||
memset(boxes, 0, size);
|
||||
memset(boxesEnabled, 0, 5 * 4);
|
||||
boxCount = 5 + GetConfigInt("Misc", "BoxBarCount", 5);
|
||||
if (boxCount < 10) boxCount = 10;
|
||||
if (boxCount > 100) boxCount = 100;
|
||||
|
||||
actualBoxCount = boxCount - 5;
|
||||
sizeBox = sSize * boxCount;
|
||||
|
||||
boxes = new sBox[boxCount]();
|
||||
boxText = new tBox[actualBoxCount]();
|
||||
boxesEnabled = new bool[actualBoxCount]();
|
||||
colorBakup = new DWORD[actualBoxCount]();
|
||||
|
||||
memcpy(boxes, (void*)0x518FE8, sSize * 5);
|
||||
|
||||
for (int i = 5; i < 10; i++) {
|
||||
for (int i = 5; i < boxCount; i++) {
|
||||
boxes[i].msg = 100 + i;
|
||||
}
|
||||
|
||||
SafeWrite8(0x46127C, 10);
|
||||
SafeWrite8(0x46140B, 10);
|
||||
SafeWrite8(0x461495, size);
|
||||
|
||||
MakeJump(0x4615A3, DisplayBoxesHook);
|
||||
auto boxBarColors = GetConfigString("Misc", "BoxBarColours", "", 6);
|
||||
if (boxBarColors.size() >= 5) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (boxBarColors[i] == '1') {
|
||||
boxes[i + 5].colour = 1;
|
||||
clrBakup[i] = 1;
|
||||
} else {
|
||||
clrBakup[i] = 0;
|
||||
}
|
||||
auto boxBarColors = GetConfigString("Misc", "BoxBarColours", "", actualBoxCount + 1);
|
||||
int size = boxBarColors.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (boxBarColors[i] == '1') {
|
||||
boxes[i + 5].colour = 1;
|
||||
colorBakup[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
SafeWriteBatch<DWORD>((DWORD)boxes + 8, bboxMemAddr); //.mem
|
||||
SafeWrite32(0x4612FE, (DWORD)boxes + 4); //.colour
|
||||
SafeWrite32(0x46133C, (DWORD)boxes); //.msg
|
||||
|
||||
SafeWrite8(0x46127C, boxCount);
|
||||
SafeWrite8(0x46140B, boxCount);
|
||||
|
||||
if (boxCount > 10) {
|
||||
MakeJump(0x461493, BarBoxesSizeHack);
|
||||
} else {
|
||||
SafeWrite8(0x461495, sizeBox);
|
||||
}
|
||||
MakeJump(0x4615A3, DisplayBoxesHack);
|
||||
|
||||
LoadGameHook::OnGameReset() += ResetBoxes;
|
||||
}
|
||||
|
||||
int _stdcall GetBox(int i) {
|
||||
if (i < 5 || i > 9) return 0;
|
||||
bool BarBoxes::GetBox(int i) {
|
||||
if (i < 5 || i > BarBoxes::MaxBox()) return false;
|
||||
return boxesEnabled[i - 5];
|
||||
}
|
||||
|
||||
void _stdcall AddBox(int i) {
|
||||
if (i < 5 || i > 9) return;
|
||||
void BarBoxes::AddBox(int i) {
|
||||
if (i < 5 || i > BarBoxes::MaxBox()) return;
|
||||
boxesEnabled[i - 5] = 1;
|
||||
_asm call fo::funcoffs::refresh_box_bar_win_;
|
||||
}
|
||||
|
||||
void _stdcall RemoveBox(int i) {
|
||||
if (i < 5 || i > 9) return;
|
||||
void BarBoxes::RemoveBox(int i) {
|
||||
if (i < 5 || i > BarBoxes::MaxBox()) return;
|
||||
boxesEnabled[i - 5] = 0;
|
||||
_asm call fo::funcoffs::refresh_box_bar_win_;
|
||||
}
|
||||
|
||||
void BarBoxes::exit() {
|
||||
delete[] boxes;
|
||||
delete[] boxText;
|
||||
delete[] boxesEnabled;
|
||||
delete[] colorBakup;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,15 +4,21 @@ namespace sfall
|
||||
{
|
||||
|
||||
class BarBoxes : public Module {
|
||||
private:
|
||||
static int boxCount;
|
||||
|
||||
public:
|
||||
const char* name() { return "BarBoxes"; }
|
||||
void init();
|
||||
void exit() override;
|
||||
|
||||
static int MaxBox() { return boxCount - 1; }
|
||||
static void SetText(int box, const char* text, DWORD color);
|
||||
|
||||
static bool GetBox(int);
|
||||
static void AddBox(int);
|
||||
static void RemoveBox(int);
|
||||
|
||||
};
|
||||
|
||||
int _stdcall GetBox(int i);
|
||||
void _stdcall AddBox(int i);
|
||||
void _stdcall RemoveBox(int i);
|
||||
|
||||
}
|
||||
|
||||
@@ -305,104 +305,50 @@ end:
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_show_iface_tag() {
|
||||
__asm {
|
||||
pushad;
|
||||
mov ecx, eax;
|
||||
call fo::funcoffs::interpretPopShort_;
|
||||
mov edx, eax;
|
||||
mov eax, ecx;
|
||||
call fo::funcoffs::interpretPopLong_;
|
||||
cmp dx, VAR_TYPE_INT;
|
||||
jnz end;
|
||||
cmp eax, 3;
|
||||
je falloutfunc;
|
||||
cmp eax, 4;
|
||||
je falloutfunc;
|
||||
push eax;
|
||||
call AddBox;
|
||||
call fo::funcoffs::refresh_box_bar_win_;
|
||||
jmp end;
|
||||
falloutfunc:
|
||||
call fo::funcoffs::pc_flag_on_;
|
||||
end:
|
||||
popad;
|
||||
retn;
|
||||
void sf_show_iface_tag(OpcodeContext &ctx) {
|
||||
int tag = ctx.arg(0).asInt();
|
||||
if (tag == 3 || tag == 4) {
|
||||
_asm mov eax, tag;
|
||||
_asm call fo::funcoffs::pc_flag_on_;
|
||||
} else {
|
||||
BarBoxes::AddBox(tag);
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_hide_iface_tag() {
|
||||
__asm {
|
||||
pushad;
|
||||
mov ecx, eax;
|
||||
call fo::funcoffs::interpretPopShort_;
|
||||
mov edx, eax;
|
||||
mov eax, ecx;
|
||||
call fo::funcoffs::interpretPopLong_;
|
||||
cmp dx, VAR_TYPE_INT;
|
||||
jnz end;
|
||||
cmp eax, 3;
|
||||
je falloutfunc;
|
||||
cmp eax, 4;
|
||||
je falloutfunc;
|
||||
push eax;
|
||||
call RemoveBox;
|
||||
call fo::funcoffs::refresh_box_bar_win_;
|
||||
jmp end;
|
||||
falloutfunc:
|
||||
call fo::funcoffs::pc_flag_off_;
|
||||
end:
|
||||
popad;
|
||||
retn;
|
||||
void sf_hide_iface_tag(OpcodeContext &ctx) {
|
||||
int tag = ctx.arg(0).asInt();
|
||||
if (tag == 3 || tag == 4) {
|
||||
_asm mov eax, tag;
|
||||
_asm call fo::funcoffs::pc_flag_off_;
|
||||
} else {
|
||||
BarBoxes::RemoveBox(tag);
|
||||
}
|
||||
}
|
||||
|
||||
void __declspec(naked) op_is_iface_tag_active() {
|
||||
__asm {
|
||||
pushad;
|
||||
sub esp, 4;
|
||||
mov ebx, eax;
|
||||
call fo::funcoffs::interpretPopShort_;
|
||||
mov edx, eax;
|
||||
mov eax, ebx;
|
||||
call fo::funcoffs::interpretPopLong_;
|
||||
cmp dx, VAR_TYPE_INT;
|
||||
jnz fail;
|
||||
cmp eax, 3;
|
||||
je falloutfunc;
|
||||
cmp eax, 4;
|
||||
je falloutfunc;
|
||||
push eax;
|
||||
call GetBox;
|
||||
mov edx, eax;
|
||||
jmp end;
|
||||
falloutfunc:
|
||||
mov ecx, eax;
|
||||
mov eax, dword ptr ds:[FO_VAR_obj_dude];
|
||||
mov edx, esp;
|
||||
mov eax, [eax + 0x64];
|
||||
call fo::funcoffs::proto_ptr_;
|
||||
mov edx, 1;
|
||||
shl edx, cl;
|
||||
mov ecx, [esp];
|
||||
mov eax, [ecx + 0x20];
|
||||
and eax, edx;
|
||||
jz fail;
|
||||
xor edx, edx;
|
||||
inc edx;
|
||||
jmp end;
|
||||
fail:
|
||||
xor edx, edx;
|
||||
end:
|
||||
mov eax, ebx;
|
||||
call fo::funcoffs::interpretPushLong_;
|
||||
mov eax, ebx;
|
||||
mov edx, VAR_TYPE_INT;
|
||||
call fo::funcoffs::interpretPushShort_;
|
||||
add esp, 4;
|
||||
popad;
|
||||
retn;
|
||||
void sf_is_iface_tag_active(OpcodeContext &ctx) {
|
||||
bool result = false;
|
||||
int tag = ctx.arg(0).asInt();
|
||||
if (tag >= 0 && tag < 5) {
|
||||
if (tag == 1 || tag == 2) { // Poison/Radiation
|
||||
tag += 2;
|
||||
int* boxslot = (int*)FO_VAR_bboxslot;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int value = boxslot[i];
|
||||
if (value == tag || value == -1) {
|
||||
result = (value != -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else { // Sneak/Level/Addict
|
||||
fo::GameObject* obj = fo::var::obj_dude;
|
||||
fo::Proto* proto = fo::GetProto(obj->protoId);
|
||||
int flagBit = 1 << tag;
|
||||
result = ((proto->critter.critterFlags & flagBit) != 0);
|
||||
}
|
||||
} else {
|
||||
result = BarBoxes::GetBox(tag);
|
||||
}
|
||||
ctx.setReturn(result);
|
||||
}
|
||||
|
||||
void sf_intface_redraw(OpcodeContext& ctx) {
|
||||
@@ -410,17 +356,17 @@ void sf_intface_redraw(OpcodeContext& ctx) {
|
||||
}
|
||||
|
||||
void sf_intface_show(OpcodeContext& ctx) {
|
||||
__asm call fo::funcoffs::intface_show_
|
||||
__asm call fo::funcoffs::intface_show_;
|
||||
}
|
||||
|
||||
void sf_intface_hide(OpcodeContext& ctx) {
|
||||
__asm call fo::funcoffs::intface_hide_
|
||||
__asm call fo::funcoffs::intface_hide_;
|
||||
}
|
||||
|
||||
void sf_intface_is_hidden(OpcodeContext& ctx) {
|
||||
int isHidden;
|
||||
__asm {
|
||||
call fo::funcoffs::intface_is_hidden_
|
||||
call fo::funcoffs::intface_is_hidden_;
|
||||
mov isHidden, eax;
|
||||
}
|
||||
ctx.setReturn(isHidden);
|
||||
@@ -433,7 +379,7 @@ void sf_tile_refresh_display(OpcodeContext& ctx) {
|
||||
void sf_get_cursor_mode(OpcodeContext& ctx) {
|
||||
int cursorMode;
|
||||
__asm {
|
||||
call fo::funcoffs::gmouse_3d_get_mode_
|
||||
call fo::funcoffs::gmouse_3d_get_mode_;
|
||||
mov cursorMode, eax;
|
||||
}
|
||||
ctx.setReturn(cursorMode);
|
||||
@@ -453,10 +399,11 @@ void sf_display_stats(OpcodeContext& ctx) {
|
||||
void sf_set_iface_tag_text(OpcodeContext& ctx) {
|
||||
int boxTag = ctx.arg(0).asInt();
|
||||
|
||||
if (boxTag > 4 && boxTag < 10) {
|
||||
int maxBox = BarBoxes::MaxBox();
|
||||
if (boxTag > 4 && boxTag <= maxBox) {
|
||||
BarBoxes::SetText(boxTag, ctx.arg(1).asString(), ctx.arg(2).asInt());
|
||||
} else {
|
||||
ctx.printOpcodeError("set_iface_tag_text() - tag value must be in the range of 5 to 9.");
|
||||
ctx.printOpcodeError("set_iface_tag_text() - tag value must be in the range of 5 to %d.", maxBox);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,11 +67,11 @@ void __declspec() op_set_viewport_x();
|
||||
|
||||
void __declspec() op_set_viewport_y();
|
||||
|
||||
void __declspec() op_show_iface_tag();
|
||||
void sf_show_iface_tag(OpcodeContext&);
|
||||
|
||||
void __declspec() op_hide_iface_tag();
|
||||
void sf_hide_iface_tag(OpcodeContext&);
|
||||
|
||||
void __declspec() op_is_iface_tag_active();
|
||||
void sf_is_iface_tag_active(OpcodeContext&);
|
||||
|
||||
void sf_intface_redraw(OpcodeContext&);
|
||||
|
||||
|
||||
@@ -64,6 +64,9 @@ typedef std::unordered_map<int, const SfallOpcodeInfo*> OpcodeInfoMapType;
|
||||
// }
|
||||
static SfallOpcodeInfo opcodeInfoArray[] = {
|
||||
{0x16c, "key_pressed", sf_key_pressed, 1, true},
|
||||
{0x1dc, "show_iface_tag", sf_show_iface_tag, 1, false, {ARG_INT}},
|
||||
{0x1dd, "hide_iface_tag", sf_hide_iface_tag, 1, false, {ARG_INT}},
|
||||
{0x1de, "is_iface_tag_active", sf_is_iface_tag_active, 1, true, {ARG_INT}},
|
||||
{0x1ec, "sqrt", sf_sqrt, 1, true, {ARG_NUMBER}},
|
||||
{0x1ed, "abs", sf_abs, 1, true, {ARG_NUMBER}},
|
||||
{0x1ee, "sin", sf_sin, 1, true, {ARG_NUMBER}},
|
||||
@@ -326,9 +329,6 @@ void InitNewOpcodes() {
|
||||
opcodes[i] = op_call_offset;
|
||||
}
|
||||
}
|
||||
opcodes[0x1dc] = op_show_iface_tag;
|
||||
opcodes[0x1dd] = op_hide_iface_tag;
|
||||
opcodes[0x1de] = op_is_iface_tag_active;
|
||||
opcodes[0x1df] = op_get_bodypart_hit_modifier;
|
||||
opcodes[0x1e0] = op_set_bodypart_hit_modifier;
|
||||
opcodes[0x1e1] = op_set_critical_table;
|
||||
|
||||
Reference in New Issue
Block a user