Results 1 to 2 of 2
  1. #1
    TheMarv
    TheMarv is offline
    Guest
    Join Date
    2013 Apr
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Serverside DIF Patcher with Source

    Hey,

    because my english isn't the best, I'm not going to write much :/

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    using namespace std;
    
    char convertHexPair(char* hex) {
        int sixteensDig = (hex[0] - 48) * 16;
        int onesDig = hex[1];
        if ( (onesDig >= 97) && (onesDig <= 102) )
            onesDig -= 32;
        if (onesDig < 65) {
            return char(sixteensDig + onesDig - 48);
        } else {
            return char(sixteensDig + onesDig - 55);
        }
    }
    
    int Hex2Dec(const char *sz)
    {
        int iResult;
        sscanf(sz, "%x", &iResult);
        return iResult;
    }
    
    int main(int argc, char *argv[])
    {
        if(argc != 5)
        {
        cout << "Not enough arguments";
         return 1;
    }
      char replace = convertHexPair(argv[4]);
      fstream out(argv[1], ios::in | ios::out | ios::binary);
      out.seekp(atoi(argv[2]), ios::beg);
      char original = out.peek();
      if(!out) {
        cout << "Cannot open file.";
        return 1;
      }
      out.close();
      fstream write(argv[1], ios::in | ios::out | ios::binary);
      write.seekp(atoi(argv[2]), ios::beg);
      write.put(convertHexPair(argv[4]));
      return 0;
    }
    Put this code in a file with .cpp at the ending(for example main.cpp).
    After this execute the following command
    Code:
    g++ main.cpp
    replace main.cpp with your file!

    After that you can patch a DIF file in your game, but I would recommend to use this script:

    Code:
    echo "Please enter the name of the Dif"
    diffile = read
    cat "difs/$diffile"|while read line; do
       cp game game.bak
       ./a.out $line | sed -e 's/://g'
    done;
    Put this script in a file named patch.sh

    After that you can simply execute it via
    Code:
    ./patch.sh
    and than you have to enter the name of the Dif file!


    If you get errors, put the main.cpp & patch.sh in the path where you game file is and run
    Code:
    g++ main.cpp
    again!

    MfG
    TheMarv

  2. #2
    Sparkk
    Sparkk is offline
    New member Sparkk's Avatar
    Join Date
    2013 Sep
    Location
    Marseille, France
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Well, I would rather do this in your cpp file:

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    using namespace std;
    
    char convertHexPair(char* hex)
    {
    	int sixteensDig = (hex[0] - 48) * 16;
    	int onesDig = hex[1];
    	if ( (onesDig >= 97) && (onesDig <= 102) )
    	{
    		onesDig -= 32;
    	}
    	if (onesDig < 65)
    	{
    		return char(sixteensDig + onesDig - 48);
    	}
    	else
    	{
    		return char(sixteensDig + onesDig - 55);
    	}
    }
    
    int main(int argc, char *argv[])
    {
    	if(argc != 4)
    	{
    		cout << "Not enough arguments";
    		return 1;
    	}
    	
    	/*char replace = convertHexPair(argv[4]);
    	fstream out(argv[1], ios::in | ios::out | ios::binary);
    	out.seekp(atoi(argv[2]), ios::beg);
    	char original = out.peek();
    	if(!out) {
    		cout << "Cannot open file.";
    		return 1;
    	}
    	out.close();*/
    	fstream write(argv[1], ios::in | ios::out | ios::binary);
    	write.seekp(atoi(argv[2]), ios::beg);
    	write.put(convertHexPair(argv[3]));
    	return 0;
    }
    It's not really logic to check if the file is opened after you just used seekp.
    Furthermore, you were waiting for 5 parameters, but you only have 4 parameters in your argc:
    argc[0] = ./a.out
    argc[1] = the file name
    argc[2] = the position where we'll write the convertHexPair result
    argc[3] = the argument of the convertHexPair function

    So you just need 4 argc, and you should replace if(argc != 5) by "!= 4" and, indeed, "write.put(convertHexPair(argv[3]))" instead of "argv[4]".

    I also checked your shell, and you should do this:

    Code:
    echo -n "Enter file name: "
    read dif
    cat "difs/$dif"|while read line; do
       cd "your/game/folder/"
       cp game game.bak
       cd "/your/a.out folder/"
       ./a.out $line | sed -e 's/://g'
    done;
    Then, it should work correctly.

Similar Threads

  1. Replies: 8
    Last Post: 2015-11-03, 04:46 AM
  2. [Hack] Dragon Nest SEA Universal patcher
    By Grooguz in forum Dragon Nest Bots, Hacks, Cheats
    Replies: 20
    Last Post: 2012-07-30, 05:21 PM
  3. [Source] dPatcher, Perfect World Exe patcher Source
    By Dwar in forum Delphi
    Replies: 0
    Last Post: 2012-07-28, 05:28 AM
  4. [C++] Old Steam memory patcher
    By SheppeR in forum Game Research, Development
    Replies: 1
    Last Post: 2012-05-22, 11:08 AM
Visitors found this page by searching for:

metin2 dif

metin2 serverside error

metin2 source code

metin 2 source code

metin2 patcher source

dif patcher src metin2

argument patcher metin2

main.cpp78initmodule error metin2

game source code metin2

game patcher source

autopatcher c dev metin2

Posting Permissions

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