Advertisement
Guest User

adsf

a guest
May 1st, 2014
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.26 KB | None | 0 0
  1. /*
  2. #############################################################################################
  3. # TheFeckless UE3 SDK Generator v1.4_Beta-Rev.51
  4. # ========================================================================================= #
  5. # File: TFL_SdkGen.cpp
  6. # ========================================================================================= #
  7. # Credits: uNrEaL, Tamimego, SystemFiles, R00T88, _silencer, the1domo, K@N@VEL
  8. # Thanks: HOOAH07, lowHertz
  9. # Forums: www.uc-forum.com, www.gamedeception.net
  10. # ========================================================================================= #
  11. # This work is licensed under the
  12. # Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  13. # To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
  14. # or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View,
  15. # California, 94041, USA.
  16. #############################################################################################
  17. */
  18.  
  19. #include "TFL_SdkGen.h"
  20.  
  21. /*
  22. # ========================================================================================= #
  23. # Print Code
  24. # ========================================================================================= #
  25. */
  26.  
  27. void PrintFileHeder ( char* cFileName, char* cFileExt, bool setPP = false )
  28. {
  29. fprintf ( pFile, "/*\n" );
  30. fprintf ( pFile, "#############################################################################################\n" );
  31. fprintf ( pFile, "# %s (%s) SDK\n", GAME_NAME, GAME_VERSION );
  32. fprintf ( pFile, "# Generated with TheFeckless UE3 SDK Generator %s\n", SDK_GEN_VER );
  33. fprintf ( pFile, "# ========================================================================================= #\n" );
  34. fprintf ( pFile, "# File: %s.%s\n", cFileName, cFileExt );
  35. fprintf ( pFile, "# ========================================================================================= #\n" );
  36. fprintf ( pFile, "# Credits: %s\n", SDK_GEN_CREDITS );
  37. fprintf ( pFile, "# Thanks: %s\n", SDK_GEN_STHANKS );
  38. fprintf ( pFile, "# Forums: %s\n", SDK_GEN_FORUMS );
  39. fprintf ( pFile, "#############################################################################################\n" );
  40. fprintf ( pFile, "*/\n" );
  41.  
  42. if ( setPP )
  43. {
  44. fprintf ( pFile, "\n#ifdef _MSC_VER\n" );
  45. fprintf ( pFile, "\t#pragma pack ( push, 0x%X )\n", CLASS_ALIGN );
  46. fprintf ( pFile, "#endif\n" );
  47. }
  48. }
  49.  
  50. void PrintFileFooter()
  51. {
  52. fprintf ( pFile, "\n#ifdef _MSC_VER\n" );
  53. fprintf ( pFile, "\t#pragma pack ( pop )\n" );
  54. fprintf ( pFile, "#endif" );
  55. }
  56.  
  57. void PrintSectionHeader ( char* cSectionName )
  58. {
  59. fprintf ( pFile, "\n/*\n" );
  60. fprintf ( pFile, "# ========================================================================================= #\n" );
  61. fprintf ( pFile, "# %s\n", cSectionName );
  62. fprintf ( pFile, "# ========================================================================================= #\n" );
  63. fprintf ( pFile, "*/\n\n" );
  64. }
  65.  
  66. /*
  67. # ========================================================================================= #
  68. # Generate Flags
  69. # ========================================================================================= #
  70. */
  71.  
  72. void GetAllPropertyFlags ( int PropertyFlags, ostringstream& ssStreamBuffer )
  73. {
  74. bool first = true;
  75.  
  76. if ( PropertyFlags & CPF_Edit ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Edit"; first = false; }
  77. if ( PropertyFlags & CPF_Const ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Const"; first = false; }
  78. if ( PropertyFlags & CPF_Input ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Input"; first = false; }
  79. if ( PropertyFlags & CPF_ExportObject ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_ExportObject"; first = false; }
  80. if ( PropertyFlags & CPF_OptionalParm ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_OptionalParm"; first = false; }
  81. if ( PropertyFlags & CPF_Net ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Net"; first = false; }
  82. if ( PropertyFlags & CPF_EditConstArray ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_EditConstArray"; first = false; }
  83. if ( PropertyFlags & CPF_Parm ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Parm"; first = false; }
  84. if ( PropertyFlags & CPF_OutParm ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_OutParm"; first = false; }
  85. if ( PropertyFlags & CPF_SkipParm ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_SkipParm"; first = false; }
  86. if ( PropertyFlags & CPF_ReturnParm ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_ReturnParm"; first = false; }
  87. if ( PropertyFlags & CPF_CoerceParm ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_CoerceParm"; first = false; }
  88. if ( PropertyFlags & CPF_Native ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Native"; first = false; }
  89. if ( PropertyFlags & CPF_Transient ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Transient"; first = false; }
  90. if ( PropertyFlags & CPF_Config ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Config"; first = false; }
  91. if ( PropertyFlags & CPF_Localized ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Localized"; first = false; }
  92. if ( PropertyFlags & CPF_Travel ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Travel"; first = false; }
  93. if ( PropertyFlags & CPF_EditConst ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_EditConst"; first = false; }
  94. if ( PropertyFlags & CPF_GlobalConfig ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_GlobalConfig"; first = false; }
  95. if ( PropertyFlags & CPF_Component ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Component"; first = false; }
  96. if ( PropertyFlags & CPF_NeedCtorLink ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_NeedCtorLink"; first = false; }
  97. if ( PropertyFlags & CPF_NoExport ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_NoExport"; first = false; }
  98. if ( PropertyFlags & CPF_NoClear ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_NoClear"; first = false; }
  99. if ( PropertyFlags & CPF_EditInline ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_EditInline"; first = false; }
  100. if ( PropertyFlags & CPF_EdFindable ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_EdFindable"; first = false; }
  101. if ( PropertyFlags & CPF_EditInlineUse ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_EditInlineUse"; first = false; }
  102. if ( PropertyFlags & CPF_Deprecated ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Deprecated"; first = false; }
  103. if ( PropertyFlags & CPF_EditInlineNotify ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_EditInlineNotify"; first = false; }
  104. if ( PropertyFlags & CPF_RepNotify ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_RepNotify"; first = false; }
  105. if ( PropertyFlags & CPF_Interp ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_Interp"; first = false; }
  106. if ( PropertyFlags & CPF_NonTransactional ) { ssStreamBuffer << ( first ? "( " : " | " ) << "CPF_NonTransactional"; first = false; }
  107.  
  108. if ( ! first ) { ssStreamBuffer << " )"; }
  109. }
  110.  
  111. void GetAllFunctionFlags ( unsigned long FunctionFlags, ostringstream& ssStreamBuffer )
  112. {
  113. bool first = true;
  114.  
  115. if ( FunctionFlags & FUNC_Final ) { ssStreamBuffer << ( first ? "( " : " | " ) << "FUNC_Final"; first = false; }
  116. //if ( FunctionFlags & FUNC_Latent ) { ssStreamBuffer << ( first ? "( " : " | " ) << "FUNC_Latent"; first = false; }
  117. //if ( FunctionFlags & FUNC_Simulated ) { ssStreamBuffer << ( first ? "( " : " | " ) << "FUNC_Simulated"; first = false; }
  118. if ( FunctionFlags & FUNC_Exec ) { ssStreamBuffer << ( first ? "( " : " | " ) << "FUNC_Exec"; first = false; }
  119. if ( FunctionFlags & FUNC_Event ) { ssStreamBuffer << ( first ? "( " : " | " ) << "FUNC_Event"; first = false; }
  120. if ( FunctionFlags & FUNC_Native ) { ssStreamBuffer << ( first ? "( " : " | " ) << "FUNC_Native"; first = false; }
  121.  
  122. if ( ! first ) { ssStreamBuffer << " )"; }
  123. }
  124.  
  125. /*
  126. # ========================================================================================= #
  127. # String Utils
  128. # ========================================================================================= #
  129. */
  130.  
  131. string GetValidName ( const string& sName )
  132. {
  133. string sBuffer = sName;
  134.  
  135. for ( unsigned int i = 0; i < sBuffer.length(); i++ )
  136. {
  137. if
  138. (
  139. sBuffer[ i ] == ' '
  140. || sBuffer[ i ] == '?'
  141. || sBuffer[ i ] == '-'
  142. || sBuffer[ i ] == ':'
  143. )
  144. {
  145. sBuffer[ i ] = '_';
  146. }
  147. }
  148.  
  149. return sBuffer;
  150. }
  151.  
  152. string ToS ( const wchar_t* wcOrig )
  153. {
  154. char sBuffer0[ SDK_BUFF_SIZE ] = { NULL };
  155.  
  156. sprintf_s ( sBuffer0, "%S", wcOrig );
  157.  
  158. return string ( sBuffer0 );
  159. }
  160.  
  161. string ToS ( const char* cOrig )
  162. {
  163. char sBuffer0[ SDK_BUFF_SIZE ] = { NULL };
  164.  
  165. sprintf_s ( sBuffer0, "%s", cOrig );
  166.  
  167. return string ( sBuffer0 );
  168. }
  169.  
  170. bool StrStrMm_Exist ( StrStrMm_t& StrStrMm, string sKey, string sValue )
  171. {
  172. pair< StrStrMm_t::iterator, StrStrMm_t::iterator > prRange;
  173.  
  174. prRange = StrStrMm.equal_range ( sKey );
  175.  
  176. for ( StrStrMm_t::iterator it = prRange.first; it != prRange.second; ++it )
  177. {
  178. if ( (*it).second == sValue )
  179. return true;
  180. }
  181.  
  182. return false;
  183. }
  184.  
  185. /*
  186. # ========================================================================================= #
  187. # Property Utils
  188. # ========================================================================================= #
  189. */
  190.  
  191. bool SortProperty ( UProperty* pPropertyA, UProperty* pPropertyB )
  192. {
  193. if
  194. (
  195. pPropertyA->Offset == pPropertyB->Offset
  196. && pPropertyA->IsA ( UBoolProperty::StaticClass() )
  197. && pPropertyB->IsA ( UBoolProperty::StaticClass() )
  198. )
  199. return ( ( (UBoolProperty*) pPropertyA )->BitMask < ( (UBoolProperty*) pPropertyB )->BitMask );
  200. else
  201. return ( pPropertyA->Offset < pPropertyB->Offset );
  202. }
  203.  
  204. bool SortPropertyPair ( pair< UProperty*, string > pPropertyA, pair< UProperty*, string > pPropertyB )
  205. {
  206. if
  207. (
  208. pPropertyA.first->Offset == pPropertyB.first->Offset
  209. && pPropertyA.first->IsA ( UBoolProperty::StaticClass() )
  210. && pPropertyB.first->IsA ( UBoolProperty::StaticClass() )
  211. )
  212. return ( ( (UBoolProperty*) pPropertyA.first )->BitMask < ( (UBoolProperty*) pPropertyB.first )->BitMask );
  213. else
  214. return ( pPropertyA.first->Offset < pPropertyB.first->Offset );
  215. }
  216.  
  217. // GetPropertyType
  218. // Return values
  219. // - (0) unknown
  220. // - (1) uchar, ulong, int, float, pointers
  221. // - (2) predefined struct
  222. // - (3) custom struct
  223. // - (4) tarray
  224. // - (5) tmap
  225. int GetPropertyType ( UProperty* pProperty, string& sPropertyType, bool bFuncRet = false )
  226. {
  227. if ( ! pProperty ) // necessary because this function is recursive
  228. return 0;
  229.  
  230.  
  231. if ( false ) {}
  232.  
  233. #ifdef CCP_UBYTE
  234. else if ( pProperty->IsA ( UByteProperty::StaticClass() ) ) { sPropertyType = "unsigned char"; return 1; }
  235. #endif
  236.  
  237. #ifdef CCP_UINT
  238. else if ( pProperty->IsA ( UIntProperty::StaticClass() ) ) { sPropertyType = "int"; return 1; }
  239. #endif
  240.  
  241. #ifdef CCP_UFLOAT
  242. else if ( pProperty->IsA ( UFloatProperty::StaticClass() ) ) { sPropertyType = "float"; return 1; }
  243. #endif
  244.  
  245. #ifdef CCP_UBOOL
  246. else if ( pProperty->IsA ( UBoolProperty::StaticClass() ) )
  247. {
  248. if ( bFuncRet )
  249. sPropertyType = "bool";
  250. else
  251. sPropertyType = "unsigned long";
  252.  
  253. return 1;
  254. }
  255. #endif
  256.  
  257. #ifdef CCP_USTR
  258. else if ( pProperty->IsA ( UStrProperty::StaticClass() ) ) { sPropertyType = "struct FString"; return 2; }
  259. #endif
  260.  
  261. #ifdef CCP_USTRINGREF
  262. else if ( pProperty->IsA ( UStringRefProperty::StaticClass() ) ) { sPropertyType = "void*"; return 1; }
  263. #endif
  264.  
  265. #ifdef CCP_UNAME
  266. else if ( pProperty->IsA ( UNameProperty::StaticClass() ) ) { sPropertyType = "struct FName"; return 2; }
  267. #endif
  268.  
  269. #ifdef CCP_UDELEGATE
  270. else if ( pProperty->IsA ( UDelegateProperty::StaticClass() ) ) { sPropertyType = "struct FScriptDelegate"; return 2; }
  271. #endif
  272.  
  273. #ifdef CCP_UOBJECT
  274. else if ( pProperty->IsA ( UObjectProperty::StaticClass() ) ) { sPropertyType = "class " + GetValidName ( string ( ( (UObjectProperty*) pProperty )->PropertyClass->GetNameCPP() ) ) + "*"; return 1; }
  275. #endif
  276.  
  277. #ifdef CCP_UCLASS
  278. else if ( pProperty->IsA ( UClassProperty::StaticClass() ) ) { sPropertyType = "class " + GetValidName ( string ( ( (UClassProperty*) pProperty )->MetaClass->GetNameCPP() ) ) + "*"; return 1; }
  279. #endif
  280.  
  281. #ifdef CCP_UINTERFACE
  282. else if ( pProperty->IsA ( UInterfaceProperty::StaticClass() ) ) { sPropertyType = "class " + GetValidName ( string ( ( (UInterfaceProperty*) pProperty )->InterfaceClass->GetNameCPP() ) ) + "*"; return 1; }
  283. #endif
  284.  
  285. #ifdef CCP_USTRUCT
  286. else if ( pProperty->IsA ( UStructProperty::StaticClass() ) )
  287. {
  288. // count name
  289. strcpy_s ( cBuffer, ( (UStructProperty*) pProperty )->Struct->GetName() );
  290. unsigned int nCounterF = UObject::CountObject< UScriptStruct > ( cBuffer );
  291.  
  292. if ( nCounterF > 1 )
  293. sPropertyType = "struct " + GetValidName ( string ( ( (UStructProperty*) pProperty )->Struct->Outer->GetNameCPP() ) ) + "_" + GetValidName ( string ( ( (UStructProperty*) pProperty )->Struct->GetNameCPP() ) );
  294. else
  295. sPropertyType = "struct " + GetValidName ( string ( ( (UStructProperty*) pProperty )->Struct->GetNameCPP() ) );
  296.  
  297. return 3;
  298. }
  299. #endif
  300.  
  301. #ifdef CCP_UARRAY
  302. else if ( pProperty->IsA ( UArrayProperty::StaticClass() ) )
  303. {
  304. string sPropertyTypeInner;
  305.  
  306. if ( GetPropertyType ( ( (UArrayProperty*) pProperty )->Inner, sPropertyTypeInner ) )
  307. {
  308. sPropertyType = "TArray< " + sPropertyTypeInner + " >";
  309.  
  310. return 4;
  311. }
  312. else
  313. return 0;
  314. }
  315. #endif
  316.  
  317. #ifdef CCP_UMAP
  318. else if ( pProperty->IsA ( UMapProperty::StaticClass() ) )
  319. {
  320. string sPropertyTypeKey;
  321. string sPropertyTypeValue;
  322.  
  323. if
  324. (
  325. GetPropertyType ( ( (UMapProperty*) pProperty )-> Key, sPropertyTypeKey )
  326. && GetPropertyType ( ( (UMapProperty*) pProperty )-> Value, sPropertyTypeValue )
  327. )
  328. {
  329. sPropertyType = "TMap< " + sPropertyTypeKey + ", " + sPropertyTypeValue + " >";
  330.  
  331. return 5;
  332. }
  333. else
  334. return 0;
  335. }
  336. #endif
  337.  
  338. else
  339. return 0;
  340. }
  341.  
  342. unsigned long GetPropertySize ( UProperty* pProperty )
  343. {
  344. if ( false ) {}
  345.  
  346. #ifdef CCP_UBYTE
  347. else if ( pProperty->IsA ( UByteProperty::StaticClass() ) ) { return sizeof ( unsigned char ); }
  348. #endif
  349.  
  350. #ifdef CCP_UINT
  351. else if ( pProperty->IsA ( UIntProperty::StaticClass() ) ) { return sizeof ( int ); }
  352. #endif
  353.  
  354. #ifdef CCP_UFLOAT
  355. else if ( pProperty->IsA ( UFloatProperty::StaticClass() ) ) { return sizeof ( float ); }
  356. #endif
  357.  
  358. #ifdef CCP_UBOOL
  359. else if ( pProperty->IsA ( UBoolProperty::StaticClass() ) ) { return sizeof ( unsigned long ); }
  360. #endif
  361.  
  362. #ifdef CCP_USTR
  363. else if ( pProperty->IsA ( UStrProperty::StaticClass() ) ) { return sizeof ( FString ); }
  364. #endif
  365.  
  366. #ifdef CCP_USTRINGREF
  367. else if ( pProperty->IsA ( UStringRefProperty::StaticClass() ) ) { return sizeof ( void* ); }
  368. #endif
  369.  
  370. #ifdef CCP_UNAME
  371. else if ( pProperty->IsA ( UNameProperty::StaticClass() ) ) { return sizeof ( FName ); }
  372. #endif
  373.  
  374. #ifdef CCP_UDELEGATE
  375. else if ( pProperty->IsA ( UDelegateProperty::StaticClass() ) ) { return sizeof ( FScriptDelegate ); }
  376. #endif
  377.  
  378. #ifdef CCP_UOBJECT
  379. else if ( pProperty->IsA ( UObjectProperty::StaticClass() ) ) { return sizeof ( void* ); }
  380. #endif
  381.  
  382. #ifdef CCP_UCLASS
  383. else if ( pProperty->IsA ( UClassProperty::StaticClass() ) ) { return sizeof ( void* ); }
  384. #endif
  385.  
  386. #ifdef CCP_UINTERFACE
  387. else if ( pProperty->IsA ( UInterfaceProperty::StaticClass() ) ) { return sizeof ( void* ); }
  388. #endif
  389.  
  390. #ifdef CCP_USTRUCT
  391. else if ( pProperty->IsA ( UStructProperty::StaticClass() ) ) { return pProperty->ElementSize; } // NOT SAFE !!!
  392. #endif
  393.  
  394. #ifdef CCP_UARRAY
  395. else if ( pProperty->IsA ( UArrayProperty::StaticClass() ) ) { return sizeof ( TArray< void* > ); }
  396. #endif
  397.  
  398. #ifdef CCP_UMAP
  399. else if ( pProperty->IsA ( UMapProperty::StaticClass() ) ) { return 0x3C; }
  400. #endif
  401.  
  402. else
  403. return 0;
  404. }
  405.  
  406. /*
  407. # ========================================================================================= #
  408. # Object Utils
  409. # ========================================================================================= #
  410. */
  411.  
  412. UScriptStruct* FindBiggestScriptStruct ( string ScriptStructFullName )
  413. {
  414. unsigned long dwSize = 0;
  415. UScriptStruct* BiggestScriptStruct = NULL;
  416.  
  417. for ( int i = 0; i < UObject::GObjObjects()->Count; ++i )
  418. {
  419. UObject* Object = UObject::GObjObjects()->Data[ i ];
  420.  
  421. // skip no T class objects
  422. if
  423. (
  424. ! Object
  425. || ! Object->IsA ( UScriptStruct::StaticClass() )
  426. )
  427. continue;
  428.  
  429. // check
  430. if ( ScriptStructFullName == string ( Object->GetFullName() ) )
  431. {
  432. UScriptStruct* ScriptStruct = (UScriptStruct*) Object;
  433.  
  434. if ( ScriptStruct->PropertySize >= dwSize )
  435. {
  436. BiggestScriptStruct = ScriptStruct;
  437. dwSize = ScriptStruct->PropertySize;
  438. }
  439. }
  440. }
  441.  
  442. return BiggestScriptStruct;
  443. }
  444.  
  445. /*
  446. # ========================================================================================= #
  447. # Generate Code
  448. # ========================================================================================= #
  449. */
  450.  
  451. // constants
  452. void GenerateConst ( UConst* pConst )
  453. {
  454. // stream buffers
  455. ostringstream ssStreamBuffer0; // main stream buffer
  456. ostringstream ssStreamBuffer1; // support stream buffer
  457. ostringstream ssStreamBuffer2; // support stream buffer
  458.  
  459. // maps
  460. static StrStrMm_t mmNameValues;
  461.  
  462. // get const name
  463. string sConstName = GetValidName ( string ( pConst->GetName() ) );
  464.  
  465. // remove default const
  466. if ( sConstName.find ( "Default__" ) != string::npos )
  467. return;
  468.  
  469. // get const value
  470. string sConstValue = ToS ( pConst->Value.Data );
  471.  
  472. // count existing const
  473. size_t stI = mmNameValues.count ( sConstName );
  474.  
  475. // check if const exist
  476. if ( stI == 0 ) // name not used so not exist
  477. {
  478. // map const name value
  479. mmNameValues.insert ( StrStrPair_t ( sConstName, sConstValue ) );
  480.  
  481. // stream to main buffer
  482. ssStreamBuffer0 << "#define CONST_" << SDKMC_SSCOL ( sConstName, SDK_COL1 ) << " " << sConstValue << "\n";
  483.  
  484. // print main stream buffer to file
  485. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  486. }
  487. else if ( ! StrStrMm_Exist ( mmNameValues, sConstName, sConstValue ) ) // same name but different value
  488. {
  489. // map const name value
  490. mmNameValues.insert ( StrStrPair_t ( sConstName, sConstValue ) );
  491.  
  492. // add number to name
  493. ssStreamBuffer1 << sConstName << SDKMC_SSDEC ( stI, 2 );
  494.  
  495. // print const
  496. ssStreamBuffer0 << "#define CONST_" << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL1 ) << " " << sConstValue << "\n";
  497.  
  498. // print main stream buffer to file
  499. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  500.  
  501. // empty support stream buffer
  502. SDKFN_EMPTY ( ssStreamBuffer1 );
  503. }
  504. }
  505.  
  506. // enums
  507. void GenerateEnum ( UEnum* pEnum )
  508. {
  509. // stream buffers
  510. ostringstream ssStreamBuffer0; // main stream buffer
  511. ostringstream ssStreamBuffer1; // support stream buffer
  512. ostringstream ssStreamBuffer2; // support stream buffer
  513.  
  514. // get enum names
  515. string sEnumName = GetValidName ( string ( pEnum->GetName() ) );
  516. string sEnumOuterNameCPP = GetValidName ( string ( pEnum->Outer->GetNameCPP() ) );
  517. string sEnumFullName = string ( pEnum->GetFullName() );
  518.  
  519. // remove default enum
  520. if ( sEnumName.find ( "Default__" ) != string::npos )
  521. return;
  522.  
  523. // print enum open
  524. ssStreamBuffer0 << "// " << sEnumFullName << "\n"
  525. //<< "enum " << sEnumOuterNameCPP << "_" << sEnumName << "\n{\n";
  526. << "/*enum " << sEnumName << "\n{\n";
  527.  
  528. // property unique name array
  529. StrIntM_t mPropertyName;
  530.  
  531. // loop enum members
  532. for ( int i = 0; i < pEnum->Names.Num(); i++ )
  533. {
  534. string sPropertyName = GetValidName ( ToS ( pEnum->Names.Data[ i ].GetName() ) );
  535.  
  536. // check unique var name
  537. if ( mPropertyName.count ( sPropertyName ) == 0 ) // not exist
  538. {
  539. // insert in unique name array
  540. mPropertyName[ sPropertyName ] = 1;
  541.  
  542. // stream to support buffer (property name)
  543. //ssStreamBuffer1 << sEnumOuterNameCPP << "_" << sEnumName << "_" << sPropertyName;
  544. ssStreamBuffer1 << sPropertyName;
  545. }
  546. else
  547. {
  548. // stream to support buffer (name + index)
  549. //ssStreamBuffer1 << sEnumOuterNameCPP << "_" << sEnumName << "_" << sPropertyName << SDKMC_SSDEC ( mPropertyName[ sPropertyName ], 2 );
  550. ssStreamBuffer1 << sPropertyName << SDKMC_SSDEC ( mPropertyName[ sPropertyName ], 2 );
  551.  
  552. // incremente name usage count
  553. mPropertyName[ sPropertyName ]++;
  554. }
  555.  
  556. // stram to main buffer (name = value)
  557. if ( i != pEnum->Names.Num() - 1 )
  558. {
  559. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL1 ) << " = " << i << ",\n";
  560. }
  561. else
  562. {
  563. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL1 ) << " = " << i << "\n";
  564. }
  565.  
  566. // empty support stream buffer
  567. SDKFN_EMPTY ( ssStreamBuffer1 );
  568. }
  569.  
  570. // stream to main buffer (close enum)
  571. ssStreamBuffer0 << "};*/\n\n";
  572.  
  573. // print main stream buffer to file
  574. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  575. }
  576.  
  577. // script structs
  578. void GenerateScriptStruct ( UScriptStruct* pScriptStruct )
  579. {
  580. // stream buffers
  581. ostringstream ssStreamBuffer0; // main stream buffer
  582. ostringstream ssStreamBuffer1; // support stream buffer
  583. ostringstream ssStreamBuffer2; // support stream buffer
  584.  
  585. // get struct names
  586. string sSStructFullName = string ( pScriptStruct->GetFullName() );
  587. string sSStructName = GetValidName ( string ( pScriptStruct->GetName() ) );
  588. string sSStructNameCPP = GetValidName ( string ( pScriptStruct->GetNameCPP() ) );
  589. string sSStructOuterNameCPP = GetValidName ( string ( pScriptStruct->Outer->GetNameCPP() ) );
  590.  
  591. // log
  592. fprintf ( pLog, "ScriptStruct: %-100s - instance: 0x%08X\n", sSStructName.c_str(), pScriptStruct );
  593.  
  594. // stream to main buffer
  595. ssStreamBuffer0 << "// " << sSStructFullName << "\n";
  596.  
  597. // vars
  598. DWORD dwSize = 0;
  599. DWORD dwLastOffset = 0;
  600. DWORD dwMissedOffset = 0;
  601.  
  602. // get superfield
  603. UScriptStruct* pSuperField = ( UScriptStruct* ) pScriptStruct->SuperField;
  604.  
  605. // count name
  606. strcpy_s ( cBuffer, sSStructName.c_str() );
  607. unsigned int nCounterF = UObject::CountObject< UScriptStruct > ( cBuffer );
  608.  
  609. // print struct
  610. if ( pSuperField && pSuperField != pScriptStruct )
  611. {
  612. // calculations
  613. dwSize = pScriptStruct->PropertySize - pSuperField->PropertySize;
  614. dwLastOffset = pSuperField->PropertySize;
  615.  
  616. // get superfield name
  617. string sSFieldName = GetValidName ( string ( pSuperField->GetName() ) );
  618. string sSFieldNameCPP = GetValidName ( string ( pSuperField->GetNameCPP() ) );
  619. string sSFieldOuterNameCPP = GetValidName ( string ( pSuperField->Outer->GetNameCPP() ) );
  620.  
  621. // count superfield name
  622. strcpy_s ( cBuffer, sSFieldName.c_str() );
  623. unsigned int nCounterSF = UObject::CountObject< UScriptStruct > ( cBuffer );
  624.  
  625. // stream to main buffer
  626. ssStreamBuffer0 << "// " << SDKMC_SSHEX ( dwSize, 4 ) << "(" << SDKMC_SSHEX ( pScriptStruct->PropertySize, 4 ) << " - " << SDKMC_SSHEX ( pSuperField->PropertySize, 4 ) << ")\n";
  627.  
  628. // special case same name structs
  629. if ( nCounterF > 1)
  630. ssStreamBuffer0 << "struct " << sSStructOuterNameCPP << "_" << sSStructNameCPP << " : ";
  631. else
  632. ssStreamBuffer0 << "struct " << sSStructNameCPP << " : ";
  633.  
  634. if ( nCounterSF > 1)
  635. ssStreamBuffer0 << sSFieldOuterNameCPP << "_" << sSFieldNameCPP << "\n";
  636. else
  637. ssStreamBuffer0 << sSFieldNameCPP << "\n";
  638.  
  639. }
  640. else
  641. {
  642. // calculations
  643. dwSize = pScriptStruct->PropertySize;
  644.  
  645. // stream to main buffer
  646. ssStreamBuffer0 << "// " << SDKMC_SSHEX ( dwSize, 4 ) << "\n";
  647.  
  648. if ( nCounterF > 1)
  649. ssStreamBuffer0 << "struct " << sSStructOuterNameCPP << "_" << sSStructNameCPP << "\n";
  650. else
  651. ssStreamBuffer0 << "struct " << sSStructNameCPP << "\n";
  652. }
  653.  
  654. // stream to buffer
  655. ssStreamBuffer0 << "{\n";
  656.  
  657. // proprerty array
  658. vector< UProperty* > vProperty;
  659.  
  660. // get struct properties
  661. for ( UProperty* pProperty = (UProperty*) pScriptStruct->Children; pProperty; pProperty = (UProperty*) pProperty->Next )
  662. {
  663. if
  664. (
  665. pProperty->ElementSize > 0
  666. && ! pProperty->IsA ( UScriptStruct::StaticClass() ) // additional check for ME3
  667. )
  668. vProperty.push_back ( pProperty );
  669. }
  670.  
  671. // sort vStructProperty array using pStructProperty -> Offset
  672. sort ( vProperty.begin(), vProperty.end(), SortProperty );
  673.  
  674. // property unique name array
  675. StrIntM_t mPropertyName;
  676.  
  677. // unknown data unique name index
  678. int UnknownDataIndex = 0;
  679.  
  680. // process struct properties
  681. for ( unsigned int i = 0; i < vProperty.size(); i++ )
  682. {
  683. UProperty* pProperty = vProperty[ i ];
  684.  
  685. // fix missed offsets
  686. if ( dwLastOffset < pProperty->Offset )
  687. {
  688. dwMissedOffset = pProperty->Offset - dwLastOffset;
  689.  
  690. // fix only if missed offset >= CLASS_ALIGN
  691. if ( dwMissedOffset >= CLASS_ALIGN )
  692. {
  693. // stream to support buffer
  694. ssStreamBuffer1 << "UnknownData" << SDKMC_SSDEC ( UnknownDataIndex, 2 ) << "[ " << SDKMC_SSHEX ( dwMissedOffset, 0 ) << " ];";
  695.  
  696. // stream to main buffer
  697. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( "unsigned char", SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  698. << "\t\t// " << SDKMC_SSHEX ( dwLastOffset, 4 ) << " (" << SDKMC_SSHEX ( dwMissedOffset, 4 ) << ") MISSED OFFSET\n";
  699.  
  700. // empty support buffer
  701. SDKFN_EMPTY( ssStreamBuffer1 );
  702.  
  703. UnknownDataIndex++;
  704. }
  705. }
  706.  
  707. // declare property type
  708. string sPropertyType;
  709.  
  710. // strem properties to main buffer
  711. if ( GetPropertyType ( pProperty, sPropertyType ) )
  712. {
  713. // get correct element size
  714. unsigned long dwCorrectElementSize = GetPropertySize ( pProperty );
  715.  
  716. // get property name
  717. string sPropertyName = GetValidName ( string ( pProperty->GetName() ) );
  718.  
  719. // check unique var name
  720. if ( mPropertyName.count ( sPropertyName ) == 0 ) // not exist
  721. {
  722. // insert in unique name array
  723. mPropertyName[ sPropertyName ] = 1;
  724.  
  725. // stream to support buffer (property name)
  726. ssStreamBuffer1 << sPropertyName;
  727. }
  728. else
  729. {
  730. // stream to support buffer (name + index)
  731. ssStreamBuffer1 << sPropertyName << SDKMC_SSDEC ( mPropertyName[ sPropertyName ], 2 );
  732.  
  733. // incremente name usage count
  734. mPropertyName[ sPropertyName ]++;
  735. }
  736.  
  737. // special case array
  738. if ( pProperty->ArrayDim > 1 )
  739. {
  740. // stream to support buffer
  741. ssStreamBuffer1 << "[ " << SDKMC_SSHEX ( pProperty->ArrayDim, 0 ) << " ]";
  742. }
  743.  
  744. // special case bool
  745. if ( pProperty->IsA ( UBoolProperty::StaticClass() ) )
  746. {
  747. // stream to support buffer
  748. ssStreamBuffer1 << " : 1";
  749. }
  750.  
  751. // stream to support buffer
  752. ssStreamBuffer1 << ";";
  753.  
  754. // stream property flags to support stream
  755. GetAllPropertyFlags ( pProperty->PropertyFlags.A, ssStreamBuffer2 );
  756.  
  757. // stream to main buffer
  758. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( sPropertyType, SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  759. << "\t\t// " << SDKMC_SSHEX ( pProperty->Offset, 4 ) << " (" << SDKMC_SSHEX ( ( pProperty->ElementSize * pProperty->ArrayDim ), 4 ) << ") [" << SDKMC_SSHEX ( pProperty->PropertyFlags.A, 16 ) << "]";
  760.  
  761. // stream to main buffer (bitmask)
  762. if ( pProperty->IsA ( UBoolProperty::StaticClass() ) )
  763. {
  764. // stream to support buffer
  765. ssStreamBuffer0 << " [" << SDKMC_SSHEX ( ( (UBoolProperty*) pProperty )->BitMask, 8 ) << "] ";
  766. }
  767. else
  768. {
  769. ssStreamBuffer0 << SDKMC_SSCOL ( "", 14 ); // empty space
  770. }
  771.  
  772. ssStreamBuffer0 << ssStreamBuffer2.str() << "\n";
  773.  
  774. // empty support buffers
  775. SDKFN_EMPTY ( ssStreamBuffer1 );
  776. SDKFN_EMPTY ( ssStreamBuffer2 );
  777.  
  778. // check if property size and type size are equal otherwise add pad data
  779. int nOffserError = ( pProperty->ElementSize * pProperty->ArrayDim ) - ( dwCorrectElementSize * pProperty->ArrayDim );
  780.  
  781. // correct wrong size elements
  782. if ( nOffserError > 0)
  783. {
  784. // stream to support buffer
  785. ssStreamBuffer1 << "UnknownData" << SDKMC_SSDEC ( UnknownDataIndex, 2 ) << "[ " << SDKMC_SSHEX ( nOffserError, 0 ) << " ];";
  786.  
  787. // stream to main buffer
  788. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( "unsigned char", SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  789. << "\t\t// " << SDKMC_SSHEX ( ( pProperty->Offset + nOffserError ), 4 ) << " (" << SDKMC_SSHEX ( nOffserError, 4 ) << ") FIX WRONG TYPE SIZE OF PREVIUS PROPERTY\n";
  790.  
  791. // empty support buffers
  792. SDKFN_EMPTY ( ssStreamBuffer1 );
  793.  
  794. UnknownDataIndex++;
  795. }
  796. }
  797. else
  798. {
  799. // stream to support buffer
  800. ssStreamBuffer1 << "UnknownData" << SDKMC_SSDEC ( UnknownDataIndex, 2 ) << "[ " << SDKMC_SSHEX ( ( pProperty->ElementSize * pProperty->ArrayDim ), 0 ) << " ];";
  801.  
  802. // stream to main buffer
  803. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( "unsigned char", SDK_COL1 ) << " " << SDKMC_SSCOL( ssStreamBuffer1.str(), SDK_COL2 )
  804. << "\t\t// " << SDKMC_SSHEX ( pProperty->Offset, 4 ) << " (" << SDKMC_SSHEX ( ( pProperty->ElementSize * pProperty->ArrayDim ), 4 ) << ") UNKNOWN PROPERTY: " << string ( pProperty->GetFullName() ) << "\n";
  805.  
  806. // empty support buffer
  807. SDKFN_EMPTY ( ssStreamBuffer1 );
  808.  
  809. UnknownDataIndex++;
  810. }
  811.  
  812. // calc new last offset
  813. dwLastOffset = pProperty->Offset + ( pProperty->ElementSize * pProperty->ArrayDim );
  814. }
  815.  
  816. // fix last missed offsets
  817. if ( dwLastOffset < pScriptStruct->PropertySize )
  818. {
  819. dwMissedOffset = pScriptStruct->PropertySize - dwLastOffset;
  820.  
  821. // fix only if missed offset >= CLASS_ALIGN
  822. if ( dwMissedOffset >= CLASS_ALIGN )
  823. {
  824. // stream to support buffer
  825. ssStreamBuffer1 << "UnknownData" << SDKMC_SSDEC ( UnknownDataIndex, 2 ) << "[ " << SDKMC_SSHEX ( dwMissedOffset, 0 ) << " ];";
  826.  
  827. // stream to main buffer
  828. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( "unsigned char", SDK_COL1 ) << " " << SDKMC_SSCOL( ssStreamBuffer1.str(), SDK_COL2 )
  829. << "\t\t// " << SDKMC_SSHEX ( dwLastOffset, 4 ) << " (" << SDKMC_SSHEX ( dwMissedOffset, 4 ) << ") MISSED OFFSET\n";
  830.  
  831. // empty support buffer
  832. SDKFN_EMPTY ( ssStreamBuffer1 );
  833. }
  834. }
  835.  
  836. // stream to main buffer
  837. ssStreamBuffer0 << "};\n\n";
  838.  
  839. // print main stream buffer to file
  840. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  841. }
  842.  
  843. void GenerateScriptStructPre ( UScriptStruct* pScriptStruct, UObject* pPackageToProcess )
  844. {
  845. fprintf ( pLog, "void GenerateScriptStructPre\n" );
  846. // check package object (needed 'cause this function is recursive)
  847. UObject* pPackageObject = pScriptStruct->GetPackageObj();
  848.  
  849. if ( ! pPackageObject || pPackageObject != pPackageToProcess )
  850. {
  851. fprintf ( pLog, " ! pPackageObject || pPackageObject != pPackageToProcess \n" );
  852.  
  853. return;
  854. }
  855.  
  856.  
  857. // skip empty scriptstructs
  858. //if ( pScriptStruct->PropertySize == 0 )
  859. // return;
  860.  
  861. // generated script structs
  862. static vector< string > vGenScriptStructs;
  863.  
  864. // init property names
  865.  
  866. fprintf ( pLog, "GetValidName" );
  867. string sSStructName = GetValidName ( string ( pScriptStruct->GetName() ) );
  868. fprintf ( pLog, " %s\n", sSStructName );
  869. fprintf ( pLog, "sScriptStructFullName " );
  870. string sScriptStructFullName = string ( pScriptStruct->GetFullName() );
  871. fprintf ( pLog, "%s\n", sScriptStructFullName );
  872.  
  873. // remove default script struct
  874. if ( sSStructName.find ( "Default__" ) != string::npos )
  875. return;
  876.  
  877. // remove uninitialized script struct (ME3 fix)
  878. if ( sSStructName.find ( "<uninitialized>" ) != string::npos )
  879. return;
  880.  
  881. // init propertytype
  882. string sPropertyType;
  883.  
  884. // check if already generated
  885. if ( find ( vGenScriptStructs.begin(), vGenScriptStructs.end(), sScriptStructFullName ) == vGenScriptStructs.end() ) // not generated
  886. {
  887.  
  888. fprintf ( pLog, "check if already generated\n" );
  889.  
  890. // check if scriptstruct is duplicated, if it is get the biggest
  891. pScriptStruct = FindBiggestScriptStruct ( sScriptStructFullName );
  892. fprintf ( pLog, "FindBiggestScriptStruct\n" );
  893. // check superfield prerequisites
  894. if
  895. (
  896. pScriptStruct->SuperField
  897. && pScriptStruct->SuperField != pScriptStruct
  898. && find ( vGenScriptStructs.begin(), vGenScriptStructs.end(), string ( ( (UScriptStruct*) ( pScriptStruct->SuperField ) )->GetFullName() ) ) == vGenScriptStructs.end() // not generated
  899. )
  900. {
  901. fprintf ( pLog, "void GenerateScriptStructPreA\n" );
  902. // generate superfield struct
  903. GenerateScriptStructPre ( (UScriptStruct*) ( pScriptStruct->SuperField ), pPackageToProcess );
  904. }
  905.  
  906. // check properties prerequisites
  907. for ( UProperty* pStructProperty = (UProperty*) pScriptStruct->Children; pStructProperty; pStructProperty = (UProperty*) pStructProperty->Next )
  908. {
  909. int iTypeResult = GetPropertyType ( pStructProperty, sPropertyType );
  910. fprintf ( pLog, "check properties prerequisites\n" );
  911. // check structs
  912. if
  913. (
  914. iTypeResult == 3 // struct
  915. && (UScriptStruct*) ( ( (UStructProperty*) pStructProperty )->Struct ) != pScriptStruct // the prerequisite is not itself
  916. && find ( vGenScriptStructs.begin(), vGenScriptStructs.end(), string ( ( (UScriptStruct*) ( ( (UStructProperty*) pStructProperty )->Struct ) )->GetFullName() ) ) == vGenScriptStructs.end() // not generated
  917. )
  918. {
  919. fprintf ( pLog, "void GenerateScriptStructPreB\n" );
  920. // generate property struct
  921. GenerateScriptStructPre ( (UScriptStruct*) ( ( (UStructProperty*) pStructProperty )->Struct ), pPackageToProcess );
  922. }
  923.  
  924. // check array of struct
  925. if
  926. (
  927. iTypeResult == 4 // tarray
  928. && GetPropertyType ( ( (UArrayProperty*) pStructProperty )->Inner, sPropertyType ) == 3 // struct
  929. && (UScriptStruct*) ( ( (UStructProperty*) ( (UArrayProperty*) pStructProperty )->Inner )->Struct ) != pScriptStruct // the prerequisite is not itself
  930. && find ( vGenScriptStructs.begin(), vGenScriptStructs.end(), string ( ( (UScriptStruct*) ( ( (UStructProperty*) ( (UArrayProperty*) pStructProperty )->Inner )->Struct ) )->GetFullName() ) ) == vGenScriptStructs.end() // not generated
  931. )
  932. {
  933. fprintf ( pLog, "void GenerateScriptStructPreC\n" );
  934. // generate property struct
  935. GenerateScriptStructPre ( (UScriptStruct*) ( ( (UStructProperty*) ( (UArrayProperty*) pStructProperty )->Inner )->Struct ), pPackageToProcess );
  936. }
  937.  
  938. // TODO: check TMap
  939. }
  940.  
  941. fprintf ( pLog, "prerequisites ended\n" );
  942. // prerequisites ended
  943. GenerateScriptStruct ( pScriptStruct );
  944. fprintf ( pLog, "vGenScriptStructs\n" );
  945. vGenScriptStructs.push_back ( sScriptStructFullName );
  946. }
  947. }
  948.  
  949. // functions
  950. void GenerateFuncStruct ( UClass* pClass )
  951. {
  952. // stream buffers
  953. ostringstream ssStreamBuffer0; // main stream buffer
  954. ostringstream ssStreamBuffer1; // support stream buffer
  955. ostringstream ssStreamBuffer2; // support stream buffer
  956.  
  957. // function array
  958. vector< UFunction* > vFunction;
  959.  
  960. // get functions
  961. for ( UProperty* pProperty = (UProperty*) pClass->Children; pProperty; pProperty = (UProperty*) pProperty->Next )
  962. {
  963. if ( pProperty->IsA ( UFunction::StaticClass() ) )
  964. {
  965. vFunction.push_back ( (UFunction*) pProperty );
  966. }
  967. }
  968.  
  969. // process functions
  970. for ( unsigned int i = 0; i < vFunction.size(); i++ )
  971. {
  972. UFunction* pFunction = vFunction[ i ];
  973.  
  974. // get function names
  975. string sFunctionFullName = string ( pFunction->GetFullName() );
  976. string sFunctionName = GetValidName ( string ( pFunction->GetName() ) );
  977. string sClassNameCPP = GetValidName ( string ( pClass->GetNameCPP() ) );
  978.  
  979. // stram to support buffer (function flags)
  980. GetAllFunctionFlags ( pFunction->FunctionFlags, ssStreamBuffer1 );
  981.  
  982. // stream to main buffer (function infos + function flags)
  983. ssStreamBuffer0 << "// " << sFunctionFullName << "\n"
  984. << "// [" << SDKMC_SSHEX ( pFunction->FunctionFlags, 8 ) << "] "
  985. << ssStreamBuffer1.str();
  986.  
  987. // empty support buffers
  988. SDKFN_EMPTY ( ssStreamBuffer1 );
  989.  
  990. // stream to main buffer (iNative index)
  991. if ( ( pFunction->FunctionFlags & FUNC_Native ) && pFunction->iNative )
  992. {
  993. ssStreamBuffer0 << " iNative [" << SDKMC_SSHEX ( pFunction->iNative, 4 ) << "]";
  994. }
  995.  
  996. // stream to support buffer (struct name)
  997. if ( pFunction->FunctionFlags & FUNC_Exec ) { ssStreamBuffer1 << "exec"; }
  998. else if ( pFunction->FunctionFlags & FUNC_Event ) { ssStreamBuffer1 << "event"; }
  999. else { ssStreamBuffer1 << "exec"; }
  1000.  
  1001.  
  1002. // stream to main buffer (struct name)
  1003. ssStreamBuffer0 << "\n"
  1004. << "struct " << sClassNameCPP << "_" << ssStreamBuffer1.str() << sFunctionName << "_Parms\n"
  1005. << "{\n";
  1006.  
  1007. // empty support buffers
  1008. SDKFN_EMPTY ( ssStreamBuffer1 );
  1009.  
  1010. // function property array
  1011. vector< UProperty* > vProperty;
  1012.  
  1013. // get function properties
  1014. for ( UProperty* pProperty = (UProperty*) pFunction->Children; pProperty; pProperty = (UProperty*) pProperty->Next )
  1015. {
  1016. if ( pProperty->ElementSize > 0 )
  1017. vProperty.push_back ( pProperty );
  1018. }
  1019.  
  1020. // sort vProperty array using pProperty -> Offset
  1021. sort ( vProperty.begin(), vProperty.end(), SortProperty );
  1022.  
  1023. // property unique name map
  1024. StrIntM_t mPropertyName;
  1025.  
  1026. // stream properties to main buffer
  1027. for ( unsigned int i = 0; i < vProperty.size(); i++ )
  1028. {
  1029. UProperty* pProperty = vProperty[ i ];
  1030.  
  1031. // dec property type
  1032. string sPropertyType;
  1033.  
  1034. if ( GetPropertyType ( pProperty, sPropertyType ) )
  1035. {
  1036. // get property name
  1037. string sPropertyName = GetValidName ( string ( pProperty->GetName() ) );
  1038.  
  1039. // check unique var name
  1040. if ( mPropertyName.count ( sPropertyName ) == 0 ) // not exist
  1041. {
  1042. // insert in unique name array
  1043. mPropertyName[ sPropertyName ] = 1;
  1044.  
  1045. // stream to support buffer (property name)
  1046. ssStreamBuffer1 << sPropertyName;
  1047. }
  1048. else
  1049. {
  1050. // stream to support buffer (name + index)
  1051. ssStreamBuffer1 << sPropertyName << SDKMC_SSDEC ( mPropertyName[ sPropertyName ], 2 );
  1052.  
  1053. // incremente name usage count
  1054. mPropertyName[ sPropertyName ]++;
  1055. }
  1056.  
  1057. // special case array
  1058. if ( pProperty->ArrayDim > 1 )
  1059. {
  1060. // stream to support buffer
  1061. ssStreamBuffer1 << "[ " << SDKMC_SSHEX ( pProperty->ArrayDim, 0 ) << " ]";
  1062. }
  1063.  
  1064. // special case bool
  1065. if ( pProperty->IsA ( UBoolProperty::StaticClass() ) )
  1066. {
  1067. // stream to support buffer
  1068. ssStreamBuffer1 << " : 1";
  1069. }
  1070.  
  1071. // stream to support buffer
  1072. ssStreamBuffer1 << ";";
  1073.  
  1074. // stream property flags to support stream
  1075. GetAllPropertyFlags ( pProperty->PropertyFlags.A, ssStreamBuffer2 );
  1076.  
  1077. // stream to main buffer ( comment not params )
  1078. if ( pProperty->PropertyFlags.A & CPF_Parm ) // only function parms
  1079. {
  1080. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( sPropertyType, SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  1081. << "\t\t// " << SDKMC_SSHEX ( pProperty->Offset, 4 ) << " (" << SDKMC_SSHEX ( ( pProperty->ElementSize * pProperty->ArrayDim ), 4 ) << ") [" << SDKMC_SSHEX ( pProperty->PropertyFlags.A, 16 ) << "]";
  1082. }
  1083. else
  1084. {
  1085. ssStreamBuffer0 << "\t// " << SDKMC_SSCOL ( sPropertyType, ( SDK_COL1 - 3 ) ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  1086. << "\t\t// " << SDKMC_SSHEX ( pProperty->Offset, 4 ) << " (" << SDKMC_SSHEX ( ( pProperty->ElementSize * pProperty->ArrayDim ), 4 ) << ") [" << SDKMC_SSHEX ( pProperty->PropertyFlags.A, 16 ) << "]";
  1087. }
  1088.  
  1089. // stream to main buffer (bitmask)
  1090. if ( pProperty->IsA ( UBoolProperty::StaticClass() ) )
  1091. {
  1092. // stream to support buffer
  1093. ssStreamBuffer0 << " [" << SDKMC_SSHEX ( ( (UBoolProperty*) pProperty )->BitMask, 8 ) << "] ";
  1094. }
  1095. else
  1096. {
  1097. ssStreamBuffer0 << SDKMC_SSCOL ( "", 14 ); // empty space
  1098. }
  1099.  
  1100. ssStreamBuffer0 << ssStreamBuffer2.str() << "\n";
  1101.  
  1102. // empty support buffers
  1103. SDKFN_EMPTY ( ssStreamBuffer1 );
  1104. SDKFN_EMPTY ( ssStreamBuffer2 );
  1105. }
  1106. else
  1107. {
  1108. // get property full name
  1109. string sPropertyFullName = string ( pProperty->GetFullName() );
  1110.  
  1111. // stream to main buffer
  1112. ssStreamBuffer0 << "\t// UNKNOWN PROPERTY: " << sPropertyFullName << "\n";
  1113. }
  1114. }
  1115.  
  1116. // stream to main buffer
  1117. ssStreamBuffer0 << "};\n\n";
  1118. }
  1119.  
  1120. // print main stream buffer to file
  1121. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  1122. }
  1123.  
  1124. void GenerateFuncDef ( UClass* pClass )
  1125. {
  1126. // stream buffers
  1127. ostringstream ssStreamBuffer0; // main stream buffer
  1128. ostringstream ssStreamBuffer1; // support stream buffer
  1129. ostringstream ssStreamBuffer2; // support stream buffer
  1130.  
  1131. // function array
  1132. vector< UFunction* > vFunction;
  1133.  
  1134. // get functions
  1135. for ( UProperty* pProperty = (UProperty*) pClass->Children; pProperty; pProperty = (UProperty*) pProperty->Next )
  1136. {
  1137. if ( pProperty->IsA ( UFunction::StaticClass() ) )
  1138. {
  1139. vFunction.push_back ( (UFunction*) pProperty );
  1140. }
  1141. }
  1142.  
  1143. // process functions
  1144. for ( unsigned int i = 0; i < vFunction.size(); i++ )
  1145. {
  1146. UFunction* pFunction = vFunction[ i ];
  1147.  
  1148. //get function names
  1149. string sFunctionFullName = string ( pFunction->GetFullName() );
  1150. string sFunctionName = GetValidName ( string ( pFunction->GetName() ) );
  1151. string sClassNameCPP = GetValidName ( string ( pClass->GetNameCPP() ) );
  1152.  
  1153. // stram to support buffer (function flags)
  1154. GetAllFunctionFlags ( pFunction->FunctionFlags, ssStreamBuffer1 );
  1155.  
  1156. // stream to main buffer (function infos + function flags)
  1157. ssStreamBuffer0 << "// " << sFunctionFullName << "\n"
  1158. << "// [" << SDKMC_SSHEX ( pFunction->FunctionFlags, 8 ) << "] "
  1159. << ssStreamBuffer1.str();
  1160.  
  1161. // empty support buffers
  1162. SDKFN_EMPTY ( ssStreamBuffer1 );
  1163.  
  1164. // stream to main buffer (iNative index)
  1165. if ( ( pFunction->FunctionFlags & FUNC_Native ) && pFunction->iNative )
  1166. {
  1167. ssStreamBuffer0 << " iNative [" << SDKMC_SSHEX ( pFunction->iNative, 4 ) << "]";
  1168. }
  1169.  
  1170. // funtion property "Parms" array
  1171. vector< pair< UProperty*, string > > vProperty_Parms;
  1172.  
  1173. // function property "OutParms" array
  1174. vector< pair< UProperty*, string > > vProperty_OutParms;
  1175.  
  1176. // function property "ReturnParm"
  1177. pair< UProperty*, string > pProperty_ReturnParm;
  1178.  
  1179. // property unique name map
  1180. StrIntM_t mPropertyName;
  1181.  
  1182. // get function properties
  1183. for ( UProperty* pProperty = (UProperty*) pFunction->Children; pProperty; pProperty = (UProperty*) pProperty->Next )
  1184. {
  1185. if ( pProperty->ElementSize == 0 )
  1186. continue;
  1187.  
  1188. // get property name
  1189. string sPropertyNameBuffer = GetValidName ( string ( pProperty->GetName() ) );
  1190. string sPropertyNameUnique;
  1191.  
  1192. // check unique var name
  1193. if ( mPropertyName.count ( sPropertyNameBuffer ) == 0 ) // not exist
  1194. {
  1195. // insert in unique name array
  1196. mPropertyName[ sPropertyNameBuffer ] = 1;
  1197.  
  1198. // assign unique property name
  1199. sPropertyNameUnique = sPropertyNameBuffer;
  1200. }
  1201. else
  1202. {
  1203. // stream to support buffer (name + index)
  1204. ssStreamBuffer1 << sPropertyNameBuffer << SDKMC_SSDEC ( mPropertyName[ sPropertyNameBuffer ], 2 );
  1205.  
  1206. // assign unique property name
  1207. sPropertyNameUnique = ssStreamBuffer1.str();
  1208.  
  1209. // empty stream buffer
  1210. SDKFN_EMPTY ( ssStreamBuffer1 );
  1211.  
  1212. // incremente name usage count
  1213. mPropertyName[ sPropertyNameBuffer ]++;
  1214. }
  1215.  
  1216. if ( pProperty->PropertyFlags.A & CPF_ReturnParm ) { pProperty_ReturnParm = make_pair ( pProperty, sPropertyNameUnique ); } // property is the return param
  1217. else if ( pProperty->PropertyFlags.A & CPF_OutParm ) { vProperty_OutParms.push_back ( make_pair ( pProperty, sPropertyNameUnique ) ); } // property is a out param
  1218. else if ( pProperty->PropertyFlags.A & CPF_Parm ) { vProperty_Parms.push_back ( make_pair ( pProperty, sPropertyNameUnique ) ); } // property is a in param
  1219. }
  1220.  
  1221. // sort vProperty arrays using pProperty -> Offset
  1222. sort ( vProperty_Parms.begin(), vProperty_Parms.end(), SortPropertyPair );
  1223. sort ( vProperty_OutParms.begin(), vProperty_OutParms.end(), SortPropertyPair );
  1224.  
  1225. // stream to main buffer
  1226. ssStreamBuffer0 << "\n// Parameters infos:\n";
  1227.  
  1228. // property type
  1229. string sPropertyType;
  1230.  
  1231. // stream to main buffer properties infos ( CPF_ReturnParm )
  1232. if ( pProperty_ReturnParm.first && GetPropertyType ( pProperty_ReturnParm.first, sPropertyType, true ) )
  1233. {
  1234. // stram to support buffer (property flags)
  1235. GetAllPropertyFlags ( pProperty_ReturnParm.first->PropertyFlags.A, ssStreamBuffer1 );
  1236.  
  1237. // stream to main buffer (property type + name + flags)
  1238. ssStreamBuffer0 << "// " << SDKMC_SSCOL ( sPropertyType, 30 ) << " " << SDKMC_SSCOL ( pProperty_ReturnParm.second, 30 ) << " " << ssStreamBuffer1.str() << "\n";
  1239.  
  1240. // empty support buffer
  1241. SDKFN_EMPTY ( ssStreamBuffer1 );
  1242. }
  1243.  
  1244. // stream to main buffer properties infos ( CPF_Parm )
  1245. for ( unsigned int i = 0; i < vProperty_Parms.size(); i++ )
  1246. {
  1247. pair< UProperty*, string > pProperty ( vProperty_Parms[ i ] );
  1248.  
  1249. if ( GetPropertyType ( pProperty.first, sPropertyType ) )
  1250. {
  1251. // stram to support buffer (property flags)
  1252. GetAllPropertyFlags ( pProperty.first->PropertyFlags.A, ssStreamBuffer1 );
  1253.  
  1254. // stream to main buffer (property type + name + flags)
  1255. ssStreamBuffer0 << "// " << SDKMC_SSCOL ( sPropertyType, 30 ) << " " << SDKMC_SSCOL ( pProperty.second, 30 ) << " " << ssStreamBuffer1.str() << "\n";
  1256.  
  1257. // empty support buffer
  1258. SDKFN_EMPTY ( ssStreamBuffer1 );
  1259. }
  1260. }
  1261.  
  1262. // stream to main buffer properties infos ( CPF_OutParm )
  1263. for ( unsigned int i = 0; i < vProperty_OutParms.size(); i++ )
  1264. {
  1265. pair< UProperty*, string > pProperty ( vProperty_OutParms[ i ] );
  1266.  
  1267. if ( GetPropertyType ( pProperty.first, sPropertyType ) )
  1268. {
  1269. // stram to support buffer (property flags)
  1270. GetAllPropertyFlags ( pProperty.first->PropertyFlags.A, ssStreamBuffer1 );
  1271.  
  1272. // stream to main buffer (property type + name + flags)
  1273. ssStreamBuffer0 << "// " << SDKMC_SSCOL ( sPropertyType, 30 ) << " " << SDKMC_SSCOL ( pProperty.second, 30 ) << " " << ssStreamBuffer1.str() << "\n";
  1274.  
  1275. // empty support buffer
  1276. SDKFN_EMPTY ( ssStreamBuffer1 );
  1277. }
  1278. }
  1279.  
  1280. // stream to main buffer return type
  1281. if ( pProperty_ReturnParm.first && GetPropertyType ( pProperty_ReturnParm.first, sPropertyType, true ) )
  1282. {
  1283. ssStreamBuffer0 << "\n" << sPropertyType;
  1284. }
  1285. else
  1286. {
  1287. ssStreamBuffer0 << "\nvoid";
  1288. }
  1289.  
  1290. // stream to main buffer function name
  1291. if ( pFunction->FunctionFlags & FUNC_Exec ) { ssStreamBuffer0 << " " << sClassNameCPP << "::" << sFunctionName << " ("; }
  1292. else if ( pFunction -> FunctionFlags & FUNC_Event ) { ssStreamBuffer0 << " " << sClassNameCPP << "::event" << sFunctionName << " ("; }
  1293. else { ssStreamBuffer0 << " " << sClassNameCPP << "::" << sFunctionName << " ("; }
  1294.  
  1295. // init comma flag
  1296. bool bPrintComma = false;
  1297.  
  1298. // stream to main buffer properties ( CPF_Parm )
  1299. for ( unsigned int i = 0; i < vProperty_Parms.size(); i++ )
  1300. {
  1301. pair< UProperty*, string > pProperty ( vProperty_Parms[ i ] );
  1302.  
  1303. if ( GetPropertyType ( pProperty.first, sPropertyType ) )
  1304. {
  1305. // stream to main buffer (comma)
  1306. if ( bPrintComma ) { ssStreamBuffer0 << ","; }
  1307.  
  1308. // special case array
  1309. if ( pProperty.first->ArrayDim > 1 )
  1310. {
  1311. // stream to main buffer (property type + name)
  1312. ssStreamBuffer0 << " " << sPropertyType << "* " << pProperty.second;
  1313. }
  1314. else
  1315. {
  1316. // stream to main buffer (property type + name)
  1317. ssStreamBuffer0 << " " << sPropertyType << " " << pProperty.second;
  1318. }
  1319.  
  1320. // set comma flag
  1321. bPrintComma = true;
  1322. }
  1323. }
  1324.  
  1325. // stream to main buffer properties ( CPF_OutParm )
  1326. for ( unsigned int i = 0; i < vProperty_OutParms.size(); i++ )
  1327. {
  1328. pair< UProperty*, string > pProperty ( vProperty_OutParms[ i ] );
  1329.  
  1330. if ( GetPropertyType ( pProperty.first, sPropertyType ) )
  1331. {
  1332. // stream to main buffer (comma)
  1333. if ( bPrintComma ) { ssStreamBuffer0 << ","; }
  1334.  
  1335. // stream to main buffer (property type* + name)
  1336. ssStreamBuffer0 << " " << sPropertyType << "* " << pProperty.second;
  1337.  
  1338. // set comma flag
  1339. bPrintComma = true;
  1340. }
  1341. }
  1342.  
  1343. // stream to main buffer function
  1344. if ( SDK_NO_STR )
  1345. {
  1346. ssStreamBuffer0 << " )\n{\n" // open function
  1347. << "\tstatic UFunction* pFn" << sFunctionName << " = NULL;\n\n" // function static pointer
  1348. << "\tif ( ! pFn" << sFunctionName << " )\n" // init function static pointer
  1349. << "\t\tpFn" << sFunctionName << " = (UFunction*) UObject::GObjObjects()->Data[ " << SDKMC_SSDEC( pFunction->ObjectInternalInteger, 0 ) << " ];\n\n"
  1350. << "\t" << sClassNameCPP << "_"; // params struct
  1351. }
  1352. else
  1353. {
  1354. ssStreamBuffer0 << " )\n{\n" // open function
  1355. << "\tstatic UFunction* pFn" << sFunctionName << " = NULL;\n\n" // function static pointer
  1356. << "\tif ( ! pFn" << sFunctionName << " )\n" // init function static pointer
  1357. << "\t\tpFn" << sFunctionName << " = UObject::FindObject< UFunction > ( \"" << sFunctionFullName << "\" );\n\n"
  1358. << "\t" << sClassNameCPP << "_"; // params struct
  1359. }
  1360.  
  1361. // params struct
  1362. if ( pFunction->FunctionFlags & FUNC_Exec ) { ssStreamBuffer0 << "exec"; }
  1363. else if ( pFunction->FunctionFlags & FUNC_Event ) { ssStreamBuffer0 << "event"; }
  1364. else { ssStreamBuffer0 << "exec"; }
  1365.  
  1366. // params struct
  1367. ssStreamBuffer0 << sFunctionName << "_Parms " << sFunctionName << "_Parms;\n";
  1368.  
  1369. // stream to main buffer (populate parms struct) ( CPF_Parm )
  1370. for ( unsigned int i = 0; i < vProperty_Parms.size(); i++ )
  1371. {
  1372. pair< UProperty*, string > pProperty ( vProperty_Parms[ i ] );
  1373.  
  1374. int iTypeResult = GetPropertyType ( pProperty.first, sPropertyType );
  1375.  
  1376. if ( iTypeResult > 1 || pProperty.first->ArrayDim > 1 ) // struct, tarray, tmap OR array
  1377. {
  1378. ssStreamBuffer0 << "\tmemcpy ( &" << sFunctionName << "_Parms." << pProperty.second << ", &" << pProperty.second << ", " << SDKMC_SSHEX ( ( pProperty.first->ElementSize * pProperty.first->ArrayDim ), 0 ) << " );\n";
  1379. }
  1380. else if ( iTypeResult == 1 ) // dword, byte, string, ecc.
  1381. {
  1382. ssStreamBuffer0 << "\t" << sFunctionName << "_Parms." << pProperty.second << " = " << pProperty.second << ";\n";
  1383. }
  1384. }
  1385.  
  1386. // stream to main buffer (function native tricks)
  1387. if ( ( pFunction->FunctionFlags & FUNC_Native ) && pFunction->iNative )
  1388. {
  1389. ssStreamBuffer0 << "\n\tunsigned short NativeIndex = pFn" << sFunctionName << "->iNative;\n"
  1390. << "\tpFn" << sFunctionName << "->iNative = 0;\n";
  1391. }
  1392.  
  1393. // stream to main buffer (function native tricks)
  1394. if ( pFunction->FunctionFlags & FUNC_Native )
  1395. {
  1396. ssStreamBuffer0 << "\n\tpFn" << sFunctionName << "->FunctionFlags |= ~" << SDKMC_SSHEX ( FUNC_Native, 0 ) << ";\n";
  1397. }
  1398.  
  1399. // stream to main buffer (call process event)
  1400. ssStreamBuffer0 << "\n\tthis->ProcessEvent ( pFn" << sFunctionName << ", &" << sFunctionName << "_Parms, NULL );\n";
  1401.  
  1402. // stream to main buffer (reset function native tricks)
  1403. if ( pFunction -> FunctionFlags & FUNC_Native )
  1404. {
  1405. ssStreamBuffer0 << "\n\tpFn" << sFunctionName << "->FunctionFlags |= " << SDKMC_SSHEX ( FUNC_Native, 0 ) << ";\n";
  1406. }
  1407.  
  1408. // stream to main buffer (reset function native tricks)
  1409. if ( ( pFunction -> FunctionFlags & FUNC_Native ) && pFunction -> iNative )
  1410. {
  1411. ssStreamBuffer0 << "\n\tpFn" << sFunctionName << "->iNative = NativeIndex;\n";
  1412. }
  1413.  
  1414. // stream to main buffer (populate CPF_OutParm)
  1415. for ( unsigned int i = 0; i < vProperty_OutParms.size(); i++ )
  1416. {
  1417. pair< UProperty*, string > pProperty ( vProperty_OutParms[ i ] );
  1418.  
  1419. // stream to main buffer (if outparm)
  1420. ssStreamBuffer0 << "\n\tif ( " << pProperty.second << " )\n";
  1421.  
  1422. int iTypeResult = GetPropertyType ( pProperty.first, sPropertyType );
  1423.  
  1424. if ( iTypeResult > 1 || pProperty.first->ArrayDim > 1 ) // struct, tarray, tmap OR array
  1425. {
  1426. ssStreamBuffer0 << "\t\tmemcpy ( " << pProperty.second << ", &" << sFunctionName << "_Parms." << pProperty.second << ", " << SDKMC_SSHEX ( ( pProperty.first->ElementSize * pProperty.first->ArrayDim ), 0 ) << " );\n";
  1427. }
  1428. else if ( iTypeResult == 1 ) // dword, byte, string, ecc.
  1429. {
  1430. ssStreamBuffer0 << "\t\t*" << pProperty.second << " = " << sFunctionName << "_Parms." << pProperty.second << ";\n";
  1431. }
  1432. }
  1433.  
  1434. // stream to main buffer (return value)
  1435. if ( pProperty_ReturnParm.first && GetPropertyType ( pProperty_ReturnParm.first, sPropertyType ) )
  1436. {
  1437. ssStreamBuffer0 << "\n\treturn " << sFunctionName << "_Parms." << pProperty_ReturnParm.second << ";\n";
  1438. }
  1439.  
  1440. // stream to main buffer (function close)
  1441. ssStreamBuffer0 << "};\n\n";
  1442. }
  1443.  
  1444. // print main stream buffer to file
  1445. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  1446. }
  1447.  
  1448. void GenerateFuncDec ( UClass* pClass )
  1449. {
  1450. // stream buffers
  1451. ostringstream ssStreamBuffer0; // main stream buffer
  1452. ostringstream ssStreamBuffer1; // support stream buffer
  1453. ostringstream ssStreamBuffer2; // support stream buffer
  1454.  
  1455. // function array
  1456. vector< UFunction* > vFunction;
  1457.  
  1458. // get functions
  1459. for ( UProperty* pProperty = (UProperty*) pClass->Children; pProperty; pProperty = (UProperty*) pProperty->Next )
  1460. {
  1461. if ( pProperty->IsA ( UFunction::StaticClass() ) )
  1462. {
  1463. vFunction.push_back ( (UFunction*) pProperty );
  1464. }
  1465. }
  1466.  
  1467. // process functions
  1468. for ( unsigned int i = 0; i < vFunction.size(); i++ )
  1469. {
  1470. UFunction* pFunction = vFunction[ i ];
  1471.  
  1472. //get function names
  1473. string sFunctionName = GetValidName ( string ( pFunction->GetName() ) );
  1474.  
  1475. // funtion property "Parms" array
  1476. vector< pair< UProperty*, string > > vProperty_Parms;
  1477.  
  1478. // function property "OutParms" array
  1479. vector< pair< UProperty*, string > > vProperty_OutParms;
  1480.  
  1481. // function property "ReturnParm"
  1482. pair< UProperty*, string > pProperty_ReturnParm;
  1483.  
  1484. // property unique name map
  1485. StrIntM_t mPropertyName;
  1486.  
  1487. // get function properties
  1488. for ( UProperty* pProperty = (UProperty*) pFunction->Children; pProperty; pProperty = (UProperty*) pProperty->Next )
  1489. {
  1490. if ( pProperty->ElementSize == 0 )
  1491. continue;
  1492.  
  1493. // get property name
  1494. string sPropertyNameBuffer = GetValidName ( string ( pProperty->GetName() ) );
  1495. string sPropertyNameUnique;
  1496.  
  1497. // check unique var name
  1498. if ( mPropertyName.count ( sPropertyNameBuffer ) == 0 ) // not exist
  1499. {
  1500. // insert in unique name array
  1501. mPropertyName[ sPropertyNameBuffer ] = 1;
  1502.  
  1503. // assign unique property name
  1504. sPropertyNameUnique = sPropertyNameBuffer;
  1505. }
  1506. else
  1507. {
  1508. // stream to support buffer (name + index)
  1509. ssStreamBuffer1 << sPropertyNameBuffer << SDKMC_SSDEC ( mPropertyName[ sPropertyNameBuffer ], 2 );
  1510.  
  1511. // assign unique property name
  1512. sPropertyNameUnique = ssStreamBuffer1.str();
  1513.  
  1514. // empty stream buffer
  1515. SDKFN_EMPTY ( ssStreamBuffer1 );
  1516.  
  1517. // incremente name usage count
  1518. mPropertyName[ sPropertyNameBuffer ]++;
  1519. }
  1520.  
  1521. if ( pProperty->PropertyFlags.A & CPF_ReturnParm ) { pProperty_ReturnParm = make_pair ( pProperty, sPropertyNameUnique ); } // property is the return param
  1522. else if ( pProperty->PropertyFlags.A & CPF_OutParm ) { vProperty_OutParms.push_back ( make_pair ( pProperty, sPropertyNameUnique ) ); } // property is a out param
  1523. else if ( pProperty->PropertyFlags.A & CPF_Parm ) { vProperty_Parms.push_back ( make_pair ( pProperty, sPropertyNameUnique ) ); } // property is a in param
  1524. }
  1525.  
  1526. // sort vProperty arrays using pProperty -> Offset
  1527. sort ( vProperty_Parms.begin(), vProperty_Parms.end(), SortPropertyPair );
  1528. sort ( vProperty_OutParms.begin(), vProperty_OutParms.end(), SortPropertyPair );
  1529.  
  1530. // property type
  1531. string sPropertyType;
  1532.  
  1533. // stream to main buffer return type
  1534. if ( pProperty_ReturnParm.first && GetPropertyType ( pProperty_ReturnParm.first, sPropertyType, true ) )
  1535. {
  1536. ssStreamBuffer0 << "\t" << sPropertyType;
  1537. }
  1538. else
  1539. {
  1540. ssStreamBuffer0 << "\tvoid";
  1541. }
  1542.  
  1543. // stream to main buffer function name
  1544. if ( pFunction->FunctionFlags & FUNC_Exec ) { ssStreamBuffer0 << " " << sFunctionName << " ("; }
  1545. else if ( pFunction->FunctionFlags & FUNC_Event ) { ssStreamBuffer0 << " event" << sFunctionName << " ("; }
  1546. else { ssStreamBuffer0 << " " << sFunctionName << " ("; }
  1547.  
  1548. // init comma flag
  1549. bool bPrintComma = false;
  1550.  
  1551. // stream to main buffer properties ( CPF_Parm )
  1552. for ( unsigned int i = 0; i < vProperty_Parms.size(); i++ )
  1553. {
  1554. pair< UProperty*, string > pProperty ( vProperty_Parms[ i ] );
  1555.  
  1556. if ( GetPropertyType ( pProperty.first, sPropertyType ) )
  1557. {
  1558. // stream to main buffer (comma)
  1559. if ( bPrintComma ) { ssStreamBuffer0 << ","; }
  1560.  
  1561. // special case array
  1562. if ( pProperty.first->ArrayDim > 1 )
  1563. {
  1564. // stream to main buffer (property type + name)
  1565. ssStreamBuffer0 << " " << sPropertyType << "* " << pProperty.second;
  1566. }
  1567. else
  1568. {
  1569. // stream to main buffer (property type + name)
  1570. ssStreamBuffer0 << " " << sPropertyType << " " << pProperty.second;
  1571. }
  1572.  
  1573. // set comma flag
  1574. bPrintComma = true;
  1575. }
  1576. }
  1577.  
  1578. // stream to main buffer properties ( CPF_OutParm )
  1579. for ( unsigned int i = 0; i < vProperty_OutParms.size(); i++ )
  1580. {
  1581. pair< UProperty*, string > pProperty ( vProperty_OutParms[ i ] );
  1582.  
  1583. if ( GetPropertyType ( pProperty.first, sPropertyType ) )
  1584. {
  1585. // stream to main buffer (comma)
  1586. if ( bPrintComma ) { ssStreamBuffer0 << ","; }
  1587.  
  1588. // stream to main buffer (property type* + name)
  1589. ssStreamBuffer0 << " " << sPropertyType << "* " << pProperty.second;
  1590.  
  1591. // set comma flag
  1592. bPrintComma = true;
  1593. }
  1594. }
  1595.  
  1596. // stream to main buffer
  1597. ssStreamBuffer0 << " );\n";
  1598. }
  1599.  
  1600. // print main stream buffer to file
  1601. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  1602. }
  1603.  
  1604. void GenerateVirtualFunc ( UClass* pClass )
  1605. {
  1606. // stream buffers
  1607. ostringstream ssStreamBuffer0; // main stream buffer
  1608. ostringstream ssStreamBuffer1; // support stream buffer
  1609. ostringstream ssStreamBuffer2; // support stream buffer
  1610.  
  1611. // stream to main buffer
  1612. ssStreamBuffer0 << "\n\t// Virtual Functions\n";
  1613.  
  1614. unsigned long VfTable = (unsigned long) ( pClass->VfTableObject.Dummy );
  1615.  
  1616. for ( unsigned long i = 0x0; i < 0x400; i += 0x4 )
  1617. {
  1618. // check if pointed function is the ProcessEvent
  1619. if ( TFLHACKT00LS::FindPattern( *(unsigned long*) ( VfTable + i ), 0x200, (unsigned char*) ProcessEvent_Pattern, (char*) ProcessEvent_Mask ) )
  1620. {
  1621. // stream to main buffer (virtual function ProcessEvent)
  1622. ssStreamBuffer0 << "\tvirtual void ProcessEvent ( class UFunction* pFunction, void* pParms, void* pResult = NULL );\t\t\t\t// " << SDKMC_SSHEX ( ( *(unsigned long*) ( VfTable + i ) ), 8 ) << " (" << SDKMC_SSHEX ( i, 2 ) << ")\n";
  1623.  
  1624. break;
  1625. }
  1626. else
  1627. {
  1628. // stream to main buffer (virtual functions padding)
  1629. ssStreamBuffer0 << "\tvirtual void VirtualFunction" << SDKMC_SSDEC ( ( i / 0x4 ), 2 ) << " ( );\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// " << SDKMC_SSHEX ( ( *(unsigned long*) ( VfTable + i ) ), 8 ) << " (" << SDKMC_SSHEX ( i, 2 ) << ")\n";
  1630. }
  1631. }
  1632.  
  1633. // print main stream buffer to file
  1634. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  1635. }
  1636.  
  1637. // classes
  1638. void GenerateClass ( UClass* pClass )
  1639. {
  1640. // stream buffers
  1641. ostringstream ssStreamBuffer0; // main stream buffer
  1642. ostringstream ssStreamBuffer1; // support stream buffer
  1643. ostringstream ssStreamBuffer2; // support stream buffer
  1644.  
  1645. // vars
  1646. DWORD dwSize = 0;
  1647. DWORD dwLastOffset = 0;
  1648. DWORD dwMissedOffset = 0;
  1649.  
  1650. // get suoerfield
  1651. UClass* pSuperClass = ( UClass* ) pClass->SuperField;
  1652.  
  1653. // get class names
  1654. string sClassName = GetValidName ( string ( pClass->GetName() ) );
  1655. string sClassNameCPP = GetValidName ( string ( pClass->GetNameCPP() ) );
  1656. string sClassFullName = string ( pClass->GetFullName() );
  1657.  
  1658. // log
  1659. fprintf ( pLog, "Class: %-100s - instance: 0x%08X\n", sClassName.c_str(), pClass );
  1660.  
  1661. // property array
  1662. vector< UProperty* > vProperty;
  1663.  
  1664. // get class properties
  1665. for ( UProperty* pProperty = (UProperty*) pClass->Children; pProperty; pProperty = (UProperty*) pProperty->Next )
  1666. {
  1667. if
  1668. (
  1669. ! pProperty->IsA ( UFunction::StaticClass() )
  1670. && ! pProperty->IsA ( UConst::StaticClass() )
  1671. && ! pProperty->IsA ( UEnum::StaticClass() )
  1672. && ! pProperty->IsA ( UScriptStruct::StaticClass() )
  1673. && pProperty->ElementSize > 0
  1674. && // additional checks for ME3
  1675. (
  1676. ! pSuperClass
  1677. ||
  1678. (
  1679. pSuperClass
  1680. && pSuperClass != pClass
  1681. && pProperty->Offset >= pSuperClass->PropertySize
  1682. )
  1683. )
  1684. )
  1685. {
  1686. vProperty.push_back ( pProperty );
  1687. }
  1688. }
  1689.  
  1690. // sort vProperty array using pProperty -> Offset
  1691. sort ( vProperty.begin(), vProperty.end(), SortProperty );
  1692.  
  1693. // stream to main buffer (infos)
  1694. ssStreamBuffer0 << "// " << sClassFullName << "\n";
  1695.  
  1696. // print class
  1697. if ( pSuperClass && pSuperClass != pClass )
  1698. {
  1699. // calculations
  1700. dwSize = pClass->PropertySize - pSuperClass->PropertySize;
  1701. dwLastOffset = pSuperClass->PropertySize;
  1702.  
  1703. // get superfield name
  1704. string sSuperClassNameCPP = GetValidName ( string ( pSuperClass->GetNameCPP() ) );
  1705.  
  1706. // stream to main buffer (class size + class name)
  1707. ssStreamBuffer0 << "// " << SDKMC_SSHEX ( dwSize, 4 ) << " (" << SDKMC_SSHEX ( pClass->PropertySize, 4 ) << " - " << SDKMC_SSHEX( pSuperClass->PropertySize, 4 ) << ")\n"
  1708. << "class " << sClassNameCPP << " : public " << sSuperClassNameCPP;
  1709. }
  1710. else
  1711. {
  1712. // calculations
  1713. dwSize = pClass->PropertySize;
  1714.  
  1715. // stream to main buffer (class size + class name)
  1716. ssStreamBuffer0 << "// " << SDKMC_SSHEX ( dwSize, 4 ) << "\n"
  1717. << "class " << sClassNameCPP;
  1718. }
  1719.  
  1720. // stream to main buffer (class open)
  1721. ssStreamBuffer0 << "\n{\npublic:\n";
  1722.  
  1723. if ( false ) {}
  1724.  
  1725. // special classes that need to be filled manualy
  1726. #ifdef CLASS_PROPERTIES_UFIELD
  1727. else if ( pClass == UObject::FindClass ( "Class Core.Field" ) ) // UField
  1728. ssStreamBuffer0 << CLASS_PROPERTIES_UFIELD;
  1729. #endif
  1730.  
  1731. #ifdef CLASS_PROPERTIES_UFUNCTION
  1732. else if ( pClass == UObject::FindClass ( "Class Core.Function" ) ) // UFunction
  1733. ssStreamBuffer0 << CLASS_PROPERTIES_UFUNCTION;
  1734. #endif
  1735.  
  1736. #ifdef CLASS_PROPERTIES_USTRUCT
  1737. else if ( pClass == UObject::FindClass ( "Class Core.Struct" ) ) // UStruct
  1738. ssStreamBuffer0 << CLASS_PROPERTIES_USTRUCT;
  1739. #endif
  1740.  
  1741. else // normal classes
  1742. {
  1743. // property unique name array
  1744. StrIntM_t mPropertyName;
  1745.  
  1746. // unknown data unique name index
  1747. int UnknownDataIndex = 0;
  1748.  
  1749. // process class properties
  1750. for ( unsigned int i = 0; i < vProperty.size(); i++ )
  1751. {
  1752. UProperty* pProperty = vProperty[ i ];
  1753.  
  1754. // fix missed offsets
  1755. if ( dwLastOffset < pProperty->Offset )
  1756. {
  1757. dwMissedOffset = pProperty->Offset - dwLastOffset;
  1758.  
  1759. // fix only if missed offset >= CLASS_ALIGN
  1760. if ( dwMissedOffset >= CLASS_ALIGN )
  1761. {
  1762. // stream to support buffer
  1763. ssStreamBuffer1 << "UnknownData" << SDKMC_SSDEC ( UnknownDataIndex, 2 ) << "[ " << SDKMC_SSHEX ( dwMissedOffset, 0 ) << " ];";
  1764.  
  1765. // stream to main buffer
  1766. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( "unsigned char", SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  1767. << "\t\t// " << SDKMC_SSHEX ( dwLastOffset, 4 ) << " (" << SDKMC_SSHEX ( dwMissedOffset, 4 ) << ") MISSED OFFSET\n";
  1768.  
  1769. // empty support buffer
  1770. SDKFN_EMPTY ( ssStreamBuffer1 );
  1771.  
  1772. UnknownDataIndex++;
  1773. }
  1774. }
  1775.  
  1776. // declare property type
  1777. string sPropertyType;
  1778.  
  1779. // strem properties to main buffer
  1780. if ( GetPropertyType ( pProperty, sPropertyType ) )
  1781. {
  1782. // get correct element size
  1783. unsigned long dwCorrectElementSize = GetPropertySize ( pProperty );
  1784.  
  1785. // get property name
  1786. string sPropertyName = GetValidName ( string ( pProperty->GetName() ) );
  1787.  
  1788. // check unique var name
  1789. if ( mPropertyName.count ( sPropertyName ) == 0 ) // not exist
  1790. {
  1791. // insert in unique name array
  1792. mPropertyName[ sPropertyName ] = 1;
  1793.  
  1794. // stream to support buffer (property name)
  1795. ssStreamBuffer1 << sPropertyName;
  1796. }
  1797. else
  1798. {
  1799. // stream to support buffer (name + index)
  1800. ssStreamBuffer1 << sPropertyName << SDKMC_SSDEC ( mPropertyName[ sPropertyName ], 2 );
  1801.  
  1802. // incremente name usage count
  1803. mPropertyName[ sPropertyName ]++;
  1804. }
  1805.  
  1806. // special case array
  1807. if ( pProperty->ArrayDim > 1 )
  1808. {
  1809. // stream to support buffer
  1810. ssStreamBuffer1 << "[ " << SDKMC_SSHEX ( pProperty->ArrayDim, 0 ) << " ]";
  1811. }
  1812.  
  1813. // special case bool
  1814. if ( pProperty->IsA ( UBoolProperty::StaticClass() ) )
  1815. {
  1816. // stream to support buffer
  1817. ssStreamBuffer1 << " : 1";
  1818. }
  1819.  
  1820. // stream to support buffer
  1821. ssStreamBuffer1 << ";";
  1822.  
  1823. // stream property flags to support stream
  1824. GetAllPropertyFlags ( pProperty->PropertyFlags.A, ssStreamBuffer2 );
  1825.  
  1826. // stream to main buffer
  1827. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( sPropertyType, SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  1828. << "\t\t// " << SDKMC_SSHEX ( pProperty->Offset, 4 ) << " (" << SDKMC_SSHEX ( ( pProperty->ElementSize * pProperty->ArrayDim ), 4 ) << ") [" << SDKMC_SSHEX ( pProperty->PropertyFlags.A, 16 ) << "]";
  1829.  
  1830. // stream to main buffer (bitmask)
  1831. if ( pProperty->IsA ( UBoolProperty::StaticClass() ) )
  1832. {
  1833. // stream to support buffer
  1834. ssStreamBuffer0 << " [" << SDKMC_SSHEX ( ( (UBoolProperty*) pProperty )->BitMask, 8 ) << "] ";
  1835. }
  1836. else
  1837. {
  1838. ssStreamBuffer0 << SDKMC_SSCOL ( "", 14 ); // empty space
  1839. }
  1840.  
  1841. ssStreamBuffer0 << ssStreamBuffer2.str() << "\n";
  1842.  
  1843. // empty support buffers
  1844. SDKFN_EMPTY( ssStreamBuffer1 );
  1845. SDKFN_EMPTY( ssStreamBuffer2 );
  1846.  
  1847. // check if property size and type size are egual otherwise add pad data
  1848. int nOffserError = ( pProperty->ElementSize * pProperty->ArrayDim ) - ( dwCorrectElementSize * pProperty->ArrayDim );
  1849.  
  1850. // correct wrong size elements
  1851. if ( nOffserError > 0 )
  1852. {
  1853. // stream to support buffer
  1854. ssStreamBuffer1 << "UnknownData" << SDKMC_SSDEC ( UnknownDataIndex, 2 ) << "[ " << SDKMC_SSHEX ( nOffserError, 0 ) << " ];";
  1855.  
  1856. // stream to main buffer
  1857. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( "unsigned char", SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  1858. << "\t\t// " << SDKMC_SSHEX ( ( pProperty->Offset + nOffserError ), 4 ) << " (" << SDKMC_SSHEX ( nOffserError, 4 ) << ") FIX WRONG TYPE SIZE OF PREVIUS PROPERTY\n";
  1859.  
  1860. // empty support buffers
  1861. SDKFN_EMPTY ( ssStreamBuffer1 );
  1862.  
  1863. UnknownDataIndex++;
  1864. }
  1865. }
  1866. else
  1867. {
  1868. // stream to support buffer
  1869. ssStreamBuffer1 << "UnknownData" << SDKMC_SSDEC ( UnknownDataIndex, 2 ) << "[ " << SDKMC_SSHEX ( ( pProperty->ElementSize * pProperty->ArrayDim ), 0 ) << " ];";
  1870.  
  1871. // stream to main buffer
  1872. ssStreamBuffer0 << "\t" << SDKMC_SSCOL( "unsigned char", SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  1873. << "\t\t// " << SDKMC_SSHEX ( pProperty->Offset, 4 ) << " (" << SDKMC_SSHEX ( ( pProperty->ElementSize * pProperty->ArrayDim ), 4 ) << ") UNKNOWN PROPERTY: " << string ( pProperty->GetFullName() ) << "\n";
  1874.  
  1875. // empty support buffer
  1876. SDKFN_EMPTY ( ssStreamBuffer1 );
  1877.  
  1878. UnknownDataIndex++;
  1879. }
  1880.  
  1881. // calc new last offset
  1882. dwLastOffset = pProperty->Offset + ( pProperty->ElementSize * pProperty->ArrayDim );
  1883. }
  1884.  
  1885. // fix last missed offsets
  1886. if ( dwLastOffset < pClass->PropertySize )
  1887. {
  1888. dwMissedOffset = pClass->PropertySize - dwLastOffset;
  1889.  
  1890. // fix only if missed offset >= CLASS_ALIGN
  1891. if ( dwMissedOffset >= CLASS_ALIGN )
  1892. {
  1893. // stream to support buffer
  1894. ssStreamBuffer1 << "UnknownData" << SDKMC_SSDEC ( UnknownDataIndex, 2 ) << "[ " << SDKMC_SSHEX ( dwMissedOffset, 0 ) << " ];";
  1895.  
  1896. // stream to main buffer
  1897. ssStreamBuffer0 << "\t" << SDKMC_SSCOL ( "unsigned char", SDK_COL1 ) << " " << SDKMC_SSCOL ( ssStreamBuffer1.str(), SDK_COL2 )
  1898. << "\t\t// " << SDKMC_SSHEX ( dwLastOffset, 4 ) << " (" << SDKMC_SSHEX ( dwMissedOffset, 4 ) << ") MISSED OFFSET\n";
  1899.  
  1900. // empty support buffer
  1901. SDKFN_EMPTY ( ssStreamBuffer1 );
  1902. }
  1903. }
  1904. }
  1905.  
  1906. // stream to main buffer
  1907. ssStreamBuffer0 << "\nprivate:\n"
  1908. << "\tstatic UClass* pClassPointer;\n\n" // static class pointer
  1909. << "public:\n";
  1910.  
  1911. // print basic functions declaretion
  1912. if ( pClass == UObject::FindClass ( "Class Core.Object" ) )
  1913. ssStreamBuffer0 << BASIC_FUNCTIONS_DEC;
  1914.  
  1915. // stream to main buffer (static class function)
  1916. if ( SDK_NO_STR )
  1917. {
  1918. ssStreamBuffer0 << "\tstatic UClass* StaticClass()\n"
  1919. << "\t{\n"
  1920. << "\t\tif ( ! pClassPointer )\n"
  1921. << "\t\t\tpClassPointer = (UClass*) UObject::GObjObjects()->Data[ " << SDKMC_SSDEC( pClass->ObjectInternalInteger, 0 ) << " ];\n\n"
  1922. << "\t\treturn pClassPointer;\n"
  1923. << "\t};\n\n";
  1924. }
  1925. else
  1926. {
  1927. ssStreamBuffer0 << "\tstatic UClass* StaticClass()\n"
  1928. << "\t{\n"
  1929. << "\t\tif ( ! pClassPointer )\n"
  1930. << "\t\t\tpClassPointer = UObject::FindClass ( \"" << sClassFullName << "\" );\n\n"
  1931. << "\t\treturn pClassPointer;\n"
  1932. << "\t};\n\n";
  1933. }
  1934.  
  1935. // print main stream buffer to file
  1936. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  1937.  
  1938. // print functions declaretion
  1939. GenerateFuncDec ( pClass );
  1940.  
  1941. // print virtual functions
  1942. if ( pClass == UObject::FindClass ( "Class Core.Object" ) )
  1943. GenerateVirtualFunc ( pClass );
  1944.  
  1945. // stream to main buffer
  1946. ssStreamBuffer0 << "};\n\n" // close class
  1947. << "UClass* " << sClassNameCPP << "::pClassPointer = NULL;\n\n"; // init static pointer
  1948.  
  1949. // print main stream buffer to file
  1950. SDKFN_PRINT ( pFile, ssStreamBuffer0 );
  1951. }
  1952.  
  1953. void GenerateClassPre ( UClass* pClass, UObject* pPackageToProcess )
  1954. {
  1955. UObject* pPackageObject = pClass->GetPackageObj();
  1956.  
  1957. if ( ! pPackageObject ) // check package object (needed 'cause this function is recursive)
  1958. return;
  1959.  
  1960. // put PackagetoProcess in include vector (if not present)
  1961. if ( find ( vIncludes.begin(), vIncludes.end(), pPackageToProcess ) == vIncludes.end() )
  1962. vIncludes.push_back ( pPackageToProcess );
  1963.  
  1964.  
  1965. if ( pPackageObject != pPackageToProcess ) // that means that the required class is in another package
  1966. {
  1967. // check if pPackageObject exist and is already before pPackageToProcess
  1968. vector< UObject* >::iterator itPO = find ( vIncludes.begin(), vIncludes.end(), pPackageObject );
  1969. vector< UObject* >::iterator itPTP = find ( vIncludes.begin(), vIncludes.end(), pPackageToProcess );
  1970.  
  1971. if ( itPO == vIncludes.end() ) // required class package not present
  1972. {
  1973. // insert pPackageObject before pPackageToProcess
  1974. vIncludes.insert ( itPTP, pPackageObject );
  1975. }
  1976. else if ( itPO >= itPTP ) // required class package is after this package
  1977. {
  1978. // insert pPackageObject before pPackageToProcess
  1979. vIncludes.insert ( itPTP, pPackageObject );
  1980.  
  1981. // delete old one
  1982. vIncludes.erase ( itPO );
  1983. }
  1984.  
  1985. return;
  1986. }
  1987.  
  1988. // generated script structs
  1989. static vector< string > vGenClass;
  1990.  
  1991. // init property names
  1992. string sClassName = GetValidName ( string ( pClass->GetName() ) );
  1993. string sClassFullName = string ( pClass->GetFullName() );
  1994.  
  1995. // remove default class
  1996. if ( sClassName.find ( "Default__" ) != string::npos )
  1997. return;
  1998.  
  1999. // check if already generated
  2000. if ( find ( vGenClass.begin(), vGenClass.end(), string ( pClass->GetFullName() ) ) == vGenClass.end() ) // not generated
  2001. {
  2002. // check superfield prerequisites
  2003. if
  2004. (
  2005. pClass->SuperField
  2006. && pClass->SuperField != pClass
  2007. && find ( vGenClass.begin(), vGenClass.end(), string ( pClass->SuperField->GetFullName() ) ) == vGenClass.end() // not generated
  2008. )
  2009. {
  2010. // generate superfield class
  2011. GenerateClassPre ( (UClass*) ( pClass->SuperField ), pPackageToProcess );
  2012. }
  2013.  
  2014. // prerequisites ended
  2015. GenerateClass ( pClass );
  2016. vGenClass.push_back ( sClassFullName );
  2017. }
  2018. }
  2019.  
  2020. /*
  2021. # ========================================================================================= #
  2022. # Process Objects by Package
  2023. # ========================================================================================= #
  2024. */
  2025.  
  2026. void ProcessScriptStructsByPackage ( UObject* pPackageToProcess )
  2027. {
  2028. fprintf ( pLog, "void ProcessScriptStructsByPackage\n\n" );
  2029. for ( int i = 0; i < UObject::GObjObjects()->Num(); i++ )
  2030. {
  2031. // get object
  2032. fprintf ( pLog, "UObject::GObjObjects()->Num() ---- %i\n",UObject::GObjObjects()->Num() );
  2033. fprintf ( pLog, "GObjObjects()->Data[ %i ]\n",i );
  2034.  
  2035. UObject* pObject = UObject::GObjObjects()->Data[ i ];
  2036.  
  2037. fprintf ( pLog, "pObject->GetName --- %s\n", pObject->GetName() );
  2038.  
  2039. if ( ! pObject )
  2040. {
  2041. fprintf ( pLog, "! pObject continue\n" );
  2042. continue;
  2043. }
  2044.  
  2045. // get package object
  2046. UObject* pPackageObject = pObject->GetPackageObj();
  2047.  
  2048. if ( ! pPackageObject )
  2049. {
  2050. fprintf ( pLog, "! pPackageObject continue\n" );
  2051. continue;
  2052. }
  2053.  
  2054.  
  2055. // ScriptStruct
  2056. if
  2057. (
  2058. pPackageObject == pPackageToProcess
  2059. && pObject->IsA ( UScriptStruct::StaticClass() )
  2060. )
  2061. {
  2062.  
  2063. GenerateScriptStructPre ( (UScriptStruct*) pObject, pPackageToProcess );
  2064. }
  2065. }
  2066. }
  2067.  
  2068. void ProcessConstsByPackage ( UObject* pPackageToProcess )
  2069. {
  2070. for ( int i = 0; i < UObject::GObjObjects()->Num(); i++ )
  2071. {
  2072. // get object
  2073. UObject* pObject = UObject::GObjObjects()->Data[ i ];
  2074.  
  2075. if ( ! pObject )
  2076. continue;
  2077.  
  2078. // get package object
  2079. UObject* pPackageObject = pObject->GetPackageObj();
  2080.  
  2081. if ( ! pPackageObject )
  2082. continue;
  2083.  
  2084. // Const
  2085. if
  2086. (
  2087. pPackageObject == pPackageToProcess
  2088. && pObject->IsA ( UConst::StaticClass() )
  2089. )
  2090. {
  2091. GenerateConst ( (UConst*) pObject );
  2092. }
  2093. }
  2094. }
  2095.  
  2096. void ProcessEnumsByPackage ( UObject* pPackageToProcess )
  2097. {
  2098. for ( int i = 0; i < UObject::GObjObjects()->Num(); i++ )
  2099. {
  2100. // get object
  2101. UObject* pObject = UObject::GObjObjects()->Data[ i ];
  2102.  
  2103. if ( ! pObject )
  2104. continue;
  2105.  
  2106. // get package object
  2107. UObject* pPackageObject = pObject->GetPackageObj();
  2108.  
  2109. if ( ! pPackageObject )
  2110. continue;
  2111.  
  2112. // Enum
  2113. if
  2114. (
  2115. pPackageObject == pPackageToProcess
  2116. && pObject->IsA ( UEnum::StaticClass() )
  2117. )
  2118. {
  2119. GenerateEnum ( (UEnum*) pObject );
  2120. }
  2121. }
  2122. }
  2123.  
  2124. void ProcessClassesByPackage ( UObject* pPackageToProcess )
  2125. {
  2126. for ( int i = 0; i < UObject::GObjObjects()->Num(); i++ )
  2127. {
  2128. // get object
  2129. UObject* pObject = UObject::GObjObjects()->Data[ i ];
  2130.  
  2131. if ( ! pObject )
  2132. continue;
  2133.  
  2134. // get package object
  2135. UObject* pPackageObject = pObject->GetPackageObj();
  2136.  
  2137. if ( ! pPackageObject )
  2138. continue;
  2139.  
  2140. // Class
  2141. if
  2142. (
  2143. pPackageObject == pPackageToProcess
  2144. && pObject->IsA ( UClass::StaticClass() )
  2145. )
  2146. {
  2147. GenerateClassPre ( (UClass*) pObject, pPackageToProcess );
  2148. }
  2149. }
  2150. }
  2151.  
  2152. void ProcessFuncStructsByPackage ( UObject* pPackageToProcess )
  2153. {
  2154. for ( int i = 0; i < UObject::GObjObjects()->Num(); i++ )
  2155. {
  2156. // get object
  2157. UObject* pObject = UObject::GObjObjects()->Data[ i ];
  2158.  
  2159. if ( ! pObject )
  2160. continue;
  2161.  
  2162. // get package object
  2163. UObject* pPackageObject = pObject->GetPackageObj();
  2164.  
  2165. if ( ! pPackageObject )
  2166. continue;
  2167.  
  2168. // Class
  2169. if
  2170. (
  2171. pPackageObject == pPackageToProcess
  2172. && pObject->IsA ( UClass::StaticClass() )
  2173. )
  2174. {
  2175. GenerateFuncStruct ( (UClass*) pObject );
  2176. }
  2177. }
  2178. }
  2179.  
  2180. void ProcessFuncsByPackage ( UObject* pPackageToProcess )
  2181. {
  2182. for ( int i = 0; i < UObject::GObjObjects()->Num(); i++ )
  2183. {
  2184. // get object
  2185. UObject* pObject = UObject::GObjObjects()->Data[ i ];
  2186.  
  2187. if ( ! pObject )
  2188. continue;
  2189.  
  2190. // get package object
  2191. UObject* pPackageObject = pObject->GetPackageObj();
  2192.  
  2193. if ( ! pPackageObject )
  2194. continue;
  2195.  
  2196. // Class
  2197. if
  2198. (
  2199. pPackageObject == pPackageToProcess
  2200. && pObject->IsA ( UClass::StaticClass() )
  2201. )
  2202. {
  2203. GenerateFuncDef ( (UClass*) pObject );
  2204. }
  2205. }
  2206. }
  2207.  
  2208. void ProcessPackages()
  2209. {
  2210. fprintf ( pLog, "void ProcessPackages\n" );
  2211. // create packages array
  2212. vector< UObject* > vPackages;
  2213.  
  2214. // loop objects and process packages
  2215. for ( int i = 0; i < UObject::GObjObjects()->Num(); i++ )
  2216. {
  2217. // get object
  2218. fprintf ( pLog, "loapp %i\n",i );
  2219.  
  2220. UObject* pObject = UObject::GObjObjects()->Data[ i ];
  2221.  
  2222. if ( ! pObject ){
  2223. fprintf ( pLog, "not object\n" );
  2224. continue;
  2225. }
  2226.  
  2227.  
  2228. if ( pObject->IsA ( UClass::StaticClass() ) )
  2229. {
  2230. fprintf ( pLog, "pObject\n" );
  2231. // get package object
  2232. UObject* pPackageObject = pObject->GetPackageObj();
  2233.  
  2234. if ( ! pPackageObject )
  2235. continue;
  2236.  
  2237. // process package if not
  2238. if ( find ( vPackages.begin(), vPackages.end(), pPackageObject ) == vPackages.end() ) // not found
  2239. {
  2240. fprintf ( pLog, "process package if not\n" );
  2241. vPackages.push_back ( pPackageObject );
  2242.  
  2243. // create new structs package header file
  2244. fprintf ( pLog, "create new structs package header file\n" );
  2245. sprintf_s ( cBuffer, "%s\\%s\\SDK_HEADERS\\%s_structs.h", SDK_BASE_DIR, GAME_NAME_S, pPackageObject->GetName() );
  2246. fopen_s ( &pFile, cBuffer, "w+" );
  2247.  
  2248.  
  2249. sprintf_s ( cBuffer, "%s_structs", pPackageObject->GetName() );
  2250. PrintFileHeder ( cBuffer, "h", true );
  2251.  
  2252.  
  2253.  
  2254. PrintSectionHeader ( "Script Structs" );
  2255.  
  2256. ProcessScriptStructsByPackage ( pPackageObject );
  2257.  
  2258. fprintf ( pLog, "ProcessScriptStructsByPackage\n" );
  2259.  
  2260. PrintFileFooter();
  2261. fclose ( pFile );
  2262.  
  2263. fprintf ( pLog, "fclose\n" );
  2264.  
  2265. // create new classes package header file
  2266. sprintf_s ( cBuffer, "%s\\%s\\SDK_HEADERS\\%s_classes.h", SDK_BASE_DIR, GAME_NAME_S, pPackageObject->GetName() );
  2267. fopen_s ( &pFile, cBuffer, "w+" );
  2268.  
  2269.  
  2270. sprintf_s ( cBuffer, "%s_classes", pPackageObject->GetName() );
  2271. PrintFileHeder ( cBuffer, "h", true );
  2272.  
  2273. PrintSectionHeader ( "Constants" );
  2274. ProcessConstsByPackage ( pPackageObject );
  2275.  
  2276. PrintSectionHeader ( "Enums" );
  2277. ProcessEnumsByPackage ( pPackageObject );
  2278.  
  2279. PrintSectionHeader ( "Classes" );
  2280. ProcessClassesByPackage ( pPackageObject );
  2281.  
  2282. PrintFileFooter();
  2283. fclose ( pFile );
  2284.  
  2285. // create new function structs package header file
  2286. sprintf_s ( cBuffer, "%s\\%s\\SDK_HEADERS\\%s_f_structs.h", SDK_BASE_DIR, GAME_NAME_S, pPackageObject->GetName() );
  2287. fopen_s ( &pFile, cBuffer, "w+" );
  2288.  
  2289. sprintf_s ( cBuffer, "%s_f_structs", pPackageObject->GetName() );
  2290. PrintFileHeder ( cBuffer, "h", true );
  2291.  
  2292. PrintSectionHeader ( "Function Structs" );
  2293. ProcessFuncStructsByPackage ( pPackageObject );
  2294.  
  2295. PrintFileFooter();
  2296. fclose ( pFile );
  2297.  
  2298. // create new function package header file
  2299. sprintf_s ( cBuffer, "%s\\%s\\SDK_HEADERS\\%s_functions.h", SDK_BASE_DIR, GAME_NAME_S, pPackageObject->GetName() );
  2300. fopen_s ( &pFile, cBuffer, "w+" );
  2301.  
  2302. sprintf_s ( cBuffer, "%s_functions", pPackageObject->GetName() );
  2303. PrintFileHeder ( cBuffer, "h", true );
  2304.  
  2305. // print basic functions
  2306. if ( pPackageObject == UObject::FindClass ( "Class Core.Object" )->GetPackageObj() )
  2307. {
  2308. PrintSectionHeader ( "Basic Functions" );
  2309. fprintf ( pFile, BASIC_FUNCTIONS_DEF );
  2310. }
  2311.  
  2312. PrintSectionHeader ( "Functions" );
  2313. ProcessFuncsByPackage ( pPackageObject );
  2314.  
  2315. PrintFileFooter();
  2316. fclose ( pFile );
  2317. }
  2318. }
  2319. }
  2320. }
  2321.  
  2322. /*
  2323. # ========================================================================================= #
  2324. # Initialization
  2325. # ========================================================================================= #
  2326. */
  2327.  
  2328. void Init_Core()
  2329. {
  2330. MODULEINFO miGame = TFLHACKT00LS::GetModuleInfo ( NULL );
  2331.  
  2332. // get GObjects
  2333. GObjects = *(unsigned long*) ( TFLHACKT00LS::FindPattern( (unsigned long) miGame.lpBaseOfDll, miGame.SizeOfImage, (unsigned char*) GObjects_Pattern, (char*) GObjects_Mask ) + GObjects_Offset );
  2334.  
  2335. // log
  2336. fprintf ( pLog, "GObjects: 0x%X\n", GObjects );
  2337.  
  2338. #ifdef GNames_Pattern
  2339. // get GNames
  2340. GNames = *(unsigned long*) ( TFLHACKT00LS::FindPattern( (unsigned long) miGame.lpBaseOfDll, miGame.SizeOfImage, (unsigned char*) GNames_Pattern, (char*) GNames_Mask ) + GNames_Offset );
  2341.  
  2342. // log
  2343. fprintf ( pLog, "GNames: 0x%X\n", GNames );
  2344. #endif
  2345.  
  2346. // empty line
  2347. fprintf ( pLog, "\n" );
  2348.  
  2349. }
  2350.  
  2351. /*
  2352. # ========================================================================================= #
  2353. # Finalization
  2354. # ========================================================================================= #
  2355. */
  2356.  
  2357. void Final_SdkHeaders()
  2358. {
  2359. // init main header file
  2360. sprintf_s ( cBuffer, "%s\\%s\\SdkHeaders.h", SDK_BASE_DIR, GAME_NAME_S );
  2361. fopen_s ( &pFile, cBuffer, "w+" );
  2362.  
  2363. PrintFileHeder ( "SdkHeaders", "h" );
  2364.  
  2365. PrintSectionHeader ( "Defines" );
  2366. fprintf ( pFile, "#define GObjects\t\t\t0x%08X\n", GObjects );
  2367. #ifdef GNames_Pattern
  2368. fprintf ( pFile, "#define GNames\t\t\t\t0x%08X\n", GNames );
  2369. #endif
  2370.  
  2371. PrintSectionHeader ( "Structs" );
  2372. fprintf ( pFile, BASIC_STRUCTS );
  2373.  
  2374. PrintSectionHeader ( "Includes" );
  2375.  
  2376. for ( unsigned int i = 0; i < vIncludes.size(); i++ )
  2377. {
  2378. fprintf ( pFile, "#include \"SDK_HEADERS\\%s_structs.h\"\n", vIncludes[i]->GetName() );
  2379. fprintf ( pFile, "#include \"SDK_HEADERS\\%s_classes.h\"\n", vIncludes[i]->GetName() );
  2380. fprintf ( pFile, "#include \"SDK_HEADERS\\%s_f_structs.h\"\n", vIncludes[i]->GetName() );
  2381. fprintf ( pFile, "#include \"SDK_HEADERS\\%s_functions.h\"\n", vIncludes[i]->GetName() );
  2382. }
  2383.  
  2384. fclose ( pFile );
  2385. }
  2386.  
  2387. /*
  2388. # ========================================================================================= #
  2389. # DllMain
  2390. # ========================================================================================= #
  2391. */
  2392.  
  2393. void OnAttach()
  2394. {
  2395. //Sleep ( 60000 );
  2396.  
  2397. // times
  2398. SYSTEMTIME stST, stET;
  2399. FILETIME ftST, ftET;
  2400. ULARGE_INTEGER nST, nET;
  2401.  
  2402. float fDiff;
  2403.  
  2404. // mkdir base dir
  2405. _mkdir ( SDK_BASE_DIR );
  2406.  
  2407. // mkdir sdk dir
  2408. sprintf_s ( cBuffer, "%s\\%s", SDK_BASE_DIR, GAME_NAME_S );
  2409. _mkdir ( cBuffer );
  2410.  
  2411. // mkdir sdk headers
  2412. sprintf_s ( cBuffer, "%s\\%s\\SDK_HEADERS", SDK_BASE_DIR, GAME_NAME_S );
  2413. _mkdir ( cBuffer );
  2414.  
  2415. // open log
  2416. sprintf_s ( cBuffer, "%s\\%s\\UE3SdkGenerator.log", SDK_BASE_DIR, GAME_NAME_S );
  2417. fopen_s ( &pLog, cBuffer, "w+" );
  2418.  
  2419. // get start time
  2420. GetSystemTime ( &stST );
  2421.  
  2422. // initialize
  2423. Init_Core();
  2424.  
  2425. // process packages
  2426. ProcessPackages();
  2427.  
  2428. // finalize
  2429. Final_SdkHeaders();
  2430.  
  2431. // get end time
  2432. GetSystemTime ( &stET );
  2433.  
  2434. // calc delta time
  2435. SystemTimeToFileTime ( &stST, &ftST );
  2436. nST.HighPart = ftST.dwHighDateTime;
  2437. nST.LowPart = ftST.dwLowDateTime;
  2438.  
  2439. SystemTimeToFileTime ( &stET, &ftET );
  2440. nET.HighPart = ftET.dwHighDateTime;
  2441. nET.LowPart = ftET.dwLowDateTime;
  2442.  
  2443. fDiff = ( nET.QuadPart - nST.QuadPart ) / 10000.0f / 1000.0f; // seconds
  2444.  
  2445. // print generation time
  2446. fprintf ( pLog, "\nSDK Generated in %.3f seconds\n", fDiff );
  2447.  
  2448. // close log
  2449. fclose ( pLog );
  2450. }
  2451.  
  2452. BOOL WINAPI DllMain ( HMODULE hModule, DWORD dwReason, LPVOID lpReserved )
  2453. {
  2454. switch ( dwReason )
  2455. {
  2456. case DLL_PROCESS_ATTACH:
  2457.  
  2458. DisableThreadLibraryCalls ( hModule );
  2459. CreateThread ( NULL, 0, ( LPTHREAD_START_ROUTINE ) OnAttach, NULL, 0, NULL );
  2460.  
  2461. return true;
  2462.  
  2463. break;
  2464. }
  2465. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement