Noesis tutorial Basic Model

Read or post any tutorial related to file format analysis for modding purposes.
User avatar
Seyren
advanced
Posts: 58
Joined: Sat Oct 30, 2010 1:39 pm
Has thanked: 18 times
Been thanked: 9 times

Re: Noesis tutorial Basic Model

Post by Seyren » Tue May 13, 2014 12:06 am

I know this may sound dumb but i got lost in the very first steps.

I just did this:

Code: Select all

#Noesis Python model import+export test module, imports/exports some data from/to a made-up format

from inc_noesis import *

import noesis

#rapi methods should only be used during handler callbacks
import rapi

#registerNoesisTypes is called by Noesis to allow the script to register formats.
#Do not implement this function in script files unless you want them to be dedicated format modules!
def registerNoesisTypes():
	handle = noesis.register("S4 League", ".scn")
	noesis.setHandlerTypeCheck(handle, noepyCheckType)
	noesis.setHandlerLoadModel(handle, noepyLoadModel) #see also noepyLoadModelRPG
	#noesis.setHandlerWriteModel(handle, noepyWriteModel)
	#noesis.setHandlerWriteAnim(handle, noepyWriteAnim)

	noesis.logPopup()
	print("The log can be useful for catching debug prints from preview loads.\nBut don't leave it on when you release your script, or it will probably annoy people.")
	return 1


#check if it's this type based on the data
def noepyCheckType(data):
	bs = NoeBitStream(data)
	if bs.readInt() != 0x01000000 :
		return 0
	return 1

#load the model
def noepyLoadModel(data, mdlList):
	ctx = rapi.rpgCreateContext()
	bs = NoeBitStream(data)
	rapi.rpgClearBufferBinds()
	hdrInfo = bs.read("i")
	print(hdrInfo)	
	return 1
Not a big deal, just trying to read an int and in the guide it said it was going to be written in the output log, but only this shows up:

Image

I think it has something to do with the header reading, but i don't know what to do.

I'm not sure if this is supposed to happen, since the images from the tutorial are missing and i'm not sure if i should continue or not.

I know this is one of those mistakes that will make you be ashamed for life, but i don't know what is wrong, i'm sorry :(

File i'm trying to read is attached in the post
You do not have the required permissions to view the files attached to this post.

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2605
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 638 times
Been thanked: 1332 times

Re: Noesis tutorial Basic Model

Post by shakotay2 » Tue May 13, 2014 7:10 am

use this line:
if bs.readInt() != 0x00000001 :

because the signature 01 00 00 00 in the header is little endian.
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
Seyren
advanced
Posts: 58
Joined: Sat Oct 30, 2010 1:39 pm
Has thanked: 18 times
Been thanked: 9 times

Re: Noesis tutorial Basic Model

Post by Seyren » Wed May 14, 2014 2:46 am

Thank you for your help shakotay2, once again you got me out of this nooby issues :erm:

I got another question, how does the Vertex Buff actually works? Since in the guide they use the following:

Code: Select all

VertBuff = bs.readBytes(VCount[0] * 0x58)
   rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, 88, 0)
   rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, VCount[0], noesis.RPGEO_POINTS, 1)
   mdl = rapi.rpgConstructModel()
   mdlList.append(mdl)         #important, don't forget to put your loaded model in the mdlList
I don't really know what a vertex with a size of 88 bytes meant, so i started trying random numbers until one worked, which was 24.

Image
Using sword.scn
(Vertex count: 0x0986, after that there are 345 floats and the int that tells you the faces, which is positioned at 0x19B6, in this case are 282 faces)


the bad thing for this is that the number of the vertices, faces, uvs, etc are between the buffers, so the only way to be able to continue to get the number of faces is by using 0x04 instead of 0x18

So my question is, since the coordinates are made by floats,and since floats are 4 bytes, should i use 4 or should i use 24 and go back to the position of the faces count?, because if i do the last thing i said using FaceBuff = bs.readBytes(FCount[0] * 2) the following result appears:

Image

Thanks in advance again ^^

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2605
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 638 times
Been thanked: 1332 times

Re: Noesis tutorial Basic Model

Post by shakotay2 » Thu May 15, 2014 1:48 pm

didn't get exactly what you mean.
use this for sword.scn (and only sword.scn):

Code: Select all

#Noesis Python model import+export test module, imports/exports some data from/to a made-up format

from inc_noesis import *

import noesis

#rapi methods should only be used during handler callbacks
import rapi

#registerNoesisTypes is called by Noesis to allow the script to register formats.
#Do not implement this function in script files unless you want them to be dedicated format modules!
def registerNoesisTypes():
   handle = noesis.register("S4 League", ".scn")
   noesis.setHandlerTypeCheck(handle, noepyCheckType)
   noesis.setHandlerLoadModel(handle, noepyLoadModel) #see also noepyLoadModelRPG
   #noesis.setHandlerWriteModel(handle, noepyWriteModel)
   #noesis.setHandlerWriteAnim(handle, noepyWriteAnim)

   noesis.logPopup()
   print("The log can be useful for catching debug prints from preview loads.\nBut don't leave it on when you release your script, or it will probably annoy people.")
   return 1


#check if it's this type based on the data
def noepyCheckType(data):
   bs = NoeBitStream(data)
   if bs.readInt() != 0x00000001 :
      return 0
   return 1


#load the model
def noepyLoadModel(data, mdlList):
   ctx = rapi.rpgCreateContext()
   bs = NoeBitStream(data)
   rapi.rpgClearBufferBinds()
   hdrInfo = bs.read("i")
   print(hdrInfo)   
   # works for sword.scn only!
   bs.seek(0x982, NOESEEK_ABS)  #Seek to counts
   facesCount = bs.read("i")	# faces count
   vertsCount = bs.read("i")
   VertBuff = bs.readBytes(vertsCount[0] * 12)
   facesCount2 = bs.read("i")	# faces count again
   print(facesCount2)
   if facesCount2!=facesCount:
      print("error: 2nd facesCount doesn't match!")
      return 1
   idxBuff = bs.readBytes(facesCount[0] *2 *3)
   rapi.rpgBindPositionBufferOfs(VertBuff, noesis.RPGEODATA_FLOAT, 12, 0)
   #rapi.rpgCommitTriangles(None, noesis.RPGEODATA_USHORT, facesCount[0], noesis.RPGEO_POINTS, 1)
   rapi.rpgCommitTriangles(idxBuff, noesis.RPGEODATA_USHORT, facesCount[0]*3, noesis.RPGEO_TRIANGLE, 1)
   mdl = rapi.rpgConstructModel()
   mdlList.append(mdl)          #important, don't forget to put your loaded model in the mdlList

   return 1
it's just a quick hack - I'm not familiar with Noesis.

(Maybe it's a good idea to edit further questions into your previous post?
So not to spam chrrox' tutorial.)
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2387
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 296 times

Re: Noesis tutorial Basic Model

Post by finale00 » Thu Jun 19, 2014 5:24 pm

You should bump chrrox's tutorial as much as you can.

clang7775
ultra-n00b
Posts: 9
Joined: Sun Sep 28, 2014 7:31 pm

Re: Noesis tutorial Basic Model

Post by clang7775 » Sun Sep 28, 2014 7:43 pm

Thanks for the tutorial! Time to dust off my python skills (and indenting!)

deltaone
beginner
Posts: 37
Joined: Sat Feb 19, 2011 1:18 am
Has thanked: 4 times
Been thanked: 12 times

Re: Noesis tutorial Basic Model

Post by deltaone » Thu Oct 30, 2014 10:28 am

anyone have images for this this tutorial ?

thx ...

MarieRose1301
advanced
Posts: 55
Joined: Sat Oct 11, 2014 10:29 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Noesis tutorial Basic Model

Post by MarieRose1301 » Thu Jun 25, 2015 10:17 am

Hello. i just began writing a script for a game and i think i got the wrong header because i get this error:
Image

http://sta.sh/21xrx3h6mxxn?edit=1 - these are the model and the script,anyone able to tell me what's wrong and how to fix it?

User avatar
chrrox
Moderator
Posts: 2512
Joined: Sun May 18, 2008 3:01 pm
Has thanked: 57 times
Been thanked: 1244 times

Re: Noesis tutorial Basic Model

Post by chrrox » Thu Jun 25, 2015 10:33 am

the string you are showing is not ascii and its not 16 bytes long.
try something like

NOEPY_HEADER = 0x334D430A

#check if it's this type based on the data
def noepyCheckType(data):
bs = NoeBitStream(data)
if len(data) < 4:
return 0
if bs.readUInt() != NOEPY_HEADER:
return 0

MarieRose1301
advanced
Posts: 55
Joined: Sat Oct 11, 2014 10:29 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Noesis tutorial Basic Model

Post by MarieRose1301 » Thu Jun 25, 2015 10:42 am

It gives me an other error this time Image
It's my first time writing a noesis plugin, so I'm a little bit lost here, sorry

User avatar
chrrox
Moderator
Posts: 2512
Joined: Sun May 18, 2008 3:01 pm
Has thanked: 57 times
Been thanked: 1244 times

Re: Noesis tutorial Basic Model

Post by chrrox » Thu Jun 25, 2015 11:00 am

Here is a start for you.
You do not have the required permissions to view the files attached to this post.

MarieRose1301
advanced
Posts: 55
Joined: Sat Oct 11, 2014 10:29 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Noesis tutorial Basic Model

Post by MarieRose1301 » Thu Jun 25, 2015 11:23 am

Thank you so much, i hope there won't be any more problems ^^'

User avatar
Acewell
VIP member
VIP member
Posts: 1187
Joined: Wed Nov 05, 2008 12:16 pm
Has thanked: 2330 times
Been thanked: 689 times

Re: Noesis tutorial Basic Model

Post by Acewell » Fri Apr 29, 2016 12:58 am

finale00 wrote:There are several ways to go to different positions of a file (eg: seeking)

They are typically seeking from
-beginning of the file (absolute offset) eg: seek_abs
-current position (relative offset) eg: seek_curr
-end of file (seeking backwards)
So what is the correct syntax in Noesis for seeking to an offset from the end of a file?
i have been trying something like bs.seek(-44, 2) without success. :(

User avatar
shakotay2
MEGAVETERAN
MEGAVETERAN
Posts: 2605
Joined: Fri Apr 20, 2012 9:24 am
Location: Nexus, searching for Jim Kirk
Has thanked: 638 times
Been thanked: 1332 times

Re: Noesis tutorial Basic Model

Post by shakotay2 » Fri Apr 29, 2016 4:32 am

"2" is ony valid when using import os, I guess - since there's
NOESEEK_ABS = 0 and NOESEEK_REL = 1 only.

I tried such (import os required)

Code: Select all

   fileName= 'G:\test.txt'

   statinfo = os.stat(fileName)
   print("statinfo, file size: ", statinfo.st_size)
   fsize= statinfo.st_size
   with open(fileName, "rb") as f:
       #f.seek(fsize-11, os.SEEK_SET)
       f.seek(-11, 2)
       a= f.read()
       print("a: ", a)
where test.txt is an ASCII file, opened in binary mode (to avoid weird outputs from print())
Both f.seek lines worked - if you use f.seek(-11, 2) you don't need to get the file size!

But I dunno how to get the filename via rapi, when the file is opened in the Noesis file explorer -

bs = NoeBitStream(data)
bs.seek(-11, 2) didn't work.
Bigchillghost, Reverse Engineering a Game Model: viewtopic.php?f=29&t=17889
extracting simple models: viewtopic.php?f=29&t=10894
Make_H2O-ForzaHor3-jm9.zip
"You quoted the whole thing, what a mess."

User avatar
Acewell
VIP member
VIP member
Posts: 1187
Joined: Wed Nov 05, 2008 12:16 pm
Has thanked: 2330 times
Been thanked: 689 times

Re: Noesis tutorial Basic Model

Post by Acewell » Sat Apr 30, 2016 1:18 am

Okay thanks, i hoped there was something simple i was overlooking like NOESEEK_END i could use. i don't know enough about programming to make work what you have there. i will have to find another way :(

editx2
okay this works :D

Code: Select all

    bs.seek(len(data) - 0x2C, NOESEEK_ABS) #goto 44 bytes from end of file

Post Reply