开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 257|回复: 5
收起左侧

[易语言] C#代码转易语言(不要再AI转代码了)

[复制链接]
结帖率:95% (36/38)
发表于 2025-2-16 14:18:05 | 显示全部楼层 |阅读模式   福建省厦门市
100精币

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;

namespace TS_Server.DataTools
{
public static class SwapitemData
{
public static Dictionary swapitemInfoDatas = new Dictionary();

    public static T ReadFromItems<T>(Stream fs)
    {
        byte[] buffer = new byte[Marshal.SizeOf(typeof(T))];
        fs.Read(buffer, 0, Marshal.SizeOf(typeof(T)));
        GCHandle Handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
        T RetVal = (T)Marshal.PtrToStructure(Handle.AddrOfPinnedObject(), typeof(T));
        Handle.Free();
        return RetVal;
    }

    public static bool loadItems()
    {
        try
        {
            swapitemInfoDatas?.Clear();

            swapitemInfoDatas = new Dictionary<byte, SwapitemInfos>();

            using (FileStream fileStream = new FileStream("SwapItem.dat", FileMode.Open, FileAccess.Read))
            {
                long length = fileStream.Length;
                byte[] swapitemDatas = new byte[length];
                fileStream.Read(swapitemDatas, 0, (int)length);
                fileStream.Close();

                DatReader swapDatReader = new DatReader(swapitemDatas);
                swapDatReader.DecodeAll();

                Stream stream = new MemoryStream(swapDatReader.decodedData);
                for (int i = 0; i < swapDatReader.count; i++)
                {
                    SwapitemInfos swapitemInfos = ReadFromItems<SwapitemInfos>(stream);
                    swapitemInfoDatas.Add((byte)i, swapitemInfos);
                }
            }
            return true;
        }
        catch (Exception)
        {

            return false;
        }

    }

    /// <summary>
    /// 获取需要增加的Item, 输入月份和顺序
    /// </summary>
    /// <param name="month"></param>
    /// <param name="index"></param>
    /// <returns></returns>
    public static ushort GetAddItem(byte month,byte index)
    {
        swapitemInfoDatas.TryGetValue((byte)(month - 1), out SwapitemInfos swapitemInfos);
        if(swapitemInfos.list.Length >= index)
        {
            return swapitemInfos.list[index].id1;
        }
        return 0;
    }

    /// <summary>
    /// 获取需要增加的Item, 输入月份和顺序
    /// </summary>
    /// <param name="month"></param>
    /// <param name="index"></param>
    /// <returns></returns>
    public static SwapitemInfo GetSwapitemInfo(byte month, byte index)
    {
        swapitemInfoDatas.TryGetValue((byte)(month - 1), out SwapitemInfos swapitemInfos);
        return swapitemInfos.list[index-1];

    }

}

}



using System.Runtime.InteropServices;

namespace TS_Server.DataTools
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SwapitemInfo
{
public ushort id1;
public byte count1;

    public ushort id2;
    public byte count2;

    public ushort id3;
    public byte count3;

    public ushort id4;
    public byte count4;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SwapitemInfos
{
    public byte month;
    public byte count;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
    public SwapitemInfo[] list;
}

}


public void DecodeAll()
{
position = 0;
size = ReadInt32(bigEndian: false, signed: false);
count = ReadInt32(bigEndian: false, signed: false);
keys[0] = ReadBytes(size, count + 1);
keys[1] = ReadBytes(size, count + 2);
int decodeIndex = 0;
decodedData = new byte[count size];
for (int i = 1; i <= count; i++)
{
decodeIndex = i % 2;
byte[] tempData = ReadBytes(size, i);
tempData = TransformBytes(tempData, keys[decodeIndex]);
Array.Copy(tempData, 0, decodedData, size
(i - 1), size);
}
position = 0;
}




来个大佬帮忙看下,这个读取文件加载代码怎么转易语言


回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳
结帖率:50% (3/6)

签到天数: 11 天

发表于 2025-2-16 14:44:05 | 显示全部楼层   江苏省徐州市
这不好看啊,你发项目吧.C#浅学了点.估计你这个我应该能翻
回复

使用道具 举报

签到天数: 3 天

发表于 2025-2-17 21:49:50 | 显示全部楼层   江苏省徐州市
这个不难啊  

打个赏解决
回复

使用道具 举报

结帖率:95% (36/38)

签到天数: 1 天

 楼主| 发表于 2025-2-18 23:25:41 | 显示全部楼层   福建省厦门市
编程阿狸 发表于 2025-2-17 21:49
这个不难啊  

打个赏解决

打赏精币? ?
回复

使用道具 举报

结帖率:95% (36/38)

签到天数: 1 天

 楼主| 发表于 2025-2-19 22:26:55 | 显示全部楼层   福建省厦门市
最烦起名字 发表于 2025-2-16 14:44
这不好看啊,你发项目吧.C#浅学了点.估计你这个我应该能翻

https://yiyuan.lanzouv.com/iZWS72ob33ih 这个文件
回复

使用道具 举报

结帖率:95% (36/38)

签到天数: 1 天

 楼主| 发表于 2025-2-21 22:23:48 | 显示全部楼层   福建省厦门市
有没有大佬帮下,打赏JYB也可以
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
网站简介:精易论坛成立于2009年,是一个程序设计学习交流技术论坛,隶属于揭阳市揭东区精易科技有限公司所有。
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表