Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 19 additions & 2 deletions nmspy/data/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,10 @@ class cGcGameState(Structure):
@function_hook("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 41 56 48 83 EC ? C7 41")
def cGcGameState(self, this: "_Pointer[cGcGameState]"): ...

@function_hook("48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 88 54 24")
@function_hook(
"48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 55 41 54 41 55 41 56 41 57 48 8D AC 24 ? ? ? ? 48 81 EC ? "
"? ? ? 48 8B 99"
)
def OnSaveProgressCompleted(
self,
this: "_Pointer[cGcGameState]",
Expand Down Expand Up @@ -2544,8 +2547,22 @@ class cGcPlayerHUD(cGcHUD):
mHelmetLines: Annotated[cGcNGui, 0x20940]
mQuickMenu: Annotated[cGcNGuiLayer, 0x20DC8]
maMarkers: Annotated[tuple[cGcHUDMarker, ...], Field(cGcHUDMarker * 0x80, 0x20FE0)]
mShieldPanelBasePos: Annotated[basic.Vector2f, 0xFEAF4]
mHazardPanelBasePos: Annotated[basic.Vector2f, 0xFEAFC]
mWeaponPanelBasePos: Annotated[basic.Vector2f, 0xFEB04]
mIndicatorPanelBasePos: Annotated[basic.Vector2f, 0xFEB0C]
mBuildInfoPanelBasePos: Annotated[basic.Vector2f, 0xFEB14]
mOSDMessagePanelBasePos: Annotated[basic.Vector2f, 0xFEB1C]
mMissionMessagePanelBasePos: Annotated[basic.Vector2f, 0xFEB24]
mMissionDetailMessageBasePos: Annotated[basic.Vector2f, 0xFEB2C]
# Found in cGcPlayerHUD::LoadData
mpHUDShieldLayer: Annotated[_Pointer[cGcNGuiLayer], 0xECE08]
# TODO: There are loads more which can be added by someone who has too much time/resources.
mpHUDShieldLayer: Annotated[_Pointer[cGcNGuiLayer], 0x112608]
mpShieldBarLayer: Annotated[_Pointer[cGcNGuiLayer], 0x112610]
mpShieldIconLayer: Annotated[_Pointer[cGcNGuiLayer], 0x112618]
mpShieldTechLayer: Annotated[_Pointer[cGcNGuiLayer], 0x112620]
mpHealthIconsLayer: Annotated[_Pointer[cGcNGuiLayer], 0x112628]
mpHUDWeaponLayer: Annotated[_Pointer[cGcNGuiLayer], 0x112630]

@function_hook(
"48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 41 56 48 83 EC ? 0F 29 74 24 ? 48 8B F9 E8 "
Expand Down
29 changes: 28 additions & 1 deletion nmspy/data/xml_mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This will contain all the "modded types".
# These are basically community custom versions of all the types which can be found in MBINCompiler.

import sys
import types
import typing
import xml.etree.ElementTree as etree
Expand Down Expand Up @@ -31,6 +32,27 @@ def _strip_optional(type_: Any) -> Any:
return type_


def _resolve(type_: Any, globalns: dict[str, Any], localns: dict[str, Any]) -> Any:
"""Recursively turn str / ForwardRef annotations (even nested ones) into types."""
if isinstance(type_, typing.ForwardRef):
type_ = type_.__forward_arg__
if isinstance(type_, str):
return _resolve(eval(type_, globalns, localns), globalns, localns)

args = typing.get_args(type_)
origin = typing.get_origin(type_)
if origin is None or not args:
return type_

# Resolve the sub-types.
new_args = tuple(_resolve(a, globalns, localns) for a in args)
if new_args == args:
return type_
if origin is Union or origin is types.UnionType:
return Union[new_args] # type: ignore[return-value]
return origin[new_args if len(new_args) > 1 else new_args[0]]


class XmlMixin:
"""
Mixin for dataclasses that reads/writes them as a tree of <Property> elements.
Expand All @@ -52,7 +74,12 @@ def __init_subclass__(cls, **kwargs: Any):
@classmethod
def _hints(cls) -> dict[str, Any]:
# Get the type hints for the class.
return typing.get_type_hints(cls, localns={cls.__name__: cls, **cls._registry})
globalns = dict(vars(sys.modules.get(cls.__module__, types.ModuleType("_"))))
localns = {**cls._registry, cls.__name__: cls}
hints = typing.get_type_hints(cls, localns=localns)
# Before Python 3.11, get_type_hints leaves string forward references
# nested inside generics (e.g. list["Foo"]) unresolved, so do it here.
return {k: _resolve(v, globalns, localns) for k, v in hints.items()}

def _write_fields(self, parent: etree.Element):
# Loop over the fields, encode them and add them to the parent.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
dependencies = [
"pymhf[http_api,gui]==0.2.5"
]
version = "184702.0"
version = "185034.0"

[dependency-groups]
dev = [
Expand Down
119 changes: 117 additions & 2 deletions tools/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@
},
{
"name": "cGcGameState::OnSaveProgressCompleted",
"signature": "48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 88 54 24",
"mangled_name": "?OnSaveProgressCompleted@cGcGameState@@AEAAX_N0W4Type@SpecificSave@GcGameStatePersistence@@@Z"
"signature": "48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 55 41 54 41 55 41 56 41 57 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 99",
"mangled_name": "?OnSaveProgressCompleted@cGcGameState@@AEAAX_N0W4Type@SpecificSave@GcGameStatePersistence@@@Z",
"unique_string": "GAMEMODE_SAVE_UNSUP"
},
{
"name": "cGcGameState::LoadFromPersistentStorage",
Expand Down Expand Up @@ -2863,6 +2864,120 @@
}
}
]
},
{
"name": "cGcPlayerHUD",
"fields": [
{
"name": "mHelmetGUI",
"signature": "4C 8D B1 ? ? ? ? 48 8B D9 49 8B CE"
},
{
"name": "mCrosshairGui",
"signature": "48 8D 8B ? ? ? ? E8 ? ? ? ? 66 0F 6F 0D ? ? ? ? 66 0F 6F C1 66 48 0F 7E C8"
},
{
"name": "mHelmetLines",
"signature": "48 8D BB ? ? ? ? 41 B1"
},
{
"name": "mQuickMenu",
"signature": "48 8D 8B ? ? ? ? E8 ? ? ? ? 41 B8 ? ? ? ? 48 8D 55"
},
{
"name": "mpHUDShieldLayer",
"signature": "48 89 83 ? ? ? ? 33 F6 4C 8D 3D"
},
{
"name": "mpShieldBarLayer",
"relative_to": {
"name": "mpHUDShieldLayer",
"offset": 8
}
},
{
"name": "mpShieldIconLayer",
"relative_to": {
"name": "mpShieldBarLayer",
"offset": 8
}
},
{
"name": "mpShieldTechLayer",
"relative_to": {
"name": "mpShieldIconLayer",
"offset": 8
}
},
{
"name": "mpHealthIconsLayer",
"relative_to": {
"name": "mpShieldTechLayer",
"offset": 8
}
},
{
"name": "mpHealthIconsLayer",
"relative_to": {
"name": "mpHealthIconsLayer",
"offset": 8
}
},
{
"name": "mShieldPanelBasePos",
"signature": "F2 41 0F 10 85 ? ? ? ? F2 0F 11 45 ? F2 41 0F 10 85 ? ? ? ? F2 0F 11 45 ? F2 41 0F 10 85 ? ? ? ? F2 0F 11 45 ? F3 0F 5D CA",
"offset": 5
},
{
"name": "mHazardPanelBasePos",
"relative_to": {
"name": "mShieldPanelBasePos",
"offset": 8
}
},
{
"name": "mWeaponPanelBasePos",
"relative_to": {
"name": "mHazardPanelBasePos",
"offset": 8
}
},
{
"name": "mIndicatorPanelBasePos",
"relative_to": {
"name": "mWeaponPanelBasePos",
"offset": 8
}
},
{
"name": "mBuildInfoPanelBasePos",
"relative_to": {
"name": "mIndicatorPanelBasePos",
"offset": 8
}
},
{
"name": "mOSDMessagePanelBasePos",
"relative_to": {
"name": "mBuildInfoPanelBasePos",
"offset": 8
}
},
{
"name": "mMissionMessagePanelBasePos",
"relative_to": {
"name": "mOSDMessagePanelBasePos",
"offset": 8
}
},
{
"name": "mMissionDetailMessageBasePos",
"relative_to": {
"name": "mMissionMessagePanelBasePos",
"offset": 8
}
}
]
}
]
}
Loading