Guest User

Alien Resurrection Super Secret Feature

a guest
Dec 20th, 2023
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.97 KB | None | 0 0
  1. unsigned int __fastcall LoadLevelStuff(unsigned int *a1, unsigned int a2)
  2. {
  3.   int bootSwappedDisc; // $s4
  4.   int charCounter; // $a2
  5.   unsigned __int8 *pIndex; // $v1
  6.   char *pEncodedChar; // $a1
  7.   int bootStringOffset; // $s0
  8.   unsigned __int8 *pFileContent; // $s1
  9.   int charCounter2; // $a2
  10.   unsigned __int8 *pFileContent_; // $a0
  11.   unsigned int result; // $v0
  12.   bool bootStringNotFound; // dc
  13.   int psexePathOffset; // $s0
  14.   int psexePathOffset_; // $a2
  15.   unsigned __int8 *currentChar; // $v1
  16.   unsigned int v17; // $s2
  17.   char filename[16]; // [sp+10h] [-38h] BYREF
  18.   char encodedFilename[16]; // [sp+20h] [-28h] BYREF
  19.   unsigned __int8 filenameShuffledIndexesList_[10]; // [sp+30h] [-18h] BYREF
  20.   u_char param; // [sp+40h] [-8h] BYREF
  21.   unsigned __int8 res[7]; // [sp+41h] [-7h] BYREF
  22.  
  23.   if ( !isSuperSecretSwapMethodEnabled )        // If the super secret cheat code is not entered
  24.     goto CONTINUE_GAME_AND_LOAD_LEVEL;          // Do not trigger the swap mode and continue the game (which will start the selected level)
  25.   qmemcpy(encodedFilename, "$2$.1Y:4#9", 10);   // Obfuscation of "SYSTEM.CNF" string, see below for decoding
  26.   *(_DWORD *)filenameShuffledIndexesList_ = *(_DWORD *)filenameShuffledIndexesList;
  27.   *(_DWORD *)&filenameShuffledIndexesList_[4] = *(_DWORD *)&filenameShuffledIndexesList[4];
  28.   filenameShuffledIndexesList_[8] = filenameShuffledIndexesList[8];
  29.   filenameShuffledIndexesList_[9] = filenameShuffledIndexesList[9];
  30.   bootSwappedDisc = 0;
  31.   if ( (unsigned __int8)gameLevel != 6 )        // If the 6th level is not selected (in the cheat menu)
  32.     goto CONTINUE_GAME_AND_LOAD_LEVEL;          // Do not trigger the swap mode and continue the game (which will start the selected level)
  33.   charCounter = 0;
  34.   // Decode the "SYSTEM.CNF" string
  35.   // 1. Set the characters in the right order using the list of indexes
  36.   // 2. XOR each character with 0x77 as key
  37.   do
  38.   {
  39.     pIndex = &filenameShuffledIndexesList_[charCounter];
  40.     pEncodedChar = &encodedFilename[charCounter++];
  41.     filename[*pIndex] = *pEncodedChar ^ 0x77;
  42.   }
  43.   while ( charCounter < 10 );
  44.   filename[10] = 0;                             // Add the NULL character to the filename string
  45.   TurnOffAudioCDAndPauseCD();
  46.   param = 0;
  47.   res[0] = 0;
  48.   CdControlB(CdlStop, &param, res);             // Stop the disc allowing to swap
  49.   VSync(3);
  50.   do
  51.   {
  52.     VSync(3);
  53.     if ( (unsigned __int16)(padBuffer & (PAD_SQUARE|PAD_TRIANGLE)) == (PAD_SQUARE|PAD_TRIANGLE) )// If Square and Triangle buttons are pressed
  54.       bootSwappedDisc = 1;                      // Set boot disc flag
  55.     HandlePadState(0);
  56.     HandlePadState(1);
  57.   }
  58.   while ( (padBuffer & PAD_L1) != 0 );          // Loop while L1 button is pressed
  59.   if ( !bootSwappedDisc )                       // If Square and Triangle buttons were not pressed
  60.     goto CONTINUE_GAME_AND_LOAD_LEVEL;          // Continue the game (which will start level 6 if the disc wasn't swapped)
  61.   enableResourcesFileReadingFromCD = 0;         // Indicates to disable reading the PACK.BIN file (in sub_1E964()) since the CD is swapped
  62.   bootStringOffset = -1;
  63.   ResetScreenBufferingAndOtherStuff();
  64.   DoSomeSystemAndLevelStuff();
  65.   pFileContent = (unsigned __int8 *)GetMemoryPtrForFileContent();
  66.   GetFileFromCD(filename, pFileContent);        // Get the content of SYSTEM.CNF, e.g.:
  67.                                                 // BOOT = cdrom:\SLUS_006.33;1
  68.                                                 // TCB = 4
  69.                                                 // EVENT = 10
  70.                                                 // STACK = 1FFF00
  71.   charCounter2 = 0;
  72.   pFileContent_ = pFileContent;
  73.   do
  74.   {
  75.     if ( *pFileContent_ == 'B' && pFileContent_[1] == 'O' && pFileContent_[2] == 'O' && pFileContent_[3] == 'T' )// Check for "BOOT" string in SYSTEM.CNF
  76.       bootStringOffset = charCounter2;
  77.     ++charCounter2;
  78.     ++pFileContent_;
  79.   }
  80.   while ( charCounter2 < 2048 );                // Loop to check the whole sector for the "BOOT" string
  81.   result = -1;
  82.   bootStringNotFound = bootStringOffset == -1;
  83.   psexePathOffset = bootStringOffset + 7;       // Set an offset to get the beginning of the executable path, e.g.:
  84.                                                 // cdrom:\SLUS_006.33;1
  85.                                                 // TCB = 4
  86.                                                 // EVENT = 10
  87.                                                 // STACK = 1FFF00
  88.                                                 //
  89.                                                 // Note: this offset may be an issue if there are more or none space characters between the equal sign
  90.   if ( bootStringNotFound )
  91.     return result;
  92.   psexePathOffset_ = psexePathOffset;
  93.   if ( psexePathOffset < 2047 )
  94.   {
  95.     currentChar = &pFileContent[psexePathOffset];
  96.     do
  97.     {
  98.       // Set a NULL byte to terminate the executable path string at the end of the line
  99.       // ('\r' or '\n', both are less than 0x20 (space) in ASCII), e.g.:
  100.       // cdrom:\SLUS_006.33;1
  101.       if ( *currentChar < 0x20u )
  102.         *currentChar = 0;
  103.       ++psexePathOffset_;
  104.       ++currentChar;
  105.     }
  106.     while ( psexePathOffset_ < 2047 );
  107.   }
  108.   // Reinit some stuff
  109.   TerminateSoundProcessingWrapper();
  110.   ResetGraph(0);
  111.   VSyncCallbacks();
  112.   PadStopCom();
  113.   96_remove();
  114.   96_init();
  115.   // Finally, launch the executable at the specified path, e.g.:
  116.   // cdrom:\SLUS_006.33;1
  117.   LoadExec((char *)&pFileContent[psexePathOffset], 0x801FFF00, 0);
  118. CONTINUE_GAME_AND_LOAD_LEVEL:
  119.   dword_A8800 = (int)"<default>";
  120.   dword_A8808 = (int)"<default>";
  121.   result = a2 < 29;
  122.   dword_A47F8 = 0;
  123.   dword_A47FC = 0;
  124.   dword_A8804 = -999;
  125.   dword_A880C = -999;
  126.   bootStringNotFound = a2 < 29;
  127.   v17 = a2 - 60;
  128.   if ( bootStringNotFound )
  129.     return result;
  130.   *a1 = v17;
  131.   a1[2] = 0;
  132.   a1[4] = 0;
  133.   a1[5] = 0;
  134.   dword_A87F8 = (int)a1;
  135.   dword_A87FC = (int)a1 + v17;
  136.   dword_A4808 = 1;
  137.   sub_3F23C((unsigned int)(a1 + 7));
  138.   result = v17 - 28;
  139.   dword_A4800 = v17 - 28;
  140.   return result;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment