• Welcome to Valhalla Legends Archive.
 
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Tontow

#1
it reads the file, then outputs csv files with the data.

I tryed asking for help on vbforums.com , but I didnt get too far and ended up useing the csv output of CoreDump.
http://www.vbforums.com/showthread.php?t=433735
#2
Quote from: topaz on October 17, 2006, 03:39 PM
Why would you do that, there's a CSV module already

At the moment I don't know python and that code doesn't output everything in the file.  I also would like to do everything in visual basic 6.0.

But if you mean that there is a CSV module already made in visual basic 6.0, then I would like to know where to look for it.

Quote from: UserLoser on October 17, 2006, 09:01 PM
Visual Basic 6.0?
The code I posted reads the file and outputs .cvs files but is written in python.  I need to be able to read the file and access the data contained in the file using visual basic 6.0

#3
Here is the file I'm trying to read http://www.geocities.com/tontowmerlin/programing/file.html
The file contains variables that where stored by a c/c++ program.  I have tried opening the file in several different modes, but all I can get out of it is garbage.


Another guy has managed to read it in python using the following code:

from igc import *
import struct

class CSVEntityWriter:
    def write( self, f, entity, items = None, ignore = [] ):
        if items == None:
            items = entity.attribs.keys()
           
        for i in items:
            if entity.attribs.has_key( i ):
                f.write( '"' + str( entity.attribs[ i ] ) + '",' )
            else:
                f.write( ',' )

        if ignore == None:
            ignore = entity.attribs.keys()
           
        for name, value in entity.attribs.iteritems():
            if (not name in items) and (not name in ignore):
                f.write( '"' + str( value ) + '",' )
        f.write( "\n" )

class CSVWriter:
    def __init__(self, igcreader):
        self.reader = igcreader

    def write( self ):
        self.dir = self.reader.getCoreName() + '/'
        try:
            os.makedirs( self.dir )
        except OSError, err:
            if err.errno != errno.EEXIST:
                print "Fatal Error:", err
                return

        self.writeFactions()
        self.writeShips()
        self.writeParts()
        self.writeDmgTable()
        self.writeMissiles()
        self.writeMines()
        self.writeProbes()
        self.writeProjectiles()
        self.writeStations()
        self.writeDrones()
        self.writeChaff()
        self.writeTech()
        self.writeTreasure()

        self.writeChaffTable()
#        self.writeTechTrees()

    def writeData( self, path, data, attribs = None, ignore = [] ):
        entWriter = CSVEntityWriter()
       
        print "Writing", path, len(data), "entities"

        if len(data) == 0:
            return

        attribs = None
        ignore = []
        if attribs == None:
            attribs = data[0].attribs.keys()
        if ignore == None:
            ignore = data[0].attribs.keys()

        attribs.sort()
        f = file( self.dir + path, "w" )
        for a in attribs:
            f.write( '"' + a + '",' )
        for key in data[0].attribs:
            if ( not key in attribs ) and ( not key in ignore ):
                f.write( '"' + key + '",' )
        f.write( "\n" )
        for d in data:
            entWriter.write( f, d, attribs, ignore )

    def writeShips( self ):
        attribs = [ "Name", "Sig", "Scan", "Ammo", "Rip Time" ]
#        ignore = [ "Description" ]
        ignore = []
        self.writeData( "ships.csv", self.reader.ships, attribs, ignore )
       
    def writeFactions( self ):
        attribs = [ "Name", "Ship Sensors", "Ship Signature" ]
        self.writeData( "factions.csv", self.reader.factions, attribs )

    def writeTech( self ):
        attribs = [ "Name" ]
        ignore = [ "Description" ]
        self.writeData( "tech.csv", self.reader.techs, attribs, ignore )

    def writeParts( self ):
        attribs = [ "Name" ]
        ignore = [ "Description", "Type" ]
        self.writeData( "parts.csv", self.reader.parts, attribs, ignore )
        self.writeData( "weapons.csv", self.reader.weapons, attribs, ignore )
        self.writeData( "shields.csv", self.reader.shields, attribs, ignore )
        self.writeData( "cloaks.csv", self.reader.cloaks, attribs, ignore )
        self.writeData( "boosters.csv", self.reader.boosters, attribs, ignore )

    def writeMissiles( self ):
        attribs = [ "Name" ]
        ignore = [ "Description", "Unused" ]
        self.writeData( "missiles.csv", self.reader.missiles, attribs, ignore )

    def writeMines( self ):
        attribs = [ "Name" ]
        ignore = [ "Description", "Unused" ]
        self.writeData( "mines.csv", self.reader.mines, attribs, ignore )

    def writeDrones( self ):
        attribs = [ "Name" ]
        ignore = [ "Description", "Unused" ]
        self.writeData( "drones.csv", self.reader.drones, attribs, ignore )
   
    def writeChaff( self ):
        attribs = [ "Name" ]
        ignore = [ "Description", "Unused" ]
        self.writeData( "chaff.csv", self.reader.chaff, attribs, ignore )
   
    def writeProjectiles( self ):
        attribs = [ "UID" ]
        self.writeData( "projectiles.csv", self.reader.projectiles, attribs )

    def writeProbes( self ):
        attribs = [ "Name" ]
        ignore = [ "Description", "Unused" ]
        self.writeData( "probes.csv", self.reader.probes, attribs, ignore )

    def writeStations( self ):
        attribs = [ "Name" ]
        ignore = [ "Description", "Unused" ]
        self.writeData( "stations.csv", self.reader.stations, attribs, ignore )
   
    def writeDmgTable( self ):
        if self.reader.const != None:
            print "Writing dmgtable.csv"
            f = file( self.dir + "dmgtable.csv", "w" )
            f.write( '"DC \ AC","asteroid (AC0)","light (AC1)","medium (AC2)","heavy (AC3)","extra heavy (AC4)","utility (AC5)","minor base hull (AC6)","major base hull (AC7)","lt & med shield (AC8)","minor base shld (AC9)","major base shld (AC10)","parts (AC11)","lt base hull (AC12)","lt base shld (AC13)","large shield (AC14)","AC15","AC16","AC17","AC18","AC19"\n' )
            for i in range(20):
                f.write( '"DC' + str(i) + '",' )
                for j in range(20):
                    f.write( '"' + str( self.reader.const.dmgTable[ i*20 + j ] ) + '",' )
                f.write( '\n' )

    def writeChaffTable( self ):
        print "Writing chaff table"
        f = file( self.dir + "chaff_table.csv", "w" )

        f.write( '"Missile \ Chaff",' )
        for c in self.reader.chaff:
            f.write( '"' + c.attribs["ld_name"] + '",' )

        for m in self.reader.missiles:
            f.write( "\n" )
            f.write( '"' + m.attribs["ld_name"] + '",' )
            for c in self.reader.chaff:
                ecm = c.attribs["strength"]
                resist = m.attribs["resist"]
                chance = 0
                if( ecm <= resist ):
                    chance = 0.5 * ecm / resist
                else:
                    chance = 1.0 - (0.5 * resist / ecm)
                f.write( str(chance) + ',' )

    def writeTreasure( self ):
        self.writeData( "treasure_set.csv", self.reader.treasureset )

    def writeTechTrees(self):
        nodes = []
        nodes.extend( self.reader.parts )
        nodes.extend( self.reader.missiles )
        nodes.extend( self.reader.mines )
        nodes.extend( self.reader.probes )
        nodes.extend( self.reader.chaff )
        nodes.extend( self.reader.factions )
        nodes.extend( self.reader.techs )
        nodes.extend( self.reader.stations )
        nodes.extend( self.reader.ships )

        self.allNodes = nodes

        defMap = {}
        preMap = {}
        for i in range(400):
            defMap[str(i)] = []
            preMap[str(i)] = []

        uidMap =  {}
        for n in nodes:
            defs = n.attribs["Def"].split()
            pres = n.attribs["Pre"].split()
            tn = TechNode( n )
            uidMap[n] = tn
            for d in defs:
                defMap[d].append( tn )
            for p in pres:
                preMap[p].append( tn )

        self.uidMap = uidMap
        self.autodefs = []
        for i in range(400):
            if len(defMap[str(i)]) == 0:
                self.autodefs.append( str(i) )

        print "Writing Tech Tree"
        tfile = file( self.dir + "techtree.txt", "w" )
        for n, tn in uidMap.iteritems():
            tfile.write( tn.toString() + "\n" )
            for pre in tn.getPre().split():
                tfile.write( "    depends on: " + pre + "\n" )
                for dep in defMap[pre]:
                    tn.addParent( dep )
                    tfile.write( "         " + dep.toString() + " OR\n" )

#        self.writeFactionTree( self.factions[0] )

    def writeFactionTree(self, f):
        nw = NodeWalker( self.autodefs )
        nw.walk( self.uidMap[f] )

class NodeWalker:
    def __init__(self, defList):
        self.currentDefs = []
        self.currentDefs.append( defList )
        self.visitedNodes = []
        self.nodeQueue = []
        self.indent = 0

    def walk(self, node):
        if( self.meetsDefs( node ) and not self in self.visitedNodes ):
            print " "*self.indent + node.toString()
            self.indent += 2
            self.visitedNodes.append( self )
            defs = self.currentDefs[-1]
            defs.extend( node.getDef().split() )
            self.currentDefs.append( defs )
            self.nodeQueue.extend( node.children )
            while len(self.nodeQueue) > 0:   
                self.walk(self.nodeQueue.pop(0))
            self.indent -= 2
            self.currentDefs.pop()

    def meetsDefs(self, node):
        for p in node.getPre().split():
            if not p in self.currentDefs[-1]: return False
        return True

class TechNode:
    def __init__(self, entity):
        self.entity = entity
        self.parents = []
        self.children = []

    def getPre(self):
        return self.entity.attribs["Pre"]

    def getDef(self):
        return self.entity.attribs["Def"]

    def addParent(self, technode):
        if( technode != self and not technode in self.parents ):
            self.parents.append( technode )
            technode.children.append( self )

    def toString(self):
        return self.entity.toString()

class HTMLEntityWriter:
    def write( self, f, entity, items = None, ignore = [] ):
        if items == None:
            items = entity.attribs.keys()

        f.write( "<TR>" )
        for i in items:
            if entity.attribs.has_key( i ):
                if type( entity.attribs[ i ] ) is float:
                    f.write( '<TD>' + str( round( entity.attribs[ i ], 2 ) ) + '</TD>' )
                else:
                    f.write( '<TD>' + str( entity.attribs[ i ] ) + '</TD>' )
            else:
                f.write( '<TH></TH>' )

        if ignore == None:
            ignore = entity.attribs.keys()

        for name, value in entity.attribs.iteritems():
            if (not name in items) and (not name in ignore):
                if type( value ) is not float:
                     f.write( '<TD>' + str( value ) + '</TD>' )
                else:
                     f.write( '<TD>' + str( round( value, 2 ) ) + '</TD>' )

        f.write( "<TR>" )

def sortByAttrib( ents, key ):
    entMap = {}
    for e in ents:
        if not entMap.has_key( e.attribs[key] ):
            entMap[ e.attribs[key] ] = [ e ]
        else:
            entMap[ e.attribs[key] ].append( e )

    sList = []
    sKeys = entMap.keys()
    sKeys.sort()
    for k in sKeys:
        for s in entMap[ k ]: sList.append( s )

    return sList

class HTMLWriter:
    def __init__(self, reader):
        self.reader = reader

    def fillData(self, data, ent):
        d = data[:]
        for s in re.findall("\[.+?\]",d):
            d = string.replace(d, s, ent.getAttrib( s[1:-1] ))
        return d

    def writeHTMLTOC(self, ents, f):
        f.write( '<P>\n' )
        for e in ents:
            f.write('- <A HREF="#' + e.getAttrib("Name") + e.getAttrib("UID") + '">' + e.getAttrib("Name") + '</A> ' )
           
    def writeHTMLBody(self, ents, f, template):
        data = file( 'templates/' + template, "r").read()
        for e in ents:
            f.write( self.fillData( data, e ) )

    def writeData(self, f, header, template, data):
        print "Writing", header, len(data), "entities"
        f.write( "<H1>" + header + "</H1>\n" )
        sdata = sortByAttrib( data, "Name" )
        self.writeHTMLTOC(sdata, f)
        self.writeHTMLBody(sdata, f, template)

    def writeShipsByFaction(self):
        for f in self.reader.factions:
            ships = self.reader.filterByFaction( self.reader.ships, f )
            ships = sortByAttrib( ships, "Name" )
            print "Writing ships for faction", f.toString(), len(ships), "entities"
            output = file( self.dir + f.attribs["Name"] + ".html", "w" )
            output.write( "<H1>" + f.attribs["Name"] + " Ships</H1>\n" )
            self.writeHTMLTOC(ships, output)
            self.writeHTMLBody(ships, output, "ship_template.html" )

    def writeEquipment(self):
        self.writeData( file( self.dir + "probes.html","w"), "Probes", "probe_template.html", self.reader.probes )
        self.writeData( file( self.dir + "missiles.html","w"), "Missiles", "missile_template.html", self.reader.missiles )
        self.writeData( file( self.dir + "shields.html","w"), "Shields", "shield_template.html", self.reader.shields )
        self.writeData( file( self.dir + "boosters.html","w"), "Boosters", "boost_template.html", self.reader.boosters )
        self.writeData( file( self.dir + "weapons.html","w"), "Weapons", "weapon_template.html", self.reader.weapons )
        self.writeData( file( self.dir + "cloaks.html","w"), "Cloak", "cloak_template.html", self.reader.cloaks )

    def write(self):
        self.dir = self.reader.getCoreName() + '/'
        try:
            os.makedirs( self.dir )
        except OSError, err:
            if err.errno != errno.EEXIST:
                print "Fatal Error:", err
                return

        self.writeShipsByFaction()
        self.writeEquipment()
 

for fname in os.listdir("."):
if fname[-4:] == ".igc":
print "**** DUMPING", fname, "****"
reader = IGCReader()
reader.open( fname )
CSVWriter(reader).write()

##if len( sys.argv ) < 2:
##    reader.open( "dn_000450.igc" )
##else:
##    reader.open( sys.argv[1] )
##
##if len( sys.argv ) < 3:
##    HTMLWriter(reader).write()
##else:   
##    if sys.argv[2] == "CSV":
##        CSVWriter(reader).write()
#4
Visual Basic Programming / Re: Resetting Focus
August 14, 2005, 03:21 PM
Search for the Keyword, " AddChat ".   Its a the a commonly used sub for text boxs in bots.
#5
Thanks.  What I was asking about was other ways to acheve the same thing as Grok's DebugOutput function without the string off to the side, I thinkI saw it done in one line on the bot develobment forum, but I haven't been able to find it agen.
#6
Or he could look at http://forum.valhallalegends.com/phpbbs/index.php?topic=11582.0 .  (note: start->run->regedit)
#7
If you just want to copy someone else work then you should just use cleanslatebot2.

But, if you want to do some actual work  :o , then
http://forum.valhallalegends.com/phpbbs/index.php?action=search (google works too)
and
http://forum.valhallalegends.com/phpbbs/index.php?topic=11941.15
Would be of some help.
#8
What are the differrent methods for converting string to hex and vice versa?

I found:
http://forum.valhallalegends.com/phpbbs/index.php?topic=12151.0
Quote
Here's a function I wrote to convert from String to HEX:

Public Function ToHex(ByVal strString As String) As String
Dim A&, strOut$, strC$
For A = 1 To Len(strString)
    If Len(Hex(Asc(Mid(strString, A, 1)))) = 1 Then
       strOut = strOut & " " & "0" & Hex(Asc(Mid(strString, A, 1)))
    Else
       strOut = strOut & " " & Hex(Asc(Mid(strString, A, 1)))
    End If
Next A
ToHex = strOut
End Function


What this function does is goes through every single character of a string, get's the ASCII value of it, then converts it to HEX using Visual Basic's Hex() function. If the length of the HEX value of the ASCII value is only 1, it adds a 0 before it to make it valid. (Byte)

This function does take quite a bit of lag to execute, so I wouldn't suggest using this very often.

Here's a function I wrote to convert from HEX to String formats.

Public Function ToStr(ByVal strString As String) As String
strString = Replace(strString, " ", "")
Dim A&, strOut$, strC$
For A = 1 To Len(strString) Step 2
       strOut = strOut & Chr(Val("&H" & Mid(strString, A, 2)))
Next A
ToStr = strOut
End Function


This function goes through every byte of a hex string, gets the character value of it, and returns a full line in String format.

But, I figured that there are probabbly other ways wich may be better.
#9
Quote from: Topaz on August 02, 2005, 06:25 PM
I need a reference to a list of what all the Chr() refer to.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbstartpage.asp look on the left and go additional information->Reference->Charater set
#10
Fome the link I gave
Quote
On an attempt to make it easier for the users. I have made an installer, all you do is chose the destination file.

Destination File: Your BG3 folder.

Installer: Click Me

Change Log:
SC, SC:BW Verbyte changed to 0xCD.

Now updateing hashes is in your hands. I will not release any.

Update BG3.
#11
CommView works for every other packet (evaluation); I don't want to buy it because I'm probably only going to use it once.  And AnalogX pmon doesn't support Win 98.
#12
Or you could use BG3 if you don't want to do any codeing.  http://www.bnetalliance.com/forums/postlist.php?Cat=&Board=bg3
#13
Dose anyone know of a packet logger that supports Dialup adapters?
#14
I managed to find a compiled vershion of Tcpdump on download.com.  It didn't work  :-\ .  Nothing I found on download.com worked...  :-\ :-\ :'(

Shure, thay found my network card ok, but none of them found my 56k dileup modem.  :'( PLEASE PLEASE HELP!!!!!!