From ae7245579ea24f8cee9f4b757340119197ae9656 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 6 Apr 2019 08:24:49 +0800 Subject: [PATCH] Fixed setting array values in the debug editor. Some code corrections. --- MPClient/DebugEditor.Designer.cs | 1 - MPClient/DebugEditor.cs | 6 ++++++ MPClient/EditorWindow.Designer.cs | 2 +- sfall/InputFuncs.cpp | 5 +++++ sfall/InputFuncs.h | 5 +++-- sfall/Modules/BugFixes.cpp | 6 +++--- sfall/Modules/DebugEditor.cpp | 1 + sfall/Modules/Perks.cpp | 12 +++++------- sfall/Modules/Scripting/Arrays.cpp | 3 +++ sfall/Modules/Stats.cpp | 4 ++-- 10 files changed, 29 insertions(+), 16 deletions(-) diff --git a/MPClient/DebugEditor.Designer.cs b/MPClient/DebugEditor.Designer.cs index c9ce1dae..73b61bc9 100644 --- a/MPClient/DebugEditor.Designer.cs +++ b/MPClient/DebugEditor.Designer.cs @@ -23,7 +23,6 @@ /// the contents of this method with the code editor. /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.Column0 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); diff --git a/MPClient/DebugEditor.cs b/MPClient/DebugEditor.cs index a9051113..14ea6f9f 100644 --- a/MPClient/DebugEditor.cs +++ b/MPClient/DebugEditor.cs @@ -231,6 +231,9 @@ namespace FalloutClient { BinaryReader br = new BinaryReader(new MemoryStream(buf)); for (int j = 0; j < strings.Length; j++) { switch (types[j]) { + case DataType.None: + br.BaseStream.Position += 4; + break; case DataType.Int: strings[j] = br.ReadInt32().ToString(); break; @@ -250,6 +253,9 @@ namespace FalloutClient { BinaryWriter bw = new BinaryWriter(ms); for (int j = 0; j < strings.Length; j++) { switch (types[j]) { + case DataType.None: + bw.BaseStream.Position += 4; + break; case DataType.Int: bw.Write(int.Parse(strings[j])); break; diff --git a/MPClient/EditorWindow.Designer.cs b/MPClient/EditorWindow.Designer.cs index b2e7b02d..052916b1 100644 --- a/MPClient/EditorWindow.Designer.cs +++ b/MPClient/EditorWindow.Designer.cs @@ -111,7 +111,7 @@ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; this.MinimumSize = new System.Drawing.Size(300, 200); this.Name = "EditorWindow"; - this.Text = "Editor Values"; + this.Text = "Edit Values"; ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); diff --git a/sfall/InputFuncs.cpp b/sfall/InputFuncs.cpp index 71a98ea6..93741447 100644 --- a/sfall/InputFuncs.cpp +++ b/sfall/InputFuncs.cpp @@ -102,6 +102,11 @@ Delegate<>& OnInputLoop() { return onInputLoop; } +void FlushInputBuffer() { + while (!bufferedPresses.empty()) bufferedPresses.pop(); + __asm call fo::funcoffs::kb_clear_; +} + DWORD _stdcall KeyDown(DWORD key) { if ((key & 0x80000000) > 0) { // special flag to check by VK code directly return GetAsyncKeyState(key & 0xFFFF) & 0x8000; diff --git a/sfall/InputFuncs.h b/sfall/InputFuncs.h index 893e0b0c..0f35604b 100644 --- a/sfall/InputFuncs.h +++ b/sfall/InputFuncs.h @@ -31,6 +31,7 @@ extern bool middleMouseDown; void SetMDown(bool down, bool right); void SetMPos(int x, int y); +void FlushInputBuffer(); DWORD _stdcall KeyDown(DWORD key); void _stdcall TapKey(DWORD key); @@ -43,6 +44,8 @@ Delegate<>& OnInputLoop(); void GetMouse(int* x, int* y); +void _stdcall ForceGraphicsRefresh(DWORD); + #define DIK_ESCAPE 0x01 #define DIK_1 0x02 #define DIK_2 0x03 @@ -190,6 +193,4 @@ void GetMouse(int* x, int* y); */ #define DIK_CIRCUMFLEX DIK_PREVTRACK /* Japanese keyboard */ -void _stdcall ForceGraphicsRefresh(DWORD); - } diff --git a/sfall/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 721cf8ad..d007bc20 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -2582,14 +2582,14 @@ void BugFixes::init() 0x499013 // PrintAMelevList_ }); + // Fix "out of bounds" bug when printing the automap list + HookCall(0x499240, PrintAMList_hook); + // Fix for a duplicate obj_dude script being created when loading a saved game HookCall(0x48D63E, obj_load_dude_hook0); HookCall(0x48D666, obj_load_dude_hook1); BlockCall(0x48D675); BlockCall(0x48D69D); - - // Fix "out of bounds" bug when printing the automap list - HookCall(0x499240, PrintAMList_hook); } } diff --git a/sfall/Modules/DebugEditor.cpp b/sfall/Modules/DebugEditor.cpp index 884de027..d67a2586 100644 --- a/sfall/Modules/DebugEditor.cpp +++ b/sfall/Modules/DebugEditor.cpp @@ -202,6 +202,7 @@ static void RunEditorInternal(SOCKET &s) { delete[] sglobals; delete[] arrays; + FlushInputBuffer(); *(DWORD*)FO_VAR_script_engine_running = 1; } diff --git a/sfall/Modules/Perks.cpp b/sfall/Modules/Perks.cpp index 990964e4..847fde03 100644 --- a/sfall/Modules/Perks.cpp +++ b/sfall/Modules/Perks.cpp @@ -92,7 +92,7 @@ std::vector fakeTraits; std::vector fakePerks; std::vector fakeSelectablePerks; // available perks for selection in the perk selection list -static std::list RemoveTraitID; +static long RemoveTraitID = -1; static std::list RemovePerkID; static std::list RemoveSelectableID; @@ -605,7 +605,7 @@ static void _stdcall AddFakePerk(DWORD perkID) { } } if (!matched) { - RemoveTraitID.push_back(count); // index of the added trait + if (RemoveTraitID == -1) RemoveTraitID = count; // index of the added trait fakeTraits.push_back(fakeSelectablePerks[perkID]); } } @@ -1314,16 +1314,14 @@ void _stdcall ClearSelectablePerks() { } void PerksEnterCharScreen() { - RemoveTraitID.clear(); + RemoveTraitID = -1; RemovePerkID.clear(); RemoveSelectableID.clear(); } void PerksCancelCharScreen() { - if (RemoveTraitID.size() > 1) RemoveTraitID.sort(); - while (!RemoveTraitID.empty()) { - fakeTraits.erase(fakeTraits.begin() + RemoveTraitID.back()); - RemoveTraitID.pop_back(); + if (RemoveTraitID != -1) { + fakeTraits.erase(fakeTraits.begin() + RemoveTraitID, fakeTraits.end()); } if (RemovePerkID.size() > 1) RemovePerkID.sort(); // sorting to correctly remove from the end while (!RemovePerkID.empty()) { diff --git a/sfall/Modules/Scripting/Arrays.cpp b/sfall/Modules/Scripting/Arrays.cpp index 15f021c6..def6b441 100644 --- a/sfall/Modules/Scripting/Arrays.cpp +++ b/sfall/Modules/Scripting/Arrays.cpp @@ -345,6 +345,9 @@ void DESetArray(int id, const DWORD* types, const char* data) { for (size_t i = 0; i < arrays[id].val.size(); i++) { auto& arVal = arrays[id].val[i]; switch (arVal.type) { + case DataType::NONE: + pos += 4; + break; case DataType::INT: arVal.intVal = *(long*)(data + pos); pos += 4; diff --git a/sfall/Modules/Stats.cpp b/sfall/Modules/Stats.cpp index 26668d0c..95dc2446 100644 --- a/sfall/Modules/Stats.cpp +++ b/sfall/Modules/Stats.cpp @@ -74,7 +74,7 @@ struct ProtoModify { std::forward_as_tuple(newProto, objPID)); } else { s_proto = it->second.proto; - if (s_proto == nullptr) { // prototype has not been created yet + if (s_proto == nullptr) { // prototype has not been created it->second.sharedCount = CreateProtoMem(it, defaultProto, s_proto); it->second.proto = s_proto; } @@ -504,7 +504,7 @@ bool Stats::LoadStatData(HANDLE file) { if (sizeRead != 20) return true; s_baseStatProto.emplace_back(data); if (protoMem.find(data.objID) == protoMem.end()) { - protoMem.emplace(data.objID, data.objPID); // protoMem[data.objID] = ProtoMem(data.objPID); + protoMem.emplace(data.objID, data.objPID); } } ReadFile(file, &count, 4, &sizeRead, 0);