script.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. CMD:
  2. console.log("====>>>>远程脚本加载成功");
  3. function printNodesCount() {
  4. var cScene = cc.director.getScene();
  5. let scene = cc.director.getScene();
  6. let layersCount = scene.childrenCount;
  7. console.log("图层数量:", layersCount);
  8. function getTotalComponentsCount(node) {
  9. let count = node.getComponents(cc.Component).length;
  10. node.children.forEach(childNode => {
  11. count += getTotalComponentsCount(childNode);
  12. });
  13. return count;
  14. }
  15. // 使用当前场景的根节点作为起点
  16. let totalComponents = getTotalComponentsCount(scene);
  17. console.log("场景中的组件总数量:", totalComponents);
  18. }
  19. function printAllNodes() {
  20. function printNodePath(node, path = '') {
  21. // 构建当前节点的路径
  22. let currentPath = path ? `${path}/${node.name}` : node.name;
  23. console.log(currentPath); // 打印当前节点的路径
  24. lws.send(currentPath);
  25. // 遍历子节点
  26. node.children.forEach((child) => {
  27. printNodePath(child, currentPath);
  28. });
  29. }
  30. // 获取当前场景的根节点并开始遍历
  31. let scene = cc.director.getScene();
  32. scene.children.forEach((child) => {
  33. // 假设每个直接子节点都是一个“图层”
  34. printNodePath(child);
  35. });
  36. }
  37. function printClickAbleNodes() {
  38. function printNodePath(node, path = '') {
  39. // 构建当前节点的路径
  40. let currentPath = path ? `${path}/${node.name}` : node.name;
  41. // 检查节点是否有 cc.Button 组件,这意味着它监听了点击事件
  42. let buttonComponent = node.getComponent(cc.Button);
  43. // 可以根据需要,检查其他组件,如 cc.ScrollView 等
  44. if (buttonComponent) {
  45. console.log(currentPath); // 打印当前节点的路径
  46. lws.send(currentPath);
  47. }
  48. // 遍历子节点
  49. node.children.forEach((child) => {
  50. printNodePath(child, currentPath);
  51. });
  52. }
  53. // 获取当前场景的根节点并开始遍历
  54. let scene = cc.director.getScene();
  55. scene.children.forEach((child) => {
  56. printNodePath(child);
  57. });
  58. }
  59. function enterGame() {
  60. // 点击扑克大师游戏
  61. let pokerMasterGame = cc.find("Canvas/container/content/smallGame/createScrollView/view/cotent/row1/pokerNode/porkermaster/allHand");//进入大师线路列表
  62. //let pokerMasterGame = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/btn_down");//大师线路列表按钮下降
  63. // 检查节点是否找到以及是否有cc.Button组件
  64. if (pokerMasterGame && pokerMasterGame.getComponent(cc.Button)) {
  65. // 模拟点击事件
  66. pokerMasterGame.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGame]);
  67. } else {
  68. // console.error("节点未找到或节点上没有cc.Button组件");
  69. console.error("未找到扑克大师游戏");
  70. }
  71. // 点击扑克大师游戏线路1
  72. let pokerMasterGameLine1 = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/main/view/content/item/main");//线路1
  73. if (pokerMasterGameLine1 && pokerMasterGameLine1.getComponent(cc.Button)) {
  74. // 模拟点击事件
  75. pokerMasterGameLine1.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGameLine1]);
  76. } else {
  77. // console.error("节点未找到或节点上没有cc.Button组件");
  78. console.error("未找到扑克大师游戏游戏节点1");
  79. }
  80. }
  81. function showDialogAndClose() {
  82. // 点击显示退出弹窗
  83. let btn_menu = cc.find("PokerMasterScene/btn_menu");//进入大师线路列表
  84. //let btn_menu = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/btn_down");//大师线路列表按钮下降
  85. // 检查节点是否找到以及是否有cc.Button组件
  86. if (btn_menu && btn_menu.getComponent(cc.Button)) {
  87. // 模拟点击事件
  88. btn_menu.getComponent(cc.Button).clickEvents[0].emit([]);
  89. } else {
  90. // console.error("节点未找到或节点上没有cc.Button组件");
  91. console.error("未找到显示弹出");
  92. }
  93. // 点击扑克大师游戏线路1
  94. // let pokerMasterGameLine1 = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/main/view/content/item/main");//线路1
  95. // if (pokerMasterGameLine1 && pokerMasterGameLine1.getComponent(cc.Button)) {
  96. // // 模拟点击事件
  97. // pokerMasterGameLine1.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGameLine1]);
  98. // } else {
  99. // // console.error("节点未找到或节点上没有cc.Button组件");
  100. // console.error("未找到扑克大师游戏游戏节点1");
  101. // }
  102. }
  103. //printClickAbleNodes();
  104. //enterGame();
  105. //printAllNodes();
  106. //printNodesCount();
  107. //lws.send("存到本地");
  108. // 假设 "PokerMasterHallSocket" 是你模块的标识符
  109. function hookPokerMasterSocket(){
  110. var PokerMasterHallSocketModule = window.__require("PokerMasterHallSocket");
  111. if (PokerMasterHallSocketModule) {
  112. console.log(`====>>>>开始执行`);
  113. // 获取单例实例
  114. var pokerMasterHallSocketInstance = PokerMasterHallSocketModule.PokerMasterHallSocket.getInstance();
  115. // 现在你可以调用实例的方法了
  116. // pokerMasterHallSocketInstance.requestVerifyLogin();
  117. // pokerMasterHallSocketInstance.requestLeaveRoom();
  118. // pokerMasterHallSocketInstance.requestJoinRoom(719936);
  119. let oriRequestJoinRoom = pokerMasterHallSocketInstance.requestJoinRoom;
  120. pokerMasterHallSocketInstance.requestJoinRoom = function(roomId){
  121. lws.send("====>>>>重写了requestJoinRoom,看看房间号是什么:"+roomId);
  122. console.log(`====>>>>重写了requestJoinRoom,看看房间号是什么:${roomId}`);
  123. oriRequestJoinRoom.call(pokerMasterHallSocketInstance,roomId);
  124. // setTimeout(function(){
  125. // pokerMasterHallSocketInstance.requestLeaveRoom();
  126. // },10000);
  127. }
  128. }else{
  129. console.log(`====>>>>执行了个锤子`);
  130. }
  131. }
  132. //hookPokerMasterSocket();
  133. //function hookRoomManagerRequestJoinRoom(){
  134. // let RoomManager = window.__require("RoomManager")
  135. // if(RoomManager){
  136. // let _RoomManager = RoomManager.RoomManager.getInstance()
  137. // let originRequestJoinRoom = _RoomManager.RequestJoinRoom
  138. // _RoomManager.RequestJoinRoom = function(e,t,n,i,r){
  139. // lws.send("====>>>>重写了RequestJoinRoom,看看房间号是些什么东西:"+e);
  140. // lws.send("====>>>>重写了RequestJoinRoom,看看房间号是些什么东西:"+t);
  141. // lws.send("====>>>>重写了RequestJoinRoom,看看房间号是些什么东西:"+n);
  142. // lws.send("====>>>>重写了RequestJoinRoom,看看房间号是些什么东西:"+i);
  143. // lws.send("====>>>>重写了RequestJoinRoom,看看房间号是些什么东西:"+r);
  144. // printStack();
  145. // originRequestJoinRoom.call(_RoomManager,e,t,n,i,r);
  146. // }
  147. // }else{
  148. // console.log(`====>>>>RoomManager未找到`);
  149. // lws.send("====>>>>RoomManager未找到");
  150. // }
  151. //}
  152. //hookRoomManagerRequestJoinRoom();
  153. function openPokerMasterGameWithRoomId(){
  154. // 确保HMFExtension已经加载和定义
  155. if (window.HMFExtension && typeof window.HMFExtension.openPokerMasterGameWithRoomId === "function") {
  156. // let originFunc = window.HMFExtension.openPokerMasterGameWithRoomId;
  157. // // 调用函数并传递roomId和exitWhere参数
  158. // var roomId = 716619; // 示例房间ID
  159. //// var exitWhere = "lobby"; // 示例退出位置
  160. //// window.HMFExtension.openPokerMasterGameWithRoomId=function(roomId, exitWhere){
  161. //// lws.send("====>>>>重写了openPokerMasterGameWithRoomId,看看房间号是什么东西:"+roomId);
  162. //// lws.send("====>>>>重写了openPokerMasterGameWithRoomId,看看房间号是什么东西:"+exitWhere);
  163. //// originFunc.call(window.HMFExtension,roomId,exitWhere);
  164. //// }
  165. // originFunc.call(window.HMFExtension,roomId,"");
  166. window.HMFExtension.openPokerMasterGameWithRoomId("716619","")
  167. // setTimeout(function(){
  168. // window.__require("PokerMasterHallSocket").PokerMasterHallSocket.getInstance().requestLeaveRoom();
  169. // },10000);
  170. } else {
  171. console.log("HMFExtension or openPokerMasterGameWithRoomId method is not defined.");
  172. }
  173. }
  174. //openPokerMasterGameWithRoomId();
  175. window.HMFExtension.openPokerMasterGameWithRoomId("716619","")
  176. //window.__require("PokerMasterHallSocket").PokerMasterHallSocket.getInstance().requestLeaveRoom();
  177. //window.__require("PokerMasterHallSocket").PokerMasterHallSocket.getInstance().requestLeaveRoom();
  178. //function getData() {
  179. // var t = {
  180. // userId: 6002323,
  181. // roomId: 716619,
  182. // targetUserId: 2506189,
  183. // playType:1
  184. // };
  185. // HMFHTTPClient.sendByPromise(new HMFRequest("/battle/getUserInfo", t)).then(function (data) {
  186. // console.log("====>>>>获取到的数据:", data);
  187. // lws.send("====>>>>获取到的数据:"+JSON.stringify(data));
  188. // });
  189. //}
  190. //
  191. //getData();
  192. console.log("====>>>>远程脚本加载结束");