Jump to content
  • 0
Sign in to follow this  
rteshima

Request AI.OBJ Editor Gracia Epilogue

Question

5 answers to this question

Recommended Posts

  • 0
On 12/5/2018 at 12:38 AM, rteshima said:

The decompiler could execute it and modify the files that I wanted, but the compiler does not work for me.

 

You need one single NASC source file in UTF-16LE encoding, then it should work fine. If you're using split and/or UTF-8 options in decompiler, you'll have to write some script that will join and recode that into one single UTF-16LE file (in correct order).

Share this post


Link to post
Share on other sites
  • 0
On 12/7/2018 at 4:58 PM, rteshima said:

uhh so complicated: / .. It might be that I'm not working because they are advext files?

 

I replied you in mail but as someone else might need it, I'll copy my response here as well:

 

 

Hi, it should run on Win Vista and newer and the single input NASC file has to be UTF-16LE.

 

I personally use split AI structure which looks like this

 

C:/l2/ai-src/default_npc.nasc

C:/l2/ai-src/default_npc/citizen.nasc

C:/l2/ai-src/default_npc/citizen/merchant.nasc

C:/l2/ai-src/default_npc/citizen/merchant/bandor.nasc

...

 

all these files are in UTF-8 without BOM (Byte Order Mask)

 

I also have NASC there:

 

C:/l2/nasc/compile.bat

C:/l2/nasc/l2npc/l2npc.exe

...

 

I join it, recode it to UTF-16LE and compile it with C:/l2/make.py:

 

#!/usr/bin/env python

# (C) 2017 L2Shrine.com

# Usage:
#
# If you need just some classes, run "make.py" and let it compile everything that's not up to date
# If you need to compile whole ai to get full ai.obj for server, run "make.py all"

from os import walk, stat, getcwd, system, mkdir, unlink
from codecs import open
from sys import stderr, argv
from glob import glob

makeAll = False
if len(argv) == 1:
    pass
elif len(argv) == 2:
    if argv[1] == "all":
        makeAll = True
    else:
        print >> stderr, "Usage: %s [all]" % (argv[0], )
        raise SystemExit(1)
else:
    print >> stderr, "Usage: %s [all]" % (argv[0], )
    raise SystemExit(1)

if makeAll:
    aiFilename = "ai"
else:
    aiFilename = "tmp"

cwd = getcwd()

def createPath(s):
    if s.startswith(u"\\\\?\\"):
        return s.replace("/", "\\")
    return u"\\\\?\\%s\\%s" % (cwd, s.replace("/", "\\"), )

files = []

for path, dirnames, filenames in walk(createPath("ai-src")):
    for i in filenames:
        srcPath = createPath("%s/%s" % (path, i, ))
        objPath = createPath("%s/%s" % (path[:len(cwd)+4] + path[len(cwd)+4:].replace("\\ai-src", "\\ai", 1), i.replace(".nasc", ".txt"), ))
        statSrc = stat(srcPath)
        try:
            if makeAll: raise Exception()
            statObj = stat(objPath)
        except:
            statObj = None
        if statObj == None or max(statSrc.st_ctime, statSrc.st_mtime) >= max(statObj.st_ctime, statObj.st_mtime):
            files.append(srcPath)

if not files:
    print "Everything up to date"
    raise SystemExit(0)

try:
    unlink("%s.obj" % (aiFilename, ))
except:
    pass
fw = open("%s.nasc" % (aiFilename, ), "w", "utf-16le")

required = set(files)
written = set()

if not makeAll:
    print >> stderr, "Going to compile:"

for i in files:
    if not makeAll:
        print >> stderr, "    %s" % (i.replace("\\", "/").split("/")[-1], )
    parts = i[len(createPath("ai-src/")):].replace("\\", "/").split("/")
    for j in xrange(len(parts)):
        if j != len(parts) - 1:
            filename = createPath("ai-src/%s.nasc" % ("/".join(parts[:j+1]), ))
        else:
            filename = createPath("ai-src/%s" % ("/".join(parts[:j+1]), ))

        if filename not in written:
            fw.write(open(filename).read())
            written.add(filename)

fw.close()

print >> stderr, "Compiling %d sources..." % (len(files), )

result = system("cd nasc && compile.bat ..\\%s.nasc" % (aiFilename, ))

err = glob("nasc/l2npc/log/err/*-01-npc*.log")
if err and len(open(err[0], "r").read()) > 0 or result > 0:
    print >> stderr, "Compilation failed"
    raise SystemExit(1)

curClass = None
fw = None
classes = [{}, {}]
outputDir = "ai"
for line in open("%s.obj" % (aiFilename, ), "r", "utf-16le"):
    line = line.strip("\n").strip("\r")
    if line.startswith("class"):
        if curClass == None:
            lineSplit = line.split()
            curClass = lineSplit[2]
            path = []
            if lineSplit[4] != "(null)":
                classes[int(lineSplit[1])][curClass] = lineSplit[4]
                parent = lineSplit[4]
                while True:
                    path.append(parent)
                    parent = classes[int(lineSplit[1])].get(parent)
                    if parent == None:
                        break
            path.append(outputDir)
            path.reverse()
            try:
                mkdir(createPath("/".join(path)))
            except WindowsError, e:
                if e.winerror != 183:
                    raise
            path.append(curClass)
            srcFilename = u"%s.nasc" % (createPath("/".join(path)), )
            srcFilename = srcFilename[:len(cwd)+4] + srcFilename[len(cwd)+4:].replace("%s\\" % (outputDir, ), "ai-src\\", 1)
            if srcFilename in required:
                filename = "%s.txt" % (createPath("/".join(path)), )
                fw = open(filename, "w")
        else:
            curClass = None

    if fw != None:
        print >> fw, line

    if curClass == None and fw != None:
        fw.close()
        fw = None

if not makeAll:
    #unlink("%s.nasc" % (aiFilename, )) # uncomment this if you don't need single NASC file
    #unlink("%s.obj" % (aiFilename, )) # uncomment this if you don't need ai.obj file
    pass

print >> stderr, "Done!"

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.



×