Skip to content

Commit

Permalink
fix(super chat): 修复 blrec 与 录播姬 的 SC 金额颜色显示
Browse files Browse the repository at this point in the history
将礼物金额读取单位由“元”改为“厘”,内部存储类型由单精度浮点数统一转换为整型。

BREAKING CHANGE: 由于现在统一以“厘”为单位读入礼物金额,如果在以前单独处理 blrec 的 xml 时将 `price` 统一除以 1000 的话,会在这次更新后使读入金额缩小
1000 倍出现计算错误。

re hihkm#53
  • Loading branch information
lengyanyu258 committed Jul 25, 2024
1 parent dcf2081 commit 68ab42c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 41 deletions.
19 changes: 10 additions & 9 deletions AssFile/AssFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,7 @@ int writeAssDanmakuPart(FILE *opF, DANMAKU *head, CONFIG config, STATUS *const s
COORDIN msgBoxPos = config.msgBoxPos;
int msgFontSize = config.msgboxFontsize;
const int msgDuration = GET_ASS_MS_FLT(config.msgboxDuration); // 精度为 10 毫秒
const int giftMinPrice = config.giftMinPrice * 1000.0f; // 单位:厘
const BOOL giftComboSwitch = GET_ASS_MS_FLT(config.giftMergeTolerance) >= 0;

/* 刷新status */
Expand Down Expand Up @@ -2336,7 +2337,7 @@ int writeAssDanmakuPart(FILE *opF, DANMAKU *head, CONFIG config, STATUS *const s
else if (IS_MSG(now) && showMsgBox)/* 消息 */
{
/* 按最低价格屏蔽 */
if (now->gift->price < config.giftMinPrice && now->gift->price > -EPS)
if (now->gift->price < giftMinPrice && now->gift->price >= 0)
{
goto NEXTNODE;
}
Expand Down Expand Up @@ -3310,13 +3311,13 @@ int printMessage(FILE *filePtr,

strcpy(textColor, "\\c&H313131");

if (message->gift->price + EPS > 2000)
if (message->gift->price >= 2000 * 1000)
{ /* 2k及以上 */
strcpy(topBoxColor, "\\c&HD8D8FF");
strcpy(btmBoxColor, "\\c&H321AAB");
strcpy(userIDColor, "\\c&H1B0E5E");
}
else if (message->gift->price + EPS > 1000)
else if (message->gift->price >= 1000 * 1000)
{ /* 1k及以上 */
// strcpy(topBoxColor, "\\c&HE5E5FF");
// strcpy(btmBoxColor, "\\c&H8C8CF7");
Expand All @@ -3325,7 +3326,7 @@ int printMessage(FILE *filePtr,
strcpy(btmBoxColor, "\\c&H4D4DE5");
strcpy(userIDColor, "\\c&H333398");
}
else if (message->gift->price + EPS > 500)
else if (message->gift->price >= 500 * 1000)
{ /* 500及以上 */
// strcpy(topBoxColor, "\\c&HD4F6FF");
// strcpy(btmBoxColor, "\\c&H8CCEF7");
Expand All @@ -3334,7 +3335,7 @@ int printMessage(FILE *filePtr,
strcpy(btmBoxColor, "\\c&H4394E0");
strcpy(userIDColor, "\\c&H2C6193");
}
else if (message->gift->price + EPS > 100)
else if (message->gift->price >= 100 * 1000)
{ /* 100及以上 */
// strcpy(topBoxColor, "\\c&HCAF9F8");
// strcpy(btmBoxColor, "\\c&H76E8E9");
Expand All @@ -3343,7 +3344,7 @@ int printMessage(FILE *filePtr,
strcpy(btmBoxColor, "\\c&H2BB5E2");
strcpy(userIDColor, "\\c&H1C7795");
}
else if (message->gift->price + EPS > 50)
else if (message->gift->price >= 50 * 1000)
{ /* 50及以上 */
strcpy(topBoxColor, "\\c&HFDFFDB");
strcpy(btmBoxColor, "\\c&H9E7D42");
Expand Down Expand Up @@ -3413,7 +3414,7 @@ int printMessage(FILE *filePtr,
effect, /* 补充特效 */
textColor, /* 颜色 */
(int)(fontSize*(4.0/5.0)), /* 金额文字大小 */
(int)message->gift->price /* SC金额 */
message->gift->price / 1000/* SC金额 */
);

/* SC内容 */
Expand All @@ -3436,12 +3437,12 @@ int printMessage(FILE *filePtr,
char textColor[ASS_COLOR_LEN];

strcpy(textColor, "\\c&H313131");
if (message->gift->price + EPS > 19800)
if (message->gift->price >= 19998 * 1000)
{ /* 总督 */
strcpy(boxColor, "\\c&HE5E5FF");
strcpy(userIDColor, "\\c&H0F0F75");
}
else if (message->gift->price + EPS > 1980)
else if (message->gift->price >= 1998 * 1000)
{ /* 提督 */
strcpy(boxColor, "\\c&HCAF9F8");
strcpy(userIDColor, "\\c&H1A8B87");
Expand Down
2 changes: 1 addition & 1 deletion Config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct Configurations
struct Coordinate msgBoxPos; /* 消息框位置 */
int msgboxFontsize; /* 消息框内文字大小 */
float msgboxDuration; /* 消息框持续时长(秒数) */
float giftMinPrice; /* 消息框礼物最低价格限制 */
float giftMinPrice; /* 消息框礼物最低价格限制(元) */
float giftMergeTolerance; /* 相同用户相同礼物合并时间窗(秒数) */

int blockmode; /* 屏蔽模式 */
Expand Down
2 changes: 1 addition & 1 deletion Define/DanmakuDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct UserPart
struct GiftPart
{
char name[GIFT_NAME_LEN];
float price;
int price; // 礼物金额(厘)
int count;
int duration; // 持续时间(毫秒)
};
Expand Down
47 changes: 17 additions & 30 deletions XmlFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl
/* 读取xml文件 */
float time;
short type;
short fontSize;
int color;
short fontSize = 0;
int color = 0;
int messageType;
char *text;
char tempText[MAX_TEXT_LENGTH];
Expand Down Expand Up @@ -126,7 +126,7 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl

text = NULL;

gift.price = -1.00;
gift.price = -1;
gift.count = -1;
gift.name[0] = '\0';
gift.duration = 0;
Expand Down Expand Up @@ -198,7 +198,6 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl
continue;
}

double giftPriceUnit = 1.0;
while (*labelPtr != '\0')
{
strGetLeftPart(key, &labelPtr, '=', MAX_TEXT_LENGTH);
Expand Down Expand Up @@ -245,12 +244,12 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl
else if (strcmp(key, "giftcount") == 0 || strcmp(key, "count") == 0)
{
getNextWord(&labelPtr, tempText, MAX_TEXT_LENGTH, ' ', TRUE);
gift.count = atof(deQuotMarks(tempText));
gift.count = atoi(deQuotMarks(tempText));
}
else if (strcmp(key, "price") == 0)
{
getNextWord(&labelPtr, tempText, MAX_TEXT_LENGTH, ' ', TRUE);
gift.price = atof(deQuotMarks(tempText));
gift.price = atoi(deQuotMarks(tempText));
}
else if (strcmp(key, "time") == 0)
{
Expand All @@ -261,28 +260,23 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl
else if (strcmp(key, "level") == 0)
{
getNextWord(&labelPtr, tempText, MAX_TEXT_LENGTH, ' ', TRUE);
giftPriceUnit = 1;
switch (atoi(deQuotMarks(tempText)))
{
case 1:
// 总督
gift.duration = 19998000;
gift.price = 19998;
gift.duration = gift.price = 19998000;
break;
case 2:
// 提督
gift.duration = 1998000;
gift.price = 1998;
gift.duration = gift.price = 1998000;
break;
case 3:
// 舰长
gift.duration = 198000;
gift.price = 198;
gift.duration = gift.price = 198000;
break;
default:
// 未知
gift.duration = 18000;
gift.price = 0;
gift.duration = gift.price = 18000;
break;
}
}
Expand Down Expand Up @@ -325,9 +319,9 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl
}
else if (strcmp(rawKey, "price") == 0)
{
if (FLOAT_IS_EQUAL(gift.price, -1.00))
if (gift.price == -1)
{
gift.price = atof(rawValue);
gift.price = atoi(rawValue);
}
}
else if (strcmp(rawKey, "combo_stay_time") == 0)
Expand All @@ -340,13 +334,13 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl

if (strcmp(coinTypeValue, "silver") == 0)
{
giftPriceUnit = 0.0;
gift.price = 0;
}
else if (messageType != MSG_SUPER_CHAT)
// 录播姬的 SC 金额特殊处理
if (messageType == MSG_SUPER_CHAT)
{
giftPriceUnit = 1e-3;
gift.price *= 1000;
}

}

}
Expand All @@ -355,11 +349,9 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl
char coinTypeValue[VALUE_LEN];
getNextWord(&labelPtr, coinTypeValue, GIFT_NAME_LEN, ' ', TRUE);
deQuotMarks(coinTypeValue);
// 银瓜子 —— 免费礼物
if (strcmp(coinTypeValue, "\xe9\x93\xb6\xe7\x93\x9c\xe5\xad\x90") == 0) {
giftPriceUnit = 0.0;
}
else if (strcmp(coinTypeValue, "\xe9\x87\x91\xe7\x93\x9c\xe5\xad\x90") == 0) {
giftPriceUnit = 1e-3;
gift.price = 0;
}
}
else
Expand All @@ -368,11 +360,6 @@ int readXml(const char *const ipFile, DANMAKU **head, const char *mode, const fl
}
}

if (hasGiftInfo == TRUE && messageType != MSG_SUPER_CHAT)
{
gift.price *= giftPriceUnit;
}

if (messageType == MSG_GIFT && gift.duration == 0) {
gift.duration = 5 * 1000;
}
Expand Down

0 comments on commit 68ab42c

Please sign in to comment.