diff --git a/README.md b/README.md index d591cf1..e81b453 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # gopenfusion -A toy implementation of the Fusionfall Packet Protocol written in Go. +A toy implementation of the [Fusionfall Packet Protocol](https://openpunk.com/pages/fusionfall-openfusion/) written in Go. ## Generating structures diff --git a/protocol/structs.go b/protocol/structs.go index a33b58c..87ab752 100644 --- a/protocol/structs.go +++ b/protocol/structs.go @@ -1,3 +1,4 @@ +// generated via genstructs.py - All structure padding and member alignment verified package protocol type SPCStyle struct { diff --git a/tools/genstructs.py b/tools/genstructs.py index 9c56ed1..b3f21c5 100755 --- a/tools/genstructs.py +++ b/tools/genstructs.py @@ -9,6 +9,8 @@ (because it already does!) usage: ./genstructs.py [IN.cs] > structs.go + + It's recommended to run structs.go through `gofmt`. ''' from distutils.ccompiler import new_compiler import subprocess @@ -25,6 +27,8 @@ def writeToFile(source: str, filePath: str) -> None: with open(filePath, "w") as out: out.write(source) +WARN_INVALID = False + class StructTranspiler: class StructField: def __init__(self, name: str, type: str, marshal: str) -> None: @@ -132,7 +136,7 @@ class StructTranspiler: def getNextLine(self) -> str: self.cursor += 1 - return self.lines[self.cursor] + return self.getLine() def needsPatching(self) -> int: for i in range(len(self.fields)): @@ -206,6 +210,8 @@ class StructTranspiler: line = self.getLine() def toGoStyle(self) -> str: + global WARN_INVALID + source = "type " + self.name + " struct {" currentSize = 0 for field in self.fields: @@ -223,6 +229,7 @@ class StructTranspiler: if currentSize != self.size: source += "\n// WARNING: computed size is %d, needs to be %d!!" % (currentSize, self.size) + WARN_INVALID = True else: source += "\n// SIZE: %d" % self.size source += "\n}\n" @@ -277,8 +284,15 @@ if __name__ == '__main__': structs[i].populatePadding(lines[i].split(" ")) # emit structures + source = "// generated via genstructs.py" + if WARN_INVALID: + source += " - WARN!! Not all structures are valid, grep 'WARNING'\n" + else: + source += " - All structure padding and member alignment verified\n" + source += "package protocol\n\n" for struct in structs: - print(struct.toGoStyle()) + source += struct.toGoStyle() + "\n" + print(source) os.remove("tmp") os.remove("tmp.c")