| | |
| | | PatchSubpackageGameJs(Path.Combine(miniRoot, ".dy-game-cache", "wasmcode", "game.js"), ".dy-game-cache/wasmcode"); |
| | | PatchGameJson(Path.Combine(miniRoot, "game.json")); |
| | | PatchLoadingImages(miniRoot); |
| | | EnsureXingwanSdkFile(miniRoot); |
| | | EnsureXingwanImport(Path.Combine(miniRoot, "game.js")); |
| | | Debug.Log("[DouyinBuildPostFixer] 构建产物 game.js/game.json 修复完成。"); |
| | | } |
| | | |
| | |
| | | CopyIfExists(Path.Combine(sourceDir, "logo.png"), Path.Combine(targetDir, "unity_logo.png")); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 星玩渠道 SDK:确保小游戏根目录存在 xingwanTTGameSdk.js。 |
| | | /// 构建工具可能未把 DefaultTemplate 下的自定义 js 拷进产物,这里兜底复制。 |
| | | /// </summary> |
| | | private static void EnsureXingwanSdkFile(string miniRoot) |
| | | { |
| | | const string fileName = "xingwanTTGameSdk.js"; |
| | | var target = Path.Combine(miniRoot, fileName); |
| | | if (File.Exists(target) && new FileInfo(target).Length > 0) |
| | | return; |
| | | |
| | | var source = Path.Combine(Application.dataPath, "Plugins", "ByteGame", |
| | | "com.bytedance.starksdk", "DefaultTemplate", fileName); |
| | | if (!File.Exists(source)) |
| | | { |
| | | Debug.LogWarning("[DouyinBuildPostFixer] 未找到星玩 SDK 源文件: " + source); |
| | | return; |
| | | } |
| | | |
| | | Directory.CreateDirectory(miniRoot); |
| | | File.Copy(source, target, true); |
| | | Debug.Log("[DouyinBuildPostFixer] 已复制星玩 SDK 到产物目录: " + fileName); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 星玩渠道 SDK:确保产物 game.js 已 import 并把 SDK 挂到全局作用域。 |
| | | /// 模板被还原/覆盖时自动补回,避免 jslib 找不到 SDK。 |
| | | /// </summary> |
| | | private static void EnsureXingwanImport(string gameJsPath) |
| | | { |
| | | if (!File.Exists(gameJsPath)) |
| | | return; |
| | | |
| | | string text = File.ReadAllText(gameJsPath); |
| | | if (text.Contains("xingwanTTGameSdk")) |
| | | return; |
| | | |
| | | const string block = |
| | | "// 星玩渠道 SDK 注入(构建后自动补回)\n" + |
| | | "try {\n" + |
| | | " const xingwanModule = require('./xingwanTTGameSdk.js');\n" + |
| | | " const xingwanTTGameSdk = (xingwanModule && xingwanModule.default) || xingwanModule;\n" + |
| | | " GameGlobal.xingwanTTGameSdk = xingwanTTGameSdk;\n" + |
| | | " if (typeof globalThis !== 'undefined') globalThis.xingwanTTGameSdk = xingwanTTGameSdk;\n" + |
| | | " if (typeof window !== 'undefined') window.xingwanTTGameSdk = xingwanTTGameSdk;\n" + |
| | | "} catch (e) {\n" + |
| | | " console.error('[Xingwan] 星玩 SDK 注入失败: ' + (e && e.message ? e.message : e));\n" + |
| | | "}\n"; |
| | | |
| | | File.WriteAllText(gameJsPath, block + text, Utf8NoBom); |
| | | Debug.Log("[DouyinBuildPostFixer] 已为 game.js 补回星玩 SDK 注入代码。"); |
| | | } |
| | | |
| | | private static void CopyIfExists(string source, string target) |
| | | { |
| | | if (!File.Exists(source)) |
| | |
| | | }; |
| | | GameGlobal.managerConfig = managerConfig; |
| | | |
| | | // 暴露星玩渠道 SDK 给 Unity 侧(XingwanTTGameSdk.jslib 从 GameGlobal / globalThis / window 取用)。 |
| | | // 源文件是 ES Module(export default),编译后 require 拿到的是 { default: sdk },这里做兼容取值。 |
| | | try { |
| | | const xingwanModule = require('./xingwanTTGameSdk.js'); |
| | | const xingwanTTGameSdk = (xingwanModule && xingwanModule.default) || xingwanModule; |
| | | GameGlobal.xingwanTTGameSdk = xingwanTTGameSdk; |
| | | if (typeof globalThis !== 'undefined') globalThis.xingwanTTGameSdk = xingwanTTGameSdk; |
| | | if (typeof window !== 'undefined') window.xingwanTTGameSdk = xingwanTTGameSdk; |
| | | } catch (e) { |
| | | console.error('[Xingwan] 星玩 SDK 注入失败: ' + (e && e.message ? e.message : e)); |
| | | } |
| | | |
| | | function reportGameEvent(eventName, data) { |
| | | try { |
| | | if (typeof tt !== 'undefined' && typeof tt.reportAnalytics === 'function') { |
| New file |
| | |
| | | // 三国大英雄(马赛克三国)-欢游抖小 - 三国大英雄(抖音小游戏) - 无 - 无 |
| | | const _0x3dc0=['request','https://api.xingwan001.com','accessKeyId','roleLevel','productId','length','clickId','windowHeight','Android','type','now','同步异常','ios','log','requestGamePayment','from','[Request] HTTP失败:','支付失败','subarray','versions','windowWidth','system :>> ','token','padStart','networkStatus','clientKeySecret','system','application/json','userInfo','未知系统,无法支付','请求失败: ','roleId','screenHeight','encode','join','charCodeAt','UNKNOWN','getStorageSync','tradeState','orderId','Unknown','code','push','isInit','error','prefix','payParams','floor','getSystemInfo','none','登录成功','model','msg','android','split','/api/v1/open/mini-game/login','clickid','Windows','toLowerCase','data','showToast','10046_5','zoneId','money','subpackageId','toString','业务错误','replace','getLaunchOptionsSync','test','channelId'];const _0x1b25=function(_0x3dc016,_0x1b252e){_0x3dc016=_0x3dc016-0x0;let _0x337d44=_0x3dc0[_0x3dc016];return _0x337d44;};function utf8ToBytes(_0x276a78){const _0x287c38=typeof TextEncoder!=='undefined'?new TextEncoder():null;if(_0x287c38)return _0x287c38[_0x1b25('0x21')](_0x276a78);const _0x2a3d80=[];for(let _0x30c839=0x0;_0x30c839<_0x276a78[_0x1b25('0x5')];_0x30c839++){let _0x503034=_0x276a78[_0x1b25('0x23')](_0x30c839);if(_0x503034<0x80)_0x2a3d80[_0x1b25('0x2a')](_0x503034);else if(_0x503034<0x800){_0x2a3d80[_0x1b25('0x2a')](0xc0|_0x503034>>0x6);_0x2a3d80[_0x1b25('0x2a')](0x80|_0x503034&0x3f);}else if(_0x503034<0xd800||_0x503034>0xdfff){_0x2a3d80['push'](0xe0|_0x503034>>0xc);_0x2a3d80[_0x1b25('0x2a')](0x80|_0x503034>>0x6&0x3f);_0x2a3d80['push'](0x80|_0x503034&0x3f);}else{_0x30c839++;_0x503034=0x10000+((_0x503034&0x3ff)<<0xa|_0x276a78[_0x1b25('0x23')](_0x30c839)&0x3ff);_0x2a3d80['push'](0xf0|_0x503034>>0x12);_0x2a3d80[_0x1b25('0x2a')](0x80|_0x503034>>0xc&0x3f);_0x2a3d80[_0x1b25('0x2a')](0x80|_0x503034>>0x6&0x3f);_0x2a3d80['push'](0x80|_0x503034&0x3f);}}return new Uint8Array(_0x2a3d80);}function rol64(_0x2dec55,_0x62995c,_0x172087){_0x172087%=0x40;if(_0x172087===0x0)return[_0x2dec55,_0x62995c];if(_0x172087<0x20){const _0x5db261=(_0x2dec55<<_0x172087|_0x62995c>>>0x20-_0x172087)>>>0x0;const _0x170080=(_0x62995c<<_0x172087|_0x2dec55>>>0x20-_0x172087)>>>0x0;return[_0x5db261,_0x170080];}else{const _0x17cf35=_0x172087-0x20;const _0x44a72d=(_0x62995c<<_0x17cf35|_0x2dec55>>>0x20-_0x17cf35)>>>0x0;const _0x21f42c=(_0x2dec55<<_0x17cf35|_0x62995c>>>0x20-_0x17cf35)>>>0x0;return[_0x44a72d,_0x21f42c];}}const RC=[[0x0,0x1],[0x0,0x8082],[0x80000000,0x808a],[0x80000000,0x80008000],[0x0,0x808b],[0x0,0x80000001],[0x80000000,0x80008081],[0x80000000,0x8009],[0x0,0x8a],[0x0,0x88],[0x0,0x80008009],[0x0,0x8000000a],[0x0,0x8000808b],[0x80000000,0x8b],[0x80000000,0x8089],[0x80000000,0x8003],[0x80000000,0x8002],[0x80000000,0x80],[0x0,0x800a],[0x80000000,0x8000000a],[0x80000000,0x80008081],[0x80000000,0x8080],[0x0,0x80000001],[0x80000000,0x80008008]];const r=[[0x0,0x24,0x3,0x29,0x12],[0x1,0x2c,0xa,0x2d,0x2],[0x3e,0x6,0x2b,0xf,0x3d],[0x1c,0x37,0x19,0x15,0x38],[0x1b,0x14,0x27,0x8,0xe]];function formRotate(_0x34f37c){return rol64(_0x34f37c[0x0],_0x34f37c[0x1],0x1);}function keccakF(_0xbe2b1e){for(let _0x1dcaa0=0x0;_0x1dcaa0<0x18;_0x1dcaa0++){const _0x394002=new Array(0x5);for(let _0x28ddf7=0x0;_0x28ddf7<0x5;_0x28ddf7++){let _0x4ac708=0x0,_0x1647fe=0x0;for(let _0x96e26=0x0;_0x96e26<0x5;_0x96e26++){const _0x36f8d5=_0xbe2b1e[_0x28ddf7+0x5*_0x96e26];_0x4ac708^=_0x36f8d5[0x0];_0x1647fe^=_0x36f8d5[0x1];}_0x394002[_0x28ddf7]=[_0x4ac708,_0x1647fe];}const _0x69d7cd=new Array(0x5);for(let _0x3f6458=0x0;_0x3f6458<0x5;_0x3f6458++){const [_0x5dcbc0,_0x4e4bf3]=_0x394002[(_0x3f6458+0x4)%0x5];const [_0x5e3dcb,_0x3ffd13]=formRotate(_0x394002[(_0x3f6458+0x1)%0x5]);_0x69d7cd[_0x3f6458]=[(_0x5dcbc0^_0x5e3dcb)>>>0x0,(_0x4e4bf3^_0x3ffd13)>>>0x0];}for(let _0x46ca7e=0x0;_0x46ca7e<0x19;_0x46ca7e++){_0xbe2b1e[_0x46ca7e][0x0]^=_0x69d7cd[_0x46ca7e%0x5][0x0];_0xbe2b1e[_0x46ca7e][0x1]^=_0x69d7cd[_0x46ca7e%0x5][0x1];}const _0x2af8ca=new Array(0x19);for(let _0x516272=0x0;_0x516272<0x5;_0x516272++){for(let _0x18e7ed=0x0;_0x18e7ed<0x5;_0x18e7ed++){const _0x4e6373=_0x516272+0x5*_0x18e7ed;const _0xf68ec4=r[_0x516272][_0x18e7ed];const [_0x2e06b0,_0x564b27]=_0xbe2b1e[_0x4e6373];const [_0x140a6e,_0x1ef2dc]=rol64(_0x2e06b0,_0x564b27,_0xf68ec4);const _0x593afd=_0x18e7ed;const _0x1b8941=(0x2*_0x516272+0x3*_0x18e7ed)%0x5;_0x2af8ca[_0x593afd+0x5*_0x1b8941]=[_0x140a6e,_0x1ef2dc];}}for(let _0xe25ae3=0x0;_0xe25ae3<0x5;_0xe25ae3++){for(let _0x2cec70=0x0;_0x2cec70<0x5;_0x2cec70++){const _0x320224=_0x2cec70+0x5*_0xe25ae3;const _0x4e4bb9=_0x2af8ca[_0x320224],_0x437de7=_0x2af8ca[(_0x2cec70+0x1)%0x5+0x5*_0xe25ae3],_0x2d5dec=_0x2af8ca[(_0x2cec70+0x2)%0x5+0x5*_0xe25ae3];_0xbe2b1e[_0x320224]=[(_0x4e4bb9[0x0]^~_0x437de7[0x0]&_0x2d5dec[0x0])>>>0x0,(_0x4e4bb9[0x1]^~_0x437de7[0x1]&_0x2d5dec[0x1])>>>0x0];}}_0xbe2b1e[0x0][0x0]^=RC[_0x1dcaa0][0x0];_0xbe2b1e[0x0][0x1]^=RC[_0x1dcaa0][0x1];}}function keccak(_0x35972a,_0xa14597,_0x2201b7){const _0x521603=Array[_0x1b25('0xf')]({'length':0x19},()=>[0x0,0x0]);let _0x4af350=0x0;while(_0x4af350+_0x35972a<=_0xa14597['length']){for(let _0xa1cd80=0x0;_0xa1cd80<_0x35972a/0x8;_0xa1cd80++){let _0x1aceb9=0x0,_0x3bf686=0x0;for(let _0xdf812f=0x0;_0xdf812f<0x4;_0xdf812f++)_0x1aceb9|=_0xa14597[_0x4af350+_0xa1cd80*0x8+_0xdf812f]<<0x8*_0xdf812f;for(let _0x210c64=0x0;_0x210c64<0x4;_0x210c64++)_0x3bf686|=_0xa14597[_0x4af350+_0xa1cd80*0x8+0x4+_0x210c64]<<0x8*_0x210c64;_0x521603[_0xa1cd80][0x0]^=_0x3bf686;_0x521603[_0xa1cd80][0x1]^=_0x1aceb9;}keccakF(_0x521603);_0x4af350+=_0x35972a;}const _0x50c021=new Uint8Array(_0x35972a);_0x50c021['set'](_0xa14597[_0x1b25('0x12')](_0x4af350));_0x50c021[_0xa14597[_0x1b25('0x5')]-_0x4af350]^=_0x2201b7;_0x50c021[_0x35972a-0x1]^=0x80;for(let _0x30bf3c=0x0;_0x30bf3c<_0x35972a/0x8;_0x30bf3c++){let _0x278968=0x0,_0x3e0ef4=0x0;for(let _0x2cfb35=0x0;_0x2cfb35<0x4;_0x2cfb35++)_0x278968|=_0x50c021[_0x30bf3c*0x8+_0x2cfb35]<<0x8*_0x2cfb35;for(let _0x22f7cf=0x0;_0x22f7cf<0x4;_0x22f7cf++)_0x3e0ef4|=_0x50c021[_0x30bf3c*0x8+0x4+_0x22f7cf]<<0x8*_0x22f7cf;_0x521603[_0x30bf3c][0x0]^=_0x3e0ef4;_0x521603[_0x30bf3c][0x1]^=_0x278968;}keccakF(_0x521603);const _0xcf141=new Uint8Array(0x20);let _0x4fa901=0x0;for(let _0x8c3e50=0x0;_0x8c3e50<_0x35972a/0x8&&_0x4fa901<0x20;_0x8c3e50++){const [_0x353f4b,_0x3e0a1a]=_0x521603[_0x8c3e50];for(let _0x2db2e9=0x0;_0x2db2e9<0x4&&_0x4fa901<0x20;_0x2db2e9++)_0xcf141[_0x4fa901++]=_0x3e0a1a>>>0x8*_0x2db2e9&0xff;for(let _0xd03861=0x0;_0xd03861<0x4&&_0x4fa901<0x20;_0xd03861++)_0xcf141[_0x4fa901++]=_0x353f4b>>>0x8*_0xd03861&0xff;}return _0xcf141;}function sha3_256(_0x4e8ac5){const _0x41bed2=typeof _0x4e8ac5==='string'?utf8ToBytes(_0x4e8ac5):_0x4e8ac5;const _0x42f02c=keccak(0x88,_0x41bed2,0x6);return Array['from'](_0x42f02c,_0x21234a=>_0x21234a[_0x1b25('0x41')](0x10)[_0x1b25('0x17')](0x2,'0'))[_0x1b25('0x22')]('');}let cachedDeviceInfo=null;const getDeviceInfo=()=>{if(cachedDeviceInfo){return Promise['resolve'](cachedDeviceInfo);}return new Promise(_0x13a8a4=>{tt[_0x1b25('0x30')]({'success':_0x348b44=>{const _0x26492e={..._0x348b44,'windowWidth':_0x348b44['screenWidth'],'windowHeight':_0x348b44[_0x1b25('0x20')]};tt['getNetworkType']({'success':_0xd222ca=>{_0x26492e['networkStatus']=_0xd222ca['networkType']['toUpperCase']();cachedDeviceInfo=_0x26492e;_0x13a8a4(_0x26492e);},'fail':()=>{_0x26492e[_0x1b25('0x18')]=_0x1b25('0x24');cachedDeviceInfo=_0x26492e;_0x13a8a4(_0x26492e);}});},'fail':()=>{const _0x2f465b={'system':_0x1b25('0x28'),'model':_0x1b25('0x28'),'windowWidth':0x177,'windowHeight':0x29b,'networkStatus':'UNKNOWN'};cachedDeviceInfo=_0x2f465b;_0x13a8a4(_0x2f465b);}});});};const IP='ww';const APILIST={'qa':{'prefix':'https://api-qa.xingwan001.com','versions':'ttgame1.0.1_debug'},'ww':{'prefix':_0x1b25('0x1'),'versions':'ttgame1.0.1_release'}};const sdkConfig={'gameId':10670,'subpackageId':'10670_1','channelId':'10670_1_ttgame','accessKeyId':'','clientKeySecret':'','userInfo':{},'token':'','pureSystem':'','isInit':![],'clickId':''};let query=tt[_0x1b25('0x44')]()['query'];if(query[_0x1b25('0x38')]||query['clickId']){tt['setStorageSync'](_0x1b25('0x6'),query['clickid']||query['clickId']);sdkConfig[_0x1b25('0x6')]=query['clickid']||query['clickId'];}if(query['channelId']){tt['setStorageSync'](_0x1b25('0x46'),query['channelId']);sdkConfig[_0x1b25('0x46')]=query[_0x1b25('0x46')];}function getUUID(){let _0x2bfa9c=tt['getStorageSync']('uuid');if(!_0x2bfa9c){const _0x255671=()=>((0x1+Math['random']())*0x10000|0x0)['toString'](0x10)['substring'](0x1);_0x2bfa9c=_0x255671()+_0x255671()+'-'+_0x255671()+'-'+_0x255671()+'-'+_0x255671()+'-'+_0x255671()+_0x255671()+_0x255671();tt['setStorageSync']('uuid',_0x2bfa9c);}return _0x2bfa9c;}function generateSignedOptions(_0x3c3214={}){const _0x5aa578=Math[_0x1b25('0x2f')](Date[_0x1b25('0xa')]()/0x3e8);const _0x50d2cd=tt[_0x1b25('0x25')](_0x1b25('0x6'))||sdkConfig['clickId'];const _0x43cc3f=tt[_0x1b25('0x25')]('channelId')||sdkConfig[_0x1b25('0x46')];const _0x2b3172=sdkConfig[_0x1b25('0x40')];const _0x37a65f=getUUID();const _0x4e590d={'timestamp':_0x5aa578,'channelId':_0x43cc3f,'clickId':_0x50d2cd,'subpackageId':_0x2b3172,'uuid':_0x37a65f,..._0x3c3214};const _0x50392d=JSON['stringify'](_0x4e590d);const _0x235db5=sha3_256(_0x50392d+sdkConfig[_0x1b25('0x19')]);const _0x553799=sdkConfig[_0x1b25('0x2')]+':'+_0x235db5;return{'body':_0x4e590d,'signature':_0x553799};}async function request(_0xfc1ad5,_0x2bb024={},_0x33903f='POST'){const {body,signature}=generateSignedOptions(_0x2bb024);const _0x1f2b91=await getDeviceInfo();let _0x450c0f='';if(/iOS/i[_0x1b25('0x45')](_0x1f2b91[_0x1b25('0x1a')])){_0x450c0f='iOS';}else if(/Android/i['test'](_0x1f2b91['system'])){_0x450c0f=_0x1b25('0x8');}else if(/Windows/i[_0x1b25('0x45')](_0x1f2b91[_0x1b25('0x1a')])){_0x450c0f=_0x1b25('0x39');}else{_0x450c0f=_0x1f2b91[_0x1b25('0x1a')][_0x1b25('0x36')](' ')[0x0]||'Unknown';}sdkConfig['pureSystem']=_0x450c0f;let _0x34ea9e=_0x450c0f+'/'+APILIST[IP][_0x1b25('0x13')]+'('+_0x1f2b91[_0x1b25('0x33')]+';'+_0x1f2b91[_0x1b25('0x1a')]+';'+_0x1f2b91[_0x1b25('0x14')]+'x'+_0x1f2b91[_0x1b25('0x7')]+';'+_0x1f2b91['networkStatus']+')';_0x34ea9e=_0x34ea9e[_0x1b25('0x43')](/./g,_0x241d88=>_0x241d88[_0x1b25('0x23')](0x0)<=0x7f?_0x241d88:'');return new Promise((_0x3faab2,_0x172176)=>{tt[_0x1b25('0x0')]({'url':APILIST[IP][_0x1b25('0x2d')]+_0xfc1ad5,'method':_0x33903f,'data':body,'header':{'content-type':_0x1b25('0x1b'),'Signature':signature,'X-Ua':_0x34ea9e,'Authorization':sdkConfig[_0x1b25('0x16')]},'success':_0x2a5553=>{if(_0x2a5553['statusCode']===0xc8){const _0x572194=_0x2a5553['data'];if(_0x572194['code']===0x4e20){_0x3faab2(_0x572194);}else{const _0x5d4b2e=_0x572194['msg']||_0x1b25('0x42');tt[_0x1b25('0x3c')]({'title':_0x5d4b2e,'icon':_0x1b25('0x31'),'duration':0x7d0});_0x172176(new Error(_0x5d4b2e));}}else{console['error'](_0x1b25('0x10'),_0x2a5553);_0x172176(new Error(_0x1b25('0x1e')+_0x2a5553['statusCode']));}},'fail':_0x89cd4c=>{console[_0x1b25('0x2c')]('[Request] 网络错误:',_0x89cd4c);_0x172176(_0x89cd4c);}});});}async function polling(_0x38472f){const _0xb52ea8=[0x3e8,0x7d0,0x7d0,0x1388,0x1388];try{for(let _0x5ceef1=0x0;_0x5ceef1<_0xb52ea8['length'];_0x5ceef1++){const _0x2c47c5=await request('/api/v1/channel/get-order-state',{'orderId':_0x38472f},'GET');if(_0x2c47c5['code']!==0x4e20){return;}if(_0x2c47c5[_0x1b25('0x3b')]['tradeState']===0x1){return;}else if(_0x2c47c5[_0x1b25('0x3b')][_0x1b25('0x26')]===0x2){return;}await new Promise(_0xe3922b=>setTimeout(_0xe3922b,_0xb52ea8[_0x5ceef1]));}}catch(_0x189c28){}}const xingwanTTGameSdk={async 'initGame'(_0x174af0){sdkConfig[_0x1b25('0x2')]=_0x174af0[_0x1b25('0x2')];sdkConfig[_0x1b25('0x19')]=_0x174af0[_0x1b25('0x19')];try{const _0x34753e=await request('/api/v1/open/sdk-init');if(_0x34753e[_0x1b25('0x29')]===0x4e20){sdkConfig['isInit']=!![];}return{'status':_0x34753e['code']===0x4e20?'初始化成功':_0x34753e['msg'],'statusCode':_0x34753e[_0x1b25('0x29')]};}catch(_0x59ee66){sdkConfig[_0x1b25('0x2b')]=![];return{'status':'初始化失败','statusCode':-0x1,'error':_0x59ee66};}},async 'login'(){if(!sdkConfig['isInit']){return{'statusCode':0x1,'status':'请先初始化'};}return new Promise((_0x4177ee,_0x4987ad)=>{tt['login']({'success':async _0x61ae99=>{try{const _0x3566b2=await request(_0x1b25('0x37'),{'code':_0x61ae99['code']});if(_0x3566b2[_0x1b25('0x3b')]){sdkConfig[_0x1b25('0x1c')]=_0x3566b2['data'];sdkConfig['token']=_0x3566b2[_0x1b25('0x3b')][_0x1b25('0x16')];_0x4177ee({'status':_0x1b25('0x32'),'statusCode':0x4e20,'data':_0x3566b2['data']});}else{_0x4177ee({'status':_0x3566b2['msg']||'登录失败','statusCode':_0x3566b2['code']||-0x1});}}catch(_0x1b52b3){_0x4987ad(_0x1b52b3);}},'fail':_0x33f6a0=>{_0x4987ad({'status':'tt.login 失败','statusCode':-0x1,'error':_0x33f6a0});}});});},async 'syncData'(_0x5e4abd){try{_0x5e4abd[_0x1b25('0x9')]=Number(_0x5e4abd['type']);_0x5e4abd['roleId']=_0x5e4abd[_0x1b25('0x1f')][_0x1b25('0x41')]();_0x5e4abd[_0x1b25('0x3')]=_0x5e4abd[_0x1b25('0x3')][_0x1b25('0x41')]();_0x5e4abd[_0x1b25('0x3e')]=_0x5e4abd[_0x1b25('0x3e')]['toString']();const _0x101c64=await request('/api/v1/sync-role',_0x5e4abd);if(_0x101c64['code']===0x4e20){return{'status':'同步成功','statusCode':_0x101c64[_0x1b25('0x29')],'data':_0x101c64[_0x1b25('0x3b')]};}else{return{'status':_0x101c64['msg']||'同步失败','statusCode':_0x101c64[_0x1b25('0x29')]};}}catch(_0x24d5d9){return{'status':_0x1b25('0xb'),'statusCode':-0x1,'error':_0x24d5d9};}},async 'pay'(_0x398f03){try{_0x398f03['productId']=_0x398f03[_0x1b25('0x4')]['toString']();_0x398f03[_0x1b25('0x1f')]=_0x398f03[_0x1b25('0x1f')][_0x1b25('0x41')]();_0x398f03[_0x1b25('0x3')]=_0x398f03['roleLevel']['toString']();_0x398f03['zoneId']=_0x398f03['zoneId']['toString']();_0x398f03[_0x1b25('0x3f')]=Number(_0x398f03['money']);const _0x5ecf1c=await request('/api/v1/mini-game/create-order',_0x398f03);if(_0x5ecf1c['code']!==0x4e20){tt['showToast']({'title':_0x5ecf1c[_0x1b25('0x34')]||'支付信息获取失败','icon':_0x1b25('0x31')});return{'status':_0x5ecf1c['msg'],'statusCode':_0x5ecf1c['code']};}const _0x3364bc=_0x5ecf1c[_0x1b25('0x3b')];const _0x161332=_0x3364bc[_0x1b25('0x2e')];const _0x2331df=String(sdkConfig['pureSystem'])[_0x1b25('0x3a')]();console[_0x1b25('0xd')](_0x1b25('0x15'),_0x2331df);return new Promise((_0x351938,_0x231287)=>{if(_0x2331df===_0x1b25('0xc')){tt['openAwemeCustomerService']({..._0x161332,'success':_0x306530=>{polling(_0x3364bc[_0x1b25('0x27')]);_0x351938({'status':'支付成功','statusCode':0x4e20,'data':_0x3364bc,'result':_0x306530});},'fail':_0xd2ae2d=>{_0x351938({'status':_0x1b25('0x11'),'statusCode':-0x1,'error':_0xd2ae2d});},'complete':_0x1964f6=>{}});}else if(_0x2331df===_0x1b25('0x35')||_0x2331df==='windows'||_0x2331df==='openharmony'){tt[_0x1b25('0xe')]({..._0x161332,'success':_0x27f43b=>{polling(_0x3364bc[_0x1b25('0x27')]);_0x351938({'status':'支付成功','statusCode':0x4e20,'data':_0x3364bc,'result':_0x27f43b});},'fail':_0x1e40e9=>{_0x351938({'status':'支付失败','statusCode':-0x1,'error':_0x1e40e9});}});}else{_0x351938({'status':_0x1b25('0x1d'),'statusCode':-0x1});}});}catch(_0x332fb1){return{'status':'支付异常','statusCode':-0x2,'error':_0x332fb1};}}};export default xingwanTTGameSdk; |
| | | |
| New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 27140c47d2a4ea347a853042d89010e7 |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
| New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: eeff02f49bea01a45a8a000aa386d306 |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
| New file |
| | |
| | | /** |
| | | * XingwanTTGameSdk.jslib — 星玩(xingwan001)抖音小游戏 SDK 的 C# <-> JS 桥接层。 |
| | | * |
| | | * 依赖:小游戏根目录下的 xingwanTTGameSdk.js(由 DefaultTemplate 拷贝,文档 |
| | | * https://docs.xingwan001.com/client/ttDoc.html 提供的 SDK 文件)。 |
| | | * 该文件是 ES Module(export default),无法直接被 jslib require,因此由 game.js 顶部 |
| | | * import 后挂到 GameGlobal / globalThis / window,本层统一从全局作用域取用; |
| | | * 若全局未挂载,则退化为 require('./xingwanTTGameSdk.js') 兜底。 |
| | | * |
| | | * 对外暴露给 C#(DllImport("__Internal"))的函数: |
| | | * Xingwan_Init(accessKeyId, clientKeySecret, cb) |
| | | * Xingwan_Login(cb) |
| | | * Xingwan_Pay(payJson, cb) |
| | | * Xingwan_SyncData(syncJson, cb) |
| | | * 回调统一回传一个 JSON 字符串:{ statusCode, status, data, raw },statusCode==20000 表示成功。 |
| | | */ |
| | | var XingwanTTGameSdkLibrary = { |
| | | |
| | | $XingwanTT: { |
| | | // 兼容 Unity 2019(Pointer_stringify)与新版本(UTF8ToString) |
| | | Str: function (ptr) { |
| | | if (typeof UTF8ToString !== "undefined") return UTF8ToString(ptr); |
| | | return Pointer_stringify(ptr); |
| | | }, |
| | | |
| | | Resolve: function () { |
| | | var holder = null; |
| | | if (typeof GameGlobal !== "undefined") holder = GameGlobal; |
| | | else if (typeof globalThis !== "undefined") holder = globalThis; |
| | | else if (typeof window !== "undefined") holder = window; |
| | | |
| | | if (holder && holder.xingwanTTGameSdk && typeof holder.xingwanTTGameSdk.initGame === "function") { |
| | | return holder.xingwanTTGameSdk; |
| | | } |
| | | |
| | | try { |
| | | var mod = require('./xingwanTTGameSdk.js'); |
| | | var sdk = mod && (mod.default || mod); |
| | | if (sdk && typeof sdk.initGame === "function") { |
| | | if (holder) holder.xingwanTTGameSdk = sdk; |
| | | return sdk; |
| | | } |
| | | } catch (e) { |
| | | console.error('[Xingwan] xingwanTTGameSdk.js 加载失败: ' + (e && e.message ? e.message : e)); |
| | | } |
| | | |
| | | return null; |
| | | }, |
| | | |
| | | Parse: function (json) { |
| | | if (!json) return {}; |
| | | try { return JSON.parse(json); } catch (e) { return {}; } |
| | | }, |
| | | |
| | | // 把 SDK 的 { status, statusCode, data } 统一成回传给 C# 的结构 |
| | | Result: function (res) { |
| | | res = res || {}; |
| | | var code = res.statusCode; |
| | | if (typeof code !== "number") code = -1; |
| | | var status = typeof res.status === "string" ? res.status : (res.msg ? String(res.msg) : ""); |
| | | var raw = ""; |
| | | try { raw = JSON.stringify(res); } catch (e) { raw = "{}"; } |
| | | return { statusCode: code, status: status, data: res.data || null, raw: raw }; |
| | | }, |
| | | |
| | | Fail: function (message, code) { |
| | | return { statusCode: typeof code === "number" ? code : -1, status: String(message), data: null, raw: "{}" }; |
| | | }, |
| | | |
| | | // 回调 C#:字符串过堆,dynCall('vi', cb, [ptr]) |
| | | Emit: function (cb, payload) { |
| | | if (!cb) return; |
| | | var str = ""; |
| | | try { |
| | | str = JSON.stringify(payload); |
| | | } catch (e) { |
| | | str = JSON.stringify({ statusCode: -3, status: "回调序列化失败", data: null, raw: "{}" }); |
| | | } |
| | | var size = lengthBytesUTF8(str) + 1; |
| | | var ptr = _malloc(size); |
| | | stringToUTF8(str, ptr, size); |
| | | try { |
| | | if (typeof Runtime !== "undefined" && Runtime.dynCall) Runtime.dynCall('vi', cb, [ptr]); |
| | | else dynCall('vi', cb, [ptr]); |
| | | } catch (e) { |
| | | console.error('[Xingwan] 回调 C# 异常: ' + (e && e.stack ? e.stack : e)); |
| | | } finally { |
| | | _free(ptr); |
| | | } |
| | | } |
| | | }, |
| | | |
| | | // ------------------------------------------------------------------ |
| | | // 初始化(必须在 login / pay 之前调用) |
| | | // ------------------------------------------------------------------ |
| | | Xingwan_Init: function (accessKeyIdPtr, clientKeySecretPtr, cb) { |
| | | var sdk = XingwanTT.Resolve(); |
| | | if (!sdk) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("xingwanTTGameSdk 未注入,请检查 game.js 是否已 import", -2)); |
| | | return; |
| | | } |
| | | try { |
| | | sdk.initGame({ |
| | | accessKeyId: XingwanTT.Str(accessKeyIdPtr) || "", |
| | | clientKeySecret: XingwanTT.Str(clientKeySecretPtr) || "" |
| | | }).then(function (res) { |
| | | XingwanTT.Emit(cb, XingwanTT.Result(res)); |
| | | })['catch'](function (err) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("initGame 异常: " + (err && err.message ? err.message : err), -1)); |
| | | }); |
| | | } catch (e) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("initGame 调用异常: " + (e && e.message ? e.message : e), -1)); |
| | | } |
| | | }, |
| | | |
| | | // ------------------------------------------------------------------ |
| | | // 登录:内部走 tt.login + 星玩服务端换取 token / userId |
| | | // ------------------------------------------------------------------ |
| | | Xingwan_Login: function (cb) { |
| | | var sdk = XingwanTT.Resolve(); |
| | | if (!sdk) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("xingwanTTGameSdk 未注入,请检查 game.js 是否已 import", -2)); |
| | | return; |
| | | } |
| | | try { |
| | | sdk.login().then(function (res) { |
| | | XingwanTT.Emit(cb, XingwanTT.Result(res)); |
| | | })['catch'](function (err) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("login 异常: " + (err && err.message ? err.message : err), -1)); |
| | | }); |
| | | } catch (e) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("login 调用异常: " + (e && e.message ? e.message : e), -1)); |
| | | } |
| | | }, |
| | | |
| | | // ------------------------------------------------------------------ |
| | | // 支付:payJson 为 XingwanTTSDK 组装的订单参数 |
| | | // ------------------------------------------------------------------ |
| | | Xingwan_Pay: function (payJsonPtr, cb) { |
| | | var sdk = XingwanTT.Resolve(); |
| | | if (!sdk) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("xingwanTTGameSdk 未注入,请检查 game.js 是否已 import", -2)); |
| | | return; |
| | | } |
| | | var payParams = XingwanTT.Parse(XingwanTT.Str(payJsonPtr)); |
| | | try { |
| | | sdk.pay(payParams).then(function (res) { |
| | | XingwanTT.Emit(cb, XingwanTT.Result(res)); |
| | | })['catch'](function (err) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("pay 异常: " + (err && err.message ? err.message : err), -1)); |
| | | }); |
| | | } catch (e) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("pay 调用异常: " + (e && e.message ? e.message : e), -1)); |
| | | } |
| | | }, |
| | | |
| | | // ------------------------------------------------------------------ |
| | | // 角色数据同步:1-创建角色 2-进入游戏 3-等级提升 4-退出游戏 |
| | | // ------------------------------------------------------------------ |
| | | Xingwan_SyncData: function (syncJsonPtr, cb) { |
| | | var sdk = XingwanTT.Resolve(); |
| | | if (!sdk) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("xingwanTTGameSdk 未注入,请检查 game.js 是否已 import", -2)); |
| | | return; |
| | | } |
| | | var syncParams = XingwanTT.Parse(XingwanTT.Str(syncJsonPtr)); |
| | | try { |
| | | sdk.syncData(syncParams).then(function (res) { |
| | | XingwanTT.Emit(cb, XingwanTT.Result(res)); |
| | | })['catch'](function (err) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("syncData 异常: " + (err && err.message ? err.message : err), -1)); |
| | | }); |
| | | } catch (e) { |
| | | XingwanTT.Emit(cb, XingwanTT.Fail("syncData 调用异常: " + (e && e.message ? e.message : e), -1)); |
| | | } |
| | | }, |
| | | |
| | | // ------------------------------------------------------------------ |
| | | // 供 C# 侧探测 JS 层是否可用(0/1) |
| | | // ------------------------------------------------------------------ |
| | | Xingwan_IsReady: function () { |
| | | return XingwanTT.Resolve() ? 1 : 0; |
| | | } |
| | | }; |
| | | |
| | | autoAddDeps(XingwanTTGameSdkLibrary, '$XingwanTT'); |
| | | mergeInto(LibraryManager.library, XingwanTTGameSdkLibrary); |
| New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 384761485556c3c4db945c749bf34662 |
| | | PluginImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | iconMap: {} |
| | | executionOrder: {} |
| | | defineConstraints: [] |
| | | isPreloaded: 0 |
| | | isOverridable: 0 |
| | | isExplicitlyReferenced: 0 |
| | | validateReferences: 1 |
| | | platformData: |
| | | - first: |
| | | Any: |
| | | second: |
| | | enabled: 0 |
| | | settings: {} |
| | | - first: |
| | | Editor: Editor |
| | | second: |
| | | enabled: 0 |
| | | settings: |
| | | DefaultValueInitialized: true |
| | | - first: |
| | | WebGL: WebGL |
| | | second: |
| | | enabled: 1 |
| | | settings: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |