Staredit Network

Staredit Network -> Computers and Technical -> Loading CHKs
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-20 at 21:00:48
Whenever I try loading a CHK, I end up with this (converted to .txt so I could upload it)
[attachmentid=14653]

How do I load a file without it becoming null? (It is null, I converted it to hex and checked. Some things are 01h though)
Report, edit, etc...Posted by LegacyWeapon on 2005-10-21 at 18:36:17
Open it with binary mode.
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-23 at 01:04:09
What is binary mode, and how would I open it with binary mode.

In binary mode, would things be "01000011 01001111 01001100 01010010" (in binary), or "COLR" (in ASCII)?

If its in binary, is there a Hex mode?
Report, edit, etc...Posted by DT_Battlekruser on 2005-10-23 at 02:05:33
Been a while since I touched VB, but the command that opens a file makes you select a mode for opening and one is binary..
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-23 at 02:38:42
I have to script everything; I do not have Windows XP...
Report, edit, etc...Posted by BSTRhino on 2005-10-23 at 03:04:33
I know .NET well but I can't give you 100% clear instructions for VB6 or earlier. Binary is a lot like reading in ASCII mode, but the system doesn't do conversions for newlines, UNICODE and things like that. I don't remember exactly how it is done in VB6, but I think you read one byte at a time in binary mode, is that correct? It loads the data one byte at a time into a variable of type byte, doesn't it?

You can use the CHR function to convert this byte value into a character, and concatenate it with other characters. Most people store bytes as strings by doing this.

QUOTE
I do not have Windows XP...

I'm trying to see why that's relevant, but I can't work it out...
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-23 at 03:07:07
QUOTE(BSTRhino @ Oct 23 2005, 01:04 AM)
I know .NET well but I can't give you 100% clear instructions for VB6 or earlier. Binary is a lot like reading in ASCII mode, but the system doesn't do conversions for newlines, UNICODE and things like that. I don't remember exactly how it is done in VB6, but I think you read one byte at a time in binary mode, is that correct? It loads the data one byte at a time into a variable of type byte, doesn't it?

You can use the CHR function to convert this byte value into a character, and concatenate it with other characters. If you have to read, say, four bytes and combine them into an integer, then you can first multiply them by different powers of two to get them into the right "decimal" place (or binary place) and then add them together. I don't know if VB6 has a built-in type that lets you store a series of bytes like you store a series of characters in a string. You might need to create a byte array and stick byte arrays into collections or something.
I'm trying to see why that's relevant, but I can't work it out...
[right][snapback]339482[/snapback][/right]

That is what I am looking for (CHKs aren't Unicode, and they don't use NewLines except in strings) biggrin.gif
Is there a way to get it in VBS? Some things don't work in the scripting.
Report, edit, etc...Posted by MindArchon on 2005-10-23 at 03:09:00
QUOTE(O)FaRTy1billion @ Oct 22 2005, 11:38 PM)
I have to script everything; I do not have Windows XP...
[right][snapback]339464[/snapback][/right]


Script? You dont have Visual Basic 6? Are you using VBS?
Edit: Oh, you ARE using script, so that brings me to...

Why are you using VBS?

Anyway, here is the code I use in Visual Basic 6. It may work for VBS.

CODE
Open App.Path & "\scenario.chk" for binary as #1

'//Parse the CHK

Close #1


There are several ways you can parse the chk, you can output each section into an array, or read from it directly, it depends on what you are trying to accomplish.
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-23 at 13:49:08
Windows ME does not support Visual Studios or any of those. (Need Windows 2000 or later)
Report, edit, etc...Posted by MindArchon on 2005-10-23 at 16:28:07
QUOTE(O)FaRTy1billion @ Oct 23 2005, 10:49 AM)
Windows ME does not support Visual Studios or any of those. (Need Windows 2000 or later)
[right][snapback]339701[/snapback][/right]


.. My copy of Visual Basic 6 is from 1998. Why wouldnt ME run it?

ME probably cannot run .NET
Report, edit, etc...Posted by BSTRhino on 2005-10-23 at 18:03:26
Have you seen the VBScript documentation? http://www.microsoft.com/downloads/details...&displaylang=en

It might be helpful if you get stuck, it's the best reference I've found for it. I don't think that VBScript has an Open statement, does it? I can't find it in the reference. You can use the FileSystemObject though, that's what I've been using for the MPQ Compactor (which is JScript, but it's the same thing basically.) But the TextStream object in the FileSystemObject thingy doesn't do binary, that's the problem. I've made it read and write binary files before though, but I guess the UNICODE or two-character newline thing doesn't get in the way, so perhaps it might work.

Read the reference about the FileSystemObject and see what it can teach you. I have knowledge about using the FileSystemObject if you need it, I've used it quite a bit.
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-23 at 18:37:48
I used FSO to get what I first posted.
What is "Genuine Microsoft Windows"?

I once made a script to try and get it to change player colors, and that is when I found it. So I tried this:
CODE
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ReadFile = FSO.OpenTextFile(App.Path & "\scenario.chk", 1)
Set WriteFile = FSO.OpenTextFile(App.Path & "\scenario.txt", 2, True)
WriteFile.Write ReadFile.ReadAll
ReadFile.Close
WriteFile.Close

And that is what I used to get the text file I attached in the first post. (or something pretty closed, typed that out from what I remembered)
Report, edit, etc...Posted by LegacyWeapon on 2005-10-23 at 18:51:17
I goggled "vbs binary access"
http://www.pstruh.cz/tips/detpg_read-write-binary-files/
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-23 at 20:16:10
I have a C program to convert CHK files into a hex file.
Could I use that?
Can you use VBS to act like a batch file?
CODE
@echo off
echo Converting...
chkhex scenario.chk > scenario.chk.hex
Exit
Report, edit, etc...Posted by BSTRhino on 2005-10-23 at 21:09:24
Wouldn't it would be easier to go (bear with me, I'm converting my JavaScript knowledge into VBScript here):

CODE
Dim fso, inputStream, sectionName, sectionLength, sectionData
Set fso = CreateObject("Scripting.FileSystemObject")
Set inputStream = FSO.OpenTextFile(App.Path & "\scenario.chk", 1)

While Not TextStream.AtEndOfStream
sectionName = inputStream.Read(4)
sectionLength = AscB(inputStream.Read(1)) + AscB(inputStream.Read(1)) * 256 + AscB(inputStream.Read(1)) * 256 ^ 2 + AscB(inputStream.Read(1)) * 256 ^ 3

sectionData = inputStream.Read(sectionLength)
'sectionData = inputStream.Skip(sectionLength)
Wend


AscB converts a character into a byte value without doing any UNICODE stuff. Anyway, that'd be a skeleton of what you might do. You could change the Read method with a Skip method like I've described there if you're looking at a section which you don't care about.

If you want to run a program and capture its output:
CODE
Dim shellObject, execObject, execOutputStream, execData
Set shellObject = WScript.CreateObject("WScript.Shell")
Set execObject = shellObject.Exec("chkhex scenario.chk")
Set execOutputStream = execObject.StdOut

execData = ""
While execObject.Status = 0
While Not execOutputStream.AtEndOfStream
execData = execData & execOutputStream.ReadAll
Wend
WScript.Sleep 100
Wend


It'd be something like that. I used that to capture errors from IceCC in one of my scripts, but I can't remember if that was my exact (VBScript translated) code or not.
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-25 at 19:34:57
At least now it is not all nulls...
Report, edit, etc...Posted by BSTRhino on 2005-10-27 at 15:05:16
No, so, does that mean it's fixed?

Did you need more help with anything specific?
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-27 at 19:54:02
It means I got something other than mostly nulls.. but if you know anything bout CHKs you can see that is way wrong.
Report, edit, etc...Posted by BSTRhino on 2005-10-27 at 22:39:29
I guess... but what exactly are you trying to do when loading your CHK? When I read that file I can see the strings in the string section just fine, and I'm using that as a basis to tell me that it's probably loading everything in the file fine. Perhaps if you told me what you wanted to do I'd be able to help.
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-27 at 22:50:41
I'm trying to laod CHKs to edit parts of them, but whatever I try using to load them corrupts them somehow.
I am trying now to run CHKHEX.exe so I can load it as a string (in hex). But if I make it run a Batch file it ignores the Exit command...
Report, edit, etc...Posted by BSTRhino on 2005-10-28 at 18:05:41
Hmmm... I can't find anything corrupted with it from this point of view, but perhaps I'm looking in the wrong place. I opened up your CHK in SCXE 2.6 Special Mode and it loaded fine. I see a twilight terrain map which is really thin on the horizontal dimension. Is there a specific part of the data which is being corrupted?
Report, edit, etc...Posted by O)FaRTy1billion on 2005-10-29 at 12:16:03
blushing.gif I might know the problem...
I may be opening it with a different text editor. Let me check..


ADDITION:
Yup, that was the problem. If I open them with the same text editor they are the same. (One opened with WordPad, the other would open with Notepad.)

Thanks for the help biggrin.gif
Report, edit, etc...Posted by BSTRhino on 2005-10-29 at 17:22:57
Oh cool, I'm glad I could be of help.
Next Page (1)