Results 1 to 3 of 3

Thread: [RESOLVED] Convert Xliveless sample from C++ to C#

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Convert Xliveless sample from C++ to C#

    Hi,

    Is it possible to convert the attached C++ code sample to C# code and if so how? The reason I am asking is because I had an idea for some code I recently made to be able to convert live saves for gta to liveless save games so I don't have to start the whole game again in the middle of a current game.

    I have requested this thread moved to the C# section because I would have better luck converting the across languages rather than down a level.

    Edit:

    By the above I meant it would be easier converting the code to another modern language that uses possibly the same framework rather than trying to convert to an older language such as Visual Basic 6.0 which, uses a different framework.

    Thanks,


    Nightwalker
    Attached Files Attached Files
    Last edited by Nightwalker83; May 27th, 2011 at 04:58 AM. Reason: Changed title!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Convert Xliveless sample from C++ to C#

    This is my attempt at using the C++ to C# Converter demo from Tangible Software Solutions.

    C# Code:
    1. public static class GlobalMembersSaveToGameFolder
    2. {
    3.     public static void getSavefilePath(int __unused, string pBuffer, string pszSaveName)
    4.     {
    5.         sbyte pszPath = (string)(0xF9FF08+dwLoadOffset);
    6.         if (dwGameVersion == 0x00010001)
    7.             pszPath = (string)(0xFA7778+dwLoadOffset); // char pszProgramPath[128];
    8.             else if (dwGameVersion == 0x00010003)
    9.             pszPath = (string)(0xFBF260+dwLoadOffset);
    10.             else if (dwGameVersion == 0x00010004)
    11.             pszPath = (string)(0xFC4700+dwLoadOffset); // ?? FC4500?
    12.         pBuffer = pszPath;
    13.         pBuffer += "savegames";
    14.  
    15.         // check path and create directory if necessary
    16.         uint attrs = GetFileAttributes (pBuffer);
    17.         if (attrs == INVALID_FILE_ATTRIBUTES)
    18.             CreateDirectory (pBuffer, null);
    19.         else if (!(attrs & FILE_ATTRIBUTE_DIRECTORY))
    20.         {
    21.             trace("ERROR: unable to create directory '%s', file '%s' already exists\n", pBuffer);
    22.             pBuffer = pszSaveName;
    23.             return;
    24.         }
    25.         if (pszSaveName != null)
    26.         {
    27.             pBuffer += "\\";
    28.             pBuffer += pszSaveName;
    29.         }
    30.     }
    31.  
    32. //C++ TO C# CONVERTER NOTE: APIENTRY is not available in C#:
    33. //ORIGINAL LINE: int APIENTRY DllMain(IntPtr hModule, uint ul_reason_for_call, IntPtr  lpReserved)
    34.     public static int DllMain(IntPtr hModule, uint ul_reason_for_call, IntPtr  lpReserved)
    35.     {
    36.         switch (ul_reason_for_call)
    37.         {
    38.         case DLL_PROCESS_ATTACH:
    39.             if (dwGameVersion == 0x00010001)
    40.                 injectFunction(0x608660, (uint)GlobalMembersSaveToGameFolder.getSavefilePath);
    41.             else if (dwGameVersion == 0x00010002)
    42.                 injectFunction(0x6080E0, (uint)GlobalMembersSaveToGameFolder.getSavefilePath);
    43.             else if (dwGameVersion == 0x00010003)
    44.                 injectFunction(0x60BAC0, (uint)GlobalMembersSaveToGameFolder.getSavefilePath);
    45.             else if (dwGameVersion == 0x00010004)
    46.                 injectFunction(0x60BBD0, (uint)GlobalMembersSaveToGameFolder.getSavefilePath);
    47.             break;
    48.         case DLL_THREAD_ATTACH:
    49.         case DLL_THREAD_DETACH:
    50.         case DLL_PROCESS_DETACH:
    51.             break;
    52.         }
    53.         return 1;
    54.     }
    55. }

    xliveless.h:
    C# Code:
    1. public static class GlobalMembersXliveless
    2. {
    3.         // game version
    4.     //C++ TO C# CONVERTER WARNING: Most '__declspec' modifiers cannot be converted to C#.
    5.     //ORIGINAL LINE: __declspec(dllimport)uint dwGameVersion;
    6.         public static uint dwGameVersion;
    7.         // Offset to the "real" loding address
    8.     //C++ TO C# CONVERTER WARNING: Most '__declspec' modifiers cannot be converted to C#.
    9.     //ORIGINAL LINE: __declspec(dllimport)uint dwLoadOffset;
    10.         public static uint dwLoadOffset;
    11.  
    12.         // for Delphi plugins (same as two variables above)
    13.     //C++ TO C# CONVERTER TODO TASK: Enter the dll name in the following attribute:
    14.     //ORIGINAL LINE: __declspec(dllimport) DWORD getGameVersion();
    15.         [DllImport(<dll file name>)]
    16.         internal static extern uint getGameVersion();
    17.     //C++ TO C# CONVERTER TODO TASK: Enter the dll name in the following attribute:
    18.     //ORIGINAL LINE: __declspec(dllimport) DWORD getLoadOffset ();
    19.         [DllImport(<dll file name>)]
    20.         internal static extern uint getLoadOffset();
    21.  
    22.         // Print message to the log
    23. //C++ TO C# CONVERTER TODO TASK: The implementation of the following method could not be found:
    24.     //  void trace(string message, params object[] LegacyParamArray);
    25.  
    26.         // Replace game function at dwAddress with plugin function
    27. //C++ TO C# CONVERTER TODO TASK: The implementation of the following method could not be found:
    28.     //  void injectFunction(uint dwAddress, uint pfnReplacement);
    29.     }
    30. }
    31.  
    32. // XLiveLess plugin API
    33.  
    34. //C++ TO C# CONVERTER TODO TASK: Extern blocks are not supported in C#.
    35. extern "C"
    36. {

    Unfortunately, xlive.cpp is too big at 845 lines to convert with the demo version.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Convert Xliveless sample from C++ to C#

    Here is the conversion of xlive.cpp I converted using the above method.
    Attached Files Attached Files
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width