Using Variant instead of Dispatch
Getting an object variant instead of a dispatch one
This commit is contained in:
parent
17c3d4c268
commit
d3dbea885c
9 changed files with 44 additions and 20 deletions
|
@ -134,7 +134,9 @@ public class PluginMain extends JavaPlugin {
|
|||
private void error(String message) {
|
||||
getLogger().severe("A fatal error occured, disabling plugin!");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
throw new RuntimeException(message);
|
||||
val ex = new RuntimeException(message);
|
||||
ex.setStackTrace(new StackTraceElement[0]);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
// Fired when plugin is disabled
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.jacob.com;
|
||||
|
||||
public class COMConverter {
|
||||
public static long GetVariantAddress(Variant variant) {
|
||||
return variant.m_pVariant;
|
||||
}
|
||||
|
||||
public static void SetVariantAddress(Variant variant, long addr) {
|
||||
variant.m_pVariant = addr;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package sznp.virtualcomputer.util;
|
||||
|
||||
import com.jacob.com.COMConverter;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.val;
|
||||
import lombok.var;
|
||||
|
@ -14,10 +16,10 @@ public final class COMUtils {
|
|||
}
|
||||
|
||||
public static IEventListener registerListener(IEventSource source, IEventHandler listener, List<VBoxEventType> types) {
|
||||
long handler = Exports.GetEventHandler(listener);
|
||||
var dp = new Dispatch();
|
||||
dp.m_pDispatch = handler;
|
||||
var ret = new IEventListener(dp);
|
||||
var variant = new Variant();
|
||||
COMConverter.SetVariantAddress(variant, Exports.GetEventHandler(listener, COMConverter.GetVariantAddress(variant)));
|
||||
System.out.println("Variant as int: "+variant.toInt());
|
||||
var ret = new IEventListener(variant.changeType((short) 9).getDispatch()); //Object variant to dispatch variant
|
||||
source.registerListener(ret, types, true);
|
||||
return ret;
|
||||
}
|
||||
|
@ -28,9 +30,9 @@ public final class COMUtils {
|
|||
}
|
||||
|
||||
public static IFramebuffer gimmeAFramebuffer(IMCFrameBuffer frameBuffer) {
|
||||
var dp = new Dispatch();
|
||||
dp.m_pDispatch = Exports.GetFrameBuffer(frameBuffer);
|
||||
return new IFramebuffer(dp);
|
||||
var variant = new Variant();
|
||||
COMConverter.SetVariantAddress(variant, Exports.GetFrameBuffer(frameBuffer, COMConverter.GetVariantAddress(variant)));
|
||||
return new IFramebuffer(variant.toDispatch()); //Object variant
|
||||
}
|
||||
|
||||
public static void queryBitmapInfo(IDisplaySourceBitmap bitmap, long[] ptr, long[] w, long[] h, long[] bpp, long[] bpl, long[] pf) {
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,12 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VirtualBox;
|
||||
|
||||
namespace VirtualComputerWindows
|
||||
{
|
||||
public class EventHandler
|
||||
public class EventHandler : IEventListener
|
||||
{
|
||||
private readonly IEventHandler handler;
|
||||
private bool enabled = true;
|
||||
|
@ -21,11 +23,11 @@ namespace VirtualComputerWindows
|
|||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void handleEvent(long iEvent)
|
||||
public void HandleEvent(IEvent aEvent)
|
||||
{
|
||||
if (!enabled)
|
||||
return;
|
||||
handler.handleEvent(iEvent);
|
||||
handler.handleEvent((long)Marshal.GetIDispatchForObject(aEvent));
|
||||
}
|
||||
|
||||
public void disable()
|
||||
|
|
|
@ -49,22 +49,28 @@ namespace VirtualComputerWindows
|
|||
private static void Main()
|
||||
{
|
||||
//Init();
|
||||
long asd = GetEventHandler(null);
|
||||
Console.WriteLine("Returned: " + asd);
|
||||
GetEventHandler(null, 0L);
|
||||
Console.ReadLine();
|
||||
|
||||
}
|
||||
|
||||
public static long GetFrameBuffer(IMCFrameBuffer framebuffer)
|
||||
private static WinFrameBuffer framebuffer;
|
||||
public static long GetFrameBuffer(IMCFrameBuffer framebuffer, long addr)
|
||||
{
|
||||
var fb = new WinFrameBuffer(framebuffer);
|
||||
return (long) Marshal.GetIUnknownForObject(fb);
|
||||
Exports.framebuffer = new WinFrameBuffer(framebuffer);
|
||||
Marshal.GetNativeVariantForObject(Exports.framebuffer, (IntPtr)addr);
|
||||
return (long)Marshal.GetIDispatchForObject(Exports.framebuffer);
|
||||
}
|
||||
|
||||
public static long GetEventHandler(IEventHandler handler)
|
||||
private static EventHandler eventHandler;
|
||||
private static DispatchWrapper handlerWrapper;
|
||||
public static long GetEventHandler(IEventHandler handler, long addr)
|
||||
{
|
||||
var han = new EventHandler(handler);
|
||||
return (long)Marshal.GetIUnknownForObject(han);
|
||||
eventHandler = new EventHandler(handler);
|
||||
//handlerWrapper = new DispatchWrapper(eventHandler);
|
||||
Marshal.GetNativeVariantForObject(eventHandler, (IntPtr)addr);
|
||||
//return (long)Marshal.GetIDispatchForObject(eventHandler);
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VirtualBox;
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue