public static CreateInterfaceFn Sys_GetFactory(string module) { IntPtr handle = NativeLibrary.Load(module); if (handle == IntPtr.Zero) { throw new DllNotFoundException(module); } CreateInterfaceFn factory = null; Exception exception = null; try { factory = Sys_GetFactory(handle); } catch (Exception e) { exception = e; } if (exception is not null) { throw exception; } return(factory); }
private static IntPtr GetSystem(string interfaceNoVersionName, string path) { Console.WriteLine($"GetSystem(): Searching for {interfaceNoVersionName} in {path}"); CreateInterfaceFn createInterfaceFn = interfaceh.Sys_GetFactory(path); for (int i = 99; i >= 0; i--) { int last = i % 10; int middle = i / 10; string verString = $"0{middle}{last}"; if (verString.Length > 3) { throw new IndexOutOfRangeException(nameof(verString)); } Console.WriteLine($"GetSystem(): Trying {verString}"); IntPtr systemPtr = createInterfaceFn(interfaceNoVersionName + verString, out IFACE returnCode); if (returnCode == IFACE.OK) { Console.WriteLine($"GetSystem(): Found {interfaceNoVersionName}{verString}"); return(systemPtr); } } Console.WriteLine($"GetSystem(): Not Found {interfaceNoVersionName}"); return(IntPtr.Zero); }
/// <summary> /// Load Interface <typeparamref name="TClass"/> /// </summary> /// <typeparam name="TClass">Interface Wrapper/Representory Class</typeparam> /// <param name="dllname">Path or Name of DLL to load from</param> /// <param name="interfaceVersionString">Version of Interface to load</param> /// <returns>Instance of <typeparamref name="TClass"/></returns> public static TClass Load <TClass>(String dllname, String interfaceVersionString) where TClass : class { CreateInterfaceFn factory = LoadCreateInterface(dllname); IntPtr classptr = factory(interfaceVersionString, IntPtr.Zero); return(JIT.ConvertInstance <TClass>(classptr)); }
public static TClass GetFromFactory <TClass>(CreateInterfaceFn factory) where TClass : class { if (factory == null) { return(null); //throw new JITEngineException("GetFromFactory called with NULL factory"); } IntPtr classptr = factory(InterfaceVersions.GetInterfaceIdentifier(typeof(TClass)), IntPtr.Zero); return(GenerateClass <TClass>(classptr)); }
/// <summary> /// Creates Instance of <typeparamref name="TClass"/>, must have <see cref="ModuleNameAttribute"/> /// </summary> /// <typeparam name="TClass">Interface Wrapper/Representory Class</typeparam> /// <returns>Pointer to <typeparamref name="TClass"/></returns> public static IntPtr GetClassPointer <TClass>() where TClass : class { // Validate That class has a Module Name Attribute. if (!(typeof(TClass).GetCustomAttributes(typeof(ModuleNameAttribute), false).FirstOrDefault() is ModuleNameAttribute moduleName)) { throw new Exception($"{typeof(TClass).Name} does not have a ModuleName attribute."); } // Call Native (SourceSDK) CreateInterface(String:InterfaceIdentifier, NULL) CreateInterfaceFn factory = LoadCreateInterface(moduleName.ModuleName); return(factory(InterfaceVersions.GetInterfaceIdentifier(typeof(TClass)), IntPtr.Zero)); }
/// <summary> /// Creates Instance of <typeparamref name="TClass"/>, using a preloaded CreateInterface delegate from a Module in memory /// </summary> /// <typeparam name="TClass">Interface Wrapper/Representory Class</typeparam> /// <param name="factory">CreateInterface Delegate</param> /// <returns>Instance of <typeparamref name="TClass"/></returns> public static TClass GetFromFactory <TClass>(CreateInterfaceFn factory) where TClass : class { if (factory == null) { return(null); //throw new JITEngineException("GetFromFactory called with NULL factory"); } // Create Instance of TClass IntPtr classptr = factory(InterfaceVersions.GetInterfaceIdentifier(typeof(TClass)), IntPtr.Zero); // if not NULL cast Pointer to TClass via JIT Conversion. And Return return(classptr == IntPtr.Zero ? null : JIT.ConvertInstance <TClass>(classptr)); }
private unsafe void LoadOffsets() { //TODO Add scanning Logger.Info("LoadOffsets"); OffsetScanner.ScanOffsets(_memory); if (_memory.Internal) { var createInter = _memory["engine.dll"]["CreateInterface"]; Logger.Info("New Interface name: " + createInter.Name + "\nAddress" + createInter.BaseAddress); EngineCreateInterface = createInter.GetDelegate <CreateInterfaceFn>(); var returncode = 0; var IEngineTracePtr = EngineCreateInterface(IEngineTraceVTable, ref returncode); var IEngineTrace = new VirtualClass(IEngineTracePtr); var traceFunction = IEngineTrace.GetVirtualFunction <IEngineTrace.TraceRay>(5 /*TraceRayindex*/); Logger.Info("New VClass name: " + IEngineTraceVTable + "\nAddress: " + IEngineTrace.ClassAddress.ToString()); } offsetsLoaded = true; }
internal static partial void IMaterialSystem_Init(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string shaderAPIDLL, IntPtr materialProxyFactory, CreateInterfaceFn fileSystemFactory, CreateInterfaceFn cvarFactory = null);
public void Init(string shaderAPIDLL, IntPtr materialProxyFactory, CreateInterfaceFn fileSystemFactory, CreateInterfaceFn cvarFactory = null) => Methods.IMaterialSystem_Init(ptr, shaderAPIDLL, materialProxyFactory, fileSystemFactory, cvarFactory);
public bool Connect(CreateInterfaceFn factory) { return(IAppSystem_Connect(ptr, factory)); }
internal static extern bool IAppSystem_Connect(IntPtr ptr, CreateInterfaceFn factory);
public void Reconnect(CreateInterfaceFn factory, string interfaceName) { IAppSystem_Reconnect(ptr, factory, interfaceName); }
internal static extern void IAppSystem_Reconnect(IntPtr ptr, CreateInterfaceFn factory, string interfaceName);