Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity vtable fixes and new stuff #397

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0626e90
fix some virtual functions, add missing parameters etc.
Mr-Auto Aug 25, 2024
264b3de
look thru entity virtual functions to understand them better, fix som…
Mr-Auto Sep 11, 2024
2fedd8b
fix build
Mr-Auto Sep 11, 2024
a203288
fix build 2
Mr-Auto Sep 12, 2024
4477162
merge main
Mr-Auto Sep 12, 2024
38f0d5b
some post merge changes, update docs
Mr-Auto Sep 12, 2024
6b7d54f
update and fix entity casting, also rename variables in `Animation`
Mr-Auto Sep 12, 2024
c417296
update vtable names for `vtable_sizes.csv`, update full doscs
Mr-Auto Sep 12, 2024
b9acb98
exposing more vitrual functions and hooks
Mr-Auto Sep 12, 2024
8c1a691
add SOUNDID alias, add function to convert from it to `VANILLA_SOUND`…
Mr-Auto Sep 23, 2024
edd94cb
add and improve entity attach/detach
Mr-Auto Sep 29, 2024
5a09f69
fix invalidating iterator in `remove_spawn`
Mr-Auto Oct 6, 2024
665428d
fix Backpack subclass in lua, add more hookable functions to lua, tes…
Mr-Auto Nov 15, 2024
cf38c6a
typo
Mr-Auto Nov 16, 2024
02ae583
add small comment
Mr-Auto Nov 17, 2024
fd154ab
bring back move semantics
Mr-Auto Nov 17, 2024
b10aebc
more comments
Mr-Auto Nov 19, 2024
79dcb16
typos and YellowCape base
Mr-Auto Dec 7, 2024
380de08
rename `pickup` to `give_powerup` and expose it, fix comments for vta…
Mr-Auto Dec 8, 2024
85b8999
make b3f optional in `set_draw_depth`, manually align some comments i…
Mr-Auto Dec 12, 2024
0d42b36
rename `generate_fall_poof_particles`, also Floor and Door virtuals u…
Mr-Auto Dec 14, 2024
4da0fa8
rename `acquire` -> `equip`, changes the comment, update docs
Mr-Auto Dec 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 83 additions & 42 deletions docs/game_data/spel2.lua

Large diffs are not rendered by default.

118 changes: 82 additions & 36 deletions docs/parse_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"game_unordered_map<": "map<",
"game_set<": "set<",
"game_unordered_set<": "set<",
"unordered_map<": "map<", # doesn't seam to matter for lua if it's ordered or not
"unordered_set<": "set<", # doesn't seam to matter for lua if it's ordered or not
"unordered_map<": "map<", # doesn't seam to matter for lua if it's ordered or not
"unordered_set<": "set<", # doesn't seam to matter for lua if it's ordered or not
# removers
", identity_hasher<>": "",
"std::": "",
Expand Down Expand Up @@ -215,23 +215,25 @@ def cb_signature_dict(ret, param):
"param": param,
}


def custom_split(var):
result = []
level = 0
current = ""
for char in var:
if char == ',' and level == 0:
if char == "," and level == 0:
result.append(current.strip())
current = ""
else:
current += char
if char == '[' or char == '(' or char == '<':
if char == "[" or char == "(" or char == "<":
level += 1
elif char == ']' or char == ')' or char == '>':
elif char == "]" or char == ")" or char == ">":
level -= 1
result.append(current.strip())
return result


def get_cb_signature(text):
signature_ms = reSignature.findall(text)
if not signature_ms:
Expand All @@ -249,9 +251,10 @@ def camel_case_to_snake_case(name):

def fix_spaces(thing):
thing = thing.strip()
thing = re.sub(r"\s{2,}", " ", thing) # change double spaces into single
thing = re.sub(r"(?<=\(|\<)\s", "", thing) # remove spaces after ( or <
return thing.replace("*", "").replace("&", "") # remove * and &
thing = re.sub(r"\s{2,}", " ", thing) # change double spaces into single
thing = re.sub(r"(?<=\(|\<)\s", "", thing) # remove spaces after ( or <
return thing.replace("*", "").replace("&", "") # remove * and &


def getfunc(name):
for func in funcs:
Expand All @@ -267,9 +270,11 @@ def rpcfunc(name):
ret.append(func)
return ret


def replace_fun(text):
return fix_spaces(replace_fun_import(text))


def configure_parse(replace_function, cache_file):
global replace_fun_import, CACHE_FILE
replace_fun_import = replace_function
Expand Down Expand Up @@ -384,25 +389,27 @@ def run_parse():
if m:
continue

m = re.search(r"\s*(virtual\s)?(.*)\s+([^\(]*)\(([^\)]*)", line)
m = re.search(
r"\s*(?:virtual\s)?(.*)\s+([\w]+)\(([^\)]*)", line
)
if m:
name = m[3]
name = m[2]
# move ctor is useless for Lua
is_move_ctr = (
re.fullmatch(r"^[a-zA-Z0-9_]*$", name)
and re.fullmatch(rf"\s*{name}\s*&&[^,]*", m[4])
and not m[2]
re.fullmatch(r"^[\w]*$", name)
and re.fullmatch(rf"\s*{name}\s*&&[^,]*", m[3])
and not m[1]
)
if not is_move_ctr:
if name not in member_funs:
member_funs[name] = []
param = m[4]
param = m[3]
if " " not in param:
param = f"{param} {param.lower()}"
member_funs[name].append(
{
"return": replace_fun(m[2]),
"name": m[3],
"return": replace_fun(m[1]),
"name": m[2],
"param": replace_fun(param),
"comment": comment,
}
Expand Down Expand Up @@ -440,7 +447,11 @@ def run_parse():
)
else:
member_vars.append(
{"type": replace_fun(m[1]), "name": m[2], "comment": comment}
{
"type": replace_fun(m[1]),
"name": m[2],
"comment": comment,
}
)
comment = []
elif brackets_depth == 0:
Expand Down Expand Up @@ -568,6 +579,7 @@ def run_parse():
data = open(file, "r").read().split("\n")
vtables = {}
vtable_name = None
skip = False
for line in data:
if vtable_def := re.search(
r'static (\w*) \w*\(lua, lua\["(.*)"\](, "(.*)")?\)', line
Expand All @@ -592,7 +604,13 @@ def run_parse():
vtable_name = line.split()[1]
vtable_entries = {}
elif vtable_name != None:
if entry_math := re.search(r"/// NoDoc", line):
skip = True
continue
if entry_math := re.search(r"VTableEntry<(.*)>", line):
if skip:
skip = False
continue
[name, index, signature_and_binder] = entry_math.group(1).split(
",", 2
)
Expand All @@ -606,20 +624,42 @@ def run_parse():
signature = re.sub(
r"\), BackBinder<([^>]*)>", r", \g<1>)", signature_and_binder
).replace("(, ", "(")
signature = re.search(
r"([_a-zA-Z][_a-zA-Z0-9]*.*)\((.*)\)", signature
)
ret = signature.group(1)
args = [
t for t in signature.group(2).split(",")
]
vtable_entries[name] = {
"name": name,
"index": index,
"ret": ret,
"args": args,
"binds": binds,
}
func_ref = re.search(r"MemFun<&?([\w]+)::([\w]+)>", line)

if func_ref and func_ref.group(1) is not None:
for item in classes:
if item["name"] != func_ref.group(1):
continue
# TODO: pretty sure if the actual virtual function name is different then the one in VTableEntry there won't be comment in callback signature
func_name = func_ref.group(2)
# if it throws error at `item["member_funs"][func_name]` then the virtual defined using MemFun was not found in the parsed class/struct code
if (
item["member_funs"]
and item["member_funs"][func_name]
and len(item["member_funs"][func_name]) > 0
):
func = item["member_funs"][func_name][-1]
vtable_entries[name] = {
"name": name,
"index": index,
"ret": func["return"],
"args": [t for t in func["param"].split(",")],
# "ref": func_name.group(2),
"binds": binds,
}
else:
signature = re.search(
r"([_a-zA-Z][\w]*.*)\((.*)\)", signature
)
ret = signature.group(1)
args = [t for t in signature.group(2).split(",")]
vtable_entries[name] = {
"name": name,
"index": index,
"ret": ret,
"args": args,
"binds": binds,
}
if ">>;" in line:
vtables[vtable_name] = {
"name": vtable_name,
Expand Down Expand Up @@ -711,7 +751,9 @@ def run_parse():
var[1] = var[1][:-1]

var_name = var[0]
cpp = replace_fun(var[1]) # should probably be done later, so the regex doesn't have to relay on some of the changes, also generate_emmylua.py uses some unique formats replacements
cpp = replace_fun(
var[1]
) # should probably be done later, so the regex doesn't have to relay on some of the changes, also generate_emmylua.py uses some unique formats replacements

if var[1].startswith("sol::property"):
param_match = re.match(
Expand All @@ -731,7 +773,7 @@ def run_parse():
cpp_name = cpp
else:
cpp_name = cpp[cpp.find("::") + 2 :] if cpp.find("::") >= 0 else cpp

if var_name.startswith("sol::constructors"):
for fun in underlying_cpp_type["member_funs"][cpp_type]:
param = fun["param"]
Expand All @@ -746,14 +788,18 @@ def run_parse():
}
)
elif cpp.startswith("[]("):
param_match = re.match(r"\[\]\(([\w &*:,]+)?\) -> ([\w.*&<>\?\[\]:]+)?(?: )?{", cpp)
param_match = re.match(
r"\[\]\(([\w &*:,]+)?\) -> ([\w.*&<>\?\[\]:]+)?(?: )?{", cpp
)
if param_match:
ret = param_match.group(2)
if ret is None:
ret = "nil"

sig = param_match.group(1)
if sig.startswith(cpp_type): # remove the self parameter if present
if sig.startswith(
cpp_type
): # remove the self parameter if present
first_param_end = sig.find(",") + 1
if first_param_end == 0:
sig = ""
Expand Down
20 changes: 18 additions & 2 deletions docs/src/includes/_enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,30 +232,46 @@ Name | Data | Description
[KILL](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.KILL) | 3 |
[ON_COLLISION1](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.ON_COLLISION1) | 4 |
[DESTROY](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.DESTROY) | 5 |
[GENERATE_STOMP_DAMAGE_PARTICLES](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.GENERATE_STOMP_DAMAGE_PARTICLES) | 8 |
[CAN_BE_PUSHED](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.CAN_BE_PUSHED) | 10 |
[IS_IN_LIQUID](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.IS_IN_LIQUID) | 12 |
[SET_INVISIBLE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.SET_INVISIBLE) | 15 |
[FRICTION](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.FRICTION) | 17 |
[FLIP](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.FLIP) | 16 |
[SET_DRAW_DEPTH](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.SET_DRAW_DEPTH) | 17 |
[RESET_DRAW_DEPTH](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.RESET_DRAW_DEPTH) | 18 |
[FRICTION](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.FRICTION) | 19 |
[SET_AS_SOUND_SOURCE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.SET_AS_SOUND_SOURCE) | 20 |
[REMOVE_ITEM](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.REMOVE_ITEM) | 21 |
[GET_HELD_ENTITY](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.GET_HELD_ENTITY) | 22 |
[TRIGGER_ACTION](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.TRIGGER_ACTION) | 24 |
[ACTIVATE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.ACTIVATE) | 25 |
[ON_COLLISION2](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.ON_COLLISION2) | 26 |
[GET_METADATA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.GET_METADATA) | 27 |
[APPLY_METADATA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.APPLY_METADATA) | 28 |
[WALKED_ON](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.WALKED_ON) | 29 |
[WALKED_OFF](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.WALKED_OFF) | 30 |
[LEDGE_GRAB](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.LEDGE_GRAB) | 31 |
[STOOD_ON](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.STOOD_ON) | 32 |
[LIBERATE_FROM_SHOP](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.LIBERATE_FROM_SHOP) | 35 |
[INIT](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.INIT) | 36 |
[CAN_JUMP](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.CAN_JUMP) | 37 |
[STOMP_DAMAGE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.STOMP_DAMAGE) | 43 |
[GET_COLLISION_INFO](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.GET_COLLISION_INFO) | 38 |
[SPRINT_FACTOR](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.SPRINT_FACTOR) | 39 |
[CALCULATE_JUMP_VELOCITY](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.CALCULATE_JUMP_VELOCITY) | 40 |
[GET_ANIMATION_MAP](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.GET_ANIMATION_MAP) | 41 |
[APPLY_VELOCITY](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.APPLY_VELOCITY) | 42 |
[GET_DAMAGE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.GET_DAMAGE) | 43 |
[IS_ON_FIRE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.IS_ON_FIRE) | 45 |
[DAMAGE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.DAMAGE) | 48 |
[ON_HIT](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.ON_HIT) | 49 |
[GET_DAMAGE_SOUND](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.GET_DAMAGE_SOUND) | 50 |
[STUN](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.STUN) | 51 |
[FREEZE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.FREEZE) | 52 |
[LIGHT_ON_FIRE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.LIGHT_ON_FIRE) | 53 |
[SET_CURSED](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.SET_CURSED) | 54 |
[WEB_COLLISION](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.WEB_COLLISION) | 55 |
[CHECK_OUT_OF_BOUNDS](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.CHECK_OUT_OF_BOUNDS) | 58 |
[SET_STANDING_ON](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.SET_STANDING_ON) | 59 |
[STANDING_ON](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.STANDING_ON) | 60 |
[STOMPED_BY](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.STOMPED_BY) | 61 |
[THROWN_BY](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.THROWN_BY) | 62 |
Expand Down
8 changes: 4 additions & 4 deletions docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ Use empty table as argument to reset to the game default

> Search script examples for [drop](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=drop)

#### nil drop(int who_uid, int what_uid)
#### nil drop(int who_uid, optional<int> what_uid)

Drop an entity by uid
Drop held entity, `what_uid` optional, if set, it will check if entity is holding that entity first before dropping it

### enter_door

Expand Down Expand Up @@ -572,9 +572,9 @@ Check if the entity `uid` has some specific `item_uid` by uid in their inventory

> Search script examples for [entity_remove_item](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=entity_remove_item)

#### nil entity_remove_item(int uid, int item_uid)
#### nil entity_remove_item(int uid, int item_uid, optional<bool> check_autokill)

Remove item by uid from entity
Remove item by uid from entity. `check_autokill` defaults to true, checks if entity should be killed when missing overlay and kills it if so (can help with avoiding crashes)

### filter_entities

Expand Down
Loading
Loading