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) {
|
private void error(String message) {
|
||||||
getLogger().severe("A fatal error occured, disabling plugin!");
|
getLogger().severe("A fatal error occured, disabling plugin!");
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
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
|
// 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;
|
package sznp.virtualcomputer.util;
|
||||||
|
|
||||||
|
import com.jacob.com.COMConverter;
|
||||||
import com.jacob.com.Dispatch;
|
import com.jacob.com.Dispatch;
|
||||||
|
import com.jacob.com.Variant;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import lombok.var;
|
import lombok.var;
|
||||||
|
@ -14,10 +16,10 @@ public final class COMUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEventListener registerListener(IEventSource source, IEventHandler listener, List<VBoxEventType> types) {
|
public static IEventListener registerListener(IEventSource source, IEventHandler listener, List<VBoxEventType> types) {
|
||||||
long handler = Exports.GetEventHandler(listener);
|
var variant = new Variant();
|
||||||
var dp = new Dispatch();
|
COMConverter.SetVariantAddress(variant, Exports.GetEventHandler(listener, COMConverter.GetVariantAddress(variant)));
|
||||||
dp.m_pDispatch = handler;
|
System.out.println("Variant as int: "+variant.toInt());
|
||||||
var ret = new IEventListener(dp);
|
var ret = new IEventListener(variant.changeType((short) 9).getDispatch()); //Object variant to dispatch variant
|
||||||
source.registerListener(ret, types, true);
|
source.registerListener(ret, types, true);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -28,9 +30,9 @@ public final class COMUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IFramebuffer gimmeAFramebuffer(IMCFrameBuffer frameBuffer) {
|
public static IFramebuffer gimmeAFramebuffer(IMCFrameBuffer frameBuffer) {
|
||||||
var dp = new Dispatch();
|
var variant = new Variant();
|
||||||
dp.m_pDispatch = Exports.GetFrameBuffer(frameBuffer);
|
COMConverter.SetVariantAddress(variant, Exports.GetFrameBuffer(frameBuffer, COMConverter.GetVariantAddress(variant)));
|
||||||
return new IFramebuffer(dp);
|
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) {
|
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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using VirtualBox;
|
||||||
|
|
||||||
namespace VirtualComputerWindows
|
namespace VirtualComputerWindows
|
||||||
{
|
{
|
||||||
public class EventHandler
|
public class EventHandler : IEventListener
|
||||||
{
|
{
|
||||||
private readonly IEventHandler handler;
|
private readonly IEventHandler handler;
|
||||||
private bool enabled = true;
|
private bool enabled = true;
|
||||||
|
@ -21,11 +23,11 @@ namespace VirtualComputerWindows
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleEvent(long iEvent)
|
public void HandleEvent(IEvent aEvent)
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
handler.handleEvent(iEvent);
|
handler.handleEvent((long)Marshal.GetIDispatchForObject(aEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable()
|
public void disable()
|
||||||
|
|
|
@ -49,22 +49,28 @@ namespace VirtualComputerWindows
|
||||||
private static void Main()
|
private static void Main()
|
||||||
{
|
{
|
||||||
//Init();
|
//Init();
|
||||||
long asd = GetEventHandler(null);
|
GetEventHandler(null, 0L);
|
||||||
Console.WriteLine("Returned: " + asd);
|
|
||||||
Console.ReadLine();
|
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);
|
Exports.framebuffer = new WinFrameBuffer(framebuffer);
|
||||||
return (long) Marshal.GetIUnknownForObject(fb);
|
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);
|
eventHandler = new EventHandler(handler);
|
||||||
return (long)Marshal.GetIUnknownForObject(han);
|
//handlerWrapper = new DispatchWrapper(eventHandler);
|
||||||
|
Marshal.GetNativeVariantForObject(eventHandler, (IntPtr)addr);
|
||||||
|
//return (long)Marshal.GetIDispatchForObject(eventHandler);
|
||||||
|
return addr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using VirtualBox;
|
using VirtualBox;
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue