[RESOLVED] I need help reading a data file. (Visual Basic 6.0)
I'm having trouble reading a file. The file is a core file from Microsoft's now debunked but open source game Allegiance that was written in C/C++; I don't know C/C++. (On a side note: A few users kept the game alive and running, see http://www.freeallegiance.org/forums/index.php?act=home )
I have tried:
VB Code:
Dim strText As String
Dim intFile As Integer
intFile = FreeFile()
Open App.Path + "\dn_000450.igc" For Input As #intFile
MsgBox (LOF(intFile))
MsgBox (EOF(intFile))
strText = Input$(LOF(intFile), intFile)
Close #intFile
But it gives an error.
I have also tried:
VB Code:
Dim sfile As String
sfile = App.Path + "\dn_000450.igc"
Dim myArray() As String
ReDim myArray(0)
Open sfile For Input As #1
Do Until EOF(1)
Input #1, myArray(UBound(myArray))
ReDim Preserve myArray(UBound(myArray) + 1)
Loop
ReDim Preserve myArray(UBound(myArray) - 1)
Close #1
'Check to see if everything was read
For i = 0 To UBound(myArray())
txt1.Text = txt1.Text & myArray(i)
Next i
But it only appeared to read part of the file.
How do I read the file and extract usable data from it??
Additional information:
Currently I'm reading the .CSV file output from a program called CoreDump that was written in Python, but the current version is buggy and doesn’t output everything. Currently, I don't know any Python and would like to deal with just the one core file instead of the several CSV files that CoreDump outputs.
If anyone wants me to, I will post the Python source code to CoreDump.
Thalgor has graciously set up a Subversion repository on one of his servers to allow all Allegiance developers to collaboratively develop additions and enhancements to Allegiance.
This repository is located at http://svn.alleg.net:8080/svn/Allegiance and can easily be browsed with your web browser.
predefining ObjectID just makes it easier to distinguish your C short variables from other C short variables (you can reference them by more descriptive 'ObjectID' rather than just saying its a short). And makes the 'description', for lack of a better term, available as a data type. what all that is saying is
VB Code:
Dim BucketI As Integer
Dim PartID As Integer
Dim ShipID As Integer
Dim BuoyID As Integer
Dim AsteroidID As Integer
Dim HullID As Integer
Dim StationTypeID As Integer
Dim DroneTypeID As Integer
Dim DevelopmentID As Integer
Dim SectorID As Integer
Dim WarpID As Integer
Dim ProjectileTypeID As Integer
Dim TreasureID As Integer
Dim SideID As Integer
Dim StationID As Integer
Dim MissileID As Integer
Dim ChaffID As Integer
Dim MineID As Integer
Dim ProbeID As Integer
Dim ExpendableTypeID As Integer
Dim CivID As Integer
Dim MunitionID As Integer
Dim TreasureSetID As Integer
Dim SquadID As Long 'since it was an int in C
Dim WingID As Integer
Since most of the declarations in igc.h would probably be used in the file, you can occupy yourself Tontow in the meantime with converting it into a vb module. just comment the classes for now.
Last edited by leinad31; Oct 20th, 2006 at 02:03 PM.
Re: I need help reading a data file. (Visual Basic 6.0)
Originally Posted by leinad31
Still can't find the procedures that access the file. Must have missed it due to reading all those lines
If someone has the time, pls look for LoadIGCStaticCore function.
Maybe this will help?
Starting at line 2819 in igc.h
Code:
//Warning these should never be called except from LoadIGCStaticCore
virtual CstaticIGC* GetStaticCore(void) const = 0;
virtual void SetStaticCore(CstaticIGC* pStatic) = 0;
virtual short GetReplayCount(void) const = 0;
virtual const char* GetContextName(void) = 0;
};
class IbaseIGC : public IObject
{
public:
virtual HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int length) = 0;
virtual void Terminate(void) = 0;
virtual void Update(Time now) {}
//Exporting an object which doesn't support export is also bad.
virtual int Export(void* data) const { assert (false); return -1;}
// GetUniqueID() is provided for convenience because AGC uses GetObjectType and GetObjectID often.
virtual int GetUniqueID(void) const { return GetObjectType() | (GetObjectID() << 16); }
virtual ObjectType GetObjectType(void) const = 0;
//Calling either of these methods on something that doesn't have either an object ID or a mission is bad.
virtual ObjectID GetObjectID(void) const { assert (false); return NA;}
virtual ImissionIGC* GetMission(void) const { assert (false); return NULL; }
};
And at line 5867 of igc.h (basically at the very bottom)
Code:
//------------------------------------------------------------------------------
// normal igc files, i.e. missions can be dumped and loaded using these two
// functions. They return true if successful.
//------------------------------------------------------------------------------
bool DumpIGCFile (const char* name, ImissionIGC* pMission, __int64 iMaskExportTypes,
void (*munge)(int size, char* data) = NULL);
bool LoadIGCFile (const char* name, ImissionIGC* pMission, void (*munge)(int size, char* data) = NULL);
//------------------------------------------------------------------------------
// static data core files are dealt with by these functions. They are
// almost identical to the normal igc file loaders, but there is a version
// number in the file, and it is returned by the LoadIGCStaticCore function.
// if the load function fails, it returns NA.
//------------------------------------------------------------------------------
bool DumpIGCStaticCore (const char* name, ImissionIGC* pMission, __int64 iMaskExportTypes, void (*munge)(int size, char* data) = NULL);
int LoadIGCStaticCore (const char* name, ImissionIGC* pMission, bool fGetVersionOnly, void (*munge)(int size, char* data) = NULL);
int CacheIGCStaticCore (const char* name, ImissionIGC* pMission, bool fGetVersionOnly, void (*munge)(int size, char* data) = NULL);
#endif
And then missionigc.ccp seems to have the rest of it.
Also at line 1036 of igc.h
Code:
//------------------------------------------------------------------------------
char strGameName[c_cbGameName]; //Name of game
char szIGCStaticFile[c_cbFileName]; //Name of static IGC file
called proc LoadIGCFile just seems to call SetConstants and move the stream pointer to skip objects. Not much help downstream... can't figure out how *munge is used since its not in icg.h.
Maybe upstream... where is LoadICGStaticCore called?
Last edited by leinad31; Oct 21st, 2006 at 12:19 PM.
In that same file, there is a notation at line 61 that might clear things up ,but I'm not quite shure what it dose.
Code:
static void DoDecrypt(int size, char* pdata)
{
DWORD encrypt = 0;
//Do a rolling XOR to demunge the data
for (int i = 0; (i < size); i += 4)
{
DWORD* p = (DWORD*)(pdata + i);
encrypt = *p = *p ^ encrypt;
}
}
And I also forgot to mention that you need igc.py for coredump.py to work.
Also, dose anyone know how to convert Python to Visual Basic 6.0?
Even though I would very much like to use Get to retrieve the data from the file, I’m not having much luck finding the read order of the variables in the C++ game source code and I may have to use the method that CoreDump uses. – My best guess from looking at the Coredump and igc.py Python source code is that it reads the individual bytes instead of retrieving the types.
(Note: I’m still guessing on most of this stuff since I don’t know C++ or Python.)
Last edited by Tontow; Oct 22nd, 2006 at 08:12 PM.
Reason: added another question and more information
Re: I need help reading a data file. (Visual Basic 6.0)
I did a search for the word munge in the game's source code using Visual C++ 2005 Express Edition and came up with several hits of "ScrambleMunge" in \zlib\zstring.cpp at lines 911, 978, 983, 988 and of "ScrambleUnmunge" in \zlib\zstring.cpp at lines 937, 1006, 1011, 1016 and of "XMunge" in \xmunge\xmunge.cpp at lines 60, 45 .
Dose anyone have any further help or input?
In the mean time, I've managed to make a function to read the .csv output of CoreDump since I have not figured out how to read the variables from the .igc file. If anyone has any suggestions on how I can make it better, then it would be greatly welcome.
Re: I need help reading a data file. (Visual Basic 6.0)
Originally Posted by leinad31
Yes, might as well use the CSV rather than reinventing the wheel ^^
Post the CSV so we have something to work with
But I want to reinvent the wheel, just think of what one could make off the copyright.
BTW, Usage of the function is getdata("name of the file here", "variable that you want to get") It should return with an array of values based on what is in the fist row.
Here’s the zip.
Last edited by Tontow; Oct 24th, 2006 at 09:48 PM.
Re: I need help reading a data file. (Visual Basic 6.0)
Originally Posted by Tontow
But I want to reinvent the wheel, just think of what one could make off the copyright.
BTW, Usage of the function is getdata("name of the file here", "variable that you want to get") It should return with an array of values based on what is in the fist row.
Here’s the zip.
Yes, but then you'd be forced to implement the original data structure, we'd also have to build class modules for the classes in C++.
While if we manipulate the CSV, we can treat the CSV's as tables through ADO+SQL which is easier especially if your looking for particular records or returning particular columns. So development moves on instead of being stuck in translation phase.
Later on we can go back and implement an on demand creation of the CSV's ... If I'm not mistaken, and if the dll function's parameter data types are supported in VB, we can reference the CoreDump function in the C++ dll like what we do with API calls. So we declare the dll function, call it in VB then access the CSVs it creates.
Last edited by leinad31; Oct 25th, 2006 at 12:05 AM.
Re: I need help reading a data file. (Visual Basic 6.0)
I tried timing the speed of the code. It shows my code to be way faster than yours.
Did I do the timing it right?
BTW, Thankyou everyone for all your help thus far.
(NOTE: I have 3 text boxes on my form txt1 txt2 and txt3, my results show 6 sec for txt1, 5 sec for txt2 and 1 sec for txt3 . txt1 and txt2 show your methods and txt3 shows mine.)
VB Code:
Option Explicit
' filenames less extension. also worksheet names
Private Const FNM_BOOSTERS = "boosters#csv"
Private Const FNM_CHAFF = "chaff#csv"
Private Const FNM_CHAFF_TABLE = "chaff_table#csv"
Private Const FNM_CLOAKS = "cloaks#csv"
Private Const FNM_DMGTABLE = "dmgtable#csv"
Private Const FNM_DRONES = "drones#csv"
Private Const FNM_FACTIONS = "factions#csv"
Private Const FNM_MINES = "mines#csv"
Private Const FNM_MISSILES = "missiles#csv"
Private Const FNM_PARTS = "parts#csv"
Private Const FNM_PROBES = "probes#csv"
Private Const FNM_PROJECTILES = "projectiles#csv"
Private Const FNM_SHIELDS = "shields#csv"
Private Const FNM_SHIPS = "ships#csv"
Private Const FNM_STATIONS = "stations#csv"
Private Const FNM_TECH = "tech#csv"
Private Const FNM_TREASURE = "treasure#csv"
Private Const FNM_WEAPONS = "weapons#csv"
Private cn As New ADODB.Connection 'better if public in a module
Re: I need help reading a data file. (Visual Basic 6.0)
Of course arrays are faster than initializing a recordset... but then you would have a hard time getting relationships out of all those tables... but if there are no relationships or they are not normalized tables then go ahead with the by array extraction.
Re: I need help reading a data file. (Visual Basic 6.0)
Originally Posted by leinad31
but then you would have a hard time getting relationships out of all those tables... but if there are no relationships or they are not normalized tables then go ahead with the by array extraction.
What do you mean by relationships and normalized tables?
If your talking about formulas that involve more than one table, then there are none. And there all *.csv (Comma Separated Values Files) if that’s what you meant by normalized tables.