Files
hjha-server/base/funs.cs
xiaoou e9616125ce feat: initial commit - HJHA game server full source
6 major server modules (PdkFriendServer/GlobalSever/ServerCore/GameModule/GameNetModule) +
game logic (GameFix/GameDAL/ServerData) +
network layer (NetWorkMessage) +
data layer (ObjectModel) +
utilities (MrWu/Core/Config/CloudAPI/dll) +
adapters (zyxAdapter/base)

.NET 8.0 C# solution, 16 projects, 958 source files
2026-07-07 12:02:15 +08:00

87 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Forms;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using nativeCom;
public class funs{
static funs _ins;
public static funs instance{get{if(_ins==null)_ins=new funs();return _ins;}set{_ins=value;}}
public byte[] StructToBytes(object structObj)
{
int size = Marshal.SizeOf(structObj);
IntPtr buffer = Marshal.AllocHGlobal(size);
try
{
Marshal.StructureToPtr(structObj, buffer, false);
byte[] bytes = new byte[size];
Marshal.Copy(buffer, bytes, 0, size);
return bytes;
}
finally
{
Marshal.FreeHGlobal(buffer);
}
}
unsafe public object clone(object obj){
byte[] bt=StructToBytes(obj);
fixed(byte* pb=bt ){
IntPtr itp=new IntPtr(pb);
return Marshal.PtrToStructure(itp, obj.GetType());
}
}
ABlock a1=new ABlock();
ABlock a2=new ABlock();
/// <summary>
/// 把bt总的数值 写入到ab指针中 偏移ofs个值
/// </summary>
/// <param name="bt"></param>
/// <param name="ab"></param>
/// <param name="ofs"></param>
unsafe public void memToNative_bytes(byte[] bt,ref ABlock ab,int ofs){
fixed(byte* pb=bt ){
IntPtr pt= new IntPtr( (int)ab.pt+ofs);
NativeDllMethod.nativefun("1",((int)pb ).ToString()+'*'+pt.ToString()+'*'+bt.Length.ToString(),ref a1,ref a2);
//
// myCom_zyx.Instance.move2Process((int*)pb,new IntPtr( (int)ab.pt+ofs),bt.Length);
}
}
unsafe public void memToNative_bytes_(byte[] bt,int addr_){
ABlock ab= new ABlock();
int* ttt=(int*)&ab;
myCom_zyx.Instance.getDataOfStruct<ABlock>(addr_, ref ab,ttt);
memToNative_bytes(bt,ref ab,0);
}
/// <summary>
/// 获取服务器所在的路径
/// </summary>
/// <returns></returns>
public string getSeverPath(){
return Application.StartupPath;
}
/// <summary>
/// 获取服务规则路径
/// </summary>
/// <returns></returns>
public string getGzPath(){ //待换
return getSeverPath() + "/mjgz.xml";
}
}