
import clr
import sys
import os
import System
from System import AppDomain
from System.Reflection import BindingFlags

def inspect_dll(dll_path):
    print(f"Inspecting: {dll_path}")
    try:
        clr.AddReference(dll_path)
        assembly = None
        for a in AppDomain.CurrentDomain.GetAssemblies():
            if "rapiplus" in a.FullName.lower():
                assembly = a
                break
        
        if not assembly:
            print("Assembly not found.")
            return

        results = []
        target_classes = ["com.omnesys.rapi.AdmCallbacks", "com.omnesys.rapi.RCallbacks"]
        
        for full_name in target_classes:
            t = assembly.GetType(full_name)
            if not t:
                results.append(f"Type {full_name} not found.")
                continue
            
            results.append(f"\n--- {t.FullName} ---")
            # 継承元も含めてすべての仮想メソッドをリスト
            methods = t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy)
            for m in methods:
                if m.IsVirtual and not m.IsFinal and m.DeclaringType.FullName != "System.Object":
                    abstract_str = "[ABSTRACT] " if m.IsAbstract else ""
                    params = [f"{p.ParameterType.Name} {p.Name}" for p in m.GetParameters()]
                    results.append(f"  {abstract_str}{m.Name}({', '.join(params)})")

        with open("inspect_callbacks_all_v2.txt", "w") as f:
            f.write("\n".join(results))
        print("Done. Results in inspect_callbacks_all_v2.txt")

    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    dll_path = os.path.join(os.getcwd(), "libs", "rapiplus.dll")
    inspect_dll(dll_path)
