Advertisement
dragonbane

[Wreckage] Main Code Snippets

Feb 23rd, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.38 KB | None | 0 0
  1. Newspaper articles etc: https://crytek.4thdimension.info/forum/mod-database/14846-mod-wreckage.html
  2.  
  3. //Wreckage MOD: Suit Deactivation Control
  4. void CGame::CmdDeactivateSuit(IConsoleCmdArgs* pArgs)
  5. {
  6.     CryLogAlways("Wreckage Log: NanoSuit disabled!");
  7.  
  8.     ICVar* suit = gEnv->pConsole->GetCVar("wreckage_isSuitActivated");
  9.     if(suit)
  10.         suit->ForceSet("0");
  11.  
  12.  
  13.     //Change Player Arms to Lambert
  14.     IScriptSystem* m_pScriptSystem = g_pGame->GetIGameFramework()->GetISystem()->GetIScriptSystem();
  15.  
  16.     CActor* pActor = static_cast<CActor*> (g_pGame->GetIGameFramework()->GetClientActor());
  17.     if (pActor)
  18.     {
  19.         SmartScriptTable m_script = pActor->GetEntity()->GetScriptTable();
  20.         if (m_pScriptSystem)
  21.         {
  22.             m_pScriptSystem->BeginCall(m_script, "SetModel"); m_pScriptSystem->PushFuncParam(m_script);
  23.             m_pScriptSystem->PushFuncParam("objects/characters/human/us/nanosuit/nanosuit_us_multiplayer.cdf");
  24.             m_pScriptSystem->PushFuncParam("objects/weapons/arms_lambert/arms_nanosuit_us.chr");
  25.             m_pScriptSystem->PushFuncParam("objects/characters/human/asian/nk_soldier/nk_soldier_frozen_scatter.cgf");
  26.             m_pScriptSystem->PushFuncParam("Characters/Lambert_fp3p.cdf");
  27.             m_pScriptSystem->EndCall();
  28.  
  29.             pActor->Physicalize();
  30.         }
  31.        
  32.         //Adjust STANCE_STAND speed values
  33.         CPlayer* pPlayer = static_cast<CPlayer*> (pActor);
  34.         if (pPlayer)
  35.         {
  36.             const SStanceInfo *sInfo = pPlayer->GetStanceInfo(STANCE_STAND);
  37.  
  38.             SStanceInfo standInfo;
  39.  
  40.             //Copy old values
  41.             standInfo.heightCollider = sInfo->heightCollider;
  42.             standInfo.heightPivot = sInfo->heightPivot;
  43.  
  44.             standInfo.leanLeftViewOffset = sInfo->leanLeftViewOffset;
  45.             standInfo.leanLeftWeaponOffset = sInfo->leanLeftWeaponOffset;
  46.             standInfo.leanRightViewOffset = sInfo->leanRightViewOffset;
  47.             standInfo.leanRightWeaponOffset = sInfo->leanRightWeaponOffset;
  48.  
  49.             standInfo.modelOffset = sInfo->modelOffset;
  50.             strcpy(standInfo.name, sInfo->name);
  51.             standInfo.size = sInfo->size;
  52.  
  53.             standInfo.useCapsule = sInfo->useCapsule;
  54.             standInfo.viewOffset = sInfo->viewOffset;
  55.             standInfo.weaponOffset = sInfo->weaponOffset;
  56.  
  57.             //Set new values
  58.             standInfo.normalSpeed = 4;
  59.             standInfo.maxSpeed = 9;
  60.  
  61.             pPlayer->SetupStance(STANCE_STAND, &standInfo);
  62.         }
  63.     }
  64.  
  65.  
  66.     //Set Suit Mode to Armor
  67.     CPlayer *pPlayer = static_cast<CPlayer *>(g_pGame->GetIGameFramework()->GetClientActor());
  68.     if(pPlayer)
  69.     {
  70.         CNanoSuit *m_pNanoSuit = pPlayer->GetNanoSuit();
  71.         m_pNanoSuit->SetMode(NANOMODE_DEFENSE, true);
  72.     }
  73.  
  74.     //Editor specific
  75.     if (gEnv->pSystem->IsEditor())
  76.     {
  77.         //Select Fists as Default Weapon
  78.         if (pActor && pPlayer)
  79.             pPlayer->SelectFists(true);
  80.     }
  81.     //Custom Health Values
  82.     g_pGame->GetMenu()->SetDifficulty(0);
  83.  
  84.     /*
  85.     ICVar* HealthValue = gEnv->pConsole->GetCVar("g_playerHealthValue");
  86.     if(HealthValue)
  87.         HealthValue->ForceSet("200");
  88.  
  89.     ICVar* SuitHealthRegenTime = gEnv->pConsole->GetCVar("g_playerSuitHealthRegenTime");
  90.     if(SuitHealthRegenTime)
  91.         SuitHealthRegenTime->ForceSet("10");
  92.  
  93.     ICVar* SuitHealthRegenTimeMoving = gEnv->pConsole->GetCVar("g_playerSuitHealthRegenTimeMoving");
  94.     if(SuitHealthRegenTimeMoving)
  95.         SuitHealthRegenTimeMoving->ForceSet("13.5");
  96.  
  97.     ICVar* SuitArmorModeHealthRegenTime = gEnv->pConsole->GetCVar("g_playerSuitArmorModeHealthRegenTime");
  98.     if(SuitArmorModeHealthRegenTime)
  99.         SuitArmorModeHealthRegenTime->ForceSet("5");
  100.  
  101.     ICVar* SuitArmorModeHealthRegenTimeMoving = gEnv->pConsole->GetCVar("g_playerSuitArmorModeHealthRegenTimeMoving");
  102.     if(SuitArmorModeHealthRegenTimeMoving)
  103.         SuitArmorModeHealthRegenTimeMoving->ForceSet("7.5");
  104.  
  105.     ICVar* SuitHealthRegenDelay = gEnv->pConsole->GetCVar("g_playerSuitHealthRegenDelay");
  106.     if(SuitHealthRegenDelay)
  107.         SuitHealthRegenDelay->ForceSet("1.25");
  108.     */
  109.  
  110.     //Change HUD to Lambert
  111.     g_pGame->GetHUD()->SetLambertHUDEnabled(true);
  112. }
  113.  
  114. //Wreckage MOD: Select Fists void
  115. void CPlayer::SelectFists(bool active)
  116. {
  117.     if(active)
  118.     {  
  119.         //Select Fists as Default Weapon
  120.         CFists *pFists = static_cast<CFists*>(GetItemByClass(CItem::sFistsClass));
  121.  
  122.         if(!pFists)
  123.             return;
  124.  
  125.         COffHand *pOffHand = static_cast<COffHand*>(GetItemByClass(CItem::sOffHandClass));
  126.         //Drop object or NPC
  127.         if (pOffHand)
  128.         {
  129.             if(pOffHand->IsHoldingEntity())
  130.             {
  131.                 //Force drop
  132.                 if(pOffHand->GetOffHandState()==eOHS_MELEE)
  133.                 {
  134.                     pOffHand->GetScheduler()->Reset();
  135.                     pOffHand->SetOffHandState(eOHS_HOLDING_OBJECT);
  136.                 }
  137.                 pOffHand->OnAction(GetEntityId(),"use",eAAM_OnPress,0);
  138.                 pOffHand->OnAction(GetEntityId(),"use",eAAM_OnRelease,0);
  139.             }
  140.             else if(pOffHand->GetOffHandState()==eOHS_HOLDING_GRENADE)
  141.                 pOffHand->FinishAction(eOHA_RESET);
  142.         }
  143.    
  144.         //Select Fists
  145.         CItem *currentItem = static_cast<CItem*>(GetCurrentItem());
  146.         if(!currentItem)
  147.         {
  148.             //Player has no item selected... just select fists
  149.             pFists->EnableAnimations(false);
  150.             SelectItem(pFists->GetEntityId(),false);
  151.             pFists->EnableAnimations(true);
  152.         }
  153.         else if(pFists->GetEntityId()==currentItem->GetEntityId())
  154.         {
  155.             //Fists already selected
  156.             pFists->Select(false);
  157.             SelectItem(pFists->GetEntityId(),false);
  158.             GetInventory()->SetLastItem(pFists->GetEntityId());
  159.             pFists->Select(true);
  160.         }
  161.         else
  162.         {
  163.             //Deselect current item and select fists
  164.             currentItem->Select(false);
  165.             pFists->EnableAnimations(false);
  166.             SelectItem(pFists->GetEntityId(),false);
  167.             pFists->EnableAnimations(true);
  168.         }
  169.     }
  170. }
  171.  
  172. //Chapter Load Snippet and take screenshot for map transition
  173. void CFlashMenuObject::OnLoadingStart(ILevelInfo *pLevel)
  174. {
  175.     //Wreckage MOD: Here is the Loading Start Function: Start Timer for the Subtitles in the Loading Screen
  176.     //                and load the right pak files
  177.  
  178.     string levelname = pLevel->GetName();
  179.  
  180.     //Wreckage MOD: Crash Fix
  181.     CryLog("Wreckage Log: Reset NanoSuit Status!");
  182.     ICVar* suit = gEnv->pConsole->GetCVar("wreckage_isSuitActivated");
  183.     if(suit)
  184.         suit->ForceSet("1");
  185.  
  186.     //Wreckage MOD: When Chapter is loaded, prevent loading music from playing
  187.     ICVar* chapter = gEnv->pConsole->GetCVar("wreckage_chapterName");
  188.  
  189.     if (chapter)
  190.     {
  191.         const char* chapterName = chapter->GetString();
  192.         int result = stricmp(chapterName, "None");
  193.  
  194.         if (result != 0)
  195.         {
  196.             CryLogAlways("Wreckage: Chapter is loading - NewGame = false; Loading = true");
  197.        
  198.             m_RainysTimer_IsNewGame = false;
  199.             m_Rainys_IsLoading = true;
  200.         }
  201.     }
  202.  
  203.     IGameTokenSystem *pGameTokenSystem = gEnv->pGame->GetIGameFramework()->GetIGameTokenSystem();
  204.  
  205.     string PreviousLevel;
  206.     pGameTokenSystem->GetTokenValueAs("Game.General.Previous_Level", PreviousLevel);
  207.     CryLogAlways("Wreckage: PreviousLevel: %s", PreviousLevel);
  208.  
  209.  
  210.     //Wreckage MOD: Play Custom Intro Theme and Set Fade Out Timer if User
  211.     //                starts Wreckage from scratch or Part 2
  212.     if (levelname == "Wreckage" && m_Rainys_IsLoading == false)
  213.     {
  214.         if (m_pMusicSystem && !g_pGame->IsReloading())
  215.         {
  216.             m_fMusicFirstTime = -1;
  217.             m_pMusicSystem->EndTheme(EThemeFade_StopAtOnce, 0, true);
  218.  
  219.             m_pMusicSystem->SetTheme("Wreckage_loading_sounds", true, false);
  220.             m_pMusicSystem->SetMood("intro_map1", true, false);
  221.  
  222.             m_fRemindOfHarbour = gEnv->pTimer->GetAsyncTime().GetSeconds();
  223.  
  224.             //Wreckage MOD: Activate the Subtitle System for Loading Screen
  225.  
  226.             m_RainysTimer_IsNewGame = true;
  227.  
  228.         }
  229.     }
  230.     if (levelname == "Wreckage_Part2" && m_Rainys_IsLoading == false || levelname == "Wreckage_Part2" && PreviousLevel == "Wreckage")
  231.     {
  232.         if (m_pMusicSystem && !g_pGame->IsReloading())
  233.         {
  234.             m_fMusicFirstTime = -1;
  235.             m_pMusicSystem->EndTheme(EThemeFade_StopAtOnce, 0, true);
  236.  
  237.             m_pMusicSystem->SetTheme("Wreckage_loading_sounds", true, false);
  238.             m_pMusicSystem->SetMood("intro_map2", true, false);
  239.            
  240.             m_fRemindOfHarbour = gEnv->pTimer->GetAsyncTime().GetSeconds();
  241.  
  242.             //Wreckage MOD: Activate the Subtitle System for Loading Screen
  243.  
  244.             m_RainysTimer_IsNewGame = true;
  245.  
  246.         }
  247.     }
  248.  
  249.  
  250.     //Wreckage MOD: Log a few things...
  251.     if (m_RainysTimer_IsNewGame)
  252.         CryLogAlways("Wreckage: m_WreckageTimer_IsNewGame: True");
  253.     else
  254.         CryLogAlways("Wreckage: m_WreckageTimer_IsNewGame: False");
  255.  
  256.     if (m_Rainys_IsLoading)
  257.         CryLogAlways("Wreckage: m_Wreckage_IsLoading: True");
  258.     else
  259.         CryLogAlways("Wreckage: m_Wreckage_IsLoading: False");
  260.  
  261.  
  262.     if (PreviousLevel == "Wreckage_Part2" && levelname == "Wreckage_Part3")
  263.     {
  264.         CryLog("Wreckage: Starte Part 3!");
  265.  
  266.         gEnv->pRenderer->ScreenShot("Mods/Wreckage/Game/Levels/Wreckage_Part3/wreckage_03_loading_new.jpg", gEnv->pRenderer->GetWidth());
  267.         OnLoadingStart_Part3(pLevel);
  268.         CryLog("Wreckage: Lade Part 3 eingeleitet!");
  269.         return;
  270.     }
  271.  
  272.     m_bInLoading = true;
  273. }
  274.  
  275. //Map transition function
  276. void CFlashMenuObject::OnLoadingStart_Part3(ILevelInfo *pLevel)
  277. {
  278.     //Wreckage MOD: Here is the Loading Start_Part3 Function
  279.  
  280.     CryLog("Wreckage: Lade Part 3 Funktion läuft!");
  281.  
  282.     m_bInLoading = true;
  283.  
  284.     SAFE_HUD_FUNC(OnLoadingStart(pLevel));
  285.  
  286.     StopVideo();    //stop background video
  287.     StopTutorialVideo();
  288.  
  289.     if(m_stateEntryMovies!=eEMS_Done)
  290.     {
  291.         if (m_stateEntryMovies < eEMS_Done)
  292.             SAFE_HARDWARE_MOUSE_FUNC(IncrementCounter());
  293.         m_stateEntryMovies=eEMS_Done;
  294.     }
  295.    
  296.  
  297.     if(gEnv->pSystem->IsEditor() || gEnv->pSystem->IsDedicated()) return;
  298.  
  299.     if(m_bLanQuery)
  300.     {
  301.     gEnv->pGame->GetIGameFramework()->EndCurrentQuery();
  302.        m_bLanQuery = false;
  303.     }
  304.     if(pLevel)
  305.     {
  306.         m_iMaxProgress = pLevel->GetDefaultGameType()->cgfCount;
  307.     }
  308.     else
  309.     {
  310.         m_iMaxProgress = 100;
  311.     }
  312.    
  313.     if(!m_apFlashMenuScreens[MENUSCREEN_FRONTENDLOADING_PART2]->IsLoaded())
  314.     {
  315.         CryLog("Wreckage: Lade Wechsel Screen!");
  316.         m_apFlashMenuScreens[MENUSCREEN_FRONTENDLOADING_PART2]->Load("Libs/UI/Menus_Loading_Wreckage_Part2.gfx");
  317.         m_apFlashMenuScreens[MENUSCREEN_FRONTENDLOADING_PART2]->GetFlashPlayer()->SetFSCommandHandler(this);
  318.         m_apFlashMenuScreens[MENUSCREEN_FRONTENDLOADING_PART2]->Invoke("SetProgress", 0.0f);
  319.  
  320.         UpdateMenuColor();
  321.     }
  322.    
  323.     m_pCurrentFlashMenuScreen = m_apFlashMenuScreens[MENUSCREEN_FRONTENDLOADING_PART2];
  324.  
  325.     //Prepare Loading Texture
  326.     IRenderer* pRenderer = gEnv->pRenderer;
  327.     assert( pRenderer != NULL );
  328.  
  329.     if (pRenderer)
  330.     {
  331.         IUIDraw *m_pUiDraw = gEnv->pGame->GetIGameFramework()->GetIUIDraw();
  332.         assert( m_pUiDraw != NULL );
  333.  
  334.         if (m_pUiDraw)
  335.         {
  336.             char fileName[255];
  337.  
  338.             sprintf(fileName,"Game/Levels/Wreckage_Part3/wreckage_03_loading_new.jpg");
  339.        
  340.             m_LoadingTexture = m_pUiDraw->CreateTexture(fileName);
  341.  
  342.             pRenderer->SetState( GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA | GS_NODEPTHTEST );
  343.  
  344.             m_bIsQuickLevelSwitchLoading = true;
  345.         }
  346.     }
  347.  
  348.  
  349.     m_bUpdate = true;
  350.     m_nBlackGraceFrames = 0;
  351.  
  352.     if(!gEnv->pSystem->IsSerializingFile())
  353.     {
  354.         m_sLastSaveGame = "";
  355.         SetDifficulty(); //set difficulty setting at game/level start
  356.     }
  357.  
  358.     //remove the hud to be re-created
  359.     if(g_pGame)
  360.         g_pGame->DestroyHUD();
  361.  
  362. }
  363.  
  364. //Wreckage MOD: Draw Loading Texture if needed
  365. void CFlashMenuObject::OnPostUpdate(float fDeltaTime)
  366. {
  367.     if (m_bIsQuickLevelSwitchLoading && m_LoadingTexture != 0)
  368.     {
  369.         IRenderer* pRenderer = gEnv->pRenderer;
  370.         assert( pRenderer != NULL );
  371.         if ( pRenderer == NULL )
  372.         {
  373.             return;
  374.         }
  375.  
  376.         pRenderer->Draw2dImage(0.0f,-0.5f, 800.0f,600.0f, m_LoadingTexture, 0.0f,1.0f,1.0f,0.0f, 0.0f);
  377.  
  378.         if (m_bInLoading == false && m_nBlackGraceFrames == 0 && curFrameID >= m_nBlackGraceFrames)
  379.         {
  380.             m_bIsQuickLevelSwitchLoading = false;
  381.         }
  382.  
  383.     }  
  384. }
  385.  
  386. //Load correct player post load and set chapter gametoken (show flowgraph check)
  387. void CFlashMenuObject::OnLoadingComplete(ILevel *pLevel)
  388. {
  389.     //Wreckage MOD: Here is The OnLoading Complete Function - Less ToDo here since we moved to 'OnPostUpdate'
  390.     SAFE_HUD_FUNC(OnLoadingComplete(pLevel));
  391.  
  392.     if(gEnv->pSystem->IsEditor() || gEnv->pSystem->IsDedicated())
  393.     {
  394.         return;
  395.     }
  396.  
  397.     //Wreckage MOD: Load the correct player model and HUD based of Levelname
  398.     //Load Nomad or Lambert
  399.     string levelname = pLevel->GetLevelInfo()->GetName();
  400.     if (levelname == "Wreckage") //Nomad
  401.         gEnv->pConsole->ExecuteString("wreckage_suit_activate");
  402.  
  403.     else if (levelname == "Wreckage_Part2" || levelname == "Wreckage_Part3") //Lambert
  404.         gEnv->pConsole->ExecuteString("wreckage_suit_deactivate");
  405.  
  406.     //Wreckage MOD: Set GameToken for Map SpawnPoint if necessary
  407.     ICVar* chapter = gEnv->pConsole->GetCVar("wreckage_chapterName");
  408.  
  409.     if (chapter)
  410.     {
  411.         const char* chapterName = chapter->GetString();
  412.         int result = stricmp(chapterName, "None");
  413.  
  414.         if (result != 0)
  415.         {
  416.             string chapterNameString = chapterName;
  417.             CryLog("Wreckage: Chapter Name: %s", chapterNameString);
  418.  
  419.             IGameTokenSystem *pGameTokenSystem = gEnv->pGame->GetIGameFramework()->GetIGameTokenSystem();
  420.  
  421.             if (pGameTokenSystem)
  422.             {
  423.                 pGameTokenSystem->SetOrCreateToken("Game.General.Chapter_Name", TFlowInputData(chapterNameString, true));
  424.  
  425.                 string Value;
  426.                 pGameTokenSystem->GetTokenValueAs("Game.General.Chapter_Name", Value);
  427.        
  428.                 CryLog("Wreckage: Token Value: %s", Value);
  429.             }
  430.  
  431.             //Wreckage MOD: Reset CVar for Chapter Name
  432.             chapter->ForceSet("None");
  433.  
  434.         }
  435.     }
  436. }
  437.  
  438. //Wreckage MOD: Overloaded Memory Callback Function (for Listener) (Critical Emergency Save)
  439. void CFlashMenuObject::HandleFSCommand(const char *szCommand,const char *szArgs)
  440. {
  441.     else if(!strcmp(szCommand, "OverloadedMemory"))
  442.     {
  443.         if(szArgs != 0)
  444.         {
  445.             ILocalizationManager* pLocMgr = gEnv->pSystem->GetLocalizationManager();
  446.             const char* pProfileName;
  447.             string pSaveGameFileName;
  448.  
  449.             string pCVarString = gEnv->pConsole->GetCVar("g_language")->GetString();
  450.  
  451.             bool IsEnglish = false;
  452.  
  453.             if(pCVarString == "English") //Check language: German or English
  454.                 IsEnglish = true;
  455.  
  456.             if(IsEnglish)
  457.                 pSaveGameFileName = "Wreckage - Auto Save.CRYSISJMSF";  //English File Name
  458.             else
  459.                 pSaveGameFileName = "Wreckage - Auto Speicherung.CRYSISJMSF"; //German File Name
  460.  
  461.  
  462.             IPlayerProfile *pProfile = m_pPlayerProfileManager->GetCurrentProfile(m_pPlayerProfileManager->GetCurrentUser());
  463.        
  464.             pProfileName = pProfile->GetName(); //Get Current User Profile Name
  465.  
  466.             //pSaveGame = g_pGame->CreateSaveGameName();
  467.             //ESaveGameReason::eSGR_FlowGraph
  468.  
  469.             CryLog("Wreckage: Save Current Game Status For '%s' As '%s'...", pProfileName, pSaveGameFileName);
  470.            
  471.             //Save Game
  472.             const bool bSuccess = g_pGame->GetIGameFramework()->SaveGame(pSaveGameFileName, false, true, eSGR_LevelStart, true);
  473.            
  474.             if(bSuccess)
  475.             {
  476.                 CryLog("Wreckage: Game Saving Succeed...");
  477.  
  478.                 CryLog("Wreckage: Restart Wreckage...");
  479.                 gEnv->pConsole->ExecuteString("g_loadMod Wreckage"); //Restart Wreckage
  480.             }
  481.             else
  482.             {
  483.                 CryLog("Wreckage: Game Saving Failed!");
  484.                 ShowMenuMessage("@ui_SYSFatalError");
  485.             }
  486.            
  487.         }
  488.     }
  489. }
  490.  
  491. //Memory Overloaded Snippet
  492. void CFlashMenuObject::OnPostUpdate(float fDeltaTime)
  493. {
  494.     if(gEnv->pSystem->IsEditor() || gEnv->pSystem->IsDedicated()) return;
  495.  
  496.     //Wreckage MOD: These Function controls our Timer, the Subtitles for the Loading Screen and our new Memory Overload Protection System
  497.     fDeltaTime = gEnv->pTimer->GetFrameTime(ITimer::ETIMER_UI);
  498.  
  499.     //Wreckage MOD: Check only memory every 5 seconds
  500.     if (m_MemoryListener_LastUpdate == 0.0f)
  501.         m_MemoryListener_LastUpdate = gEnv->pTimer->GetAsyncCurTime();
  502.  
  503.     if(m_MemoryListener_LastUpdate + 5.0f <= gEnv->pTimer->GetAsyncCurTime())
  504.     {
  505.         m_MemoryListener_LastUpdate = gEnv->pTimer->GetAsyncCurTime();
  506.  
  507.         //Wreckage MOD: Check only memory if no cutscenes are playing (because in a cutscene you can't save!)
  508.         ISequenceIt* pSeqIt = gEnv->pMovieSystem->GetSequences(true, true);
  509.    
  510.         IAnimSequence *pSeq=pSeqIt->first();
  511.  
  512.         if(m_bMemoryListener_Enabled && !gEnv->pMovieSystem->IsPlaying(pSeq))
  513.         {
  514.             CryLog("Wreckage: Used Memory: %i", gEnv->pSystem->GetUsedMemory() /1000000);
  515.             if(gEnv->pSystem->GetUsedMemory() /1000000 >= 1035 && !m_bIs64Bit || gEnv->pSystem->GetUsedMemory() /1000000 >= 2070 && m_bIs64Bit) //Editor: 1400MB ~ GetUsedMemory: 1035MB
  516.             {
  517.                 m_bMemoryListener_Enabled = false;
  518.                 CryLog("Wreckage: Warning - Memory Overload!");
  519.            
  520.                 ShowInGameMenu(true);
  521.                 if(!m_bIs64Bit)
  522.                 {
  523.                     ILocalizationManager* pLocMgr = gEnv->pSystem->GetLocalizationManager();
  524.                     wstring localizedString, finalString;
  525.                     pLocMgr->LocalizeLabel("@ui_overloaded_memory_32", localizedString);
  526.                
  527.                     char status[64];
  528.                     sprintf(status, "%d", gEnv->pSystem->GetUsedMemory() /1000000);
  529.                     wstring outString;
  530.                     outString.resize(strlen(status));
  531.                     wchar_t* dst = outString.begin();
  532.                     const char* src = status;
  533.                     while (const wchar_t c=(wchar_t)(*src++))
  534.                     {
  535.                         *dst++ = c;
  536.                     }
  537.  
  538.                     pLocMgr->FormatStringMessage(finalString, localizedString, outString, 0, 0, 0);
  539.        
  540.                     m_pCurrentFlashMenuScreen->Invoke("showErrorMessageYesNo","overloaded_memory"); //Wreckage MOD: Display our new Error Message in 32 Bit
  541.            
  542.                     m_pCurrentFlashMenuScreen->Invoke("setErrorTextNonLocalized", SFlashVarValue(finalString)); //Wreckage MOD: Set Text
  543.                 }
  544.                 else
  545.                 {
  546.                     ILocalizationManager* pLocMgr = gEnv->pSystem->GetLocalizationManager();
  547.                     wstring localizedString, finalString;
  548.                     pLocMgr->LocalizeLabel("@ui_overloaded_memory_64", localizedString);
  549.                
  550.                     char status[64];
  551.                     sprintf(status, "%d", gEnv->pSystem->GetUsedMemory() /1000000);
  552.                     wstring outString;
  553.                     outString.resize(strlen(status));
  554.                     wchar_t* dst = outString.begin();
  555.                     const char* src = status;
  556.                     while (const wchar_t c=(wchar_t)(*src++))
  557.                     {
  558.                         *dst++ = c;
  559.                     }
  560.  
  561.                     pLocMgr->FormatStringMessage(finalString, localizedString, outString, 0, 0, 0);
  562.        
  563.                     m_pCurrentFlashMenuScreen->Invoke("showErrorMessageYesNo","overloaded_memory"); //Wreckage MOD: Display our new Error Message in 64 Bit
  564.  
  565.                     m_pCurrentFlashMenuScreen->Invoke("setErrorTextNonLocalized", SFlashVarValue(finalString));
  566.                 }
  567.             }
  568.         }
  569.     }
  570.  
  571. //Wreckage MOD: 64 Bit Restart if available Callback Function (for Listener)
  572. void CFlashMenuObject::InitStartMenu()
  573. {
  574.     //Wreckage MOD: Check if 64 Bit is theoretically available, but not used
  575.     SPlatformInfo pi = gEnv->pi;
  576.     if (m_bIsFirstStart && !m_bIs64Bit && pi.win64Bit)
  577.     {
  578.         m_bIsFirstStart = false;
  579.         ILocalizationManager* pLocMgr = gEnv->pSystem->GetLocalizationManager();
  580.         wstring localizedString;
  581.  
  582.         if (gEnv->pCryPak->IsFileExist("../Bin64/Crysis.exe")) //64 Bit is even installed. Request user to use it
  583.         {
  584.             pLocMgr->LocalizeLabel("@ui_menu_wreckage_64bit_available", localizedString);
  585.  
  586.             m_pCurrentFlashMenuScreen->Invoke("setErrorTextNonLocalized", SFlashVarValue(localizedString));
  587.             m_pCurrentFlashMenuScreen->Invoke("showErrorMessageYesNo","restart_64bit");
  588.  
  589.         }
  590.         else //64 Bit is not installed. Advice user to install it
  591.         {
  592.             pLocMgr->LocalizeLabel("@ui_menu_wreckage_64bit_detected", localizedString);
  593.  
  594.             m_pCurrentFlashMenuScreen->Invoke("setErrorTextNonLocalized", SFlashVarValue(localizedString));
  595.             m_pCurrentFlashMenuScreen->Invoke("showErrorMessage","Box1");
  596.         }
  597.        
  598.     }
  599. }
  600.  
  601. //Wreckage MOD: 64 Bit Restart if available Callback Function (for Listener)
  602. void CFlashMenuObject::HandleFSCommand(const char *szCommand,const char *szArgs)
  603. {
  604.     if(!strcmp(szCommand, "Restart64Bit"))
  605.     {
  606.         if(szArgs != 0)
  607.         {
  608.             SPlatformInfo pi = gEnv->pi;
  609.             if (pi.win64Bit)
  610.             {
  611.                 if (gEnv->pCryPak->IsFileExist("../Bin64/Crysis.exe"))
  612.                 {
  613.                     //Prepare launch.bat
  614.                     FILE *pFile = gEnv->pCryPak->FOpen("../launch.bat","wb");
  615.                     if (pFile)
  616.                     {
  617.                         const string launchHeader("@echo Please wait...\n@echo off\n\n:start\n\ntasklist /FI \"IMAGENAME eq Crysis.exe\" 2>NUL | find /I /N \"Crysis.exe\">NUL\nif \"%ERRORLEVEL%\"==\"0\" GOTO start\n\n");
  618.                
  619.                         gEnv->pCryPak->FWrite((void*)launchHeader.c_str(), launchHeader.size(), 1, pFile);
  620.  
  621.                         string cmd = "start /WAIT";
  622.                         cmd.append(" Bin64\\Crysis.exe");
  623.            
  624.                         if(gEnv->pSystem->IsDevMode())
  625.                         {
  626.                             cmd.append(" -devmode");
  627.                         }
  628.                         SModInfo info;
  629.                         if(gEnv->pGame->GetIGameFramework()->GetModInfo(&info))
  630.                         {
  631.                             cmd.append(" -mod ");
  632.                             cmd.append(info.m_name);
  633.                         }
  634.                         cmd.append(" -DX9");
  635.  
  636.                         const string launchBody = cmd;
  637.                
  638.                         gEnv->pCryPak->FWrite((void*)launchBody.c_str(), launchBody.size(), 1, pFile);
  639.                
  640.                         gEnv->pCryPak->FClose(pFile);
  641.  
  642.                         if(gEnv->pGame->GetIGameFramework()->StartProcess("launch.bat"))
  643.                         {
  644.                             gEnv->pSystem->Quit();
  645.                         }
  646.                     }
  647.                 }
  648.             }
  649.         }
  650.     }
  651. }
  652.  
  653. //Wreckage MOD: New Chapter Selection Screen
  654. void CFlashMenuObject::UpdateChapterScreen()
  655. {
  656.     CFlashMenuScreen* pScreen = m_pCurrentFlashMenuScreen;
  657.     if(!pScreen)
  658.         return;
  659.  
  660.     //*************************************************************************
  661.  
  662.     pScreen->CheckedInvoke("resetSPChapters");
  663.  
  664.     // TODO: find a better place for this as it needs to be set only once -- CW
  665.     gEnv->pSystem->SetFlashLoadMovieHandler(this);
  666.  
  667.     if(!m_pPlayerProfileManager)
  668.         return;
  669.  
  670.     IPlayerProfile *pProfile = m_pPlayerProfileManager->GetCurrentProfile(m_pPlayerProfileManager->GetCurrentUser());
  671.     if(!pProfile)
  672.         return;
  673.  
  674.     ICryPak *pCryPak = gEnv->pCryPak;
  675.     ILocalizationManager* pLocMgr = gEnv->pSystem->GetLocalizationManager();
  676.  
  677.     //*************************************************************************
  678.  
  679.     const string szModDir = pCryPak->GetModDir();
  680.     int m_bUnlockedChapterCount;
  681.  
  682.     // Load Profile
  683.     bool bGotProfile = false;
  684.     string szInfoFile = "..\\";
  685.     szInfoFile += szModDir;
  686.     szInfoFile += "\\Game\\Libs\\UI\\Chapters\\Profile.xml";
  687.     if (XmlNodeRef root = gEnv->pSystem->LoadXmlFile(szInfoFile.c_str()))
  688.     {
  689.         if (strnicmp(root->getTag(), "ChapterSettings", 15) == 0)
  690.         {
  691.             // Get value
  692.             root->getAttr("Unlocked", m_bUnlockedChapterCount);
  693.  
  694.             if (m_bUnlockedChapterCount < 1)
  695.                 bGotProfile = false;
  696.             else
  697.                 bGotProfile = true;
  698.         }
  699.     }
  700.     if (false == bGotProfile)
  701.     {
  702.         CryLogAlways("[Error] Wreckage: Chapter System - Failed to load profile. Using default values.");
  703.         m_bUnlockedChapterCount = 1;
  704.        
  705.     }
  706.     else
  707.     {
  708.         CryLogAlways("Wreckage: Chapter System - Profile file loaded.");
  709.     }
  710.  
  711.     //Load ChapterList
  712.     bool bGotChapterList = false;
  713.     szInfoFile = "..\\";
  714.     szInfoFile += szModDir;
  715.     szInfoFile += "\\Game\\Libs\\UI\\Chapters\\ChapterNames.xml";
  716.     if (XmlNodeRef root = gEnv->pSystem->LoadXmlFile(szInfoFile.c_str()))
  717.     {
  718.         if (strnicmp(root->getTag(), "ChapterNames", 12) == 0)
  719.         {
  720.             bGotChapterList = true;
  721.         }
  722.     }
  723.  
  724.     //Create and send chapter list based on UnlockedChapterCount
  725.     if (bGotChapterList)
  726.     {
  727.         if (XmlNodeRef root = gEnv->pSystem->LoadXmlFile(szInfoFile.c_str()))
  728.         {
  729.             if (strnicmp(root->getTag(), "ChapterNames", 12) == 0)
  730.             {
  731.                 CFlashMenuScreen* pCurrentScreen = m_pCurrentFlashMenuScreen;
  732.  
  733.                 for(int i = 1; i != m_bUnlockedChapterCount + 1; i++)
  734.                 {
  735.                     char *key;
  736.                     const char *chapterNameDefault;
  737.                     const char *chapterNameTranslated;
  738.  
  739.                     sprintf(key, "Chapter_%i", i);
  740.                     chapterNameDefault = root->getAttr(key);
  741.  
  742.                     chapterNameTranslated = chapterNameDefault;
  743.  
  744.                     SFlashVarValue args[2] =
  745.                     {
  746.                         chapterNameDefault,
  747.                         chapterNameTranslated
  748.                     };
  749.  
  750.                     pCurrentScreen->CheckedInvoke("addChapterToList", args, sizeof(args) / sizeof(args[0]));
  751.  
  752.                 }
  753.             }
  754.         }
  755.     }
  756.     else
  757.     {
  758.         CryLogAlways("[Error] Wreckage: Chapter System - Failed to load chapter list. System disabled!");
  759.     }
  760.  
  761.     pScreen->CheckedInvoke("updateChapterList");
  762. }
  763.  
  764. //Wreckage MOD: New Chapter Selection Screen
  765. void CFlashMenuObject::LoadChapter(const char *ChapterName)
  766. {
  767.     //overwrite the last savegame with the to be loaded one
  768.     //m_sLastSaveGame = ChapterName;
  769.    
  770.     //gEnv->pGame->GetIGameFramework()->LoadGame(ChapterName, false, true);
  771.  
  772.     //Find corresponding Level based of ChapterName
  773.     ICryPak *pCryPak = gEnv->pCryPak;
  774.     const string szModDir = pCryPak->GetModDir();
  775.  
  776.     string levelName;
  777.     bool bGotLevelMapping = false;
  778.  
  779.     string szInfoFile = "..\\";
  780.     szInfoFile += szModDir;
  781.     szInfoFile += "\\Game\\Libs\\UI\\Chapters\\ChapterLevelMapping.xml";
  782.     if (XmlNodeRef root = gEnv->pSystem->LoadXmlFile(szInfoFile.c_str()))
  783.     {
  784.         if (strnicmp(root->getTag(), "LevelChapterNames", 17) == 0)
  785.         {
  786.             //Get Level Name
  787.             levelName = root->getAttr(ChapterName);
  788.  
  789.             if (levelName)
  790.                 bGotLevelMapping = true;
  791.             else
  792.                 bGotLevelMapping = false;
  793.         }
  794.     }
  795.     if (false == bGotLevelMapping)
  796.     {
  797.         CryLogAlways("[Error] Wreckage: Chapter System - Failed to find map. Do nothing.");
  798.         return;
  799.     }
  800.     else
  801.     {
  802.         CryLogAlways("Wreckage: Chapter System - Map found.");
  803.     }
  804.  
  805.     //Set CVar for Map SpawnPoint
  806.     ICVar* chapter = gEnv->pConsole->GetCVar("wreckage_chapterName");
  807.     if(chapter)
  808.         chapter->ForceSet(ChapterName);
  809.  
  810.  
  811.     //Load Map
  812.     string szCmd = "map ";
  813.     szCmd += levelName;
  814.     szCmd += " nonblocking";
  815.     gEnv->pConsole->ExecuteString(szCmd.c_str());
  816. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement