Skip to content

Commit

Permalink
Fixed setting array values in the debug editor.
Browse files Browse the repository at this point in the history
Some code corrections.
  • Loading branch information
NovaRain committed Apr 6, 2019
1 parent 9ec8a12 commit 4232be0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
1 change: 0 additions & 1 deletion MPClient/DebugEditor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions MPClient/DebugEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ private void bEdit_Click(object sender, EventArgs e) {
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;
Expand All @@ -250,6 +253,9 @@ private void bEdit_Click(object sender, EventArgs e) {
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;
Expand Down
3 changes: 3 additions & 0 deletions sfall/Arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ void DESetArray(int id, const DWORD* types, const char* data) {
for (size_t i = 0; i < arrays[id].val.size(); i++) {
sArrayElement& arVal = arrays[id].val[i];
switch (arVal.type) {
case DATATYPE_NONE:
pos += 4;
break;
case DATATYPE_INT:
arVal.intVal = *(long*)(data + pos);
pos += 4;
Expand Down
6 changes: 3 additions & 3 deletions sfall/Bugs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2536,12 +2536,12 @@ void BugsInit()
HookCall(0x499212, PrintAutoMapList); // PrintAMList_
HookCall(0x499013, PrintAutoMapList); // 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);
}
12 changes: 5 additions & 7 deletions sfall/Perks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ std::vector<FakePerk> fakeTraits;
std::vector<FakePerk> fakePerks;
std::vector<FakePerk> fakeSelectablePerks;

static std::list<int> RemoveTraitID;
static long RemoveTraitID = -1;
static std::list<int> RemovePerkID;
static std::list<int> RemoveSelectableID;

Expand Down Expand Up @@ -566,7 +566,7 @@ static void _stdcall AddFakePerk(DWORD perkID) {
}
}
if (!matched) {
RemoveTraitID.push_back(fakeTraits.size());
if (RemoveTraitID == -1) RemoveTraitID = fakeTraits.size();
fakeTraits.push_back(fakeSelectablePerks[perkID]);
}
}
Expand Down Expand Up @@ -1134,16 +1134,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()) {
Expand Down
4 changes: 2 additions & 2 deletions sfall/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ void _stdcall TapKey(DWORD key);

void GetMouse(int* x, int* y);

void _stdcall ForceGraphicsRefresh(DWORD);

#define DIK_ESCAPE 0x01
#define DIK_1 0x02
#define DIK_2 0x03
Expand Down Expand Up @@ -176,5 +178,3 @@ void GetMouse(int* x, int* y);
* Alternate names for keys originally not used on US keyboards.
*/
#define DIK_CIRCUMFLEX DIK_PREVTRACK /* Japanese keyboard */

void _stdcall ForceGraphicsRefresh(DWORD);

5 comments on commit 4232be0

@NovaRain
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the FlushInputBuffer in 4.x makes 3.8 key press acting weird, so I didn't backport it. Not sure what it really does for 4.x.
For example, I set the 'V' key as the debug editor key. Press V key in game to call the editor and close the editor, now press any other key will also call the editor, and after closing the editor again the game will act like you keep tapping the same key (e.g. the Options menu keeps flashing)

@FakelsHub
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what it really does for 4.x.

Clears the buffer so that no keystrokes occur in the game.

@NovaRain
Copy link
Collaborator Author

@NovaRain NovaRain commented on 4232be0 Apr 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, but I don't know why it messed up the key press in 3.8.

EDIT: I think it's because 3.8 has different handling on key press than 4.x. Guess it's probably better to leave it. Would be great if you could look into this.

@FakelsHub
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to leave only the engine cleaning function, in fact only it is needed.

@NovaRain
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to leave only the engine cleaning function, in fact only it is needed.

You mean calling the kb_clean_? But it's exactly the cause for messing up key press.

Please sign in to comment.