C/C++ Coding Problems & Questions [EHM 2005]

Discuss all aspects of editing the data and databases in EHM here. Have a question about the EHM Editor, EHM Assistant, editing the .cfg files, hex editing the .dat or .db files? Want to tweak the EHM exe file to change league rules/structure, start date etc? This is the place!
Forum rules
This is the forum to discuss all aspects of editing the EHM data and tweaking the game.

Have a bug or feature request for the EHM Editor? Post them in the EHM Editor thread. Please start a new thread or post in another thread if you have a question about how to use the EHM Editor.

Given the large number of questions on similar topics, we ask that you start a new thread for a new question unless you can locate a similar question in an existing thread. This will hopefully ensure that similar questions do not get buried in large threads.

Useful links: EHM 1 Assistant (Download) | EHM 1 Editor (Download) | EHM 1 Editor Tutorials | Editing Rules & Structures Guide | Converting EHM 2004 / 2005 DBs to EHM 1 | Converting an EHM 2007 DB to EHM 1 | Extra_config.cfg | Import_config.cfg | Player Roles
Post Reply
Midas
Minor League
Posts: 238
Joined: Sun Nov 07, 2010 5:57 am

C/C++ Coding Problems & Questions [EHM 2005]

Post by Midas »

As requested Archie, here's the code I'm using:

Code: Select all

#include <iostream>
#include <fstream>

#pragma pack(1)                                       // This is essential because the data in the .dat files are byte-swapped
#include "database_types.h"                              // The three EHM database format .h files must be called after #pragma pack(1)
#include "database_flags.h"
#include "language_types.h"

using namespace std;                                 // As we are just using the standard library, we'll use std namespace for ease of reference

int main() {

   fstream dat_infile ("index.dat", ios::in | ios::binary);   // Open index.dat for reading in binary mode. We'll call it dat_infile.
   fstream csv_outfile ("index.csv", ios::out);            // Create a blank index.csv file in text mode. We'll call it csv_outfile.

   struct INDEX dat;                                 // Within the database_types.h file the structure of index.dat INDEX
                                                // We'll assign "dat" as the identifier for use with this structure

   // Calculate the length of index.dat and call is dat_filesize:
   dat_infile.seekg (0, ios::end);
   auto dat_filesize = dat_infile.tellg();
   dat_infile.seekg (0, ios::beg);

   if (dat_infile.is_open())                           // If index.dat has been successfully opened then perform the following code within the {} braces
   {
      dat_infile.seekg(INDEX_IGNORE_DATA,ios::beg);         // DELETE THIS LINE IF YOU ARE OPENING ANY FILE OTHER THAN INDEX.DAT
                                                // The first 8 bytes of index.dat are blank and therefore we must skip over these. Hence the reason of the line above.

      // A loop to read the data stream into the buffer one record at a time and save it as a csv file
      while( dat_infile.tellg() < dat_filesize )
      {
         dat_infile.read ((char*)&dat, sizeof(INDEX));
         csv_outfile << dat.filename << "," << dat.file_id << "," << dat.table_sz << "," << dat.version << endl;      // Commas are added between each field as per csv file format. The final field of each record is terminated by a new line - i.e. 'endl'.
      }

      // Close the index.dat and index.csv files
      dat_infile.close();
      csv_outfile.close();
   }

   else                                          // If index.dat cannot be opened then do the following
   {
      cout << "Unable to open index.dat" << endl;
   }

   cout << "Press ENTER to close this window.";
   cin.get();                                       // Wait until the user has pressed ENTER before closing the window

   return(0);                                       // Exit the script / close the window.
}
It's Visual C++ 2010 Express and pulled it straight out of your tutorial. I downloaded the EHM 2005 database and just plugged it in. I'm terrible atm. with C++ but playing around with this should get me to improve.

Code: Select all

1>------ Build started: Project: EHM2005, Configuration: Debug Win32 ------
1>  dat_example.cpp
1>dat_example.cpp(16): error C2079: 'dat' uses undefined struct 'main::INDEX'
1>dat_example.cpp(26): error C2065: 'INDEX_IGNORE_DATA' : undeclared identifier
1>dat_example.cpp(32): error C2027: use of undefined type 'main::INDEX'
1>          dat_example.cpp(16) : see declaration of 'main::INDEX'
1>dat_example.cpp(33): error C2039: 'filename' : is not a member of 'System::Int32'
1>          c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>dat_example.cpp(33): error C2039: 'file_id' : is not a member of 'System::Int32'
1>          c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>dat_example.cpp(33): error C2039: 'table_sz' : is not a member of 'System::Int32'
1>          c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>dat_example.cpp(33): error C2039: 'version' : is not a member of 'System::Int32'
1>          c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.0\mscorlib.dll : see declaration of 'System::Int32'
1>  directory.cpp
1>directory.cpp(1): error C2143: syntax error : missing ';' before '.'
1>directory.cpp(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>directory.cpp(1): error C2365: 'System' : redefinition; previous definition was 'namespace'
1>  Generating Code...
This is the error message list.

If you need more information, I'd be happy to post. Thanks!
User avatar
archibalduk
TBL Admin Team
Posts: 20373
Joined: Tue Jul 06, 2004 8:44 pm
Custom Rank: Seaside + Fruit Juice Mode
Favourite Team: Guildford (EPL) / Invicta (NIHL)
Location: United Kingdom
Contact:

Re: C/C++ Coding Problems & Questions

Post by archibalduk »

I had some spare time this evening so I took a look for you. The problem is because of some mistakes in the database_types.h file. There were similar mistakes with the EHM 07 .h file too, but I corrected these a while back when I first started coding. I'd never touched the EHM 05 .h files before.

Anyway, I've uploaded a corrected copy of the .h files here: http://www.ehmtheblueline.com/forums/vi ... 85#p127185

Replace your original database_types.h file with the updated one from the link above. This will fix all of the syntax errors.

It does look, however, that you're using a Win32 project. When you created the project in MSVC++ 2010 Express, you should select the 'Empty Project'' option.

One final note: When I wrote those guides, I was still very new to C++. With the benefit of (some) experience I'd do things a little differently now (and I'd use classes/OOP too). If you run into a brick wall or struggle with anything then just post your code here and I'll be happy to help.
Midas
Minor League
Posts: 238
Joined: Sun Nov 07, 2010 5:57 am

Re: C/C++ Coding Problems & Questions

Post by Midas »

Thanks for the help Archie, I did indeed get it to work. Glad you could show me the light!
Midas
Minor League
Posts: 238
Joined: Sun Nov 07, 2010 5:57 am

Re: C/C++ Coding Problems & Questions

Post by Midas »

Alright so I know I have this all mucked up, but I wanted clarification on what specifically :D

I'm trying to export the staff.dat to .csv but debugger can't process the SI_DATE. I know you posted some stuff on it, I tried my hand and it and no doubt butchered it. When you have time, can you have a look at what's going wrong here?

Code: Select all

#include <iostream>
#include <fstream>

#pragma pack(1)                                       // This is essential because the data in the .dat files are byte-swapped
#include "database_types.h"                              // The three EHM database format .h files must be called after #pragma pack(1)
#include "database_flags.h"
#include "language_types.h"

using namespace std;                                 // As we are just using the standard library, we'll use std namespace for ease of reference

int main() {

   fstream dat_infile ("staff.dat", ios::in | ios::binary);   // Open index.dat for reading in binary mode. We'll call it dat_infile.
   fstream csv_outfile ("staff.csv", ios::out);            // Create a blank index.csv file in text mode. We'll call it csv_outfile.
   int monthtable[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	short monthdays = 0;
	short month = 0;
	short day = 0;

   struct STAFF dat;                                 // Within the database_types.h file the structure of index.dat INDEX
                                                // We'll assign "dat" as the identifier for use with this structure

   // Calculate the length of index.dat and call is dat_filesize:
   dat_infile.seekg (0, ios::end);
   auto dat_filesize = dat_infile.tellg();
   dat_infile.seekg (0, ios::beg);

   if (dat_infile.is_open())                           // If index.dat has been successfully opened then perform the following code within the {} braces
   {
      // A loop to read the data stream into the buffer one record at a time and save it as a csv file
      while( dat_infile.tellg() < dat_filesize )
      {
         dat_infile.read ((char*)&dat, sizeof(STAFF));
		 if ( dat.StaffDateOfBirth.leap_year == 0 ) { monthtable[1] = 28; }
			else  { monthtable[1] = 29; }

			monthdays = 0;
			month = 0;
			day = 0;

			while ( static_cast<short>(dat.StaffDateOfBirth.day) > monthdays ) { monthdays += monthtable[month++]; }
			day = static_cast<short>(dat.StaffDateOfBirth.day) - monthdays + monthtable[month-1];
         csv_outfile << dat.StaffID << "," << dat.StaffFirstName << "," << dat.StaffSecondName << "," << day << "/" << month << "/" << static_cast<int>(dat.StaffDateOfBirth.year) << "," << dat.StaffNation << "," << dat.StaffSecondNation << "," << dat.StaffDeclaredNation << "," << dat.StaffInternationalApps << "," << dat.StaffInternationalGoals << "," << dat.StaffInternationalAssists << "," << dat.StaffNationContracted << "," << dat.StaffJobForNation << "," << dat.StaffDateJoinedNation << "," << dat.StaffContractExpiresNation << "," << dat.StaffClubContracted << "," << dat.StaffClubPlaying << "," << dat.StaffJobForClub << "," << dat.StaffDateJoinedClub << "," << dat.StaffEstimatedWage << "," << dat.StaffEstimatedValue << "," << dat.StaffAdaptability << "," << dat.StaffAmbition << "," << dat.StaffLoyalty << "," << dat.StaffPressure << "," << dat.StaffProfessionalism << "," << dat.StaffSportsmanship << "," << dat.StaffTemperament << "," << dat.StaffPlayingSquad << "," << dat.StaffClassification << "," << dat.StaffClubValuation << "," << dat.player_data << "," << dat.youth_player_data << "," << dat.non_player_data << "," << dat.StaffBirthTown << "," << endl;      // Commas are added between each field as per csv file format. The final field of each record is terminated by a new line - i.e. 'endl'.
      }

      // Close the index.dat and index.csv files
      dat_infile.close();
      csv_outfile.close();
   }

   else                                          // If index.dat cannot be opened then do the following
   {
      cout << "Unable to open staff.dat" << endl;
   }

   cout << "Press ENTER to close this window.";
   cin.get();                                       // Wait until the user has pressed ENTER before closing the window

   return(0);                                       // Exit the script / close the window.
}
Here's the error code.

Code: Select all

 index.cpp
1>c:\users\midas\documents\visual studio 2010\projects\midasdb (ehm 2005)\midasdb (ehm 2005)\index.cpp(43): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'SI_DATE' (or there is no acceptable conversion)
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(726): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(764): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(811): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(937): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(944): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(951): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(958): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(968): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>,SI_DATE>(std::basic_ostream<_Elem,_Traits> &&,_Ty)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ty=SI_DATE
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(1085): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(186): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(192): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(199): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(206): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(226): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(260): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(280): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(305): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(325): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(345): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(366): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(386): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(407): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(427): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(447): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(467): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(487): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          while trying to match the argument list '(std::basic_ostream<_Elem,_Traits>, SI_DATE)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I also selected empty project, but it seems to return win32 everytime. Not sure what to do there. Hmph.
Post Reply