280 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			280 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:BaseTool_Class.nut
 | |
| 路径:Base/_Tool/BaseTool_Class.nut
 | |
| 创建日期:2024-08-06	23:49
 | |
| 文件用途:基础工具类
 | |
| */
 | |
| //Json类
 | |
| class Json {
 | |
|     function Encode(Table) {
 | |
|         local Size = Table.len();
 | |
|         local Pos = 0;
 | |
|         local Str = "{";
 | |
|         foreach(Key, Value in Table) {
 | |
|             ++Pos;
 | |
|             Str += "\"";
 | |
|             Str += Key.tostring();
 | |
|             Str += "\"";
 | |
|             Str += ":";
 | |
|             if (typeof(Value) == "string") {
 | |
|                 Str += "\"";
 | |
|                 Str += Value;
 | |
|                 Str += "\"";
 | |
|             } else if (typeof(Value) == "table") {
 | |
|                 Str += Json.Encode(Value);
 | |
|             } else if (typeof(Value) == "array") {
 | |
|                 Str += "[";
 | |
|                 foreach(ArrObj in Value) {
 | |
|                     if (typeof(ArrObj) == "table") Str += Json.Encode(Value);
 | |
|                     else {
 | |
|                         Str += ArrObj;
 | |
|                         Str += ",";
 | |
|                     }
 | |
|                 }
 | |
|                 Str = Str.slice(0, Str.len() - 1);
 | |
|                 Str += "]";
 | |
|             } else Str += Value;
 | |
|             if (Pos != Size) Str += ",";
 | |
|         }
 | |
|         Str += "}";
 | |
|         return Str;
 | |
|     }
 | |
| 
 | |
|     function Decode(Str) {
 | |
|         // Str = L_sq_DecondeJson(Str);
 | |
|         // local Str = "local _M = " + Str + ";\n return _M;\n";
 | |
|         // local Func = compilestring(Str);
 | |
|         // return Func();
 | |
| 
 | |
|         local JsonObj = JSONParser();
 | |
|         return JsonObj.parse(Str);
 | |
|     }
 | |
| }
 | |
| //Key 键盘按键类
 | |
| class KeyPress {
 | |
|     function KeyDown(obj, KeyValue) {
 | |
|         local KeyEvent = obj.getVar(KeyValue.tostring()); //声明储存器
 | |
|         KeyEvent.clear_vector(); //清空储存器的向量位
 | |
|         if (sq_IsKeyDown(KeyValue, ENUM_SUBKEY_TYPE_ALL) && KeyEvent.getInt(0) == 0) {
 | |
|             KeyEvent.setInt(0, 1);
 | |
|             return true;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function KeyUp(obj, KeyValue) {
 | |
|         local KeyEvent = obj.getVar(KeyValue.tostring()); //声明储存器
 | |
|         if (sq_IsKeyUp(KeyValue, ENUM_SUBKEY_TYPE_ALL)) {
 | |
|             KeyEvent.setInt(0, 0);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function isKeyPress(KeyValue) {
 | |
|         local obj = sq_getMyCharacter();
 | |
|         if (KeyPress.KeyDown(obj, KeyValue)) {
 | |
|             return true;
 | |
|         }
 | |
|         KeyPress.KeyUp(obj, KeyValue);
 | |
|     }
 | |
| }
 | |
| //Key 键盘按键类
 | |
| class KeyPressNB {
 | |
|     function KeyDown(obj, KeyValue, VarKey) {
 | |
|         local KeyEvent = obj.getVar(VarKey); //声明储存器
 | |
|         KeyEvent.clear_vector(); //清空储存器的向量位
 | |
|         if (sq_IsKeyDown(KeyValue, ENUM_SUBKEY_TYPE_ALL) && KeyEvent.getInt(0) == 0) {
 | |
|             KeyEvent.setInt(0, 1);
 | |
|             return true;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function KeyUp(obj, KeyValue, VarKey) {
 | |
|         local KeyEvent = obj.getVar(VarKey); //声明储存器
 | |
|         if (sq_IsKeyUp(KeyValue, ENUM_SUBKEY_TYPE_ALL)) {
 | |
|             KeyEvent.setInt(0, 0);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function isKeyPress(KeyValue, VarKey) {
 | |
|         local obj = sq_getMyCharacter();
 | |
|         obj = sq_GetCNRDObjectToActiveObject(obj);
 | |
|         if (KeyPressNB.KeyDown(obj, KeyValue, VarKey)) {
 | |
|             return true;
 | |
|         }
 | |
|         KeyPressNB.KeyUp(obj, KeyValue, VarKey);
 | |
|     }
 | |
| }
 | |
| //基础工具类
 | |
| class Rindro_BaseToolClass {
 | |
| 
 | |
|     function SendPack(T) {
 | |
|         local str = Json.Encode(T);
 | |
|         L_sq_SendPackType(130);
 | |
|         L_sq_SendPackWChar(str);
 | |
|         L_sq_SendPack();
 | |
|     }
 | |
| 
 | |
|     function SendPackEx(T) {
 | |
|         local str = L_sq_EncondeJson(T);
 | |
|         L_sq_SendPackType(130);
 | |
|         L_sq_SendPackWChar(str);
 | |
|         L_sq_SendPack();
 | |
|     }
 | |
| 
 | |
|     //绘制简易静态Ani					// obj --  ani路径  --  X   --  Y  --  第几帧  --  ani名字
 | |
|     function T_DrawStayAni(obj, aniFileName, x, y, index, aniname) {
 | |
|         local SelectAni = obj.getVar().GetAnimationMap(aniname, aniFileName);
 | |
|         //sq_AnimationProc(SelectAni);
 | |
|         sq_DrawSpecificFrame(SelectAni, x, y, false, index, false, 1.0);
 | |
|         return SelectAni;
 | |
|     }
 | |
| 
 | |
|     //绘制简易静态Ani					// obj --  ani路径  --  X   --  Y  --  第几帧  --  ani名字
 | |
|     function T_DrawStayAniRate(obj, aniFileName, x, y, index, aniname, rate) {
 | |
|         local SelectAni = obj.getVar().GetAnimationMap(aniname, aniFileName);
 | |
|         SelectAni.setImageRateFromOriginal(rate, rate);
 | |
|         //sq_AnimationProc(SelectAni);
 | |
|         sq_DrawSpecificFrame(SelectAni, x, y, false, index, false, 1.0);
 | |
|         return SelectAni;
 | |
|     }
 | |
| 
 | |
|     //绘制简易动态Ani					// obj --  ani路径  --  X   --  Y  --  ani名字
 | |
|     function T_DrawDynamicAni(obj, aniFileName, x, y, aniname) {
 | |
|         local ani = obj.getVar().GetAnimationMap(aniname, aniFileName);
 | |
|         sq_AnimationProc(ani);
 | |
|         sq_drawCurrentFrame(ani, x, y, true);
 | |
|         return ani;
 | |
|     }
 | |
| 
 | |
| 
 | |
|     //初始化根表成员
 | |
|     function InitClass(Name) {
 | |
|         local RootTab = getroottable();
 | |
|         if (RootTab.rawin(Name) == true) {
 | |
|             RootTab.rawdelete(Name);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //获取交互Npc名称
 | |
|     function GetEachNpcId() {
 | |
|         local OneAddress = L_sq_RA(0x1ADE0E0);
 | |
|         if (OneAddress) {
 | |
|             local TowAddress = L_sq_RA(OneAddress + 8);
 | |
|             if (TowAddress) {
 | |
|                 local Id = L_sq_RA(TowAddress + 0x210);
 | |
|                 return Id;
 | |
|             }
 | |
|         }
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
| }
 | |
| //获取文字绘制长度
 | |
| class LenheartTextClass {
 | |
| 
 | |
|     function GetStringLength(str) {
 | |
|         return L_sq_GetStringDrawLength(str);
 | |
|     }
 | |
| 
 | |
| }
 | |
| class MemoryTool {
 | |
|     //给指定地址写入字节数组
 | |
|     function WirteByteArr(Address, ByteArr) {
 | |
|         for (local i = 0; i< ByteArr.len(); i++) {
 | |
|             L_sq_WAB(Address + i, ByteArr[i]);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //解密读取内存地址的数据
 | |
|     function DecodeMemoryData(Address) {
 | |
|         local nEax, nEcx8, nEsi, nEdx, nTmp;
 | |
|         nEax = L_sq_RA(Address);
 | |
|         if (nEax == -1) return nEax;
 | |
|         nEcx8 = L_sq_RA(Address + 8);
 | |
|         if (nEcx8 == -1) return nEcx8;
 | |
|         nEsi = L_sq_RA(0x1AF8D78);
 | |
|         nEdx = nEax >> 16;
 | |
|         nTmp = (nEdx << 2) + nEsi + 36;
 | |
|         nEdx = L_sq_RA(nTmp);
 | |
|         if (nEdx == -1) return nEdx;
 | |
|         nEax = nEax & 65535;
 | |
|         nTmp = (nEax << 2) + nEdx + 8468;
 | |
|         nEax = L_sq_RA(nTmp);
 | |
|         if (nEax == -1) return nEax;
 | |
|         nEdx = nEax & 0xFFFF;
 | |
|         nEsi = nEdx << 16;
 | |
|         nEsi = nEsi | nEdx;
 | |
|         nEax = nEsi ^ nEcx8;
 | |
|         return nEax;
 | |
|     }
 | |
| 
 | |
|     //加密写入内存地址数据
 | |
|     function EncodeMemoryData() {
 | |
|         local JEdi, JEcx, JEax, JEsi, JEdx, JSs;
 | |
|         JEcx = AddreSs;
 | |
|         JEax = L_sq_RA(0x1AF8DB8);
 | |
|         JEax = JEax + 1;
 | |
|         L_sq_WA(0x1AF8DB8, JEax);
 | |
|         JEdx = JEax;
 | |
|         JEdx = JEdx >> 8;
 | |
|         JEdx = JEdx << 24;
 | |
|         JEdx = JEdx >> 24;
 | |
|         JEdx = L_sq_RA(JEdx * 2 + 0x1843F58);
 | |
|         JEdx = JEdx & 0xFFFF;
 | |
|         JEax = JEax << 24;
 | |
|         JEax = JEax >> 24;
 | |
|         JSs = L_sq_RA(JEax * 2 + 0x1844158);
 | |
|         JSs = JSs & 0xFFFF;
 | |
|         JEdx = JEdx ^ JSs;
 | |
|         JEax = JEdx;
 | |
|         JEax = JEax & 0xFFFF;
 | |
|         JEsi = Data;
 | |
|         JEdx = JEsi >> 16;
 | |
| 
 | |
|         JSs = JEsi & 0xFFFF;
 | |
|         JEdx = JEdx + JSs;
 | |
|         JEdx = JEdx ^ JEax;
 | |
|         JEdi = JEdx;
 | |
|         JEdx = JEax;
 | |
|         JEax = JEax << 16;
 | |
|         JEax = JEax + JEdx;
 | |
|         JEsi = Data;
 | |
|         JEax = JEax ^ JEsi;
 | |
|         JEsi = AddreSs + 8;
 | |
|         L_sq_WA(JEsi, JEax);
 | |
|         JEax = L_sq_RA(AddreSs);
 | |
|         JEsi = L_sq_RA(0x1AF8D78);
 | |
| 
 | |
|         JEcx = JEdi;
 | |
|         JEcx = JEcx << 16;
 | |
|         JEcx = JEcx + JEdx;
 | |
|         JEdx = JEax;
 | |
|         JEdx = JEdx >> 16;
 | |
|         JEdx = L_sq_RA(JEsi + JEdx * 4 + 36);
 | |
|         JEax = JEax & 0xFFFF;
 | |
|         L_sq_WA(JEdx + JEax * 4 + 8468, JEcx);
 | |
|     }
 | |
| 
 | |
|     function DecodeMemoryDataF(Address) {
 | |
|         local Value = MemoryTool.DecodeMemoryData(Address);
 | |
|         local Bl = blob();
 | |
|         Bl.writen(Value, 'i');
 | |
|         Bl.seek(0);
 | |
|         return Bl.readn('f');
 | |
|     }
 | |
| 
 | |
|     function ReadFloat(Address) {
 | |
|         local Arr = [];
 | |
|         for (local i = 0; i< 4; i++) {
 | |
|             Arr.append(L_sq_RAB(Address + i));
 | |
|         }
 | |
|         // local Value = L_sq_RAB(Address);
 | |
|         // print(Value);
 | |
|         local Bl = blob();
 | |
|         foreach(intvalue in Arr) {
 | |
|             Bl.writen(intvalue, 'c');
 | |
|         }
 | |
|         // Bl.writen(Value, 'i');
 | |
|         Bl.seek(0);
 | |
|         return Bl.readn('f');
 | |
|     }
 | |
| } |