[MaxScript 12] ReadLong returns true?

Joined
Aug 14, 2009
Messages
2,308
Reaction score
1,207
Hey,

Maybe someone has knowledge about MaxScript. I normally don't write "help" threads but I'm now clueless for about ~3 Hours.

So I want to rewrite / update the LoL skl importer from 2009, for WarZ / War Inc / Eclipse Engine Stuff.

Now to my problem:

The skeleton files are in binary format. I'm able to read them trough C# (I "translated" the maxscript to C#):

Code:
public void LoadFromStream(BinaryReader bstream)
        {
            type = bstream.ReadChars(8);
            version = bstream.ReadUInt32();
            flag1 = bstream.ReadUInt32();
            bones = bstream.ReadUInt32();
        }

But with the MaxScript I get the following error:

Code:
true
SKL_Header
----------
type: r3d2sklt
1: -- Error occurred in DebugOut(); filename: C:\Program Files\Autodesk\3ds Max 2012\Scripts\Eclipse Model\LOL_allinone.ms; position: 2258; line: 104
--  Frame:
--   called in LoadSkeleton(); filename: C:\Program Files\Autodesk\3ds Max 2012\Scripts\Eclipse Model\LOL_allinone.ms; position: 6764; line: 320
--  Frame:
--   header: (LOL_Skeleton_Header type:"r3d2sklt" sklVersion:<<error printing value>>
--   boned: undefined
--   called in import(); filename: C:\Program Files\Autodesk\3ds Max 2012\Scripts\Eclipse Model\LOL_allinone.ms; position: 8993; line: 428
--  Frame:
--   called in importSKL.pressed(); filename: C:\Program Files\Autodesk\3ds Max 2012\Scripts\Eclipse Model\LOL_tool.ms; position: 4015; line: 150
--  Frame:
--   sklFilename: "D:\Server\Rar Files\Infestation MMO\WarZSources\bin\Data\ObjectsDepot\Weapons\ASR_AKM_Turkey_FPS.skl"
--   inipath: "C:\Program Files\Autodesk\3ds Max 2012\scripts\LOLtool.ini"
--   filename: "D:\Server\Rar Files\Infestation MMO\WarZSources\bin\Data\ObjectsDepot\Weapons\ASR_AK74.sco"
--   importer: (LOL_Import file_sco:"D:\Server\Rar Files\Infestation MMO\WarZSources\bin\Data\ObjectsDepot\Weapons\ASR_AKM_Turkey_FPS.skl" file_skl:"D:\Server\Rar Files\Infestation MMO\WarZSources\bin\Data\ObjectsDepot\Weapons\ASR_AKM_Turkey_FPS.skl" file_wgt:"D:\Server\Rar Files\Infestation MMO\WarZSources\bin\Data\ObjectsDepot\Weapons\ASR_AKM_Turkey_FPS.skl" fstream:undefined line:undefined surfacename:undefined centralpoint:undefined vertlist:#() tvertlist:#() trislist:#() new_mesh:undefined bstream:<BinStream:D:\Server\Rar Files\Infestation MMO\WarZSources\bin\Data\ObjectsDepot\Weapons\ASR_AKM_Turkey_FPS.skl> boneNames:#() boneLinks:#() boneList:#() nodes:#() weights:#())

This is the maxscript:
Code:
fn ReadFixedString bstream fixedLen =
(
   local str = ""
   for i = 1 to fixedLen do
   (
      str0 = ReadByte bstream #unsigned
      if str0!=0xFD AND str0!=0xFC do str+= bit.intAsChar str0
   )
   str
)

struct LOL_Skeleton_Header
(
	type,			--"r3d2sklt"
	sklVersion,		-- always 1?
	flag1, 			-- dunno what this is
	numBones,			-- number of bone indices

	fn LoadFromStream bstream=
	(
		type		= ReadFixedString bstream 8
		sklVersion = ReadLong bstream #unsigned
		flag1		= ReadLong bstream #unsigned
		numBones	= ReadLong bstream #unsigned
	),
	fn IsValid=
	(
		if type != "r3d2sklt" then return false
		true
	),
		
	fn DebugOut=
	(
		print(sklVersion as String)
		format "SKL_Header\n----------\n"
		format "type: %\n1: %, 2: %, 3: %\n" type sklVersion flag1 numBones
		ok
	)
)

I tried replacing the ReadLong to ReadString (obviously it returns this "[SOH]" as binary^^).

I noticed If I convert the "Long" to string it gives me "true", but wtf. Shouldn't ReadLong return an Integer and read exactly 4 bytes of data?

Quote from MaxScript Help:
<Integer>ReadLong <BinStream> [#signed | #unsigned]
Read a four byte value and return as an Integer.

Forgot to mention the error is at:
format "type: %\n1: %, 2: %, 3: %\n" type sklVersion flag1 numBones

and 3dsmax says:
---------------------------
MAXScript Rollout Handler Exception
---------------------------
MAXScript error - unable to show details
---------------------------
OK
---------------------------

EDIT2:
I got it. sklVersion must be signed.

#closerequest
 
Last edited:
Back