OpenSWE1R / openswe1r

An Open-Source port of the 1999 Game "Star Wars Episode 1: Racer"
https://openswe1r.github.io/
GNU General Public License v2.0
312 stars 26 forks source link

Video settings are not saved #160

Open JayFoxRox opened 6 years ago

JayFoxRox commented 6 years ago

When quitting after changing video settings; then restarting the game, the previous video settings are not restored. Instead, they are returned to the initial state they were before making any changes.

This probably happens because of crashes while exiting the game:

Unknown function!

Stack at 0xC07FFE78; returning EAX: 0x0DDE1000
 463142 Emulation at 484A17 ('IA3dListener__2') from 484A17

openswe1r: /home/fox/Data/Projects/OpenSWE1R/main.c:3682: UnknownImport: Assertion `false' failed.

The video config might not have been written at this point.

firodj commented 6 years ago

IA3dListener__2 is IA3dListener::Release, and IA3d4__2 is IA3d4::Release. I think it may use the stub to avoid the assert(false).

diff --git a/com/a3d.c b/com/a3d.c
index 5cdf154..375581e 100644
--- a/com/a3d.c
+++ b/com/a3d.c
@@ -232,6 +232,13 @@ HACKY_COM_BEGIN(IA3d4, 0)
   esp += 3 * 4;
 HACKY_COM_END()

+// IA3d4 -> STDMETHOD_(ULONG,Release)       (THIS) PURE; //2
+HACKY_COM_BEGIN(IA3d4, 2)
+  hacky_printf("p 0x%" PRIX32 "\n", stack[1]);
+  eax = 0; // FIXME: No idea what this expects to return..
+  esp += 1 * 4;
+HACKY_COM_END()
+
 // IA3d4 -> STDMETHOD(GetHardwareCaps)                         (THIS_ LPA3DCAPS_HARDWARE) PURE; // 11
 HACKY_COM_BEGIN(IA3d4, 11)
   hacky_printf("GetHardwareCaps\n");
@@ -666,6 +673,13 @@ HACKY_COM_END()

+// IA3dListener -> STDMETHOD_(ULONG,Release)       (THIS) PURE; //2
+HACKY_COM_BEGIN(IA3dListener, 2)
+  hacky_printf("p 0x%" PRIX32 "\n", stack[1]);
+  eax = 0; // FIXME: No idea what this expects to return..
+  esp += 1 * 4;
+HACKY_COM_END()
+
 // IA3dListener -> STDMETHOD(SetPosition3f)            (THIS_ A3DVAL, A3DVAL, A3DVAL) PURE; // 3
 HACKY_COM_BEGIN(IA3dListener, 3)
   hacky_printf("SetPosition3f\n");
JayFoxRox commented 6 years ago

If you want to submit changes, please send a PR. For something minor like this I'll probably just hit merge. Review of existing PRs by other people is also welcome.

Note that there's also a WIP branch which includes this fix: https://github.com/JayFoxRox/openswe1r/pull/16 However, I don't have time or motivation for coding, reviewing or testing larger changes for OpenSWE1R right now.