Author Topic: solitary vaules in QfGIV changeStage switch statement  (Read 3031 times)

0 Members and 2 Guests are viewing this topic.

Offline doomlazer

solitary vaules in QfGIV changeStage switch statement
« on: January 07, 2026, 06:27:37 PM »
What's the purpose of the solitary vaules such as this from QfGIV rm340:

Code: [Select]
(method (changeState newState)
(switch (= state newState)
(0
0 ; THE VALUE IN QUESTION
(theGame handsOff:)
(if (and (== (barrel x?) 116) (not (Btst 254)))
(self changeState: 6)
else
(= cycles 1)
)
)
...

I've looked at 'setScript' and some other possibilities and maybe it's setting the register value or something, but found nothing conclusive. Honestly, it just doesn't make sense to me.

They appear in both EO's and Sluice's decompile repos, so I don't think it's a mistake. Anyone know?



Offline lskovlun

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #1 on: January 07, 2026, 09:18:48 PM »
I have seen these in Longbow, which was apparently written by some interns. The compiler was lenient enough to allow it, and the final code worked. These interns were named (there are names in the credits you don't see anywhere else). So it's possibly an intern.

Offline doomlazer

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #2 on: January 07, 2026, 09:31:56 PM »
Ok, that's a satisfying enough explanation for me. TY

Offline Kawa

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #3 on: January 08, 2026, 03:33:30 AM »
If I had to make a technical guess, having a bare expression like that might serve to set the PMachine's accumulator.

Now, we don't know what the original code looks like, whatever caused this code
Code: [Select]
0e69:35 00            ldi 0 //That's him, officer!
0e6b:38 0216          pushi 216 // $216 handsOff
0e6e:76               push0
0e6f:81 01            lag theGame
0e71:4a 0004          send 4
but I can imagine why our decompilers would include that mystery value.

Still, all it does is set the accumulator, which is then replaced with a pointer to the game. However it got in there, it does nothing.

Offline lskovlun

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #4 on: January 08, 2026, 02:36:26 PM »
And the Longbow code I was thinking of is this:
Code: [Select]
       (method (changeState newState &tmp temp0)
                (switch (= state newState)
                        (0               
                                (HandsOff)                             
                                (if (not (IsFlag 129))         
                                        (NormalEgo)
                                )                       
                                (switch register               
                                        (1       
                                                (cond
                                                        ((== local0 220)
                                                                (cond           
                                                                        (21     
                                                                                36
                                                                                37
                                                                                38
                                                                                50
                                                                                56
                                                                                67
                                                                                75
                                                                                98
                                                                                99
                                                                                103
                                                                                115
                                                                                119
                                                                                135
                                                                                167
                                                                                (if
                                                                                        (and
                                                                                                (> (gEgo x:) 35)
                                                                                                (< (gEgo x:) 150)
                                                                                        )
                                                                                        (= global104 155)
                                                                                )
                                                                        )
                                                                        (
                                                                                (and
                                                                                        (> (gEgo x:) 170)
                                                                                        (< (gEgo x:) 285)
                                                                                )
                                                                                (= global104 165)
                                                                        )
                                                                )
                                                        )
This should most likely have been (if (OneOf gForestRoom blah) blah) because there are numerous of those in the script. Typo, cut/paste error, or intern.

Offline Kawa

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #5 on: January 08, 2026, 02:47:45 PM »
How the hell is that supposed to work?! I wouldn't know what that's supposed to do if you hadn't brought up the OneOf thing. There's no way that code works the way it supposedly should.

Offline lskovlun

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #6 on: January 08, 2026, 07:15:28 PM »
One more, from the same script:
Code: [Select]
                (LoadMany
                        rsVIEW 
                        805
                        792
                        764     
                        763
                        230
                        231     
                        232
                        233
                        234
                        235
                        236
                        237
                        238
                        (if (== gDay 2)
                                214
                                218
                                16
                                4         
                                5
                                7
                                585
                        )
                        (switch gDisguiseNum
                                (0 ; outlaw
                                        0
                                        1
                                        2
                                )
                                (1 ; beggar
                                        36
                                        37
                                        38
                                )
                                (2 ; jewler (no rouge)
                                        29
                                        30
                                        31
                                )
                               (3 ; jewler (rouge)
                                        29
                                        30
                                        31
                                )
                                (4 ; yeoman
                                        33
                                        34
                                        35
                                )
                                (5 ; abbey monk
                                        23
                                        24
                                        27
                                )
                                (6 ; fens monk
                                        16
                                        17
                                        18
                                )
                        )
                )
Someone who knows the PMachine knows that that won't work.

Offline Kawa

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #7 on: January 09, 2026, 05:47:53 AM »
Load all of these, and in this particular case also these? Forget the PMachine, that's a script-level mistake.

Offline troflip

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #8 on: January 09, 2026, 12:11:59 PM »
I'm more curious what the original source code looked like that ended up compiling to that. Do any of the games that have had the original code released (there are a few I think, like maybe one of the LSLs?) have logic like that?
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Kawa

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #9 on: January 09, 2026, 12:40:02 PM »
All I have is Larry, and I'm pretty sure they don't.

The first instance with the same intent as the Longbow example would be LSL1 room 320, where the dancers or comedian and drummer are loaded along with the rest. But those are separate LoadMany calls with some distance between them. Same deal in rooms 350, 370, and 390. Then in LSL5 I see similar constructs all over.

If I were to ascribe to the "silly interns" theory, I'd say they misunderstood how sub-expressions (putting an if or switch in the middle of the argument list for OneOf or LoadMany) works. Clearly, Brian K. Hughes, Juan Carlos Escobar, and John Hartin knew what they were doing (except for BKH messing up the Hollywood sign feature in room 190 lol)

Offline Collector

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #10 on: January 09, 2026, 03:56:03 PM »
Omer hasn't been around, lately. I wonder if he has any of the original sources in question.
KQII Remake Pic

Offline Kawa

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #11 on: January 09, 2026, 04:33:57 PM »
Just for fun, I replicated the basic premise in isolation:

Setup
Code: [Select]
(procedure (Test)
  (TestHelper
    1 2 3
    (if (== gTest 2)
      4 5 6
    )
    7 8 9
  )
)
Code: [Select]
(procedure Test
  pushi 7 // argc
  push1 // push the first three values to the stack
  push2
  pushi 3

  lsg gTest // push gTest
  ldi 2 // load 2 to acc
  eq?
  bnt nope
  ldi 4 // load to acc, not push
  ldi 5
  ldi 6

nope:
  push // push acc to stack

  pushi 7 // push the rest
  pushi 8
  pushi 9
  call TestHelper 14
)

Result from TestHelper
When the test fails:
Code: [Select]
0 = 1
1 = 2
2 = 3
3 = 0 <-- ?
4 = 7
5 = 8
6 = 9
When the test succeeds:
Code: [Select]
0 = 1
1 = 2
2 = 3
3 = 6 <-- !
4 = 7
5 = 8
6 = 9

Takeaways:
1. We try to supply either six or nine items, but only ever push seven values. argc being 7 and the call looking back 14 bytes says as much.
2. If the test fails, we still push whatever is in acc! Values 4 and 5 are wasted.
3. This is not only Technically Valid code, but also even more hilariously broken at runtime than I expected!

Offline troflip

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #12 on: January 09, 2026, 07:11:17 PM »
If this is SCI Companion, the success case seems correct anyway. The value of a section of code is the last thing in that code, so 6 in this case. There should be 7 params, because the if statement resolves to a single param.

Not sure if it's "defined" what the value of a condition expression will be if there is no else, but it seems like it will always be the result of the last acc value that was branched on, 0.
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Kawa

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #13 on: January 10, 2026, 04:33:56 AM »
I just tried it myself. A switch instead of an if gave the expected, similar results, just with the PMachine equivalent of a switch.
Code: [Select]
(ListAll
  1 2 3
  (switch gTest
    (0
      ; Left blank for fun
    )
    (1
      4 5 6
    )
  )
  7 8 9
)
Always seven values, and the fourth is either 6 or leftovers.

Offline doomlazer

Re: solitary vaules in QfGIV changeStage switch statement
« Reply #14 on: January 10, 2026, 12:53:11 PM »
Great. This will be a pattern I use in my own fan mods from now on. :)


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.128 seconds with 22 queries.