About Monkey 2 › Forums › Monkey 2 Code Library › MumbleLink (Memory Shared File)
This topic contains 0 replies, has 1 voice, and was last updated by 
 Hezkore
 1 year, 10 months ago.
- 
		AuthorPosts
 - 
		
			
				
June 17, 2017 at 1:48 pm #8796
Mumble is a VOIP application with positional sound.
Games that support Mumble creates something called a MumbleLink, which is a shared memory file.
That file includes lots of information, such as avatar/camera position, rotation, name, map etc.
Mumble then uses that file to track your location in the game world.
The following code lets you too read that shared file, and get all the juicy information from it!
You could use it to create things like external map viewers for your favorite game, or “event schedules” for MMO’s etc.For example, Guild Wars 2 uses this to share a lot of player information, like team, profession and all that:
https://wiki.guildwars2.com/wiki/API:MumbleLink#Usage_in_Guild_Wars_2You’ll need this mumble.h file:
C++123456789101112131415161718192021222324252627282930313233#include <windows.h>struct LinkedMem {UINT32 uiVersion;DWORD uiTick;float fAvatarPosition[3];float fAvatarFront[3];float fAvatarTop[3];wchar_t name[256];float fCameraPosition[3];float fCameraFront[3];float fCameraTop[3];wchar_t identity[256];UINT32 context_len;unsigned char context[256];wchar_t description[2048];};static LinkedMem *lm = NULL;static void initMumble() {// HANDLE hMapObject = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink");HANDLE hMapObject = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(LinkedMem), L"MumbleLink");if (hMapObject == NULL)return;lm = (LinkedMem *) MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(LinkedMem));if (lm == NULL) {CloseHandle(hMapObject);hMapObject = NULL;return;}}And here’s the Monkey 2 wrapper for it, which I call “mumble.monkey2”:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142Namespace mumble#Import "mumble.h"ExternStruct LinkedMemField uiVersion:UIntField fAvatarPosition:Float[]Field fAvatarFront:Float[]Field fAvatarTop:Float[]Field fCameraPosition:Float[]Field fCameraFront:Float[]Field fCameraTop:Float[]Field name:StringField identity:StringField context_len:IntField context:UByte[]Field description:StringEndFunction initMumble_C:Void()="initMumble"Function updateMumble_C:Void()="updateMumble"Global lm:LinkedMem PtrPublicGlobal link:LinkedMemFunction InitMumble:Int()initMumble_C()If lm Thenlink=lm[0]Return 1ElseReturn 0EndifEndFunction UpdateMumble()If lm Then link=lm[0]EndYou use it by first calling InitMumble()
Then call UpdateMumble() as you want new information. (every frame)
You then use the Global link variable to check avatar/cameras position, rotation, name, map etc.Super basic example of usage:
Monkey1234567891011121314151617181920212223242526272829#Import "<std>"#Import "<mojo>"#Import "<mojox>"Using std..Using mojo..Using mojox..#Import "mumble"Using mumble..Class MyWindow Extends WindowMethod New()Super.New( "Simple Mojo Gui App",640,480,WindowFlags.Resizable )InitMumble()EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()UpdateMumble()Print link.fAvatarPosition[0]+", "+link.fAvatarPosition[1]+", "+link.fAvatarPosition[2]EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()End - 
		AuthorPosts
 
You must be logged in to reply to this topic.