|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199 |
- using System;
- using System.Runtime.InteropServices;
- using System.Text;
-
- namespace Discord
- {
- public enum Result
- {
- Ok = 0,
- ServiceUnavailable = 1,
- InvalidVersion = 2,
- LockFailed = 3,
- InternalError = 4,
- InvalidPayload = 5,
- InvalidCommand = 6,
- InvalidPermissions = 7,
- NotFetched = 8,
- NotFound = 9,
- Conflict = 10,
- InvalidSecret = 11,
- InvalidJoinSecret = 12,
- NoEligibleActivity = 13,
- InvalidInvite = 14,
- NotAuthenticated = 15,
- InvalidAccessToken = 16,
- ApplicationMismatch = 17,
- InvalidDataUrl = 18,
- InvalidBase64 = 19,
- NotFiltered = 20,
- LobbyFull = 21,
- InvalidLobbySecret = 22,
- InvalidFilename = 23,
- InvalidFileSize = 24,
- InvalidEntitlement = 25,
- NotInstalled = 26,
- NotRunning = 27,
- InsufficientBuffer = 28,
- PurchaseCanceled = 29,
- InvalidGuild = 30,
- InvalidEvent = 31,
- InvalidChannel = 32,
- InvalidOrigin = 33,
- RateLimited = 34,
- OAuth2Error = 35,
- SelectChannelTimeout = 36,
- GetGuildTimeout = 37,
- SelectVoiceForceRequired = 38,
- CaptureShortcutAlreadyListening = 39,
- UnauthorizedForAchievement = 40,
- InvalidGiftCode = 41,
- PurchaseError = 42,
- TransactionAborted = 43,
- }
-
- public enum CreateFlags
- {
- Default = 0,
- NoRequireDiscord = 1,
- }
-
- public enum LogLevel
- {
- Error = 1,
- Warn,
- Info,
- Debug,
- }
-
- public enum UserFlag
- {
- Partner = 2,
- HypeSquadEvents = 4,
- HypeSquadHouse1 = 64,
- HypeSquadHouse2 = 128,
- HypeSquadHouse3 = 256,
- }
-
- public enum PremiumType
- {
- None = 0,
- Tier1 = 1,
- Tier2 = 2,
- }
-
- public enum ImageType
- {
- User,
- }
-
- public enum ActivityType
- {
- Playing,
- Streaming,
- Listening,
- Watching,
- }
-
- public enum ActivityActionType
- {
- Join = 1,
- Spectate,
- }
-
- public enum ActivityJoinRequestReply
- {
- No,
- Yes,
- Ignore,
- }
-
- public enum Status
- {
- Offline = 0,
- Online = 1,
- Idle = 2,
- DoNotDisturb = 3,
- }
-
- public enum RelationshipType
- {
- None,
- Friend,
- Blocked,
- PendingIncoming,
- PendingOutgoing,
- Implicit,
- }
-
- public enum LobbyType
- {
- Private = 1,
- Public,
- }
-
- public enum LobbySearchComparison
- {
- LessThanOrEqual = -2,
- LessThan,
- Equal,
- GreaterThan,
- GreaterThanOrEqual,
- NotEqual,
- }
-
- public enum LobbySearchCast
- {
- String = 1,
- Number,
- }
-
- public enum LobbySearchDistance
- {
- Local,
- Default,
- Extended,
- Global,
- }
-
- public enum EntitlementType
- {
- Purchase = 1,
- PremiumSubscription,
- DeveloperGift,
- TestModePurchase,
- FreePurchase,
- UserGift,
- PremiumPurchase,
- }
-
- public enum SkuType
- {
- Application = 1,
- DLC,
- Consumable,
- Bundle,
- }
-
- public enum InputModeType
- {
- VoiceActivity = 0,
- PushToTalk,
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct User
- {
- public Int64 Id;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
- public string Username;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
- public string Discriminator;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string Avatar;
-
- public bool Bot;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct OAuth2Token
- {
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string AccessToken;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
- public string Scopes;
-
- public Int64 Expires;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct ImageHandle
- {
- public ImageType Type;
-
- public Int64 Id;
-
- public UInt32 Size;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct ImageDimensions
- {
- public UInt32 Width;
-
- public UInt32 Height;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct ActivityTimestamps
- {
- public Int64 Start;
-
- public Int64 End;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct ActivityAssets
- {
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string LargeImage;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string LargeText;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string SmallImage;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string SmallText;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct PartySize
- {
- public Int32 CurrentSize;
-
- public Int32 MaxSize;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct ActivityParty
- {
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string Id;
-
- public PartySize Size;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct ActivitySecrets
- {
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string Match;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string Join;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string Spectate;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct Activity
- {
- public ActivityType Type;
-
- public Int64 ApplicationId;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string Name;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string State;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string Details;
-
- public ActivityTimestamps Timestamps;
-
- public ActivityAssets Assets;
-
- public ActivityParty Party;
-
- public ActivitySecrets Secrets;
-
- public bool Instance;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct Presence
- {
- public Status Status;
-
- public Activity Activity;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct Relationship
- {
- public RelationshipType Type;
-
- public User User;
-
- public Presence Presence;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct Lobby
- {
- public Int64 Id;
-
- public LobbyType Type;
-
- public Int64 OwnerId;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string Secret;
-
- public UInt32 Capacity;
-
- public bool Locked;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct FileStat
- {
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
- public string Filename;
-
- public UInt64 Size;
-
- public UInt64 LastModified;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct Entitlement
- {
- public Int64 Id;
-
- public EntitlementType Type;
-
- public Int64 SkuId;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct SkuPrice
- {
- public UInt32 Amount;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
- public string Currency;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct Sku
- {
- public Int64 Id;
-
- public SkuType Type;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
- public string Name;
-
- public SkuPrice Price;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct InputMode
- {
- public InputModeType Type;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
- public string Shortcut;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct UserAchievement
- {
- public Int64 UserId;
-
- public Int64 AchievementId;
-
- public byte PercentComplete;
-
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
- public string UnlockedAt;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct LobbyTransaction
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetTypeMethod(IntPtr methodsPtr, LobbyType type);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetOwnerMethod(IntPtr methodsPtr, Int64 ownerId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetCapacityMethod(IntPtr methodsPtr, UInt32 capacity);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetMetadataMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string key, [MarshalAs(UnmanagedType.LPStr)]string value);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result DeleteMetadataMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string key);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetLockedMethod(IntPtr methodsPtr, bool locked);
-
- internal SetTypeMethod SetType;
-
- internal SetOwnerMethod SetOwner;
-
- internal SetCapacityMethod SetCapacity;
-
- internal SetMetadataMethod SetMetadata;
-
- internal DeleteMetadataMethod DeleteMetadata;
-
- internal SetLockedMethod SetLocked;
- }
-
- internal IntPtr MethodsPtr;
-
- internal Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public void SetType(LobbyType type)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.SetType(MethodsPtr, type);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void SetOwner(Int64 ownerId)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.SetOwner(MethodsPtr, ownerId);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void SetCapacity(UInt32 capacity)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.SetCapacity(MethodsPtr, capacity);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void SetMetadata(string key, string value)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.SetMetadata(MethodsPtr, key, value);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void DeleteMetadata(string key)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.DeleteMetadata(MethodsPtr, key);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void SetLocked(bool locked)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.SetLocked(MethodsPtr, locked);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct LobbyMemberTransaction
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetMetadataMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string key, [MarshalAs(UnmanagedType.LPStr)]string value);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result DeleteMetadataMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string key);
-
- internal SetMetadataMethod SetMetadata;
-
- internal DeleteMetadataMethod DeleteMetadata;
- }
-
- internal IntPtr MethodsPtr;
-
- internal Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public void SetMetadata(string key, string value)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.SetMetadata(MethodsPtr, key, value);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void DeleteMetadata(string key)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.DeleteMetadata(MethodsPtr, key);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public partial struct LobbySearchQuery
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result FilterMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string key, LobbySearchComparison comparison, LobbySearchCast cast, [MarshalAs(UnmanagedType.LPStr)]string value);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SortMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string key, LobbySearchCast cast, [MarshalAs(UnmanagedType.LPStr)]string value);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result LimitMethod(IntPtr methodsPtr, UInt32 limit);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result DistanceMethod(IntPtr methodsPtr, LobbySearchDistance distance);
-
- internal FilterMethod Filter;
-
- internal SortMethod Sort;
-
- internal LimitMethod Limit;
-
- internal DistanceMethod Distance;
- }
-
- internal IntPtr MethodsPtr;
-
- internal Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public void Filter(string key, LobbySearchComparison comparison, LobbySearchCast cast, string value)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.Filter(MethodsPtr, key, comparison, cast, value);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void Sort(string key, LobbySearchCast cast, string value)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.Sort(MethodsPtr, key, cast, value);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void Limit(UInt32 limit)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.Limit(MethodsPtr, limit);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public void Distance(LobbySearchDistance distance)
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- var res = Methods.Distance(MethodsPtr, distance);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
- }
-
- public partial class ResultException : Exception
- {
- public readonly Result Result;
-
- public ResultException(Result result) : base(result.ToString())
- {
- }
- }
-
- public partial class Discord : IDisposable
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
-
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void DestroyHandler(IntPtr MethodsPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result RunCallbacksMethod(IntPtr methodsPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SetLogHookCallback(IntPtr ptr, LogLevel level, [MarshalAs(UnmanagedType.LPStr)]string message);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SetLogHookMethod(IntPtr methodsPtr, LogLevel minLevel, IntPtr callbackData, SetLogHookCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetApplicationManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetUserManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetImageManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetActivityManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetRelationshipManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetLobbyManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetNetworkManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetOverlayManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetStorageManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetStoreManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetVoiceManagerMethod(IntPtr discordPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate IntPtr GetAchievementManagerMethod(IntPtr discordPtr);
-
- internal DestroyHandler Destroy;
-
- internal RunCallbacksMethod RunCallbacks;
-
- internal SetLogHookMethod SetLogHook;
-
- internal GetApplicationManagerMethod GetApplicationManager;
-
- internal GetUserManagerMethod GetUserManager;
-
- internal GetImageManagerMethod GetImageManager;
-
- internal GetActivityManagerMethod GetActivityManager;
-
- internal GetRelationshipManagerMethod GetRelationshipManager;
-
- internal GetLobbyManagerMethod GetLobbyManager;
-
- internal GetNetworkManagerMethod GetNetworkManager;
-
- internal GetOverlayManagerMethod GetOverlayManager;
-
- internal GetStorageManagerMethod GetStorageManager;
-
- internal GetStoreManagerMethod GetStoreManager;
-
- internal GetVoiceManagerMethod GetVoiceManager;
-
- internal GetAchievementManagerMethod GetAchievementManager;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFICreateParams
- {
- internal Int64 ClientId;
-
- internal UInt64 Flags;
-
- internal IntPtr Events;
-
- internal IntPtr EventData;
-
- internal IntPtr ApplicationEvents;
-
- internal UInt32 ApplicationVersion;
-
- internal IntPtr UserEvents;
-
- internal UInt32 UserVersion;
-
- internal IntPtr ImageEvents;
-
- internal UInt32 ImageVersion;
-
- internal IntPtr ActivityEvents;
-
- internal UInt32 ActivityVersion;
-
- internal IntPtr RelationshipEvents;
-
- internal UInt32 RelationshipVersion;
-
- internal IntPtr LobbyEvents;
-
- internal UInt32 LobbyVersion;
-
- internal IntPtr NetworkEvents;
-
- internal UInt32 NetworkVersion;
-
- internal IntPtr OverlayEvents;
-
- internal UInt32 OverlayVersion;
-
- internal IntPtr StorageEvents;
-
- internal UInt32 StorageVersion;
-
- internal IntPtr StoreEvents;
-
- internal UInt32 StoreVersion;
-
- internal IntPtr VoiceEvents;
-
- internal UInt32 VoiceVersion;
-
- internal IntPtr AchievementEvents;
-
- internal UInt32 AchievementVersion;
- }
-
- [DllImport(Constants.DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
- private static extern Result DiscordCreate(UInt32 version, ref FFICreateParams createParams, out IntPtr manager);
-
- public delegate void SetLogHookHandler(LogLevel level, string message);
-
- private GCHandle SelfHandle;
-
- private IntPtr EventsPtr;
-
- private FFIEvents Events;
-
- private IntPtr ApplicationEventsPtr;
-
- private ApplicationManager.FFIEvents ApplicationEvents;
-
- internal ApplicationManager ApplicationManagerInstance;
-
- private IntPtr UserEventsPtr;
-
- private UserManager.FFIEvents UserEvents;
-
- internal UserManager UserManagerInstance;
-
- private IntPtr ImageEventsPtr;
-
- private ImageManager.FFIEvents ImageEvents;
-
- internal ImageManager ImageManagerInstance;
-
- private IntPtr ActivityEventsPtr;
-
- private ActivityManager.FFIEvents ActivityEvents;
-
- internal ActivityManager ActivityManagerInstance;
-
- private IntPtr RelationshipEventsPtr;
-
- private RelationshipManager.FFIEvents RelationshipEvents;
-
- internal RelationshipManager RelationshipManagerInstance;
-
- private IntPtr LobbyEventsPtr;
-
- private LobbyManager.FFIEvents LobbyEvents;
-
- internal LobbyManager LobbyManagerInstance;
-
- private IntPtr NetworkEventsPtr;
-
- private NetworkManager.FFIEvents NetworkEvents;
-
- internal NetworkManager NetworkManagerInstance;
-
- private IntPtr OverlayEventsPtr;
-
- private OverlayManager.FFIEvents OverlayEvents;
-
- internal OverlayManager OverlayManagerInstance;
-
- private IntPtr StorageEventsPtr;
-
- private StorageManager.FFIEvents StorageEvents;
-
- internal StorageManager StorageManagerInstance;
-
- private IntPtr StoreEventsPtr;
-
- private StoreManager.FFIEvents StoreEvents;
-
- internal StoreManager StoreManagerInstance;
-
- private IntPtr VoiceEventsPtr;
-
- private VoiceManager.FFIEvents VoiceEvents;
-
- internal VoiceManager VoiceManagerInstance;
-
- private IntPtr AchievementEventsPtr;
-
- private AchievementManager.FFIEvents AchievementEvents;
-
- internal AchievementManager AchievementManagerInstance;
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- private GCHandle? setLogHook;
-
- public Discord(Int64 clientId, UInt64 flags)
- {
- FFICreateParams createParams;
- createParams.ClientId = clientId;
- createParams.Flags = flags;
- Events = new FFIEvents();
- EventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(Events));
- createParams.Events = EventsPtr;
- SelfHandle = GCHandle.Alloc(this);
- createParams.EventData = GCHandle.ToIntPtr(SelfHandle);
- ApplicationEvents = new ApplicationManager.FFIEvents();
- ApplicationEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ApplicationEvents));
- createParams.ApplicationEvents = ApplicationEventsPtr;
- createParams.ApplicationVersion = 1;
- UserEvents = new UserManager.FFIEvents();
- UserEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(UserEvents));
- createParams.UserEvents = UserEventsPtr;
- createParams.UserVersion = 1;
- ImageEvents = new ImageManager.FFIEvents();
- ImageEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ImageEvents));
- createParams.ImageEvents = ImageEventsPtr;
- createParams.ImageVersion = 1;
- ActivityEvents = new ActivityManager.FFIEvents();
- ActivityEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ActivityEvents));
- createParams.ActivityEvents = ActivityEventsPtr;
- createParams.ActivityVersion = 1;
- RelationshipEvents = new RelationshipManager.FFIEvents();
- RelationshipEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(RelationshipEvents));
- createParams.RelationshipEvents = RelationshipEventsPtr;
- createParams.RelationshipVersion = 1;
- LobbyEvents = new LobbyManager.FFIEvents();
- LobbyEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(LobbyEvents));
- createParams.LobbyEvents = LobbyEventsPtr;
- createParams.LobbyVersion = 1;
- NetworkEvents = new NetworkManager.FFIEvents();
- NetworkEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(NetworkEvents));
- createParams.NetworkEvents = NetworkEventsPtr;
- createParams.NetworkVersion = 1;
- OverlayEvents = new OverlayManager.FFIEvents();
- OverlayEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(OverlayEvents));
- createParams.OverlayEvents = OverlayEventsPtr;
- createParams.OverlayVersion = 1;
- StorageEvents = new StorageManager.FFIEvents();
- StorageEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(StorageEvents));
- createParams.StorageEvents = StorageEventsPtr;
- createParams.StorageVersion = 1;
- StoreEvents = new StoreManager.FFIEvents();
- StoreEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(StoreEvents));
- createParams.StoreEvents = StoreEventsPtr;
- createParams.StoreVersion = 1;
- VoiceEvents = new VoiceManager.FFIEvents();
- VoiceEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(VoiceEvents));
- createParams.VoiceEvents = VoiceEventsPtr;
- createParams.VoiceVersion = 1;
- AchievementEvents = new AchievementManager.FFIEvents();
- AchievementEventsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(AchievementEvents));
- createParams.AchievementEvents = AchievementEventsPtr;
- createParams.AchievementVersion = 1;
- InitEvents(EventsPtr, ref Events);
- var result = DiscordCreate(2, ref createParams, out MethodsPtr);
- if (result != Result.Ok)
- {
- Dispose();
- throw new ResultException(result);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- public void Dispose()
- {
- if (MethodsPtr != IntPtr.Zero)
- {
- Methods.Destroy(MethodsPtr);
- }
- SelfHandle.Free();
- Marshal.FreeHGlobal(EventsPtr);
- Marshal.FreeHGlobal(ApplicationEventsPtr);
- Marshal.FreeHGlobal(UserEventsPtr);
- Marshal.FreeHGlobal(ImageEventsPtr);
- Marshal.FreeHGlobal(ActivityEventsPtr);
- Marshal.FreeHGlobal(RelationshipEventsPtr);
- Marshal.FreeHGlobal(LobbyEventsPtr);
- Marshal.FreeHGlobal(NetworkEventsPtr);
- Marshal.FreeHGlobal(OverlayEventsPtr);
- Marshal.FreeHGlobal(StorageEventsPtr);
- Marshal.FreeHGlobal(StoreEventsPtr);
- Marshal.FreeHGlobal(VoiceEventsPtr);
- Marshal.FreeHGlobal(AchievementEventsPtr);
- if (setLogHook.HasValue) {
- setLogHook.Value.Free();
- }
- }
-
- public void RunCallbacks()
- {
- var res = Methods.RunCallbacks(MethodsPtr);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- [MonoPInvokeCallback]
- private static void SetLogHookCallbackImpl(IntPtr ptr, LogLevel level, string message)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- SetLogHookHandler callback = (SetLogHookHandler)h.Target;
- callback(level, message);
- }
-
- public void SetLogHook(LogLevel minLevel, SetLogHookHandler callback)
- {
- if (setLogHook.HasValue) {
- setLogHook.Value.Free();
- }
- setLogHook = GCHandle.Alloc(callback);
- Methods.SetLogHook(MethodsPtr, minLevel, GCHandle.ToIntPtr(setLogHook.Value), SetLogHookCallbackImpl);
- }
-
- public ApplicationManager GetApplicationManager()
- {
- if (ApplicationManagerInstance == null) {
- ApplicationManagerInstance = new ApplicationManager(
- Methods.GetApplicationManager(MethodsPtr),
- ApplicationEventsPtr,
- ref ApplicationEvents
- );
- }
- return ApplicationManagerInstance;
- }
-
- public UserManager GetUserManager()
- {
- if (UserManagerInstance == null) {
- UserManagerInstance = new UserManager(
- Methods.GetUserManager(MethodsPtr),
- UserEventsPtr,
- ref UserEvents
- );
- }
- return UserManagerInstance;
- }
-
- public ImageManager GetImageManager()
- {
- if (ImageManagerInstance == null) {
- ImageManagerInstance = new ImageManager(
- Methods.GetImageManager(MethodsPtr),
- ImageEventsPtr,
- ref ImageEvents
- );
- }
- return ImageManagerInstance;
- }
-
- public ActivityManager GetActivityManager()
- {
- if (ActivityManagerInstance == null) {
- ActivityManagerInstance = new ActivityManager(
- Methods.GetActivityManager(MethodsPtr),
- ActivityEventsPtr,
- ref ActivityEvents
- );
- }
- return ActivityManagerInstance;
- }
-
- public RelationshipManager GetRelationshipManager()
- {
- if (RelationshipManagerInstance == null) {
- RelationshipManagerInstance = new RelationshipManager(
- Methods.GetRelationshipManager(MethodsPtr),
- RelationshipEventsPtr,
- ref RelationshipEvents
- );
- }
- return RelationshipManagerInstance;
- }
-
- public LobbyManager GetLobbyManager()
- {
- if (LobbyManagerInstance == null) {
- LobbyManagerInstance = new LobbyManager(
- Methods.GetLobbyManager(MethodsPtr),
- LobbyEventsPtr,
- ref LobbyEvents
- );
- }
- return LobbyManagerInstance;
- }
-
- public NetworkManager GetNetworkManager()
- {
- if (NetworkManagerInstance == null) {
- NetworkManagerInstance = new NetworkManager(
- Methods.GetNetworkManager(MethodsPtr),
- NetworkEventsPtr,
- ref NetworkEvents
- );
- }
- return NetworkManagerInstance;
- }
-
- public OverlayManager GetOverlayManager()
- {
- if (OverlayManagerInstance == null) {
- OverlayManagerInstance = new OverlayManager(
- Methods.GetOverlayManager(MethodsPtr),
- OverlayEventsPtr,
- ref OverlayEvents
- );
- }
- return OverlayManagerInstance;
- }
-
- public StorageManager GetStorageManager()
- {
- if (StorageManagerInstance == null) {
- StorageManagerInstance = new StorageManager(
- Methods.GetStorageManager(MethodsPtr),
- StorageEventsPtr,
- ref StorageEvents
- );
- }
- return StorageManagerInstance;
- }
-
- public StoreManager GetStoreManager()
- {
- if (StoreManagerInstance == null) {
- StoreManagerInstance = new StoreManager(
- Methods.GetStoreManager(MethodsPtr),
- StoreEventsPtr,
- ref StoreEvents
- );
- }
- return StoreManagerInstance;
- }
-
- public VoiceManager GetVoiceManager()
- {
- if (VoiceManagerInstance == null) {
- VoiceManagerInstance = new VoiceManager(
- Methods.GetVoiceManager(MethodsPtr),
- VoiceEventsPtr,
- ref VoiceEvents
- );
- }
- return VoiceManagerInstance;
- }
-
- public AchievementManager GetAchievementManager()
- {
- if (AchievementManagerInstance == null) {
- AchievementManagerInstance = new AchievementManager(
- Methods.GetAchievementManager(MethodsPtr),
- AchievementEventsPtr,
- ref AchievementEvents
- );
- }
- return AchievementManagerInstance;
- }
- }
-
- internal partial class MonoPInvokeCallbackAttribute : Attribute
- {
-
- }
-
- public partial class ApplicationManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
-
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ValidateOrExitCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ValidateOrExitMethod(IntPtr methodsPtr, IntPtr callbackData, ValidateOrExitCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetCurrentLocaleMethod(IntPtr methodsPtr, StringBuilder locale);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetCurrentBranchMethod(IntPtr methodsPtr, StringBuilder branch);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetOAuth2TokenCallback(IntPtr ptr, Result result, ref OAuth2Token oauth2Token);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetOAuth2TokenMethod(IntPtr methodsPtr, IntPtr callbackData, GetOAuth2TokenCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetTicketCallback(IntPtr ptr, Result result, [MarshalAs(UnmanagedType.LPStr)]ref string data);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetTicketMethod(IntPtr methodsPtr, IntPtr callbackData, GetTicketCallback callback);
-
- internal ValidateOrExitMethod ValidateOrExit;
-
- internal GetCurrentLocaleMethod GetCurrentLocale;
-
- internal GetCurrentBranchMethod GetCurrentBranch;
-
- internal GetOAuth2TokenMethod GetOAuth2Token;
-
- internal GetTicketMethod GetTicket;
- }
-
- public delegate void ValidateOrExitHandler(Result result);
-
- public delegate void GetOAuth2TokenHandler(Result result, ref OAuth2Token oauth2Token);
-
- public delegate void GetTicketHandler(Result result, ref string data);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- internal ApplicationManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- [MonoPInvokeCallback]
- private static void ValidateOrExitCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- ValidateOrExitHandler callback = (ValidateOrExitHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void ValidateOrExit(ValidateOrExitHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.ValidateOrExit(MethodsPtr, GCHandle.ToIntPtr(wrapped), ValidateOrExitCallbackImpl);
- }
-
- public string GetCurrentLocale()
- {
- var ret = new StringBuilder(128);
- Methods.GetCurrentLocale(MethodsPtr, ret);
- return ret.ToString();
- }
-
- public string GetCurrentBranch()
- {
- var ret = new StringBuilder(4096);
- Methods.GetCurrentBranch(MethodsPtr, ret);
- return ret.ToString();
- }
-
- [MonoPInvokeCallback]
- private static void GetOAuth2TokenCallbackImpl(IntPtr ptr, Result result, ref OAuth2Token oauth2Token)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- GetOAuth2TokenHandler callback = (GetOAuth2TokenHandler)h.Target;
- h.Free();
- callback(result, ref oauth2Token);
- }
-
- public void GetOAuth2Token(GetOAuth2TokenHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.GetOAuth2Token(MethodsPtr, GCHandle.ToIntPtr(wrapped), GetOAuth2TokenCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void GetTicketCallbackImpl(IntPtr ptr, Result result, ref string data)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- GetTicketHandler callback = (GetTicketHandler)h.Target;
- h.Free();
- callback(result, ref data);
- }
-
- public void GetTicket(GetTicketHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.GetTicket(MethodsPtr, GCHandle.ToIntPtr(wrapped), GetTicketCallbackImpl);
- }
- }
-
- public partial class UserManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CurrentUserUpdateHandler(IntPtr ptr);
-
- internal CurrentUserUpdateHandler OnCurrentUserUpdate;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetCurrentUserMethod(IntPtr methodsPtr, ref User currentUser);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetUserCallback(IntPtr ptr, Result result, ref User user);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetUserMethod(IntPtr methodsPtr, Int64 userId, IntPtr callbackData, GetUserCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetCurrentUserPremiumTypeMethod(IntPtr methodsPtr, ref PremiumType premiumType);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result CurrentUserHasFlagMethod(IntPtr methodsPtr, UserFlag flag, ref bool hasFlag);
-
- internal GetCurrentUserMethod GetCurrentUser;
-
- internal GetUserMethod GetUser;
-
- internal GetCurrentUserPremiumTypeMethod GetCurrentUserPremiumType;
-
- internal CurrentUserHasFlagMethod CurrentUserHasFlag;
- }
-
- public delegate void GetUserHandler(Result result, ref User user);
-
- public delegate void CurrentUserUpdateHandler();
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event CurrentUserUpdateHandler OnCurrentUserUpdate;
-
- internal UserManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnCurrentUserUpdate = OnCurrentUserUpdateImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- public User GetCurrentUser()
- {
- var ret = new User();
- var res = Methods.GetCurrentUser(MethodsPtr, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void GetUserCallbackImpl(IntPtr ptr, Result result, ref User user)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- GetUserHandler callback = (GetUserHandler)h.Target;
- h.Free();
- callback(result, ref user);
- }
-
- public void GetUser(Int64 userId, GetUserHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.GetUser(MethodsPtr, userId, GCHandle.ToIntPtr(wrapped), GetUserCallbackImpl);
- }
-
- public PremiumType GetCurrentUserPremiumType()
- {
- var ret = new PremiumType();
- var res = Methods.GetCurrentUserPremiumType(MethodsPtr, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public bool CurrentUserHasFlag(UserFlag flag)
- {
- var ret = new bool();
- var res = Methods.CurrentUserHasFlag(MethodsPtr, flag, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void OnCurrentUserUpdateImpl(IntPtr ptr)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.UserManagerInstance.OnCurrentUserUpdate != null)
- {
- d.UserManagerInstance.OnCurrentUserUpdate.Invoke();
- }
- }
- }
-
- public partial class ImageManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
-
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FetchCallback(IntPtr ptr, Result result, ImageHandle handleResult);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FetchMethod(IntPtr methodsPtr, ImageHandle handle, bool refresh, IntPtr callbackData, FetchCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetDimensionsMethod(IntPtr methodsPtr, ImageHandle handle, ref ImageDimensions dimensions);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetDataMethod(IntPtr methodsPtr, ImageHandle handle, byte[] data, Int32 dataLen);
-
- internal FetchMethod Fetch;
-
- internal GetDimensionsMethod GetDimensions;
-
- internal GetDataMethod GetData;
- }
-
- public delegate void FetchHandler(Result result, ImageHandle handleResult);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- internal ImageManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- [MonoPInvokeCallback]
- private static void FetchCallbackImpl(IntPtr ptr, Result result, ImageHandle handleResult)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- FetchHandler callback = (FetchHandler)h.Target;
- h.Free();
- callback(result, handleResult);
- }
-
- public void Fetch(ImageHandle handle, bool refresh, FetchHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.Fetch(MethodsPtr, handle, refresh, GCHandle.ToIntPtr(wrapped), FetchCallbackImpl);
- }
-
- public ImageDimensions GetDimensions(ImageHandle handle)
- {
- var ret = new ImageDimensions();
- var res = Methods.GetDimensions(MethodsPtr, handle, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public void GetData(ImageHandle handle, byte[] data)
- {
- var res = Methods.GetData(MethodsPtr, handle, data, data.Length);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
- }
-
- public partial class ActivityManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ActivityJoinHandler(IntPtr ptr, [MarshalAs(UnmanagedType.LPStr)]string secret);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ActivitySpectateHandler(IntPtr ptr, [MarshalAs(UnmanagedType.LPStr)]string secret);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ActivityJoinRequestHandler(IntPtr ptr, ref User user);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ActivityInviteHandler(IntPtr ptr, ActivityActionType type, ref User user, ref Activity activity);
-
- internal ActivityJoinHandler OnActivityJoin;
-
- internal ActivitySpectateHandler OnActivitySpectate;
-
- internal ActivityJoinRequestHandler OnActivityJoinRequest;
-
- internal ActivityInviteHandler OnActivityInvite;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result RegisterCommandMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string command);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result RegisterSteamMethod(IntPtr methodsPtr, UInt32 steamId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void UpdateActivityCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void UpdateActivityMethod(IntPtr methodsPtr, ref Activity activity, IntPtr callbackData, UpdateActivityCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ClearActivityCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ClearActivityMethod(IntPtr methodsPtr, IntPtr callbackData, ClearActivityCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SendRequestReplyCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SendRequestReplyMethod(IntPtr methodsPtr, Int64 userId, ActivityJoinRequestReply reply, IntPtr callbackData, SendRequestReplyCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SendInviteCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SendInviteMethod(IntPtr methodsPtr, Int64 userId, ActivityActionType type, [MarshalAs(UnmanagedType.LPStr)]string content, IntPtr callbackData, SendInviteCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void AcceptInviteCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void AcceptInviteMethod(IntPtr methodsPtr, Int64 userId, IntPtr callbackData, AcceptInviteCallback callback);
-
- internal RegisterCommandMethod RegisterCommand;
-
- internal RegisterSteamMethod RegisterSteam;
-
- internal UpdateActivityMethod UpdateActivity;
-
- internal ClearActivityMethod ClearActivity;
-
- internal SendRequestReplyMethod SendRequestReply;
-
- internal SendInviteMethod SendInvite;
-
- internal AcceptInviteMethod AcceptInvite;
- }
-
- public delegate void UpdateActivityHandler(Result result);
-
- public delegate void ClearActivityHandler(Result result);
-
- public delegate void SendRequestReplyHandler(Result result);
-
- public delegate void SendInviteHandler(Result result);
-
- public delegate void AcceptInviteHandler(Result result);
-
- public delegate void ActivityJoinHandler(string secret);
-
- public delegate void ActivitySpectateHandler(string secret);
-
- public delegate void ActivityJoinRequestHandler(ref User user);
-
- public delegate void ActivityInviteHandler(ActivityActionType type, ref User user, ref Activity activity);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event ActivityJoinHandler OnActivityJoin;
-
- public event ActivitySpectateHandler OnActivitySpectate;
-
- public event ActivityJoinRequestHandler OnActivityJoinRequest;
-
- public event ActivityInviteHandler OnActivityInvite;
-
- internal ActivityManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnActivityJoin = OnActivityJoinImpl;
- events.OnActivitySpectate = OnActivitySpectateImpl;
- events.OnActivityJoinRequest = OnActivityJoinRequestImpl;
- events.OnActivityInvite = OnActivityInviteImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- public void RegisterCommand(string command)
- {
- var res = Methods.RegisterCommand(MethodsPtr, command);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public void RegisterSteam(UInt32 steamId)
- {
- var res = Methods.RegisterSteam(MethodsPtr, steamId);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- [MonoPInvokeCallback]
- private static void UpdateActivityCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- UpdateActivityHandler callback = (UpdateActivityHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void UpdateActivity(Activity activity, UpdateActivityHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.UpdateActivity(MethodsPtr, ref activity, GCHandle.ToIntPtr(wrapped), UpdateActivityCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void ClearActivityCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- ClearActivityHandler callback = (ClearActivityHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void ClearActivity(ClearActivityHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.ClearActivity(MethodsPtr, GCHandle.ToIntPtr(wrapped), ClearActivityCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void SendRequestReplyCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- SendRequestReplyHandler callback = (SendRequestReplyHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void SendRequestReply(Int64 userId, ActivityJoinRequestReply reply, SendRequestReplyHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.SendRequestReply(MethodsPtr, userId, reply, GCHandle.ToIntPtr(wrapped), SendRequestReplyCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void SendInviteCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- SendInviteHandler callback = (SendInviteHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void SendInvite(Int64 userId, ActivityActionType type, string content, SendInviteHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.SendInvite(MethodsPtr, userId, type, content, GCHandle.ToIntPtr(wrapped), SendInviteCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void AcceptInviteCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- AcceptInviteHandler callback = (AcceptInviteHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void AcceptInvite(Int64 userId, AcceptInviteHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.AcceptInvite(MethodsPtr, userId, GCHandle.ToIntPtr(wrapped), AcceptInviteCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void OnActivityJoinImpl(IntPtr ptr, string secret)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.ActivityManagerInstance.OnActivityJoin != null)
- {
- d.ActivityManagerInstance.OnActivityJoin.Invoke(secret);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnActivitySpectateImpl(IntPtr ptr, string secret)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.ActivityManagerInstance.OnActivitySpectate != null)
- {
- d.ActivityManagerInstance.OnActivitySpectate.Invoke(secret);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnActivityJoinRequestImpl(IntPtr ptr, ref User user)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.ActivityManagerInstance.OnActivityJoinRequest != null)
- {
- d.ActivityManagerInstance.OnActivityJoinRequest.Invoke(ref user);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnActivityInviteImpl(IntPtr ptr, ActivityActionType type, ref User user, ref Activity activity)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.ActivityManagerInstance.OnActivityInvite != null)
- {
- d.ActivityManagerInstance.OnActivityInvite.Invoke(type, ref user, ref activity);
- }
- }
- }
-
- public partial class RelationshipManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void RefreshHandler(IntPtr ptr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void RelationshipUpdateHandler(IntPtr ptr, ref Relationship relationship);
-
- internal RefreshHandler OnRefresh;
-
- internal RelationshipUpdateHandler OnRelationshipUpdate;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate bool FilterCallback(IntPtr ptr, ref Relationship relationship);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FilterMethod(IntPtr methodsPtr, IntPtr callbackData, FilterCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result CountMethod(IntPtr methodsPtr, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetMethod(IntPtr methodsPtr, Int64 userId, ref Relationship relationship);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetAtMethod(IntPtr methodsPtr, UInt32 index, ref Relationship relationship);
-
- internal FilterMethod Filter;
-
- internal CountMethod Count;
-
- internal GetMethod Get;
-
- internal GetAtMethod GetAt;
- }
-
- public delegate bool FilterHandler(ref Relationship relationship);
-
- public delegate void RefreshHandler();
-
- public delegate void RelationshipUpdateHandler(ref Relationship relationship);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event RefreshHandler OnRefresh;
-
- public event RelationshipUpdateHandler OnRelationshipUpdate;
-
- internal RelationshipManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnRefresh = OnRefreshImpl;
- events.OnRelationshipUpdate = OnRelationshipUpdateImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- [MonoPInvokeCallback]
- private static bool FilterCallbackImpl(IntPtr ptr, ref Relationship relationship)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- FilterHandler callback = (FilterHandler)h.Target;
- return callback(ref relationship);
- }
-
- public void Filter(FilterHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.Filter(MethodsPtr, GCHandle.ToIntPtr(wrapped), FilterCallbackImpl);
- wrapped.Free();
- }
-
- public Int32 Count()
- {
- var ret = new Int32();
- var res = Methods.Count(MethodsPtr, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public Relationship Get(Int64 userId)
- {
- var ret = new Relationship();
- var res = Methods.Get(MethodsPtr, userId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public Relationship GetAt(UInt32 index)
- {
- var ret = new Relationship();
- var res = Methods.GetAt(MethodsPtr, index, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void OnRefreshImpl(IntPtr ptr)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.RelationshipManagerInstance.OnRefresh != null)
- {
- d.RelationshipManagerInstance.OnRefresh.Invoke();
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnRelationshipUpdateImpl(IntPtr ptr, ref Relationship relationship)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.RelationshipManagerInstance.OnRelationshipUpdate != null)
- {
- d.RelationshipManagerInstance.OnRelationshipUpdate.Invoke(ref relationship);
- }
- }
- }
-
- public partial class LobbyManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void LobbyUpdateHandler(IntPtr ptr, Int64 lobbyId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void LobbyDeleteHandler(IntPtr ptr, Int64 lobbyId, UInt32 reason);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void MemberConnectHandler(IntPtr ptr, Int64 lobbyId, Int64 userId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void MemberUpdateHandler(IntPtr ptr, Int64 lobbyId, Int64 userId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void MemberDisconnectHandler(IntPtr ptr, Int64 lobbyId, Int64 userId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void LobbyMessageHandler(IntPtr ptr, Int64 lobbyId, Int64 userId, IntPtr dataPtr, Int32 dataLen);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SpeakingHandler(IntPtr ptr, Int64 lobbyId, Int64 userId, bool speaking);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void NetworkMessageHandler(IntPtr ptr, Int64 lobbyId, Int64 userId, byte channelId, IntPtr dataPtr, Int32 dataLen);
-
- internal LobbyUpdateHandler OnLobbyUpdate;
-
- internal LobbyDeleteHandler OnLobbyDelete;
-
- internal MemberConnectHandler OnMemberConnect;
-
- internal MemberUpdateHandler OnMemberUpdate;
-
- internal MemberDisconnectHandler OnMemberDisconnect;
-
- internal LobbyMessageHandler OnLobbyMessage;
-
- internal SpeakingHandler OnSpeaking;
-
- internal NetworkMessageHandler OnNetworkMessage;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetLobbyCreateTransactionMethod(IntPtr methodsPtr, ref IntPtr transaction);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetLobbyUpdateTransactionMethod(IntPtr methodsPtr, Int64 lobbyId, ref IntPtr transaction);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetMemberUpdateTransactionMethod(IntPtr methodsPtr, Int64 lobbyId, Int64 userId, ref IntPtr transaction);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CreateLobbyCallback(IntPtr ptr, Result result, ref Lobby lobby);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CreateLobbyMethod(IntPtr methodsPtr, IntPtr transaction, IntPtr callbackData, CreateLobbyCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void UpdateLobbyCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void UpdateLobbyMethod(IntPtr methodsPtr, Int64 lobbyId, IntPtr transaction, IntPtr callbackData, UpdateLobbyCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void DeleteLobbyCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void DeleteLobbyMethod(IntPtr methodsPtr, Int64 lobbyId, IntPtr callbackData, DeleteLobbyCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ConnectLobbyCallback(IntPtr ptr, Result result, ref Lobby lobby);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ConnectLobbyMethod(IntPtr methodsPtr, Int64 lobbyId, [MarshalAs(UnmanagedType.LPStr)]string secret, IntPtr callbackData, ConnectLobbyCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ConnectLobbyWithActivitySecretCallback(IntPtr ptr, Result result, ref Lobby lobby);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ConnectLobbyWithActivitySecretMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string activitySecret, IntPtr callbackData, ConnectLobbyWithActivitySecretCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void DisconnectLobbyCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void DisconnectLobbyMethod(IntPtr methodsPtr, Int64 lobbyId, IntPtr callbackData, DisconnectLobbyCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetLobbyMethod(IntPtr methodsPtr, Int64 lobbyId, ref Lobby lobby);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetLobbyActivitySecretMethod(IntPtr methodsPtr, Int64 lobbyId, StringBuilder secret);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetLobbyMetadataValueMethod(IntPtr methodsPtr, Int64 lobbyId, [MarshalAs(UnmanagedType.LPStr)]string key, StringBuilder value);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetLobbyMetadataKeyMethod(IntPtr methodsPtr, Int64 lobbyId, Int32 index, StringBuilder key);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result LobbyMetadataCountMethod(IntPtr methodsPtr, Int64 lobbyId, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result MemberCountMethod(IntPtr methodsPtr, Int64 lobbyId, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetMemberUserIdMethod(IntPtr methodsPtr, Int64 lobbyId, Int32 index, ref Int64 userId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetMemberUserMethod(IntPtr methodsPtr, Int64 lobbyId, Int64 userId, ref User user);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetMemberMetadataValueMethod(IntPtr methodsPtr, Int64 lobbyId, Int64 userId, [MarshalAs(UnmanagedType.LPStr)]string key, StringBuilder value);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetMemberMetadataKeyMethod(IntPtr methodsPtr, Int64 lobbyId, Int64 userId, Int32 index, StringBuilder key);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result MemberMetadataCountMethod(IntPtr methodsPtr, Int64 lobbyId, Int64 userId, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void UpdateMemberCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void UpdateMemberMethod(IntPtr methodsPtr, Int64 lobbyId, Int64 userId, IntPtr transaction, IntPtr callbackData, UpdateMemberCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SendLobbyMessageCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SendLobbyMessageMethod(IntPtr methodsPtr, Int64 lobbyId, byte[] data, Int32 dataLen, IntPtr callbackData, SendLobbyMessageCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetSearchQueryMethod(IntPtr methodsPtr, ref IntPtr query);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SearchCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SearchMethod(IntPtr methodsPtr, IntPtr query, IntPtr callbackData, SearchCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void LobbyCountMethod(IntPtr methodsPtr, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetLobbyIdMethod(IntPtr methodsPtr, Int32 index, ref Int64 lobbyId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ConnectVoiceCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ConnectVoiceMethod(IntPtr methodsPtr, Int64 lobbyId, IntPtr callbackData, ConnectVoiceCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void DisconnectVoiceCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void DisconnectVoiceMethod(IntPtr methodsPtr, Int64 lobbyId, IntPtr callbackData, DisconnectVoiceCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result ConnectNetworkMethod(IntPtr methodsPtr, Int64 lobbyId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result DisconnectNetworkMethod(IntPtr methodsPtr, Int64 lobbyId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result FlushNetworkMethod(IntPtr methodsPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result OpenNetworkChannelMethod(IntPtr methodsPtr, Int64 lobbyId, byte channelId, bool reliable);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SendNetworkMessageMethod(IntPtr methodsPtr, Int64 lobbyId, Int64 userId, byte channelId, byte[] data, Int32 dataLen);
-
- internal GetLobbyCreateTransactionMethod GetLobbyCreateTransaction;
-
- internal GetLobbyUpdateTransactionMethod GetLobbyUpdateTransaction;
-
- internal GetMemberUpdateTransactionMethod GetMemberUpdateTransaction;
-
- internal CreateLobbyMethod CreateLobby;
-
- internal UpdateLobbyMethod UpdateLobby;
-
- internal DeleteLobbyMethod DeleteLobby;
-
- internal ConnectLobbyMethod ConnectLobby;
-
- internal ConnectLobbyWithActivitySecretMethod ConnectLobbyWithActivitySecret;
-
- internal DisconnectLobbyMethod DisconnectLobby;
-
- internal GetLobbyMethod GetLobby;
-
- internal GetLobbyActivitySecretMethod GetLobbyActivitySecret;
-
- internal GetLobbyMetadataValueMethod GetLobbyMetadataValue;
-
- internal GetLobbyMetadataKeyMethod GetLobbyMetadataKey;
-
- internal LobbyMetadataCountMethod LobbyMetadataCount;
-
- internal MemberCountMethod MemberCount;
-
- internal GetMemberUserIdMethod GetMemberUserId;
-
- internal GetMemberUserMethod GetMemberUser;
-
- internal GetMemberMetadataValueMethod GetMemberMetadataValue;
-
- internal GetMemberMetadataKeyMethod GetMemberMetadataKey;
-
- internal MemberMetadataCountMethod MemberMetadataCount;
-
- internal UpdateMemberMethod UpdateMember;
-
- internal SendLobbyMessageMethod SendLobbyMessage;
-
- internal GetSearchQueryMethod GetSearchQuery;
-
- internal SearchMethod Search;
-
- internal LobbyCountMethod LobbyCount;
-
- internal GetLobbyIdMethod GetLobbyId;
-
- internal ConnectVoiceMethod ConnectVoice;
-
- internal DisconnectVoiceMethod DisconnectVoice;
-
- internal ConnectNetworkMethod ConnectNetwork;
-
- internal DisconnectNetworkMethod DisconnectNetwork;
-
- internal FlushNetworkMethod FlushNetwork;
-
- internal OpenNetworkChannelMethod OpenNetworkChannel;
-
- internal SendNetworkMessageMethod SendNetworkMessage;
- }
-
- public delegate void CreateLobbyHandler(Result result, ref Lobby lobby);
-
- public delegate void UpdateLobbyHandler(Result result);
-
- public delegate void DeleteLobbyHandler(Result result);
-
- public delegate void ConnectLobbyHandler(Result result, ref Lobby lobby);
-
- public delegate void ConnectLobbyWithActivitySecretHandler(Result result, ref Lobby lobby);
-
- public delegate void DisconnectLobbyHandler(Result result);
-
- public delegate void UpdateMemberHandler(Result result);
-
- public delegate void SendLobbyMessageHandler(Result result);
-
- public delegate void SearchHandler(Result result);
-
- public delegate void ConnectVoiceHandler(Result result);
-
- public delegate void DisconnectVoiceHandler(Result result);
-
- public delegate void LobbyUpdateHandler(Int64 lobbyId);
-
- public delegate void LobbyDeleteHandler(Int64 lobbyId, UInt32 reason);
-
- public delegate void MemberConnectHandler(Int64 lobbyId, Int64 userId);
-
- public delegate void MemberUpdateHandler(Int64 lobbyId, Int64 userId);
-
- public delegate void MemberDisconnectHandler(Int64 lobbyId, Int64 userId);
-
- public delegate void LobbyMessageHandler(Int64 lobbyId, Int64 userId, byte[] data);
-
- public delegate void SpeakingHandler(Int64 lobbyId, Int64 userId, bool speaking);
-
- public delegate void NetworkMessageHandler(Int64 lobbyId, Int64 userId, byte channelId, byte[] data);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event LobbyUpdateHandler OnLobbyUpdate;
-
- public event LobbyDeleteHandler OnLobbyDelete;
-
- public event MemberConnectHandler OnMemberConnect;
-
- public event MemberUpdateHandler OnMemberUpdate;
-
- public event MemberDisconnectHandler OnMemberDisconnect;
-
- public event LobbyMessageHandler OnLobbyMessage;
-
- public event SpeakingHandler OnSpeaking;
-
- public event NetworkMessageHandler OnNetworkMessage;
-
- internal LobbyManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnLobbyUpdate = OnLobbyUpdateImpl;
- events.OnLobbyDelete = OnLobbyDeleteImpl;
- events.OnMemberConnect = OnMemberConnectImpl;
- events.OnMemberUpdate = OnMemberUpdateImpl;
- events.OnMemberDisconnect = OnMemberDisconnectImpl;
- events.OnLobbyMessage = OnLobbyMessageImpl;
- events.OnSpeaking = OnSpeakingImpl;
- events.OnNetworkMessage = OnNetworkMessageImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- public LobbyTransaction GetLobbyCreateTransaction()
- {
- var ret = new LobbyTransaction();
- var res = Methods.GetLobbyCreateTransaction(MethodsPtr, ref ret.MethodsPtr);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public LobbyTransaction GetLobbyUpdateTransaction(Int64 lobbyId)
- {
- var ret = new LobbyTransaction();
- var res = Methods.GetLobbyUpdateTransaction(MethodsPtr, lobbyId, ref ret.MethodsPtr);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public LobbyMemberTransaction GetMemberUpdateTransaction(Int64 lobbyId, Int64 userId)
- {
- var ret = new LobbyMemberTransaction();
- var res = Methods.GetMemberUpdateTransaction(MethodsPtr, lobbyId, userId, ref ret.MethodsPtr);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void CreateLobbyCallbackImpl(IntPtr ptr, Result result, ref Lobby lobby)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- CreateLobbyHandler callback = (CreateLobbyHandler)h.Target;
- h.Free();
- callback(result, ref lobby);
- }
-
- public void CreateLobby(LobbyTransaction transaction, CreateLobbyHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.CreateLobby(MethodsPtr, transaction.MethodsPtr, GCHandle.ToIntPtr(wrapped), CreateLobbyCallbackImpl);
- transaction.MethodsPtr = IntPtr.Zero;
- }
-
- [MonoPInvokeCallback]
- private static void UpdateLobbyCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- UpdateLobbyHandler callback = (UpdateLobbyHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void UpdateLobby(Int64 lobbyId, LobbyTransaction transaction, UpdateLobbyHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.UpdateLobby(MethodsPtr, lobbyId, transaction.MethodsPtr, GCHandle.ToIntPtr(wrapped), UpdateLobbyCallbackImpl);
- transaction.MethodsPtr = IntPtr.Zero;
- }
-
- [MonoPInvokeCallback]
- private static void DeleteLobbyCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- DeleteLobbyHandler callback = (DeleteLobbyHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void DeleteLobby(Int64 lobbyId, DeleteLobbyHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.DeleteLobby(MethodsPtr, lobbyId, GCHandle.ToIntPtr(wrapped), DeleteLobbyCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void ConnectLobbyCallbackImpl(IntPtr ptr, Result result, ref Lobby lobby)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- ConnectLobbyHandler callback = (ConnectLobbyHandler)h.Target;
- h.Free();
- callback(result, ref lobby);
- }
-
- public void ConnectLobby(Int64 lobbyId, string secret, ConnectLobbyHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.ConnectLobby(MethodsPtr, lobbyId, secret, GCHandle.ToIntPtr(wrapped), ConnectLobbyCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void ConnectLobbyWithActivitySecretCallbackImpl(IntPtr ptr, Result result, ref Lobby lobby)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- ConnectLobbyWithActivitySecretHandler callback = (ConnectLobbyWithActivitySecretHandler)h.Target;
- h.Free();
- callback(result, ref lobby);
- }
-
- public void ConnectLobbyWithActivitySecret(string activitySecret, ConnectLobbyWithActivitySecretHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.ConnectLobbyWithActivitySecret(MethodsPtr, activitySecret, GCHandle.ToIntPtr(wrapped), ConnectLobbyWithActivitySecretCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void DisconnectLobbyCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- DisconnectLobbyHandler callback = (DisconnectLobbyHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void DisconnectLobby(Int64 lobbyId, DisconnectLobbyHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.DisconnectLobby(MethodsPtr, lobbyId, GCHandle.ToIntPtr(wrapped), DisconnectLobbyCallbackImpl);
- }
-
- public Lobby GetLobby(Int64 lobbyId)
- {
- var ret = new Lobby();
- var res = Methods.GetLobby(MethodsPtr, lobbyId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public string GetLobbyActivitySecret(Int64 lobbyId)
- {
- var ret = new StringBuilder(128);
- var res = Methods.GetLobbyActivitySecret(MethodsPtr, lobbyId, ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret.ToString();
- }
-
- public string GetLobbyMetadataValue(Int64 lobbyId, string key)
- {
- var ret = new StringBuilder(4096);
- var res = Methods.GetLobbyMetadataValue(MethodsPtr, lobbyId, key, ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret.ToString();
- }
-
- public string GetLobbyMetadataKey(Int64 lobbyId, Int32 index)
- {
- var ret = new StringBuilder(256);
- var res = Methods.GetLobbyMetadataKey(MethodsPtr, lobbyId, index, ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret.ToString();
- }
-
- public Int32 LobbyMetadataCount(Int64 lobbyId)
- {
- var ret = new Int32();
- var res = Methods.LobbyMetadataCount(MethodsPtr, lobbyId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public Int32 MemberCount(Int64 lobbyId)
- {
- var ret = new Int32();
- var res = Methods.MemberCount(MethodsPtr, lobbyId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public Int64 GetMemberUserId(Int64 lobbyId, Int32 index)
- {
- var ret = new Int64();
- var res = Methods.GetMemberUserId(MethodsPtr, lobbyId, index, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public User GetMemberUser(Int64 lobbyId, Int64 userId)
- {
- var ret = new User();
- var res = Methods.GetMemberUser(MethodsPtr, lobbyId, userId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public string GetMemberMetadataValue(Int64 lobbyId, Int64 userId, string key)
- {
- var ret = new StringBuilder(4096);
- var res = Methods.GetMemberMetadataValue(MethodsPtr, lobbyId, userId, key, ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret.ToString();
- }
-
- public string GetMemberMetadataKey(Int64 lobbyId, Int64 userId, Int32 index)
- {
- var ret = new StringBuilder(256);
- var res = Methods.GetMemberMetadataKey(MethodsPtr, lobbyId, userId, index, ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret.ToString();
- }
-
- public Int32 MemberMetadataCount(Int64 lobbyId, Int64 userId)
- {
- var ret = new Int32();
- var res = Methods.MemberMetadataCount(MethodsPtr, lobbyId, userId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void UpdateMemberCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- UpdateMemberHandler callback = (UpdateMemberHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void UpdateMember(Int64 lobbyId, Int64 userId, LobbyMemberTransaction transaction, UpdateMemberHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.UpdateMember(MethodsPtr, lobbyId, userId, transaction.MethodsPtr, GCHandle.ToIntPtr(wrapped), UpdateMemberCallbackImpl);
- transaction.MethodsPtr = IntPtr.Zero;
- }
-
- [MonoPInvokeCallback]
- private static void SendLobbyMessageCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- SendLobbyMessageHandler callback = (SendLobbyMessageHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void SendLobbyMessage(Int64 lobbyId, byte[] data, SendLobbyMessageHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.SendLobbyMessage(MethodsPtr, lobbyId, data, data.Length, GCHandle.ToIntPtr(wrapped), SendLobbyMessageCallbackImpl);
- }
-
- public LobbySearchQuery GetSearchQuery()
- {
- var ret = new LobbySearchQuery();
- var res = Methods.GetSearchQuery(MethodsPtr, ref ret.MethodsPtr);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void SearchCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- SearchHandler callback = (SearchHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void Search(LobbySearchQuery query, SearchHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.Search(MethodsPtr, query.MethodsPtr, GCHandle.ToIntPtr(wrapped), SearchCallbackImpl);
- query.MethodsPtr = IntPtr.Zero;
- }
-
- public Int32 LobbyCount()
- {
- var ret = new Int32();
- Methods.LobbyCount(MethodsPtr, ref ret);
- return ret;
- }
-
- public Int64 GetLobbyId(Int32 index)
- {
- var ret = new Int64();
- var res = Methods.GetLobbyId(MethodsPtr, index, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void ConnectVoiceCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- ConnectVoiceHandler callback = (ConnectVoiceHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void ConnectVoice(Int64 lobbyId, ConnectVoiceHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.ConnectVoice(MethodsPtr, lobbyId, GCHandle.ToIntPtr(wrapped), ConnectVoiceCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void DisconnectVoiceCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- DisconnectVoiceHandler callback = (DisconnectVoiceHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void DisconnectVoice(Int64 lobbyId, DisconnectVoiceHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.DisconnectVoice(MethodsPtr, lobbyId, GCHandle.ToIntPtr(wrapped), DisconnectVoiceCallbackImpl);
- }
-
- public void ConnectNetwork(Int64 lobbyId)
- {
- var res = Methods.ConnectNetwork(MethodsPtr, lobbyId);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public void DisconnectNetwork(Int64 lobbyId)
- {
- var res = Methods.DisconnectNetwork(MethodsPtr, lobbyId);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public void FlushNetwork()
- {
- var res = Methods.FlushNetwork(MethodsPtr);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public void OpenNetworkChannel(Int64 lobbyId, byte channelId, bool reliable)
- {
- var res = Methods.OpenNetworkChannel(MethodsPtr, lobbyId, channelId, reliable);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public void SendNetworkMessage(Int64 lobbyId, Int64 userId, byte channelId, byte[] data)
- {
- var res = Methods.SendNetworkMessage(MethodsPtr, lobbyId, userId, channelId, data, data.Length);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnLobbyUpdateImpl(IntPtr ptr, Int64 lobbyId)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.LobbyManagerInstance.OnLobbyUpdate != null)
- {
- d.LobbyManagerInstance.OnLobbyUpdate.Invoke(lobbyId);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnLobbyDeleteImpl(IntPtr ptr, Int64 lobbyId, UInt32 reason)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.LobbyManagerInstance.OnLobbyDelete != null)
- {
- d.LobbyManagerInstance.OnLobbyDelete.Invoke(lobbyId, reason);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnMemberConnectImpl(IntPtr ptr, Int64 lobbyId, Int64 userId)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.LobbyManagerInstance.OnMemberConnect != null)
- {
- d.LobbyManagerInstance.OnMemberConnect.Invoke(lobbyId, userId);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnMemberUpdateImpl(IntPtr ptr, Int64 lobbyId, Int64 userId)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.LobbyManagerInstance.OnMemberUpdate != null)
- {
- d.LobbyManagerInstance.OnMemberUpdate.Invoke(lobbyId, userId);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnMemberDisconnectImpl(IntPtr ptr, Int64 lobbyId, Int64 userId)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.LobbyManagerInstance.OnMemberDisconnect != null)
- {
- d.LobbyManagerInstance.OnMemberDisconnect.Invoke(lobbyId, userId);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnLobbyMessageImpl(IntPtr ptr, Int64 lobbyId, Int64 userId, IntPtr dataPtr, Int32 dataLen)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.LobbyManagerInstance.OnLobbyMessage != null)
- {
- byte[] data = new byte[dataLen];
- Marshal.Copy(dataPtr, data, 0, (int)dataLen);
- d.LobbyManagerInstance.OnLobbyMessage.Invoke(lobbyId, userId, data);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnSpeakingImpl(IntPtr ptr, Int64 lobbyId, Int64 userId, bool speaking)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.LobbyManagerInstance.OnSpeaking != null)
- {
- d.LobbyManagerInstance.OnSpeaking.Invoke(lobbyId, userId, speaking);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnNetworkMessageImpl(IntPtr ptr, Int64 lobbyId, Int64 userId, byte channelId, IntPtr dataPtr, Int32 dataLen)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.LobbyManagerInstance.OnNetworkMessage != null)
- {
- byte[] data = new byte[dataLen];
- Marshal.Copy(dataPtr, data, 0, (int)dataLen);
- d.LobbyManagerInstance.OnNetworkMessage.Invoke(lobbyId, userId, channelId, data);
- }
- }
- }
-
- public partial class NetworkManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void MessageHandler(IntPtr ptr, UInt64 peerId, byte channelId, IntPtr dataPtr, Int32 dataLen);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void RouteUpdateHandler(IntPtr ptr, [MarshalAs(UnmanagedType.LPStr)]string routeData);
-
- internal MessageHandler OnMessage;
-
- internal RouteUpdateHandler OnRouteUpdate;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void GetPeerIdMethod(IntPtr methodsPtr, ref UInt64 peerId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result FlushMethod(IntPtr methodsPtr);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result OpenPeerMethod(IntPtr methodsPtr, UInt64 peerId, [MarshalAs(UnmanagedType.LPStr)]string routeData);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result UpdatePeerMethod(IntPtr methodsPtr, UInt64 peerId, [MarshalAs(UnmanagedType.LPStr)]string routeData);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result ClosePeerMethod(IntPtr methodsPtr, UInt64 peerId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result OpenChannelMethod(IntPtr methodsPtr, UInt64 peerId, byte channelId, bool reliable);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result CloseChannelMethod(IntPtr methodsPtr, UInt64 peerId, byte channelId);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SendMessageMethod(IntPtr methodsPtr, UInt64 peerId, byte channelId, byte[] data, Int32 dataLen);
-
- internal GetPeerIdMethod GetPeerId;
-
- internal FlushMethod Flush;
-
- internal OpenPeerMethod OpenPeer;
-
- internal UpdatePeerMethod UpdatePeer;
-
- internal ClosePeerMethod ClosePeer;
-
- internal OpenChannelMethod OpenChannel;
-
- internal CloseChannelMethod CloseChannel;
-
- internal SendMessageMethod SendMessage;
- }
-
- public delegate void MessageHandler(UInt64 peerId, byte channelId, byte[] data);
-
- public delegate void RouteUpdateHandler(string routeData);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event MessageHandler OnMessage;
-
- public event RouteUpdateHandler OnRouteUpdate;
-
- internal NetworkManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnMessage = OnMessageImpl;
- events.OnRouteUpdate = OnRouteUpdateImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- /// <summary>
- /// Get the local peer ID for this process.
- /// </summary>
- public UInt64 GetPeerId()
- {
- var ret = new UInt64();
- Methods.GetPeerId(MethodsPtr, ref ret);
- return ret;
- }
-
- /// <summary>
- /// Send pending network messages.
- /// </summary>
- public void Flush()
- {
- var res = Methods.Flush(MethodsPtr);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- /// <summary>
- /// Open a connection to a remote peer.
- /// </summary>
- public void OpenPeer(UInt64 peerId, string routeData)
- {
- var res = Methods.OpenPeer(MethodsPtr, peerId, routeData);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- /// <summary>
- /// Update the route data for a connected peer.
- /// </summary>
- public void UpdatePeer(UInt64 peerId, string routeData)
- {
- var res = Methods.UpdatePeer(MethodsPtr, peerId, routeData);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- /// <summary>
- /// Close the connection to a remote peer.
- /// </summary>
- public void ClosePeer(UInt64 peerId)
- {
- var res = Methods.ClosePeer(MethodsPtr, peerId);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- /// <summary>
- /// Open a message channel to a connected peer.
- /// </summary>
- public void OpenChannel(UInt64 peerId, byte channelId, bool reliable)
- {
- var res = Methods.OpenChannel(MethodsPtr, peerId, channelId, reliable);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- /// <summary>
- /// Close a message channel to a connected peer.
- /// </summary>
- public void CloseChannel(UInt64 peerId, byte channelId)
- {
- var res = Methods.CloseChannel(MethodsPtr, peerId, channelId);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- /// <summary>
- /// Send a message to a connected peer over an opened message channel.
- /// </summary>
- public void SendMessage(UInt64 peerId, byte channelId, byte[] data)
- {
- var res = Methods.SendMessage(MethodsPtr, peerId, channelId, data, data.Length);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnMessageImpl(IntPtr ptr, UInt64 peerId, byte channelId, IntPtr dataPtr, Int32 dataLen)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.NetworkManagerInstance.OnMessage != null)
- {
- byte[] data = new byte[dataLen];
- Marshal.Copy(dataPtr, data, 0, (int)dataLen);
- d.NetworkManagerInstance.OnMessage.Invoke(peerId, channelId, data);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnRouteUpdateImpl(IntPtr ptr, string routeData)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.NetworkManagerInstance.OnRouteUpdate != null)
- {
- d.NetworkManagerInstance.OnRouteUpdate.Invoke(routeData);
- }
- }
- }
-
- public partial class OverlayManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ToggleHandler(IntPtr ptr, bool locked);
-
- internal ToggleHandler OnToggle;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void IsEnabledMethod(IntPtr methodsPtr, ref bool enabled);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void IsLockedMethod(IntPtr methodsPtr, ref bool locked);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SetLockedCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SetLockedMethod(IntPtr methodsPtr, bool locked, IntPtr callbackData, SetLockedCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void OpenActivityInviteCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void OpenActivityInviteMethod(IntPtr methodsPtr, ActivityActionType type, IntPtr callbackData, OpenActivityInviteCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void OpenGuildInviteCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void OpenGuildInviteMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string code, IntPtr callbackData, OpenGuildInviteCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void OpenVoiceSettingsCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void OpenVoiceSettingsMethod(IntPtr methodsPtr, IntPtr callbackData, OpenVoiceSettingsCallback callback);
-
- internal IsEnabledMethod IsEnabled;
-
- internal IsLockedMethod IsLocked;
-
- internal SetLockedMethod SetLocked;
-
- internal OpenActivityInviteMethod OpenActivityInvite;
-
- internal OpenGuildInviteMethod OpenGuildInvite;
-
- internal OpenVoiceSettingsMethod OpenVoiceSettings;
- }
-
- public delegate void SetLockedHandler(Result result);
-
- public delegate void OpenActivityInviteHandler(Result result);
-
- public delegate void OpenGuildInviteHandler(Result result);
-
- public delegate void OpenVoiceSettingsHandler(Result result);
-
- public delegate void ToggleHandler(bool locked);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event ToggleHandler OnToggle;
-
- internal OverlayManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnToggle = OnToggleImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- public bool IsEnabled()
- {
- var ret = new bool();
- Methods.IsEnabled(MethodsPtr, ref ret);
- return ret;
- }
-
- public bool IsLocked()
- {
- var ret = new bool();
- Methods.IsLocked(MethodsPtr, ref ret);
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void SetLockedCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- SetLockedHandler callback = (SetLockedHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void SetLocked(bool locked, SetLockedHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.SetLocked(MethodsPtr, locked, GCHandle.ToIntPtr(wrapped), SetLockedCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void OpenActivityInviteCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- OpenActivityInviteHandler callback = (OpenActivityInviteHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void OpenActivityInvite(ActivityActionType type, OpenActivityInviteHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.OpenActivityInvite(MethodsPtr, type, GCHandle.ToIntPtr(wrapped), OpenActivityInviteCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void OpenGuildInviteCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- OpenGuildInviteHandler callback = (OpenGuildInviteHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void OpenGuildInvite(string code, OpenGuildInviteHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.OpenGuildInvite(MethodsPtr, code, GCHandle.ToIntPtr(wrapped), OpenGuildInviteCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void OpenVoiceSettingsCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- OpenVoiceSettingsHandler callback = (OpenVoiceSettingsHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void OpenVoiceSettings(OpenVoiceSettingsHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.OpenVoiceSettings(MethodsPtr, GCHandle.ToIntPtr(wrapped), OpenVoiceSettingsCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void OnToggleImpl(IntPtr ptr, bool locked)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.OverlayManagerInstance.OnToggle != null)
- {
- d.OverlayManagerInstance.OnToggle.Invoke(locked);
- }
- }
- }
-
- public partial class StorageManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
-
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result ReadMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string name, byte[] data, Int32 dataLen, ref UInt32 read);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ReadAsyncCallback(IntPtr ptr, Result result, IntPtr dataPtr, Int32 dataLen);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ReadAsyncMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string name, IntPtr callbackData, ReadAsyncCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ReadAsyncPartialCallback(IntPtr ptr, Result result, IntPtr dataPtr, Int32 dataLen);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void ReadAsyncPartialMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string name, UInt64 offset, UInt64 length, IntPtr callbackData, ReadAsyncPartialCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result WriteMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string name, byte[] data, Int32 dataLen);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void WriteAsyncCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void WriteAsyncMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string name, byte[] data, Int32 dataLen, IntPtr callbackData, WriteAsyncCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result DeleteMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string name);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result ExistsMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string name, ref bool exists);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CountMethod(IntPtr methodsPtr, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result StatMethod(IntPtr methodsPtr, [MarshalAs(UnmanagedType.LPStr)]string name, ref FileStat stat);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result StatAtMethod(IntPtr methodsPtr, Int32 index, ref FileStat stat);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetPathMethod(IntPtr methodsPtr, StringBuilder path);
-
- internal ReadMethod Read;
-
- internal ReadAsyncMethod ReadAsync;
-
- internal ReadAsyncPartialMethod ReadAsyncPartial;
-
- internal WriteMethod Write;
-
- internal WriteAsyncMethod WriteAsync;
-
- internal DeleteMethod Delete;
-
- internal ExistsMethod Exists;
-
- internal CountMethod Count;
-
- internal StatMethod Stat;
-
- internal StatAtMethod StatAt;
-
- internal GetPathMethod GetPath;
- }
-
- public delegate void ReadAsyncHandler(Result result, byte[] data);
-
- public delegate void ReadAsyncPartialHandler(Result result, byte[] data);
-
- public delegate void WriteAsyncHandler(Result result);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- internal StorageManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- public UInt32 Read(string name, byte[] data)
- {
- var ret = new UInt32();
- var res = Methods.Read(MethodsPtr, name, data, data.Length, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void ReadAsyncCallbackImpl(IntPtr ptr, Result result, IntPtr dataPtr, Int32 dataLen)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- ReadAsyncHandler callback = (ReadAsyncHandler)h.Target;
- h.Free();
- byte[] data = new byte[dataLen];
- Marshal.Copy(dataPtr, data, 0, (int)dataLen);
- callback(result, data);
- }
-
- public void ReadAsync(string name, ReadAsyncHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.ReadAsync(MethodsPtr, name, GCHandle.ToIntPtr(wrapped), ReadAsyncCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void ReadAsyncPartialCallbackImpl(IntPtr ptr, Result result, IntPtr dataPtr, Int32 dataLen)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- ReadAsyncPartialHandler callback = (ReadAsyncPartialHandler)h.Target;
- h.Free();
- byte[] data = new byte[dataLen];
- Marshal.Copy(dataPtr, data, 0, (int)dataLen);
- callback(result, data);
- }
-
- public void ReadAsyncPartial(string name, UInt64 offset, UInt64 length, ReadAsyncPartialHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.ReadAsyncPartial(MethodsPtr, name, offset, length, GCHandle.ToIntPtr(wrapped), ReadAsyncPartialCallbackImpl);
- }
-
- public void Write(string name, byte[] data)
- {
- var res = Methods.Write(MethodsPtr, name, data, data.Length);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- [MonoPInvokeCallback]
- private static void WriteAsyncCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- WriteAsyncHandler callback = (WriteAsyncHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void WriteAsync(string name, byte[] data, WriteAsyncHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.WriteAsync(MethodsPtr, name, data, data.Length, GCHandle.ToIntPtr(wrapped), WriteAsyncCallbackImpl);
- }
-
- public void Delete(string name)
- {
- var res = Methods.Delete(MethodsPtr, name);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public bool Exists(string name)
- {
- var ret = new bool();
- var res = Methods.Exists(MethodsPtr, name, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public Int32 Count()
- {
- var ret = new Int32();
- Methods.Count(MethodsPtr, ref ret);
- return ret;
- }
-
- public FileStat Stat(string name)
- {
- var ret = new FileStat();
- var res = Methods.Stat(MethodsPtr, name, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public FileStat StatAt(Int32 index)
- {
- var ret = new FileStat();
- var res = Methods.StatAt(MethodsPtr, index, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public string GetPath()
- {
- var ret = new StringBuilder(4096);
- var res = Methods.GetPath(MethodsPtr, ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret.ToString();
- }
- }
-
- public partial class StoreManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void EntitlementCreateHandler(IntPtr ptr, ref Entitlement entitlement);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void EntitlementDeleteHandler(IntPtr ptr, ref Entitlement entitlement);
-
- internal EntitlementCreateHandler OnEntitlementCreate;
-
- internal EntitlementDeleteHandler OnEntitlementDelete;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FetchSkusCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FetchSkusMethod(IntPtr methodsPtr, IntPtr callbackData, FetchSkusCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CountSkusMethod(IntPtr methodsPtr, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetSkuMethod(IntPtr methodsPtr, Int64 skuId, ref Sku sku);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetSkuAtMethod(IntPtr methodsPtr, Int32 index, ref Sku sku);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FetchEntitlementsCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FetchEntitlementsMethod(IntPtr methodsPtr, IntPtr callbackData, FetchEntitlementsCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CountEntitlementsMethod(IntPtr methodsPtr, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetEntitlementMethod(IntPtr methodsPtr, Int64 entitlementId, ref Entitlement entitlement);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetEntitlementAtMethod(IntPtr methodsPtr, Int32 index, ref Entitlement entitlement);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result HasSkuEntitlementMethod(IntPtr methodsPtr, Int64 skuId, ref bool hasEntitlement);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void StartPurchaseCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void StartPurchaseMethod(IntPtr methodsPtr, Int64 skuId, IntPtr callbackData, StartPurchaseCallback callback);
-
- internal FetchSkusMethod FetchSkus;
-
- internal CountSkusMethod CountSkus;
-
- internal GetSkuMethod GetSku;
-
- internal GetSkuAtMethod GetSkuAt;
-
- internal FetchEntitlementsMethod FetchEntitlements;
-
- internal CountEntitlementsMethod CountEntitlements;
-
- internal GetEntitlementMethod GetEntitlement;
-
- internal GetEntitlementAtMethod GetEntitlementAt;
-
- internal HasSkuEntitlementMethod HasSkuEntitlement;
-
- internal StartPurchaseMethod StartPurchase;
- }
-
- public delegate void FetchSkusHandler(Result result);
-
- public delegate void FetchEntitlementsHandler(Result result);
-
- public delegate void StartPurchaseHandler(Result result);
-
- public delegate void EntitlementCreateHandler(ref Entitlement entitlement);
-
- public delegate void EntitlementDeleteHandler(ref Entitlement entitlement);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event EntitlementCreateHandler OnEntitlementCreate;
-
- public event EntitlementDeleteHandler OnEntitlementDelete;
-
- internal StoreManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnEntitlementCreate = OnEntitlementCreateImpl;
- events.OnEntitlementDelete = OnEntitlementDeleteImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- [MonoPInvokeCallback]
- private static void FetchSkusCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- FetchSkusHandler callback = (FetchSkusHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void FetchSkus(FetchSkusHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.FetchSkus(MethodsPtr, GCHandle.ToIntPtr(wrapped), FetchSkusCallbackImpl);
- }
-
- public Int32 CountSkus()
- {
- var ret = new Int32();
- Methods.CountSkus(MethodsPtr, ref ret);
- return ret;
- }
-
- public Sku GetSku(Int64 skuId)
- {
- var ret = new Sku();
- var res = Methods.GetSku(MethodsPtr, skuId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public Sku GetSkuAt(Int32 index)
- {
- var ret = new Sku();
- var res = Methods.GetSkuAt(MethodsPtr, index, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void FetchEntitlementsCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- FetchEntitlementsHandler callback = (FetchEntitlementsHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void FetchEntitlements(FetchEntitlementsHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.FetchEntitlements(MethodsPtr, GCHandle.ToIntPtr(wrapped), FetchEntitlementsCallbackImpl);
- }
-
- public Int32 CountEntitlements()
- {
- var ret = new Int32();
- Methods.CountEntitlements(MethodsPtr, ref ret);
- return ret;
- }
-
- public Entitlement GetEntitlement(Int64 entitlementId)
- {
- var ret = new Entitlement();
- var res = Methods.GetEntitlement(MethodsPtr, entitlementId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public Entitlement GetEntitlementAt(Int32 index)
- {
- var ret = new Entitlement();
- var res = Methods.GetEntitlementAt(MethodsPtr, index, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public bool HasSkuEntitlement(Int64 skuId)
- {
- var ret = new bool();
- var res = Methods.HasSkuEntitlement(MethodsPtr, skuId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void StartPurchaseCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- StartPurchaseHandler callback = (StartPurchaseHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void StartPurchase(Int64 skuId, StartPurchaseHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.StartPurchase(MethodsPtr, skuId, GCHandle.ToIntPtr(wrapped), StartPurchaseCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void OnEntitlementCreateImpl(IntPtr ptr, ref Entitlement entitlement)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.StoreManagerInstance.OnEntitlementCreate != null)
- {
- d.StoreManagerInstance.OnEntitlementCreate.Invoke(ref entitlement);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnEntitlementDeleteImpl(IntPtr ptr, ref Entitlement entitlement)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.StoreManagerInstance.OnEntitlementDelete != null)
- {
- d.StoreManagerInstance.OnEntitlementDelete.Invoke(ref entitlement);
- }
- }
- }
-
- public partial class VoiceManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SettingsUpdateHandler(IntPtr ptr);
-
- internal SettingsUpdateHandler OnSettingsUpdate;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetInputModeMethod(IntPtr methodsPtr, ref InputMode inputMode);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SetInputModeCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SetInputModeMethod(IntPtr methodsPtr, InputMode inputMode, IntPtr callbackData, SetInputModeCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result IsSelfMuteMethod(IntPtr methodsPtr, ref bool mute);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetSelfMuteMethod(IntPtr methodsPtr, bool mute);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result IsSelfDeafMethod(IntPtr methodsPtr, ref bool deaf);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetSelfDeafMethod(IntPtr methodsPtr, bool deaf);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result IsLocalMuteMethod(IntPtr methodsPtr, Int64 userId, ref bool mute);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetLocalMuteMethod(IntPtr methodsPtr, Int64 userId, bool mute);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetLocalVolumeMethod(IntPtr methodsPtr, Int64 userId, ref byte volume);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result SetLocalVolumeMethod(IntPtr methodsPtr, Int64 userId, byte volume);
-
- internal GetInputModeMethod GetInputMode;
-
- internal SetInputModeMethod SetInputMode;
-
- internal IsSelfMuteMethod IsSelfMute;
-
- internal SetSelfMuteMethod SetSelfMute;
-
- internal IsSelfDeafMethod IsSelfDeaf;
-
- internal SetSelfDeafMethod SetSelfDeaf;
-
- internal IsLocalMuteMethod IsLocalMute;
-
- internal SetLocalMuteMethod SetLocalMute;
-
- internal GetLocalVolumeMethod GetLocalVolume;
-
- internal SetLocalVolumeMethod SetLocalVolume;
- }
-
- public delegate void SetInputModeHandler(Result result);
-
- public delegate void SettingsUpdateHandler();
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event SettingsUpdateHandler OnSettingsUpdate;
-
- internal VoiceManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnSettingsUpdate = OnSettingsUpdateImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- public InputMode GetInputMode()
- {
- var ret = new InputMode();
- var res = Methods.GetInputMode(MethodsPtr, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void SetInputModeCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- SetInputModeHandler callback = (SetInputModeHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void SetInputMode(InputMode inputMode, SetInputModeHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.SetInputMode(MethodsPtr, inputMode, GCHandle.ToIntPtr(wrapped), SetInputModeCallbackImpl);
- }
-
- public bool IsSelfMute()
- {
- var ret = new bool();
- var res = Methods.IsSelfMute(MethodsPtr, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public void SetSelfMute(bool mute)
- {
- var res = Methods.SetSelfMute(MethodsPtr, mute);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public bool IsSelfDeaf()
- {
- var ret = new bool();
- var res = Methods.IsSelfDeaf(MethodsPtr, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public void SetSelfDeaf(bool deaf)
- {
- var res = Methods.SetSelfDeaf(MethodsPtr, deaf);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public bool IsLocalMute(Int64 userId)
- {
- var ret = new bool();
- var res = Methods.IsLocalMute(MethodsPtr, userId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public void SetLocalMute(Int64 userId, bool mute)
- {
- var res = Methods.SetLocalMute(MethodsPtr, userId, mute);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- public byte GetLocalVolume(Int64 userId)
- {
- var ret = new byte();
- var res = Methods.GetLocalVolume(MethodsPtr, userId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public void SetLocalVolume(Int64 userId, byte volume)
- {
- var res = Methods.SetLocalVolume(MethodsPtr, userId, volume);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- }
-
- [MonoPInvokeCallback]
- private static void OnSettingsUpdateImpl(IntPtr ptr)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.VoiceManagerInstance.OnSettingsUpdate != null)
- {
- d.VoiceManagerInstance.OnSettingsUpdate.Invoke();
- }
- }
- }
-
- public partial class AchievementManager
- {
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIEvents
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void UserAchievementUpdateHandler(IntPtr ptr, ref UserAchievement userAchievement);
-
- internal UserAchievementUpdateHandler OnUserAchievementUpdate;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal partial struct FFIMethods
- {
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SetUserAchievementCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void SetUserAchievementMethod(IntPtr methodsPtr, Int64 achievementId, byte percentComplete, IntPtr callbackData, SetUserAchievementCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FetchUserAchievementsCallback(IntPtr ptr, Result result);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void FetchUserAchievementsMethod(IntPtr methodsPtr, IntPtr callbackData, FetchUserAchievementsCallback callback);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CountUserAchievementsMethod(IntPtr methodsPtr, ref Int32 count);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetUserAchievementMethod(IntPtr methodsPtr, Int64 userAchievementId, ref UserAchievement userAchievement);
-
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate Result GetUserAchievementAtMethod(IntPtr methodsPtr, Int32 index, ref UserAchievement userAchievement);
-
- internal SetUserAchievementMethod SetUserAchievement;
-
- internal FetchUserAchievementsMethod FetchUserAchievements;
-
- internal CountUserAchievementsMethod CountUserAchievements;
-
- internal GetUserAchievementMethod GetUserAchievement;
-
- internal GetUserAchievementAtMethod GetUserAchievementAt;
- }
-
- public delegate void SetUserAchievementHandler(Result result);
-
- public delegate void FetchUserAchievementsHandler(Result result);
-
- public delegate void UserAchievementUpdateHandler(ref UserAchievement userAchievement);
-
- private IntPtr MethodsPtr;
-
- private Object MethodsStructure;
-
- private FFIMethods Methods
- {
- get
- {
- if (MethodsStructure == null)
- {
- MethodsStructure = Marshal.PtrToStructure(MethodsPtr, typeof(FFIMethods));
- }
- return (FFIMethods)MethodsStructure;
- }
-
- }
-
- public event UserAchievementUpdateHandler OnUserAchievementUpdate;
-
- internal AchievementManager(IntPtr ptr, IntPtr eventsPtr, ref FFIEvents events)
- {
- if (eventsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- InitEvents(eventsPtr, ref events);
- MethodsPtr = ptr;
- if (MethodsPtr == IntPtr.Zero) {
- throw new ResultException(Result.InternalError);
- }
- }
-
- private void InitEvents(IntPtr eventsPtr, ref FFIEvents events)
- {
- events.OnUserAchievementUpdate = OnUserAchievementUpdateImpl;
- Marshal.StructureToPtr(events, eventsPtr, false);
- }
-
- [MonoPInvokeCallback]
- private static void SetUserAchievementCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- SetUserAchievementHandler callback = (SetUserAchievementHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void SetUserAchievement(Int64 achievementId, byte percentComplete, SetUserAchievementHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.SetUserAchievement(MethodsPtr, achievementId, percentComplete, GCHandle.ToIntPtr(wrapped), SetUserAchievementCallbackImpl);
- }
-
- [MonoPInvokeCallback]
- private static void FetchUserAchievementsCallbackImpl(IntPtr ptr, Result result)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- FetchUserAchievementsHandler callback = (FetchUserAchievementsHandler)h.Target;
- h.Free();
- callback(result);
- }
-
- public void FetchUserAchievements(FetchUserAchievementsHandler callback)
- {
- GCHandle wrapped = GCHandle.Alloc(callback);
- Methods.FetchUserAchievements(MethodsPtr, GCHandle.ToIntPtr(wrapped), FetchUserAchievementsCallbackImpl);
- }
-
- public Int32 CountUserAchievements()
- {
- var ret = new Int32();
- Methods.CountUserAchievements(MethodsPtr, ref ret);
- return ret;
- }
-
- public UserAchievement GetUserAchievement(Int64 userAchievementId)
- {
- var ret = new UserAchievement();
- var res = Methods.GetUserAchievement(MethodsPtr, userAchievementId, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- public UserAchievement GetUserAchievementAt(Int32 index)
- {
- var ret = new UserAchievement();
- var res = Methods.GetUserAchievementAt(MethodsPtr, index, ref ret);
- if (res != Result.Ok)
- {
- throw new ResultException(res);
- }
- return ret;
- }
-
- [MonoPInvokeCallback]
- private static void OnUserAchievementUpdateImpl(IntPtr ptr, ref UserAchievement userAchievement)
- {
- GCHandle h = GCHandle.FromIntPtr(ptr);
- Discord d = (Discord)h.Target;
- if (d.AchievementManagerInstance.OnUserAchievementUpdate != null)
- {
- d.AchievementManagerInstance.OnUserAchievementUpdate.Invoke(ref userAchievement);
- }
- }
- }
- }
|