Advertisement
AlisaCodeDragon

UCC source code c++

Feb 24th, 2019
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.56 KB | None | 0 0
  1. #if WIN32
  2.     #include <windows.h>
  3. #else
  4.     #include <errno.h>
  5.     #include <sys/stat.h>
  6. #endif
  7. #include <malloc.h>
  8. #include <stdio.h>
  9.  
  10. // Core and Engine
  11. #include "Engine.h"
  12.  
  13. #if __STATIC_LINK
  14.  
  15. // Extra stuff for static links for Engine.
  16. //#include "UnCon.h"
  17. #include "UnRender.h"
  18. #include "UnNet.h"
  19.  
  20. // NullNetDriver static stuff
  21. //#include "NullNetDriver.h"
  22.  
  23. #ifdef __LINUX_X86__
  24. // Fire static stuff.
  25. //#include "UnFractal.h"
  26.  
  27. // IpDrv static stuff.
  28. //#include "UnIpDrv.h"
  29. //#include "UnTcpNetDriver.h"
  30. //#include "UnIpDrvCommandlets.h"
  31. //#include "UnIpDrvNative.h"
  32.  
  33. // UWeb static stuff
  34. //#include "UWeb.h"
  35. //#include "UWebNative.h"
  36. #endif
  37.  
  38. #endif
  39.  
  40. INT GFilesOpen, GFilesOpened;
  41.  
  42. /*-----------------------------------------------------------------------------
  43.     Global variables.
  44. -----------------------------------------------------------------------------*/
  45.  
  46. // General.
  47. #if _MSC_VER
  48.     extern "C" {HINSTANCE hInstance;}
  49. #endif
  50. extern "C" {TCHAR GPackage[64]=TEXT("UCC");}
  51.  
  52. // Log.
  53. #include "FOutputDeviceFile.h"
  54.  
  55. // Error.
  56. #include "FOutputDeviceAnsiError.h"
  57. FOutputDeviceAnsiError Error;
  58.  
  59. // Feedback.
  60. #include "FFeedbackContextAnsi.h"
  61. FFeedbackContextAnsi Warn;
  62.  
  63. // File manager.
  64. #if WIN32
  65.     #include "FFileManagerWindows.h"
  66.     FFileManagerWindows FileManager;
  67. //  #include "FMallocDebug.h"
  68. //  FMallocDebug Malloc;
  69.     #include "FMallocAnsi.h"
  70.     FMallocAnsi Malloc;
  71. #elif __PSX2_EE__
  72.     #include "FFileManagerPSX2.h"
  73.     FFileManagerPSX2 FileManager;
  74.     #include "FMallocAnsi.h"
  75.     FMallocAnsi Malloc;
  76. #elif __LINUX_X86__
  77.     #include "FFileManagerLinux.h"
  78.     FFileManagerLinux FileManager;
  79.     #include "FMallocAnsi.h"
  80.     FMallocAnsi Malloc;
  81. #else
  82.     #include "FFileManagerAnsi.h"
  83.     FFileManagerAnsi FileManager;
  84.     #include "FMallocAnsi.h"
  85.     FMallocAnsi Malloc;
  86. #endif
  87.  
  88. // Config.
  89. #include "FConfigCacheIni.h"
  90.  
  91. /*-----------------------------------------------------------------------------
  92.     Main.
  93. -----------------------------------------------------------------------------*/
  94.  
  95. // Unreal command-line applet executor.
  96. FString RightPad( FString In, INT Count )
  97. {
  98.     while( In.Len()<Count )
  99.         In += TEXT(" ");
  100.     return In;
  101. }
  102. static INT Compare( FString& A, FString& B )
  103. {
  104.     return appStricmp( *A, *B );
  105. }
  106. void ShowBanner( FOutputDevice& Warn )
  107. {
  108.     Warn.Logf( TEXT("=======================================") );
  109.     Warn.Logf( TEXT("ucc.exe: UnrealOS execution environment") );
  110.     Warn.Logf( TEXT("Copyright 2001 Epic Games Inc") );
  111.     Warn.Logf( TEXT("=======================================") );
  112.     Warn.Logf( TEXT("") );
  113. }
  114.  
  115. #if __DO_LINUX_MCHECKING__
  116. extern "C"
  117. {
  118.     int mcheck(void *feh);
  119. }
  120. #endif
  121.  
  122. int main( int argc, char* argv[] )
  123. {
  124.     FOutputDeviceFile Log;
  125.  
  126.     #if __LINUX__
  127.         setbuf(stdout, NULL);
  128.         setbuf(stderr, NULL);
  129.         #if __DO_LINUX_MCHECKING__
  130.             mcheck(NULL);
  131.         #endif
  132.     #endif
  133.  
  134.     UObject::SetGlobalLoadFlags( LOAD_NoSync );
  135.  
  136.     #if __STATIC_LINK
  137.     // Clean lookups.
  138.     for (INT k=0; k<ARRAY_COUNT(GNativeLookupFuncs); k++)
  139.     {
  140.         GNativeLookupFuncs[k] = NULL;
  141.     }
  142.  
  143.     // Core lookups.
  144.     GNativeLookupFuncs[0] = &FindCoreUObjectNative;
  145.     GNativeLookupFuncs[1] = &FindCoreUCommandletNative;
  146.  
  147.     // Engine lookups.
  148.     GNativeLookupFuncs[2] = &FindEngineAActorNative;
  149.     GNativeLookupFuncs[3] = &FindEngineAPawnNative;
  150.     GNativeLookupFuncs[4] = &FindEngineAPlayerPawnNative;
  151.     GNativeLookupFuncs[5] = &FindEngineADecalNative;
  152.     GNativeLookupFuncs[6] = &FindEngineAStatLogNative;
  153.     GNativeLookupFuncs[7] = &FindEngineAStatLogFileNative;
  154.     GNativeLookupFuncs[8] = &FindEngineAZoneInfoNative;
  155.     GNativeLookupFuncs[9] = &FindEngineAWarpZoneInfoNative;
  156.     GNativeLookupFuncs[10] = &FindEngineALevelInfoNative;
  157.     GNativeLookupFuncs[11] = &FindEngineAGameInfoNative;
  158.     GNativeLookupFuncs[12] = &FindEngineANavigationPointNative;
  159.     GNativeLookupFuncs[13] = &FindEngineUCanvasNative;
  160.     GNativeLookupFuncs[14] = &FindEngineUConsoleNative;
  161.  
  162.     #ifdef __LINUX_X86__
  163.     // IpDrv lookups.
  164. //  GNativeLookupFuncs[16] = &FindIpDrvAInternetLinkNative;
  165. //  GNativeLookupFuncs[17] = &FindIpDrvAUdpLinkNative;
  166. //  GNativeLookupFuncs[18] = &FindIpDrvATcpLinkNative;
  167.  
  168.     // UWeb lookups.
  169. //  GNativeLookupFuncs[19] = &FindUWebUWebResponseNative;
  170. //  GNativeLookupFuncs[20] = &FindUWebUWebRequestNative;
  171.     #endif
  172.  
  173.     #endif
  174.  
  175.     INT ErrorLevel = 0;
  176.     GIsStarted     = 1;
  177. #ifndef _DEBUG
  178.     try
  179. #endif
  180.     {
  181.         GIsGuarded = 1;
  182.  
  183.         #if !_MSC_VER
  184.         // Set module name.
  185.         strcpy( GModule, "ucc" );
  186.         //!!vogel: pathname might be too long
  187.         //appStrcpy( GModule, argv[0] );
  188.         #endif
  189.        
  190.         // Parse command line.
  191.         TCHAR CmdLine[1024], *CmdLinePtr=CmdLine;
  192.         *CmdLinePtr = 0;
  193.         #if WIN32
  194.             ANSICHAR* Ch = GetCommandLineA();
  195.             while( *Ch && *Ch!=' ' )
  196.                 Ch++;
  197.             while( *Ch==' ' )
  198.                 Ch++;
  199.             while( *Ch )
  200.                 *CmdLinePtr++ = *Ch++;
  201.             *CmdLinePtr++ = 0;
  202.         #else
  203.             for( INT i=2; i<argc; i++ )
  204.             {
  205.                 if( i>2 )
  206.                     appStrcat( CmdLine, TEXT(" ") );
  207.                 appStrcat( CmdLine, ANSI_TO_TCHAR(argv[i]) );
  208.             }
  209.         #endif
  210.  
  211.         // Init engine core.
  212.         appInit( TEXT("RagII"), CmdLine, &Malloc, &Log, &Error, &Warn, &FileManager, FConfigCacheIni::Factory, 1 ); //!!
  213.  
  214.         // Init static classes.
  215.         #if __STATIC_LINK
  216.             AUTO_INITIALIZE_REGISTRANTS_ENGINE;
  217.             AUTO_INITIALIZE_REGISTRANTS_NULLNETDRIVER;
  218.             #ifdef __LINUX_86__
  219.         //  AUTO_INITIALIZE_REGISTRANTS_FIRE;
  220.         //  AUTO_INITIALIZE_REGISTRANTS_IPDRV;
  221.         //  AUTO_INITIALIZE_REGISTRANTS_UWEB;
  222.             #endif
  223.         #endif
  224.  
  225.         // Set up meta package readers.
  226. //      for( i=0; i<GSys->MetaPackages.Num(); i++ )
  227. //      {
  228. //          printf("%s\n", *GSys->MetaPackages(i));
  229. //          ((FFileManagerPSX2*) GFileManager)->AddMetaArchive( *GSys->MetaPackages(i), &Error );
  230. //      }
  231.  
  232.         // Get the ucc stuff going.
  233.         UObject::SetLanguage(TEXT("int"));
  234.         FString Token = argc>1 ? appFromAnsi(argv[1]) : TEXT("");
  235.         TArray<FRegistryObjectInfo> List;
  236.         UObject::GetRegistryObjects( List, UClass::StaticClass(), UCommandlet::StaticClass(), 0 );
  237.         GIsClient = GIsServer = GIsEditor = GIsScriptable = GIsUCC = 1;
  238.         GLazyLoad = 0;
  239.         UBOOL Help = 0;
  240.         DWORD LoadFlags = LOAD_NoWarn | LOAD_Quiet;
  241.         if( Token==TEXT("") )
  242.         {
  243.             ShowBanner( Warn );
  244.             Warn.Logf( TEXT("Use \"ucc help\" for help") );
  245.         }
  246.         else if( Token==TEXT("HELP") )
  247.         {
  248.             ShowBanner( Warn );
  249.             verify(UObject::StaticLoadClass( UCommandlet::StaticClass(), NULL, TEXT("Core.Commandlet"), NULL, LOAD_NoFail|LOAD_NoSync, NULL )==UCommandlet::StaticClass());
  250.             const TCHAR* Tmp = appCmdLine();
  251.             GIsEditor = 0; // To enable loading localized text.
  252.             if( !ParseToken( Tmp, Token, 0 ) )
  253.             {
  254.                 INT i;
  255.                 Warn.Logf( TEXT("Usage:") );
  256.                 Warn.Logf( TEXT("   ucc <command> <parameters>") );
  257.                 Warn.Logf( TEXT("") );
  258.                 Warn.Logf( TEXT("Commands for \"ucc\":") );
  259.                 TArray<FString> Items;
  260.                 for( i=0; i<List.Num(); i++ )
  261.                 {
  262.                     UClass* Class = UObject::StaticLoadClass( UCommandlet::StaticClass(), NULL, *List(i).Object, NULL, LoadFlags|LOAD_NoSync, NULL );
  263.                     if( Class )
  264.                     {
  265.                         UCommandlet* Default = (UCommandlet*)Class->GetDefaultObject();
  266.                         new(Items)FString( FString(TEXT("   ucc ")) + RightPad(Default->HelpCmd,21) + TEXT(" ") + Default->HelpOneLiner );
  267.                     }
  268.                 }
  269.                 new(Items)FString( TEXT("   ucc help <command>        Get help on a command") );
  270.                 Sort( &Items(0), Items.Num() );
  271.                 for( i=0; i<Items.Num(); i++ )
  272.                     Warn.Log( Items(i) );
  273.             }
  274.             else
  275.             {
  276.                 Help = 1;
  277.                 goto Process;
  278.             }
  279.         }
  280.         else
  281.         {
  282.             // Look it up.
  283.             if( Token==TEXT("Make") )
  284.                 LoadFlags |= LOAD_DisallowFiles;
  285.         Process:
  286.             UClass* Class = UObject::StaticLoadClass( UCommandlet::StaticClass(), NULL, *Token, NULL, LoadFlags|LOAD_NoSync, NULL );
  287.             if( !Class )
  288.                 Class = UObject::StaticLoadClass( UCommandlet::StaticClass(), NULL, *(Token+TEXT("Commandlet")), NULL, LoadFlags|LOAD_NoSync, NULL );
  289.             if( !Class )
  290.             {
  291.                 INT i;
  292.                 for( i=0; i<List.Num(); i++ )
  293.                 {
  294.                     FString Str = List(i).Object;
  295.                     while( Str.InStr(TEXT("."))>=0 )
  296.                         Str = Str.Mid(Str.InStr(TEXT("."))+1);
  297.                     if( Token==Str || Token+TEXT("Commandlet")==Str )
  298.                         break;
  299.                 }
  300.                 if( i<List.Num() )
  301.                     Class = UObject::StaticLoadClass( UCommandlet::StaticClass(), NULL, *List(i).Object, NULL, LoadFlags|LOAD_NoSync, NULL );
  302.             }
  303.             if( Class )
  304.             {
  305.                 UCommandlet* Default = (UCommandlet*)Class->GetDefaultObject();
  306.                 if( Help )
  307.                 {
  308.                     // Get help on it.
  309.                     if( Default->HelpUsage!=TEXT("") )
  310.                     {
  311.                         Warn.Logf( TEXT("Usage:") );
  312.                         Warn.Logf( TEXT("   ucc %s"), *Default->HelpUsage );
  313.                     }
  314.                     if( Default->HelpParm[0]!=TEXT("") )
  315.                     {
  316.                         Warn.Logf( TEXT("") );
  317.                         Warn.Logf( TEXT("Parameters:") );
  318.                         for( INT i=0; i<ARRAY_COUNT(Default->HelpParm) && Default->HelpParm[i]!=TEXT(""); i++ )
  319.                             Warn.Logf( TEXT("   %s %s"), *RightPad(Default->HelpParm[i],16), *Default->HelpDesc[i] );
  320.                     }
  321.                     if( Default->HelpWebLink!=TEXT("") )
  322.                     {
  323.                         Warn.Logf( TEXT("") );
  324.                         Warn.Logf( TEXT("For more info, see") );
  325.                         Warn.Logf( TEXT("   %s"), *Default->HelpWebLink );
  326.                     }
  327.                 }
  328.                 else
  329.                 {
  330.                     // Run it.
  331.                     if( Default->LogToStdout )
  332.                     {
  333.                         Warn.AuxOut = GLog;
  334.                         GLog        = &Warn;
  335.                     }
  336.                     if( Default->ShowBanner )
  337.                     {
  338.                         ShowBanner( Warn );
  339.                     }
  340.                     debugf( TEXT("Executing %s"), Class->GetFullName() );
  341.                     GIsClient = Default->IsClient;
  342.                     GIsServer = Default->IsServer;
  343.                     GIsEditor = Default->IsEditor;
  344.                     GLazyLoad = Default->LazyLoad;
  345.                     UCommandlet* Commandlet = ConstructObject<UCommandlet>( Class );
  346.                     Commandlet->InitExecution();
  347.                     Commandlet->ParseParms( appCmdLine() );
  348.                     Commandlet->Main( appCmdLine() );
  349.                     if( Commandlet->ShowErrorCount )
  350.                     {
  351.                         if ( Warn.ErrorCount == 0)
  352.                             GWarn->Logf( TEXT("Success - %d error(s), %d warning(s)"), Warn.ErrorCount, Warn.WarningCount );
  353.                         else
  354.                         {
  355.                             GWarn->Logf( TEXT("Failure - %d error(s), %d warning(s)"), Warn.ErrorCount, Warn.WarningCount );
  356.                             ErrorLevel = 1;
  357.                         }
  358.                     }
  359.                     if( Default->LogToStdout )
  360.                     {
  361.                         Warn.AuxOut = NULL;
  362.                         GLog        = &Log;
  363.                     }
  364.                 }
  365.             }
  366.             else
  367.             {
  368.                 ShowBanner( Warn );
  369.                 Warn.Logf( TEXT("Commandlet %s not found"), *Token );
  370.             }
  371.         }
  372.         appPreExit();
  373.         GIsGuarded = 0;
  374.     }
  375. #ifndef _DEBUG
  376.     catch( ... )
  377.     {
  378.         // Crashed.
  379.         ErrorLevel = 1;
  380.         GIsGuarded = 0;
  381.         Error.HandleError();
  382.     }
  383. #endif
  384.     appExit();
  385.     GIsStarted = 0;
  386.     return ErrorLevel;
  387. }
  388.  
  389. /*-----------------------------------------------------------------------------
  390.     The End.
  391. -----------------------------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement