CSGOItemsJSON 将items_game.txt转为json格式 代码鉴赏

我不当学长 管理员组 2023-3-25 349

参考:[CS:GO] CSGOItemsJSON - AlliedModders (alliedmods.net)

#pragma newdecls required
public void OnPluginStart() 
{
    char path[PLATFORM_MAX_PATH];
    BuildPath(Path_SM, path, sizeof(path), "../../scripts/items/items_game.txt");

    char jsonpath[PLATFORM_MAX_PATH];
    BuildPath(Path_SM, jsonpath, sizeof(jsonpath), "../../scripts/items/items_game.json");

    char last[4096], curr[4096];
    char explodeString[3][4096];
    int strings;

    File file = OpenFile(path, "r");
    File json = OpenFile(jsonpath, "w");

    file.ReadLine(curr, sizeof(curr));
    
    while (!file.EndOfFile()) {
        file.ReadLine(curr, sizeof(curr));
        TrimString(curr);

        if (strcmp(curr, "{") == 0) {
            if (strlen(last) > 0) json.WriteLine("%s:", last);
        } else if (strcmp(curr, "}") == 0) {
            if (strings == 3) json.WriteLine("%s: %s", explodeString[0], explodeString[2]);
            else json.WriteLine("%s", last);
        } else {
            if (strings == 3) json.WriteLine("%s: %s,", explodeString[0], explodeString[2]);
            else {
                if (strcmp(last, "}") == 0) json.WriteLine("},");
                else json.WriteLine("%s", last);
            }
        }

        strings = ExplodeString(curr, "\t", explodeString, sizeof(explodeString), 4096);
        strcopy(last, sizeof(last), curr);
    }

    delete file;
    delete json;
} 

CSGO插件分享-申明 1、本网站名称:CSGO插件分享-中文站  网址:https://bbs.csgocn.net
2、本站的宗旨在于为CSGO玩家提供一个插件分享的中文资源平台,多数插件来源于SourceMod论坛,并配以中文介绍和安装教程。
3、欢迎有能力的朋友共享有趣的CSGO插件资源。
4、本站资源大多为百度网盘,如发现链接失效,可以点: 这里进行反馈,我们会第一时间更新。
最新回复 (0)
返回